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 › midi input data problem!
Page Index Toggle Pages: 1
midi input data problem! (Read 513 times)
midi input data problem!
Jan 1st, 2009, 3:30pm
 
hey, i'm quite new to processing, so my problem should be an easy one for you pros!

i'm able to get the midi pitch and velocities from midi input, but how can i use the varibles "vel" and "pit" in the draw method?

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();
}



greetz

thomas
Re: midi input data problem!
Reply #1 - Jan 6th, 2009, 6:55pm
 
you are on a wrong way try this :


int pit, vel;//at the beginning of the sketch

//replace the note event by this
void noteOn(
 Note note,
 int deviceNumber,
 int midiChannel
){
 vel = note.getVelocity();
 pit = note.getPitch();
 println("noteOn, Velocity: " + vel + ", Pitch: " + pit);
}

void noteOff(
 Note note,
 int deviceNumber,
 int midiChannel
){
 pit = note.getPitch();
 println("noteOff, Pitch: " + pit);
}

now you can use pit and vel everywhere
Bye, have fun
Re: midi input data problem!
Reply #2 - Jan 6th, 2009, 7:41pm
 
and this is why double-posting is a bad idea

have already solved this over here:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Syntax;action=display;num=1230819777
Page Index Toggle Pages: 1