djipco / webmidi

Tame the Web MIDI API. Send and receive MIDI messages with ease. Control instruments with user-friendly functions (playNote, sendPitchBend, etc.). React to MIDI input with simple event listeners (noteon, pitchbend, controlchange, etc.).
Apache License 2.0
1.53k stars 115 forks source link

Does not create a new interface and only detects MIDI Thourgh interfaces #255

Closed tobiasBora closed 2 years ago

tobiasBora commented 2 years ago

First, thanks a lot for this super cool software.

Description

Typically, when I run a MIDI software, if often re-creates new MIDI interfaces for inputs/outputs, that I can connect together using a tool like QJackCtl (running Linux). For instance, If I run mamba (a fake MIDI keyboard), it generates automatically multiple MIDI inputs:

image

I'm not an expert on MIDI, but I think that the in/out wires going out of Mamba are following the Jack MIDI protocol, while the capture/playback sockets in MIDI bridge are following the ALSA MIDI specification. It seems that there are two kinds of MIDI sockets in the MIDI bridge: the one labelled Midi Through Port-XX (created by the kernel snd-seq-dummy module, which means that it's a bit annoying to create new ports as I need to restart the module) and the one created by specific applications. Anyway, since I'm using Pipewire I can easily connect all of these MIDI sockets as I like. Unfortunately, when I start webmidi.js, it only list the Midi Through Port-XX inputs:

image

Moreover, in QJackCtl, I can't see any new input created by Chromium (Firefox does not even support WebMidi apparently). This means that I need to redirect everything to the Midi Through Port-0 interface:

image

When I do so, it works, but I find it not really practical as I can't easily create new MIDI inputs. Would it be possible to list all MIDI inputs, and potentially create new MIDI inputs/outputs? I'm reporting this here, but it may be an issue to report to Chromium developers, I'm not sure.

Code:

<!DOCTYPE html>

<html lang="en">

  <head>
    <meta charset="UTF-8">
    <title>WebMidi.js Quick Start</title>
    <script src="https://cdn.jsdelivr.net/npm/webmidi@next/dist/iife/webmidi.iife.js"></script>
  </head>

  <body>
    <h1>WebMidi.js Quick Start</h1>
    <script type="module">

      // Enable WebMidi.js and trigger the onEnabled() function when ready
      WebMidi
        .enable()
        .then(onEnabled)
        .catch(err => alert(err));

      function onEnabled() {

        if (WebMidi.inputs.length < 1) {
          document.body.innerHTML+= "No device detected.";
        } else {
          WebMidi.inputs.forEach((device, index) => {
            document.body.innerHTML+= `${index}: ${device.name} <br>`;
          });
        }

        const mySynth = WebMidi.inputs[0];
        // const mySynth = WebMidi.getInputByName("TYPE NAME HERE!")

        mySynth.channels[1].addListener("noteon", e => {
          document.body.innerHTML+= `${e.note.name} <br>`;
        });

      }
    </script>
  </body>

</html>

Environment: Specify the environment where you are witnessing the problem:

djipco commented 2 years ago

Thank you for your kind words.

I do agree that the ability for WEBMIDI.js to create its own MIDI ports would be cool. Unfortunately, the Web MIDI API does not support the creation of virtual ports. This has been requested as early as 2013 but, as you can see on this thread, it is problematic for various reasons.

If the Web MIDI API is ever updated to include virtual in/out ports, I will happily implement them in WEBMIDI.js. However, until then, there isn't much I can do.

P.S. MIDI support in Firefox is very near. You can actuallt try it out in the latest experimental versions (Firefox Nightly).

tobiasBora commented 2 years ago

Thanks a lot for the clarification and the pointer the the issue ! I hope this will be sorted out at some points ;-)