author | František Kučera <franta-hg@frantovo.cz> |
Sat, 17 Oct 2020 19:36:13 +0200 | |
branch | v_0 |
changeset 17 | 4e6b33312c5a |
parent 16 | 79520ded76f0 |
permissions | -rw-r--r-- |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
1 |
/** |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
2 |
* Relational pipes |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
3 |
* Copyright © 2020 František Kučera (Frantovo.cz, GlobalCode.info) |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
4 |
* |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
5 |
* This program is free software: you can redistribute it and/or modify |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
6 |
* it under the terms of the GNU General Public License as published by |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
7 |
* the Free Software Foundation, version 3 of the License. |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
8 |
* |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
9 |
* This program is distributed in the hope that it will be useful, |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
12 |
* GNU General Public License for more details. |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
13 |
* |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
16 |
*/ |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
17 |
#pragma once |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
18 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
19 |
#include <memory> |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
20 |
#include <atomic> |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
21 |
#include <cstdlib> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
22 |
#include <cstring> |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
23 |
#include <sstream> |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
24 |
#include <sys/mman.h> |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
25 |
#include <unistd.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
26 |
#include <pthread.h> |
2
e5f0d3f92eb4
pass RelationalWriter instead of std::ostream to the JackCommand
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
27 |
#include <functional> |
4
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
28 |
#include <iomanip> |
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
29 |
#include <regex> |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
30 |
|
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
31 |
#include <jack/jack.h> |
15
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
32 |
#include <jack/metadata.h> |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
33 |
#include <jack/uuid.h> |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
34 |
#include <jack/midiport.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
35 |
#include <jack/ringbuffer.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
36 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
37 |
#include <relpipe/common/type/typedefs.h> |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
38 |
#include <relpipe/writer/RelationalWriter.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
39 |
#include <relpipe/writer/RelpipeWriterException.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
40 |
#include <relpipe/writer/AttributeMetadata.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
41 |
#include <relpipe/writer/Factory.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
42 |
#include <relpipe/writer/TypeId.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
43 |
#include <relpipe/cli/CLI.h> |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
44 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
45 |
#include "Configuration.h" |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
46 |
#include "JackException.h" |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
47 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
48 |
namespace relpipe { |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
49 |
namespace in { |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
50 |
namespace jack { |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
51 |
|
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
52 |
int enqueueMessage(jack_nframes_t frames, void* arg); |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
53 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
54 |
class JackCommand { |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
55 |
private: |
8
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
56 |
Configuration& configuration; |
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
57 |
std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: local system encoding |
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
58 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
59 |
std::atomic<bool> continueProcessing{true}; |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
60 |
|
10
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
61 |
int maxJackPortConnections = 0; |
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
62 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
63 |
/** |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
64 |
* Is passed through the ring buffer |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
65 |
* from the the jack-writing thread (callback) to the relpipe-writing thread. |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
66 |
*/ |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
67 |
struct MidiMessage { |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
68 |
uint8_t buffer[4096] = {0}; |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
69 |
size_t size; |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
70 |
/** |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
71 |
* Time in micro seconds; |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
72 |
* starts on the first recorded note/message. |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
73 |
*/ |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
74 |
relpipe::common::type::Integer time; |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
75 |
}; |
3
0222c20f590f
report also unknown messages
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
76 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
77 |
/** |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
78 |
* JACK callbacks (called from the real-time thread) |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
79 |
*/ |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
80 |
class RealTimeContext { |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
81 |
private: |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
82 |
jack_nframes_t startFrame = 0; |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
83 |
public: |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
84 |
jack_client_t* jackClient = nullptr; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
85 |
jack_port_t* jackPort = nullptr; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
86 |
jack_ringbuffer_t* ringBuffer = nullptr; |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
87 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
88 |
pthread_mutex_t processingLock = PTHREAD_MUTEX_INITIALIZER; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
89 |
pthread_cond_t processingDone = PTHREAD_COND_INITIALIZER; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
90 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
91 |
const int RING_BUFFER_SIZE = 100; |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
92 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
93 |
int processCallback(jack_nframes_t frames) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
94 |
void* buffer = jack_port_get_buffer(jackPort, frames); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
95 |
if (buffer == nullptr) throw JackException(L"Unable to get port buffer."); // TODO: exception in RT callback? |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
96 |
|
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
97 |
jack_nframes_t lastFrame = jack_last_frame_time(jackClient); |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
98 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
99 |
for (jack_nframes_t i = 0, eventCount = jack_midi_get_event_count(buffer); i < eventCount; i++) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
100 |
jack_midi_event_t event; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
101 |
int noData = jack_midi_event_get(&event, buffer, i); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
102 |
if (noData) continue; |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
103 |
|
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
104 |
if (startFrame == 0) startFrame = lastFrame; |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
105 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
106 |
if (event.size > sizeof (MidiMessage::buffer)) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
107 |
// TODO: should not printf in RT callback: |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
108 |
fwprintf(stderr, L"Error: MIDI message was too large → skipping event. Maximum allowed size: %lu bytes.\n", sizeof (MidiMessage::buffer)); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
109 |
} else if (jack_ringbuffer_write_space(ringBuffer) >= sizeof (MidiMessage)) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
110 |
MidiMessage m; |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
111 |
m.time = lastFrame - startFrame + event.time; |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
112 |
m.time = m.time * 1000 * 1000 / jack_get_sample_rate(jackClient); |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
113 |
m.size = event.size; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
114 |
memcpy(m.buffer, event.buffer, event.size); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
115 |
jack_ringbuffer_write(ringBuffer, (const char *) &m, sizeof (MidiMessage)); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
116 |
} else { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
117 |
// TODO: should not printf in RT callback: |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
118 |
fwprintf(stderr, L"Error: ring buffer is full → skipping event.\n"); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
119 |
} |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
120 |
} |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
121 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
122 |
// TODO: just count skipped events and bytes and report them in next successful message instead of printing to STDERR |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
123 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
124 |
if (pthread_mutex_trylock(&processingLock) == 0) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
125 |
pthread_cond_signal(&processingDone); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
126 |
pthread_mutex_unlock(&processingLock); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
127 |
} |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
128 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
129 |
return 0; |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
130 |
} |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
131 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
132 |
static int processCallback(jack_nframes_t frames, void* instance) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
133 |
return static_cast<RealTimeContext*> (instance)->processCallback(frames); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
134 |
} |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
135 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
136 |
} realTimeContext; |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
137 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
138 |
static void writeRecord(std::shared_ptr<relpipe::writer::RelationalWriter> writer, |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
139 |
relpipe::common::type::StringX eventType, |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
140 |
relpipe::common::type::Integer time, |
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
141 |
relpipe::common::type::Integer channel, |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
142 |
relpipe::common::type::Boolean noteOn, relpipe::common::type::Integer pitch, relpipe::common::type::Integer velocity, |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
143 |
relpipe::common::type::Integer controllerId, relpipe::common::type::Integer value, |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
144 |
relpipe::common::type::StringX raw) { |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
145 |
writer->writeAttribute(eventType); |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
146 |
writer->writeAttribute(&time, typeid (time)); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
147 |
writer->writeAttribute(&channel, typeid (channel)); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
148 |
writer->writeAttribute(¬eOn, typeid (noteOn)); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
149 |
writer->writeAttribute(&pitch, typeid (pitch)); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
150 |
writer->writeAttribute(&velocity, typeid (velocity)); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
151 |
writer->writeAttribute(&controllerId, typeid (controllerId)); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
152 |
writer->writeAttribute(&value, typeid (value)); |
4
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
153 |
writer->writeAttribute(&raw, typeid (raw)); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
154 |
} |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
155 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
156 |
void processMessage(std::shared_ptr<relpipe::writer::RelationalWriter> writer, MidiMessage* event) { |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
157 |
if (event->size == 0) { |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
158 |
return; |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
159 |
} else { |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
160 |
uint8_t type = event->buffer[0] & 0xF0; |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
161 |
uint8_t channel = event->buffer[0] & 0x0F; |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
162 |
jack_time_t time = event->time; |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
163 |
|
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
164 |
if ((type == 0x90 || type == 0x80) && event->size == 3) { |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
165 |
writeRecord(writer, L"note", time, channel, type == 0x90, event->buffer[1], event->buffer[2], 0, 0, toHex(event)); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
166 |
} else if (type == 0xB0 && event->size == 3) { |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
167 |
writeRecord(writer, L"control", time, channel, false, 0, 0, event->buffer[1], event->buffer[2], toHex(event)); |
5
40dd6deafaca
recognize SysEx (System Exclusive) messages
František Kučera <franta-hg@frantovo.cz>
parents:
4
diff
changeset
|
168 |
} else if (event->buffer[0] == 0xF0) { |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
169 |
writeRecord(writer, L"sysex", time, channel, false, 0, 0, 0, 0, toHex(event)); |
3
0222c20f590f
report also unknown messages
František Kučera <franta-hg@frantovo.cz>
parents:
2
diff
changeset
|
170 |
} else { |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
171 |
writeRecord(writer, L"unknown", time, channel, false, 0, 0, 0, 0, toHex(event)); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
172 |
} |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
173 |
} |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
174 |
} |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
175 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
176 |
relpipe::common::type::StringX toHex(MidiMessage* event) { |
4
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
177 |
std::wstringstream result; |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
178 |
result << std::hex << std::setfill(L'0'); |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
179 |
|
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
180 |
for (size_t i = 0; i < event->size && i < sizeof (event->buffer); i++) { |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
181 |
if (i > 0) result << L' '; |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
182 |
result << std::setw(2) << event->buffer[i]; |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
183 |
// result << ("0123456789abcdef"[event->buffer[i] >> 4]); |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
184 |
// result << ("0123456789abcdef"[event->buffer[i] & 0xf]); |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
185 |
} |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
186 |
|
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
187 |
return result.str(); |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
188 |
} |
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
189 |
|
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
190 |
void listPorts(std::shared_ptr<relpipe::writer::RelationalWriter> writer) { |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
191 |
using namespace relpipe::writer; |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
192 |
vector<AttributeMetadata> metadata; |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
193 |
|
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
194 |
metadata.push_back({L"name", TypeId::STRING}); |
15
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
195 |
metadata.push_back({L"uuid", TypeId::STRING}); |
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
196 |
metadata.push_back({L"input", TypeId::BOOLEAN}); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
197 |
metadata.push_back({L"output", TypeId::BOOLEAN}); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
198 |
metadata.push_back({L"physical", TypeId::BOOLEAN}); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
199 |
metadata.push_back({L"terminal", TypeId::BOOLEAN}); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
200 |
metadata.push_back({L"mine", TypeId::BOOLEAN}); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
201 |
metadata.push_back({L"midi", TypeId::BOOLEAN}); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
202 |
metadata.push_back({L"type", TypeId::STRING}); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
203 |
writer->startRelation(L"port", metadata, true); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
204 |
|
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
205 |
const char** portNames = jack_get_ports(realTimeContext.jackClient, nullptr, nullptr, 0); |
13
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
206 |
|
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
207 |
std::regex midiTypePattern(".*midi$"); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
208 |
|
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
209 |
for (const char** portName = portNames; *portName; portName++) { |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
210 |
jack_port_t* port = jack_port_by_name(realTimeContext.jackClient, *portName); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
211 |
|
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
212 |
const char* portType = jack_port_type(port); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
213 |
int portFlags = jack_port_flags(port); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
214 |
|
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
215 |
bool isInput = portFlags & JackPortFlags::JackPortIsInput; |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
216 |
bool isOuputput = portFlags & JackPortFlags::JackPortIsOutput; |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
217 |
bool isPhysical = portFlags & JackPortFlags::JackPortIsPhysical; |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
218 |
bool isTerminal = portFlags & JackPortFlags::JackPortIsTerminal; |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
219 |
bool isMine = jack_port_is_mine(realTimeContext.jackClient, port); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
220 |
bool isMidi = std::regex_search(portType, midiTypePattern); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
221 |
|
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
222 |
writer->writeAttribute(convertor.from_bytes(*portName)); |
15
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
223 |
writer->writeAttribute(convertor.from_bytes(uuidToString(jack_port_uuid(port)))); |
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
224 |
writer->writeAttribute(&isInput, typeid (isInput)); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
225 |
writer->writeAttribute(&isOuputput, typeid (isOuputput)); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
226 |
writer->writeAttribute(&isPhysical, typeid (isPhysical)); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
227 |
writer->writeAttribute(&isTerminal, typeid (isTerminal)); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
228 |
writer->writeAttribute(&isMine, typeid (isMine)); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
229 |
writer->writeAttribute(&isMidi, typeid (isMidi)); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
230 |
writer->writeAttribute(convertor.from_bytes(portType)); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
231 |
} |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
232 |
|
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
233 |
jack_free(portNames); |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
234 |
} |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
235 |
|
13
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
236 |
void listConnections(std::shared_ptr<relpipe::writer::RelationalWriter> writer) { |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
237 |
using namespace relpipe::writer; |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
238 |
vector<AttributeMetadata> metadata; |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
239 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
240 |
metadata.push_back({L"event", TypeId::STRING}); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
241 |
metadata.push_back({L"source_port", TypeId::STRING}); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
242 |
metadata.push_back({L"destination_port", TypeId::STRING}); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
243 |
writer->startRelation(L"connection", metadata, true); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
244 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
245 |
const relpipe::common::type::StringX event = L"connect"; |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
246 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
247 |
const char** sourcePortNames = jack_get_ports(realTimeContext.jackClient, nullptr, nullptr, JackPortFlags::JackPortIsOutput); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
248 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
249 |
for (const char** sourcePortName = sourcePortNames; *sourcePortName; sourcePortName++) { |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
250 |
jack_port_t* sourcePort = jack_port_by_name(realTimeContext.jackClient, *sourcePortName); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
251 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
252 |
const char** destinationPortNames = jack_port_get_all_connections(realTimeContext.jackClient, sourcePort); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
253 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
254 |
for (const char** destinationPortName = destinationPortNames; destinationPortNames && *destinationPortName; destinationPortName++) { |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
255 |
writer->writeAttribute(event); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
256 |
writer->writeAttribute(convertor.from_bytes(*sourcePortName)); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
257 |
writer->writeAttribute(convertor.from_bytes(*destinationPortName)); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
258 |
} |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
259 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
260 |
jack_free(destinationPortNames); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
261 |
} |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
262 |
|
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
263 |
jack_free(sourcePortNames); |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
264 |
} |
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
265 |
|
15
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
266 |
std::string uuidToString(jack_uuid_t uuid) { |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
267 |
char buffer[JACK_UUID_STRING_SIZE] = {0}; |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
268 |
jack_uuid_unparse(uuid, buffer); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
269 |
return buffer; |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
270 |
} |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
271 |
|
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
272 |
void listProperties(std::shared_ptr<relpipe::writer::RelationalWriter> writer) { |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
273 |
using namespace relpipe::writer; |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
274 |
vector<AttributeMetadata> metadata; |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
275 |
|
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
276 |
metadata.push_back({L"uuid", TypeId::STRING}); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
277 |
//metadata.push_back({L"port", TypeId::STRING}); // TODO: port name |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
278 |
metadata.push_back({L"name", TypeId::STRING}); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
279 |
metadata.push_back({L"type", TypeId::STRING}); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
280 |
metadata.push_back({L"value", TypeId::STRING}); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
281 |
writer->startRelation(L"property", metadata, true); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
282 |
|
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
283 |
jack_description_t* descriptions = nullptr; |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
284 |
|
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
285 |
int descriptionsCount = jack_get_all_properties(&descriptions); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
286 |
|
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
287 |
for (int i = 0; i < descriptionsCount; i++) { |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
288 |
jack_description_t* description = &descriptions[i]; |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
289 |
for (uint32_t j = 0; j < description->property_cnt; j++) { |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
290 |
jack_property_t* property = &description->properties[j]; |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
291 |
writer->writeAttribute(convertor.from_bytes(uuidToString(description->subject))); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
292 |
//writer->writeAttribute(L"TODO: port name"); // TODO: port name |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
293 |
writer->writeAttribute(convertor.from_bytes(property->key)); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
294 |
writer->writeAttribute(convertor.from_bytes(property->type)); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
295 |
writer->writeAttribute(convertor.from_bytes(property->data)); // TODO: format value (some in HEX), according to .type |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
296 |
} |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
297 |
jack_free_description(description, false); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
298 |
} |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
299 |
jack_free(descriptions); |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
300 |
} |
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
301 |
|
14
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
302 |
void applyConnectionRecipes() { |
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
303 |
for (Configuration::ConnectionRecipe recipe : configuration.connectionRecipes) { |
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
304 |
auto operation = recipe.connected ? jack_connect : jack_disconnect; |
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
305 |
int result = operation(realTimeContext.jackClient, convertor.to_bytes(recipe.sourcePort).c_str(), convertor.to_bytes(recipe.destinationPort).c_str()); |
16
79520ded76f0
fix bash-completion (uuid) + connect/disconnect error message (to/from)
František Kučera <franta-hg@frantovo.cz>
parents:
15
diff
changeset
|
306 |
if (result != 0 && result != EEXIST) std::wcerr << L"Unable to " << (recipe.connected ? L"connect" : L"disconnect") << L": „" << recipe.sourcePort << (recipe.connected ? L"“ to: „" : L"“ from: „") << recipe.destinationPort << L"“." << std::endl; |
14
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
307 |
} |
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
308 |
} |
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
309 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
310 |
static void jackErrorCallback(const char * message) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
311 |
std::wstring_convert < std::codecvt_utf8<wchar_t>> convertor; // TODO: local system encoding |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
312 |
std::wcerr << L"JACK: " << convertor.from_bytes(message) << std::endl; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
313 |
} |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
314 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
315 |
void finalize() { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
316 |
// Close JACK connection: |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
317 |
jack_deactivate(realTimeContext.jackClient); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
318 |
jack_client_close(realTimeContext.jackClient); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
319 |
jack_ringbuffer_free(realTimeContext.ringBuffer); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
320 |
pthread_mutex_unlock(&realTimeContext.processingLock); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
321 |
} |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
322 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
323 |
void failInConstructor(const relpipe::common::type::StringX& errorMessage) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
324 |
finalize(); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
325 |
throw JackException(errorMessage); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
326 |
} |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
327 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
328 |
/** |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
329 |
* Wait for the signal that is emitted at the end of the real-time processCallback() cycle. |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
330 |
*/ |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
331 |
void waitForRTCycle() { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
332 |
pthread_cond_wait(&realTimeContext.processingDone, &realTimeContext.processingLock); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
333 |
} |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
334 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
335 |
public: |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
336 |
|
8
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
337 |
JackCommand(Configuration& configuration) : configuration(configuration) { |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
338 |
pthread_mutex_lock(&realTimeContext.processingLock); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
339 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
340 |
// Initialize JACK connection: |
12
e8aae4d42c01
simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
341 |
std::string clientName = convertor.to_bytes(configuration.client); |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
342 |
realTimeContext.jackClient = jack_client_open(clientName.c_str(), JackNullOption, nullptr); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
343 |
if (realTimeContext.jackClient == nullptr) failInConstructor(L"Could not create JACK client."); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
344 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
345 |
realTimeContext.ringBuffer = jack_ringbuffer_create(realTimeContext.RING_BUFFER_SIZE * sizeof (MidiMessage)); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
346 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
347 |
jack_set_process_callback(realTimeContext.jackClient, RealTimeContext::processCallback, &realTimeContext); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
348 |
// TODO: report also other events (connections etc.) |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
349 |
jack_set_error_function(jackErrorCallback); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
350 |
jack_set_info_function(jackErrorCallback); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
351 |
|
12
e8aae4d42c01
simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
352 |
realTimeContext.jackPort = jack_port_register(realTimeContext.jackClient, convertor.to_bytes(configuration.port).c_str(), JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0); |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
353 |
if (realTimeContext.jackPort == nullptr) failInConstructor(L"Could not register the JACK port."); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
354 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
355 |
if (mlockall(MCL_CURRENT | MCL_FUTURE)) fwprintf(stderr, L"Warning: Can not lock memory.\n"); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
356 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
357 |
int jackError = jack_activate(realTimeContext.jackClient); |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
358 |
if (jackError) failInConstructor(L"Could not activate the JACK client."); |
10
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
359 |
|
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
360 |
|
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
361 |
// Connect to configured destination ports: |
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
362 |
const char* jackPortName = jack_port_name(realTimeContext.jackPort); |
12
e8aae4d42c01
simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
363 |
for (auto sourcePort : configuration.connectTo) { |
10
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
364 |
int error = jack_connect(realTimeContext.jackClient, convertor.to_bytes(sourcePort).c_str(), jackPortName); |
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
365 |
if (error) failInConstructor(L"Connection to the JACK port failed: " + sourcePort); |
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
366 |
} |
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
367 |
|
8
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
368 |
} |
8ef1980db907
configurable JACK client name
František Kučera <franta-hg@frantovo.cz>
parents:
6
diff
changeset
|
369 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
370 |
void processJackStream(std::shared_ptr<relpipe::writer::RelationalWriter> writer, std::function<void() > relationalWriterFlush) { |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
371 |
// Relation headers: |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
372 |
using namespace relpipe::writer; |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
373 |
vector<AttributeMetadata> metadata; |
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
374 |
|
14
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
375 |
applyConnectionRecipes(); |
cde9bb07ea0a
add options --connect-ports and --disconnect-ports to allow connecting and disconnecting arbitrary JACK ports
František Kučera <franta-hg@frantovo.cz>
parents:
13
diff
changeset
|
376 |
|
12
e8aae4d42c01
simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
377 |
if (configuration.listPorts) listPorts(writer); |
13
326935d1bfab
add option --list-connections for listing JACK connections
František Kučera <franta-hg@frantovo.cz>
parents:
12
diff
changeset
|
378 |
if (configuration.listConnections) listConnections(writer); |
15
463ce61415f1
partial support for metadata: --list-properties
František Kučera <franta-hg@frantovo.cz>
parents:
14
diff
changeset
|
379 |
if (configuration.listProperties) listProperties(writer); |
11
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
380 |
if (!configuration.listMidiMessages) return; |
07247893054e
add options --list-jack-ports and --list-midi-messages useful for bash-completion
František Kučera <franta-hg@frantovo.cz>
parents:
10
diff
changeset
|
381 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
382 |
metadata.push_back({L"event", TypeId::STRING}); |
17
4e6b33312c5a
timing (first version)
František Kučera <franta-hg@frantovo.cz>
parents:
16
diff
changeset
|
383 |
metadata.push_back({L"time", TypeId::INTEGER}); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
384 |
metadata.push_back({L"channel", TypeId::INTEGER}); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
385 |
metadata.push_back({L"note_on", TypeId::BOOLEAN}); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
386 |
metadata.push_back({L"note_pitch", TypeId::INTEGER}); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
387 |
metadata.push_back({L"note_velocity", TypeId::INTEGER}); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
388 |
metadata.push_back({L"controller_id", TypeId::INTEGER}); |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
389 |
metadata.push_back({L"controller_value", TypeId::INTEGER}); |
4
30da4232cdbc
add raw MIDI data in HEX
František Kučera <franta-hg@frantovo.cz>
parents:
3
diff
changeset
|
390 |
metadata.push_back({L"raw", TypeId::STRING}); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
391 |
writer->startRelation(L"midi", metadata, true); |
2
e5f0d3f92eb4
pass RelationalWriter instead of std::ostream to the JackCommand
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
392 |
relationalWriterFlush(); |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
393 |
|
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
394 |
// Process messages from the ring buffer queue: |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
395 |
while (continueProcessing) { |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
396 |
while (jack_ringbuffer_read_space(realTimeContext.ringBuffer) >= sizeof (MidiMessage)) { |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
397 |
MidiMessage m; |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
398 |
jack_ringbuffer_read(realTimeContext.ringBuffer, (char*) &m, sizeof (MidiMessage)); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
399 |
processMessage(writer, &m); |
2
e5f0d3f92eb4
pass RelationalWriter instead of std::ostream to the JackCommand
František Kučera <franta-hg@frantovo.cz>
parents:
1
diff
changeset
|
400 |
relationalWriterFlush(); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
401 |
} |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
402 |
waitForRTCycle(); |
10
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
403 |
|
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
404 |
// Once the Configuration::requiredJackConnections count was reached, we will disconnect if the count drops under this level. |
12
e8aae4d42c01
simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
405 |
if (configuration.requiredConnections) { |
10
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
406 |
int currentConnectionCount = jack_port_connected(realTimeContext.jackPort); |
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
407 |
if (currentConnectionCount > maxJackPortConnections) maxJackPortConnections = currentConnectionCount; |
12
e8aae4d42c01
simplify CLI options: --client --connect-to --required-connections --list-ports + add --port
František Kučera <franta-hg@frantovo.cz>
parents:
11
diff
changeset
|
408 |
else if (maxJackPortConnections >= configuration.requiredConnections && currentConnectionCount < configuration.requiredConnections) break; |
10
ded44e94147c
add --jack-connect-to-port and --required-jack-connections options
František Kučera <franta-hg@frantovo.cz>
parents:
9
diff
changeset
|
409 |
} |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
410 |
} |
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
411 |
} |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
412 |
|
9
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
413 |
void finish(int sig) { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
414 |
continueProcessing = false; |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
415 |
} |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
416 |
|
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
417 |
virtual ~JackCommand() { |
0d362165241e
refactoring, syncrhonize code structure with JackHandler.cpp (relpipe-out-jack)
František Kučera <franta-hg@frantovo.cz>
parents:
8
diff
changeset
|
418 |
finalize(); |
1
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
419 |
} |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
420 |
|
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
421 |
}; |
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
422 |
|
001b956610ca
separate JackCommand class
František Kučera <franta-hg@frantovo.cz>
parents:
0
diff
changeset
|
423 |
} |
0
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
424 |
} |
c8c8ec34120f
first dirty version, writes MIDI events from JACK
František Kučera <franta-hg@frantovo.cz>
parents:
diff
changeset
|
425 |
} |