Closed oubiwann closed 1 month ago
Maybe the messages for controlling sequences?
My qualms with a MIDI approach to this problem are:
I'd rather just keep everything in Erlang (LFE) the whole time, without the need for the overhead of translation to and from.
That being said, MIDI does have useful and time-worn abstractions for this problem ...
The Erlang VM is accurate to the millisecond. In 4/4 time a fast song at say 350 bpm would have the following note durations in any given measure:
350/60=4/x
--> (/ 1 (/ (/ 350 60) 4))
--> 0.69s
--> 685.7 msA 64th note at 350 bpm is insane and probably not something that's going to happen very often, if at all. If it does, then Erlang is probably not the target platform for the developer who needs this capability. That being said, we should test this with actual notes + human ears over time. But we'll need to build something to test, first.
Instead of creating separate services for this, with code running in new Erlang processes in this or some other supervision tree, it would be nice to run a timer + queue at the same place where notes are being sent to the system MIDI device.
However ...
As soon as we need to write synchronised timings to multiple devices simultaneously, we need a little separation from timer-and-sender in the same Erlang process. Two instruments on separate devices should be able to play completely in-time with each other, so whatever is keeping time (and tracking beats, time sig, tempo, measures, etc.) should be able to provide clock info fast enough that the multiple devices can play in-time.
However ...
The Erlang NIF doesn't offer any native concurrency support for writing to system MIDI devices, so having a bunch of processes that request timing info from a central source and then send messages themselves doesn't really match up well with the lowest level dependency. It might make more sense to have a single Erlang process that dispatches to system MIDI. If that's the case, then we probably want something like the following:
To support this, we would need the following:
Hrm, looks like this analysis ultimately belonged up one level in the ticket hierarchy ;-)
With regard to this (comment above):
My qualms with a MIDI approach to this problem are ...
I see now that I didn't fully capture my thinking from last night, 'cause reading it now just makes it sound like I didn't want to do MIDI (and we're doing so much MIDI, what's the problem?)
So:
Yeah, I think that's enough context :-)
Read up on best way to set beat, time sig, play notes by beat, play rests, etc.