| 1 | package Music::Scales; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 7 | $Music::Scales::VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | our $AUTHORITY = 'cpan:GENE'; | |||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Generate musical scales | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Text::Abbrev; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 7 | ▶ | use vars qw($VERSION @ISA @EXPORT); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | $VERSION = '0.13'; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 7 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 15 | 7 | @EXPORT = qw(get_scale_notes get_scale_nums get_scale_offsets is_scale get_scale_PDL get_scale_MIDI %modes %original_modes %abbrevs @scales); | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | our %modes = qw(ionian 1 major 1 hypolydian 1 dorian 2 hypomyxolydian 2 | |||||||||||||||||||||||||||||||||||||||||
| 20 | phrygian 3 hypoaeolian 3 lydian 4 hypolocrian 4 mixolydian 5 hypoionian 5 | ||||||||||||||||||||||||||||||||||||||||||
| 21 | aeolian 6 minor 6 m 6 hypodorian 6 locrian 7 hypophrygian 7 | ||||||||||||||||||||||||||||||||||||||||||
| 22 | harmonicminor 8 hm 8 melodicminor 9 mm 9 | ||||||||||||||||||||||||||||||||||||||||||
| 23 | blues 10 pentatonic 11 pmaj 11 chromatic 12 diminished 13 wholetone 14 | ||||||||||||||||||||||||||||||||||||||||||
| 24 | augmented 15 hungarianminor 16 3semitone 17 4semitone 18 | ||||||||||||||||||||||||||||||||||||||||||
| 25 | neapolitanminor 19 nmin 19 neapolitanmajor 20 nmaj 20 | ||||||||||||||||||||||||||||||||||||||||||
| 26 | todi 21 marva 22 persian 23 oriental 24 romanian 25 pelog 26 | ||||||||||||||||||||||||||||||||||||||||||
| 27 | iwato 27 hirajoshi 28 egyptian 29 pminor 30 pentatonicminor 30 | ||||||||||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 7 | our %original_modes = %modes; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 7 | our %abbrevs = abbrev(keys %modes); | |||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | ▶ | while (my ($k,$v) = each %abbrevs) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1876 | $modes{$k} = $modes{$v}; | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | our @scales=([0,2,4,5,7,9,11], # Ionian(1) | |||||||||||||||||||||||||||||||||||||||||
| 36 | [0,2,3,5,7,9,10], # Dorian (2) | ||||||||||||||||||||||||||||||||||||||||||
| 37 | [0,1,3,5,7,8,10], # Phrygian (3) | ||||||||||||||||||||||||||||||||||||||||||
| 38 | [0,2,4,6,7,9,11], # Lydian (4) | ||||||||||||||||||||||||||||||||||||||||||
| 39 | [0,2,4,5,7,9,10], # Mixolydian (5) | ||||||||||||||||||||||||||||||||||||||||||
| 40 | [0,2,3,5,7,8,10], # Aeolian (6) | ||||||||||||||||||||||||||||||||||||||||||
| 41 | [0,1,3,5,6,8,10], # Locrian (7) | ||||||||||||||||||||||||||||||||||||||||||
| 42 | [0,2,3,5,7,8,11], # Harmonic Minor (8) | ||||||||||||||||||||||||||||||||||||||||||
| 43 | [0,2,3,5,7,9,11], # Melodic Minor (9) | ||||||||||||||||||||||||||||||||||||||||||
| 44 | [0,3,5,6,7,10], # Blues (10) | ||||||||||||||||||||||||||||||||||||||||||
| 45 | [0,2,4,7,9], # Pentatonic (11) | ||||||||||||||||||||||||||||||||||||||||||
| 46 | [0,1,2,3,4,5,6,7,8,9,10,11],# Chromatic (12) | ||||||||||||||||||||||||||||||||||||||||||
| 47 | [0,2,3,5,6,8,9,11], # Diminished (13) | ||||||||||||||||||||||||||||||||||||||||||
| 48 | [0,2,4,6,8,10], # Whole tone(14) | ||||||||||||||||||||||||||||||||||||||||||
| 49 | [0,3,4,7,8,11], # Augmented (15) | ||||||||||||||||||||||||||||||||||||||||||
| 50 | [0,2,3,6,7,8,11], # Hungarian minor (16) | ||||||||||||||||||||||||||||||||||||||||||
| 51 | [0,3,6,9], # 3 semitone (dimished arpeggio) (17) | ||||||||||||||||||||||||||||||||||||||||||
| 52 | [0,4,8], # 4 semitone (augmented arpeggio) (18) | ||||||||||||||||||||||||||||||||||||||||||
| 53 | [0,1,3,5,7,8,11], # Neapolitan minor (19) | ||||||||||||||||||||||||||||||||||||||||||
| 54 | [0,1,3,5,7,9,11], # Neapolitan major (20) | ||||||||||||||||||||||||||||||||||||||||||
| 55 | [0,1,3,6,7,8,11], # Todi (Indian) (21) | ||||||||||||||||||||||||||||||||||||||||||
| 56 | [0,1,4,6,7,9,11], # Marva (Indian) (22) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | [0,1,4,5,6,8,11], # Persian (23) | ||||||||||||||||||||||||||||||||||||||||||
| 58 | [0,1,4,5,6,9,10], # Oriental (24) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | [0,2,3,6,7,9,10], # Romanian (25) | ||||||||||||||||||||||||||||||||||||||||||
| 60 | [0,1,3,7,10], # Pelog (Balinese) (26) | ||||||||||||||||||||||||||||||||||||||||||
| 61 | [0,1,5,6,10], # Iwato (Japanese) (27) | ||||||||||||||||||||||||||||||||||||||||||
| 62 | [0,2,3,7,8], # Hirajoshi (Japanese) (28) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | [0,2,5,7,10], # Egyptian (29) | ||||||||||||||||||||||||||||||||||||||||||
| 64 | [0,3,5,7,10], # Pentatonic Minor (30) | ||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 14 | ▶ | sub get_scale_nums { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_scale_nums: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 14 | my ($mode,$descending) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 14 | $mode = _get_mode($mode); | |||||||||||||||||||||||||||||||||||||||||
| 70 | 14 | my @dists = @{$scales[$mode-1]}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 14 | ▶ | if ($descending && $mode == 9) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$descending and $mode == 9
MC/DC0%0/2
$descending and $mode == 9
$descending
$mode == 9
Truth table66%2/3
A and B
A= $descendingB= $mode == 9
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $dists[5]-- ;$dists[6]--; | |||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 14 | ▶ | ($descending) ? reverse @dists : @dists; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub get_scale_offsets { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_scale_offsets: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my @scale = get_scale_notes(@_); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my %key_alts = qw(C 0 D 0 E 0 F 0 G 0 A 0 B 0); | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | foreach (@scale) { | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | $key_alts{$_}++ if s/#//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $key_alts{$_}-- if s/b//; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | %key_alts; | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 23 | ▶ | sub _get_mode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_mode: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | 23 | ▶ | my $mode = shift() || 1; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() || 1
MC/DC100%1/1
shift() || 1
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 23 | $mode =~ s/[^a-zA-Z0-9]//g; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 23 | ▶ | $mode = $modes{lc($mode)} unless $mode =~/^[0-9]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 23 | ▶ | ($mode && ($mode <= @scales)) ? $mode : 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$mode and $mode <= @Music::Scales::scales
MC/DC0%0/2
$mode and $mode <= @Music::Scales::scales
$mode
$mode <= @Music::Scales::scales
Truth table33%1/3
A and B
A= $modeB= $mode <= @Music::Scales::scales
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 46 | ▶ | sub _note_to_num { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_note_to_num: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 46 | my $note = shift(); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 46 | my %note2num = ('A','0','A#','1','BB','1','B','2','C','3','C#','4','DB','4','D','5','D#','6','EB','6','E','7','F','8','F#','9','GB','9','G','10','G#','11','AB','11'); | |||||||||||||||||||||||||||||||||||||||||
| 97 | 46 | ▶ | return $note if ($note =~/^[0-9]+$/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 46 | ▶ | (defined $note2num{uc($note)}) ? $note2num{uc($note)} : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | 3 | ▶ | sub _note_to_MIDI { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_note_to_MIDI: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 102 | 3 | my ($note,$octave) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 103 | 3 | ((_note_to_num($note)+9) % 12) + (12 * ++$octave ); | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 3 | ▶ | sub get_scale_MIDI { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_scale_MIDI: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 3 | my ($note,$octave,$mode,$descending) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 3 | my $basenum = _note_to_MIDI($note,$octave); | |||||||||||||||||||||||||||||||||||||||||
| 109 | 3 | return map {$basenum + $_} get_scale_nums($mode,$descending); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 4 | ▶ | sub get_scale_PDL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_scale_PDL: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | 4 | my ($note,$octave,$mode,$descending,$keypref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | _scale_to_PDL($octave,get_scale_notes($note,$mode,$descending,$keypref)); | |||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 9 | ▶ | sub get_scale_notes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_scale_notes: called CC=22 SCAR=31.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | my ($keynote,$mode,$descending,$keypref) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | my @notes = ('A'..'G'); | |||||||||||||||||||||||||||||||||||||||||
| 120 | 9 | my @nums = (2,1,2,2,1,2,2); | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 9 | $keynote =~ s/^[a-z]/\u$&/; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 9 | ▶ | $keypref='' unless defined $keypref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 9 | my $keynum = _note_to_num(uc($keynote)); | |||||||||||||||||||||||||||||||||||||||||
| 125 | 9 | $mode = _get_mode($mode); | |||||||||||||||||||||||||||||||||||||||||
| 126 | 9 | my @dists = get_scale_nums($mode,$descending); | |||||||||||||||||||||||||||||||||||||||||
| 127 | 9 | ▶ | @dists = reverse @dists if $descending; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 9 | my @scale = map {($_+$keynum-$dists[0])%12} @dists; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 9 | ▶ | $keypref='b' if (!$keypref && $descending && $mode == 12); #prefer flat descending chromatic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $keypref and $descending and $mode == 12
not $keypref and $descending
MC/DC66%2/3
not $keypref and $descending and $mode == 12
not $keypref
$descending
$mode == 12
Truth table75%3/4
not(A) and B and C
A= not $keyprefB= $descendingC= $mode == 12
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 9 | my %num2note = (0,'A',1,'A#',2,'B',3,'C',4,'C#',5,'D',6,'D#',7,'E',8,'F',9,'F#',10,'G',11,'G#'); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 9 | ▶ | %num2note = (0,'A',1,'Bb',2,'B',3,'C',4,'Db',5,'D',6,'Eb',7,'E',8,'F',9,'Gb',10,'G',11,'Ab') if (($keypref eq 'b') || ($keynote =~ /.b/i)); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$keypref eq "b" or $keynote =~ /.b/i
MC/DC100%2/2
$keypref eq "b" or $keynote =~ /.b/i
$keypref eq "b"
$keynote =~ /.b/i
Truth table100%3/3
A or B
A= $keypref eq "b"B= $keynote =~ /.b/i
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 9 | my @mscale = $keynote; | |||||||||||||||||||||||||||||||||||||||||
| 134 | 9 | ▶ | if (@scale > 7) { # we're not bothered by niceties, so just convert | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 2 | @mscale = map {$num2note{$_}} @scale; | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 7 | ▶ | $keynote = $num2note{$keynote} if $keynote =~/^[0-9]+$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | 7 | my $kk = $keynote; $kk =~ s/b|\#//; $kk = ord($kk) - ord('A'); | |||||||||||||||||||||||||||||||||||||||||
| 140 | 7 | foreach(0..$kk-1) {# rotate to keynote | |||||||||||||||||||||||||||||||||||||||||
| 141 | 27 | push @notes,shift(@notes); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 27 | push @nums,shift(@nums); | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 7 | push @notes,shift(@notes); | |||||||||||||||||||||||||||||||||||||||||
| 145 | 7 | shift(@dists); | |||||||||||||||||||||||||||||||||||||||||
| 146 | 7 | my $cu = shift(@nums); | |||||||||||||||||||||||||||||||||||||||||
| 147 | 7 | ▶ | $cu++ if ($keynote =~ /b/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | 7 | ▶ | $cu-- if ($keynote =~ /#/); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | 7 | foreach (@dists) { | |||||||||||||||||||||||||||||||||||||||||
| 150 | 36 | my $m = $_ - $cu; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 36 | my $ns = shift(@nums); | |||||||||||||||||||||||||||||||||||||||||
| 152 | 36 | push @nums,$ns; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 36 | my $n = shift(@notes); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 36 | push @notes,$n; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 36 | ▶ | while (abs($m) > 2 || (@scale < 7 && abs($m) >= $ns)) { # step up/down notes, 'reducing' flats/sharps | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
abs $m > 2 or @scale < 7 and abs $m >= $ns
@scale < 7 and abs $m >= $ns
MC/DC66%2/3
abs $m > 2 or @scale < 7 and abs $m >= $ns
abs $m > 2
@scale < 7
abs $m >= $ns
Truth table75%3/4
A or B and C
A= abs $m > 2B= @scale < 7C= abs $m >= $ns
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | 6 | $n = shift(@notes); push @notes,$n; | |||||||||||||||||||||||||||||||||||||||||
| 157 | 6 | ▶ | if ($m > 0) {$m -= $ns;$cu += $ns } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | elsif ($m < 0){$m += $ns;$cu -= $ns} | |||||||||||||||||||||||||||||||||||||||||
| 159 | 6 | $ns = shift(@nums); push @nums,$ns; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 36 | ▶ | $n .= '#' x $m if ($m > 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | 36 | ▶ | $n .= 'b' x abs($m) if ($m < 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 36 | push @mscale,$n; | |||||||||||||||||||||||||||||||||||||||||
| 164 | 36 | $cu += $ns; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||
| 167 | 9 | ▶ | if ($descending) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | @mscale = reverse @mscale; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | unshift @mscale,pop(@mscale); | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 9 | @mscale; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | ▶ | sub is_scale { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_scale: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | my $name = shift(); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 6 | $name =~ s/[^a-zA-Z0-9]//g; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | ▶ | return exists $modes{lc $name} ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 4 | ▶ | sub _scale_to_PDL { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_scale_to_PDL: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | my ($octave,@scale)=@_; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 4 | my @result; | |||||||||||||||||||||||||||||||||||||||||
| 184 | my $descending; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | my $n1 = _note_to_num($scale[0]); | |||||||||||||||||||||||||||||||||||||||||
| 186 | 4 | my $n2 = _note_to_num($scale[1]); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | ▶ | if ($n2 < $n1 && ($n1-$n2 < 5)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$n2 < $n1 and $n1 - $n2 < 5
MC/DC100%2/2
$n2 < $n1 and $n1 - $n2 < 5
$n2 < $n1
$n1 - $n2 < 5
Truth table100%3/3
A and B
A= $n2 < $n1B= $n1 - $n2 < 5
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | $descending = 1; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | @scale = reverse @scale; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | my $last = (_note_to_num($scale[0]) + 9) % 12; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | foreach (@scale) { | |||||||||||||||||||||||||||||||||||||||||
| 193 | 22 | my $n = (_note_to_num($_) + 9) % 12; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 22 | ▶ | $octave++ if ($last > $n); #switched over octave at 'c' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 22 | s/\#/s/g; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 22 | s/b/f/g; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 22 | push @result,lc($_).$octave; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 22 | $last = $n; | |||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | ▶ | @result = reverse @result if $descending; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 4 | @result; | |||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | __END__ | ||||||||||||||||||||||||||||||||||||||||||