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