//Settings 360 => float bpm; 60/bpm => float secBeat; // 4/4 time 4 => float bpmeasure; // Recording Settings 8 => float recMeasures; 10000 => int numSamples; //samples in the course of the recording (60/bpm)*bpmeasure*recMeasures => float recTime;//Length of recording recTime/numSamples => float sampLen; //instruments 0 => int jug; 1 => int drum; //2 => int mand; jug => int curInst; //start with jug int instruments[2][numSamples]; //recording settings 1 => int recording; //boolean to see if we are recording or not //metronome 1 => int metronome; //OSC messaging system 1 => int flipped; Wiimote wii; wii.start(); //be able to send vibrate msgs to the wiimote "localhost" => string hostname; 8000 => int port; OscSend xmit; xmit.setHost( hostname, port ); //Chords 60 => int key; [0, 2, 4, 5, 7, 9, 11, 12] @=> int majScal[]; //only using I, minII, IV, and V [[0, 4, 7], [2, 5, 9], [5, 9, 11], [7, 11, 14]] @=>int chords[][]; [0, 2, 4, 7, 9] @=> int majPent[]; 0 => int curChord; //----recording fun void record(int index){ 10=>float coeff; if(index==0)8.99/3=>coeff; if(index==2)10/2=>coeff; 1 => int flipped; for(0=>int i; i instruments[index][i]; //<<>>; if ((flipped==1 && wii.pitch()<.5) || (flipped==-1 && wii.pitch()>=.5)){ //<<<"bloop", (wii.roll()*coeff) $ int>>>; -1 *=> flipped; (wii.roll()*coeff) $ int => instruments[index][i]; } sampLen::second=>now; } } fun void jugLive(){ BlowBotl bottle => Envelope e => dac; 0 => float noisegain; Math.random2f( 0, 128 ) => float vibratofreq; Math.random2f( 0, 128 ) => float vibratogain; Math.random2f( 100, 128 ) => float volume; // noise gain bottle.controlChange( 4, noisegain ); // vibrato freq bottle.controlChange( 11, vibratofreq ); // vibrato gain bottle.controlChange( 1, vibratogain ); // volume bottle.controlChange( 128, volume ); // set freq (wii.roll()*10/2) $ int => int index; key+12+majPent[index] =>Std.mtof => bottle.freq; // go .8 => bottle.noteOn; 90::ms => dur t => e.duration; // key on - start attack e.keyOn(); // advance time by 800 ms 200::ms => now; // key off - start release e.keyOff(); // advance time by 800 ms 300::ms => now; } fun void drumLive(){ Shakers shake => JCRev r => dac; .025 => r.mix; 11 => shake.which; Std.mtof( Math.random2f( 0.0, 50 ) ) => shake.freq; Math.random2f( 0, 128 ) => shake.objects; Math.random2f( 0.8, 1.3 ) => shake.noteOn; 75::ms => now; .2 => shake.noteOff; 25::ms => now; } fun void mandoLive(){ Mandolin mand => dac;// set the gain // position wii.yah() => mand.pluckPos; .9 => mand.bodySize; .2 => mand.stringDamping; // frequency... (wii.roll()*10/2) $ int => int index; key+12+majPent[index] =>Std.mtof => mand.freq; // pluck it! .5 => mand.pluck; 10::second=>now; } fun void playLive(int instr){ //define the instrument for(0=>int i; i=.5)){ //vibrateImpulse(50::ms); -1 *=> flipped; if(instr==0)//jug { spork ~ jugLive(); } else if(instr==1){ spork ~ drumLive(); } else { //spork ~ mandoLive(); spork ~ jugLive(); } } sampLen::second=>now; } //10::second=>now; } fun void playJug(int index){ BlowBotl bottle => Envelope e => dac; 0 => float noisegain; Math.random2f( 0, 128 ) => float vibratofreq; Math.random2f( 0, 128 ) => float vibratogain; Math.random2f( 100, 128 ) => float volume; // noise gain bottle.controlChange( 4, noisegain ); // vibrato freq bottle.controlChange( 11, vibratofreq ); // vibrato gain bottle.controlChange( 1, vibratogain ); // volume bottle.controlChange( 128, volume ); // set freq key+majPent[index] =>Std.mtof => bottle.freq; // go .8 => bottle.noteOn; 90::ms => dur t => e.duration; // key on - start attack e.keyOn(); // advance time by 800 ms 200::ms => now; // key off - start release e.keyOff(); // advance time by 800 ms 300::ms => now; } fun void playDrum(int index){ Shakers shake => JCRev r => dac; .025 => r.mix; 11 => shake.which; Std.mtof( Math.random2f( 0.0, 50 ) ) => shake.freq; Math.random2f( 0, 128 ) => shake.objects; Math.random2f( 0.8, 1.3 ) => shake.noteOn; 75::ms => now; .2 => shake.noteOff; 25::ms => now; } fun void playMand(int index){ Mandolin mand => dac;// set the gain // position wii.yah() => mand.pluckPos; .9 => mand.bodySize; .1 => mand.stringDamping; // frequency... key+12+majPent[index] =>Std.mtof => mand.freq; // pluck it! .5 => mand.pluck; 10::second=>now; } fun void play(int instr){ if(instr==jug){ for(0=>int i; i int curVal; if(curVal != 0) spork ~ playJug(curVal); sampLen::second=>now; } } if(instr==drum){ for(0=>int i; i int curVal; if(curVal != 0) spork ~ playDrum(curVal); sampLen::second=>now; } } //if(instr==mand){ // for(0=>int i; i int curVal; // if(curVal != 0) spork ~ playMand(curVal); // sampLen::second=>now; // } //} } //---Metronome fun void metro(){ ModalBar m => dac; 440 => m.freq; 5 => m.preset; while(true){ for(0=> int i; i m.strike; }else if(i==0){ .9 => m.strike; }else{ .2 => m.strike; } secBeat::second=>now; } } } //Chord transition table [[.2, .2, .5, .1], [.1, .2, .1, .6], [.2, .1, .2, .5], [.4, .3, .1, .2]] @=> float transTable[][]; fun void changeChord(){ Math.random2(0,10) => int randomNum; <<>>; for (0=>int i; i<4; i++){ (10*transTable[curChord][i]) $ int-=>randomNum; if(randomNum<0) { i=>curChord; <<>>; break; } } Mandolin mand1 => dac; Mandolin mand2 => dac; Mandolin mand3 => dac; .8 => mand1.pluckPos => mand2.pluckPos => mand3.pluckPos; .3 => mand1.bodySize => mand2.bodySize=> mand3.bodySize; .6 => mand1.stringDamping => mand2.stringDamping => mand3.stringDamping; // frequency... key+chords[curChord][0] =>Std.mtof => mand1.freq; key+chords[curChord][1] =>Std.mtof => mand2.freq; key+chords[curChord][2] =>Std.mtof => mand3.freq; // pluck it! .5 => mand1.pluck; .5 => mand2.pluck; .5 => mand3.pluck; (recTime/4)::second=>now; } //---Main Loop //.spork ~ keyListeners(); spork ~ metro(); while(true){ spork ~ record(jug); spork ~ playLive(jug); spork ~ play(drum); spork ~ play(jug); recTime::second=>now; spork ~ play(jug); spork ~ record(drum); spork ~ playLive(drum); recTime::second=>now; changeChord(); //Math.random2(0,1) => curInst; //spork ~ record(curInst); //spork ~ playLive(curInst); //play other instruments //spork ~ play((curInst+1)%2); //spork ~ play((curInst+2)%3); //recTime::second=>now; }