first commit for customSettings

This commit is contained in:
lathoub 2022-05-31 23:01:42 +02:00
parent 8dee1f7d25
commit 12c1e135d4
5 changed files with 98 additions and 15 deletions

View File

@ -0,0 +1,61 @@
#include <BLEMIDI_Transport.h>
struct CustomBufferSizeSettings : public BLEMIDI_NAMESPACE::DefaultSettings {
static const size_t MaxBufferSize = 16; // was 64
};
#include <hardware/BLEMIDI_ESP32_NimBLE.h>
//#include <hardware/BLEMIDI_ESP32.h>
//#include <hardware/BLEMIDI_nRF52.h>
//#include <hardware/BLEMIDI_ArduinoBLE.h>
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomBufferSizeSettings> BLEMIDI("Esp32-NimBLE-MIDI"); \
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE>, BLEMIDI_NAMESPACE::MySettings> MIDI((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE> &)BLEMIDI);
unsigned long t0 = millis();
bool isConnected = false;
// -----------------------------------------------------------------------------
// When BLE connected, LED will turn on (indication that connection was successful)
// When receiving a NoteOn, LED will go out, on NoteOff, light comes back on.
// This is an easy and conveniant way to show that the connection is alive and working.
// -----------------------------------------------------------------------------
void setup()
{
MIDI.begin();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
BLEMIDI.setHandleConnected([]() {
isConnected = true;
digitalWrite(LED_BUILTIN, HIGH);
});
BLEMIDI.setHandleDisconnected([]() {
isConnected = false;
digitalWrite(LED_BUILTIN, LOW);
});
MIDI.setHandleNoteOn([](byte channel, byte note, byte velocity) {
digitalWrite(LED_BUILTIN, LOW);
});
MIDI.setHandleNoteOff([](byte channel, byte note, byte velocity) {
digitalWrite(LED_BUILTIN, HIGH);
});
}
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
void loop()
{
MIDI.read();
if (isConnected && (millis() - t0) > 1000)
{
t0 = millis();
MIDI.sendNoteOn (60, 100, 1); // note 60, velocity 100 on channel 1
}
}

View File

@ -63,7 +63,7 @@ private:
class BLEMIDI_ArduinoBLE class BLEMIDI_ArduinoBLE
{ {
private: private:
static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE>* _bleMidiTransport; static BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* _bleMidiTransport;
static BLEDevice* _central; static BLEDevice* _central;
Fifo<byte, 64> mRxBuffer; Fifo<byte, 64> mRxBuffer;
@ -73,7 +73,7 @@ public:
{ {
} }
bool begin(const char*, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE>*); bool begin(const char*, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>*);
void end() void end()
{ {
@ -183,10 +183,10 @@ protected:
} }
}; };
BLEMIDI_Transport<class BLEMIDI_ArduinoBLE>* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr; BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* BLEMIDI_ArduinoBLE::_bleMidiTransport = nullptr;
BLEDevice* BLEMIDI_ArduinoBLE::_central = nullptr; BLEDevice* BLEMIDI_ArduinoBLE::_central = nullptr;
bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE>* bleMidiTransport) bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport<class BLEMIDI_ArduinoBLE, DefaultSettings>* bleMidiTransport)
{ {
_bleMidiTransport = bleMidiTransport; _bleMidiTransport = bleMidiTransport;
@ -217,6 +217,12 @@ bool BLEMIDI_ArduinoBLE::begin(const char* deviceName, BLEMIDI_Transport<class B
return true; return true;
} }
/*! \brief Create an instance for nRF52 named <DeviceName>
*/
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE, CustomSettings> BLE##Name(DeviceName); \
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE, CustomSettings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ArduinoBLE, CustomSettings> &)BLE##Name);
/*! \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) \

View File

@ -15,7 +15,7 @@ private:
BLEAdvertising *_advertising = nullptr; BLEAdvertising *_advertising = nullptr;
BLECharacteristic *_characteristic = nullptr; BLECharacteristic *_characteristic = nullptr;
BLEMIDI_Transport<class BLEMIDI_ESP32> *_bleMidiTransport = nullptr; BLEMIDI_Transport<class BLEMIDI_ESP32, DefaultSettings> *_bleMidiTransport = nullptr;
friend class MyServerCallbacks; friend class MyServerCallbacks;
friend class MyCharacteristicCallbacks; friend class MyCharacteristicCallbacks;
@ -28,7 +28,7 @@ public:
{ {
} }
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32> *); bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32, DefaultSettings> *);
void end() void end()
{ {
@ -121,7 +121,7 @@ protected:
} }
}; };
bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32> *bleMidiTransport) bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32, DefaultSettings> *bleMidiTransport)
{ {
_bleMidiTransport = bleMidiTransport; _bleMidiTransport = bleMidiTransport;
@ -161,11 +161,15 @@ bool BLEMIDI_ESP32::begin(const char *deviceName, BLEMIDI_Transport<class BLEMID
_advertising->setAppearance(0x00); _advertising->setAppearance(0x00);
_advertising->start(); _advertising->start();
Serial.println("begin");
return true; return true;
} }
/*! \brief Create an instance for ESP32 named <DeviceName>
*/
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32, CustomSettings> BLE##Name(DeviceName); \
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32, CustomSettings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32, CustomSettings> &)BLE##Name);
/*! \brief Create an instance for ESP32 named <DeviceName> /*! \brief Create an instance for ESP32 named <DeviceName>
*/ */
#define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \ #define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \

View File

@ -12,7 +12,7 @@ private:
BLEAdvertising *_advertising = nullptr; BLEAdvertising *_advertising = nullptr;
BLECharacteristic *_characteristic = nullptr; BLECharacteristic *_characteristic = nullptr;
BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE> *_bleMidiTransport = nullptr; BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *_bleMidiTransport = nullptr;
friend class MyServerCallbacks; friend class MyServerCallbacks;
friend class MyCharacteristicCallbacks; friend class MyCharacteristicCallbacks;
@ -25,7 +25,7 @@ public:
{ {
} }
bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE> *); bool begin(const char *, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *);
void end() void end()
{ {
@ -114,7 +114,7 @@ protected:
} }
}; };
bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE> *bleMidiTransport) bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class BLEMIDI_ESP32_NimBLE, DefaultSettings> *bleMidiTransport)
{ {
_bleMidiTransport = bleMidiTransport; _bleMidiTransport = bleMidiTransport;
@ -156,6 +156,12 @@ bool BLEMIDI_ESP32_NimBLE::begin(const char *deviceName, BLEMIDI_Transport<class
return true; return true;
} }
/*! \brief Create an instance for ESP32 named <DeviceName>
*/
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings> BLE##Name(DeviceName); \
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32_NimBLE, CustomSettings> &)BLE##Name);
/*! \brief Create an instance for ESP32 named <DeviceName> /*! \brief Create an instance for ESP32 named <DeviceName>
*/ */
#define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \ #define BLEMIDI_CREATE_INSTANCE(DeviceName, Name) \

View File

@ -12,7 +12,7 @@ private:
// BLEDis bledis; // BLEDis bledis;
// BLEMidi blemidi; // BLEMidi blemidi;
BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52>* _bleMidiTransport; BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52, DefaultSettings>* _bleMidiTransport;
friend class MyServerCallbacks; friend class MyServerCallbacks;
friend class MyCharacteristicCallbacks; friend class MyCharacteristicCallbacks;
@ -22,7 +22,7 @@ public:
{ {
} }
bool begin(const char*, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52>*); bool begin(const char*, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52, DefaultSettings>*);
void end() void end()
{ {
@ -61,7 +61,7 @@ protected:
} }
}; };
bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52>* bleMidiTransport) bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Transport<class BLEMIDI_nRF52, DefaultSettings>* bleMidiTransport)
{ {
_bleMidiTransport = bleMidiTransport; _bleMidiTransport = bleMidiTransport;
@ -114,6 +114,12 @@ bool BLEMIDI_nRF52::begin(const char* deviceName, BLEMIDI_NAMESPACE::BLEMIDI_Tra
return true; return true;
} }
/*! \brief Create an instance for nRF52 named <DeviceName>
*/
#define BLEMIDI_CREATE_CUSTOM_INSTANCE(DeviceName, Name, CustomSettings) \
BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52, CustomSettings> BLE##Name(DeviceName); \
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52, CustomSettings>, BLEMIDI_NAMESPACE::MySettings> Name((BLEMIDI_NAMESPACE::BLEMIDI_Transport<BLEMIDI_NAMESPACE::BLEMIDI_nRF52, CustomSettings> &)BLE##Name);
/*! \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) \