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
- 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.