trying to avoid internal buffers
This commit is contained in:
parent
721fe62034
commit
0787571f5f
|
|
@ -7,6 +7,9 @@ bleMidi::BluetoothEsp32 sBluetoothEsp32;
|
|||
bleMidi::BleMidiTransport<bleMidi::BluetoothEsp32> bm((bleMidi::BluetoothEsp32&) sBluetoothEsp32);
|
||||
midi::MidiInterface<bleMidi::BleMidiTransport<bleMidi::BluetoothEsp32>> MIDI((bleMidi::BleMidiTransport<bleMidi::BluetoothEsp32>&)bm);
|
||||
|
||||
unsigned long t0 = millis();
|
||||
bool isConnected = false;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
//
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -16,7 +19,9 @@ void setup()
|
|||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
MIDI.begin("hihi", 1);
|
||||
Serial.println(F("booting"));
|
||||
|
||||
MIDI.begin("Huzzah BLE MIDI", 1);
|
||||
|
||||
bm.onConnected(OnBleMidiConnected);
|
||||
bm.onDisconnected(OnBleMidiDisconnected);
|
||||
|
|
@ -24,7 +29,7 @@ void setup()
|
|||
MIDI.setHandleNoteOn(OnBleMidiNoteOn);
|
||||
MIDI.setHandleNoteOff(OnBleMidiNoteOff);
|
||||
|
||||
Serial.println(F("looping"));
|
||||
Serial.println(F("ready"));
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -34,10 +39,14 @@ void loop()
|
|||
{
|
||||
MIDI.read();
|
||||
|
||||
MIDI.sendNoteOn(60, 127, 1); // note 60, velocity 127 on channel 1
|
||||
MIDI.sendNoteOff(60, 127, 1);
|
||||
if (isConnected && (millis() - t0) > 1000)
|
||||
{
|
||||
t0 = millis();
|
||||
|
||||
MIDI.sendNoteOn(60, 127, 1); // note 60, velocity 127 on channel 1
|
||||
MIDI.sendNoteOff(60, 127, 1);
|
||||
}
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
// ====================================================================================
|
||||
|
|
@ -49,6 +58,7 @@ void loop()
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnBleMidiConnected() {
|
||||
Serial.println(F("Connected"));
|
||||
isConnected = true;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
@ -56,6 +66,7 @@ void OnBleMidiConnected() {
|
|||
// -----------------------------------------------------------------------------
|
||||
void OnBleMidiDisconnected() {
|
||||
Serial.println(F("Disconnected"));
|
||||
isConnected = false;
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@ bool BluetoothEsp32::begin(const char* deviceName, BleMidiTransport<class Blueto
|
|||
advertisementData.setFlags(0x04);
|
||||
advertisementData.setCompleteServices(BLEUUID(SERVICE_UUID));
|
||||
advertisementData.setName(deviceName);
|
||||
|
||||
|
||||
// Start advertising
|
||||
_advertising = _server->getAdvertising();
|
||||
_advertising->setAdvertisementData(advertisementData);
|
||||
|
|
|
|||
|
|
@ -15,12 +15,10 @@ template<class BleClass>
|
|||
class BleMidiTransport
|
||||
{
|
||||
private:
|
||||
uint8_t _midiPacket[5]; // outgoing
|
||||
midi::RingBuffer<byte, 44> mRxBuffer;
|
||||
|
||||
typedef midi::RingBuffer<byte, 44> TxBuffer;
|
||||
typedef midi::RingBuffer<byte, 44> RxBuffer;
|
||||
TxBuffer mTxBuffer;
|
||||
RxBuffer mRxBuffer;
|
||||
byte mTxBuffer[44];
|
||||
unsigned mTxIndex;
|
||||
|
||||
bool _connected;
|
||||
|
||||
|
|
@ -29,35 +27,44 @@ private:
|
|||
|
||||
public:
|
||||
inline BleMidiTransport(BleClass& inBleClass)
|
||||
: mBleClass(inBleClass)
|
||||
: mBleClass(inBleClass), mTxIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
inline ~BleMidiTransport() {}
|
||||
|
||||
inline bool begin(int baudrate) {} // n/a
|
||||
|
||||
inline bool begin(const char* deviceName)
|
||||
{
|
||||
return mBleClass.begin(deviceName, this);
|
||||
}
|
||||
inline bool begin(const char* deviceName) { return mBleClass.begin(deviceName, this); }
|
||||
|
||||
inline unsigned available() { return mRxBuffer.getLength(); }
|
||||
inline byte read() { return mRxBuffer.read(); }
|
||||
inline void beginWrite() { mTxBuffer.clear(); }
|
||||
inline void write(byte inData) { mTxBuffer.write(inData); }
|
||||
|
||||
inline void beginWrite()
|
||||
{
|
||||
getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]);
|
||||
mTxIndex = 2;
|
||||
}
|
||||
inline void write(byte inData)
|
||||
{
|
||||
// check for size! SysEx!!!
|
||||
if (false)
|
||||
{
|
||||
// should only happen from SysEx!
|
||||
// if we approach the end of the buffer, chop-up in segments until
|
||||
// we reach F7 (end of SysEx)
|
||||
}
|
||||
|
||||
mTxBuffer[mTxIndex++] = inData;
|
||||
}
|
||||
inline void endWrite()
|
||||
{
|
||||
getMidiTimestamp(&_midiPacket[0], &_midiPacket[1]);
|
||||
|
||||
mTxBuffer.read(_midiPacket + 2, mTxBuffer.getLength());
|
||||
|
||||
mBleClass.write((uint8_t*)_midiPacket, mTxBuffer.getLength() + 2);
|
||||
mBleClass.write(mTxBuffer, mTxIndex);
|
||||
}
|
||||
|
||||
public:
|
||||
void receive(uint8_t* buffer, uint8_t length)
|
||||
{
|
||||
// TODO: check for size!! (SysEx!!)
|
||||
mRxBuffer.read(buffer, length);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue