-
Notifications
You must be signed in to change notification settings - Fork 5
/
perm-perm
105 lines (94 loc) · 3.13 KB
/
perm-perm
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
#!/usr/bin/env perl
use strict;
use warnings;
use lib '/Users/gene/sandbox/MIDI-Util/lib';
use MIDI::Util qw(setup_score);
use MIDI::Simple;
use Math::Combinatorics;
use List::Util qw( shuffle );
my $max = shift || 16; # Maximum notes to play
my $bpm = shift || 120;
my @treb_notes = qw( 0 Ds5 F5 As5 Bf5 ); # 0 = rest, Bf5, Cs5, Ds5, etc
my @treb_dura = qw( en en qn qn qn ); # sn, dsn, ddsn, tsn, etc
my @treb_volu = qw( mezzo mezzo mezzo mf mf ); # ppp pp p mp mezzo mf f ff fff
my @bass_notes = qw( Bf3 C3 C3 F3 G3 );
my @bass_dura = qw( qn qn qn qn qn );
my @bass_volu = qw( mf mf mf mf mf );
my @treb_combos = shuffle permute(@treb_notes);
my @treb_dura_combos = shuffle permute(@treb_dura);
my @treb_volu_combos = shuffle permute(@treb_volu);
my @bass_combos = shuffle permute(@bass_notes);
my @bass_dura_combos = shuffle permute(@bass_dura);
my @bass_volu_combos = shuffle permute(@bass_volu);
my $score = setup_score(
lead_in => 4,
patch => 69,
bpm => $bpm,
);
my $n = 0;
for my $i ( 0 .. @treb_combos - 1 ) {
for my $j ( 0 .. @{ $treb_combos[$i] } - 1 ) {
$n++;
last if $max && $n > $max;
printf "%2d. Treble: %s, %s, %s\n",
$n,
$treb_volu_combos[$i][$j],
$treb_dura_combos[$i][$j],
$treb_combos[$i][$j];
printf "\tBass: %s, %s, %s\n",
$bass_volu_combos[$i][$j],
$bass_dura_combos[$i][$j],
$bass_combos[$i][$j];
if ( $treb_dura_combos[$i][$j] eq $bass_dura_combos[$i][$j] ) {
if ( $treb_combos[$i][$j] && $bass_combos[$i][$j] ) {
$score->n(
$treb_volu_combos[$i][$j],
$treb_dura_combos[$i][$j],
$treb_combos[$i][$j],
$bass_combos[$i][$j]
);
}
elsif ( $treb_combos[$i][$j] ) {
$score->n(
$treb_volu_combos[$i][$j],
$treb_dura_combos[$i][$j],
$treb_combos[$i][$j]
);
}
elsif ( $bass_combos[$i][$j] ) {
$score->n(
$bass_volu_combos[$i][$j],
$bass_dura_combos[$i][$j],
$bass_combos[$i][$j]
);
}
else {
$score->r( $treb_dura_combos[$i][$j] );
}
}
else {
if ( $treb_combos[$i][$j] ) {
$score->n(
$treb_volu_combos[$i][$j],
$treb_dura_combos[$i][$j],
$treb_combos[$i][$j]
);
}
else {
$score->r( $treb_dura_combos[$i][$j] );
}
if ( $bass_combos[$i][$j] ) {
$score->n(
$bass_volu_combos[$i][$j],
$bass_dura_combos[$i][$j],
$bass_combos[$i][$j]
);
}
else {
$score->r( $bass_dura_combos[$i][$j] );
}
}
}
last if $max && $n > $max;
}
$score->write_score( $0 . '.mid' );