-
-
Save jeaye/191590c5d1d2505c5ca5ced689aaf4a7 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
#import Sporth | |
#import Math | |
110 :=> const float bpm; | |
(60.0 / bpm) :: second :=> const dur t; | |
[0, 1, 5, 7, 8] :=> const int scale[]; | |
fun void loop_me(const int root) { | |
var int stp; | |
var int nbars; | |
var int block; | |
var Sporth s ~> dac; | |
s.parse(#"0 p 0.01 port mtof 1 p 0.003 | |
port 1 1 2 p 0.01 port fm 0.5 * | |
dup dup 0.94 10000 revsc drop 0.1 * +"#); | |
s.p(1, 0.2); | |
root :=> var int base; | |
while(true) { | |
if(stp == 0) { | |
s.p(1, 0.4); | |
nbars++; | |
} else | |
s.p(1, 0.4); | |
if(nbars > block) { | |
if(base == root) | |
53 => base; | |
else | |
60 => base; | |
1 => nbars; | |
} | |
s.p(0, base + scale[stp] + 12 * Math.rand2(-1, 1)); | |
s.p(2, Math.rand2f(0.1, 3)); | |
0.25::t => now; | |
(stp + 1) % scale.size() :=> stp; | |
} | |
} | |
spork loop_me(60); | |
spork loop_me(36); | |
minute => now; |
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
#import RtMidi | |
#! open a MIDI output device | |
fun RtMidi.In open(const string name) { | |
#! get names of all available devices | |
RtMidi.In.names() :=> const auto names; | |
#! check full match | |
foreach(i, a: names) { | |
if(name == a) | |
return new RtMidi.In(i); | |
} | |
#! check partial match | |
foreach(i, a: names) { | |
if(a.find(name) > -1) | |
return new RtMidi.In(i); | |
} | |
<<< "${ name } not found. Opening virtual device" >>>; | |
return new RtMidi.In(name); | |
} | |
#! read incoming messages | |
fun void read(const RtMidi.In min) { | |
while(true) { | |
min => now; | |
var int status; | |
var int data1; | |
var int data2; | |
while(min.read(status, data1, data2)) | |
<<< "${status} ${data1} ${data2}" >>>; | |
} | |
} | |
"Launch" => open :=> const auto min => read; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment