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.

205 lines
5.0KB

  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 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. JackFreewheelCallback freewheelCb;
  100. void* freewheelCbPtr;
  101. JackBufferSizeCallback bufferSizeCb;
  102. void* bufferSizeCbPtr;
  103. JackSampleRateCallback sampleRateCb;
  104. void* sampleRateCbPtr;
  105. JackSyncCallback syncCb;
  106. void* syncCbPtr;
  107. JackClientState(const JackServerState& s, const char* const n)
  108. : server(s),
  109. activated(false),
  110. deactivated(false),
  111. name(strdup(n)),
  112. audioIns(),
  113. audioOuts(),
  114. midiIns(),
  115. midiOuts(),
  116. shutdownCb(nullptr),
  117. shutdownCbPtr(nullptr),
  118. infoShutdownCb(nullptr),
  119. infoShutdownCbPtr(nullptr),
  120. processCb(nullptr),
  121. processCbPtr(nullptr),
  122. freewheelCb(nullptr),
  123. freewheelCbPtr(nullptr),
  124. bufferSizeCb(nullptr),
  125. bufferSizeCbPtr(nullptr),
  126. sampleRateCb(nullptr),
  127. sampleRateCbPtr(nullptr),
  128. syncCb(nullptr),
  129. syncCbPtr(nullptr) {}
  130. ~JackClientState()
  131. {
  132. const CarlaMutexLocker cms(mutex);
  133. for (LinkedList<JackPortState*>::Itenerator it = audioIns.begin2(); it.valid(); it.next())
  134. {
  135. if (JackPortState* const jport = it.getValue(nullptr))
  136. delete jport;
  137. }
  138. for (LinkedList<JackPortState*>::Itenerator it = audioOuts.begin2(); it.valid(); it.next())
  139. {
  140. if (JackPortState* const jport = it.getValue(nullptr))
  141. delete jport;
  142. }
  143. free(name);
  144. name = nullptr;
  145. audioIns.clear();
  146. audioOuts.clear();
  147. }
  148. };
  149. struct JackServerState {
  150. CarlaJackAppClient* jackAppPtr;
  151. uint32_t bufferSize;
  152. double sampleRate;
  153. bool playing;
  154. jack_position_t position;
  155. JackServerState()
  156. : jackAppPtr(nullptr),
  157. bufferSize(0),
  158. sampleRate(0.0),
  159. playing(false)
  160. {
  161. carla_zeroStruct(position);
  162. }
  163. };
  164. CARLA_BACKEND_END_NAMESPACE
  165. // --------------------------------------------------------------------------------------------------------------------