branch | v_0 |
changeset 5 | ef8f4023e32e |
parent 2 | f34476ab597f |
child 6 | bddcf2bf29f2 |
4:4d777d6c8024 | 5:ef8f4023e32e |
---|---|
13 * |
13 * |
14 * You should have received a copy of the GNU General Public License |
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/>. |
15 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
16 */ |
16 */ |
17 #include <iostream> |
17 #include <iostream> |
18 #include <iomanip> |
|
18 #include <thread> |
19 #include <thread> |
20 #include <atomic> |
|
19 #include <chrono> |
21 #include <chrono> |
20 #include <stdexcept> |
22 #include <stdexcept> |
21 |
23 |
22 #include "DJMFix.h" |
24 #include "DJMFix.h" |
23 |
25 |
25 |
27 |
26 class DJMFixImpl : public DJMFix { |
28 class DJMFixImpl : public DJMFix { |
27 private: |
29 private: |
28 MidiSender* midiSender; |
30 MidiSender* midiSender; |
29 std::thread keepAliveThread; |
31 std::thread keepAliveThread; |
30 bool running = false; |
32 std::atomic<bool> running{false}; |
31 bool stopped = false; |
33 std::atomic<bool> stopped{false}; |
32 |
34 |
33 void run() { |
35 void run() { |
34 while (!stopped) { |
36 while (!stopped) { |
35 std::cerr << "DJMFixImpl::run()" << std::endl; // TODO: do not mess STDIO |
37 std::cerr << "DJMFixImpl::run()" << std::endl; // TODO: do not mess STDIO |
36 // TODO: send keep-alive messages |
38 // TODO: send keep-alive messages |
37 std::this_thread::sleep_for(std::chrono::milliseconds(200)); |
39 std::this_thread::sleep_for(std::chrono::milliseconds(200)); |
38 } |
40 } |
41 } |
|
42 |
|
43 // TODO: remove |
|
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; |
|
47 return result.str(); |
|
39 } |
48 } |
40 |
49 |
41 public: |
50 public: |
42 |
51 |
43 virtual ~DJMFixImpl() override { |
52 virtual ~DJMFixImpl() override { |
49 std::cerr << "DJMFixImpl::setMidiSender()" << std::endl; // TODO: do not mess STDIO |
58 std::cerr << "DJMFixImpl::setMidiSender()" << std::endl; // TODO: do not mess STDIO |
50 this->midiSender = midiSender; |
59 this->midiSender = midiSender; |
51 } |
60 } |
52 |
61 |
53 virtual void receive(MidiMessage midiMessage) override { |
62 virtual void receive(MidiMessage midiMessage) override { |
54 std::cerr << "DJMFixImpl::receive()" << std::endl; // TODO: do not mess STDIO |
63 std::cerr << "DJMFixImpl::receive(): size = " << midiMessage.size() << " data = " << toString(midiMessage) << std::endl; // TODO: do not mess STDIO |
64 |
|
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 |
|
67 } |
|
68 |
|
55 } |
69 } |
56 |
70 |
57 void start() override { |
71 void start() override { |
58 std::cerr << "DJMFixImpl::start()" << std::endl; // TODO: do not mess STDIO |
72 std::cerr << "DJMFixImpl::start()" << std::endl; // TODO: do not mess STDIO |
59 if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting"); |
73 if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting DJMFix"); |
60 midiSender->send({0xf0, 0xf7}); |
74 |
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}); |
|
61 |
79 |
62 keepAliveThread = std::thread(&DJMFixImpl::run, this); |
80 keepAliveThread = std::thread(&DJMFixImpl::run, this); |
63 running = true; |
81 running = true; |
64 |
82 |
65 } |
83 } |