diff -r 4d777d6c8024 -r ef8f4023e32e DJMFix.cpp --- a/DJMFix.cpp Fri Dec 18 23:58:03 2020 +0100 +++ b/DJMFix.cpp Sat Dec 19 17:33:16 2020 +0100 @@ -15,7 +15,9 @@ * along with this program. If not, see . */ #include +#include #include +#include #include #include @@ -27,8 +29,8 @@ private: MidiSender* midiSender; std::thread keepAliveThread; - bool running = false; - bool stopped = false; + std::atomic running{false}; + std::atomic stopped{false}; void run() { while (!stopped) { @@ -38,6 +40,13 @@ } } + // TODO: remove + std::string toString(const MidiMessage& midiMessage) { + std::stringstream result; + for (uint8_t b : midiMessage) result << std::hex << std::setw(2) << std::setfill('0') << (int) b; + return result.str(); + } + public: virtual ~DJMFixImpl() override { @@ -51,13 +60,22 @@ } virtual void receive(MidiMessage midiMessage) override { - std::cerr << "DJMFixImpl::receive()" << std::endl; // TODO: do not mess STDIO + std::cerr << "DJMFixImpl::receive(): size = " << midiMessage.size() << " data = " << toString(midiMessage) << std::endl; // TODO: do not mess STDIO + + if (midiMessage.size() == 54 && midiMessage[9] == 0x13) { + std::cerr << "DJMFixImpl::receive(): got message with HashA and SeedE" << std::endl; // TODO: do not mess STDIO + } + } void start() override { std::cerr << "DJMFixImpl::start()" << std::endl; // TODO: do not mess STDIO - if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting"); - midiSender->send({0xf0, 0xf7}); + if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting DJMFix"); + + // TODO: methods for parsing and constructing messages from parts (TLV) + midiSender->send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x50, 0x01, 0xf7}); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + midiSender->send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x12, 0x2a, 0x01, 0x0b, 0x50, 0x69, 0x6f, 0x6e, 0x65, 0x65, 0x72, 0x44, 0x4a, 0x02, 0x0b, 0x72, 0x65, 0x6b, 0x6f, 0x72, 0x64, 0x62, 0x6f, 0x78, 0x03, 0x12, 0x02, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0x04, 0x08, 0x00, 0x00, 0x00, 0x00, 0xf7}); keepAliveThread = std::thread(&DJMFixImpl::run, this); running = true;