class Synth implements ddf.minim.ugens.Instrument { Oscil wave; Damp env; int noteNumber; Blip blip; Synth( int note, int velocity ) { noteNumber = note; float freq = Frequency.ofMidiNote( noteNumber ).asHz(); float amp = (float)(velocity-1) / 126.0f; wave = new Oscil( freq, amp, Waves.SQUARE ); env = new Damp( 0.001f, 0.1f, 1.0f ); wave.patch( env ); } void noteOn( float dur ) { // make visual color c = color( 0, 200, 64, 255*(wave.amplitude.getLastValue()) ); blip = new Blip( c, map(noteNumber, 30, 55, height, 0), 200 ); blips.add( blip ); // make sound env.activate(); env.patch( out ); } void noteOff() { env.unpatchAfterDamp( out ); blips.remove( blip ); } }