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.

1758 lines
56KB

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