PluginProcessor.cpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. )
  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->processorChain.pushProcessor(*equalizer);
  28. this->processorChain.pushProcessor(*distortion);
  29. this->processorChain.pushProcessor(*chorus);
  30. this->processorChain.pushProcessor(*delay);
  31. this->processorChain.pushProcessor(*reverb);
  32. this->processorChain.reset();
  33. }
  34. CMLSProjectAudioProcessor::~CMLSProjectAudioProcessor()
  35. {
  36. }
  37. //==============================================================================
  38. const juce::String CMLSProjectAudioProcessor::getName() const
  39. {
  40. return JucePlugin_Name;
  41. }
  42. bool CMLSProjectAudioProcessor::acceptsMidi() const
  43. {
  44. #if JucePlugin_WantsMidiInput
  45. return true;
  46. #else
  47. return false;
  48. #endif
  49. }
  50. bool CMLSProjectAudioProcessor::producesMidi() const
  51. {
  52. #if JucePlugin_ProducesMidiOutput
  53. return true;
  54. #else
  55. return false;
  56. #endif
  57. }
  58. bool CMLSProjectAudioProcessor::isMidiEffect() const
  59. {
  60. #if JucePlugin_IsMidiEffect
  61. return true;
  62. #else
  63. return false;
  64. #endif
  65. }
  66. double CMLSProjectAudioProcessor::getTailLengthSeconds() const
  67. {
  68. return 0.0;
  69. }
  70. int CMLSProjectAudioProcessor::getNumPrograms()
  71. {
  72. return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
  73. // so this should be at least 1, even if you're not really implementing programs.
  74. }
  75. int CMLSProjectAudioProcessor::getCurrentProgram()
  76. {
  77. return 0;
  78. }
  79. void CMLSProjectAudioProcessor::setCurrentProgram (int index)
  80. {
  81. }
  82. const juce::String CMLSProjectAudioProcessor::getProgramName (int index)
  83. {
  84. return {};
  85. }
  86. void CMLSProjectAudioProcessor::changeProgramName (int index, const juce::String& newName)
  87. {
  88. }
  89. //==============================================================================
  90. void CMLSProjectAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
  91. {
  92. // Use this method as the place to do any pre-playback
  93. // initialisation that you need..
  94. juce::dsp::ProcessSpec spec;
  95. spec.maximumBlockSize = samplesPerBlock;
  96. spec.numChannels = getTotalNumOutputChannels();
  97. spec.sampleRate = sampleRate;
  98. this->processorChain.prepare(spec);
  99. }
  100. void CMLSProjectAudioProcessor::releaseResources()
  101. {
  102. // When playback stops, you can use this as an opportunity to free up any
  103. // spare memory, etc.
  104. }
  105. #ifndef JucePlugin_PreferredChannelConfigurations
  106. bool CMLSProjectAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  107. {
  108. #if JucePlugin_IsMidiEffect
  109. juce::ignoreUnused (layouts);
  110. return true;
  111. #else
  112. // This is the place where you check if the layout is supported.
  113. // In this template code we only support mono or stereo.
  114. // Some plugin hosts, such as certain GarageBand versions, will only
  115. // load plugins that support stereo bus layouts.
  116. if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
  117. && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
  118. return false;
  119. // This checks if the input layout matches the output layout
  120. #if ! JucePlugin_IsSynth
  121. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  122. return false;
  123. #endif
  124. return true;
  125. #endif
  126. }
  127. #endif
  128. void CMLSProjectAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
  129. {
  130. juce::ScopedNoDenormals noDenormals;
  131. auto totalNumInputChannels = getTotalNumInputChannels();
  132. auto totalNumOutputChannels = getTotalNumOutputChannels();
  133. const auto numChannels = juce::jmax(totalNumInputChannels, totalNumOutputChannels);
  134. auto audioBlock = juce::dsp::AudioBlock<float>(buffer).getSubsetChannelBlock(0, (int)numChannels);
  135. auto context = juce::dsp::ProcessContextReplacing<float>(audioBlock);
  136. /* Processing */
  137. this->processorChain.process(context);
  138. }
  139. //==============================================================================
  140. bool CMLSProjectAudioProcessor::hasEditor() const
  141. {
  142. return true; // (change this to false if you choose to not supply an editor)
  143. }
  144. juce::AudioProcessorEditor* CMLSProjectAudioProcessor::createEditor()
  145. {
  146. return new CMLSProjectAudioProcessorEditor (*this);
  147. }
  148. //==============================================================================
  149. void CMLSProjectAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
  150. {
  151. // You should use this method to store your parameters in the memory block.
  152. // You could do that either as raw data, or use the XML or ValueTree classes
  153. // as intermediaries to make it easy to save and load complex data.
  154. }
  155. void CMLSProjectAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  156. {
  157. // You should use this method to restore your parameters from this memory block,
  158. // whose contents will have been created by the getStateInformation() call.
  159. }
  160. void CMLSProjectAudioProcessor::muteEffectInSlot(int slot) {
  161. this->processorChain.muteProcessrInSlot(slot);
  162. }
  163. void CMLSProjectAudioProcessor::unmuteEffectInSlot(int slot) {
  164. this->processorChain.unmuteProcessorInSlot(slot);
  165. }
  166. void CMLSProjectAudioProcessor::swapEffectInSlot(int slot1, int slot2) {
  167. this->processorChain.swapPlaces(slot1, slot2);
  168. }
  169. void CMLSProjectAudioProcessor::setEqLowGain(float value) {
  170. ((CMLSEqualizer*)this->equalizer)->setEqLowGain(value);
  171. }
  172. void CMLSProjectAudioProcessor::setEqHighGain(float value) {
  173. ((CMLSEqualizer*)this->equalizer)->setEqHighGain(value);
  174. }
  175. void CMLSProjectAudioProcessor::setDistortionDrive(float value) {
  176. ((CMLSDistortion*)this->distortion)->setDrive(value);
  177. }
  178. void CMLSProjectAudioProcessor::setDistortionMix(float value) {
  179. ((CMLSDistortion*)this->distortion)->setMix(value);
  180. }
  181. void CMLSProjectAudioProcessor::setChorusDryWet(float value) {
  182. //auto& instance = this->processorChain.template get<0>();
  183. //instance.setDryWet(value);
  184. ((CMLSChorus*)this->chorus)->setDryWet(value);
  185. }
  186. void CMLSProjectAudioProcessor::setChorusAmount(float value) {
  187. ((CMLSChorus*)this->chorus)->setAmount(value);
  188. }
  189. void CMLSProjectAudioProcessor::setReverbDryWet(float value) {
  190. ((CMLSReverb*)this->reverb)->setDryWet(value);
  191. }
  192. void CMLSProjectAudioProcessor::setReverbRoomSize(float value) {
  193. ((CMLSReverb*)this->reverb)->setRoomSize(value);
  194. }
  195. void CMLSProjectAudioProcessor::setDelayDryWet(float value) {
  196. ((CMLSDelay*)this->delay)->setDryWet(value);
  197. }
  198. void CMLSProjectAudioProcessor::setDelayAmount(float value) {
  199. ((CMLSDelay*)this->delay)->setAmount(value);
  200. }
  201. //==============================================================================
  202. // This creates new instances of the plugin..
  203. juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  204. {
  205. return new CMLSProjectAudioProcessor();
  206. }