Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
getDevices() {
// MIDI I/O
const input = new midi.input();
const output = new midi.output();
// Set array of ports
const results = [];
const portTypes = {input, output};
for (const key in portTypes) {
results.push(this.getPorts(portTypes[key], key));
}
// Open and close ports
// Prevent `RtMidiIn::cancelCallback: no callback function was set!` error
// Sometimes node-midi doesn't exit nicely when closing I/O without a callback but it also doesn't exit when it doesn't have one.
// For testing, use `ctrl + c` or `process.exit();` if this doesn't work for you.
// Related: justinlatimer/node-midi#117
input.openPort(0);
output.openPort(0);
// Close MIDI I/O ports
*/
const expect = require("chai").expect;
const inquirer = require("inquirer");
const chalk = require("chalk");
const table = require("markdown-table");
const strip = require("strip-ansi");
const _ = require("lodash");
const midi = require("midi");
const rocketry = require("../../lib/index.js");
// MIDI I/O
const input = new midi.input();
const output = new midi.output();
// Device names, ports, support
// TODO: add API features for these and then use them in here
const getDeviceInfo = function(port, portName) {
// Get names of ports
const names = rocketry.core.getAllPortNames(port);
// For all ports in input/output
for (let i = 0; i < names.length; i++) {
// Push into ports
ports.push({
"port": portName === "output" ? chalk.yellow("output") : chalk.cyan("input"),
"number": chalk.gray(i),
"name": names[i],
"supported": names[i].match(rocketry.support.regex) ? chalk.green("true") : chalk.red("false")
});
const Pattern = require('./pattern/pattern.class.js');
const midi = require('midi');
global.startTime = Date.now();
global.bpm = 120;
// Set up a new output.
const output = new midi.output();
let outputIndex;
for(var n=0;n
function connectToLaunchpad() { // Attempt to connect to the Launchpad
const midiIn = new midi.input(); // Create new Midi input
const midiOut = new midi.output(); // Create new Midi output
const midiInCount = midiIn.getPortCount(); // Gets the number of Midi input ports connected
const midiOutCount = midiOut.getPortCount(); // Gets the number of Midi output ports connected
if (midiInCount <= 0 || midiOutCount <= 0) {
console.log('No Midi devices found. Have you plugged in the Launchpad Device yet?');
return;
}
let midiInPort = null;
let midiOutPort = null;
for (let i = 0; i < midiInCount; i++) { // Loop through Midi input ports
if (midiIn.getPortName(i).toLowerCase().includes('launchpad')) {
midiInPort = i; // Save index of Launchpad input port if found
}
}
for (let i = 0; i < midiOutCount; i++) { // Loop through Midi output ports
if (midiOut.getPortName(i).toLowerCase().includes('launchpad')) {
} else if (data.class == 'hyperdeckNext') {
myStreamDeck.fillImageFromFile(sd, path.resolve(__dirname, 'assets/stream-deck/forward-clear.png')).then(() => {
});
} else if (data.class == 'hyperdeckPrevious') {
myStreamDeck.fillImageFromFile(sd, path.resolve(__dirname, 'assets/stream-deck/back-clear.png')).then(() => {
});
};
});
};
};
// MIDI //
// Set up a new input.
var input = new midi.input();
// Configure a callback.
input.on('message', function(deltaTime, message) {
// The message is an array of numbers corresponding to the MIDI bytes:
// [status, data1, data2]
// https://www.cs.cf.ac.uk/Dave/Multimedia/node158.html has some helpful
// information interpreting the messages.
console.log('m:' + message);
// Cut Auto
if (message == '176,95,127') {
atem.cutTransition();
};
if (message == '176,95,0') {
tallyCut.style.backgroundColor = "";
};
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);
}
// logger(keyData, 'key data', data);
}
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);
}
module.exports = function(recordingFileName) {
const midi = require('midi');
// create a readable stream
var stream1 = midi.createReadStream();
var input = new midi.input();
let inputIndex;
for(var n=0;n
const midi = require('midi');
// create a readable stream
var stream1 = midi.createReadStream();
var input = new midi.input();
let inputIndex;
for(var n=0;n
function playNote(note: any, velocity?: number = VELOCITY): void {
console.log(note)
if (Array.isArray(note)) {
// play chord
app.currentChord = note
MIDI.chordOn(CHANNEL, note, velocity, DELAY)
if (AUTO_CLICK_BASE) {
MIDI.noteOn(CHANNEL, note[0] - 2 * 12, LEFT_HAND_VELOCITY, DELAY)
app.currentNote = note[0] - 2 * 12
}
} else {
app.currentNote = note
MIDI.noteOn(CHANNEL, note, velocity, DELAY)
}
}