-
Notifications
You must be signed in to change notification settings - Fork 5
/
cadences
90 lines (76 loc) · 2.26 KB
/
cadences
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env perl
use strict;
use warnings;
use Music::Cadence; # https://metacpan.org/release/Music-Cadence
use MIDI::Util qw(midi_format setup_score); # https://metacpan.org/release/MIDI-Util
use Music::Chord::Note;
use Music::Scales;
use constant M => 'major';
my $bpm = shift || 100;
my $note = shift || 'C'; # Bb, C\#, etc.
my $name = shift || M; # major or minor
my @scale = get_scale_notes($note, $name);
my $cn = Music::Chord::Note->new;
my @chords = (
[$cn->chord($scale[0] . ($name eq M ? '' : 'm'))],
[$cn->chord($scale[1] . ($name eq M ? 'm' : 'dim'))],
[$cn->chord($scale[2] . ($name eq M ? 'm' : ''))],
[$cn->chord($scale[3] . ($name eq M ? '' : 'm'))],
[$cn->chord($scale[4] . ($name eq M ? '' : 'm'))],
[$cn->chord($scale[5] . ($name eq M ? 'm' : ''))],
[$cn->chord($scale[6] . ($name eq M ? 'dim' : ''))],
);
@chords = map { [ midi_format(@$_) ] } @chords;
my $half = 'hn';
my $whole = 'wn';
my $mc = Music::Cadence->new(
key => $note,
scale => $name,
octave => 4,
);
my $score = setup_score( bpm => $bpm );
A();
A();
$score->n( $whole, @{ $chords[0] } );
$score->n( $whole, @{ $chords[0] } );
$score->write_score("$0.mid");
sub A {
a1( 0, [1,2] );
a1( 1, [4,2] );
a2();
}
sub a1 {
my ( $i, $degrees ) = @_;
for my $n ( @$degrees ) {
my $cadence = $mc->cadence(
type => 'deceptive',
variation => ($n % 2 ? 1 : 2),
);
@$cadence = map { [ midi_format(@$_) ] } @$cadence;
$score->n( $half, @$_ ) for @$cadence;
$cadence = $mc->cadence(
type => 'half',
leading => $n,
);
@$cadence = map { [ midi_format(@$_) ] } @$cadence;
$score->n( $whole, @$_ ) for @$cadence;
}
if ( $i % 2 == 0 ) {
$score->n( $whole, @{ $chords[2] } );
$score->n( $whole, @{ $chords[5] } );
}
else {
$score->n( $whole, @{ $chords[5] } );
$score->n( $whole, @{ $chords[2] } );
}
}
sub a2 {
my $cadence = $mc->cadence(
type => 'imperfect',
inversion => { 2 => 1 },
);
@$cadence = map { [ midi_format(@$_) ] } @$cadence;
$score->n( $whole, @$_ ) for @$cadence;
$score->n( $whole, @{ $chords[2] } );
$score->n( $whole, @{ $chords[1] } );
}