add midi rx test
This commit is contained in:
1 parent
8193fc58a7
commit
8d3cada73f
2 files changed
+138
No files matched your search
@@ -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,69 @@
|
||||
/*********************************************************************
|
||||
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>
|
||||
|
||||
BLEMidi 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(midi_callback);
|
||||
blemidi.start();
|
||||
|
||||
Bluefruit.addAdvFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||
Bluefruit.addAdvTxPower();
|
||||
Bluefruit.addAdvService(blemidi);
|
||||
Bluefruit.addScanRespName();
|
||||
|
||||
Bluefruit.startAdvertising();
|
||||
}
|
||||
|
||||
void loop() {}
|
||||
|
||||
void midi_callback(uint32_t timestamp, uint8_t data[])
|
||||
{
|
||||
Serial.print("[MIDI ");
|
||||
Serial.print(timestamp);
|
||||
Serial.print(" ] ");
|
||||
|
||||
Serial.print(data[0], HEX); Serial.print(" ");
|
||||
Serial.print(data[1] , HEX); Serial.print(" ");
|
||||
Serial.print(data[2] , HEX); Serial.print(" ");
|
||||
|
||||
if(data[0] == 0x90 && data[2] == 0x00) {
|
||||
off_count++;
|
||||
} else if(data[0] == 0x90 && data[2] == 0x7F) {
|
||||
on_count++;
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
|
||||
Serial.print("note on count: ");
|
||||
Serial.println(on_count, DEC);
|
||||
Serial.print("note off count: ");
|
||||
Serial.println(off_count, DEC);
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user