diff --git a/README.md b/README.md index 68476fc..a7d0009 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,33 @@ make cp -L libADLMIDI.so ../../ADLMidi.NET/runtimes/linux-x64/native ``` +## macOS (Apple Silicon): +Requires Xcode command-line tools and CMake. Tested on macOS 14 (arm64); the same flags should also produce an x86_64 dylib if `-DCMAKE_OSX_ARCHITECTURES=x86_64` is passed (untested here). cmake produces a versioned dylib (`libADLMIDI.1.6.2.dylib`) plus two install-name symlinks; copy the unversioned `libADLMIDI.dylib` and rename to `libadlmidi.dylib` to match the cross-platform lowercase name the wrapper P/Invokes. + +``` +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_OSX_ARCHITECTURES=arm64 \ + -DlibADLMIDI_STATIC=OFF \ + -DlibADLMIDI_SHARED=ON \ + -DWITH_EMBEDDED_BANKS=OFF \ + -DWITH_XMI_SUPPORT=ON \ + -DUSE_DOSBOX_EMULATOR=OFF \ + -DUSE_NUKED_EMULATOR=ON \ + -DUSE_OPAL_EMULATOR=OFF \ + -DUSE_JAVA_EMULATOR=OFF \ + -DUSE_ESFMU_EMULATOR=OFF \ + -DUSE_MAME_EMULATOR=OFF \ + -DUSE_YMFM_EMULATOR=OFF \ + .. +make +[ -d ../../ADLMidi.NET/runtimes/osx-arm64/native ] || mkdir -p ../../ADLMidi.NET/runtimes/osx-arm64/native +cp -L libADLMIDI.dylib ../../ADLMidi.NET/runtimes/osx-arm64/native/libadlmidi.dylib +``` + +The linker produces an adhoc code signature automatically on Apple Silicon (no manual `codesign` step needed). Verify with `codesign -dv libadlmidi.dylib` (expect `Signature=adhoc`). + ## Windows: * Run CMake setup program * Pick libADLMIDI directory diff --git a/src/ADLMidi.NET.Tests/DllImportFixture.cs b/src/ADLMidi.NET.Tests/DllImportFixture.cs index 59e2feb..b7311a1 100644 --- a/src/ADLMidi.NET.Tests/DllImportFixture.cs +++ b/src/ADLMidi.NET.Tests/DllImportFixture.cs @@ -28,6 +28,12 @@ public DllImportFixture() ? name : name + ".so"; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + filename = string.Equals(Path.GetExtension(name), ".DYLIB", StringComparison.OrdinalIgnoreCase) + ? name + : name + ".dylib"; + } else throw new PlatformNotSupportedException(); var fullPath = Path.Combine(root, "runtimes", runtime, "native", filename); diff --git a/src/ADLMidi.NET/MidiPlayer.cs b/src/ADLMidi.NET/MidiPlayer.cs index 7b55cf7..f676510 100644 --- a/src/ADLMidi.NET/MidiPlayer.cs +++ b/src/ADLMidi.NET/MidiPlayer.cs @@ -408,7 +408,7 @@ public unsafe int Generate(Span buffer) /// The user data to pass to the callback. public void SetNoteHook(NoteHook noteHook, IntPtr userData) => AdlMidiImports.adl_setNoteHook(_device, noteHook, userData); -#if false + // Real-time API — send MIDI events directly to the synth for live playback. public void RealTimeResetState() => AdlMidiImports.adl_rt_resetState(_device); public int RealTimeNoteOn(byte channel, byte note, byte velocity) => AdlMidiImports.adl_rt_noteOn(_device, channel, note, velocity); public void RealTimeNoteOff(byte channel, byte note) => AdlMidiImports.adl_rt_noteOff(_device, channel, note); @@ -421,8 +421,7 @@ public unsafe int Generate(Span buffer) public void RealTimeBankChangeLSB(byte channel, byte lsb) => AdlMidiImports.adl_rt_bankChangeLSB(_device, channel, lsb); public void RealTimeBankChangeMSB(byte channel, byte msb) => AdlMidiImports.adl_rt_bankChangeMSB(_device, channel, msb); public void RealTimeBankChange(byte channel, short bank) => AdlMidiImports.adl_rt_bankChange(_device, channel, bank); - public int RealTimeSystemExclusive(IntPtr message, UIntPtr size) => AdlMidiImports.adl_rt_systemExclusive(_device, message, size); -#endif + public unsafe int RealTimeSystemExclusive(IntPtr message, UIntPtr size) => AdlMidiImports.adl_rt_systemExclusive(_device, (byte*)message, size); #if false public void SetRawEventHook(AdlMidiImports.RawEventHook rawEventHook, IntPtr userData) => AdlMidiImports.adl_setRawEventHook(_device, rawEventHook, userData); diff --git a/src/ADLMidi.NET/runtimes/osx-arm64/native/libadlmidi.dylib b/src/ADLMidi.NET/runtimes/osx-arm64/native/libadlmidi.dylib new file mode 100755 index 0000000..7172074 Binary files /dev/null and b/src/ADLMidi.NET/runtimes/osx-arm64/native/libadlmidi.dylib differ diff --git a/src/TestApp/Program.cs b/src/TestApp/Program.cs index 64af4ea..63370bd 100644 --- a/src/TestApp/Program.cs +++ b/src/TestApp/Program.cs @@ -242,6 +242,12 @@ static void SetupDllLoader() ? name : name + ".so"; } + else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + filename = string.Equals(Path.GetExtension(name), ".DYLIB", StringComparison.OrdinalIgnoreCase) + ? name + : name + ".dylib"; + } else throw new PlatformNotSupportedException(); var fullPath = Path.Combine(root, "runtimes", runtime, "native", filename);