Difference between revisions of "Link to all related files (chuck, audio files, instructions, scores)"
(Created page with ' == '''ChucK Code''' for the instrument. A Beginning. == Hid hi; HidMsg msg; // all joystick values are roughly normalized -1 to 1 float ax; // left joystick x axis float …') |
(→ChucK Code for the instrument. A Beginning.) |
||
Line 11: | Line 11: | ||
// all joystick values are roughly normalized -1 to 1 | // all joystick values are roughly normalized -1 to 1 | ||
+ | |||
float ax; // left joystick x axis | float ax; // left joystick x axis | ||
+ | |||
float ay; // left joystick y axis | float ay; // left joystick y axis | ||
+ | |||
float az; // left joystick z axis | float az; // left joystick z axis | ||
+ | |||
float bx; // right joystick x axis | float bx; // right joystick x axis | ||
+ | |||
float by; // right joystick y axis | float by; // right joystick y axis | ||
+ | |||
float bz; // right joystick z axis | float bz; // right joystick z axis | ||
+ | |||
0 => int fp; | 0 => int fp; | ||
+ | |||
float axprev, ayprev, azprev, bxprev, byprev, bzprev; | float axprev, ayprev, azprev, bxprev, byprev, bzprev; | ||
+ | |||
float vax, vay, vaz, vbx, vby, vbz; | float vax, vay, vaz, vbx, vby, vbz; | ||
+ | |||
float vaxprev, vayprev, vazprev, vbxprev, vbyprev, vbzprev; | float vaxprev, vayprev, vazprev, vbxprev, vbyprev, vbzprev; | ||
+ | |||
float vaxprevprev, vayprevprev, vayprevprevprev, vazprevprev, vbxprevprev, vbyprevprev, vbzprevprev; | float vaxprevprev, vayprevprev, vayprevprevprev, vazprevprev, vbxprevprev, vbyprevprev, vbzprevprev; | ||
float vayAvg;//Keeps an average of the last vay, vay-1, vay-2 | float vayAvg;//Keeps an average of the last vay, vay-1, vay-2 | ||
+ | |||
float vayPrevAvg; //Keeps an average of the last vay-3, vay-4, vay-5 | float vayPrevAvg; //Keeps an average of the last vay-3, vay-4, vay-5 | ||
+ | |||
float vbyAvg, vbyPrevAvg; //More of the same | float vbyAvg, vbyPrevAvg; //More of the same | ||
Line 30: | Line 43: | ||
float vayPrevs[keepInMem]; | float vayPrevs[keepInMem]; | ||
+ | |||
float vayPrevPrevs[keepInMem]; | float vayPrevPrevs[keepInMem]; | ||
+ | |||
float vbyPrevs[keepInMem]; | float vbyPrevs[keepInMem]; | ||
+ | |||
float vbyPrevPrevs[keepInMem]; | float vbyPrevPrevs[keepInMem]; | ||
+ | |||
int i, n; //global for loop? Wow style != good. | int i, n; //global for loop? Wow style != good. | ||
SndBuf bell1 => dac; | SndBuf bell1 => dac; | ||
+ | |||
SndBuf bell2 => dac; | SndBuf bell2 => dac; | ||
− | " | + | |
− | " | + | "PATHNAME" => bell1.read; |
+ | |||
+ | "PATHNAME" => bell2.read; | ||
+ | |||
1.0 => bell1.gain; | 1.0 => bell1.gain; | ||
− | |||
+ | 1.0 => bell2.gain; | ||
// which joystick | // which joystick | ||
0 => int device; | 0 => int device; | ||
+ | |||
// get from command line | // get from command line | ||
if( me.args() ) me.arg(0) => Std.atoi => device; | if( me.args() ) me.arg(0) => Std.atoi => device; | ||
Line 52: | Line 74: | ||
<<< "joystick '" + hi.name() + "' ready", "" >>>; | <<< "joystick '" + hi.name() + "' ready", "" >>>; | ||
+ | |||
spork ~GetJoystickInput(); | spork ~GetJoystickInput(); | ||
+ | |||
spork ~LeftBell(); | spork ~LeftBell(); | ||
+ | |||
spork ~RightBell(); | spork ~RightBell(); | ||
0 => int ring; | 0 => int ring; | ||
+ | |||
0 => int ring2; | 0 => int ring2; | ||
0.01 => float yThreshold; | 0.01 => float yThreshold; | ||
+ | |||
0.01 => float yDiff; | 0.01 => float yDiff; | ||
Revision as of 07:08, 12 May 2010
ChucK Code for the instrument. A Beginning.
Hid hi; HidMsg msg;
// all joystick values are roughly normalized -1 to 1
float ax; // left joystick x axis
float ay; // left joystick y axis
float az; // left joystick z axis
float bx; // right joystick x axis
float by; // right joystick y axis
float bz; // right joystick z axis
0 => int fp;
float axprev, ayprev, azprev, bxprev, byprev, bzprev;
float vax, vay, vaz, vbx, vby, vbz;
float vaxprev, vayprev, vazprev, vbxprev, vbyprev, vbzprev;
float vaxprevprev, vayprevprev, vayprevprevprev, vazprevprev, vbxprevprev, vbyprevprev, vbzprevprev;
float vayAvg;//Keeps an average of the last vay, vay-1, vay-2
float vayPrevAvg; //Keeps an average of the last vay-3, vay-4, vay-5
float vbyAvg, vbyPrevAvg; //More of the same
6 => int keepInMem;
float vayPrevs[keepInMem];
float vayPrevPrevs[keepInMem];
float vbyPrevs[keepInMem];
float vbyPrevPrevs[keepInMem];
int i, n; //global for loop? Wow style != good.
SndBuf bell1 => dac;
SndBuf bell2 => dac;
"PATHNAME" => bell1.read;
"PATHNAME" => bell2.read;
1.0 => bell1.gain;
1.0 => bell2.gain;
// which joystick 0 => int device;
// get from command line if( me.args() ) me.arg(0) => Std.atoi => device;
// open joystick 0, exit on fail if( !hi.openJoystick( device ) ) me.exit();
<<< "joystick '" + hi.name() + "' ready", "" >>>;
spork ~GetJoystickInput();
spork ~LeftBell();
spork ~RightBell();
0 => int ring;
0 => int ring2;
0.01 => float yThreshold;
0.01 => float yDiff;
while(true) {
1::day => now;
}
fun void LeftBell() {
while(true) { if (vayprev > yThreshold) { <<< vay >>>; if (ring == 0 && (vayAvg - vayPrevAvg) > yDiff){ <<<"DIFF: ",(vayAvg - vayPrevAvg)>>>; 1=>ring; } if(ring && (vayAvg - vayPrevAvg) < yDiff ){ <<<"AAding!", vayprev>>>; 1.0 => bell1.rate; vayprev*20 => bell1.gain; 0 => bell1.pos; 50::ms => now; 0=>ring; //wipeMemory(); } //<<<"DIFF: ",(vayAvg - vayPrevAvg)>>>; } vay => vayprev; 5::ms => now; }
}
fun void RightBell() {
while(true) { if (vbyprev > yThreshold) { <<< vby >>>; if (ring2 == 0 && (vbyAvg - vbyPrevAvg) > yDiff){ <<<"DIFF: ",(vbyAvg - vbyPrevAvg)>>>; 1=>ring2; } if(ring2 && (vbyAvg - vbyPrevAvg) < yDiff ){ <<<"AAding!", vbyprev>>>; 1.0 => bell2.rate; vbyprev*20 => bell2.gain; 0 => bell2.pos; 50::ms => now; 0=>ring2; //wipeMemory(); } //<<<"DIFF: ",(vayAvg - vayPrevAvg)>>>; } vby => vbyprev; 5::ms => now; }
}
fun void GetJoystickInput() {
while( true ) { // wait on HidIn as event hi => now; // messages received while( hi.recv( msg ) ) { // dual joysticks axis motion if( msg.isAxisMotion() ) { if( msg.which == 0 ) { ax => axprev; msg.axisPosition => ax; Math.fabs(ax - axprev) => vax; } else if( msg.which == 1 ) { ay => ayprev; msg.axisPosition => ay; Math.fabs(ay - ayprev) => vay; if(vay != vayprev){ vayPrevs[i] => vayPrevPrevs[i]; vay => vayPrevs[i]; i++; if (i == keepInMem) 0 => i; calcAvgs(); } } else if( msg.which == 2 ) { az => azprev; msg.axisPosition*-1 => az; Math.fabs(az - azprev) => vaz; } else if( msg.which == 3 ) { bx => bxprev; msg.axisPosition => bx; Math.fabs(bx - bxprev) => vbx; } else if( msg.which == 4 ) { by => byprev; msg.axisPosition => by; Math.fabs(by - byprev) => vby; if(vby != vbyprev){ vbyPrevs[n] => vbyPrevPrevs[n]; vby => vbyPrevs[n]; n++; if (n == keepInMem) 0 => n; calcBAvgs(); } } else if( msg.which == 5 ) { bz => bzprev; msg.axisPosition*-1 => bz; Math.fabs(bz - bzprev) => vbz; } } // footpedal message else if( msg.isButtonDown() ) { 1 => fp; <<< "footpedal depressed " + fp >>>; } else if( msg.isButtonUp() ) { 0 => fp; <<< "footpedal released " + fp >>>; } } }
}
fun void calcAvgs(){
float curAvgPrev, curAvgPrevPrev; for (int j; j < keepInMem; j++){ curAvgPrev + vayPrevs[j] => curAvgPrev; curAvgPrevPrev + vayPrevPrevs[j] => curAvgPrevPrev; } curAvgPrev/keepInMem => vayAvg; curAvgPrevPrev/keepInMem => vayPrevAvg;
}
fun void calcBAvgs(){
float curAvgPrev, curAvgPrevPrev; for (int j; j < keepInMem; j++){ curAvgPrev + vbyPrevs[j] => curAvgPrev; curAvgPrevPrev + vbyPrevPrevs[j] => curAvgPrevPrev; } curAvgPrev/keepInMem => vbyAvg; curAvgPrevPrev/keepInMem => vbyPrevAvg;
}