forked from ology/Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
synch-oo
81 lines (62 loc) · 1.5 KB
/
synch-oo
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
#!/usr/bin/env perl
use strict;
use warnings;
use MIDI::Simple;
use Music::Chord::Note;
use List::Util qw( shuffle );
my $bars = shift || 4;
my $m = MIDI::Simple->new_score();
$m->set_tempo(700_000); # 1 qn => .5 seconds (500,000 microseconds)
my @subs = ( \&hihat, \&kick, \&snare, \&chords, \&pattern );
my $measure = 0;
$m->synch(@subs) for 1 .. $bars;
$m->write_score("$0.mid");
sub hihat {
my $self = shift;
$self->noop('c9', 'fff', 'n42', 'qn');
$self->n for 1 .. 4;
}
sub kick {
my $self = shift;
$self->noop('c9', 'fff', 'n35', 'qn');
$self->n;
$self->r;
$self->n('en');
$self->n;
$self->r;
}
sub snare {
my $self = shift;
$self->noop('c9', 'fff', 'n38', 'qn');
$self->r;
$self->n;
$self->r;
$self->n;
}
sub pattern {
my $self = shift;
my @phrase = qw(Ds5 As4 D5 G4 Ds4 Ds4 As4 G4);
$self->patch_change(0, 2);
$self->noop('c0', 'fff', 'en');
$self->n($_) for shuffle @phrase[0 .. 4];
if ( $measure++ % 2 ) {
$self->n($_) for shuffle @phrase[5 .. 7];
}
}
sub chords {
my $self = shift;
my $c = Music::Chord::Note->new;
my @phrase;
my @progression = $measure++ % 2
? qw( Gm C Dm Gm )
# : qw( Gm F Gm C );
: qw( Gm Dm F Gm );
for my $chord ( @progression ) {
my @chord = $c->chord($chord);
s/#/s/ for @chord;
push @phrase, \@chord;
}
$self->patch_change(0, 2);
$self->noop('c0', 'o4', 'f', 'qn');
$self->n(@$_) for @phrase;
}