forked from ology/Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oeis-midi
43 lines (33 loc) · 995 Bytes
/
oeis-midi
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
#!/usr/bin/env perl
###
# Play an OEIS sequence modulo the number of notes of the given scale.
#
# Example:
# perl oeis-midi 40 128 major 30 95 3; timidity oeis-midi.mid
#
# 40=Primes 45=Fibonacci
###
use strict;
use warnings;
# Use local libraries
use lib map { "$ENV{HOME}/sandbox/$_/lib" } qw(MIDI-Util);
use MIDI::Util qw(setup_score);
use Music::Scales qw(get_scale_MIDI);
use OEIS qw(oeis);
my $oeis = shift || die "Usage: perl $0 oeis-number [how-many scale bpm patch octave]\n";
my $limit = shift || 64;
my $scale = shift || 'major';
my $bpm = shift || 300;
my $patch = shift || 0;
my $octave = shift || 4;
my $score = setup_score(bpm => $bpm, patch => $patch);
my @scale = get_scale_MIDI('C', $octave, $scale);
my $i = 0;
for my $n (oeis($oeis, $limit)) {
my $mod = $n % @scale;
my $note = $scale[$mod];
printf "%d. n: %d, mod %d: %d, note: %d\n",
++$i, $n, scalar(@scale), $mod, $note;
$score->n('qn', $note);
}
$score->write_score("$0.mid");