PluginProcessor.cpp 6.5 KB

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