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.

176 lines
4.5KB

  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. static CarlaJackClient gClient;
  20. static int gClientRefCount = 0;
  21. // --------------------------------------------------------------------------------------------------------------------
  22. CARLA_EXPORT
  23. jack_client_t* jack_client_open(const char* client_name, jack_options_t /*options*/, jack_status_t* status, ...)
  24. {
  25. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  26. if (! gClient.initIfNeeded(client_name))
  27. {
  28. if (status != nullptr)
  29. *status = JackServerError;
  30. return nullptr;
  31. }
  32. ++gClientRefCount;
  33. return (jack_client_t*)&gClient;
  34. }
  35. CARLA_EXPORT
  36. jack_client_t* jack_client_new(const char* client_name)
  37. {
  38. return jack_client_open(client_name, JackNullOption, nullptr);
  39. }
  40. CARLA_EXPORT
  41. int jack_client_close(jack_client_t* client)
  42. {
  43. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  44. CarlaJackClient* const jclient = (CarlaJackClient*)client;
  45. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  46. JackClientState& jstate(jclient->fState);
  47. if (jstate.activated)
  48. jclient->deactivate();
  49. --gClientRefCount;
  50. return 0;
  51. }
  52. // --------------------------------------------------------------------------------------------------------------------
  53. CARLA_EXPORT
  54. int jack_client_name_size(void)
  55. {
  56. return STR_MAX;
  57. }
  58. CARLA_EXPORT
  59. char* jack_get_client_name(jack_client_t* client)
  60. {
  61. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  62. CarlaJackClient* const jclient = (CarlaJackClient*)client;
  63. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, nullptr);
  64. const JackClientState& jstate(jclient->fState);
  65. return jstate.name;
  66. }
  67. CARLA_EXPORT
  68. char* jack_get_uuid_for_client_name(jack_client_t*, const char*)
  69. {
  70. return nullptr;
  71. }
  72. CARLA_EXPORT
  73. char* jack_get_client_name_by_uuid (jack_client_t*, const char*)
  74. {
  75. return nullptr;
  76. }
  77. // --------------------------------------------------------------------------------------------------------------------
  78. CARLA_EXPORT
  79. int jack_internal_client_new(const char*, const char*, const char*)
  80. {
  81. return 1;
  82. }
  83. CARLA_EXPORT
  84. void jack_internal_client_close(const char*)
  85. {
  86. }
  87. // --------------------------------------------------------------------------------------------------------------------
  88. CARLA_EXPORT
  89. int jack_activate(jack_client_t* client)
  90. {
  91. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  92. CarlaJackClient* const jclient = (CarlaJackClient*)client;
  93. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  94. const JackClientState& jstate(jclient->fState);
  95. CARLA_SAFE_ASSERT_RETURN(! jstate.activated, 1);
  96. #if 0
  97. // needed for pulseaudio
  98. static bool skipFirstActivate = true;
  99. if (skipFirstActivate) {
  100. skipFirstActivate = false;
  101. return 0;
  102. }
  103. #endif
  104. jclient->activate();
  105. return 0;
  106. }
  107. CARLA_EXPORT
  108. int jack_deactivate(jack_client_t* /*client*/)
  109. {
  110. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  111. //CarlaJackClient* const jclient = (CarlaJackClient*)client;
  112. //CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 1);
  113. //JackClientState& jstate(jclient->fState);
  114. //CARLA_SAFE_ASSERT_RETURN(jstate.activated, 1);
  115. //jclient->deactivate();
  116. return 0;
  117. }
  118. // --------------------------------------------------------------------------------------------------------------------
  119. CARLA_EXPORT
  120. int jack_get_client_pid(const char*)
  121. {
  122. return 0;
  123. }
  124. CARLA_EXPORT
  125. pthread_t jack_client_thread_id(jack_client_t* client)
  126. {
  127. carla_stdout("CarlaJackClient :: %s", __FUNCTION__);
  128. CarlaJackClient* const jclient = (CarlaJackClient*)client;
  129. CARLA_SAFE_ASSERT_RETURN(jclient != nullptr, 0);
  130. const JackClientState& jstate(jclient->fState);
  131. CARLA_SAFE_ASSERT_RETURN(jstate.activated, 0);
  132. return (pthread_t)jclient->getThreadId();
  133. }
  134. // --------------------------------------------------------------------------------------------------------------------