File Coverage

blib/lib/MIDI/XML/SetTempo.pm
Criterion Covered Total %
statement 11 41 26.8
branch 0 16 0.0
condition 0 3 0.0
subroutine 4 9 44.4
pod 5 5 100.0
total 20 74 27.0


line stmt bran cond sub pod time code
1             package MIDI::XML::SetTempo;
2              
3 1     1   11 use 5.006;
  1         2  
4 1     1   3 use strict;
  1         1  
  1         14  
5 1     1   2 use warnings;
  1         5  
  1         17  
6              
7 1     1   3 use MIDI::XML::Message;
  1         0  
  1         432  
8              
9             our @ISA = qw(MIDI::XML::Message);
10              
11             =head1 NAME
12              
13             MIDI::XML::SetTempo - MIDI Set Tempo messages.
14              
15             =head1 SYNOPSIS
16              
17             use MIDI::XML::SetTempo;
18             $Set_Tempo = MIDI::XML::SetTempo->new();
19             $Set_Tempo->delta(0);
20             $Set_Tempo->value(4);
21             @event = $Set_Tempo->as_event();
22             $midi_track = MIDI::Track->new();
23             push( @{$midi_track->events_r},\@event;
24             @xml = $Set_Tempo->as_MidiXML();
25             print join("\n",@xml);
26              
27             =head1 DESCRIPTION
28              
29             MIDI::XML::SetTempo is a class encapsulating MIDI Set Tempo
30             meta messages. A Set Tempo message includes either a delta time
31             or absolute time as implemented by MIDI::XML::Message and the MIDI
32             Set Tempo event encoded in 6 bytes as follows:
33              
34             0xFF 0x51 0x03 0xtt 0xtt 0xtt
35              
36             =head2 EXPORT
37              
38             None.
39              
40             =cut
41              
42             our $VERSION = '0.02';
43              
44             #==========================================================================
45              
46             =head1 METHODS AND ATTRIBUTES
47              
48             =over 4
49              
50             =item $Set_Tempo = MIDI::XML::SetTempo->new()
51              
52             This creates a new MIDI::XML::SetTempo object.
53              
54             =item $Set_Tempo = MIDI::XML::SetTempo->new($event);
55              
56             Creates a new SetTempo object initialized with the values of a
57             MIDI::Event set_tempo array.
58              
59             =cut
60              
61             sub new {
62 0     0 1   my $class = shift;
63 0   0       $class = ref($class) || $class;
64              
65 0           my $self = {
66             '_Delta'=> undef,
67             '_Absolute'=> undef,
68             '_Value'=> undef,
69             };
70 0 0         if (@_) {
71 0 0         if (ref($_[0]) eq 'ARRAY') {
    0          
    0          
72 0 0         if ($_[0][0] eq 'set_tempo') {
73 0           $self->{'_Delta'} = $_[0][1];
74 0           $self->{'_Value'} = $_[0][2];
75             }
76             } elsif (ref($_[0]) eq 'HASH') {
77 0           foreach my $attr (keys %{$_[0]}) {
  0            
78 0 0         $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
79             }
80             } elsif (ref($_[0]) eq '') {
81 0 0         if ($_[0] eq 'set_tempo') {
82 0           $self->{'_Delta'} = $_[1];
83 0           $self->{'_Value'} = $_[2];
84             }
85             }
86             }
87              
88 0           bless($self,$class);
89 0           return $self;
90             }
91              
92             =item $delta_time = $Set_Tempo->delta() or $Set_Tempo->delta($delta_time);
93              
94             Returns the message time as a delta time or undef if it is an absolute
95             time. Optionally sets the message time to the specified delta time. To
96             avoid contradictory times, the absolute time is set to undef when a delta time
97             is set.
98              
99             This functionality is provided by the MIDI::XML::Message base class.
100              
101             =item $absolute_time = $Set_Tempo->absolute() or $Set_Tempo->absolute($absolute_time);
102              
103             Returns the message time as an absolute time or undef if it is a delta
104             time. Optionally sets the message time to the specified absolute time. To
105             avoid contradictory times, the delta time is set to undef when an absolute time
106             is set. The absolute time should be zero according to the specification.
107              
108             This functionality is provided by the MIDI::XML::Message base class.
109              
110             =item $time = $Set_Tempo->time();
111              
112             Returns the message time, absolute or delta, whichever was last set.
113              
114             This functionality is provided by the MIDI::XML::Message base class.
115              
116             =cut
117              
118             #==========================================================================
119              
120             =item $tempo = $Set_Tempo->tempo() or $Set_Tempo->tempo($tempo);
121              
122             Returns and optionally sets the tempo value.
123              
124             =cut
125              
126             sub tempo {
127 0     0 1   my $self = shift;
128 0 0         if (@_) {
129 0           $self->{'_Value'} = shift;
130             }
131 0           return $self->{'_Value'};
132             }
133              
134             #==========================================================================
135              
136             =item $ordinal = $Set_Tempo->ordinal();
137              
138             Returns a value to be used to order events that occur at the same time.
139              
140             =cut
141              
142             sub ordinal {
143 0     0 1   my $self = shift;
144 0           return 0x0051 ;
145             }
146              
147             #==========================================================================
148              
149             =item @event = $Set_Tempo->as_event();
150              
151             Returns a MIDI::Event set_tempo array initialized with the values
152             of the SetTempo object. MIDI::Event does not expect absolute times
153             and will interpret them as delta times. Calling this method when the time
154             is absolute will not generate a warning or error but it is unlikely that
155             the results will be satisfactory.
156              
157             =cut
158              
159             sub as_event {
160 0     0 1   my $self = shift;
161              
162             my @event = (
163             'set_tempo',
164             MIDI::XML::Message::time($self),
165 0           $self->{'_Value'}
166             );
167 0           return @event;
168             }
169              
170             #==========================================================================
171              
172             =item @xml = $Set_Tempo->as_MidiXML();
173              
174             Returns an array of elements formatted according to the MidiXML DTD. These
175             elements may be assembled by track into entire documents with the following
176             suggested DOCTYPE declaration:
177              
178            
179             "-//Recordare//DTD MusicXML 0.7 MIDI//EN"
180             "http://www.musicxml.org/dtds/midixml.dtd">
181              
182             =back
183              
184             =cut
185              
186             sub as_MidiXML {
187 0     0 1   my $self = shift;
188 0           my @xml;
189              
190 0           push @xml, MIDI::XML::Message::as_MidiXML($self);
191 0           $xml[2] = "{'_Value'}\"/>";
192 0           return @xml;
193             }
194              
195             #==========================================================================
196              
197              
198             return 1;
199             __END__