1
0
Fork 0

Add (modified) version of patch 1490638: Coremidi support by Peter McCombs

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@3062
This commit is contained in:
Peter Veenstra 2007-12-12 19:18:39 +00:00
parent ecb56a96ac
commit a1b4e1c778
3 changed files with 107 additions and 1 deletions

View file

@ -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*)

View file

@ -80,6 +80,7 @@ MidiHandler Midi_none;
#if defined(MACOSX)
#include "midi_coreaudio.h"
#include "midi_coremidi.h"
#elif defined (WIN32)

105
src/gui/midi_coremidi.h Normal file
View file

@ -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 <CoreMIDI/MIDIServices.h>
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;