3 * Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 3 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 class DJMFixImpl : public DJMFix {
30 MidiSender* midiSender;
31 std::thread keepAliveThread;
32 std::atomic<bool> running{false};
33 std::atomic<bool> stopped{false};
37 std::cerr << "DJMFixImpl::run()" << std::endl; // TODO: do not mess STDIO
38 // TODO: send keep-alive messages
39 std::this_thread::sleep_for(std::chrono::milliseconds(200));
44 std::string toString(const MidiMessage& midiMessage) {
45 std::stringstream result;
46 for (uint8_t b : midiMessage) result << std::hex << std::setw(2) << std::setfill('0') << (int) b;
52 virtual ~DJMFixImpl() override {
53 std::cerr << "~DJMFixImpl()" << std::endl; // TODO: do not mess STDIO
57 void setMidiSender(MidiSender* midiSender) {
58 std::cerr << "DJMFixImpl::setMidiSender()" << std::endl; // TODO: do not mess STDIO
59 this->midiSender = midiSender;
62 virtual void receive(MidiMessage midiMessage) override {
63 std::cerr << "DJMFixImpl::receive(): size = " << midiMessage.size() << " data = " << toString(midiMessage) << std::endl; // TODO: do not mess STDIO
65 if (midiMessage.size() == 54 && midiMessage[9] == 0x13) {
66 std::cerr << "DJMFixImpl::receive(): got message with HashA and SeedE" << std::endl; // TODO: do not mess STDIO
71 void start() override {
72 std::cerr << "DJMFixImpl::start()" << std::endl; // TODO: do not mess STDIO
73 if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting DJMFix");
75 // TODO: methods for parsing and constructing messages from parts (TLV)
76 midiSender->send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x50, 0x01, 0xf7});
77 std::this_thread::sleep_for(std::chrono::milliseconds(10));
78 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});
80 keepAliveThread = std::thread(&DJMFixImpl::run, this);
85 void stop() override {
87 keepAliveThread.join();
89 std::cerr << "DJMFixImpl::stop()" << std::endl; // TODO: do not mess STDIO
94 return new DJMFixImpl();