| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MIDI::XML::TimeSignature; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13
|
use 5.006; |
|
|
1
|
|
|
|
|
1
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
27
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
22
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use MIDI::XML::Message; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
576
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(MIDI::XML::Message); |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
MIDI::XML::TimeSignature - MIDI Time Signature messages. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use MIDI::XML::TimeSignature; |
|
18
|
|
|
|
|
|
|
$Time_Sig = MIDI::XML::TimeSignature->new(); |
|
19
|
|
|
|
|
|
|
$Time_Sig->delta(0); |
|
20
|
|
|
|
|
|
|
$Time_Sig->numerator(4); |
|
21
|
|
|
|
|
|
|
$Time_Sig->logDenominator(2); |
|
22
|
|
|
|
|
|
|
$Time_Sig->midiClocksPerMetronomeClick(96); |
|
23
|
|
|
|
|
|
|
$Time_Sig->thirtySecondsPer24Clocks(8); |
|
24
|
|
|
|
|
|
|
@event = $Time_Sig->as_event(); |
|
25
|
|
|
|
|
|
|
$midi_track = MIDI::Track->new(); |
|
26
|
|
|
|
|
|
|
push( @{$midi_track->events_r},\@event; |
|
27
|
|
|
|
|
|
|
@xml = $Time_Sig->as_MidiXML(); |
|
28
|
|
|
|
|
|
|
print join("\n",@xml); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
MIDI::XML::TimeSignature is a class encapsulating MIDI Time Signature |
|
33
|
|
|
|
|
|
|
meta messages. A Time Signature message includes either a delta time |
|
34
|
|
|
|
|
|
|
or absolute time as implemented by MIDI::XML::Message and the MIDI |
|
35
|
|
|
|
|
|
|
Time Signature event encoded in 7 bytes as follows: |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
0xFF 0x58 0x04 0xnn 0xpp 0xmm 0xqq |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
nn = numerator |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
pp = log(2) denominator |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
mm = clock signals per metronome pulse |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
qq = thirty-second notes per MIDI quarter notes |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head2 EXPORT |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
None. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#========================================================================== |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 METHODS AND ATTRIBUTES |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=over 4 |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item $Time_Sig = MIDI::XML::TimeSignature->new() |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This creates a new MIDI::XML::TimeSignature object. |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=item $Time_Sig = MIDI::XML::TimeSignature->new($event); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Creates a new TimeSignature object initialized with the values of a |
|
68
|
|
|
|
|
|
|
MIDI::Event set_sequence_number array. |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub new { |
|
73
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
74
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
my $self = { |
|
77
|
|
|
|
|
|
|
'_Delta'=> undef, |
|
78
|
|
|
|
|
|
|
'_Absolute'=> undef, |
|
79
|
|
|
|
|
|
|
'_Numerator'=> undef, |
|
80
|
|
|
|
|
|
|
'_LogDenominator'=> undef, |
|
81
|
|
|
|
|
|
|
'_MidiClocksPerMetronomeClick'=> undef, |
|
82
|
|
|
|
|
|
|
'_ThirtySecondsPer24Clocks'=> undef, |
|
83
|
|
|
|
|
|
|
}; |
|
84
|
0
|
0
|
|
|
|
|
if (@_) { |
|
85
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq 'ARRAY') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if ($_[0][0] eq 'time_signature') { |
|
87
|
0
|
|
|
|
|
|
$self->{'_Delta'} = $_[0][1]; |
|
88
|
0
|
|
|
|
|
|
$self->{'_Numerator'} = $_[0][2]; |
|
89
|
0
|
|
|
|
|
|
$self->{'_LogDenominator'} = $_[0][3]; |
|
90
|
0
|
|
|
|
|
|
$self->{'_MidiClocksPerMetronomeClick'} = $_[0][4]; |
|
91
|
0
|
|
|
|
|
|
$self->{'_ThirtySecondsPer24Clocks'} = $_[0][5]; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
} elsif (ref($_[0]) eq 'HASH') { |
|
94
|
0
|
|
|
|
|
|
foreach my $attr (keys %{$_[0]}) { |
|
|
0
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
$self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/); |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} elsif (ref($_[0]) eq '') { |
|
98
|
0
|
0
|
|
|
|
|
if ($_[0] eq 'time_signature') { |
|
99
|
0
|
|
|
|
|
|
$self->{'_Delta'} = $_[1]; |
|
100
|
0
|
|
|
|
|
|
$self->{'_Numerator'} = $_[2]; |
|
101
|
0
|
|
|
|
|
|
$self->{'_LogDenominator'} = $_[3]; |
|
102
|
0
|
|
|
|
|
|
$self->{'_MidiClocksPerMetronomeClick'} = $_[4]; |
|
103
|
0
|
|
|
|
|
|
$self->{'_ThirtySecondsPer24Clocks'} = $_[5]; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
bless($self,$class); |
|
109
|
0
|
|
|
|
|
|
return $self; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item $delta_time = $Time_Sig->delta() or $Time_Sig->delta($delta_time); |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns the message time as a delta time or undef if it is an absolute |
|
115
|
|
|
|
|
|
|
time. Optionally sets the message time to the specified delta time. To |
|
116
|
|
|
|
|
|
|
avoid contradictory times, the absolute time is set to undef when a delta time |
|
117
|
|
|
|
|
|
|
is set. |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This functionality is provided by the MIDI::XML::Message base class. |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item $absolute_time = $Time_Sig->absolute() or $Time_Sig->absolute($absolute_time); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns the message time as an absolute time or undef if it is a delta |
|
124
|
|
|
|
|
|
|
time. Optionally sets the message time to the specified absolute time. To |
|
125
|
|
|
|
|
|
|
avoid contradictory times, the delta time is set to undef when an absolute time |
|
126
|
|
|
|
|
|
|
is set. The absolute time should be zero according to the specification. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This functionality is provided by the MIDI::XML::Message base class. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item $time = $Time_Sig->time(); |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns the message time, absolute or delta, whichever was last set. |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
This functionality is provided by the MIDI::XML::Message base class. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#========================================================================== |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item $numerator = $Time_Sig->numerator() or $Time_Sig->numerator($numerator); |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns and optionally sets the numerator. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=cut |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub numerator { |
|
147
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
148
|
0
|
0
|
|
|
|
|
if (@_) { |
|
149
|
0
|
|
|
|
|
|
$self->{'_Numerator'} = shift; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
0
|
|
|
|
|
|
return $self->{'_Numerator'}; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#========================================================================== |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item $log_denominator = $Time_Sig->logDenominator() or $Time_Sig->logDenominator($log_denominator); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Returns and optionally sets the log Denominator. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=cut |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub logDenominator { |
|
163
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
164
|
0
|
0
|
|
|
|
|
if (@_) { |
|
165
|
0
|
|
|
|
|
|
$self->{'_LogDenominator'} = shift; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
0
|
|
|
|
|
|
return $self->{'_LogDenominator'}; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
#========================================================================== |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item $clocks = $Time_Sig->midiClocksPerMetronomeClick() or $Time_Sig->midiClocksPerMetronomeClick($clocks); |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Returns and optionally sets the number of MIDI clocks per metronome click. |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=cut |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub midiClocksPerMetronomeClick { |
|
179
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
180
|
0
|
0
|
|
|
|
|
if (@_) { |
|
181
|
0
|
|
|
|
|
|
$self->{'_MidiClocksPerMetronomeClick'} = shift; |
|
182
|
|
|
|
|
|
|
} |
|
183
|
0
|
|
|
|
|
|
return $self->{'_MidiClocksPerMetronomeClick'}; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
#========================================================================== |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item $ts = $Time_Sig->thirtySecondsPer24Clocks() or $Time_Sig->thirtySecondsPer24Clocks($ts); |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Returns and optionally sets the number of thirty-second note per 24 MIDI clocks. |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=cut |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub thirtySecondsPer24Clocks { |
|
195
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
196
|
0
|
0
|
|
|
|
|
if (@_) { |
|
197
|
0
|
|
|
|
|
|
$self->{'_ThirtySecondsPer24Clocks'} = shift; |
|
198
|
|
|
|
|
|
|
} |
|
199
|
0
|
|
|
|
|
|
return $self->{'_ThirtySecondsPer24Clocks'}; |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
#========================================================================== |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item $ordinal = $Time_Sig->ordinal(); |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Returns a value to be used to order events that occur at the same time. |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub ordinal { |
|
209
|
|
|
|
|
|
|
my $self = shift; |
|
210
|
|
|
|
|
|
|
return 0x0050 ; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
#========================================================================== |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=item @event = $Time_Sig->as_event(); |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
Returns a MIDI::Event time_signature array initialized with the values |
|
218
|
|
|
|
|
|
|
of the TimeSignature object. MIDI::Event does not expect absolute times |
|
219
|
|
|
|
|
|
|
and will interpret them as delta times. Calling this method when the time |
|
220
|
|
|
|
|
|
|
is absolute will not generate a warning or error but it is unlikely that |
|
221
|
|
|
|
|
|
|
the results will be satisfactory. |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
|
224
|
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
sub as_event { |
|
226
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
my @event = ( |
|
229
|
|
|
|
|
|
|
'time_signature', |
|
230
|
|
|
|
|
|
|
MIDI::XML::Message::time($self), |
|
231
|
|
|
|
|
|
|
$self->{'_Numerator'}, |
|
232
|
|
|
|
|
|
|
$self->{'_LogDenominator'}, |
|
233
|
|
|
|
|
|
|
$self->{'_MidiClocksPerMetronomeClick'}, |
|
234
|
0
|
|
|
|
|
|
$self->{'_ThirtySecondsPer24Clocks'} |
|
235
|
|
|
|
|
|
|
); |
|
236
|
0
|
|
|
|
|
|
return @event; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
#========================================================================== |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
=item @xml = $Time_Sig->as_MidiXML(); |
|
242
|
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
Returns an array of elements formatted according to the MidiXML DTD. These |
|
244
|
|
|
|
|
|
|
elements may be assembled by track into entire documents with the following |
|
245
|
|
|
|
|
|
|
suggested DOCTYPE declaration: |
|
246
|
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
"-//Recordare//DTD MusicXML 0.7 MIDI//EN" |
|
249
|
|
|
|
|
|
|
"http://www.musicxml.org/dtds/midixml.dtd"> |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
=back |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=cut |
|
254
|
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub as_MidiXML { |
|
256
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
257
|
0
|
|
|
|
|
|
my @xml; |
|
258
|
|
|
|
|
|
|
my @attr; |
|
259
|
|
|
|
|
|
|
|
|
260
|
0
|
0
|
|
|
|
|
if ( defined($self->{'_Numerator'})) { |
|
261
|
0
|
|
|
|
|
|
push @attr, "Numerator=\"$self->{'_Numerator'}\""; |
|
262
|
|
|
|
|
|
|
} |
|
263
|
0
|
0
|
|
|
|
|
if ( defined($self->{'_LogDenominator'})) { |
|
264
|
0
|
|
|
|
|
|
push @attr, "LogDenominator=\"$self->{'_LogDenominator'}\""; |
|
265
|
|
|
|
|
|
|
} |
|
266
|
0
|
0
|
|
|
|
|
if ( defined($self->{'_MidiClocksPerMetronomeClick'})) { |
|
267
|
0
|
|
|
|
|
|
push @attr, "MidiClocksPerMetronomeClick=\"$self->{'_MidiClocksPerMetronomeClick'}\""; |
|
268
|
|
|
|
|
|
|
} |
|
269
|
0
|
0
|
|
|
|
|
if ( defined($self->{'_ThirtySecondsPer24Clocks'})) { |
|
270
|
0
|
|
|
|
|
|
push @attr, "ThirtySecondsPer24Clocks=\"$self->{'_ThirtySecondsPer24Clocks'}\""; |
|
271
|
|
|
|
|
|
|
} |
|
272
|
|
|
|
|
|
|
|
|
273
|
0
|
|
|
|
|
|
push @xml, MIDI::XML::Message::as_MidiXML($self); |
|
274
|
0
|
|
|
|
|
|
$xml[2] = ""; |
|
275
|
0
|
|
|
|
|
|
return @xml; |
|
276
|
|
|
|
|
|
|
} |
|
277
|
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
#========================================================================== |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
return 1; |
|
282
|
|
|
|
|
|
|
__END__ |