We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, I have been trying to make a paint music application or say creating music with colors application. Here what's happening, when you draw on canvas with a color it detects the blob of the drawing/stroke and picks the color from its centroid using get() function. B-)
Furthermore, currently it plays randomly three different file when it detects the r,g,b values of color of the centroid. I have called 16 audio file and divided it into three sets, for 0< r values < 256 it plays randomly any file (0,5) // for 0< g values < 256 it plays randomly any file (5, 10) // for 0< b values < 256 it plays randomly any file (10,16)
The idea was each time when a color gets detected three different sounds would play.
Problems: :-B :-B
C. (This is a logic problem) It should play only file at a time but after sometime random number gets activated and generates new numbers and new files gets played. I want that new files only get played when a new stroke gets drawn/ new blob gets detected.
import Blobscanner.*;
import ddf.minim.*;
Minim minim;
AudioPlayer[] player = new AudioPlayer[16];
PGraphics edges;
PGraphics testLayer;
Detector bs;
int minimumWeight = 900;
final int MAXEDGES = (500*500)/4;
int[] X ;
int[] Y ;
color c;
int A, B, C;
void setup() {
size(500, 500);
bs = new Detector(this, 0, 0, width, height, 255);
edges = createGraphics(width, height);
testLayer = createGraphics(width, height);
testLayer.beginDraw();
testLayer.endDraw();
minim = new Minim(this);
for (int i=0; i<player.length;i++) {
String str = "matter_"+i+".mp3";
println(str);
player[i] = minim.loadFile(str); // loadSample( "FILE NAME", Buffer size);
}
}
void draw() {
background(255);
if (keyPressed) {
c = color(random(255), random(255), random(255));
}
//---------------------------------
testLayer.beginDraw();
if (mousePressed) {
// testLayer.fill(c);
// testLayer.noStroke();
testLayer.stroke(c);
testLayer.strokeWeight(30);
testLayer.line(mouseX, mouseY, pmouseX, pmouseY);
//testLayer.ellipse(mouseX, mouseY, 30, 30);
}
testLayer.endDraw();
//---------------------------------
int k = 0;
bs.imageFindBlobs(testLayer);
bs.loadBlobsFeatures();
bs.weightBlobs(false);
bs.findCentroids(false, false);
getEdgeCoordinates();
edges.beginDraw();
for (int i = 0; boolean( X[i]); i++) {
edges.stroke(0, 255, 0);
edges.strokeWeight(2);
edges.point(X[i], Y[i]);//or do what you want
}
//--------------------------------------------------
bs.findCentroids(false, false);
for (int i = 0; i < bs.getBlobsNumber(); i++) {
edges.point(bs.getCentroidX(i), bs.getCentroidY(i));
// println(bs.getCentroidX(i)+ " " + bs.getCentroidY(i));
text("G", bs.getCentroidX(i), bs.getCentroidY(i));
color c = testLayer.get((int)bs.getCentroidX(i), (int)bs.getCentroidY(i));
float r = red(c);
float g = green(c);
float b = blue(c);
//println("r " + r + " g " + g + " b " + b);
//-----------------RED CHANNEL ---------------------
if (0<r && r< 256 && player[A].isPlaying() ) {
A = (int)random(0, 5);
}
if (!player[A].isPlaying()) {
println(A);
player[A].pause();
player[A].rewind();
player[A].play();
}
//------------------GREEN CHANNLE ------------------
if (0<g && g< 256 && player[B].isPlaying() ) {
B = (int)random(5, 10);
}
if (!player[B].isPlaying()) {
println(B);
player[B].pause();
player[B].rewind();
player[B].play();
}
//-----------------BLUE CHANNEL --------------------
if (0<b && b< 256 && player[C].isPlaying() ) {
C = (int)random(10, 16);
}
if (!player[C].isPlaying()) {
println(C);
player[C].pause();
player[C].rewind();
player[C].play();
}
}
//--------------------------------------------------
edges.endDraw();
image(testLayer, 0, 0);
image(edges, 0, 0);
}
//----------------------------------------------------
void getEdgeCoordinates() {
X = new int[MAXEDGES];
Y = new int[MAXEDGES];
int i = 0;
for (int y = 0; y < testLayer.height; y++) {
for (int x = 0; x < testLayer.width; x++) {
if (bs.isEdge(x, y) &&
bs.getBlobWeightLabel(bs.getLabel(x, y)) >= minimumWeight) {
X[i] = x;
Y[i] = y;
i++;
}
}
}
}
void stop() {
//song.stop();
minim.stop();
super.stop();
}
It is playing the audio file files but simultaneously gives these errors too......
matter_0.mp3 ==== JavaSound Minim Error ==== ==== Don't know the ID3 code TSS ==== JavaSound Minim Error ==== ==== Error parsing ID3v2: String index out of range: -131 . . . .
Answers
Can any one help me ? .... I have gone so far recognizing and detecting color blobs and able to play music. Please help me out .... this is really nagging me :(( :(( :(( :(( :(( :((
Looks like an error that somebody already had on the first forum :) check the resolutions there: http://www.processing.org/discourse/beta/num_1240704675.html
Hi mrzl, Thanks for replying but my question was not about the minim error because it is working fine even with those error.
My question was: - A. Default j=0 gets played after running the application (I don't want this) - B. I do generate random color by hitting random key and draw with that color. Problem is sometimes the drawn blob doesn't get detected. - C.(This is a logic problem) It should play one file at a time but after sometime random number gets activated and generates new numbers and new files gets played. I want that new files only get played when a new stroke gets drawn/ new blob gets detected. (line: 68 -98 ) - D. When I use get() method to detect the centroid color it returns values like this
The problem is for exact red, blue & green, get() returns correct value but for any shade of these color, for example blue [I'av marked in the image] , get function returns { r:some value, g: some value, b: 2555 } it should not happen like this. It has to return exact value of blue. Same with the other color shades.
P.S. I don't know how attach the image in the forum. It was easy and intuitive in old forum.
Please help ! this is really nagging me ........
[-O< [-O< [-O< [-O< [-O< [-O< [-O<
-