author | František Kučera <franta-hg@frantovo.cz> |
Sat, 19 Dec 2020 23:59:39 +0100 | |
branch | v_0 |
changeset 6 | bddcf2bf29f2 |
parent 5 | ef8f4023e32e |
child 7 | 889b4b8737bd |
permissions | -rw-r--r-- |
0 | 1 |
/** |
2 |
* DJM-Fix |
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
|
4 |
* |
|
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. |
|
8 |
* |
|
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. |
|
13 |
* |
|
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/>. |
|
16 |
*/ |
|
1 | 17 |
#include <iostream> |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
18 |
#include <iomanip> |
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
19 |
#include <thread> |
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
20 |
#include <mutex> |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
21 |
#include <atomic> |
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
22 |
#include <chrono> |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
23 |
#include <stdexcept> |
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
24 |
#include <vector> |
1 | 25 |
|
26 |
#include "DJMFix.h" |
|
27 |
||
28 |
namespace djmfix { |
|
29 |
||
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
30 |
using Bytes = std::vector<uint8_t>; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
31 |
|
1 | 32 |
class DJMFixImpl : public DJMFix { |
33 |
private: |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
34 |
MidiSender* midiSender; |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
35 |
std::thread keepAliveThread; |
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
36 |
std::recursive_mutex midiMutex; |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
37 |
std::atomic<bool> running{false}; |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
38 |
std::atomic<bool> stopped{false}; |
1 | 39 |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
40 |
void run() { |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
41 |
while (!stopped) { |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
42 |
std::cerr << "DJMFixImpl::run()" << std::endl; // TODO: do not mess STDIO |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
43 |
// TODO: send keep-alive messages |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
44 |
std::this_thread::sleep_for(std::chrono::milliseconds(200)); |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
45 |
} |
1 | 46 |
} |
47 |
||
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
48 |
void send(const MidiMessage& midiMessage) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
49 |
std::lock_guard<std::recursive_mutex> lock(midiMutex); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
50 |
midiSender->send(midiMessage); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
51 |
} |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
52 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
53 |
std::string toString(const Bytes& midiMessage) { |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
54 |
std::stringstream result; |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
55 |
for (uint8_t b : midiMessage) result << std::hex << std::setw(2) << std::setfill('0') << (int) b; |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
56 |
return result.str(); |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
57 |
} |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
58 |
|
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
59 |
Bytes normalize(const Bytes& data) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
60 |
if (data.size() % 2) throw std::invalid_argument("data before normalization must have even number of bytes"); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
61 |
Bytes result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
62 |
result.reserve(data.size() / 2); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
63 |
for (size_t i = 0; i < data.size() / 2; i++) result.push_back((data[i * 2] & 0x0F) << 4 | (data[i * 2 + 1] & 0x0F)); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
64 |
return result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
65 |
} |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
66 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
67 |
uint32_t fnv32hash(const Bytes& buff) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
68 |
uint32_t hash = 0x811c9dc5; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
69 |
for (uint8_t b : buff) hash = ((b^hash) * 0x1000193); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
70 |
return hash; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
71 |
} |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
72 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
73 |
Bytes toBytes(const uint32_t value) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
74 |
Bytes result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
75 |
result.reserve(4); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
76 |
result.push_back(value >> 24); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
77 |
result.push_back(value >> 16); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
78 |
result.push_back(value >> 8); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
79 |
result.push_back(value >> 0); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
80 |
return result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
81 |
} |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
82 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
83 |
bool equals(Bytes a, Bytes b) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
84 |
if (a.size() != b.size()) return false; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
85 |
for (size_t i = 0; i < a.size(); i++) if (a[i] != b[i]) return false; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
86 |
return true; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
87 |
} |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
88 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
89 |
template<typename T> std::vector<T> concat(const std::vector<T>& a, const std::vector<T>& b, const std::vector<T>& c = {}) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
90 |
std::vector<T> result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
91 |
result.reserve(a.size() + b.size() + c.size()); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
92 |
for (size_t i = 0; i < a.size(); i++) result.push_back(a[i]); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
93 |
for (size_t i = 0; i < b.size(); i++) result.push_back(b[i]); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
94 |
for (size_t i = 0; i < c.size(); i++) result.push_back(c[i]); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
95 |
return result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
96 |
} |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
97 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
98 |
template<typename T> std::vector<T> xOR(const std::vector<T>& a, const std::vector<T>& b) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
99 |
if (a.size() != b.size()) throw std::invalid_argument("xor: both must be the same length"); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
100 |
std::vector<T> result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
101 |
result.reserve(a.size()); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
102 |
for (size_t i = 0; i < a.size(); i++) result.push_back(a[i] ^ b[i]); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
103 |
return result; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
104 |
} |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
105 |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
106 |
public: |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
107 |
|
1 | 108 |
virtual ~DJMFixImpl() override { |
109 |
std::cerr << "~DJMFixImpl()" << std::endl; // TODO: do not mess STDIO |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
110 |
if (running) stop(); |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
111 |
} |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
112 |
|
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
113 |
void setMidiSender(MidiSender* midiSender) { |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
114 |
std::cerr << "DJMFixImpl::setMidiSender()" << std::endl; // TODO: do not mess STDIO |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
115 |
this->midiSender = midiSender; |
1 | 116 |
} |
117 |
||
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
118 |
virtual void receive(const MidiMessage& midiMessage) override { |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
119 |
std::cerr << "DJMFixImpl::receive(): size = " << midiMessage.size() << " data = " << toString(midiMessage) << std::endl; // TODO: do not mess STDIO |
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
120 |
std::lock_guard<std::recursive_mutex> lock(midiMutex); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
121 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
122 |
if (midiMessage.size() == 54 && midiMessage[9] == 0x13 && midiMessage[33] == 0x04 && midiMessage[43] == 0x03) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
123 |
Bytes hash1(midiMessage.begin() + 35, midiMessage.begin() + 35 + 8); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
124 |
Bytes seed2(midiMessage.begin() + 45, midiMessage.begin() + 45 + 8); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
125 |
hash1 = normalize(hash1); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
126 |
seed2 = normalize(seed2); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
127 |
std::cerr << "DJMFixImpl::receive(): got message with hash1 = " << toString(hash1) << " and seed2 = " << toString(seed2) << std::endl; // TODO: do not mess STDIO |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
128 |
|
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
129 |
Bytes seed0 = {0x68, 0x01, 0x31, 0xFB}; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
130 |
Bytes seed1 = {0x29, 0x00, 0x00, 0x00, 0x23, 0x48, 0x00, 0x00}; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
131 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
132 |
Bytes hash1check = toBytes(fnv32hash(concat(seed1, xOR(seed0, seed2)))); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
133 |
|
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
134 |
if (equals(hash1, hash1check)) { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
135 |
std::cerr << "DJMFixImpl::receive(): hash1 verification: OK" << std::endl; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
136 |
} else { |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
137 |
std::cerr << "DJMFixImpl::receive(): hash1 verification: ERROR: check = " << toString(hash1check) << std::endl; |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
138 |
} |
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
139 |
} |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
140 |
|
1 | 141 |
} |
142 |
||
143 |
void start() override { |
|
144 |
std::cerr << "DJMFixImpl::start()" << std::endl; // TODO: do not mess STDIO |
|
5
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
145 |
if (midiSender == nullptr) throw std::logic_error("need a midiSender when starting DJMFix"); |
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
146 |
|
ef8f4023e32e
sending and receiving MIDI messages through ALSA (the dirty way)
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
147 |
// TODO: methods for parsing and constructing messages from parts (TLV) |
6
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
148 |
send({0xf0, 0x00, 0x40, 0x05, 0x00, 0x00, 0x00, 0x17, 0x00, 0x50, 0x01, 0xf7}); |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
149 |
std::this_thread::sleep_for(std::chrono::milliseconds(30)); // TODO: wait until we got the response |
bddcf2bf29f2
verify the response from the mixer
František Kučera <franta-hg@frantovo.cz>
parents:
5
diff
changeset
|
150 |
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}); |
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
151 |
|
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
152 |
keepAliveThread = std::thread(&DJMFixImpl::run, this); |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
153 |
running = true; |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
154 |
|
1 | 155 |
} |
156 |
||
157 |
void stop() override { |
|
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
158 |
stopped = true; |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
159 |
keepAliveThread.join(); |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
160 |
running = false; |
1 | 161 |
std::cerr << "DJMFixImpl::stop()" << std::endl; // TODO: do not mess STDIO |
162 |
} |
|
163 |
}; |
|
164 |
||
2
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
165 |
DJMFix* create() { |
f34476ab597f
background thread + AlsaBridge skeleton
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
166 |
return new DJMFixImpl(); |
1 | 167 |
} |
168 |
||
169 |
} |