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.

1534 lines
49KB

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