• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: MusicTrackNewUserEvent in Swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: MusicTrackNewUserEvent in Swift


  • Subject: Re: MusicTrackNewUserEvent in Swift
  • From: Matt Grippaldi <email@hidden>
  • Date: Mon, 29 Aug 2016 15:40:50 -0400

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@hidden> 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, _ inTimeStamp: MusicTimeStamp, _ inUserData: UnsafePointer<MusicEventUserData>) -> OSStatus


A MusicEventUserData is defined as:

struct MusicEventUserData { var length: UInt32 var data: (UInt8) init() init(length length: UInt32, data data: (UInt8)) }


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@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >MusicTrackNewUserEvent in Swift (From: GW Rodriguez <email@hidden>)

  • Prev by Date: MusicTrackNewUserEvent in Swift
  • Previous by thread: MusicTrackNewUserEvent in Swift
  • Index(es):
    • Date
    • Thread