Audio plugin host https://kx.studio/carla
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.

258 lines
7.9KB

  1. /*
  2. * Carla JACK API for external applications
  3. * Copyright (C) 2016-2017 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #include "libjack.hpp"
  18. CARLA_BACKEND_USE_NAMESPACE
  19. // --------------------------------------------------------------------------------------------------------------------
  20. CARLA_EXPORT
  21. jack_port_t* jack_port_register(jack_client_t* client, const char* port_name, const char* port_type,
  22. unsigned long flags, unsigned long /*buffer_size*/)
  23. {
  24. carla_stdout("CarlaJackClient :: %s | %s %s %lu", __FUNCTION__, port_name, port_type, flags);
  25. JackClientState* const jclient = (JackClientState*)client;
  26. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, nullptr);
  27. CARLA_SAFE_ASSERT_RETURN(port_name != nullptr && port_name[0] != '\0', nullptr);
  28. CARLA_SAFE_ASSERT_RETURN(port_type != nullptr && port_type[0] != '\0', nullptr);
  29. if (std::strcmp(port_type, JACK_DEFAULT_AUDIO_TYPE) == 0)
  30. {
  31. if (flags & JackPortIsInput)
  32. {
  33. JackPortState* const port = new JackPortState(jclient->name, port_name, jclient->audioIns.count(), flags, false);
  34. const CarlaMutexLocker cms(jclient->mutex);
  35. jclient->audioIns.append(port);
  36. return (jack_port_t*)port;
  37. }
  38. if (flags & JackPortIsOutput)
  39. {
  40. JackPortState* const port = new JackPortState(jclient->name, port_name, jclient->audioOuts.count(), flags, false);
  41. const CarlaMutexLocker cms(jclient->mutex);
  42. jclient->audioOuts.append(port);
  43. return (jack_port_t*)port;
  44. }
  45. carla_stderr2("Invalid port flags '%x'", flags);
  46. return nullptr;
  47. }
  48. carla_stderr2("Invalid port type '%s'", port_type);
  49. return nullptr;
  50. }
  51. CARLA_EXPORT
  52. int jack_port_unregister(jack_client_t* client, jack_port_t* port)
  53. {
  54. JackClientState* const jclient = (JackClientState*)client;
  55. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  56. JackPortState* const jport = (JackPortState*)port;
  57. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 1);
  58. CARLA_SAFE_ASSERT_RETURN(! jport->isSystem, 1);
  59. const CarlaMutexLocker cms(jclient->mutex);
  60. if (jport->flags & JackPortIsInput)
  61. {
  62. CARLA_SAFE_ASSERT_RETURN(jclient->audioIns.removeOne(jport), 1);
  63. return 0;
  64. }
  65. if (jport->flags & JackPortIsOutput)
  66. {
  67. CARLA_SAFE_ASSERT_RETURN(jclient->audioOuts.removeOne(jport), 1);
  68. return 0;
  69. }
  70. carla_stderr2("Invalid port type on unregister");
  71. return 1;
  72. }
  73. CARLA_EXPORT
  74. void* jack_port_get_buffer(jack_port_t* port, jack_nframes_t)
  75. {
  76. JackPortState* const jport = (JackPortState*)port;
  77. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  78. return jport->buffer;
  79. }
  80. // --------------------------------------------------------------------------------------------------------------------
  81. CARLA_EXPORT
  82. jack_uuid_t jack_port_uuid(const jack_port_t*)
  83. {
  84. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  85. return 0;
  86. }
  87. CARLA_EXPORT
  88. const char* jack_port_name(const jack_port_t* port)
  89. {
  90. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  91. JackPortState* const jport = (JackPortState*)port;
  92. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  93. return jport->fullname;
  94. }
  95. CARLA_EXPORT
  96. const char* jack_port_short_name(const jack_port_t* port)
  97. {
  98. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  99. JackPortState* const jport = (JackPortState*)port;
  100. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  101. return jport->name;
  102. }
  103. CARLA_EXPORT
  104. int jack_port_flags(const jack_port_t* port)
  105. {
  106. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  107. JackPortState* const jport = (JackPortState*)port;
  108. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, 0);
  109. return jport->flags;
  110. }
  111. CARLA_EXPORT
  112. const char* jack_port_type(const jack_port_t* port)
  113. {
  114. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  115. JackPortState* const jport = (JackPortState*)port;
  116. CARLA_SAFE_ASSERT_RETURN(jport != nullptr, nullptr);
  117. // TODO
  118. return JACK_DEFAULT_AUDIO_TYPE;
  119. }
  120. //jack_port_type_id_t jack_port_type_id (const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  121. // --------------------------------------------------------------------------------------------------------------------
  122. //int jack_port_is_mine (const jack_client_t *client, const jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  123. CARLA_EXPORT
  124. int jack_port_connected(const jack_port_t*)
  125. {
  126. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  127. return 1;
  128. }
  129. //int jack_port_connected_to (const jack_port_t *port,
  130. // const char *port_name) JACK_OPTIONAL_WEAK_EXPORT;
  131. // --------------------------------------------------------------------------------------------------------------------
  132. CARLA_EXPORT
  133. const char** jack_port_get_connections (const jack_port_t*)
  134. {
  135. return nullptr;
  136. }
  137. CARLA_EXPORT
  138. const char** jack_port_get_all_connections(const jack_client_t*, const jack_port_t*)
  139. {
  140. return nullptr;
  141. }
  142. // --------------------------------------------------------------------------------------------------------------------
  143. //int jack_port_tie (jack_port_t *src, jack_port_t *dst) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  144. //int jack_port_untie (jack_port_t *port) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  145. // --------------------------------------------------------------------------------------------------------------------
  146. //int jack_port_set_name (jack_port_t *port, const char *port_name) JACK_OPTIONAL_WEAK_DEPRECATED_EXPORT;
  147. //int jack_port_rename (jack_client_t* client, jack_port_t *port, const char *port_name) JACK_OPTIONAL_WEAK_EXPORT;
  148. //int jack_port_set_alias (jack_port_t *port, const char *alias) JACK_OPTIONAL_WEAK_EXPORT;
  149. //int jack_port_unset_alias (jack_port_t *port, const char *alias) JACK_OPTIONAL_WEAK_EXPORT;
  150. //int jack_port_get_aliases (const jack_port_t *port, char* const aliases[2]) JACK_OPTIONAL_WEAK_EXPORT;
  151. // --------------------------------------------------------------------------------------------------------------------
  152. //int jack_port_request_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  153. //int jack_port_request_monitor_by_name (jack_client_t *client,
  154. // const char *port_name, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  155. //int jack_port_ensure_monitor (jack_port_t *port, int onoff) JACK_OPTIONAL_WEAK_EXPORT;
  156. //int jack_port_monitoring_input (jack_port_t *port) JACK_OPTIONAL_WEAK_EXPORT;
  157. // --------------------------------------------------------------------------------------------------------------------
  158. CARLA_EXPORT
  159. int jack_connect(jack_client_t*, const char*, const char*)
  160. {
  161. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  162. return 0;
  163. }
  164. CARLA_EXPORT
  165. int jack_disconnect(jack_client_t*, const char*, const char*)
  166. {
  167. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  168. return 0;
  169. }
  170. CARLA_EXPORT
  171. int jack_port_disconnect(jack_client_t*, jack_port_t*)
  172. {
  173. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  174. return 0;
  175. }
  176. // --------------------------------------------------------------------------------------------------------------------
  177. CARLA_EXPORT
  178. int jack_port_name_size(void)
  179. {
  180. return STR_MAX;
  181. }
  182. // int jack_port_type_size(void) JACK_OPTIONAL_WEAK_EXPORT;
  183. //size_t jack_port_type_get_buffer_size (jack_client_t *client, const char *port_type) JACK_WEAK_EXPORT;
  184. // --------------------------------------------------------------------------------------------------------------------