From 8193fc58a7111fa6e52e79173f3921c55f8abb89 Mon Sep 17 00:00:00 2001 From: Todd Treece Date: Tue, 28 Feb 2017 17:04:49 -0500 Subject: [PATCH 1/2] add midi tx test --- tools/midi_tests/package.json | 17 ++++ tools/midi_tests/tx.js | 47 +++++++++++ tools/midi_tests/tx_arduino/tx_arduino.ino | 92 ++++++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 tools/midi_tests/package.json create mode 100644 tools/midi_tests/tx.js create mode 100644 tools/midi_tests/tx_arduino/tx_arduino.ino diff --git a/tools/midi_tests/package.json b/tools/midi_tests/package.json new file mode 100644 index 00000000..d7c3c95a --- /dev/null +++ b/tools/midi_tests/package.json @@ -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" + } +} diff --git a/tools/midi_tests/tx.js b/tools/midi_tests/tx.js new file mode 100644 index 00000000..24ad4e52 --- /dev/null +++ b/tools/midi_tests/tx.js @@ -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) return; + if(message[2] == 0) off_bar.tick(); + if(message[2] == 100) on_bar.tick(); + }); + +} diff --git a/tools/midi_tests/tx_arduino/tx_arduino.ino b/tools/midi_tests/tx_arduino/tx_arduino.ino new file mode 100644 index 00000000..ca005ba8 --- /dev/null +++ b/tools/midi_tests/tx_arduino/tx_arduino.ino @@ -0,0 +1,92 @@ +/********************************************************************* + 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 + +BLEMidi 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"); + + blemidi.start(); + + Bluefruit.addAdvFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE); + Bluefruit.addAdvTxPower(); + Bluefruit.addAdvService(blemidi); + Bluefruit.addScanRespName(); + + Bluefruit.startAdvertising(); + +} + +void loop() +{ + + if (! Bluefruit.connected()) + return; + + if (! blemidi.configured()) + 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) { + blemidi.send(0x90, on_count, 0x64); + on_count++; + prev_on = currentMillis; + } + + if (currentMillis - prev_off >= off_interval && off_count < 128) { + blemidi.send(0x90, off_count, 0x00); + off_count++; + prev_off = currentMillis; + } + +} From 8d3cada73f317eee78c6369030a5ac5e62d4c3b5 Mon Sep 17 00:00:00 2001 From: Todd Treece Date: Tue, 28 Feb 2017 17:05:12 -0500 Subject: [PATCH 2/2] add midi rx test --- tools/midi_tests/rx.js | 69 ++++++++++++++++++++++ tools/midi_tests/rx_arduino/rx_arduino.ino | 69 ++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 tools/midi_tests/rx.js create mode 100644 tools/midi_tests/rx_arduino/rx_arduino.ino diff --git a/tools/midi_tests/rx.js b/tools/midi_tests/rx.js new file mode 100644 index 00000000..f537bd20 --- /dev/null +++ b/tools/midi_tests/rx.js @@ -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() {}); + +} diff --git a/tools/midi_tests/rx_arduino/rx_arduino.ino b/tools/midi_tests/rx_arduino/rx_arduino.ino new file mode 100644 index 00000000..165deb34 --- /dev/null +++ b/tools/midi_tests/rx_arduino/rx_arduino.ino @@ -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 + +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); + +} +