If indeed you did set the user event using the method you described you should
be able to get the actual value back using “.memory”. So after you have called
MusicEventIteratorGetEventInfo() and and have a kMusicEventType_User event you
should be able to to do this…
MusicEventIteratorGetEventInfo(iterator,
&beatTime,
&eventType,
&eventData,
&eventDataSize)
.
.
.
if (eventType == kMusicEventType_User)
{
let eventPtr = UnsafePointer<EventPlayer>(eventData)
let userData:EventPlayer = eventPtr.memory
.
.
.
To be honest I have not done this myself and I am not sure it will work. I
used the MusicEventUserData structure itself. Set the length variable to the
size of my structure (EventPlayer in your case) and set the bytes of the data
member to be the bytes of my structure.
- Matt Grippaldi
> On Aug 29, 2016, at 2:12 PM, GW Rodriguez <[email protected]> wrote:
>
> 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/mattg%40kinematicsystems.com
>
> This email sent to [email protected]
_______________________________________________
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]