This is my first real project with Processing so forgive me if this is a really stupid question.
I have 3 sine waves playing various note frequencies mapped to RGB color codes. As you drag the mouse over a pixel it gets the RGB values and plays the frequency associated with it. I only want this to happen when the mouse button is down. So how do I get the sound to stop on mouse button release? Currently I am just setting the sine to freq 0 but it is still outputing sound. Here is my code. Be kind
/* Allow the image to also be played by holding the left mouse button down and dragging over the image getting the pixel infomation and just playing the freq ignoring the duration and pan values. Include a button to allow user to upload an image file. */
void setup() { int w = 500; int h = 500; size(w, h); Build_Freq(); minim = new Minim(this); //create line out out = minim.getLineOut(Minim.MONO); //create RGB sine waves sine_red = new SineWave(0, 0.5, out.sampleRate()); sine_green = new SineWave(0, 0.5, out.sampleRate()); sine_blue = new SineWave(0, 0.5, out.sampleRate()); //Send RGB sine waves to out out.addSignal(sine_red); out.addSignal(sine_green); out.addSignal(sine_blue); //load image - for now. b = loadImage("1.jpg"); image(b, 0, 0, w, h); }
void draw() { if (mousePressed && (mouseButton == LEFT)) { //get color info color pc = get(mouseX, mouseY); //get individual RGB values float rc = red(pc); float gc = green(pc); float bc = blue(pc); //Convert individual RGB values to ints for array use int push_red = int(rc); int push_green = int(gc); int push_blue = int(bc); //Set sine waves to the RGB values sine_red.setFreq(color_to_freq[push_red]); sine_green.setFreq(color_to_freq[push_green]); sine_blue.setFreq(color_to_freq[push_blue]); soundOut = true; } else { soundOut = false; sine_red.setFreq(0); sine_green.setFreq(0); sine_blue.setFreq(0); } }
for (int i = 0; i < 250; i++) { float aaa = i / 10; int fl = floor(aaa); color_to_freq[i] = freq[fl]; } for (int i = 250; i < 255; i++) { color_to_freq[i] = 987.77; //b } // for (int i = 0; i < 255; i++) { // println(color_to_freq[i]); // } }
First let me say I am very new to Processing and I am working on my first real project.
The only programming experience I have is with high level scripting languages like AutoIt and AHK.
So, I am getting the error "Unexpected token: [" when trying to set values to an array. I don't really know what i am doing wrong here. any suggestions?