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.

carla.cpp 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * Carla Native Plugins
  3. * Copyright (C) 2013 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 GPL.txt file
  16. */
  17. #include "CarlaNative.hpp"
  18. #include "CarlaEngine.hpp"
  19. #include "CarlaEngineInternal.hpp"
  20. CARLA_BACKEND_START_NAMESPACE
  21. // -----------------------------------------------------------------------
  22. class CarlaEngineNative : public CarlaEngine,
  23. public PluginDescriptorClass
  24. {
  25. public:
  26. CarlaEngineNative(const HostDescriptor* const host)
  27. : CarlaEngine(),
  28. PluginDescriptorClass(host)
  29. {
  30. carla_debug("CarlaEngineNative::CarlaEngineNative()");
  31. // set-up engine
  32. fOptions.processMode = PROCESS_MODE_CONTINUOUS_RACK;
  33. fOptions.transportMode = TRANSPORT_MODE_INTERNAL;
  34. fOptions.forceStereo = true;
  35. fOptions.preferPluginBridges = false;
  36. fOptions.preferUiBridges = false;
  37. init("Carla");
  38. }
  39. ~CarlaEngineNative()
  40. {
  41. carla_debug("CarlaEngineNative::~CarlaEngineNative()");
  42. setAboutToClose();
  43. removeAllPlugins();
  44. close();
  45. }
  46. // -------------------------------------
  47. // CarlaEngine virtual calls
  48. bool init(const char* const clientName)
  49. {
  50. carla_debug("CarlaEngineNative::init(\"%s\")", clientName);
  51. fBufferSize = CarlaEngine::getBufferSize();
  52. fSampleRate = CarlaEngine::getSampleRate();
  53. CarlaEngine::init(clientName);
  54. return true;
  55. }
  56. bool close()
  57. {
  58. carla_debug("CarlaEngineNative::close()");
  59. CarlaEngine::close();
  60. return true;
  61. }
  62. bool isRunning() const
  63. {
  64. return true;
  65. }
  66. bool isOffline() const
  67. {
  68. return false;
  69. }
  70. EngineType type() const
  71. {
  72. return kEngineTypePlugin;
  73. }
  74. protected:
  75. // -------------------------------------------------------------------
  76. // Plugin parameter calls
  77. uint32_t getParameterCount()
  78. {
  79. if (kData->curPluginCount == 0 || kData->plugins == nullptr)
  80. return 0;
  81. CarlaPlugin* const plugin(kData->plugins[0].plugin);
  82. if (plugin == nullptr || ! plugin->enabled())
  83. return 0;
  84. return kData->plugins[0].plugin->parameterCount();
  85. }
  86. const Parameter* getParameterInfo(const uint32_t index)
  87. {
  88. if (index >= getParameterCount())
  89. return nullptr;
  90. CarlaPlugin* const plugin(kData->plugins[0].plugin);
  91. if (plugin == nullptr || ! plugin->enabled())
  92. return nullptr;
  93. static ::Parameter param;
  94. static char strBufName[STR_MAX+1];
  95. static char strBufUnit[STR_MAX+1];
  96. const ParameterData& paramData(plugin->parameterData(index));
  97. const ParameterRanges& paramRanges(plugin->parameterRanges(index));
  98. plugin->getParameterName(index, strBufName);
  99. plugin->getParameterUnit(index, strBufUnit);
  100. int hints = 0x0;
  101. if (paramData.hints & PARAMETER_IS_BOOLEAN)
  102. hints |= ::PARAMETER_IS_BOOLEAN;
  103. if (paramData.hints & PARAMETER_IS_INTEGER)
  104. hints |= ::PARAMETER_IS_INTEGER;
  105. if (paramData.hints & PARAMETER_IS_LOGARITHMIC)
  106. hints |= ::PARAMETER_IS_LOGARITHMIC;
  107. if (paramData.hints & PARAMETER_IS_AUTOMABLE)
  108. hints |= ::PARAMETER_IS_AUTOMABLE;
  109. if (paramData.hints & PARAMETER_USES_SAMPLERATE)
  110. hints |= ::PARAMETER_USES_SAMPLE_RATE;
  111. if (paramData.hints & PARAMETER_USES_SCALEPOINTS)
  112. hints |= ::PARAMETER_USES_SCALEPOINTS;
  113. if (paramData.hints & PARAMETER_USES_CUSTOM_TEXT)
  114. hints |= ::PARAMETER_USES_CUSTOM_TEXT;
  115. if (paramData.type == PARAMETER_INPUT || paramData.type == PARAMETER_OUTPUT)
  116. {
  117. if (paramData.hints & PARAMETER_IS_ENABLED)
  118. hints |= ::PARAMETER_IS_ENABLED;
  119. if (paramData.type == PARAMETER_OUTPUT)
  120. hints |= ::PARAMETER_IS_OUTPUT;
  121. }
  122. param.hints = (::ParameterHints)hints;
  123. param.name = strBufName;
  124. param.unit = strBufUnit;
  125. param.ranges.def = paramRanges.def;
  126. param.ranges.min = paramRanges.min;
  127. param.ranges.max = paramRanges.max;
  128. param.ranges.step = paramRanges.step;
  129. param.ranges.stepSmall = paramRanges.stepSmall;
  130. param.ranges.stepLarge = paramRanges.stepLarge;
  131. param.scalePointCount = 0; // TODO
  132. param.scalePoints = nullptr;
  133. return &param;
  134. }
  135. float getParameterValue(const uint32_t index)
  136. {
  137. if (index >= getParameterCount())
  138. return 0.0f;
  139. CarlaPlugin* const plugin(kData->plugins[0].plugin);
  140. if (plugin == nullptr || ! plugin->enabled())
  141. return 0.0f;
  142. return plugin->getParameterValue(index);
  143. }
  144. // -------------------------------------------------------------------
  145. // Plugin process calls
  146. void activate()
  147. {
  148. }
  149. void deactivate()
  150. {
  151. }
  152. void process(float**, float**, const uint32_t frames, const uint32_t midiEventCount, const MidiEvent* const midiEvents)
  153. {
  154. }
  155. private:
  156. PluginDescriptorClassEND(CarlaEngineNative)
  157. CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(CarlaEngineNative)
  158. };
  159. // -----------------------------------------------------------------------
  160. static const PluginDescriptor carlaDesc = {
  161. /* category */ ::PLUGIN_CATEGORY_OTHER,
  162. /* hints */ /*static_cast<::PluginCategory>(*/::PLUGIN_IS_SYNTH/*)*/,
  163. /* audioIns */ 2,
  164. /* audioOuts */ 2,
  165. /* midiIns */ 1,
  166. /* midiOuts */ 1,
  167. /* paramIns */ 0,
  168. /* paramOuts */ 0,
  169. /* name */ "Carla",
  170. /* label */ "carla",
  171. /* maker */ "falkTX",
  172. /* copyright */ "GNU GPL v2+",
  173. PluginDescriptorFILL(CarlaEngineNative)
  174. };
  175. // -----------------------------------------------------------------------
  176. CARLA_BACKEND_END_NAMESPACE
  177. // -----------------------------------------------------------------------
  178. void carla_register_native_plugin_carla()
  179. {
  180. CARLA_BACKEND_USE_NAMESPACE
  181. carla_register_native_plugin(&carlaDesc);
  182. }
  183. // -----------------------------------------------------------------------