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.

220 lines
5.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. // need to include this first
  18. #include "CarlaDefines.h"
  19. // now define as bridge
  20. #define BUILD_BRIDGE 1
  21. // now include a bunch of stuff
  22. #include "CarlaBackendUtils.hpp"
  23. #include "CarlaBridgeUtils.hpp"
  24. #include "CarlaMIDI.h"
  25. #include "CarlaMutex.hpp"
  26. #include "LinkedList.hpp"
  27. #include "AppConfig.h"
  28. #include "juce_audio_basics/juce_audio_basics.h"
  29. #if 0
  30. #include <jack/jack.h>
  31. #include <jack/midiport.h>
  32. #include <jack/transport.h>
  33. #include <jack/session.h>
  34. #include <jack/metadata.h>
  35. #endif
  36. #ifdef __SSE2_MATH__
  37. # include <xmmintrin.h>
  38. #endif
  39. // must be last include
  40. #include "jackbridge/JackBridge.hpp"
  41. // small check to not hurt myself
  42. #ifdef JACKBRIDGE_DIRECT
  43. # error "Cannot create custom jack server while linking to libjack directly"
  44. #endif
  45. CARLA_BACKEND_START_NAMESPACE
  46. // --------------------------------------------------------------------------------------------------------------------
  47. class CarlaJackAppClient;
  48. struct JackClientState;
  49. struct JackServerState;
  50. struct JackPortState {
  51. char* name;
  52. char* fullname;
  53. void* buffer;
  54. uint index;
  55. uint flags;
  56. bool isMidi;
  57. bool isSystem;
  58. JackPortState()
  59. : name(nullptr),
  60. fullname(nullptr),
  61. buffer(nullptr),
  62. index(0),
  63. flags(0),
  64. isMidi(false),
  65. isSystem(false) {}
  66. JackPortState(const char* const cn, const char* const pn, const uint i, const uint f, const bool midi, const bool sys)
  67. : name(strdup(pn)),
  68. fullname(nullptr),
  69. buffer(nullptr),
  70. index(i),
  71. flags(f),
  72. isMidi(midi),
  73. isSystem(sys)
  74. {
  75. char strBuf[STR_MAX+1];
  76. snprintf(strBuf, STR_MAX, "%s:%s", cn, pn);
  77. strBuf[STR_MAX] = '\0';
  78. fullname = strdup(strBuf);
  79. }
  80. ~JackPortState()
  81. {
  82. free(name);
  83. free(fullname);
  84. }
  85. };
  86. struct JackClientState {
  87. const JackServerState& server;
  88. CarlaMutex mutex;
  89. bool activated;
  90. bool deactivated; // activated once, then deactivated
  91. char* name;
  92. LinkedList<JackPortState*> audioIns;
  93. LinkedList<JackPortState*> audioOuts;
  94. LinkedList<JackPortState*> midiIns;
  95. LinkedList<JackPortState*> midiOuts;
  96. JackShutdownCallback shutdownCb;
  97. void* shutdownCbPtr;
  98. JackInfoShutdownCallback infoShutdownCb;
  99. void* infoShutdownCbPtr;
  100. JackProcessCallback processCb;
  101. void* processCbPtr;
  102. JackFreewheelCallback freewheelCb;
  103. void* freewheelCbPtr;
  104. JackBufferSizeCallback bufferSizeCb;
  105. void* bufferSizeCbPtr;
  106. JackSampleRateCallback sampleRateCb;
  107. void* sampleRateCbPtr;
  108. JackSyncCallback syncCb;
  109. void* syncCbPtr;
  110. JackClientState(const JackServerState& s, const char* const n)
  111. : server(s),
  112. activated(false),
  113. deactivated(false),
  114. name(strdup(n)),
  115. audioIns(),
  116. audioOuts(),
  117. midiIns(),
  118. midiOuts(),
  119. shutdownCb(nullptr),
  120. shutdownCbPtr(nullptr),
  121. infoShutdownCb(nullptr),
  122. infoShutdownCbPtr(nullptr),
  123. processCb(nullptr),
  124. processCbPtr(nullptr),
  125. freewheelCb(nullptr),
  126. freewheelCbPtr(nullptr),
  127. bufferSizeCb(nullptr),
  128. bufferSizeCbPtr(nullptr),
  129. sampleRateCb(nullptr),
  130. sampleRateCbPtr(nullptr),
  131. syncCb(nullptr),
  132. syncCbPtr(nullptr) {}
  133. ~JackClientState()
  134. {
  135. const CarlaMutexLocker cms(mutex);
  136. for (LinkedList<JackPortState*>::Itenerator it = audioIns.begin2(); it.valid(); it.next())
  137. {
  138. if (JackPortState* const jport = it.getValue(nullptr))
  139. delete jport;
  140. }
  141. for (LinkedList<JackPortState*>::Itenerator it = audioOuts.begin2(); it.valid(); it.next())
  142. {
  143. if (JackPortState* const jport = it.getValue(nullptr))
  144. delete jport;
  145. }
  146. for (LinkedList<JackPortState*>::Itenerator it = midiIns.begin2(); it.valid(); it.next())
  147. {
  148. if (JackPortState* const jport = it.getValue(nullptr))
  149. delete jport;
  150. }
  151. for (LinkedList<JackPortState*>::Itenerator it = midiOuts.begin2(); it.valid(); it.next())
  152. {
  153. if (JackPortState* const jport = it.getValue(nullptr))
  154. delete jport;
  155. }
  156. free(name);
  157. name = nullptr;
  158. audioIns.clear();
  159. audioOuts.clear();
  160. }
  161. };
  162. struct JackServerState {
  163. CarlaJackAppClient* jackAppPtr;
  164. uint32_t bufferSize;
  165. double sampleRate;
  166. bool playing;
  167. jack_position_t position;
  168. JackServerState(CarlaJackAppClient* const app)
  169. : jackAppPtr(app),
  170. bufferSize(0),
  171. sampleRate(0.0),
  172. playing(false)
  173. {
  174. carla_zeroStruct(position);
  175. }
  176. };
  177. CARLA_BACKEND_END_NAMESPACE
  178. // --------------------------------------------------------------------------------------------------------------------