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.

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