File Coverage

blib/lib/MIDI/XML/SequenceNumber.pm
Criterion Covered Total %
statement 11 41 26.8
branch 0 16 0.0
condition 0 3 0.0
subroutine 4 9 44.4
pod 5 5 100.0
total 20 74 27.0


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