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.

235 lines
6.8KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2014 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 "CarlaPluginInternal.hpp"
  18. #include "CarlaLibCounter.hpp"
  19. #include <QtCore/QSettings>
  20. CARLA_BACKEND_START_NAMESPACE
  21. #if 0
  22. } // Fix editor indentation
  23. #endif
  24. // -----------------------------------------------------------------------
  25. // Buffer functions
  26. void CarlaPluginProtectedData::clearBuffers()
  27. {
  28. if (latencyBuffers != nullptr)
  29. {
  30. CARLA_ASSERT(audioIn.count > 0);
  31. for (uint32_t i=0; i < audioIn.count; ++i)
  32. {
  33. CARLA_SAFE_ASSERT_CONTINUE(latencyBuffers[i] != nullptr);
  34. delete[] latencyBuffers[i];
  35. latencyBuffers[i] = nullptr;
  36. }
  37. delete[] latencyBuffers;
  38. latencyBuffers = nullptr;
  39. latency = 0;
  40. }
  41. else
  42. {
  43. CARLA_ASSERT(latency == 0);
  44. }
  45. audioIn.clear();
  46. audioOut.clear();
  47. param.clear();
  48. event.clear();
  49. }
  50. void CarlaPluginProtectedData::recreateLatencyBuffers()
  51. {
  52. if (latencyBuffers != nullptr)
  53. {
  54. CARLA_ASSERT(audioIn.count > 0);
  55. for (uint32_t i=0; i < audioIn.count; ++i)
  56. {
  57. CARLA_SAFE_ASSERT_CONTINUE(latencyBuffers[i] != nullptr);
  58. delete[] latencyBuffers[i];
  59. latencyBuffers[i] = nullptr;
  60. }
  61. delete[] latencyBuffers;
  62. latencyBuffers = nullptr;
  63. }
  64. if (audioIn.count > 0 && latency > 0)
  65. {
  66. latencyBuffers = new float*[audioIn.count];
  67. for (uint32_t i=0; i < audioIn.count; ++i)
  68. {
  69. latencyBuffers[i] = new float[latency];
  70. FLOAT_CLEAR(latencyBuffers[i], latency);
  71. }
  72. }
  73. }
  74. // -----------------------------------------------------------------------
  75. // Post-poned events
  76. void CarlaPluginProtectedData::postponeRtEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const float value3)
  77. {
  78. CARLA_SAFE_ASSERT_RETURN(type != kPluginPostRtEventNull,);
  79. PluginPostRtEvent event = { type, value1, value2, value3 };
  80. postRtEvents.appendRT(event);
  81. }
  82. // -----------------------------------------------------------------------
  83. // Library functions
  84. static LibCounter sLibCounter;
  85. const char* CarlaPluginProtectedData::libError(const char* const filename)
  86. {
  87. return lib_error(filename);
  88. }
  89. bool CarlaPluginProtectedData::libOpen(const char* const filename)
  90. {
  91. lib = sLibCounter.open(filename);
  92. return (lib != nullptr);
  93. }
  94. bool CarlaPluginProtectedData::libClose()
  95. {
  96. const bool ret = sLibCounter.close(lib);
  97. lib = nullptr;
  98. return ret;
  99. }
  100. void* CarlaPluginProtectedData::libSymbol(const char* const symbol)
  101. {
  102. return lib_symbol(lib, symbol);
  103. }
  104. bool CarlaPluginProtectedData::uiLibOpen(const char* const filename)
  105. {
  106. uiLib = sLibCounter.open(filename);
  107. return (uiLib != nullptr);
  108. }
  109. bool CarlaPluginProtectedData::uiLibClose()
  110. {
  111. const bool ret = sLibCounter.close(uiLib);
  112. uiLib = nullptr;
  113. return ret;
  114. }
  115. void* CarlaPluginProtectedData::uiLibSymbol(const char* const symbol)
  116. {
  117. return lib_symbol(uiLib, symbol);
  118. }
  119. // -----------------------------------------------------------------------
  120. // Settings functions
  121. void CarlaPluginProtectedData::saveSetting(const unsigned int option, const bool yesNo)
  122. {
  123. CARLA_SAFE_ASSERT_RETURN(identifier != nullptr && identifier[0] != '\0',);
  124. QSettings settings("falkTX", "CarlaPluginSettings");
  125. settings.beginGroup(identifier);
  126. switch (option)
  127. {
  128. case PLUGIN_OPTION_FIXED_BUFFERS:
  129. settings.setValue("FixedBuffers", yesNo);
  130. break;
  131. case PLUGIN_OPTION_FORCE_STEREO:
  132. settings.setValue("ForceStereo", yesNo);
  133. break;
  134. case PLUGIN_OPTION_MAP_PROGRAM_CHANGES:
  135. settings.setValue("MapProgramChanges", yesNo);
  136. break;
  137. case PLUGIN_OPTION_USE_CHUNKS:
  138. settings.setValue("UseChunks", yesNo);
  139. break;
  140. case PLUGIN_OPTION_SEND_CONTROL_CHANGES:
  141. settings.setValue("SendControlChanges", yesNo);
  142. break;
  143. case PLUGIN_OPTION_SEND_CHANNEL_PRESSURE:
  144. settings.setValue("SendChannelPressure", yesNo);
  145. break;
  146. case PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH:
  147. settings.setValue("SendNoteAftertouch", yesNo);
  148. break;
  149. case PLUGIN_OPTION_SEND_PITCHBEND:
  150. settings.setValue("SendPitchbend", yesNo);
  151. break;
  152. case PLUGIN_OPTION_SEND_ALL_SOUND_OFF:
  153. settings.setValue("SendAllSoundOff", yesNo);
  154. break;
  155. default:
  156. break;
  157. }
  158. settings.endGroup();
  159. }
  160. unsigned int CarlaPluginProtectedData::loadSettings(const unsigned int options, const unsigned int availOptions)
  161. {
  162. CARLA_SAFE_ASSERT_RETURN(identifier != nullptr && identifier[0] != '\0', 0x0);
  163. QSettings settings("falkTX", "CarlaPluginSettings");
  164. settings.beginGroup(identifier);
  165. unsigned int newOptions = 0x0;
  166. #define CHECK_AND_SET_OPTION(STR, BIT) \
  167. if ((availOptions & BIT) != 0 || BIT == PLUGIN_OPTION_FORCE_STEREO) \
  168. { \
  169. if (settings.contains(STR)) \
  170. { \
  171. if (settings.value(STR, (options & BIT) != 0).toBool()) \
  172. newOptions |= BIT; \
  173. } \
  174. else if (options & BIT) \
  175. newOptions |= BIT; \
  176. }
  177. CHECK_AND_SET_OPTION("FixedBuffers", PLUGIN_OPTION_FIXED_BUFFERS);
  178. CHECK_AND_SET_OPTION("ForceStereo", PLUGIN_OPTION_FORCE_STEREO);
  179. CHECK_AND_SET_OPTION("MapProgramChanges", PLUGIN_OPTION_MAP_PROGRAM_CHANGES);
  180. CHECK_AND_SET_OPTION("UseChunks", PLUGIN_OPTION_USE_CHUNKS);
  181. CHECK_AND_SET_OPTION("SendControlChanges", PLUGIN_OPTION_SEND_CONTROL_CHANGES);
  182. CHECK_AND_SET_OPTION("SendChannelPressure", PLUGIN_OPTION_SEND_CHANNEL_PRESSURE);
  183. CHECK_AND_SET_OPTION("SendNoteAftertouch", PLUGIN_OPTION_SEND_NOTE_AFTERTOUCH);
  184. CHECK_AND_SET_OPTION("SendPitchbend", PLUGIN_OPTION_SEND_PITCHBEND);
  185. CHECK_AND_SET_OPTION("SendAllSoundOff", PLUGIN_OPTION_SEND_ALL_SOUND_OFF);
  186. #undef CHECK_AND_SET_OPTION
  187. settings.endGroup();
  188. return newOptions;
  189. }
  190. CARLA_BACKEND_END_NAMESPACE