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