/* This is the fifth part of building a 4-step Sequencer Synthesizer modeling the one found at: http://www.handmadeelectronicinstruments.com/store/product/four-step-sequencer-synthesizer/ As a final step we add the ability to control the interface with a midi controller. This code requires the external library The MidiBus found at: http://www.smallbutdigital.com/themidibus.php The program now detects which midi input devices exist. The user is asked to pick a device or no device at all. There is lots of bad coding implemented here: The midi controls are mapped (hard coded) to be used with the Korg nanoKontrol2. There is no error checking performed. If there are no midi input devices present, the program will likely crash. Andy Sarroff, 2/2014 */ import beads.*; import themidibus.*; //Import the library int uiX; int bSize; color c; PImage bgimg; PImage ledOn; PImage ledOff; PImage swOn; PImage swOff; int zone; Control[] controls = new Control[7]; Switch[] switches = new Switch[5]; Clock cl; MidiBus midiCtrl; boolean midiSelected; String[] midiNames; PFont f; // create our AudioContext, which will oversee audio input/output AudioContext ac; Glide[] glides = new Glide[7]; BiquadFilter lpf; WavePlayer[] wp = new WavePlayer[4]; ScalingMixer sc; Gain g; void setup() { size(692, 692); // http://img.ehowcdn.com/default/ehow/images/a07/fd/m6/types-brushed-aluminum-sheets-1.1-800x800.jpg bgimg = loadImage("aluminum.jpg"); uiX = bgimg.height; bgimg.resize(bgimg.width*2, bgimg.height*2); // Set size of window to match background image imageMode(CENTER); // Load images // http://openclipart.org/image/300px/svg_to_png/88123/led_red_black.png ledOn = loadImage("led.png"); ledOn.resize(ledOn.width/10, 0); ledOff = loadImage("ledOff.png"); ledOff.resize(ledOff.width/10, 0); // http://www.yourpowercentre.com.au/wp-content/uploads/2013/10/switch.jpg swOn = loadImage("swOn.png"); swOn.resize(swOn.width/3, 0); swOff = loadImage("swOff.png"); swOff.resize(swOff.width/3, 0); // http://578e7a9bafc08e847f59-b21544d490ba797ec9de9d17e947de3d.r81.cf1.rackcdn.com/lrs-18519e_7379.jpg PImage img = loadImage("knob_t.png"); img.resize(img.width/4, 0); background(0); // Inititalize controls for (int i=0; i=20 && number <= 23) { i = number-17; } else if (number == 16) { i = 0; } else if (number >=18 && number <=19) { i = number-17; } else if (number == 49 && value == 127) { toggleSound(); return; } else { return; } float ctrl = map(value, 0, 127, controls[i].ll, controls[i].ul); controls[i].ctrl = ctrl; controls[i].setAngle(); controls[i].update(); } void draw() { // We insert this message before the device is turned on. The user must now // specify which midi device (if any) will be used before the UI appears. // All message passing is handled in the keyPressed() function. if (!midiSelected) { background(0); fill(c); text("Please Pick a MIDI input device:", 80, height/2-30); int i; for (i=0; i= 2 && zone <=3) { controls[zone-1].update(); } else if (zone >=8 && zone <= 11) { controls[zone-5].update(); } } void mousePressed() { getZone(); if (zone == 1 && midiSelected) { toggleSound(); } } void keyPressed() { // If the midi device has not been selected, we check that a valid device // number or the char 'x' has been pressed. I f a valid device has been chosen // we initialize the midi device. if (!midiSelected) { if (int(key)>=48 && int(key) <= midiNames.length+47) { println(int(key)-48); initializeMidi(midiNames[int(key)-48]); midiSelected = true; } else if (key == 'x') { midiSelected = true; } } } void toggleSound() { switches[4].on = !switches[4].on; if (switches[4].on) { ac.start(); } else { for (int i=0; i<4; i++) { switches[i].on = false; } ac.stop(); } } // START NO NOTES // code used to capture screenshots void keyReleased() { boolean online = true; if (key == '`' && !online) save("sketch.png"); }