RE: Editing a looping MusicTrack as it plays
RE: Editing a looping MusicTrack as it plays
- Subject: RE: Editing a looping MusicTrack as it plays
- From: David Hicks <email@hidden>
- Date: Sat, 21 Jan 2012 11:36:58 -0500
Title: RE: Editing a looping MusicTrack as it plays
Neil,
I haven’t seen any responses to your query yet, so until someone with more experience with looping MusicTracks weighs in, here’s what occurs to me. (I have some experience with populating MusicTracks on the fly, but not with looping.)
It makes some sense to me that there might be a conflict with playing a MIDI note event while it is being removed via MusicTrackClear. (I wouldn’t necessarily expect the whole track to go silent, but who knows?) If I were in your shoes (not much documentation of looping MusicTracks, no input from this list) I would keep track of where I was during playback of the MusicTrack, and to avoid Clearing any events at or near the current play position.
At a minimum this would mean providing a callback function to the sequence (I assume you don’t have one, from your code snippet), see documentation below from MusicSequence reference. The callback provides you with ‘inStartSliceBeat’ and ‘inEndSliceBeat’, which you can use to determine if an event you are about to clear is scheduled for immediate playback. If so, don’t clear these now. You could clear any other events you want to without hazard, I would think, and add back in their new note-versions as well.
I probably wouldn’t do the Clear and Add during the callback itself. I think I would instead add member variables, say mStartSliceBeat and mEndSliceBeat, to my class, and these would get set from the callback. Then these member variables would be referenced in the main thread at the point where you normally do your MusicTrackClear (touchesBegan).
HTH,
David
MusicSequenceSetUserCallback
Registers a user callback function with a music sequence.
OSStatus MusicSequenceSetUserCallback (
MusicSequence inSequence,
MusicSequenceUserCallback inCallback,
void *inClientData
);
Parameters
inSequence
inCallback
inClientData
Your data that the music sequence provides back to your callback function when it is invoked.
Return Value
A result code.
Discussion
The music sequence invokes your callback for each user event added to any music track owned by the sequence. If there is a callback registered, then UserEvents will be chased when MusicPlayerSetTime is called. In that case the inStartSliceBeat and inEndSliceBeat will both be the same value and will be the beat that the player is chasing to.
Usually, where the sequence data is being scheduled for playback, the following applies:
inStartSliceBeat <= inEventTime < inEndSliceBeat
The only exception to this is if the track that owns the MusicEvent is looping. In this case the start beat will still be less than the end beat (so your callback can still determine that it is playing, and what beats are currently being scheduled), however, the inEventTime will be the original time-stamped time of the user event.
Further down the MusicSequence reference we find this:
MusicSequenceUserCallback
typedef void (*MusicSequenceUserCallback) (
void *inClientData,
MusicSequence inSequence,
MusicTrack inTrack,
MusicTimeStamp inEventTime,
const MusicEventUserData *inEventData,
MusicTimeStamp inStartSliceBeat,
MusicTimeStamp inEndSliceBeat
);
If you named your callback MyMusicSequenceUserCallback, you would declare it like this:
void MyMusicSequenceUserCallback (
void *inClientData,
MusicSequence inSequence,
MusicTrack inTrack,
MusicTimeStamp inEventTime,
const MusicEventUserData *inEventData,
MusicTimeStamp inStartSliceBeat,
MusicTimeStamp inEndSliceBeat
);
_______________________________________________
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