How to use the midi.noteOn function in midi

To help you get started, we’ve selected a few midi 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 michaelnew / web-piano / js / app.js View on Github external
cmd = data[0] >> 4,
		channel = data[0] & 0xf,
		type = data[0] & 0xf0, // channel agnostic message type. Thanks, Phil Burk.
		note = data[1],
		velocity = data[2];
	// with pressure and tilt off
	// note off: 128, cmd: 8
	// note on: 144, cmd: 9
	// pressure / tilt on
	// pressure: 176, cmd 11:
	// bend: 224, cmd: 14
	// log('MIDI data', data);
	switch(type){
		case 144: // noteOn message
			if (velocity > 0) {
				MIDI.noteOn(0, note, velocity, 0);
				piano.toggleKey(note, true);
				beatVisualizer.triggerNearestNodeOnChannel(note, currentNumericBeat + percentAccumulator);
			} else {
				MIDI.noteOff(0, note, 0);
				piano.toggleKey(note, false);
			}
			break;
		case 128: // noteOff message
			MIDI.noteOff(0, note, 0);
			piano.toggleKey(note, false);
			// noteOff(note, velocity);
			break;
	}
if (channel != 8 && channel != 14) {
		console.log('data', data, 'cmd', cmd, 'channel', channel);
	}
github michaelnew / web-piano / js / app.js View on Github external
beatVisualizer = new BeatVisualizer(stage, function(note) {
		// TODO: make this depend on the selected instrument
		if (currentBeatSound < 3) {
			MIDI.noteOn(currentBeatSound, note, 50, 0);
			MIDI.noteOff(currentBeatSound, note, .2);
		}
	});
github michaelnew / web-piano / js / app.js View on Github external
if ("activeElement" in document) {
    	  	document.activeElement.blur();
  	}
	e = e || window.event;

	var note = keyCodeToNote(e.keyCode);
	var alreadyTriggered = false;

    for (var i = 0, kc; kc = triggeredKeyCodes[i]; i++) {
		if (kc == note) {
			alreadyTriggered = true;
		}
	}

	if (!alreadyTriggered) {
		MIDI.noteOn(0, note, 90, 0);
		triggeredKeyCodes.push(note);

		piano.toggleKey(note, true);
		//beatVisualizer.addNodeToChannel(note, currentBeat);
		beatVisualizer.triggerNearestNodeOnChannel(note, currentNumericBeat + percentAccumulator);

		//keyCodeRecorder.push(e.keyCode);
		//console.log(keyCodeRecorder);
	}
};
github michaelnew / web-piano / js / app.js View on Github external
piano = new PianoVisualizer(stage, function(note, on) {
		if (on) {
			MIDI.noteOn(0, note, 50, 0);
			beatVisualizer.triggerNearestNodeOnChannel(note, currentNumericBeat + percentAccumulator);
		} else {
			MIDI.noteOff(0, note, 0);
		}
	});