问题
Need to play 1 or 2 bars for count In before the current sequence start playing. Just to play a click for count in.
It would be cool to be able to do something like ...
player.sequencer.setTime(MusicTimeStamp(-4))
It set time to 0, doesn't work.
What's the way to make a count in with AKSequencer ?
回答1:
Edited: Originally I thought you could simply add the count in bars to the end of the existing sequence, then reset to the proper length using a AKCallbackInstrument with an event at beat zero, but it turns out it is somewhat more involved.
After any call to setLength()
, you must call enableLooping()
to re-establish looping behaviour. Under the hood, this involves calling MusicTrackSetProperty
with kSequenceTrackProperty_LoopInfo
for each track in the underlying MusicSequence
. Calling this while the sequencer is running has the bizarre side effect of relocating the playhead to a position whose distance from the end the original sequence is equal to the new length of the sequence. So for example, if you have a 20 beat sequence and you want to dynamically change it to an 16 beat sequence, the call to enableLooping()
will relocate the playhead to beat 4 (i.e., 20 - 16 = 4). It will then play through to beat 16, and then loop as expected. Fortunately, it doesn't mangle the timing too much when making this jump.
The solution then is to double the length of the sequence and put the count in at the very end. For example, if you have a 16 beat sequence, set the length to 32 beats, and start the count in events at beat 28. Then at beat 0, you can call setLength(AKDuration(beats: 16.0))
and enableLooping()
, and the playhead will jump to beat 16, which, under the new looping behaviour, is effectively beat 0. The timing isn't perfect, but it's not bad (there is a delay of about 3ms, but that's probably not a deal breaker if you're already using a MusicSequence
based sequencer.)
It's not a nice solution, but I can confirm that it works.
来源:https://stackoverflow.com/questions/50191394/aksequencer-count-in-for-one-or-two-bars