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.
IndexProcessing DevelopmentLibraries,  Tool Development › ProMidi using multiple input channels
Page Index Toggle Pages: 1
ProMidi using multiple input channels (Read 956 times)
ProMidi using multiple input channels
Oct 18th, 2007, 10:21pm
 
This might be an obvious question, but how can I listen for noteOn events on all 16 channels. For example...

Code:

int midiInputDeviceNum = 0;

void setup(){

midiIO = MidiIO.getInstance(this);
midiIO.printDevices();

for(int i=0; i<16; i++){
// open input channels
midiIO.openInput(midiInputDeviceNum, i);
// assign events to inputs
// how can the event say which channel it is?
midiIO.plug(this, "noteOn", midiInputDeviceNum, i);
}

}

void noteOn(Note note){
int vel = note.getVelocity();
int pit = note.getPitch();
println("velocity = " + vel + " pitch = "+pit);
}


The event recognises when I send notes on different channels, but I've no way of knowing which channel it was on.

Any ideas? Thanks
Re: ProMidi using multiple input channels
Reply #1 - Oct 18th, 2007, 10:38pm
 
Wait a minute. It looks like you're just opening devices on channel one, for starters -- don't you want?

midiIO.openInput(midiInputDeviceNum, i);

Plug also receives based on channel number, according to the ProMIDI documentation:
plug(i_object, i_methodName, i_intputDeviceNumber, i_midiChannel);

So there would be a number ways to do this, depending on what you want to do with that channel number. If you were building a multi-timbral synth, for instance, you might have an array of each channel and process the array to route the note where you want it to go.

In JavaSound, the MidiMessage class is the actual MIDI message... so there, for the range 0x90 to 0x9F in the data byte, the low nibble is the channel number. That's how to get at it in a note on / note off message if you're ready to get your hands a little dirty. See:
http://java.sun.com/products/java-media/sound/doc-midi.html

Does that answer the question?
Re: ProMidi using multiple input channels
Reply #2 - Oct 18th, 2007, 10:45pm
 
Quote:
Wait a minute. It looks like you're just opening devices on channel one, for starters -- don't you want?

midiIO.openInput(midiInputDeviceNum, i);


Oops, that was me just trying to paste a simpler version of the code for this forum as i had stripped some stuff out. Have changed the post. Thats not it anyway.

Quote:
Plug also receives based on channel number, according to the ProMIDI documentation:
plug(i_object, i_methodName, i_intputDeviceNumber, i_midiChannel);


Yeah I have that in my for loop
midiIO.plug(this, "noteOn", midiInputDeviceNum, i);

However, how do I get the channel from the event noteOn called?

I tried this but it didn't work

void noteOn(Note note, int channel){
}

Thanks

p.s. I've just looked at the Director Midi Xtra and you can only read inputs from one channel at a time I think.
Re: ProMidi using multiple input channels
Reply #3 - Oct 18th, 2007, 11:02pm
 
You can definitely read inputs from more than one channel at a time. Have you tried using plug to route to different channels? I.e., it's ugly, but create 16 methods, one for each channel? Unless I'm missing something, that appears to be the only way to do this: the Note class doesn't include a channel information parameter, and there doesn't appear to be a raw Message as an alternative. To me, this is a problem with ProMIDI: Note ought to have a channel parameter, and it doesn't. That's out of line with the MIDI spec itself, in which that's all embedded in the same message.

Alternatively, you could just go to javax.sound.midi and get notes that way directly, using the method I mentioned above (just read channel information right out of the note on message).
Re: ProMidi using multiple input channels
Reply #4 - Oct 18th, 2007, 11:08pm
 
But it only likes a method called NoteOn, as you specify the plug like

midiIO.plug(this, "noteOn", midiInputDeviceNum, i);  

So it listens for noteOn and then calls method noteOn. There doesn't seem to be a way of specifying calling different methods either.

I've emailed the author anyway as I think its probably to do with the library.
Re: ProMidi using multiple input channels
Reply #5 - Oct 18th, 2007, 11:12pm
 
Ah, yes, I see that now. I can't even get plug to work properly here on XP; now I have to go figure out why.

I'd recommend using the standard javax.sound.midi, honestly.
Re: ProMidi using multiple input channels
Reply #6 - Oct 19th, 2007, 10:33am
 
Alright seems that the plug methods need some testing, though when I implemented this everything seemed to work. I will think about adding the channeldata to the note, I will also add a method to define a plug for all Channels.

I think it also makes sense to pass the midiChannel, to the plug so I will check the parameters of the plugmethod and send the channel.
Page Index Toggle Pages: 1