How to use the webmidi.enable 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 NERDDISCO / luminave / src / components / midi-manager / index.js View on Github external
constructor() {
    super()

    // Web MIDI is disabled
    store.dispatch(enableMidi(false))

    // Enable Web MIDI
    WebMidi.enable(err => {

      if (err) {
        console.error('Web MIDI API could not be enabled:', err)
      } else {
        // MIDI input / output ports (from a single device) are connected to the computer
        WebMidi.addListener('connected', e => {
          const { manufacturer, name, id, type } = e.port
          console.log('MIDIController added:', 'Manufacturer:', manufacturer, '| Name:', name, '| ID:', id, '| Type:', type)
        })

        WebMidi.addListener('disconnected', e => {
          const { manufacturer, name, type, id } = e.port
          console.log('MIDIController removed:', 'Manufacturer:', manufacturer, '| Name:', name, '| ID:', id, '| Type:', type)
        })

        // Web MIDI is enabled
github garrensmith / abletonpush / src / index.js View on Github external
constructor (opts = {}) {
    super();

    const options = Object.assign(opts, {logging: true});
    log.enabled = options.logging;
    this.activePads = [];
    this.batchCommands = []; // batch commands in case something is called before web midi is enabled
    this.midiEnabled = false;
    this.pushConnected = false;

    WebMidi.enable((err) => {
      if (err) {
        log('WebMidi could not be enabled.');
        return;
      }

      this.midiEnabled = true;
      log('WebMidi enabled!');

      WebMidi.addListener('connected', (...args) => {
        if (this.pushConnected) {
          return;
        }
        this.pushConnected = true;
        this.setupPush();
        log('CONNECTED', args);
        this.emit('push:connected');
github ambewas / react-audio-tools / src / lib / components / inputs / MidiController / MidiController.js View on Github external
requestMidiAccess = () => {
    webmidi.enable(err => {
      if (err) {
        this.canAccessMidi = false;
        alert("No midi support in your browser."); // eslint-disable-line
      } else {
        this.canAccessMidi = true;
        this.initializeMidi();
      }
    });
  }
github baku89 / ui-study / src / manager / BindManager.ts View on Github external
private setupMidi() {
		WebMidi.enable(err => {
			if (err) {
				console.warn(err)
				return
			}

			const onMidimessage = ({data}: InputEventBase<'midimessage'>) => {
				const [_, ch, velocity] = data
				const pressed = velocity > 64
				const address = `/midi/ch${ch}`
				const toggleType = pressed ? 'press' : 'release'
				const togglePayload = {address, value: pressed}
				const changePayload = {address, value: velocity}

				this.toggleTable.set(address, pressed)

				this.emit(toggleType, togglePayload)
github cfry / dde / music / note.js View on Github external
static init(){
        if(!WebMidi.enabled){
            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"
        }
        else {
            Midi.all_notes_off()
            WebMidi.disable() //undefines the listeners, maybe other stuff
            setTimeout(Midi.init, 1000)
         }
github tambien / Piano / src / Main.js View on Github external
constructor(){
		super()

		this._isEnabled = false

		WebMidi.enable((err) => {
			if (!err){
				this._isEnabled = true
				if (WebMidi.inputs){
					WebMidi.inputs.forEach((input) => this._bindInput(input))
				}
				WebMidi.addListener('connected', (device) => {
					if (device.input){
						this._bindInput(device.input)
					}
				})
			}
		})
	}
github googlecreativelab / creatability-seeing-music / src / piano / Keyboard.js View on Github external
this.ready = new Promise((done, error) => {
				WebMidi.enable((e) => {
					if (e){
						error(e)
					}
					WebMidi.inputs.forEach(i => this._addListeners(i))
					WebMidi.addListener('connected', (e) => {
						if (e.port.type === 'input'){
							this._addListeners(e.port)
						}
					})
					WebMidi.addListener('disconnected', (e) => {
						this._removeListeners(e.port)
					})
					done()
				})
			})
		} else {
github tambien / Piano / src / MidiKeyboard.ts View on Github external
this.ready = new Promise((done, error) => {
			WebMidi.enable((e) => {
				if (e) {
					error(e)
				}
				WebMidi.addListener('connected', (event) => {
					if (event.port.type === 'input') {
						this._addListeners(event.port)
					}
				})
				WebMidi.addListener('disconnected', (event) => {
					this._removeListeners(event.port)
				})
				done()
			})
		})
github SonyCSLParis / NONOTO / src / renderer / midiOut.ts View on Github external
export function render(useChordsInstrument: boolean = false) {
    let topControlsGridElem = document.getElementById('bottom-controls');
    let midiOutSelectElem: HTMLElement = document.createElement('control-item');
    midiOutSelectElem.id = 'select-midiout';
    topControlsGridElem.appendChild(midiOutSelectElem);

    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;
            }

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 3 months ago

Package Health Score

80 / 100
Full package analysis