import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.effects.*; import ddf.minim.signals.*; import ddf.minim.spi.*; import ddf.minim.ugens.*; import themidibus.*; // An Oscil object which generates a synthesized signal. Oscil wave; // An object representing an audio output. We use this hear the signal. AudioOutput out; // Processing's setup method. Runs once at the start of the program. void setup() { size(1000, 200); Minim minim = new Minim(this); out = minim.getLineOut(); wave = new Oscil(440, 1, Waves.SINE); wave.patch(out); MidiBus.list(); MidiBus midi = new MidiBus(this, "USB Oxygen 8 v2", "USB Oxygen 8 v2"); } // Processing's draw method. Runs multiple times a second after the program // starts. void draw() { drawOutput(out); } void noteOn(int channel, int pitch, int velocity) { double exponent = (pitch - 69) / 12.0; double frequency = 440 * Math.pow(2, exponent); wave.setFrequency((float) frequency); System.out.println("Note has been fired!"); System.out.println("Channel = " + channel); System.out.println("pitch = " + pitch); System.out.println("velocity = " + velocity); } void noteOff(int channel, int pitch, int velocity) { System.out.println("Note has been released!"); System.out.println("Channel = " + channel); System.out.println("pitch = " + pitch); System.out.println("velocity = " + velocity); } // Accepts an AudioOutput object and draws the waveform currently stored // in the AudioOutput's buffer. void drawOutput(AudioOutput out) { // erase the window to black background(0); // draw using a white stroke stroke(255); // draw the waveforms for(int i = 0; i < out.bufferSize() - 1; i++) { // find the x position of each buffer value float x1 = map( i, 0, out.bufferSize(), 0, width ); float x2 = map( i+1, 0, out.bufferSize(), 0, width ); // draw a line from one buffer position to the next for both channels line( x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50); line( x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50); } }