File Coverage

blib/lib/MIDI/XML/EndOfTrack.pm
Criterion Covered Total %
statement 11 33 33.3
branch 0 14 0.0
condition 0 3 0.0
subroutine 4 7 57.1
pod 3 3 100.0
total 18 60 30.0


line stmt bran cond sub pod time code
1             package MIDI::XML::EndOfTrack;
2              
3 1     1   17 use 5.006;
  1         3  
4 1     1   5 use strict;
  1         1  
  1         19  
5 1     1   3 use warnings;
  1         1  
  1         16  
6              
7 1     1   3 use MIDI::XML::Message;
  1         1  
  1         266  
8              
9             our @ISA = qw(MIDI::XML::Message);
10              
11             =head1 NAME
12              
13             MIDI::XML::EndOfTrack - MIDI End Of Track messages.
14              
15             =head1 SYNOPSIS
16              
17             use MIDI::XML::EndOfTrack;
18             $Eot = MIDI::XML::EndOfTrack->new();
19             $Eot->delta(0);
20             @event = $Eot->as_event();
21             $midi_track = MIDI::Track->new();
22             push( @{$midi_track->events_r},\@event;
23             @xml = $Eot->as_MidiXML();
24             print join("\n",@xml);
25              
26             =head1 DESCRIPTION
27              
28             MIDI::XML::EndOfTrack is a class encapsulating MIDI End Of Track
29             meta messages. A End Of Track message includes either a delta time
30             or absolute time as implemented by MIDI::XML::Message and the
31             MIDI End Of Track event encoded in 3 bytes as follows:
32              
33             0xFF 0x2F 0x00
34              
35             =head2 EXPORT
36              
37             None.
38              
39             =cut
40              
41             our $VERSION = '0.01';
42              
43             #==========================================================================
44              
45             =head1 METHODS AND ATTRIBUTES
46              
47             =over 4
48              
49             =item $Eot = MIDI::XML::EndOfTrack->new()
50              
51             This creates a new MIDI::XML::EndOfTrack object.
52              
53             =item $Eot = MIDI::XML::EndOfTrack->new($event);
54              
55             Creates a new EndOfTrack object initialized with the values of a
56             MIDI::Event end_track array.
57              
58             =cut
59              
60             sub new {
61 0     0 1   my $class = shift;
62 0   0       $class = ref($class) || $class;
63              
64 0           my $self = {
65             '_Delta'=> undef,
66             '_Absolute'=> undef,
67             };
68 0 0         if (@_) {
69 0 0         if (ref($_[0]) eq 'ARRAY') {
    0          
    0          
70 0 0         if ($_[0][0] eq 'end_track') {
71 0           $self->{'_Delta'} = $_[0][1];
72             }
73             } elsif (ref($_[0]) eq 'HASH') {
74 0           foreach my $attr (keys %{$_[0]}) {
  0            
75 0 0         $self->{"_$attr"} = $_[0]->{$attr} unless ($attr =~ /^_/);
76             }
77             } elsif (ref($_[0]) eq '') {
78 0 0         if ($_[0] eq 'end_track') {
79 0           $self->{'_Delta'} = $_[1];
80             }
81             }
82             }
83              
84 0           bless($self,$class);
85 0           return $self;
86             }
87              
88             =item $delta_time = $Eot->delta() or $Eot->delta($delta_time);
89              
90             Returns the message time as a delta time or undef if it is an absolute
91             time. Optionally sets the message time to the specified delta time. To
92             avoid contradictory times, the absolute time is set to undef when a delta time
93             is set.
94              
95             This functionality is provided by the MIDI::XML::Message base class.
96              
97             =item $absolute_time = $Eot->absolute() or $Eot->absolute($absolute_time);
98              
99             Returns the message time as an absolute time or undef if it is a delta
100             time. Optionally sets the message time to the specified absolute time. To
101             avoid contradictory times, the delta time is set to undef when an absolute time
102             is set. The absolute time should be zero according to the specification.
103              
104             This functionality is provided by the MIDI::XML::Message base class.
105              
106             =item $time = $Eot->time();
107              
108             Returns the message time, absolute or delta, whichever was last set.
109              
110             This functionality is provided by the MIDI::XML::Message base class.
111              
112             =cut
113              
114             #==========================================================================
115              
116             =item $ordinal = $Eot->ordinal();
117              
118             Returns a value to be used to order events that occur at the same time.
119              
120             sub ordinal {
121             my $self = shift;
122             return 0xFFFF ;
123             }
124              
125             #==========================================================================
126              
127             =item @event = $Eot->as_event();
128              
129             Returns a MIDI::Event end_track array initialized with the values
130             of the EndOfTrack object. MIDI::Event does not expect absolute times
131             and will interpret them as delta times. Calling this method when the time
132             is absolute will not generate a warning or error but it is unlikely that
133             the results will be satisfactory.
134              
135             =cut
136              
137             sub as_event {
138 0     0 1   my $self = shift;
139              
140 0           my @event = (
141             'end_track',
142             MIDI::XML::Message::time($self)
143             );
144 0           return @event;
145             }
146              
147             #==========================================================================
148              
149             =item @xml = $Eot->as_MidiXML();
150              
151             Returns an array of elements formatted according to the MidiXML DTD. These
152             elements may be assembled by track into entire documents with the following
153             suggested DOCTYPE declaration:
154              
155            
156             "-//Recordare//DTD MusicXML 0.7 MIDI//EN"
157             "http://www.musicxml.org/dtds/midixml.dtd">
158              
159             =back
160              
161             =cut
162              
163             sub as_MidiXML {
164 0     0 1   my $self = shift;
165 0           my @xml;
166              
167 0           push @xml, MIDI::XML::Message::as_MidiXML($self);
168 0           $xml[2] = "";
169 0           return @xml;
170             }
171              
172             #==========================================================================
173              
174              
175             return 1;
176             __END__