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 & HelpSound,  Music Libraries › How to use Midi Controller for Graphics
Page Index Toggle Pages: 1
How to use Midi Controller for Graphics? (Read 1189 times)
How to use Midi Controller for Graphics?
Mar 6th, 2010, 3:51pm
 
Hello All,

Im working on a sound visualisation project and I just bought a Korg nano Kontrol, thinking that i could tweak some of my code graphical values with it.
Im a total amateur, and maybe its just a lexical problem, but i couldnt find anything to show me the way. Can someone orient me on a library  or just simply post a code that would change the background from black to white using a midi controler?
thanks in advance
Re: How to use Midi Controller for Graphics?
Reply #1 - Mar 7th, 2010, 4:40am
 
Ok guys,

I think Im getting closer, using the Midibus library. Here is the code, im trying to change the ellipse fill color using my sliders and knobs. I can see it prints correct values, but the ellipse doesnt seem to react. I also dont know how to assign tasks to specific knobs and sliders.

Quote:
import themidibus.*; //Import the library

MidiBus myBus; // The MidiBus

void setup() {
     size(400,400);
     background(0);
     MidiBus.list();
     myBus = new MidiBus(this, "nanoKONTROL 1 SLIDER/KNOB", "nanoKONTROL 1 CTRL"); //
}

void draw() {
     int channel = 0;
     int number = 0;
     int value = 90;
       
      fill(value, value, 0);      
      ellipse(200,200,90,90);

     myBus.sendControllerChange(channel, number, value); // Send a controllerChange
}

void controllerChange(int channel, int number, int value) {
     // Receive a controllerChange
     println();
     println("Channel:"+channel);
     println("Number:"+number);
     println("Value:"+value);
}


Re: How to use Midi Controller for Graphics?
Reply #2 - Mar 7th, 2010, 4:47am
 
I guess your code should be :

Code:
import themidibus.*;

MidiBus myBus;
color controllerValue = 0;

void setup() {
 size(400,400);
 background(0);
 MidiBus.list();
 myBus = new MidiBus(this, "nanoKONTROL 1 SLIDER/KNOB", "nanoKONTROL 1 CTRL");
}

void draw() {
 fill(controllerValue, controllerValue, 0);      
 ellipse(200,200,90,90);
}

void controllerChange(int channel, int number, int value) {
 controllerValue = value;
}


To listen to a specific controller, just do a conditional test in the controllerChange() method :

Code:
void controllerChange(int channel, int number, int value) {
 switch(number) {
   case 1:
     // controller #1
     // do something
     break;
   case 2:
    // controller #2
     // do something
     break;
 }
}
Re: How to use Midi Controller for Graphics?
Reply #3 - Mar 7th, 2010, 8:20am
 

Thanks Antiplastik,
its working perfectly.
Page Index Toggle Pages: 1