Hi all, I’m working on an app in OS X using Swift and having trouble with the MusicPlayer API.
The MusicTrackNewUserEvent is defined as: func MusicTrackNewUserEvent(_ inTrack: MusicTrack <https://developer.apple.com/library/mac/documentation/AudioToolbox/Reference/MusicTrack_Reference/index.html#//apple_ref/swift/tdef/c:@T@MusicTrack>, _ inTimeStamp: MusicTimeStamp <https://developer.apple.com/library/mac/documentation/AudioToolbox/Reference/MusicSequence_Reference/index.html#//apple_ref/swift/tdef/c:@T@MusicTimeStamp>, _ inUserData: UnsafePointer <https://developer.apple.com/library/mac/documentation/Swift/Reference/Swift_UnsafePointer_Structure/index.html#//apple_ref/swift/struct/s:SP><MusicEventUserData <https://developer.apple.com/library/mac/documentation/AudioToolbox/Reference/MusicTrack_Reference/index.html#//apple_ref/swift/struct/c:@S@MusicEventUserData>>) -> OSStatus A MusicEventUserData is defined as: struct MusicEventUserData { var length: UInt32 <https://developer.apple.com/library/mac/documentation/Swift/Reference/Swift_UInt32_Structure/index.html#//apple_ref/swift/struct/s:Vs6UInt32> var data: (UInt8 <https://developer.apple.com/library/mac/documentation/Swift/Reference/Swift_UInt8_Structure/index.html#//apple_ref/swift/struct/s:Vs5UInt8>) init() init(length length: UInt32 <https://developer.apple.com/library/mac/documentation/Swift/Reference/Swift_UInt32_Structure/index.html#//apple_ref/swift/struct/s:Vs6UInt32>, data data: (UInt8 <https://developer.apple.com/library/mac/documentation/Swift/Reference/Swift_UInt8_Structure/index.html#//apple_ref/swift/struct/s:Vs5UInt8>)) } It’s my understanding that this is a C style trick where I can define my own structure and pass it into the MusicTrackNewUserEvent function. So I defined a structure: struct EventPlayer { var length = UInt32(sizeof(EventPlayer)) let stack: Something init (x: Something) {self.stack = x} } I can, at least I believe because there are no errors, create a new event like so: var a = Something() var data = EventPlayer(x: a) withUnsafePointer(&data) {pointer in let dataPtr = UnsafePointer<MusicEventUserData>(pointer) MusicTrackNewUserEvent(track, 1.0, dataPtr) } Here’s the problem I have though: the MusicSequenceUserCallback (which I created and passed into the sequencer just fine) has an argument data: UnsafePointer<MusicEventUserData> I am not sure how to convert that into my custom structure EventPlayer. Any help would be really appreciated, a google search on most CoreAudio questions for Swift result in only 5 hits. Thanks, -- GW Rodriguez
_______________________________________________ Do not post admin requests to the list. They will be ignored. Coreaudio-api mailing list ([email protected]) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/coreaudio-api/archive%40mail-archive.com This email sent to [email protected]
