@@ -14,14 +14,15 @@ NAMESPACE_LIBREMIDI
1414{
1515struct jack_client
1616{
17+ const libjack& jack = libjack::instance();
1718 jack_client_t * client{};
1819
19- static std::string get_port_display_name (jack_port_t * port)
20+ std::string get_port_display_name (jack_port_t * port) const
2021 {
21- auto p1 = std::make_unique<char []>(jack_port_name_size ());
22- auto p2 = std::make_unique<char []>(jack_port_name_size ());
22+ auto p1 = std::make_unique<char []>(jack. port . name_size ());
23+ auto p2 = std::make_unique<char []>(jack. port . name_size ());
2324 char * aliases[3 ] = {p1.get (), p2.get (), nullptr };
24- int n = jack_port_get_aliases (port, aliases);
25+ int n = jack. port . get_aliases (port, aliases);
2526 if (n > 1 )
2627 {
2728 return aliases[1 ];
@@ -35,39 +36,39 @@ struct jack_client
3536 }
3637 else
3738 {
38- const auto short_name = jack_port_short_name (port);
39+ const auto short_name = jack. port . short_name (port);
3940 if (short_name && strlen (short_name) > 0 )
4041 return short_name;
41- return jack_port_name (port);
42+ return jack. port . name (port);
4243 }
4344 }
4445
4546 template <bool Input, libremidi::API Api>
46- static auto to_port_info (jack_client_t * client, jack_port_t * port)
47+ auto to_port_info (jack_client_t * client, jack_port_t * port) const
4748 -> std::conditional_t<Input, input_port, output_port>
4849 {
4950 return {{
5051 .api = Api,
5152 .client = reinterpret_cast <std::uintptr_t >(client),
5253 .port = 0 ,
5354 .manufacturer = " " ,
54- .device_name = jack_get_client_name (client),
55- .port_name = jack_port_name (port),
55+ .device_name = jack. get_client_name (client),
56+ .port_name = jack. port . name (port),
5657 .display_name = get_port_display_name (port),
5758 }};
5859 }
5960
6061 template <bool Input, libremidi::API Api>
61- static auto get_ports (
62+ auto get_ports (
6263 jack_client_t * client, const char * pattern, const char * type, const JackPortFlags flags,
63- bool midi2) noexcept -> std::vector<std::conditional_t<Input, input_port, output_port>>
64+ bool midi2) const noexcept -> std::vector<std::conditional_t<Input, input_port, output_port>>
6465 {
6566 std::vector<std::conditional_t <Input, input_port, output_port>> ret;
6667
6768 if (!client)
6869 return {};
6970
70- const char ** ports = jack_get_ports (client, pattern, type, flags);
71+ const char ** ports = jack. get_ports (client, pattern, type, flags);
7172
7273 if (ports == nullptr )
7374 return {};
@@ -76,16 +77,16 @@ struct jack_client
7677 while (ports[i] != nullptr )
7778 {
7879 // FIXME this does not take into account filtering sw / hw ports
79- auto port = jack_port_by_name (client, ports[i]);
80+ auto port = jack. port . by_name (client, ports[i]);
8081 if (port)
8182 {
82- if (bool (midi2) == bool (jack_port_flags (port) & 0x20 ))
83+ if (bool (midi2) == bool (jack. port . flags (port) & 0x20 ))
8384 ret.push_back (to_port_info<Input, Api>(client, port));
8485 }
8586 i++;
8687 }
8788
88- jack_free (ports);
89+ jack. free (ports);
8990
9091 return ret;
9192 }
@@ -154,7 +155,7 @@ struct jack_helpers : jack_client
154155 {
155156 jack_status_t status{};
156157 this ->client
157- = jack_client_open (configuration.client_name .c_str (), JackNoStartServer, &status);
158+ = jack. client_open (configuration.client_name .c_str (), JackNoStartServer, &status);
158159 if (this ->client != nullptr )
159160 {
160161 if (status & JackNameNotUnique)
@@ -163,7 +164,7 @@ struct jack_helpers : jack_client
163164 self.configuration , " JACK client with the same name already exists, renamed." );
164165 }
165166
166- jack_set_process_callback (this ->client , +[](jack_nframes_t nf, void * ctx) -> int {
167+ jack. set_process_callback (this ->client , +[](jack_nframes_t nf, void * ctx) -> int {
167168 auto & self = *static_cast <Self*>(ctx);
168169 jack_port_t * port = self.port ;
169170
@@ -176,7 +177,7 @@ struct jack_helpers : jack_client
176177 self.thread_lock .check_client_released ();
177178 return 0 ;
178179 }, &self);
179- jack_activate (this ->client );
180+ jack. activate (this ->client );
180181 }
181182 return status;
182183 }
@@ -194,7 +195,7 @@ struct jack_helpers : jack_client
194195 }
195196
196197 if (this ->client && !self.configuration .context )
197- jack_client_close (this ->client );
198+ jack. client_close (this ->client );
198199
199200 self.client_open_ = std::errc::not_connected;
200201 }
@@ -207,15 +208,15 @@ struct jack_helpers : jack_client
207208 portName = flags & JackPortIsInput ? " i" : " o" ;
208209
209210 if (self.configuration .client_name .size () + portName.size () + 2u
210- >= static_cast <size_t >(jack_port_name_size ()))
211+ >= static_cast <size_t >(jack. port . name_size ()))
211212 {
212213 self.libremidi_handle_error (self.configuration , " port name length limit exceeded" );
213214 return std::errc::invalid_argument;
214215 }
215216
216217 if (!this ->port )
217218 {
218- this ->port = jack_port_register (this ->client , portName.data (), type, flags, 0 );
219+ this ->port = jack. port . register_port (this ->client , portName.data (), type, flags, 0 );
219220 }
220221
221222 if (!this ->port )
@@ -239,7 +240,7 @@ struct jack_helpers : jack_client
239240 this ->thread_lock .prepare_release_client ();
240241
241242 // 3. Now we are sure that the client is not going to use the port anymore
242- int err = jack_port_unregister (this ->client , port_ptr);
243+ int err = jack. port . unregister (this ->client , port_ptr);
243244 return from_errc (err);
244245 }
245246};
@@ -264,45 +265,46 @@ struct jack_queue
264265
265266 explicit jack_queue (int64_t sz) noexcept
266267 {
267- ringbuffer = jack_ringbuffer_create (sz);
268- ringbuffer_space = jack_ringbuffer_write_space (ringbuffer);
268+ ringbuffer = jack. ringbuffer . create (sz);
269+ ringbuffer_space = jack. ringbuffer . write_space (ringbuffer);
269270 }
270271
271272 ~jack_queue () noexcept
272273 {
273274 if (ringbuffer)
274- jack_ringbuffer_free (ringbuffer);
275+ jack. ringbuffer . free (ringbuffer);
275276 }
276277
277278 stdx::error write (const unsigned char * data, int64_t sz) const noexcept
278279 {
279280 if (static_cast <std::size_t >(sz + size_sz) > ringbuffer_space)
280281 return std::errc::no_buffer_space;
281282
282- while (jack_ringbuffer_write_space (ringbuffer) < sz + size_sz)
283+ while (jack. ringbuffer . write_space (ringbuffer) < sz + size_sz)
283284 std::this_thread::yield ();
284285
285- jack_ringbuffer_write (ringbuffer, reinterpret_cast <char *>(&sz), size_sz);
286- jack_ringbuffer_write (ringbuffer, reinterpret_cast <const char *>(data), sz);
286+ jack. ringbuffer . write (ringbuffer, reinterpret_cast <char *>(&sz), size_sz);
287+ jack. ringbuffer . write (ringbuffer, reinterpret_cast <const char *>(data), sz);
287288
288289 return stdx::error{};
289290 }
290291
291292 void read (void * jack_events) const noexcept
292293 {
293294 int32_t sz;
294- while (jack_ringbuffer_peek (ringbuffer, reinterpret_cast <char *>(&sz), size_sz) == size_sz
295- && jack_ringbuffer_read_space (ringbuffer) >= size_sz + sz)
295+ while (jack. ringbuffer . peek (ringbuffer, reinterpret_cast <char *>(&sz), size_sz) == size_sz
296+ && jack. ringbuffer . read_space (ringbuffer) >= size_sz + sz)
296297 {
297- jack_ringbuffer_read_advance (ringbuffer, size_sz);
298+ jack. ringbuffer . read_advance (ringbuffer, size_sz);
298299
299- if (auto midi = jack_midi_event_reserve (jack_events, 0 , sz))
300- jack_ringbuffer_read (ringbuffer, reinterpret_cast <char *>(midi), sz);
300+ if (auto midi = jack. midi . event_reserve (jack_events, 0 , sz))
301+ jack. ringbuffer . read (ringbuffer, reinterpret_cast <char *>(midi), sz);
301302 else
302- jack_ringbuffer_read_advance (ringbuffer, sz);
303+ jack. ringbuffer . read_advance (ringbuffer, sz);
303304 }
304305 }
305306
307+ const libjack& jack = libjack::instance();
306308 jack_ringbuffer_t * ringbuffer{};
307309 std::size_t ringbuffer_space{}; // actual writable size, usually 1 less than ringbuffer
308310};
0 commit comments