Search code examples
core-audioaudiokit

Is it possible to modify the MusicSequnce while AudioKit sequencer is playing


I wonder, is it possible to modify the MusicSequnce on the fly without stopping the AudioKit sequencer. The Apple docs for the method MusicPlayerSetSequence says that you must stop the MusicPlayer before calling this method. So I guess the answer to my question is NO. Or am I missing something?


Solution

  • I modify my MusicSequences all the time on the fly (using AKSequencer), and it has never caused a problem. One potential issue you need to address though is when to change it. When you change the sequence contents, the change will take effect almost immediately, so if you have a looping sequence, you can schedule the change to happen just before the repeat, but you might occasionally lose notes at the end of the sequence (i.e., if those notes are not included in the updated version of the sequence).

    One pattern that I used to prevent dropped notes was to ping-pong between two different versions of the sequence. So if I had a four bar repeating pattern, I would make my sequence eight bars (repeating the same sequences twice), updating every four bars, and only changing the half that wasn't currently playing. It was difficult to code, but it worked well.

    Edit: I should clarify that I am talking about changing the contents of the sequence itself. Changing the position of the 'playback head' during playback is basically a disaster timing-wise.