lib/ChordPro/Chords/Parser.pm

filter: Statementstmt 77.7% 478 / 615 Branchbran 60.6% 182 / 300 Conditioncond 53.9% 103 / 191 MC/DCmcdc 28.4% 31 / 109 Subroutinesub 67.4% 87 / 129 Podpod 0.0% 0 / 10 totaltotal 65.0% 881 / 1354 CC 240 SCAR 24.9
CC
240
Cov
69%
simplify
56.0
parse_chord
38.9
get_parser
27.0
CRAP 12.0
« blib/lib/ChordPro/Wx/SettingsDialog_wxg.pm ↑ Summary lib/ChordPro/Output/Debug.pm »
1 #! perl
2  
3 92 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 92 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 92 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 92 ▶use feature qw( signatures state);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 92 ▶no warnings "experimental::signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 92 our $config;
10  
11 # package ParserWatch;
12 #
13 # require Tie::Hash;
14 # our @ISA = qw( Tie::StdHash );
15 #
16 # sub STORE {
17 # if ( $_[1] !~ /^[[:alpha:]]+$/ ) {
18 # Carp::cluck("STORE $_[1] " . $_[2]);
19 # ::dump($_[2]);
20 # }
21 # $_[0]->{$_[1]} = $_[2];
22 # }
23  
24 92 ▶use ChordPro;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 92 my %parsers;
27  
28 # tie %parsers => 'ParserWatch';
29  
30 package ChordPro::Chords::Parser;
31  
32 # The parser analyses a chord and returns an object with the following
33 # attributes:
34 #
35 # name name as passed to the parser (e.g. Cism7)
36 #
37 # root textual decomposition: root part (e.g. Cis)
38 # qual textual decomposition: quality part (e.g. m)
39 # ext textual decomposition: extension part (e.g. 7)
40 # bass textual decomposition: bass part (a root)
41 #
42 # system notation system (common, nashville, user defined)
43 # root_canon canonical root (e.g. Cis => C#)
44 # root_ord root ordinal (e.g. Cis => 1)
45 # root_mod root modifier (e.g. is => # => +1)
46 # qual_canon canonical qualifier (e.g. m => -)
47 # ext_canon canonical extension (e.g. sus => sus4)
48 # bass_canon like root, for bass note
49 # bass_ord like root, for bass note
50 # bass_mod like root, for bass note
51 #
52 # The parsers are one of
53 # ChordPro::Chords::Parser::Common
54 # ChordPro::Chords::Parser::Nashville
55 # ChordPro::Chords::Parser::Roman
56 #
57 # The objects are one of
58 # ChordPro::Chord::Common
59 # ChordPro::Chord::Nashville
60 # ChordPro::Chord::Roman
61  
62 # Creates a parser based on the current (optionally augmented)
63 # context.
64 # Note that the appropriate way is to call
65 # ChordPro::Chords::Parser->get_parser.
66  
67 2 ▶sub new ( $pkg, $init ) {
Subroutine new: called CC=8 SCAR=23.7
Pod undocumented
68  
69 2 ▶ Carp::confess("Missing config?") unless $::config;
Branch: 1 branch
BranchTrueFalseTotal
unless $main::config 0 2 2
70 # Use current config, optionally augmented by $init.
71 2 ▶ my $cfg = { %{$::config//{}}, %{$init//{}} };
Condition50%2/4
$main::config // {}
l!l
20
$init // {}
l!l
20
MC/DC0%0/1
$main::config // {}
$main::config
MC/DC0%0/1
$init // {}
$init
Truth table50%1/2
A
A= $main::config
Aresult
11
00
Truth table50%1/2
A
A= $init
Aresult
11
00
72  
73 Carp::croak("Missing notes in parser creation")
74 2 ▶ unless $cfg->{notes};
Branch: 1 branch
BranchTrueFalseTotal
unless $cfg->{"notes"} 0 2 2
75 2 my $system = $cfg->{notes}->{system};
76 2 ▶ Carp::croak("Missing notes system in parser creation")
Branch: 1 branch
BranchTrueFalseTotal
unless $system 0 2 2
77 unless $system;
78  
79 2 ▶ if ( $system eq "nashville" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($system eq "nashville") 0 2 2
80 0 return ChordPro::Chords::Parser::Nashville->new($cfg);
81 }
82 2 ▶ if ( $system eq "roman" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($system eq "roman") 0 2 2
83 0 return ChordPro::Chords::Parser::Roman->new($cfg);
84 }
85 2 return ChordPro::Chords::Parser::Common->new($cfg);
86 }
87  
88 # The default parser has built-in support for common (dutch) note
89 # names.
90  
91 29853 ▶sub default ( $pkg ) {
Subroutine default: called CC=2 SCAR=10.5
Pod undocumented
92  
93 return $parsers{common} //=
94 ChordPro::Chords::Parser::Common->new
95 0 ▶ ( { %{$::config},
Condition33%1/3
$parsers{"common"} //= "ChordPro::Chords::Parser::Common"->new({%{$main::config;}, "notes", {"system", "common", "sharp", ["C", ["C#", "Cis", "C\x{266f}"], "D", ["D#", "Dis", "D\x{266f}"], "E", "F", ["F#", "Fis", "F\x{266f}"], "G", ["G#", "Gis", "G\x{266f}"], "A", ["A#", "Ais", "A\x{266f}"], "B"], "flat", ["C", ["Db", "Des", "D\x{266d}"], "D", ["Eb", "Es", "Ees", "E\x{266d}"], "E", "F", ["Gb", "Ges", "G\x{266d}"], "G", ["Ab", "As", "Aes", "A\x{266d}"], "A", ["Bb", "Bes", "B\x{266d}"], "B"]}})
l!l&&r!l&&!r
2985300
MC/DC0%0/2
$parsers{"common"} //= "ChordPro::Chords::Parser::Common"->new({%{$main::config;}, "notes", {"system", "common", "sharp", ["C", ["C#", "Cis", "C\x{266f}"], "D", ["D#", "Dis", "D\x{266f}"], "E", "F", ["F#", "Fis", "F\x{266f}"], "G", ["G#", "Gis", "G\x{266f}"], "A", ["A#", "Ais", "A\x{266f}"], "B"], "flat", ["C", ["Db", "Des", "D\x{266d}"], "D", ["Eb", "Es", "Ees", "E\x{266d}"], "E", "F", ["Gb", "Ges", "G\x{266d}"], "G", ["Ab", "As", "Aes", "A\x{266d}"], "A", ["Bb", "Bes", "B\x{266d}"], "B"]}})
$parsers{"common"} "ChordPro::Chords::Parser::Common"->new({%{$main::config;}, "notes", {"system", "common", "sharp", ["C", ["C#", "Cis", "C\x{266f}"], "D", ["D#", "Dis", "D\x{266f}"], "E", "F", ["F#", "Fis", "F\x{266f}"], "G", ["G#", "Gis", "G\x{266f}"], "A", ["A#", "Ais", "A\x{266f}"], "B"], "flat", ["C", ["Db", "Des", "D\x{266d}"], "D", ["Eb", "Es", "Ees", "E\x{266d}"], "E", "F", ["Gb", "Ges", "G\x{266d}"], "G", ["Ab", "As", "Aes", "A\x{266d}"], "A", ["Bb", "Bes", "B\x{266d}"], "B"]}})
Truth table33%1/3
A //= B
A= $parsers{"common"}B= "ChordPro::Chords::Parser::Common"->new({%{$main::config;}, "notes", {"system", "common", "sharp", ["C", ["C#", "Cis", "C\x{266f}"], "D", ["D#", "Dis", "D\x{266f}"], "E", "F", ["F#", "Fis", "F\x{266f}"], "G", ["G#", "Gis", "G\x{266f}"], "A", ["A#", "Ais", "A\x{266f}"], "B"], "flat", ["C", ["Db", "Des", "D\x{266d}"], "D", ["Eb", "Es", "Ees", "E\x{266d}"], "E", "F", ["Gb", "Ges", "G\x{266d}"], "G", ["Ab", "As", "Aes", "A\x{266d}"], "A", ["Bb", "Bes", "B\x{266d}"], "B"]}})
ABresult
1X1
011
000
96 "notes" =>
97 { "system" => "common",
98 "sharp" => [ "C", [ "C#", "Cis", "C♯" ],
99 "D", [ "D#", "Dis", "D♯" ],
100 "E",
101 "F", [ "F#", "Fis", "F♯" ],
102 "G", [ "G#", "Gis", "G♯" ],
103 "A", [ "A#", "Ais", "A♯" ],
104 "B",
105 ],
106 "flat" => [ "C",
107 [ "Db", "Des", "D♭" ], "D",
108 [ "Eb", "Es", "Ees", "E♭" ], "E",
109 "F",
110 [ "Gb", "Ges", "G♭" ], "G",
111 [ "Ab", "As", "Aes", "A♭" ], "A",
112 [ "Bb", "Bes", "B♭" ], "B",
113 ],
114 },
115 },
116 );
117 }
118  
119 # Cached version of the individual parser's parse_chord.
120 176635 ▶sub parse ( $self, $chord ) {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
121 #### $self->{chord_cache}->{$chord} //=
122 176635 $self->parse_chord($chord);
123 }
124  
125 # Virtual.
126 0 ▶sub parse_chord ( $self, $chord ) {
Subroutine parse_chord: not called CC=1 SCAR=6.9
Pod undocumented
127 0 Carp::confess("Virtual method 'parse_chord' not defined");
128 }
129  
130 # Fetch a parser for a known system, with fallback.
131 # Default is a parser for the current config.
132 656 ▶sub get_parser ( $self, $system = undef, $nofallback = undef ) {
Subroutine get_parser: called CC=13 SCAR=33.0
Pod undocumented
133  
134 656 ▶ $system //= $::config->{notes}->{system};
Condition66%2/3
$system //= $main::config->{"notes"}{"system"}
l!l&&r!l&&!r
5231330
MC/DC0%0/2
$system //= $main::config->{"notes"}{"system"}
$system $main::config->{"notes"}{"system"}
Truth table66%2/3
A //= B
A= $systemB= $main::config->{"notes"}{"system"}
ABresult
1X1
011
000
135 656 ▶ return $parsers{$system} if $parsers{$system};
Branch: 1 branch
BranchTrueFalseTotal
if $parsers{$system} 336 320 656
136  
137 320 ▶ if ( $system eq "nashville" ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($system eq 'nashville') { } 2 318 320
elsif ($system eq 'roman') { } 2 316 318
elsif ($system ne $main::config->{'notes'}{'system'}) { } 0 316 316
elsif ($system) { } 316 0 316
elsif ($nofallback) { } 0 0 0
138 2 ▶ return $parsers{$system} //=
Condition33%1/3
$parsers{$system} //= "ChordPro::Chords::Parser::Nashville"->new
l!l&&r!l&&!r
020
MC/DC0%0/2
$parsers{$system} //= "ChordPro::Chords::Parser::Nashville"->new
$parsers{$system} "ChordPro::Chords::Parser::Nashville"->new
Truth table33%1/3
A //= B
A= $parsers{$system}B= "ChordPro::Chords::Parser::Nashville"->new
ABresult
1X1
011
000
139 ChordPro::Chords::Parser::Nashville->new;
140 }
141 elsif ( $system eq "roman" ) {
142 2 ▶ return $parsers{$system} //=
Condition33%1/3
$parsers{$system} //= "ChordPro::Chords::Parser::Roman"->new
l!l&&r!l&&!r
020
MC/DC0%0/2
$parsers{$system} //= "ChordPro::Chords::Parser::Roman"->new
$parsers{$system} "ChordPro::Chords::Parser::Roman"->new
Truth table33%1/3
A //= B
A= $parsers{$system}B= "ChordPro::Chords::Parser::Roman"->new
ABresult
1X1
011
000
143 ChordPro::Chords::Parser::Roman->new;
144 }
145 elsif ( $system ne $::config->{notes}->{system} ) {
146 0 my $p = ChordPro::Chords::Parser::Common->new
147 ( { notes => { system => $system } } );
148 0 return $parsers{$system} = $p;
149 }
150 elsif ( $system ) {
151 316 my $p = ChordPro::Chords::Parser::Common->new;
152 316 $p->{system} = $system;
153 316 return $parsers{$system} = $p;
154 }
155 elsif ( $nofallback ) {
156 0 return;
157 };
158  
159 0 Carp::confess("No parser for $system, falling back to default\n");
160 0 ▶ return $parsers{common} //= $self->default;
Condition0%0/3
$parsers{"common"} //= $self->default
l!l&&r!l&&!r
000
MC/DC0%0/2
$parsers{"common"} //= $self->default
$parsers{"common"} $self->default
Truth table0%0/3
A //= B
A= $parsers{"common"}B= $self->default
ABresult
1X1
011
000
161 }
162  
163 4 ▶sub have_parser ( $self, $system ) {
Subroutine have_parser: called CC=1 SCAR=0.0
Pod undocumented
164 4 exists $parsers{$system};
165 }
166  
167 # The list of instantiated parsers.
168 0 ▶sub parsers ( $self ) {
Subroutine parsers: not called CC=1 SCAR=6.9
Pod undocumented
169 0 \%parsers;
170 }
171  
172 226 ▶sub reset_parsers ( $self, @which ) {
Subroutine reset_parsers: called CC=3 SCAR=11.4
Pod undocumented
173 226 ▶ @which = keys(%parsers) unless @which;
Branch: 1 branch
BranchTrueFalseTotal
unless @which 226 0 226
174 226 delete $parsers{$_} for @which;
175 }
176  
177 # The number of intervals for this note system.
178 324 ▶sub intervals ( $self ) {
Subroutine intervals: called CC=1 SCAR=0.0
Pod undocumented
179 324 $self->{intervals};
180 }
181  
182 0 ▶sub simplify ( $self ) {
Subroutine simplify: not called CC=1 SCAR=6.9
Pod undocumented
183 0 ref($self);
184 }
185  
186 ################ Parsing Common notated chords ################
187  
188 package ChordPro::Chords::Parser::Common;
189  
190 92 our @ISA = qw( ChordPro::Chords::Parser );
191  
192 92 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
193  
194 318 ▶sub new ( $pkg, $cfg = $::config ) {
Subroutine new: called CC=4 SCAR=14.2
195 318 my $self = bless { chord_cache => {} } => $pkg;
196 318 bless $self => 'ChordPro::Chords::Parser::Common';
197 318 my $notes = $cfg->{notes};
198 318 $self->load_notes($cfg);
199 318 $self->{system} = $notes->{system};
200 318 $self->{target} = 'ChordPro::Chord::Common';
201 318 $self->{movable} = $notes->{movable};
202 warn("Chords: Created parser for ", $self->{system},
203 $cfg->{settings}->{chordnames} eq "relaxed"
204 ? ", relaxed" : "",
205 318 ▶ "\n") if $::options->{verbose} > 1;
Branch: 2 branches
BranchTrueFalseTotal
if $main::options->{"verbose"} > 1 0 318 318
$cfg->{'settings'}{'chordnames'} eq 'relaxed' ? : 0 0 0
206 318 return $parsers{$self->{system}} = $self;
207 }
208  
209 175615 ▶sub parse_chord ( $self, $chord ) {
Subroutine parse_chord: called CC=31 SCAR=36.6
210  
211 my $info = { system => $self->{system},
212 175615 parser => $self,
213 name => $chord };
214  
215 175615 my $bass = "";
216 175615 ▶ if ( $chord =~ m;^(.*)/($self->{n_pat})$; ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chord =~ m[^(.*)/($self->{"n_pat"})$]u) 25068 150547 175615
217 25068 $chord = $1;
218 25068 $bass = $2;
219 }
220  
221 175615 my %plus;
222  
223 # Match chord.
224 175615 ▶ if ( $chord eq "" && $bass ne "" ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($chord eq '' and $bass ne '') { } 0 175615 175615
elsif ($chord =~ /^$self->{'c_pat'}$/u) { } 114960 60655 175615
elsif ($self->{'c_rpat'} and $main::config->{'settings'}{'chordnames'} eq 'relaxed' and $chord =~ /^$self->{'c_rpat'}$/u) { } 22 60633 60655
elsif ($main::config->{'settings'}{'notenames'} and ucfirst($chord) =~ /^$self->{'n_pat'}$/u) { } 6 60627 60633
Condition33%1/3
$chord eq "" and $bass ne ""
!ll&&!rl&&r
17561500
MC/DC0%0/2
$chord eq "" and $bass ne ""
$chord eq "" $bass ne ""
Truth table33%1/3
A and B
A= $chord eq ""B= $bass ne ""
ABresult
0X0
100
111
225 0 $info->{rootless} = 1;
226 }
227 elsif ( $chord =~ /^$self->{c_pat}$/ ) {
228 114960 %plus = %+;
229 114960 $info->{root} = $plus{root};
230 }
231 # Retry with relaxed pattern if requested.
232 ▶ elsif ( $self->{c_rpat}
Condition83%5/6
$self->{"c_rpat"} and $main::config->{"settings"}{"chordnames"} eq "relaxed" and $chord =~ /^$self->{"c_rpat"}$/u
!ll&&!rl&&r
60630322
$self->{"c_rpat"} and $main::config->{"settings"}{"chordnames"} eq "relaxed"
!ll&&!rl&&r
06063025
MC/DC66%2/3
$self->{"c_rpat"} and $main::config->{"settings"}{"chordnames"} eq "relaxed" and $chord =~ /^$self->{"c_rpat"}$/u
$self->{"c_rpat"} $main::config->{"settings"}{"chordnames"} eq "relaxed" $chord =~ /^$self->{"c_rpat"}$/u
Truth table75%3/4
A and B and C
A= $self->{"c_rpat"}B= $main::config->{"settings"}{"chordnames"} eq "relaxed"C= $chord =~ /^$self->{"c_rpat"}$/u
ABCresult
0XX0
10X0
1100
1111
233 && $::config->{settings}->{chordnames} eq "relaxed"
234 && $chord =~ /^$self->{c_rpat}$/ ) {
235 22 %plus = %+; # keep it outer
236 22 ▶ return unless $info->{root} = $plus{root};
Branch: 1 branch
BranchTrueFalseTotal
unless $info->{"root"} = $plus{"root"} 0 22 22
237 }
238 # Not a chord. Try note name.
239 ▶ elsif ( $::config->{settings}->{notenames}
Condition66%2/3
$main::config->{"settings"}{"notenames"} and ucfirst($chord) =~ /^$self->{"n_pat"}$/u
!ll&&!rl&&r
6062706
MC/DC50%1/2
$main::config->{"settings"}{"notenames"} and ucfirst($chord) =~ /^$self->{"n_pat"}$/u
$main::config->{"settings"}{"notenames"} ucfirst($chord) =~ /^$self->{"n_pat"}$/u
Truth table66%2/3
A and B
A= $main::config->{"settings"}{"notenames"}B= ucfirst($chord) =~ /^$self->{"n_pat"}$/u
ABresult
0X0
100
111
240 && ucfirst($chord) =~ /^$self->{n_pat}$/ ) {
241 6 $info->{root} = $chord;
242 6 $info->{isnote} = 1;
243 }
244 # Nope.
245 else {
246 60627 return;
247 }
248  
249 114988 bless $info => $self->{target};
250  
251 114988 ▶ my $q = $plus{qual} // "";
Condition100%2/2
$plus{"qual"} // ""
l!l
1149826
MC/DC100%1/1
$plus{"qual"} // ""
$plus{"qual"}
Truth table100%2/2
A
A= $plus{"qual"}
Aresult
11
00
252 114988 $info->{qual} = $q;
253 114988 ▶ $q = "-" if $q eq "m" || $q eq "mi" || $q eq "min";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "m" or $q eq "mi" or $q eq "min" 23531 91457 114988
Condition83%5/6
$q eq "m" or $q eq "mi" or $q eq "min"
l!l&&r!l&&!r
21372215991457
$q eq "m" or $q eq "mi"
l!l&&r!l&&!r
21372093616
MC/DC66%2/3
$q eq "m" or $q eq "mi" or $q eq "min"
$q eq "m" $q eq "mi" $q eq "min"
Truth table75%3/4
A or B or C
A= $q eq "m"B= $q eq "mi"C= $q eq "min"
ABCresult
1XX1
01X1
0011
0000
254 114988 ▶ $q = "+" if $q eq "aug";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "aug" 4216 110772 114988
255 114988 ▶ $q = "0" if $q eq "dim";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "dim" 4267 110721 114988
256 114988 ▶ $q = "0" if $q eq "o";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "o" 41 114947 114988
257 114988 $info->{qual_canon} = $q;
258  
259 114988 ▶ my $x = $plus{ext} // "";
Condition100%2/2
$plus{"ext"} // ""
l!l
1149826
MC/DC100%1/1
$plus{"ext"} // ""
$plus{"ext"}
Truth table100%2/2
A
A= $plus{"ext"}
Aresult
11
00
260 114988 ▶ if ( !$info->{qual} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($info->{"qual"}) 76558 38430 114988
261 76558 ▶ if ( $x eq "maj" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x eq "maj") 48 76510 76558
262 48 $x = "";
263 }
264 }
265 114988 $info->{ext} = $x;
266 114988 ▶ $x = "sus4" if $x eq "sus";
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "sus" 2160 112828 114988
267 114988 $info->{ext_canon} = $x;
268  
269 140056 ▶ my $ordmod = sub {
Subroutine __ANON__: called CC=5 SCAR=16.3
270 140056 my ( $pfx ) = @_;
271 140056 my $r = $info->{$pfx};
272 140056 ▶ $r = ucfirst($r) if $info->{isnote};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"isnote"} 6 140050 140056
273 140056 ▶ if ( defined $self->{ns_tbl}->{$r} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $self->{'ns_tbl'}{$r}) { } 101741 38315 140056
elsif (defined $self->{'nf_tbl'}{$r}) { } 38315 0 38315
274 101741 $info->{"${pfx}_ord"} = $self->{ns_tbl}->{$r};
275 101741 ▶ $info->{"${pfx}_mod"} = defined $self->{nf_tbl}->{$r} ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'nf_tbl'}{$r} ? : 62029 39712 101741
276 101741 $info->{"${pfx}_canon"} = $self->{ns_canon}->[$self->{ns_tbl}->{$r}];
277 }
278 elsif ( defined $self->{nf_tbl}->{$r} ) {
279 38315 $info->{"${pfx}_ord"} = $self->{nf_tbl}->{$r};
280 38315 $info->{"${pfx}_mod"} = -1;
281 38315 $info->{"${pfx}_canon"} = $self->{nf_canon}->[$self->{nf_tbl}->{$r}];
282 }
283 else {
284 0 Carp::croak("CANT HAPPEN ($r)");
285 0 return;
286 }
287 #### $info->{isflat} = $info->{"${pfx}_mod"} < 0;
288 114988 };
289  
290 114988 ▶ $ordmod->("root") unless $info->is_rootless;
Branch: 1 branch
BranchTrueFalseTotal
unless $info->is_rootless 114988 0 114988
291  
292 114988 ▶ cluck("BLESS info for $chord into ", $self->{target}, "\n")
Branch: 1 branch
BranchTrueFalseTotal
unless ref($info) =~ /ChordPro::Chord::/u 0 114988 114988
293 unless ref($info) =~ /ChordPro::Chord::/;
294  
295 114988 ▶ if ( $info->{bass} = $bass ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->{"bass"} = $bass) 25068 89920 114988
296 25068 ▶ if ( $bass =~ /^$self->{n_pat}$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($bass =~ /^$self->{"n_pat"}$/u) 25068 0 25068
297 25068 $ordmod->("bass");
298 25068 ▶ if ( $info->is_rootless ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($info->is_rootless) 0 25068 25068
299 0 for ( qw( ord mod canon ) ) {
300 0 $info->{"root_$_"} = $info->{"bass_$_"};
301 }
302 }
303 }
304 }
305  
306 114988 ▶ if ( $::config->{settings}->{'chords-canonical'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($main::config->{"settings"}{"chords-canonical"}) 0 114988 114988
307 0 my $t = $info->{name};
308 0 $info->{name_canon} = $info->canonical;
309 warn("Parsing chord: \"$chord\" canon \"", $info->canonical, "\"\n" )
310 0 ▶ if $info->{name_canon} ne $t and $::config->{debug}->{chords};
Branch: 1 branch
BranchTrueFalseTotal
if $info->{"name_canon"} ne $t and $main::config->{"debug"}{"chords"} 0 0 0
Condition0%0/3
$info->{"name_canon"} ne $t and $main::config->{"debug"}{"chords"}
!ll&&!rl&&r
000
MC/DC0%0/2
$info->{"name_canon"} ne $t and $main::config->{"debug"}{"chords"}
$info->{"name_canon"} ne $t $main::config->{"debug"}{"chords"}
Truth table0%0/3
A and B
A= $info->{"name_canon"} ne $tB= $main::config->{"debug"}{"chords"}
ABresult
0X0
100
111
311 }
312  
313 114988 return $info;
314 }
315  
316 ################ Chords ################
317  
318 # The following additions are recognized for major chords.
319  
320 my $additions_maj =
321 {
322 9292 map { $_ => $_ }
323 "",
324 "11",
325 "13",
326 "13#11",
327 "13#9",
328 "13b9",
329 "2",
330 "3",
331 "4",
332 "5",
333 "6",
334 "69",
335 "6add9",
336 "7",
337 "711",
338 "7add11",
339 "7#11",
340 "7#5",
341 "7#9",
342 "7#9#11",
343 "7#9#5",
344 "7#9b5",
345 "7alt",
346 "7b13",
347 "7b13sus",
348 "7b5",
349 "7b9",
350 "7b9#11",
351 "7b9#5",
352 "7b9#9",
353 "7b9b13",
354 "7b9b5",
355 "7b9sus",
356 "7-13",
357 "7-13sus",
358 "7-5",
359 "7\\+5",
360 "7-9",
361 "7-9#11",
362 "7-9#5",
363 "7-9#9",
364 "7-9-13",
365 "7-9-5",
366 "7-9sus",
367 "7sus",
368 "7susadd3",
369 "7\\+", # REGEXP!!!
370 "9",
371 "9\\+", # REGEXP!!!
372 "911",
373 "9#11",
374 "9#5",
375 "9b5",
376 "9-5",
377 "9sus",
378 "9add6",
379 1104 ( map { ( "maj$_", "^$_" ) }
380 "",
381 "13",
382 "7",
383 "711",
384 "7#11",
385 "7#5",
386 276 ( map { "7sus$_" } "", "2", "4" ),
387 "9",
388 "911",
389 "9#11",
390 ),
391 "alt",
392 "h",
393 "h7",
394 "h9",
395 368 ( map { "add$_" } "2", "4", "9", "11" ),
396 368 ( map { "sus$_" } "", "2", "4", "9" ),
397 276 ( map { "6sus$_" } "", "2", "4" ),
398 276 ( map { "7sus$_" } "", "2", "4" ),
399 92 ( map { "13sus$_" } "", "2", "4" ),
400 };
401  
402 # The following additions are recognized for minor chords.
403  
404 my $additions_min =
405 {
406 2300 map { $_ => $_ }
407 "",
408 "#5",
409 "11",
410 "13",
411 "6",
412 "69",
413 "7b5",
414 "7-5",
415 "711", # for George Kooymans
416 184 ( map { ( "$_", "maj$_", "^$_" ) }
417 "7",
418 "9",
419 ),
420 "9maj7", "9^7",
421 "add9",
422 "b6",
423 "#7",
424 276 ( map { "sus$_" } "", "4", "9" ),
425 92 ( map { "7sus$_" } "", "4" ),
426 };
427  
428 # The following additions are recognized for augmented chords.
429  
430 my $additions_aug =
431 {
432 92 map { $_ => $_ }
433 "",
434 "7",
435 };
436  
437 # The following additions are recognized for diminished chords.
438  
439 my $additions_dim =
440 {
441 92 map { $_ => $_ }
442 "",
443 "7",
444 };
445  
446 # Build tables and patterns from the "notes" element from the
447 # configuration.
448  
449 318 ▶sub load_notes ( $self, $init ) {
Subroutine load_notes: called CC=13 SCAR=25.7
450 318 ▶ my $cfg = { %{$::config//{}}, %{$init//{}} };
Condition50%2/4
$main::config // {}
l!l
3180
$init // {}
l!l
3180
MC/DC0%0/1
$main::config // {}
$main::config
MC/DC0%0/1
$init // {}
$init
Truth table50%1/2
A
A= $main::config
Aresult
11
00
Truth table50%1/2
A
A= $init
Aresult
11
00
451 318 my $n = $cfg->{notes};
452 318 ▶ Carp::confess("No notes?") unless $n->{system};
Branch: 1 branch
BranchTrueFalseTotal
unless $n->{"system"} 0 318 318
453 318 my ( @ns_canon, %ns_tbl, @nf_canon, %nf_tbl );
454  
455 318 my $rix = 0;
456 318 foreach my $root ( @{ $n->{sharp} } ) {
457 3816 ▶ if ( UNIVERSAL::isa($root, 'ARRAY') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($root, 'ARRAY')) { } 1575 2241 3816
458 1575 $ns_canon[$rix] = $root->[0];
459 1575 $ns_tbl{$_} = $rix foreach @$root;
460 }
461 else {
462 2241 $ns_canon[$rix] = $root;
463 2241 $ns_tbl{$root} = $rix;
464 }
465 3816 $rix++;
466 }
467 318 $rix = 0;
468 318 foreach my $root ( @{ $n->{flat} } ) {
469 3816 ▶ if ( UNIVERSAL::isa($root, 'ARRAY') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($root, 'ARRAY')) { } 1584 2232 3816
470 1584 $nf_canon[$rix] = $root->[0];
471 1584 $nf_tbl{$_} = $rix foreach @$root;
472 }
473 else {
474 2232 $nf_canon[$rix] = $root;
475 2232 $nf_tbl{$root} = $rix;
476 }
477 3816 $rix++;
478 }
479  
480 # Pattern to match note names.
481 318 my $n_pat = '(?:' ;
482 318 my @n;
483 318 foreach ( keys %ns_tbl ) {
484 6941 push( @n, $_ );
485 }
486 318 foreach ( sort keys %nf_tbl ) {
487 7570 ▶ next if $ns_tbl{$_};
Branch: 1 branch
BranchTrueFalseTotal
if $ns_tbl{$_} 1908 5662 7570
488 5662 push( @n, $_ );
489 }
490  
491 318 $n_pat = '(?:' . join( '|', sort { length($b) <=> length($a) } @n ) . ')';
492  
493 # Pattern to match chord names.
494 318 my $c_pat;
495 # Accept root, qual, and only known extensions.
496 318 $c_pat = "(?<root>" . $n_pat . ")";
497 318 $c_pat .= "(?:";
498 318 $c_pat .= "(?<qual>-|min?|m(?!aj))".
499 "(?<ext>" . join("|", keys(%$additions_min)) . ")|";
500 318 $c_pat .= "(?<qual>\\+|aug)".
501 "(?<ext>" . join("|", keys(%$additions_aug)) . ")|";
502 318 $c_pat .= "(?<qual>0|o|dim|h)".
503 "(?<ext>" . join("|", keys(%$additions_dim)) . ")|";
504 318 $c_pat .= "(?<qual>)".
505 "(?<ext>" . join("|", keys(%$additions_maj)) . ")";
506 318 $c_pat .= ")";
507 318 $c_pat = qr/$c_pat/;
508 318 $n_pat = qr/$n_pat/;
509  
510 # In relaxed form, we accept anything for extension.
511 318 my $c_rpat = "(?<root>" . $n_pat . ")";
512 318 $c_rpat .= "(?:(?<qual>-|min?|m(?!aj)|\\+|aug|0|o|dim|)(?<ext>.*))";
513 318 $c_rpat = qr/$c_rpat/;
514  
515 # Store in the object.
516 318 $self->{n_pat} = $n_pat;
517 318 $self->{c_pat} = $c_pat;
518 318 $self->{c_rpat} = $c_rpat;
519 318 $self->{ns_tbl} = \%ns_tbl;
520 318 $self->{nf_tbl} = \%nf_tbl;
521 318 $self->{ns_canon} = \@ns_canon;
522 318 $self->{nf_canon} = \@nf_canon;
523 318 $self->{intervals} = @ns_canon;
524 }
525  
526 661 ▶sub root_canon ( $self, $root, $sharp = 0, $minor = 0 ) {
Subroutine root_canon: called CC=4 SCAR=13.9
527 661 ▶ ( $sharp ? $self->{ns_canon} : $self->{nf_canon} )->[$root];
Branch: 1 branch
BranchTrueFalseTotal
$sharp ? : 549 112 661
528 }
529  
530 # Has chord diagrams.
531 229 ▶sub has_diagrams ( $self ) { !$self->{movable} }
Subroutine has_diagrams: called CC=1 SCAR=0.0
532  
533 # Movable notes system.
534 34 ▶sub movable ( $self ) { $self->{movable} }
Subroutine movable: called CC=1 SCAR=0.0
535  
536 ################ Parsing Nashville notated chords ################
537  
538 package ChordPro::Chords::Parser::Nashville;
539  
540 92 our @ISA = qw(ChordPro::Chords::Parser::Common);
541  
542 92 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
543  
544 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
545 2 my ( $pkg, $init ) = @_;
546 2 my $self = bless { chord_cache => {} } => $pkg;
547 2 $self->{system} = "nashville";
548 2 $self->{target} = 'ChordPro::Chord::Nashville';
549 2 $self->{intervals} = 12;
550 warn("Chords: Created parser for ", $self->{system}, "\n")
551 2 ▶ if $::options->{verbose} && $::options->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} and $main::options->{"verbose"} > 1 0 2 2
Condition33%1/3
$main::options->{"verbose"} and $main::options->{"verbose"} > 1
!ll&&!rl&&r
200
MC/DC0%0/2
$main::options->{"verbose"} and $main::options->{"verbose"} > 1
$main::options->{"verbose"} $main::options->{"verbose"} > 1
Truth table33%1/3
A and B
A= $main::options->{"verbose"}B= $main::options->{"verbose"} > 1
ABresult
0X0
100
111
552 2 return $parsers{$self->{system}} = $self;
553 }
554  
555 92 my $n_pat = qr/(?<shift>[b#]?)(?<root>[1-7])/;
556  
557 92 my %nmap = ( 1 => 0, 2 => 2, 3 => 4, 4 => 5, 5 => 7, 6 => 9, 7 => 11 );
558 92 my @nmap = ( 1, 1, 2, 2, 3, 4, 4, 5, 5, 6, 6, 7, 1 );
559  
560 408 ▶sub parse_chord {
Subroutine parse_chord: called CC=13 SCAR=27.8
561 408 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 408 408
562 408 my ( $self, $chord ) = @_;
563  
564 408 $chord =~ tr/\x{266d}\x{266f}\x{0394}\x{f8}\x{b0}/b#^h0/;
565  
566 408 my $bass = "";
567 408 ▶ if ( $chord =~ m;^(.*)/(.*); ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chord =~ m[^(.*)/(.*)]u) 0 408 408
568 0 $chord = $1;
569 0 $bass = $2;
570 }
571  
572 408 ▶ return unless $chord =~ /^$n_pat(?<qual>-|\+|0|o|aug|m(?!aj)|dim)?(?<ext>.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $chord =~ /^$n_pat(?<qual>-|\+|0|o|aug|m(?!aj)|dim)?(?<ext>.*)$/u 0 408 408
573  
574 my $info = { system => "nashville",
575 parser => $self,
576 name => $_[1],
577 root => $+{root},
578 408 };
579 408 bless $info => $self->{target};
580  
581 408 ▶ my $q = $+{qual} // "";
Condition100%2/2
$+{"qual"} // ""
l!l
306102
MC/DC100%1/1
$+{"qual"} // ""
$+{"qual"}
Truth table100%2/2
A
A= $+{"qual"}
Aresult
11
00
582 408 $info->{qual} = $q;
583 408 ▶ $q = "-" if $q eq "m";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "m" 0 408 408
584 408 ▶ $q = "+" if $q eq "aug";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "aug" 0 408 408
585 408 ▶ $q = "0" if $q eq "dim";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "dim" 0 408 408
586 408 ▶ $q = "0" if $q eq "o";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "o" 0 408 408
587 408 $info->{qual_canon} = $q;
588  
589 408 ▶ my $x = $+{ext} // "";
Condition50%1/2
$+{"ext"} // ""
l!l
4080
MC/DC0%0/1
$+{"ext"} // ""
$+{"ext"}
Truth table50%1/2
A
A= $+{"ext"}
Aresult
11
00
590 408 $info->{ext} = $x;
591 408 ▶ $x = "sus4" if $x eq "sus";
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "sus" 0 408 408
592 408 $info->{ext_canon} = $x;
593  
594 408 ▶ my $ordmod = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
595 408 my ( $pfx ) = @_;
596 408 my $r = 0 + $info->{$pfx};
597 408 $info->{"${pfx}_ord"} = $nmap{$r};
598 408 ▶ if ( $+{shift} eq "#" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($+{'shift'} eq '#') { } 120 288 408
elsif ($+{'shift'} eq 'b') { } 120 168 288
599 120 $info->{"${pfx}_mod"} = 1;
600 120 $info->{"${pfx}_ord"}++;
601 $info->{"${pfx}_ord"} = 0
602 120 ▶ if $info->{"${pfx}_ord"} >= 12;
Branch: 1 branch
BranchTrueFalseTotal
if $$info{"${pfx}_ord"} >= 12 0 120 120
603 }
604 elsif ( $+{shift} eq "b" ) {
605 120 $info->{"${pfx}_mod"} = -1;
606 120 $info->{"${pfx}_ord"}--;
607 $info->{"${pfx}_ord"} += 12
608 120 ▶ if $info->{"${pfx}_ord"} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$info{"${pfx}_ord"} < 0 0 120 120
609 }
610 else {
611 168 $info->{"${pfx}_mod"} = 0;
612 }
613 408 $info->{"${pfx}_canon"} = $r;
614 408 };
615  
616 408 $ordmod->("root");
617  
618 408 $info->{bass} = $bass;
619 408 ▶ return $info unless $bass;
Branch: 1 branch
BranchTrueFalseTotal
unless $bass 408 0 408
620 0 ▶ return unless $bass =~ /^$n_pat$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $bass =~ /^$n_pat$/u 0 0 0
621 0 $ordmod->("bass");
622  
623 0 return $info;
624 }
625  
626 0 ▶sub load_notes { Carp::confess("OOPS") }
Subroutine load_notes: not called CC=1 SCAR=6.9
627  
628 14 ▶sub root_canon {
Subroutine root_canon: called CC=3 SCAR=11.0
629 14 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 14 14
630 14 my ( $self, $root, $sharp ) = @_;
631 92 ▶ no warnings 'qw';
Subroutine BEGIN: called CC=1 SCAR=0.0
632 14 ▶ $sharp
Branch: 1 branch
BranchTrueFalseTotal
$sharp ? : 12 2 14
633 ? qw( 1 #1 2 #2 3 4 #4 5 #5 6 #6 7 )[$root]
634 : qw( 1 b2 2 b3 3 4 b5 5 b6 6 b7 7 )[$root]
635 }
636  
637 # Has chord diagrams.
638 2 ▶sub has_diagrams {
Subroutine has_diagrams: called CC=2 SCAR=7.2
639 2 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 2 2
640 2 0;
641 }
642  
643 # Movable notes system.
644 2 ▶sub movable {
Subroutine movable: called CC=2 SCAR=7.2
645 2 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 2 2
646 2 1;
647 }
648  
649 ################ Parsing Roman notated chords ################
650  
651 package ChordPro::Chords::Parser::Roman;
652  
653 92 ▶use ChordPro;
Subroutine BEGIN: called CC=1 SCAR=0.0
654  
655 92 our @ISA = qw(ChordPro::Chords::Parser::Common);
656  
657 2 ▶sub new {
Subroutine new: called CC=3 SCAR=11.4
658 2 my ( $pkg, $init ) = @_;
659 2 my $self = bless { chord_cache => {} } => $pkg;
660 2 $self->{system} = "roman";
661 2 $self->{target} = 'ChordPro::Chord::Roman';
662 2 $self->{intervals} = 12;
663 warn("Chords: Created parser for ", $self->{system}, "\n")
664 2 ▶ if $::options->{verbose} && $::options->{verbose} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $main::options->{"verbose"} and $main::options->{"verbose"} > 1 0 2 2
Condition33%1/3
$main::options->{"verbose"} and $main::options->{"verbose"} > 1
!ll&&!rl&&r
200
MC/DC0%0/2
$main::options->{"verbose"} and $main::options->{"verbose"} > 1
$main::options->{"verbose"} $main::options->{"verbose"} > 1
Truth table33%1/3
A and B
A= $main::options->{"verbose"}B= $main::options->{"verbose"} > 1
ABresult
0X0
100
111
665 2 return $parsers{$self->{system}} = $self;
666 }
667  
668 92 my $r_pat = qr/(?<shift>[b#]?)(?<root>(?i)iii|ii|iv|i|viii|vii|vi|v)/;
669  
670 92 my %rmap = ( I => 0, II => 2, III => 4, IV => 5, V => 7, VI => 9, VII => 11 );
671  
672 612 ▶sub parse_chord {
Subroutine parse_chord: called CC=14 SCAR=28.4
673 612 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 612 612
674 612 my ( $self, $chord ) = @_;
675  
676 612 $chord =~ tr/\x{266d}\x{266f}\x{0394}\x{f8}\x{b0}/b#^h0/;
677  
678 612 my $bass = "";
679 612 ▶ if ( $chord =~ m;^(.*)/(.*); ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chord =~ m[^(.*)/(.*)]u) 0 612 612
680 0 $chord = $1;
681 0 $bass = $2;
682 }
683  
684 612 ▶ return unless $chord =~ /^$r_pat(?<qual>\+|0|o|aug|dim|h)?(?<ext>.*)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $chord =~ /^$r_pat(?<qual>\+|0|o|aug|dim|h)?(?<ext>.*)$/u 0 612 612
685 612 my $r = $+{shift}.$+{root};
686  
687 612 my $info = { system => "roman",
688 parser => $self,
689 name => $_[1],
690 root => $r };
691 612 bless $info => $self->{target};
692  
693 612 ▶ my $q = $+{qual} // "";
Condition100%2/2
$+{"qual"} // ""
l!l
476136
MC/DC100%1/1
$+{"qual"} // ""
$+{"qual"}
Truth table100%2/2
A
A= $+{"qual"}
Aresult
11
00
694 612 $info->{qual} = $q;
695 612 ▶ $q = "-" if $r eq lc($r);
Branch: 1 branch
BranchTrueFalseTotal
if $r eq lc $r 306 306 612
696 612 ▶ $q = "+" if $q eq "aug";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "aug" 0 612 612
697 612 ▶ $q = "0" if $q eq "dim";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "dim" 0 612 612
698 612 ▶ $q = "0" if $q eq "o";
Branch: 1 branch
BranchTrueFalseTotal
if $q eq "o" 0 612 612
699 612 $info->{qual_canon} = $q;
700  
701 612 ▶ my $x = $+{ext} // "";
Condition50%1/2
$+{"ext"} // ""
l!l
6120
MC/DC0%0/1
$+{"ext"} // ""
$+{"ext"}
Truth table50%1/2
A
A= $+{"ext"}
Aresult
11
00
702 612 $info->{ext} = $x;
703 612 ▶ $x = "sus4" if $x eq "sus";
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "sus" 0 612 612
704 612 ▶ $x = "^7" if $x eq "7+";
Branch: 1 branch
BranchTrueFalseTotal
if $x eq "7+" 0 612 612
705 612 $info->{ext_canon} = $x;
706  
707 612 ▶ my $ordmod = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
708 612 my ( $pfx ) = @_;
709 612 my $r = $info->{$pfx};
710 612 $info->{"${pfx}_ord"} = $rmap{uc $r};
711 612 ▶ if ( $+{shift} eq "#" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($+{'shift'} eq '#') { } 180 432 612
elsif ($+{'shift'} eq 'b') { } 180 252 432
712 180 $info->{"${pfx}_mod"} = 1;
713 180 $info->{"${pfx}_ord"}++;
714 $info->{"${pfx}_ord"} = 0
715 180 ▶ if $info->{"${pfx}_ord"} >= 12;
Branch: 1 branch
BranchTrueFalseTotal
if $$info{"${pfx}_ord"} >= 12 0 180 180
716 }
717 elsif ( $+{shift} eq "b" ) {
718 180 $info->{"${pfx}_mod"} = -1;
719 180 $info->{"${pfx}_ord"}--;
720 $info->{"${pfx}_ord"} += 12
721 180 ▶ if $info->{"${pfx}_ord"} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$info{"${pfx}_ord"} < 0 180 0 180
722 }
723 else {
724 252 $info->{"${pfx}_mod"} = 0;
725 }
726 612 $info->{"${pfx}_canon"} = $r;
727 612 };
728  
729 612 $ordmod->("root");
730  
731 612 $info->{bass} = uc $bass;
732 612 ▶ return $info unless $bass;
Branch: 1 branch
BranchTrueFalseTotal
unless $bass 612 0 612
733 0 ▶ return unless $bass =~ /^$r_pat$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $bass =~ /^$r_pat$/u 0 0 0
734 0 $ordmod->("bass");
735  
736 0 return $info;
737 }
738  
739 0 ▶sub load_notes { Carp::confess("OOPS") }
Subroutine load_notes: not called CC=1 SCAR=6.9
740  
741 14 ▶sub root_canon {
Subroutine root_canon: called CC=4 SCAR=14.0
742 14 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 14 14
743 14 my ( $self, $root, $sharp, $minor ) = @_;
744 14 ▶ return lc( $self->root_canon( $root, $sharp ) ) if $minor;
Branch: 1 branch
BranchTrueFalseTotal
if $minor 0 14 14
745 92 ▶ no warnings 'qw';
Subroutine BEGIN: called CC=1 SCAR=0.0
746 14 ▶ $sharp
Branch: 1 branch
BranchTrueFalseTotal
$sharp ? : 12 2 14
747 ? qw( I #I II #II III IV #IV V #V VI #VI VII )[$root]
748 : qw( I bII II bIII III IV bV V bVI VI bVII VII )[$root]
749 }
750  
751 # Has chord diagrams.
752 2 ▶sub has_diagrams {
Subroutine has_diagrams: called CC=2 SCAR=7.2
753 2 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 2 2
754 2 0;
755 }
756  
757 # Movable notes system.
758 0 ▶sub movable {
Subroutine movable: not called CC=2 SCAR=17.9
759 0 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 0 0
760 0 1;
761 }
762  
763 ################ Chord objects: Common ################
764  
765 package ChordPro::Chord::Base;
766  
767 92 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
768  
769 31967 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
770 31967 my ( $pkg, $data ) = @_;
771 31967 ▶ $pkg = ref($pkg) || $pkg;
Condition66%2/3
ref $pkg || $pkg
l!l&&r!l&&!r
2024299430
MC/DC0%0/2
ref $pkg || $pkg
ref $pkg $pkg
Truth table66%2/3
A || B
A= ref $pkgB= $pkg
ABresult
1X1
011
000
772 31967 bless { %$data } => $pkg;
773 }
774  
775 328 ▶sub clone {
Subroutine clone: called CC=2 SCAR=7.1
776 328 ▶ Carp::confess("NMC") unless UNIVERSAL::isa($_[0],__PACKAGE__);
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($_[0], __PACKAGE__) 0 328 328
777 328 my ( $self ) = shift;
778 328 dclone($self);
779 }
780  
781 115948 ▶sub is_note { $_[0]->{isnote} };
Subroutine is_note: called CC=1 SCAR=0.0
782 0 ▶sub is_flat { $_[0]->{isflat} };
Subroutine is_flat: not called CC=1 SCAR=6.9
783  
784 1898 ▶sub is_nc {
Subroutine is_nc: called CC=7 SCAR=19.5
785 1898 my ( $self ) = @_;
786 # Keyboard...
787 1898 ▶ return 1 if defined($self->kbkeys) && !@{$self->kbkeys};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->kbkeys and not @{$self->kbkeys;} 8 1890 1898
Condition66%2/3
defined $self->kbkeys and not @{$self->kbkeys;}
!ll&&!rl&&r
018908
MC/DC50%1/2
defined $self->kbkeys and not @{$self->kbkeys;}
defined $self->kbkeys not @{$self->kbkeys;}
Truth table66%2/3
A and not(B)
A= defined $self->kbkeysB= not @{$self->kbkeys;}
ABresult
0X0
100
111
788 # Strings...
789 1890 ▶ return unless @{ $self->frets // [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->frets // [];} 210 1680 1890
Condition100%2/2
$self->frets // []
l!l
1680210
MC/DC100%1/1
$self->frets // []
$self->frets
Truth table100%2/2
A
A= $self->frets
Aresult
11
00
790 1680 for ( @{ $self->frets } ) {
791 3449 ▶ return unless $_ < 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $_ < 0 1680 1769 3449
792 }
793 0 return 1; # all -1 => N.C.
794 }
795  
796 # Can be transposed/transcoded.
797 1450 ▶sub is_xpxc {
Subroutine is_xpxc: called CC=3 SCAR=14.2
798 1450 ▶ defined($_[0]->{root}) || defined($_[0]->{bass}) || $_[0]->is_nc;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{"root"} or defined $_[0]{"bass"} or $_[0]->is_nc 1450 0 1450
Condition33%1/3
defined $_[0]{"root"} or defined $_[0]{"bass"}
l!l&&r!l&&!r
145000
MC/DC0%0/2
defined $_[0]{"root"} or defined $_[0]{"bass"}
defined $_[0]{"root"} defined $_[0]{"bass"}
Truth table33%1/3
A or B
A= defined $_[0]{"root"}B= defined $_[0]{"bass"}
ABresult
1X1
011
000
799 }
800  
801 838 ▶sub has_diagram {
Subroutine has_diagram: called CC=4 SCAR=17.9
802 838 my ( $self ) = @_;
803 ( $::config->{instrument}->{type} eq "keyboard" )
804 0 ▶ ? @{ $self->kbkeys // []}
Condition0%0/2
$self->kbkeys // []
l!l
00
MC/DC0%0/1
$self->kbkeys // []
$self->kbkeys
Truth table0%0/2
A
A= $self->kbkeys
Aresult
11
00
805 838 ▶ : @{ $self->frets // []};
Branch: 1 branch
BranchTrueFalseTotal
$main::config->{'instrument'}{'type'} eq 'keyboard' ? : 0 838 838
Condition50%1/2
$self->frets // []
l!l
8380
MC/DC0%0/1
$self->frets // []
$self->frets
Truth table50%1/2
A
A= $self->frets
Aresult
11
00
806 }
807  
808 # For convenience.
809 469929 ▶sub is_chord { defined $_[0]->{root_ord} }
Subroutine is_chord: called CC=1 SCAR=0.0
810 254192 ▶sub is_rootless { $_[0]->{rootless} }
Subroutine is_rootless: called CC=1 SCAR=0.0
811 606 ▶sub is_annotation { 0 }
Subroutine is_annotation: called CC=1 SCAR=0.0
812 0 ▶sub is_movable { $_[0]->{movable} }
Subroutine is_movable: not called CC=1 SCAR=6.9
813 0 ▶sub is_gridstrum { 0 }
Subroutine is_gridstrum: not called CC=1 SCAR=6.9
814  
815 # Common accessors.
816 7087 ▶sub name {
Subroutine name: called CC=5 SCAR=20.9
817 7087 my ( $self, $np ) = @_;
818 Carp::confess("Double parens")
819 7087 ▶ if $self->{parens} && $self->{name} =~ /^\(.*\)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"parens"} and $self->{"name"} =~ /^\(.*\)$/u 0 7087 7087
Condition33%1/3
$self->{"parens"} and $self->{"name"} =~ /^\(.*\)$/u
!ll&&!rl&&r
708700
MC/DC0%0/2
$self->{"parens"} and $self->{"name"} =~ /^\(.*\)$/u
$self->{"parens"} $self->{"name"} =~ /^\(.*\)$/u
Truth table33%1/3
A and B
A= $self->{"parens"}B= $self->{"name"} =~ /^\(.*\)$/u
ABresult
0X0
100
111
820 7087 ▶ return $self->{name} if $np || !$self->{parens};
Branch: 1 branch
BranchTrueFalseTotal
if $np or not $self->{"parens"} 7087 0 7087
Condition33%1/3
$np or not $self->{"parens"}
l!l&&r!l&&!r
070870
MC/DC0%0/2
$np or not $self->{"parens"}
$np not $self->{"parens"}
Truth table33%1/3
A or not(B)
A= $npB= not $self->{"parens"}
ABresult
1X1
011
000
821 0 "(" . $self->{name} . ")";
822 }
823  
824 0 ▶sub canon { $_[0]->{name_canon} }
Subroutine canon: not called CC=1 SCAR=6.9
825 4 ▶sub root { $_[0]->{root} }
Subroutine root: called CC=1 SCAR=0.0
826 1999 ▶sub root_ord { $_[0]->{root_ord} }
Subroutine root_ord: called CC=1 SCAR=0.0
827 0 ▶sub root_mod { $_[0]->{root_mod} }
Subroutine root_mod: not called CC=1 SCAR=6.9
828 4 ▶sub qual { $_[0]->{qual} }
Subroutine qual: called CC=1 SCAR=0.0
829 4 ▶sub ext { $_[0]->{ext} }
Subroutine ext: called CC=1 SCAR=0.0
830 4 ▶sub bass { $_[0]->{bass} }
Subroutine bass: called CC=1 SCAR=0.0
831 3 ▶sub base { $_[0]->{base} }
Subroutine base: called CC=1 SCAR=0.0
832 4409 ▶sub frets { $_[0]->{frets} }
Subroutine frets: called CC=1 SCAR=0.0
833 1 ▶sub fingers { $_[0]->{fingers} }
Subroutine fingers: called CC=1 SCAR=0.0
834 0 ▶sub display { $_[0]->{display} }
Subroutine display: not called CC=1 SCAR=6.9
835 0 ▶sub format { $_[0]->{format} }
Subroutine format: not called CC=1 SCAR=6.9
836 7 ▶sub diagram { $_[0]->{diagram} }
Subroutine diagram: called CC=1 SCAR=0.0
837 70 ▶sub parser { $_[0]->{parser} }
Subroutine parser: called CC=1 SCAR=0.0
838  
839 15 ▶sub strings {
Subroutine strings: called CC=1 SCAR=0.0
840 15 $_[0]->{parser}->{intervals};
841 }
842  
843 3797 ▶sub kbkeys {
Subroutine kbkeys: called CC=3 SCAR=11.0
844 3797 ▶ return $_[0]->{keys} if $_[0]->{keys} && @{$_[0]->{keys}};
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"keys"} and @{$_[0]{"keys"};} 3250 547 3797
Condition100%3/3
$_[0]{"keys"} and @{$_[0]{"keys"};}
!ll&&!rl&&r
2423053250
MC/DC100%2/2
$_[0]{"keys"} and @{$_[0]{"keys"};}
$_[0]{"keys"} @{$_[0]{"keys"};}
Truth table100%3/3
A and B
A= $_[0]{"keys"}B= @{$_[0]{"keys"};}
ABresult
0X0
100
111
845 547 $_[0]->{keys} = ChordPro::Chords::get_keys($_[0]);
846 }
847  
848 # Valid keys may not have bass, ext and qual (unless minor).
849 96 ▶sub is_key {
Subroutine is_key: called CC=5 SCAR=21.7
850 defined $_[0]->{root_ord}
851 && !$_[0]->{ext}
852 && !$_[0]->{bass}
853 96 ▶ && ( !$_[0]->{qual} || $_[0]->is_key_minor );
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{"root_ord"} and not $_[0]{"ext"} and not $_[0]{"bass"} and !$_[0]{"qual"} || $_[0]->is_key_minor 96 0 96
Condition41%5/12
defined $_[0]{'root_ord'} && !$_[0]{'ext'} && !$_[0]{'bass'} && (!$_[0]{'qual'} || $_[0]->is_key_minor)
!ll&&!rl&&r
0096
defined $_[0]{"root_ord"} and not $_[0]{"ext"} and not $_[0]{"bass"}
!ll&&!rl&&r
0096
defined $_[0]{"root_ord"} and not $_[0]{"ext"}
!ll&&!rl&&r
0096
not $_[0]{"qual"} or $_[0]->is_key_minor
l!l&&r!l&&!r
9150
MC/DC0%0/5
defined $_[0]{'root_ord'} && !$_[0]{'ext'} && !$_[0]{'bass'} && (!$_[0]{'qual'} || $_[0]->is_key_minor)
defined $_[0]{"root_ord"} not $_[0]{"ext"} not $_[0]{"bass"} not $_[0]{"qual"} $_[0]->is_key_minor
Truth table33%2/6
A and not(B) and not(C) && not(D) or E
A= defined $_[0]{"root_ord"}B= not $_[0]{"ext"}C= not $_[0]{"bass"}D= not $_[0]{"qual"}E= $_[0]->is_key_minor
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
854 }
855  
856 1041 ▶sub is_key_minor {
Subroutine is_key_minor: called CC=1 SCAR=0.0
857 1041 $_[0]->{qual_canon} eq '-';
858 }
859  
860 73 ▶sub is_key_flat {
Subroutine is_key_flat: called CC=7 SCAR=19.5
861 73 my ( $self ) = @_;
862 73 my $r = $self->root_ord;
863 73 ▶ $r = ( $r - 3 ) % $self->strings if $self->is_key_minor;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_key_minor 0 73 73
864  
865 return $::config->{keys}->{flats}
866 73 ▶ if $r == 6 # Gb
Branch: 1 branch
BranchTrueFalseTotal
if $r == 6 16 57 73
867 ;
868  
869 return
870 57 ▶ $r == 10 # Bb
Condition100%12/12
$r == 10 || $r == 8 || $r == 5 || $r == 3 || $r == 1
l!l&&r!l&&!r
161625
$r == 10 or $r == 8 or $r == 5 or $r == 3
l!l&&r!l&&!r
12441
$r == 10 or $r == 8 or $r == 5
l!l&&r!l&&!r
8445
$r == 10 or $r == 8
l!l&&r!l&&!r
4449
MC/DC100%5/5
$r == 10 || $r == 8 || $r == 5 || $r == 3 || $r == 1
$r == 10 $r == 8 $r == 5 $r == 3 $r == 1
Truth table100%6/6
A or B or C or D || E
A= $r == 10B= $r == 8C= $r == 5D= $r == 3E= $r == 1
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
871 || $r == 8 # Ab
872 || $r == 5 # F
873 || $r == 3 # Eb
874 || $r == 1 # Db
875 # || $r == 0 # C (neutral)
876 ;
877 }
878  
879 # Some keys are not used since they would have too many sharps.
880 963 ▶sub is_key_toosharp {
Subroutine is_key_toosharp: called CC=6 SCAR=17.9
881 963 my ( $self ) = @_;
882 963 my $r = $self->root_ord;
883 963 ▶ $r = ( $r - 3 ) % $self->strings if $self->is_key_minor;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_key_minor 15 948 963
884  
885 return $::config->{keys}->{flats}
886 963 ▶ if $r == 6 # F#
Branch: 1 branch
BranchTrueFalseTotal
if $r == 6 212 751 963
887 ;
888  
889 return
890 751 ▶ $r == 10 # A#
Condition100%9/9
$r == 10 || $r == 8 || $r == 3 || $r == 1
l!l&&r!l&&!r
7036645
$r == 10 or $r == 8 or $r == 3
l!l&&r!l&&!r
619681
$r == 10 or $r == 8
l!l&&r!l&&!r
2437690
MC/DC100%4/4
$r == 10 || $r == 8 || $r == 3 || $r == 1
$r == 10 $r == 8 $r == 3 $r == 1
Truth table100%5/5
A or B or C || D
A= $r == 10B= $r == 8C= $r == 3D= $r == 1
ABCDresult
1XXX1
01XX1
001X1
00011
00000
891 || $r == 8 # G#
892 || $r == 3 # D#
893 || $r == 1 # C#
894 ;
895 }
896  
897 963 ▶sub keyname {
Subroutine keyname: called CC=5 SCAR=16.3
898 963 my ( $k ) = @_;
899 963 ▶ return $k->name unless $::config->{keys}->{'force-common'};
Branch: 1 branch
BranchTrueFalseTotal
unless $main::config->{"keys"}{"force-common"} 0 963 963
900 963 ▶ if ( is_key_toosharp($k) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_key_toosharp($k)) 155 808 963
901 return $k->{parser}->{nf_canon}->[$k->root_ord] .
902 155 ▶ ( $k->{qual_canon} eq '-' ? "m" : "" );
Branch: 1 branch
BranchTrueFalseTotal
$k->{'qual_canon'} eq '-' ? : 0 155 155
903 }
904  
905 return $k->{parser}->{ns_canon}->[$k->root_ord] .
906 808 ▶ ( $k->{qual_canon} eq '-' ? "m" : "" );
Branch: 1 branch
BranchTrueFalseTotal
$k->{'qual_canon'} eq '-' ? : 15 793 808
907 }
908  
909 808 ▶sub chord_display ( $self, $default ) {
Subroutine chord_display: called CC=13 SCAR=32.3
910  
911 92 ▶ use String::Interpolate::Named;
Subroutine BEGIN: called CC=1 SCAR=0.0
912  
913 808 my $res = $self->name;
914 808 my $args = {};
915 808 ▶ $self->flat_copy( $args, $self->{display} // $self );
Condition33%1/3
$self->{"display"} // $self
l!l&&r!l&&!r
08080
MC/DC0%0/2
$self->{"display"} // $self
$self->{"display"} $self
Truth table33%1/3
A // B
A= $self->{"display"}B= $self
ABresult
1X1
011
000
916  
917 808 ▶ if ( !$::config->{settings}->{'enharmonic-transpose'} && $args->{key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $main::config->{"settings"}{"enharmonic-transpose"} and $args->{"key"}) 0 808 808
Condition33%1/3
not $main::config->{"settings"}{"enharmonic-transpose"} and $args->{"key"}
!ll&&!rl&&r
80800
MC/DC0%0/2
not $main::config->{"settings"}{"enharmonic-transpose"} and $args->{"key"}
not $main::config->{"settings"}{"enharmonic-transpose"} $args->{"key"}
Truth table33%1/3
not(A) and B
A= not $main::config->{"settings"}{"enharmonic-transpose"}B= $args->{"key"}
ABresult
0X0
100
111
918 $args->{root} = 'E#'
919 0 ▶ if $args->{root} eq 'F' && $args->{key} eq 'F#';
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"root"} eq "F" and $args->{"key"} eq "F#" 0 0 0
Condition0%0/3
$args->{"root"} eq "F" and $args->{"key"} eq "F#"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"root"} eq "F" and $args->{"key"} eq "F#"
$args->{"root"} eq "F" $args->{"key"} eq "F#"
Truth table0%0/3
A and B
A= $args->{"root"} eq "F"B= $args->{"key"} eq "F#"
ABresult
0X0
100
111
920 $args->{root} = 'Cb'
921 0 ▶ if $args->{root} eq 'B' && $args->{key} eq 'Gb';
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"root"} eq "B" and $args->{"key"} eq "Gb" 0 0 0
Condition0%0/3
$args->{"root"} eq "B" and $args->{"key"} eq "Gb"
!ll&&!rl&&r
000
MC/DC0%0/2
$args->{"root"} eq "B" and $args->{"key"} eq "Gb"
$args->{"root"} eq "B" $args->{"key"} eq "Gb"
Truth table0%0/3
A and B
A= $args->{"root"} eq "B"B= $args->{"key"} eq "Gb"
ABresult
0X0
100
111
922 }
923  
924 808 for my $fmt ( $default,
925 $self->{format},
926 $self->{chordformat} ) {
927 2424 ▶ next unless $fmt;
Branch: 1 branch
BranchTrueFalseTotal
unless $fmt 1602 822 2424
928 822 ▶ $args->{root} = lc($args->{root}) if $self->is_note;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_note 10 812 822
929 822 $args->{formatted} = $res;
930 822 $res = interpolate( { args => $args }, $fmt );
931 }
932  
933 # Substitute musical symbols if wanted.
934 $res = $self->fix_musicsyms($res)
935 808 ▶ if $::config->{settings}->{truesf} || $::config->{settings}->{maj7delta};
Branch: 1 branch
BranchTrueFalseTotal
if $main::config->{"settings"}{"truesf"} or $main::config->{"settings"}{"maj7delta"} 22 786 808
Condition66%2/3
$main::config->{"settings"}{"truesf"} or $main::config->{"settings"}{"maj7delta"}
l!l&&r!l&&!r
220786
MC/DC50%1/2
$main::config->{"settings"}{"truesf"} or $main::config->{"settings"}{"maj7delta"}
$main::config->{"settings"}{"truesf"} $main::config->{"settings"}{"maj7delta"}
Truth table66%2/3
A or B
A= $main::config->{"settings"}{"truesf"}B= $main::config->{"settings"}{"maj7delta"}
ABresult
1X1
011
000
936 808 return $res;
937 }
938  
939 895 ▶sub flat_copy ( $self, $ret, $o, $pfx = "" ) {
Subroutine flat_copy: called CC=6 SCAR=17.9
940 895 ▶ while ( my ( $k, $v ) = each %$o ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$o) 18234 895 19129
941 18234 ▶ if ( $k eq "orig" || $k eq "xc" || $k eq "xp" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k eq 'orig' or $k eq 'xc' or $k eq 'xp') { } 87 18147 18234
Condition100%6/6
$k eq "orig" or $k eq "xc" or $k eq "xp"
l!l&&r!l&&!r
186918147
$k eq "orig" or $k eq "xc"
l!l&&r!l&&!r
10818216
MC/DC100%3/3
$k eq "orig" or $k eq "xc" or $k eq "xp"
$k eq "orig" $k eq "xc" $k eq "xp"
Truth table100%4/4
A or B or C
A= $k eq "orig"B= $k eq "xc"C= $k eq "xp"
ABCresult
1XX1
01X1
0011
0000
942 87 $self->flat_copy( $ret, $v, "$k.$pfx");
943 87 $ret->{"$k.${pfx}formatted"} = $v->chord_display;
944 }
945 else {
946 18147 $ret->{"$pfx$k"} = $v;
947 }
948 }
949 895 $ret;
950 }
951  
952 22 ▶sub fix_musicsyms ( $self, $str ) {
Subroutine fix_musicsyms: called CC=8 SCAR=20.9
953  
954 92 ▶ use ChordPro::Utils qw( splitmarkup );
Subroutine BEGIN: called CC=1 SCAR=0.0
955  
956 22 my $sf = $::config->{settings}->{truesf};
957 22 my $delta = $::config->{settings}->{maj7delta};
958 22 my @c = splitmarkup($str);
959 22 my $res = '';
960 22 ▶ push( @c, '' ) if @c % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @c % 2 15 7 22
961 22 my $did = 0; # TODO: not for roman
962 22 ▶ while ( @c ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@c) 37 22 59
963 37 for ( shift(@c) ) {
964 37 ▶ if ( $sf ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf) 37 0 37
965 37 ▶ if ( $did ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($did) { } 10 27 37
elsif (length $_) { } 22 5 27
966 10 s/b/♭/g;
967 }
968 elsif ( length($_) ) {
969 22 s/(?<=[[:alnum:]])b/♭/g;
970 22 $did++;
971 }
972 37 s/#/♯/g;
973 }
974 37 ▶ if ( $delta ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($delta) 0 37 37
975 0 s/maj7/Δ/g;
976 }
977 37 $res .= $_ . shift(@c);
978 }
979 }
980 22 $res;
981 }
982  
983 0 ▶sub simplify ( $self ) {
Subroutine simplify: not called CC=7 SCAR=40.3
984 0 my $c = {};
985 0 for ( keys %$self ) {
986 0 ▶ next unless defined $self->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{$_} 0 0 0
987 0 ▶ next if defined $c->{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $c->{$_} 0 0 0
988 0 ▶ if ( UNIVERSAL::can( $self->{$_}, "simplify" ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::can($self->{$_}, 'simplify')) { } 0 0 0
elsif (ref $self->{$_} eq 'ARRAY' and @{$self->{$_};}) { } 0 0 0
989 0 $c->{$_} = $self->{$_}->simplify;
990 }
991 0 ▶ elsif ( ref($self->{$_}) eq 'ARRAY' && @{$self->{$_}} ) {
Condition0%0/3
ref $self->{$_} eq "ARRAY" and @{$self->{$_};}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $self->{$_} eq "ARRAY" and @{$self->{$_};}
ref $self->{$_} eq "ARRAY" @{$self->{$_};}
Truth table0%0/3
A and B
A= ref $self->{$_} eq "ARRAY"B= @{$self->{$_};}
ABresult
0X0
100
111
992 0 $c->{$_} = "[ " . join(" ", @{$self->{$_}}) . " ]";
993 }
994 else {
995 0 $c->{$_} = $self->{$_};
996 }
997 }
998 0 $c;
999 }
1000  
1001 0 ▶sub dump ( $self ) {
Subroutine dump: not called CC=1 SCAR=6.9
1002 0 ::dump($self->simplify);
1003 }
1004  
1005 package ChordPro::Chord::Common;
1006  
1007 92 our @ISA = qw( ChordPro::Chord::Base );
1008  
1009 # Show reconstructs the chord from its constituents.
1010 # Result is canonical.
1011 0 ▶sub show {
Subroutine show: not called CC=1 SCAR=6.9
1012 0 Carp::croak("call canonical instead of show");
1013 }
1014  
1015 343 ▶sub canonical ( $self ) {
Subroutine canonical: called CC=7 SCAR=20.0
1016 343 my $res;
1017  
1018 $res =
1019 $self->is_rootless
1020 ? ""
1021 : $self->is_chord
1022 ? $self->{parser}->root_canon( $self->{root_ord},
1023 $self->{root_mod} >= 0,
1024 $self->{qual} eq '-',
1025 # !$self->is_flat ???
1026 ) . $self->{qual} . $self->{ext}
1027 343 ▶ : $self->{name};
Branch: 2 branches
BranchTrueFalseTotal
$self->is_rootless ? : 0 343 343
$self->is_chord ? : 343 0 343
1028  
1029 343 ▶ if ( $self->is_note ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_note) 4 339 343
1030 4 return lcfirst($res);
1031 }
1032 339 ▶ if ( $self->{bass} && $self->{bass} ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bass"} and $self->{"bass"} ne "") 3 336 339
Condition66%2/3
$self->{"bass"} and $self->{"bass"} ne ""
!ll&&!rl&&r
33603
MC/DC50%1/2
$self->{"bass"} and $self->{"bass"} ne ""
$self->{"bass"} $self->{"bass"} ne ""
Truth table66%2/3
A and B
A= $self->{"bass"}B= $self->{"bass"} ne ""
ABresult
0X0
100
111
1033 $res .= "/" .
1034 3 ▶ ($self->{system} eq "roman" ? lc($self->{bass}) : $self->{bass});
Branch: 1 branch
BranchTrueFalseTotal
$self->{'system'} eq 'roman' ? : 0 3 3
1035 }
1036 339 return $res;
1037 }
1038  
1039 # Returns a representation indepent of notation system.
1040 113793 ▶sub agnostic ( $self ) {
Subroutine agnostic: called CC=4 SCAR=14.2
1041 113793 ▶ return if $self->is_rootless || $self->is_note;
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_rootless or $self->is_note 6 113787 113793
Condition66%2/3
$self->is_rootless or $self->is_note
l!l&&r!l&&!r
06113787
MC/DC50%1/2
$self->is_rootless or $self->is_note
$self->is_rootless $self->is_note
Truth table66%2/3
A or B
A= $self->is_rootlessB= $self->is_note
ABresult
1X1
011
000
1042 join( " ", "",
1043 $self->{root_ord},
1044 $self->{root_mod},
1045 $self->{qual_canon},
1046 $self->{ext_canon},
1047 113787 ▶ $self->{bass_ord} // () );
Condition66%2/3
$self->{"bass_ord"} // ()
l!l&&r!l&&!r
24928888590
MC/DC0%0/2
$self->{"bass_ord"} // ()
$self->{"bass_ord"} ()
Truth table66%2/3
A // B
A= $self->{"bass_ord"}B= ()
ABresult
1X1
011
000
1048 }
1049  
1050 319 ▶sub transpose ( $self, $xpose ) {
Subroutine transpose: called CC=9 SCAR=22.3
1051 319 ▶ return $self unless $xpose;
Branch: 1 branch
BranchTrueFalseTotal
unless $xpose 0 319 319
1052 319 ▶ Carp::confess("xpose is not a transpose object")
Branch: 1 branch
BranchTrueFalseTotal
unless UNIVERSAL::isa($xpose, "transpose") 0 319 319
1053 unless UNIVERSAL::isa( $xpose, "transpose" );
1054 319 ▶ return $self unless $self->is_chord;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_chord 0 319 319
1055 319 my $dir = $xpose->dir;
1056 319 $xpose = $xpose->xp;
1057  
1058 319 my $info = $self->clone;
1059 319 my $p = $self->{parser};
1060  
1061 322 ▶ my $dodir = sub( $root, $dir ) {
Subroutine __ANON__: called CC=2 SCAR=6.9
1062 322 ▶ return 0 if $root =~ /^(0|2|4|5|7|9|11)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $root =~ /^(0|2|4|5|7|9|11)$/u 215 107 322
1063 107 $dir;
1064 319 };
1065  
1066 319 ▶ unless ( $self->{rootless} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"rootless"}) 319 0 319
1067 319 $info->{root_ord} = ( $self->{root_ord} + $xpose ) % $p->intervals;
1068 $info->{root_canon} = $info->{root} =
1069 $p->root_canon( $info->{root_ord},
1070 $dir > 0,
1071 319 $info->{qual_canon} eq "-" );
1072 }
1073 319 ▶ if ( $self->{bass} && $self->{bass} ne "" && $self->{bass} !~ /^\d+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bass"} and $self->{"bass"} ne "" and not $self->{"bass"} =~ /^\d+$/u) 3 316 319
Condition66%4/6
$self->{"bass"} and $self->{"bass"} ne "" and not $self->{"bass"} =~ /^\d+$/u
!ll&&!rl&&r
31603
$self->{"bass"} and $self->{"bass"} ne ""
!ll&&!rl&&r
31603
MC/DC33%1/3
$self->{"bass"} and $self->{"bass"} ne "" and not $self->{"bass"} =~ /^\d+$/u
$self->{"bass"} $self->{"bass"} ne "" not $self->{"bass"} =~ /^\d+$/u
Truth table50%2/4
A and B and not(C)
A= $self->{"bass"}B= $self->{"bass"} ne ""C= not $self->{"bass"} =~ /^\d+$/u
ABCresult
0XX0
10X0
1100
1111
1074 3 $info->{bass_ord} = ( $self->{bass_ord} + $xpose ) % $p->intervals;
1075 $info->{bass_canon} = $info->{bass} =
1076 3 $p->root_canon( $info->{bass_ord}, $xpose > 0 );
1077 3 $info->{bass_mod} = $dodir->( $info->{bass_ord}, $dir );
1078 }
1079 319 $info->{root_mod} = $dodir->( $info->{root_ord}, $dir );
1080 319 $info->{name} = $info->{name_canon} = $info->canonical;
1081  
1082 319 delete $info->{$_} for qw( copy base frets fingers keys display );
1083  
1084 319 return $info;
1085 }
1086  
1087 20 ▶sub transcode ( $self, $xcode, $key_ord = 0 ) {
Subroutine transcode: called CC=15 SCAR=32.3
1088 20 ▶ return $self unless $xcode;
Branch: 1 branch
BranchTrueFalseTotal
unless $xcode 0 20 20
1089 20 ▶ return $self unless $self->is_chord;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_chord 0 20 20
1090 20 ▶ return $self if $self->{system} eq $xcode;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"system"} eq $xcode 0 20 20
1091 20 my $info = $self->dclone;
1092 #warn("_>_XCODE = $xcode, _SELF = $self->{system}, CHORD = $info->{name}");
1093 20 $info->{system} = $xcode;
1094 20 my $p = $self->{parser}->get_parser($xcode);
1095 20 ▶ die("OOPS ", $p->{system}, " $xcode") unless $p->{system} eq $xcode;
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{"system"} eq $xcode 0 20 20
1096 20 $info->{parser} = $p;
1097 20 ▶ if ( $key_ord && $p->movable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_ord and $p->movable) 2 18 20
Condition100%3/3
$key_ord and $p->movable
!ll&&!rl&&r
1262
MC/DC100%2/2
$key_ord and $p->movable
$key_ord $p->movable
Truth table100%3/3
A and B
A= $key_ordB= $p->movable
ABresult
0X0
100
111
1098 2 $info->{root_ord} -= $key_ord % $p->intervals;
1099 }
1100 # $info->{$_} = $p->{$_} for qw( ns_tbl nf_tbl ns_canon nf_canon );
1101 20 ▶ unless ( $self->{rootless} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"rootless"}) 20 0 20
1102 $info->{root_canon} = $info->{root} =
1103 $p->root_canon( $info->{root_ord},
1104 $info->{root_mod} >= 0,
1105 20 $info->{qual_canon} eq "-" );
1106 }
1107 20 ▶ if ( $p->{system} eq "roman" && $info->{qual_canon} eq "-" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"system"} eq "roman" and $info->{"qual_canon"} eq "-") 0 20 20
Condition66%2/3
$p->{"system"} eq "roman" and $info->{"qual_canon"} eq "-"
!ll&&!rl&&r
1460
MC/DC0%0/2
$p->{"system"} eq "roman" and $info->{"qual_canon"} eq "-"
$p->{"system"} eq "roman" $info->{"qual_canon"} eq "-"
Truth table66%2/3
A and B
A= $p->{"system"} eq "roman"B= $info->{"qual_canon"} eq "-"
ABresult
0X0
100
111
1108 # Minor quality is in the root name.
1109 0 $info->{qual_canon} = $info->{qual} = "";
1110 }
1111 20 ▶ if ( $self->{bass} && $self->{bass} ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bass"} and $self->{"bass"} ne "") 0 20 20
Condition33%1/3
$self->{"bass"} and $self->{"bass"} ne ""
!ll&&!rl&&r
2000
MC/DC0%0/2
$self->{"bass"} and $self->{"bass"} ne ""
$self->{"bass"} $self->{"bass"} ne ""
Truth table33%1/3
A and B
A= $self->{"bass"}B= $self->{"bass"} ne ""
ABresult
0X0
100
111
1112 0 ▶ if ( $key_ord && $p->movable ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_ord and $p->movable) 0 0 0
Condition0%0/3
$key_ord and $p->movable
!ll&&!rl&&r
000
MC/DC0%0/2
$key_ord and $p->movable
$key_ord $p->movable
Truth table0%0/3
A and B
A= $key_ordB= $p->movable
ABresult
0X0
100
111
1113 0 $info->{bass_ord} -= $key_ord % $p->intervals;
1114 }
1115 $info->{bass_canon} = $info->{bass} =
1116 0 $p->root_canon( $info->{bass_ord}, $info->{bass_mod} >= 0 );
1117 }
1118 20 $info->{name} = $info->{name_canon} = $info->canonical;
1119 20 $info->{system} = $p->{system};
1120 20 bless $info => $p->{target};
1121 # ::dump($info);
1122 #warn("_<_XCODE = $xcode, CHORD = ", $info->canonical);
1123 20 return $info;
1124 }
1125  
1126 800 ▶sub chord_display ( $self ) {
Subroutine chord_display: called CC=3 SCAR=14.2
1127  
1128 $self->SUPER::chord_display
1129 ( $::config->{"chord-formats"}->{common}
1130 800 ▶ // $::config->{settings}->{"chord-format"}
Condition40%2/5
($main::config->{"chord-formats"}{"common"} // $main::config->{"settings"}{"chord-format"}) // "%{name}"
l!l
8000
$main::config->{"chord-formats"}{"common"} // $main::config->{"settings"}{"chord-format"}
l!l&&r!l&&!r
80000
MC/DC0%0/2
($main::config->{"chord-formats"}{"common"} // $main::config->{"settings"}{"chord-format"}) // "%{name}"
$main::config->{"chord-formats"}{"common"} $main::config->{"settings"}{"chord-format"}
Truth table33%1/3
A // B
A= $main::config->{"chord-formats"}{"common"}B= $main::config->{"settings"}{"chord-format"}
ABresult
1X1
011
000
1131 // "%{name}" );
1132 }
1133  
1134 ################ Chord objects: Nashville ################
1135  
1136 package ChordPro::Chord::Nashville;
1137  
1138 92 our @ISA = 'ChordPro::Chord::Base';
1139  
1140 0 ▶sub transpose ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transpose: not called CC=2 SCAR=17.9
1141  
1142 0 ▶sub show {
Subroutine show: not called CC=1 SCAR=6.9
1143 0 Carp::croak("call canonical instead of show");
1144 }
1145  
1146 0 ▶sub canonical ( $self ) {
Subroutine canonical: not called CC=3 SCAR=24.8
1147 0 my $res = $self->{root_canon} . $self->{qual} . $self->{ext};
1148 0 ▶ if ( $self->{bass} && $self->{bass} ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bass"} and $self->{"bass"} ne "") 0 0 0
Condition0%0/3
$self->{"bass"} and $self->{"bass"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"bass"} and $self->{"bass"} ne ""
$self->{"bass"} $self->{"bass"} ne ""
Truth table0%0/3
A and B
A= $self->{"bass"}B= $self->{"bass"} ne ""
ABresult
0X0
100
111
1149 0 $res .= "/" . lc($self->{bass});
1150 }
1151 0 return $res;
1152 }
1153  
1154 4 ▶sub chord_display ( $self ) {
Subroutine chord_display: called CC=2 SCAR=7.6
1155  
1156 $self->SUPER::chord_display
1157 ( $::config->{"chord-formats"}->{nashville}
1158 4 ▶ // "%{name}" );
Condition50%1/2
$main::config->{"chord-formats"}{"nashville"} // "%{name}"
l!l
40
MC/DC0%0/1
$main::config->{"chord-formats"}{"nashville"} // "%{name}"
$main::config->{"chord-formats"}{"nashville"}
Truth table50%1/2
A
A= $main::config->{"chord-formats"}{"nashville"}
Aresult
11
00
1159 }
1160  
1161 # Key name.
1162 2 ▶sub keyname( $k ) {
Subroutine keyname: called CC=2 SCAR=7.6
1163 return $k->{parser}->root_canon( $k->{root_ord} ) .
1164 2 ▶ ( $k->{qual_canon} eq '-' ? "m" : "" );
Branch: 1 branch
BranchTrueFalseTotal
$k->{'qual_canon'} eq '-' ? : 0 2 2
1165 }
1166  
1167 ################ Chord objects: Roman ################
1168  
1169 package ChordPro::Chord::Roman;
1170  
1171 92 our @ISA = 'ChordPro::Chord::Base';
1172  
1173 0 ▶sub transpose ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transpose: not called CC=2 SCAR=17.9
1174  
1175 0 ▶sub show {
Subroutine show: not called CC=1 SCAR=6.9
1176 0 Carp::croak("call canonical instead of show");
1177 }
1178  
1179 0 ▶sub canonical ( $self ) {
Subroutine canonical: not called CC=3 SCAR=24.8
1180 0 my $res = $self->{root_canon} . $self->{qual} . $self->{ext};
1181 0 ▶ if ( $self->{bass} && $self->{bass} ne "" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"bass"} and $self->{"bass"} ne "") 0 0 0
Condition0%0/3
$self->{"bass"} and $self->{"bass"} ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"bass"} and $self->{"bass"} ne ""
$self->{"bass"} $self->{"bass"} ne ""
Truth table0%0/3
A and B
A= $self->{"bass"}B= $self->{"bass"} ne ""
ABresult
0X0
100
111
1182 0 $res .= "/" . lc($self->{bass});
1183 }
1184 0 return $res;
1185 }
1186  
1187 4 ▶sub chord_display ( $self ) {
Subroutine chord_display: called CC=2 SCAR=7.6
1188  
1189 $self->SUPER::chord_display
1190 ( $::config->{"chord-formats"}->{roman}
1191 4 ▶ // "%{name}" );
Condition50%1/2
$main::config->{"chord-formats"}{"roman"} // "%{name}"
l!l
40
MC/DC0%0/1
$main::config->{"chord-formats"}{"roman"} // "%{name}"
$main::config->{"chord-formats"}{"roman"}
Truth table50%1/2
A
A= $main::config->{"chord-formats"}{"roman"}
Aresult
11
00
1192 }
1193  
1194 # Key name.
1195 2 ▶sub keyname( $k ) {
Subroutine keyname: called CC=1 SCAR=0.0
1196 2 return $k->{parser}->root_canon( $k->{root_canon}, 0, $k->{qual_canon} eq '-' );
1197 }
1198  
1199 ################ Chord objects: Annotations ################
1200  
1201 package ChordPro::Chord::Annotation;
1202  
1203 92 ▶use String::Interpolate::Named;
Subroutine BEGIN: called CC=1 SCAR=0.0
1204  
1205 92 our @ISA = 'ChordPro::Chord::Base';
1206  
1207 0 ▶sub transpose ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transpose: not called CC=2 SCAR=17.9
1208 0 ▶sub transcode ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transcode: not called CC=2 SCAR=17.9
1209  
1210 0 ▶sub canonical ( $self ) {
Subroutine canonical: not called CC=1 SCAR=6.9
1211 0 my $res = $self->{text};
1212 0 return $res;
1213 }
1214  
1215 2 ▶sub chord_display ( $self ) {
Subroutine chord_display: called CC=1 SCAR=0.0
1216 2 return interpolate( { args => $self }, $self->{text} );
1217 }
1218  
1219 # For convenience.
1220 0 ▶sub is_chord ( $self ) { 0 };
Subroutine is_chord: not called CC=1 SCAR=6.9
1221 3 ▶sub is_annotation ( $self ) { 1 };
Subroutine is_annotation: called CC=1 SCAR=0.0
1222  
1223 ################ Chord objects: Strums ################
1224  
1225 package ChordPro::Chord::Strum;
1226  
1227 # Special 'chord'-like objects for strums in grids.
1228 #
1229 # Main purpose is to show an arrow from the ChordProSymbols font.
1230  
1231 92 our @ISA = 'ChordPro::Chord::Base';
1232  
1233 92 ▶use ChordPro::Symbols qw( strum );
Subroutine BEGIN: called CC=1 SCAR=0.0
1234  
1235 0 ▶sub new( $pkg, $data ) {
Subroutine new: not called CC=2 SCAR=17.9
1236 0 my $self = $pkg->SUPER::new( $data );
1237 0 my $fmt = strum( $data->{name} );
1238 0 ▶ unless ( defined $fmt ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $fmt) { } 0 0 0
1239 0 warn("Unknown strum: $data->{name}\n");
1240 0 $self->{format} = "";
1241 }
1242 else {
1243 0 $self->{format} = $fmt;
1244 }
1245 0 return $self;
1246 }
1247  
1248 0 ▶sub chord_display ( $self, $default = undef ) {
Subroutine chord_display: not called CC=2 SCAR=17.9
1249 0 $self->{format};
1250 }
1251  
1252 0 ▶sub transpose ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transpose: not called CC=2 SCAR=17.9
1253 0 ▶sub transcode ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transcode: not called CC=2 SCAR=17.9
1254  
1255 0 ▶sub canonical ( $self ) {
Subroutine canonical: not called CC=1 SCAR=6.9
1256 0 my $res = $self->{text};
1257 0 return $res;
1258 }
1259  
1260 # For convenience.
1261 0 ▶sub is_chord ( $self ) { 0 };
Subroutine is_chord: not called CC=1 SCAR=6.9
1262 0 ▶sub is_annotation ( $self ) { 1 };
Subroutine is_annotation: not called CC=1 SCAR=6.9
1263 0 ▶sub is_nc ( $self ) { 1 };
Subroutine is_nc: not called CC=1 SCAR=6.9
1264 0 ▶sub is_xpxc ( $self ) { 0 };
Subroutine is_xpxc: not called CC=1 SCAR=6.9
1265 0 ▶sub has_diagram ( $self ) { 0 };
Subroutine has_diagram: not called CC=1 SCAR=6.9
1266 0 ▶sub is_gridstrum ( $self ) { 1 };
Subroutine is_gridstrum: not called CC=1 SCAR=6.9
1267  
1268 ################ Chord objects: NC ################
1269  
1270 package ChordPro::Chord::NC;
1271  
1272 92 ▶use String::Interpolate::Named;
Subroutine BEGIN: called CC=1 SCAR=0.0
1273  
1274 92 our @ISA = 'ChordPro::Chord::Base';
1275  
1276 0 ▶sub transpose ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transpose: not called CC=2 SCAR=17.9
1277 0 ▶sub transcode ( $self, $dummy1, $dummy2=0 ) { $self }
Subroutine transcode: not called CC=2 SCAR=17.9
1278  
1279 0 ▶sub canonical ( $self ) {
Subroutine canonical: not called CC=1 SCAR=6.9
1280 0 my $res = $self->{name};
1281 0 return $res;
1282 }
1283  
1284 2 ▶sub chord_display ( $self ) {
Subroutine chord_display: called CC=1 SCAR=0.0
1285 2 return interpolate( { args => $self }, $self->{name} );
1286 }
1287  
1288 # For convenience.
1289 7 ▶sub is_nc ( $self ) { 1 };
Subroutine is_nc: called CC=1 SCAR=0.0
1290 0 ▶sub is_chord ( $self ) { 0 };
Subroutine is_chord: not called CC=1 SCAR=6.9
1291 2 ▶sub is_annotation ( $self ) { 0 };
Subroutine is_annotation: called CC=1 SCAR=0.0
1292 0 ▶sub has_diagram ( $self ) { 0 };
Subroutine has_diagram: not called CC=1 SCAR=6.9
1293  
1294 ################ Testing ################
1295  
1296 package main;
1297  
1298 92 ▶unless ( caller ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (caller) 0 92 92
1299 0 select(STDERR);
1300 0 binmode(STDERR, ':utf8');
1301 0 $::config = { settings => { chordnames => "strict" } };
1302 0 $::options = { verbose => 2 };
1303 0 foreach ( @ARGV ) {
1304 0 ▶ if ( $_ eq '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_ eq "-") 0 0 0
1305 0 $::config = { settings => { chordnames => "relaxed" } };
1306 0 ChordPro::Chords::Parser->reset_parsers("common");
1307 0 next;
1308 }
1309 0 my $p0 = ChordPro::Chords::Parser->default;
1310 0 my $p1 = ChordPro::Chords::Parser->get_parser("common", 1);
1311 0 ▶ die unless $p0 eq $p1;
Branch: 1 branch
BranchTrueFalseTotal
unless $p0 eq $p1 0 0 0
1312 0 my $p2 = ChordPro::Chords::Parser->get_parser("nashville", 1);
1313 0 my $p3 = ChordPro::Chords::Parser->get_parser("roman", 1);
1314 0 my $info = $p1->parse($_);
1315 0 ▶ $info = $p2->parse($_) if !$info && $p2;
Branch: 1 branch
BranchTrueFalseTotal
if not $info and $p2 0 0 0
Condition0%0/3
not $info and $p2
!ll&&!rl&&r
000
MC/DC0%0/2
not $info and $p2
not $info $p2
Truth table0%0/3
not(A) and B
A= not $infoB= $p2
ABresult
0X0
100
111
1316 0 ▶ $info = $p3->parse($_) if !$info && $p3;
Branch: 1 branch
BranchTrueFalseTotal
if not $info and $p3 0 0 0
Condition0%0/3
not $info and $p3
!ll&&!rl&&r
000
MC/DC0%0/2
not $info and $p3
not $info $p3
Truth table0%0/3
not(A) and B
A= not $infoB= $p3
ABresult
0X0
100
111
1317 0 ▶ print( "$_ => OOPS\n" ), next unless $info;
Branch: 1 branch
BranchTrueFalseTotal
unless $info 0 0 0
1318 0 print( "$_ ($info->{system}) =>" );
1319 print( " ", $info->transcode($_)->canonical, " ($_)" )
1320 0 for qw( common nashville roman );
1321 0 print( " '", $info->agnostic, "' (agnostic)\n" );
1322 0 print( "$_ =>" );
1323 0 print( " ", $info->transpose(ChordPro::Chords::Transpose::parse_transpose($_))->canonical, " ($_)" ) for -2..2;
1324 0 print( "\n" );
1325 # my $clone = $info->clone;
1326 # delete($clone->{parser});
1327 # print( ::dump($clone), "\n" );
1328 }
1329 }
1330  
1331 92 1;
« blib/lib/ChordPro/Wx/SettingsDialog_wxg.pm ↑ Summary lib/ChordPro/Output/Debug.pm »