How to use the webmidi.supported 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 googlecreativelab / creatability-seeing-music / src / piano / Model.js View on Github external
require.ensure(['@magenta/music'], async () => {
				try {
					await this.piano.load()
					const { OnsetsAndFrames } = require('@magenta/music')
					this.model = new OnsetsAndFrames('/assets/model')
					await this.model.initialize()
					this.loading = false
					this._enabled = true
					//add a notification
					if (WebMidi.supported){
						document.querySelector('acc-snackbar').setAttribute('message', 'Choose an audio file to transcribe, or play live with a MIDI keyboard.')
					} else {
						document.querySelector('acc-snackbar').setAttribute('message', 'Choose an audio file to transcribe.')
					}
				} catch (e){
					this.loading = false
					this.emit('error', e)
					console.log(e)
					document.querySelector('#error-snack').setAttribute('message', 'Transcription not supported')
				}
			})
		}
github googlecreativelab / creatability-seeing-music / src / piano / Keyboard.js View on Github external
constructor(){
		super()

		this.connectedDevices = new Map()

		if (WebMidi.supported){
			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()
				})
github ritz078 / raaga / components / MidiSelect / MidiSelect.tsx View on Github external
useEffect(() => {
    if (!webMidi.supported) {
      setError("Your Device doesn't support the WebMIDI API.");
      return;
    }

    setInputMidis(webMidi.inputs);

    webMidi.addListener("connected", handleMidiDeviceChange);
    webMidi.addListener("disconnected", handleMidiDeviceChange);
    return () => {
      webMidi.removeListener("connected", handleMidiDeviceChange);
      webMidi.removeListener("disconnected", handleMidiDeviceChange);
    };
  }, []);
github ritz078 / raaga / components / SoundPlayer.tsx View on Github external
useEffect(() => {
    const _onNoteStart = e => {
      onNoteStart(e.note.number, e.velocity, true);
    };

    const _onNoteStop = e => {
      onNoteStop(e.note.number, true);
    };

    if (!webMidi.supported) return;

    const input = webMidi.getInputById(midiDevice);

    if (input) {
      input.addListener("noteon", "all", _onNoteStart);
      input.addListener("noteoff", "all", _onNoteStop);
    }
    return () => {
      if (input) {
        input.removeListener("noteon", "all", _onNoteStart);
        input.removeListener("noteoff", "all", _onNoteStop);
      }
    };
  }, [midiDevice, onNoteStart, onNoteStop]);

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

84 / 100
Full package analysis