Should MIDIInput use a callback instead of events?

Greetings Web Audiophiles,

In reading the Web MIDI spec I note that MIDIInput is declared this way [1]:

MIDIInput implements EventTarget;

interface MIDIInput : MIDIPort {
             attribute EventHandler onmessage;
};

interface MIDIEvent : Event {
    readonly attribute double     receivedTime;
    readonly attribute Uint8Array data;
};

There are a number of problems with these definitions.

1. MIDIEvent does not specify a constructor, so it is not possible to
programmatically create and dispatch a MIDIEvent. That complicates
scenarios such as writing unit tests for MIDI input handlers.

2. As noted in the spec, DOM4 Event objects have a lower-resolution
timeStamp. I think it is confusing to have two kinds of timestamps.

3. The Event interface [2] and EventTarget interface [3] bring with them a
number of concepts that aren’t useful for this application: related targets
(ie the currentTarget property), event phases, event propagation (perhaps),
bubbling, cancelation, default handling and capturing.

4. The style of MIDIInput implements EventTarget is not used by recent
specs; these universally use X : EventTarget for some interface X. This old
style of EventTarget implementation complicates implementation.

One possible benefit of using DOM Events is that it permits wiring up
multiple listeners. Is that an intended use case of onmessage?

I note that Web Audio’s ScriptProcessorNode has a roughly analogous case:
processing buffers of binary audio data in onaudioprocess.
ScriptProcessorNode has moved away from using DOM Events. Given the
problems using DOM Events for MIDIInput noted above, I think it would be
better for MIDIInput to have a simple callback, perhaps something like:

interface MIDIInput {
    attribute MIDIInputHandler? onmessage;
}

callback MIDIInputHandler = void (double receivedTime, Uint8Array data);

Faithfully,

Dominic

[1] <http://webaudio.github.com/web-midi-api/#midiinput-interface>
[2] <http://www.w3.org/TR/2012/WD-dom-20121206/#interface-event>
[3] <http://www.w3.org/TR/2012/WD-dom-20121206/#interface-eventtarget>
-- 
<http://goto.google.com/dc-email-sla>

Received on Tuesday, 19 February 2013 06:47:18 UTC