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.

1548 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_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* port_name)
  314. {
  315. #ifdef __CLIENTDEBUG__
  316. JackLibGlobals::CheckContext();
  317. #endif
  318. jack_port_id_t src = (jack_port_id_t)port;
  319. if (!CheckPort(src)) {
  320. jack_error("jack_port_connected_to called with an incorrect port %ld", src);
  321. return -1;
  322. } else if (port_name == NULL) {
  323. jack_error("jack_port_connected_to called with a NULL port name");
  324. return -1;
  325. } else {
  326. WaitGraphChange();
  327. jack_port_id_t dst = GetGraphManager()->GetPort(port_name);
  328. if (dst == NO_PORT) {
  329. jack_error("Unknown destination port port_name = %s", port_name);
  330. return 0;
  331. } else {
  332. return GetGraphManager()->IsConnected(src, dst);
  333. }
  334. }
  335. }
  336. EXPORT int jack_port_tie(jack_port_t* src, jack_port_t* dst)
  337. {
  338. #ifdef __CLIENTDEBUG__
  339. JackLibGlobals::CheckContext();
  340. #endif
  341. jack_port_id_t mysrc = (jack_port_id_t)src;
  342. if (!CheckPort(mysrc)) {
  343. jack_error("jack_port_tie called with a NULL src port");
  344. return -1;
  345. }
  346. jack_port_id_t mydst = (jack_port_id_t)dst;
  347. if (!CheckPort(mydst)) {
  348. jack_error("jack_port_tie called with a NULL dst port");
  349. return -1;
  350. }
  351. if (GetGraphManager()->GetPort(mysrc)->GetRefNum() != GetGraphManager()->GetPort(mydst)->GetRefNum()) {
  352. jack_error("jack_port_tie called with ports not belonging to the same client");
  353. return -1;
  354. }
  355. return GetGraphManager()->GetPort(mydst)->Tie(mysrc);
  356. }
  357. EXPORT int jack_port_untie(jack_port_t* port)
  358. {
  359. #ifdef __CLIENTDEBUG__
  360. JackLibGlobals::CheckContext();
  361. #endif
  362. jack_port_id_t myport = (jack_port_id_t)port;
  363. if (!CheckPort(myport)) {
  364. jack_error("jack_port_untie called with an incorrect port %ld", myport);
  365. return -1;
  366. } else {
  367. return GetGraphManager()->GetPort(myport)->UnTie();
  368. }
  369. }
  370. EXPORT jack_nframes_t jack_port_get_latency(jack_port_t* port)
  371. {
  372. #ifdef __CLIENTDEBUG__
  373. JackLibGlobals::CheckContext();
  374. #endif
  375. jack_port_id_t myport = (jack_port_id_t)port;
  376. if (!CheckPort(myport)) {
  377. jack_error("jack_port_get_latency called with an incorrect port %ld", myport);
  378. return 0;
  379. } else {
  380. WaitGraphChange();
  381. return GetGraphManager()->GetPort(myport)->GetLatency();
  382. }
  383. }
  384. EXPORT void jack_port_set_latency(jack_port_t* port, jack_nframes_t frames)
  385. {
  386. #ifdef __CLIENTDEBUG__
  387. JackLibGlobals::CheckContext();
  388. #endif
  389. jack_port_id_t myport = (jack_port_id_t)port;
  390. if (!CheckPort(myport)) {
  391. jack_error("jack_port_set_latency called with an incorrect port %ld", myport);
  392. } else {
  393. GetGraphManager()->GetPort(myport)->SetLatency(frames);
  394. }
  395. }
  396. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client, jack_port_t* port)
  397. {
  398. #ifdef __CLIENTDEBUG__
  399. JackLibGlobals::CheckContext();
  400. #endif
  401. JackClient* client = (JackClient*)ext_client;
  402. jack_port_id_t myport = (jack_port_id_t)port;
  403. if (client == NULL) {
  404. jack_error("jack_recompute_total_latencies called with a NULL client");
  405. return -1;
  406. } else if (!CheckPort(myport)) {
  407. jack_error("jack_recompute_total_latencies called with a NULL port");
  408. return -1;
  409. } else {
  410. // TODO
  411. }
  412. // The latency computation is done each time jack_port_get_total_latency is called
  413. return 0;
  414. }
  415. EXPORT int jack_recompute_total_latencies(jack_client_t* ext_client)
  416. {
  417. #ifdef __CLIENTDEBUG__
  418. JackLibGlobals::CheckContext();
  419. #endif
  420. JackClient* client = (JackClient*)ext_client;
  421. if (client == NULL) {
  422. jack_error("jack_recompute_total_latencies called with a NULL client");
  423. return -1;
  424. } else {
  425. // TODO
  426. }
  427. // The latency computation is done each time jack_port_get_total_latency is called
  428. return 0;
  429. }
  430. EXPORT int jack_port_set_name(jack_port_t* port, const char* name)
  431. {
  432. #ifdef __CLIENTDEBUG__
  433. JackLibGlobals::CheckContext();
  434. #endif
  435. jack_port_id_t myport = (jack_port_id_t)port;
  436. if (!CheckPort(myport)) {
  437. jack_error("jack_port_set_name called with an incorrect port %ld", myport);
  438. return -1;
  439. } else if (name == NULL) {
  440. jack_error("jack_port_set_name called with a NULL port name");
  441. return -1;
  442. } else {
  443. return GetGraphManager()->GetPort(myport)->SetName(name);
  444. }
  445. }
  446. EXPORT int jack_port_set_alias(jack_port_t* port, const char* name)
  447. {
  448. #ifdef __CLIENTDEBUG__
  449. JackLibGlobals::CheckContext();
  450. #endif
  451. jack_port_id_t myport = (jack_port_id_t)port;
  452. if (!CheckPort(myport)) {
  453. jack_error("jack_port_set_alias called with an incorrect port %ld", myport);
  454. return -1;
  455. } else if (name == NULL) {
  456. jack_error("jack_port_set_alias called with a NULL port name");
  457. return -1;
  458. } else {
  459. return GetGraphManager()->GetPort(myport)->SetAlias(name);
  460. }
  461. }
  462. EXPORT int jack_port_unset_alias(jack_port_t* port, const char* name)
  463. {
  464. #ifdef __CLIENTDEBUG__
  465. JackLibGlobals::CheckContext();
  466. #endif
  467. jack_port_id_t myport = (jack_port_id_t)port;
  468. if (!CheckPort(myport)) {
  469. jack_error("jack_port_unset_alias called with an incorrect port %ld", myport);
  470. return -1;
  471. } else if (name == NULL) {
  472. jack_error("jack_port_unset_alias called with a NULL port name");
  473. return -1;
  474. } else {
  475. return GetGraphManager()->GetPort(myport)->UnsetAlias(name);
  476. }
  477. }
  478. EXPORT int jack_port_get_aliases(const jack_port_t* port, char* const aliases[2])
  479. {
  480. #ifdef __CLIENTDEBUG__
  481. JackLibGlobals::CheckContext();
  482. #endif
  483. jack_port_id_t myport = (jack_port_id_t)port;
  484. if (!CheckPort(myport)) {
  485. jack_error("jack_port_get_aliases called with an incorrect port %ld", myport);
  486. return -1;
  487. } else {
  488. return GetGraphManager()->GetPort(myport)->GetAliases(aliases);
  489. }
  490. }
  491. EXPORT int jack_port_request_monitor(jack_port_t* port, int onoff)
  492. {
  493. #ifdef __CLIENTDEBUG__
  494. JackLibGlobals::CheckContext();
  495. #endif
  496. jack_port_id_t myport = (jack_port_id_t)port;
  497. if (!CheckPort(myport)) {
  498. jack_error("jack_port_request_monitor called with an incorrect port %ld", myport);
  499. return -1;
  500. } else {
  501. return GetGraphManager()->RequestMonitor(myport, onoff);
  502. }
  503. }
  504. EXPORT int jack_port_request_monitor_by_name(jack_client_t* ext_client, const char* port_name, int onoff)
  505. {
  506. #ifdef __CLIENTDEBUG__
  507. JackLibGlobals::CheckContext();
  508. #endif
  509. JackClient* client = (JackClient*)ext_client;
  510. if (client == NULL) {
  511. jack_error("jack_port_request_monitor_by_name called with a NULL client");
  512. return -1;
  513. } else {
  514. jack_port_id_t myport = GetGraphManager()->GetPort(port_name);
  515. if (!CheckPort(myport)) {
  516. jack_error("jack_port_request_monitor_by_name called with an incorrect port %s", port_name);
  517. return -1;
  518. } else {
  519. return GetGraphManager()->RequestMonitor(myport, onoff);
  520. }
  521. }
  522. }
  523. EXPORT int jack_port_ensure_monitor(jack_port_t* port, int onoff)
  524. {
  525. #ifdef __CLIENTDEBUG__
  526. JackLibGlobals::CheckContext();
  527. #endif
  528. jack_port_id_t myport = (jack_port_id_t)port;
  529. if (!CheckPort(myport)) {
  530. jack_error("jack_port_ensure_monitor called with an incorrect port %ld", myport);
  531. return -1;
  532. } else {
  533. return GetGraphManager()->GetPort(myport)->EnsureMonitor(onoff);
  534. }
  535. }
  536. EXPORT int jack_port_monitoring_input(jack_port_t* port)
  537. {
  538. #ifdef __CLIENTDEBUG__
  539. JackLibGlobals::CheckContext();
  540. #endif
  541. jack_port_id_t myport = (jack_port_id_t)port;
  542. if (!CheckPort(myport)) {
  543. jack_error("jack_port_monitoring_input called with an incorrect port %ld", myport);
  544. return -1;
  545. } else {
  546. return GetGraphManager()->GetPort(myport)->MonitoringInput();
  547. }
  548. }
  549. EXPORT int jack_is_realtime(jack_client_t* ext_client)
  550. {
  551. #ifdef __CLIENTDEBUG__
  552. JackLibGlobals::CheckContext();
  553. #endif
  554. JackClient* client = (JackClient*)ext_client;
  555. if (client == NULL) {
  556. jack_error("jack_is_realtime called with a NULL client");
  557. return -1;
  558. } else {
  559. return GetEngineControl()->fRealTime;
  560. }
  561. }
  562. EXPORT void jack_on_shutdown(jack_client_t* ext_client, void (*function)(void* arg), void* arg)
  563. {
  564. #ifdef __CLIENTDEBUG__
  565. JackLibGlobals::CheckContext();
  566. #endif
  567. JackClient* client = (JackClient*)ext_client;
  568. if (client == NULL) {
  569. jack_error("jack_on_shutdown called with a NULL client");
  570. } else {
  571. client->OnShutdown(function, arg);
  572. }
  573. }
  574. EXPORT int jack_set_process_callback(jack_client_t* ext_client, JackProcessCallback callback, void* arg)
  575. {
  576. #ifdef __CLIENTDEBUG__
  577. JackLibGlobals::CheckContext();
  578. #endif
  579. JackClient* client = (JackClient*)ext_client;
  580. if (client == NULL) {
  581. jack_error("jack_set_process_callback called with a NULL client");
  582. return -1;
  583. } else {
  584. return client->SetProcessCallback(callback, arg);
  585. }
  586. }
  587. EXPORT int jack_set_freewheel_callback(jack_client_t* ext_client, JackFreewheelCallback freewheel_callback, void* arg)
  588. {
  589. #ifdef __CLIENTDEBUG__
  590. JackLibGlobals::CheckContext();
  591. #endif
  592. JackClient* client = (JackClient*)ext_client;
  593. if (client == NULL) {
  594. jack_error("jack_set_freewheel_callback called with a NULL client");
  595. return -1;
  596. } else {
  597. return client->SetFreewheelCallback(freewheel_callback, arg);
  598. }
  599. }
  600. EXPORT int jack_set_freewheel(jack_client_t* ext_client, int onoff)
  601. {
  602. #ifdef __CLIENTDEBUG__
  603. JackLibGlobals::CheckContext();
  604. #endif
  605. JackClient* client = (JackClient*)ext_client;
  606. if (client == NULL) {
  607. jack_error("jack_set_freewheel called with a NULL client");
  608. return -1;
  609. } else {
  610. return client->SetFreeWheel(onoff);
  611. }
  612. }
  613. EXPORT int jack_set_buffer_size(jack_client_t* ext_client, jack_nframes_t buffer_size)
  614. {
  615. #ifdef __CLIENTDEBUG__
  616. JackLibGlobals::CheckContext();
  617. #endif
  618. JackClient* client = (JackClient*)ext_client;
  619. if (client == NULL) {
  620. jack_error("jack_set_buffer_size called with a NULL client");
  621. return -1;
  622. } else if (!CheckBufferSize(buffer_size)) {
  623. return -1;
  624. } else {
  625. return client->SetBufferSize(buffer_size);
  626. }
  627. }
  628. EXPORT int jack_set_buffer_size_callback(jack_client_t* ext_client, JackBufferSizeCallback bufsize_callback, void* arg)
  629. {
  630. #ifdef __CLIENTDEBUG__
  631. JackLibGlobals::CheckContext();
  632. #endif
  633. JackClient* client = (JackClient*)ext_client;
  634. if (client == NULL) {
  635. jack_error("jack_set_buffer_size_callback called with a NULL client");
  636. return -1;
  637. } else {
  638. return client->SetBufferSizeCallback(bufsize_callback, arg);
  639. }
  640. }
  641. EXPORT int jack_set_sample_rate_callback(jack_client_t* ext_client, JackSampleRateCallback srate_callback, void* arg)
  642. {
  643. #ifdef __CLIENTDEBUG__
  644. JackLibGlobals::CheckContext();
  645. #endif
  646. JackClient* client = (JackClient*)ext_client;
  647. if (client == NULL) {
  648. jack_error("jack_set_sample_rate_callback called with a NULL client");
  649. return -1;
  650. } else {
  651. jack_error("jack_set_sample_rate_callback: deprecated");
  652. return 0;
  653. }
  654. }
  655. EXPORT int jack_set_client_registration_callback(jack_client_t* ext_client, JackClientRegistrationCallback registration_callback, void* arg)
  656. {
  657. #ifdef __CLIENTDEBUG__
  658. JackLibGlobals::CheckContext();
  659. #endif
  660. JackClient* client = (JackClient*)ext_client;
  661. if (client == NULL) {
  662. jack_error("jack_set_client_registration_callback called with a NULL client");
  663. return -1;
  664. } else {
  665. return client->SetClientRegistrationCallback(registration_callback, arg);
  666. }
  667. }
  668. EXPORT int jack_set_port_registration_callback(jack_client_t* ext_client, JackPortRegistrationCallback registration_callback, void* arg)
  669. {
  670. #ifdef __CLIENTDEBUG__
  671. JackLibGlobals::CheckContext();
  672. #endif
  673. JackClient* client = (JackClient*)ext_client;
  674. if (client == NULL) {
  675. jack_error("jack_set_port_registration_callback called with a NULL client");
  676. return -1;
  677. } else {
  678. return client->SetPortRegistrationCallback(registration_callback, arg);
  679. }
  680. }
  681. EXPORT int jack_set_port_connect_callback(jack_client_t* ext_client, JackPortConnectCallback portconnect_callback, void* arg)
  682. {
  683. #ifdef __CLIENTDEBUG__
  684. JackLibGlobals::CheckContext();
  685. #endif
  686. JackClient* client = (JackClient*)ext_client;
  687. if (client == NULL) {
  688. jack_error("jack_set_port_connect_callback called with a NULL client");
  689. return -1;
  690. } else {
  691. return client->SetPortConnectCallback(portconnect_callback, arg);
  692. }
  693. }
  694. EXPORT int jack_set_graph_order_callback(jack_client_t* ext_client, JackGraphOrderCallback graph_callback, void* arg)
  695. {
  696. #ifdef __CLIENTDEBUG__
  697. JackLibGlobals::CheckContext();
  698. #endif
  699. JackClient* client = (JackClient*)ext_client;
  700. JackLog("jack_set_graph_order_callback ext_client %x client %x \n", ext_client, client);
  701. if (client == NULL) {
  702. jack_error("jack_set_graph_order_callback called with a NULL client");
  703. return -1;
  704. } else {
  705. return client->SetGraphOrderCallback(graph_callback, arg);
  706. }
  707. }
  708. EXPORT int jack_set_xrun_callback(jack_client_t* ext_client, JackXRunCallback xrun_callback, void* arg)
  709. {
  710. #ifdef __CLIENTDEBUG__
  711. JackLibGlobals::CheckContext();
  712. #endif
  713. JackClient* client = (JackClient*)ext_client;
  714. if (client == NULL) {
  715. jack_error("jack_set_xrun_callback called with a NULL client");
  716. return -1;
  717. } else {
  718. return client->SetXRunCallback(xrun_callback, arg);
  719. }
  720. }
  721. EXPORT int jack_set_thread_init_callback(jack_client_t* ext_client, JackThreadInitCallback init_callback, void *arg)
  722. {
  723. #ifdef __CLIENTDEBUG__
  724. JackLibGlobals::CheckContext();
  725. #endif
  726. JackClient* client = (JackClient*)ext_client;
  727. JackLog("jack_set_thread_init_callback ext_client %x client %x \n", ext_client, client);
  728. if (client == NULL) {
  729. jack_error("jack_set_thread_init_callback called with a NULL client");
  730. return -1;
  731. } else {
  732. return client->SetInitCallback(init_callback, arg);
  733. }
  734. }
  735. EXPORT int jack_activate(jack_client_t* ext_client)
  736. {
  737. #ifdef __CLIENTDEBUG__
  738. JackLibGlobals::CheckContext();
  739. #endif
  740. JackClient* client = (JackClient*)ext_client;
  741. if (client == NULL) {
  742. jack_error("jack_activate called with a NULL client");
  743. return -1;
  744. } else {
  745. return client->Activate();
  746. }
  747. }
  748. EXPORT int jack_deactivate(jack_client_t* ext_client)
  749. {
  750. #ifdef __CLIENTDEBUG__
  751. JackLibGlobals::CheckContext();
  752. #endif
  753. JackClient* client = (JackClient*)ext_client;
  754. if (client == NULL) {
  755. jack_error("jack_deactivate called with a NULL client");
  756. return -1;
  757. } else {
  758. return client->Deactivate();
  759. }
  760. }
  761. 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)
  762. {
  763. #ifdef __CLIENTDEBUG__
  764. JackLibGlobals::CheckContext();
  765. #endif
  766. JackClient* client = (JackClient*)ext_client;
  767. if (client == NULL) {
  768. jack_error("jack_port_register called with a NULL client");
  769. return NULL;
  770. } else if ((port_name == NULL) || (port_type == NULL)) {
  771. jack_error("jack_port_register called with a NULL port name or a NULL port_type");
  772. return NULL;
  773. } else {
  774. return (jack_port_t *)client->PortRegister(port_name, port_type, flags, buffer_size);
  775. }
  776. }
  777. EXPORT int jack_port_unregister(jack_client_t* ext_client, jack_port_t* port)
  778. {
  779. #ifdef __CLIENTDEBUG__
  780. JackLibGlobals::CheckContext();
  781. #endif
  782. JackClient* client = (JackClient*)ext_client;
  783. if (client == NULL) {
  784. jack_error("jack_port_unregister called with a NULL client");
  785. return -1;
  786. }
  787. jack_port_id_t myport = (jack_port_id_t)port;
  788. if (!CheckPort(myport)) {
  789. jack_error("jack_port_unregister called with an incorrect port %ld", myport);
  790. return -1;
  791. }
  792. return client->PortUnRegister(myport);
  793. }
  794. EXPORT int jack_port_is_mine(const jack_client_t* ext_client, const jack_port_t* port)
  795. {
  796. #ifdef __CLIENTDEBUG__
  797. JackLibGlobals::CheckContext();
  798. #endif
  799. JackClient* client = (JackClient*)ext_client;
  800. if (client == NULL) {
  801. jack_error("jack_port_is_mine called with a NULL client");
  802. return -1;
  803. }
  804. jack_port_id_t myport = (jack_port_id_t)port;
  805. if (!CheckPort(myport)) {
  806. jack_error("jack_port_is_mine called with an incorrect port %ld", myport);
  807. return -1;
  808. }
  809. return client->PortIsMine(myport);
  810. }
  811. EXPORT const char** jack_port_get_connections(const jack_port_t* port)
  812. {
  813. #ifdef __CLIENTDEBUG__
  814. JackLibGlobals::CheckContext();
  815. #endif
  816. jack_port_id_t myport = (jack_port_id_t)port;
  817. if (!CheckPort(myport)) {
  818. jack_error("jack_port_get_connections called with an incorrect port %ld", myport);
  819. return NULL;
  820. } else {
  821. WaitGraphChange();
  822. return GetGraphManager()->GetConnections(myport);
  823. }
  824. }
  825. // Calling client does not need to "own" the port
  826. EXPORT const char** jack_port_get_all_connections(const jack_client_t* ext_client, const jack_port_t* port)
  827. {
  828. #ifdef __CLIENTDEBUG__
  829. JackLibGlobals::CheckContext();
  830. #endif
  831. JackClient* client = (JackClient*)ext_client;
  832. if (client == NULL) {
  833. jack_error("jack_port_get_all_connections called with a NULL client");
  834. return NULL;
  835. }
  836. jack_port_id_t myport = (jack_port_id_t)port;
  837. if (!CheckPort(myport)) {
  838. jack_error("jack_port_get_all_connections called with an incorrect port %ld", myport);
  839. return NULL;
  840. } else {
  841. WaitGraphChange();
  842. return GetGraphManager()->GetConnections(myport);
  843. }
  844. }
  845. EXPORT jack_nframes_t jack_port_get_total_latency(jack_client_t* ext_client, jack_port_t* port)
  846. {
  847. #ifdef __CLIENTDEBUG__
  848. JackLibGlobals::CheckContext();
  849. #endif
  850. JackClient* client = (JackClient*)ext_client;
  851. if (client == NULL) {
  852. jack_error("jack_port_get_total_latency called with a NULL client");
  853. return 0;
  854. }
  855. jack_port_id_t myport = (jack_port_id_t)port;
  856. if (!CheckPort(myport)) {
  857. jack_error("jack_port_get_total_latency called with an incorrect port %ld", myport);
  858. return 0;
  859. } else {
  860. // The latency computation is done each time
  861. WaitGraphChange();
  862. return GetGraphManager()->GetTotalLatency(myport);
  863. }
  864. }
  865. EXPORT int jack_connect(jack_client_t* ext_client, const char* src, const char* dst)
  866. {
  867. #ifdef __CLIENTDEBUG__
  868. JackLibGlobals::CheckContext();
  869. #endif
  870. JackClient* client = (JackClient*)ext_client;
  871. if (client == NULL) {
  872. jack_error("jack_connect called with a NULL client");
  873. return -1;
  874. } else if ((src == NULL) || (dst == NULL)) {
  875. jack_error("jack_connect called with a NULL port name");
  876. return -1;
  877. } else {
  878. return client->PortConnect(src, dst);
  879. }
  880. }
  881. EXPORT int jack_disconnect(jack_client_t* ext_client, const char* src, const char* dst)
  882. {
  883. #ifdef __CLIENTDEBUG__
  884. JackLibGlobals::CheckContext();
  885. #endif
  886. JackClient* client = (JackClient*)ext_client;
  887. if (client == NULL) {
  888. jack_error("jack_disconnect called with a NULL client");
  889. return -1;
  890. } else if ((src == NULL) || (dst == NULL)) {
  891. jack_error("jack_connect called with a NULL port name");
  892. return -1;
  893. } else {
  894. return client->PortDisconnect(src, dst);
  895. }
  896. }
  897. EXPORT int jack_port_connect(jack_client_t* ext_client, jack_port_t* src, jack_port_t* dst)
  898. {
  899. #ifdef __CLIENTDEBUG__
  900. JackLibGlobals::CheckContext();
  901. #endif
  902. JackClient* client = (JackClient*)ext_client;
  903. if (client == NULL) {
  904. jack_error("jack_port_connect called with a NULL client");
  905. return -1;
  906. }
  907. jack_port_id_t mysrc = (jack_port_id_t)src;
  908. if (!CheckPort(mysrc)) {
  909. jack_error("jack_port_connect called with a NULL src port");
  910. return -1;
  911. }
  912. jack_port_id_t mydst = (jack_port_id_t)dst;
  913. if (!CheckPort(mydst)) {
  914. jack_error("jack_port_connect called with a NULL dst port");
  915. return -1;
  916. }
  917. return client->PortConnect(mysrc, mydst);
  918. }
  919. EXPORT int jack_port_disconnect(jack_client_t* ext_client, jack_port_t* src)
  920. {
  921. #ifdef __CLIENTDEBUG__
  922. JackLibGlobals::CheckContext();
  923. #endif
  924. JackClient* client = (JackClient*)ext_client;
  925. if (client == NULL) {
  926. jack_error("jack_port_disconnect called with a NULL client");
  927. return -1;
  928. }
  929. jack_port_id_t myport = (jack_port_id_t)src;
  930. if (!CheckPort(myport)) {
  931. jack_error("jack_port_disconnect called with an incorrect port %ld", myport);
  932. return -1;
  933. }
  934. return client->PortDisconnect(myport);
  935. }
  936. EXPORT jack_nframes_t jack_get_sample_rate(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_sample_rate called with a NULL client");
  944. return 0;
  945. } else {
  946. return GetEngineControl()->fSampleRate;
  947. }
  948. }
  949. EXPORT jack_nframes_t jack_get_buffer_size(jack_client_t* ext_client)
  950. {
  951. #ifdef __CLIENTDEBUG__
  952. JackLibGlobals::CheckContext();
  953. #endif
  954. JackClient* client = (JackClient*)ext_client;
  955. if (client == NULL) {
  956. jack_error("jack_get_buffer_size called with a NULL client");
  957. return 0;
  958. } else {
  959. return GetEngineControl()->fBufferSize;
  960. }
  961. }
  962. EXPORT const char** jack_get_ports(jack_client_t* ext_client, const char* port_name_pattern, const char* type_name_pattern, unsigned long flags)
  963. {
  964. #ifdef __CLIENTDEBUG__
  965. JackLibGlobals::CheckContext();
  966. #endif
  967. JackClient* client = (JackClient*)ext_client;
  968. if (client == NULL) {
  969. jack_error("jack_get_ports called with a NULL client");
  970. return NULL;
  971. }
  972. return GetGraphManager()->GetPorts(port_name_pattern, type_name_pattern, flags);
  973. }
  974. EXPORT jack_port_t* jack_port_by_name(jack_client_t* ext_client, const char* portname)
  975. {
  976. #ifdef __CLIENTDEBUG__
  977. JackLibGlobals::CheckContext();
  978. #endif
  979. JackClient* client = (JackClient*)ext_client;
  980. if (client == NULL) {
  981. jack_error("jack_get_ports called with a NULL client");
  982. return 0;
  983. }
  984. if (portname == NULL) {
  985. jack_error("jack_port_by_name called with a NULL port name");
  986. return NULL;
  987. } else {
  988. int res = GetGraphManager()->GetPort(portname); // returns a port index at least > 1
  989. return (res == NO_PORT) ? NULL : (jack_port_t*)res;
  990. }
  991. }
  992. EXPORT jack_port_t* jack_port_by_id(jack_client_t* ext_client, jack_port_id_t id)
  993. {
  994. #ifdef __CLIENTDEBUG__
  995. JackLibGlobals::CheckContext();
  996. #endif
  997. /* jack_port_t* type is actually the port index */
  998. return (jack_port_t*)id;
  999. }
  1000. EXPORT int jack_engine_takeover_timebase(jack_client_t* ext_client)
  1001. {
  1002. #ifdef __CLIENTDEBUG__
  1003. JackLibGlobals::CheckContext();
  1004. #endif
  1005. JackClient* client = (JackClient*)ext_client;
  1006. if (client == NULL) {
  1007. jack_error("jack_engine_takeover_timebase called with a NULL client");
  1008. return -1;
  1009. } else {
  1010. jack_error("jack_engine_takeover_timebase: deprecated\n");
  1011. return 0;
  1012. }
  1013. }
  1014. EXPORT jack_nframes_t jack_frames_since_cycle_start(const jack_client_t* ext_client)
  1015. {
  1016. #ifdef __CLIENTDEBUG__
  1017. JackLibGlobals::CheckContext();
  1018. #endif
  1019. JackTimer timer;
  1020. GetEngineControl()->ReadFrameTime(&timer);
  1021. return (jack_nframes_t) floor((((float)GetEngineControl()->fSampleRate) / 1000000.0f) * (GetMicroSeconds() - timer.fCurrentCallback));
  1022. }
  1023. EXPORT jack_time_t jack_get_time(jack_client_t *client)
  1024. {
  1025. return GetMicroSeconds();
  1026. }
  1027. EXPORT jack_time_t jack_frames_to_time(const jack_client_t* ext_client, jack_nframes_t frames)
  1028. {
  1029. #ifdef __CLIENTDEBUG__
  1030. JackLibGlobals::CheckContext();
  1031. #endif
  1032. JackClient* client = (JackClient*)ext_client;
  1033. if (client == NULL) {
  1034. jack_error("jack_frames_to_time called with a NULL client");
  1035. return 0;
  1036. } else {
  1037. JackTimer timer;
  1038. GetEngineControl()->ReadFrameTime(&timer);
  1039. if (timer.fInitialized) {
  1040. return timer.fCurrentWakeup +
  1041. (long) rint(((double) ((frames - timer.fFrames)) *
  1042. ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) / GetEngineControl()->fBufferSize);
  1043. } else {
  1044. return 0;
  1045. }
  1046. }
  1047. }
  1048. EXPORT jack_nframes_t jack_time_to_frames(const jack_client_t* ext_client, jack_time_t time)
  1049. {
  1050. #ifdef __CLIENTDEBUG__
  1051. JackLibGlobals::CheckContext();
  1052. #endif
  1053. JackClient* client = (JackClient*)ext_client;
  1054. if (client == NULL) {
  1055. jack_error("jack_time_to_frames called with a NULL client");
  1056. return 0;
  1057. } else {
  1058. JackTimer timer;
  1059. GetEngineControl()->ReadFrameTime(&timer);
  1060. if (timer.fInitialized) {
  1061. return timer.fFrames +
  1062. (long) rint(((double) ((time - timer.fCurrentWakeup)) /
  1063. ((jack_time_t)(timer.fNextWakeUp - timer.fCurrentWakeup))) * GetEngineControl()->fBufferSize);
  1064. } else {
  1065. return 0;
  1066. }
  1067. }
  1068. }
  1069. EXPORT jack_nframes_t jack_frame_time(const jack_client_t* ext_client)
  1070. {
  1071. return jack_time_to_frames(ext_client, GetMicroSeconds());
  1072. }
  1073. EXPORT jack_nframes_t jack_last_frame_time(const jack_client_t* ext_client)
  1074. {
  1075. #ifdef __CLIENTDEBUG__
  1076. JackLibGlobals::CheckContext();
  1077. #endif
  1078. JackTimer timer;
  1079. GetEngineControl()->ReadFrameTime(&timer);
  1080. return timer.fFrames;
  1081. }
  1082. EXPORT float jack_cpu_load(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_cpu_load called with a NULL client");
  1090. return 0.0f;
  1091. } else {
  1092. return GetEngineControl()->fCPULoad;
  1093. }
  1094. }
  1095. EXPORT pthread_t jack_client_thread_id(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_client_thread_id called with a NULL client");
  1103. return (pthread_t)NULL;
  1104. } else {
  1105. return client->GetThreadID();
  1106. }
  1107. }
  1108. EXPORT char* jack_get_client_name (jack_client_t* ext_client)
  1109. {
  1110. #ifdef __CLIENTDEBUG__
  1111. JackLibGlobals::CheckContext();
  1112. #endif
  1113. JackClient* client = (JackClient*)ext_client;
  1114. if (client == NULL) {
  1115. jack_error("jack_get_client_name called with a NULL client");
  1116. return NULL;
  1117. } else {
  1118. return client->GetClientControl()->fName;
  1119. }
  1120. }
  1121. EXPORT int jack_client_name_size(void)
  1122. {
  1123. return JACK_CLIENT_NAME_SIZE;
  1124. }
  1125. EXPORT int jack_port_name_size(void)
  1126. {
  1127. return JACK_PORT_NAME_SIZE;
  1128. }
  1129. EXPORT int jack_port_type_size(void)
  1130. {
  1131. return JACK_PORT_TYPE_SIZE;
  1132. }
  1133. // transport.h
  1134. EXPORT int jack_release_timebase(jack_client_t* ext_client)
  1135. {
  1136. #ifdef __CLIENTDEBUG__
  1137. JackLibGlobals::CheckContext();
  1138. #endif
  1139. JackClient* client = (JackClient*)ext_client;
  1140. if (client == NULL) {
  1141. jack_error("jack_release_timebase called with a NULL client");
  1142. return -1;
  1143. } else {
  1144. return client->ReleaseTimebase();
  1145. }
  1146. }
  1147. EXPORT int jack_set_sync_callback(jack_client_t* ext_client, JackSyncCallback sync_callback, void *arg)
  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_callback called with a NULL client");
  1155. return -1;
  1156. } else {
  1157. return client->SetSyncCallback(sync_callback, arg);
  1158. }
  1159. }
  1160. EXPORT int jack_set_sync_timeout(jack_client_t* ext_client, jack_time_t timeout)
  1161. {
  1162. #ifdef __CLIENTDEBUG__
  1163. JackLibGlobals::CheckContext();
  1164. #endif
  1165. JackClient* client = (JackClient*)ext_client;
  1166. if (client == NULL) {
  1167. jack_error("jack_set_sync_timeout called with a NULL client");
  1168. return -1;
  1169. } else {
  1170. return client->SetSyncTimeout(timeout);
  1171. }
  1172. }
  1173. EXPORT int jack_set_timebase_callback(jack_client_t* ext_client, int conditional, JackTimebaseCallback timebase_callback, void* arg)
  1174. {
  1175. #ifdef __CLIENTDEBUG__
  1176. JackLibGlobals::CheckContext();
  1177. #endif
  1178. JackClient* client = (JackClient*)ext_client;
  1179. if (client == NULL) {
  1180. jack_error("jack_set_timebase_callback called with a NULL client");
  1181. return -1;
  1182. } else {
  1183. return client->SetTimebaseCallback(conditional, timebase_callback, arg);
  1184. }
  1185. }
  1186. EXPORT int jack_transport_locate(jack_client_t* ext_client, jack_nframes_t frame)
  1187. {
  1188. #ifdef __CLIENTDEBUG__
  1189. JackLibGlobals::CheckContext();
  1190. #endif
  1191. JackClient* client = (JackClient*)ext_client;
  1192. if (client == NULL) {
  1193. jack_error("jack_transport_locate called with a NULL client");
  1194. return -1;
  1195. } else {
  1196. return client->TransportLocate(frame);
  1197. }
  1198. }
  1199. EXPORT jack_transport_state_t jack_transport_query(const jack_client_t* ext_client, jack_position_t* pos)
  1200. {
  1201. #ifdef __CLIENTDEBUG__
  1202. JackLibGlobals::CheckContext();
  1203. #endif
  1204. JackClient* client = (JackClient*)ext_client;
  1205. if (client == NULL) {
  1206. jack_error("jack_transport_query called with a NULL client");
  1207. return JackTransportStopped;
  1208. } else {
  1209. return client->TransportQuery(pos);
  1210. }
  1211. }
  1212. EXPORT jack_nframes_t jack_get_current_transport_frame(const jack_client_t* ext_client)
  1213. {
  1214. #ifdef __CLIENTDEBUG__
  1215. JackLibGlobals::CheckContext();
  1216. #endif
  1217. JackClient* client = (JackClient*)ext_client;
  1218. if (client == NULL) {
  1219. jack_error("jack_get_current_transport_frame called with a NULL client");
  1220. return 0;
  1221. } else {
  1222. return client->GetCurrentTransportFrame();
  1223. }
  1224. }
  1225. EXPORT int jack_transport_reposition(jack_client_t* ext_client, jack_position_t* pos)
  1226. {
  1227. #ifdef __CLIENTDEBUG__
  1228. JackLibGlobals::CheckContext();
  1229. #endif
  1230. JackClient* client = (JackClient*)ext_client;
  1231. if (client == NULL) {
  1232. jack_error("jack_transport_reposition called with a NULL client");
  1233. return -1;
  1234. } else {
  1235. return client->TransportReposition(pos);
  1236. }
  1237. }
  1238. EXPORT void jack_transport_start(jack_client_t* ext_client)
  1239. {
  1240. #ifdef __CLIENTDEBUG__
  1241. JackLibGlobals::CheckContext();
  1242. #endif
  1243. JackClient* client = (JackClient*)ext_client;
  1244. if (client == NULL) {
  1245. jack_error("jack_transport_start called with a NULL client");
  1246. } else {
  1247. client->TransportStart();
  1248. }
  1249. }
  1250. EXPORT void jack_transport_stop(jack_client_t* ext_client)
  1251. {
  1252. #ifdef __CLIENTDEBUG__
  1253. JackLibGlobals::CheckContext();
  1254. #endif
  1255. JackClient* client = (JackClient*)ext_client;
  1256. if (client == NULL) {
  1257. jack_error("jack_transport_stop called with a NULL client");
  1258. } else {
  1259. client->TransportStop();
  1260. }
  1261. }
  1262. // deprecated
  1263. EXPORT void jack_get_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1264. {
  1265. jack_error("jack_get_transport_info: deprecated");
  1266. if (tinfo)
  1267. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1268. }
  1269. EXPORT void jack_set_transport_info(jack_client_t* ext_client, jack_transport_info_t* tinfo)
  1270. {
  1271. jack_error("jack_set_transport_info: deprecated");
  1272. if (tinfo)
  1273. memset(tinfo, 0, sizeof(jack_transport_info_t));
  1274. }
  1275. // statistics.h
  1276. EXPORT float jack_get_max_delayed_usecs(jack_client_t* ext_client)
  1277. {
  1278. #ifdef __CLIENTDEBUG__
  1279. JackLibGlobals::CheckContext();
  1280. #endif
  1281. JackLog("jack_get_max_delayed_usecs: not yet implemented\n");
  1282. return 0.f;
  1283. }
  1284. EXPORT float jack_get_xrun_delayed_usecs(jack_client_t* ext_client)
  1285. {
  1286. #ifdef __CLIENTDEBUG__
  1287. JackLibGlobals::CheckContext();
  1288. #endif
  1289. JackLog("jack_get_xrun_delayed_usecs: not yet implemented\n");
  1290. return 0.f;
  1291. }
  1292. EXPORT void jack_reset_max_delayed_usecs(jack_client_t* ext_client)
  1293. {
  1294. #ifdef __CLIENTDEBUG__
  1295. JackLibGlobals::CheckContext();
  1296. #endif
  1297. JackLog("jack_reset_max_delayed_usecs: not yet implemented\n");
  1298. }
  1299. // thread.h
  1300. EXPORT int jack_acquire_real_time_scheduling(pthread_t thread, int priority)
  1301. {
  1302. #ifdef __APPLE__
  1303. return JackMachThread::AcquireRealTimeImp(thread, GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
  1304. #elif WIN32
  1305. return JackWinThread::AcquireRealTimeImp(thread, priority);
  1306. #else
  1307. return JackPosixThread::AcquireRealTimeImp(thread, priority);
  1308. #endif
  1309. }
  1310. EXPORT int jack_client_create_thread(jack_client_t* client,
  1311. pthread_t *thread,
  1312. int priority,
  1313. int realtime, /* boolean */
  1314. void *(*start_routine)(void*),
  1315. void *arg)
  1316. {
  1317. #ifdef __APPLE__
  1318. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1319. #elif WIN32
  1320. return JackWinThread::StartImp(thread, priority, realtime, (ThreadCallback)start_routine, arg);
  1321. #else
  1322. return JackPosixThread::StartImp(thread, priority, realtime, start_routine, arg);
  1323. #endif
  1324. }
  1325. EXPORT int jack_drop_real_time_scheduling(pthread_t thread)
  1326. {
  1327. #ifdef __APPLE__
  1328. return JackMachThread::DropRealTimeImp(thread);
  1329. #elif WIN32
  1330. return JackWinThread::DropRealTimeImp(thread);
  1331. #else
  1332. return JackPosixThread::DropRealTimeImp(thread);
  1333. #endif
  1334. }
  1335. // intclient.h
  1336. EXPORT int jack_internal_client_new (const char *client_name,
  1337. const char *load_name,
  1338. const char *load_init)
  1339. {
  1340. jack_error("jack_internal_client_new: deprecated");
  1341. return -1;
  1342. }
  1343. EXPORT void jack_internal_client_close (const char *client_name)
  1344. {
  1345. jack_error("jack_internal_client_close: deprecated");
  1346. }
  1347. EXPORT char* jack_get_internal_client_name(jack_client_t* ext_client, jack_intclient_t intclient)
  1348. {
  1349. #ifdef __CLIENTDEBUG__
  1350. JackLibGlobals::CheckContext();
  1351. #endif
  1352. JackClient* client = (JackClient*)ext_client;
  1353. if (client == NULL) {
  1354. jack_error("jack_get_internal_client_name called with a NULL client");
  1355. return NULL;
  1356. } else if (intclient < 0 || intclient >= CLIENT_NUM) {
  1357. jack_error("jack_get_internal_client_name: incorrect client");
  1358. return NULL;
  1359. } else {
  1360. return client->GetInternalClientName(intclient);
  1361. }
  1362. }
  1363. EXPORT jack_intclient_t jack_internal_client_handle(jack_client_t* ext_client, const char* client_name, jack_status_t* status)
  1364. {
  1365. #ifdef __CLIENTDEBUG__
  1366. JackLibGlobals::CheckContext();
  1367. #endif
  1368. JackClient* client = (JackClient*)ext_client;
  1369. if (client == NULL) {
  1370. jack_error("jack_internal_client_handle called with a NULL client");
  1371. return 0;
  1372. } else {
  1373. jack_status_t my_status;
  1374. if (status == NULL) /* no status from caller? */
  1375. status = &my_status; /* use local status word */
  1376. *status = (jack_status_t)0;
  1377. return client->InternalClientHandle(client_name, status);
  1378. }
  1379. }
  1380. 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, ...)
  1381. {
  1382. #ifdef __CLIENTDEBUG__
  1383. JackLibGlobals::CheckContext();
  1384. #endif
  1385. JackClient* client = (JackClient*)ext_client;
  1386. if (client == NULL) {
  1387. jack_error("jack_internal_client_load called with a NULL client");
  1388. return 0;
  1389. } else {
  1390. va_list ap;
  1391. jack_varargs_t va;
  1392. jack_status_t my_status;
  1393. if (status == NULL) /* no status from caller? */
  1394. status = &my_status; /* use local status word */
  1395. *status = (jack_status_t)0;
  1396. /* validate parameters */
  1397. if ((options & ~JackLoadOptions)) {
  1398. int my_status1 = *status | (JackFailure | JackInvalidOption);
  1399. *status = (jack_status_t)my_status1;
  1400. return 0;
  1401. }
  1402. /* parse variable arguments */
  1403. va_start(ap, status);
  1404. jack_varargs_parse(options, ap, &va);
  1405. va_end(ap);
  1406. return client->InternalClientLoad(client_name, options, status, &va);
  1407. }
  1408. }
  1409. EXPORT jack_status_t jack_internal_client_unload(jack_client_t* ext_client, jack_intclient_t intclient)
  1410. {
  1411. #ifdef __CLIENTDEBUG__
  1412. JackLibGlobals::CheckContext();
  1413. #endif
  1414. JackClient* client = (JackClient*)ext_client;
  1415. if (client == NULL) {
  1416. jack_error("jack_internal_client_unload called with a NULL client");
  1417. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1418. } else if (intclient < 0 || intclient >= CLIENT_NUM) {
  1419. jack_error("jack_internal_client_unload: incorrect client");
  1420. return (jack_status_t)(JackNoSuchClient | JackFailure);
  1421. } else {
  1422. jack_status_t my_status;
  1423. client->InternalClientUnload(intclient, &my_status);
  1424. return my_status;
  1425. }
  1426. }