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.

2090 lines
70KB

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