blib/lib/Music/Dataset/ChordProgressions.pm

filter: Statementstmt 100% 48 / 48 Branchbran 70.0% 7 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 90.9% 70 / 77 CC 7 SCAR 8.2
CC
7
Cov
92%
as_file
3.7
as_list
3.0
as_hash
3.0
CRAP 2.3
↑ Summary
1 package Music::Dataset::ChordProgressions;
2 2 our $AUTHORITY = 'cpan:GENE';
3  
4 # ABSTRACT: Provide access to hundreds of chord progressions
5  
6 2 our $VERSION = '0.0500';
7  
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Text::CSV_XS ();
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 Music::Scales qw(get_scale_notes);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use Exporter 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 our $share_file = eval { dist_dir('Music-Dataset-ChordProgressions') . '/Chord-Progressions.csv' };
17  
18 2 our @EXPORT = qw(
19 as_file
20 as_list
21 as_hash
22 transpose
23 $share_file
24 );
25  
26  
27  
28 3 ▶sub as_file {
Subroutine as_file: called CC=3 SCAR=13.1
Pod documented
29 3 ▶ $share_file = 'share/Chord-Progressions.csv'
Branch: 1 branch
BranchTrueFalseTotal
unless $Music::Dataset::ChordProgressions::share_file and -e $Music::Dataset::ChordProgressions::share_file 0 3 3
Condition33%1/3
$Music::Dataset::ChordProgressions::share_file and -e $Music::Dataset::ChordProgressions::share_file
!ll&&!rl&&r
003
MC/DC0%0/2
$Music::Dataset::ChordProgressions::share_file and -e $Music::Dataset::ChordProgressions::share_file
$Music::Dataset::ChordProgressions::share_file -e $Music::Dataset::ChordProgressions::share_file
Truth table33%1/3
A and B
A= $Music::Dataset::ChordProgressions::share_fileB= -e $Music::Dataset::ChordProgressions::share_file
ABresult
0X0
100
111
30 unless $share_file && -e $share_file;
31 3 return $share_file;
32 }
33  
34  
35 1 ▶sub as_list {
Subroutine as_list: called CC=3 SCAR=11.0
Pod documented
36 1 my $file = as_file();
37  
38 1 my @data;
39  
40 1 my $csv = Text::CSV_XS->new({ binary => 1 });
41  
42 1 ▶ open my $fh, '<', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't read ${file}: $!" 1 0 1
43 or die "Can't read $file: $!";
44  
45 1 ▶ while (my $row = $csv->getline($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $csv->getline($fh)) 777 1 778
46 777 push @data, $row;
47 }
48  
49 1 close $fh;
50  
51 1 return @data;
52 }
53  
54  
55 1 ▶sub as_hash {
Subroutine as_hash: called CC=3 SCAR=11.0
Pod documented
56 1 my $file = as_file();
57  
58 1 my %data;
59  
60 1 my $csv = Text::CSV_XS->new({ binary => 1 });
61  
62 1 ▶ open my $fh, '<', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't read ${file}: $!" 1 0 1
63 or die "Can't read $file: $!";
64  
65 1 ▶ while (my $row = $csv->getline($fh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $row = $csv->getline($fh)) 777 1 778
66 # Row = Genre, Key, Type, Chords, Roman
67 777 push @{ $data{ $row->[0] }{ $row->[1] }{ $row->[2] } }, [ $row->[3], $row->[4] ];
68 }
69  
70 1 close $fh;
71  
72 1 return %data;
73 }
74  
75  
76 1 ▶sub transpose {
Subroutine transpose: called CC=1 SCAR=0.0
Pod documented
77 1 my ($note, $scale, $progression) = @_;
78  
79 1 my %note_map;
80 1 @note_map{ get_scale_notes('C', $scale) } = get_scale_notes($note, $scale);
81  
82 # transpose the progression chords from C
83 1 $progression =~ s/([A-G][#b]?)/$note_map{$1}/g;
84  
85 1 return $progression;
86 }
87  
88 2 1;
89  
90 __END__
↑ Summary