diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 13b4d5a452..4de596a259 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,17 +22,27 @@ on: schedule: - cron: '35 11 * * *' # once a day @ 11:35am UTC (4:35am PST) -jobs: - macOS: - name: macOS - runs-on: macos-latest +jobs: + macOS-11: + name: macOS 11 Big Sur + runs-on: macos-11 steps: - uses: actions/checkout@main - name: Build run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "MIDIKit-CI" -destination "platform=macOS,arch=x86_64" - name: Unit Tests run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "MIDIKit-CI" -destination "platform=macOS,arch=x86_64" - + + macOS-10_15: + name: macOS 10.15 Catalina + runs-on: macos-10.15 + steps: + - uses: actions/checkout@main + - name: Build + run: xcodebuild build -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "MIDIKit-CI" -destination "platform=macOS,arch=x86_64" + - name: Unit Tests + run: xcodebuild test -workspace ".swiftpm/xcode/package.xcworkspace" -scheme "MIDIKit-CI" -destination "platform=macOS,arch=x86_64" + macCatalyst: name: macCatalyst runs-on: macos-latest @@ -67,7 +77,7 @@ jobs: - name: MIDISystemInfo - Build run: xcodebuild build -project "Examples/MIDISystemInfo/MIDISystemInfo.xcodeproj" -scheme "MIDISystemInfo" -# we flew too close to the sun... tvOS is not yet ready for primetime because CoreMIDI is still in beta for tvOS +# Core MIDI is still in beta for tvOS and watchOS; can add CI tests later once it's supported # # tvOS: # name: tvOS diff --git a/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOManagedProtocol.swift b/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOManagedProtocol.swift index f9bc113c71..b89be946e9 100644 --- a/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOManagedProtocol.swift +++ b/Sources/MIDIKit/IO/Managed/Protocols/MIDIIOManagedProtocol.swift @@ -5,7 +5,7 @@ // MARK: - Public Protocol -public protocol MIDIIOManagedProtocol { +public protocol MIDIIOManagedProtocol: AnyObject { /// Core MIDI API version used to create the endpoint and send/receive MIDI messages (if applicable). /* public private(set) */ var api: MIDI.IO.APIVersion { get } diff --git a/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift b/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift index ea0d57f53c..46225fc3f1 100644 --- a/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift +++ b/Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift @@ -15,9 +15,9 @@ extension MIDI.IO { public let uniqueID: MIDI.IO.AnyUniqueID // _MIDIIOObjectProtocol - var coreMIDIObjectRef: MIDI.IO.CoreMIDIObjectRef + internal var coreMIDIObjectRef: MIDI.IO.CoreMIDIObjectRef - internal init(_ base: T) { + internal init(_ base: O) { self.objectType = base.objectType self.name = base.name @@ -41,3 +41,14 @@ extension _MIDIIOObjectProtocol { } } + +extension Collection where Element : MIDIIOObjectProtocol { + + /// Return as [`AnyMIDIIOObject`], type-erased representations of MIDIKit objects conforming to `MIDIIOObjectProtocol`. + public func asAnyMIDIIOObjects() -> [MIDI.IO.AnyMIDIIOObject] { + + map { $0.asAnyMIDIIOObject() } + + } + +} diff --git a/Sources/MIDIKit/IO/Objects/Endpoint/AnyEndpoint/AnyEndpoint.swift b/Sources/MIDIKit/IO/Objects/Endpoint/AnyEndpoint/AnyEndpoint.swift index 529e66c230..b7ba083780 100644 --- a/Sources/MIDIKit/IO/Objects/Endpoint/AnyEndpoint/AnyEndpoint.swift +++ b/Sources/MIDIKit/IO/Objects/Endpoint/AnyEndpoint/AnyEndpoint.swift @@ -10,14 +10,16 @@ extension MIDI.IO { public let endpointType: MIDI.IO.EndpointType - public let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef + internal let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef public let name: String - public var uniqueID: UniqueID + public typealias UniqueID = MIDI.IO.AnyUniqueID + public let uniqueID: UniqueID - internal init(_ other: T) { - switch other { + internal init(_ base: E) { + + switch base { case is MIDI.IO.InputEndpoint: endpointType = .input @@ -28,20 +30,38 @@ extension MIDI.IO { endpointType = otherCast.endpointType default: - preconditionFailure("Unexpected MIDIIOEndpointProtocol type: \(other)") + preconditionFailure("Unexpected MIDIIOEndpointProtocol type: \(base)") + } - self.coreMIDIObjectRef = other.coreMIDIObjectRef - self.name = other.name - self.uniqueID = .init(other.uniqueID.coreMIDIUniqueID) + self.coreMIDIObjectRef = base.coreMIDIObjectRef + self.name = base.name + self.uniqueID = .init(base.uniqueID.coreMIDIUniqueID) + } } } -extension MIDI.IO.AnyEndpoint { +extension _MIDIIOEndpointProtocol { + + /// Returns the endpoint as a type-erased `AnyEndpoint`. + public func asAnyEndpoint() -> MIDI.IO.AnyEndpoint { + + .init(self) + + } - public typealias UniqueID = MIDI.IO.AnyUniqueID +} + +extension Collection where Element : MIDIIOEndpointProtocol { + + /// Returns the collection as a collection of type-erased `AnyEndpoint` endpoints. + public func asAnyEndpoints() -> [MIDI.IO.AnyEndpoint] { + + map { $0.asAnyEndpoint() } + + } } diff --git a/Sources/MIDIKit/IO/Objects/Endpoint/InputEndpoint/InputEndpoint.swift b/Sources/MIDIKit/IO/Objects/Endpoint/InputEndpoint/InputEndpoint.swift index d79027198a..37691c7a3a 100644 --- a/Sources/MIDIKit/IO/Objects/Endpoint/InputEndpoint/InputEndpoint.swift +++ b/Sources/MIDIKit/IO/Objects/Endpoint/InputEndpoint/InputEndpoint.swift @@ -16,7 +16,7 @@ extension MIDI.IO { // MARK: CoreMIDI ref - public let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef + internal let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef // MARK: Init @@ -70,15 +70,6 @@ extension MIDI.IO.InputEndpoint { } -extension MIDI.IO.InputEndpoint { - - /// Returns the endpoint as a type-erased `AnyEndpoint`. - public func asAnyEndpoint() -> MIDI.IO.AnyEndpoint { - .init(self) - } - -} - extension MIDI.IO.InputEndpoint: CustomDebugStringConvertible { public var debugDescription: String { diff --git a/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift b/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift index 3117a29c05..88d58fc132 100644 --- a/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift +++ b/Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift @@ -3,40 +3,41 @@ // MIDIKit • https://github.com/orchetect/MIDIKit // -// MARK: - Endpoint +// MARK: - Public Protocol public protocol MIDIIOEndpointProtocol: MIDIIOObjectProtocol { // implemented in extension _MIDIIOEndpointProtocol + /// Returns the entity the endpoint originates from. For virtual endpoints, this will return `nil`. func getEntity() -> MIDI.IO.Entity? + /// Returns the endpoint as a type-erased `AnyEndpoint`. + func asAnyEndpoint() -> MIDI.IO.AnyEndpoint + } +// MARK: - Internal Protocol + internal protocol _MIDIIOEndpointProtocol: MIDIIOEndpointProtocol, _MIDIIOObjectProtocol { } +// MIDIIOObjectProtocol implementation + extension _MIDIIOEndpointProtocol { public var objectType: MIDI.IO.ObjectType { .endpoint } - public func getEntity() -> MIDI.IO.Entity? { - - try? MIDI.IO.getSystemEntity(for: self.coreMIDIObjectRef) - - } - } -extension Collection where Element : MIDIIOEndpointProtocol { +// MIDIIOEndpointProtocol implementation + +extension _MIDIIOEndpointProtocol { - /// Returns the collection as a collection of type-erased `AnyEndpoint` endpoints. - public func asAnyEndpoints() -> [MIDI.IO.AnyEndpoint] - where Element : _MIDIIOEndpointProtocol - { + public func getEntity() -> MIDI.IO.Entity? { - map { MIDI.IO.AnyEndpoint($0) } + try? MIDI.IO.getSystemEntity(for: self.coreMIDIObjectRef) } diff --git a/Sources/MIDIKit/IO/Objects/Endpoint/OutputEndpoint/OutputEndpoint.swift b/Sources/MIDIKit/IO/Objects/Endpoint/OutputEndpoint/OutputEndpoint.swift index 3ed88ff1d2..a288dab6b3 100644 --- a/Sources/MIDIKit/IO/Objects/Endpoint/OutputEndpoint/OutputEndpoint.swift +++ b/Sources/MIDIKit/IO/Objects/Endpoint/OutputEndpoint/OutputEndpoint.swift @@ -16,7 +16,7 @@ extension MIDI.IO { // MARK: CoreMIDI ref - public let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef + internal let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef // MARK: Init @@ -70,15 +70,6 @@ extension MIDI.IO.OutputEndpoint { } -extension MIDI.IO.OutputEndpoint { - - /// Returns the endpoint as a type-erased `AnyEndpoint`. - public func asAnyEndpoint() -> MIDI.IO.AnyEndpoint { - .init(self) - } - -} - extension MIDI.IO.OutputEndpoint: CustomDebugStringConvertible { public var debugDescription: String { diff --git a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Collection.swift b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Collection.swift index 569f1c36f8..c48ea9ac0b 100644 --- a/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Collection.swift +++ b/Sources/MIDIKit/IO/Objects/MIDIIOObjectProtocol/MIDIIOObjectProtocol Collection.swift @@ -38,7 +38,7 @@ extension Collection where Element : MIDIIOObjectProtocol { extension Collection where Element : MIDIIOObjectProtocol { /// Returns all elements matching all supplied parameters. - public func filter(displayName: String) -> [Element] where Element : _MIDIIOObjectProtocol { + public func filter(displayName: String) -> [Element] { filter { $0.getDisplayName() == displayName } diff --git a/Tests/MIDIKitTests/IO/Manager/Manager Public Tests.swift b/Tests/MIDIKitTests/IO/Manager/Manager Public Tests.swift index a74f70aa8e..2522474711 100644 --- a/Tests/MIDIKitTests/IO/Manager/Manager Public Tests.swift +++ b/Tests/MIDIKitTests/IO/Manager/Manager Public Tests.swift @@ -115,7 +115,7 @@ final class Manager_Public_Tests: XCTestCase { // we just want to test the API - struct Foo: MIDIIOManagedProtocol { + class Foo: MIDIIOManagedProtocol { var api: MIDI.IO.APIVersion = .legacyCoreMIDI } diff --git a/Tests/MIDIKitTests/IO/Manager/Manager Tests.swift b/Tests/MIDIKitTests/IO/Manager/Manager Tests.swift index 417701e473..dceb7be3dc 100644 --- a/Tests/MIDIKitTests/IO/Manager/Manager Tests.swift +++ b/Tests/MIDIKitTests/IO/Manager/Manager Tests.swift @@ -49,7 +49,7 @@ final class Manager_Tests: XCTestCase { // public protocol - struct Foo: MIDIIOManagedProtocol { + class Foo: MIDIIOManagedProtocol { var api: MIDI.IO.APIVersion = .legacyCoreMIDI } @@ -59,7 +59,7 @@ final class Manager_Tests: XCTestCase { // internal protocol - struct Bar: _MIDIIOManagedProtocol { + class Bar: _MIDIIOManagedProtocol { var midiManager: MIDI.IO.Manager? = nil var api: MIDI.IO.APIVersion = .legacyCoreMIDI }