Created
June 6, 2015 22:15
-
-
Save RemyPorter/23e7234d89d9a19e576d to your computer and use it in GitHub Desktop.
Simple, event-driven conductor for ChucK
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
public class Conductor { | |
float interval; | |
int divs; | |
int divsPerM; | |
fun void setTiming(float bpm, int subdivs, int measure) { | |
bpm / subdivs / 60 => interval; | |
subdivs => divs; | |
subdivs * measure => divsPerM; | |
} | |
Event subdiv; | |
Event beat; | |
Event measure; | |
fun Event divisions() { return subdiv; } | |
fun Event beats() { return beat; } | |
fun Event measures() { return measure; } | |
fun void run() { | |
0 => int i; | |
while (true) { | |
subdiv.broadcast(); | |
if (i % divs == 0) beat.broadcast(); | |
if (i % divsPerM == 0) measure.broadcast(); | |
i++; | |
interval::second => 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
SinOsc beats => ADSR benv => dac; | |
SinOsc measures => ADSR menv => dac; | |
SinOsc divs => ADSR denv => dac; | |
Std.mtof(69) => beats.freq; | |
Std.mtof(61) => measures.freq; | |
Std.mtof(52) => divs.freq; | |
Conductor c; | |
(60,4,4) => c.setTiming; | |
fun void hear(Event evt, ADSR env) { | |
while (true) { | |
evt => now; | |
env.keyOn(); | |
0.25::second => now; | |
env.keyOff(); | |
} | |
} | |
spork ~ hear(c.beats(), benv); | |
spork ~ hear(c.measures(), menv); | |
spork ~ hear(c.divisions(), denv); | |
spork ~ c.run(); | |
while(true) { | |
1::samp => now; | |
me.yield(); | |
} |
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
Machine.add(me.dir() + "/beat.ck"); | |
Machine.add(me.dir() + "/beattest.ck"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment