commit 20b528ceee0fefa4b7c8da6dc79cd2b3798d2d93
parent f06a4cb1650d8ce670014b7a190118be9a2869ee
Author: Tal Aviram <me@talaviram.com>
Date: Fri, 23 Jul 2021 20:41:30 +0300
controller - toward parsings messages to controller.
Diffstat:
2 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/source/jucePlugin/VirusController.cpp b/source/jucePlugin/VirusController.cpp
@@ -1,10 +1,53 @@
#include "VirusController.h"
#include "PluginProcessor.h"
+// TODO: all sysex structs can be refactored to common instead of including this!
+#include "../virusLib/microcontroller.h"
+
+using MessageType = virusLib::Microcontroller::SysexMessageType;
+
namespace Virus
{
+ static constexpr uint8_t kSysExStart[] = {0xf0, 0x00, 0x20, 0x33, 0x01};
+
Controller::Controller(AudioPluginAudioProcessor &p, unsigned char deviceId) : m_processor(p), m_deviceId(deviceId)
{
+ sendSysEx(constructMessage({0x30, 0x00, 0x00}));
+ }
+
+ void Controller::parseMessage(const SysEx &msg)
+ {
+ if (msg.size() < 8)
+ return; // shorter than expected!
+
+ if (msg[msg.size() - 1] != 0xf7)
+ return; // invalid end?!?
+
+ for (auto i = 0; i < msg.size(); ++i)
+ {
+ if (i < 5)
+ {
+ if (msg[i] != kSysExStart[i])
+ return; // invalid header
+ }
+ else if (i == 5)
+ {
+ if (msg[i] != m_deviceId)
+ return; // not intended to this device!
+ }
+ else if (i == 6)
+ {
+ switch (msg[i])
+ {
+ case MessageType::DUMP_SINGLE:
+ std::cout << "Parse Single" << std::endl;
+ break;
+ case MessageType::DUMP_MULTI:
+ std::cout << "Parse Multi" << std::endl;
+ break;
+ }
+ }
+ }
}
void Controller::printMessage(const SysEx &msg) const
@@ -25,7 +68,7 @@ namespace Virus
std::vector<uint8_t> Controller::constructMessage(SysEx msg)
{
- uint8_t start[] = {0xf0, 0x00, 0x20, 0x33, 0x01, static_cast<uint8_t>(m_deviceId)};
+ const uint8_t start[] = {0xf0, 0x00, 0x20, 0x33, 0x01, static_cast<uint8_t>(m_deviceId)};
msg.insert(msg.begin(), std::begin(start), std::end(start));
msg.push_back(0xf7);
return msg;
@@ -37,7 +80,7 @@ namespace Virus
for (auto msg : m_virusOut)
{
// parse here
- printMessage(msg.sysex);
+ parseMessage(msg.sysex);
}
}
}; // namespace Virus
diff --git a/source/jucePlugin/VirusController.h b/source/jucePlugin/VirusController.h
@@ -17,6 +17,7 @@ namespace Virus
void printMessage(const SysEx &) const;
private:
+ void parseMessage(const SysEx &);
void sendSysEx(const SysEx &);
std::vector<uint8_t> constructMessage(SysEx msg);