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 & HelpSyntax Questions › woriking with midi data input
Page Index Toggle Pages: 1
woriking with midi data input (Read 289 times)
woriking with midi data input
Jan 1st, 2009, 3:22pm
 
Hey,
i'm quite new to processing. I'm fighting with the code concerning working with midi data input. I'm able to get pitch and velocity, but i want to use these variables "vel" and "pit" to manipulate my visual stuff.

please help!

code:




import JMyron.*;
import promidi.*;

import processing.opengl.*;
JMyron m;//a camera object
MidiIO midiIO;
int MyMusic = noteOff(Note note, int deviceNumber, int midiChannel);


void setup(){
 size(1024,576);
 m = new JMyron();//make a new instance of the object
 m.start(width,height);//start a capture at 320x240
 //m.findGlobs(20);//disable the intelligence to speed up frame rate
 println("Myron " + m.version());
 rectMode(RIGHT);
 stroke(0,0,0);
 
  midiIO = MidiIO.getInstance(this);
 println("printPorts of midiIO");
 midiIO.printDevices();
 //÷ffnen des LoopBe Inputs, Channel 3(== Wert 2) <- MUSS angepasst werden
 midiIO.openInput(0,0);
 frameRate(120);

 
 

 
}
int noteOn(
 Note note,
 int deviceNumber,
 int midiChannel
){
 //Aus der ¸bergebenen Note holen wir uns Velocity und Pitch
 int vel = note.getVelocity();
 int pit = note.getPitch();
 println("noteOn, Velocity: " + vel + ", Pitch: " + pit);
 return vel;
}

//Event Handler f¸r den Midi Befehl Note On.
//Wird ausgef¸hrt, sobald ¸ber das geˆffnete Device ein NoteOff kommt.
int noteOff(
 Note note,
 int deviceNumber,
 int midiChannel
){
 //Aus der ¸bergebenen Note holen wir uns Velocity
  int pit = note.getPitch();
 println("noteOff, Pitch: " + pit);
 return pit;
}






void draw(){
 background(0);


 m.update();//update the camera view
 int[] img = m.image(); //get the normal image of the camera
 float r,g,b;
 for(int y=0;y<height;y+=5){ //loop through all the pixels
   for(int x=0;x<width;x+=100){ //loop through all the pixels
     float av = (red(img[y*width])+red(img[y*width])+red(img[y*width]))/10;
     fill(red(123),green(20),blue(20));
      fill(255);
     
     pushMatrix();
     

     translate(y*10,y+200);
     
       for(int j = 10; j<200; j = j+1) {
      rotate(av/j);
     }
     
     for(int i = 0; i<10; i = i+1) {
       rect(0,0,av*i,av*i/(i/10));
     }
     popMatrix();
   }
 }
 //saveFrame("glitch3-####.tiff");
}






void mousePressed(){
 m.settings();//click the window to get the settings
}

public void stop(){
 m.stop();//stop the object
 super.stop();
}




thx
Re: woriking with midi data input
Reply #1 - Jan 2nd, 2009, 9:56pm
 
> i want to use these variables "vel" and "pit" to manipulate my visual stuff.

then define them outside the methods (ie before setup()) and then they'll have global scope and you can set them and read them anywhere.

int pit; // global pitch

setup() {
...
}

then in noteOn() and noteOff() just set using

pit = note.getPitch();

(ie remove the 'int' so that you aren't defining a local variable of the same name)

and please don't post the exact same question in multiple places as it makes searching difficult.
Page Index Toggle Pages: 1