line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MIDI::XML::Port; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
12
|
use 5.006; |
|
1
|
|
|
|
|
1
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
13
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use MIDI::XML::Message; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
345
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(MIDI::XML::Message); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
MIDI::XML::Port - Class MIDI Port messages. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use MIDI::XML::Port; |
18
|
|
|
|
|
|
|
$Port = MIDI::XML::Port->new(); |
19
|
|
|
|
|
|
|
$Port->delta(0); |
20
|
|
|
|
|
|
|
$Port->port(2); |
21
|
|
|
|
|
|
|
@event = $Port->as_event(); |
22
|
|
|
|
|
|
|
$midi_track = MIDI::Track->new(); |
23
|
|
|
|
|
|
|
push( @{$midi_track->events_r},\@event; |
24
|
|
|
|
|
|
|
@xml = $Port->as_MidiXML(); |
25
|
|
|
|
|
|
|
print join("\n",@xml); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
MIDI::XML::Port is a class encapsulating MIDI Port |
30
|
|
|
|
|
|
|
meta messages. A Port message includes either a delta time |
31
|
|
|
|
|
|
|
or absolute time as implemented by MIDI::XML::Message and the MIDI |
32
|
|
|
|
|
|
|
Poer event encoded in 4 bytes as follows: |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
0xFF 0x21 0x01 0xnn |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
nn = port number |
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 $Port = MIDI::XML::Port->new() |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
This creates a new MIDI::XML::Port object. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item $Port = MIDI::XML::Port->new($event); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Creates a new Port object initialized with the values of a |
59
|
|
|
|
|
|
|
MIDI::Event port 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 'port') { |
75
|
0
|
|
|
|
|
|
$self->{'_Delta'} = $_[0][1]; |
76
|
0
|
|
|
|
|
|
$self->{'_Port'} = $_[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
|
|
|
|
|
|
|
} elsif (ref($_[0]) eq '') { |
83
|
0
|
0
|
|
|
|
|
if ($_[0] eq 'port') { |
84
|
0
|
|
|
|
|
|
$self->{'_Delta'} = $_[1]; |
85
|
0
|
|
|
|
|
|
$self->{'_Port'} = $_[2]; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
bless($self,$class); |
91
|
0
|
|
|
|
|
|
return $self; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=item $delta_time = $Port->delta() or $Port->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 = $Port->absolute() or $Port->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. The absolute time should be zero according to the specification. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This functionality is provided by the MIDI::XML::Message base class. |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=item $time = $Port->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 $port = $Port->port() or $Port->port($port); |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns and optionally sets the port number. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub port { |
129
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
130
|
0
|
0
|
|
|
|
|
if (@_) { |
131
|
0
|
|
|
|
|
|
$self->{'_Port'} = shift; |
132
|
|
|
|
|
|
|
} |
133
|
0
|
|
|
|
|
|
return $self->{'_Port'}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#========================================================================== |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item $ordinal = $Port->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 0x0021 ; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#========================================================================== |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=item @event = $Port->as_event(); |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Returns a MIDI::Event port array initialized with the values |
154
|
|
|
|
|
|
|
of the Port 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
|
|
|
|
|
|
|
'port', |
166
|
|
|
|
|
|
|
MIDI::XML::Message::time($self), |
167
|
0
|
|
|
|
|
|
$self->{'_Port'} |
168
|
|
|
|
|
|
|
); |
169
|
0
|
|
|
|
|
|
return @event; |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
#========================================================================== |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=item @xml = $Port->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
|
|
|
|
|
|
push @xml, MIDI::XML::Message::as_MidiXML($self); |
193
|
0
|
|
|
|
|
|
$xml[2] = "{'_Port'}\"/>"; |
194
|
0
|
|
|
|
|
|
return @xml; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
#========================================================================== |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
return 1; |
201
|
|
|
|
|
|
|
__END__ |