| 1 | package Music::BachChoralHarmony; | ||||||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Parse the UCI Bach choral harmony data set | ||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.0412'; | |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Text::CSV (); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::ShareDir qw/ dist_dir /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use List::Util qw/ any /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | has data_file => ( | ||||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 20 | 0 | ▶ | default => sub { dist_dir('Music-BachChoralHarmony') . '/jsbach_chorals_harmony.data' }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 21 | 2 | ); | |||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||
| 24 | has key_title => ( | ||||||||||||||||||||||||||||||||
| 25 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | default => sub { dist_dir('Music-BachChoralHarmony') . '/jsbach_BWV_keys_titles.txt' }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 27 | 2 | ); | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | has data => ( | ||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||
| 32 | init_arg => undef, | ||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | 2 | ); | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub parse { | ||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=14 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||
| 38 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | # Collect the key signatures and titles | ||||||||||||||||||||||||||||||||
| 41 | 1 | my %data; | |||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | open my $fh, '<', $self->key_title | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | or die "Can't read ", $self->key_title, ": $!"; | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 1 | ▶ | while ( my $line = readline($fh) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | 64 | chomp $line; | |||||||||||||||||||||||||||||||
| 48 | 64 | ▶ | next if $line =~ /^\s*$/ || $line =~ /^#/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$line =~ /^\s*$/ or $line =~ /^#/
MC/DC100%2/2
$line =~ /^\s*$/ or $line =~ /^#/
$line =~ /^\s*$/
$line =~ /^#/
Truth table100%3/3
A or B
A= $line =~ /^\s*$/B= $line =~ /^#/
| |||||||||||||||||||||||||||||||||
| 49 | 60 | my @parts = split /\s+/, $line, 4; | |||||||||||||||||||||||||||||||
| 50 | 60 | $data{ $parts[0] } = { | |||||||||||||||||||||||||||||||
| 51 | bwv => $parts[1], | ||||||||||||||||||||||||||||||||
| 52 | key => $parts[2], | ||||||||||||||||||||||||||||||||
| 53 | title => $parts[3], | ||||||||||||||||||||||||||||||||
| 54 | }; | ||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 1 | close $fh; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | # Collect the events | ||||||||||||||||||||||||||||||||
| 60 | 1 | ▶ | my $csv = Text::CSV->new( { binary => 1 } ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | or die "Can't use CSV: ", Text::CSV->error_diag; | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | open $fh, '<', $self->data_file | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 64 | or die "Can't read ", $self->data_file, ": $!"; | ||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 1 | my $progression; | |||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||
| 68 | # 000106b_ 2 YES NO NO NO YES NO NO YES NO NO NO NO E 5 C_M | ||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | while ( my $row = $csv->getline($fh) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 5665 | ( my $id = $row->[0] ) =~ s/\s*//g; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 5665 | my $notes = ''; | |||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 5665 | for my $note ( 2 .. 13 ) { | |||||||||||||||||||||||||||||||
| 76 | 67980 | ▶ | $notes .= $row->[$note] eq 'YES' ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | 5665 | ( my $bass = $row->[14] ) =~ s/\s*//g; | |||||||||||||||||||||||||||||||
| 80 | 5665 | ( my $accent = $row->[15] ) =~ s/\s*//g; | |||||||||||||||||||||||||||||||
| 81 | 5665 | ( my $chord = $row->[16] ) =~ s/\s*//g; | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 5665 | ▶ | $progression->{$id}{key} ||= $data{$id}{key}; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$progression->{$id}{"key"} ||= $data{$id}{"key"}
MC/DC0%0/2
$progression->{$id}{"key"} ||= $data{$id}{"key"}
$progression->{$id}{"key"}
$data{$id}{"key"}
Truth table66%2/3
A ||= B
A= $progression->{$id}{"key"}B= $data{$id}{"key"}
| |||||||||||||||||||||||||||||||||
| 84 | 5665 | ▶ | $progression->{$id}{bwv} ||= $data{$id}{bwv}; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$progression->{$id}{"bwv"} ||= $data{$id}{"bwv"}
MC/DC0%0/2
$progression->{$id}{"bwv"} ||= $data{$id}{"bwv"}
$progression->{$id}{"bwv"}
$data{$id}{"bwv"}
Truth table66%2/3
A ||= B
A= $progression->{$id}{"bwv"}B= $data{$id}{"bwv"}
| |||||||||||||||||||||||||||||||||
| 85 | 5665 | ▶ | $progression->{$id}{title} ||= $data{$id}{title}; | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$progression->{$id}{"title"} ||= $data{$id}{"title"}
MC/DC0%0/2
$progression->{$id}{"title"} ||= $data{$id}{"title"}
$progression->{$id}{"title"}
$data{$id}{"title"}
Truth table66%2/3
A ||= B
A= $progression->{$id}{"title"}B= $data{$id}{"title"}
| |||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | 5665 | my $struct = { | |||||||||||||||||||||||||||||||
| 88 | notes => $notes, | ||||||||||||||||||||||||||||||||
| 89 | bass => $bass, | ||||||||||||||||||||||||||||||||
| 90 | accent => $accent, | ||||||||||||||||||||||||||||||||
| 91 | chord => $chord, | ||||||||||||||||||||||||||||||||
| 92 | }; | ||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||
| 94 | 5665 | push @{ $progression->{$id}{events} }, $struct; | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||
| 97 | 1 | ▶ | $csv->eof or die $csv->error_diag; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 98 | 1 | close $fh; | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | 1 | $self->data($progression); | |||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | 1 | return $self->data; | |||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | 63 | ▶ | sub search { | ||||||||||||||||||||||||||||||
|
Subroutine
search: called CC=32 SCAR=34.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 107 | 63 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | 63 | my %results = (); | |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | 63 | ▶ | if ( $args{id} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 112 | 26 | my @ids = split /\s+/, $args{id}; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | 26 | for my $id ( @ids ) { | |||||||||||||||||||||||||||||||
| 115 | 30 | $results{$id} = $self->data->{$id}; | |||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 63 | ▶ | if ( $args{key} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 120 | 12 | ▶ | my @iter = keys %results ? keys %results : keys %{ $self->data }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | 12 | my @keys = split /\s+/, $args{key}; | |||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | 12 | for my $id ( @iter ) { | |||||||||||||||||||||||||||||||
| 125 | 427 | ▶ | if ( $results{$id} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 126 | delete $results{$id} | ||||||||||||||||||||||||||||||||
| 127 | 7 | ▶ | unless any { $_ eq $results{$id}{key} } @keys; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||
| 129 | else { | ||||||||||||||||||||||||||||||||
| 130 | $results{$id} = $self->data->{$id} | ||||||||||||||||||||||||||||||||
| 131 | 420 | ▶ | if any { $_ eq $self->data->{$id}{key} } @keys; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||
| 136 | 63 | ▶ | if ( $args{bass} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 137 | 8 | %results = $self->_search_param( bass => $args{bass}, \%results ); | |||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||
| 140 | 63 | ▶ | if ( $args{chord} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 141 | 8 | %results = $self->_search_param( chord => $args{chord}, \%results ); | |||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 63 | ▶ | if ( $args{notes} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 145 | 27 | ▶ | my @iter = keys %results ? keys %results : keys %{ $self->data }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||
| 147 | 27 | ▶ | my $and = $args{notes} =~ /&/ ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 148 | 27 | ▶ | my $re = $and ? qr/\s*&\s*/ : qr/\s+/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | 27 | my @notes = split $re, $args{notes}; | |||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||
| 152 | 27 | my %index = ( | |||||||||||||||||||||||||||||||
| 153 | 'C' => 0, | ||||||||||||||||||||||||||||||||
| 154 | 'C#' => 1, | ||||||||||||||||||||||||||||||||
| 155 | 'Db' => 1, | ||||||||||||||||||||||||||||||||
| 156 | 'D' => 2, | ||||||||||||||||||||||||||||||||
| 157 | 'D#' => 3, | ||||||||||||||||||||||||||||||||
| 158 | 'Eb' => 3, | ||||||||||||||||||||||||||||||||
| 159 | 'E' => 4, | ||||||||||||||||||||||||||||||||
| 160 | 'F' => 5, | ||||||||||||||||||||||||||||||||
| 161 | 'F#' => 6, | ||||||||||||||||||||||||||||||||
| 162 | 'Gb' => 6, | ||||||||||||||||||||||||||||||||
| 163 | 'G' => 7, | ||||||||||||||||||||||||||||||||
| 164 | 'G#' => 8, | ||||||||||||||||||||||||||||||||
| 165 | 'Ab' => 8, | ||||||||||||||||||||||||||||||||
| 166 | 'A' => 9, | ||||||||||||||||||||||||||||||||
| 167 | 'A#' => 10, | ||||||||||||||||||||||||||||||||
| 168 | 'Bb' => 10, | ||||||||||||||||||||||||||||||||
| 169 | 'B' => 11, | ||||||||||||||||||||||||||||||||
| 170 | ); | ||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||
| 172 | 27 | ID: for my $id ( @iter ) { | |||||||||||||||||||||||||||||||
| 173 | 972 | my %and_notes = (); | |||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||
| 175 | 972 | my $match = 0; | |||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||
| 177 | 972 | for my $event ( @{ $self->data->{$id}{events} } ) { | |||||||||||||||||||||||||||||||
| 178 | 92219 | my @bitstring = split //, $event->{notes}; | |||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | 92219 | my $i = 0; | |||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | 92219 | for my $bit ( @bitstring ) { | |||||||||||||||||||||||||||||||
| 183 | 1106628 | ▶ | if ( $bit ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 184 | 303415 | for my $note ( sort @notes ) { | |||||||||||||||||||||||||||||||
| 185 | 530590 | ▶ | if ( defined $index{$note} && $i == $index{$note} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $index{$note} and $i == $index{$note}
MC/DC100%2/2
defined $index{$note} and $i == $index{$note}
defined $index{$note}
$i == $index{$note}
Truth table100%3/3
A and B
A= defined $index{$note}B= $i == $index{$note}
| |||||||||||||||||||||||||||||||||
| 186 | 49038 | ▶ | if ( $and ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 187 | 20572 | $and_notes{$note}++; | |||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||
| 189 | else { | ||||||||||||||||||||||||||||||||
| 190 | 28466 | $match++; | |||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||
| 196 | 1106628 | $i++; | |||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||
| 200 | 972 | ▶ | if ( $and ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 201 | 305 | ▶ | if ( keys %and_notes ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 202 | 292 | my %notes; | |||||||||||||||||||||||||||||||
| 203 | 292 | @notes{@notes} = undef; | |||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 292 | my $i = 0; | |||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||
| 207 | 292 | for my $n ( keys %and_notes ) { | |||||||||||||||||||||||||||||||
| 208 | $i++ | ||||||||||||||||||||||||||||||||
| 209 | 547 | ▶ | if exists $notes{$n}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||
| 212 | 292 | ▶ | if ( $i == scalar keys %notes ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 213 | 198 | $results{$id} = $self->data->{$id}; | |||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||
| 215 | else { | ||||||||||||||||||||||||||||||||
| 216 | delete $results{$id} | ||||||||||||||||||||||||||||||||
| 217 | 94 | ▶ | if $results{$id}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||
| 221 | else { | ||||||||||||||||||||||||||||||||
| 222 | 667 | ▶ | if ( $results{$id} && $match <= 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$results{$id} and $match <= 0
MC/DC100%2/2
$results{$id} and $match <= 0
$results{$id}
$match <= 0
Truth table100%3/3
A and B
A= $results{$id}B= $match <= 0
| |||||||||||||||||||||||||||||||||
| 223 | 2 | delete $results{$id}; | |||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||
| 225 | elsif ( $match > 0 ) { | ||||||||||||||||||||||||||||||||
| 226 | 547 | $results{$id} = $self->data->{$id}; | |||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||
| 232 | 63 | return \%results; | |||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | 20 | ▶ | sub bits2notes { | ||||||||||||||||||||||||||||||
|
Subroutine
bits2notes: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 237 | 20 | my ( $self, $string, $accidental ) = @_; | |||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||
| 239 | 20 | ▶ | $accidental ||= 'b'; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$accidental ||= "b"
MC/DC100%1/1
$accidental ||= "b"
$accidental
Truth table100%2/2
A
A= $accidental
| |||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||
| 241 | 20 | my @notes = (); | |||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||
| 243 | 2 | ▶ | no warnings 'qw'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 244 | 20 | my @positions = qw( C C#|Db D D#|Eb E F F#|Gb G G#|Ab A A#|Bb B ); | |||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | 20 | my @bits = split //, $string; | |||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||
| 248 | 20 | my $i = 0; | |||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||
| 250 | 20 | for my $bit ( @bits ) { | |||||||||||||||||||||||||||||||
| 251 | 240 | ▶ | if ( $bit ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 252 | 21 | my @note = split /\|/, $positions[$i]; | |||||||||||||||||||||||||||||||
| 253 | 21 | my $note = ''; | |||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||
| 255 | 21 | ▶ | if ( @note > 1 ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 256 | 12 | ▶ | $note = $accidental eq '#' ? $note[0] : $note[1]; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||
| 258 | else { | ||||||||||||||||||||||||||||||||
| 259 | 9 | $note = $note[0]; | |||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||
| 262 | 21 | push @notes, $note; | |||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | 240 | $i++; | |||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||
| 268 | 20 | return \@notes; | |||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||
| 271 | 16 | ▶ | sub _search_param { | ||||||||||||||||||||||||||||||
|
Subroutine
_search_param: called CC=18 SCAR=29.4
| |||||||||||||||||||||||||||||||||
| 272 | 16 | my ( $self, $name, $param, $seen ) = @_; | |||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||
| 274 | 16 | ▶ | my @iter = keys %$seen ? keys %$seen : keys %{ $self->data }; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||
| 276 | 16 | my %results = (); | |||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||
| 278 | 16 | ▶ | my $and = $param =~ /&/ ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 279 | 16 | ▶ | my $re = $and ? qr/\s*&\s*/ : qr/\s+/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||
| 281 | 16 | my %notes = (); | |||||||||||||||||||||||||||||||
| 282 | 16 | @notes{ split $re, $param } = undef; | |||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||
| 284 | 16 | ID: for my $id ( @iter ) { | |||||||||||||||||||||||||||||||
| 285 | 488 | my %and_notes = (); | |||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||
| 287 | 488 | my $match = 0; | |||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||
| 289 | 488 | for my $event ( @{ $self->data->{$id}{events} } ) { | |||||||||||||||||||||||||||||||
| 290 | 46616 | for my $note ( keys %notes ) { | |||||||||||||||||||||||||||||||
| 291 | 69924 | ▶ | if ( $note eq $event->{$name} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 292 | 3516 | ▶ | if ( $and ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 293 | 1172 | $and_notes{$note}++; | |||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||
| 295 | else { | ||||||||||||||||||||||||||||||||
| 296 | 2344 | $match++; | |||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||
| 302 | 488 | ▶ | if ( $and ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 303 | 122 | ▶ | if ( keys %and_notes ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 304 | 86 | my $i = 0; | |||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||
| 306 | 86 | for my $n ( keys %and_notes ) { | |||||||||||||||||||||||||||||||
| 307 | $i++ | ||||||||||||||||||||||||||||||||
| 308 | 86 | ▶ | if exists $notes{$n}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||
| 311 | 86 | ▶ | if ( $i == scalar keys %notes ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 312 | 0 | $results{$id} = $self->data->{$id}; | |||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||
| 314 | else { | ||||||||||||||||||||||||||||||||
| 315 | delete $results{$id} | ||||||||||||||||||||||||||||||||
| 316 | 86 | ▶ | if $results{$id}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||
| 320 | else { | ||||||||||||||||||||||||||||||||
| 321 | 366 | ▶ | if ( $results{$id} && $match <= 0 ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$results{$id} and $match <= 0
MC/DC0%0/2
$results{$id} and $match <= 0
$results{$id}
$match <= 0
Truth table33%1/3
A and B
A= $results{$id}B= $match <= 0
| |||||||||||||||||||||||||||||||||
| 322 | 0 | delete $results{$id}; | |||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||
| 324 | elsif ( $match > 0 ) { | ||||||||||||||||||||||||||||||||
| 325 | 172 | $results{$id} = $self->data->{$id}; | |||||||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||
| 330 | 16 | return %results; | |||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||
| 333 | 2 | 1; | |||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||
| 335 | __END__ | ||||||||||||||||||||||||||||||||