equal
deleted
inserted
replaced
53 Configuration& configuration; |
53 Configuration& configuration; |
54 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: local system encoding |
54 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: local system encoding |
55 |
55 |
56 std::atomic<bool> continueProcessing{true}; |
56 std::atomic<bool> continueProcessing{true}; |
57 |
57 |
|
58 int maxJackPortConnections = 0; |
|
59 |
58 /** |
60 /** |
59 * Is passed through the ring buffer |
61 * Is passed through the ring buffer |
60 * from the the jack-writing thread (callback) to the relpipe-writing thread. |
62 * from the the jack-writing thread (callback) to the relpipe-writing thread. |
61 */ |
63 */ |
62 struct MidiMessage { |
64 struct MidiMessage { |
216 |
218 |
217 if (mlockall(MCL_CURRENT | MCL_FUTURE)) fwprintf(stderr, L"Warning: Can not lock memory.\n"); |
219 if (mlockall(MCL_CURRENT | MCL_FUTURE)) fwprintf(stderr, L"Warning: Can not lock memory.\n"); |
218 |
220 |
219 int jackError = jack_activate(realTimeContext.jackClient); |
221 int jackError = jack_activate(realTimeContext.jackClient); |
220 if (jackError) failInConstructor(L"Could not activate the JACK client."); |
222 if (jackError) failInConstructor(L"Could not activate the JACK client."); |
|
223 |
|
224 |
|
225 // Connect to configured destination ports: |
|
226 const char* jackPortName = jack_port_name(realTimeContext.jackPort); |
|
227 for (auto sourcePort : configuration.portsToConnect) { |
|
228 int error = jack_connect(realTimeContext.jackClient, convertor.to_bytes(sourcePort).c_str(), jackPortName); |
|
229 if (error) failInConstructor(L"Connection to the JACK port failed: " + sourcePort); |
|
230 } |
|
231 |
221 } |
232 } |
222 |
233 |
223 void processJackStream(std::shared_ptr<relpipe::writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) { |
234 void processJackStream(std::shared_ptr<relpipe::writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) { |
224 // Relation headers: |
235 // Relation headers: |
225 using namespace relpipe::writer; |
236 using namespace relpipe::writer; |
242 jack_ringbuffer_read(realTimeContext.ringBuffer, (char*) &m, sizeof (MidiMessage)); |
253 jack_ringbuffer_read(realTimeContext.ringBuffer, (char*) &m, sizeof (MidiMessage)); |
243 processMessage(writer, &m); |
254 processMessage(writer, &m); |
244 relationalWriterFlush(); |
255 relationalWriterFlush(); |
245 } |
256 } |
246 waitForRTCycle(); |
257 waitForRTCycle(); |
|
258 |
|
259 // Once the Configuration::requiredJackConnections count was reached, we will disconnect if the count drops under this level. |
|
260 if (configuration.requiredJackConnections) { |
|
261 int currentConnectionCount = jack_port_connected(realTimeContext.jackPort); |
|
262 if (currentConnectionCount > maxJackPortConnections) maxJackPortConnections = currentConnectionCount; |
|
263 else if (maxJackPortConnections >= configuration.requiredJackConnections && currentConnectionCount < configuration.requiredJackConnections) break; |
|
264 } |
247 } |
265 } |
248 } |
266 } |
249 |
267 |
250 void finish(int sig) { |
268 void finish(int sig) { |
251 continueProcessing = false; |
269 continueProcessing = false; |