Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input Latency upper bound #187

Open
smilingthax opened this issue May 19, 2018 · 0 comments
Open

Input Latency upper bound #187

smilingthax opened this issue May 19, 2018 · 0 comments
Labels
class: substantive https://www.w3.org/2023/Process-20230612/#correction-classes
Milestone

Comments

@smilingthax
Copy link

When Recording MIDI Events via MIDIInput.onmessage, when can I be sure that no more Events with timeStamp < t0 will be emitted?

e.g.:

... onmidimessage = (ev) {
  if (ev.timeStamp < stopRecordingAt) {
     // ... store event
  }
};

setTimeout(() => {
    console.log('Stopping Recording');
    stopRecordingAt = performance.now();
    // PROBLEM: can't `processStoredEvents(...)` just yet, because there could still be
    //                    midi events pending with ev.timeStamp < stopRecordingAt ...
}, ...);

When there are regular Midi Clock Messages on the input, it would be sufficient to wait for the next Clock Message to occur, but this doesn't cover the general case.

Idea:

  • setTimeout(... , 0) (or similar) to run processStoredEvents() function after the currently running JS context has exited, so that the event loop has a chance to dispatch all pending events. But this will only work reliably, when the midi timeStamps are assigned in such a way, that any event with timeStamp < now is immediately available to be dispatched (i.e. when a browser uses a separate midi input thread, it MUST make sure, that any midi events timestamped there with t0 < now will be dispatched before the setTimeout function is executed).

Does the current Web MIDI Standard guarantee this?

Otherwise, these are my thoughts of how the standard could be extended:

  • it guarantees a fixed upper latency boundary (e.g. 100ms), during which the events are surely delivered.
    This does not seem feasible, as a running JS context can delay the execution of onmidimessage arbitrarily.

  • there is some way to request a "synchronisation" on the input, i.e. onmidimessage is executed with an "empty" event that contains the "current input timeStamp" (and there is some ordering guarantee, i.e. midi events are delivered with monotonically increasing timeStamps).

  • MIDIInput is extended to contain the "current input timeStamp", similiar to the synchronisation case.

What do you suggest?

@cwilso cwilso added the future label Oct 16, 2018
@cwilso cwilso added this to the V2 milestone Mar 19, 2019
@mjwilson-google mjwilson-google added class: substantive https://www.w3.org/2023/Process-20230612/#correction-classes and removed future labels Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
class: substantive https://www.w3.org/2023/Process-20230612/#correction-classes
Projects
None yet
Development

No branches or pull requests

3 participants