diff --git a/configure.in b/configure.in index b453220f..0b1ba0f9 100644 --- a/configure.in +++ b/configure.in @@ -404,7 +404,7 @@ case "$target" in dnl to do more to distinguish them. dnl For now I am lazy and do not add proper detection code. AC_DEFINE(MACOSX, 1, [Compiling on Mac OS X]) - LIBS="$LIBS -framework AudioUnit" + LIBS="$LIBS -framework CoreMidi -framework AudioUnit" AC_DEFINE(C_DIRECTSERIAL, 1, [ Define to 1 if you want serial passthrough support (Win32, Posix and OS/2).]) ;; *-*-linux*) diff --git a/src/gui/midi.cpp b/src/gui/midi.cpp index 22407130..85a6a8fe 100644 --- a/src/gui/midi.cpp +++ b/src/gui/midi.cpp @@ -80,6 +80,7 @@ MidiHandler Midi_none; #if defined(MACOSX) #include "midi_coreaudio.h" +#include "midi_coremidi.h" #elif defined (WIN32) diff --git a/src/gui/midi_coremidi.h b/src/gui/midi_coremidi.h new file mode 100644 index 00000000..4f44fe2b --- /dev/null +++ b/src/gui/midi_coremidi.h @@ -0,0 +1,105 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +class MidiHandler_coremidi : public MidiHandler { +private: + MIDIPortRef m_port; + MIDIClientRef m_client; + MIDIEndpointRef m_endpoint; + MIDIPacket* m_pCurPacket; +public: + MidiHandler_coremidi() {m_pCurPacket = 0;} + char * GetName(void) { return "coremidi"; } + bool Open(const char * conf) { + + // Get the MIDIEndPoint + m_endpoint = 0; + OSStatus result; + Bitu numDests = MIDIGetNumberOfDestinations(); + Bitu destId = 0; + if(conf && conf[0]) destId = atoi(conf); + if (destId < numDests) + { + m_endpoint = MIDIGetDestination(destId); + } + + // Create a MIDI client and port + MIDIClientCreate(CFSTR("MyClient"), 0, 0, &m_client); + + if (!m_client) + { + LOG_MSG("MIDI:coremidi: No client created."); + return false; + } + + MIDIOutputPortCreate(m_client, CFSTR("MyOutPort"), &m_port); + + if (!m_port) + { + LOG_MSG("MIDI:coremidi: No port created."); + return false; + } + + + return true; + } + + void Close(void) { + // Dispose the port + MIDIPortDispose(m_port); + + // Dispose the client + MIDIClientDispose(m_client); + + // Dispose the endpoint + MIDIEndpointDispose(m_endpoint); + } + + void PlayMsg(Bit8u * msg) { + // Acquire a MIDIPacketList + Byte packetBuf[128]; + MIDIPacketList *packetList = (MIDIPacketList *)packetBuf; + m_pCurPacket = MIDIPacketListInit(packetList); + + // Determine the length of msg + Bitu len=MIDI_evt_len[*msg]; + + // Add msg to the MIDIPacketList + MIDIPacketListAdd(packetList, (ByteCount)sizeof(packetBuf), m_pCurPacket, (MIDITimeStamp)0, len, msg); + + // Send the MIDIPacketList + MIDISend(m_port,m_endpoint,packetList); + } + + void PlaySysex(Bit8u * sysex, Bitu len) { + // Acquire a MIDIPacketList + Byte packetBuf[SYSEX_SIZE*4]; + Bitu pos=0; + MIDIPacketList *packetList = (MIDIPacketList *)packetBuf; + m_pCurPacket = MIDIPacketListInit(packetList); + + // Add msg to the MIDIPacketList + MIDIPacketListAdd(packetList, (ByteCount)sizeof(packetBuf), m_pCurPacket, (MIDITimeStamp)0, len, sysex); + + // Send the MIDIPacketList + MIDISend(m_port,m_endpoint,packetList); + } +}; + +MidiHandler_coremidi Midi_coremidi; +