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