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