PluginProcessor.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. ==============================================================================
  3. This file contains the basic framework code for a JUCE plugin processor.
  4. ==============================================================================
  5. */
  6. #include "PluginProcessor.h"
  7. #include "PluginEditor.h"
  8. //==============================================================================
  9. CMLSProjectAudioProcessor::CMLSProjectAudioProcessor()
  10. #ifndef JucePlugin_PreferredChannelConfigurations
  11. : AudioProcessor (BusesProperties()
  12. #if ! JucePlugin_IsMidiEffect
  13. #if ! JucePlugin_IsSynth
  14. .withInput ("Input", juce::AudioChannelSet::stereo(), true)
  15. #endif
  16. .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
  17. #endif
  18. ), apvts(*this, nullptr, "Parameters", createParameters())
  19. #endif
  20. {
  21. // Chaining the effects
  22. this->equalizer = new CMLSEqualizer();
  23. this->distortion = new CMLSDistortion();
  24. this->chorus = new CMLSChorus();
  25. this->delay = new CMLSDelay();
  26. this->reverb = new CMLSReverb();
  27. this->apvtsListeners.setEqualizerProcessor((CMLSEqualizer*)this->equalizer);
  28. this->apvtsListeners.setDistortionProcssor((CMLSDistortion*)this->distortion);
  29. this->apvtsListeners.setChorusProcessor((CMLSChorus*)this->chorus);
  30. this->apvtsListeners.setDelayProcessor((CMLSDelay*)this->delay);
  31. this->apvtsListeners.setReverbProcessor((CMLSReverb*)this->reverb);
  32. this->apvts.addParameterListener("EQLOWBANDGAIN", &apvtsListeners);
  33. this->apvts.addParameterListener("EQHIGHBANDGAIN", &apvtsListeners);
  34. this->apvts.addParameterListener("DISTORTIONDRIVE", &apvtsListeners);
  35. this->apvts.addParameterListener("DISTORTIONMIX", &apvtsListeners);
  36. this->apvts.addParameterListener("CHORUSDRYWET", &apvtsListeners);
  37. this->apvts.addParameterListener("CHORUSAMOUNT", &apvtsListeners);
  38. this->apvts.addParameterListener("DELAYDRYWET", &apvtsListeners);
  39. this->apvts.addParameterListener("DELAYAMOUNT", &apvtsListeners);
  40. this->apvts.addParameterListener("REVERBROOMSIZE", &apvtsListeners);
  41. this->apvts.addParameterListener("REVERBDRYWET", &apvtsListeners);
  42. this->processorChain.pushProcessor(*equalizer);
  43. this->processorChain.pushProcessor(*distortion);
  44. this->processorChain.pushProcessor(*chorus);
  45. this->processorChain.pushProcessor(*delay);
  46. this->processorChain.pushProcessor(*reverb);
  47. this->processorChain.reset();
  48. }
  49. CMLSProjectAudioProcessor::~CMLSProjectAudioProcessor()
  50. {
  51. }
  52. //==============================================================================
  53. const juce::String CMLSProjectAudioProcessor::getName() const
  54. {
  55. return JucePlugin_Name;
  56. }
  57. bool CMLSProjectAudioProcessor::acceptsMidi() const
  58. {
  59. #if JucePlugin_WantsMidiInput
  60. return true;
  61. #else
  62. return false;
  63. #endif
  64. }
  65. bool CMLSProjectAudioProcessor::producesMidi() const
  66. {
  67. #if JucePlugin_ProducesMidiOutput
  68. return true;
  69. #else
  70. return false;
  71. #endif
  72. }
  73. bool CMLSProjectAudioProcessor::isMidiEffect() const
  74. {
  75. #if JucePlugin_IsMidiEffect
  76. return true;
  77. #else
  78. return false;
  79. #endif
  80. }
  81. double CMLSProjectAudioProcessor::getTailLengthSeconds() const
  82. {
  83. return 0.0;
  84. }
  85. int CMLSProjectAudioProcessor::getNumPrograms()
  86. {
  87. return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
  88. // so this should be at least 1, even if you're not really implementing programs.
  89. }
  90. int CMLSProjectAudioProcessor::getCurrentProgram()
  91. {
  92. return 0;
  93. }
  94. void CMLSProjectAudioProcessor::setCurrentProgram (int index)
  95. {
  96. }
  97. const juce::String CMLSProjectAudioProcessor::getProgramName (int index)
  98. {
  99. return {};
  100. }
  101. void CMLSProjectAudioProcessor::changeProgramName (int index, const juce::String& newName)
  102. {
  103. }
  104. //==============================================================================
  105. void CMLSProjectAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
  106. {
  107. // Use this method as the place to do any pre-playback
  108. // initialisation that you need..
  109. juce::dsp::ProcessSpec spec;
  110. spec.maximumBlockSize = samplesPerBlock;
  111. spec.numChannels = getTotalNumOutputChannels();
  112. spec.sampleRate = sampleRate;
  113. this->processorChain.prepare(spec);
  114. }
  115. void CMLSProjectAudioProcessor::releaseResources()
  116. {
  117. // When playback stops, you can use this as an opportunity to free up any
  118. // spare memory, etc.
  119. }
  120. #ifndef JucePlugin_PreferredChannelConfigurations
  121. bool CMLSProjectAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  122. {
  123. #if JucePlugin_IsMidiEffect
  124. juce::ignoreUnused (layouts);
  125. return true;
  126. #else
  127. // This is the place where you check if the layout is supported.
  128. // In this template code we only support mono or stereo.
  129. // Some plugin hosts, such as certain GarageBand versions, will only
  130. // load plugins that support stereo bus layouts.
  131. if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
  132. && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
  133. return false;
  134. // This checks if the input layout matches the output layout
  135. #if ! JucePlugin_IsSynth
  136. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  137. return false;
  138. #endif
  139. return true;
  140. #endif
  141. }
  142. #endif
  143. void CMLSProjectAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
  144. {
  145. juce::ScopedNoDenormals noDenormals;
  146. auto totalNumInputChannels = getTotalNumInputChannels();
  147. auto totalNumOutputChannels = getTotalNumOutputChannels();
  148. const auto numChannels = juce::jmax(totalNumInputChannels, totalNumOutputChannels);
  149. auto audioBlock = juce::dsp::AudioBlock<float>(buffer).getSubsetChannelBlock(0, (int)numChannels);
  150. auto context = juce::dsp::ProcessContextReplacing<float>(audioBlock);
  151. /* Processing */
  152. this->processorChain.process(context);
  153. }
  154. //==============================================================================
  155. bool CMLSProjectAudioProcessor::hasEditor() const
  156. {
  157. return true; // (change this to false if you choose to not supply an editor)
  158. }
  159. juce::AudioProcessorEditor* CMLSProjectAudioProcessor::createEditor()
  160. {
  161. return new juce::GenericAudioProcessorEditor (*this);
  162. }
  163. //==============================================================================
  164. void CMLSProjectAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
  165. {
  166. // You should use this method to store your parameters in the memory block.
  167. // You could do that either as raw data, or use the XML or ValueTree classes
  168. // as intermediaries to make it easy to save and load complex data.
  169. }
  170. void CMLSProjectAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  171. {
  172. // You should use this method to restore your parameters from this memory block,
  173. // whose contents will have been created by the getStateInformation() call.
  174. }
  175. void CMLSProjectAudioProcessor::muteEffectInSlot(int slot) {
  176. this->processorChain.muteProcessrInSlot(slot);
  177. }
  178. void CMLSProjectAudioProcessor::unmuteEffectInSlot(int slot) {
  179. this->processorChain.unmuteProcessorInSlot(slot);
  180. }
  181. void CMLSProjectAudioProcessor::swapEffectInSlot(int slot1, int slot2) {
  182. this->processorChain.swapPlaces(slot1, slot2);
  183. }
  184. juce::AudioProcessorValueTreeState* CMLSProjectAudioProcessor::getApvts() {
  185. return &this->apvts;
  186. }
  187. //==============================================================================
  188. // This creates new instances of the plugin..
  189. juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  190. {
  191. return new CMLSProjectAudioProcessor();
  192. }
  193. juce::AudioProcessorValueTreeState::ParameterLayout CMLSProjectAudioProcessor::createParameters() {
  194. std::vector<std::unique_ptr<juce::RangedAudioParameter>> params;
  195. // Equalizer parameters
  196. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  197. "EQLOWBANDGAIN",
  198. "EqLowBandGain",
  199. -60.0f,
  200. 20.0f,
  201. 0.0f
  202. ));
  203. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  204. "EQHIGHBANDGAIN",
  205. "EqHighBandGain",
  206. -60.0f,
  207. 20.0f,
  208. 0.0f
  209. ));
  210. // Distortion parameter
  211. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  212. "DISTORTIONDRIVE",
  213. "DistortionDrive",
  214. 1.0f,
  215. 15.0f,
  216. 1.0f
  217. ));
  218. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  219. "DISTORTIONMIX",
  220. "DistortionMix",
  221. 0.0f,
  222. 1.0f,
  223. 0.0f
  224. ));
  225. // Chorus parameter
  226. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  227. "CHORUSDRYWET",
  228. "ChorusDryWet",
  229. 0.0f,
  230. 1.0f,
  231. 0.0f
  232. ));
  233. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  234. "CHORUSAMOUNT",
  235. "ChorusAmount",
  236. 0.0f,
  237. 1.0f,
  238. 0.0f
  239. ));
  240. // Delay parameter
  241. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  242. "DELAYDRYWET",
  243. "DelayDryWet",
  244. 0.0f,
  245. 1.0f,
  246. 0.0f
  247. ));
  248. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  249. "DELAYAMOUNT",
  250. "DelayAmount",
  251. 0.0f,
  252. 1.0f,
  253. 0.0f
  254. ));
  255. // Reverb parameters
  256. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  257. "REVERBROOMSIZE",
  258. "ReverbRoomSize",
  259. 0.0f,
  260. 1.0f,
  261. 0.0f
  262. ));
  263. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  264. "REVERBDRYWET",
  265. "ReverbDryWet",
  266. 0.0f,
  267. 1.0f,
  268. 0.0f
  269. ));
  270. return { params.begin(), params.end() };
  271. }