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