Skip to content

Commit

Permalink
Merge pull request #43 from orchetect/dev
Browse files Browse the repository at this point in the history
Improved access levels and build reliability
  • Loading branch information
orchetect authored Oct 1, 2021
2 parents 025f885 + eaddaa9 commit 0d90991
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 56 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
15 changes: 13 additions & 2 deletions Sources/MIDIKit/IO/Objects/AnyMIDIIOObject/AnyMIDIIOObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: _MIDIIOObjectProtocol>(_ base: T) {
internal init<O: _MIDIIOObjectProtocol>(_ base: O) {

self.objectType = base.objectType
self.name = base.name
Expand All @@ -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() }

}

}
40 changes: 30 additions & 10 deletions Sources/MIDIKit/IO/Objects/Endpoint/AnyEndpoint/AnyEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: _MIDIIOEndpointProtocol>(_ other: T) {
switch other {
internal init<E: _MIDIIOEndpointProtocol>(_ base: E) {

switch base {
case is MIDI.IO.InputEndpoint:
endpointType = .input

Expand All @@ -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() }

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension MIDI.IO {

// MARK: CoreMIDI ref

public let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef
internal let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef

// MARK: Init

Expand Down Expand Up @@ -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 {
Expand Down
27 changes: 14 additions & 13 deletions Sources/MIDIKit/IO/Objects/Endpoint/MIDIIOEndpointProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension MIDI.IO {

// MARK: CoreMIDI ref

public let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef
internal let coreMIDIObjectRef: MIDI.IO.CoreMIDIEndpointRef

// MARK: Init

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down
2 changes: 1 addition & 1 deletion Tests/MIDIKitTests/IO/Manager/Manager Public Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/MIDIKitTests/IO/Manager/Manager Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ final class Manager_Tests: XCTestCase {

// public protocol

struct Foo: MIDIIOManagedProtocol {
class Foo: MIDIIOManagedProtocol {
var api: MIDI.IO.APIVersion = .legacyCoreMIDI
}

Expand All @@ -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
}
Expand Down

0 comments on commit 0d90991

Please sign in to comment.