hw5 is about creating a webchuck instrument with gestural controls

HW5

Thereminimum demonstrates use of mouse and trackpad to play a Theremin-like tone generator. The "theremin work space" is a canvas object. Hit the start button and point at the canvas. After entering it, trackpad scroll (aka, trackpad wheel) changes volume up and down and mouse pointer `Y' position is mapped to pitch (2 octave range). Mouse wheel affects timbre by changing the mix of a bank of oscillators with different waveforms. Panning and stereo reverb effects are also included.

live code
global float mouseW, trackW, mouseX, mouseY; global float red, green, blue; Pan2 pan; // stereo panner, set separate mono reverbs for each channel pan.chan(0) => NRev revLeft => dac.chan(0); pan.chan(1) => NRev revRight => dac.chan(1); // bank of oscillators SinOsc sin => pan; PulseOsc pul => pan; SqrOsc sqr => pan; TriOsc tri => pan; SawOsc saw => pan; // envelopes for ramping gestures between gesture updates 50::ms => dur updateRate; Step unity => Envelope freqEnv => blackhole; unity => Envelope ampEnv => blackhole; unity => Envelope timbreEnv => blackhole; freqEnv.duration(updateRate); ampEnv.duration(updateRate); timbreEnv.duration(updateRate); fun void updateFromGestures() { while( true ) { // frequency from mouseY Std.mtof( mouseY*24 + 50 ) => float freq; freqEnv.target(freq); // amplitude from trackpad wheel trackW => float amp; if ((amp >= 0.0) && (amp <= 1.0)) ampEnv.target(amp); // timbre from mouse wheel timbreEnv.target(mouseW); // display all three in rgb color space trackW*256 => red; mouseY*256 => green; mouseW*256 => blue; updateRate => now; } } spork ~ updateFromGestures(); fun void updateOscillators() { while( true ) { sin.freq( freqEnv.last() ); pul.freq( freqEnv.last() ); sqr.freq( freqEnv.last() ); tri.freq( freqEnv.last() ); saw.freq( freqEnv.last() ); timbreEnv.last() => float tmp; sin.gain( ampEnv.last() * panTimbre( tmp, 0.0) ); pul.gain( ampEnv.last() * panTimbre( tmp, 1.0) ); sqr.gain( ampEnv.last() * panTimbre( tmp, 2.0) ); tri.gain( ampEnv.last() * panTimbre( tmp, 3.0) ); saw.gain( ampEnv.last() * panTimbre( tmp, 4.0) ); 1::samp => now; } } spork ~ updateOscillators(); // function used above to pan and voice the oscillator bank fun float panTimbre(float x, float y) { Math.sin( x*5.0 + y*2.0 ) => float tmp; pan.pan(tmp); (1.0 + tmp) / 2.0 => tmp; 0.15 *=> tmp; return tmp; } 1::week => now;





output is a stereo .wav file