How to use the webmidi.outputs function in webmidi

To help you get started, we’ve selected a few webmidi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyter-widgets / midicontrols / src / widget.ts View on Github external
const input = midi.inputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
    if (input === -1) {
      throw new Error("Could not find Behringer X-TOUCH MINI input");
    }

    const output = midi.outputs.findIndex(x => x.manufacturer === "Behringer" && x.name.startsWith("X-TOUCH MINI"));
    if (output === -1) {
      throw new Error("Could not find Behringer X-TOUCH MINI output");
    }

    this.set('_controller_input', input);
    this.set('_controller_output', output);


    // Make sure we are in MCU protocol mode
    midi.outputs[output].sendChannelMode(
      127,
      1 /* MCU mode */,
      1 /* global channel */
    );
    this.setup().then((controls: any) => {
      this.set(controls);
      this.save_changes();
    });
  }
github cfry / dde / music / note.js View on Github external
start(seconds_per_beat=1){
        if (!WebMidi.enabled) {
            Midi.init()
            let the_note = this
            setTimeout(function() { the_note.start(seconds_per_beat) }, 1000)
        }
        else if (WebMidi.outputs.length == 0) {
            dde_error("There are no WebMidi outputs to play a Note on. <a href="#">Help</a>")
        }
        else if (this.is_rest()) { return this } //skip playing the "Rest" as it would error
        else {
            var extra_args = {duration:       Math.round(this.dur  * seconds_per_beat * 1000),
                              time:     "+" + Math.round(this.time * seconds_per_beat * 1000),
                              velocity: this.velocity}
            const pitch = this.pitch
            const chan  = this.channel
            WebMidi.outputs[0].playNote(pitch, chan, extra_args)
            return this
        }
    }
github ISNIT0 / webaudio-generator / src / nodes / inputs / midi.ts View on Github external
WebMidi.enable(function (err: any) {
            if (err) {
                alert("WebMidi could not be enabled.");
            }

            const output = WebMidi.outputs[0];
            const input = WebMidi.inputs[0];

            input.addListener('noteon', "all",
                function (e: any) {
                    console.log("Received 'noteon' message (" + e.note.name + e.note.octave + ").");
                    output.playNote(`${e.note.name}${e.note.octave}`, 'all', { velocity: 1 });
                    synth.triggerAttack(`${e.note.name}${e.note.octave}`);
                }
            );
            input.addListener('noteoff', "all",
                function (e: any) {
                    console.log("Received 'noteoff' message (" + e.note.name + e.note.octave + ").");
                    output.playNote(`${e.note.name}${e.note.octave}`, 'all', { velocity: 0 });
                    synth.triggerRelease();
                }
            );
github cfry / dde / music / note.js View on Github external
if (!WebMidi.enabled) {
            Midi.init()
            let the_note = this
            setTimeout(function() { the_note.start(seconds_per_beat) }, 1000)
        }
        else if (WebMidi.outputs.length == 0) {
            dde_error("There are no WebMidi outputs to play a Note on. <a href="#">Help</a>")
        }
        else if (this.is_rest()) { return this } //skip playing the "Rest" as it would error
        else {
            var extra_args = {duration:       Math.round(this.dur  * seconds_per_beat * 1000),
                              time:     "+" + Math.round(this.time * seconds_per_beat * 1000),
                              velocity: this.velocity}
            const pitch = this.pitch
            const chan  = this.channel
            WebMidi.outputs[0].playNote(pitch, chan, extra_args)
            return this
        }
    }
github cfry / dde / music / note.js View on Github external
static all_notes_off(){
        for(let an_out of WebMidi.outputs){
            an_out.sendChannelMode('allnotesoff', 0)
        }
    }
}
github jupyter-widgets / midicontrols / src / widget.ts View on Github external
initialize(attributes: any, options: any) {
    super.initialize(attributes, options);
    if (!midi.enabled) {
      throw new Error('WebMidi library not enabled');
    }
    const values = {...this.defaults(), ...attributes};
    const input = midi.inputs[values._controller_input];
    const output = midi.outputs[values._controller_output];
    this._button = new Button({input, output}, values._control, {
      mode: values.mode,
      light: values._light
    });
    this._button.stateChanged.connect((sender, args) => {
      switch (args.name) {
        case 'toggled':
          this.set('value', args.newValue);
          break;
        case 'mode':
          this.set('mode', args.newValue);
          break;
      }
      this.save_changes();
    });
    this.listenTo(this, 'change', () => {
github SonyCSLParis / NONOTO / src / renderer / midiOut.ts View on Github external
WebMidi.enable(function (err) {
        if (err) log.error(err);

        let midiOutSelect = new Nexus.Select('#select-midiout', {
            'size': [150, 50],
            'options': ['No Output'].concat(WebMidi.outputs.map((output) => output.name)),
        });

        function midiOutOnChange(ev) {
            if (this.value !== 'No Output') {
                Instruments.mute(true, useChordsInstrument);
                midiOut = WebMidi.getOutputByName(this.value);
            }
            else {
                Instruments.mute(false, useChordsInstrument);
                midiOut = dummyMidiOut;
            }
            log.info('Selected MIDI out: ' + this.value);
        };

        midiOutSelect.on('change', midiOutOnChange.bind(midiOutSelect));
        midiOutSelect.value = 'No Output';
github cfry / dde / music / note.js View on Github external
WebMidi.enable(function(err) {
                                if (err) { warning("WebMidi couldn't be enabled: " + err) }
                                else {
                                    out("WedMidi enabled")
                                    //out(WebMidi.inputs)
                                    //out(WebMidi.outputs)
                                    inspect({"WebMidi.inputs":  WebMidi.inputs,
                                             "WebMidi.outputs": WebMidi.outputs})
                                }
                             })
            //eval_and_play_button_id.style.display = "inline-block"

webmidi

WEBMIDI.js makes it easy to talk to MIDI instruments from a browser or from Node.js. It simplifies the control of external or virtual MIDI instruments with functions such as playNote(), sendPitchBend(), sendControlChange(), etc. It also allows reacting to

Apache-2.0
Latest version published 29 days ago

Package Health Score

84 / 100
Full package analysis