| 1 | package Music::Chord::Progression; | ||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Create network transition chord progressions | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.0609'; | |||||||||||||||||||||||||||||||||||||||||||||||
| 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 Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Data::Dumper::Compact qw(ddc); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Graph::Directed (); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Music::Chord::Note (); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Music::Scales qw(get_scale_notes); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | has max => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid integer" unless $_[0] =~ /^\d+$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | ▶ | default => sub { 8 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | has net => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 9 | ▶ | isa => sub { croak "$_[0] is not a hashref" unless ref $_[0] eq 'HASH' }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 8 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 8 | { 1 => [qw( 1 2 3 4 5 6 )], | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 2 => [qw( 3 4 5 )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 3 => [qw( 1 2 4 6 )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 => [qw( 1 3 5 6 )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 => [qw( 1 4 6 )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 6 => [qw( 1 2 4 5 )], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 7 => [] } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | has chord_map => ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | sub _build_chord_map { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_chord_map: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | my %scale = ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 48 | chromatic => [ ('m') x 12 ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | major => [ '', 'm', 'm', '', '', 'm', 'dim' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ionian => [ '', 'm', 'm', '', '', 'm', 'dim' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | dorian => [ 'm', 'm', '', '', 'm', 'dim', '' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | phrygian => [ 'm', '', '', 'm', 'dim', '', 'm' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | lydian => [ '', '', 'm', 'dim', '', 'm', 'm' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | mixolydian => [ '', 'm', 'dim', '', 'm', 'm', '' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | minor => [ 'm', 'dim', '', 'm', 'm', '', '' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | aeolian => [ 'm', 'dim', '', 'm', 'm', '', '' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | locrian => [ 'dim', '', 'm', 'm', '', '', 'm' ], | ||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 6 | return $scale{ $self->scale_name }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | has scale_name => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid string" if ref $_[0] }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | ▶ | default => sub { 'major' }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | has scale_note => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid note" unless $_[0] =~ /^[A-G][#b]?$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | ▶ | default => sub { 'C' }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | has scale => ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | init_args => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 6 | ▶ | sub _build_scale { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_scale: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | my @scale = get_scale_notes($self->scale_note, $self->scale_name); | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 6 | my %equiv = ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 'C#' => 'Db', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 'D#' => 'Eb', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 'E#' => 'F', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 'F#' => 'Gb', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 'G#' => 'Ab', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 'A#' => 'Bb', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 'B#' => 'C', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 'Cb' => 'B', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 'Dbb' => 'C', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 'Ebb' => 'D', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 'Fb' => 'E', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 'Gbb' => 'F', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 'Abb' => 'G', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 'Bbb' => 'A', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | for (@scale) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 42 | ▶ | $_ = $equiv{$_} if exists $equiv{$_}; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | print ucfirst($self->scale_name), ' scale: ', ddc(\@scale) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 6 | return \@scale; | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | has octave => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid octave" unless $_[0] =~ /^-?\d+$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 9 | ▶ | default => sub { 4 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | has tonic => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid setting" unless $_[0] =~ /^-?[01]$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | ▶ | default => sub { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | has resolve => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid setting" unless $_[0] =~ /^-?[01]$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 8 | ▶ | default => sub { 1 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | has substitute => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid boolean" unless $_[0] =~ /^[01]$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 8 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | has sub_cond => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid coderef" unless ref($_[0]) eq 'CODE' }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | ▶ | default => sub { return sub { int rand 4 == 0 } }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | has flat => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid boolean" unless $_[0] =~ /^[01]$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 2 | has graph => ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | is => 'lazy', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | init_args => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | ▶ | sub _build_graph { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_graph: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 6 | my $g = Graph::Directed->new; | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | for my $posn (keys %{ $self->net }) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 42 | for my $p (@{ $self->net->{$posn} }) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 127 | $g->add_edge($posn, $p); | |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 6 | return $g; | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | has phrase => ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | init_args => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | has chords => ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | init_args => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | has verbose => ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | ▶ | isa => sub { croak "$_[0] is not a valid boolean" unless $_[0] =~ /^[01]$/ }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 7 | ▶ | sub generate { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=19 SCAR=30.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | croak 'chord_map length must equal number of net keys' | ||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | ▶ | unless @{ $self->chord_map } == keys %{ $self->net }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 6 | ▶ | print 'Graph: ' . $self->graph, "\n" if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Create a random progression | ||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | my @progression; | |||||||||||||||||||||||||||||||||||||||||||||||
| 198 | my $v; # Vertex | ||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 6 | for my $n (1 .. $self->max) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 42 | $v = $self->_next_successor($n, $v); | |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 42 | push @progression, $v; | |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 6 | ▶ | print 'Progression: ', ddc(\@progression) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 6 | my @chord_map = @{ $self->chord_map }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 6 | ▶ | if ($self->substitute) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | for my $chord (@chord_map) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 7 | ▶ | my $substitute = $self->sub_cond->() ? $self->substitution($chord) : $chord; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 7 | ▶ | if ($substitute eq $chord && $i < @progression && $self->sub_cond->()) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$substitute eq $chord and $i < @progression and $self->sub_cond->()
$substitute eq $chord and $i < @progression
MC/DC0%0/3
$substitute eq $chord and $i < @progression and $self->sub_cond->()
$substitute eq $chord
$i < @progression
$self->sub_cond->()
Truth table25%1/4
A and B and C
A= $substitute eq $chordB= $i < @progressionC= $self->sub_cond->()
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | $progression[$i] .= 't'; # Indicate that we should tritone substitute | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 7 | $chord = $substitute; | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 7 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 6 | ▶ | print 'Chord map: ', ddc(\@chord_map) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 6 | my @phrase = map { $self->_tt_sub(\@chord_map, $_) } @progression; | |||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 6 | $self->phrase(\@phrase); | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 6 | ▶ | print 'Phrase: ', ddc($self->phrase) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # Add octaves to the chords | ||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 6 | my $mcn = Music::Chord::Note->new; | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 6 | my @chords; | |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 6 | for my $chord (@phrase) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 42 | my @chord = $mcn->chord_with_octave($chord, $self->octave); | |||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 42 | push @chords, \@chord; | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 6 | ▶ | if ($self->flat) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 1 | my %equiv = ( | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 'C#' => 'Db', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 'D#' => 'Eb', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 'E#' => 'F', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 'F#' => 'Gb', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 'G#' => 'Ab', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 'A#' => 'Bb', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 'B#' => 'C', | ||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | for my $chord (@chords) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 8 | for my $note (@$chord) { | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 24 | ▶ | $note =~ s/^([A-G]#)(\d+)$/$equiv{$1}$2/ if $note =~ /#/; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 6 | $self->chords(\@chords); | |||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 6 | ▶ | print 'Chords: ', ddc($self->chords) if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 6 | return \@chords; | |||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 42 | ▶ | sub _next_successor { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_successor: called CC=9 SCAR=23.4
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 42 | my ($self, $n, $v) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 42 | ▶ | $v //= 1; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$v //= 1
MC/DC100%1/1
$v //= 1
$v
Truth table100%2/2
A
A= $v
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 42 | my $s; | |||||||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 42 | ▶ | if ($n == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 6 | ▶ | if ($self->tonic == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | $s = $self->graph->random_successor(1); | |||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | elsif ($self->tonic == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 6 | $s = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 268 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $s = $self->_full_keys; | |||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | elsif ($n == $self->max) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 6 | ▶ | if ($self->resolve == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 1 | ▶ | $s = $self->graph->random_successor($v) || $self->_full_keys; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->graph->random_successor($v) || $self->_full_keys
MC/DC0%0/2
$self->graph->random_successor($v) || $self->_full_keys
$self->graph->random_successor($v)
$self->_full_keys
Truth table33%1/3
A || B
A= $self->graph->random_successor($v)B= $self->_full_keys
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | elsif ($self->resolve == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 5 | $s = 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $s = $self->_full_keys; | |||||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 30 | $s = $self->graph->random_successor($v); | |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 42 | return $s; | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | sub _full_keys { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_full_keys: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | my @keys = grep { keys @{ $self->net->{$_} } > 0 } keys %{ $self->net }; | |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | return $keys[int rand @keys]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 42 | ▶ | sub _tt_sub { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_tt_sub: called CC=5 SCAR=24.5
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 42 | my ($self, $chord_map, $n) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 42 | my $note; | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 42 | ▶ | if ($n =~ /t/) { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | my @fnotes = get_scale_notes('C', 'chromatic', 0, 'b'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my @snotes = get_scale_notes('C', 'chromatic'); | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my %ftritone = map { $fnotes[$_] => $fnotes[($_ + 6) % @fnotes] } 0 .. $#fnotes; | |||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | my %stritone = map { $snotes[$_] => $snotes[($_ + 6) % @snotes] } 0 .. $#snotes; | |||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $n =~ s/t//; | |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $note = $ftritone{ $self->scale->[$n - 1] } || $stritone{ $self->scale->[$n - 1] }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ftritone{$self->scale->[$n - 1]} || $stritone{$self->scale->[$n - 1]}
MC/DC0%0/2
$ftritone{$self->scale->[$n - 1]} || $stritone{$self->scale->[$n - 1]}
$ftritone{$self->scale->[$n - 1]}
$stritone{$self->scale->[$n - 1]}
Truth table0%0/3
A || B
A= $ftritone{$self->scale->[$n - 1]}B= $stritone{$self->scale->[$n - 1]}
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | print 'Tritone: ', $self->scale->[$n - 1], " => $note\n" if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 42 | $note = $self->scale->[$n - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 42 | $note .= $chord_map->[$n - 1]; | |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 42 | ▶ | print "Note: $note\n" if $self->verbose; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 42 | return $note; | |||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 10 | ▶ | sub substitution { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
substitution: called CC=19 SCAR=40.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 10 | my ($self, $chord) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 10 | my $substitute = $chord; | |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 10 | ▶ | if ($chord eq '' || $chord eq 'm') { | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
Condition100%3/3
$chord eq "" or $chord eq "m"
MC/DC100%2/2
$chord eq "" or $chord eq "m"
$chord eq ""
$chord eq "m"
Truth table100%3/3
A or B
A= $chord eq ""B= $chord eq "m"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 8 | my $roll = int rand 2; | |||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 8 | ▶ | $substitute = $roll == 0 ? $chord . 'M7' : $chord . 7; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | ▶ | elsif ($chord eq 'dim' || $chord eq 'aug') { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$chord eq "dim" or $chord eq "aug"
MC/DC50%1/2
$chord eq "dim" or $chord eq "aug"
$chord eq "dim"
$chord eq "aug"
Truth table66%2/3
A or B
A= $chord eq "dim"B= $chord eq "aug"
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | $substitute = $chord . 7; | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | ▶ | elsif ($chord eq '-5' || $chord eq '-9') { | |||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$chord eq -5 or $chord eq -9
MC/DC0%0/2
$chord eq -5 or $chord eq -9
$chord eq -5
$chord eq -9
Truth table33%1/3
A or B
A= $chord eq -5B= $chord eq -9
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | $substitute = "7($chord)"; | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | elsif ($chord eq 'M7') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $roll = int rand 3; | |||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | $substitute = $roll == 0 ? 'M9' : $roll == 1 ? 'M11' : 'M13'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | elsif ($chord eq '7') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | my $roll = int rand 3; | |||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | ▶ | $substitute = $roll == 0 ? '9' : $roll == 1 ? '11' : '13'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | elsif ($chord eq 'm7') { | ||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $roll = int rand 3; | |||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | $substitute = $roll == 0 ? 'm9' : $roll == 1 ? 'm11' : 'm13'; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 10 | ▶ | print qq|Substitute: "$chord" => "$substitute"\n| if $self->verbose && $substitute ne $chord; | ||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->verbose and $substitute ne $chord
MC/DC0%0/2
$self->verbose and $substitute ne $chord
$self->verbose
$substitute ne $chord
Truth table33%1/3
A and B
A= $self->verboseB= $substitute ne $chord
| |||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 10 | return $substitute; | |||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||