forked from kshoji/USB-MIDI-Driver
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* overhaul MIDIOutConnection (no protocol) * add LightController API
- Loading branch information
Showing
9 changed files
with
132 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// LightController.swift | ||
// NoteDetectionIOS | ||
// | ||
// Created by flowing erik on 25.05.18. | ||
// Copyright © 2018 flowkey. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public typealias LightControlStatusChangedCallback = (LightControlStatus) -> Void | ||
|
||
public enum LightControlStatus { | ||
case notAvailable // no compatible device is connected | ||
case disabled // compatible device connected but disabled by user | ||
case enabled // compatible device connected and enabled by user | ||
|
||
// toggles between enabled and disabled or returns notAvailable | ||
public func toggled() -> LightControlStatus { | ||
switch self { | ||
case .enabled: return .disabled | ||
case .disabled: return .enabled | ||
case .notAvailable: return .notAvailable | ||
} | ||
} | ||
} | ||
|
||
public protocol LightController { | ||
func set(onLightControlStatusChanged: @escaping LightControlStatusChangedCallback) | ||
func disableLightControl() throws | ||
func enableLightControl() throws | ||
} | ||
|
||
public enum LightControlError: Error { | ||
case notAvailable | ||
} | ||
|
||
extension NoteDetection: LightController { | ||
public func set(onLightControlStatusChanged: @escaping (LightControlStatus) -> Void) { | ||
self.onLightControlStatusChanged = onLightControlStatusChanged | ||
} | ||
|
||
public func disableLightControl() throws { | ||
guard let lightControl = lightControl else { | ||
throw LightControlError.notAvailable | ||
} | ||
lightControl.isEnabled = false | ||
onLightControlStatusChanged?(.disabled) | ||
} | ||
|
||
public func enableLightControl() throws { | ||
guard let lightControl = lightControl else { | ||
throw LightControlError.notAvailable | ||
} | ||
lightControl.isEnabled = true | ||
onLightControlStatusChanged?(.enabled) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// MIDIOutConnectionAndroid.swift | ||
// NoteDetection | ||
// | ||
// Created by flowing erik on 22.03.18. | ||
// Copyright © 2018 flowkey. All rights reserved. | ||
// | ||
|
||
// MIDIOutConnection stub for Android, to be implemented when we support Yamaha Light Control in Android | ||
public class MIDIOutConnection { | ||
private let refCon: UnsafeMutablePointer<UInt32> | ||
|
||
init(refCon: UnsafeMutablePointer<UInt32>) { | ||
self.refCon = refCon | ||
} | ||
} | ||
|
||
extension MIDIOutConnection { | ||
public var displayName: String { | ||
// TODO: Implement Me | ||
return "MIDIOutConnection Stub" | ||
} | ||
|
||
public func send(messages: [[UInt8]]) { | ||
// TODO: Implement Me | ||
} | ||
} | ||
|
||
extension MIDIOutConnection: Equatable { | ||
public static func == (lhs: MIDIOutConnection, rhs: MIDIOutConnection) -> Bool { | ||
return lhs.refCon == rhs.refCon | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters