Difference between revisions of "Metronome.ck"
From CSWiki
Line 17: | Line 17: | ||
tempo.size(400,60); | tempo.size(400,60); | ||
tempo.position(0,0); | tempo.position(0,0); | ||
+ | tempo.displayFormat(tempo.integerFormat); | ||
tempo.name("tempo"); | tempo.name("tempo"); | ||
36 => tempo.value; | 36 => tempo.value; |
Latest revision as of 12:33, 14 November 2007
// A simple metronome for miniAudicle. // Jascha Narveson (2007). Impulse pulse => BiQuad filt => dac; 330 => filt.pfreq; 0.99 => filt.prad; float bpm; 1::second => dur beat; MAUI_View view; view.size(400,400); MAUI_Slider tempo; tempo.range(30, 120); tempo.size(400,60); tempo.position(0,0); tempo.displayFormat(tempo.integerFormat); tempo.name("tempo"); 36 => tempo.value; view.addElement(tempo); MAUI_LED redlight; redlight.size(30,30); redlight.position(170, 70); redlight.color(redlight.red); view.addElement(redlight); MAUI_LED greenlight; greenlight.size(30,30); greenlight.position(200, 70); greenlight.color(greenlight.green); view.addElement(greenlight); MAUI_Button eighths; eighths.toggleType(); eighths.size(110,70); eighths.position(145, 100); eighths.name("eighths"); view.addElement(eighths); MAUI_Button triplets; triplets.toggleType(); triplets.size(110,70); triplets.position(145, 150); triplets.name("triplets"); view.addElement(triplets); MAUI_Button sixteenths; sixteenths.toggleType(); sixteenths.size(110,70); sixteenths.position(145, 200); sixteenths.name("sixteenths"); view.addElement(sixteenths); view.display(); fun void poller() { while(true) { 60.0/tempo.value() => bpm; bpm::second => beat; 50::ms => now; } } fun void flashRed() { redlight.light(); 0.125::beat => now; redlight.unlight(); } fun void flashGreen() { greenlight.light(); 0.125::beat => now; greenlight.unlight(); } fun void controlEighths() { while (true) { eighths => now; if (eighths.state() != 0) {triplets.state(0); sixteenths.state(0);} } } fun void controlTriplets() { while (true) { triplets => now; if (triplets.state() != 0) {eighths.state(0); sixteenths.state(0);} } } fun void controlSixteenths() { while (true) { sixteenths => now; if (sixteenths.state() != 0) {eighths.state(0); triplets.state(0);} } } fun void pulsing() { while (true) { if (sixteenths.state() != 0) { 660 => filt.pfreq; 1 => pulse.next; spork ~ flashRed(); 0.25::beat => now; 0 => int i; do{ 330 => filt.pfreq; 1 => pulse.next; spork ~ flashGreen(); 0.25::beat => now; i++; } until (i > 2); } if (triplets.state() != 0) { 660 => filt.pfreq; 1 => pulse.next; spork ~ flashRed(); 0.334::beat => now; 0 => int i; do{ 330 => filt.pfreq; 1 => pulse.next; spork ~ flashGreen(); 0.333::beat => now; i++; } until (i > 1); } if (eighths.state() != 0) { 660 => filt.pfreq; 1 => pulse.next; spork ~ flashRed(); 0.5::beat => now; 330 => filt.pfreq; 1 => pulse.next; spork ~ flashGreen(); 0.5::beat => now; } if (eighths.state() == 0 && triplets.state() == 0 && sixteenths.state() == 0) { 660 => filt.pfreq; 1 => pulse.next; spork ~ flashRed(); 1::beat => now; } } } spork ~ poller(); spork ~ pulsing(); spork ~ controlEighths(); spork ~ controlTriplets(); spork ~ controlSixteenths(); while (true) { 1::second => now; }