ut-proj / undermidi

An Erlang/LFE MIDI soft real time server for live play of MIDI devices
BSD 2-Clause "Simplified" License
4 stars 1 forks source link

Consider using MIDI-based note durations, timings, rests, delays, etc. #60

Closed oubiwann closed 1 month ago

oubiwann commented 2 months ago

Read up on best way to set beat, time sig, play notes by beat, play rests, etc.

oubiwann commented 1 month ago

Maybe the messages for controlling sequences?

oubiwann commented 1 month ago

My qualms with a MIDI approach to this problem are:

  1. timing is critical and we need to have as much consistency and as little overhead as possible, and
  2. all operations would have to be translated between Erlang and MIDI

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 ...

oubiwann commented 1 month ago

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:

A 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.

oubiwann commented 1 month ago

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:

oubiwann commented 1 month ago

Hrm, looks like this analysis ultimately belonged up one level in the ticket hierarchy ;-)

oubiwann commented 1 month ago

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 :-)