File Coverage

blib/lib/MIDI/XML/MidiChannelPrefix.pm
Criterion Covered Total %
statement 11 38 28.9
branch 0 12 0.0
condition 0 3 0.0
subroutine 4 9 44.4
pod 5 5 100.0
total 20 67 29.8


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