renamed BLEMIDI to BLEMIDITransport

This commit is contained in:
lathoub 2020-04-18 11:40:57 +02:00
parent eaa2f29568
commit 6d6fa61f83
6 changed files with 49 additions and 275 deletions

View File

@ -1,33 +1,29 @@
#define DEBUG 4
#include <BLE-MIDI.h> #include <BLE-MIDI.h>
#include <hardware/BLE-MIDI_ESP32.h> #include <hardware/BLE-MIDI_ESP32.h>
BLEMIDI_CREATE_DEFAULT_ESP32_INSTANCE() BLEMIDI_CREATE_DEFAULT_ESP32_INSTANCE()
USING_NAMESPACE_BLEMIDI
unsigned long t0 = millis(); unsigned long t0 = millis();
#ifdef ESP32
bool isConnected = false; bool isConnected = false;
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// //
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void setup() void setup()
{ {
// Serial communications and wait for port to open: Serial.begin(115200);
DEBUG_BEGIN(115200); while (!Serial);
Serial.println("Booting");
MIDI.begin(1); MIDI.begin(1);
bm.onConnected(OnBleMidiConnected); BLEMIDI.onConnected(OnBleMidiConnected);
bm.onDisconnected(OnBleMidiDisconnected); BLEMIDI.onDisconnected(OnBleMidiDisconnected);
MIDI.setHandleNoteOn(OnBleMidiNoteOn); MIDI.setHandleNoteOn(OnBleMidiNoteOn);
MIDI.setHandleNoteOff(OnBleMidiNoteOff); MIDI.setHandleNoteOff(OnBleMidiNoteOff);
N_DEBUG_PRINTLN(F("Ready")); Serial.println(F("Ready"));
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -44,7 +40,6 @@ void loop()
MIDI.sendNoteOn(60, 127, 1); // note 60, velocity 127 on channel 1 MIDI.sendNoteOn(60, 127, 1); // note 60, velocity 127 on channel 1
MIDI.sendNoteOff(60, 0, 1); MIDI.sendNoteOff(60, 0, 1);
} }
} }
// ==================================================================================== // ====================================================================================
@ -55,7 +50,7 @@ void loop()
// rtpMIDI session. Device connected // rtpMIDI session. Device connected
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void OnBleMidiConnected() { void OnBleMidiConnected() {
N_DEBUG_PRINTLN(F("Connected")); Serial.println(F("Connected"));
isConnected = true; isConnected = true;
} }
@ -71,25 +66,24 @@ void OnBleMidiDisconnected() {
// received note on // received note on
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void OnBleMidiNoteOn(byte channel, byte note, byte velocity) { void OnBleMidiNoteOn(byte channel, byte note, byte velocity) {
N_DEBUG_PRINT(F("Incoming NoteOn from channel:")); Serial.print(F("Incoming NoteOn from channel:"));
N_DEBUG_PRINT(channel); Serial.print(channel);
N_DEBUG_PRINT(F(" note:")); Serial.print(F(" note:"));
N_DEBUG_PRINT(note); Serial.print(note);
N_DEBUG_PRINT(F(" velocity:")); Serial.print(F(" velocity:"));
N_DEBUG_PRINT(velocity); Serial.print(velocity);
N_DEBUG_PRINTLN(); Serial.println();
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// received note off // received note off
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void OnBleMidiNoteOff(byte channel, byte note, byte velocity) { void OnBleMidiNoteOff(byte channel, byte note, byte velocity) {
N_DEBUG_PRINT(F("Incoming NoteOff from channel:")); Serial.print(F("Incoming NoteOff from channel:"));
N_DEBUG_PRINT(channel); Serial.print(channel);
N_DEBUG_PRINT(F(" note:")); Serial.print(F(" note:"));
N_DEBUG_PRINT(note); Serial.print(note);
N_DEBUG_PRINT(F(" velocity:")); Serial.print(F(" velocity:"));
N_DEBUG_PRINT(velocity); Serial.print(velocity);
N_DEBUG_PRINTLN(); Serial.println();
} }

View File

@ -5,9 +5,8 @@
####################################### #######################################
# Datatypes (KEYWORD1) # Datatypes (KEYWORD1)
####################################### #######################################
midi_bleTransport KEYWORD1 BLE-MIDI.h KEYWORD1
midi_bleTransport.h KEYWORD1 BLEMIDI KEYWORD1
Ble_esp32.h KEYWORD1
####################################### #######################################
# Methods and Functions (KEYWORD2) # Methods and Functions (KEYWORD2)
@ -41,10 +40,11 @@ tick KEYWORD2
####################################### #######################################
# Instances (KEYWORD3) # Instances (KEYWORD3)
####################################### #######################################
BLEMIDI KEYWORD3
####################################### #######################################
# Constants (LITERAL1) # Constants (LITERAL1)
####################################### #######################################
# Namespace, considering it as a literal # Namespace, considering it as a literal
blemidi LITERAL1 BLEMIDI LITERAL1

View File

@ -14,10 +14,12 @@ using namespace MIDI_NAMESPACE;
BEGIN_BLEMIDI_NAMESPACE BEGIN_BLEMIDI_NAMESPACE
template<class T, class _Settings = DefaultSettings> template<class T, class _Settings = DefaultSettings>
class BLEMIDI class BLEMIDITransport
{ {
typedef _Settings Settings; typedef _Settings Settings;
friend class MIDI_NAMESPACE::MidiInterface<BLEMIDITransport<T>>;
private: private:
byte mRxBuffer[Settings::MaxBufferSize]; byte mRxBuffer[Settings::MaxBufferSize];
unsigned mRxIndex = 0; unsigned mRxIndex = 0;
@ -31,7 +33,7 @@ private:
T mBleClass; T mBleClass;
public: public:
BLEMIDI(const char* deviceName) BLEMIDITransport(const char* deviceName)
{ {
strncpy(mDeviceName, deviceName, 24); strncpy(mDeviceName, deviceName, 24);
@ -169,4 +171,20 @@ public:
}; };
/*! \brief Create an instance of the library
*/
#define BLEMIDI_CREATE_INSTANCE(Type, DeviceName, Name) \
BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32> BLE##Name(DeviceName); \
MIDI_NAMESPACE::MidiInterface<BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32>> Name((BLEMIDI_NAMESPACE::BLEMIDITransport<BLEMIDI_NAMESPACE::BLEMIDI_ESP32> &)BLE##Name);
/*! \brief Create an instance for ESP32 named <DeviceName>
*/
#define BLEMIDI_CREATE_ESP32_INSTANCE(DeviceName) \
BLEMIDI_CREATE_INSTANCE(BLEMIDI_NAMESPACE::BLEMIDI_ESP32, DeviceName, MIDI);
/*! \brief Create a default instance for ESP32 named BLE-MIDI
*/
#define BLEMIDI_CREATE_DEFAULT_ESP32_INSTANCE() \
BLEMIDI_CREATE_ESP32_INSTANCE("BLE-MIDI")
END_BLEMIDI_NAMESPACE END_BLEMIDI_NAMESPACE

View File

@ -15,24 +15,3 @@
#include <inttypes.h> #include <inttypes.h>
typedef uint8_t byte; typedef uint8_t byte;
#endif #endif
BEGIN_BLEMIDI_NAMESPACE
/*! \brief Create an instance of the library
*/
#define BLEMIDI_CREATE_INSTANCE(Type, DeviceName, Name) \
typedef BLEMIDI_NAMESPACE::BLEMIDI<BLEMIDI_NAMESPACE::BLEMIDI_ESP32> BLEMIDI_t; \
BLEMIDI_t Name(DeviceName); \
MIDI_NAMESPACE::MidiInterface<BLEMIDI_t> MIDI((BLEMIDI_t &)Name);
/*! \brief Create an instance for ESP32 named <DeviceName>
*/
#define BLEMIDI_CREATE_ESP32_INSTANCE(DeviceName) \
BLEMIDI_CREATE_INSTANCE(BLEMIDI_NAMESPACE::BLEMIDI_ESP32, DeviceName, bm);
/*! \brief Create a default instance for ESP32 named BLE-MIDI
*/
#define BLEMIDI_CREATE_DEFAULT_ESP32_INSTANCE() \
BLEMIDI_CREATE_ESP32_INSTANCE("BLE-MIDI")
END_BLEMIDI_NAMESPACE

View File

@ -15,14 +15,14 @@ private:
BLEAdvertising* _advertising = nullptr; BLEAdvertising* _advertising = nullptr;
BLECharacteristic* _characteristic = nullptr; BLECharacteristic* _characteristic = nullptr;
BLEMIDI<class BLEMIDI_ESP32>* _bleMidiTransport = nullptr; BLEMIDITransport<class BLEMIDI_ESP32>* _bleMidiTransport = nullptr;
public: public:
BLEMIDI_ESP32() BLEMIDI_ESP32()
{ {
} }
bool begin(const char*, BLEMIDI<class BLEMIDI_ESP32>*); bool begin(const char*, BLEMIDITransport<class BLEMIDI_ESP32>*);
void write(uint8_t* buffer, size_t length) void write(uint8_t* buffer, size_t length)
{ {
@ -187,7 +187,7 @@ protected:
} }
}; };
bool BLEMIDI_ESP32::begin(const char* deviceName, BLEMIDI<class BLEMIDI_ESP32>* bleMidiTransport) bool BLEMIDI_ESP32::begin(const char* deviceName, BLEMIDITransport<class BLEMIDI_ESP32>* bleMidiTransport)
{ {
_bleMidiTransport = bleMidiTransport; _bleMidiTransport = bleMidiTransport;

View File

@ -1,217 +0,0 @@
#pragma once
#include <stddef.h>
template<typename T, size_t Size>
class Deque {
// class iterator;
private:
int _head, _tail;
T _data[Size];
public:
Deque()
{
clear();
};
size_t free();
const size_t size() const;
const size_t max_size() const;
T & front();
const T & front() const;
T & back();
const T & back() const;
void push_front(const T &);
void push_back(const T &);
T pop_front();
T pop_back();
T& operator[](size_t);
const T& operator[](size_t) const;
T& at(size_t);
const T& at(size_t) const;
void clear();
// iterator begin();
// iterator end();
void erase(size_t);
void erase(size_t, size_t);
bool empty() const {
return size() == 0;
}
bool full() const {
return (size() == Size);
}
};
template<typename T, size_t Size>
size_t Deque<T, Size>::free()
{
return Size - size();
}
template<typename T, size_t Size>
const size_t Deque<T, Size>::size() const
{
if (_tail < 0)
return 0; // empty
else if (_head > _tail)
return _head - _tail;
else
return Size - _tail + _head;
}
template<typename T, size_t Size>
const size_t Deque<T, Size>::max_size() const
{
return Size;
}
template<typename T, size_t Size>
T & Deque<T, Size>::front()
{
return _data[_tail];
}
template<typename T, size_t Size>
const T & Deque<T, Size>::front() const
{
return _data[_tail];
}
template<typename T, size_t Size>
T & Deque<T, Size>::back()
{
int idx = _head - 1;
if (idx < 0) idx = Size - 1;
return _data[idx];
}
template<typename T, size_t Size>
const T & Deque<T, Size>::back() const
{
int idx = _head - 1;
if (idx < 0) idx = Size - 1;
return _data[idx];
}
template<typename T, size_t Size>
void Deque<T, Size>::push_front(const T &value)
{
//if container is full, do nothing.
if (free()){
if (--_tail < 0)
_tail = Size - 1;
_data[_tail] = value;
}
}
template<typename T, size_t Size>
void Deque<T, Size>::push_back(const T &value)
{
//if container is full, do nothing.
if (free()){
_data[_head] = value;
if (empty())
_tail = _head;
if (++_head >= Size)
_head %= Size;
}
}
template<typename T, size_t Size>
T Deque<T, Size>::pop_front() {
if (empty()) // if empty, do nothing.
return T();
auto item = front();
if (++_tail >= Size)
_tail %= Size;
if (_tail == _head)
clear();
return item;
}
template<typename T, size_t Size>
T Deque<T, Size>::pop_back() {
if (empty()) // if empty, do nothing.
return T();
auto item = front();
if (--_head < 0)
_head = Size - 1;
if (_head == _tail) //now buffer is empty
clear();
return item;
}
template<typename T, size_t Size>
void Deque<T, Size>::erase(size_t position) {
if (position >= size()) // out-of-range!
return; // do nothing.
for (size_t i = position; i < size() - 1; i++){
at(i) = at(i + 1);
}
pop_back();
}
template<typename T, size_t Size>
void Deque<T, Size>::erase(size_t first, size_t last) {
if (first > last // invalid arguments
|| first >= size()) // out-of-range
return; //do nothing.
size_t tgt = first;
for (size_t i = last + 1; i < size(); i++){
at(tgt++) = at(i);
}
for (size_t i = first; i <= last; i++){
pop_back();
}
}
template<typename T, size_t Size>
T& Deque<T, Size>::operator[](size_t index)
{
auto i = _tail + index;
if (i >= Size)
i %= Size;
return _data[i];
}
template<typename T, size_t Size>
const T& Deque<T, Size>::operator[](size_t index) const
{
auto i = _tail + index;
if (i >= Size)
i %= Size;
return _data[i];
}
template<typename T, size_t Size>
T& Deque<T, Size>::at(size_t index)
{
auto i = _tail + index;
if (i >= Size)
i %= Size;
return _data[i];
}
template<typename T, size_t Size>
const T& Deque<T, Size>::at(size_t index) const
{
auto i = _tail + index;
if (i >= Size)
i %= Size;
return _data[i];
}
template<typename T, size_t Size>
void Deque<T, Size>::clear()
{
_tail = -1;
_head = 0;
}