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.54k stars 115 forks source link

Fails in Chrome #2

Closed vibber closed 8 years ago

vibber commented 8 years ago

I tried this sample code:

        <script>
        WebMidi.enable(
  function() { 
    // Send control change value 127 to controller 1 (modulation) on channel 
    // 12 of all devices
    WebMidi.sendControlChange(1, 127, "all", 12);
 },
  function(m) {
    console.log("Could not enable MIDI interface: " + m);
  }
);
        </script>

but in a fresh Chrome (v49.0) it fails with the following message: Uncaught (in promise) ReferenceError: There is no such output device. webmidi.js 1380

djipco commented 8 years ago

You have an error in your code. The third parameter is the MIDI output device you want to use. For instance, if you wanted to send the Control Change command to all channels of the first MIDI device, you would use:

WebMidi.sendControlChange(1, 127, WebMidi.outputs[0], "all");

vibber commented 8 years ago

I have my example from your article, so maybe you should correct your example in your article:

// Send control change value 127 to controller 1 (modulation) on channel 
    // 12 of all devices
    WebMidi.sendControlChange(1, 127, "all", 12);

http://tangiblejs.com/posts/web-midi-music-and-show-control-in-the-browser

vibber commented 8 years ago

Thank you for getting back to me...

djipco commented 8 years ago

Oh, I see. Thanks for pointing it out. The example code has been fixed. Cheers!

mattHorrigan commented 7 years ago

There is still an error here. When I run the amended code, I get:

Uncaught (in promise) TypeError: WebMidi.sendControlChange is not a function.

djipco commented 7 years ago

The syntax you are using is from legacy version 1. If you are using version 2+ (which I recommend you do), please use the current syntax:

  WebMidi.enable(function(err) {
    if (err) console.log("An error occurred", err);
    console.log(WebMidi.outputs);
    WebMidi.outputs[0].sendControlChange("expressioncoarse", 123);
  });

The latest documentation can be found here.

mattHorrigan commented 7 years ago

Aha. It's working now, yes! I think i did indeed have a version mismatch originally.