PluginProcessor.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "PluginProcessor.h"
  2. #include "PluginEditor.h"
  3. //==============================================================================
  4. CMLSProjectAudioProcessor::CMLSProjectAudioProcessor()
  5. #ifndef JucePlugin_PreferredChannelConfigurations
  6. : AudioProcessor(BusesProperties()
  7. #if ! JucePlugin_IsMidiEffect
  8. #if ! JucePlugin_IsSynth
  9. .withInput("Input", juce::AudioChannelSet::stereo(), true)
  10. #endif
  11. .withOutput("Output", juce::AudioChannelSet::stereo(), true)
  12. #endif
  13. )
  14. #endif
  15. {
  16. // chaining the effects
  17. this->processorChain.reset();
  18. }
  19. CMLSProjectAudioProcessor::~CMLSProjectAudioProcessor() {}
  20. //==============================================================================
  21. const juce::String CMLSProjectAudioProcessor::getName() const
  22. {
  23. return JucePlugin_Name;
  24. }
  25. bool CMLSProjectAudioProcessor::acceptsMidi() const
  26. {
  27. #if JucePlugin_WantsMidiInput
  28. return true;
  29. #else
  30. return false;
  31. #endif
  32. }
  33. bool CMLSProjectAudioProcessor::producesMidi() const
  34. {
  35. #if JucePlugin_ProducesMidiOutput
  36. return true;
  37. #else
  38. return false;
  39. #endif
  40. }
  41. bool CMLSProjectAudioProcessor::isMidiEffect() const
  42. {
  43. #if JucePlugin_IsMidiEffect
  44. return true;
  45. #else
  46. return false;
  47. #endif
  48. }
  49. double CMLSProjectAudioProcessor::getTailLengthSeconds() const
  50. {
  51. return 0.0;
  52. }
  53. int CMLSProjectAudioProcessor::getNumPrograms() { return 1; }
  54. int CMLSProjectAudioProcessor::getCurrentProgram() { return 0; }
  55. void CMLSProjectAudioProcessor::setCurrentProgram(int index) {}
  56. const juce::String CMLSProjectAudioProcessor::getProgramName(int index) { return {}; }
  57. void CMLSProjectAudioProcessor::changeProgramName(int index, const juce::String& newName) {}
  58. //==============================================================================
  59. void CMLSProjectAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
  60. {
  61. // the place to do any pre-playback & initialisation
  62. juce::dsp::ProcessSpec spec;
  63. spec.sampleRate = sampleRate;
  64. spec.maximumBlockSize = samplesPerBlock;
  65. spec.numChannels = getTotalNumOutputChannels();
  66. this->processorChain.prepare(spec);
  67. }
  68. void CMLSProjectAudioProcessor::releaseResources() {}
  69. #ifndef JucePlugin_PreferredChannelConfigurations
  70. bool CMLSProjectAudioProcessor::isBusesLayoutSupported(const BusesLayout& layouts) const
  71. {
  72. #if JucePlugin_IsMidiEffect
  73. juce::ignoreUnused(layouts);
  74. return true;
  75. #else
  76. // This is the place where you check if the layout is supported.
  77. // In this template code we only support mono or stereo.
  78. if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
  79. && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
  80. return false;
  81. // This checks if the input layout matches the output layout.
  82. #if ! JucePlugin_IsSynth
  83. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  84. return false;
  85. #endif
  86. return true;
  87. #endif
  88. }
  89. #endif
  90. void CMLSProjectAudioProcessor::processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midiMessages)
  91. {
  92. juce::ScopedNoDenormals noDenormals;
  93. auto totalNumInputChannels = getTotalNumInputChannels();
  94. auto totalNumOutputChannels = getTotalNumOutputChannels();
  95. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  96. buffer.clear(i, 0, buffer.getNumSamples()); // clear any output channels that don't have input data
  97. const auto numChannels = juce::jmax(totalNumInputChannels, totalNumOutputChannels);
  98. auto audioBlock = juce::dsp::AudioBlock<float>(buffer).getSubsetChannelBlock(0, (int)numChannels);
  99. auto context = juce::dsp::ProcessContextReplacing<float>(audioBlock);
  100. this->processorChain.process(context);
  101. }
  102. //==============================================================================
  103. bool CMLSProjectAudioProcessor::hasEditor() const
  104. {
  105. return true;
  106. }
  107. juce::AudioProcessorEditor* CMLSProjectAudioProcessor::createEditor()
  108. {
  109. return new CMLSProjectAudioProcessorEditor(*this);
  110. }
  111. //==============================================================================
  112. void CMLSProjectAudioProcessor::getStateInformation(juce::MemoryBlock& destData)
  113. {
  114. }
  115. void CMLSProjectAudioProcessor::setStateInformation(const void* data, int sizeInBytes)
  116. {
  117. }
  118. //==============================================================================
  119. void CMLSProjectAudioProcessor::setEqLowGain(float value)
  120. {
  121. auto& instance = this->processorChain.template get<0>();
  122. instance.setEqLowGain(value);
  123. }
  124. void CMLSProjectAudioProcessor::setEqHighGain(float value)
  125. {
  126. auto& instance = this->processorChain.template get<0>();
  127. instance.setEqHighGain(value);
  128. }
  129. void CMLSProjectAudioProcessor::setDistortionDrive(float value)
  130. {
  131. auto& instance = this->processorChain.template get<1>();
  132. instance.setDrive(value);
  133. }
  134. void CMLSProjectAudioProcessor::setDistortionMix(float value)
  135. {
  136. auto& instance = this->processorChain.template get<1>();
  137. instance.setMix(value);
  138. }
  139. //==============================================================================
  140. // This creates new instances of the plugin.
  141. juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  142. {
  143. return new CMLSProjectAudioProcessor();
  144. }