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.

200 lines
4.8KB

  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_core/juce_core.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 isSystem;
  57. JackPortState()
  58. : name(nullptr),
  59. fullname(nullptr),
  60. buffer(nullptr),
  61. index(0),
  62. flags(0),
  63. isSystem(false) {}
  64. JackPortState(const char* const cn, const char* const pn, const uint i, const uint f, const bool sys)
  65. : name(strdup(pn)),
  66. fullname(nullptr),
  67. buffer(nullptr),
  68. index(i),
  69. flags(f),
  70. isSystem(sys)
  71. {
  72. char strBuf[STR_MAX+1];
  73. snprintf(strBuf, STR_MAX, "%s:%s", cn, pn);
  74. strBuf[STR_MAX] = '\0';
  75. fullname = strdup(strBuf);
  76. }
  77. ~JackPortState()
  78. {
  79. free(name);
  80. free(fullname);
  81. }
  82. };
  83. struct JackClientState {
  84. const JackServerState& server;
  85. CarlaMutex mutex;
  86. bool activated;
  87. bool deactivated; // activated once, then deactivated
  88. char* name;
  89. LinkedList<JackPortState*> audioIns;
  90. LinkedList<JackPortState*> audioOuts;
  91. LinkedList<JackPortState> midiIns;
  92. LinkedList<JackPortState> midiOuts;
  93. JackShutdownCallback shutdownCb;
  94. void* shutdownCbPtr;
  95. JackInfoShutdownCallback infoShutdownCb;
  96. void* infoShutdownCbPtr;
  97. JackProcessCallback processCb;
  98. void* processCbPtr;
  99. JackBufferSizeCallback bufferSizeCb;
  100. void* bufferSizeCbPtr;
  101. JackSampleRateCallback sampleRateCb;
  102. void* sampleRateCbPtr;
  103. JackSyncCallback syncCb;
  104. void* syncCbPtr;
  105. JackClientState(const JackServerState& s, const char* const n)
  106. : server(s),
  107. activated(false),
  108. deactivated(false),
  109. name(strdup(n)),
  110. audioIns(),
  111. audioOuts(),
  112. midiIns(),
  113. midiOuts(),
  114. shutdownCb(nullptr),
  115. shutdownCbPtr(nullptr),
  116. infoShutdownCb(nullptr),
  117. infoShutdownCbPtr(nullptr),
  118. processCb(nullptr),
  119. processCbPtr(nullptr),
  120. bufferSizeCb(nullptr),
  121. bufferSizeCbPtr(nullptr),
  122. sampleRateCb(nullptr),
  123. sampleRateCbPtr(nullptr),
  124. syncCb(nullptr),
  125. syncCbPtr(nullptr) {}
  126. ~JackClientState()
  127. {
  128. const CarlaMutexLocker cms(mutex);
  129. for (LinkedList<JackPortState*>::Itenerator it = audioIns.begin2(); it.valid(); it.next())
  130. {
  131. if (JackPortState* const jport = it.getValue(nullptr))
  132. delete jport;
  133. }
  134. for (LinkedList<JackPortState*>::Itenerator it = audioOuts.begin2(); it.valid(); it.next())
  135. {
  136. if (JackPortState* const jport = it.getValue(nullptr))
  137. delete jport;
  138. }
  139. free(name);
  140. name = nullptr;
  141. audioIns.clear();
  142. audioOuts.clear();
  143. }
  144. };
  145. struct JackServerState {
  146. CarlaJackAppClient* jackAppPtr;
  147. uint32_t bufferSize;
  148. double sampleRate;
  149. bool playing;
  150. jack_position_t position;
  151. JackServerState()
  152. : jackAppPtr(nullptr),
  153. bufferSize(0),
  154. sampleRate(0.0),
  155. playing(false)
  156. {
  157. carla_zeroStruct(position);
  158. }
  159. };
  160. CARLA_BACKEND_END_NAMESPACE
  161. // --------------------------------------------------------------------------------------------------------------------