I'd like create a class/struct/other that contains each measure of a song, complete with independent tempo and beat count, then play the entire song back (with potential updates from user input). I'm only aware of how to change those variables on an AKSequencer track as a whole; is there a way to store that data independently and then have it play back as one? And keep coherence between the measures so as not to "jump" between them? Thanks!
-
Not sure what you mean by 'store that data independently and then have it play back as one.' You want to play back a bunch of segments (of different lengths, and tempos) sequentially? simultaneously? If sequentially, is the order fixed beforehand (before playback starts)? If not, when is the playback order decided? Is looping necessary? If so, what would be looping (single segments, clusters of segments)? – c_booth Jun 03 '18 at 22:32
-
@c_booth thanks for the response. I'm looking for segments to play back sequentially; essentially a metronome that has the ability to vary each measure's beat and tempo independently. While on-the-fly changes during playback would be ideal, the primary use-case is to set up the number of "measures", each with their own tempo/beat count variables, and play back the entire song. Looping of the entire song is not necessary. – moosgrn Jun 03 '18 at 23:18
1 Answers
AKSequencer is not good at setting loop length on the fly, but it is totally fine for adding to or re-writing the contents of a track while the sequencer is running. This includes tempo events.
Why don't you set the length to something arbitrarily long, and string together your MIDI events measure after measure without ever looping? Keep track of how many beats have been written so far, and just keep adding after that point. Doing this while the sequencer is running should be no problem. You could even automate writing the next bar by triggering a callback function near the end of each measure getting it to write the next segment (which could be selected or 'cued up' at run-time). You can schedule the tempo events with addTempoEventAt()
, with the starting point for the next segment.
When your user stops the sequence, clear the track(s), reset the tempo, rewind the sequence and start over.

- 2,185
- 1
- 13
- 22
-
Interesting; thanks for the feedback. Would the MIDI events be contained/referenced in a struct/dictionary/other? I'm envisioning: user enters values for each measure in a struct, sequence gets created with arbitrarily long length, sequence begins playing, callback function creates each measure slightly-in-advance based on MIDI info contained (or referenced) in struct, and everything plays back as a single track. Thanks again. – moosgrn Jun 04 '18 at 00:56
-
That's it exactly. Your struct could contain a template with the events you want to write, the length of the segment, the tempo, and a method that takes the starting point as an argument then writes to the sequence, and updates the position. – c_booth Jun 04 '18 at 02:39