21 #include <vector> |
21 #include <vector> |
22 #include <iostream> |
22 #include <iostream> |
23 #include <sstream> |
23 #include <sstream> |
24 #include <locale> |
24 #include <locale> |
25 #include <codecvt> |
25 #include <codecvt> |
|
26 #include <sys/mman.h> |
|
27 |
|
28 #include <jack/jack.h> |
|
29 #include <jack/midiport.h> |
|
30 #include <jack/ringbuffer.h> |
26 |
31 |
27 #include <relpipe/common/type/typedefs.h> |
32 #include <relpipe/common/type/typedefs.h> |
28 #include <relpipe/reader/TypeId.h> |
33 #include <relpipe/reader/TypeId.h> |
29 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
34 #include <relpipe/reader/handlers/RelationalReaderStringHandler.h> |
30 #include <relpipe/reader/handlers/AttributeMetadata.h> |
35 #include <relpipe/reader/handlers/AttributeMetadata.h> |
38 |
43 |
39 class JackHandler : public relpipe::reader::handlers::RelationalReaderStringHandler { |
44 class JackHandler : public relpipe::reader::handlers::RelationalReaderStringHandler { |
40 private: |
45 private: |
41 Configuration& configuration; |
46 Configuration& configuration; |
42 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: local system encoding |
47 std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: local system encoding |
|
48 |
|
49 jack_client_t* jackClient = nullptr; |
|
50 jack_port_t* jackPort = nullptr; |
|
51 //jack_ringbuffer_t* ringBuffer = nullptr; |
43 public: |
52 public: |
44 |
53 |
45 JackHandler(Configuration& configuration) : configuration(configuration) { |
54 JackHandler(Configuration& configuration) : configuration(configuration) { |
|
55 // Initialize JACK connection: |
|
56 std::string clientName = "relpipe-out-jack"; |
|
57 jackClient = jack_client_open(clientName.c_str(), JackNullOption, nullptr); |
|
58 if (jackClient == nullptr) throw JackException(L"Could not create JACK client."); |
|
59 |
|
60 //ringBuffer = jack_ringbuffer_create(RING_BUFFER_SIZE * sizeof (MidiMessage)); |
|
61 |
|
62 //jack_set_process_callback(jackClient, relpipe::in::jack::enqueueMessage, this); |
|
63 // TODO: report also other events (connections etc.) |
|
64 |
|
65 jackPort = jack_port_register(jackClient, "output", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0); |
|
66 if (jackPort == nullptr) throw JackException(L"Could not register port."); |
|
67 |
|
68 if (mlockall(MCL_CURRENT | MCL_FUTURE)) fwprintf(stderr, L"Warning: Can not lock memory.\n"); |
|
69 |
|
70 int jackError = jack_activate(jackClient); |
|
71 if (jackError) throw JackException(L"Could not activate client."); |
46 } |
72 } |
47 |
73 |
48 void startRelation(const relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override { |
74 void startRelation(const relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override { |
49 |
75 |
50 } |
76 } |