We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
webcam to midi (Read 1994 times)
webcam to midi
Oct 27th, 2007, 7:37pm
 
hi there!

I'm new to processing and have little to none prgamming experience. I'm learning a lot by looking at the examples on this site. I was pleased to see that my webcam was recognised by processing verry easily.  What i'm trying to achive - for the moment Wink - is manimpulating the image from my webcam and generate midi note events.

As a starting point i took the two mirror examples by Daniel Shiffman. I pieced them togehther, messed a bit with colors and resolution and added some extra's (i.e. mouseX and mouseY, and mouse click genrate some changes).

Code:

import processing.video.*;

// Size of each cell in the grid
int cellSize = 10;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;

void setup() {
size(640, 480, P3D);
frameRate(30);
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

// Uses the default video input, see the reference if this causes an error
video = new Capture(this, width, height, 12);

background(0);
}

void draw()
{
if(mousePressed) {
background(255);
}
else {
background(0);
}
if (video.available()) {
video.read();
video.loadPixels();
}
// Not bothering to clear background
// background(0);

// Begin loop for columns
for ( int i = 0; i < cols;i++) {
// Begin loop for rows
for ( int j = 0; j < rows;j++) {

// Where are we, pixel-wise?
int x = i*cellSize;
int y = j*cellSize;
int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the image

// Make a new color with an alpha component
float r = red(video.pixels[loc]);
float g = green(video.pixels[loc]);
float b = blue(video.pixels[loc]);
color c = color(g, r, b, 75);

// dy and dy change the rect size depending on mouse position
float dx = (mouseX+50)/50;
int dy = (mouseY+50)/50;
float sz = (brightness(c)/255.0f)*cellSize;
rectMode(CENTER);
fill(c);
noStroke();
rect(x+cellSize/2,y+cellSize/2,sz*dx,sz*dy);
}
}
}



I used a cellsize of 160, so i get 12 (4*3) cells in total. What i am trying is to have twelve midi notes playing continuously and the velocity would be controled by the brightness values.

any pointers as to start structure this.  

I have installed the proMIDI library but find it hard to get this to work.

its my first processing sketch so any comments are more then welcome. Does anyone know a good tutorial/reference that explains the basics of programming? So i can already start while i'm waiting for my processing book to be shipped.

Re: webcam to midi
Reply #1 - Dec 4th, 2007, 3:35am
 
Did you have any further development on this ? I am also attempting to track a object in front of the camera and generate music out of it. But I am having problems with generating music. I tried some of the libraries like jm-etude, minim, but I couldn't get the real time generation of sound working.

Thanks
Srini
Re: webcam to midi
Reply #2 - Jun 2nd, 2008, 7:38pm
 
I finally did it in vvvv...  

come to think of it i should take this up again, as a test to see wether my processing skills have increased Wink
Re: webcam to midi
Reply #3 - Jun 2nd, 2008, 8:44pm
 
Hi Introspector, this is something I'm really into. I did a version in Quartz Composer which you can find here (with source) http://www.memo.tv/webcam_piano

And I also ported it to Processing a while ago but never added all the features I wanted to (scales etc.) so didn't post it... but maybe it will be helpful for you and  you can build on it so I just posted it here  http://www.memo.tv/webcam_piano_with_processing_v0_1

Lemme know if it works for you...
Page Index Toggle Pages: 1