• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: General CoreMIDI Newbie-Questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: General CoreMIDI Newbie-Questions


  • Subject: Re: General CoreMIDI Newbie-Questions
  • From: Kurt Revis <email@hidden>
  • Date: Sat, 28 Dec 2002 13:30:29 -0800

On Saturday, December 28, 2002, at 08:49 AM, Oliver Jaun wrote:

It is not a problem to send a sysex message. But then how do I get the response? I know that I can specify a completionProc in the MIDISysexSendRequest struct. But then how do I wait for the answer?

The completionProc just tells you about the status of *sending* the sysex message. It doesn't have anything to do with a response. In general the CoreMIDI API provides one-way communication; it's up to you to write code to manage a two-way conversation.

In order to receive MIDI data, you need to create a MIDI input port and hook it up to one (or more) source endpoints. See /Developer/Examples/CoreAudio/MIDI/SampleTools/Echo.cpp for a brief example.

DeviceInquiryMessage DataProvider::getDeviceInquiryMessage() {

Byte data[] = { _SYSEX_MSG, 0x7E, _deviceId, 0x06, 0x01, _EOX };
// create MIDISysexSendRequest struct here.
OSStatus status = MIDISendSysex(&sysx);

// wait for completion... but how? while(sysx.complete == false); ???
// get the result... but how????
// create DeviceInquiryMessage Object

return DeviceInquiryMessage;
}


One problem here is that this method must block forever, waiting for a response. However, a response may never come. What if the MIDI device is unplugged or turned off? These are both pretty common cases, and it would be bad for your whole program to hang while it waits.

Basically, your program needs to implement a state machine. (Google for "finite state machine", or look in a programming textbook, for more details.) Your program would start with its state set to 'idle'. When you send a sysex message, you would set the state to 'listening'. Then, when you get a response, your MIDIReadProc will be called; you should have it check the state, do the appropriate thing, and then update the state. How you design this state machine is up to you.

Also, you will probably want to have a timeout. If no response happens after a while (perhaps 1 second) then you should assume that something has gone wrong with the MIDI device you're trying to talk to. Both Carbon and Cocoa provide timers you can use.

You do *not* want to sit in a loop waiting for a flag to be set. This will use a lot of CPU time for no benefit. Instead, think of things in terms of events: when an event happens, some function in your program will be called. (There are separate functions for receiving MIDI, timeouts firing, and so on.) Each function should look at the current state, figure out what to do, do it, and update the state.

I'm omitting a lot of details here, but I hope you get the general idea.

--
Kurt Revis
email@hidden
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: General CoreMIDI Newbie-Questions
      • From: Oliver Jaun <email@hidden>
References: 
 >General CoreMIDI Newbie-Questions (From: Oliver Jaun <email@hidden>)

  • Prev by Date: Re: ANN: Transverb with AUCarbonView
  • Next by Date: Re: General CoreMIDI Newbie-Questions
  • Previous by thread: General CoreMIDI Newbie-Questions
  • Next by thread: Re: General CoreMIDI Newbie-Questions
  • Index(es):
    • Date
    • Thread