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.
IndexProgramming Questions & HelpPrograms › simple color mixer with controller
Page Index Toggle Pages: 1
simple color mixer with controller (Read 674 times)
simple color mixer with controller
Feb 17th, 2009, 3:30am
 
hi,

I try to make a very simple RGB color mixer with MIDI controller faders to set RGB values.
I use proMIDI lib to connect my fader box, and to assign each fader RGB values, I use this lines of code.

void controllerIn(Controller controller, int device, int channel){
 int num = controller.getNumber();
 int val = controller.getValue();

//println(num + "and" + val);
//every fader has controller number of 7
int r = 0;
int g = 0;
int b = 0;
if (channel == 0){
 
 val = r;

}
if (channel == 1){
 
 val = g;

}
if (channel == 2){
 
 val = b;
 
}
colorMode(RGB, 127, 127, 127);
background(r, g, b);
}

but it doesn't work.
for me, it's quite obvious to store incoming data to variables then use it in a function.

can you guys see where's the problem?

thank you.

Re: simple color mixer with controller
Reply #1 - Feb 17th, 2009, 9:55am
 
Might work better if you write: r = val; and similar instead of the reverse... Smiley
Note that with this code, you don't mix, you will have only one primary color set at a time. You might want to keep the r g b variables outside of the function.
Re: simple color mixer with controller
Reply #2 - Feb 17th, 2009, 12:14pm
 
thanks, it works in that way.
but as you said, it does not mix color at all.

I have honestly no idea at all where to start to make a working color mixer.

any kind of little help will be appriciated.
an example, a website, a reference...whaetver.


thanks a lot.
Re: simple color mixer with controller
Reply #3 - Feb 17th, 2009, 5:06pm
 
Perhaps try:
Code:
int r = 0;
int g = 0;
int b = 0;
void controllerIn(Controller controller, int device, int channel) {
//every fader has controller number of 7
int num = controller.getNumber();
int val = controller.getValue();
if (channel == 0) {
r = val;
} else if (channel == 1) {
g = val;
} else if (channel == 2) {
b = val;
}
colorMode(RGB, 127, 127, 127);
background(r, g, b);
}

I no longer have Midi devices, so I can't try.
Re: simple color mixer with controller
Reply #4 - Feb 17th, 2009, 5:36pm
 
thank you infinitely, it works very very fine.
though I don't really get the idea how "else if" can change all...

I'm really sorry to bother you again, but there's one other small problem, that is the alpha value in background function not working at all. I've just added

int a = 0;
...
else if (channel == 3){
a = val;
}
...
colorMode(RGB, 127,127,127,127);
background(r,g,b,a);

for me, it has to work as other values, can you see what's going on here?

Re: simple color mixer with controller
Reply #5 - Feb 17th, 2009, 6:16pm
 
The else changes nothing... Smiley
That's only a pet peeve of mine, I think once you have found one value, there is no need to test the next values.
Here, it is just a question of style, as performance is unchanged, of course.

I think you got the alpha right, but by definition, background is below everything, so you won't see anything by transparency: the alpha value cannot be seen (it alone doesn't change luminosity/brightness or something like that).
Re: simple color mixer with controller
Reply #6 - Feb 17th, 2009, 6:32pm
 
I finally understood and confirmed my understanding of alpha by successfully placing a rect under another rect that I control the alpha value.

I'll develop further my color mixer by layering rects and use different color schemes. if it'll go well, I'll post here later.

it has been a good lesson to have thread with you.

thank you very much.
Page Index Toggle Pages: 1