LiSa loops[ 10 ]; Chorus chorus; 0.35 => adc.gain; int key; int currentloop; int ID; int editorID; int chorusID; int mouseX; int mouseY; 0 => int recordswitch => int playswitch => int firstloopswitch; 0 => int muteswitch => int clearswitch => int editswitch; 0 => int killswitch => int effectswitch => int addswitch; 0 => int chorusswitch; 0::samp => dur position; spork ~ checkbuttons(); spork ~ checkmouse(); spork ~ startvoices(); 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 => key; if( 29 < key ) { if( key < 40 ) { msg.which => currentloop; currentloop - 30 => currentloop; if( clearswitch == 1 ) { <<< "Loop ", ( currentloop + 1 ), "cleared" >>>; loops[ currentloop ].clear(); Machine.remove( ID ); 0 => clearswitch; } else { <<< "Current Loop:", ( currentloop + 1 ) >>>; } } } if( key == 21 ) { if( recordswitch == 0 ) { 1 => recordswitch; <<< "Recording..." >>>; } else { 0 => recordswitch; <<< "Recording Off" >>>; } } if( key == 44 ) { loops[ currentloop ].gain() => float gain; if( gain == 1.0 ) { 0.0 => loops[ currentloop ].gain; <<< "Muting Loop :", ( currentloop + 1 ) >>>; } if( gain == 0.0 ) { 1 => loops[ currentloop ].gain; <<< "Un-Muting Loop :", ( currentloop + 1 ) >>>; } } if( key == 45 ) { if( clearswitch == 0 ) { 1 => clearswitch; } } if( key == 46 ) { if( addswitch == 0 ) { 1 => addswitch; } } if( key == 8 ) { if( clearswitch == 1 ) { Machine.remove( editorID ); <<< "Editor removed on Loop :", ( currentloop + 1 ) >>>; 0 => clearswitch; } if( addswitch == 1 ) { 1 => editswitch; 0 => addswitch; } } if( key == 6 ) { if( clearswitch == 1 ) { 1 => killswitch; <<< "Loop :", ( currentloop + 1 ), " Chorus Off" >>>; Machine.remove( chorusID ); 0 => clearswitch; } if( addswitch == 1 ) { 1 => effectswitch; 1 => chorusswitch; } } } } 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( effectswitch == 1 ) { if( msg.isMouseMotion() ) { if( msg.deltaX ) { msg.deltaX => mouseX; } if( msg.deltaY ) { msg.deltaY => mouseY; } } } } 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); 0 => playswitch; } if( editswitch == 1 ) { spork ~ editor(); 0 => editswitch; } } 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; } while( true ) { loops[ currentloop ].recPos() => position; if( recordswitch == 0 ) { 0 => loops[ currentloop ].record; adc =< loops[ currentloop ] =< dac; 1 => playswitch; me.exit(); } 1::samp => now; } } fun void play( int currentloop, dur position ) { currentloop => int playloop; <<< "Playing Loop :", ( playloop + 1 ) >>>; int starterswitch; position => loops[ playloop ].loopEnd; loops[ playloop ] => dac; 0::ms => loops[ currentloop ].playPos; if( firstloopswitch == 0 ) { 1 => starterswitch; } else { 0 => starterswitch; } Event a; while( true ) { if( currentloop == playloop ) { me.id() => ID; } 1 => loops[ playloop ].play; if( 1 == starterswitch ) { a.signal(); } else { a => now; } } } fun void editor() { currentloop => int editorloop; Chorus chorus; <<< "Editing Loop :", ( editorloop + 1 ) >>>; while( true ) { if( currentloop == editorloop ) { me.id() => editorID; } if( chorusswitch == 1 ) { loops[ editorloop ] =< dac; spork ~ chorusmod(); 0 => chorusswitch; } 1::samp => now; } } fun void chorusmod() { currentloop => int cmodloop; loops[ cmodloop ] => chorus => dac; <<< "Loop :", ( cmodloop + 1 ), " Chorus On" >>>; Hid hi; HidMsg msg; 0 => int deviceNum; float chorusx; float chorusy; 0.0001 => float Xrate; 0.01 => float Yrate; me.id() => chorusID; 0 => chorus.modFreq => float chorusfreq => float chorusmin; 0 => chorus.modDepth => float chorusdepth; 15 => float chorusmax; 0.25 => float cdepthmax; 0 => float cdepthmin; while( true ) { if( currentloop == cmodloop ) { me.id() => chorusID; if( killswitch == 1 ) { loops[ cmodloop ] =< chorus =< dac; loops[ cmodloop ] => dac; 0 => killswitch; me.exit(); } } if( !hi.openMouse( deviceNum ) ) me.exit(); hi => now; while( hi.recv( msg ) ) { if( msg.isMouseMotion() ) { if( currentloop == cmodloop ) { if( msg.deltaY ) { msg.deltaY => chorusy; if( chorusmin < ( Yrate * chorusy ) + chorusfreq ) { if ( chorusfreq + ( Yrate * chorusy ) < chorusmax ) { chorusfreq + ( Yrate * chorusy ) => chorusfreq; chorusfreq => chorus.modFreq; <<< chorusfreq, "= Chorus Frequency (Hz)">>>; } else { <<< chorusfreq, "= Chorus Frequency (Hz)">>>; chorusmax => chorusfreq; } } else { <<< chorusfreq, "= Chorus Frequency (Hz)">>>; chorusmin => chorusfreq; } } if( msg.deltaX ) { msg.deltaX => chorusx; if( chorusdepth + ( Xrate * chorusx ) > cdepthmin ) { if( chorusdepth + ( Xrate * chorusx ) < cdepthmax ) { <<< "Chorus Depth =", chorusdepth >>>; chorusdepth + ( Xrate * chorusx ) => chorusdepth; chorusdepth => chorus.modDepth; } else { <<< "Chorus Depth =", chorusdepth >>>; cdepthmax => chorusdepth; } } else { <<< "Chorus Depth =", chorusdepth >>>; cdepthmin => chorusdepth; } } } } } 1::samp => now; } }