Created
May 20, 2016 13:52
-
-
Save peschwa/fc0c9bbfbcfafa55faed33b5971c80ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6.c; | |
use Music::Helpers; | |
sub MAIN(:$mode = 'major', :$root = C, :$tempo = 120, :$arrangement = 'ABA', :$outfile = 'song.pl6') { | |
my \prologue = qq:to/END/; | |
use Audio::PortMIDI; | |
use Music::Helpers; | |
use Audio::MIDI::Note; | |
my \$tempo = $tempo; | |
my \$pm = Audio::PortMIDI.new; | |
my \$stream = \$pm.open-output(\$pm.default-output-device, 32); | |
my \$note = Audio::MIDI::Note.new(:\$tempo, :\$stream, :value(1), :100velocity); | |
\$note | |
END | |
my \epilogue = qq:to/END/; | |
\$stream.close; | |
END | |
my $mode-obj = Mode.new(:$mode, :$root); | |
my %parts = %($arrangement.comb.antipairs); | |
my @four-bar-pats = [ 2, 2], | |
[ 2, 1, 1], | |
[ 2, 1, .5, .5], | |
[ 1, 1, 1, 1], | |
[ 1, 1, 1, .5, .5], | |
[ 2, .5, .5, .5, .5], | |
[ 1, 1, .5, .5, .5, .5], | |
[ 1, .5, .5, .5, .5, .5, .5], | |
[.5, .5, .5, .5, .5, .5, .5, .5] | |
; | |
my %pats{Any}; | |
for @four-bar-pats[^(*-2)] -> @raw-pat { | |
for @raw-pat.permutations -> $pat { | |
%pats{$pat} = 1; | |
} | |
} | |
for %parts.keys { | |
%parts{$_} = my % = (pattern => %pats.keys.pick, chords => []); | |
} | |
for %parts -> %part { | |
for ^@(%part.value<pattern>) { | |
%part.value<chords>.push: $mode-obj.chords.grep({ .root.octave == 4 }).pick; | |
} | |
} | |
my $outfh = $outfile.IO.open(:w); | |
$outfh.print: prologue; | |
for $arrangement.comb -> $part { | |
for %parts{$part} -> %part { | |
for ^@(%part<chords>) { | |
$outfh.say: ".play(<{%part<chords>[$_].notes.map(~*).eager}>, {%part<pattern>[$_]})" | |
} | |
} | |
} | |
$outfh.close; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment