From b5a12ca98ab572878cbebfead5cab05b69023a37 Mon Sep 17 00:00:00 2001 From: Michael Wilson Date: Fri, 16 Oct 2026 01:38:08 -0700 Subject: [PATCH] Add sendQueueSize and ondequeue to MIDIOutput for backpressure --- index.html | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 80d236b..5d35cfa 100644 --- a/index.html +++ b/index.html @@ -1029,11 +1029,41 @@

           [SecureContext, Exposed=(Window,Worker)] interface MIDIOutput : MIDIPort {
+            readonly attribute unsigned long sendQueueSize;
+            attribute EventHandler ondequeue;
             undefined send(sequence<octet> data, optional DOMHighResTimeStamp timestamp = 0);
             undefined clear();
           };
           
+
+ sendQueueSize +
+
+

+ The number of bytes remaining in the {{MIDIOutput}}'s queue + waiting to be sent by the underlying system. While the + underlying system is saturated (i.e. active send requests have + reached an implementation-specific maximum and the system is + temporarily not able to accept more work), additional calls to + {{MIDIOutput/send()}} are buffered in the queue and increase + {{MIDIOutput/sendQueueSize}} by the number of bytes in + data. Once the underlying system makes sufficient + progress on the current workload, it becomes unsaturated and + processes queued data, decreasing {{MIDIOutput/sendQueueSize}} + by the number of bytes sent. +

+
+
+ ondequeue +
+
+

+ This [=event handler=], of type "dequeue", MUST be supported by + all objects implementing the {{MIDIOutput}} interface. It is + called to signal a decrease in {{MIDIOutput/sendQueueSize}}. +

+
send
@@ -1074,6 +1104,14 @@

"MIDIPortConnectionState.closed">"closed", asynchronously try to [=open the port=].

+

+ Increase {{MIDIOutput/sendQueueSize}} by the number of bytes in + data when the message is enqueued. When the + underlying system finishes sending the enqueued data + to the port, decrease {{MIDIOutput/sendQueueSize}} by the number + of bytes in data and [=fire an event=] named + "dequeue" at the {{MIDIOutput}}. +

sequence<octet> data @@ -1106,7 +1144,10 @@

the {{MIDIOutput}}'s queue. The implementation will need to ensure the MIDI stream is left in a good state, so if the output port is in the middle of a sysex message, a sysex - termination byte (0xf7) should be sent. + termination byte (0xf7) should be sent. If + {{MIDIOutput/sendQueueSize}} is greater than 0, set + {{MIDIOutput/sendQueueSize}} to 0 and [=fire an event=] named + "dequeue" at the {{MIDIOutput}}.