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.

1522 lines
48KB

  1. /*
  2. Copyright (C) 2001-2003 Paul Davis
  3. Copyright (C) 2004-2006 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 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 General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, 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 "JackExports.h"
  24. #include "JackAPI.h"
  25. #ifdef __APPLE__
  26. #include "JackMachThread.h"
  27. #elif WIN32
  28. #include "JackWinThread.h"
  29. #else
  30. #include "JackPosixThread.h"
  31. #endif
  32. #include <math.h>
  33. #ifdef __CLIENTDEBUG__
  34. #include "JackLibGlobals.h"
  35. #endif
  36. using namespace Jack;
  37. #ifdef __cplusplus
  38. extern "C"
  39. {
  40. #endif
  41. EXPORT jack_client_t * jack_client_open (const char *client_name,
  42. jack_options_t options,
  43. jack_status_t *status, ...);
  44. EXPORT jack_client_t * jack_client_new (const char *client_name);
  45. EXPORT int jack_client_name_size (void);
  46. EXPORT char* jack_get_client_name (jack_client_t *client);
  47. EXPORT int jack_internal_client_new (const char *client_name,
  48. const char *load_name,
  49. const char *load_init);
  50. EXPORT void jack_internal_client_close (const char *client_name);
  51. EXPORT int jack_is_realtime (jack_client_t *client);
  52. EXPORT void jack_on_shutdown (jack_client_t *client,
  53. void (*function)(void *arg), void *arg);
  54. EXPORT int jack_set_process_callback (jack_client_t *client,
  55. JackProcessCallback process_callback,
  56. void *arg);
  57. EXPORT int jack_set_thread_init_callback (jack_client_t *client,
  58. JackThreadInitCallback thread_init_callback,
  59. void *arg);
  60. EXPORT int jack_set_freewheel_callback (jack_client_t *client,
  61. JackFreewheelCallback freewheel_callback,
  62. void *arg);
  63. EXPORT int jack_set_freewheel(jack_client_t* client, int onoff);
  64. EXPORT int jack_set_buffer_size (jack_client_t *client, jack_nframes_t nframes);
  65. EXPORT int jack_set_buffer_size_callback (jack_client_t *client,
  66. JackBufferSizeCallback bufsize_callback,
  67. void *arg);
  68. EXPORT int jack_set_sample_rate_callback (jack_client_t *client,
  69. JackSampleRateCallback srate_callback,
  70. void *arg);
  71. EXPORT int jack_set_client_registration_callback (jack_client_t *,
  72. JackClientRegistrationCallback
  73. registration_callback, void *arg);
  74. EXPORT int jack_set_port_registration_callback (jack_client_t *,
  75. JackPortRegistrationCallback
  76. registration_callback, void *arg);
  77. EXPORT int jack_set_port_connect_callback (jack_client_t *,
  78. JackPortConnectCallback
  79. connect_callback, void *arg);
  80. EXPORT int jack_set_graph_order_callback (jack_client_t *,
  81. JackGraphOrderCallback graph_callback,
  82. void *);
  83. EXPORT int jack_set_xrun_callback (jack_client_t *,
  84. JackXRunCallback xrun_callback, void *arg);
  85. EXPORT int jack_activate (jack_client_t *client);
  86. EXPORT int jack_deactivate (jack_client_t *client);
  87. EXPORT jack_port_t * jack_port_register (jack_client_t *client,
  88. const char *port_name,
  89. const char *port_type,
  90. unsigned long flags,
  91. unsigned long buffer_size);
  92. EXPORT int jack_port_unregister (jack_client_t *, jack_port_t *);
  93. EXPORT void * jack_port_get_buffer (jack_port_t *, jack_nframes_t);
  94. EXPORT const char * jack_port_name (const jack_port_t *port);
  95. EXPORT const char * jack_port_short_name (const jack_port_t *port);
  96. EXPORT int jack_port_flags (const jack_port_t *port);
  97. EXPORT const char * jack_port_type (const jack_port_t *port);
  98. EXPORT int jack_port_is_mine (const jack_client_t *, const jack_port_t *port);
  99. EXPORT int jack_port_connected (const jack_port_t *port);
  100. EXPORT int jack_port_connected_to (const jack_port_t *port,
  101. const char *port_name);
  102. EXPORT const char ** jack_port_get_connections (const jack_port_t *port);
  103. EXPORT const char ** jack_port_get_all_connections (const jack_client_t *client,
  104. const jack_port_t *port);
  105. EXPORT int jack_port_tie (jack_port_t *src, jack_port_t *dst);
  106. EXPORT int jack_port_untie (jack_port_t *port);
  107. EXPORT jack_nframes_t jack_port_get_latency (jack_port_t *port);
  108. EXPORT jack_nframes_t jack_port_get_total_latency (jack_client_t *,
  109. jack_port_t *port);
  110. EXPORT void jack_port_set_latency (jack_port_t *, jack_nframes_t);
  111. EXPORT int jack_recompute_total_latency (jack_client_t*, jack_port_t* port);
  112. EXPORT int jack_recompute_total_latencies (jack_client_t*);
  113. EXPORT int jack_port_set_name (jack_port_t *port, const char *port_name);
  114. EXPORT int jack_port_set_alias (jack_port_t *port, const char *alias);
  115. EXPORT int jack_port_unset_alias (jack_port_t *port, const char *alias);
  116. EXPORT int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]);
  117. EXPORT int jack_port_request_monitor (jack_port_t *port, int onoff);
  118. EXPORT int jack_port_request_monitor_by_name (jack_client_t *client,
  119. const char *port_name, int onoff);
  120. EXPORT int jack_port_ensure_monitor (jack_port_t *port, int onoff);
  121. EXPORT int jack_port_monitoring_input (jack_port_t *port);
  122. EXPORT int jack_connect (jack_client_t *,
  123. const char *source_port,
  124. const char *destination_port);
  125. EXPORT int jack_disconnect (jack_client_t *,
  126. const char *source_port,
  127. const char *destination_port);
  128. EXPORT int jack_port_disconnect (jack_client_t *, jack_port_t *);
  129. EXPORT int jack_port_name_size(void);
  130. EXPORT int jack_port_type_size(void);
  131. EXPORT jack_nframes_t jack_get_sample_rate (jack_client_t *);
  132. EXPORT jack_nframes_t jack_get_buffer_size (jack_client_t *);
  133. EXPORT const char ** jack_get_ports (jack_client_t *,
  134. const char *port_name_pattern,
  135. const char *type_name_pattern,
  136. unsigned long flags);
  137. EXPORT jack_port_t * jack_port_by_name (jack_client_t *, const char *port_name);
  138. EXPORT jack_port_t * jack_port_by_id (jack_client_t *client,
  139. jack_port_id_t port_id);
  140. EXPORT int jack_engine_takeover_timebase (jack_client_t *);
  141. EXPORT jack_nframes_t jack_frames_since_cycle_start (const jack_client_t *);
  142. EXPORT jack_time_t jack_get_time(const jack_client_t *client);
  143. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t *client, jack_time_t time);
  144. EXPORT jack_time_t jack_frames_to_time(const jack_client_t *client, jack_nframes_t frames);
  145. EXPORT jack_nframes_t jack_frame_time (const jack_client_t *);
  146. EXPORT jack_nframes_t jack_last_frame_time (const jack_client_t *client);
  147. EXPORT float jack_cpu_load (jack_client_t *client);
  148. EXPORT pthread_t jack_client_thread_id (jack_client_t *);
  149. EXPORT void jack_set_error_function (void (*func)(const char *));
  150. EXPORT float jack_get_max_delayed_usecs (jack_client_t *client);
  151. EXPORT float jack_get_xrun_delayed_usecs (jack_client_t *client);
  152. EXPORT void jack_reset_max_delayed_usecs (jack_client_t *client);
  153. EXPORT int jack_release_timebase (jack_client_t *client);
  154. EXPORT int jack_set_sync_callback (jack_client_t *client,
  155. JackSyncCallback sync_callback,
  156. void *arg);
  157. EXPORT int jack_set_sync_timeout (jack_client_t *client,
  158. jack_time_t timeout);
  159. EXPORT int jack_set_timebase_callback (jack_client_t *client,
  160. int conditional,
  161. JackTimebaseCallback timebase_callback,
  162. void *arg);
  163. EXPORT int jack_transport_locate (jack_client_t *client,
  164. jack_nframes_t frame);
  165. EXPORT jack_transport_state_t jack_transport_query (const jack_client_t *client,
  166. jack_position_t *pos);
  167. EXPORT jack_nframes_t jack_get_current_transport_frame (const jack_client_t *client);
  168. EXPORT int jack_transport_reposition (jack_client_t *client,
  169. jack_position_t *pos);
  170. EXPORT void jack_transport_start (jack_client_t *client);
  171. EXPORT void jack_transport_stop (jack_client_t *client);
  172. EXPORT void jack_get_transport_info (jack_client_t *client,
  173. jack_transport_info_t *tinfo);
  174. EXPORT void jack_set_transport_info (jack_client_t *client,
  175. jack_transport_info_t *tinfo);
  176. EXPORT int jack_acquire_real_time_scheduling (pthread_t thread, int priority);
  177. EXPORT int jack_client_create_thread (jack_client_t* client,
  178. pthread_t *thread,
  179. int priority,
  180. int realtime, // boolean
  181. void *(*start_routine)(void*),
  182. void *arg);
  183. EXPORT int jack_drop_real_time_scheduling (pthread_t thread);
  184. EXPORT char * jack_get_internal_client_name (jack_client_t *client,
  185. jack_intclient_t intclient);
  186. EXPORT jack_intclient_t jack_internal_client_handle (jack_client_t *client,
  187. const char *client_name,
  188. jack_status_t *status);
  189. EXPORT jack_intclient_t jack_internal_client_load (jack_client_t *client,
  190. const char *client_name,
  191. jack_options_t options,
  192. jack_status_t *status, ...);
  193. EXPORT jack_status_t jack_internal_client_unload (jack_client_t *client,
  194. jack_intclient_t intclient);
  195. #ifdef __cplusplus
  196. }
  197. #endif
  198. #ifdef WIN32
  199. /* missing on Windows : see http://bugs.mysql.com/bug.php?id=15936 */
  200. inline double rint(double nr)
  201. {
  202. double f = floor(nr);
  203. double c = ceil(nr);
  204. return (((c -nr) >= (nr - f)) ? f : c);
  205. }
  206. #endif
  207. static inline bool CheckPort(jack_port_id_t port_index)
  208. {
  209. return (port_index > 0 && port_index < PORT_NUM);
  210. }
  211. static inline bool CheckBufferSize(jack_nframes_t buffer_size)
  212. {
  213. return (buffer_size <= BUFFER_SIZE_MAX);
  214. }
  215. static inline void WaitGraphChange()
  216. {
  217. if (GetGraphManager()->IsPendingChange()) {
  218. JackLog("WaitGraphChange...\n");
  219. JackSleep(GetEngineControl()->fPeriodUsecs * 2);
  220. }
  221. }
  222. EXPORT void jack_set_error_function (void (*func)(const char *))
  223. {
  224. jack_error_callback = func;
  225. }
  226. EXPORT jack_client_t* jack_client_new(const char* client_name)
  227. {
  228. jack_error("jack_client_new: deprecated");
  229. int options = JackUseExactName;
  230. if (getenv("JACK_START_SERVER") == NULL)
  231. options |= JackNoStartServer;
  232. return jack_client_open(client_name, (jack_options_t)options, NULL);
  233. }
  234. EXPORT void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t frames)
  235. {
  236. #ifdef __CLIENTDEBUG__
  237. JackLibGlobals::CheckContext();
  238. #endif
  239. jack_port_id_t myport = (jack_port_id_t)port;
  240. if (!CheckPort(myport)) {
  241. jack_error("jack_port_get_buffer called with an incorrect port %ld", myport);
  242. return NULL;
  243. } else {
  244. return GetGraphManager()->GetBuffer(myport, frames);
  245. }
  246. }
  247. EXPORT const char* jack_port_name(const jack_port_t* port)
  248. {
  249. #ifdef __CLIENTDEBUG__
  250. JackLibGlobals::CheckContext();
  251. #endif
  252. jack_port_id_t myport = (jack_port_id_t)port;
  253. if (!CheckPort(myport)) {
  254. jack_error("jack_port_name called with an incorrect port %ld", myport);
  255. return NULL;
  256. } else {
  257. return GetGraphManager()->GetPort(myport)->GetName();
  258. }
  259. }
  260. EXPORT const char* jack_port_short_name(const jack_port_t* port)
  261. {
  262. #ifdef __CLIENTDEBUG__
  263. JackLibGlobals::CheckContext();
  264. #endif
  265. jack_port_id_t myport = (jack_port_id_t)port;
  266. if (!CheckPort(myport)) {
  267. jack_error("jack_port_short_name called with an incorrect port %ld", myport);
  268. return NULL;
  269. } else {
  270. return GetGraphManager()->GetPort(myport)->GetShortName();
  271. }
  272. }
  273. EXPORT int jack_port_flags(const jack_port_t* port)
  274. {
  275. #ifdef __CLIENTDEBUG__
  276. JackLibGlobals::CheckContext();
  277. #endif
  278. jack_port_id_t myport = (jack_port_id_t)port;
  279. if (!CheckPort(myport)) {
  280. jack_error("jack_port_flags called with an incorrect port %ld", myport);
  281. return -1;
  282. } else {
  283. return GetGraphManager()->GetPort(myport)->GetFlags();
  284. }
  285. }
  286. EXPORT const char* jack_port_type(const jack_port_t* port)
  287. {
  288. #ifdef __CLIENTDEBUG__
  289. JackLibGlobals::CheckContext();
  290. #endif
  291. jack_port_id_t myport = (jack_port_id_t)port;
  292. if (!CheckPort(myport)) {
  293. jack_error("jack_port_flags called an incorrect port %ld", myport);
  294. return NULL;
  295. } else {
  296. return GetGraphManager()->GetPort(myport)->GetType();
  297. }
  298. }
  299. EXPORT int jack_port_connected(const jack_port_t* port)
  300. {
  301. #ifdef __CLIENTDEBUG__
  302. JackLibGlobals::CheckContext();
  303. #endif
  304. jack_port_id_t myport = (jack_port_id_t)port;
  305. if (!CheckPort(myport)) {
  306. jack_error("jack_port_connected called with an incorrect port %ld", myport);
  307. return -1;
  308. } else {
  309. WaitGraphChange();
  310. return GetGraphManager()->GetConnectionsNum(myport);
  311. }
  312. }
  313. EXPORT int jack_port_connected_to(const jack_port_t* port, const char* portname)
  314. {
  315. #ifdef __CLIENTDEBUG__
  316. JackLibGlobals::CheckContext();
  317. #endif
  318. jack_port_id_t myport = (jack_port_id_t)port;
  319. if (!CheckPort(myport)) {
  320. jack_error("jack_port_connected_to called with an incorrect port %ld", myport);
  321. return -1;
  322. } else if (portname == NULL) {
  323. jack_error("jack_port_connected_to called with a NULL port name");
  324. return -1;
  325. } else {
  326. WaitGraphChange();
  327. return GetGraphManager()->ConnectedTo(myport, portname);
  328. }
  329. }
  330. EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  331. {
  332. #ifdef __CLIENTDEBUG__
  333. JackLibGlobals::CheckContext();
  334. #endif
  335. jack_port_id_t mysrc = (jack_port_id_t)src;
  336. if (!CheckPort(mysrc)) {
  337. jack_error("jack_port_tie called with a NULL src port");
  338. return -1;
  339. }
  340. jack_port_id_t mydst = (jack_port_id_t)dst;
  341. if (!CheckPort(mydst)) {
  342. jack_error("jack_port_tie called with a NULL dst port");
  343. return -1;
  344. }
  345. if (GetGraphManager()->GetPort(mysrc)->GetRefNum() != GetGraphManager()->GetPort(mydst)->GetRefNum()) {
  346. jack_error("jack_port_tie called with ports not belonging to the same client");
  347. return -1;
  348. }
  349. return GetGraphManager()->GetPort(mydst)->Tie(mysrc);
  350. }
  351. EXPORT int jack_port_untie(jack_port_t* port)
  352. {
  353. #ifdef __CLIENTDEBUG__
  354. JackLibGlobals::CheckContext();
  355. #endif
  356. jack_port_id_t myport = (jack_port_id_t)port;
  357. if (!CheckPort(myport)) {
  358. jack_error("jack_port_untie called with an incorrect port %ld", myport);
  359. return -1;
  360. } else {
  361. return GetGraphManager()->GetPort(myport)->UnTie();
  362. }
  363. }
  364. EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  365. {
  366. #ifdef __CLIENTDEBUG__
  367. JackLibGlobals::CheckContext();
  368. #endif
  369. jack_port_id_t myport = (jack_port_id_t)port;
  370. if (!CheckPort(myport)) {
  371. jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
  372. return 0;
  373. } else {
  374. WaitGraphChange();
  375. return GetGraphManager()->GetPort(myport)->GetLatency();
  376. }
  377. }
  378. EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  379. {
  380. #ifdef __CLIENTDEBUG__
  381. JackLibGlobals::CheckContext();
  382. #endif
  383. jack_port_id_t myport = (jack_port_id_t)port;
  384. if (!CheckPort(myport)) {
  385. jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
  386. } else {
  387. GetGraphManager()->GetPort(myport)->SetLatency(frames);
  388. }
  389. }
  390. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client, jack_port_t* port)
  391. {
  392. #ifdef __CLIENTDEBUG__
  393. JackLibGlobals::CheckContext();
  394. #endif
  395. // The latency computation is done each time jack_port_get_total_latency is called
  396. return 0;
  397. }
  398. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  399. {
  400. #ifdef __CLIENTDEBUG__
  401. JackLibGlobals::CheckContext();
  402. #endif
  403. // The latency computation is done each time jack_port_get_total_latency is called
  404. return 0;
  405. }
  406. EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  407. {
  408. #ifdef __CLIENTDEBUG__
  409. JackLibGlobals::CheckContext();
  410. #endif
  411. jack_port_id_t myport = (jack_port_id_t)port;
  412. if (!CheckPort(myport)) {
  413. jack_error("jack_port_set_name called with an incorrect port %ld", myport);
  414. return -1;
  415. } else if (name == NULL) {
  416. jack_error("jack_port_set_name called with a NULL port name");
  417. return -1;
  418. } else {
  419. return GetGraphManager()->GetPort(myport)->SetName(name);
  420. }
  421. }
  422. EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
  423. {
  424. #ifdef __CLIENTDEBUG__
  425. JackLibGlobals::CheckContext();
  426. #endif
  427. jack_port_id_t myport = (jack_port_id_t)port;
  428. if (!CheckPort(myport)) {
  429. jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
  430. return -1;
  431. } else if (name == NULL) {
  432. jack_error("jack_port_set_alias called with a NULL port name");
  433. return -1;
  434. } else {
  435. return GetGraphManager()->GetPort(myport)->SetAlias(name);
  436. }
  437. }
  438. EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
  439. {
  440. #ifdef __CLIENTDEBUG__
  441. JackLibGlobals::CheckContext();
  442. #endif
  443. jack_port_id_t myport = (jack_port_id_t)port;
  444. if (!CheckPort(myport)) {
  445. jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
  446. return -1;
  447. } else if (name == NULL) {
  448. jack_error("jack_port_unset_alias called with a NULL port name");
  449. return -1;
  450. } else {
  451. return GetGraphManager()->GetPort(myport)->UnsetAlias(name);
  452. }
  453. }
  454. EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  455. {
  456. #ifdef __CLIENTDEBUG__
  457. JackLibGlobals::CheckContext();
  458. #endif
  459. jack_port_id_t myport = (jack_port_id_t)port;
  460. if (!CheckPort(myport)) {
  461. jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
  462. return -1;
  463. } else {
  464. return GetGraphManager()->GetPort(myport)->GetAliases(aliases);
  465. }
  466. }
  467. EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  468. {
  469. #ifdef __CLIENTDEBUG__
  470. JackLibGlobals::CheckContext();
  471. #endif
  472. jack_port_id_t myport = (jack_port_id_t)port;
  473. if (!CheckPort(myport)) {
  474. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  475. return -1;
  476. } else {
  477. return GetGraphManager()->RequestMonitor(myport, onoff);
  478. }
  479. }
  480. EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  481. {
  482. #ifdef __CLIENTDEBUG__
  483. JackLibGlobals::CheckContext();
  484. #endif
  485. JackClient* client = (JackClient*)ext_client;
  486. if (client == NULL) {
  487. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  488. return -1;
  489. } else {
  490. jack_port_id_t myport = GetGraphManager()->GetPort(port_name);
  491. if (!CheckPort(myport)) {
  492. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  493. return -1;
  494. } else {
  495. return GetGraphManager()->RequestMonitor(myport, onoff);
  496. }
  497. }
  498. }
  499. EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  500. {
  501. #ifdef __CLIENTDEBUG__
  502. JackLibGlobals::CheckContext();
  503. #endif
  504. jack_port_id_t myport = (jack_port_id_t)port;
  505. if (!CheckPort(myport)) {
  506. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  507. return -1;
  508. } else {
  509. return GetGraphManager()->GetPort(myport)->EnsureMonitor(onoff);
  510. }
  511. }
  512. EXPORT int jack_port_monitoring_input(jack_port_t* port)
  513. {
  514. #ifdef __CLIENTDEBUG__
  515. JackLibGlobals::CheckContext();
  516. #endif
  517. jack_port_id_t myport = (jack_port_id_t)port;
  518. if (!CheckPort(myport)) {
  519. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  520. return -1;
  521. } else {
  522. return GetGraphManager()->GetPort(myport)->MonitoringInput();
  523. }
  524. }
  525. EXPORT int jack_is_realtime(jack_client_t* ext_client)
  526. {
  527. #ifdef __CLIENTDEBUG__
  528. JackLibGlobals::CheckContext();
  529. #endif
  530. JackClient* client = (JackClient*)ext_client;
  531. if (client == NULL) {
  532. jack_error("jack_is_realtime called with a NULL client");
  533. return -1;
  534. } else {
  535. return GetEngineControl()->fRealTime;
  536. }
  537. }
  538. EXPORT void jack_on_shutdown(jack_client_t* ext_client, void (*function)(void* arg), void* arg)
  539. {
  540. #ifdef __CLIENTDEBUG__
  541. JackLibGlobals::CheckContext();
  542. #endif
  543. JackClient* client = (JackClient*)ext_client;
  544. if (client == NULL) {
  545. jack_error("jack_on_shutdown called with a NULL client");
  546. } else {
  547. client->OnShutdown(function, arg);
  548. }
  549. }
  550. EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  551. {
  552. #ifdef __CLIENTDEBUG__
  553. JackLibGlobals::CheckContext();
  554. #endif
  555. JackClient* client = (JackClient*)ext_client;
  556. if (client == NULL) {
  557. jack_error("jack_set_process_callback called with a NULL client");
  558. return -1;
  559. } else {
  560. return client->SetProcessCallback(callback, arg);
  561. }
  562. }
  563. EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  564. {
  565. #ifdef __CLIENTDEBUG__
  566. JackLibGlobals::CheckContext();
  567. #endif
  568. JackClient* client = (JackClient*)ext_client;
  569. if (client == NULL) {
  570. jack_error("jack_set_freewheel_callback called with a NULL client");
  571. return -1;
  572. } else {
  573. return client->SetFreewheelCallback(freewheel_callback, arg);
  574. }
  575. }
  576. EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  577. {
  578. #ifdef __CLIENTDEBUG__
  579. JackLibGlobals::CheckContext();
  580. #endif
  581. JackClient* client = (JackClient*)ext_client;
  582. if (client == NULL) {
  583. jack_error("jack_set_freewheel called with a NULL client");
  584. return -1;
  585. } else {
  586. return client->SetFreeWheel(onoff);
  587. }
  588. }
  589. EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  590. {
  591. #ifdef __CLIENTDEBUG__
  592. JackLibGlobals::CheckContext();
  593. #endif
  594. JackClient* client = (JackClient*)ext_client;
  595. if (client == NULL) {
  596. jack_error("jack_set_buffer_size called with a NULL client");
  597. return -1;
  598. } else if (!CheckBufferSize(buffer_size)) {
  599. return -1;
  600. } else {
  601. return client->SetBufferSize(buffer_size);
  602. }
  603. }
  604. EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  605. {
  606. #ifdef __CLIENTDEBUG__
  607. JackLibGlobals::CheckContext();
  608. #endif
  609. JackClient* client = (JackClient*)ext_client;
  610. if (client == NULL) {
  611. jack_error("jack_set_buffer_size_callback called with a NULL client");
  612. return -1;
  613. } else {
  614. return client->SetBufferSizeCallback(bufsize_callback, arg);
  615. }
  616. }
  617. EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  618. {
  619. #ifdef __CLIENTDEBUG__
  620. JackLibGlobals::CheckContext();
  621. #endif
  622. JackClient* client = (JackClient*)ext_client;
  623. if (client == NULL) {
  624. jack_error("jack_set_sample_rate_callback called with a NULL client");
  625. return -1;
  626. } else {
  627. jack_error("jack_set_sample_rate_callback: deprecated");
  628. return 0;
  629. }
  630. }
  631. EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  632. {
  633. #ifdef __CLIENTDEBUG__
  634. JackLibGlobals::CheckContext();
  635. #endif
  636. JackClient* client = (JackClient*)ext_client;
  637. if (client == NULL) {
  638. jack_error("jack_set_client_registration_callback called with a NULL client");
  639. return -1;
  640. } else {
  641. return client->SetClientRegistrationCallback(registration_callback, arg);
  642. }
  643. }
  644. EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  645. {
  646. #ifdef __CLIENTDEBUG__
  647. JackLibGlobals::CheckContext();
  648. #endif
  649. JackClient* client = (JackClient*)ext_client;
  650. if (client == NULL) {
  651. jack_error("jack_set_port_registration_callback called with a NULL client");
  652. return -1;
  653. } else {
  654. return client->SetPortRegistrationCallback(registration_callback, arg);
  655. }
  656. }
  657. EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
  658. {
  659. #ifdef __CLIENTDEBUG__
  660. JackLibGlobals::CheckContext();
  661. #endif
  662. JackClient* client = (JackClient*)ext_client;
  663. if (client == NULL) {
  664. jack_error("jack_set_port_connect_callback called with a NULL client");
  665. return -1;
  666. } else {
  667. return client->SetPortConnectCallback(portconnect_callback, arg);
  668. }
  669. }
  670. EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  671. {
  672. #ifdef __CLIENTDEBUG__
  673. JackLibGlobals::CheckContext();
  674. #endif
  675. JackClient* client = (JackClient*)ext_client;
  676. JackLog("jack_set_graph_order_callback ext_client %x client %x \n", ext_client, client);
  677. if (client == NULL) {
  678. jack_error("jack_set_graph_order_callback called with a NULL client");
  679. return -1;
  680. } else {
  681. return client->SetGraphOrderCallback(graph_callback, arg);
  682. }
  683. }
  684. EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  685. {
  686. #ifdef __CLIENTDEBUG__
  687. JackLibGlobals::CheckContext();
  688. #endif
  689. JackClient* client = (JackClient*)ext_client;
  690. if (client == NULL) {
  691. jack_error("jack_set_xrun_callback called with a NULL client");
  692. return -1;
  693. } else {
  694. return client->SetXRunCallback(xrun_callback, arg);
  695. }
  696. }
  697. EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  698. {
  699. #ifdef __CLIENTDEBUG__
  700. JackLibGlobals::CheckContext();
  701. #endif
  702. JackClient* client = (JackClient*)ext_client;
  703. JackLog("jack_set_thread_init_callback ext_client %x client %x \n", ext_client, client);
  704. if (client == NULL) {
  705. jack_error("jack_set_thread_init_callback called with a NULL client");
  706. return -1;
  707. } else {
  708. return client->SetInitCallback(init_callback, arg);
  709. }
  710. }
  711. EXPORT int jack_activate(jack_client_t* ext_client)
  712. {
  713. #ifdef __CLIENTDEBUG__
  714. JackLibGlobals::CheckContext();
  715. #endif
  716. JackClient* client = (JackClient*)ext_client;
  717. if (client == NULL) {
  718. jack_error("jack_activate called with a NULL client");
  719. return -1;
  720. } else {
  721. return client->Activate();
  722. }
  723. }
  724. EXPORT int jack_deactivate(jack_client_t* ext_client)
  725. {
  726. #ifdef __CLIENTDEBUG__
  727. JackLibGlobals::CheckContext();
  728. #endif
  729. JackClient* client = (JackClient*)ext_client;
  730. if (client == NULL) {
  731. jack_error("jack_deactivate called with a NULL client");
  732. return -1;
  733. } else {
  734. return client->Deactivate();
  735. }
  736. }
  737. 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)
  738. {
  739. #ifdef __CLIENTDEBUG__
  740. JackLibGlobals::CheckContext();
  741. #endif
  742. JackClient* client = (JackClient*)ext_client;
  743. if (client == NULL) {
  744. jack_error("jack_port_register called with a NULL client");
  745. return NULL;
  746. } else if ((port_name == NULL) || (port_type == NULL)) {
  747. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  748. return NULL;
  749. } else {
  750. return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
  751. }
  752. }
  753. EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  754. {
  755. #ifdef __CLIENTDEBUG__
  756. JackLibGlobals::CheckContext();
  757. #endif
  758. JackClient* client = (JackClient*)ext_client;
  759. if (client == NULL) {
  760. jack_error("jack_port_unregister called with a NULL client");
  761. return -1;
  762. }
  763. jack_port_id_t myport = (jack_port_id_t)port;
  764. if (!CheckPort(myport)) {
  765. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  766. return -1;
  767. }
  768. return client->PortUnRegister(myport);
  769. }
  770. EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  771. {
  772. #ifdef __CLIENTDEBUG__
  773. JackLibGlobals::CheckContext();
  774. #endif
  775. JackClient* client = (JackClient*)ext_client;
  776. if (client == NULL) {
  777. jack_error("jack_port_is_mine called with a NULL client");
  778. return -1;
  779. }
  780. jack_port_id_t myport = (jack_port_id_t)port;
  781. if (!CheckPort(myport)) {
  782. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  783. return -1;
  784. }
  785. return client->PortIsMine(myport);
  786. }
  787. EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  788. {
  789. #ifdef __CLIENTDEBUG__
  790. JackLibGlobals::CheckContext();
  791. #endif
  792. jack_port_id_t myport = (jack_port_id_t)port;
  793. if (!CheckPort(myport)) {
  794. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  795. return NULL;
  796. } else {
  797. WaitGraphChange();
  798. return GetGraphManager()->GetConnections(myport);
  799. }
  800. }
  801. // Calling client does not need to "own" the port
  802. EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  803. {
  804. #ifdef __CLIENTDEBUG__
  805. JackLibGlobals::CheckContext();
  806. #endif
  807. JackClient* client = (JackClient*)ext_client;
  808. if (client == NULL) {
  809. jack_error("jack_port_get_all_connections called with a NULL client");
  810. return NULL;
  811. }
  812. jack_port_id_t myport = (jack_port_id_t)port;
  813. if (!CheckPort(myport)) {
  814. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  815. return NULL;
  816. } else {
  817. WaitGraphChange();
  818. return GetGraphManager()->GetConnections(myport);
  819. }
  820. }
  821. EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  822. {
  823. #ifdef __CLIENTDEBUG__
  824. JackLibGlobals::CheckContext();
  825. #endif
  826. JackClient* client = (JackClient*)ext_client;
  827. if (client == NULL) {
  828. jack_error("jack_port_get_total_latency called with a NULL client");
  829. return 0;
  830. }
  831. jack_port_id_t myport = (jack_port_id_t)port;
  832. if (!CheckPort(myport)) {
  833. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  834. return 0;
  835. } else {
  836. // The latency computation is done each time
  837. WaitGraphChange();
  838. return GetGraphManager()->GetTotalLatency(myport);
  839. }
  840. }
  841. EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  842. {
  843. #ifdef __CLIENTDEBUG__
  844. JackLibGlobals::CheckContext();
  845. #endif
  846. JackClient* client = (JackClient*)ext_client;
  847. if (client == NULL) {
  848. jack_error("jack_connect called with a NULL client");
  849. return -1;
  850. } else if ((src == NULL) || (dst == NULL)) {
  851. jack_error("jack_connect called with a NULL port name");
  852. return -1;
  853. } else {
  854. return client->PortConnect(src, dst);
  855. }
  856. }
  857. EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  858. {
  859. #ifdef __CLIENTDEBUG__
  860. JackLibGlobals::CheckContext();
  861. #endif
  862. JackClient* client = (JackClient*)ext_client;
  863. if (client == NULL) {
  864. jack_error("jack_disconnect called with a NULL client");
  865. return -1;
  866. } else if ((src == NULL) || (dst == NULL)) {
  867. jack_error("jack_connect called with a NULL port name");
  868. return -1;
  869. } else {
  870. return client->PortDisconnect(src, dst);
  871. }
  872. }
  873. EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst)
  874. {
  875. #ifdef __CLIENTDEBUG__
  876. JackLibGlobals::CheckContext();
  877. #endif
  878. JackClient* client = (JackClient*)ext_client;
  879. if (client == NULL) {
  880. jack_error("jack_port_connect called with a NULL client");
  881. return -1;
  882. }
  883. jack_port_id_t mysrc = (jack_port_id_t)src;
  884. if (!CheckPort(mysrc)) {
  885. jack_error("jack_port_connect called with a NULL src port");
  886. return -1;
  887. }
  888. jack_port_id_t mydst = (jack_port_id_t)dst;
  889. if (!CheckPort(mydst)) {
  890. jack_error("jack_port_connect called with a NULL dst port");
  891. return -1;
  892. }
  893. return client->PortConnect(mysrc, mydst);
  894. }
  895. EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  896. {
  897. #ifdef __CLIENTDEBUG__
  898. JackLibGlobals::CheckContext();
  899. #endif
  900. JackClient* client = (JackClient*)ext_client;
  901. if (client == NULL) {
  902. jack_error("jack_port_disconnect called with a NULL client");
  903. return -1;
  904. }
  905. jack_port_id_t myport = (jack_port_id_t)src;
  906. if (!CheckPort(myport)) {
  907. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  908. return -1;
  909. }
  910. return client->PortDisconnect(myport);
  911. }
  912. EXPORT jack_nframes_t jack_get_sample_rate(jack_client_t* ext_client)
  913. {
  914. #ifdef __CLIENTDEBUG__
  915. JackLibGlobals::CheckContext();
  916. #endif
  917. JackClient* client = (JackClient*)ext_client;
  918. if (client == NULL) {
  919. jack_error("jack_get_sample_rate called with a NULL client");
  920. return 0;
  921. } else {
  922. return GetEngineControl()->fSampleRate;
  923. }
  924. }
  925. EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  926. {
  927. #ifdef __CLIENTDEBUG__
  928. JackLibGlobals::CheckContext();
  929. #endif
  930. JackClient* client = (JackClient*)ext_client;
  931. if (client == NULL) {
  932. jack_error("jack_get_buffer_size called with a NULL client");
  933. return 0;
  934. } else {
  935. return GetEngineControl()->fBufferSize;
  936. }
  937. }
  938. EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  939. {
  940. #ifdef __CLIENTDEBUG__
  941. JackLibGlobals::CheckContext();
  942. #endif
  943. JackClient* client = (JackClient*)ext_client;
  944. if (client == NULL) {
  945. jack_error("jack_get_ports called with a NULL client");
  946. return NULL;
  947. }
  948. return GetGraphManager()->GetPorts(port_name_pattern, type_name_pattern, flags);
  949. }
  950. EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  951. {
  952. #ifdef __CLIENTDEBUG__
  953. JackLibGlobals::CheckContext();
  954. #endif
  955. JackClient* client = (JackClient*)ext_client;
  956. if (client == NULL) {
  957. jack_error("jack_get_ports called with a NULL client");
  958. return 0;
  959. }
  960. if (portname == NULL) {
  961. jack_error("jack_port_by_name called with a NULL port name");
  962. return NULL;
  963. } else {
  964. int res = GetGraphManager()->GetPort(portname); // returns a port index at least > 1
  965. return (res == NO_PORT) ? NULL : (jack_port_t*)res;
  966. }
  967. }
  968. EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  969. {
  970. #ifdef __CLIENTDEBUG__
  971. JackLibGlobals::CheckContext();
  972. #endif
  973. /* jack_port_t* type is actually the port index */
  974. return (jack_port_t*)id;
  975. }
  976. EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  977. {
  978. #ifdef __CLIENTDEBUG__
  979. JackLibGlobals::CheckContext();
  980. #endif
  981. JackClient* client = (JackClient*)ext_client;
  982. if (client == NULL) {
  983. jack_error("jack_engine_takeover_timebase called with a NULL client");
  984. return -1;
  985. } else {
  986. jack_error("jack_engine_takeover_timebase: deprecated\n");
  987. return 0;
  988. }
  989. }
  990. EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  991. {
  992. #ifdef __CLIENTDEBUG__
  993. JackLibGlobals::CheckContext();
  994. #endif
  995. JackTimer timer;
  996. GetEngineControl()->ReadFrameTime(&timer);
  997. return (jack_nframes_t) floor((((float)GetEngineControl()->fSampleRate) / 1000000.0f) * (GetMicroSeconds() - timer.fCurrentCallback));
  998. }
  999. EXPORT jack_time_t jack_get_time(jack_client_t *client)
  1000. {
  1001. return GetMicroSeconds();
  1002. }
  1003. EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1004. {
  1005. #ifdef __CLIENTDEBUG__
  1006. JackLibGlobals::CheckContext();
  1007. #endif
  1008. JackClient* client = (JackClient*)ext_client;
  1009. if (client == NULL) {
  1010. jack_error("jack_frames_to_time called with a NULL client");
  1011. return 0;
  1012. } else {
  1013. JackTimer timer;
  1014. GetEngineControl()->ReadFrameTime(&timer);
  1015. if (timer.fInitialized) {
  1016. return timer.fCurrentWakeup +
  1017. (long) rint(((double) ((frames - timer.fFrames)) *
  1018. ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) / GetEngineControl()->fBufferSize);
  1019. } else {
  1020. return 0;
  1021. }
  1022. }
  1023. }
  1024. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1025. {
  1026. #ifdef __CLIENTDEBUG__
  1027. JackLibGlobals::CheckContext();
  1028. #endif
  1029. JackClient* client = (JackClient*)ext_client;
  1030. if (client == NULL) {
  1031. jack_error("jack_time_to_frames called with a NULL client");
  1032. return 0;
  1033. } else {
  1034. JackTimer timer;
  1035. GetEngineControl()->ReadFrameTime(&timer);
  1036. if (timer.fInitialized) {
  1037. return timer.fFrames +
  1038. (long) rint(((double) ((time - timer.fCurrentWakeup)) /
  1039. ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) * GetEngineControl()->fBufferSize);
  1040. } else {
  1041. return 0;
  1042. }
  1043. }
  1044. }
  1045. EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1046. {
  1047. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1048. }
  1049. EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1050. {
  1051. #ifdef __CLIENTDEBUG__
  1052. JackLibGlobals::CheckContext();
  1053. #endif
  1054. JackTimer timer;
  1055. GetEngineControl()->ReadFrameTime(&timer);
  1056. return timer.fFrames;
  1057. }
  1058. EXPORT float jack_cpu_load(jack_client_t* ext_client)
  1059. {
  1060. #ifdef __CLIENTDEBUG__
  1061. JackLibGlobals::CheckContext();
  1062. #endif
  1063. JackClient* client = (JackClient*)ext_client;
  1064. if (client == NULL) {
  1065. jack_error("jack_cpu_load called with a NULL client");
  1066. return 0.0f;
  1067. } else {
  1068. return GetEngineControl()->fCPULoad;
  1069. }
  1070. }
  1071. EXPORT pthread_t jack_client_thread_id(jack_client_t* ext_client)
  1072. {
  1073. #ifdef __CLIENTDEBUG__
  1074. JackLibGlobals::CheckContext();
  1075. #endif
  1076. JackClient* client = (JackClient*)ext_client;
  1077. if (client == NULL) {
  1078. jack_error("jack_client_thread_id called with a NULL client");
  1079. return (pthread_t)NULL;
  1080. } else {
  1081. return client->GetThreadID();
  1082. }
  1083. }
  1084. EXPORT char* jack_get_client_name (jack_client_t* ext_client)
  1085. {
  1086. #ifdef __CLIENTDEBUG__
  1087. JackLibGlobals::CheckContext();
  1088. #endif
  1089. JackClient* client = (JackClient*)ext_client;
  1090. if (client == NULL) {
  1091. jack_error("jack_get_client_name called with a NULL client");
  1092. return NULL;
  1093. } else {
  1094. return client->GetClientControl()->fName;
  1095. }
  1096. }
  1097. EXPORT int jack_client_name_size(void)
  1098. {
  1099. return JACK_CLIENT_NAME_SIZE;
  1100. }
  1101. EXPORT int jack_port_name_size(void)
  1102. {
  1103. return JACK_PORT_NAME_SIZE;
  1104. }
  1105. EXPORT int jack_port_type_size(void)
  1106. {
  1107. return JACK_PORT_TYPE_SIZE;
  1108. }
  1109. // transport.h
  1110. EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1111. {
  1112. #ifdef __CLIENTDEBUG__
  1113. JackLibGlobals::CheckContext();
  1114. #endif
  1115. JackClient* client = (JackClient*)ext_client;
  1116. if (client == NULL) {
  1117. jack_error("jack_release_timebase called with a NULL client");
  1118. return -1;
  1119. } else {
  1120. return client->ReleaseTimebase();
  1121. }
  1122. }
  1123. EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  1124. {
  1125. #ifdef __CLIENTDEBUG__
  1126. JackLibGlobals::CheckContext();
  1127. #endif
  1128. JackClient* client = (JackClient*)ext_client;
  1129. if (client == NULL) {
  1130. jack_error("jack_set_sync_callback called with a NULL client");
  1131. return -1;
  1132. } else {
  1133. return client->SetSyncCallback(sync_callback, arg);
  1134. }
  1135. }
  1136. EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1137. {
  1138. #ifdef __CLIENTDEBUG__
  1139. JackLibGlobals::CheckContext();
  1140. #endif
  1141. JackClient* client = (JackClient*)ext_client;
  1142. if (client == NULL) {
  1143. jack_error("jack_set_sync_timeout called with a NULL client");
  1144. return -1;
  1145. } else {
  1146. return client->SetSyncTimeout(timeout);
  1147. }
  1148. }
  1149. EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1150. {
  1151. #ifdef __CLIENTDEBUG__
  1152. JackLibGlobals::CheckContext();
  1153. #endif
  1154. JackClient* client = (JackClient*)ext_client;
  1155. if (client == NULL) {
  1156. jack_error("jack_set_timebase_callback called with a NULL client");
  1157. return -1;
  1158. } else {
  1159. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1160. }
  1161. }
  1162. EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1163. {
  1164. #ifdef __CLIENTDEBUG__
  1165. JackLibGlobals::CheckContext();
  1166. #endif
  1167. JackClient* client = (JackClient*)ext_client;
  1168. if (client == NULL) {
  1169. jack_error("jack_transport_locate called with a NULL client");
  1170. return -1;
  1171. } else {
  1172. return client->TransportLocate(frame);
  1173. }
  1174. }
  1175. EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1176. {
  1177. #ifdef __CLIENTDEBUG__
  1178. JackLibGlobals::CheckContext();
  1179. #endif
  1180. JackClient* client = (JackClient*)ext_client;
  1181. if (client == NULL) {
  1182. jack_error("jack_transport_query called with a NULL client");
  1183. return JackTransportStopped;
  1184. } else {
  1185. return client->TransportQuery(pos);
  1186. }
  1187. }
  1188. EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1189. {
  1190. #ifdef __CLIENTDEBUG__
  1191. JackLibGlobals::CheckContext();
  1192. #endif
  1193. JackClient* client = (JackClient*)ext_client;
  1194. if (client == NULL) {
  1195. jack_error("jack_get_current_transport_frame called with a NULL client");
  1196. return 0;
  1197. } else {
  1198. return client->GetCurrentTransportFrame();
  1199. }
  1200. }
  1201. EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
  1202. {
  1203. #ifdef __CLIENTDEBUG__
  1204. JackLibGlobals::CheckContext();
  1205. #endif
  1206. JackClient* client = (JackClient*)ext_client;
  1207. if (client == NULL) {
  1208. jack_error("jack_transport_reposition called with a NULL client");
  1209. return -1;
  1210. } else {
  1211. return client->TransportReposition(pos);
  1212. }
  1213. }
  1214. EXPORT void jack_transport_start(jack_client_t* ext_client)
  1215. {
  1216. #ifdef __CLIENTDEBUG__
  1217. JackLibGlobals::CheckContext();
  1218. #endif
  1219. JackClient* client = (JackClient*)ext_client;
  1220. if (client == NULL) {
  1221. jack_error("jack_transport_start called with a NULL client");
  1222. } else {
  1223. client->TransportStart();
  1224. }
  1225. }
  1226. EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1227. {
  1228. #ifdef __CLIENTDEBUG__
  1229. JackLibGlobals::CheckContext();
  1230. #endif
  1231. JackClient* client = (JackClient*)ext_client;
  1232. if (client == NULL) {
  1233. jack_error("jack_transport_stop called with a NULL client");
  1234. } else {
  1235. client->TransportStop();
  1236. }
  1237. }
  1238. // deprecated
  1239. EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1240. {
  1241. jack_error("jack_get_transport_info: deprecated");
  1242. if (tinfo)
  1243. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1244. }
  1245. EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1246. {
  1247. jack_error("jack_set_transport_info: deprecated");
  1248. if (tinfo)
  1249. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1250. }
  1251. // statistics.h
  1252. EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1253. {
  1254. #ifdef __CLIENTDEBUG__
  1255. JackLibGlobals::CheckContext();
  1256. #endif
  1257. JackLog("jack_get_max_delayed_usecs: not yet implemented\n");
  1258. return 0.f;
  1259. }
  1260. EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1261. {
  1262. #ifdef __CLIENTDEBUG__
  1263. JackLibGlobals::CheckContext();
  1264. #endif
  1265. JackLog("jack_get_xrun_delayed_usecs: not yet implemented\n");
  1266. return 0.f;
  1267. }
  1268. EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1269. {
  1270. #ifdef __CLIENTDEBUG__
  1271. JackLibGlobals::CheckContext();
  1272. #endif
  1273. JackLog("jack_reset_max_delayed_usecs: not yet implemented\n");
  1274. }
  1275. // thread.h
  1276. EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
  1277. {
  1278. #ifdef __APPLE__
  1279. return JackMachThread::AcquireRealTimeImp(thread, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
  1280. #elif WIN32
  1281. return JackWinThread::AcquireRealTimeImp(thread, priority);
  1282. #else
  1283. return JackPosixThread::AcquireRealTimeImp(thread, priority);
  1284. #endif
  1285. }
  1286. EXPORT int jack_client_create_thread(jack_client_t* client,
  1287. pthread_t *thread,
  1288. int priority,
  1289. int realtime, /* boolean */
  1290. void *(*start_routine)(void*),
  1291. void *arg)
  1292. {
  1293. #ifdef __APPLE__
  1294. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1295. #elif WIN32
  1296. return JackWinThread::StartImp(thread, priority, realtime, (ThreadCallback)start_routine, arg);
  1297. #else
  1298. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1299. #endif
  1300. }
  1301. EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
  1302. {
  1303. #ifdef __APPLE__
  1304. return JackMachThread::DropRealTimeImp(thread);
  1305. #elif WIN32
  1306. return JackWinThread::DropRealTimeImp(thread);
  1307. #else
  1308. return JackPosixThread::DropRealTimeImp(thread);
  1309. #endif
  1310. }
  1311. // intclient.h
  1312. EXPORT int jack_internal_client_new (const char *client_name,
  1313. const char *load_name,
  1314. const char *load_init)
  1315. {
  1316. jack_error("jack_internal_client_new: deprecated");
  1317. return -1;
  1318. }
  1319. EXPORT void jack_internal_client_close (const char *client_name)
  1320. {
  1321. jack_error("jack_internal_client_close: deprecated");
  1322. }
  1323. EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1324. {
  1325. #ifdef __CLIENTDEBUG__
  1326. JackLibGlobals::CheckContext();
  1327. #endif
  1328. JackClient* client = (JackClient*)ext_client;
  1329. if (client == NULL) {
  1330. jack_error("jack_get_internal_client_name called with a NULL client");
  1331. return NULL;
  1332. } else if (intclient < 0 || intclient >= CLIENT_NUM) {
  1333. jack_error("jack_get_internal_client_name: incorrect client");
  1334. return NULL;
  1335. } else {
  1336. return client->GetInternalClientName(intclient);
  1337. }
  1338. }
  1339. EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1340. {
  1341. #ifdef __CLIENTDEBUG__
  1342. JackLibGlobals::CheckContext();
  1343. #endif
  1344. JackClient* client = (JackClient*)ext_client;
  1345. if (client == NULL) {
  1346. jack_error("jack_internal_client_handle called with a NULL client");
  1347. return 0;
  1348. } else {
  1349. jack_status_t my_status;
  1350. if (status == NULL) /* no status from caller? */
  1351. status = &my_status; /* use local status word */
  1352. *status = (jack_status_t)0;
  1353. return client->InternalClientHandle(client_name, status);
  1354. }
  1355. }
  1356. EXPORT jack_intclient_t jack_internal_client_load(jack_client_t* ext_client, const char* client_name, jack_options_t options, jack_status_t* status, ...)
  1357. {
  1358. #ifdef __CLIENTDEBUG__
  1359. JackLibGlobals::CheckContext();
  1360. #endif
  1361. JackClient* client = (JackClient*)ext_client;
  1362. if (client == NULL) {
  1363. jack_error("jack_internal_client_load called with a NULL client");
  1364. return 0;
  1365. } else {
  1366. va_list ap;
  1367. jack_varargs_t va;
  1368. jack_status_t my_status;
  1369. if (status == NULL) /* no status from caller? */
  1370. status = &my_status; /* use local status word */
  1371. *status = (jack_status_t)0;
  1372. /* validate parameters */
  1373. if ((options & ~JackLoadOptions)) {
  1374. int my_status1 = *status | (JackFailure | JackInvalidOption);
  1375. *status = (jack_status_t)my_status1;
  1376. return 0;
  1377. }
  1378. /* parse variable arguments */
  1379. va_start(ap, status);
  1380. jack_varargs_parse(options, ap, &va);
  1381. va_end(ap);
  1382. return client->InternalClientLoad(client_name, options, status, &va);
  1383. }
  1384. }
  1385. EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1386. {
  1387. #ifdef __CLIENTDEBUG__
  1388. JackLibGlobals::CheckContext();
  1389. #endif
  1390. JackClient* client = (JackClient*)ext_client;
  1391. if (client == NULL) {
  1392. jack_error("jack_internal_client_unload called with a NULL client");
  1393. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1394. } else if (intclient < 0 || intclient >= CLIENT_NUM) {
  1395. jack_error("jack_internal_client_unload: incorrect client");
  1396. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1397. } else {
  1398. jack_status_t my_status;
  1399. client->InternalClientUnload(intclient, &my_status);
  1400. return my_status;
  1401. }
  1402. }