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.

2126 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. JackClient* client = NULL;
  589. for (int i = 0; i < CLIENT_NUM; i++) {
  590. // Find a valid client
  591. if ((client = JackGlobals::fClientTable[i])) {
  592. break;
  593. }
  594. }
  595. return (client) ? client->PortRename(myport, name) : -1;
  596. }
  597. }
  598. LIB_EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
  599. {
  600. #ifdef __CLIENTDEBUG__
  601. JackGlobals::CheckContext("jack_port_set_alias");
  602. #endif
  603. uintptr_t port_aux = (uintptr_t)port;
  604. jack_port_id_t myport = (jack_port_id_t)port_aux;
  605. if (!CheckPort(myport)) {
  606. jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
  607. return -1;
  608. } else if (name == NULL) {
  609. jack_error("jack_port_set_alias called with a NULL port name");
  610. return -1;
  611. } else {
  612. JackGraphManager* manager = GetGraphManager();
  613. return (manager ? manager->GetPort(myport)->SetAlias(name) : -1);
  614. }
  615. }
  616. LIB_EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
  617. {
  618. #ifdef __CLIENTDEBUG__
  619. JackGlobals::CheckContext("jack_port_unset_alias");
  620. #endif
  621. uintptr_t port_aux = (uintptr_t)port;
  622. jack_port_id_t myport = (jack_port_id_t)port_aux;
  623. if (!CheckPort(myport)) {
  624. jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
  625. return -1;
  626. } else if (name == NULL) {
  627. jack_error("jack_port_unset_alias called with a NULL port name");
  628. return -1;
  629. } else {
  630. JackGraphManager* manager = GetGraphManager();
  631. return (manager ? manager->GetPort(myport)->UnsetAlias(name) : -1);
  632. }
  633. }
  634. LIB_EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  635. {
  636. #ifdef __CLIENTDEBUG__
  637. JackGlobals::CheckContext("jack_port_get_aliases");
  638. #endif
  639. uintptr_t port_aux = (uintptr_t)port;
  640. jack_port_id_t myport = (jack_port_id_t)port_aux;
  641. if (!CheckPort(myport)) {
  642. jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
  643. return -1;
  644. } else {
  645. JackGraphManager* manager = GetGraphManager();
  646. return (manager ? manager->GetPort(myport)->GetAliases(aliases) : -1);
  647. }
  648. }
  649. LIB_EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  650. {
  651. #ifdef __CLIENTDEBUG__
  652. JackGlobals::CheckContext("jack_port_request_monitor");
  653. #endif
  654. uintptr_t port_aux = (uintptr_t)port;
  655. jack_port_id_t myport = (jack_port_id_t)port_aux;
  656. if (!CheckPort(myport)) {
  657. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  658. return -1;
  659. } else {
  660. JackGraphManager* manager = GetGraphManager();
  661. return (manager ? manager->RequestMonitor(myport, onoff) : -1);
  662. }
  663. }
  664. LIB_EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  665. {
  666. #ifdef __CLIENTDEBUG__
  667. JackGlobals::CheckContext("jack_port_request_monitor_by_name");
  668. #endif
  669. JackClient* client = (JackClient*)ext_client;
  670. if (client == NULL) {
  671. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  672. return -1;
  673. } else {
  674. JackGraphManager* manager = GetGraphManager();
  675. if (!manager)
  676. return -1;
  677. jack_port_id_t myport = manager->GetPort(port_name);
  678. if (!CheckPort(myport)) {
  679. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  680. return -1;
  681. } else {
  682. return manager->RequestMonitor(myport, onoff);
  683. }
  684. }
  685. }
  686. LIB_EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  687. {
  688. #ifdef __CLIENTDEBUG__
  689. JackGlobals::CheckContext("jack_port_ensure_monitor");
  690. #endif
  691. uintptr_t port_aux = (uintptr_t)port;
  692. jack_port_id_t myport = (jack_port_id_t)port_aux;
  693. if (!CheckPort(myport)) {
  694. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  695. return -1;
  696. } else {
  697. JackGraphManager* manager = GetGraphManager();
  698. return (manager ? manager->GetPort(myport)->EnsureMonitor(onoff) : -1);
  699. }
  700. }
  701. LIB_EXPORT int jack_port_monitoring_input(jack_port_t* port)
  702. {
  703. #ifdef __CLIENTDEBUG__
  704. JackGlobals::CheckContext("jack_port_monitoring_input");
  705. #endif
  706. uintptr_t port_aux = (uintptr_t)port;
  707. jack_port_id_t myport = (jack_port_id_t)port_aux;
  708. if (!CheckPort(myport)) {
  709. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  710. return -1;
  711. } else {
  712. JackGraphManager* manager = GetGraphManager();
  713. return (manager ? manager->GetPort(myport)->MonitoringInput() : -1);
  714. }
  715. }
  716. LIB_EXPORT int jack_is_realtime(jack_client_t* ext_client)
  717. {
  718. #ifdef __CLIENTDEBUG__
  719. JackGlobals::CheckContext("jack_is_realtime");
  720. #endif
  721. JackClient* client = (JackClient*)ext_client;
  722. if (client == NULL) {
  723. jack_error("jack_is_realtime called with a NULL client");
  724. return -1;
  725. } else {
  726. JackEngineControl* control = GetEngineControl();
  727. return (control ? control->fRealTime : -1);
  728. }
  729. }
  730. LIB_EXPORT void jack_on_shutdown(jack_client_t* ext_client, JackShutdownCallback callback, void* arg)
  731. {
  732. #ifdef __CLIENTDEBUG__
  733. JackGlobals::CheckContext("jack_on_shutdown");
  734. #endif
  735. JackClient* client = (JackClient*)ext_client;
  736. if (client == NULL) {
  737. jack_error("jack_on_shutdown called with a NULL client");
  738. } else {
  739. client->OnShutdown(callback, arg);
  740. }
  741. }
  742. LIB_EXPORT void jack_on_info_shutdown(jack_client_t* ext_client, JackInfoShutdownCallback callback, void* arg)
  743. {
  744. #ifdef __CLIENTDEBUG__
  745. JackGlobals::CheckContext("jack_on_info_shutdown");
  746. #endif
  747. JackClient* client = (JackClient*)ext_client;
  748. if (client == NULL) {
  749. jack_error("jack_on_info_shutdown called with a NULL client");
  750. } else {
  751. client->OnInfoShutdown(callback, arg);
  752. }
  753. }
  754. LIB_EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  755. {
  756. #ifdef __CLIENTDEBUG__
  757. JackGlobals::CheckContext("jack_set_process_callback");
  758. #endif
  759. JackClient* client = (JackClient*)ext_client;
  760. if (client == NULL) {
  761. jack_error("jack_set_process_callback called with a NULL client");
  762. return -1;
  763. } else {
  764. return client->SetProcessCallback(callback, arg);
  765. }
  766. }
  767. LIB_EXPORT jack_nframes_t jack_thread_wait(jack_client_t* ext_client, int status)
  768. {
  769. #ifdef __CLIENTDEBUG__
  770. JackGlobals::CheckContext("jack_thread_wait");
  771. #endif
  772. JackClient* client = (JackClient*)ext_client;
  773. if (client == NULL) {
  774. jack_error("jack_thread_wait called with a NULL client");
  775. return 0;
  776. } else {
  777. jack_error("jack_thread_wait: deprecated, use jack_cycle_wait/jack_cycle_signal");
  778. return 0;
  779. }
  780. }
  781. LIB_EXPORT jack_nframes_t jack_cycle_wait(jack_client_t* ext_client)
  782. {
  783. #ifdef __CLIENTDEBUG__
  784. JackGlobals::CheckContext("jack_cycle_wait");
  785. #endif
  786. JackClient* client = (JackClient*)ext_client;
  787. if (client == NULL) {
  788. jack_error("jack_cycle_wait called with a NULL client");
  789. return 0;
  790. } else {
  791. return client->CycleWait();
  792. }
  793. }
  794. LIB_EXPORT void jack_cycle_signal(jack_client_t* ext_client, int status)
  795. {
  796. #ifdef __CLIENTDEBUG__
  797. JackGlobals::CheckContext("jack_cycle_signal");
  798. #endif
  799. JackClient* client = (JackClient*)ext_client;
  800. if (client == NULL) {
  801. jack_error("jack_cycle_signal called with a NULL client");
  802. } else {
  803. client->CycleSignal(status);
  804. }
  805. }
  806. LIB_EXPORT int jack_set_process_thread(jack_client_t* ext_client, JackThreadCallback fun, void *arg)
  807. {
  808. #ifdef __CLIENTDEBUG__
  809. JackGlobals::CheckContext("jack_set_process_thread");
  810. #endif
  811. JackClient* client = (JackClient*)ext_client;
  812. if (client == NULL) {
  813. jack_error("jack_set_process_thread called with a NULL client");
  814. return -1;
  815. } else {
  816. return client->SetProcessThread(fun, arg);
  817. }
  818. }
  819. LIB_EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  820. {
  821. #ifdef __CLIENTDEBUG__
  822. JackGlobals::CheckContext("jack_set_freewheel_callback");
  823. #endif
  824. JackClient* client = (JackClient*)ext_client;
  825. if (client == NULL) {
  826. jack_error("jack_set_freewheel_callback called with a NULL client");
  827. return -1;
  828. } else {
  829. return client->SetFreewheelCallback(freewheel_callback, arg);
  830. }
  831. }
  832. LIB_EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  833. {
  834. #ifdef __CLIENTDEBUG__
  835. JackGlobals::CheckContext("jack_set_freewheel");
  836. #endif
  837. JackClient* client = (JackClient*)ext_client;
  838. if (client == NULL) {
  839. jack_error("jack_set_freewheel called with a NULL client");
  840. return -1;
  841. } else {
  842. return client->SetFreeWheel(onoff);
  843. }
  844. }
  845. LIB_EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  846. {
  847. #ifdef __CLIENTDEBUG__
  848. JackGlobals::CheckContext("jack_set_buffer_size");
  849. #endif
  850. JackClient* client = (JackClient*)ext_client;
  851. if (client == NULL) {
  852. jack_error("jack_set_buffer_size called with a NULL client");
  853. return -1;
  854. } else if (!CheckBufferSize(buffer_size)) {
  855. return -1;
  856. } else {
  857. return client->SetBufferSize(buffer_size);
  858. }
  859. }
  860. LIB_EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  861. {
  862. #ifdef __CLIENTDEBUG__
  863. JackGlobals::CheckContext("jack_set_buffer_size_callback");
  864. #endif
  865. JackClient* client = (JackClient*)ext_client;
  866. if (client == NULL) {
  867. jack_error("jack_set_buffer_size_callback called with a NULL client");
  868. return -1;
  869. } else {
  870. return client->SetBufferSizeCallback(bufsize_callback, arg);
  871. }
  872. }
  873. LIB_EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  874. {
  875. #ifdef __CLIENTDEBUG__
  876. JackGlobals::CheckContext("jack_set_sample_rate_callback");
  877. #endif
  878. JackClient* client = (JackClient*)ext_client;
  879. if (client == NULL) {
  880. jack_error("jack_set_sample_rate_callback called with a NULL client");
  881. return -1;
  882. } else {
  883. return client->SetSampleRateCallback(srate_callback, arg);
  884. }
  885. }
  886. LIB_EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  887. {
  888. #ifdef __CLIENTDEBUG__
  889. JackGlobals::CheckContext("jack_set_client_registration_callback");
  890. #endif
  891. JackClient* client = (JackClient*)ext_client;
  892. if (client == NULL) {
  893. jack_error("jack_set_client_registration_callback called with a NULL client");
  894. return -1;
  895. } else {
  896. return client->SetClientRegistrationCallback(registration_callback, arg);
  897. }
  898. }
  899. LIB_EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  900. {
  901. #ifdef __CLIENTDEBUG__
  902. JackGlobals::CheckContext("jack_set_port_registration_callback");
  903. #endif
  904. JackClient* client = (JackClient*)ext_client;
  905. if (client == NULL) {
  906. jack_error("jack_set_port_registration_callback called with a NULL client");
  907. return -1;
  908. } else {
  909. return client->SetPortRegistrationCallback(registration_callback, arg);
  910. }
  911. }
  912. LIB_EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
  913. {
  914. #ifdef __CLIENTDEBUG__
  915. JackGlobals::CheckContext("jack_set_port_connect_callback");
  916. #endif
  917. JackClient* client = (JackClient*)ext_client;
  918. if (client == NULL) {
  919. jack_error("jack_set_port_connect_callback called with a NULL client");
  920. return -1;
  921. } else {
  922. return client->SetPortConnectCallback(portconnect_callback, arg);
  923. }
  924. }
  925. LIB_EXPORT int jack_set_port_rename_callback(jack_client_t* ext_client, JackPortRenameCallback rename_callback, void* arg)
  926. {
  927. #ifdef __CLIENTDEBUG__
  928. JackGlobals::CheckContext("jack_set_port_rename_callback");
  929. #endif
  930. JackClient* client = (JackClient*)ext_client;
  931. if (client == NULL) {
  932. jack_error("jack_set_port_rename_callback called with a NULL client");
  933. return -1;
  934. } else {
  935. return client->SetPortRenameCallback(rename_callback, arg);
  936. }
  937. }
  938. LIB_EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  939. {
  940. #ifdef __CLIENTDEBUG__
  941. JackGlobals::CheckContext("jack_set_graph_order_callback");
  942. #endif
  943. JackClient* client = (JackClient*)ext_client;
  944. jack_log("jack_set_graph_order_callback ext_client %x client %x ", ext_client, client);
  945. if (client == NULL) {
  946. jack_error("jack_set_graph_order_callback called with a NULL client");
  947. return -1;
  948. } else {
  949. return client->SetGraphOrderCallback(graph_callback, arg);
  950. }
  951. }
  952. LIB_EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  953. {
  954. #ifdef __CLIENTDEBUG__
  955. JackGlobals::CheckContext("jack_set_xrun_callback");
  956. #endif
  957. JackClient* client = (JackClient*)ext_client;
  958. if (client == NULL) {
  959. jack_error("jack_set_xrun_callback called with a NULL client");
  960. return -1;
  961. } else {
  962. return client->SetXRunCallback(xrun_callback, arg);
  963. }
  964. }
  965. LIB_EXPORT int jack_set_latency_callback(jack_client_t* ext_client, JackLatencyCallback latency_callback, void *arg)
  966. {
  967. #ifdef __CLIENTDEBUG__
  968. JackGlobals::CheckContext("jack_set_latency_callback");
  969. #endif
  970. JackClient* client = (JackClient*)ext_client;
  971. if (client == NULL) {
  972. jack_error("jack_set_latency_callback called with a NULL client");
  973. return -1;
  974. } else {
  975. return client->SetLatencyCallback(latency_callback, arg);
  976. }
  977. }
  978. LIB_EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  979. {
  980. #ifdef __CLIENTDEBUG__
  981. JackGlobals::CheckContext("jack_set_thread_init_callback");
  982. #endif
  983. JackClient* client = (JackClient*)ext_client;
  984. jack_log("jack_set_thread_init_callback ext_client %x client %x ", ext_client, client);
  985. if (client == NULL) {
  986. jack_error("jack_set_thread_init_callback called with a NULL client");
  987. return -1;
  988. } else {
  989. return client->SetInitCallback(init_callback, arg);
  990. }
  991. }
  992. LIB_EXPORT int jack_activate(jack_client_t* ext_client)
  993. {
  994. #ifdef __CLIENTDEBUG__
  995. JackGlobals::CheckContext("jack_activate");
  996. #endif
  997. JackClient* client = (JackClient*)ext_client;
  998. if (client == NULL) {
  999. jack_error("jack_activate called with a NULL client");
  1000. return -1;
  1001. } else {
  1002. return client->Activate();
  1003. }
  1004. }
  1005. LIB_EXPORT int jack_deactivate(jack_client_t* ext_client)
  1006. {
  1007. #ifdef __CLIENTDEBUG__
  1008. JackGlobals::CheckContext("jack_deactivate");
  1009. #endif
  1010. JackClient* client = (JackClient*)ext_client;
  1011. if (client == NULL) {
  1012. jack_error("jack_deactivate called with a NULL client");
  1013. return -1;
  1014. } else {
  1015. return client->Deactivate();
  1016. }
  1017. }
  1018. 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)
  1019. {
  1020. #ifdef __CLIENTDEBUG__
  1021. JackGlobals::CheckContext("jack_port_register");
  1022. #endif
  1023. JackClient* client = (JackClient*)ext_client;
  1024. if (client == NULL) {
  1025. jack_error("jack_port_register called with a NULL client");
  1026. return NULL;
  1027. } else if ((port_name == NULL) || (port_type == NULL)) {
  1028. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  1029. return NULL;
  1030. } else {
  1031. return (jack_port_t *)((uintptr_t)client->PortRegister(port_name, port_type, flags, buffer_size));
  1032. }
  1033. }
  1034. LIB_EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  1035. {
  1036. #ifdef __CLIENTDEBUG__
  1037. JackGlobals::CheckContext("jack_port_unregister");
  1038. #endif
  1039. JackClient* client = (JackClient*)ext_client;
  1040. if (client == NULL) {
  1041. jack_error("jack_port_unregister called with a NULL client");
  1042. return -1;
  1043. }
  1044. uintptr_t port_aux = (uintptr_t)port;
  1045. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1046. if (!CheckPort(myport)) {
  1047. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  1048. return -1;
  1049. }
  1050. return client->PortUnRegister(myport);
  1051. }
  1052. LIB_EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  1053. {
  1054. #ifdef __CLIENTDEBUG__
  1055. JackGlobals::CheckContext("jack_port_is_mine");
  1056. #endif
  1057. JackClient* client = (JackClient*)ext_client;
  1058. if (client == NULL) {
  1059. jack_error("jack_port_is_mine called with a NULL client");
  1060. return -1;
  1061. }
  1062. uintptr_t port_aux = (uintptr_t)port;
  1063. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1064. if (!CheckPort(myport)) {
  1065. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  1066. return -1;
  1067. }
  1068. return client->PortIsMine(myport);
  1069. }
  1070. LIB_EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  1071. {
  1072. #ifdef __CLIENTDEBUG__
  1073. JackGlobals::CheckContext("jack_port_get_connections");
  1074. #endif
  1075. uintptr_t port_aux = (uintptr_t)port;
  1076. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1077. if (!CheckPort(myport)) {
  1078. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  1079. return NULL;
  1080. } else {
  1081. WaitGraphChange();
  1082. JackGraphManager* manager = GetGraphManager();
  1083. return (manager ? manager->GetConnections(myport) : NULL);
  1084. }
  1085. }
  1086. // Calling client does not need to "own" the port
  1087. LIB_EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  1088. {
  1089. #ifdef __CLIENTDEBUG__
  1090. JackGlobals::CheckContext("jack_port_get_all_connections");
  1091. #endif
  1092. JackClient* client = (JackClient*)ext_client;
  1093. if (client == NULL) {
  1094. jack_error("jack_port_get_all_connections called with a NULL client");
  1095. return NULL;
  1096. }
  1097. uintptr_t port_aux = (uintptr_t)port;
  1098. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1099. if (!CheckPort(myport)) {
  1100. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  1101. return NULL;
  1102. } else {
  1103. WaitGraphChange();
  1104. JackGraphManager* manager = GetGraphManager();
  1105. return (manager ? manager->GetConnections(myport) : NULL);
  1106. }
  1107. }
  1108. LIB_EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  1109. {
  1110. #ifdef __CLIENTDEBUG__
  1111. JackGlobals::CheckContext("jack_port_get_total_latency");
  1112. #endif
  1113. JackClient* client = (JackClient*)ext_client;
  1114. if (client == NULL) {
  1115. jack_error("jack_port_get_total_latency called with a NULL client");
  1116. return 0;
  1117. }
  1118. uintptr_t port_aux = (uintptr_t)port;
  1119. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1120. if (!CheckPort(myport)) {
  1121. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  1122. return 0;
  1123. } else {
  1124. WaitGraphChange();
  1125. JackGraphManager* manager = GetGraphManager();
  1126. if (manager) {
  1127. manager->ComputeTotalLatency(myport);
  1128. return manager->GetPort(myport)->GetTotalLatency();
  1129. } else {
  1130. return 0;
  1131. }
  1132. }
  1133. }
  1134. LIB_EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  1135. {
  1136. #ifdef __CLIENTDEBUG__
  1137. JackGlobals::CheckContext("jack_connect");
  1138. #endif
  1139. JackClient* client = (JackClient*)ext_client;
  1140. if (client == NULL) {
  1141. jack_error("jack_connect called with a NULL client");
  1142. return -1;
  1143. } else if ((src == NULL) || (dst == NULL)) {
  1144. jack_error("jack_connect called with a NULL port name");
  1145. return -1;
  1146. } else {
  1147. return client->PortConnect(src, dst);
  1148. }
  1149. }
  1150. LIB_EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  1151. {
  1152. #ifdef __CLIENTDEBUG__
  1153. JackGlobals::CheckContext("jack_disconnect");
  1154. #endif
  1155. JackClient* client = (JackClient*)ext_client;
  1156. if (client == NULL) {
  1157. jack_error("jack_disconnect 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->PortDisconnect(src, dst);
  1164. }
  1165. }
  1166. LIB_EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  1167. {
  1168. #ifdef __CLIENTDEBUG__
  1169. JackGlobals::CheckContext("jack_port_disconnect");
  1170. #endif
  1171. JackClient* client = (JackClient*)ext_client;
  1172. if (client == NULL) {
  1173. jack_error("jack_port_disconnect called with a NULL client");
  1174. return -1;
  1175. }
  1176. uintptr_t port_aux = (uintptr_t)src;
  1177. jack_port_id_t myport = (jack_port_id_t)port_aux;
  1178. if (!CheckPort(myport)) {
  1179. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  1180. return -1;
  1181. }
  1182. return client->PortDisconnect(myport);
  1183. }
  1184. LIB_EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  1185. {
  1186. #ifdef __CLIENTDEBUG__
  1187. JackGlobals::CheckContext("jack_get_sample_rate");
  1188. #endif
  1189. JackClient* client = (JackClient*)ext_client;
  1190. if (client == NULL) {
  1191. jack_error("jack_get_sample_rate called with a NULL client");
  1192. return 0;
  1193. } else {
  1194. JackEngineControl* control = GetEngineControl();
  1195. return (control ? control->fSampleRate : 0);
  1196. }
  1197. }
  1198. LIB_EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  1199. {
  1200. #ifdef __CLIENTDEBUG__
  1201. JackGlobals::CheckContext("jack_get_buffer_size");
  1202. #endif
  1203. JackClient* client = (JackClient*)ext_client;
  1204. if (client == NULL) {
  1205. jack_error("jack_get_buffer_size called with a NULL client");
  1206. return 0;
  1207. } else {
  1208. JackEngineControl* control = GetEngineControl();
  1209. return (control ? control->fBufferSize : 0);
  1210. }
  1211. }
  1212. 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)
  1213. {
  1214. #ifdef __CLIENTDEBUG__
  1215. JackGlobals::CheckContext("jack_get_ports");
  1216. #endif
  1217. JackClient* client = (JackClient*)ext_client;
  1218. if (client == NULL) {
  1219. jack_error("jack_get_ports called with a NULL client");
  1220. return NULL;
  1221. }
  1222. JackGraphManager* manager = GetGraphManager();
  1223. return (manager ? manager->GetPorts(port_name_pattern, type_name_pattern, flags) : NULL);
  1224. }
  1225. LIB_EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  1226. {
  1227. #ifdef __CLIENTDEBUG__
  1228. JackGlobals::CheckContext("jack_port_by_name");
  1229. #endif
  1230. JackClient* client = (JackClient*)ext_client;
  1231. if (client == NULL) {
  1232. jack_error("jack_get_ports called with a NULL client");
  1233. return 0;
  1234. }
  1235. if (portname == NULL) {
  1236. jack_error("jack_port_by_name called with a NULL port name");
  1237. return NULL;
  1238. } else {
  1239. JackGraphManager* manager = GetGraphManager();
  1240. if (!manager)
  1241. return NULL;
  1242. int res = manager->GetPort(portname); // returns a port index at least > 1
  1243. return (res == NO_PORT) ? NULL : (jack_port_t*)((uintptr_t)res);
  1244. }
  1245. }
  1246. LIB_EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  1247. {
  1248. #ifdef __CLIENTDEBUG__
  1249. JackGlobals::CheckContext("jack_port_by_id");
  1250. #endif
  1251. /* jack_port_t* type is actually the port index */
  1252. return (jack_port_t*)((uintptr_t)id);
  1253. }
  1254. LIB_EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  1255. {
  1256. #ifdef __CLIENTDEBUG__
  1257. JackGlobals::CheckContext("jack_engine_takeover_timebase");
  1258. #endif
  1259. JackClient* client = (JackClient*)ext_client;
  1260. if (client == NULL) {
  1261. jack_error("jack_engine_takeover_timebase called with a NULL client");
  1262. return -1;
  1263. } else {
  1264. jack_error("jack_engine_takeover_timebase: deprecated\n");
  1265. return 0;
  1266. }
  1267. }
  1268. LIB_EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  1269. {
  1270. #ifdef __CLIENTDEBUG__
  1271. JackGlobals::CheckContext("jack_frames_since_cycle_start");
  1272. #endif
  1273. JackTimer timer;
  1274. JackEngineControl* control = GetEngineControl();
  1275. if (control) {
  1276. control->ReadFrameTime(&timer);
  1277. return timer.FramesSinceCycleStart(GetMicroSeconds(), control->fSampleRate);
  1278. } else {
  1279. return 0;
  1280. }
  1281. }
  1282. LIB_EXPORT jack_time_t jack_get_time()
  1283. {
  1284. #ifdef __CLIENTDEBUG__
  1285. JackGlobals::CheckContext("jack_get_time");
  1286. #endif
  1287. return GetMicroSeconds();
  1288. }
  1289. LIB_EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1290. {
  1291. #ifdef __CLIENTDEBUG__
  1292. JackGlobals::CheckContext("jack_frames_to_time");
  1293. #endif
  1294. JackClient* client = (JackClient*)ext_client;
  1295. if (client == NULL) {
  1296. jack_error("jack_frames_to_time called with a NULL client");
  1297. return 0;
  1298. } else {
  1299. JackTimer timer;
  1300. JackEngineControl* control = GetEngineControl();
  1301. if (control) {
  1302. control->ReadFrameTime(&timer);
  1303. return timer.Frames2Time(frames, control->fBufferSize);
  1304. } else {
  1305. return 0;
  1306. }
  1307. }
  1308. }
  1309. LIB_EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1310. {
  1311. #ifdef __CLIENTDEBUG__
  1312. JackGlobals::CheckContext("jack_time_to_frames");
  1313. #endif
  1314. JackClient* client = (JackClient*)ext_client;
  1315. if (client == NULL) {
  1316. jack_error("jack_time_to_frames called with a NULL client");
  1317. return 0;
  1318. } else {
  1319. JackTimer timer;
  1320. JackEngineControl* control = GetEngineControl();
  1321. if (control) {
  1322. control->ReadFrameTime(&timer);
  1323. return timer.Time2Frames(time, control->fBufferSize);
  1324. } else {
  1325. return 0;
  1326. }
  1327. }
  1328. }
  1329. LIB_EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1330. {
  1331. #ifdef __CLIENTDEBUG__
  1332. JackGlobals::CheckContext("jack_frame_time");
  1333. #endif
  1334. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1335. }
  1336. LIB_EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1337. {
  1338. #ifdef __CLIENTDEBUG__
  1339. JackGlobals::CheckContext("jack_last_frame_time");
  1340. #endif
  1341. JackEngineControl* control = GetEngineControl();
  1342. return (control) ? control->fFrameTimer.ReadCurrentState()->CurFrame() : 0;
  1343. }
  1344. LIB_EXPORT float jack_cpu_load(jack_client_t* ext_client)
  1345. {
  1346. #ifdef __CLIENTDEBUG__
  1347. JackGlobals::CheckContext("jack_cpu_load");
  1348. #endif
  1349. JackClient* client = (JackClient*)ext_client;
  1350. if (client == NULL) {
  1351. jack_error("jack_cpu_load called with a NULL client");
  1352. return 0.0f;
  1353. } else {
  1354. JackEngineControl* control = GetEngineControl();
  1355. return (control ? control->fCPULoad : 0.0f);
  1356. }
  1357. }
  1358. LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t* ext_client)
  1359. {
  1360. #ifdef __CLIENTDEBUG__
  1361. JackGlobals::CheckContext("jack_client_thread_id");
  1362. #endif
  1363. JackClient* client = (JackClient*)ext_client;
  1364. if (client == NULL) {
  1365. jack_error("jack_client_thread_id called with a NULL client");
  1366. return (jack_native_thread_t)NULL;
  1367. } else {
  1368. return client->GetThreadID();
  1369. }
  1370. }
  1371. LIB_EXPORT char* jack_get_client_name(jack_client_t* ext_client)
  1372. {
  1373. #ifdef __CLIENTDEBUG__
  1374. JackGlobals::CheckContext("jack_get_client_name");
  1375. #endif
  1376. JackClient* client = (JackClient*)ext_client;
  1377. if (client == NULL) {
  1378. jack_error("jack_get_client_name called with a NULL client");
  1379. return NULL;
  1380. } else {
  1381. return client->GetClientControl()->fName;
  1382. }
  1383. }
  1384. LIB_EXPORT int jack_client_name_size(void)
  1385. {
  1386. return JACK_CLIENT_NAME_SIZE;
  1387. }
  1388. LIB_EXPORT int jack_port_name_size(void)
  1389. {
  1390. return JACK_PORT_NAME_SIZE;
  1391. }
  1392. LIB_EXPORT int jack_port_type_size(void)
  1393. {
  1394. return JACK_PORT_TYPE_SIZE;
  1395. }
  1396. LIB_EXPORT size_t jack_port_type_get_buffer_size(jack_client_t* ext_client, const char* port_type)
  1397. {
  1398. #ifdef __CLIENTDEBUG__
  1399. JackGlobals::CheckContext("jack_port_type_get_buffer_size");
  1400. #endif
  1401. JackClient* client = (JackClient*)ext_client;
  1402. if (client == NULL) {
  1403. jack_error("jack_port_type_get_buffer_size called with a NULL client");
  1404. return 0;
  1405. } else {
  1406. jack_port_type_id_t port_id = GetPortTypeId(port_type);
  1407. if (port_id == PORT_TYPES_MAX) {
  1408. jack_error("jack_port_type_get_buffer_size called with an unknown port type = %s", port_type);
  1409. return 0;
  1410. } else {
  1411. return GetPortType(port_id)->size();
  1412. }
  1413. }
  1414. }
  1415. // transport.h
  1416. LIB_EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1417. {
  1418. #ifdef __CLIENTDEBUG__
  1419. JackGlobals::CheckContext("jack_release_timebase");
  1420. #endif
  1421. JackClient* client = (JackClient*)ext_client;
  1422. if (client == NULL) {
  1423. jack_error("jack_release_timebase called with a NULL client");
  1424. return -1;
  1425. } else {
  1426. return client->ReleaseTimebase();
  1427. }
  1428. }
  1429. LIB_EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1430. {
  1431. #ifdef __CLIENTDEBUG__
  1432. JackGlobals::CheckContext("jack_set_sync_callback");
  1433. #endif
  1434. JackClient* client = (JackClient*)ext_client;
  1435. if (client == NULL) {
  1436. jack_error("jack_set_sync_callback called with a NULL client");
  1437. return -1;
  1438. } else {
  1439. return client->SetSyncCallback(sync_callback, arg);
  1440. }
  1441. }
  1442. LIB_EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1443. {
  1444. #ifdef __CLIENTDEBUG__
  1445. JackGlobals::CheckContext("jack_set_sync_timeout");
  1446. #endif
  1447. JackClient* client = (JackClient*)ext_client;
  1448. if (client == NULL) {
  1449. jack_error("jack_set_sync_timeout called with a NULL client");
  1450. return -1;
  1451. } else {
  1452. return client->SetSyncTimeout(timeout);
  1453. }
  1454. }
  1455. LIB_EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1456. {
  1457. #ifdef __CLIENTDEBUG__
  1458. JackGlobals::CheckContext("jack_set_timebase_callback");
  1459. #endif
  1460. JackClient* client = (JackClient*)ext_client;
  1461. if (client == NULL) {
  1462. jack_error("jack_set_timebase_callback called with a NULL client");
  1463. return -1;
  1464. } else {
  1465. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1466. }
  1467. }
  1468. LIB_EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1469. {
  1470. #ifdef __CLIENTDEBUG__
  1471. JackGlobals::CheckContext("jack_transport_locate");
  1472. #endif
  1473. JackClient* client = (JackClient*)ext_client;
  1474. if (client == NULL) {
  1475. jack_error("jack_transport_locate called with a NULL client");
  1476. return -1;
  1477. } else {
  1478. client->TransportLocate(frame);
  1479. return 0;
  1480. }
  1481. }
  1482. LIB_EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1483. {
  1484. #ifdef __CLIENTDEBUG__
  1485. JackGlobals::CheckContext("jack_transport_query");
  1486. #endif
  1487. JackClient* client = (JackClient*)ext_client;
  1488. if (client == NULL) {
  1489. jack_error("jack_transport_query called with a NULL client");
  1490. return JackTransportStopped;
  1491. } else {
  1492. return client->TransportQuery(pos);
  1493. }
  1494. }
  1495. LIB_EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1496. {
  1497. #ifdef __CLIENTDEBUG__
  1498. JackGlobals::CheckContext("jack_get_current_transport_frame");
  1499. #endif
  1500. JackClient* client = (JackClient*)ext_client;
  1501. if (client == NULL) {
  1502. jack_error("jack_get_current_transport_frame called with a NULL client");
  1503. return 0;
  1504. } else {
  1505. return client->GetCurrentTransportFrame();
  1506. }
  1507. }
  1508. LIB_EXPORT int jack_transport_reposition(jack_client_t* ext_client, const jack_position_t* pos)
  1509. {
  1510. #ifdef __CLIENTDEBUG__
  1511. JackGlobals::CheckContext("jack_transport_reposition");
  1512. #endif
  1513. JackClient* client = (JackClient*)ext_client;
  1514. if (client == NULL) {
  1515. jack_error("jack_transport_reposition called with a NULL client");
  1516. return -1;
  1517. } else {
  1518. client->TransportReposition(pos);
  1519. return 0;
  1520. }
  1521. }
  1522. LIB_EXPORT void jack_transport_start(jack_client_t* ext_client)
  1523. {
  1524. #ifdef __CLIENTDEBUG__
  1525. JackGlobals::CheckContext("jack_transport_start");
  1526. #endif
  1527. JackClient* client = (JackClient*)ext_client;
  1528. if (client == NULL) {
  1529. jack_error("jack_transport_start called with a NULL client");
  1530. } else {
  1531. client->TransportStart();
  1532. }
  1533. }
  1534. LIB_EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1535. {
  1536. #ifdef __CLIENTDEBUG__
  1537. JackGlobals::CheckContext("jack_transport_stop");
  1538. #endif
  1539. JackClient* client = (JackClient*)ext_client;
  1540. if (client == NULL) {
  1541. jack_error("jack_transport_stop called with a NULL client");
  1542. } else {
  1543. client->TransportStop();
  1544. }
  1545. }
  1546. // deprecated
  1547. LIB_EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1548. {
  1549. #ifdef __CLIENTDEBUG__
  1550. JackGlobals::CheckContext("jack_get_transport_info");
  1551. #endif
  1552. jack_error("jack_get_transport_info: deprecated");
  1553. if (tinfo)
  1554. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1555. }
  1556. LIB_EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1557. {
  1558. #ifdef __CLIENTDEBUG__
  1559. JackGlobals::CheckContext("jack_set_transport_info");
  1560. #endif
  1561. jack_error("jack_set_transport_info: deprecated");
  1562. if (tinfo)
  1563. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1564. }
  1565. // statistics.h
  1566. LIB_EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1567. {
  1568. #ifdef __CLIENTDEBUG__
  1569. JackGlobals::CheckContext("jack_get_max_delayed_usecs");
  1570. #endif
  1571. JackClient* client = (JackClient*)ext_client;
  1572. if (client == NULL) {
  1573. jack_error("jack_get_max_delayed_usecs called with a NULL client");
  1574. return 0.f;
  1575. } else {
  1576. JackEngineControl* control = GetEngineControl();
  1577. return (control ? control->fMaxDelayedUsecs : 0.f);
  1578. }
  1579. }
  1580. LIB_EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1581. {
  1582. #ifdef __CLIENTDEBUG__
  1583. JackGlobals::CheckContext("jack_get_xrun_delayed_usecs");
  1584. #endif
  1585. JackClient* client = (JackClient*)ext_client;
  1586. if (client == NULL) {
  1587. jack_error("jack_get_xrun_delayed_usecs called with a NULL client");
  1588. return 0.f;
  1589. } else {
  1590. JackEngineControl* control = GetEngineControl();
  1591. return (control ? control->fXrunDelayedUsecs : 0.f);
  1592. }
  1593. }
  1594. LIB_EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1595. {
  1596. #ifdef __CLIENTDEBUG__
  1597. JackGlobals::CheckContext("jack_reset_max_delayed_usecs");
  1598. #endif
  1599. JackClient* client = (JackClient*)ext_client;
  1600. if (client == NULL) {
  1601. jack_error("jack_reset_max_delayed_usecs called with a NULL client");
  1602. } else {
  1603. JackEngineControl* control = GetEngineControl();
  1604. control->ResetXRun();
  1605. }
  1606. }
  1607. // thread.h
  1608. LIB_EXPORT int jack_client_real_time_priority(jack_client_t* ext_client)
  1609. {
  1610. #ifdef __CLIENTDEBUG__
  1611. JackGlobals::CheckContext("jack_client_real_time_priority");
  1612. #endif
  1613. JackClient* client = (JackClient*)ext_client;
  1614. if (client == NULL) {
  1615. jack_error("jack_client_real_time_priority called with a NULL client");
  1616. return -1;
  1617. } else {
  1618. JackEngineControl* control = GetEngineControl();
  1619. return (control->fRealTime) ? control->fClientPriority : -1;
  1620. }
  1621. }
  1622. LIB_EXPORT int jack_client_max_real_time_priority(jack_client_t* ext_client)
  1623. {
  1624. #ifdef __CLIENTDEBUG__
  1625. JackGlobals::CheckContext("jack_client_max_real_time_priority");
  1626. #endif
  1627. JackClient* client = (JackClient*)ext_client;
  1628. if (client == NULL) {
  1629. jack_error("jack_client_max_real_time_priority called with a NULL client");
  1630. return -1;
  1631. } else {
  1632. JackEngineControl* control = GetEngineControl();
  1633. return (control->fRealTime) ? control->fMaxClientPriority : -1;
  1634. }
  1635. }
  1636. LIB_EXPORT int jack_acquire_real_time_scheduling(jack_native_thread_t thread, int priority)
  1637. {
  1638. JackEngineControl* control = GetEngineControl();
  1639. return (control ? JackThread::AcquireRealTimeImp(thread, priority, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint) : -1);
  1640. }
  1641. LIB_EXPORT int jack_client_create_thread(jack_client_t* client,
  1642. jack_native_thread_t *thread,
  1643. int priority,
  1644. int realtime, /* boolean */
  1645. thread_routine routine,
  1646. void *arg)
  1647. {
  1648. #ifdef __CLIENTDEBUG__
  1649. JackGlobals::CheckContext("jack_client_create_thread");
  1650. #endif
  1651. return JackThread::StartImp(thread, priority, realtime, routine, arg);
  1652. }
  1653. LIB_EXPORT int jack_drop_real_time_scheduling(jack_native_thread_t thread)
  1654. {
  1655. return JackThread::DropRealTimeImp(thread);
  1656. }
  1657. LIB_EXPORT int jack_client_stop_thread(jack_client_t* client, jack_native_thread_t thread)
  1658. {
  1659. #ifdef __CLIENTDEBUG__
  1660. JackGlobals::CheckContext("jack_client_stop_thread");
  1661. #endif
  1662. return JackThread::StopImp(thread);
  1663. }
  1664. LIB_EXPORT int jack_client_kill_thread(jack_client_t* client, jack_native_thread_t thread)
  1665. {
  1666. #ifdef __CLIENTDEBUG__
  1667. JackGlobals::CheckContext("jack_client_kill_thread");
  1668. #endif
  1669. return JackThread::KillImp(thread);
  1670. }
  1671. #ifndef WIN32
  1672. LIB_EXPORT void jack_set_thread_creator (jack_thread_creator_t jtc)
  1673. {
  1674. JackGlobals::fJackThreadCreator = (jtc == NULL) ? pthread_create : jtc;
  1675. }
  1676. #endif
  1677. // intclient.h
  1678. LIB_EXPORT int jack_internal_client_new (const char* client_name,
  1679. const char* load_name,
  1680. const char* load_init)
  1681. {
  1682. #ifdef __CLIENTDEBUG__
  1683. JackGlobals::CheckContext("jack_internal_client_new");
  1684. #endif
  1685. jack_error("jack_internal_client_new: deprecated");
  1686. return -1;
  1687. }
  1688. LIB_EXPORT void jack_internal_client_close (const char* client_name)
  1689. {
  1690. #ifdef __CLIENTDEBUG__
  1691. JackGlobals::CheckContext("jack_internal_client_close");
  1692. #endif
  1693. jack_error("jack_internal_client_close: deprecated");
  1694. }
  1695. LIB_EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1696. {
  1697. #ifdef __CLIENTDEBUG__
  1698. JackGlobals::CheckContext("jack_get_internal_client_name");
  1699. #endif
  1700. JackClient* client = (JackClient*)ext_client;
  1701. if (client == NULL) {
  1702. jack_error("jack_get_internal_client_name called with a NULL client");
  1703. return NULL;
  1704. } else if (intclient >= CLIENT_NUM) {
  1705. jack_error("jack_get_internal_client_name: incorrect client");
  1706. return NULL;
  1707. } else {
  1708. return client->GetInternalClientName(intclient);
  1709. }
  1710. }
  1711. LIB_EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1712. {
  1713. #ifdef __CLIENTDEBUG__
  1714. JackGlobals::CheckContext("jack_internal_client_handle");
  1715. #endif
  1716. JackClient* client = (JackClient*)ext_client;
  1717. if (client == NULL) {
  1718. jack_error("jack_internal_client_handle called with a NULL client");
  1719. return 0;
  1720. } else {
  1721. jack_status_t my_status;
  1722. if (status == NULL) /* no status from caller? */
  1723. status = &my_status; /* use local status word */
  1724. *status = (jack_status_t)0;
  1725. return client->InternalClientHandle(client_name, status);
  1726. }
  1727. }
  1728. 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)
  1729. {
  1730. #ifdef __CLIENTDEBUG__
  1731. JackGlobals::CheckContext("jack_internal_client_load_aux");
  1732. #endif
  1733. JackClient* client = (JackClient*)ext_client;
  1734. if (client == NULL) {
  1735. jack_error("jack_internal_client_load called with a NULL client");
  1736. return 0;
  1737. } else {
  1738. jack_varargs_t va;
  1739. jack_status_t my_status;
  1740. if (status == NULL) /* no status from caller? */
  1741. status = &my_status; /* use local status word */
  1742. *status = (jack_status_t)0;
  1743. /* validate parameters */
  1744. if ((options & ~JackLoadOptions)) {
  1745. int my_status1 = *status | (JackFailure | JackInvalidOption);
  1746. *status = (jack_status_t)my_status1;
  1747. return 0;
  1748. }
  1749. /* parse variable arguments */
  1750. jack_varargs_parse(options, ap, &va);
  1751. return client->InternalClientLoad(client_name, options, status, &va);
  1752. }
  1753. }
  1754. 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, ...)
  1755. {
  1756. #ifdef __CLIENTDEBUG__
  1757. JackGlobals::CheckContext("jack_internal_client_load");
  1758. #endif
  1759. va_list ap;
  1760. va_start(ap, status);
  1761. jack_intclient_t res = jack_internal_client_load_aux(client, client_name, options, status, ap);
  1762. va_end(ap);
  1763. return res;
  1764. }
  1765. LIB_EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1766. {
  1767. #ifdef __CLIENTDEBUG__
  1768. JackGlobals::CheckContext("jack_internal_client_load");
  1769. #endif
  1770. JackClient* client = (JackClient*)ext_client;
  1771. if (client == NULL) {
  1772. jack_error("jack_internal_client_unload called with a NULL client");
  1773. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1774. } else if (intclient >= CLIENT_NUM) {
  1775. jack_error("jack_internal_client_unload: incorrect client");
  1776. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1777. } else {
  1778. jack_status_t my_status;
  1779. client->InternalClientUnload(intclient, &my_status);
  1780. return my_status;
  1781. }
  1782. }
  1783. LIB_EXPORT void jack_get_version(int *major_ptr,
  1784. int *minor_ptr,
  1785. int *micro_ptr,
  1786. int *proto_ptr)
  1787. {
  1788. #ifdef __CLIENTDEBUG__
  1789. JackGlobals::CheckContext("jack_get_version");
  1790. #endif
  1791. // FIXME: We need these comming from build system
  1792. *major_ptr = 0;
  1793. *minor_ptr = 0;
  1794. *micro_ptr = 0;
  1795. *proto_ptr = 0;
  1796. }
  1797. LIB_EXPORT const char* jack_get_version_string()
  1798. {
  1799. #ifdef __CLIENTDEBUG__
  1800. JackGlobals::CheckContext("jack_get_version_string");
  1801. #endif
  1802. return VERSION;
  1803. }
  1804. LIB_EXPORT void jack_free(void* ptr)
  1805. {
  1806. #ifdef __CLIENTDEBUG__
  1807. JackGlobals::CheckContext("jack_free");
  1808. #endif
  1809. if (ptr) {
  1810. free(ptr);
  1811. }
  1812. }
  1813. // session.h
  1814. LIB_EXPORT int jack_set_session_callback(jack_client_t* ext_client, JackSessionCallback session_callback, void* arg)
  1815. {
  1816. #ifdef __CLIENTDEBUG__
  1817. JackGlobals::CheckContext("jack_set_session_callback");
  1818. #endif
  1819. JackClient* client = (JackClient*)ext_client;
  1820. jack_log("jack_set_session_callback ext_client %x client %x ", ext_client, client);
  1821. if (client == NULL) {
  1822. jack_error("jack_set_session_callback called with a NULL client");
  1823. return -1;
  1824. } else {
  1825. return client->SetSessionCallback(session_callback, arg);
  1826. }
  1827. }
  1828. 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)
  1829. {
  1830. #ifdef __CLIENTDEBUG__
  1831. JackGlobals::CheckContext("jack_session_notify");
  1832. #endif
  1833. JackClient* client = (JackClient*)ext_client;
  1834. jack_log("jack_session_notify ext_client %x client %x ", ext_client, client);
  1835. if (client == NULL) {
  1836. jack_error("jack_session_notify called with a NULL client");
  1837. return NULL;
  1838. } else {
  1839. return client->SessionNotify(target, ev_type, path);
  1840. }
  1841. }
  1842. LIB_EXPORT int jack_session_reply(jack_client_t* ext_client, jack_session_event_t *event)
  1843. {
  1844. #ifdef __CLIENTDEBUG__
  1845. JackGlobals::CheckContext("jack_session_reply");
  1846. #endif
  1847. JackClient* client = (JackClient*)ext_client;
  1848. jack_log("jack_session_reply ext_client %x client %x ", ext_client, client);
  1849. if (client == NULL) {
  1850. jack_error("jack_session_reply called with a NULL client");
  1851. return -1;
  1852. } else {
  1853. return client->SessionReply(event);
  1854. }
  1855. }
  1856. LIB_EXPORT void jack_session_event_free(jack_session_event_t* ev)
  1857. {
  1858. #ifdef __CLIENTDEBUG__
  1859. JackGlobals::CheckContext("jack_session_event_free");
  1860. #endif
  1861. if (ev) {
  1862. if (ev->session_dir)
  1863. free((void *)ev->session_dir);
  1864. if (ev->client_uuid)
  1865. free((void *)ev->client_uuid);
  1866. if (ev->command_line)
  1867. free(ev->command_line);
  1868. free(ev);
  1869. }
  1870. }
  1871. LIB_EXPORT char *jack_client_get_uuid(jack_client_t* ext_client)
  1872. {
  1873. #ifdef __CLIENTDEBUG__
  1874. JackGlobals::CheckContext("jack_client_get_uuid");
  1875. #endif
  1876. JackClient* client = (JackClient*)ext_client;
  1877. if (client == NULL) {
  1878. jack_error("jack_client_get_uuid called with a NULL client");
  1879. return NULL;
  1880. } else {
  1881. char retval[16];
  1882. snprintf(retval, sizeof(retval), "%d", client->GetClientControl()->fSessionID);
  1883. return strdup(retval);
  1884. }
  1885. }
  1886. LIB_EXPORT char* jack_get_uuid_for_client_name(jack_client_t* ext_client, const char* client_name)
  1887. {
  1888. #ifdef __CLIENTDEBUG__
  1889. JackGlobals::CheckContext("jack_get_uuid_for_client_name");
  1890. #endif
  1891. JackClient* client = (JackClient*)ext_client;
  1892. jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
  1893. if (client == NULL) {
  1894. jack_error("jack_get_uuid_for_client_name called with a NULL client");
  1895. return NULL;
  1896. } else {
  1897. return client->GetUUIDForClientName(client_name);
  1898. }
  1899. }
  1900. LIB_EXPORT char* jack_get_client_name_by_uuid(jack_client_t* ext_client, const char* client_uuid)
  1901. {
  1902. #ifdef __CLIENTDEBUG__
  1903. JackGlobals::CheckContext("jack_get_client_name_by_uuid");
  1904. #endif
  1905. JackClient* client = (JackClient*)ext_client;
  1906. jack_log("jack_get_uuid_for_client_name ext_client %x client %x ", ext_client, client);
  1907. if (client == NULL) {
  1908. jack_error("jack_get_client_name_by_uuid called with a NULL client");
  1909. return NULL;
  1910. } else {
  1911. return client->GetClientNameByUUID(client_uuid);
  1912. }
  1913. }
  1914. LIB_EXPORT int jack_reserve_client_name(jack_client_t* ext_client, const char* client_name, const char* uuid)
  1915. {
  1916. #ifdef __CLIENTDEBUG__
  1917. JackGlobals::CheckContext("jack_reserve_client_name");
  1918. #endif
  1919. JackClient* client = (JackClient*)ext_client;
  1920. jack_log("jack_reserve_client_name ext_client %x client %x ", ext_client, client);
  1921. if (client == NULL) {
  1922. jack_error("jack_reserve_client_name called with a NULL client");
  1923. return -1;
  1924. } else {
  1925. return client->ReserveClientName(client_name, uuid);
  1926. }
  1927. }
  1928. LIB_EXPORT void jack_session_commands_free(jack_session_command_t *cmds)
  1929. {
  1930. #ifdef __CLIENTDEBUG__
  1931. JackGlobals::CheckContext("jack_session_commands_free");
  1932. #endif
  1933. if (!cmds)
  1934. return;
  1935. int i = 0;
  1936. while (1) {
  1937. if (cmds[i].client_name)
  1938. free ((char *)cmds[i].client_name);
  1939. if (cmds[i].command)
  1940. free ((char *)cmds[i].command);
  1941. if (cmds[i].uuid)
  1942. free ((char *)cmds[i].uuid);
  1943. else
  1944. break;
  1945. i += 1;
  1946. }
  1947. free(cmds);
  1948. }
  1949. LIB_EXPORT int jack_client_has_session_callback(jack_client_t* ext_client, const char* client_name)
  1950. {
  1951. #ifdef __CLIENTDEBUG__
  1952. JackGlobals::CheckContext("jack_client_has_session_callback");
  1953. #endif
  1954. JackClient* client = (JackClient*)ext_client;
  1955. jack_log("jack_client_has_session_callback ext_client %x client %x ", ext_client, client);
  1956. if (client == NULL) {
  1957. jack_error("jack_client_has_session_callback called with a NULL client");
  1958. return -1;
  1959. } else {
  1960. return client->ClientHasSessionCallback(client_name);
  1961. }
  1962. }