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