diff --git a/README.md b/README.md index b9d3dab..8055a56 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ When manually installing this library, you have to manually download [Arduino MI ## Usage ### Basic / Default ```cpp -#include +#include #include ... BLEMIDI_CREATE_DEFAULT_ESP32_INSTANCE(); diff --git a/examples/MidiBle/MidiBle.ino b/examples/MidiBle/MidiBle.ino index 1a65d6f..2d530d9 100644 --- a/examples/MidiBle/MidiBle.ino +++ b/examples/MidiBle/MidiBle.ino @@ -1,4 +1,4 @@ -#include +#include #include //#include diff --git a/examples/SysEx_Receive/SysEx_Receive.ino b/examples/SysEx_Receive/SysEx_Receive.ino index 52e3cf9..98cc209 100644 --- a/examples/SysEx_Receive/SysEx_Receive.ino +++ b/examples/SysEx_Receive/SysEx_Receive.ino @@ -1,14 +1,16 @@ -#include +#include -#include -//#include +//#include +#include //#include //#include -BLEMIDI_CREATE_DEFAULT_INSTANCE() +BLEMIDI_CREATE_INSTANCE("CustomName", MIDI) bool isConnected = false; +//#define LOGGING + // ----------------------------------------------------------------------------- // // ----------------------------------------------------------------------------- diff --git a/examples/SysEx_Send/SysEx_Send.ino b/examples/SysEx_Send/SysEx_Send.ino index 67df0a0..b1c28b8 100644 --- a/examples/SysEx_Send/SysEx_Send.ino +++ b/examples/SysEx_Send/SysEx_Send.ino @@ -1,4 +1,4 @@ -#include +#include #include //#include @@ -84,4 +84,4 @@ void OnConnected() { void OnDisconnected() { isConnected = false; digitalWrite(LED_BUILTIN, LOW); -} \ No newline at end of file +} diff --git a/keywords.txt b/keywords.txt index 76cb26d..fbc266f 100644 --- a/keywords.txt +++ b/keywords.txt @@ -5,37 +5,14 @@ ####################################### # Datatypes (KEYWORD1) ####################################### -BLEMIDI.h KEYWORD1 +BLEMIDI_Transport.h KEYWORD1 BLEMIDI KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) ####################################### - -run KEYWORD2 -noteOn KEYWORD2 -noteOff KEYWORD2 -afterTouchPoly KEYWORD2 -controlChange KEYWORD2 -programChange KEYWORD2 -afterTouchChannel KEYWORD2 -pitchBend KEYWORD2 -systemExclusive KEYWORD2 -timeCodeQuarterFrame KEYWORD2 -songPosition KEYWORD2 -songSelect KEYWORD2 -tuneRequest KEYWORD2 -clock KEYWORD2 -start KEYWORD2 -Continue KEYWORD2 -stop KEYWORD2 -activeSensing KEYWORD2 -systemReset KEYWORD2 -timeCodeQuarterFrame KEYWORD2 -sysEx KEYWORD2 -afterTouch KEYWORD2 -polyPressure KEYWORD2 -tick KEYWORD2 +setHandleConnected KEYWORD2 +setHandleDisconnected KEYWORD2 ####################################### # Instances (KEYWORD3) diff --git a/library.properties b/library.properties index 73617cc..46e413e 100644 --- a/library.properties +++ b/library.properties @@ -7,5 +7,5 @@ paragraph=MIDI over Bluetooth Low Energy (BLE-MIDI) 1.0 for Arduino category=Communication url=https://github.com/lathoub/Arduino-BLE-MIDI architectures=esp32,samd,megaavr,mbed,nrf52 -includes=BLEMIDI.h +includes=BLEMIDI_Transport.h depends=MIDI Library, NimBLE-Arduino, ArduinoBLE diff --git a/src/BLEMIDI.cpp b/src/BLEMIDI.cpp deleted file mode 100644 index e2b30e3..0000000 --- a/src/BLEMIDI.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "BLEMIDI.h" \ No newline at end of file diff --git a/src/BLEMIDI_Config.h b/src/BLEMIDI_Config.h deleted file mode 100644 index 5d83206..0000000 --- a/src/BLEMIDI_Config.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#ifdef ARDUINO_ARCH_ESP32 -#include -//#include -#endif - -#include -#ifdef BLEMIDI_nRF52 -#endif - - -#ifdef ArduinoBLE -#include -#endif diff --git a/src/BLEMIDI_Transport.cpp b/src/BLEMIDI_Transport.cpp new file mode 100644 index 0000000..94ad585 --- /dev/null +++ b/src/BLEMIDI_Transport.cpp @@ -0,0 +1 @@ +#include "BLEMIDI_Transport.h" \ No newline at end of file diff --git a/src/BLEMIDI.h b/src/BLEMIDI_Transport.h similarity index 98% rename from src/BLEMIDI.h rename to src/BLEMIDI_Transport.h index 7ec29dd..63a61ec 100644 --- a/src/BLEMIDI.h +++ b/src/BLEMIDI_Transport.h @@ -1,11 +1,10 @@ /*! - * @file BLEMIDI.h + * @file BLEMIDI_Transport.h */ #pragma once #include -using namespace MIDI_NAMESPACE; #include "BLEMIDI_Settings.h" #include "BLEMIDI_Defs.h" @@ -14,7 +13,7 @@ using namespace MIDI_NAMESPACE; BEGIN_BLEMIDI_NAMESPACE template -class BLEMIDITransport +class BLEMIDI_Transport { typedef _Settings Settings; @@ -33,7 +32,7 @@ private: T mBleClass; public: - BLEMIDITransport(const char* deviceName) + BLEMIDI_Transport(const char* deviceName) { strncpy(mDeviceName, deviceName, sizeof(mDeviceName)); @@ -49,7 +48,7 @@ public: mBleClass.begin(mDeviceName, this); } - bool beginTransmission(MidiType type) + bool beginTransmission(MIDI_NAMESPACE::MidiType type) { getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]); mTxIndex = 2; @@ -288,9 +287,10 @@ public: }; -END_BLEMIDI_NAMESPACE - struct MySettings : public MIDI_NAMESPACE::DefaultSettings { static const bool Use1ByteParsing = false; }; + +END_BLEMIDI_NAMESPACE + diff --git a/src/hardware/BLEMIDI_ArduinoBLE.h b/src/hardware/BLEMIDI_ArduinoBLE.h index ef49e97..c88bdc1 100644 --- a/src/hardware/BLEMIDI_ArduinoBLE.h +++ b/src/hardware/BLEMIDI_ArduinoBLE.h @@ -63,7 +63,7 @@ private: class BLEMIDI_ArduinoBLE { private: - static BLEMIDITransport* _bleMidiTransport; + static BLEMIDI_Transport* _bleMidiTransport; static BLEDevice* _central; Fifo mRxBuffer; @@ -73,7 +73,7 @@ public: { } - bool begin(const char*, BLEMIDITransport*); + bool begin(const char*, BLEMIDI_Transport*); void write(uint8_t* buffer, size_t length) { @@ -177,10 +177,10 @@ protected: } }; -BLEMIDITransport* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr; +BLEMIDI_Transport* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr; BLEDevice* BLEMIDI_ArduinoBLE::_central = nullptr; -bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDITransport* bleMidiTransport) +bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport* bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -214,10 +214,10 @@ bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDITransport */ #define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \ -BLEMIDI_NAMESPACE::BLEMIDITransport BLE##Name(DeviceName); \ -MIDI_NAMESPACE::MidiInterface, MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDITransport &)BLE##Name); +BLEMIDI_NAMESPACE::BLEMIDI_Transport BLE##Name(DeviceName); \ +MIDI_NAMESPACE::MidiInterface, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport &)BLE##Name); - /*! \brief Create a default instance for nRF52 named BLE-MIDI + /*! \brief Create a default instance for nRF52 (Nano 33 BLE) named BLE-MIDI */ #define BLEMIDI_CREATE_DEFAULT_INSTANCE() \ BLEMIDI_CREATE_INSTANCE("BLE-MIDI", MIDI) diff --git a/src/hardware/BLEMIDI_ESP32.h b/src/hardware/BLEMIDI_ESP32.h index 73a3ea7..d09b57b 100644 --- a/src/hardware/BLEMIDI_ESP32.h +++ b/src/hardware/BLEMIDI_ESP32.h @@ -15,7 +15,7 @@ private: BLEAdvertising* _advertising = nullptr; BLECharacteristic* _characteristic = nullptr; - BLEMIDITransport* _bleMidiTransport = nullptr; + BLEMIDI_Transport* _bleMidiTransport = nullptr; friend class MyServerCallbacks; friend class MyCharacteristicCallbacks; @@ -28,7 +28,7 @@ public: { } - bool begin(const char*, BLEMIDITransport*); + bool begin(const char*, BLEMIDI_Transport*); void write(uint8_t* buffer, size_t length) { @@ -104,7 +104,7 @@ protected: } }; -bool BLEMIDI_ESP32::begin(const char* deviceName, BLEMIDITransport* bleMidiTransport) +bool BLEMIDI_ESP32::begin(const char* deviceName, BLEMIDI_Transport* bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -151,8 +151,8 @@ bool BLEMIDI_ESP32::begin(const char* deviceName, BLEMIDITransport */ #define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \ -BLEMIDI_NAMESPACE::BLEMIDITransport BLE##Name(DeviceName); \ -MIDI_NAMESPACE::MidiInterface, MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDITransport &)BLE##Name); +BLEMIDI_NAMESPACE::BLEMIDI_Transport BLE##Name(DeviceName); \ +MIDI_NAMESPACE::MidiInterface, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport &)BLE##Name); /*! \brief Create a default instance for ESP32 named BLE-MIDI */ diff --git a/src/hardware/BLEMIDI_ESP32_NimBLE.h b/src/hardware/BLEMIDI_ESP32_NimBLE.h index 4eb706f..52e8524 100644 --- a/src/hardware/BLEMIDI_ESP32_NimBLE.h +++ b/src/hardware/BLEMIDI_ESP32_NimBLE.h @@ -12,7 +12,7 @@ private: BLEAdvertising* _advertising = nullptr; BLECharacteristic* _characteristic = nullptr; - BLEMIDITransport* _bleMidiTransport = nullptr; + BLEMIDI_Transport* _bleMidiTransport = nullptr; friend class MyServerCallbacks; friend class MyCharacteristicCallbacks; @@ -25,7 +25,7 @@ public: { } - bool begin(const char*, BLEMIDITransport*); + bool begin(const char*, BLEMIDI_Transport*); void write(uint8_t* buffer, size_t length) { @@ -102,7 +102,7 @@ protected: } }; -bool BLEMIDI_ESP32_NimBLE::begin(const char* deviceName, BLEMIDITransport* bleMidiTransport) +bool BLEMIDI_ESP32_NimBLE::begin(const char* deviceName, BLEMIDI_Transport* bleMidiTransport) { _bleMidiTransport = bleMidiTransport; @@ -147,12 +147,12 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char* deviceName, BLEMIDITransport */ #define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \ -BLEMIDI_NAMESPACE::BLEMIDITransport BLE##Name(DeviceName); \ -MIDI_NAMESPACE::MidiInterface, MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDITransport &)BLE##Name); +BLEMIDI_NAMESPACE::BLEMIDI_Transport BLE##Name(DeviceName); \ +MIDI_NAMESPACE::MidiInterface, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport &)BLE##Name); /*! \brief Create a default instance for ESP32 named BLE-MIDI */ #define BLEMIDI_CREATE_DEFAULT_INSTANCE() \ -BLEMIDI_CREATE_INSTANCE("BLE-MIDI", MIDI) +BLEMIDI_CREATE_INSTANCE("Esp32-BLE-MIDI", MIDI) END_BLEMIDI_NAMESPACE diff --git a/src/hardware/BLEMIDI_nRF52.h b/src/hardware/BLEMIDI_nRF52.h index 920550f..619f6b9 100644 --- a/src/hardware/BLEMIDI_nRF52.h +++ b/src/hardware/BLEMIDI_nRF52.h @@ -1,16 +1,18 @@ #pragma once -#include +// I N D E V E L O P M E N T + +//#include BEGIN_BLEMIDI_NAMESPACE class BLEMIDI_nRF52 { private: - BLEDis bledis; - BLEMidi blemidi; +// BLEDis bledis; +// BLEMidi blemidi; - BLEMIDITransport* _bleMidiTransport; + BLEMIDI_NAMESPACE::BLEMIDI_Transport* _bleMidiTransport; friend class MyServerCallbacks; friend class MyCharacteristicCallbacks; @@ -20,7 +22,7 @@ public: { } - bool begin(const char*, BLEMIDITransport*); + bool begin(const char*, BLEMIDI_NAMESPACE::BLEMIDI_Transport*); void write(uint8_t* buffer, size_t length) { @@ -54,41 +56,41 @@ protected: } }; -bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDITransport* bleMidiTransport) +bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport* bleMidiTransport) { _bleMidiTransport = bleMidiTransport; // Config the peripheral connection with maximum bandwidth // more SRAM required by SoftDevice // Note: All config***() function must be called before begin() - Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); +// Bluefruit.configPrphBandwidth(BANDWIDTH_MAX); - Bluefruit.begin(); - Bluefruit.setName(deviceName); - Bluefruit.setTxPower(4); // Check bluefruit.h for supported values +// Bluefruit.begin(); +// Bluefruit.setName(deviceName); +// Bluefruit.setTxPower(4); // Check bluefruit.h for supported values // Setup the on board blue LED to be enabled on CONNECT - Bluefruit.autoConnLed(true); +// Bluefruit.autoConnLed(true); // Configure and Start Device Information Service - bledis.setManufacturer("Adafruit Industries"); - bledis.setModel("Bluefruit Feather52"); - bledis.begin(); +// bledis.setManufacturer("Adafruit Industries"); +// bledis.setModel("Bluefruit Feather52"); + // bledis.begin(); // Start advertising ---------------------------- // 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 - Bluefruit.Advertising.addTxPower(); +// Bluefruit.Advertising.addTxPower(); // Advertise BLE MIDI Service - Bluefruit.Advertising.addService(blemidi); +// Bluefruit.Advertising.addService(blemidi); // Secondary Scan Response packet (optional) // Since there is no room for 'Name' in Advertising packet - Bluefruit.ScanResponse.addName(); +// Bluefruit.ScanResponse.addName(); /* Start Advertising * - Enable auto advertising if disconnected @@ -99,10 +101,10 @@ bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDITransport */ #define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \ -BLEMIDI_NAMESPACE::BLEMIDITransport BLE##Name(DeviceName); \ -MIDI_NAMESPACE::MidiInterface, MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDITransport &)BLE##Name); +BLEMIDI_NAMESPACE::BLEMIDI_Transport BLE##Name(DeviceName); \ +MIDI_NAMESPACE::MidiInterface, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport &)BLE##Name); /*! \brief Create a default instance for nRF52 named BLE-MIDI */ #define BLEMIDI_CREATE_DEFAULT_INSTANCE() \ -BLEMIDI_CREATE_INSTANCE("BLE-MIDI", MIDI) +BLEMIDI_CREATE_INSTANCE("nRF85BLE-MIDI", MIDI) END_BLEMIDI_NAMESPACE