How to use the webmidi.addListener 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-controller / index.js View on Github external
midiEnabledChanged() {
    if (this.midiEnabled) {
      // MIDI input / output ports (from a single device) are connected to the computer
      WebMidi.addListener('connected', e => {

        const { port } = e
        const { name, type } = port

        // The connected event is triggered twice for input, that's why we need to check
        // if this.input is already defined or not, @see https://github.com/NERDDISCO/luminave/issues/14
        if (name === this.inputname && type === 'input' && this.input === null) {
          this.input = port

          // Listen to "noteon" events
          this.input.addListener('noteon', 'all', this.noteon.bind(this))

          // Listen to "controlchange" events
          this.input.addListener('controlchange', 'all', this.controlchange.bind(this))

          // Controller is connected
github NERDDISCO / luminave / src / components / midi-controller / index.js View on Github external
// Listen to "noteon" events
          this.input.addListener('noteon', 'all', this.noteon.bind(this))

          // Listen to "controlchange" events
          this.input.addListener('controlchange', 'all', this.controlchange.bind(this))

          // Controller is connected
          this.connected = true

        } else if (name === this.outputname && type === 'output') {
          this.output = port
        }
      })

      // MIDI input / output ports (from a single device) are disconnected to the computer
      WebMidi.addListener('disconnected', e => {
        const { name, type } = e.port

        if (name === this.inputname && type === 'input') {
          // Remove all listener
          this.input.removeListener()

          this.input = null
        } else if (name === this.outputname && type === 'output') {
          this.output = null
        }

        this.connected = false
      })

    }
  }
github tensorflow / magenta / demos / ai-duet / static / src / keyboard / Midi.js View on Github external
_bindInput(inputDevice){
		if (this._isEnabled){
			WebMidi.addListener('disconnected', (device) => {
				if (device.input){
					device.input.removeListener('noteOn')
					device.input.removeListener('noteOff')
				}
			})
			inputDevice.addListener('noteon', 'all', (event) => {
				try {
					this.emit('keyDown', event.note.number)
				} catch(e){
					console.warn(e)
				}
			})
			inputDevice.addListener('noteoff', 'all',  (event) => {
				try {
					this.emit('keyUp', event.note.number)
				} catch(e){
github googlecreativelab / aiexperiments-ai-duet / static / src / keyboard / Midi.js View on Github external
_bindInput(inputDevice){
		if (this._isEnabled){
			WebMidi.addListener('disconnected', (device) => {
				if (device.input){
					device.input.removeListener('noteOn')
					device.input.removeListener('noteOff')
				}
			})
			inputDevice.addListener('noteon', 'all', (event) => {
				try {
					this.emit('keyDown', event.note.number)
				} catch(e){
					console.warn(e)
				}
			})
			inputDevice.addListener('noteoff', 'all',  (event) => {
				try {
					this.emit('keyUp', event.note.number)
				} catch(e){
github tambien / Piano / src / Main.js View on Github external
_bindInput(inputDevice){
		if (this._isEnabled){
			WebMidi.addListener('disconnected', (device) => {
				if (device.input){
					device.input.removeListener('noteOn')
					device.input.removeListener('noteOff')
				}
			})
			inputDevice.addListener('noteon', 'all', (event) => {
                this.emit('keyDown', event.note.number, event.velocity)
			})
			inputDevice.addListener('noteoff', 'all',  (event) => {
                this.emit('keyUp', event.note.number, event.velocity)
			})

			inputDevice.addListener('controlchange', "all", (event) => {
				if (event.controller.name === 'holdpedal'){
					this.emit(event.value ? 'pedalDown' : 'pedalUp')
				}
github googlecreativelab / aiexperiments-ai-duet / static / src / keyboard / Midi.js View on Github external
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 tensorflow / magenta / demos / ai-duet / static / src / keyboard / Midi.js View on Github external
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 tambien / Piano / src / MidiKeyboard.ts View on Github external
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 grame-cncm / fausteditorweb / src / index.ts View on Github external
webmidi.enable((e) => {
        if (e) return;
        $("#midi-ui-default").hide();
        $("#select-midi-input").prop("disabled", false);
        webmidi.addListener("connected", handleMIDIConnect);
        webmidi.addListener("disconnected", handleMIDIDisconnect);
    });
    /**
github grame-cncm / fausteditorweb / src / index.ts View on Github external
webmidi.enable((e) => {
        if (e) return;
        $("#midi-ui-default").hide();
        $("#select-midi-input").prop("disabled", false);
        webmidi.addListener("connected", handleMIDIConnect);
        webmidi.addListener("disconnected", handleMIDIDisconnect);
    });
    /**

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

Package Health Score

80 / 100
Full package analysis