Last active
August 29, 2015 14:14
-
-
Save JRHeaton/364461a563fd56f37c1b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| infix operator >>= { } | |
| func >>= <A, B> (x: A?, f: A -> B?) -> B? { | |
| if let val = x { | |
| return f(val) | |
| } | |
| return nil | |
| } | |
| protocol MIDIEnumerable { | |
| class func count() -> Int | |
| class func atIndex(Int) -> Self? | |
| } | |
| struct MIDI { | |
| static func enumerate<A: MIDIEnumerable>() -> GeneratorOf<A> { | |
| var index = 0 | |
| return GeneratorOf<A> { | |
| return A.atIndex(++index) | |
| } | |
| } | |
| static func all<A: MIDIEnumerable>() -> [A] { | |
| var ret: [A] = [] | |
| for val: A in enumerate() { | |
| ret.append(val) | |
| } | |
| return ret | |
| } | |
| class Object { | |
| let ref: MIDIObjectRef | |
| var properties: NSDictionary? { | |
| var cfProps: Unmanaged<CFPropertyList>? | |
| MIDIObjectGetProperties(ref, &cfProps, 1) | |
| return cfProps?.takeUnretainedValue() as? NSDictionary | |
| } | |
| init(ref: MIDIObjectRef) { | |
| self.ref = ref | |
| } | |
| } | |
| class Device: Object, MIDIEnumerable { | |
| class func count() -> Int { | |
| return Int(MIDIGetNumberOfDevices()) | |
| } | |
| class func atIndex(index: Int) -> Self? { | |
| if index < count() { | |
| return self.init(ref: MIDIGetDevice(ItemCount(index))) | |
| } | |
| return nil | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment