blib/lib/MIDI/Trans.pm

filter: Statementstmt 6.5% 19 / 292 Branchbran 0.0% 0 / 112 Conditioncond 0.0% 0 / 64 MC/DCmcdc 0.0% 0 / 39 Subroutinesub 11.4% 4 / 35 Podpod 0.0% 0 / 27 totaltotal 4.0% 23 / 569 CC 83 SCAR 49.3
CC
83
Cov
4%
trans
462.0
read_corpus
272.0
process
110.0
CRAP 137.8
↑ Summary
1 package MIDI::Trans;
2
3 1 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6
7 1 ▶use MIDI::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 1 require Exporter;
10
11 1 our @ISA = qw(Exporter);
12
13 # Items to export into callers namespace by default. Note: do not export
14 # names by default without a very good reason. Use EXPORT_OK instead.
15 # Do not simply export all your public functions/methods/constants.
16
17 # This allows declaration use MIDI::Trans ':all';
18 # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
19 # will save memory.
20 1 our %EXPORT_TAGS = ( 'all' => [ qw(
21
22 ) ] );
23
24 1 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
25
26 1 our @EXPORT = qw(
27
28 );
29 1 our $VERSION = '0.15';
30
31
32 # Preloaded methods go here.
33
34 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
35
36 0 my $class = shift;
37 0 ▶ my $self=bless {}, ref($class)||$class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
38
39 0 $self->_init(@_);
40
41 0 return $self;
42
43 }
44
45 0 ▶sub _init {
Subroutine _init: not called CC=3 SCAR=24.8
46
47 0 my $self = shift;
48 0 my $opt_HR = shift;
49
50 # default values
51
52 0 $self->{'Raise_Error'} = 0;
53 0 $self->{'ERRx1'} = undef;
54 0 $self->{'ElementDelimiter'} = '\s+';
55 0 $self->{'SentenceDelimiter'} = '\.|\!|\?|';
56 0 $self->{'NoteCallBack'} = undef;
57 0 $self->{'VolumeCallBack'} = undef;
58 0 $self->{'DurationCallBack'} = undef;
59 0 $self->{'TempoCallBack'} = undef;
60 0 $self->{'AllAttributes'} = 1;
61 0 $self->{'OpenFiles'} = ();
62 0 $self->{'CurElem'} = undef;
63 0 $self->{'CurPos'} = undef;
64 0 $self->{'Channel'} = 1;
65 0 $self->{'Events'} = ();
66 0 $self->{'qn_len'} = 96;
67 0 $self->{'BaseMilliseconds'} = 60000000;
68 0 $self->{'Tempo'} = 120;
69 0 $self->{'CCorp'} = undef;
70 0 $self->{'TransObj'} = undef;
71
72 0 foreach my $key ('Raise_Error','ElementDelimiter','NoteCallBack','VolumeCallBack','DurationCallBack','SentenceDelimiter','AllAttributes','Channel','qn_len', 'TempoCallBack', 'Tempo') {
73 0 ▶ map {$self->{$_}=$opt_HR->{$_}} ($key) if(defined($opt_HR->{"$key"}));
Branch: 1 branch
BranchTrueFalseTotal
if defined $$opt_HR{"$key"} 0 0 0
74 }
75
76 0 return(1);
77 }
78
79
80 0 ▶sub error {
Subroutine error: not called CC=3 SCAR=24.8
Pod undocumented
81
82 0 my $self = shift;
83 0 ▶ return($self->{'ERRx1'}) if(!defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
84
85 0 ▶ if($self->raise_error()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->raise_error) { } 0 0 0
86 0 die("[MIDI::Trans] ERROR: $_[0]\n");
87 } else {
88 0 $self->{'ERRx1'} = $_[0];
89 0 return($self->{'ERRx1'});
90 }
91 }
92
93 0 ▶sub raise_error {
Subroutine raise_error: not called CC=2 SCAR=17.9
Pod undocumented
94
95 0 my $self = shift;
96
97 0 ▶ $self->{'Raise_Error'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
98 0 return($self->{'Raise_Error'});
99 }
100
101
102 0 ▶sub delimiter {
Subroutine delimiter: not called CC=2 SCAR=17.9
Pod undocumented
103
104 0 my $self = shift;
105
106 0 ▶ $self->{'ElementDelimiter'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
107 0 return($self->{'ElementDelimiter'});
108 }
109
110 0 ▶sub sentence_delimiter {
Subroutine sentence_delimiter: not called CC=2 SCAR=17.9
Pod undocumented
111
112 0 my $self = shift;
113
114 0 ▶ $self->{'SentenceDelimiter'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
115 0 return($self->{'SentenceDelimiter'});
116 }
117
118 0 ▶sub all_attributes {
Subroutine all_attributes: not called CC=2 SCAR=17.9
Pod undocumented
119
120 0 my $self = shift;
121 0 ▶ $self->{'AllAttributes'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
122 0 return($self->{'AllAttributes'});
123 }
124
125 0 ▶sub channel {
Subroutine channel: not called CC=2 SCAR=17.9
Pod undocumented
126
127 0 my $self = shift;
128 0 ▶ $self->{'Channel'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
129 0 return($self->{'Channel'});
130 }
131
132 0 ▶sub read_corpus {
Subroutine read_corpus: not called CC=16 SCAR=56.1
Pod undocumented
133
134 0 my $self = shift;
135 0 my $hRef = shift;
136
137 0 ▶ if(!defined($hRef) || ref($hRef) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $hRef or ref $hRef ne "HASH") 0 0 0
Condition0%0/3
not defined $hRef or ref $hRef ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $hRef or ref $hRef ne "HASH"
not defined $hRef ref $hRef ne "HASH"
Truth table0%0/3
not(A) or B
A= not defined $hRefB= ref $hRef ne "HASH"
ABresult
1X1
011
000
138 0 $self->error("[read_corpus] ERROR: HASHREF Argument Required.");
139 0 return(undef);
140 }
141
142 0 my($data,$file);
143 0 my $lines = 0;
144 0 my $delim = $self->delimiter();
145 0 my $sent_delim = $self->sentence_delimiter();
146
147 0 ▶ if(exists($hRef->{'File'}) && defined($hRef->{'File'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $hRef->{'File'} and defined $hRef->{'File'}) { } 0 0 0
elsif (exists $hRef->{'String'} and defined $hRef->{'String'}) { } 0 0 0
Condition0%0/3
exists $hRef->{"File"} and defined $hRef->{"File"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $hRef->{"File"} and defined $hRef->{"File"}
exists $hRef->{"File"} defined $hRef->{"File"}
Truth table0%0/3
A and B
A= exists $hRef->{"File"}B= defined $hRef->{"File"}
ABresult
0X0
100
111
148
149 0 $file = $hRef->{'File'};
150
151 0 ▶ if(open(TRFH,$file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open TRFH, $file) { } 0 0 0
152
153 0 ▶ while(<TRFH>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline TRFH)) 0 0 0
154 0 chomp;
155 0 $data .= $_;
156 0 $lines++;
157 }
158
159 0 close(TRFH);
160
161 0 ▶ return(1) if(length($data) < 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $data < 1 0 0 0
162
163 # could not open file...
164 } else {
165 0 $self->error("[read_corpus] ERROR: Could not open $hRef->{'File'} -> $!");
166 0 return(undef);
167 }
168
169 ▶ } elsif(exists($hRef->{'String'}) && defined($hRef->{'String'})) {
Condition0%0/3
exists $hRef->{"String"} and defined $hRef->{"String"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $hRef->{"String"} and defined $hRef->{"String"}
exists $hRef->{"String"} defined $hRef->{"String"}
Truth table0%0/3
A and B
A= exists $hRef->{"String"}B= defined $hRef->{"String"}
ABresult
0X0
100
111
170 0 $data = $hRef->{'String'};
171 0 ▶ return(1) if(length($data) < 1);
Branch: 1 branch
BranchTrueFalseTotal
if length $data < 1 0 0 0
172 }
173
174
175 0 my %hash = ();
176
177 0 ▶ $hash{'Name'} = $hRef->{'Name'} || $file if(defined($file));
Branch: 1 branch
BranchTrueFalseTotal
if defined $file 0 0 0
Condition0%0/3
$hRef->{'Name'} || $file
l!l&&r!l&&!r
000
MC/DC0%0/2
$hRef->{'Name'} || $file
$hRef->{'Name'} $file
Truth table0%0/3
A || B
A= $hRef->{'Name'}B= $file
ABresult
1X1
011
000
178 0 ▶ $hash{'Name'} = $hRef->{'Name'} || 'String' if(!defined($file));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 0 0
Condition0%0/2
$hRef->{'Name'} || 'String'
l!l
00
MC/DC0%0/1
$hRef->{'Name'} || 'String'
$hRef->{'Name'}
Truth table0%0/2
A
A= $hRef->{'Name'}
Aresult
11
00
179
180 # if we calculate all attributes...
181
182 0 ▶ if ($self->all_attributes()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->all_attributes) { } 0 0 0
183 0 my @Sentences = split(/(?:$sent_delim)/,$data);
184 0 $hash{'NumSent'} = $#Sentences + 1;
185
186 0 undef(@Sentences);
187
188 0 my @words = split(/\b/,$data);
189 0 $hash{'NumWords'} = $#words + 1;
190
191 0 undef(@words);
192 } else {
193 # otherwise... set to undef
194 0 $hash{'NumSent'} = 0;
195 0 $hash{'NumWords'} = 0;
196 }
197
198 # get our elements on the delimiter
199
200 0 my @elems = split(/(?:$delim)/,$data);
201 0 $hash{'NumElems'} = $#elems + 1;
202 0 $hash{'Elems'} = \@elems;
203
204 0 push(@{ $self->{'OpenFiles'} },\%hash);
205
206 0 return(1);
207 }
208
209
210 0 ▶sub sentences {
Subroutine sentences: not called CC=1 SCAR=6.9
Pod undocumented
211
212 0 my $self = shift;
213
214 0 my $cur_corp = $self->_cur_corpus();
215
216 0 return($self->{'OpenFiles'}[$cur_corp]->{'NumSent'});
217 }
218
219 0 ▶sub words {
Subroutine words: not called CC=1 SCAR=6.9
Pod undocumented
220
221 0 my $self = shift;
222
223 0 my $cur_corp = $self->_cur_corpus();
224
225 0 return($self->{'OpenFiles'}[$cur_corp]->{'NumWords'});
226 }
227
228 0 ▶sub elements {
Subroutine elements: not called CC=1 SCAR=6.9
Pod undocumented
229
230 0 my $self = shift;
231
232 0 my $cur_corp = $self->_cur_corpus();
233
234 0 return($self->{'OpenFiles'}[$cur_corp]->{'NumElems'});
235 }
236
237 0 ▶sub _cur_corpus {
Subroutine _cur_corpus: not called CC=2 SCAR=17.9
238
239 0 my $self = shift;
240
241 0 ▶ $self->{'CCorp'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
242 0 return($self->{'CCorp'});
243 }
244
245
246 0 ▶sub current_elem {
Subroutine current_elem: not called CC=2 SCAR=17.9
Pod undocumented
247
248 0 my $self = shift;
249
250 0 ▶ $self->{'CurElem'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
251 0 return($self->{'CurElem'});
252 }
253
254 0 ▶sub current_pos {
Subroutine current_pos: not called CC=2 SCAR=17.9
Pod undocumented
255
256 0 my $self = shift;
257
258 0 ▶ $self->{'CurPos'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
259 0 return($self->{'CurPos'});
260 }
261
262
263 0 ▶sub note_callback {
Subroutine note_callback: not called CC=2 SCAR=17.9
Pod undocumented
264 0 my $self = shift;
265
266 0 ▶ $self->{'NoteCallBack'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
267 0 return($self->{'NoteCallBack'});
268 }
269
270
271 0 ▶sub tempo_callback {
Subroutine tempo_callback: not called CC=2 SCAR=17.9
Pod undocumented
272 0 my $self = shift;
273
274 0 ▶ $self->{'TempoCallBack'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
275 0 return($self->{'TempoCallBack'});
276 }
277
278
279 0 ▶sub duration_callback {
Subroutine duration_callback: not called CC=2 SCAR=17.9
Pod undocumented
280 0 my $self = shift;
281
282 0 ▶ $self->{'DurationCallBack'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
283 0 return($self->{'DurationCallBack'});
284 }
285
286
287 0 ▶sub volume_callback {
Subroutine volume_callback: not called CC=2 SCAR=17.9
Pod undocumented
288 0 my $self = shift;
289
290 0 ▶ $self->{'VolumeCallBack'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
291 0 return($self->{'VolumeCallBack'});
292 }
293
294
295 0 ▶sub qn_len {
Subroutine qn_len: not called CC=2 SCAR=17.9
Pod undocumented
296
297 0 my $self = shift;
298
299 0 ▶ $self->{'qn_len'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
300 0 return($self->{'qn_len'});
301 }
302
303 0 ▶sub trans_obj {
Subroutine trans_obj: not called CC=2 SCAR=17.9
Pod undocumented
304
305 0 my $self = shift;
306
307 0 ▶ $self->{'TransObj'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
308 0 return($self->{'TransObj'});
309 }
310
311
312 0 ▶sub round {
Subroutine round: not called CC=2 SCAR=17.9
Pod undocumented
313
314 0 my $self = shift;
315 0 my $val = shift;
316
317 0 ▶ $val = $val < int($val) + .5 ? int($val) : int($val) + 1;
Branch: 1 branch
BranchTrueFalseTotal
$val < int($val) + 0.5 ? : 0 0 0
318
319 0 return($val);
320 }
321
322
323 0 ▶sub _get_num_by_name {
Subroutine _get_num_by_name: not called CC=4 SCAR=30.0
324
325 0 my $self = shift;
326 0 my $name = shift;
327
328 0 ▶ return(undef) if(!defined($name));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 0 0
329
330 0 my $aRef = \@{ $self->{'OpenFiles'} };
331
332 0 foreach (0..$#{ $aRef }) {
333 0 my $hRef = \%{ $aRef->[$_] };
334 0 ▶ return($_) if($hRef->{'Name'} eq $name);
Branch: 1 branch
BranchTrueFalseTotal
if $hRef->{"Name"} eq $name 0 0 0
335 }
336
337 0 return(undef);
338 }
339
340
341 0 ▶sub tempo {
Subroutine tempo: not called CC=2 SCAR=17.9
Pod undocumented
342
343 0 my $self = shift;
344
345 0 ▶ $self->{'Tempo'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
346 0 return($self->{'Tempo'});
347 }
348
349 0 ▶sub base_milliseconds {
Subroutine base_milliseconds: not called CC=2 SCAR=17.9
Pod undocumented
350
351 0 my $self = shift;
352
353 0 ▶ $self->{'BaseMilliseconds'} = $_[0] if(defined($_[0]));
Branch: 1 branch
BranchTrueFalseTotal
if defined $_[0] 0 0 0
354 0 return($self->{'BaseMilliseconds'});
355 }
356
357
358 0 ▶sub process {
Subroutine process: not called CC=10 SCAR=47.0
Pod undocumented
359
360 0 my $self = shift;
361 0 my $hRef = shift;
362
363 0 my $num = undef;
364
365
366 0 ▶ if($#{ $self->{'OpenFiles'} } < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#{$$self{"OpenFiles"};} < 0) 0 0 0
367 0 $self->error("[process] No Files/Strings Have Been Read\n");
368 0 return(undef);
369 }
370
371 0 ▶ if(exists($hRef->{'Name'}) && defined($hRef->{'Name'})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $hRef->{'Name'} and defined $hRef->{'Name'}) { } 0 0 0
elsif (exists $hRef->{'Num'} and defined $hRef->{'Num'}) { } 0 0 0
Condition0%0/3
exists $hRef->{"Name"} and defined $hRef->{"Name"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $hRef->{"Name"} and defined $hRef->{"Name"}
exists $hRef->{"Name"} defined $hRef->{"Name"}
Truth table0%0/3
A and B
A= exists $hRef->{"Name"}B= defined $hRef->{"Name"}
ABresult
0X0
100
111
372 0 my $name = $hRef->{'Name'};
373 0 $num = $self->_get_num_by_name("$name");
374 0 ▶ if(!defined($num)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $num) 0 0 0
375 0 $self->error("[process] No Data Found With Name '$name'");
376 0 return(undef);
377 }
378 ▶ } elsif(exists($hRef->{'Num'}) && defined($hRef->{'Num'})) {
Condition0%0/3
exists $hRef->{"Num"} and defined $hRef->{"Num"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $hRef->{"Num"} and defined $hRef->{"Num"}
exists $hRef->{"Num"} defined $hRef->{"Num"}
Truth table0%0/3
A and B
A= exists $hRef->{"Num"}B= defined $hRef->{"Num"}
ABresult
0X0
100
111
379 0 $num = $hRef->{'Num'};
380 0 ▶ if(!defined($self->{'OpenFiles'}[$num])) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"OpenFiles"}[$num]) 0 0 0
381 0 $self->error("[process] No Data Found In Entry #$num");
382 0 return(undef);
383 }
384 } else {
385 0 $num = 0;
386 }
387
388 0 my $aRef = \@{ $self->{'OpenFiles'}[$num]->{'Elems'} };
389
390 0 $self->_cur_corpus($num);
391
392 0 ▶ if(defined($self->tempo_callback)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->tempo_callback) 0 0 0
393 0 my $tempo_c = $self->tempo_callback();
394 0 my $tempo = &$tempo_c();
395 0 $self->tempo($tempo);
396 }
397
398 0 foreach my $elem (0..$#{ $aRef }) {
399 0 $self->current_elem($aRef->[$elem]);
400 0 $self->current_pos($elem);
401
402 0 my $note_c = $self->note_callback();
403 0 my $vol_c = $self->volume_callback();
404 0 my $dur_c = $self->duration_callback();
405
406 0 my $note = &$note_c($aRef->[$elem],$elem);
407 0 my $vol = &$vol_c($aRef->[$elem],$elem);
408 0 my $dur = &$dur_c($aRef->[$elem],$elem);
409
410 0 $self->_store_events($num,$note,$vol,$dur);
411 }
412
413 0 return(1);
414 }
415
416 0 ▶sub _store_events {
Subroutine _store_events: not called CC=6 SCAR=37.4
417
418 0 my $self = shift;
419 0 my $num = shift;
420 0 my $note = shift;
421 0 my $vol = shift;
422 0 my $dur = shift;
423
424 0 ▶ return(undef) if(!defined($num) || !defined($note) || !defined($vol) || !defined($dur));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num and defined $note and defined $vol and defined $dur 0 0 0
Condition0%0/9
defined $num and defined $note and defined $vol and defined $dur
!ll&&!rl&&r
000
defined $num and defined $note and defined $vol
!ll&&!rl&&r
000
defined $num and defined $note
!ll&&!rl&&r
000
MC/DC0%0/4
defined $num and defined $note and defined $vol and defined $dur
defined $num defined $note defined $vol defined $dur
Truth table0%0/5
A and B and C and D
A= defined $numB= defined $noteC= defined $volD= defined $dur
ABCDresult
0XXX0
10XX0
110X0
11100
11111
425
426 0 ▶ $self->{'Events'}{$num} = () if(!exists($self->{'Events'}{$num}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"Events"}{$num} 0 0 0
427
428 0 push(@{ $self->{'Events'}{$num} },[$note,$vol,$dur]);
429 0 return(1);
430 }
431
432 0 ▶sub create_score {
Subroutine create_score: not called CC=6 SCAR=37.4
Pod undocumented
433
434 0 my $self = shift;
435 0 my $num = shift;
436
437 0 ▶ $num = 0 if(!defined($num));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 0 0
438
439 0 ▶ if(!defined($self->{'Events'}{$num})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Events"}{$num}) 0 0 0
440 0 $self->error("[create_score] No Events Have Been Generated For Entry #$num");
441 0 return(undef);
442 }
443
444 0 my $aRef = \@{ $self->{'Events'}{$num} };
445
446 0 my $scoreObj = MIDI::Simple->new_score({ 'Tempo' => $self->qn_len() });
447
448 0 my $tempo_qn = $self->tempo();
449
450 0 my $bm = $self->base_milliseconds();
451
452 0 my $tempo_act = $self->round($self->base_milliseconds() / $tempo_qn);
453 0 my $channel = $self->channel();
454
455 0 $scoreObj->set_tempo($tempo_act);
456
457 0 foreach my $elem (0..$#{ $aRef }) {
458 0 my $eRef = \@{ $aRef->[$elem] };
459 0 ▶ next if($#{ $eRef } < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $#{$eRef;} < 0 0 0 0
460 0 ▶ if($eRef->[0] eq 'rest') {
Branch: 1 branch
BranchTrueFalseTotal
if ($eRef->[0] eq 'rest') { } 0 0 0
461 0 $scoreObj->r("c$channel","v$eRef->[1]","d$eRef->[2]");
462 } else {
463 0 $scoreObj->n("c$channel","v$eRef->[1]","d$eRef->[2]","n$eRef->[0]");
464 }
465 }
466
467 0 return($scoreObj);
468 }
469
470 0 ▶sub reset_error {
Subroutine reset_error: not called CC=1 SCAR=6.9
Pod undocumented
471
472 0 my $self = shift;
473 0 $self->{'ERRx1'} = undef;
474 0 return(1);
475 }
476
477 0 ▶sub write_file {
Subroutine write_file: not called CC=4 SCAR=30.0
Pod undocumented
478
479 0 my $self = shift;
480 0 my $file = shift;
481 0 my $scoreObj = shift;
482
483 0 ▶ if(!defined($file) || !defined($scoreObj)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file and defined $scoreObj) 0 0 0
Condition0%0/3
defined $file and defined $scoreObj
!ll&&!rl&&r
000
MC/DC0%0/2
defined $file and defined $scoreObj
defined $file defined $scoreObj
Truth table0%0/3
A and B
A= defined $fileB= defined $scoreObj
ABresult
0X0
100
111
484 0 $self->error("[write_file] Arguments FILE, OBJECT expected");
485 0 return(undef);
486 }
487
488 0 eval { $scoreObj->write_score($file); };
489
490 0 ▶ if($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
491 0 $self->error("[write_file] MIDI::Simple Returned: $@");
492 0 return(undef);
493 }
494
495 0 return(1);
496 }
497
498 0 ▶sub trans {
Subroutine trans: not called CC=21 SCAR=61.4
Pod undocumented
499
500 0 my $self = shift;
501 0 my $hRef = shift;
502
503 0 ▶ my $file_o = $hRef->{'Outfile'} || './out.midi';
Condition0%0/2
$hRef->{'Outfile'} || './out.midi'
l!l
00
MC/DC0%0/1
$hRef->{'Outfile'} || './out.midi'
$hRef->{'Outfile'}
Truth table0%0/2
A
A= $hRef->{'Outfile'}
Aresult
11
00
504 0 my $file = $hRef->{'File'};
505 0 ▶ my $vol_c = $hRef->{'Volume'} || $self->volume_callback();
Condition0%0/3
$hRef->{'Volume'} || $self->volume_callback
l!l&&r!l&&!r
000
MC/DC0%0/2
$hRef->{'Volume'} || $self->volume_callback
$hRef->{'Volume'} $self->volume_callback
Truth table0%0/3
A || B
A= $hRef->{'Volume'}B= $self->volume_callback
ABresult
1X1
011
000
506 0 ▶ my $note_c = $hRef->{'Note'} || $self->note_callback();
Condition0%0/3
$hRef->{'Note'} || $self->note_callback
l!l&&r!l&&!r
000
MC/DC0%0/2
$hRef->{'Note'} || $self->note_callback
$hRef->{'Note'} $self->note_callback
Truth table0%0/3
A || B
A= $hRef->{'Note'}B= $self->note_callback
ABresult
1X1
011
000
507 0 ▶ my $dur_c = $hRef->{'Duration'} || $self->duration_callback();
Condition0%0/3
$hRef->{'Duration'} || $self->duration_callback
l!l&&r!l&&!r
000
MC/DC0%0/2
$hRef->{'Duration'} || $self->duration_callback
$hRef->{'Duration'} $self->duration_callback
Truth table0%0/3
A || B
A= $hRef->{'Duration'}B= $self->duration_callback
ABresult
1X1
011
000
508 0 ▶ my $tempo_c = $hRef->{'TempoCallBack'} || $self->tempo_callback();
Condition0%0/3
$hRef->{'TempoCallBack'} || $self->tempo_callback
l!l&&r!l&&!r
000
MC/DC0%0/2
$hRef->{'TempoCallBack'} || $self->tempo_callback
$hRef->{'TempoCallBack'} $self->tempo_callback
Truth table0%0/3
A || B
A= $hRef->{'TempoCallBack'}B= $self->tempo_callback
ABresult
1X1
011
000
509 0 ▶ my $delim = $hRef->{'Delimiter'} || $self->delimiter();
Condition0%0/3
$hRef->{'Delimiter'} || $self->delimiter
l!l&&r!l&&!r
000
MC/DC0%0/2
$hRef->{'Delimiter'} || $self->delimiter
$hRef->{'Delimiter'} $self->delimiter
Truth table0%0/3
A || B
A= $hRef->{'Delimiter'}B= $self->delimiter
ABresult
1X1
011
000
510 0 ▶ my $tempo = $hRef->{'Tempo'} || $self->tempo();
Condition0%0/3
$hRef->{'Tempo'} || $self->tempo
l!l&&r!l&&!r
000
MC/DC0%0/2
$hRef->{'Tempo'} || $self->tempo
$hRef->{'Tempo'} $self->tempo
Truth table0%0/3
A || B
A= $hRef->{'Tempo'}B= $self->tempo
ABresult
1X1
011
000
511
512 0 ▶ if(!defined($file)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $file) 0 0 0
513 0 $self->error("[trans] FILE Argument not specified");
514 0 return(undef);
515 }
516
517 0 ▶ if(!defined($dur_c) || !defined($note_c) || !defined($vol_c)) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $dur_c && defined $note_c && defined $vol_c) { } 0 0 0
elsif (not defined $tempo_c || defined $tempo) { } 0 0 0
Condition0%0/6
defined $dur_c && defined $note_c && defined $vol_c
!ll&&!rl&&r
000
defined $dur_c and defined $note_c
!ll&&!rl&&r
000
MC/DC0%0/3
defined $dur_c && defined $note_c && defined $vol_c
defined $dur_c defined $note_c defined $vol_c
Truth table0%0/4
A and B && C
A= defined $dur_cB= defined $note_cC= defined $vol_c
ABCresult
0XX0
10X0
1100
1111
518 0 $self->error("[trans] DURATION, NOTE, and VOLUME callbacks must be specified");
519 0 return(undef);
520 ▶ } elsif(!defined($tempo_c) && !defined($tempo)) {
Condition0%0/3
defined $tempo_c || defined $tempo
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $tempo_c || defined $tempo
defined $tempo_c defined $tempo
Truth table0%0/3
A || B
A= defined $tempo_cB= defined $tempo
ABresult
1X1
011
000
521 0 $self->error("[trans] Either TEMPO or TEMPOCALLBACK must be specified");
522 0 return(undef);
523 }
524
525 0 my $new_object = MIDI::Trans->new( {
526 'VolumeCallBack' => $vol_c,
527 'DurationCallBack' => $dur_c,
528 'NoteCallBack' => $note_c,
529 'TempoCallBack' => $tempo_c,
530 'Tempo' => $tempo,
531 'Delimiter' => $delim });
532
533 0 ▶ if(!defined($new_object)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $new_object) 0 0 0
534 0 $self->error("[trans] Error Creating Object");
535 0 return(undef);
536 }
537
538 0 $self->trans_obj($new_object);
539
540 0 ▶ $self->tempo_callback($tempo_c) if(!defined($tempo));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tempo 0 0 0
541 0 ▶ $self->tempo($tempo) if(defined($tempo));
Branch: 1 branch
BranchTrueFalseTotal
if defined $tempo 0 0 0
542
543 0 ▶ if($new_object->read_corpus({ 'File' => "$file" })) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_object->read_corpus({'File', "$file"})) { } 0 0 0
544 0 ▶ if($new_object->process({ 'Name' => "$file" })) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_object->process({'Name', "$file"})) { } 0 0 0
545 0 my $scoreObj = $new_object->create_score(0);
546 0 ▶ if(defined($scoreObj)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $scoreObj) { } 0 0 0
547 0 ▶ if($new_object->write_file($file_o,$scoreObj)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_object->write_file($file_o, $scoreObj)) { } 0 0 0
548 0 return(1);
549 } else {
550 0 $self->error($new_object->error());
551 0 return(undef);
552 }
553 } else {
554 0 $self->error($new_object->error());
555 0 return(undef);
556 }
557 } else {
558 0 $self->error($new_object->error());
559 0 return(undef);
560 }
561 } else {
562 0 $self->error($new_object->error());
563 0 return(undef);
564 }
565
566 0 return(undef);
567 }
568
569
570 1 1;
571 __END__
↑ Summary