diff --git a/examples/MidiBle/MidiBle.ino b/examples/MidiBle/MidiBle.ino index 2e3e6a1..b69621e 100644 --- a/examples/MidiBle/MidiBle.ino +++ b/examples/MidiBle/MidiBle.ino @@ -2,9 +2,12 @@ #include #include -bleMidi::BluetoothEsp32 sBluetoothEsp32; -bleMidi::BleMidiTransport bm((bleMidi::BluetoothEsp32&) sBluetoothEsp32); -midi::MidiInterface> MIDI((bleMidi::BleMidiTransport&)bm); + +typedef BLEMIDI_NAMESPACE::BleMidiTransport bleMIDI_t; +bleMIDI_t bm("Huzzah BLE MIDI"); +MIDI_NAMESPACE::MidiInterface MIDI((bleMIDI_t &)bm); + +USING_NAMESPACE_BLEMIDI unsigned long t0 = millis(); bool isConnected = false; @@ -17,7 +20,7 @@ void setup() // Serial communications and wait for port to open: DEBUG_BEGIN(115200); - MIDI.begin("Huzzah BLE MIDI", 1); + MIDI.begin(1); bm.onConnected(OnBleMidiConnected); bm.onDisconnected(OnBleMidiDisconnected); @@ -39,8 +42,8 @@ void loop() { t0 = millis(); - MIDI.sendNoteOn(60, 127, 1); // note 60, velocity 127 on channel 1 - MIDI.sendNoteOff(60, 127, 1); + // MIDI.sendNoteOn(60, 127, 1); // note 60, velocity 127 on channel 1 + // MIDI.sendNoteOff(60, 0, 1); } } @@ -69,7 +72,7 @@ void OnBleMidiDisconnected() { // received note on // ----------------------------------------------------------------------------- void OnBleMidiNoteOn(byte channel, byte note, byte velocity) { - N_DEBUG_PRINT(F("Incoming NoteOn from channel:")); + N_DEBUG_PRINT(F("Incoming NoteOn from channel:")); N_DEBUG_PRINT(channel); N_DEBUG_PRINT(F(" note:")); N_DEBUG_PRINT(note); diff --git a/src/Ble_esp32.h b/src/Ble_esp32.h index cbe38e6..95a0678 100755 --- a/src/Ble_esp32.h +++ b/src/Ble_esp32.h @@ -25,10 +25,6 @@ public: { } - ~BluetoothEsp32() - { - } - bool begin(const char*, BleMidiTransport*); inline void write(uint8_t* data, uint8_t length) @@ -84,7 +80,7 @@ protected: void onWrite(BLECharacteristic * characteristic) { std::string rxValue = characteristic->getValue(); - if (rxValue.length() > 0) { + if (rxValue.length() > 2) { _bluetoothEsp32->receive((uint8_t *)(rxValue.c_str()), rxValue.length()); } } diff --git a/src/midi_bleDefs.h b/src/midi_bleDefs.h index ebdf750..1f0b965 100755 --- a/src/midi_bleDefs.h +++ b/src/midi_bleDefs.h @@ -3,14 +3,16 @@ #include "midi_bleNamespace.h" #if ARDUINO - #include +#include #else - #include - typedef uint8_t byte; +#include +typedef uint8_t byte; #endif BEGIN_BLEMIDI_NAMESPACE +#define BleBuffer_t Deque + /*! \brief Create an instance of the library */ #define BLEMIDI_CREATE_INSTANCE(Type, Name) \ diff --git a/src/midi_bleTransport.h b/src/midi_bleTransport.h index 070ed9c..3622996 100755 --- a/src/midi_bleTransport.h +++ b/src/midi_bleTransport.h @@ -4,6 +4,10 @@ #pragma once +#include "utility/midi_feat4_4_0/MIDI.h" + +#include "utility/Logging.h" + #include "midi_bleSettings.h" #include "midi_bleDefs.h" @@ -15,34 +19,40 @@ template class BleMidiTransport { private: - Deque mRxBuffer; - + byte mRxBuffer[44]; + unsigned mRxIndex = 0; + byte mTxBuffer[44]; unsigned mTxIndex = 0; + char mDeviceName[24]; + private: - BleClass& mBleClass; + BleClass mBleClass; public: - inline BleMidiTransport(BleClass& inBleClass) - : mBleClass(inBleClass) + BleMidiTransport(const char* deviceName) { + strncpy(mDeviceName, deviceName, 24); + + mRxIndex = 0; + mTxIndex = 0; } - inline ~BleMidiTransport() {} + void begin(MIDI_NAMESPACE::Channel inChannel = 1) + { + mBleClass.begin(mDeviceName, this); + } - inline bool begin(int baudrate) {} // n/a - 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() + bool beginTransmission() { getMidiTimestamp(&mTxBuffer[0], &mTxBuffer[1]); mTxIndex = 2; + + return true; } - inline void write(byte inData) + + void write(byte inData) { // check for size! SysEx!!! if (false) @@ -54,16 +64,32 @@ public: mTxBuffer[mTxIndex++] = inData; } - inline void endWrite() + + void endTransmission() { mBleClass.write(mTxBuffer, mTxIndex); + mTxIndex = 0; } + unsigned available() + { + return mRxIndex; + } + + byte read() + { + return mRxBuffer[--mRxIndex]; + } + public: void receive(uint8_t* buffer, uint8_t length) { - // TODO: check for size!! (SysEx!!) - mRxBuffer.read(buffer, length); + // drop the first 2 bytes + + for (int i = 2; i < length; i++) + mRxBuffer[length - i - 1] = buffer[i]; + + mRxIndex = (length - 2); } protected: diff --git a/src/utility/Deque.h b/src/utility/Deque.h index a1676a5..bbd8f1a 100644 --- a/src/utility/Deque.h +++ b/src/utility/Deque.h @@ -1,5 +1,7 @@ #pragma once +#include + template class Deque { // class iterator; diff --git a/test/TestParser.sln b/test/TestParser.sln deleted file mode 100644 index 02d7b49..0000000 --- a/test/TestParser.sln +++ /dev/null @@ -1,31 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29306.81 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TestParser", "TestParser.vcxproj", "{25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Debug|x64.ActiveCfg = Debug|x64 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Debug|x64.Build.0 = Debug|x64 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Debug|x86.ActiveCfg = Debug|Win32 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Debug|x86.Build.0 = Debug|Win32 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Release|x64.ActiveCfg = Release|x64 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Release|x64.Build.0 = Release|x64 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Release|x86.ActiveCfg = Release|Win32 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {E91ABBB5-98C4-4D25-B603-CA43FE39B327} - EndGlobalSection -EndGlobal diff --git a/test/TestParser.vcxproj b/test/TestParser.vcxproj deleted file mode 100644 index 05d5db0..0000000 --- a/test/TestParser.vcxproj +++ /dev/null @@ -1,138 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 16.0 - {25F82AE6-0CAA-4AF7-A003-BB54DB5EBA5E} - TestParser - 10.0 - - - - Application - true - v142 - MultiByte - - - Application - false - v142 - true - MultiByte - - - Application - true - v142 - MultiByte - - - Application - false - v142 - true - MultiByte - - - - - - - - - - - - - - - - - - - - - - - Level3 - Disabled - true - true - - - Console - - - - - Level3 - Disabled - true - true - - - Default - - - Console - - - - - Level3 - MaxSpeed - true - true - true - true - - - Console - true - true - - - - - Level3 - MaxSpeed - true - true - true - true - - - Console - true - true - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/TestParser.vcxproj.filters b/test/TestParser.vcxproj.filters deleted file mode 100644 index 58698e7..0000000 --- a/test/TestParser.vcxproj.filters +++ /dev/null @@ -1,26 +0,0 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - - - Source Files - - - - - Header Files - - - Header Files - - - \ No newline at end of file diff --git a/test/TestParser.vcxproj.user b/test/TestParser.vcxproj.user deleted file mode 100644 index 88a5509..0000000 --- a/test/TestParser.vcxproj.user +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/test/bleMidi.xcodeproj/project.xcworkspace/xcuserdata/bart.xcuserdatad/UserInterfaceState.xcuserstate b/test/bleMidi.xcodeproj/project.xcworkspace/xcuserdata/bart.xcuserdatad/UserInterfaceState.xcuserstate index a325218..d447496 100644 Binary files a/test/bleMidi.xcodeproj/project.xcworkspace/xcuserdata/bart.xcuserdatad/UserInterfaceState.xcuserstate and b/test/bleMidi.xcodeproj/project.xcworkspace/xcuserdata/bart.xcuserdatad/UserInterfaceState.xcuserstate differ