-
Notifications
You must be signed in to change notification settings - Fork 5
/
blue-gene
168 lines (145 loc) · 4.59 KB
/
blue-gene
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper::Compact qw(ddc);
use List::Util qw(any);
use Music::Bassline::Generator;
use MIDI::Chord::Guitar;
use MIDI::Drummer::Tiny;
use MIDI::Util qw(set_chan_patch);
use Music::Duration::Partition;
use Music::Scales qw(get_scale_MIDI);
use Music::VoiceGen;
my $bpm = shift || 90;
my $tscale = shift || 'pentatonic';
my $bscale = shift || 'major';
my $note = 'Bb';
my $bass_patch = 35; # fretless bass=35
my $melody_patch = 66; # tenor sax=66
my $chord_patch = 4; # electric piano=4
my $d = MIDI::Drummer::Tiny->new(
file => $0 . '.mid',
bpm => 100,
bars => 4,
);
my $channel = 0; # Internal increment
$d->score->synch(
\&drums,
\&bass,
\&chords,
\&melody,
);
$d->write;
sub drums {
$d->count_in(1);
$d->metronome44swing($d->bars * $d->bars);
}
sub bass {
set_chan_patch($d->score, $channel++, $bass_patch);
my $modal = Music::Bassline::Generator->new(
verbose => 1,
guitar => 1,
tonic => 1,
modal => 1,
keycenter => $note,
);
my $tandem = Music::Bassline::Generator->new(
verbose => 1,
guitar => 1,
tonic => 1,
scale => sub { $_[0] =~ /^[A-G][#b]?m/ ? 'pminor' : 'pentatonic' },
);
$d->rest($d->whole); # while counting-in
for my $n (1 .. 2) {
_walk($modal, 'Bb', 4, 'Bb7');
_walk($modal, 'Bb7', 4, 'Eb');
_walk($modal, 'Eb', 4, 'Eb9');
_walk($modal, 'Eb9', 2, 'D7#9');
_walk($tandem, 'D7#9', 2, 'BbM7');
_walk($modal, 'BbM7', 4, 'DbM7');
_walk($modal, 'DbM7', 4, 'Cm7');
_walk($modal, 'Cm7', 4, 'Gm7');
_walk($modal, 'Gm7', 2, 'Ab7b5');
_walk($tandem, 'Ab7b5', 2, 'Bb');
}
}
sub _walk {
my ($bassline, $chord, $n, $next_chord) = @_;
my $notes = $bassline->generate($chord, $n, $next_chord);
$d->note('qn', $_) for @$notes;
}
sub chords {
set_chan_patch($d->score, $channel++, $chord_patch);
my $mcg = MIDI::Chord::Guitar->new(
# Local voicings for me. Unneeded for everyone else!
voicing_file =>
"$ENV{HOME}/sandbox/MIDI-Chord-Guitar/share/midi-guitar-chord-voicings.csv"
);
# 1
my $Bfmaj7 = $mcg->transform('Bb2', 'maj7', 3);
my $Dfmaj7 = $mcg->transform('Db3', 'maj7', 1);
my $Cm7 = $mcg->transform('C3', 'm7', 1);
my $Gm7 = $mcg->transform('G2', 'm7', 2);
my $Af7f5 = $mcg->transform('Ab2', '7b5', 0);
# 2
my $Bf = $mcg->transform('Bb2', '', 3);
my $Bf7 = $mcg->transform('Bb2', '7', 3);
my $Ef = $mcg->transform('Eb3', '', 1);
my $Ef9 = $mcg->transform('Eb3', '9', 0);
my $D7s9 = $mcg->transform('D3', '7#9', 0);
$d->rest($d->whole); # while counting-in
for my $n (1 .. $d->bars) {
if ($n % 2 == 0) {
$d->note($d->whole, @$Bfmaj7);
$d->note($d->whole, @$Dfmaj7);
$d->note($d->whole, @$Cm7);
$d->note($d->half, @$Gm7);
$d->note($d->half, @$Af7f5);
}
else {
$d->note($d->whole, @$Bf);
$d->note($d->whole, @$Bf7);
$d->note($d->whole, @$Ef);
$d->note($d->half, @$Ef9);
$d->note($d->half, @$D7s9);
}
}
}
sub melody {
set_chan_patch($d->score, $channel++, $melody_patch);
my $slower = Music::Duration::Partition->new(
size => 4,
pool => [qw/hn dqn qn den en/],
# weights => [1, 1, 2, 2, 2],
groups => [1, 2, 1, 2, 1],
);
my @motifs = map { $slower->motif } 1 .. 8;
print 'Melody motifs: ', ddc(\@motifs);
# my $faster = Music::Duration::Partition->new(
# size => 4,
# pool => [qw/dqn qn den en dsn sn/],
# weights => [1, 2, 2, 2, 2, 3],
# groups => [1, 1, 1, 2, 1, 4],
# );
# my @motifs = map { $faster->motif } 1 .. 8;
# print 'Melody motifs: ', ddc(\@motifs);
my @pitches = (
get_scale_MIDI($note, 2, $tscale),
get_scale_MIDI($note, 3, $tscale),
# get_scale_MIDI($note, 4, $tscale),
);
my @intervals = qw(-4 -3 -2 -1 1 2 3 4);
my $voice = Music::VoiceGen->new(
pitches => \@pitches,
intervals => \@intervals,
);
my @notes = map { [ map { $voice->rand } @$_ ] } @motifs;
print 'Melody pitches: ', ddc(\@notes);
$d->rest($d->whole); # while counting-in
for my $n (1 .. $d->bars * $d->bars) {
my $index = int rand @motifs;
my $motif = $motifs[$index];
my $notes = $notes[$index];
$slower->add_to_score($d->score, $motif, $notes);
}
}