-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcombi-duras.pl
More file actions
34 lines (29 loc) · 809 Bytes
/
combi-duras.pl
File metadata and controls
34 lines (29 loc) · 809 Bytes
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
#!/usr/bin/env perl
use strict;
use warnings;
use Algorithm::Combinatorics qw(variations_with_repetition);
use Getopt::Long qw(GetOptions);
use List::Util qw(min sum0);
use MIDI::Util qw(dura_size);
my %opt = (
size => 4, # number of beats
pool => 'dqn qn den en dsn sn', # possible phrase durations
);
GetOptions(\%opt,
'size=i',
'pool=s',
);
$opt{pool} = [ split /\s+/, $opt{pool} ];
my @durations = map { dura_size($_) } $opt{pool}->@*;
my $grain = $opt{size} / min(@durations);
my $n = 1;
for my $take (1 .. $grain) {
my $i = variations_with_repetition($opt{pool}, $take);
while (my $c = $i->next) {
my @durations = map { dura_size($_) } @$c;
my $sum = sum0(@durations);
next unless $sum == $opt{size};
print "$n. @$c\n";
$n++;
}
}