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_status_t jack_internal_client_unload(jack_client_t *client,
  227. jack_intclient_t intclient);
  228. LIB_EXPORT void jack_free(void* ptr);
  229. LIB_EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg);
  230. 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);
  231. LIB_EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event);
  232. LIB_EXPORT void jack_session_event_free(jack_session_event_t* ev);
  233. LIB_EXPORT char* jack_client_get_uuid (jack_client_t *client);
  234. LIB_EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name);
  235. LIB_EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid);
  236. LIB_EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* name, const char* uuid);
  237. LIB_EXPORT void jack_session_commands_free(jack_session_command_t *cmds);
  238. LIB_EXPORT int jack_client_has_session_callback(jack_client_t *client, const char* client_name);
  239. #ifdef __cplusplus
  240. }
  241. #endif
  242. static inline bool CheckPort(jack_port_id_t port_index)
  243. {
  244. return (port_index > 0 && port_index < PORT_NUM_MAX);
  245. }
  246. static inline bool CheckBufferSize(jack_nframes_t buffer_size)
  247. {
  248. return (buffer_size >= 1 && buffer_size <= BUFFER_SIZE_MAX);
  249. }
  250. static inline void WaitGraphChange()
  251. {
  252. /*
  253. TLS key that is set only in RT thread, so never waits for pending
  254. graph change in RT context (just read the current graph state).
  255. */
  256. if (jack_tls_get(JackGlobals::fRealTime) == NULL) {
  257. JackGraphManager* manager = GetGraphManager();
  258. JackEngineControl* control = GetEngineControl();
  259. assert(manager);
  260. assert(control);
  261. if (manager->IsPendingChange()) {
  262. jack_log("WaitGraphChange...");
  263. JackSleep(int(control->fPeriodUsecs * 1.1f));
  264. }
  265. }
  266. }
  267. LIB_EXPORT void jack_set_error_function(print_function func)
  268. {
  269. jack_error_callback = (func == NULL) ? &default_jack_error_callback : func;
  270. }
  271. LIB_EXPORT void jack_set_info_function(print_function func)
  272. {
  273. jack_info_callback = (func == NULL) ? &default_jack_info_callback : func;
  274. }
  275. LIB_EXPORT jack_client_t* jack_client_new(const char* client_name)
  276. {
  277. #ifdef __CLIENTDEBUG__
  278. JackGlobals::CheckContext("jack_client_new");
  279. #endif
  280. try {
  281. assert(JackGlobals::fOpenMutex);
  282. JackGlobals::fOpenMutex->Lock();
  283. jack_error("jack_client_new: deprecated");
  284. int options = JackUseExactName;
  285. if (getenv("JACK_START_SERVER") == NULL)
  286. options |= JackNoStartServer;
  287. jack_client_t* res = jack_client_new_aux(client_name, (jack_options_t)options, NULL);
  288. JackGlobals::fOpenMutex->Unlock();
  289. return res;
  290. } catch (std::bad_alloc& e) {
  291. jack_error("Memory allocation error...");
  292. return NULL;
  293. } catch (...) {
  294. jack_error("Unknown error...");
  295. return NULL;
  296. }
  297. }
  298. LIB_EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
  299. {
  300. #ifdef __CLIENTDEBUG__
  301. JackGlobals::CheckContext("jack_port_get_buffer");
  302. #endif
  303. uintptr_t port_aux = (uintptr_t)port;
  304. jack_port_id_t myport = (jack_port_id_t)port_aux;
  305. if (!CheckPort(myport)) {
  306. jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
  307. return NULL;
  308. } else {
  309. JackGraphManager* manager = GetGraphManager();
  310. return (manager ? manager->GetBuffer(myport, frames) : NULL);
  311. }
  312. }
  313. LIB_EXPORT const char* jack_port_name(const jack_port_t* port)
  314. {
  315. #ifdef __CLIENTDEBUG__
  316. JackGlobals::CheckContext("jack_port_name");
  317. #endif
  318. uintptr_t port_aux = (uintptr_t)port;
  319. jack_port_id_t myport = (jack_port_id_t)port_aux;
  320. if (!CheckPort(myport)) {
  321. jack_error("jack_port_name called with an incorrect port %ld", myport);
  322. return NULL;
  323. } else {
  324. JackGraphManager* manager = GetGraphManager();
  325. return (manager ? manager->GetPort(myport)->GetName() : NULL);
  326. }
  327. }
  328. LIB_EXPORT const char* jack_port_short_name(const jack_port_t* port)
  329. {
  330. #ifdef __CLIENTDEBUG__
  331. JackGlobals::CheckContext("jack_port_short_name");
  332. #endif
  333. uintptr_t port_aux = (uintptr_t)port;
  334. jack_port_id_t myport = (jack_port_id_t)port_aux;
  335. if (!CheckPort(myport)) {
  336. jack_error("jack_port_short_name called with an incorrect port %ld", myport);
  337. return NULL;
  338. } else {
  339. JackGraphManager* manager = GetGraphManager();
  340. return (manager ? manager->GetPort(myport)->GetShortName() : NULL);
  341. }
  342. }
  343. LIB_EXPORT int jack_port_flags(const jack_port_t* port)
  344. {
  345. #ifdef __CLIENTDEBUG__
  346. JackGlobals::CheckContext("jack_port_flags");
  347. #endif
  348. uintptr_t port_aux = (uintptr_t)port;
  349. jack_port_id_t myport = (jack_port_id_t)port_aux;
  350. if (!CheckPort(myport)) {
  351. jack_error("jack_port_flags called with an incorrect port %ld", myport);
  352. return -1;
  353. } else {
  354. JackGraphManager* manager = GetGraphManager();
  355. return (manager ? manager->GetPort(myport)->GetFlags() : -1);
  356. }
  357. }
  358. LIB_EXPORT const char* jack_port_type(const jack_port_t* port)
  359. {
  360. #ifdef __CLIENTDEBUG__
  361. JackGlobals::CheckContext("jack_port_type");
  362. #endif
  363. uintptr_t port_aux = (uintptr_t)port;
  364. jack_port_id_t myport = (jack_port_id_t)port_aux;
  365. if (!CheckPort(myport)) {
  366. jack_error("jack_port_flags called an incorrect port %ld", myport);
  367. return NULL;
  368. } else {
  369. JackGraphManager* manager = GetGraphManager();
  370. return (manager ? manager->GetPort(myport)->GetType() : NULL);
  371. }
  372. }
  373. LIB_EXPORT jack_port_type_id_t jack_port_type_id(const jack_port_t *port)
  374. {
  375. #ifdef __CLIENTDEBUG__
  376. JackGlobals::CheckContext("jack_port_type_id");
  377. #endif
  378. uintptr_t port_aux = (uintptr_t)port;
  379. jack_port_id_t myport = (jack_port_id_t)port_aux;
  380. if (!CheckPort(myport)) {
  381. jack_error("jack_port_type_id called an incorrect port %ld", myport);
  382. return 0;
  383. } else {
  384. JackGraphManager* manager = GetGraphManager();
  385. return (manager ? GetPortTypeId(manager->GetPort(myport)->GetType()) : 0);
  386. }
  387. }
  388. LIB_EXPORT int jack_port_connected(const jack_port_t* port)
  389. {
  390. #ifdef __CLIENTDEBUG__
  391. JackGlobals::CheckContext("jack_port_connected");
  392. #endif
  393. uintptr_t port_aux = (uintptr_t)port;
  394. jack_port_id_t myport = (jack_port_id_t)port_aux;
  395. if (!CheckPort(myport)) {
  396. jack_error("jack_port_connected called with an incorrect port %ld", myport);
  397. return -1;
  398. } else {
  399. WaitGraphChange();
  400. JackGraphManager* manager = GetGraphManager();
  401. return (manager ? manager->GetConnectionsNum(myport) : -1);
  402. }
  403. }
  404. LIB_EXPORT int jack_port_connected_to(const jack_port_t* port, const char* port_name)
  405. {
  406. #ifdef __CLIENTDEBUG__
  407. JackGlobals::CheckContext("jack_port_connected_to");
  408. #endif
  409. uintptr_t port_aux = (uintptr_t)port;
  410. jack_port_id_t src = (jack_port_id_t)port_aux;
  411. if (!CheckPort(src)) {
  412. jack_error("jack_port_connected_to called with an incorrect port %ld", src);
  413. return -1;
  414. } else if (port_name == NULL) {
  415. jack_error("jack_port_connected_to called with a NULL port name");
  416. return -1;
  417. } else {
  418. WaitGraphChange();
  419. JackGraphManager* manager = GetGraphManager();
  420. jack_port_id_t dst = (manager ? manager->GetPort(port_name) : NO_PORT);
  421. if (dst == NO_PORT) {
  422. jack_error("Unknown destination port port_name = %s", port_name);
  423. return 0;
  424. } else {
  425. return manager->IsConnected(src, dst);
  426. }
  427. }
  428. }
  429. LIB_EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  430. {
  431. #ifdef __CLIENTDEBUG__
  432. JackGlobals::CheckContext("jack_port_tie");
  433. #endif
  434. uintptr_t src_aux = (uintptr_t)src;
  435. jack_port_id_t mysrc = (jack_port_id_t)src_aux;
  436. if (!CheckPort(mysrc)) {
  437. jack_error("jack_port_tie called with a NULL src port");
  438. return -1;
  439. }
  440. uintptr_t dst_aux = (uintptr_t)dst;
  441. jack_port_id_t mydst = (jack_port_id_t)dst_aux;
  442. if (!CheckPort(mydst)) {
  443. jack_error("jack_port_tie called with a NULL dst port");
  444. return -1;
  445. }
  446. JackGraphManager* manager = GetGraphManager();
  447. if (manager && manager->GetPort(mysrc)->GetRefNum() != manager->GetPort(mydst)->GetRefNum()) {
  448. jack_error("jack_port_tie called with ports not belonging to the same client");
  449. return -1;
  450. } else {
  451. return manager->GetPort(mydst)->Tie(mysrc);
  452. }
  453. }
  454. LIB_EXPORT int jack_port_untie(jack_port_t* port)
  455. {
  456. #ifdef __CLIENTDEBUG__
  457. JackGlobals::CheckContext("jack_port_untie");
  458. #endif
  459. uintptr_t port_aux = (uintptr_t)port;
  460. jack_port_id_t myport = (jack_port_id_t)port_aux;
  461. if (!CheckPort(myport)) {
  462. jack_error("jack_port_untie called with an incorrect port %ld", myport);
  463. return -1;
  464. } else {
  465. JackGraphManager* manager = GetGraphManager();
  466. return (manager ? manager->GetPort(myport)->UnTie() : -1);
  467. }
  468. }
  469. LIB_EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  470. {
  471. #ifdef __CLIENTDEBUG__
  472. JackGlobals::CheckContext("jack_port_get_latency");
  473. #endif
  474. uintptr_t port_aux = (uintptr_t)port;
  475. jack_port_id_t myport = (jack_port_id_t)port_aux;
  476. if (!CheckPort(myport)) {
  477. jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
  478. return 0;
  479. } else {
  480. WaitGraphChange();
  481. JackGraphManager* manager = GetGraphManager();
  482. return (manager ? manager->GetPort(myport)->GetLatency() : 0);
  483. }
  484. }
  485. LIB_EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  486. {
  487. #ifdef __CLIENTDEBUG__
  488. JackGlobals::CheckContext("jack_port_set_latency");
  489. #endif
  490. uintptr_t port_aux = (uintptr_t)port;
  491. jack_port_id_t myport = (jack_port_id_t)port_aux;
  492. if (!CheckPort(myport)) {
  493. jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
  494. } else {
  495. JackGraphManager* manager = GetGraphManager();
  496. if (manager)
  497. manager->GetPort(myport)->SetLatency(frames);
  498. }
  499. }
  500. LIB_EXPORT void jack_port_get_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
  501. {
  502. #ifdef __CLIENTDEBUG__
  503. JackGlobals::CheckContext("jack_port_get_latency_range");
  504. #endif
  505. uintptr_t port_aux = (uintptr_t)port;
  506. jack_port_id_t myport = (jack_port_id_t)port_aux;
  507. if (!CheckPort(myport)) {
  508. jack_error("jack_port_get_latency_range called with an incorrect port %ld", myport);
  509. } else {
  510. WaitGraphChange();
  511. JackGraphManager* manager = GetGraphManager();
  512. if (manager)
  513. manager->GetPort(myport)->GetLatencyRange(mode, range);
  514. }
  515. }
  516. LIB_EXPORT void jack_port_set_latency_range(jack_port_t *port, jack_latency_callback_mode_t mode, jack_latency_range_t *range)
  517. {
  518. #ifdef __CLIENTDEBUG__
  519. JackGlobals::CheckContext("jack_port_set_latency_range");
  520. #endif
  521. uintptr_t port_aux = (uintptr_t)port;
  522. jack_port_id_t myport = (jack_port_id_t)port_aux;
  523. if (!CheckPort(myport)) {
  524. jack_error("jack_port_set_latency_range called with an incorrect port %ld", myport);
  525. } else {
  526. WaitGraphChange();
  527. JackGraphManager* manager = GetGraphManager();
  528. if (manager)
  529. manager->GetPort(myport)->SetLatencyRange(mode, range);
  530. }
  531. }
  532. LIB_EXPORT int jack_recompute_total_latency(jack_client_t* ext_client, jack_port_t* port)
  533. {
  534. #ifdef __CLIENTDEBUG__
  535. JackGlobals::CheckContext("jack_recompute_total_latency");
  536. #endif
  537. JackClient* client = (JackClient*)ext_client;
  538. uintptr_t port_aux = (uintptr_t)port;
  539. jack_port_id_t myport = (jack_port_id_t)port_aux;
  540. if (client == NULL) {
  541. jack_error("jack_recompute_total_latency called with a NULL client");
  542. return -1;
  543. } else if (!CheckPort(myport)) {
  544. jack_error("jack_recompute_total_latency called with a NULL port");
  545. return -1;
  546. } else {
  547. WaitGraphChange();
  548. JackGraphManager* manager = GetGraphManager();
  549. return (manager ? manager->ComputeTotalLatency(myport) : -1);
  550. }
  551. }
  552. LIB_EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  553. {
  554. #ifdef __CLIENTDEBUG__
  555. JackGlobals::CheckContext("jack_recompute_total_latencies");
  556. #endif
  557. JackClient* client = (JackClient*)ext_client;
  558. if (client == NULL) {
  559. jack_error("jack_recompute_total_latencies called with a NULL client");
  560. return -1;
  561. } else {
  562. return client->ComputeTotalLatencies();
  563. }
  564. }
  565. LIB_EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  566. {
  567. #ifdef __CLIENTDEBUG__
  568. JackGlobals::CheckContext("jack_port_set_name");
  569. #endif
  570. uintptr_t port_aux = (uintptr_t)port;
  571. jack_port_id_t myport = (jack_port_id_t)port_aux;
  572. if (!CheckPort(myport)) {
  573. jack_error("jack_port_set_name called with an incorrect port %ld", myport);
  574. return -1;
  575. } else if (name == NULL) {
  576. jack_error("jack_port_set_name called with a NULL port name");
  577. return -1;
  578. } else {
  579. JackClient* client = NULL;
  580. for (int i = 0; i < CLIENT_NUM; i++) {
  581. // Find a valid client
  582. if ((client = JackGlobals::fClientTable[i])) {
  583. break;
  584. }
  585. }
  586. return (client) ? client->PortRename(myport, name) : -1;
  587. }
  588. }
  589. LIB_EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
  590. {
  591. #ifdef __CLIENTDEBUG__
  592. JackGlobals::CheckContext("jack_port_set_alias");
  593. #endif
  594. uintptr_t port_aux = (uintptr_t)port;
  595. jack_port_id_t myport = (jack_port_id_t)port_aux;
  596. if (!CheckPort(myport)) {
  597. jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
  598. return -1;
  599. } else if (name == NULL) {
  600. jack_error("jack_port_set_alias called with a NULL port name");
  601. return -1;
  602. } else {
  603. JackGraphManager* manager = GetGraphManager();
  604. return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
  605. }
  606. }
  607. LIB_EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
  608. {
  609. #ifdef __CLIENTDEBUG__
  610. JackGlobals::CheckContext("jack_port_unset_alias");
  611. #endif
  612. uintptr_t port_aux = (uintptr_t)port;
  613. jack_port_id_t myport = (jack_port_id_t)port_aux;
  614. if (!CheckPort(myport)) {
  615. jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
  616. return -1;
  617. } else if (name == NULL) {
  618. jack_error("jack_port_unset_alias called with a NULL port name");
  619. return -1;
  620. } else {
  621. JackGraphManager* manager = GetGraphManager();
  622. return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
  623. }
  624. }
  625. LIB_EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  626. {
  627. #ifdef __CLIENTDEBUG__
  628. JackGlobals::CheckContext("jack_port_get_aliases");
  629. #endif
  630. uintptr_t port_aux = (uintptr_t)port;
  631. jack_port_id_t myport = (jack_port_id_t)port_aux;
  632. if (!CheckPort(myport)) {
  633. jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
  634. return -1;
  635. } else {
  636. JackGraphManager* manager = GetGraphManager();
  637. return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
  638. }
  639. }
  640. LIB_EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  641. {
  642. #ifdef __CLIENTDEBUG__
  643. JackGlobals::CheckContext("jack_port_request_monitor");
  644. #endif
  645. uintptr_t port_aux = (uintptr_t)port;
  646. jack_port_id_t myport = (jack_port_id_t)port_aux;
  647. if (!CheckPort(myport)) {
  648. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  649. return -1;
  650. } else {
  651. JackGraphManager* manager = GetGraphManager();
  652. return (manager ? manager->RequestMonitor(myport, onoff) : -1);
  653. }
  654. }
  655. LIB_EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  656. {
  657. #ifdef __CLIENTDEBUG__
  658. JackGlobals::CheckContext("jack_port_request_monitor_by_name");
  659. #endif
  660. JackClient* client = (JackClient*)ext_client;
  661. if (client == NULL) {
  662. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  663. return -1;
  664. } else {
  665. JackGraphManager* manager = GetGraphManager();
  666. if (!manager)
  667. return -1;
  668. jack_port_id_t myport = manager->GetPort(port_name);
  669. if (!CheckPort(myport)) {
  670. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  671. return -1;
  672. } else {
  673. return manager->RequestMonitor(myport, onoff);
  674. }
  675. }
  676. }
  677. LIB_EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  678. {
  679. #ifdef __CLIENTDEBUG__
  680. JackGlobals::CheckContext("jack_port_ensure_monitor");
  681. #endif
  682. uintptr_t port_aux = (uintptr_t)port;
  683. jack_port_id_t myport = (jack_port_id_t)port_aux;
  684. if (!CheckPort(myport)) {
  685. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  686. return -1;
  687. } else {
  688. JackGraphManager* manager = GetGraphManager();
  689. return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
  690. }
  691. }
  692. LIB_EXPORT int jack_port_monitoring_input(jack_port_t* port)
  693. {
  694. #ifdef __CLIENTDEBUG__
  695. JackGlobals::CheckContext("jack_port_monitoring_input");
  696. #endif
  697. uintptr_t port_aux = (uintptr_t)port;
  698. jack_port_id_t myport = (jack_port_id_t)port_aux;
  699. if (!CheckPort(myport)) {
  700. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  701. return -1;
  702. } else {
  703. JackGraphManager* manager = GetGraphManager();
  704. return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
  705. }
  706. }
  707. LIB_EXPORT int jack_is_realtime(jack_client_t* ext_client)
  708. {
  709. #ifdef __CLIENTDEBUG__
  710. JackGlobals::CheckContext("jack_is_realtime");
  711. #endif
  712. JackClient* client = (JackClient*)ext_client;
  713. if (client == NULL) {
  714. jack_error("jack_is_realtime called with a NULL client");
  715. return -1;
  716. } else {
  717. JackEngineControl* control = GetEngineControl();
  718. return (control ? control->fRealTime : -1);
  719. }
  720. }
  721. LIB_EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
  722. {
  723. #ifdef __CLIENTDEBUG__
  724. JackGlobals::CheckContext("jack_on_shutdown");
  725. #endif
  726. JackClient* client = (JackClient*)ext_client;
  727. if (client == NULL) {
  728. jack_error("jack_on_shutdown called with a NULL client");
  729. } else {
  730. client->OnShutdown(callback, arg);
  731. }
  732. }
  733. LIB_EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
  734. {
  735. #ifdef __CLIENTDEBUG__
  736. JackGlobals::CheckContext("jack_on_info_shutdown");
  737. #endif
  738. JackClient* client = (JackClient*)ext_client;
  739. if (client == NULL) {
  740. jack_error("jack_on_info_shutdown called with a NULL client");
  741. } else {
  742. client->OnInfoShutdown(callback, arg);
  743. }
  744. }
  745. LIB_EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  746. {
  747. #ifdef __CLIENTDEBUG__
  748. JackGlobals::CheckContext("jack_set_process_callback");
  749. #endif
  750. JackClient* client = (JackClient*)ext_client;
  751. if (client == NULL) {
  752. jack_error("jack_set_process_callback called with a NULL client");
  753. return -1;
  754. } else {
  755. return client->SetProcessCallback(callback, arg);
  756. }
  757. }
  758. LIB_EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
  759. {
  760. #ifdef __CLIENTDEBUG__
  761. JackGlobals::CheckContext("jack_thread_wait");
  762. #endif
  763. JackClient* client = (JackClient*)ext_client;
  764. if (client == NULL) {
  765. jack_error("jack_thread_wait called with a NULL client");
  766. return 0;
  767. } else {
  768. jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
  769. return 0;
  770. }
  771. }
  772. LIB_EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
  773. {
  774. #ifdef __CLIENTDEBUG__
  775. JackGlobals::CheckContext("jack_cycle_wait");
  776. #endif
  777. JackClient* client = (JackClient*)ext_client;
  778. if (client == NULL) {
  779. jack_error("jack_cycle_wait called with a NULL client");
  780. return 0;
  781. } else {
  782. return client->CycleWait();
  783. }
  784. }
  785. LIB_EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
  786. {
  787. #ifdef __CLIENTDEBUG__
  788. JackGlobals::CheckContext("jack_cycle_signal");
  789. #endif
  790. JackClient* client = (JackClient*)ext_client;
  791. if (client == NULL) {
  792. jack_error("jack_cycle_signal called with a NULL client");
  793. } else {
  794. client->CycleSignal(status);
  795. }
  796. }
  797. LIB_EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
  798. {
  799. #ifdef __CLIENTDEBUG__
  800. JackGlobals::CheckContext("jack_set_process_thread");
  801. #endif
  802. JackClient* client = (JackClient*)ext_client;
  803. if (client == NULL) {
  804. jack_error("jack_set_process_thread called with a NULL client");
  805. return -1;
  806. } else {
  807. return client->SetProcessThread(fun, arg);
  808. }
  809. }
  810. LIB_EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  811. {
  812. #ifdef __CLIENTDEBUG__
  813. JackGlobals::CheckContext("jack_set_freewheel_callback");
  814. #endif
  815. JackClient* client = (JackClient*)ext_client;
  816. if (client == NULL) {
  817. jack_error("jack_set_freewheel_callback called with a NULL client");
  818. return -1;
  819. } else {
  820. return client->SetFreewheelCallback(freewheel_callback, arg);
  821. }
  822. }
  823. LIB_EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  824. {
  825. #ifdef __CLIENTDEBUG__
  826. JackGlobals::CheckContext("jack_set_freewheel");
  827. #endif
  828. JackClient* client = (JackClient*)ext_client;
  829. if (client == NULL) {
  830. jack_error("jack_set_freewheel called with a NULL client");
  831. return -1;
  832. } else {
  833. return client->SetFreeWheel(onoff);
  834. }
  835. }
  836. LIB_EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  837. {
  838. #ifdef __CLIENTDEBUG__
  839. JackGlobals::CheckContext("jack_set_buffer_size");
  840. #endif
  841. JackClient* client = (JackClient*)ext_client;
  842. if (client == NULL) {
  843. jack_error("jack_set_buffer_size called with a NULL client");
  844. return -1;
  845. } else if (!CheckBufferSize(buffer_size)) {
  846. return -1;
  847. } else {
  848. return client->SetBufferSize(buffer_size);
  849. }
  850. }
  851. LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  852. {
  853. #ifdef __CLIENTDEBUG__
  854. JackGlobals::CheckContext("jack_set_buffer_size_callback");
  855. #endif
  856. JackClient* client = (JackClient*)ext_client;
  857. if (client == NULL) {
  858. jack_error("jack_set_buffer_size_callback called with a NULL client");
  859. return -1;
  860. } else {
  861. return client->SetBufferSizeCallback(bufsize_callback, arg);
  862. }
  863. }
  864. LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  865. {
  866. #ifdef __CLIENTDEBUG__
  867. JackGlobals::CheckContext("jack_set_sample_rate_callback");
  868. #endif
  869. JackClient* client = (JackClient*)ext_client;
  870. if (client == NULL) {
  871. jack_error("jack_set_sample_rate_callback called with a NULL client");
  872. return -1;
  873. } else {
  874. return client->SetSampleRateCallback(srate_callback, arg);
  875. }
  876. }
  877. LIB_EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  878. {
  879. #ifdef __CLIENTDEBUG__
  880. JackGlobals::CheckContext("jack_set_client_registration_callback");
  881. #endif
  882. JackClient* client = (JackClient*)ext_client;
  883. if (client == NULL) {
  884. jack_error("jack_set_client_registration_callback called with a NULL client");
  885. return -1;
  886. } else {
  887. return client->SetClientRegistrationCallback(registration_callback, arg);
  888. }
  889. }
  890. LIB_EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  891. {
  892. #ifdef __CLIENTDEBUG__
  893. JackGlobals::CheckContext("jack_set_port_registration_callback");
  894. #endif
  895. JackClient* client = (JackClient*)ext_client;
  896. if (client == NULL) {
  897. jack_error("jack_set_port_registration_callback called with a NULL client");
  898. return -1;
  899. } else {
  900. return client->SetPortRegistrationCallback(registration_callback, arg);
  901. }
  902. }
  903. LIB_EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
  904. {
  905. #ifdef __CLIENTDEBUG__
  906. JackGlobals::CheckContext("jack_set_port_connect_callback");
  907. #endif
  908. JackClient* client = (JackClient*)ext_client;
  909. if (client == NULL) {
  910. jack_error("jack_set_port_connect_callback called with a NULL client");
  911. return -1;
  912. } else {
  913. return client->SetPortConnectCallback(portconnect_callback, arg);
  914. }
  915. }
  916. LIB_EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
  917. {
  918. #ifdef __CLIENTDEBUG__
  919. JackGlobals::CheckContext("jack_set_port_rename_callback");
  920. #endif
  921. JackClient* client = (JackClient*)ext_client;
  922. if (client == NULL) {
  923. jack_error("jack_set_port_rename_callback called with a NULL client");
  924. return -1;
  925. } else {
  926. return client->SetPortRenameCallback(rename_callback, arg);
  927. }
  928. }
  929. LIB_EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  930. {
  931. #ifdef __CLIENTDEBUG__
  932. JackGlobals::CheckContext("jack_set_graph_order_callback");
  933. #endif
  934. JackClient* client = (JackClient*)ext_client;
  935. jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
  936. if (client == NULL) {
  937. jack_error("jack_set_graph_order_callback called with a NULL client");
  938. return -1;
  939. } else {
  940. return client->SetGraphOrderCallback(graph_callback, arg);
  941. }
  942. }
  943. LIB_EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  944. {
  945. #ifdef __CLIENTDEBUG__
  946. JackGlobals::CheckContext("jack_set_xrun_callback");
  947. #endif
  948. JackClient* client = (JackClient*)ext_client;
  949. if (client == NULL) {
  950. jack_error("jack_set_xrun_callback called with a NULL client");
  951. return -1;
  952. } else {
  953. return client->SetXRunCallback(xrun_callback, arg);
  954. }
  955. }
  956. LIB_EXPORT int jack_set_latency_callback(jack_client_t* ext_client, JackLatencyCallback latency_callback, void *arg)
  957. {
  958. #ifdef __CLIENTDEBUG__
  959. JackGlobals::CheckContext("jack_set_latency_callback");
  960. #endif
  961. JackClient* client = (JackClient*)ext_client;
  962. if (client == NULL) {
  963. jack_error("jack_set_latency_callback called with a NULL client");
  964. return -1;
  965. } else {
  966. return client->SetLatencyCallback(latency_callback, arg);
  967. }
  968. }
  969. LIB_EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  970. {
  971. #ifdef __CLIENTDEBUG__
  972. JackGlobals::CheckContext("jack_set_thread_init_callback");
  973. #endif
  974. JackClient* client = (JackClient*)ext_client;
  975. jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
  976. if (client == NULL) {
  977. jack_error("jack_set_thread_init_callback called with a NULL client");
  978. return -1;
  979. } else {
  980. return client->SetInitCallback(init_callback, arg);
  981. }
  982. }
  983. LIB_EXPORT int jack_activate(jack_client_t* ext_client)
  984. {
  985. #ifdef __CLIENTDEBUG__
  986. JackGlobals::CheckContext("jack_activate");
  987. #endif
  988. JackClient* client = (JackClient*)ext_client;
  989. if (client == NULL) {
  990. jack_error("jack_activate called with a NULL client");
  991. return -1;
  992. } else {
  993. return client->Activate();
  994. }
  995. }
  996. LIB_EXPORT int jack_deactivate(jack_client_t* ext_client)
  997. {
  998. #ifdef __CLIENTDEBUG__
  999. JackGlobals::CheckContext("jack_deactivate");
  1000. #endif
  1001. JackClient* client = (JackClient*)ext_client;
  1002. if (client == NULL) {
  1003. jack_error("jack_deactivate called with a NULL client");
  1004. return -1;
  1005. } else {
  1006. return client->Deactivate();
  1007. }
  1008. }
  1009. 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)
  1010. {
  1011. #ifdef __CLIENTDEBUG__
  1012. JackGlobals::CheckContext("jack_port_register");
  1013. #endif
  1014. JackClient* client = (JackClient*)ext_client;
  1015. if (client == NULL) {
  1016. jack_error("jack_port_register called with a NULL client");
  1017. return NULL;
  1018. } else if ((port_name == NULL) || (port_type == NULL)) {
  1019. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  1020. return NULL;
  1021. } else {
  1022. return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size));
  1023. }
  1024. }
  1025. LIB_EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  1026. {
  1027. #ifdef __CLIENTDEBUG__
  1028. JackGlobals::CheckContext("jack_port_unregister");
  1029. #endif
  1030. JackClient* client = (JackClient*)ext_client;
  1031. if (client == NULL) {
  1032. jack_error("jack_port_unregister called with a NULL client");
  1033. return -1;
  1034. }
  1035. uintptr_t port_aux = (uintptr_t)port;
  1036. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1037. if (!CheckPort(myport)) {
  1038. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  1039. return -1;
  1040. }
  1041. return client->PortUnRegister(myport);
  1042. }
  1043. LIB_EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  1044. {
  1045. #ifdef __CLIENTDEBUG__
  1046. JackGlobals::CheckContext("jack_port_is_mine");
  1047. #endif
  1048. JackClient* client = (JackClient*)ext_client;
  1049. if (client == NULL) {
  1050. jack_error("jack_port_is_mine called with a NULL client");
  1051. return -1;
  1052. }
  1053. uintptr_t port_aux = (uintptr_t)port;
  1054. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1055. if (!CheckPort(myport)) {
  1056. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  1057. return -1;
  1058. }
  1059. return client->PortIsMine(myport);
  1060. }
  1061. LIB_EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  1062. {
  1063. #ifdef __CLIENTDEBUG__
  1064. JackGlobals::CheckContext("jack_port_get_connections");
  1065. #endif
  1066. uintptr_t port_aux = (uintptr_t)port;
  1067. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1068. if (!CheckPort(myport)) {
  1069. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  1070. return NULL;
  1071. } else {
  1072. WaitGraphChange();
  1073. JackGraphManager* manager = GetGraphManager();
  1074. return (manager ? manager->GetConnections(myport) : NULL);
  1075. }
  1076. }
  1077. // Calling client does not need to "own" the port
  1078. LIB_EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  1079. {
  1080. #ifdef __CLIENTDEBUG__
  1081. JackGlobals::CheckContext("jack_port_get_all_connections");
  1082. #endif
  1083. JackClient* client = (JackClient*)ext_client;
  1084. if (client == NULL) {
  1085. jack_error("jack_port_get_all_connections called with a NULL client");
  1086. return NULL;
  1087. }
  1088. uintptr_t port_aux = (uintptr_t)port;
  1089. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1090. if (!CheckPort(myport)) {
  1091. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  1092. return NULL;
  1093. } else {
  1094. WaitGraphChange();
  1095. JackGraphManager* manager = GetGraphManager();
  1096. return (manager ? manager->GetConnections(myport) : NULL);
  1097. }
  1098. }
  1099. LIB_EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  1100. {
  1101. #ifdef __CLIENTDEBUG__
  1102. JackGlobals::CheckContext("jack_port_get_total_latency");
  1103. #endif
  1104. JackClient* client = (JackClient*)ext_client;
  1105. if (client == NULL) {
  1106. jack_error("jack_port_get_total_latency called with a NULL client");
  1107. return 0;
  1108. }
  1109. uintptr_t port_aux = (uintptr_t)port;
  1110. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1111. if (!CheckPort(myport)) {
  1112. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  1113. return 0;
  1114. } else {
  1115. WaitGraphChange();
  1116. JackGraphManager* manager = GetGraphManager();
  1117. if (manager) {
  1118. manager->ComputeTotalLatency(myport);
  1119. return manager->GetPort(myport)->GetTotalLatency();
  1120. } else {
  1121. return 0;
  1122. }
  1123. }
  1124. }
  1125. LIB_EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  1126. {
  1127. #ifdef __CLIENTDEBUG__
  1128. JackGlobals::CheckContext("jack_connect");
  1129. #endif
  1130. JackClient* client = (JackClient*)ext_client;
  1131. if (client == NULL) {
  1132. jack_error("jack_connect called with a NULL client");
  1133. return -1;
  1134. } else if ((src == NULL) || (dst == NULL)) {
  1135. jack_error("jack_connect called with a NULL port name");
  1136. return -1;
  1137. } else {
  1138. return client->PortConnect(src, dst);
  1139. }
  1140. }
  1141. LIB_EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  1142. {
  1143. #ifdef __CLIENTDEBUG__
  1144. JackGlobals::CheckContext("jack_disconnect");
  1145. #endif
  1146. JackClient* client = (JackClient*)ext_client;
  1147. if (client == NULL) {
  1148. jack_error("jack_disconnect called with a NULL client");
  1149. return -1;
  1150. } else if ((src == NULL) || (dst == NULL)) {
  1151. jack_error("jack_connect called with a NULL port name");
  1152. return -1;
  1153. } else {
  1154. return client->PortDisconnect(src, dst);
  1155. }
  1156. }
  1157. LIB_EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  1158. {
  1159. #ifdef __CLIENTDEBUG__
  1160. JackGlobals::CheckContext("jack_port_disconnect");
  1161. #endif
  1162. JackClient* client = (JackClient*)ext_client;
  1163. if (client == NULL) {
  1164. jack_error("jack_port_disconnect called with a NULL client");
  1165. return -1;
  1166. }
  1167. uintptr_t port_aux = (uintptr_t)src;
  1168. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1169. if (!CheckPort(myport)) {
  1170. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  1171. return -1;
  1172. }
  1173. return client->PortDisconnect(myport);
  1174. }
  1175. LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  1176. {
  1177. #ifdef __CLIENTDEBUG__
  1178. JackGlobals::CheckContext("jack_get_sample_rate");
  1179. #endif
  1180. JackClient* client = (JackClient*)ext_client;
  1181. if (client == NULL) {
  1182. jack_error("jack_get_sample_rate called with a NULL client");
  1183. return 0;
  1184. } else {
  1185. JackEngineControl* control = GetEngineControl();
  1186. return (control ? control->fSampleRate : 0);
  1187. }
  1188. }
  1189. LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  1190. {
  1191. #ifdef __CLIENTDEBUG__
  1192. JackGlobals::CheckContext("jack_get_buffer_size");
  1193. #endif
  1194. JackClient* client = (JackClient*)ext_client;
  1195. if (client == NULL) {
  1196. jack_error("jack_get_buffer_size called with a NULL client");
  1197. return 0;
  1198. } else {
  1199. JackEngineControl* control = GetEngineControl();
  1200. return (control ? control->fBufferSize : 0);
  1201. }
  1202. }
  1203. 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)
  1204. {
  1205. #ifdef __CLIENTDEBUG__
  1206. JackGlobals::CheckContext("jack_get_ports");
  1207. #endif
  1208. JackClient* client = (JackClient*)ext_client;
  1209. if (client == NULL) {
  1210. jack_error("jack_get_ports called with a NULL client");
  1211. return NULL;
  1212. }
  1213. JackGraphManager* manager = GetGraphManager();
  1214. return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
  1215. }
  1216. LIB_EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  1217. {
  1218. #ifdef __CLIENTDEBUG__
  1219. JackGlobals::CheckContext("jack_port_by_name");
  1220. #endif
  1221. JackClient* client = (JackClient*)ext_client;
  1222. if (client == NULL) {
  1223. jack_error("jack_get_ports called with a NULL client");
  1224. return 0;
  1225. }
  1226. if (portname == NULL) {
  1227. jack_error("jack_port_by_name called with a NULL port name");
  1228. return NULL;
  1229. } else {
  1230. JackGraphManager* manager = GetGraphManager();
  1231. if (!manager)
  1232. return NULL;
  1233. int res = manager->GetPort(portname); // returns a port index at least > 1
  1234. return (res == NO_PORT) ? NULL : (jack_port_t*)((uintptr_t)res);
  1235. }
  1236. }
  1237. LIB_EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  1238. {
  1239. #ifdef __CLIENTDEBUG__
  1240. JackGlobals::CheckContext("jack_port_by_id");
  1241. #endif
  1242. /* jack_port_t* type is actually the port index */
  1243. return (jack_port_t*)((uintptr_t)id);
  1244. }
  1245. LIB_EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  1246. {
  1247. #ifdef __CLIENTDEBUG__
  1248. JackGlobals::CheckContext("jack_engine_takeover_timebase");
  1249. #endif
  1250. JackClient* client = (JackClient*)ext_client;
  1251. if (client == NULL) {
  1252. jack_error("jack_engine_takeover_timebase called with a NULL client");
  1253. return -1;
  1254. } else {
  1255. jack_error("jack_engine_takeover_timebase: deprecated\n");
  1256. return 0;
  1257. }
  1258. }
  1259. LIB_EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  1260. {
  1261. #ifdef __CLIENTDEBUG__
  1262. JackGlobals::CheckContext("jack_frames_since_cycle_start");
  1263. #endif
  1264. JackTimer timer;
  1265. JackEngineControl* control = GetEngineControl();
  1266. if (control) {
  1267. control->ReadFrameTime(&timer);
  1268. return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
  1269. } else {
  1270. return 0;
  1271. }
  1272. }
  1273. LIB_EXPORT jack_time_t jack_get_time()
  1274. {
  1275. #ifdef __CLIENTDEBUG__
  1276. JackGlobals::CheckContext("jack_get_time");
  1277. #endif
  1278. return GetMicroSeconds();
  1279. }
  1280. LIB_EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1281. {
  1282. #ifdef __CLIENTDEBUG__
  1283. JackGlobals::CheckContext("jack_frames_to_time");
  1284. #endif
  1285. JackClient* client = (JackClient*)ext_client;
  1286. if (client == NULL) {
  1287. jack_error("jack_frames_to_time called with a NULL client");
  1288. return 0;
  1289. } else {
  1290. JackTimer timer;
  1291. JackEngineControl* control = GetEngineControl();
  1292. if (control) {
  1293. control->ReadFrameTime(&timer);
  1294. return timer.Frames2Time(frames, control->fBufferSize);
  1295. } else {
  1296. return 0;
  1297. }
  1298. }
  1299. }
  1300. LIB_EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1301. {
  1302. #ifdef __CLIENTDEBUG__
  1303. JackGlobals::CheckContext("jack_time_to_frames");
  1304. #endif
  1305. JackClient* client = (JackClient*)ext_client;
  1306. if (client == NULL) {
  1307. jack_error("jack_time_to_frames called with a NULL client");
  1308. return 0;
  1309. } else {
  1310. JackTimer timer;
  1311. JackEngineControl* control = GetEngineControl();
  1312. if (control) {
  1313. control->ReadFrameTime(&timer);
  1314. return timer.Time2Frames(time, control->fBufferSize);
  1315. } else {
  1316. return 0;
  1317. }
  1318. }
  1319. }
  1320. LIB_EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1321. {
  1322. #ifdef __CLIENTDEBUG__
  1323. JackGlobals::CheckContext("jack_frame_time");
  1324. #endif
  1325. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1326. }
  1327. LIB_EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1328. {
  1329. #ifdef __CLIENTDEBUG__
  1330. JackGlobals::CheckContext("jack_last_frame_time");
  1331. #endif
  1332. JackEngineControl* control = GetEngineControl();
  1333. return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
  1334. }
  1335. LIB_EXPORT float jack_cpu_load(jack_client_t* ext_client)
  1336. {
  1337. #ifdef __CLIENTDEBUG__
  1338. JackGlobals::CheckContext("jack_cpu_load");
  1339. #endif
  1340. JackClient* client = (JackClient*)ext_client;
  1341. if (client == NULL) {
  1342. jack_error("jack_cpu_load called with a NULL client");
  1343. return 0.0f;
  1344. } else {
  1345. JackEngineControl* control = GetEngineControl();
  1346. return (control ? control->fCPULoad : 0.0f);
  1347. }
  1348. }
  1349. LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t* ext_client)
  1350. {
  1351. #ifdef __CLIENTDEBUG__
  1352. JackGlobals::CheckContext("jack_client_thread_id");
  1353. #endif
  1354. JackClient* client = (JackClient*)ext_client;
  1355. if (client == NULL) {
  1356. jack_error("jack_client_thread_id called with a NULL client");
  1357. return (jack_native_thread_t)NULL;
  1358. } else {
  1359. return client->GetThreadID();
  1360. }
  1361. }
  1362. LIB_EXPORT char* jack_get_client_name(jack_client_t* ext_client)
  1363. {
  1364. #ifdef __CLIENTDEBUG__
  1365. JackGlobals::CheckContext("jack_get_client_name");
  1366. #endif
  1367. JackClient* client = (JackClient*)ext_client;
  1368. if (client == NULL) {
  1369. jack_error("jack_get_client_name called with a NULL client");
  1370. return NULL;
  1371. } else {
  1372. return client->GetClientControl()->fName;
  1373. }
  1374. }
  1375. LIB_EXPORT int jack_client_name_size(void)
  1376. {
  1377. return JACK_CLIENT_NAME_SIZE;
  1378. }
  1379. LIB_EXPORT int jack_port_name_size(void)
  1380. {
  1381. return REAL_JACK_PORT_NAME_SIZE;
  1382. }
  1383. LIB_EXPORT int jack_port_type_size(void)
  1384. {
  1385. return JACK_PORT_TYPE_SIZE;
  1386. }
  1387. LIB_EXPORT size_t jack_port_type_get_buffer_size(jack_client_t* ext_client, const char* port_type)
  1388. {
  1389. #ifdef __CLIENTDEBUG__
  1390. JackGlobals::CheckContext("jack_port_type_get_buffer_size");
  1391. #endif
  1392. JackClient* client = (JackClient*)ext_client;
  1393. if (client == NULL) {
  1394. jack_error("jack_port_type_get_buffer_size called with a NULL client");
  1395. return 0;
  1396. } else {
  1397. jack_port_type_id_t port_id = GetPortTypeId(port_type);
  1398. if (port_id == PORT_TYPES_MAX) {
  1399. jack_error("jack_port_type_get_buffer_size called with an unknown port type = %s", port_type);
  1400. return 0;
  1401. } else {
  1402. return GetPortType(port_id)->size();
  1403. }
  1404. }
  1405. }
  1406. // transport.h
  1407. LIB_EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1408. {
  1409. #ifdef __CLIENTDEBUG__
  1410. JackGlobals::CheckContext("jack_release_timebase");
  1411. #endif
  1412. JackClient* client = (JackClient*)ext_client;
  1413. if (client == NULL) {
  1414. jack_error("jack_release_timebase called with a NULL client");
  1415. return -1;
  1416. } else {
  1417. return client->ReleaseTimebase();
  1418. }
  1419. }
  1420. LIB_EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1421. {
  1422. #ifdef __CLIENTDEBUG__
  1423. JackGlobals::CheckContext("jack_set_sync_callback");
  1424. #endif
  1425. JackClient* client = (JackClient*)ext_client;
  1426. if (client == NULL) {
  1427. jack_error("jack_set_sync_callback called with a NULL client");
  1428. return -1;
  1429. } else {
  1430. return client->SetSyncCallback(sync_callback, arg);
  1431. }
  1432. }
  1433. LIB_EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1434. {
  1435. #ifdef __CLIENTDEBUG__
  1436. JackGlobals::CheckContext("jack_set_sync_timeout");
  1437. #endif
  1438. JackClient* client = (JackClient*)ext_client;
  1439. if (client == NULL) {
  1440. jack_error("jack_set_sync_timeout called with a NULL client");
  1441. return -1;
  1442. } else {
  1443. return client->SetSyncTimeout(timeout);
  1444. }
  1445. }
  1446. LIB_EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1447. {
  1448. #ifdef __CLIENTDEBUG__
  1449. JackGlobals::CheckContext("jack_set_timebase_callback");
  1450. #endif
  1451. JackClient* client = (JackClient*)ext_client;
  1452. if (client == NULL) {
  1453. jack_error("jack_set_timebase_callback called with a NULL client");
  1454. return -1;
  1455. } else {
  1456. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1457. }
  1458. }
  1459. LIB_EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1460. {
  1461. #ifdef __CLIENTDEBUG__
  1462. JackGlobals::CheckContext("jack_transport_locate");
  1463. #endif
  1464. JackClient* client = (JackClient*)ext_client;
  1465. if (client == NULL) {
  1466. jack_error("jack_transport_locate called with a NULL client");
  1467. return -1;
  1468. } else {
  1469. client->TransportLocate(frame);
  1470. return 0;
  1471. }
  1472. }
  1473. LIB_EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1474. {
  1475. #ifdef __CLIENTDEBUG__
  1476. JackGlobals::CheckContext("jack_transport_query");
  1477. #endif
  1478. JackClient* client = (JackClient*)ext_client;
  1479. if (client == NULL) {
  1480. jack_error("jack_transport_query called with a NULL client");
  1481. return JackTransportStopped;
  1482. } else {
  1483. return client->TransportQuery(pos);
  1484. }
  1485. }
  1486. LIB_EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1487. {
  1488. #ifdef __CLIENTDEBUG__
  1489. JackGlobals::CheckContext("jack_get_current_transport_frame");
  1490. #endif
  1491. JackClient* client = (JackClient*)ext_client;
  1492. if (client == NULL) {
  1493. jack_error("jack_get_current_transport_frame called with a NULL client");
  1494. return 0;
  1495. } else {
  1496. return client->GetCurrentTransportFrame();
  1497. }
  1498. }
  1499. LIB_EXPORT int jack_transport_reposition(jack_client_t* ext_client, const jack_position_t* pos)
  1500. {
  1501. #ifdef __CLIENTDEBUG__
  1502. JackGlobals::CheckContext("jack_transport_reposition");
  1503. #endif
  1504. JackClient* client = (JackClient*)ext_client;
  1505. if (client == NULL) {
  1506. jack_error("jack_transport_reposition called with a NULL client");
  1507. return -1;
  1508. } else {
  1509. client->TransportReposition(pos);
  1510. return 0;
  1511. }
  1512. }
  1513. LIB_EXPORT void jack_transport_start(jack_client_t* ext_client)
  1514. {
  1515. #ifdef __CLIENTDEBUG__
  1516. JackGlobals::CheckContext("jack_transport_start");
  1517. #endif
  1518. JackClient* client = (JackClient*)ext_client;
  1519. if (client == NULL) {
  1520. jack_error("jack_transport_start called with a NULL client");
  1521. } else {
  1522. client->TransportStart();
  1523. }
  1524. }
  1525. LIB_EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1526. {
  1527. #ifdef __CLIENTDEBUG__
  1528. JackGlobals::CheckContext("jack_transport_stop");
  1529. #endif
  1530. JackClient* client = (JackClient*)ext_client;
  1531. if (client == NULL) {
  1532. jack_error("jack_transport_stop called with a NULL client");
  1533. } else {
  1534. client->TransportStop();
  1535. }
  1536. }
  1537. // deprecated
  1538. LIB_EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1539. {
  1540. #ifdef __CLIENTDEBUG__
  1541. JackGlobals::CheckContext("jack_get_transport_info");
  1542. #endif
  1543. jack_error("jack_get_transport_info: deprecated");
  1544. if (tinfo)
  1545. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1546. }
  1547. LIB_EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1548. {
  1549. #ifdef __CLIENTDEBUG__
  1550. JackGlobals::CheckContext("jack_set_transport_info");
  1551. #endif
  1552. jack_error("jack_set_transport_info: deprecated");
  1553. if (tinfo)
  1554. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1555. }
  1556. // statistics.h
  1557. LIB_EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1558. {
  1559. #ifdef __CLIENTDEBUG__
  1560. JackGlobals::CheckContext("jack_get_max_delayed_usecs");
  1561. #endif
  1562. JackClient* client = (JackClient*)ext_client;
  1563. if (client == NULL) {
  1564. jack_error("jack_get_max_delayed_usecs called with a NULL client");
  1565. return 0.f;
  1566. } else {
  1567. JackEngineControl* control = GetEngineControl();
  1568. return (control ? control->fMaxDelayedUsecs : 0.f);
  1569. }
  1570. }
  1571. LIB_EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1572. {
  1573. #ifdef __CLIENTDEBUG__
  1574. JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
  1575. #endif
  1576. JackClient* client = (JackClient*)ext_client;
  1577. if (client == NULL) {
  1578. jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
  1579. return 0.f;
  1580. } else {
  1581. JackEngineControl* control = GetEngineControl();
  1582. return (control ? control->fXrunDelayedUsecs : 0.f);
  1583. }
  1584. }
  1585. LIB_EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1586. {
  1587. #ifdef __CLIENTDEBUG__
  1588. JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
  1589. #endif
  1590. JackClient* client = (JackClient*)ext_client;
  1591. if (client == NULL) {
  1592. jack_error("jack_reset_max_delayed_usecs called with a NULL client");
  1593. } else {
  1594. JackEngineControl* control = GetEngineControl();
  1595. control->ResetXRun();
  1596. }
  1597. }
  1598. // thread.h
  1599. LIB_EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
  1600. {
  1601. #ifdef __CLIENTDEBUG__
  1602. JackGlobals::CheckContext("jack_client_real_time_priority");
  1603. #endif
  1604. JackClient* client = (JackClient*)ext_client;
  1605. if (client == NULL) {
  1606. jack_error("jack_client_real_time_priority called with a NULL client");
  1607. return -1;
  1608. } else {
  1609. JackEngineControl* control = GetEngineControl();
  1610. return (control->fRealTime) ? control->fClientPriority : -1;
  1611. }
  1612. }
  1613. LIB_EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
  1614. {
  1615. #ifdef __CLIENTDEBUG__
  1616. JackGlobals::CheckContext("jack_client_max_real_time_priority");
  1617. #endif
  1618. JackClient* client = (JackClient*)ext_client;
  1619. if (client == NULL) {
  1620. jack_error("jack_client_max_real_time_priority called with a NULL client");
  1621. return -1;
  1622. } else {
  1623. JackEngineControl* control = GetEngineControl();
  1624. return (control->fRealTime) ? control->fMaxClientPriority : -1;
  1625. }
  1626. }
  1627. LIB_EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority)
  1628. {
  1629. JackEngineControl* control = GetEngineControl();
  1630. return (control
  1631. ? JackThread::AcquireRealTimeImp(thread, priority, control->fPeriod, control->fComputation, control->fConstraint)
  1632. : -1);
  1633. }
  1634. LIB_EXPORT int jack_client_create_thread(jack_client_t* client,
  1635. jack_native_thread_t *thread,
  1636. int priority,
  1637. int realtime, /* boolean */
  1638. thread_routine routine,
  1639. void *arg)
  1640. {
  1641. #ifdef __CLIENTDEBUG__
  1642. JackGlobals::CheckContext("jack_client_create_thread");
  1643. #endif
  1644. JackEngineControl* control = GetEngineControl();
  1645. int res = JackThread::StartImp(thread, priority, realtime, routine, arg);
  1646. return (res == 0)
  1647. ? ((realtime ? JackThread::AcquireRealTimeImp(*thread, priority, control->fPeriod, control->fComputation, control->fConstraint) : res))
  1648. : res;
  1649. }
  1650. LIB_EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread)
  1651. {
  1652. return JackThread::DropRealTimeImp(thread);
  1653. }
  1654. LIB_EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread)
  1655. {
  1656. #ifdef __CLIENTDEBUG__
  1657. JackGlobals::CheckContext("jack_client_stop_thread");
  1658. #endif
  1659. return JackThread::StopImp(thread);
  1660. }
  1661. LIB_EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread)
  1662. {
  1663. #ifdef __CLIENTDEBUG__
  1664. JackGlobals::CheckContext("jack_client_kill_thread");
  1665. #endif
  1666. return JackThread::KillImp(thread);
  1667. }
  1668. #ifndef WIN32
  1669. LIB_EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
  1670. {
  1671. if (jtc == NULL) {
  1672. JackGlobals::fJackThreadCreator = pthread_create;
  1673. } else {
  1674. JackGlobals::fJackThreadCreator = jtc;
  1675. }
  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. static 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. }