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.

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