// Wah + Pitch Mouse HID Demonstration // Copyright 2008 Les Hall // This software is protected by the GNU General Public License // variables int j[8]; // the binary count variables float freq; // the guitar's frequency 440 => float x; // the x value of the mouse for wah 1 => float y; // the y value of the mouse for reverb 0 => int mouse_device; // mouse device number // instantiate class objects kjzGuitar101 A; // the guitar Mouse_Interface M; // the mouse interface // the patch A.output => LPF wah_lpf => PitShift ps => dac; A.output => BPF wah_bpf => ps; // the patch parameters x => wah_lpf.freq; x => wah_bpf.freq; 1 => ps.mix; y => ps.shift; // play the guitar in a boolean sequence while (true) { for (0 => j[7]; j[7] < 2; j[7]++) { for (0 => j[6]; j[6] < 2; j[6]++) { for (0 => j[5]; j[5] < 2; j[5]++) { for (0 => j[4]; j[4] < 2; j[4]++) { for (0 => j[3]; j[3] < 2; j[3]++) { for (0 => j[2]; j[2] < 2; j[2]++) { for (0 => j[1]; j[1] < 2; j[1]++) { for (0 => j[0]; j[0] < 2; j[0]++) { if ((j[7] ^ j[6]) + (j[5] ^ j[4] ^ j[3]) + (j[2] ^ j[1] ^ j[0])) { ((j[7] + j[6]) + (j[5] + j[4] + j[3]) + (j[2] + j[1] + j[0]) + 1) * 80 => freq; for (0 => int i; i < 3; i++) { freq * (i+1) => A.str[i].freq; 0.8 - i/4.0 => A.str[i].pluck; } } 250::ms => now; } } } } } } } } } // Interface to mouse class Mouse_Interface { // hid initialization Hid hid; HidMsg hidmsg; if (!hid.openMouse (mouse_device)) { me.exit(); } // launch the time loop spork ~ time_loop (); // time loop fun void time_loop () { while (true) { hid => now; while (hid.recv (hidmsg)) { if ( hidmsg.isMouseMotion() ) { // do X adjustment hidmsg.deltaX * 10.0 +=> x; if (x < 400) { // check lower limit on x 400 => x; } if (x > 2000) { // check upper limit on x 2000 => x; } x => wah_lpf.freq; x => wah_bpf.freq; // do Y adjustment hidmsg.deltaY / 500.0 -=> y; if (y < 0.5) { // check lower limit on y 0.5 => y; } if (y > 2) { // check upper limit on y 2 => y; } y => ps.shift; } } } } } // many thanks to kijjaz for the mandolin-based Stratocaster guitar sound with overdrive: // Mandolin as the electric guitar test: by kijjaz (kijjaz@yahoo.com) // feel free to use, modify, publish class kjzGuitar101 { Mandolin str[3]; // create mandolin strings SinOsc overdrive => NRev rev => Gain output; // create overdrive to reverb to dac overdrive.sync(1); // make overdrive do Sine waveshaping rev.mix(0.02); // set reverb mix rev.gain(0.6); // set master gain output.gain(1.0); // set output gain // connect strings, set string damping for(int i; i < 3; i++) { str[i] => overdrive; .9 => str[i].stringDamping; 0.5 => str[i].bodySize; } }