File Coverage

blib/lib/MIDI/XML/EndOfExclusive.pm
Criterion Covered Total %
statement 11 45 24.4
branch 0 18 0.0
condition 0 3 0.0
subroutine 4 8 50.0
pod 4 4 100.0
total 19 78 24.3


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