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.

211 lines
5.1KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021 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. #include "DistrhoPlugin.hpp"
  19. #include "DistrhoUI.hpp"
  20. DISTRHO_PLUGIN_EXPORT DISTRHO_NAMESPACE::Plugin* createSharedPlugin();
  21. #define createPlugin ::createSharedPlugin
  22. #include "src/DistrhoPluginInternal.hpp"
  23. START_NAMESPACE_DISTRHO
  24. // -----------------------------------------------------------------------------------------------------------
  25. class ParameterForDPF : public juce::AudioProcessorParameter
  26. {
  27. PluginExporter& plugin;
  28. const uint index;
  29. public:
  30. ParameterForDPF(PluginExporter& plugin_, const uint index_)
  31. : plugin(plugin_),
  32. index(index_) {}
  33. protected:
  34. float getValue() const override
  35. {
  36. return plugin.getParameterRanges(index).getNormalizedValue(plugin.getParameterValue(index));
  37. }
  38. void setValue(const float newValue) override
  39. {
  40. plugin.setParameterValue(index, plugin.getParameterRanges(index).getUnnormalizedValue(newValue));
  41. }
  42. float getDefaultValue() const override
  43. {
  44. return plugin.getParameterDefault(index);
  45. }
  46. juce::String getName(int) const override
  47. {
  48. return plugin.getParameterName(index).buffer();
  49. }
  50. juce::String getLabel() const override
  51. {
  52. return plugin.getParameterUnit(index).buffer();
  53. }
  54. float getValueForText(const juce::String& text) const override
  55. {
  56. return 0.0f;
  57. }
  58. };
  59. // -----------------------------------------------------------------------------------------------------------
  60. class CardinalWrapperProcessor : public juce::AudioProcessor
  61. {
  62. PluginExporter plugin;
  63. static bool writeMidiCb(void* ptr, const MidiEvent& midiEvent)
  64. {
  65. return false;
  66. }
  67. static bool requestParameterValueChangeCb(void* ptr, uint32_t index, float value)
  68. {
  69. return false;
  70. }
  71. public:
  72. CardinalWrapperProcessor()
  73. : plugin(this, writeMidiCb, requestParameterValueChangeCb)
  74. {
  75. for (uint i=0; i<plugin.getParameterCount(); ++i)
  76. addParameter(new ParameterForDPF(plugin, i));
  77. }
  78. ~CardinalWrapperProcessor() override
  79. {
  80. }
  81. const juce::String getName() const override
  82. {
  83. return plugin.getName();
  84. }
  85. juce::StringArray getAlternateDisplayNames() const override
  86. {
  87. return juce::StringArray(plugin.getLabel());
  88. }
  89. void prepareToPlay(double sampleRate, int samplesPerBlock) override
  90. {
  91. plugin.deactivateIfNeeded();
  92. plugin.setSampleRate(sampleRate);
  93. plugin.setBufferSize(samplesPerBlock);
  94. plugin.activate();
  95. }
  96. void releaseResources() override
  97. {
  98. plugin.deactivateIfNeeded();
  99. }
  100. void processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages) override
  101. {
  102. midiMessages.clear();
  103. // AudioPlayHead* getPlayHead()
  104. }
  105. double getTailLengthSeconds() const override
  106. {
  107. return true;
  108. }
  109. bool acceptsMidi() const override
  110. {
  111. return true;
  112. }
  113. bool producesMidi() const override
  114. {
  115. return true;
  116. }
  117. juce::AudioProcessorEditor* createEditor() override;
  118. bool hasEditor() const override
  119. {
  120. return true;
  121. }
  122. int getNumPrograms() override
  123. {
  124. return 0;
  125. }
  126. int getCurrentProgram() override
  127. {
  128. return 0;
  129. }
  130. void setCurrentProgram(int) override
  131. {
  132. }
  133. const juce::String getProgramName(int) override
  134. {
  135. return {};
  136. }
  137. void changeProgramName(int, const juce::String&) override
  138. {
  139. }
  140. void getStateInformation(juce::MemoryBlock& destData) override
  141. {
  142. }
  143. void setStateInformation(const void* data, int sizeInBytes) override
  144. {
  145. }
  146. };
  147. class CardinalWrapperEditor : public juce::AudioProcessorEditor
  148. {
  149. public:
  150. CardinalWrapperEditor(CardinalWrapperProcessor& processor)
  151. : juce::AudioProcessorEditor(processor)
  152. {}
  153. ~CardinalWrapperEditor() override
  154. {}
  155. };
  156. // -----------------------------------------------------------------------------------------------------------
  157. END_NAMESPACE_DISTRHO
  158. // -----------------------------------------------------------------------------------------------------------
  159. juce::AudioProcessor* createPluginFilter()
  160. {
  161. return new DISTRHO_NAMESPACE::CardinalWrapperProcessor;
  162. }
  163. // -----------------------------------------------------------------------------------------------------------
  164. #define DISTRHO_IS_STANDALONE 0
  165. #include "src/DistrhoPlugin.cpp"
  166. #include "src/DistrhoUtils.cpp"