parent
2efc6e5f0a
commit
915dc85dac
|
|
@ -2,3 +2,4 @@
|
||||||
examples/.DS_Store
|
examples/.DS_Store
|
||||||
src/.DS_Store
|
src/.DS_Store
|
||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
|
.vscode/c_cpp_properties.json
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
#include <BLE-MIDI.h>
|
|
||||||
#include <hardware/ESP32.h>
|
|
||||||
|
|
||||||
// Simple tutorial on how to receive and send MIDI messages.
|
|
||||||
// Here, when receiving any message on channel 4, the Arduino
|
|
||||||
// will blink a led and play back a note for 1 second.
|
|
||||||
|
|
||||||
BLEMIDI_CREATE_DEFAULT_INSTANCE()
|
|
||||||
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
// pinMode(LED_BUILTIN, OUTPUT);
|
|
||||||
MIDI.begin(4); // Launch MIDI and listen to channel 4
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop()
|
|
||||||
{
|
|
||||||
if (MIDI.read()) // If we have received a message
|
|
||||||
{
|
|
||||||
// digitalWrite(LED_BUILTIN, HIGH);
|
|
||||||
MIDI.sendNoteOn(42, 127, 1); // Send a Note (pitch 42, velo 127 on channel 1)
|
|
||||||
delay(1000); // Wait for a second
|
|
||||||
MIDI.sendNoteOff(42, 0, 1); // Stop the note
|
|
||||||
// digitalWrite(LED_BUILTIN, LOW);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,10 +1,13 @@
|
||||||
#include <BLE-MIDI.h>
|
#include <BLE-MIDI.h>
|
||||||
#include <BLE-MIDI_Config.h>
|
|
||||||
|
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
|
||||||
|
//#include <hardware/BLEMIDI_ESP32.h>
|
||||||
|
//#include <hardware/BLEMIDI_nRF52.h>
|
||||||
|
//#include <hardware/BLEMIDI_ArduinoBLE.h>
|
||||||
|
|
||||||
BLEMIDI_CREATE_DEFAULT_INSTANCE()
|
BLEMIDI_CREATE_DEFAULT_INSTANCE()
|
||||||
|
|
||||||
unsigned long t0 = millis();
|
unsigned long t0 = millis();
|
||||||
unsigned long t1 = millis();
|
|
||||||
bool isConnected = false;
|
bool isConnected = false;
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -12,13 +15,8 @@ bool isConnected = false;
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
|
||||||
while (!Serial);
|
|
||||||
|
|
||||||
MIDI.begin();
|
MIDI.begin();
|
||||||
|
|
||||||
Serial.println("booting!");
|
|
||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
|
|
||||||
|
|
@ -42,12 +40,6 @@ void loop()
|
||||||
|
|
||||||
MIDI.sendNoteOn (60, 100, 1); // note 60, velocity 127 on channel 1
|
MIDI.sendNoteOn (60, 100, 1); // note 60, velocity 127 on channel 1
|
||||||
}
|
}
|
||||||
if (isConnected && (millis() - t1) > 1250)
|
|
||||||
{
|
|
||||||
t1 = millis();
|
|
||||||
|
|
||||||
MIDI.sendNoteOff(60, 0, 1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ====================================================================================
|
// ====================================================================================
|
||||||
|
|
@ -60,7 +52,6 @@ void loop()
|
||||||
void OnConnected() {
|
void OnConnected() {
|
||||||
isConnected = true;
|
isConnected = true;
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
digitalWrite(LED_BUILTIN, HIGH);
|
||||||
Serial.println("connected!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
@ -69,19 +60,16 @@ void OnConnected() {
|
||||||
void OnDisconnected() {
|
void OnDisconnected() {
|
||||||
isConnected = false;
|
isConnected = false;
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
digitalWrite(LED_BUILTIN, LOW);
|
||||||
Serial.println("disconnected!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Received note on
|
// Received note on
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void OnNoteOn(byte channel, byte note, byte velocity) {
|
void OnNoteOn(byte channel, byte note, byte velocity) {
|
||||||
Serial.println("note on");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Received note off
|
// Received note off
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
void OnNoteOff(byte channel, byte note, byte velocity) {
|
void OnNoteOff(byte channel, byte note, byte velocity) {
|
||||||
Serial.println("note off");
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,6 @@ sentence=BLE-MIDI I/Os for Arduino
|
||||||
paragraph=MIDI over Bluetooth Low Energy (BLE-MIDI) 1.0 for Arduino
|
paragraph=MIDI over Bluetooth Low Energy (BLE-MIDI) 1.0 for Arduino
|
||||||
category=Communication
|
category=Communication
|
||||||
url=https://github.com/lathoub/Arduino-BLE-MIDI
|
url=https://github.com/lathoub/Arduino-BLE-MIDI
|
||||||
architectures=esp32,samd,megaavr,mbed
|
architectures=esp32,samd,megaavr,mbed,nrf52
|
||||||
includes=BLE-MIDI.h
|
includes=BLE-MIDI.h
|
||||||
depends=MIDI Library, NimBLE-Arduino, ArduinoBLE
|
depends=MIDI Library, NimBLE-Arduino, ArduinoBLE
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@
|
||||||
//#include <hardware/BLEMIDI_ESP32.h>
|
//#include <hardware/BLEMIDI_ESP32.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef AAA
|
|
||||||
#include <hardware/BLEMIDI_nRF52.h>
|
#include <hardware/BLEMIDI_nRF52.h>
|
||||||
|
#ifdef BLEMIDI_nRF52
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
//#ifdef BBB
|
#ifdef ArduinoBLE
|
||||||
#include <hardware/BLEMIDI_ArduinoBLE.h>
|
#include <hardware/BLEMIDI_ArduinoBLE.h>
|
||||||
//#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -1,58 +1,42 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// Headers for nRF52 BLE
|
#include <bluefruit.h>
|
||||||
//#include "BLECharacteristic.h"
|
|
||||||
//#include "BLEService.h"
|
|
||||||
|
|
||||||
BEGIN_BLEMIDI_NAMESPACE
|
BEGIN_BLEMIDI_NAMESPACE
|
||||||
|
|
||||||
class BLEMIDI
|
class BLEMIDI_nRF52
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
BLEDis bledis;
|
||||||
|
BLEMidi blemidi;
|
||||||
|
|
||||||
BLEMIDITransport<class BLEMIDI>* _bleMidiTransport = nullptr;
|
BLEMIDITransport<class BLEMIDI_nRF52>* _bleMidiTransport;
|
||||||
|
|
||||||
|
friend class MyServerCallbacks;
|
||||||
|
friend class MyCharacteristicCallbacks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BLEMIDI()
|
BLEMIDI_nRF52()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool begin(const char*, BLEMIDITransport<class BLEMIDI>*);
|
bool begin(const char*, BLEMIDITransport<class BLEMIDI_nRF52>*);
|
||||||
|
|
||||||
void write(uint8_t* buffer, size_t length)
|
void write(uint8_t* buffer, size_t length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
bool available(byte* pvBuffer)
|
||||||
The general form of a MIDI message follows:
|
{
|
||||||
n-byte MIDI Message
|
return false;
|
||||||
Byte 0 MIDI message Status byte, Bit 7 is Set to 1.
|
}
|
||||||
Bytes 1 to n-1 MIDI message Data bytes, if n > 1. Bit 7 is Set to 0
|
|
||||||
There are two types of MIDI messages that can appear in a single packet: full MIDI messages and
|
void add(byte value)
|
||||||
Running Status MIDI messages. Each is encoded differently.
|
{
|
||||||
A full MIDI message is simply the MIDI message with the Status byte included.
|
}
|
||||||
A Running Status MIDI message is a MIDI message with the Status byte omitted. Running Status
|
|
||||||
MIDI messages may only be placed in the data stream if the following criteria are met:
|
|
||||||
1. The original MIDI message is 2 bytes or greater and is not a System Common or System
|
protected:
|
||||||
Real-Time message.
|
|
||||||
2. The omitted Status byte matches the most recently preceding full MIDI message’s Status
|
|
||||||
byte within the same BLE packet.
|
|
||||||
In addition, the following rules apply with respect to Running Status:
|
|
||||||
1. A Running Status MIDI message is allowed within the packet after at least one full MIDI
|
|
||||||
message.
|
|
||||||
2. Every MIDI Status byte must be preceded by a timestamp byte. Running Status MIDI
|
|
||||||
messages may be preceded by a timestamp byte. If a Running Status MIDI message is not
|
|
||||||
preceded by a timestamp byte, the timestamp byte of the most recently preceding message
|
|
||||||
in the same packet is used.
|
|
||||||
3. System Common and System Real-Time messages do not cancel Running Status if
|
|
||||||
interspersed between Running Status MIDI messages. However, a timestamp byte must
|
|
||||||
precede the Running Status MIDI message that follows.
|
|
||||||
4. The end of a BLE packet does cancel Running Status.
|
|
||||||
In the MIDI 1.0 protocol, System Real-Time messages can be sent at any time and may be
|
|
||||||
inserted anywhere in a MIDI data stream, including between Status and Data bytes of any other
|
|
||||||
MIDI messages. In the MIDI BLE protocol, the System Real-Time messages must be deinterleaved
|
|
||||||
from other messages – except for System Exclusive messages.
|
|
||||||
*/
|
|
||||||
void receive(uint8_t* buffer, size_t length)
|
void receive(uint8_t* buffer, size_t length)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
@ -70,40 +54,41 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool BLEMIDI::begin(const char* deviceName, BLEMIDITransport<class BLEMIDI>* bleMidiTransport)
|
bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDITransport<class BLEMIDI_nRF52>* bleMidiTransport)
|
||||||
{
|
{
|
||||||
_bleMidiTransport = bleMidiTransport;
|
_bleMidiTransport = bleMidiTransport;
|
||||||
|
|
||||||
// Config the peripheral connection with maximum bandwidth
|
// Config the peripheral connection with maximum bandwidth
|
||||||
// more SRAM required by SoftDevice
|
// more SRAM required by SoftDevice
|
||||||
// Note: All config***() function must be called before begin()
|
// Note: All config***() function must be called before begin()
|
||||||
// Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
|
||||||
|
|
||||||
// Bluefruit.begin();
|
Bluefruit.begin();
|
||||||
// Bluefruit.setName(deviceName);
|
Bluefruit.setName(deviceName);
|
||||||
// Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
|
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
|
||||||
|
|
||||||
// Setup the on board blue LED to be enabled on CONNECT
|
// Setup the on board blue LED to be enabled on CONNECT
|
||||||
// Bluefruit.autoConnLed(true);
|
Bluefruit.autoConnLed(true);
|
||||||
|
|
||||||
// Configure and Start Device Information Service
|
// Configure and Start Device Information Service
|
||||||
// bledis.setManufacturer("Adafruit Industries");
|
bledis.setManufacturer("Adafruit Industries");
|
||||||
// bledis.setModel("Bluefruit Feather52");
|
bledis.setModel("Bluefruit Feather52");
|
||||||
// bledis.begin();
|
bledis.begin();
|
||||||
|
|
||||||
|
// Start advertising ----------------------------
|
||||||
|
|
||||||
// Start advertising
|
|
||||||
// Set General Discoverable Mode flag
|
// Set General Discoverable Mode flag
|
||||||
// Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||||
|
|
||||||
// Advertise TX Power
|
// Advertise TX Power
|
||||||
// Bluefruit.Advertising.addTxPower();
|
Bluefruit.Advertising.addTxPower();
|
||||||
|
|
||||||
// Advertise BLE MIDI Service
|
// Advertise BLE MIDI Service
|
||||||
// Bluefruit.Advertising.addService(blemidi);
|
Bluefruit.Advertising.addService(blemidi);
|
||||||
|
|
||||||
// Secondary Scan Response packet (optional)
|
// Secondary Scan Response packet (optional)
|
||||||
// Since there is no room for 'Name' in Advertising packet
|
// Since there is no room for 'Name' in Advertising packet
|
||||||
// Bluefruit.ScanResponse.addName();
|
Bluefruit.ScanResponse.addName();
|
||||||
|
|
||||||
/* Start Advertising
|
/* Start Advertising
|
||||||
* - Enable auto advertising if disconnected
|
* - Enable auto advertising if disconnected
|
||||||
|
|
@ -114,10 +99,10 @@ bool BLEMIDI::begin(const char* deviceName, BLEMIDITransport<class BLEMIDI>* ble
|
||||||
* For recommended advertising interval
|
* For recommended advertising interval
|
||||||
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
* https://developer.apple.com/library/content/qa/qa1931/_index.html
|
||||||
*/
|
*/
|
||||||
// Bluefruit.Advertising.restartOnDisconnect(true);
|
Bluefruit.Advertising.restartOnDisconnect(true);
|
||||||
// Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
|
||||||
// Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
|
||||||
// Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -125,8 +110,8 @@ bool BLEMIDI::begin(const char* deviceName, BLEMIDITransport<class BLEMIDI>* ble
|
||||||
/*! \brief Create an instance for nRF52 named <DeviceName>
|
/*! \brief Create an instance for nRF52 named <DeviceName>
|
||||||
*/
|
*/
|
||||||
#define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \
|
#define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \
|
||||||
BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI> BLE##Name(DeviceName); \
|
BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52> BLE##Name(DeviceName); \
|
||||||
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI>, MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI> &)BLE##Name);
|
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52>, MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52> &)BLE##Name);
|
||||||
|
|
||||||
/*! \brief Create a default instance for nRF52 named BLE-MIDI
|
/*! \brief Create a default instance for nRF52 named BLE-MIDI
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue