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.

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