Skip to content

CoreMIDI tvOS xcode14.0 beta1

TJ Lambert edited this page Sep 9, 2022 · 3 revisions

#CoreMIDI.framework https://github.com/xamarin/xamarin-macios/pull/15917

diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h	2022-02-12 06:58:47.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/CoreMIDI.h	2022-05-21 05:15:26.000000000 -0400
@@ -20,6 +20,7 @@
 #include <CoreMIDI/MIDIThruConnection.h>
 #include <CoreMIDI/MIDIDriver.h>
 #include <CoreMIDI/MIDIMessages.h>
+#include <CoreMIDI/MIDIBluetoothConnection.h>
 
 #if __OBJC__
 #import <CoreMIDI/MIDINetworkSession.h>
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIBluetoothConnection.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIBluetoothConnection.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIBluetoothConnection.h	1969-12-31 19:00:00.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIBluetoothConnection.h	2022-06-03 18:07:24.000000000 -0400
@@ -0,0 +1,82 @@
+/*
+    File:       CoreMIDI/MIDIBluetoothConnection.h
+ 
+    Contains:   Routines for connecting MIDI over Bluetooth LE.
+ 
+    Copyright:  (c) 2022 by Apple Inc., all rights reserved.
+ 
+    Bugs?:      For bug reports, consult the following page on
+                the World Wide Web:
+ 
+                    http://feedbackassistant.apple.com/
+ 
+*/
+
+#pragma once
+#include <CoreFoundation/CoreFoundation.h>
+#include <CoreMIDI/MIDIServices.h>
+
+CF_ASSUME_NONNULL_BEGIN
+
+//  -----------------------------------------------------------------------------
+/*!
+    @header MIDIBluetoothConnection.h
+
+    The following methods are used to register connected Bluetooth Low Energy
+    MIDI peripherals with CoreMIDI so that MIDI I/O becomes possible and to
+	programmatically disconnect a BLE MIDI peripheral from CoreMIDI.
+        
+*/
+//  -----------------------------------------------------------------------------
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// =================================================================================================
+
+/*!
+	@function       MIDIBluetoothDriverActivateAllConnections
+
+	@abstract       Promotes all active CoreBluetooth connections to peripherals' Bluetooth LE MIDI
+					service into online MIDI devices capable of I/O.
+	 
+	@result         An OSStatus result code.
+
+	@discussion
+		To programmatically establish a Bluetooth MIDI driver connection to a LE MIDI peripheral,
+		the following steps must be completed in order.
+		
+		1. Using CoreBluetooth API, scan for the peripheral's advertised LE MIDI service.
+		2. Using CoreBluetooth API, connect to the desired advertised peripheral.
+		3. Upon successful connection, call MIDIBluetoothDriverActivateAllConnections.
+		4. Using CoreMIDI API, confirm the peripheral's registration by locating its MIDIDeviceRef.
+		5. If present, CoreMIDI now owns a connection the peripheral.
+		6. Using CoreBluetooth API, disconnect from the peripheral now managed by CoreMIDI.
+*/
+extern OSStatus
+MIDIBluetoothDriverActivateAllConnections(void) API_AVAILABLE(macos(13.0), ios(16.0));
+
+/*!
+	@function       MIDIBluetoothDriverDisconnect
+
+	@abstract       Disconnects the Bluetooth MIDI driver from a BLE MIDI peripheral.
+	
+	@param          uuid
+						A string representation of the CoreBluetooth UUI for a connected peripheral.
+ 
+	@result         An OSStatus result code.
+
+	@discussion
+		If a CoreMIDI is connected to a BLE MIDI peripheral with the supplied UUID, it will disconnect.
+*/
+extern OSStatus
+MIDIBluetoothDriverDisconnect(__nonnull CFStringRef uuid) API_AVAILABLE(macos(13.0), ios(16.0));
+
+#ifdef __cplusplus
+}
+#endif
+
+CF_ASSUME_NONNULL_END
+
diff -ruN /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIMessages.h /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIMessages.h
--- /Applications/Xcode_13.3.0.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIMessages.h	2022-02-23 07:10:28.000000000 -0500
+++ /Applications/Xcode_14.0.0-beta.app/Contents/Developer/Platforms/AppleTVOS.platform/Developer/SDKs/AppleTVOS.sdk/System/Library/Frameworks/CoreMIDI.framework/Headers/MIDIMessages.h	2022-06-03 18:09:42.000000000 -0400
@@ -213,13 +213,18 @@
     return sysExOut;
 }
 
+static const UInt8 kMIDI1UPMaxSysexSize = 6;
 CF_INLINE MIDIMessage_64 MIDI1UPSysExArray(UInt8 group, UInt8 status, const Byte *begin, const Byte *end)
 {
-    Byte arrayCopy[6] = {};
-    int numberOfBytes = end <= begin ? 0 : end - begin;
-    for (int i = 0; i < numberOfBytes; ++i)
-        arrayCopy[i] = *(begin + i);
-    return MIDI1UPSysEx(group, status, numberOfBytes, arrayCopy[0], arrayCopy[1], arrayCopy[2], arrayCopy[3], arrayCopy[4], arrayCopy[5]);
+	int numberOfBytes = end <= begin ? 0 : end - begin;
+	if (numberOfBytes > kMIDI1UPMaxSysexSize) numberOfBytes = kMIDI1UPMaxSysexSize; // prevent overflow
+    return MIDI1UPSysEx(group, status, numberOfBytes,
+						numberOfBytes > 0 ? *begin : 0,
+						numberOfBytes > 1 ? *(begin + 1) : 0,
+						numberOfBytes > 2 ? *(begin + 2) : 0,
+						numberOfBytes > 3 ? *(begin + 3) : 0,
+						numberOfBytes > 4 ? *(begin + 4) : 0,
+						numberOfBytes > 5 ? *(begin + 5) : 0);
 }
 
 //==================================================================================================
@@ -232,7 +237,7 @@
 	Word0: [aaaa][bbbb][cccc][dddd][eeeeeeeeeeeeeeee]
 	Word1: [nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn]
 	
-	a: Message Type (type 1 for all voice messages)
+	a: Message Type (type 4 for all voice messages)
 	b: Channel group number
 	c: MIDI status
 	d: MIDI channel
Clone this wiki locally