RtMidi crash...

Hi,

I am currently trying to use RtMidi in OpenFrameworks and have used these instructions http://forum.openframeworks.cc/t/making-an-rtmidi-addon/595/0 to import it into my project. I can make a new MIDI output object and create a virtual port and connect to a port with no errors. However, when I try to send a midi message, I get a crash and I don’t know why. Has anyone else had any issues, or can perhaps give some insight into the issue?

If I get this working properly, I may see if I can make this into a proper Addon.

I am using OS X 10.5.2

RtMidi can be a little tricky to setup, especially if you’re new to C++.

Can you show the code you’re using to send the midi message?

Cheers,
P.

Hehe, I’m not even new to C++ :slight_smile:

Thanks

Seems ok to me.

You say the program freezes, perhaps you’re getting stuck somewhere in the update loop? Have you tried attaching a debugger to your frozen program while running?

Hope this helps,
P.

Ok, I ran it through the debugger and have stepped through the sendMessage function and found the line that was causing the problems

  
  
CoreMidiData *data = static_cast<CoreMidiData *> (apiData_);  
  

I’m at a loss to figure out what is wrong. When I step over that line, the debugger said that the program recieved the signal “EXC_BAD_ACCESS”

  
  
void RtMidiOut :: sendMessage( std::vector<unsigned char> *message )  
{  
  unsigned int nBytes = message->size();  
  // Pad the buffer for extra (unknown) structure data.  
  Byte buffer[nBytes+32];  
  MIDIPacketList *pktlist = (MIDIPacketList *) buffer;  
  MIDIPacket *curPacket = MIDIPacketListInit( pktlist );  
  
  MIDITimeStamp timeStamp = 0;  
  curPacket = MIDIPacketListAdd( pktlist, sizeof(buffer), curPacket, timeStamp, nBytes, &message->at(0) );  
  
  CoreMidiData *data = static_cast<CoreMidiData *> (apiData_);  
  
  // Send to any destinations that may have connected to us.  
  OSStatus result;  
  if ( data->endpoint ) {  
    result = MIDIReceived( data->endpoint, pktlist );  
    if ( result != noErr ) {  
      errorString_ = "RtMidiOut::sendMessage: error sending MIDI to virtual destinations.";  
      error( RtError::WARNING );  
    }  
  }  
  
  // And send to an explicit destination port if we're connected.  
  if ( connected_ ) {  
    result = MIDISend( data->port, data->destinationId, pktlist );  
    if ( result != noErr ) {  
      errorString_ = "RtMidiOut::sendMessage: error sending MIDI message to port.";  
      error( RtError::WARNING );  
    }  
  }  
}  
  

If anyone can help that’d be cool :slight_smile:

Well, this isn’t such an issue anymore as I decided to start writing my own library directly with CoreMidi on OS X.

I’ve currently got noteOn and noteOff commands that work like this

ofxMidi.sendNoteOn(channel, noteNumber, velocity);

I’ll add some more commands and then release the source code. The syntax for using this will be a lot easier as it doesn’t involve any vectors or pointers like RtMidi as well as not having to construct the midi message yourself.

When I’m done with the OS X version, I may try and take a look at windows and linux too.