lib/ChordPro/Output/MMA.pm

filter: Statementstmt 47.6% 141 / 296 Branchbran 37.6% 73 / 194 Conditioncond 46.2% 37 / 80 MC/DCmcdc 30.2% 13 / 43 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 7 totaltotal 43.3% 273 / 630 CC 132 SCAR 61.7
CC
132
Cov
44%
generate_song
849.2
songline
182.0
makegroove
129.1
CRAP 476.0
« lib/ChordPro/Output/PDF.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Image.pm »
1 #! perl
2  
3 package main;
4  
5 1 our $options;
6 1 our $config;
7  
8 package ChordPro::Output::MMA;
9  
10 1 ▶use ChordPro::Output::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 7 ▶sub generate_songbook {
Subroutine generate_songbook: called CC=5 SCAR=17.6
Pod undocumented
16 7 my ( $self, $sb ) = @_;
17 7 my @book;
18  
19 die("MMA generation requires a single song\n")
20 7 ▶ if @{$sb->{songs}} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$sb->{"songs"};} > 1 0 7 7
21  
22 7 foreach my $song ( @{$sb->{songs}} ) {
23 7 ▶ if ( @book ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@book) 0 7 7
24 0 ▶ push(@book, "") if $options->{'backend-option'}->{tidy};
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"backend-option"}{"tidy"} 0 0 0
25 0 push(@book, "-- New song");
26 }
27 7 push(@book, @{generate_song($song)});
28 }
29  
30 7 push( @book, "");
31 7 \@book;
32 }
33  
34 1 my $groove; # groove to use
35 1 my $single_space = 0; # suppress chords line when empty
36 1 my $chords_under = 0; # chords under lyrics
37  
38 14 ▶sub safemeta {
Subroutine safemeta: called CC=3 SCAR=12.5
Pod undocumented
39 14 my ( $s, $meta, $default ) = @_;
40 14 ▶ return $default unless defined $meta && defined $s->{meta}->{$meta};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $meta and defined $s->{"meta"}{$meta} 0 14 14
Condition33%1/3
defined $meta and defined $s->{"meta"}{$meta}
!ll&&!rl&&r
0014
MC/DC0%0/2
defined $meta and defined $s->{"meta"}{$meta}
defined $meta defined $s->{"meta"}{$meta}
Truth table33%1/3
A and B
A= defined $metaB= defined $s->{"meta"}{$meta}
ABresult
0X0
100
111
41 14 return $s->{meta}->{$meta}->[0];
42 }
43  
44 7 ▶sub generate_song {
Subroutine generate_song: called CC=73 SCAR=67.4
Pod undocumented
45 7 my ( $s ) = @_;
46  
47 7 my $st = 0; # current MMA statement number
48 7 my $cur = ''; # MMA statement under construction
49 7 my $prev = ''; # previous MMA statement
50 7 my $did = 0; # preamble was emitted
51 7 my $pchord = '.'; # last real chord
52  
53 7 $groove = $options->{'backend-option'}->{groove};
54 7 my $tidy = $options->{'backend-option'}->{tidy};
55  
56 # Normally a counting beat is 1 quarter. deCoda uses 1/8th.
57 7 ▶ my $decoda = $options->{'backend-option'}->{decoda} || $options->{'backend-option'}->{deCoda};
Condition66%2/3
$main::options->{'backend-option'}{'decoda'} || $main::options->{'backend-option'}{'deCoda'}
l!l&&r!l&&!r
403
MC/DC50%1/2
$main::options->{'backend-option'}{'decoda'} || $main::options->{'backend-option'}{'deCoda'}
$main::options->{'backend-option'}{'decoda'} $main::options->{'backend-option'}{'deCoda'}
Truth table66%2/3
A || B
A= $main::options->{'backend-option'}{'decoda'}B= $main::options->{'backend-option'}{'deCoda'}
ABresult
1X1
011
000
58  
59 7 $single_space = $options->{'single-space'};
60 7 $chords_under = $config->{settings}->{'chords-under'};
61  
62 $s->structurize
63 7 ▶ if ( $options->{'backend-option'}->{structure} // '' ) eq 'structured';
Branch: 1 branch
BranchTrueFalseTotal
if ($main::options->{"backend-option"}{"structure"} // "") eq "structured" 0 7 7
Condition50%1/2
$main::options->{"backend-option"}{"structure"} // ""
l!l
07
MC/DC0%0/1
$main::options->{"backend-option"}{"structure"} // ""
$main::options->{"backend-option"}{"structure"}
Truth table50%1/2
A
A= $main::options->{"backend-option"}{"structure"}
Aresult
11
00
64  
65 7 my @s;
66  
67 # Preamble.
68 7 ▶ push( @s, "// title: " . $s->{title}, "" ) if defined $s->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $s->{"title"} 7 0 7
69  
70 # Select a groove.
71 7 my $bpm = 4;
72 7 my $q = 4;
73 7 ▶ ( $bpm, $q ) = ( $1, $2 ) if safemeta( $s, "time", "4/4" ) =~ /^(\d+)\/(\d+)/;
Branch: 1 branch
BranchTrueFalseTotal
if safemeta($s, "time", "4/4") =~ m[^(\d+)/(\d+)] 7 0 7
74 7 ▶ unless ( $groove ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($groove) 0 7 7
75 0 ▶ if ( $bpm == 3 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bpm == 3) { } 0 0 0
elsif ($bpm == 6) { } 0 0 0
76 0 ▶ $q = 4 unless $q == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $q == 8 0 0 0
77 0 $groove = "Neutral$bpm$q";
78 }
79 elsif ( $bpm == 6 ) {
80 0 ▶ warn("Time 6/$q set to 6/8\n") unless $q == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $q == 8 0 0 0
81 0 $q = 8;
82 0 $groove = "Neutral$bpm$q";
83 }
84 else {
85 0 warn("Time $bpm/$q set to 4/4\n");
86 0 $q = $bpm = 4;
87 0 $groove = "Neutral44";
88 }
89 }
90  
91 7 push( @s, sprintf( "Time %d/%d", $bpm, $q ) );
92 7 push( @s, makegroove( $bpm, $q ) );
93  
94 # When deCoda decodes a song in 6/8 at 100bpm, it gets interpreted as 2/4.
95 # When the time signature is manually fixed to 6/8, the song becomes
96 # twice as long. So we must double the tempo.
97 7 ▶ push( @s, sprintf( "Tempo %d",
Branch: 1 branch
BranchTrueFalseTotal
$q == 8 && $decoda ? : 1 6 7
Condition100%3/3
$q == 8 and $decoda
!ll&&!rl&&r
511
MC/DC100%2/2
$q == 8 and $decoda
$q == 8 $decoda
Truth table100%3/3
A and B
A= $q == 8B= $decoda
ABresult
0X0
100
111
98 safemeta( $s, "tempo", 60 ) * (( $q == 8 && $decoda ) ? 2 : 1 )
99 ) );
100  
101 7 push( @s, "", "/**** End of Preamble ****/", "" );
102  
103 7 my $ctx = "";
104 7 my $line;
105  
106 7 foreach my $elt ( @{$s->{body}} ) {
107 77 my $line = sprintf( "%3d", $elt->{line} );
108  
109 77 ▶ if ( $elt->{context} ne $ctx ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"context"} ne $ctx) 14 63 77
110 14 ▶ push(@s, "// $line End of $ctx") if $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx 7 7 14
111 14 ▶ push(@s, "// $line Start of $ctx") if $ctx = $elt->{context};
Branch: 1 branch
BranchTrueFalseTotal
if $ctx = $elt->{"context"} 7 7 14
112 }
113  
114 77 ▶ if ( $elt->{type} eq "empty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "empty") 14 63 77
115 push(@s, "***SHOULD NOT HAPPEN***")
116 14 ▶ if $s->{structure} eq 'structured';
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"structure"} eq "structured" 0 14 14
117 14 push(@s, "");
118 14 next;
119 }
120  
121 63 ▶ if ( $elt->{type} eq "colb" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "colb") 0 63 63
122 0 push(@s, "// $line Column break");
123 0 next;
124 }
125  
126 63 ▶ if ( $elt->{type} eq "newpage" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "newpage") 0 63 63
127 0 push(@s, "// $line New page");
128 0 next;
129 }
130  
131 63 ▶ if ( $elt->{type} eq "gridline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "gridline") 21 42 63
132 21 my @a = @{ $elt->{tokens} };
133 # Reduce the elements (objects) to simple chords or symbols.
134 21 @a = map { $_->{class} eq 'chord'
135 ? $_->{chord}->key
136 405 ▶ : $_->{symbol} } @a;
Branch: 1 branch
BranchTrueFalseTotal
$_->{'class'} eq 'chord' ? : 59 346 405
137  
138 21 push( @s, "// $line @a" );
139  
140 # Remove label and initial bar symbol.
141 21 my $firstbar;
142 21 ▶ do { } until is_bar( $firstbar = shift(@a) );
Branch: 1 branch
BranchTrueFalseTotal
is_bar($firstbar = shift @a) or do { do { () } } 21 0 21
143  
144 21 ▶ if ( $decoda && $q == 4 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($decoda and $q == 4) 9 12 21
Condition100%3/3
$decoda and $q == 4
!ll&&!rl&&r
939
MC/DC100%2/2
$decoda and $q == 4
$decoda $q == 4
Truth table100%3/3
A and B
A= $decodaB= $q == 4
ABresult
0X0
100
111
145 # deCoda always uses a beat step of 8. For x/4 times we must reduce.
146 9 @a = reduce( \@a, $bpm, $line, \@s);
147 9 push( @s, "// $line $firstbar " .
148 join(" ", @a) );
149 }
150  
151 # Bars must be full.
152 21 ▶ if ( @a % ( $bpm + 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a % ($bpm + 1)) 0 21 21
153 0 push( @s, "// $line $bpm $q ".scalar(@a)." OOPS?" );
154 0 next;
155 }
156  
157 21 my $rept = 0;
158 21 my $bar = 0;
159  
160 # Process the elements.
161 21 ▶ while ( @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 56 21 77
162 # Increment bar number and mma statement number.
163 56 $bar++;
164 56 $st++;
165 56 my $c = ''; # mma statement being constructed
166  
167 # Reuse last chord if we have none.
168 56 ▶ if ( $a[0] eq '.' && $a[1] eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[0] eq "." and $a[1] eq ".") 7 49 56
Condition66%2/3
$a[0] eq "." and $a[1] eq "."
!ll&&!rl&&r
4907
MC/DC50%1/2
$a[0] eq "." and $a[1] eq "."
$a[0] eq "." $a[1] eq "."
Truth table66%2/3
A and B
A= $a[0] eq "."B= $a[1] eq "."
ABresult
0X0
100
111
169 7 $a[0] = $pchord;
170 }
171  
172 # Process the beats.
173 56 ▶ for ( my $b = 1; $b <= $bpm; $b++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b <= $bpm) 240 56 296
174  
175 # Get a chord.
176 240 $cur = shift(@a);
177  
178 # Append to statement.
179 240 ▶ $c .= $cur eq '.' ? "/ " : "$cur ";
Branch: 1 branch
BranchTrueFalseTotal
$cur eq '.' ? : 174 66 240
180 240 ▶ $pchord = $cur unless $cur eq '.';
Branch: 1 branch
BranchTrueFalseTotal
unless $cur eq "." 66 174 240
181 }
182  
183 # Remove trailing slashes.
184 56 $c =~ s;[\s/]+$;;;
185 56 ▶ $c = $prev unless $c =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $c =~ /\S/ 0 56 56
186  
187 # Print MMA statement.
188 56 ▶ if ( $prev eq $c || $st == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prev eq $c or $st == 1) { } 14 42 56
Condition100%3/3
$prev eq $c or $st == 1
l!l&&r!l&&!r
7742
MC/DC100%2/2
$prev eq $c or $st == 1
$prev eq $c $st == 1
Truth table100%3/3
A or B
A= $prev eq $cB= $st == 1
ABresult
1X1
011
000
189 14 $rept++;
190 }
191 else {
192 42 ▶ push( @s,
Branch: 2 branches
BranchTrueFalseTotal
if $rept 35 7 42
$rept > 1 ? : 0 35 35
193 sprintf( "%3d %s%s", $st-$rept, $prev,
194 $rept > 1 ? " * $rept" : "" )
195 ) if $rept;
196 42 $rept = 1;
197 }
198 56 $prev = $c;
199  
200 # Check for trailing barline.
201 56 ▶ unless ( is_bar(shift(@a)) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_bar(shift @a)) 0 56 56
202 0 push( @s, "// bar $bar: Missing final barline?" );
203 0 warn("line $., bar $bar: Missing final barline?\n");
204 }
205 }
206 21 ▶ push( @s,
Branch: 1 branch
BranchTrueFalseTotal
$rept > 1 ? : 0 21 21
207 sprintf( "%3d %s%s", $st-$rept+1, $prev,
208 $rept > 1 ? " * $rept" : "" ) );
209 21 $rept = 0;
210  
211 21 next;
212 }
213  
214 42 ▶ if ( $elt->{type} =~ /^comment(?:_italic|_box)?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} =~ /^comment(?:_italic|_box)?$/) 7 35 42
215 7 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 7 7
216 7 my $text = $elt->{text};
217 7 ▶ if ( $elt->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"chords"}) 0 7 7
218 0 $text = "";
219 0 for ( 0..$#{ $elt->{chords} } ) {
220 $text .= "[" . $elt->{chords}->[$_] . "]"
221 0 ▶ if $elt->{chords}->[$_] ne "";
Branch: 1 branch
BranchTrueFalseTotal
if $elt->{"chords"}[$_] ne "" 0 0 0
222 0 $text .= $elt->{phrases}->[$_];
223 }
224 }
225 7 $text = fmt_subst( $s, $text );
226 7 push(@s, "// $line comment: $text");
227 7 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 7 7
228 7 next;
229 }
230  
231 35 next;
232  
233 0 ▶ if ( $elt->{type} eq "songline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "songline") 0 0 0
234 0 push(@s, songline($elt));
235 0 next;
236 }
237  
238 0 ▶ if ( $elt->{type} eq "tabline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "tabline") 0 0 0
239 0 push(@s, $elt->{text});
240 0 next;
241 }
242  
243 0 ▶ if ( $elt->{type} eq "chorus" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "chorus") 0 0 0
244 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
245 0 push(@s, "// $line Start of chorus*");
246 0 foreach my $e ( @{$elt->{body}} ) {
247 0 ▶ if ( $e->{type} eq "empty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "empty") 0 0 0
248 0 push(@s, "");
249 0 next;
250 }
251 0 ▶ if ( $e->{type} eq "songline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "songline") 0 0 0
252 0 push(@s, songline($e));
253 0 next;
254 }
255 }
256 0 push(@s, "// $line End of chorus*");
257 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
258 0 next;
259 }
260  
261 0 ▶ if ( $elt->{type} eq "tab" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "tab") 0 0 0
262 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
263 0 push(@s, "// $line Start of tab");
264 0 push(@s, map { "// " . $_->{text} } @{$elt->{body}} );
265 0 push(@s, "// $line End of tab");
266 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
267 0 next;
268 }
269  
270 0 ▶ if ( $elt->{type} eq "verse" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "verse") 0 0 0
271 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
272 0 push(@s, "// $line Start of verse");
273 0 foreach my $e ( @{$elt->{body}} ) {
274 0 ▶ if ( $e->{type} eq "empty" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "empty") 0 0 0
275 push(@s, "***SHOULD NOT HAPPEN***")
276 0 ▶ if $s->{structure} eq 'structured';
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"structure"} eq "structured" 0 0 0
277 0 next;
278 }
279 0 ▶ if ( $e->{type} eq "songline" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "songline") 0 0 0
280 0 push(@s, songline($e));
281 0 next;
282 }
283 0 ▶ if ( $e->{type} eq "comment" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "comment") 0 0 0
284 0 push(@s, "-c- " . $e->{text});
285 0 next;
286 }
287 0 ▶ if ( $e->{type} eq "comment_italic" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e->{"type"} eq "comment_italic") 0 0 0
288 0 push(@s, "-i- " . $e->{text});
289 0 next;
290 }
291 }
292 0 push(@s, "// $line End of verse");
293 0 ▶ push(@s, "") if $tidy;
Branch: 1 branch
BranchTrueFalseTotal
if $tidy 0 0 0
294 0 next;
295 }
296  
297 0 ▶ if ( $elt->{type} eq "image" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "image") 0 0 0
298 0 my @args = ( "image:", $elt->{uri} );
299 0 ▶ while ( my($k,$v) = each( %{ $elt->{opts} } ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$elt{"opts"};}) 0 0 0
300 0 push( @args, "$k=$v" );
301 }
302 0 foreach ( @args ) {
303 0 ▶ next unless /\s/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\s/ 0 0 0
304 0 $_ = '"' . $_ . '"';
305 }
306 0 push( @s, "// $line @args" );
307 0 next;
308 }
309  
310 0 ▶ if ( $elt->{type} eq "set" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "set") 0 0 0
311 0 next;
312 }
313  
314 0 ▶ if ( $elt->{type} eq "control" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elt->{"type"} eq "control") 0 0 0
315 0 next;
316 }
317  
318 # Ignore everyting else.
319  
320 }
321 7 ▶ push(@s, "// $line End of $ctx") if $ctx;
Branch: 1 branch
BranchTrueFalseTotal
if $ctx 0 7 7
322  
323 7 \@s;
324 }
325  
326 0 ▶sub songline {
Subroutine songline: not called CC=13 SCAR=52.0
Pod undocumented
327 0 my ($elt) = @_;
328  
329 0 my $t_line = "";
330  
331 0 ▶ if ( $single_space && ! ( $elt->{chords} && join( "", @{ $elt->{chords} } ) =~ /\S/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($single_space and not $elt->{"chords"} && join("", @{$elt->{"chords"};}) =~ /\S/) 0 0 0
Condition0%0/6
$single_space and not $elt->{"chords"} && join("", @{$elt->{"chords"};}) =~ /\S/
!ll&&!rl&&r
000
$elt->{'chords'} && join('', @{$elt->{'chords'};}) =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/3
$single_space and not $elt->{"chords"} && join("", @{$elt->{"chords"};}) =~ /\S/
$single_space $elt->{'chords'} join('', @{$elt->{'chords'};}) =~ /\S/
Truth table0%0/4
A and not(B && C)
A= $single_spaceB= $elt->{'chords'}C= join('', @{$elt->{'chords'};}) =~ /\S/
ABCresult
0XX0
1110
10X1
1101
332 ) {
333 0 $t_line = join( "", @{ $elt->{phrases} } );
334 0 $t_line =~ s/\s+$//;
335 0 return $t_line;
336 }
337  
338 0 ▶ unless ( $elt->{chords} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($elt->{"chords"}) 0 0 0
339 0 return ( "", join( " ", @{ $elt->{phrases} } ) );
340 }
341  
342 0 ▶ if ( my $f = $::config->{settings}->{'inline-chords'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $f = $main::config->{"settings"}{"inline-chords"}) 0 0 0
343 0 ▶ $f = '[%s]' unless $f =~ /^[^%]*\%s[^%]*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $f =~ /^[^%]*\%s[^%]*$/ 0 0 0
344 0 $f .= '%s';
345 0 foreach ( 0..$#{$elt->{chords}} ) {
346 $t_line .= sprintf( $f,
347 $elt->{chords}->[$_]->key,
348 0 $elt->{phrases}->[$_] );
349 }
350 0 return ( $t_line );
351 }
352  
353 0 my $c_line = "";
354 0 foreach ( 0..$#{$elt->{chords}} ) {
355 0 $c_line .= $elt->{chords}->[$_]->key . " ";
356 0 $t_line .= $elt->{phrases}->[$_];
357 0 my $d = length($c_line) - length($t_line);
358 0 ▶ $t_line .= "-" x $d if $d > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $d > 0 0 0 0
359 0 ▶ $c_line .= " " x -$d if $d < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $d < 0 0 0 0
360 }
361 0 s/\s+$// for ( $t_line, $c_line );
362 0 ▶ return $chords_under
Branch: 1 branch
BranchTrueFalseTotal
$chords_under ? : 0 0 0
363 ? ( $t_line, $c_line )
364 : ( $c_line, $t_line )
365 }
366  
367 102 ▶sub is_bar {
Subroutine is_bar: called CC=11 SCAR=30.9
Pod undocumented
368 102 for ( $_[0] ) {
369 102 ▶ return 1
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}" or $_ eq ":|:" or $_ eq "}{" or $_ eq "|" or $_ eq "||" or $_ eq "|." 101 1 102
Condition45%11/24
$_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}" or $_ eq ":|:" or $_ eq "}{" or $_ eq "|" or $_ eq "||" or $_ eq "|."
l!l&&r!l&&!r
10101
$_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}" or $_ eq ":|:" or $_ eq "}{" or $_ eq "|" or $_ eq "||"
l!l&&r!l&&!r
10101
$_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}" or $_ eq ":|:" or $_ eq "}{" or $_ eq "|"
l!l&&r!l&&!r
01011
$_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}" or $_ eq ":|:" or $_ eq "}{"
l!l&&r!l&&!r
00102
$_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}" or $_ eq ":|:"
l!l&&r!l&&!r
00102
$_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}"
l!l&&r!l&&!r
00102
$_ eq "|:" or $_ eq "{" or $_ eq ":|"
l!l&&r!l&&!r
00102
$_ eq "|:" or $_ eq "{"
l!l&&r!l&&!r
00102
MC/DC11%1/9
$_ eq "|:" or $_ eq "{" or $_ eq ":|" or $_ eq "}" or $_ eq ":|:" or $_ eq "}{" or $_ eq "|" or $_ eq "||" or $_ eq "|."
$_ eq "|:" $_ eq "{" $_ eq ":|" $_ eq "}" $_ eq ":|:" $_ eq "}{" $_ eq "|" $_ eq "||" $_ eq "|."
Truth table20%2/10
A or B or C or D or E or F or G or H or I
A= $_ eq "|:"B= $_ eq "{"C= $_ eq ":|"D= $_ eq "}"E= $_ eq ":|:"F= $_ eq "}{"G= $_ eq "|"H= $_ eq "||"I= $_ eq "|."
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
370 if $_ eq "|:" || $_ eq "{"
371 || $_ eq ":|" || $_ eq "}"
372 || $_ eq ":|:" || $_ eq "}{"
373 || $_ eq "|" || $_ eq "||" || $_ eq "|.";
374 }
375 1 return;
376 }
377  
378 9 ▶sub reduce {
Subroutine reduce: called CC=21 SCAR=37.8
Pod undocumented
379 9 my ( $a, $bpm, $line, $s ) = @_;
380 9 my @a = @$a;
381 9 ▶ warn("R: ", join(' ',@a), "\n") if $config->{debug}->{mma};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"debug"}{"mma"} 0 9 9
382 9 my @reduced;
383 9 my $bar = 0;
384 9 my $carry;
385  
386 9 ▶ while ( @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 24 9 33
387 24 $bar++;
388 24 ▶ if ( $carry ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($carry) 0 24 24
389 0 ▶ if ( $a[0] eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a[0] eq '.') { } 0 0 0
390 0 $a[0] = $carry;
391 }
392 else {
393 0 push( @$s,
394 sprintf( "// line %d, bar %d, cannot resolve %s (from previous line)",
395 $line, $bar, $carry ) );
396 }
397 0 $carry = '';
398 }
399 24 ▶ for ( my $b = 1; $b <= $bpm; $b++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b <= $bpm) 88 24 112
400 88 my $a0 = shift(@a);
401 88 my $a1 = shift(@a);
402 # Check for clash.
403 88 ▶ if ( $a0 ne '.' && $a1 ne '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a0 ne "." and $a1 ne ".") 1 87 88
Condition100%3/3
$a0 ne "." and $a1 ne "."
!ll&&!rl&&r
62251
MC/DC100%2/2
$a0 ne "." and $a1 ne "."
$a0 ne "." $a1 ne "."
Truth table100%3/3
A and B
A= $a0 ne "."B= $a1 ne "."
ABresult
0X0
100
111
404 1 ▶ if ( @a > 1 && $a[0] eq '.' && $a[1] eq '.' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a > 1 and $a[0] eq '.' and $a[1] eq '.') { } 1 0 1
Condition33%2/6
@a > 1 and $a[0] eq "." and $a[1] eq "."
!ll&&!rl&&r
001
@a > 1 and $a[0] eq "."
!ll&&!rl&&r
001
MC/DC0%0/3
@a > 1 and $a[0] eq "." and $a[1] eq "."
@a > 1 $a[0] eq "." $a[1] eq "."
Truth table25%1/4
A and B and C
A= @a > 1B= $a[0] eq "."C= $a[1] eq "."
ABCresult
0XX0
10X0
1100
1111
405 # X Y . . => X . Y .
406 1 $a[0] = $a1;
407 1 push( @$s,
408 sprintf("// line %d, bar %d, beat %d: shifting %s to beat %d",
409 $line, $bar, $b, $a[0], $b+1) );
410 }
411 else {
412 # Cannot resolve.
413 0 push( @$s,
414 sprintf( "// line %d, bar %d, beat %d: too many chords",
415 $line, $bar, $b ) );
416 }
417 }
418
419 # Check for clash and try to resolve.
420 # . X => X .
421 88 ▶ if ( $a0 eq '.' && $a1 ne '.' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($a0 eq '.' and $a1 ne '.') { } 1 87 88
elsif ($a1 ne '.') { } 1 86 87
Condition100%3/3
$a0 eq "." and $a1 ne "."
!ll&&!rl&&r
26611
MC/DC100%2/2
$a0 eq "." and $a1 ne "."
$a0 eq "." $a1 ne "."
Truth table100%3/3
A and B
A= $a0 eq "."B= $a1 ne "."
ABresult
0X0
100
111
422 1 $a0 = $a1;
423 1 push( @$s,
424 sprintf( "// line %d, bar %d, beat %d: move back %s",
425 $line, $bar, $b, $a1) );
426 }
427 # x X . => x . X
428 elsif ( $a1 ne '.' ) {
429 1 ▶ if ( @a > 1 && is_bar($a[0]) && $a[1] eq '.' ) {
Branch: 3 branches
BranchTrueFalseTotal
if (@a > 1 and is_bar($a[0]) and $a[1] eq '.') { } 0 1 1
elsif (@a > 0 and $a[0] eq '.') { } 0 1 1
elsif (not @a) { } 0 1 1
Condition33%2/6
@a > 1 and is_bar($a[0]) and $a[1] eq "."
!ll&&!rl&&r
100
@a > 1 and is_bar($a[0])
!ll&&!rl&&r
010
MC/DC0%0/3
@a > 1 and is_bar($a[0]) and $a[1] eq "."
@a > 1 is_bar($a[0]) $a[1] eq "."
Truth table25%1/4
A and B and C
A= @a > 1B= is_bar($a[0])C= $a[1] eq "."
ABCresult
0XX0
10X0
1100
1111
430 0 $a[1] = $a1;
431 0 push( @$s,
432 sprintf( "// line %d, bar %d, beat %d: advancing %s",
433 $line, $bar, $b, $a1) );
434 }
435 ▶ elsif ( @a > 0 && $a[0] eq '.' ) {
Condition33%1/3
@a > 0 and $a[0] eq "."
!ll&&!rl&&r
010
MC/DC0%0/2
@a > 0 and $a[0] eq "."
@a > 0 $a[0] eq "."
Truth table33%1/3
A and B
A= @a > 0B= $a[0] eq "."
ABresult
0X0
100
111
436 0 $a[0] = $a1;
437 0 push( @$s,
438 sprintf( "// line %d, bar %d, beat %d: advancing %s",
439 $line, $bar, $b, $a1) );
440 }
441 elsif ( !@a ) {
442 0 $carry = $a1;
443 0 push( @$s,
444 sprintf( "// line %d, bar %d, beat %d: carry %s to next line",
445 $line, $bar, $b, $a1) );
446 }
447 }
448 88 push( @reduced, $a0 );
449 }
450 24 ▶ if ( is_bar($a[0]) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_bar($a[0])) { } 24 0 24
451 24 push( @reduced, shift(@a) );
452 }
453 else {
454 0 push( @$s,
455 sprintf( "// line %d, bar %d, missing bar line?", $line, $bar ) )
456 }
457 }
458 9 return @reduced;
459 }
460  
461 7 ▶sub makegroove {
Subroutine makegroove: called CC=12 SCAR=48.6
Pod undocumented
462 7 my ( $bpm, $q ) = @_;
463  
464 7 ▶ return ( "Groove $groove" ) if $groove;
Branch: 1 branch
BranchTrueFalseTotal
if $groove 7 0 7
465  
466 0 my @s;
467 0 ▶ if ( $bpm == 3 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($bpm == 3) { } 0 0 0
elsif ($bpm == 6) { } 0 0 0
468 0 ▶ $q = 4 unless $q == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $q == 8 0 0 0
469 0 $groove = "Neutral$bpm$q";
470 }
471 elsif ( $bpm == 6 ) {
472 0 ▶ $q = 4 unless $q == 8;
Branch: 1 branch
BranchTrueFalseTotal
unless $q == 8 0 0 0
473 0 $groove = "Neutral$bpm$q";
474 }
475 else {
476 0 $groove = "Neutral44";
477 }
478  
479 0 my $seq;
480 my $whole;
481  
482 0 ▶ if ( $bpm == 3 && $q == 4 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($bpm == 3 and $q == 4) { } 0 0 0
elsif ($bpm == 3 and $q == 8) { } 0 0 0
elsif ($bpm == 6 and $q == 8) { } 0 0 0
Condition0%0/3
$bpm == 3 and $q == 4
!ll&&!rl&&r
000
MC/DC0%0/2
$bpm == 3 and $q == 4
$bpm == 3 $q == 4
Truth table0%0/3
A and B
A= $bpm == 3B= $q == 4
ABresult
0X0
100
111
483 0 $whole = "2.";
484 0 $seq = "{ 1 0 90; 2 0 30; 3 0 30 }";
485 }
486 ▶ elsif ( $bpm == 3 && $q == 8 ) {
Condition0%0/3
$bpm == 3 and $q == 8
!ll&&!rl&&r
000
MC/DC0%0/2
$bpm == 3 and $q == 8
$bpm == 3 $q == 8
Truth table0%0/3
A and B
A= $bpm == 3B= $q == 8
ABresult
0X0
100
111
487 0 $whole = "4.";
488 0 $seq = "{ 1 0 90; 1.67 0 30; 2.33 0 30 }";
489 }
490 ▶ elsif ( $bpm == 6 && $q == 8 ) {
Condition0%0/3
$bpm == 6 and $q == 8
!ll&&!rl&&r
000
MC/DC0%0/2
$bpm == 6 and $q == 8
$bpm == 6 $q == 8
Truth table0%0/3
A and B
A= $bpm == 6B= $q == 8
ABresult
0X0
100
111
491 0 $whole = "1.";
492 0 $seq = "{ 1 0 90; 2 0 30; 3 0 30; 4 0 80; 5 0 30; 6 0 30 }";
493 }
494 else { # assume 4/4
495 0 $whole = "1";
496 0 $seq = "{ 1 0 90; 2 0 30; 3 0 50; 4 0 30 }";
497 }
498  
499 0 return split( /\n/, <<EOD );
500 SeqClear
501 SeqSize 1
502 Time $bpm/$q
503  
504 Begin Drum-Side
505 Tone KickDrum1
506 Sequence { 1.0 0 60 }
507 Volume 30
508 End
509  
510 Begin Drum-CHH
511 Tone ClosedHiHat
512 Sequence $seq
513 Volume 30
514 End
515  
516 Begin Chord
517 Channel 2
518 Voice ReedOrgan
519 Sequence { 1 $whole 50 }
520 Volume 30
521 Articulate 100
522 End
523  
524 DefGroove $groove
525  
526 Groove $groove
527  
528 EOD
529  
530 }
531  
532 1 1;
533  
534 1 ▶unless ( caller) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 1 1
535 0 my $bpm = 4;
536 0 my @s = ();
537 0 ▶ unless ( join( ' ',
Branch: 1 branch
BranchTrueFalseTotal
unless (join(" ", reduce([split(' ', "C . . . . . . . | C . . . . . . . | C . . . . . . . | C . . . . . . . |", 0)], $bpm, 1, \@s)) eq "C . . . | C . . . | C . . . | C . . . |") 0 0 0
538 reduce( [split(' ','C . . . . . . . | C . . . . . . . | C . . . . . . . | C . . . . . . . |')], $bpm, 1, \@s) )
539 eq 'C . . . | C . . . | C . . . | C . . . |'
540 ) {
541 0 warn("reduce error\n");
542 0 print "$_\n" for @s;
543 }
544 0 ▶ while ( <> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline ARGV)) 0 0 0
545 0 @s = ();
546 0 chomp;
547 0 print("=> ", join(' ',reduce([split(' ',$_)], $bpm, 1, \@s)), "\n");
548 0 print "$_\n" for @s;
549 }
550 }
« lib/ChordPro/Output/PDF.pm ↑ Summary lib/ChordPro/lib/SVGPDF/Image.pm »