Created
March 31, 2016 14:45
-
-
Save peschwa/a8fabd272c6c747fde08f714bdb0195b 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
$ perl6 -I. clock.pl6 | |
0000011011011010100010011001010100000101101001101000011011011111 | |
0000011011011010100010011001010100001011100111000110011111011111 | |
0000011011011010100010011001010101000001010000010101000011011111 | |
0000011011011010100010011001010101000111001101110011000111011111 | |
0000011011011010100010011001011101011001101100100110101011011111 | |
0000011011011010100010011001010101000111001101110011000111011111 | |
0000011011011010100010011001010101000001010000010101000011011111 | |
0000011011011010100010011001010100001011100111000110011111011111 | |
0000011011011010100010011001010100000101101001101000011011011111 | |
0000011011011010100010011001010100001011100111000110011111011111 | |
0000011011011010100010011001010101000001010000010101000011011111 | |
0000011011011010100010011001010101000111001101110011000111011111 | |
0000011011011010100010011001011101011001101100100110101011011111 | |
0000011011011010100010011001010101000111001101110011000111011111 | |
0000011011011010100010011001010101000001010000010101000011011111 | |
0000011011011010100010011001010100001011100111000110011111011111 | |
0000011011011010100010011001010100000101101001101000011011011111 | |
0000011011011010100010011001010100001011100111000110011111011111 | |
^C |
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 Audio::PortMIDI; | |
use CircularArray; | |
my $pm = Audio::PortMIDI.new; | |
my $stream = $pm.open-output($pm.default-output-device.device-id, 32); | |
constant MfID = 0x7d; # Manufacturer ID 'Educational' | |
my $step = 1/((120/60)*2); | |
my CircularArray $nth; | |
{ | |
$_ = 0; | |
my @sig; | |
@sig.push($_++) while 0 fff 3; | |
@sig.push($_--) while 4 fff 1; | |
$nth .= new(storage => @sig); | |
} | |
react { | |
whenever Supply.interval($step) { | |
my $data = $nth[$++]; | |
# as per https://www.midi.org/specifications/item/table-1-summary-of-midi-message | |
# 11110000 - start system exclusive | |
# 01111101 - 'Educational' | |
# $data - the actual message | |
# 11110111 - end sysex | |
my $sysmsg = "11110000" ~ sprintf("%08b", MfID) ~ sprintf("%08b", $data) ~ "11110111"; | |
my $m = Audio::PortMIDI::Event.new(event => $sysmsg.Int); | |
say sprintf "%064b", $m.Int; | |
$stream.write($m); | |
} | |
} |
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
$ perl6 listener.pl6 | |
0000000000000000000010000111000100000000000000000110011111011111 | |
0000000000000000000010010110110000000000000000000101000011011111 | |
0000000000000000000010100110011100000000000000000011000111011111 | |
0000000000000000000010110110000100000000000000000110101011011111 | |
0000000000000000000011000101101100000000000000000011000111011111 | |
0000000000000000000011010101010100000000000000000101000011011111 | |
0000000000000000000011100100111100000000000000000110011111011111 | |
# one missing here | |
0000000000000000000100000100010000000000000000000110011111011111 | |
0000000000000000000100010011111100000000000000000101000011011111 | |
0000000000000000000100100011100100000000000000000011000111011111 | |
0000000000000000000100110011001100000000000000000110101011011111 | |
0000000000000000000101000010110100000000000000000011000111011111 | |
0000000000000000000101010010011100000000000000000101000011011111 | |
0000000000000000000101100010001000000000000000000110011111011111 | |
# same missing here | |
0000000000000000000110000001011000000000000000000110011111011111 |
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 Audio::PortMIDI; | |
my $pm = Audio::PortMIDI.new; | |
my $clock = $pm.open-input($pm.default-input-device.device-id, 32); | |
my $out = $pm.open-output($pm.default-output-device.device-id, 32); | |
my $code = supply { | |
# not sure this is a great idea... | |
whenever supply { emit $clock.poll while True } { | |
emit $clock.read(1) | |
} | |
} | |
react { | |
whenever $code -> $ev { | |
if $ev { | |
say sprintf "%064b", $ev[0].Int; | |
# if $ev[0].data-one == 0 { | |
# my $event-type = $++ %% 2 ?? NoteOn !! NoteOff; | |
# my $n = Audio::PortMIDI::Event.new(:$event-type, :channel(3), data-one => 49, data-two => 127); | |
# $out.write($n); | |
# } | |
} | |
} | |
} |
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
I'm only building an event of 32 bits. Should the event still contain 64, as it apparently does? | |
Where do those missing messages go..? | |
Is building messages and only passing :event maybe just a bad idea, because it's not really supported or is that just sysex? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment