Skip to content

Instantly share code, notes, and snippets.

@peschwa
Last active May 6, 2016 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peschwa/f60774251b53e47496a0167ffd7265f7 to your computer and use it in GitHub Desktop.
Save peschwa/f60774251b53e47496a0167ffd7265f7 to your computer and use it in GitHub Desktop.
use Audio::PortMIDI;
use Audio::MIDI::Note;
use Music::Helpers;
sub MAIN(Str :$mode = 'major', Str :$root = 'C') {
my $Mode = Mode.new(:$mode, root => ::($root));
my $pm = Audio::PortMIDI.new;
my $stream = $pm.open-output(3, 32);
my $keys = Audio::MIDI::Note.new(:tempo(120), :$stream, :value(1), :velocity(85), :channel(0));
my @chords = $Mode.chords.eager.grep({ 2 < $_.root.octave < 4 }).pick(4);
my &chordloop = sub ($note, @inner-chords is copy) {
.Str.say for @inner-chords;
$note.play(@inner-chords[$++ % *].notes.map(~*).eager)
};
my $key-promise = start { $keys.riff(&chordloop.assuming(*, my @ = @chords)) for ^8 };
@chords = do [ .^can('variant-methods') ?? ($_.variant-methods.pick)($_) !! $_ for @chords ];
await $key-promise;
$key-promise = start { $keys.riff(&chordloop.assuming(*, @chords)) for ^8 };
await $key-promise;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment