-
Notifications
You must be signed in to change notification settings - Fork 5
/
five-four-durations
148 lines (126 loc) · 3.89 KB
/
five-four-durations
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
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper::Compact qw(ddc);
use MIDI::Drummer::Tiny;
use MIDI::Praxis::Variation 'diminution';
use MIDI::Util qw(set_chan_patch);
use Music::Scales;
use Music::VoiceGen;
use Music::Duration::Partition;
my $bpm = shift || 105;
my $note = shift || 'A';
my $bscale = shift || 'pminor';
my $tscale = shift || 'minor';
my $octave = 1;
my $beats = 5;
my $d = MIDI::Drummer::Tiny->new(
file => "$0.mid",
bpm => $bpm,
signature => '5/4',
kick => 'n36', # Override default patch
snare => 'n40', # "
);
$d->score->synch(
\&drums,
\&bass,
\&top,
);
$d->write;
sub bass {
set_chan_patch($d->score, 1, 35);
my $mdp = Music::Duration::Partition->new(
size => $beats,
pool => [qw/ hn qn /],
weights => [2, 1],
);
my $motif1 = $mdp->motif;
my $motif2 = $mdp->motif;
print 'Bottom motif #1: ', ddc($motif1);
print 'Bottom motif #2: ', ddc($motif2);
my @pitches = get_scale_MIDI($note, $octave, $bscale);
my @intervals = qw(-3 -2 -1 1 2 3);
my $voice = Music::VoiceGen->new(
pitches => \@pitches,
intervals => \@intervals,
);
my @notes1 = map { $voice->rand } @$motif1;
my @notes2 = map { $voice->rand } @$motif2;
print 'Bottom pitches #1: ', ddc(\@notes1);
print 'Bottom pitches #2: ', ddc(\@notes2);
for my $n (1 .. $d->bars * 2) {
for my $i (0 .. $#$motif1) {
$d->note($motif1->[$i], $n % 2 ? $notes1[$i] : $notes2[$i]);
}
for my $i (0 .. $#$motif2) {
$d->note($motif2->[$i], $n % 2 ? $notes1[$i] : $notes2[$i]);
}
}
for my $n (1 .. $d->bars / 2) {
$d->note($d->quarter, $pitches[0]);
$d->note($d->quarter, $pitches[0]);
$d->rest($d->eighth);
$d->note($d->quarter, $pitches[0]);
$d->note($d->quarter, $pitches[0]);
$d->rest($d->eighth);
}
}
sub top {
set_chan_patch($d->score, 0, 4);
my $mdp = Music::Duration::Partition->new(
size => $beats,
pool => [qw/ dqn qn en /],
# pool => [qw/ qn den en sn /],
# groups => [0, 0, 2, 2],
);
my $motif1 = $mdp->motif;
my $motif2 = $mdp->motif;
print 'Top motif #1: ', ddc($motif1);
print 'Top motif #2: ', ddc($motif2);
my @pitches = (
get_scale_MIDI($note, $octave + 1, $tscale),
get_scale_MIDI($note, $octave + 2, $tscale)
);
my @intervals = qw(-4 -3 -2 -1 1 2 3 4);
my $voice = Music::VoiceGen->new(
pitches => \@pitches,
intervals => \@intervals,
);
my @pitches2 = (
get_scale_MIDI($note, $octave + 2, $tscale),
get_scale_MIDI($note, $octave + 3, $tscale),
);
@intervals = qw(-2 -1 1 2);
my $voice2 = Music::VoiceGen->new(
pitches => \@pitches2,
intervals => \@intervals,
);
my @notes1 = map { $voice->rand } @$motif1;
my @notes2 = map { $voice->rand } @$motif1;
my @notes3 = map { $voice->rand } @$motif2;
my @notes4 = map { $voice2->rand } @$motif2;
print 'Top pitches #1: ', ddc(\@notes1);
print 'Top pitches #2: ', ddc(\@notes2);
print 'Top pitches #3: ', ddc(\@notes3);
print 'Top pitches #4: ', ddc(\@notes4);
for my $n (1 .. $d->bars * 2) {
for my $i (0 .. $#$motif1) {
$d->note($motif1->[$i], $n % 6 == 0 ? $notes4[$i] : $n % 2 ? $notes1[$i] : $notes2[$i]);
}
for my $i (0 .. $#$motif2) {
my @halved = diminution($motif2->[$i]);
$d->note($halved[0], $n % 4 == 0 ? $notes4[$i] : $notes3[$i]);
$d->rest($halved[0]);
}
}
for my $n (1 .. $d->bars / 2) {
$d->rest($d->quarter);
$d->note($d->quarter, $pitches[0]);
$d->rest($d->dotted_quarter);
$d->note($d->quarter, $pitches[0]);
$d->rest($d->eighth);
}
}
sub drums {
$d->metronome54($d->bars * 4 + 2);
}