jazz-soft / web-midi

Web MIDI API for browsers
32 stars 3 forks source link

Firefox extension does not get MIDI interface state change events #4

Open jeffgca opened 3 years ago

jeffgca commented 3 years ago

Chromium based browsers reliably propagate MIDI interface state changes, however Firefox + the web midi extension do not seem to get events when MIDI interfaces are added to or removed from the host system.

Browser version: Firefox 87, macOS 10.15.7, latest versions of the JAZZ plugin and web-midi extension.

To reproduce:

  1. load the Codepen linked below in Firefox and Chrome, and ensure that the built in devtools consoles are open
  2. open macOS Audio / MIDI setup utility
  3. toggle a single port IAC Loopbac Driver interface on and off
  4. observe if these connect / disconnect events are logged in the console.

Results:

Chrome: all events are logged Firefox: no events are logged, except a single event is logged if the page is refreshed.

The location bar icon for the Jazz MIDI plugin displays the following text:

Module not found.

Please (re)install the Jazz-Plugin!

Aside: is there logging available for crashes in the underlying Jazz compiled code?

Test code:

navigator.requestMIDIAccess({sysex: true}).then((access)  => {
  console.log('sysexEnabled', access.sysexEnabled);

  setTimeout(function() {
     document.querySelector('#answer')
       .textContent = access.sysexEnabled ? "⚡️Yes! 🎹⚡️" : "🚫 NO 🚫";
  }, 750); 

  access.onstatechange = function(e) {
    // Print information about the (dis)connected MIDI controller
    let s = `Changed: ${e.port.name} ${e.port.manufacturer} ${e.port.state}\n`;
    console.log(e.port.name, e.port.manufacturer, e.port.state);
    document.querySelector('#last-event').textContent = s;
  };
});

( Codepen here )

jeffgca commented 3 years ago

An additional thing I observe when debugging this. If I disable, then re-enable the two extensions in Firefox I get these "refresh" events printed to the page:

[
  "refresh",
  {
    "ins": [
      {
        "name": "NewName",
        "manufacturer": "Unknown",
        "version": "0.0"
      }
    ],
    "outs": [
      {
        "name": "Apple DLS Synth",
        "manufacturer": "Apple",
        "version": "1.0"
      },
      {
        "name": "NewName",
        "manufacturer": "Unknown",
        "version": "0.0"
      }
    ]
  }
]

These seem to be coming from the underlying extension?

jazz-soft commented 3 years ago

The JSON above comes from the jazz-midi extension

jeffgca commented 3 years ago

The JSON above comes from the jazz-midi extension

Yeah I was able to discover this using the debugger. Should these messages not be printed to the browser console instead?

jazz-soft commented 3 years ago

This is the way jazz-midi communicates with JZZ. On some systems this is the only solution. JZZ deletes the text immediately after it is published.

jeffgca commented 3 years ago

I definitely see that - I'm just wondering if the generic Web MIDI extension needs to be adjusted to bring the behaviour closer to what developers see on a browser with native web midi support. The extra messages printed to the page aren't really the point - @jazz-soft I was wondering about your thoughts on whether it is possible to get the Firefox / Jazz combination to reliably propagate MIDI interface change events as per the spec.