LiSa loops[ 10 ]; Event e; 0.175 => adc.gain; int currentloop; 0 => int recordswitch => int playswitch => int firstloopswitch; 0 => int muteswitch => int metronomeswitch => int clearswitch; 0::samp => dur position => dur length; 500 => float BPM; spork ~ checkbuttons(); spork ~ checkmouse(); spork ~ startvoices(); spork ~ metronome(); spork ~ counter( e ); while( true ) { runloops( currentloop ); 1::samp => now; } fun void checkbuttons() { while( true ) { Hid hi; HidMsg msg; 0 => int deviceNum; if(!hi.openKeyboard( deviceNum ) ) me.exit(); hi => now; if( hi.recv( msg ) ) { if( msg.isButtonDown() ) { msg.which => int x; if( 29 < x ) { if( x < 40 ) { msg.which => currentloop; currentloop - 30 => currentloop; if( clearswitch == 1 ) { <<< "Loop ", ( currentloop + 1 ), "cleared" >>>; loops[ currentloop ].clear(); 0 => clearswitch; } <<< "Current Loop:", ( currentloop + 1 ) >>>; } } if( x == 21 ) { if( recordswitch == 0 ) { 1 => recordswitch; <<< "Recording..." >>>; } else { 0 => recordswitch; <<< "Recording Off" >>>; } } if( x == 44 ) { if( muteswitch == 1 ) { 1 => muteswitch; } } if( x == 16 ) { if( metronomeswitch == 0 ) { 1 => metronomeswitch; } else { 0 => metronomeswitch; } } if( x == 45 ) { if( clearswitch == 0 ) { 1 => clearswitch; } } } } else { 1::samp => now; } } } fun void checkmouse() { Hid hi; HidMsg msg; 0 => int deviceNum; 0 => int x; if( !hi.openMouse( deviceNum ) ) me.exit(); while( true ) { hi => now; if( hi.recv( msg ) ) { if( msg.isMouseMotion() ) { if( metronomeswitch == 1 ) { if( msg.deltaX ) { if( firstloopswitch == 0 ) { msg.deltaX => x; if( 60 < x + BPM ) { if( x + BPM < 3000 ) { x + BPM => BPM; BPM => float bperminute; ( 60 / ( bperminute / 1000 ) ) => bperminute; <<< "BPM =", bperminute >>>; } } } } } } } else { 1::samp => now; } } } fun void startvoices() { for( 0 => int i; i < 10; i++ ) { 1::minute => loops[ i ].duration; 50::ms => loops[ i ].recRamp; 1 => loops[ i ].record; 250::ms => now; 0 => loops[ i ].record; 1 => loops[ i ].play; 1 => loops[ i ].loop; <<< "Loop", ( i + 1 ), "ready..." >>>; } } fun void runloops( int currentloop ) { if( recordswitch == 1 ) { spork ~ record( currentloop ); 2 => recordswitch; } if( playswitch == 1 ) { spork ~ play( currentloop, position, e ); 0 => playswitch; } if( clearswitch == 1 ) { loops[ currentloop ].clear; <<< "Loop ", ( currentloop + 1 ), "cleared" >>>; 0 => clearswitch; } } fun void metronome() { Impulse i => dac; 0.01 => i.gain; while( true ) { if( metronomeswitch == 1 ) { 1.0 => i.next; BPM::ms => now; e.signal(); } else { if( position > 0::samp ) { e.signal(); BPM::ms => now; e.signal(); } else { 1::samp => now; } } } } fun void counter( Event e ) { 1 => int i; while( true ) { e => now; <<< i >>>; if( i == 4 ) { 1 => i; } else { i++; } } } fun void record( int currentloop ) { adc => loops[ currentloop ] => dac; 0::samp => loops[ currentloop ].recPos; 30::ms => loops[ currentloop ].recRamp; 1 => loops[ currentloop].record; if( firstloopswitch == 0 ) { 1 => firstloopswitch; } e => now; while( true ) { loops[ currentloop ].recPos() => position; if( recordswitch == 0 ) { 0 => loops[ currentloop ].record; adc =< loops[ currentloop ] =< dac; 1 => playswitch; me.exit(); } BPM::ms => now; } } fun void play( int currentloop, dur position, Event e ) { <<< "Playing..." >>>; 0::ms => loops[ currentloop ].playPos; loops[ currentloop ] => dac; /// loops[ currentloop ].left => dac.left; /// loops[ currentloop ].left => dac.chan( 0 ); dur difference; int starterswitch; 1.0 => float gain; currentloop => int playloop; position => dur looplength; ( looplength / BPM::ms ) => float beats; beats $ int => int wholebeats; if( ( beats - wholebeats ) < 0.5 ) { ( looplength - ( wholebeats * BPM::ms ) ) => difference; } else { ( looplength - ( ( 1 + wholebeats ) * BPM::ms ) ) => difference; } looplength - difference => loops[ playloop ].loopEnd; if( firstloopswitch == 0 ) { 1 => starterswitch; } else { 0 => starterswitch; } Event a; while( true ) { 1 => loops[ playloop ].play; if( 1 == starterswitch ) { a.signal(); } else { a => now; } e => now; } }