• 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
Basic CoreMIDI setup (was Re: Coreaudio-api Digest, Vol 4, Issue 283)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Basic CoreMIDI setup (was Re: Coreaudio-api Digest, Vol 4, Issue 283)


  • Subject: Basic CoreMIDI setup (was Re: Coreaudio-api Digest, Vol 4, Issue 283)
  • From: Kurt Revis <email@hidden>
  • Date: Wed, 17 Oct 2007 11:48:20 -0700

On Oct 17, 2007, at 5:24 AM, Morgan Harris wrote:

The Core MIDI documentation escapes me.

Do you mean that you don't know where it is, or that you don't understand it?


Most of the docs are in MIDIServices.h itself, or the same thing here:
http://developer.apple.com/documentation/MusicAudio/Reference/ CACoreMIDIRef/MIDIServices/CompositePage.html


I have no idea what I'm supposed to do. I tried to setup a basic thing to give me the number of devices attached to the system (as an intro to the whole thing) but even those two lines of code didn't work. Incidentally, they were:

UInt32 foo = MIDIGetNumberOfExternalDevices();
NSLog([NSString stringWithFormat:@"Num devices: %1i", foo]);

in a Cocoa (obj-c) project. The method consistently returned 0. I don't even know what the MIDI Client is, if I'm supposed to create one or if there is already one, and if it somehow pertains to accessing the devices. So, can someone point me in the direction of some good sample code or give me a rundown of how the whole thing hangs together, or tell me what I'm doing wrong?

Take a look at /Developer/Examples/CoreAudio/MIDI/SampleTools/ Echo.cpp if you haven't already. It's a very simple example, but it shows how to set up CoreMIDI, how to enumerate MIDI sources and destinations, and how to get input and send output.


Yes, you should create a MIDI client; it represents your app's connection to CoreMIDI, and lets you set up callbacks for configuration changes and so on. You only need to do this once, when your app starts. CoreMIDI may be nice and create one for you if you don't do it, but I wouldn't rely on that.

I suspect you don't understand what an "external device" is. The names are confusing. In CoreMIDI, a "device" is typically something like a USB MIDI interface -- some piece of hardware that can send and receive MIDI data. An "external device" is entirely different: It's a representation of something that is connected to a device via a MIDI cable, like a synthesizer or keyboard.

By default, no external devices will be present, because OS X doesn't have any way to discover them automatically. Users typically create them using Audio MIDI Setup, by using the "Add Device" button. If you haven't done that, it makes sense that you'd get 0 external devices back.

You probably want to use MIDIGetNumberOfDevices() instead; that should return the number of MIDI interfaces that are present.

Most of the time apps don't care about devices themselves, all they want to know is what endpoints (sources and destinations) are available. In that case you'd use MIDIGetNumberOfSources(), MIDIGetSource(), MIDIGetNumberOfEndpoints(), MIDIGetEndpoint(), etc. Again, Echo.cpp shows how to do this.

(By the way, the first argument to NSLog needs to be a format specifier; it isn't safe to just log an arbitrary string, because it could have % characters in it. You should be doing this:
NSLog(@"Num devices: %1i", foo);
)


--
Kurt Revis
email@hidden

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Re: Coreaudio-api Digest, Vol 4, Issue 283 (From: "Morgan Harris" <email@hidden>)

  • Prev by Date: Re: AUSplitter and kAudioUnitSubType_Splitter
  • Next by Date: Re: AudioDevice Callback Frequency
  • Previous by thread: Re: Coreaudio-api Digest, Vol 4, Issue 283
  • Next by thread: AudioFileOpenWithCallbacks() bug
  • Index(es):
    • Date
    • Thread