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 listen to MIDI, for each note draw a blob
Page Index Toggle Pages: 1
How to listen to MIDI, for each note draw a blob (Read 928 times)
How to listen to MIDI, for each note draw a blob
Apr 22nd, 2009, 8:39am
 
I am new to Processing -- I tried themidibus and the sample works.  I wrote the following, and it works once in a while.  (The same sketch -- no change.)  At other times, the noteOn never comes (no writeln, no sound).  The mouse always responds.  Can someone help?  Or is there an alternate package I should use?  (I've downloaded jmetude because of its power, but when I ask it to play a midi file -- only a few lines of code! -- it played but the timing on each of the voices were off.  So I haven't tried to use it for this purpose yet.  Intend to use it eventually.)

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

MidiBus myBus; // The MidiBus

void setup() {
     size(400,400);
     background(0);
     
     MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
     
     //                 Parent         In                   Out
     //                   |            |                     |
     myBus = new MidiBus(this, "Creative Prodikeys PC-MIDI", "Out-B USB MIDISPORT 2x2"); // Create a new MidiBus using the device names to select the Midi input and output devices respectively.
}

void draw() {
     delay(200);
}

void mousePressed() {
     int channel = 0;
     int pitch = 64;
     int velocity = 127;
     myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
     delay(200);
     myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
}
     
     
void noteOn(int channel, int pitch, int velocity) {
     // Receive a noteOn
     println();
     println("Note On:");
     println("--------");
     println("Channel:"+channel);
     println("Pitch:"+pitch);
     println("Velocity:"+velocity);
  // draw eye pattern
        coloteNote(pitch, velocity);
     myBus.sendNoteOn(channel, pitch, velocity); // Send a Midi noteOn
}

void noteOff(int channel, int pitch, int velocity) {
     // Receive a noteOff
     println();
     println("Note Off:");
     println("--------");
     println("Channel:"+channel);
     println("Pitch:"+pitch);
     println("Velocity:"+velocity);
  // draw eye pattern
        coloteNote(pitch, 0);
     myBus.sendNoteOff(channel, pitch, velocity); // Send a Midi nodeOff
}

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

void coloteNote(int pitch, int velocity) {
     // Receive a noteOff
     println();
     println("Color:");
     println("--------");
     println("Pitch:"+pitch);
     println("Velocity:"+velocity);
  // draw eye pattern
        fill(204*velocity/128, 102*velocity/128, 30*velocity/128);
        beginShape();
        curveVertex(84,  91);
        curveVertex(84,  91);
        curveVertex(68,  19);
        curveVertex(21,  17);
        curveVertex(32, 100);
        curveVertex(32, 100);
        endShape();
}

Re: How to listen to MIDI, for each note draw a blob
Reply #1 - Apr 23rd, 2009, 6:55am
 
I figured out the problem: midibus is not compatible with Creative Prodikeys PC-MIDI, which is a USB-based dual keyboard (text and music) and use software driver to generate the MIDI streams.
Re: How to listen to MIDI, for each note draw a blob
Reply #2 - Apr 23rd, 2009, 4:43pm
 
It appears that it may be similar case on the Mac as well, even after mmj was used.  It seems like USB-based keyboards (in this case Oxygen 48) causes exception in Processing after the first notein, which disables it...
Page Index Toggle Pages: 1