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.

300 lines
7.8KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021-2022 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 3 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 LICENSE file.
  16. */
  17. #include <juce_audio_processors/juce_audio_processors.h>
  18. #define createPlugin createStaticPlugin
  19. #include "src/DistrhoPluginInternal.hpp"
  20. #include "src/DistrhoUIInternal.hpp"
  21. START_NAMESPACE_DISTRHO
  22. #if 0
  23. // -----------------------------------------------------------------------------------------------------------
  24. class ParameterForDPF : public juce::AudioProcessorParameter
  25. {
  26. PluginExporter& plugin;
  27. const uint index;
  28. public:
  29. ParameterForDPF(PluginExporter& plugin_, const uint index_)
  30. : plugin(plugin_),
  31. index(index_) {}
  32. protected:
  33. float getValue() const override
  34. {
  35. return plugin.getParameterRanges(index).getNormalizedValue(plugin.getParameterValue(index));
  36. }
  37. void setValue(const float newValue) override
  38. {
  39. plugin.setParameterValue(index, plugin.getParameterRanges(index).getUnnormalizedValue(newValue));
  40. }
  41. float getDefaultValue() const override
  42. {
  43. return plugin.getParameterDefault(index);
  44. }
  45. juce::String getName(int) const override
  46. {
  47. return plugin.getParameterName(index).buffer();
  48. }
  49. juce::String getLabel() const override
  50. {
  51. return plugin.getParameterUnit(index).buffer();
  52. }
  53. float getValueForText(const juce::String& text) const override
  54. {
  55. return 0.0f;
  56. }
  57. };
  58. #endif
  59. // -----------------------------------------------------------------------------------------------------------
  60. class CardinalWrapperProcessor : public juce::AudioProcessor
  61. {
  62. friend class CardinalWrapperEditor;
  63. PluginExporter plugin;
  64. static bool writeMidi(void* ptr, const MidiEvent& midiEvent)
  65. {
  66. return false;
  67. }
  68. static bool requestParameterValueChange(void* ptr, uint32_t index, float value)
  69. {
  70. return false;
  71. }
  72. static bool updateStateValue(void* ptr, const char* key, const char* value)
  73. {
  74. return false;
  75. }
  76. public:
  77. CardinalWrapperProcessor()
  78. : plugin(this, writeMidi, requestParameterValueChange, updateStateValue)
  79. {
  80. if (const double sampleRate = getSampleRate())
  81. plugin.setSampleRate(sampleRate);
  82. if (const int blockSize = getBlockSize())
  83. plugin.setBufferSize(blockSize);
  84. // for (uint i=0; i<plugin.getParameterCount(); ++i)
  85. // addParameter(new ParameterForDPF(plugin, i));
  86. }
  87. ~CardinalWrapperProcessor() override
  88. {
  89. }
  90. const juce::String getName() const override
  91. {
  92. return plugin.getName();
  93. }
  94. juce::StringArray getAlternateDisplayNames() const override
  95. {
  96. return juce::StringArray(plugin.getLabel());
  97. }
  98. void prepareToPlay(double sampleRate, int samplesPerBlock) override
  99. {
  100. plugin.deactivateIfNeeded();
  101. plugin.setSampleRate(sampleRate);
  102. plugin.setBufferSize(samplesPerBlock);
  103. plugin.activate();
  104. }
  105. void releaseResources() override
  106. {
  107. plugin.deactivateIfNeeded();
  108. }
  109. void processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) override
  110. {
  111. midiMessages.clear();
  112. // AudioPlayHead* getPlayHead()
  113. const int numSamples = buffer.getNumSamples();
  114. DISTRHO_SAFE_ASSERT_INT_RETURN(numSamples > 0, numSamples,);
  115. DISTRHO_SAFE_ASSERT_RETURN(buffer.getNumChannels() == 2,);
  116. const float* audioBufferIn[2];
  117. float* audioBufferOut[2];
  118. audioBufferIn[0] = buffer.getReadPointer(0);
  119. audioBufferIn[1] = buffer.getReadPointer(1);
  120. audioBufferOut[0] = buffer.getWritePointer(0);
  121. audioBufferOut[1] = buffer.getWritePointer(1);
  122. plugin.run(audioBufferIn, audioBufferOut, numSamples, nullptr, 0);
  123. }
  124. double getTailLengthSeconds() const override
  125. {
  126. return 0.0;
  127. }
  128. bool acceptsMidi() const override
  129. {
  130. return true;
  131. }
  132. bool producesMidi() const override
  133. {
  134. return true;
  135. }
  136. juce::AudioProcessorEditor* createEditor() override;
  137. bool hasEditor() const override
  138. {
  139. return true;
  140. }
  141. int getNumPrograms() override
  142. {
  143. return 0;
  144. }
  145. int getCurrentProgram() override
  146. {
  147. return 0;
  148. }
  149. void setCurrentProgram(int) override
  150. {
  151. }
  152. const juce::String getProgramName(int) override
  153. {
  154. return {};
  155. }
  156. void changeProgramName(int, const juce::String&) override
  157. {
  158. }
  159. void getStateInformation(juce::MemoryBlock& destData) override
  160. {
  161. }
  162. void setStateInformation(const void* data, int sizeInBytes) override
  163. {
  164. }
  165. };
  166. // -----------------------------------------------------------------------------------------------------------
  167. class CardinalWrapperEditor : public juce::AudioProcessorEditor
  168. {
  169. UIExporter* ui;
  170. void* const dspPtr;
  171. static void editParamFunc(void* ptr, uint32_t rindex, bool started) {}
  172. static void setParamFunc(void* ptr, uint32_t rindex, float value) {}
  173. static void setStateFunc(void* ptr, const char* key, const char* value) {}
  174. static void sendNoteFunc(void* ptr, uint8_t channel, uint8_t note, uint8_t velo) {}
  175. static void setSizeFunc(void* ptr, uint width, uint height)
  176. {
  177. static_cast<CardinalWrapperEditor*>(ptr)->setSize(width, height);
  178. }
  179. static bool fileRequestFunc(void* ptr, const char* key) { return false; }
  180. public:
  181. CardinalWrapperEditor(CardinalWrapperProcessor& cardinalProcessor)
  182. : juce::AudioProcessorEditor(cardinalProcessor),
  183. ui(nullptr),
  184. dspPtr(cardinalProcessor.plugin.getInstancePointer())
  185. {
  186. setOpaque(true);
  187. setResizable(true, false);
  188. // setResizeLimits(648, 538, -1, -1);
  189. setSize(1228, 666);
  190. }
  191. ~CardinalWrapperEditor() override
  192. {
  193. delete ui;
  194. }
  195. void paint(juce::Graphics&)
  196. {
  197. if (ui == nullptr)
  198. {
  199. auto peer = getPeer();
  200. d_stdout("peer is %p", peer);
  201. auto handle = peer->getNativeHandle();
  202. d_stdout("handle is %p", handle);
  203. auto proc = getAudioProcessor();
  204. d_stdout("proc is %p", proc);
  205. ui = new UIExporter(this,
  206. (uintptr_t)handle,
  207. proc->getSampleRate(),
  208. editParamFunc,
  209. setParamFunc,
  210. setStateFunc,
  211. sendNoteFunc,
  212. setSizeFunc,
  213. fileRequestFunc,
  214. nullptr, // bundlePath
  215. dspPtr,
  216. 0.0 // scaleFactor
  217. );
  218. }
  219. ui->plugin_idle();
  220. repaint();
  221. }
  222. };
  223. juce::AudioProcessorEditor* CardinalWrapperProcessor::createEditor()
  224. {
  225. return new CardinalWrapperEditor(*this);
  226. }
  227. // -----------------------------------------------------------------------------------------------------------
  228. END_NAMESPACE_DISTRHO
  229. // -----------------------------------------------------------------------------------------------------------
  230. juce::AudioProcessor* createPluginFilter()
  231. {
  232. // set valid but dummy values
  233. d_nextBufferSize = 512;
  234. d_nextSampleRate = 48000.0;
  235. return new DISTRHO_NAMESPACE::CardinalWrapperProcessor;
  236. }
  237. // -----------------------------------------------------------------------------------------------------------