| 1 | package Music::Cadence; | ||||||||||||||||||||||||||||||||||
| 2 | 3 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Generate musical cadence chords | ||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.1512'; | |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Data::Dumper::Compact qw(ddc); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use List::Util qw(any); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Music::Chord::Note (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Music::Chord::Positions (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Music::Note (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use Music::Scales qw(get_scale_notes); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Music::ToRoman (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||
| 19 | 3 | with('Music::PitchNum'); | |||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||
| 22 | has verbose => ( | ||||||||||||||||||||||||||||||||||
| 23 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 24 | 23 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 25 | 3 | ); | |||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||
| 28 | has key => ( | ||||||||||||||||||||||||||||||||||
| 29 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 30 | 21 | ▶ | default => sub { 'C' }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 31 | 3 | ); | |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||
| 34 | has scale => ( | ||||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 36 | 23 | ▶ | default => sub { 'major' }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 37 | 3 | ); | |||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||
| 40 | has octave => ( | ||||||||||||||||||||||||||||||||||
| 41 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 42 | 17 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 43 | 3 | ); | |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||
| 46 | has format => ( | ||||||||||||||||||||||||||||||||||
| 47 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 48 | 13 | ▶ | default => sub { 'isobase' }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 49 | 3 | ); | |||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||
| 52 | has seven => ( | ||||||||||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 54 | 14 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 55 | 3 | ); | |||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||
| 58 | has picardy => ( | ||||||||||||||||||||||||||||||||||
| 59 | is => 'ro', | ||||||||||||||||||||||||||||||||||
| 60 | 23 | ▶ | default => sub { 0 }, | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 61 | 3 | ); | |||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||
| 64 | 60 | ▶ | sub cadence { | ||||||||||||||||||||||||||||||||
|
Subroutine
cadence: called CC=47 SCAR=39.5
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 65 | 60 | my ( $self, %args ) = @_; | |||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||
| 67 | 60 | my $cadence = []; | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 60 | ▶ | my $key = $args{key} || $self->key; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'key'} || $self->key
MC/DC0%0/2
$args{'key'} || $self->key
$args{'key'}
$self->key
Truth table66%2/3
A || B
A= $args{'key'}B= $self->key
| |||||||||||||||||||||||||||||||||||
| 70 | 60 | ▶ | my $scale = $args{scale} || $self->scale; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'scale'} || $self->scale
MC/DC0%0/2
$args{'scale'} || $self->scale
$args{'scale'}
$self->scale
Truth table66%2/3
A || B
A= $args{'scale'}B= $self->scale
| |||||||||||||||||||||||||||||||||||
| 71 | 60 | ▶ | my $octave = $args{octave} // $self->octave; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{"octave"} // $self->octave
MC/DC0%0/2
$args{"octave"} // $self->octave
$args{"octave"}
$self->octave
Truth table66%2/3
A // B
A= $args{"octave"}B= $self->octave
| |||||||||||||||||||||||||||||||||||
| 72 | 60 | ▶ | my $picardy = $args{picardy} || $self->picardy; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{'picardy'} || $self->picardy
MC/DC50%1/2
$args{'picardy'} || $self->picardy
$args{'picardy'}
$self->picardy
Truth table66%2/3
A || B
A= $args{'picardy'}B= $self->picardy
| |||||||||||||||||||||||||||||||||||
| 73 | 60 | ▶ | my $type = $args{type} || 'perfect'; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'type'} || 'perfect'
MC/DC100%1/1
$args{'type'} || 'perfect'
$args{'type'}
Truth table100%2/2
A
A= $args{'type'}
| |||||||||||||||||||||||||||||||||||
| 74 | 60 | ▶ | my $leading = $args{leading} || 1; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'leading'} || 1
MC/DC100%1/1
$args{'leading'} || 1
$args{'leading'}
Truth table100%2/2
A
A= $args{'leading'}
| |||||||||||||||||||||||||||||||||||
| 75 | 60 | ▶ | my $variation = $args{variation} || 1; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'variation'} || 1
MC/DC100%1/1
$args{'variation'} || 1
$args{'variation'}
Truth table100%2/2
A
A= $args{'variation'}
| |||||||||||||||||||||||||||||||||||
| 76 | 60 | ▶ | my $inversion = $args{inversion} || 0; | ||||||||||||||||||||||||||||||||
|
Condition100%2/2
$args{'inversion'} || 0
MC/DC100%1/1
$args{'inversion'} || 0
$args{'inversion'}
Truth table100%2/2
A
A= $args{'inversion'}
| |||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||
| 78 | 60 | ▶ | die 'unknown leader' if $leading < 1 or $leading > 7; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$leading < 1 or $leading > 7
MC/DC50%1/2
$leading < 1 or $leading > 7
$leading < 1
$leading > 7
Truth table66%2/3
A or B
A= $leading < 1B= $leading > 7
| |||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||
| 80 | 59 | my @scale_notes = get_scale_notes( $key, $scale ); | |||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||
| 82 | 59 | ▶ | if ( $type eq 'perfect' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 7 branches
| |||||||||||||||||||||||||||||||||||
| 83 | 15 | my $chord = $self->_generate_chord( $key, $scale, $scale_notes[4], $octave ); | |||||||||||||||||||||||||||||||||
| 84 | 12 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||
| 86 | 12 | $chord = $self->_generate_chord( $key, $scale, $scale_notes[0], $octave ); | |||||||||||||||||||||||||||||||||
| 87 | # Add another top note, but an octave above | ||||||||||||||||||||||||||||||||||
| 88 | 12 | my $top = $chord->[0]; | |||||||||||||||||||||||||||||||||
| 89 | 12 | ▶ | if ( $self->format eq 'midinum' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | 6 | $top += 12; | |||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||
| 92 | else { | ||||||||||||||||||||||||||||||||||
| 93 | 6 | ▶ | if ( $top =~ /^(.+?)(\d+)$/ ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | 4 | my $note = $1; | |||||||||||||||||||||||||||||||||
| 95 | 4 | my $octave = $2; | |||||||||||||||||||||||||||||||||
| 96 | 4 | $top = $note . ++$octave; | |||||||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||
| 99 | 12 | ▶ | print ddc($top) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 100 | 12 | push @$chord, $top; | |||||||||||||||||||||||||||||||||
| 101 | 12 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 102 | 12 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | ▶ | elsif ( $type eq 'imperfect' && $inversion ) { | |||||||||||||||||||||||||||||||||
|
Condition100%3/3
$type eq "imperfect" and $inversion
MC/DC100%2/2
$type eq "imperfect" and $inversion
$type eq "imperfect"
$inversion
Truth table100%3/3
A and B
A= $type eq "imperfect"B= $inversion
| |||||||||||||||||||||||||||||||||||
| 105 | 16 | my $chord = $self->_generate_chord( $key, $scale, $scale_notes[4], $octave ); | |||||||||||||||||||||||||||||||||
| 106 | $chord = $self->_invert_chord( $chord, $inversion->{1}, $octave ) | ||||||||||||||||||||||||||||||||||
| 107 | 16 | ▶ | if $inversion->{1}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | 16 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||
| 110 | 16 | $chord = $self->_generate_chord( $key, $scale, $scale_notes[0], $octave ); | |||||||||||||||||||||||||||||||||
| 111 | $chord = $self->_invert_chord( $chord, $inversion->{2}, $octave ) | ||||||||||||||||||||||||||||||||||
| 112 | 16 | ▶ | if $inversion->{2}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 113 | 16 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||
| 115 | elsif ( $type eq 'imperfect' ) { | ||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | my $note = $variation == 1 ? $scale_notes[4] : $scale_notes[6]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 117 | 4 | my $chord = $self->_generate_chord( $key, $scale, $note, $octave ); | |||||||||||||||||||||||||||||||||
| 118 | 4 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 119 | 4 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||
| 121 | 4 | $chord = $self->_generate_chord( $key, $scale, $scale_notes[0], $octave ); | |||||||||||||||||||||||||||||||||
| 122 | 4 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | 4 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | ▶ | elsif ( $type eq 'evaded' && $self->seven ) { | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
$type eq "evaded" and $self->seven
MC/DC50%1/2
$type eq "evaded" and $self->seven
$type eq "evaded"
$self->seven
Truth table66%2/3
A and B
A= $type eq "evaded"B= $self->seven
| |||||||||||||||||||||||||||||||||||
| 126 | 2 | ▶ | if ( $inversion ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | $inversion->{1} = 3 | ||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | unless defined $inversion->{1}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 129 | $inversion->{2} = 1 | ||||||||||||||||||||||||||||||||||
| 130 | 1 | ▶ | unless defined $inversion->{2}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||||||||
| 133 | 1 | $inversion = { 1 => 3, 2 => 1 }; | |||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||
| 136 | 2 | my $chord = $self->_generate_chord( $key, $scale, $scale_notes[4], $octave ); | |||||||||||||||||||||||||||||||||
| 137 | 2 | $chord = $self->_invert_chord( $chord, $inversion->{1}, $octave ); | |||||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | 2 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||
| 141 | 2 | $chord = $self->_generate_chord( $key, $scale, $scale_notes[0], $octave ); | |||||||||||||||||||||||||||||||||
| 142 | 2 | $chord = $self->_invert_chord( $chord, $inversion->{2}, $octave ); | |||||||||||||||||||||||||||||||||
| 143 | 2 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 144 | 2 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | elsif ( $type eq 'plagal' ) { | ||||||||||||||||||||||||||||||||||
| 147 | 4 | my $chord = $self->_generate_chord( $key, $scale, $scale_notes[3], $octave ); | |||||||||||||||||||||||||||||||||
| 148 | 4 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | 4 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | 4 | $chord = $self->_generate_chord( $key, $scale, $scale_notes[0], $octave ); | |||||||||||||||||||||||||||||||||
| 152 | 4 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 153 | 4 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | elsif ( $type eq 'half' ) { | ||||||||||||||||||||||||||||||||||
| 156 | 13 | my $chord = $self->_generate_chord( $key, $scale, $scale_notes[ $leading - 1 ], $octave ); | |||||||||||||||||||||||||||||||||
| 157 | $chord = $self->_invert_chord( $chord, $inversion->{1}, $octave ) | ||||||||||||||||||||||||||||||||||
| 158 | 13 | ▶ | if $inversion && $inversion->{1}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$inversion and $inversion->{1}
MC/DC50%1/2
$inversion and $inversion->{1}
$inversion
$inversion->{1}
Truth table66%2/3
A and B
A= $inversionB= $inversion->{1}
| |||||||||||||||||||||||||||||||||||
| 159 | 13 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 160 | 13 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||
| 162 | 13 | $chord = $self->_generate_chord( $key, $scale, $scale_notes[4], $octave ); | |||||||||||||||||||||||||||||||||
| 163 | $chord = $self->_invert_chord( $chord, $inversion->{2}, $octave ) | ||||||||||||||||||||||||||||||||||
| 164 | 13 | ▶ | if $inversion && $inversion->{2}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$inversion and $inversion->{2}
MC/DC0%0/2
$inversion and $inversion->{2}
$inversion
$inversion->{2}
Truth table66%2/3
A and B
A= $inversionB= $inversion->{2}
| |||||||||||||||||||||||||||||||||||
| 165 | 13 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 166 | 13 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||
| 168 | elsif ( $type eq 'deceptive' ) { | ||||||||||||||||||||||||||||||||||
| 169 | 4 | my $chord = $self->_generate_chord( $key, $scale, $scale_notes[4], $octave ); | |||||||||||||||||||||||||||||||||
| 170 | 4 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 171 | 4 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||
| 173 | 4 | ▶ | my $note = $variation == 1 ? $scale_notes[5] : $scale_notes[3]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 174 | 4 | $chord = $self->_generate_chord( $key, $scale, $note, $octave ); | |||||||||||||||||||||||||||||||||
| 175 | 4 | ▶ | print ddc($chord) if $self->verbose; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 176 | 4 | push @$cadence, $chord; | |||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||
| 178 | else { | ||||||||||||||||||||||||||||||||||
| 179 | 1 | die 'unknown cadence'; | |||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||
| 182 | 55 | ▶ | if ( $picardy ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 183 | 3 | ▶ | if ( $self->format eq 'midinum' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 184 | 1 | $cadence->[1][1]++; | |||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||||||||
| 187 | 2 | my $note = Music::Note->new( $cadence->[1][1], $self->format ); | |||||||||||||||||||||||||||||||||
| 188 | 2 | my $num = $note->format('midinum'); | |||||||||||||||||||||||||||||||||
| 189 | 2 | $num++; | |||||||||||||||||||||||||||||||||
| 190 | 2 | $note = Music::Note->new( $num, 'midinum' ); | |||||||||||||||||||||||||||||||||
| 191 | 2 | $cadence->[1][1] = $note->format( $self->format ); | |||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||
| 195 | 55 | return $cadence; | |||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||
| 198 | 32 | ▶ | sub _invert_chord { | ||||||||||||||||||||||||||||||||
|
Subroutine
_invert_chord: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 199 | 32 | my ( $self, $chord, $inversion, $octave ) = @_; | |||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||
| 201 | 32 | my $mcp = Music::Chord::Positions->new; | |||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||
| 203 | 32 | ▶ | if ( $self->format eq 'midinum' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 204 | 2 | $chord = $mcp->chord_inv( $chord, inv_num => $inversion ); | |||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||
| 206 | else { # Perform these gymnastics to convert named notes to inverted named notes: | ||||||||||||||||||||||||||||||||||
| 207 | # Strip the octave if present | ||||||||||||||||||||||||||||||||||
| 208 | 30 | ▶ | $chord = [ map { s/\d+//; $_ } @$chord ] | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 209 | if $octave; | ||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | # Convert the chord into pitch-class representation | ||||||||||||||||||||||||||||||||||
| 212 | 30 | my $pitches = [ map { $self->pitchnum( $_ . -1 ) } @$chord ]; | |||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||
| 214 | # Do the inversion! | ||||||||||||||||||||||||||||||||||
| 215 | 30 | $pitches = $mcp->chord_inv( $pitches, inv_num => $inversion ); | |||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||
| 217 | # Convert the pitch-classes back to named notes | ||||||||||||||||||||||||||||||||||
| 218 | 30 | $chord = [ map { $self->pitchname($_) } @$pitches ]; | |||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||
| 220 | # Clean-up the chord | ||||||||||||||||||||||||||||||||||
| 221 | 30 | for ( @$chord ) { | |||||||||||||||||||||||||||||||||
| 222 | 106 | ▶ | if ( $octave ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 223 | 64 | s/-1/$octave/; | |||||||||||||||||||||||||||||||||
| 224 | 64 | s/0/$octave + 1/e; | |||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||
| 226 | else { | ||||||||||||||||||||||||||||||||||
| 227 | 42 | s/-1//; | |||||||||||||||||||||||||||||||||
| 228 | 42 | s/0//; | |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||
| 231 | 106 | ▶ | if ( $self->format eq 'midi' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 232 | 12 | s/#/s/; | |||||||||||||||||||||||||||||||||
| 233 | 12 | s/b/f/; | |||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||
| 238 | 32 | return $chord; | |||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||
| 241 | 113 | ▶ | sub _generate_chord { | ||||||||||||||||||||||||||||||||
|
Subroutine
_generate_chord: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||
| 242 | 113 | my ( $self, $key, $scale, $note, $octave ) = @_; | |||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||
| 244 | # Know what chords should be diminished | ||||||||||||||||||||||||||||||||||
| 245 | 113 | my %diminished = ( | |||||||||||||||||||||||||||||||||
| 246 | ionian => 'vii', | ||||||||||||||||||||||||||||||||||
| 247 | major => 'vii', | ||||||||||||||||||||||||||||||||||
| 248 | dorian => 'vi', | ||||||||||||||||||||||||||||||||||
| 249 | phrygian => 'v', | ||||||||||||||||||||||||||||||||||
| 250 | lydian => 'iv', | ||||||||||||||||||||||||||||||||||
| 251 | mixolydian => 'iii', | ||||||||||||||||||||||||||||||||||
| 252 | aeolian => 'ii', | ||||||||||||||||||||||||||||||||||
| 253 | minor => 'ii', | ||||||||||||||||||||||||||||||||||
| 254 | locrian => 'i', | ||||||||||||||||||||||||||||||||||
| 255 | ); | ||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||
| 257 | 113 | ▶ | die 'unknown scale' unless exists $diminished{$scale}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||
| 259 | 112 | my $mtr = Music::ToRoman->new( | |||||||||||||||||||||||||||||||||
| 260 | scale_note => $key, | ||||||||||||||||||||||||||||||||||
| 261 | scale_name => $scale, | ||||||||||||||||||||||||||||||||||
| 262 | chords => 0, | ||||||||||||||||||||||||||||||||||
| 263 | ); | ||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||
| 265 | # Figure out if the chord is diminished, minor, or major | ||||||||||||||||||||||||||||||||||
| 266 | 111 | my $roman = $mtr->parse($note); | |||||||||||||||||||||||||||||||||
| 267 | 111 | ▶ | my $type = $roman =~ /^$diminished{$scale}$/ ? 'dim' : $roman =~ /^[a-z]/ ? 'm' : ''; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||
| 269 | 111 | ▶ | $type .= 7 | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 270 | if $self->seven; | ||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||
| 272 | 111 | my $mcn = Music::Chord::Note->new; | |||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||
| 274 | # Get the notes of the chord (without an octave) | ||||||||||||||||||||||||||||||||||
| 275 | 111 | my @notes = $mcn->chord( $note . $type ); | |||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||
| 277 | 111 | ▶ | if ( $self->format eq 'midi' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 278 | # Convert the sharps and flats | ||||||||||||||||||||||||||||||||||
| 279 | 8 | for ( @notes ) { | |||||||||||||||||||||||||||||||||
| 280 | 26 | s/#/s/; | |||||||||||||||||||||||||||||||||
| 281 | 26 | s/b/f/; | |||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||
| 284 | elsif ( $self->format eq 'midinum' ) { | ||||||||||||||||||||||||||||||||||
| 285 | # Convert the notes to midinum format | ||||||||||||||||||||||||||||||||||
| 286 | 14 | @notes = map { $self->pitchnum( $_ . $octave ) } @notes; | |||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||
| 288 | elsif ( $self->format ne 'isobase' ) { | ||||||||||||||||||||||||||||||||||
| 289 | 1 | die 'unknown format'; | |||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||
| 292 | # Append the octave if defined and the format is not midinum | ||||||||||||||||||||||||||||||||||
| 293 | 110 | ▶ | @notes = map { $_ . $octave } @notes | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$octave and $self->format ne "midinum"
MC/DC100%2/2
$octave and $self->format ne "midinum"
$octave
$self->format ne "midinum"
Truth table100%3/3
A and B
A= $octaveB= $self->format ne "midinum"
| |||||||||||||||||||||||||||||||||||
| 294 | if $octave && $self->format ne 'midinum'; | ||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||
| 296 | 110 | return \@notes; | |||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||
| 299 | 3 | 1; | |||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||
| 301 | __END__ | ||||||||||||||||||||||||||||||||||