forked from ology/Music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
primes
39 lines (31 loc) · 849 Bytes
/
primes
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
#!/usr/bin/env perl
use strict;
use warnings;
###
#
# Play the prime numbers modulo the number of notes of the given scale.
#
# Example:
# perl primes 1000 major 30 95 3; timidity primes.mid
#
###
use Math::Prime::XS qw(primes);
use lib map { "$ENV{HOME}/sandbox/$_/lib" } qw(MIDI-Util);
use MIDI::Util qw(setup_score);
use Music::Scales qw(get_scale_MIDI);
my $limit = shift || die "Usage: perl $0 limit scale\n";
my $name = shift || 'chromatic';
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, $name);
my $i = 0;
for my $p (primes($limit)) {
$i++;
my $mod = $p % @scale;
my $note = $scale[$mod];
print "$i. P: $p, Mod: $mod, Note: $note\n";
$score->n('qn', $note);
}
$score->write_score("$0.mid");