forked from ology/Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
possible-reggae
77 lines (68 loc) · 1.82 KB
/
possible-reggae
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
#!/usr/bin/env perl
use strict;
use warnings;
use lib map { "$ENV{HOME}/sandbox/$_/lib" } qw(MIDI-Chord-Guitar MIDI-Drummer-Tiny MIDI-Util);
use MIDI::Drummer::Tiny;
use MIDI::Chord::Guitar;
use MIDI::Util qw(set_chan_patch);
my $d = MIDI::Drummer::Tiny->new(
file => $0 . '.mid',
bpm => 120,
bars => 8,
);
$d->score->synch(
\&drums,
\&rhythm,
);
$d->write;
sub drums {
$d->count_in(1);
for my $i (1 .. 4) {
my $j = 0;
for my $n (1 .. $d->bars * 4) {
if ($n % 2 == 0) {
$d->note($d->triplet_eighth, $d->closed_hh);
$d->rest($d->triplet_eighth);
$d->note($d->triplet_eighth, $d->closed_hh);
}
else {
if ( $j % 2 == 0 ) {
$d->note($d->quarter, $d->closed_hh, $d->kick);
}
else {
$d->note($d->quarter, $d->closed_hh, $d->snare);
}
$j++;
}
}
}
}
sub rhythm {
set_chan_patch($d->score, 0, 24);
my $mcg = MIDI::Chord::Guitar->new(voicing_file => "$ENV{HOME}/sandbox/MIDI-Chord-Guitar/share/midi-guitar-chord-voicings.csv");
my $Dm = $mcg->transform('D3', 'm', 3);
my $Am = $mcg->transform('A2', 'm', 2);
my $G = $mcg->transform('G2', '', 3);
$d->rest($d->whole);
for my $i (1 .. 4) {
for my $n (1 .. $d->bars) {
if ($n == 3 || $n == 4 || $n == 7) {
phrase($Am);
}
elsif ($n == 8) {
phrase($G);
}
else {
phrase($Dm);
}
}
}
}
sub phrase {
my ($notes) = @_;
$d->rest($d->quarter);
$d->note($d->eighth, @$notes);
$d->rest($d->dotted_quarter);
$d->note($d->eighth, @$notes);
$d->rest($d->eighth);
}