Re: Using the MusicEventUserData structure
Re: Using the MusicEventUserData structure
- Subject: Re: Using the MusicEventUserData structure
- From: William Stewart <email@hidden>
- Date: Wed, 15 Feb 2006 17:45:39 -0800
On 15/02/2006, at 10:05 AM, Brian Sheehan wrote:
Hi,
I am wondering how I should use user defined events in a sequence. It
all seems fairly straightforward, except I'm a little confused about
the MusicEventUserData structure:
typedef struct MusicEventUserData {
UInt32 length;
UInt8 data[1];
} MusicEventUserData;
So you can do this:
struct MyMusicEventUserData {
UInt32 length;
<some type> eventID;
<some other type> ...
};
The length field at the start is required as the MusicSequence needs
to know how big the structure is that you are passing to it. It
doesn't know (or care) what is in it past this length filed.
How exactly should I use the "data" member of the above struct? It's
probably clearer if I give some psuedo code to put across how I
imagine things should/could work (I'm obviously missing something
along the way, please tell me where):
//First I define a struct representing some custom music event
typedef struct MyMusicEvent {
-> you are missing the UInt32 length field here...
<some type> eventID;
<some other type> eventParam1;
<yet another type> eventParam2;
.......... and whatever other members I need
} MyMusicEvent;
//Now I declare and initialize a MusicEventUserData structure
MusicEventUserData userData;
userData.length = sizeof(MyMusicEvent);
userData.data = (UInt8 *) malloc(userData.length);
Nope - when you see this kind of pattern:
UInt8 data[1];
it means the the memory is contiguous from that point on - it isn't a
pointer to memory. If it were a pointer, it would be declared as such
(ie. as a void*)
Then, you take your struct and cast it to a MusicEventUserData when
interfacing with the sequence APIs (and cast back when you need to
use it of course)
Bill
//Now I'd like to do something like:
userData.data = (UInt8 *) &MyMusicEvent; ??? not sure will this work,
casting at arbitrary pointer type to a (UInt8 *)
Why is a UInt8 [] is being used for the "data" member? I would have
expected a void * to be used. I suppose my code above is wishful
thinking, but in what ways could I use the MyMusicEvent structure?
Thanks for all and any help, I couldn't find anything on the lists
about the above - any pointers to code examples would be great.
Brian
_______________________________________________
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
--
mailto:email@hidden
tel: +1 408 974 4056
________________________________________________________________________
__
"Much human ingenuity has gone into finding the ultimate Before.
The current state of knowledge can be summarized thus:
In the beginning, there was nothing, which exploded" - Terry Pratchett
________________________________________________________________________
__
_______________________________________________
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