sowbug / groove

A digital audio workstation (DAW) engine.
Other
19 stars 0 forks source link

Orchestrator dispatches messages in arbitrary order #101

Closed sowbug closed 1 year ago

sowbug commented 1 year ago

This causes problems with controllers that send MIDI to instruments. If the instrument gets its tick() before the controller does, then it won't start emitting sound until the next batch. This all depends on how the Store hash table happens to store items for any given run.

As long as there are no cycles, then we should be able to do this all in one frame, so that they all appear to happen simultaneously.

sowbug commented 1 year ago

This is solved by the new multipass main loop.

  1. We calculate the time range.
  2. We tell everyone the range.
  3. We ask everyone to do work.
  4. We route all controls/messages they produce.
  5. Repeat Step 4 until everything is routed.
  6. Ask instruments to produce sound.
  7. Ask effects to process sound.

We even detect a simple version of loops -- if the sender is listening on the same channel as a message it sends, then we drop it. That doesn't prevent A -> B -> C -> A, though.

This effectively means that all messages happen simultaneously. You could imagine situations where a message is triggered only if a device is in a certain state, and that state is set by a different message. But I think it's OK, at least for now, to call that undefined.