From 98b32db971856143c753581e3af1829124ee280b Mon Sep 17 00:00:00 2001 From: Sjoerd van der Berg Date: Fri, 28 Mar 2003 07:57:30 +0000 Subject: [PATCH] CoreAudio midi support Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@824 --- src/gui/midi_coreaudio.h | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 src/gui/midi_coreaudio.h diff --git a/src/gui/midi_coreaudio.h b/src/gui/midi_coreaudio.h new file mode 100644 index 00000000..8b95418c --- /dev/null +++ b/src/gui/midi_coreaudio.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2002-2003 The DOSBox Team + * + * 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 Library 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_coreaudio : public MidiHandler { +private: + AudioUnit m_musicDevice; + AudioUnit m_outputUnit; +public: + MidiHandler_coreaudio() : m_musicDevice(0), m_outputUnit(0) {} + char * GetName(void) { return "coreaudio"; } + bool Open(const char * conf) { + int err; + AudioUnitConnection auconnect; + ComponentDescription compdesc; + Component compid; + + if (m_outputUnit) + return false; + + // Open the Music Device + compdesc.componentType = kAudioUnitComponentType; + compdesc.componentSubType = kAudioUnitSubType_MusicDevice; + compdesc.componentManufacturer = kAudioUnitID_DLSSynth; + compdesc.componentFlags = 0; + compdesc.componentFlagsMask = 0; + compid = FindNextComponent(NULL, &compdesc); + m_musicDevice = (AudioUnit) OpenComponent(compid); + + // open the output unit + m_outputUnit = (AudioUnit) OpenDefaultComponent(kAudioUnitComponentType, kAudioUnitSubType_Output); + + // connect the units + auconnect.sourceAudioUnit = m_musicDevice; + auconnect.sourceOutputNumber = 0; + auconnect.destInputNumber = 0; + err = + AudioUnitSetProperty(m_outputUnit, kAudioUnitProperty_MakeConnection, kAudioUnitScope_Input, 0, + (void *)&auconnect, sizeof(AudioUnitConnection)); + + // initialize the units + AudioUnitInitialize(m_musicDevice); + AudioUnitInitialize(m_outputUnit); + + // start the output + AudioOutputUnitStart(m_outputUnit); + + return true; + } + + void Close(void) { + if (m_outputUnit) { + AudioOutputUnitStop(m_outputUnit); + CloseComponent(m_outputUnit); + m_outputUnit = 0; + } + if (m_musicDevice) { + CloseComponent(m_musicDevice); + m_musicDevice = 0; + } + } + + void PlayMsg(Bit32u msg) { + MusicDeviceMIDIEvent(m_musicDevice, + (msg & 0x000000FF), + (msg & 0x0000FF00) >> 8, + (msg & 0x00FF0000) >> 16, + 0); + } + + void PlaySysex(Bit8u * sysex, Bitu len) { + MusicDeviceSysEx(m_musicDevice, sysex, len); + } +}; + +MidiHandler_coreaudio Midi_coreaudio;