OfxPD - Receiving messages/MIDI

Hi,

I am trying to pass data such as MIDI, bangs and messages between a PD patch and OpenFrameworks.

As easy as it was to work out how to send messages from the program to the PD patch, I can’t for the life of me figure out how to reverse this and receive data from the patch to use in the program.

for instance:

sendMessage("MYSOURCE", "TEST", testList);

Will send the message “TEST” to whatever in the patch is listening for “MYSOURCE”.

But this function:

receiveMessage();

also requires a source, a message and a list, which I don’t quite understand.

Basically, is there a way I can grab a message or some midi data from a specific source or channel when some get sent? I may very well be missing something obvious here.

Cheers.

Look at the ofxPd example.

  1. inherit a PdMidiReceiver with a class, generally your ofApp
  2. declare the receive functions in your header
  3. implement the receive functions in your cpp
  4. set the midi receiver so ofxPd/libpd know where to forward events aka call your classes’s receive callbacks

Messages (aka bang, float, symbol, etc) work in the same way, except you inherit a PdReceiever. You will also need to register for receiver names you want to receive messages from. Again, this is all in the admittedly boring example which, if you read through it, should contain everything you’ll need to know.

Many thanks for your help, I was just looking at it in completely the wrong way! I’m trying to use it in conjunction with ofxmidi and I’ve finally got some some audible midi which is immensely satisfying.

Sure. I designed both APIs to be compatible. Once you get the receiver classes working, it’s pretty easy to get going.

Sorry for reactivating this thread again… :slight_smile:

I have some questions about the infos above:
I dont understand if i need ofxMidi runing or not to receive midi from an interface.
I think the above mentioned pdExample should be set to receive midi signals?
How do I get the controller changes in PD. Is it the normal way with ctlin object?
Another question would be how often midi is exchanged? Is it done in the Audiothread or in somethin different?

Thanks!

When i implement ofxMidi…

I am getting the following error:

ofApp.cpp:153:8: error: reference to ‘StartMidi’ is ambiguous
<< StartMidi(1) << 239 << Finish()

any ideas on this?
Is that maybe connected to the c++ version or namespace?
It seams to be something with giving parameters to pd via stream.
Deleting the whole block now brings me to a working example.

Find out my self. Giving midi to pd is not done automaticaly:

i did it like following:

//--------------------------------------------------------------
void ofApp::newMidiMessage(ofxMidiMessage& msg) {

	// make a copy of the latest message
	midiMessage = msg;
	pd.sendControlChange(midiChan, 0, midiMessage.control);

}

ofxMidi is an add-on for OF, not an application by itself. You use it within your app to be bale to send/receive MIDI messages.

The basic pdExample included with ofxPd does not use ofxMidi. It only sends & receives messages & MIDI dat to/from the internal libpd instance. In order to send & received MIDI data outside of the app and with your system, you need to manually add ofxMidi to your project and pass the MIDI messages between the ofxMidi callbacks and ofxPd.

This is what the original topic of this thread is about, so read above.

This is up to you. You can either use the built-in ring buffer which passes messages as quickly as possible within the audio thread or you can process received messages manually using receiveMessages() and receiveMidi(). See the ofxPd.h comments.