Merge branch 'midi'
This commit is contained in:
commit
3d697b2ef3
5 files changed
+314
No files matched your search
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"name": "midi-test",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"async": "^2.0.0-rc.2",
|
||||
"inquirer": "^3.0.5",
|
||||
"midi": "^0.9.4",
|
||||
"multi-progress": "^2.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
var midi = require('midi'),
|
||||
async = require('async'),
|
||||
inquirer = require('inquirer'),
|
||||
progress = require('multi-progress')(process.stdout),
|
||||
output = new midi.output(),
|
||||
speed = 100,
|
||||
portNames = [];
|
||||
|
||||
for(var i=0; i < output.getPortCount(); i++) {
|
||||
portNames.push(output.getPortName(i));
|
||||
}
|
||||
|
||||
if(! portNames.length) {
|
||||
console.error('no MIDI ports available');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: 'input',
|
||||
name: 'speed',
|
||||
message: 'Send interval (ms)',
|
||||
default: speed
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
name: 'port',
|
||||
message: 'Select port',
|
||||
choices: portNames
|
||||
}
|
||||
]).then(answers => {
|
||||
output.openPort(portNames.indexOf(answers.port));
|
||||
speed = parseInt(answers.speed);
|
||||
startTest();
|
||||
});
|
||||
|
||||
function startTest() {
|
||||
|
||||
var on_bar = progress.newBar('midi on [:bar] :current/:total', {
|
||||
incomplete: ' ',
|
||||
total: 128
|
||||
});
|
||||
|
||||
var off_bar = progress.newBar('midi off [:bar] :current/:total', {
|
||||
incomplete: ' ',
|
||||
total: 128
|
||||
});
|
||||
|
||||
async.timesSeries(128, function(n, next){
|
||||
|
||||
setTimeout(function() {
|
||||
on_bar.tick();
|
||||
output.sendMessage([0x90, n, 0x7F]);
|
||||
next();
|
||||
}, speed);
|
||||
|
||||
}, function() {});
|
||||
|
||||
async.timesSeries(128, function(n, next){
|
||||
|
||||
setTimeout(function() {
|
||||
off_bar.tick();
|
||||
output.sendMessage([0x90, n, 0x00]);
|
||||
next();
|
||||
}, speed);
|
||||
|
||||
}, function() {});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF52 based Bluefruit LE modules
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
#include <bluefruit.h>
|
||||
#include <MIDI.h>
|
||||
|
||||
BLEMidi blemidi;
|
||||
|
||||
// Create a new instance of the Arduino MIDI Library,
|
||||
// and attach BluefruitLE MIDI as the transport.
|
||||
MIDI_CREATE_BLE_INSTANCE(blemidi);
|
||||
|
||||
int on_count = 0;
|
||||
int off_count = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Bluefruit52 BLEMIDI RX Test");
|
||||
|
||||
Bluefruit.autoConnLed(true);
|
||||
|
||||
Bluefruit.begin();
|
||||
Bluefruit.setName("Bluefruit52");
|
||||
|
||||
blemidi.setWriteCallback(handleWrite);
|
||||
MIDI.begin(MIDI_CHANNEL_OMNI);
|
||||
MIDI.setHandleNoteOn(handleNoteOn);
|
||||
MIDI.setHandleNoteOff(handleNoteOff);
|
||||
|
||||
// Set General Discoverable Mode flag
|
||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
|
||||
// Advertise BLE MIDI Service
|
||||
Bluefruit.Advertising.addService(blemidi);
|
||||
|
||||
// Advertise device name in the Scan Response
|
||||
Bluefruit.ScanResponse.addName();
|
||||
|
||||
// Start Advertising
|
||||
Bluefruit.Advertising.start();
|
||||
|
||||
}
|
||||
|
||||
void handleNoteOn(byte channel, byte pitch, byte velocity)
|
||||
{
|
||||
on_count++;
|
||||
Serial.print("note on count: ");
|
||||
Serial.println(on_count, DEC);
|
||||
}
|
||||
|
||||
void handleNoteOff(byte channel, byte pitch, byte velocity)
|
||||
{
|
||||
off_count++;
|
||||
Serial.print("note off count: ");
|
||||
Serial.println(off_count, DEC);
|
||||
}
|
||||
|
||||
void handleWrite() {
|
||||
// Tell the MIDI instance that we have new data.
|
||||
MIDI.read();
|
||||
}
|
||||
|
||||
void loop() {MIDI.read();}
|
||||
@@ -0,0 +1,47 @@
|
||||
var midi = require('midi'),
|
||||
async = require('async'),
|
||||
inquirer = require('inquirer'),
|
||||
progress = require('multi-progress'),
|
||||
input = new midi.input(),
|
||||
multi = new progress(),
|
||||
portNames = [];
|
||||
|
||||
for(var i=0; i < input.getPortCount(); i++) {
|
||||
portNames.push(input.getPortName(i));
|
||||
}
|
||||
|
||||
inquirer.prompt([
|
||||
{
|
||||
type: 'list',
|
||||
name: 'port',
|
||||
message: 'Select port',
|
||||
choices: portNames
|
||||
}
|
||||
]).then((answers) => {
|
||||
input.openPort(portNames.indexOf(answers.port));
|
||||
startTest();
|
||||
});
|
||||
|
||||
function startTest() {
|
||||
|
||||
var on_bar = multi.newBar('midi on [:bar] :current/:total', {
|
||||
incomplete: ' ',
|
||||
total: 128
|
||||
});
|
||||
|
||||
var off_bar = multi.newBar('midi off [:bar] :current/:total', {
|
||||
incomplete: ' ',
|
||||
total: 128,
|
||||
callback: function() {
|
||||
input.closePort();
|
||||
process.exit();
|
||||
}
|
||||
});
|
||||
|
||||
input.on('message', function(deltaTime, message) {
|
||||
if(message[0] != 144 && message[0] != 128) return;
|
||||
if(message[2] == 0) off_bar.tick();
|
||||
if(message[2] == 100) on_bar.tick();
|
||||
});
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
/*********************************************************************
|
||||
This is an example for our nRF52 based Bluefruit LE modules
|
||||
|
||||
Pick one up today in the adafruit shop!
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
MIT license, check LICENSE for more information
|
||||
All text above, and the splash screen below must be included in
|
||||
any redistribution
|
||||
*********************************************************************/
|
||||
#include <bluefruit.h>
|
||||
#include <MIDI.h>
|
||||
|
||||
BLEMidi blemidi;
|
||||
|
||||
// Create a new instance of the Arduino MIDI Library,
|
||||
// and attach BluefruitLE MIDI as the transport.
|
||||
MIDI_CREATE_BLE_INSTANCE(blemidi);
|
||||
|
||||
bool startTest = false;
|
||||
int on_count = 0;
|
||||
int off_count = 0;
|
||||
|
||||
unsigned long on_interval = 5;
|
||||
unsigned long off_interval = on_interval;
|
||||
|
||||
unsigned long prev_on = millis();
|
||||
unsigned long prev_off = millis();
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
|
||||
Serial.println("Bluefruit52 BLEMIDI TX Test");
|
||||
|
||||
Bluefruit.autoConnLed(true);
|
||||
|
||||
Bluefruit.begin();
|
||||
Bluefruit.setName("Bluefruit52");
|
||||
|
||||
MIDI.begin(MIDI_CHANNEL_OMNI);
|
||||
|
||||
// Set General Discoverable Mode flag
|
||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
|
||||
// Advertise BLE MIDI Service
|
||||
Bluefruit.Advertising.addService(blemidi);
|
||||
|
||||
// Advertise device name in the Scan Response
|
||||
Bluefruit.ScanResponse.addName();
|
||||
|
||||
// Start Advertising
|
||||
Bluefruit.Advertising.start();
|
||||
Serial.println("Waiting for connection...");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
// Don't continue if we aren't connected.
|
||||
if (! Bluefruit.connected()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't continue if the connected device isn't ready to receive messages.
|
||||
if (! blemidi.notifyEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
if(! startTest) {
|
||||
Serial.println();
|
||||
Serial.println("Start the node TX test and press a key in the serial monitor to start the test...");
|
||||
while(Serial.available() == 0) { }
|
||||
while(Serial.available()) { Serial.read(); }
|
||||
startTest = true;
|
||||
prev_on = currentMillis;
|
||||
prev_off = currentMillis;
|
||||
Serial.println("Starting test.");
|
||||
}
|
||||
|
||||
if(on_count >= 128 && off_count >= 128) {
|
||||
Serial.println("Test finished. Resetting.");
|
||||
startTest = false;
|
||||
on_count = 0;
|
||||
off_count = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentMillis - prev_on >= on_interval && on_count < 128) {
|
||||
MIDI.sendNoteOn(on_count, 100, 1);
|
||||
on_count++;
|
||||
prev_on = currentMillis;
|
||||
}
|
||||
|
||||
if (currentMillis - prev_off >= off_interval && off_count < 128) {
|
||||
MIDI.sendNoteOff(off_count, 0, 1);
|
||||
off_count++;
|
||||
prev_off = currentMillis;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user