From 2f2f93c58d4bdb5cd4e7b9de2b336a302d13354c Mon Sep 17 00:00:00 2001 From: Steffan Andrews Date: Thu, 30 Sep 2021 02:06:30 -0700 Subject: [PATCH] Fixed access levels --- .../MIDIIOSendsMIDIMessagesProtocol.swift | 12 +- .../AnyMIDIIOObject/AnyMIDIIOObject.swift | 6 +- .../Endpoint/MIDIIOEndpointProtocol.swift | 10 +- .../MIDIIOObjectProtocol Comparison.swift | 13 +- ...ObjectProtocol Properties Dictionary.swift | 12 +- .../MIDIIOObjectProtocol Properties.swift | 190 +++++------------- .../MIDIIOObjectProtocol.swift | 118 +++++++++++ .../IO/Inputs and Outputs/Output Tests.swift | 11 +- .../OutputConnection Tests.swift | 13 +- 9 files changed, 207 insertions(+), 178 deletions(-) diff --git a/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOSendsMIDIMessagesProtocol.swift b/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOSendsMIDIMessagesProtocol.swift index 4cab809609..87871a8c18 100644 --- a/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOSendsMIDIMessagesProtocol.swift +++ b/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOSendsMIDIMessagesProtocol.swift @@ -126,12 +126,10 @@ extension _MIDIIOSendsMIDIMessagesProtocol { } -extension MIDIIOSendsMIDIMessagesProtocol { +extension _MIDIIOSendsMIDIMessagesProtocol { @inline(__always) - public func send(event: MIDI.Event) throws - where Self : _MIDIIOSendsMIDIMessagesProtocol - { + public func send(event: MIDI.Event) throws { switch api { case .legacyCoreMIDI: @@ -145,14 +143,13 @@ extension MIDIIOSendsMIDIMessagesProtocol { } try send(rawWords: event.umpRawWords(protocol: self.midiProtocol)) + } } @inline(__always) - public func send(events: [MIDI.Event]) throws - where Self : _MIDIIOSendsMIDIMessagesProtocol - { + public func send(events: [MIDI.Event]) throws { switch api { case .legacyCoreMIDI: @@ -168,6 +165,7 @@ extension MIDIIOSendsMIDIMessagesProtocol { for event in events { try send(rawWords: event.umpRawWords(protocol: self.midiProtocol)) } + } } diff --git a/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift b/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift index c1e9b045d1..ea0d57f53c 100644 --- a/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift +++ b/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift @@ -31,12 +31,10 @@ extension MIDI.IO { } -extension MIDIIOObjectProtocol { +extension _MIDIIOObjectProtocol { /// Return as `AnyMIDIIOObject`, a type-erased representation of a MIDIKit object conforming to `MIDIIOObjectProtocol`. - public func asAnyMIDIIOObject() -> MIDI.IO.AnyMIDIIOObject - where Self : _MIDIIOObjectProtocol - { + public func asAnyMIDIIOObject() -> MIDI.IO.AnyMIDIIOObject { .init(self) diff --git a/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift b/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift index 65b6d4ffdc..3117a29c05 100644 --- a/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift +++ b/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift @@ -7,19 +7,21 @@ public protocol MIDIIOEndpointProtocol: MIDIIOObjectProtocol { + // implemented in extension _MIDIIOEndpointProtocol + + func getEntity() -> MIDI.IO.Entity? + } internal protocol _MIDIIOEndpointProtocol: MIDIIOEndpointProtocol, _MIDIIOObjectProtocol { } -extension MIDIIOEndpointProtocol { +extension _MIDIIOEndpointProtocol { public var objectType: MIDI.IO.ObjectType { .endpoint } - internal func getEntity() -> MIDI.IO.Entity? - where Self : _MIDIIOEndpointProtocol - { + public func getEntity() -> MIDI.IO.Entity? { try? MIDI.IO.getSystemEntity(for: self.coreMIDIObjectRef) diff --git a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Comparison.swift b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Comparison.swift index 9189f17e0e..f6d1e75f67 100644 --- a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Comparison.swift +++ b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Comparison.swift @@ -7,11 +7,9 @@ // (conforming types to MIDIIOObjectProtocol just need to conform to Equatable and this implementation will be used) -extension MIDIIOObjectProtocol { +extension _MIDIIOObjectProtocol { - static public func == (lhs: Self, rhs: Self) -> Bool - where Self : _MIDIIOObjectProtocol - { + static public func == (lhs: Self, rhs: Self) -> Bool { lhs.coreMIDIObjectRef == rhs.coreMIDIObjectRef @@ -23,12 +21,9 @@ extension MIDIIOObjectProtocol { // (conforming types to MIDIIOObjectProtocol just need to conform to Hashable and this implementation will be used) -extension MIDIIOObjectProtocol { +extension _MIDIIOObjectProtocol { - /// Hash - public func hash(into hasher: inout Hasher) - where Self : _MIDIIOObjectProtocol - { + public func hash(into hasher: inout Hasher) { hasher.combine(self.coreMIDIObjectRef) diff --git a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties Dictionary.swift b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties Dictionary.swift index a12db0dcf5..6693ad04f5 100644 --- a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties Dictionary.swift +++ b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties Dictionary.swift @@ -5,15 +5,13 @@ import Foundation -extension MIDIIOObjectProtocol { +extension _MIDIIOObjectProtocol { /// Get all properties as a key/value pair array, formatted as human-readable strings. /// Useful for displaying in a user interface or outputting to console for debugging. public func getPropertiesAsStrings( onlyIncludeRelevant: Bool = true - ) -> [(key: String, value: String)] - where Self : _MIDIIOObjectProtocol - { + ) -> [(key: String, value: String)] { ( onlyIncludeRelevant @@ -28,14 +26,12 @@ extension MIDIIOObjectProtocol { } -extension MIDIIOObjectProtocol { +extension _MIDIIOObjectProtocol { /// Returns a human-readable key and value pair for the property. internal func getPropertyKeyValuePairAsStrings( of property: MIDI.IO.kMIDIProperty - ) -> (key: String, value: String) - where Self : _MIDIIOObjectProtocol - { + ) -> (key: String, value: String) { switch property { diff --git a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties.swift b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties.swift index 99fab2e3a2..54f6eeb95a 100644 --- a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties.swift +++ b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Properties.swift @@ -16,7 +16,7 @@ import UIKit // MARK: - Properties (Computed) -extension MIDIIOObjectProtocol { +extension _MIDIIOObjectProtocol { // MARK: Identification @@ -28,9 +28,7 @@ extension MIDIIOObjectProtocol { /// A studio setup editor may allow the user to set the names of both driver-owned and external devices. /// /// - Throws: `MIDI.IO.MIDIError` - public func getName() -> String? - where Self : _MIDIIOObjectProtocol - { + public func getName() -> String? { try? MIDI.IO.getName(of: self.coreMIDIObjectRef) } @@ -43,9 +41,7 @@ extension MIDIIOObjectProtocol { /// - Creators of virtual endpoints may set this property on their endpoints. /// /// - Throws: `MIDI.IO.MIDIError` - public func getModel() -> String? - where Self : _MIDIIOObjectProtocol - { + public func getModel() -> String? { try? MIDI.IO.getModel(of: self.coreMIDIObjectRef) } @@ -58,9 +54,7 @@ extension MIDIIOObjectProtocol { /// - Creators of virtual endpoints may set this property on their endpoints. /// /// - Throws: `MIDI.IO.MIDIError` - public func getManufacturer() -> String? - where Self : _MIDIIOObjectProtocol - { + public func getManufacturer() -> String? { try? MIDI.IO.getManufacturer(of: self.coreMIDIObjectRef) } @@ -68,9 +62,7 @@ extension MIDIIOObjectProtocol { /// (`kMIDIPropertyUniqueID`) /// /// The system assigns unique IDs to all objects. Creators of virtual endpoints may set this property on their endpoints, though doing so may fail if the chosen ID is not unique. - public func getUniqueID() -> UniqueID - where Self : _MIDIIOObjectProtocol - { + public func getUniqueID() -> UniqueID { UniqueID(MIDI.IO.getUniqueID(of: self.coreMIDIObjectRef)) } @@ -78,9 +70,7 @@ extension MIDIIOObjectProtocol { /// (`kMIDIPropertyDeviceID`) /// /// MIDI drivers can set this property on their devices or entities. Studio setup editors can allow the user to set this property on external devices. - public func getDeviceManufacturerID() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getDeviceManufacturerID() -> Int32 { MIDI.IO.getDeviceManufacturerID(of: self.coreMIDIObjectRef) } @@ -88,25 +78,19 @@ extension MIDIIOObjectProtocol { /// Get a Boolean value that indicates whether the device or entity implements the MIDI Machine Control portion of the MIDI specification. /// (`kMIDIPropertySupportsMMC`) - public func getSupportsMMC() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getSupportsMMC() -> Bool { MIDI.IO.getSupportsMMC(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity implements the General MIDI specification. /// (`kMIDIPropertySupportsGeneralMIDI`) - public func getSupportsGeneralMIDI() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getSupportsGeneralMIDI() -> Bool { MIDI.IO.getSupportsGeneralMIDI(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device implements the MIDI Show Control specification. /// (`kMIDIPropertySupportsShowControl`) - public func getSupportsShowControl() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getSupportsShowControl() -> Bool { MIDI.IO.getSupportsShowControl(of: self.coreMIDIObjectRef) } @@ -117,9 +101,7 @@ extension MIDIIOObjectProtocol { /// /// - requires: macOS 10.15, macCatalyst 13.0, iOS 13.0 @available(macOS 10.15, macCatalyst 13.0, iOS 13.0, *) - public func getNameConfigurationDictionary() -> NSDictionary? - where Self : _MIDIIOObjectProtocol - { + public func getNameConfigurationDictionary() -> NSDictionary? { try? MIDI.IO.getNameConfigurationDictionary(of: self.coreMIDIObjectRef) } @@ -127,9 +109,7 @@ extension MIDIIOObjectProtocol { /// (`kMIDIPropertyMaxSysExSpeed`) /// /// The owning driver may set an integer value for this property. - public func getMaxSysExSpeed() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getMaxSysExSpeed() -> Int32 { MIDI.IO.getMaxSysExSpeed(of: self.coreMIDIObjectRef) } @@ -139,9 +119,7 @@ extension MIDIIOObjectProtocol { /// Only drivers may set this property on their owned devices. /// /// - Throws: `MIDI.IO.MIDIError` - public func getDriverDeviceEditorApp() -> URL? - where Self : _MIDIIOObjectProtocol - { + public func getDriverDeviceEditorApp() -> URL? { try? MIDI.IO.getDriverDeviceEditorApp(of: self.coreMIDIObjectRef) } @@ -155,17 +133,13 @@ extension MIDIIOObjectProtocol { /// A studio setup editor should allow the user to choose icons for external devices. /// /// - Throws: `MIDI.IO.MIDIError` - public func getImageFileURL() -> URL? - where Self : _MIDIIOObjectProtocol - { + public func getImageFileURL() -> URL? { try? MIDI.IO.getImage(of: self.coreMIDIObjectRef) } #if canImport(AppKit) && os(macOS) /// Calls `getImageFileURL` and attempts to initialize a new `NSImage`. - public func getImageAsNSImage() -> NSImage? - where Self : _MIDIIOObjectProtocol - { + public func getImageAsNSImage() -> NSImage? { guard let url = getImageFileURL() else { return nil } return NSImage(contentsOf: url) } @@ -173,9 +147,7 @@ extension MIDIIOObjectProtocol { #if canImport(UIKit) /// Calls `getImageFileURL` and attempts to initialize a new `UIImage`. - public func getImageAsUIImage() -> UIImage? - where Self : _MIDIIOObjectProtocol - { + public func getImageAsUIImage() -> UIImage? { guard let url = getImageFileURL(), let data = try? Data(contentsOf: url) else { return nil } return UIImage(data: data) @@ -189,9 +161,7 @@ extension MIDIIOObjectProtocol { /// For objects other than endpoints, the display name is the same as its `kMIDIPropertyName` value. /// /// - Throws: `MIDI.IO.MIDIError` - public func getDisplayName() -> String? - where Self : _MIDIIOObjectProtocol - { + public func getDisplayName() -> String? { try? MIDI.IO.getDisplayName(of: self.coreMIDIObjectRef) } @@ -199,9 +169,7 @@ extension MIDIIOObjectProtocol { /// Get a Boolean value that indicates whether the MIDI pan messages sent to the device or entity cause undesirable effects when playing stereo sounds. /// (`kMIDIPropertyPanDisruptsStereo`) - public func getPanDisruptsStereo() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getPanDisruptsStereo() -> Bool { MIDI.IO.getPanDisruptsStereo(of: self.coreMIDIObjectRef) } @@ -216,9 +184,7 @@ extension MIDIIOObjectProtocol { /// /// - requires: macOS 11.0, macCatalyst 14.0, iOS 14.0 @available(macOS 11.0, macCatalyst 14.0, iOS 14.0, *) - public func getProtocolID() -> MIDI.IO.ProtocolVersion? - where Self : _MIDIIOObjectProtocol - { + public func getProtocolID() -> MIDI.IO.ProtocolVersion? { guard let proto = MIDI.IO.getProtocolID(of: self.coreMIDIObjectRef) else { return nil } return .init(proto) } @@ -227,33 +193,25 @@ extension MIDIIOObjectProtocol { /// Get a Boolean value that indicates whether the device or entity transmits MIDI Time Code messages. /// (`kMIDIPropertyTransmitsMTC`) - public func getTransmitsMTC() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getTransmitsMTC() -> Bool { MIDI.IO.getTransmitsMTC(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity responds to MIDI Time Code messages. /// (`kMIDIPropertyReceivesMTC`) - public func getReceivesMTC() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getReceivesMTC() -> Bool { MIDI.IO.getReceivesMTC(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity transmits MIDI beat clock messages. /// (`kMIDIPropertyTransmitsClock`) - public func getTransmitsClock() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getTransmitsClock() -> Bool { MIDI.IO.getTransmitsClock(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity responds to MIDI beat clock messages. /// (`kMIDIPropertyReceivesClock`) - public func getReceivesClock() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getReceivesClock() -> Bool { MIDI.IO.getReceivesClock(of: self.coreMIDIObjectRef) } @@ -267,9 +225,7 @@ extension MIDIIOObjectProtocol { /// You can also set this property on any virtual destinations you create. When clients send messages to a virtual destination with an advance schedule time of 0, the destination receives the messages at the scheduled delivery time. If a virtual destination has a nonzero advance schedule time, it receives timestamped messages as soon as they’re sent, and must do its own internal scheduling of events it receives. /// /// - Throws: `MIDI.IO.MIDIError` - public func getAdvanceScheduleTimeMuSec() -> String? - where Self : _MIDIIOObjectProtocol - { + public func getAdvanceScheduleTimeMuSec() -> String? { try? MIDI.IO.getAdvanceScheduleTimeMuSec(of: self.coreMIDIObjectRef) } @@ -277,33 +233,25 @@ extension MIDIIOObjectProtocol { /// Get a Boolean value that indicates whether the device or entity mixes external audio signals. /// (`kMIDIPropertyIsMixer`) - public func getIsMixer() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsMixer() -> Bool { MIDI.IO.getIsMixer(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity plays audio samples in response to MIDI note messages. /// (`kMIDIPropertyIsSampler`) - public func getIsSampler() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsSampler() -> Bool { MIDI.IO.getIsSampler(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity primarily acts as a MIDI-controlled audio effect. /// (`kMIDIPropertyIsEffectUnit`) - public func getIsEffectUnit() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsEffectUnit() -> Bool { MIDI.IO.getIsEffectUnit(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity’s samples aren’t transposable, as with a drum kit. /// (`kMIDIPropertyIsDrumMachine`) - public func getIsDrumMachine() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsDrumMachine() -> Bool { MIDI.IO.getIsDrumMachine(of: self.coreMIDIObjectRef) } @@ -315,9 +263,7 @@ extension MIDIIOObjectProtocol { /// `False` indicates the object is present. /// /// (`kMIDIPropertyOffline`) - public func getIsOffline() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsOffline() -> Bool { MIDI.IO.getIsOffline(of: self.coreMIDIObjectRef) } @@ -326,9 +272,7 @@ extension MIDIIOObjectProtocol { /// You can set this property on a device or entity, but it still appears in the API; the system only hides the object’s owned endpoints. /// /// (`kMIDIPropertyPrivate`) - public func getIsPrivate() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsPrivate() -> Bool { MIDI.IO.getIsPrivate(of: self.coreMIDIObjectRef) } @@ -340,17 +284,13 @@ extension MIDIIOObjectProtocol { /// Set by the owning driver, on the device; should not be touched by other clients. Property is inherited from the device by its entities and endpoints. /// /// - Throws: `MIDI.IO.MIDIError` - public func getDriverOwner() -> String? - where Self : _MIDIIOObjectProtocol - { + public func getDriverOwner() -> String? { try? MIDI.IO.getDriverOwner(of: self.coreMIDIObjectRef) } /// Get the version of the driver that owns a device, entity, or endpoint. /// (`kMIDIPropertyDriverVersion`) - public func getDriverVersion() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getDriverVersion() -> Int32 { MIDI.IO.getDriverVersion(of: self.coreMIDIObjectRef) } @@ -360,9 +300,7 @@ extension MIDIIOObjectProtocol { /// (`kMIDIPropertyCanRoute`) /// /// Don’t set this property value on driver-owned devices. - public func getCanRoute() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getCanRoute() -> Bool { MIDI.IO.getCanRoute(of: self.coreMIDIObjectRef) } @@ -370,9 +308,7 @@ extension MIDIIOObjectProtocol { /// (`kMIDIPropertyIsBroadcast`) /// /// Only the owning driver may set this property. - public func getIsBroadcast() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsBroadcast() -> Bool { MIDI.IO.getIsBroadcast(of: self.coreMIDIObjectRef) } @@ -382,25 +318,19 @@ extension MIDIIOObjectProtocol { /// The value provided may be an integer. To indicate that a driver connects to multiple external objects, pass the array of big-endian SInt32 values as a CFData object. /// /// The property is nonexistent or 0 if there’s no connection. - public func getConnectionUniqueID() -> MIDI.IO.CoreMIDIUniqueID - where Self : _MIDIIOObjectProtocol - { + public func getConnectionUniqueID() -> MIDI.IO.CoreMIDIUniqueID { MIDI.IO.getConnectionUniqueID(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether this entity or endpoint has external MIDI connections. /// (`kMIDIPropertyIsEmbeddedEntity`) - public func getIsEmbeddedEntity() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getIsEmbeddedEntity() -> Bool { MIDI.IO.getIsEmbeddedEntity(of: self.coreMIDIObjectRef) } /// Get the 0-based index of the entity on which incoming real-time messages from the device appear to have originated. /// (`kMIDIPropertySingleRealtimeEntity`) - public func getSingleRealtimeEntity() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getSingleRealtimeEntity() -> Int32 { MIDI.IO.getSingleRealtimeEntity(of: self.coreMIDIObjectRef) } @@ -414,25 +344,19 @@ extension MIDIIOObjectProtocol { /// - Studio setup editors can allow the user to set this property on external endpoints. /// - Virtual destinations can set this property on their endpoints. /// - public func getReceiveChannels() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getReceiveChannels() -> Int32 { MIDI.IO.getReceiveChannels(of: self.coreMIDIObjectRef) } /// Get the bitmap of channels on which the object transmits messages. /// (`kMIDIPropertyTransmitChannels`) - public func getTransmitChannels() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getTransmitChannels() -> Int32 { MIDI.IO.getTransmitChannels(of: self.coreMIDIObjectRef) } /// Get the bitmap of channels on which the object transmits messages. /// (`kMIDIPropertyMaxReceiveChannels`) - public func getMaxReceiveChannels() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getMaxReceiveChannels() -> Int32 { MIDI.IO.getMaxReceiveChannels(of: self.coreMIDIObjectRef) } @@ -440,9 +364,7 @@ extension MIDIIOObjectProtocol { /// (`kMIDIPropertyMaxTransmitChannels`) /// /// Common values are 0, 1, or 16. - public func getMaxTransmitChannels() -> Int32 - where Self : _MIDIIOObjectProtocol - { + public func getMaxTransmitChannels() -> Int32 { MIDI.IO.getMaxTransmitChannels(of: self.coreMIDIObjectRef) } @@ -450,33 +372,25 @@ extension MIDIIOObjectProtocol { /// Get a Boolean value that indicates whether the device or entity responds to MIDI bank select LSB messages. /// (`kMIDIPropertyReceivesBankSelectLSB`) - public func getReceivesBankSelectLSB() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getReceivesBankSelectLSB() -> Bool { MIDI.IO.getReceivesBankSelectLSB(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity responds to MIDI bank select MSB messages. /// (`kMIDIPropertyReceivesBankSelectMSB`) - public func getReceivesBankSelectMSB() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getReceivesBankSelectMSB() -> Bool { MIDI.IO.getReceivesBankSelectMSB(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity transmits MIDI bank select LSB messages. /// (`kMIDIPropertyTransmitsBankSelectLSB`) - public func getTransmitsBankSelectLSB() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getTransmitsBankSelectLSB() -> Bool { MIDI.IO.getTransmitsBankSelectLSB(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity transmits MIDI bank select MSB messages. /// (`kMIDIPropertyTransmitsBankSelectMSB`) - public func getTransmitsBankSelectMSB() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getTransmitsBankSelectMSB() -> Bool { MIDI.IO.getTransmitsBankSelectMSB(of: self.coreMIDIObjectRef) } @@ -484,17 +398,13 @@ extension MIDIIOObjectProtocol { /// Get a Boolean value that indicates whether the device or entity responds to MIDI Note On messages. /// (`kMIDIPropertyReceivesNotes`) - public func getReceivesNotes() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getReceivesNotes() -> Bool { MIDI.IO.getReceivesNotes(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity transmits MIDI note messages. /// (`kMIDIPropertyTransmitsNotes`) - public func getTransmitsNotes() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getTransmitsNotes() -> Bool { MIDI.IO.getTransmitsNotes(of: self.coreMIDIObjectRef) } @@ -502,17 +412,13 @@ extension MIDIIOObjectProtocol { /// Get a Boolean value that indicates whether the device or entity responds to MIDI Program Change messages. /// (`kMIDIPropertyReceivesProgramChanges`) - public func getReceivesProgramChanges() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getReceivesProgramChanges() -> Bool { MIDI.IO.getReceivesProgramChanges(of: self.coreMIDIObjectRef) } /// Get a Boolean value that indicates whether the device or entity transmits MIDI Program Change messages. /// (`kMIDIPropertyTransmitsProgramChanges`) - public func getTransmitsProgramChanges() -> Bool - where Self : _MIDIIOObjectProtocol - { + public func getTransmitsProgramChanges() -> Bool { MIDI.IO.getTransmitsProgramChanges(of: self.coreMIDIObjectRef) } diff --git a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol.swift b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol.swift index 3b479d2f0b..86e08c5c06 100644 --- a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol.swift +++ b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol.swift @@ -3,6 +3,16 @@ // MIDIKit • https://github.com/orchetect/MIDIKit // +import Foundation + +#if canImport(AppKit) +import AppKit +#endif + +#if canImport(UIKit) +import UIKit +#endif + public protocol MIDIIOObjectProtocol { /// Enum describing the abstracted object type. @@ -16,6 +26,114 @@ public protocol MIDIIOObjectProtocol { /// The unique ID for the Core MIDI object var uniqueID: UniqueID { get } + + + // The following methods are defined in the public protocol (MIDIIOObjectProtocol) but implemented in an extension on the internal protocol (extension _MIDIIOObjectProtocol) + // This is to satisfy a Swift compiler quirk. + // If the methods are not defined here, they will not be accessible by a consumer of the library. + + + // MARK: - MIDIIOObjectProtocol Comparison.swift + + static func == (lhs: Self, rhs: Self) -> Bool + func hash(into hasher: inout Hasher) + + + // MARK: - MIDIIOObjectProtocol Properties.swift + + // Identification + func getName() -> String? + func getModel() -> String? + func getManufacturer() -> String? + func getUniqueID() -> UniqueID + func getDeviceManufacturerID() -> Int32 + + // Capabilities + func getSupportsMMC() -> Bool + func getSupportsGeneralMIDI() -> Bool + func getSupportsShowControl() -> Bool + + // Configuration + @available(macOS 10.15, macCatalyst 13.0, iOS 13.0, *) + func getNameConfigurationDictionary() -> NSDictionary? + func getMaxSysExSpeed() -> Int32 + func getDriverDeviceEditorApp() -> URL? + + // Presentation + func getImageFileURL() -> URL? + #if canImport(AppKit) && os(macOS) + func getImageAsNSImage() -> NSImage? + #endif + #if canImport(UIKit) + func getImageAsUIImage() -> UIImage? + #endif + func getDisplayName() -> String? + + // Audio + func getPanDisruptsStereo() -> Bool + + // Protocols + @available(macOS 11.0, macCatalyst 14.0, iOS 14.0, *) + func getProtocolID() -> MIDI.IO.ProtocolVersion? + + // Timing + func getTransmitsMTC() -> Bool + func getReceivesMTC() -> Bool + func getTransmitsClock() -> Bool + func getReceivesClock() -> Bool + func getAdvanceScheduleTimeMuSec() -> String? + + // Roles + func getIsMixer() -> Bool + func getIsSampler() -> Bool + func getIsEffectUnit() -> Bool + func getIsDrumMachine() -> Bool + + // Status + func getIsOffline() -> Bool + func getIsPrivate() -> Bool + + // Drivers + func getDriverOwner() -> String? + func getDriverVersion() -> Int32 + + // Connections + func getCanRoute() -> Bool + func getIsBroadcast() -> Bool + func getConnectionUniqueID() -> MIDI.IO.CoreMIDIUniqueID + func getIsEmbeddedEntity() -> Bool + func getSingleRealtimeEntity() -> Int32 + + // Channels + func getReceiveChannels() -> Int32 + func getTransmitChannels() -> Int32 + func getMaxReceiveChannels() -> Int32 + func getMaxTransmitChannels() -> Int32 + + // Banks + func getReceivesBankSelectLSB() -> Bool + func getReceivesBankSelectMSB() -> Bool + func getTransmitsBankSelectLSB() -> Bool + func getTransmitsBankSelectMSB() -> Bool + + // Notes + func getReceivesNotes() -> Bool + func getTransmitsNotes() -> Bool + func getReceivesProgramChanges() -> Bool + func getTransmitsProgramChanges() -> Bool + + + // MARK: - MIDIIOObjectProtocol Properties Dictionary.swift + + func getPropertiesAsStrings( + onlyIncludeRelevant: Bool + ) -> [(key: String, value: String)] + + + // MARK: - AnyMIDIIOObject.swift + + func asAnyMIDIIOObject() -> MIDI.IO.AnyMIDIIOObject + } internal protocol _MIDIIOObjectProtocol: MIDIIOObjectProtocol { diff --git a/Tests/MIDIKitTests/IO/Inputs and Outputs/Output Tests.swift b/Tests/MIDIKitTests/IO/Inputs and Outputs/Output Tests.swift index 5ed6adaccb..be6251c591 100644 --- a/Tests/MIDIKitTests/IO/Inputs and Outputs/Output Tests.swift +++ b/Tests/MIDIKitTests/IO/Inputs and Outputs/Output Tests.swift @@ -54,10 +54,15 @@ final class InputsAndOutputs_Output_Tests: XCTestCase { // send a midi message - XCTAssertNotNil( - _ = try? manager.managedOutputs[tag1]!.send(event: .systemReset(group: 0)) + XCTAssertNoThrow( + try manager.managedOutputs[tag1]? + .send(event: .systemReset(group: 0)) ) - + XCTAssertNoThrow( + try manager.managedOutputs[tag1]? + .send(events: [.systemReset(group: 0)]) + ) + // unique ID collision let tag2 = "2" diff --git a/Tests/MIDIKitTests/IO/Inputs and Outputs/OutputConnection Tests.swift b/Tests/MIDIKitTests/IO/Inputs and Outputs/OutputConnection Tests.swift index 8f365cc220..e4eeab9a34 100644 --- a/Tests/MIDIKitTests/IO/Inputs and Outputs/OutputConnection Tests.swift +++ b/Tests/MIDIKitTests/IO/Inputs and Outputs/OutputConnection Tests.swift @@ -59,7 +59,18 @@ final class InputsAndOutputs_OutputConnection_Tests: XCTestCase { } XCTAssertNotNil(manager.managedOutputConnections[tag1]) - + + // attempt to send a midi message + + XCTAssertThrowsError( + try manager.managedOutputConnections[tag1]? + .send(event: .systemReset(group: 0)) + ) + XCTAssertThrowsError( + try manager.managedOutputConnections[tag1]? + .send(events: [.systemReset(group: 0)]) + ) + } }