title: Programming a music sequencer
body: <p>I would like to build an audio multitrack sequencer similar to a drum machine.
  What do you think is the best way to implement this?</p>
  
  <p>At the moment I have 2 tracks represented by 2 arrays: 2 x [tick, samplePointer].
  I merge these 2 tracks in a main array to be played [tick, samplePointer] and sort it by tick.
  An audio callback fires every tick (4 ticks per beat) and checks the first element in the array and if its tick is equal to the global song position (in ticks) then i play it.
  If I add or delete a note in one of the 2 tracks(arrays) i then merge both tracks(arrays) and sort them again.</p>
  
  <p>It works but I have the feeling that there is a better way to do it.
  What would be the best practice to implement such a project? How would a professional app like Logic, Ableton, Cubase, Reason etc implement audio/midi event lists and manage what has been played, what needs to be played?</p>
  
  <p>Thank you in advance for your thoughts.</p>
  
  <p>Brice</p>