/** * cornscan * * converts light-to-dark color transitions down the centerline of the video * into midi notes. * * Ranjit Bhatnagar - Feb 14, 2011 * as part of the instrument-a-day project * moonmilk.com */ import processing.video.*; import promidi.*; MidiIO midiIO; MidiOut midiOut; Capture cam; void setup() { size(1440, 900); // If no device is specified, will just use the default. cam = new Capture(this, 320, 240); // To use another device (i.e. if the default device causes an error), // list all available capture devices to the console to find your camera. //String[] devices = Capture.list(); //println(devices); // Change devices[0] to the proper index for your camera. //cam = new Capture(this, width, height, devices[0]); // Opens the settings page for this capture device. //camera.settings(); midiIO = MidiIO.getInstance(this); midiOut = midiIO.getMidiOut(0,2); } int SCAN_TOP = 50; int SCAN_BOT = 200; int SCAN_STEPS = 30; int VID_X = 100; int VID_Y = 250; int GRID_LEFT = 500; int GRID_TOP = 50; int GRID_WIDTH = 30; int GRID_HEIGHT = 700; int NOTEBLOX_LEFT = 600; float NOTEBLOX_FADE = 0.8; // when pixel becomes darker than this, fire a note int BRIGHTNESS_THRESHOLD = 30; int NOTE_LOW = 60; int[] scans = new int[SCAN_STEPS]; int[] noteblox = new int[SCAN_STEPS]; void draw() { if (cam.available() == true) { cam.read(); image(cam, VID_X, VID_Y); stroke(20); noFill(); rect(VID_X+158, VID_Y-30, 5, 300); for (int step=0; step= BRIGHTNESS_THRESHOLD) { midiOut.sendNote(new Note(NOTE_LOW+step, 127, 200)); noteblox[step] = 255; } else { noteblox[step] *= NOTEBLOX_FADE; } stroke(0); fill(noteblox[step]); rect(NOTEBLOX_LEFT, grid_y, GRID_WIDTH, GRID_HEIGHT/SCAN_STEPS-2); } } }