| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MIDI::XML::NoteOn; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
12
|
use 5.006; |
|
|
1
|
|
|
|
|
2
|
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
15
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
24
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
349
|
use MIDI::XML::Channel; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
33
|
|
|
8
|
1
|
|
|
1
|
|
304
|
use MIDI::XML::NoteOff; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
522
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @ISA = qw(MIDI::XML::Channel MIDI::XML::NoteOff); |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
MIDI::XML::NoteOff - MIDI Note On messages. |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use MIDI::XML::NoteOn; |
|
19
|
|
|
|
|
|
|
use MIDI::Track; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$Note_On = MIDI::XML::NoteOn->new(); |
|
22
|
|
|
|
|
|
|
$Note_On->delta(0); |
|
23
|
|
|
|
|
|
|
$Note_On->channel(0); |
|
24
|
|
|
|
|
|
|
$Note_On->note('F',1,4); |
|
25
|
|
|
|
|
|
|
$Note_On->velocity(92); |
|
26
|
|
|
|
|
|
|
@event = $Note_On->as_event(); |
|
27
|
|
|
|
|
|
|
$midi_track = MIDI::Track->new(); |
|
28
|
|
|
|
|
|
|
push( @{$midi_track->events_r},\@event; |
|
29
|
|
|
|
|
|
|
@xml = $Note_On->as_MidiXML(); |
|
30
|
|
|
|
|
|
|
print join("\n",@xml); |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
MIDI::XML::NoteOn is a class encapsulating MIDI Note On messages. |
|
35
|
|
|
|
|
|
|
A Note On message includes either a delta time or absolute time as |
|
36
|
|
|
|
|
|
|
implemented by MIDI::XML::Message and the MIDI Note On event encoded |
|
37
|
|
|
|
|
|
|
in 3 bytes as follows: |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1001cccc 0nnnnnnn 0vvvvvvv |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
cccc = channel; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
nnnnnnn = note number |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
vvvvvvv = velocity |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
The classes for MIDI Note On messages and the other six channel |
|
48
|
|
|
|
|
|
|
messages are derived from MIDI::XML::Channel. |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 EXPORT |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
None by default. |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#========================================================================== |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 METHODS AND ATTRIBUTES |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=over 4 |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=item $Note_On = MIDI::XML::NoteOn->new(); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This creates a new MIDI::XML::NoteOn object. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item $Note_On = MIDI::XML::NoteOn->new($event); |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Creates a new NoteOn object initialized with the values of a |
|
71
|
|
|
|
|
|
|
MIDI::Event note_on array. |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub new { |
|
76
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
77
|
0
|
|
0
|
|
|
|
$class = ref($class) || $class; |
|
78
|
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
|
my $self = { |
|
80
|
|
|
|
|
|
|
'_Delta'=> undef, |
|
81
|
|
|
|
|
|
|
'_Absolute'=> undef, |
|
82
|
|
|
|
|
|
|
'_Channel'=> undef, |
|
83
|
|
|
|
|
|
|
'_Note'=> undef, |
|
84
|
|
|
|
|
|
|
'_Velocity'=> undef, |
|
85
|
|
|
|
|
|
|
}; |
|
86
|
0
|
0
|
|
|
|
|
if (@_) { |
|
87
|
0
|
0
|
|
|
|
|
if (ref($_[0]) eq 'ARRAY') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if ($_[0][0] eq 'note_on') { |
|
89
|
0
|
|
|
|
|
|
$self->{'_Delta'} = $_[0][1]; |
|
90
|
0
|
|
|
|
|
|
$self->{'_Channel'} = $_[0][2] & 0x0F; |
|
91
|
0
|
|
|
|
|
|
$self->{'_Note'} = $_[0][3] & 0x7F; |
|
92
|
0
|
|
|
|
|
|
$self->{'_Velocity'} = $_[0][4] & 0x7F; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
} elsif (ref($_[0]) eq 'HASH') { |
|
95
|
0
|
|
|
|
|
|
foreach my $attr (keys %{$_[0]}) { |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
$self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} elsif (ref($_[0]) eq '') { |
|
99
|
0
|
0
|
|
|
|
|
if ($_[0] eq 'note_on') { |
|
100
|
0
|
|
|
|
|
|
$self->{'_Delta'} = $_[1]; |
|
101
|
0
|
|
|
|
|
|
$self->{'_Channel'} = $_[2] & 0x0F; |
|
102
|
0
|
|
|
|
|
|
$self->{'_Note'} = $_[3] & 0x7F; |
|
103
|
0
|
|
|
|
|
|
$self->{'_Velocity'} = $_[4] & 0x7F; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
bless($self,$class); |
|
109
|
0
|
|
|
|
|
|
return $self; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item $delta_time = $Note_On->delta() or $Note_On->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 = $Note_On->absolute() or $Note_On->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. |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
This functionality is provided by the MIDI::XML::Message base class. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=item $time = $Note_On->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
|
|
|
|
|
|
|
=item $channel = $Note_On->channel() or $Note_On->channel($channel); |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Returns and optionally sets the channel number. Channel numbers are limited |
|
139
|
|
|
|
|
|
|
to the range 0-15. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
This functionality is provided by the MIDI::XML::Channel base class. |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
#========================================================================== |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item $note_no = $Note_On->note(); |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns the MIDI note number. Note numbers are limited |
|
148
|
|
|
|
|
|
|
to the range 0-127. |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item $note_no = $Note_On->note($note_no); |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Sets and returns the MIDI note number to the specified number. Note numbers |
|
153
|
|
|
|
|
|
|
are limited to the range 0-127. |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item $note_no = $Note_On->note($step, $alter, $octave); |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Sets the MIDI note number to the specified step, alter and octave |
|
158
|
|
|
|
|
|
|
values. Step is a letter designation of the note, /A|B|C|D|E|F|G/, alter |
|
159
|
|
|
|
|
|
|
is -1 for flat, 0 for natural, and 1 for sharp, and octave is the octave, -1 |
|
160
|
|
|
|
|
|
|
to 9. Valid values range from ('C',0,-1) to ('G',0,9). Returns the MIDI |
|
161
|
|
|
|
|
|
|
note number. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item $note_no = $Note_On->note($step, $octave); |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Sets and returns the MIDI note number to the specified step and octave |
|
166
|
|
|
|
|
|
|
values assuming a 0 alter value. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
This functionality is provided by the MIDI::XML::NoteOff class. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=cut |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
#========================================================================== |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item $velocity = $Note_On->velocity() or $Note_On->velocity($velocity); |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
Returns and optionally sets the velocity. Velocities are limited |
|
177
|
|
|
|
|
|
|
to the range 0-127. |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub velocity { |
|
182
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
183
|
0
|
0
|
|
|
|
|
if (@_) { |
|
184
|
0
|
|
|
|
|
|
$self->{'_Velocity'} = (shift) & 0x7F; |
|
185
|
|
|
|
|
|
|
} |
|
186
|
0
|
|
|
|
|
|
return $self->{'_Velocity'}; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
#========================================================================== |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=item $ordinal = $Note_On->ordinal(); |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Returns a value to be used to order events that occur at the same time. |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=cut |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub ordinal { |
|
198
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
199
|
0
|
|
|
|
|
|
return 0x0700 + (127 - $self->{'_Note'}); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
#========================================================================== |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item @event = $Note_On->as_event(); |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Returns a MIDI::Event note_on array initialized with the values of the |
|
207
|
|
|
|
|
|
|
NoteOn object. MIDI::Event does not expect absolute times and will interpret |
|
208
|
|
|
|
|
|
|
them as delta times. Calling this method when the time is absolute will not |
|
209
|
|
|
|
|
|
|
generate a warning or error but it is unlikely that the results will be |
|
210
|
|
|
|
|
|
|
satisfactory. |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=cut |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub as_event { |
|
215
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
my @event = ( |
|
218
|
|
|
|
|
|
|
'note_on', |
|
219
|
|
|
|
|
|
|
MIDI::XML::Message::time($self), |
|
220
|
|
|
|
|
|
|
$self->{'_Channel'} & 0x0F, |
|
221
|
|
|
|
|
|
|
$self->{'_Note'} & 0x7F, |
|
222
|
0
|
|
|
|
|
|
$self->{'_Velocity'} & 0x7F |
|
223
|
|
|
|
|
|
|
); |
|
224
|
0
|
|
|
|
|
|
return @event; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
#========================================================================== |
|
227
|
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
=item @xml = $Note_On->as_MidiXML(); |
|
229
|
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
Returns an array of elements formatted according to the MidiXML DTD. These |
|
231
|
|
|
|
|
|
|
elements may be assembled by track into entire documents with the following |
|
232
|
|
|
|
|
|
|
suggested DOCTYPE declaration: |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
"-//Recordare//DTD MusicXML 0.7 MIDI//EN" |
|
236
|
|
|
|
|
|
|
"http://www.musicxml.org/dtds/midixml.dtd"> |
|
237
|
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
=back |
|
239
|
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=cut |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
sub as_MidiXML { |
|
243
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
244
|
0
|
|
|
|
|
|
my @xml; |
|
245
|
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
push @xml, MIDI::XML::Channel::as_MidiXML($self); |
|
247
|
0
|
|
|
|
|
|
$xml[2] = "{'_Note'}\" Velocity=\"$self->{'_Velocity'}\"/>"; |
|
248
|
0
|
|
|
|
|
|
return @xml; |
|
249
|
|
|
|
|
|
|
} |
|
250
|
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
#========================================================================== |
|
252
|
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
return 1; |
|
255
|
|
|
|
|
|
|
__END__ |