PluginProcessor.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. void CMLSProjectAudioProcessor::setEqLowGain(float value) {
  185. ((CMLSEqualizer*)this->equalizer)->setEqLowGain(value);
  186. }
  187. void CMLSProjectAudioProcessor::setEqHighGain(float value) {
  188. ((CMLSEqualizer*)this->equalizer)->setEqHighGain(value);
  189. }
  190. void CMLSProjectAudioProcessor::setDistortionDrive(float value) {
  191. ((CMLSDistortion*)this->distortion)->setDrive(value);
  192. }
  193. void CMLSProjectAudioProcessor::setDistortionMix(float value) {
  194. ((CMLSDistortion*)this->distortion)->setMix(value);
  195. }
  196. void CMLSProjectAudioProcessor::setChorusDryWet(float value) {
  197. //auto& instance = this->processorChain.template get<0>();
  198. //instance.setDryWet(value);
  199. ((CMLSChorus*)this->chorus)->setDryWet(value);
  200. }
  201. void CMLSProjectAudioProcessor::setChorusAmount(float value) {
  202. ((CMLSChorus*)this->chorus)->setAmount(value);
  203. }
  204. void CMLSProjectAudioProcessor::setReverbDryWet(float value) {
  205. ((CMLSReverb*)this->reverb)->setDryWet(value);
  206. }
  207. void CMLSProjectAudioProcessor::setReverbRoomSize(float value) {
  208. ((CMLSReverb*)this->reverb)->setRoomSize(value);
  209. }
  210. void CMLSProjectAudioProcessor::setDelayDryWet(float value) {
  211. ((CMLSDelay*)this->delay)->setDryWet(value);
  212. }
  213. void CMLSProjectAudioProcessor::setDelayAmount(float value) {
  214. ((CMLSDelay*)this->delay)->setAmount(value);
  215. }
  216. //==============================================================================
  217. // This creates new instances of the plugin..
  218. juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  219. {
  220. return new CMLSProjectAudioProcessor();
  221. }
  222. juce::AudioProcessorValueTreeState::ParameterLayout CMLSProjectAudioProcessor::createParameters() {
  223. std::vector<std::unique_ptr<juce::RangedAudioParameter>> params;
  224. // Equalizer parameters
  225. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  226. "EQLOWBANDGAIN",
  227. "EqLowBandGain",
  228. -60.0f,
  229. 5.0f,
  230. 0.0f
  231. ));
  232. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  233. "EQHIGHBANDGAIN",
  234. "EqHighBandGain",
  235. -60.0f,
  236. 5.0f,
  237. 0.0f
  238. ));
  239. // Distortion parameter
  240. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  241. "DISTORTIONDRIVE",
  242. "DistortionDrive",
  243. 0.0f,
  244. 1.0f,
  245. 0.0f
  246. ));
  247. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  248. "DISTORTIONMIX",
  249. "DistortionMix",
  250. 0.0f,
  251. 1.0f,
  252. 0.0f
  253. ));
  254. // Chorus parameter
  255. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  256. "CHORUSDRYWET",
  257. "ChorusDryWet",
  258. 0.0f,
  259. 1.0f,
  260. 0.0f
  261. ));
  262. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  263. "CHORUSAMOUNT",
  264. "ChorusAmount",
  265. 0.0f,
  266. 1.0f,
  267. 0.0f
  268. ));
  269. // Delay parameter
  270. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  271. "DELAYDRYWET",
  272. "DelayDryWet",
  273. 0.0f,
  274. 1.0f,
  275. 0.0f
  276. ));
  277. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  278. "DELAYAMOUNT",
  279. "DelayAmount",
  280. 0.0f,
  281. 1.0f,
  282. 0.0f
  283. ));
  284. // Reverb parameters
  285. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  286. "REVERBROOMSIZE",
  287. "ReverbRoomSize",
  288. 0.0f,
  289. 1.0f,
  290. 0.0f
  291. ));
  292. params.push_back(std::make_unique<juce::AudioParameterFloat>(
  293. "REVERBDRYWET",
  294. "ReverbDryWet",
  295. 0.0f,
  296. 1.0f,
  297. 0.0f
  298. ));
  299. return { params.begin(), params.end() };
  300. }