jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2131 lines
72KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. */
  16. #include "JackClient.h"
  17. #include "JackError.h"
  18. #include "JackGraphManager.h"
  19. #include "JackEngineControl.h"
  20. #include "JackClientControl.h"
  21. #include "JackGlobals.h"
  22. #include "JackTime.h"
  23. #include "JackPortType.h"
  24. #include <math.h>
  25. #ifdef __CLIENTDEBUG__
  26. #include "JackLibGlobals.h"
  27. #endif
  28. using namespace Jack;
  29. #ifdef __cplusplus
  30. extern "C"
  31. {
  32. #endif
  33. typedef void (*print_function)(const char*);
  34. typedef void *(*thread_routine)(void*);
  35. LIB_EXPORT
  36. void
  37. jack_get_version(
  38. int *major_ptr,
  39. int *minor_ptr,
  40. int *micro_ptr,
  41. int *proto_ptr);
  42. LIB_EXPORT
  43. const char*
  44. jack_get_version_string();
  45. jack_client_t * jack_client_new_aux(const char* client_name,
  46. jack_options_t options,
  47. jack_status_t *status);
  48. LIB_EXPORT jack_client_t * jack_client_open(const char* client_name,
  49. jack_options_t options,
  50. jack_status_t *status, ...);
  51. LIB_EXPORT jack_client_t * jack_client_new(const char* client_name);
  52. LIB_EXPORT int jack_client_name_size(void);
  53. LIB_EXPORT char* jack_get_client_name(jack_client_t *client);
  54. LIB_EXPORT int jack_internal_client_new(const char* client_name,
  55. const char* load_name,
  56. const char* load_init);
  57. LIB_EXPORT void jack_internal_client_close(const char* client_name);
  58. LIB_EXPORT int jack_is_realtime(jack_client_t *client);
  59. LIB_EXPORT void jack_on_shutdown(jack_client_t *client,
  60. JackShutdownCallback shutdown_callback, void *arg);
  61. LIB_EXPORT void jack_on_info_shutdown(jack_client_t *client,
  62. JackInfoShutdownCallback shutdown_callback, void *arg);
  63. LIB_EXPORT int jack_set_process_callback(jack_client_t *client,
  64. JackProcessCallback process_callback,
  65. void *arg);
  66. LIB_EXPORT jack_nframes_t jack_thread_wait(jack_client_t *client, int status);
  67. // new
  68. LIB_EXPORT jack_nframes_t jack_cycle_wait(jack_client_t*);
  69. LIB_EXPORT void jack_cycle_signal(jack_client_t*, int status);
  70. LIB_EXPORT int jack_set_process_thread(jack_client_t* client, JackThreadCallback fun, void *arg);
  71. LIB_EXPORT int jack_set_thread_init_callback(jack_client_t *client,
  72. JackThreadInitCallback thread_init_callback,
  73. void *arg);
  74. LIB_EXPORT int jack_set_freewheel_callback(jack_client_t *client,
  75. JackFreewheelCallback freewheel_callback,
  76. void *arg);
  77. LIB_EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
  78. LIB_EXPORT int jack_set_buffer_size(jack_client_t *client, jack_nframes_t nframes);
  79. LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t *client,
  80. JackBufferSizeCallback bufsize_callback,
  81. void *arg);
  82. LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t *client,
  83. JackSampleRateCallback srate_callback,
  84. void *arg);
  85. LIB_EXPORT int jack_set_client_registration_callback(jack_client_t *,
  86. JackClientRegistrationCallback
  87. registration_callback, void *arg);
  88. LIB_EXPORT int jack_set_port_registration_callback(jack_client_t *,
  89. JackPortRegistrationCallback
  90. registration_callback, void *arg);
  91. LIB_EXPORT int jack_set_port_connect_callback(jack_client_t *,
  92. JackPortConnectCallback
  93. connect_callback, void *arg);
  94. LIB_EXPORT int jack_set_port_rename_callback(jack_client_t *,
  95. JackPortRenameCallback
  96. rename_callback, void *arg);
  97. LIB_EXPORT int jack_set_graph_order_callback(jack_client_t *,
  98. JackGraphOrderCallback graph_callback,
  99. void *);
  100. LIB_EXPORT int jack_set_xrun_callback(jack_client_t *,
  101. JackXRunCallback xrun_callback, void *arg);
  102. LIB_EXPORT int jack_set_latency_callback(jack_client_t *client,
  103. JackLatencyCallback latency_callback, void *arg);
  104. LIB_EXPORT int jack_activate(jack_client_t *client);
  105. LIB_EXPORT int jack_deactivate(jack_client_t *client);
  106. LIB_EXPORT jack_port_t * jack_port_register(jack_client_t *client,
  107. const char* port_name,
  108. const char* port_type,
  109. unsigned long flags,
  110. unsigned long buffer_size);
  111. LIB_EXPORT int jack_port_unregister(jack_client_t *, jack_port_t *);
  112. LIB_EXPORT void * jack_port_get_buffer(jack_port_t *, jack_nframes_t);
  113. LIB_EXPORT const char* jack_port_name(const jack_port_t *port);
  114. LIB_EXPORT const char* jack_port_short_name(const jack_port_t *port);
  115. LIB_EXPORT int jack_port_flags(const jack_port_t *port);
  116. LIB_EXPORT const char* jack_port_type(const jack_port_t *port);
  117. LIB_EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port);
  118. LIB_EXPORT int jack_port_is_mine(const jack_client_t *, const jack_port_t *port);
  119. LIB_EXPORT int jack_port_connected(const jack_port_t *port);
  120. LIB_EXPORT int jack_port_connected_to(const jack_port_t *port,
  121. const char* port_name);
  122. LIB_EXPORT const char* * jack_port_get_connections(const jack_port_t *port);
  123. LIB_EXPORT const char* * jack_port_get_all_connections(const jack_client_t *client,
  124. const jack_port_t *port);
  125. LIB_EXPORT int jack_port_tie(jack_port_t *src, jack_port_t *dst);
  126. LIB_EXPORT int jack_port_untie(jack_port_t *port);
  127. // Old latency API
  128. LIB_EXPORT jack_nframes_t jack_port_get_latency(jack_port_t *port);
  129. LIB_EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t *,
  130. jack_port_t *port);
  131. LIB_EXPORT void jack_port_set_latency(jack_port_t *, jack_nframes_t);
  132. LIB_EXPORT int jack_recompute_total_latency(jack_client_t*, jack_port_t* port);
  133. // New latency API
  134. LIB_EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range);
  135. LIB_EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range);
  136. LIB_EXPORT int jack_recompute_total_latencies(jack_client_t*);
  137. LIB_EXPORT int jack_port_set_name(jack_port_t *port, const char* port_name);
  138. LIB_EXPORT int jack_port_set_alias(jack_port_t *port, const char* alias);
  139. LIB_EXPORT int jack_port_unset_alias(jack_port_t *port, const char* alias);
  140. LIB_EXPORT int jack_port_get_aliases(const jack_port_t *port, char* const aliases[2]);
  141. LIB_EXPORT int jack_port_request_monitor(jack_port_t *port, int onoff);
  142. LIB_EXPORT int jack_port_request_monitor_by_name(jack_client_t *client,
  143. const char* port_name, int onoff);
  144. LIB_EXPORT int jack_port_ensure_monitor(jack_port_t *port, int onoff);
  145. LIB_EXPORT int jack_port_monitoring_input(jack_port_t *port);
  146. LIB_EXPORT int jack_connect(jack_client_t *,
  147. const char* source_port,
  148. const char* destination_port);
  149. LIB_EXPORT int jack_disconnect(jack_client_t *,
  150. const char* source_port,
  151. const char* destination_port);
  152. LIB_EXPORT int jack_port_disconnect(jack_client_t *, jack_port_t *);
  153. LIB_EXPORT int jack_port_name_size(void);
  154. LIB_EXPORT int jack_port_type_size(void);
  155. LIB_EXPORT size_t jack_port_type_get_buffer_size(jack_client_t *client, const char* port_type);
  156. LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t *);
  157. LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t *);
  158. LIB_EXPORT const char* * jack_get_ports(jack_client_t *,
  159. const char* port_name_pattern,
  160. const char* type_name_pattern,
  161. unsigned long flags);
  162. LIB_EXPORT jack_port_t * jack_port_by_name(jack_client_t *, const char* port_name);
  163. LIB_EXPORT jack_port_t * jack_port_by_id(jack_client_t *client,
  164. jack_port_id_t port_id);
  165. LIB_EXPORT int jack_engine_takeover_timebase(jack_client_t *);
  166. LIB_EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t *);
  167. LIB_EXPORT jack_time_t jack_get_time();
  168. LIB_EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time);
  169. LIB_EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
  170. LIB_EXPORT jack_nframes_t jack_frame_time(const jack_client_t *);
  171. LIB_EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t *client);
  172. LIB_EXPORT float jack_cpu_load(jack_client_t *client);
  173. LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t *);
  174. LIB_EXPORT void jack_set_error_function(print_function);
  175. LIB_EXPORT void jack_set_info_function(print_function);
  176. LIB_EXPORT float jack_get_max_delayed_usecs(jack_client_t *client);
  177. LIB_EXPORT float jack_get_xrun_delayed_usecs(jack_client_t *client);
  178. LIB_EXPORT void jack_reset_max_delayed_usecs(jack_client_t *client);
  179. LIB_EXPORT int jack_release_timebase(jack_client_t *client);
  180. LIB_EXPORT int jack_set_sync_callback(jack_client_t *client,
  181. JackSyncCallback sync_callback,
  182. void *arg);
  183. LIB_EXPORT int jack_set_sync_timeout(jack_client_t *client,
  184. jack_time_t timeout);
  185. LIB_EXPORT int jack_set_timebase_callback(jack_client_t *client,
  186. int conditional,
  187. JackTimebaseCallback timebase_callback,
  188. void *arg);
  189. LIB_EXPORT int jack_transport_locate(jack_client_t *client,
  190. jack_nframes_t frame);
  191. LIB_EXPORT jack_transport_state_t jack_transport_query(const jack_client_t *client,
  192. jack_position_t *pos);
  193. LIB_EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t *client);
  194. LIB_EXPORT int jack_transport_reposition(jack_client_t *client,
  195. const jack_position_t *pos);
  196. LIB_EXPORT void jack_transport_start(jack_client_t *client);
  197. LIB_EXPORT void jack_transport_stop(jack_client_t *client);
  198. LIB_EXPORT void jack_get_transport_info(jack_client_t *client,
  199. jack_transport_info_t *tinfo);
  200. LIB_EXPORT void jack_set_transport_info(jack_client_t *client,
  201. jack_transport_info_t *tinfo);
  202. LIB_EXPORT int jack_client_real_time_priority(jack_client_t*);
  203. LIB_EXPORT int jack_client_max_real_time_priority(jack_client_t*);
  204. LIB_EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority);
  205. LIB_EXPORT int jack_client_create_thread(jack_client_t* client,
  206. jack_native_thread_t *thread,
  207. int priority,
  208. int realtime, // boolean
  209. thread_routine routine,
  210. void *arg);
  211. LIB_EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread);
  212. LIB_EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread);
  213. LIB_EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread);
  214. #ifndef WIN32
  215. LIB_EXPORT void jack_set_thread_creator(jack_thread_creator_t jtc);
  216. #endif
  217. LIB_EXPORT char * jack_get_internal_client_name(jack_client_t *client,
  218. jack_intclient_t intclient);
  219. LIB_EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t *client,
  220. const char* client_name,
  221. jack_status_t *status);
  222. LIB_EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client,
  223. const char* client_name,
  224. jack_options_t options,
  225. jack_status_t *status, ...);
  226. LIB_EXPORT jack_intclient_t jack_internal_client_load_aux(jack_client_t *client,
  227. const char* client_name,
  228. jack_options_t options,
  229. jack_status_t *status, va_list ap);
  230. LIB_EXPORT jack_status_t jack_internal_client_unload(jack_client_t *client,
  231. jack_intclient_t intclient);
  232. LIB_EXPORT void jack_free(void* ptr);
  233. LIB_EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg);
  234. LIB_EXPORT jack_session_command_t *jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path);
  235. LIB_EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event);
  236. LIB_EXPORT void jack_session_event_free(jack_session_event_t* ev);
  237. LIB_EXPORT char* jack_client_get_uuid (jack_client_t *client);
  238. LIB_EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name);
  239. LIB_EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid);
  240. LIB_EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* name, const char* uuid);
  241. LIB_EXPORT void jack_session_commands_free(jack_session_command_t *cmds);
  242. LIB_EXPORT int jack_client_has_session_callback(jack_client_t *client, const char* client_name);
  243. #ifdef __cplusplus
  244. }
  245. #endif
  246. static inline bool CheckPort(jack_port_id_t port_index)
  247. {
  248. return (port_index > 0 && port_index < PORT_NUM_MAX);
  249. }
  250. static inline bool CheckBufferSize(jack_nframes_t buffer_size)
  251. {
  252. return (buffer_size >= 1 && buffer_size <= BUFFER_SIZE_MAX);
  253. }
  254. static inline void WaitGraphChange()
  255. {
  256. /*
  257. TLS key that is set only in RT thread, so never waits for pending
  258. graph change in RT context (just read the current graph state).
  259. */
  260. if (jack_tls_get(JackGlobals::fRealTime) == NULL) {
  261. JackGraphManager* manager = GetGraphManager();
  262. JackEngineControl* control = GetEngineControl();
  263. assert(manager);
  264. assert(control);
  265. if (manager->IsPendingChange()) {
  266. jack_log("WaitGraphChange...");
  267. JackSleep(int(control->fPeriodUsecs * 1.1f));
  268. }
  269. }
  270. }
  271. LIB_EXPORT void jack_set_error_function(print_function func)
  272. {
  273. jack_error_callback = (func == NULL) ? &default_jack_error_callback : func;
  274. }
  275. LIB_EXPORT void jack_set_info_function(print_function func)
  276. {
  277. jack_info_callback = (func == NULL) ? &default_jack_info_callback : func;
  278. }
  279. LIB_EXPORT jack_client_t* jack_client_new(const char* client_name)
  280. {
  281. #ifdef __CLIENTDEBUG__
  282. JackGlobals::CheckContext("jack_client_new");
  283. #endif
  284. try {
  285. assert(JackGlobals::fOpenMutex);
  286. JackGlobals::fOpenMutex->Lock();
  287. jack_error("jack_client_new: deprecated");
  288. int options = JackUseExactName;
  289. if (getenv("JACK_START_SERVER") == NULL)
  290. options |= JackNoStartServer;
  291. jack_client_t* res = jack_client_new_aux(client_name, (jack_options_t)options, NULL);
  292. JackGlobals::fOpenMutex->Unlock();
  293. return res;
  294. } catch (std::bad_alloc& e) {
  295. jack_error("Memory allocation error...");
  296. return NULL;
  297. } catch (...) {
  298. jack_error("Unknown error...");
  299. return NULL;
  300. }
  301. }
  302. LIB_EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
  303. {
  304. #ifdef __CLIENTDEBUG__
  305. JackGlobals::CheckContext("jack_port_get_buffer");
  306. #endif
  307. uintptr_t port_aux = (uintptr_t)port;
  308. jack_port_id_t myport = (jack_port_id_t)port_aux;
  309. if (!CheckPort(myport)) {
  310. jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
  311. return NULL;
  312. } else {
  313. JackGraphManager* manager = GetGraphManager();
  314. return (manager ? manager->GetBuffer(myport, frames) : NULL);
  315. }
  316. }
  317. LIB_EXPORT const char* jack_port_name(const jack_port_t* port)
  318. {
  319. #ifdef __CLIENTDEBUG__
  320. JackGlobals::CheckContext("jack_port_name");
  321. #endif
  322. uintptr_t port_aux = (uintptr_t)port;
  323. jack_port_id_t myport = (jack_port_id_t)port_aux;
  324. if (!CheckPort(myport)) {
  325. jack_error("jack_port_name called with an incorrect port %ld", myport);
  326. return NULL;
  327. } else {
  328. JackGraphManager* manager = GetGraphManager();
  329. return (manager ? manager->GetPort(myport)->GetName() : NULL);
  330. }
  331. }
  332. LIB_EXPORT const char* jack_port_short_name(const jack_port_t* port)
  333. {
  334. #ifdef __CLIENTDEBUG__
  335. JackGlobals::CheckContext("jack_port_short_name");
  336. #endif
  337. uintptr_t port_aux = (uintptr_t)port;
  338. jack_port_id_t myport = (jack_port_id_t)port_aux;
  339. if (!CheckPort(myport)) {
  340. jack_error("jack_port_short_name called with an incorrect port %ld", myport);
  341. return NULL;
  342. } else {
  343. JackGraphManager* manager = GetGraphManager();
  344. return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
  345. }
  346. }
  347. LIB_EXPORT int jack_port_flags(const jack_port_t* port)
  348. {
  349. #ifdef __CLIENTDEBUG__
  350. JackGlobals::CheckContext("jack_port_flags");
  351. #endif
  352. uintptr_t port_aux = (uintptr_t)port;
  353. jack_port_id_t myport = (jack_port_id_t)port_aux;
  354. if (!CheckPort(myport)) {
  355. jack_error("jack_port_flags called with an incorrect port %ld", myport);
  356. return -1;
  357. } else {
  358. JackGraphManager* manager = GetGraphManager();
  359. return (manager ? manager->GetPort(myport)->GetFlags() : -1);
  360. }
  361. }
  362. LIB_EXPORT const char* jack_port_type(const jack_port_t* port)
  363. {
  364. #ifdef __CLIENTDEBUG__
  365. JackGlobals::CheckContext("jack_port_type");
  366. #endif
  367. uintptr_t port_aux = (uintptr_t)port;
  368. jack_port_id_t myport = (jack_port_id_t)port_aux;
  369. if (!CheckPort(myport)) {
  370. jack_error("jack_port_flags called an incorrect port %ld", myport);
  371. return NULL;
  372. } else {
  373. JackGraphManager* manager = GetGraphManager();
  374. return (manager ? manager->GetPort(myport)->GetType() : NULL);
  375. }
  376. }
  377. LIB_EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
  378. {
  379. #ifdef __CLIENTDEBUG__
  380. JackGlobals::CheckContext("jack_port_type_id");
  381. #endif
  382. uintptr_t port_aux = (uintptr_t)port;
  383. jack_port_id_t myport = (jack_port_id_t)port_aux;
  384. if (!CheckPort(myport)) {
  385. jack_error("jack_port_type_id called an incorrect port %ld", myport);
  386. return 0;
  387. } else {
  388. JackGraphManager* manager = GetGraphManager();
  389. return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
  390. }
  391. }
  392. LIB_EXPORT int jack_port_connected(const jack_port_t* port)
  393. {
  394. #ifdef __CLIENTDEBUG__
  395. JackGlobals::CheckContext("jack_port_connected");
  396. #endif
  397. uintptr_t port_aux = (uintptr_t)port;
  398. jack_port_id_t myport = (jack_port_id_t)port_aux;
  399. if (!CheckPort(myport)) {
  400. jack_error("jack_port_connected called with an incorrect port %ld", myport);
  401. return -1;
  402. } else {
  403. WaitGraphChange();
  404. JackGraphManager* manager = GetGraphManager();
  405. return (manager ? manager->GetConnectionsNum(myport) : -1);
  406. }
  407. }
  408. LIB_EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
  409. {
  410. #ifdef __CLIENTDEBUG__
  411. JackGlobals::CheckContext("jack_port_connected_to");
  412. #endif
  413. uintptr_t port_aux = (uintptr_t)port;
  414. jack_port_id_t src = (jack_port_id_t)port_aux;
  415. if (!CheckPort(src)) {
  416. jack_error("jack_port_connected_to called with an incorrect port %ld", src);
  417. return -1;
  418. } else if (port_name == NULL) {
  419. jack_error("jack_port_connected_to called with a NULL port name");
  420. return -1;
  421. } else {
  422. WaitGraphChange();
  423. JackGraphManager* manager = GetGraphManager();
  424. jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
  425. if (dst == NO_PORT) {
  426. jack_error("Unknown destination port port_name = %s", port_name);
  427. return 0;
  428. } else {
  429. return manager->IsConnected(src, dst);
  430. }
  431. }
  432. }
  433. LIB_EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  434. {
  435. #ifdef __CLIENTDEBUG__
  436. JackGlobals::CheckContext("jack_port_tie");
  437. #endif
  438. uintptr_t src_aux = (uintptr_t)src;
  439. jack_port_id_t mysrc = (jack_port_id_t)src_aux;
  440. if (!CheckPort(mysrc)) {
  441. jack_error("jack_port_tie called with a NULL src port");
  442. return -1;
  443. }
  444. uintptr_t dst_aux = (uintptr_t)dst;
  445. jack_port_id_t mydst = (jack_port_id_t)dst_aux;
  446. if (!CheckPort(mydst)) {
  447. jack_error("jack_port_tie called with a NULL dst port");
  448. return -1;
  449. }
  450. JackGraphManager* manager = GetGraphManager();
  451. if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
  452. jack_error("jack_port_tie called with ports not belonging to the same client");
  453. return -1;
  454. } else {
  455. return manager->GetPort(mydst)->Tie(mysrc);
  456. }
  457. }
  458. LIB_EXPORT int jack_port_untie(jack_port_t* port)
  459. {
  460. #ifdef __CLIENTDEBUG__
  461. JackGlobals::CheckContext("jack_port_untie");
  462. #endif
  463. uintptr_t port_aux = (uintptr_t)port;
  464. jack_port_id_t myport = (jack_port_id_t)port_aux;
  465. if (!CheckPort(myport)) {
  466. jack_error("jack_port_untie called with an incorrect port %ld", myport);
  467. return -1;
  468. } else {
  469. JackGraphManager* manager = GetGraphManager();
  470. return (manager ? manager->GetPort(myport)->UnTie() : -1);
  471. }
  472. }
  473. LIB_EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  474. {
  475. #ifdef __CLIENTDEBUG__
  476. JackGlobals::CheckContext("jack_port_get_latency");
  477. #endif
  478. uintptr_t port_aux = (uintptr_t)port;
  479. jack_port_id_t myport = (jack_port_id_t)port_aux;
  480. if (!CheckPort(myport)) {
  481. jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
  482. return 0;
  483. } else {
  484. WaitGraphChange();
  485. JackGraphManager* manager = GetGraphManager();
  486. return (manager ? manager->GetPort(myport)->GetLatency() : 0);
  487. }
  488. }
  489. LIB_EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  490. {
  491. #ifdef __CLIENTDEBUG__
  492. JackGlobals::CheckContext("jack_port_set_latency");
  493. #endif
  494. uintptr_t port_aux = (uintptr_t)port;
  495. jack_port_id_t myport = (jack_port_id_t)port_aux;
  496. if (!CheckPort(myport)) {
  497. jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
  498. } else {
  499. JackGraphManager* manager = GetGraphManager();
  500. if (manager)
  501. manager->GetPort(myport)->SetLatency(frames);
  502. }
  503. }
  504. LIB_EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
  505. {
  506. #ifdef __CLIENTDEBUG__
  507. JackGlobals::CheckContext("jack_port_get_latency_range");
  508. #endif
  509. uintptr_t port_aux = (uintptr_t)port;
  510. jack_port_id_t myport = (jack_port_id_t)port_aux;
  511. if (!CheckPort(myport)) {
  512. jack_error("jack_port_get_latency_range called with an incorrect port %ld", myport);
  513. } else {
  514. WaitGraphChange();
  515. JackGraphManager* manager = GetGraphManager();
  516. if (manager)
  517. manager->GetPort(myport)->GetLatencyRange(mode, range);
  518. }
  519. }
  520. LIB_EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
  521. {
  522. #ifdef __CLIENTDEBUG__
  523. JackGlobals::CheckContext("jack_port_set_latency_range");
  524. #endif
  525. uintptr_t port_aux = (uintptr_t)port;
  526. jack_port_id_t myport = (jack_port_id_t)port_aux;
  527. if (!CheckPort(myport)) {
  528. jack_error("jack_port_set_latency_range called with an incorrect port %ld", myport);
  529. } else {
  530. WaitGraphChange();
  531. JackGraphManager* manager = GetGraphManager();
  532. if (manager)
  533. manager->GetPort(myport)->SetLatencyRange(mode, range);
  534. }
  535. }
  536. LIB_EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
  537. {
  538. #ifdef __CLIENTDEBUG__
  539. JackGlobals::CheckContext("jack_recompute_total_latency");
  540. #endif
  541. JackClient* client = (JackClient*)ext_client;
  542. uintptr_t port_aux = (uintptr_t)port;
  543. jack_port_id_t myport = (jack_port_id_t)port_aux;
  544. if (client == NULL) {
  545. jack_error("jack_recompute_total_latency called with a NULL client");
  546. return -1;
  547. } else if (!CheckPort(myport)) {
  548. jack_error("jack_recompute_total_latency called with a NULL port");
  549. return -1;
  550. } else {
  551. WaitGraphChange();
  552. JackGraphManager* manager = GetGraphManager();
  553. return (manager ? manager->ComputeTotalLatency(myport) : -1);
  554. }
  555. }
  556. LIB_EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  557. {
  558. #ifdef __CLIENTDEBUG__
  559. JackGlobals::CheckContext("jack_recompute_total_latencies");
  560. #endif
  561. JackClient* client = (JackClient*)ext_client;
  562. if (client == NULL) {
  563. jack_error("jack_recompute_total_latencies called with a NULL client");
  564. return -1;
  565. } else {
  566. return client->ComputeTotalLatencies();
  567. }
  568. }
  569. LIB_EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  570. {
  571. #ifdef __CLIENTDEBUG__
  572. JackGlobals::CheckContext("jack_port_set_name");
  573. #endif
  574. uintptr_t port_aux = (uintptr_t)port;
  575. jack_port_id_t myport = (jack_port_id_t)port_aux;
  576. if (!CheckPort(myport)) {
  577. jack_error("jack_port_set_name called with an incorrect port %ld", myport);
  578. return -1;
  579. } else if (name == NULL) {
  580. jack_error("jack_port_set_name called with a NULL port name");
  581. return -1;
  582. } else {
  583. JackClient* client = NULL;
  584. for (int i = 0; i < CLIENT_NUM; i++) {
  585. // Find a valid client
  586. if ((client = JackGlobals::fClientTable[i])) {
  587. break;
  588. }
  589. }
  590. return (client) ? client->PortRename(myport, name) : -1;
  591. }
  592. }
  593. LIB_EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
  594. {
  595. #ifdef __CLIENTDEBUG__
  596. JackGlobals::CheckContext("jack_port_set_alias");
  597. #endif
  598. uintptr_t port_aux = (uintptr_t)port;
  599. jack_port_id_t myport = (jack_port_id_t)port_aux;
  600. if (!CheckPort(myport)) {
  601. jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
  602. return -1;
  603. } else if (name == NULL) {
  604. jack_error("jack_port_set_alias called with a NULL port name");
  605. return -1;
  606. } else {
  607. JackGraphManager* manager = GetGraphManager();
  608. return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
  609. }
  610. }
  611. LIB_EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
  612. {
  613. #ifdef __CLIENTDEBUG__
  614. JackGlobals::CheckContext("jack_port_unset_alias");
  615. #endif
  616. uintptr_t port_aux = (uintptr_t)port;
  617. jack_port_id_t myport = (jack_port_id_t)port_aux;
  618. if (!CheckPort(myport)) {
  619. jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
  620. return -1;
  621. } else if (name == NULL) {
  622. jack_error("jack_port_unset_alias called with a NULL port name");
  623. return -1;
  624. } else {
  625. JackGraphManager* manager = GetGraphManager();
  626. return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
  627. }
  628. }
  629. LIB_EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  630. {
  631. #ifdef __CLIENTDEBUG__
  632. JackGlobals::CheckContext("jack_port_get_aliases");
  633. #endif
  634. uintptr_t port_aux = (uintptr_t)port;
  635. jack_port_id_t myport = (jack_port_id_t)port_aux;
  636. if (!CheckPort(myport)) {
  637. jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
  638. return -1;
  639. } else {
  640. JackGraphManager* manager = GetGraphManager();
  641. return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
  642. }
  643. }
  644. LIB_EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  645. {
  646. #ifdef __CLIENTDEBUG__
  647. JackGlobals::CheckContext("jack_port_request_monitor");
  648. #endif
  649. uintptr_t port_aux = (uintptr_t)port;
  650. jack_port_id_t myport = (jack_port_id_t)port_aux;
  651. if (!CheckPort(myport)) {
  652. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  653. return -1;
  654. } else {
  655. JackGraphManager* manager = GetGraphManager();
  656. return (manager ? manager->RequestMonitor(myport, onoff) : -1);
  657. }
  658. }
  659. LIB_EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  660. {
  661. #ifdef __CLIENTDEBUG__
  662. JackGlobals::CheckContext("jack_port_request_monitor_by_name");
  663. #endif
  664. JackClient* client = (JackClient*)ext_client;
  665. if (client == NULL) {
  666. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  667. return -1;
  668. } else {
  669. JackGraphManager* manager = GetGraphManager();
  670. if (!manager)
  671. return -1;
  672. jack_port_id_t myport = manager->GetPort(port_name);
  673. if (!CheckPort(myport)) {
  674. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  675. return -1;
  676. } else {
  677. return manager->RequestMonitor(myport, onoff);
  678. }
  679. }
  680. }
  681. LIB_EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  682. {
  683. #ifdef __CLIENTDEBUG__
  684. JackGlobals::CheckContext("jack_port_ensure_monitor");
  685. #endif
  686. uintptr_t port_aux = (uintptr_t)port;
  687. jack_port_id_t myport = (jack_port_id_t)port_aux;
  688. if (!CheckPort(myport)) {
  689. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  690. return -1;
  691. } else {
  692. JackGraphManager* manager = GetGraphManager();
  693. return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
  694. }
  695. }
  696. LIB_EXPORT int jack_port_monitoring_input(jack_port_t* port)
  697. {
  698. #ifdef __CLIENTDEBUG__
  699. JackGlobals::CheckContext("jack_port_monitoring_input");
  700. #endif
  701. uintptr_t port_aux = (uintptr_t)port;
  702. jack_port_id_t myport = (jack_port_id_t)port_aux;
  703. if (!CheckPort(myport)) {
  704. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  705. return -1;
  706. } else {
  707. JackGraphManager* manager = GetGraphManager();
  708. return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
  709. }
  710. }
  711. LIB_EXPORT int jack_is_realtime(jack_client_t* ext_client)
  712. {
  713. #ifdef __CLIENTDEBUG__
  714. JackGlobals::CheckContext("jack_is_realtime");
  715. #endif
  716. JackClient* client = (JackClient*)ext_client;
  717. if (client == NULL) {
  718. jack_error("jack_is_realtime called with a NULL client");
  719. return -1;
  720. } else {
  721. JackEngineControl* control = GetEngineControl();
  722. return (control ? control->fRealTime : -1);
  723. }
  724. }
  725. LIB_EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
  726. {
  727. #ifdef __CLIENTDEBUG__
  728. JackGlobals::CheckContext("jack_on_shutdown");
  729. #endif
  730. JackClient* client = (JackClient*)ext_client;
  731. if (client == NULL) {
  732. jack_error("jack_on_shutdown called with a NULL client");
  733. } else {
  734. client->OnShutdown(callback, arg);
  735. }
  736. }
  737. LIB_EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
  738. {
  739. #ifdef __CLIENTDEBUG__
  740. JackGlobals::CheckContext("jack_on_info_shutdown");
  741. #endif
  742. JackClient* client = (JackClient*)ext_client;
  743. if (client == NULL) {
  744. jack_error("jack_on_info_shutdown called with a NULL client");
  745. } else {
  746. client->OnInfoShutdown(callback, arg);
  747. }
  748. }
  749. LIB_EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  750. {
  751. #ifdef __CLIENTDEBUG__
  752. JackGlobals::CheckContext("jack_set_process_callback");
  753. #endif
  754. JackClient* client = (JackClient*)ext_client;
  755. if (client == NULL) {
  756. jack_error("jack_set_process_callback called with a NULL client");
  757. return -1;
  758. } else {
  759. return client->SetProcessCallback(callback, arg);
  760. }
  761. }
  762. LIB_EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
  763. {
  764. #ifdef __CLIENTDEBUG__
  765. JackGlobals::CheckContext("jack_thread_wait");
  766. #endif
  767. JackClient* client = (JackClient*)ext_client;
  768. if (client == NULL) {
  769. jack_error("jack_thread_wait called with a NULL client");
  770. return 0;
  771. } else {
  772. jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
  773. return 0;
  774. }
  775. }
  776. LIB_EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
  777. {
  778. #ifdef __CLIENTDEBUG__
  779. JackGlobals::CheckContext("jack_cycle_wait");
  780. #endif
  781. JackClient* client = (JackClient*)ext_client;
  782. if (client == NULL) {
  783. jack_error("jack_cycle_wait called with a NULL client");
  784. return 0;
  785. } else {
  786. return client->CycleWait();
  787. }
  788. }
  789. LIB_EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
  790. {
  791. #ifdef __CLIENTDEBUG__
  792. JackGlobals::CheckContext("jack_cycle_signal");
  793. #endif
  794. JackClient* client = (JackClient*)ext_client;
  795. if (client == NULL) {
  796. jack_error("jack_cycle_signal called with a NULL client");
  797. } else {
  798. client->CycleSignal(status);
  799. }
  800. }
  801. LIB_EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
  802. {
  803. #ifdef __CLIENTDEBUG__
  804. JackGlobals::CheckContext("jack_set_process_thread");
  805. #endif
  806. JackClient* client = (JackClient*)ext_client;
  807. if (client == NULL) {
  808. jack_error("jack_set_process_thread called with a NULL client");
  809. return -1;
  810. } else {
  811. return client->SetProcessThread(fun, arg);
  812. }
  813. }
  814. LIB_EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  815. {
  816. #ifdef __CLIENTDEBUG__
  817. JackGlobals::CheckContext("jack_set_freewheel_callback");
  818. #endif
  819. JackClient* client = (JackClient*)ext_client;
  820. if (client == NULL) {
  821. jack_error("jack_set_freewheel_callback called with a NULL client");
  822. return -1;
  823. } else {
  824. return client->SetFreewheelCallback(freewheel_callback, arg);
  825. }
  826. }
  827. LIB_EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  828. {
  829. #ifdef __CLIENTDEBUG__
  830. JackGlobals::CheckContext("jack_set_freewheel");
  831. #endif
  832. JackClient* client = (JackClient*)ext_client;
  833. if (client == NULL) {
  834. jack_error("jack_set_freewheel called with a NULL client");
  835. return -1;
  836. } else {
  837. return client->SetFreeWheel(onoff);
  838. }
  839. }
  840. LIB_EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  841. {
  842. #ifdef __CLIENTDEBUG__
  843. JackGlobals::CheckContext("jack_set_buffer_size");
  844. #endif
  845. JackClient* client = (JackClient*)ext_client;
  846. if (client == NULL) {
  847. jack_error("jack_set_buffer_size called with a NULL client");
  848. return -1;
  849. } else if (!CheckBufferSize(buffer_size)) {
  850. return -1;
  851. } else {
  852. return client->SetBufferSize(buffer_size);
  853. }
  854. }
  855. LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  856. {
  857. #ifdef __CLIENTDEBUG__
  858. JackGlobals::CheckContext("jack_set_buffer_size_callback");
  859. #endif
  860. JackClient* client = (JackClient*)ext_client;
  861. if (client == NULL) {
  862. jack_error("jack_set_buffer_size_callback called with a NULL client");
  863. return -1;
  864. } else {
  865. return client->SetBufferSizeCallback(bufsize_callback, arg);
  866. }
  867. }
  868. LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  869. {
  870. #ifdef __CLIENTDEBUG__
  871. JackGlobals::CheckContext("jack_set_sample_rate_callback");
  872. #endif
  873. JackClient* client = (JackClient*)ext_client;
  874. if (client == NULL) {
  875. jack_error("jack_set_sample_rate_callback called with a NULL client");
  876. return -1;
  877. } else {
  878. return client->SetSampleRateCallback(srate_callback, arg);
  879. }
  880. }
  881. LIB_EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  882. {
  883. #ifdef __CLIENTDEBUG__
  884. JackGlobals::CheckContext("jack_set_client_registration_callback");
  885. #endif
  886. JackClient* client = (JackClient*)ext_client;
  887. if (client == NULL) {
  888. jack_error("jack_set_client_registration_callback called with a NULL client");
  889. return -1;
  890. } else {
  891. return client->SetClientRegistrationCallback(registration_callback, arg);
  892. }
  893. }
  894. LIB_EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  895. {
  896. #ifdef __CLIENTDEBUG__
  897. JackGlobals::CheckContext("jack_set_port_registration_callback");
  898. #endif
  899. JackClient* client = (JackClient*)ext_client;
  900. if (client == NULL) {
  901. jack_error("jack_set_port_registration_callback called with a NULL client");
  902. return -1;
  903. } else {
  904. return client->SetPortRegistrationCallback(registration_callback, arg);
  905. }
  906. }
  907. LIB_EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
  908. {
  909. #ifdef __CLIENTDEBUG__
  910. JackGlobals::CheckContext("jack_set_port_connect_callback");
  911. #endif
  912. JackClient* client = (JackClient*)ext_client;
  913. if (client == NULL) {
  914. jack_error("jack_set_port_connect_callback called with a NULL client");
  915. return -1;
  916. } else {
  917. return client->SetPortConnectCallback(portconnect_callback, arg);
  918. }
  919. }
  920. LIB_EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
  921. {
  922. #ifdef __CLIENTDEBUG__
  923. JackGlobals::CheckContext("jack_set_port_rename_callback");
  924. #endif
  925. JackClient* client = (JackClient*)ext_client;
  926. if (client == NULL) {
  927. jack_error("jack_set_port_rename_callback called with a NULL client");
  928. return -1;
  929. } else {
  930. return client->SetPortRenameCallback(rename_callback, arg);
  931. }
  932. }
  933. LIB_EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  934. {
  935. #ifdef __CLIENTDEBUG__
  936. JackGlobals::CheckContext("jack_set_graph_order_callback");
  937. #endif
  938. JackClient* client = (JackClient*)ext_client;
  939. jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
  940. if (client == NULL) {
  941. jack_error("jack_set_graph_order_callback called with a NULL client");
  942. return -1;
  943. } else {
  944. return client->SetGraphOrderCallback(graph_callback, arg);
  945. }
  946. }
  947. LIB_EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  948. {
  949. #ifdef __CLIENTDEBUG__
  950. JackGlobals::CheckContext("jack_set_xrun_callback");
  951. #endif
  952. JackClient* client = (JackClient*)ext_client;
  953. if (client == NULL) {
  954. jack_error("jack_set_xrun_callback called with a NULL client");
  955. return -1;
  956. } else {
  957. return client->SetXRunCallback(xrun_callback, arg);
  958. }
  959. }
  960. LIB_EXPORT int jack_set_latency_callback(jack_client_t* ext_client, JackLatencyCallback latency_callback, void *arg)
  961. {
  962. #ifdef __CLIENTDEBUG__
  963. JackGlobals::CheckContext("jack_set_latency_callback");
  964. #endif
  965. JackClient* client = (JackClient*)ext_client;
  966. if (client == NULL) {
  967. jack_error("jack_set_latency_callback called with a NULL client");
  968. return -1;
  969. } else {
  970. return client->SetLatencyCallback(latency_callback, arg);
  971. }
  972. }
  973. LIB_EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  974. {
  975. #ifdef __CLIENTDEBUG__
  976. JackGlobals::CheckContext("jack_set_thread_init_callback");
  977. #endif
  978. JackClient* client = (JackClient*)ext_client;
  979. jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
  980. if (client == NULL) {
  981. jack_error("jack_set_thread_init_callback called with a NULL client");
  982. return -1;
  983. } else {
  984. return client->SetInitCallback(init_callback, arg);
  985. }
  986. }
  987. LIB_EXPORT int jack_activate(jack_client_t* ext_client)
  988. {
  989. #ifdef __CLIENTDEBUG__
  990. JackGlobals::CheckContext("jack_activate");
  991. #endif
  992. JackClient* client = (JackClient*)ext_client;
  993. if (client == NULL) {
  994. jack_error("jack_activate called with a NULL client");
  995. return -1;
  996. } else {
  997. return client->Activate();
  998. }
  999. }
  1000. LIB_EXPORT int jack_deactivate(jack_client_t* ext_client)
  1001. {
  1002. #ifdef __CLIENTDEBUG__
  1003. JackGlobals::CheckContext("jack_deactivate");
  1004. #endif
  1005. JackClient* client = (JackClient*)ext_client;
  1006. if (client == NULL) {
  1007. jack_error("jack_deactivate called with a NULL client");
  1008. return -1;
  1009. } else {
  1010. return client->Deactivate();
  1011. }
  1012. }
  1013. LIB_EXPORT jack_port_t* jack_port_register(jack_client_t* ext_client, const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
  1014. {
  1015. #ifdef __CLIENTDEBUG__
  1016. JackGlobals::CheckContext("jack_port_register");
  1017. #endif
  1018. JackClient* client = (JackClient*)ext_client;
  1019. if (client == NULL) {
  1020. jack_error("jack_port_register called with a NULL client");
  1021. return NULL;
  1022. } else if ((port_name == NULL) || (port_type == NULL)) {
  1023. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  1024. return NULL;
  1025. } else {
  1026. return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size));
  1027. }
  1028. }
  1029. LIB_EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  1030. {
  1031. #ifdef __CLIENTDEBUG__
  1032. JackGlobals::CheckContext("jack_port_unregister");
  1033. #endif
  1034. JackClient* client = (JackClient*)ext_client;
  1035. if (client == NULL) {
  1036. jack_error("jack_port_unregister called with a NULL client");
  1037. return -1;
  1038. }
  1039. uintptr_t port_aux = (uintptr_t)port;
  1040. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1041. if (!CheckPort(myport)) {
  1042. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  1043. return -1;
  1044. }
  1045. return client->PortUnRegister(myport);
  1046. }
  1047. LIB_EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  1048. {
  1049. #ifdef __CLIENTDEBUG__
  1050. JackGlobals::CheckContext("jack_port_is_mine");
  1051. #endif
  1052. JackClient* client = (JackClient*)ext_client;
  1053. if (client == NULL) {
  1054. jack_error("jack_port_is_mine called with a NULL client");
  1055. return -1;
  1056. }
  1057. uintptr_t port_aux = (uintptr_t)port;
  1058. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1059. if (!CheckPort(myport)) {
  1060. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  1061. return -1;
  1062. }
  1063. return client->PortIsMine(myport);
  1064. }
  1065. LIB_EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  1066. {
  1067. #ifdef __CLIENTDEBUG__
  1068. JackGlobals::CheckContext("jack_port_get_connections");
  1069. #endif
  1070. uintptr_t port_aux = (uintptr_t)port;
  1071. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1072. if (!CheckPort(myport)) {
  1073. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  1074. return NULL;
  1075. } else {
  1076. WaitGraphChange();
  1077. JackGraphManager* manager = GetGraphManager();
  1078. return (manager ? manager->GetConnections(myport) : NULL);
  1079. }
  1080. }
  1081. // Calling client does not need to "own" the port
  1082. LIB_EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  1083. {
  1084. #ifdef __CLIENTDEBUG__
  1085. JackGlobals::CheckContext("jack_port_get_all_connections");
  1086. #endif
  1087. JackClient* client = (JackClient*)ext_client;
  1088. if (client == NULL) {
  1089. jack_error("jack_port_get_all_connections called with a NULL client");
  1090. return NULL;
  1091. }
  1092. uintptr_t port_aux = (uintptr_t)port;
  1093. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1094. if (!CheckPort(myport)) {
  1095. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  1096. return NULL;
  1097. } else {
  1098. WaitGraphChange();
  1099. JackGraphManager* manager = GetGraphManager();
  1100. return (manager ? manager->GetConnections(myport) : NULL);
  1101. }
  1102. }
  1103. LIB_EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  1104. {
  1105. #ifdef __CLIENTDEBUG__
  1106. JackGlobals::CheckContext("jack_port_get_total_latency");
  1107. #endif
  1108. JackClient* client = (JackClient*)ext_client;
  1109. if (client == NULL) {
  1110. jack_error("jack_port_get_total_latency called with a NULL client");
  1111. return 0;
  1112. }
  1113. uintptr_t port_aux = (uintptr_t)port;
  1114. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1115. if (!CheckPort(myport)) {
  1116. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  1117. return 0;
  1118. } else {
  1119. WaitGraphChange();
  1120. JackGraphManager* manager = GetGraphManager();
  1121. if (manager) {
  1122. manager->ComputeTotalLatency(myport);
  1123. return manager->GetPort(myport)->GetTotalLatency();
  1124. } else {
  1125. return 0;
  1126. }
  1127. }
  1128. }
  1129. LIB_EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  1130. {
  1131. #ifdef __CLIENTDEBUG__
  1132. JackGlobals::CheckContext("jack_connect");
  1133. #endif
  1134. JackClient* client = (JackClient*)ext_client;
  1135. if (client == NULL) {
  1136. jack_error("jack_connect called with a NULL client");
  1137. return -1;
  1138. } else if ((src == NULL) || (dst == NULL)) {
  1139. jack_error("jack_connect called with a NULL port name");
  1140. return -1;
  1141. } else {
  1142. return client->PortConnect(src, dst);
  1143. }
  1144. }
  1145. LIB_EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  1146. {
  1147. #ifdef __CLIENTDEBUG__
  1148. JackGlobals::CheckContext("jack_disconnect");
  1149. #endif
  1150. JackClient* client = (JackClient*)ext_client;
  1151. if (client == NULL) {
  1152. jack_error("jack_disconnect called with a NULL client");
  1153. return -1;
  1154. } else if ((src == NULL) || (dst == NULL)) {
  1155. jack_error("jack_connect called with a NULL port name");
  1156. return -1;
  1157. } else {
  1158. return client->PortDisconnect(src, dst);
  1159. }
  1160. }
  1161. LIB_EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  1162. {
  1163. #ifdef __CLIENTDEBUG__
  1164. JackGlobals::CheckContext("jack_port_disconnect");
  1165. #endif
  1166. JackClient* client = (JackClient*)ext_client;
  1167. if (client == NULL) {
  1168. jack_error("jack_port_disconnect called with a NULL client");
  1169. return -1;
  1170. }
  1171. uintptr_t port_aux = (uintptr_t)src;
  1172. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1173. if (!CheckPort(myport)) {
  1174. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  1175. return -1;
  1176. }
  1177. return client->PortDisconnect(myport);
  1178. }
  1179. LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  1180. {
  1181. #ifdef __CLIENTDEBUG__
  1182. JackGlobals::CheckContext("jack_get_sample_rate");
  1183. #endif
  1184. JackClient* client = (JackClient*)ext_client;
  1185. if (client == NULL) {
  1186. jack_error("jack_get_sample_rate called with a NULL client");
  1187. return 0;
  1188. } else {
  1189. JackEngineControl* control = GetEngineControl();
  1190. return (control ? control->fSampleRate : 0);
  1191. }
  1192. }
  1193. LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  1194. {
  1195. #ifdef __CLIENTDEBUG__
  1196. JackGlobals::CheckContext("jack_get_buffer_size");
  1197. #endif
  1198. JackClient* client = (JackClient*)ext_client;
  1199. if (client == NULL) {
  1200. jack_error("jack_get_buffer_size called with a NULL client");
  1201. return 0;
  1202. } else {
  1203. JackEngineControl* control = GetEngineControl();
  1204. return (control ? control->fBufferSize : 0);
  1205. }
  1206. }
  1207. LIB_EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  1208. {
  1209. #ifdef __CLIENTDEBUG__
  1210. JackGlobals::CheckContext("jack_get_ports");
  1211. #endif
  1212. JackClient* client = (JackClient*)ext_client;
  1213. if (client == NULL) {
  1214. jack_error("jack_get_ports called with a NULL client");
  1215. return NULL;
  1216. }
  1217. JackGraphManager* manager = GetGraphManager();
  1218. return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
  1219. }
  1220. LIB_EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  1221. {
  1222. #ifdef __CLIENTDEBUG__
  1223. JackGlobals::CheckContext("jack_port_by_name");
  1224. #endif
  1225. JackClient* client = (JackClient*)ext_client;
  1226. if (client == NULL) {
  1227. jack_error("jack_get_ports called with a NULL client");
  1228. return 0;
  1229. }
  1230. if (portname == NULL) {
  1231. jack_error("jack_port_by_name called with a NULL port name");
  1232. return NULL;
  1233. } else {
  1234. JackGraphManager* manager = GetGraphManager();
  1235. if (!manager)
  1236. return NULL;
  1237. int res = manager->GetPort(portname); // returns a port index at least > 1
  1238. return (res == NO_PORT) ? NULL : (jack_port_t*)((uintptr_t)res);
  1239. }
  1240. }
  1241. LIB_EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  1242. {
  1243. #ifdef __CLIENTDEBUG__
  1244. JackGlobals::CheckContext("jack_port_by_id");
  1245. #endif
  1246. /* jack_port_t* type is actually the port index */
  1247. return (jack_port_t*)((uintptr_t)id);
  1248. }
  1249. LIB_EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  1250. {
  1251. #ifdef __CLIENTDEBUG__
  1252. JackGlobals::CheckContext("jack_engine_takeover_timebase");
  1253. #endif
  1254. JackClient* client = (JackClient*)ext_client;
  1255. if (client == NULL) {
  1256. jack_error("jack_engine_takeover_timebase called with a NULL client");
  1257. return -1;
  1258. } else {
  1259. jack_error("jack_engine_takeover_timebase: deprecated\n");
  1260. return 0;
  1261. }
  1262. }
  1263. LIB_EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  1264. {
  1265. #ifdef __CLIENTDEBUG__
  1266. JackGlobals::CheckContext("jack_frames_since_cycle_start");
  1267. #endif
  1268. JackTimer timer;
  1269. JackEngineControl* control = GetEngineControl();
  1270. if (control) {
  1271. control->ReadFrameTime(&timer);
  1272. return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
  1273. } else {
  1274. return 0;
  1275. }
  1276. }
  1277. LIB_EXPORT jack_time_t jack_get_time()
  1278. {
  1279. #ifdef __CLIENTDEBUG__
  1280. JackGlobals::CheckContext("jack_get_time");
  1281. #endif
  1282. return GetMicroSeconds();
  1283. }
  1284. LIB_EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1285. {
  1286. #ifdef __CLIENTDEBUG__
  1287. JackGlobals::CheckContext("jack_frames_to_time");
  1288. #endif
  1289. JackClient* client = (JackClient*)ext_client;
  1290. if (client == NULL) {
  1291. jack_error("jack_frames_to_time called with a NULL client");
  1292. return 0;
  1293. } else {
  1294. JackTimer timer;
  1295. JackEngineControl* control = GetEngineControl();
  1296. if (control) {
  1297. control->ReadFrameTime(&timer);
  1298. return timer.Frames2Time(frames, control->fBufferSize);
  1299. } else {
  1300. return 0;
  1301. }
  1302. }
  1303. }
  1304. LIB_EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1305. {
  1306. #ifdef __CLIENTDEBUG__
  1307. JackGlobals::CheckContext("jack_time_to_frames");
  1308. #endif
  1309. JackClient* client = (JackClient*)ext_client;
  1310. if (client == NULL) {
  1311. jack_error("jack_time_to_frames called with a NULL client");
  1312. return 0;
  1313. } else {
  1314. JackTimer timer;
  1315. JackEngineControl* control = GetEngineControl();
  1316. if (control) {
  1317. control->ReadFrameTime(&timer);
  1318. return timer.Time2Frames(time, control->fBufferSize);
  1319. } else {
  1320. return 0;
  1321. }
  1322. }
  1323. }
  1324. LIB_EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1325. {
  1326. #ifdef __CLIENTDEBUG__
  1327. JackGlobals::CheckContext("jack_frame_time");
  1328. #endif
  1329. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1330. }
  1331. LIB_EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1332. {
  1333. #ifdef __CLIENTDEBUG__
  1334. JackGlobals::CheckContext("jack_last_frame_time");
  1335. #endif
  1336. JackEngineControl* control = GetEngineControl();
  1337. return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
  1338. }
  1339. LIB_EXPORT float jack_cpu_load(jack_client_t* ext_client)
  1340. {
  1341. #ifdef __CLIENTDEBUG__
  1342. JackGlobals::CheckContext("jack_cpu_load");
  1343. #endif
  1344. JackClient* client = (JackClient*)ext_client;
  1345. if (client == NULL) {
  1346. jack_error("jack_cpu_load called with a NULL client");
  1347. return 0.0f;
  1348. } else {
  1349. JackEngineControl* control = GetEngineControl();
  1350. return (control ? control->fCPULoad : 0.0f);
  1351. }
  1352. }
  1353. LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t* ext_client)
  1354. {
  1355. #ifdef __CLIENTDEBUG__
  1356. JackGlobals::CheckContext("jack_client_thread_id");
  1357. #endif
  1358. JackClient* client = (JackClient*)ext_client;
  1359. if (client == NULL) {
  1360. jack_error("jack_client_thread_id called with a NULL client");
  1361. return (jack_native_thread_t)NULL;
  1362. } else {
  1363. return client->GetThreadID();
  1364. }
  1365. }
  1366. LIB_EXPORT char* jack_get_client_name(jack_client_t* ext_client)
  1367. {
  1368. #ifdef __CLIENTDEBUG__
  1369. JackGlobals::CheckContext("jack_get_client_name");
  1370. #endif
  1371. JackClient* client = (JackClient*)ext_client;
  1372. if (client == NULL) {
  1373. jack_error("jack_get_client_name called with a NULL client");
  1374. return NULL;
  1375. } else {
  1376. return client->GetClientControl()->fName;
  1377. }
  1378. }
  1379. LIB_EXPORT int jack_client_name_size(void)
  1380. {
  1381. return JACK_CLIENT_NAME_SIZE;
  1382. }
  1383. LIB_EXPORT int jack_port_name_size(void)
  1384. {
  1385. return REAL_JACK_PORT_NAME_SIZE;
  1386. }
  1387. LIB_EXPORT int jack_port_type_size(void)
  1388. {
  1389. return JACK_PORT_TYPE_SIZE;
  1390. }
  1391. LIB_EXPORT size_t jack_port_type_get_buffer_size(jack_client_t* ext_client, const char* port_type)
  1392. {
  1393. #ifdef __CLIENTDEBUG__
  1394. JackGlobals::CheckContext("jack_port_type_get_buffer_size");
  1395. #endif
  1396. JackClient* client = (JackClient*)ext_client;
  1397. if (client == NULL) {
  1398. jack_error("jack_port_type_get_buffer_size called with a NULL client");
  1399. return 0;
  1400. } else {
  1401. jack_port_type_id_t port_id = GetPortTypeId(port_type);
  1402. if (port_id == PORT_TYPES_MAX) {
  1403. jack_error("jack_port_type_get_buffer_size called with an unknown port type = %s", port_type);
  1404. return 0;
  1405. } else {
  1406. return GetPortType(port_id)->size();
  1407. }
  1408. }
  1409. }
  1410. // transport.h
  1411. LIB_EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1412. {
  1413. #ifdef __CLIENTDEBUG__
  1414. JackGlobals::CheckContext("jack_release_timebase");
  1415. #endif
  1416. JackClient* client = (JackClient*)ext_client;
  1417. if (client == NULL) {
  1418. jack_error("jack_release_timebase called with a NULL client");
  1419. return -1;
  1420. } else {
  1421. return client->ReleaseTimebase();
  1422. }
  1423. }
  1424. LIB_EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1425. {
  1426. #ifdef __CLIENTDEBUG__
  1427. JackGlobals::CheckContext("jack_set_sync_callback");
  1428. #endif
  1429. JackClient* client = (JackClient*)ext_client;
  1430. if (client == NULL) {
  1431. jack_error("jack_set_sync_callback called with a NULL client");
  1432. return -1;
  1433. } else {
  1434. return client->SetSyncCallback(sync_callback, arg);
  1435. }
  1436. }
  1437. LIB_EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1438. {
  1439. #ifdef __CLIENTDEBUG__
  1440. JackGlobals::CheckContext("jack_set_sync_timeout");
  1441. #endif
  1442. JackClient* client = (JackClient*)ext_client;
  1443. if (client == NULL) {
  1444. jack_error("jack_set_sync_timeout called with a NULL client");
  1445. return -1;
  1446. } else {
  1447. return client->SetSyncTimeout(timeout);
  1448. }
  1449. }
  1450. LIB_EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1451. {
  1452. #ifdef __CLIENTDEBUG__
  1453. JackGlobals::CheckContext("jack_set_timebase_callback");
  1454. #endif
  1455. JackClient* client = (JackClient*)ext_client;
  1456. if (client == NULL) {
  1457. jack_error("jack_set_timebase_callback called with a NULL client");
  1458. return -1;
  1459. } else {
  1460. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1461. }
  1462. }
  1463. LIB_EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1464. {
  1465. #ifdef __CLIENTDEBUG__
  1466. JackGlobals::CheckContext("jack_transport_locate");
  1467. #endif
  1468. JackClient* client = (JackClient*)ext_client;
  1469. if (client == NULL) {
  1470. jack_error("jack_transport_locate called with a NULL client");
  1471. return -1;
  1472. } else {
  1473. client->TransportLocate(frame);
  1474. return 0;
  1475. }
  1476. }
  1477. LIB_EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1478. {
  1479. #ifdef __CLIENTDEBUG__
  1480. JackGlobals::CheckContext("jack_transport_query");
  1481. #endif
  1482. JackClient* client = (JackClient*)ext_client;
  1483. if (client == NULL) {
  1484. jack_error("jack_transport_query called with a NULL client");
  1485. return JackTransportStopped;
  1486. } else {
  1487. return client->TransportQuery(pos);
  1488. }
  1489. }
  1490. LIB_EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1491. {
  1492. #ifdef __CLIENTDEBUG__
  1493. JackGlobals::CheckContext("jack_get_current_transport_frame");
  1494. #endif
  1495. JackClient* client = (JackClient*)ext_client;
  1496. if (client == NULL) {
  1497. jack_error("jack_get_current_transport_frame called with a NULL client");
  1498. return 0;
  1499. } else {
  1500. return client->GetCurrentTransportFrame();
  1501. }
  1502. }
  1503. LIB_EXPORT int jack_transport_reposition(jack_client_t* ext_client, const jack_position_t* pos)
  1504. {
  1505. #ifdef __CLIENTDEBUG__
  1506. JackGlobals::CheckContext("jack_transport_reposition");
  1507. #endif
  1508. JackClient* client = (JackClient*)ext_client;
  1509. if (client == NULL) {
  1510. jack_error("jack_transport_reposition called with a NULL client");
  1511. return -1;
  1512. } else {
  1513. client->TransportReposition(pos);
  1514. return 0;
  1515. }
  1516. }
  1517. LIB_EXPORT void jack_transport_start(jack_client_t* ext_client)
  1518. {
  1519. #ifdef __CLIENTDEBUG__
  1520. JackGlobals::CheckContext("jack_transport_start");
  1521. #endif
  1522. JackClient* client = (JackClient*)ext_client;
  1523. if (client == NULL) {
  1524. jack_error("jack_transport_start called with a NULL client");
  1525. } else {
  1526. client->TransportStart();
  1527. }
  1528. }
  1529. LIB_EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1530. {
  1531. #ifdef __CLIENTDEBUG__
  1532. JackGlobals::CheckContext("jack_transport_stop");
  1533. #endif
  1534. JackClient* client = (JackClient*)ext_client;
  1535. if (client == NULL) {
  1536. jack_error("jack_transport_stop called with a NULL client");
  1537. } else {
  1538. client->TransportStop();
  1539. }
  1540. }
  1541. // deprecated
  1542. LIB_EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1543. {
  1544. #ifdef __CLIENTDEBUG__
  1545. JackGlobals::CheckContext("jack_get_transport_info");
  1546. #endif
  1547. jack_error("jack_get_transport_info: deprecated");
  1548. if (tinfo)
  1549. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1550. }
  1551. LIB_EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1552. {
  1553. #ifdef __CLIENTDEBUG__
  1554. JackGlobals::CheckContext("jack_set_transport_info");
  1555. #endif
  1556. jack_error("jack_set_transport_info: deprecated");
  1557. if (tinfo)
  1558. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1559. }
  1560. // statistics.h
  1561. LIB_EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1562. {
  1563. #ifdef __CLIENTDEBUG__
  1564. JackGlobals::CheckContext("jack_get_max_delayed_usecs");
  1565. #endif
  1566. JackClient* client = (JackClient*)ext_client;
  1567. if (client == NULL) {
  1568. jack_error("jack_get_max_delayed_usecs called with a NULL client");
  1569. return 0.f;
  1570. } else {
  1571. JackEngineControl* control = GetEngineControl();
  1572. return (control ? control->fMaxDelayedUsecs : 0.f);
  1573. }
  1574. }
  1575. LIB_EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1576. {
  1577. #ifdef __CLIENTDEBUG__
  1578. JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
  1579. #endif
  1580. JackClient* client = (JackClient*)ext_client;
  1581. if (client == NULL) {
  1582. jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
  1583. return 0.f;
  1584. } else {
  1585. JackEngineControl* control = GetEngineControl();
  1586. return (control ? control->fXrunDelayedUsecs : 0.f);
  1587. }
  1588. }
  1589. LIB_EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1590. {
  1591. #ifdef __CLIENTDEBUG__
  1592. JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
  1593. #endif
  1594. JackClient* client = (JackClient*)ext_client;
  1595. if (client == NULL) {
  1596. jack_error("jack_reset_max_delayed_usecs called with a NULL client");
  1597. } else {
  1598. JackEngineControl* control = GetEngineControl();
  1599. control->ResetXRun();
  1600. }
  1601. }
  1602. // thread.h
  1603. LIB_EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
  1604. {
  1605. #ifdef __CLIENTDEBUG__
  1606. JackGlobals::CheckContext("jack_client_real_time_priority");
  1607. #endif
  1608. JackClient* client = (JackClient*)ext_client;
  1609. if (client == NULL) {
  1610. jack_error("jack_client_real_time_priority called with a NULL client");
  1611. return -1;
  1612. } else {
  1613. JackEngineControl* control = GetEngineControl();
  1614. return (control->fRealTime) ? control->fClientPriority : -1;
  1615. }
  1616. }
  1617. LIB_EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
  1618. {
  1619. #ifdef __CLIENTDEBUG__
  1620. JackGlobals::CheckContext("jack_client_max_real_time_priority");
  1621. #endif
  1622. JackClient* client = (JackClient*)ext_client;
  1623. if (client == NULL) {
  1624. jack_error("jack_client_max_real_time_priority called with a NULL client");
  1625. return -1;
  1626. } else {
  1627. JackEngineControl* control = GetEngineControl();
  1628. return (control->fRealTime) ? control->fMaxClientPriority : -1;
  1629. }
  1630. }
  1631. LIB_EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority)
  1632. {
  1633. JackEngineControl* control = GetEngineControl();
  1634. return (control
  1635. ? JackThread::AcquireRealTimeImp(thread, priority, control->fPeriod, control->fComputation, control->fConstraint)
  1636. : -1);
  1637. }
  1638. LIB_EXPORT int jack_client_create_thread(jack_client_t* client,
  1639. jack_native_thread_t *thread,
  1640. int priority,
  1641. int realtime, /* boolean */
  1642. thread_routine routine,
  1643. void *arg)
  1644. {
  1645. #ifdef __CLIENTDEBUG__
  1646. JackGlobals::CheckContext("jack_client_create_thread");
  1647. #endif
  1648. JackEngineControl* control = GetEngineControl();
  1649. int res = JackThread::StartImp(thread, priority, realtime, routine, arg);
  1650. return (res == 0)
  1651. ? ((realtime ? JackThread::AcquireRealTimeImp(*thread, priority, control->fPeriod, control->fComputation, control->fConstraint) : res))
  1652. : res;
  1653. }
  1654. LIB_EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread)
  1655. {
  1656. return JackThread::DropRealTimeImp(thread);
  1657. }
  1658. LIB_EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread)
  1659. {
  1660. #ifdef __CLIENTDEBUG__
  1661. JackGlobals::CheckContext("jack_client_stop_thread");
  1662. #endif
  1663. return JackThread::StopImp(thread);
  1664. }
  1665. LIB_EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread)
  1666. {
  1667. #ifdef __CLIENTDEBUG__
  1668. JackGlobals::CheckContext("jack_client_kill_thread");
  1669. #endif
  1670. return JackThread::KillImp(thread);
  1671. }
  1672. #ifndef WIN32
  1673. LIB_EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
  1674. {
  1675. JackGlobals::fJackThreadCreator = (jtc == NULL) ? pthread_create : jtc;
  1676. }
  1677. #endif
  1678. // intclient.h
  1679. LIB_EXPORT int jack_internal_client_new (const char* client_name,
  1680. const char* load_name,
  1681. const char* load_init)
  1682. {
  1683. #ifdef __CLIENTDEBUG__
  1684. JackGlobals::CheckContext("jack_internal_client_new");
  1685. #endif
  1686. jack_error("jack_internal_client_new: deprecated");
  1687. return -1;
  1688. }
  1689. LIB_EXPORT void jack_internal_client_close (const char* client_name)
  1690. {
  1691. #ifdef __CLIENTDEBUG__
  1692. JackGlobals::CheckContext("jack_internal_client_close");
  1693. #endif
  1694. jack_error("jack_internal_client_close: deprecated");
  1695. }
  1696. LIB_EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1697. {
  1698. #ifdef __CLIENTDEBUG__
  1699. JackGlobals::CheckContext("jack_get_internal_client_name");
  1700. #endif
  1701. JackClient* client = (JackClient*)ext_client;
  1702. if (client == NULL) {
  1703. jack_error("jack_get_internal_client_name called with a NULL client");
  1704. return NULL;
  1705. } else if (intclient >= CLIENT_NUM) {
  1706. jack_error("jack_get_internal_client_name: incorrect client");
  1707. return NULL;
  1708. } else {
  1709. return client->GetInternalClientName(intclient);
  1710. }
  1711. }
  1712. LIB_EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1713. {
  1714. #ifdef __CLIENTDEBUG__
  1715. JackGlobals::CheckContext("jack_internal_client_handle");
  1716. #endif
  1717. JackClient* client = (JackClient*)ext_client;
  1718. if (client == NULL) {
  1719. jack_error("jack_internal_client_handle called with a NULL client");
  1720. return 0;
  1721. } else {
  1722. jack_status_t my_status;
  1723. if (status == NULL) /* no status from caller? */
  1724. status = &my_status; /* use local status word */
  1725. *status = (jack_status_t)0;
  1726. return client->InternalClientHandle(client_name, status);
  1727. }
  1728. }
  1729. LIB_EXPORT jack_intclient_t jack_internal_client_load_aux(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, va_list ap)
  1730. {
  1731. #ifdef __CLIENTDEBUG__
  1732. JackGlobals::CheckContext("jack_internal_client_load_aux");
  1733. #endif
  1734. JackClient* client = (JackClient*)ext_client;
  1735. if (client == NULL) {
  1736. jack_error("jack_internal_client_load called with a NULL client");
  1737. return 0;
  1738. } else {
  1739. jack_varargs_t va;
  1740. jack_status_t my_status;
  1741. if (status == NULL) /* no status from caller? */
  1742. status = &my_status; /* use local status word */
  1743. *status = (jack_status_t)0;
  1744. /* validate parameters */
  1745. if ((options & ~JackLoadOptions)) {
  1746. int my_status1 = *status | (JackFailure | JackInvalidOption);
  1747. *status = (jack_status_t)my_status1;
  1748. return 0;
  1749. }
  1750. /* parse variable arguments */
  1751. jack_varargs_parse(options, ap, &va);
  1752. return client->InternalClientLoad(client_name, options, status, &va);
  1753. }
  1754. }
  1755. LIB_EXPORT jack_intclient_t jack_internal_client_load(jack_client_t *client, const char* client_name, jack_options_t options, jack_status_t *status, ...)
  1756. {
  1757. #ifdef __CLIENTDEBUG__
  1758. JackGlobals::CheckContext("jack_internal_client_load");
  1759. #endif
  1760. va_list ap;
  1761. va_start(ap, status);
  1762. jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
  1763. va_end(ap);
  1764. return res;
  1765. }
  1766. LIB_EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1767. {
  1768. #ifdef __CLIENTDEBUG__
  1769. JackGlobals::CheckContext("jack_internal_client_load");
  1770. #endif
  1771. JackClient* client = (JackClient*)ext_client;
  1772. if (client == NULL) {
  1773. jack_error("jack_internal_client_unload called with a NULL client");
  1774. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1775. } else if (intclient >= CLIENT_NUM) {
  1776. jack_error("jack_internal_client_unload: incorrect client");
  1777. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1778. } else {
  1779. jack_status_t my_status;
  1780. client->InternalClientUnload(intclient, &my_status);
  1781. return my_status;
  1782. }
  1783. }
  1784. LIB_EXPORT void jack_get_version(int *major_ptr,
  1785. int *minor_ptr,
  1786. int *micro_ptr,
  1787. int *proto_ptr)
  1788. {
  1789. #ifdef __CLIENTDEBUG__
  1790. JackGlobals::CheckContext("jack_get_version");
  1791. #endif
  1792. // FIXME: We need these comming from build system
  1793. *major_ptr = 0;
  1794. *minor_ptr = 0;
  1795. *micro_ptr = 0;
  1796. *proto_ptr = 0;
  1797. }
  1798. LIB_EXPORT const char* jack_get_version_string()
  1799. {
  1800. #ifdef __CLIENTDEBUG__
  1801. JackGlobals::CheckContext("jack_get_version_string");
  1802. #endif
  1803. return VERSION;
  1804. }
  1805. LIB_EXPORT void jack_free(void* ptr)
  1806. {
  1807. #ifdef __CLIENTDEBUG__
  1808. JackGlobals::CheckContext("jack_free");
  1809. #endif
  1810. if (ptr) {
  1811. free(ptr);
  1812. }
  1813. }
  1814. // session.h
  1815. LIB_EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg)
  1816. {
  1817. #ifdef __CLIENTDEBUG__
  1818. JackGlobals::CheckContext("jack_set_session_callback");
  1819. #endif
  1820. JackClient* client = (JackClient*)ext_client;
  1821. jack_log("jack_set_session_callback ext_client %x client %x ", ext_client, client);
  1822. if (client == NULL) {
  1823. jack_error("jack_set_session_callback called with a NULL client");
  1824. return -1;
  1825. } else {
  1826. return client->SetSessionCallback(session_callback, arg);
  1827. }
  1828. }
  1829. LIB_EXPORT jack_session_command_t* jack_session_notify(jack_client_t* ext_client, const char* target, jack_session_event_type_t ev_type, const char* path)
  1830. {
  1831. #ifdef __CLIENTDEBUG__
  1832. JackGlobals::CheckContext("jack_session_notify");
  1833. #endif
  1834. JackClient* client = (JackClient*)ext_client;
  1835. jack_log("jack_session_notify ext_client %x client %x ", ext_client, client);
  1836. if (client == NULL) {
  1837. jack_error("jack_session_notify called with a NULL client");
  1838. return NULL;
  1839. } else {
  1840. return client->SessionNotify(target, ev_type, path);
  1841. }
  1842. }
  1843. LIB_EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event)
  1844. {
  1845. #ifdef __CLIENTDEBUG__
  1846. JackGlobals::CheckContext("jack_session_reply");
  1847. #endif
  1848. JackClient* client = (JackClient*)ext_client;
  1849. jack_log("jack_session_reply ext_client %x client %x ", ext_client, client);
  1850. if (client == NULL) {
  1851. jack_error("jack_session_reply called with a NULL client");
  1852. return -1;
  1853. } else {
  1854. return client->SessionReply(event);
  1855. }
  1856. }
  1857. LIB_EXPORT void jack_session_event_free(jack_session_event_t* ev)
  1858. {
  1859. #ifdef __CLIENTDEBUG__
  1860. JackGlobals::CheckContext("jack_session_event_free");
  1861. #endif
  1862. if (ev) {
  1863. if (ev->session_dir)
  1864. free((void *)ev->session_dir);
  1865. if (ev->client_uuid)
  1866. free((void *)ev->client_uuid);
  1867. if (ev->command_line)
  1868. free(ev->command_line);
  1869. free(ev);
  1870. }
  1871. }
  1872. LIB_EXPORT char *jack_client_get_uuid(jack_client_t* ext_client)
  1873. {
  1874. #ifdef __CLIENTDEBUG__
  1875. JackGlobals::CheckContext("jack_client_get_uuid");
  1876. #endif
  1877. JackClient* client = (JackClient*)ext_client;
  1878. if (client == NULL) {
  1879. jack_error("jack_client_get_uuid called with a NULL client");
  1880. return NULL;
  1881. } else {
  1882. char retval[16];
  1883. snprintf(retval, sizeof(retval), "%d", client->GetClientControl()->fSessionID);
  1884. return strdup(retval);
  1885. }
  1886. }
  1887. LIB_EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name)
  1888. {
  1889. #ifdef __CLIENTDEBUG__
  1890. JackGlobals::CheckContext("jack_get_uuid_for_client_name");
  1891. #endif
  1892. JackClient* client = (JackClient*)ext_client;
  1893. jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
  1894. if (client == NULL) {
  1895. jack_error("jack_get_uuid_for_client_name called with a NULL client");
  1896. return NULL;
  1897. } else {
  1898. return client->GetUUIDForClientName(client_name);
  1899. }
  1900. }
  1901. LIB_EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid)
  1902. {
  1903. #ifdef __CLIENTDEBUG__
  1904. JackGlobals::CheckContext("jack_get_client_name_by_uuid");
  1905. #endif
  1906. JackClient* client = (JackClient*)ext_client;
  1907. jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
  1908. if (client == NULL) {
  1909. jack_error("jack_get_client_name_by_uuid called with a NULL client");
  1910. return NULL;
  1911. } else {
  1912. return client->GetClientNameByUUID(client_uuid);
  1913. }
  1914. }
  1915. LIB_EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* client_name, const char* uuid)
  1916. {
  1917. #ifdef __CLIENTDEBUG__
  1918. JackGlobals::CheckContext("jack_reserve_client_name");
  1919. #endif
  1920. JackClient* client = (JackClient*)ext_client;
  1921. jack_log("jack_reserve_client_name ext_client %x client %x ", ext_client, client);
  1922. if (client == NULL) {
  1923. jack_error("jack_reserve_client_name called with a NULL client");
  1924. return -1;
  1925. } else {
  1926. return client->ReserveClientName(client_name, uuid);
  1927. }
  1928. }
  1929. LIB_EXPORT void jack_session_commands_free(jack_session_command_t *cmds)
  1930. {
  1931. #ifdef __CLIENTDEBUG__
  1932. JackGlobals::CheckContext("jack_session_commands_free");
  1933. #endif
  1934. if (!cmds) {
  1935. return;
  1936. }
  1937. int i = 0;
  1938. while (1) {
  1939. if (cmds[i].client_name) {
  1940. free ((char *)cmds[i].client_name);
  1941. }
  1942. if (cmds[i].command) {
  1943. free ((char *)cmds[i].command);
  1944. }
  1945. if (cmds[i].uuid) {
  1946. free ((char *)cmds[i].uuid);
  1947. } else {
  1948. break;
  1949. }
  1950. i += 1;
  1951. }
  1952. free(cmds);
  1953. }
  1954. LIB_EXPORT int jack_client_has_session_callback(jack_client_t* ext_client, const char* client_name)
  1955. {
  1956. #ifdef __CLIENTDEBUG__
  1957. JackGlobals::CheckContext("jack_client_has_session_callback");
  1958. #endif
  1959. JackClient* client = (JackClient*)ext_client;
  1960. jack_log("jack_client_has_session_callback ext_client %x client %x ", ext_client, client);
  1961. if (client == NULL) {
  1962. jack_error("jack_client_has_session_callback called with a NULL client");
  1963. return -1;
  1964. } else {
  1965. return client->ClientHasSessionCallback(client_name);
  1966. }
  1967. }