Re: Send MIDI Sequence to GarageBand
Re: Send MIDI Sequence to GarageBand
- Subject: Re: Send MIDI Sequence to GarageBand
- From: Chris Adamson <email@hidden>
- Date: Fri, 16 Sep 2011 21:22:35 -0400
Mike--
Hi.
Yeah.
It sounds like you have a lot of things going on at once in your post. You've already gotten some guidance from Paul and Alexis, but you seem to need more basic info to acquaint yourself to the OS X platform.
Few, if any, Apple libraries are separate downloads. You don't need to download Core Audio because you already have it. Apple distributes most of its libraries -- particularly the stuff that isn't just inherited from Darwin or other parts of the open-source community -- as .frameworks, which include the executable code library, headers, and optionally things like localizations, media resources (graphics, sounds, video), documentation, etc. These are all included with the platform SDK. When you create a project in Xcode and add in a non-standard framework (via target -> build phases -> link binary with libraries), you can press the "+" button and you'll see frameworks appropriate to your project, and they'll be things like:
AudioToolbox.framework
AudioUnit.framework
CoreAudio.framework
CoreMIDI.framework
Most audio applications for Mac and iOS actually only need the higher level AudioToolbox.framework, though we often refer to the group of these as "Core Audio", given their inter-relationships. For a MIDI app, you would actually need CoreMIDI.framework too.
Speaking of Xcode… that's something that's different about the Mac and iOS platform. Apple uses Xcode as a means of distributing both their IDE and specific SDKs. Downloading the current version of Xcode will get you SDKs for Mac OS X 10.7 and iOS 4.3. At install-time, there's an option to include the common build tools used by non-Xcode projects, stuff like make and ant. These go into /Developer and /usr/bin, and can be called by arbitrary build scripts.
Setting aside what you may or may not think is a fair price for the tools that enable you to do your work -- Eclipse and NetBeans are free, but lots of Java developers pay for IntelliJ IDEA because it's so much better -- Xcode 4.1.1 appears to be free from the Mac App Store for Lion-based developers. Xcode 4.0 had been charging $4.95 for Snow Leopard on Mac App Store, but I don't know if that's still the case. If you think $5 is still inappropriate in this day and age, I suspect that at the hourly rate of a competent programmer, it will cost you more to type up a complaint about it than to just let it slide, but you go ahead and do as you see fit.
Once you've got the tools, what you need is CoreMIDI. This framework has a few Objective-C classes for network-based MIDI I/O, and a plain-C API for working with real and virtual MIDI devices. You can read its documentation in Xcode's viewer, or here:
http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/CACoreMIDIRef/_index.html
As Paul said, to create a virtual device, you would probably create a MIDIPortRef with MIDIOutputPortCreate(), and then send events to it with MIDISend(). These C APIs use the Core Foundation techniques for laying a pseudo-OO approach over the procedural C functions, so you will have to learn that CF stuff as a prerequisite.
If you are keen on calling it from Java, you will presumably be using JNI. Since JNI uses C as its native bridge, the calls into native code should be pretty straightforward to envision.
Once built, I think Garage Band would see your output port as a real MIDI device; if not, open up /Applications/Utilities/Audio MIDI Setup and see if you have to configure "IAC" (inter-application communication) to get them connected.
Core Audio doesn't have as much sample code or practical documentation from Apple as it probably could or should. Communities like this mailing list, the devforums at apple.com, and the core-audio tag on Stack Overflow have built up a substantial -- if disorganized and ad hoc -- collection of knowledge over the years.
There is a book on Core Audio coming very soon. Most of it's available as a "Rough Cut" book on Safari Books Online: http://my.safaribooksonline.com/book/audio/9780321636973 . The MIDI chapter just got finished last week, and the author blogged about it here: http://www.subfurther.com/blog/2011/09/06/messin-with-midi/
Finally, I would like to ask if you've got a really good reason to be writing a MIDI application in Java in 2011. J2SE does have a package for this stuff, javax.sound.midi. If you need to go native, I have to suspect that has left you wanting? It's understandable. I used to specialize in Java media applications, and got out when it was clear that media was hopelessly orthogonal to the nature and direction of the Java platform. A good way to make that point is the saying "Java, media… choose at most one."
Actually, the person who said that wrote a whole book on calling QuickTime from Java a few years back. He's also the one writing the Core Audio book.
And he just finished writing this post.
--Chris
On Sep 16, 2011, at 7:57 PM, Michael B Allen wrote:
> On Wed, Sep 14, 2011 at 12:29 PM, Paul Davis <email@hidden> wrote:
>> On Wed, Sep 14, 2011 at 12:22 PM, Michael B Allen <email@hidden> wrote:
>>> Hello,
>>>
>>> Is it possible to write a Java program that OSX will see as a virtual
>>> MIDI device (just like it might see a real MIDI USB keyboard) so that
>>> I can programmatically generate and send MIDI sequences through
>>> GarageBand?
>>
>> a possibly simpler solution is not to worry about trying to create a
>> virtual MIDI *device* and just create a regular CoreMIDI output port.
>> then use Pete Yandell's MIDI patchbay to wire your app to Garageband.
>
> Hi Paul et al,
>
> Ok. So I'm all exited about trying this over the weekend and I cannot
> even find the CoreAudio libraries. Where can I download the CoreAudio
> jar or .so or whatever libs? Where is the API documentation? I cannot
> find anything on developer.apple.com. Do I have to install Xcode? I
> love how the Apple developer site says "Xcode 4 is a free download for
> all members of the iOS and Mac Developer Programs" but to become a
> member of the Mac Developer Program costs $99 / year. I'm used to the
> GNU tool chain on Linux so maybe I'm spoiled but I don't know if ANY
> company that charges people just to compile something. Even Microsoft
> gives you cl.exe with their basic SDK. WTH Apple. I don't even want
> Xcode. Can I not do this with a jar and vi?
>
> I'm a total newbie to CoreAudio. Can someone give me a pointer?
>
> Mike
> _______________________________________________
> 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
_______________________________________________
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