From 8f3474ecfdb00d41281f265510b315b2b9161e1e Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Sun, 10 Nov 2019 14:50:11 +0000 Subject: [PATCH 1/2] Make it possible to compile without CoreMIDI and CoreAudio on Mac OS X using a non-Apple compiler. Give some feedback to user in this case. (modified version of patch by krcroft with input from jmarsh, Dominus and Qbix) Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4281 --- configure.ac | 28 +++++++++++++++++++++++++++- include/midi.h | 9 ++++++++- src/gui/midi.cpp | 8 +++++++- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index af394c65..d65acfbc 100644 --- a/configure.ac +++ b/configure.ac @@ -189,6 +189,33 @@ CXXFLAGS="$CXXFLAGS -mno-ms-bitfields" ],[AC_MSG_RESULT([no])]) CFLAGS="$BACKUP_CFLAGS" +dnl When on macOS, enable support for Apple's Core MIDI and/or Core Audio if our compiler can #include their headers +case "$host" in + *-*-darwin*) + AC_MSG_CHECKING(if compiler supports Apple's Core MIDI headers) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + #include + int blah() { return 0; } + ]])], [AC_MSG_RESULT(yes);LIBS="$LIBS -framework CoreMIDI";AC_DEFINE([C_SUPPORTS_COREMIDI], [], + [Compiler supports Core MIDI headers])], + AC_MSG_RESULT(no);AC_MSG_WARN([Compiler can't compile Apple headers. CoreMIDI functionality disabled. Please use the Apple compiler!])) + + AC_MSG_CHECKING(if compiler supports Apple's Core Audio headers) + AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ + #include + #include + int blah() { return 0; } + ]])], [AC_MSG_RESULT(yes);LIBS="$LIBS -framework AudioUnit -framework AudioToolbox";AC_DEFINE([C_SUPPORTS_COREAUDIO], [], + [Compiler supports Core Audio headers])], + AC_MSG_RESULT(no);AC_MSG_WARN([Compiler can't compile Apple headers. CoreAudio functionality disabled. Please use the Apple compiler!])) + ;; + + *) + AC_MSG_CHECKING(if compiler supports Apple's MIDI headers) + AC_MSG_RESULT([no, not on Apple]) + ;; +esac + dnl enable disable alsa and pass it's cflags to CXXFLAGS AC_ARG_ENABLE(alsa-midi, AC_HELP_STRING([--enable-alsa-midi],[compile with alsa midi support (default yes)]), @@ -564,7 +591,6 @@ case "$host" 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 CoreMIDI -framework AudioUnit -framework AudioToolbox" AC_DEFINE(C_DIRECTSERIAL, 1, [ Define to 1 if you want serial passthrough support (Win32, Posix and OS/2).]) ;; *-*-linux*) diff --git a/include/midi.h b/include/midi.h index ea9afdad..773b6e6c 100644 --- a/include/midi.h +++ b/include/midi.h @@ -20,6 +20,10 @@ #ifndef DOSBOX_MIDI_H #define DOSBOX_MIDI_H +#ifndef DOSBOX_DOSBOX_H +#include "dosbox.h" +#endif + #ifndef DOSBOX_PROGRAMS_H #include "programs.h" #endif @@ -27,7 +31,10 @@ class MidiHandler { public: MidiHandler(); - virtual bool Open(const char * /*conf*/) { return true; }; + virtual bool Open(const char * /*conf*/) { + LOG_MSG("No working midi device found/selected! Please check your settings and/or compilation environment."); + return true; + }; virtual void Close(void) {}; virtual void PlayMsg(Bit8u * /*msg*/) {}; virtual void PlaySysex(Bit8u * /*sysex*/,Bitu /*len*/) {}; diff --git a/src/gui/midi.cpp b/src/gui/midi.cpp index b5361051..28b65f46 100644 --- a/src/gui/midi.cpp +++ b/src/gui/midi.cpp @@ -68,12 +68,18 @@ MidiHandler::MidiHandler(){ MidiHandler Midi_none; -/* Include different midi drivers, lowest ones get checked first for default */ +/* Include different midi drivers, lowest ones get checked first for default. + Each header provides an independent midi interface. */ #if defined(MACOSX) +#if defined(C_SUPPORTS_COREMIDI) #include "midi_coremidi.h" +#endif + +#if defined(C_SUPPORTS_COREAUDIO) #include "midi_coreaudio.h" +#endif #elif defined (WIN32) From 92da7c45ef7d2aa42d662558a198229f229089b0 Mon Sep 17 00:00:00 2001 From: Peter Veenstra Date: Mon, 11 Nov 2019 17:23:05 +0000 Subject: [PATCH 2/2] Switch to a different way to calculate the table offsets. Thanks jmarsh Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@4282 --- src/hardware/dbopl.cpp | 9 +++------ src/hardware/dbopl.h | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/hardware/dbopl.cpp b/src/hardware/dbopl.cpp index acbf2b8f..0a616c40 100644 --- a/src/hardware/dbopl.cpp +++ b/src/hardware/dbopl.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include "dosbox.h" #include "dbopl.h" @@ -1430,7 +1431,6 @@ void InitTables( void ) { TremoloTable[TREMOLO_TABLE - 1 - i] = val; } //Create a table with offsets of the channels from the start of the chip - DBOPL::Chip* chip = 0; for ( Bitu i = 0; i < 32; i++ ) { Bitu index = i & 0xf; if ( index >= 9 ) { @@ -1444,8 +1444,7 @@ void InitTables( void ) { //Add back the bits for highest ones if ( i >= 16 ) index += 9; - Bitu blah = reinterpret_cast( &(chip->chan[ index ]) ); - ChanOffsetTable[i] = blah; + ChanOffsetTable[i] = (Bit16u)(index*sizeof(DBOPL::Channel)); } //Same for operators for ( Bitu i = 0; i < 64; i++ ) { @@ -1458,9 +1457,7 @@ void InitTables( void ) { if ( chNum >= 12 ) chNum += 16 - 12; Bitu opNum = ( i % 8 ) / 3; - DBOPL::Channel* chan = 0; - Bitu blah = reinterpret_cast( &(chan->op[opNum]) ); - OpOffsetTable[i] = ChanOffsetTable[ chNum ] + blah; + OpOffsetTable[i] = ChanOffsetTable[chNum]+(Bit16u)(opNum*sizeof(DBOPL::Operator)); } #if 0 //Stupid checks if table's are correct diff --git a/src/hardware/dbopl.h b/src/hardware/dbopl.h index addaed77..97dc7cac 100644 --- a/src/hardware/dbopl.h +++ b/src/hardware/dbopl.h @@ -156,7 +156,7 @@ public: }; struct Channel { - Operator op[2]; + Operator op[2]; //Leave on top of struct for simpler pointer math. inline Operator* Op( Bitu index ) { return &( ( this + (index >> 1) )->op[ index & 1 ]); } @@ -192,6 +192,9 @@ struct Channel { }; struct Chip { + //18 channels with 2 operators each. Leave on top of struct for simpler pointer math. + Channel chan[18]; + //This is used as the base counter for vibrato and tremolo Bit32u lfoCounter; Bit32u lfoAdd; @@ -208,9 +211,6 @@ struct Chip { //Best match attack rates for the rate of this chip Bit32u attackRates[76]; - //18 channels with 2 operators each - Channel chan[18]; - Bit8u reg104; Bit8u reg08; Bit8u reg04;