The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.1KB

  1. #include "PluginProcessor.h"
  2. #include "PluginEditor.h"
  3. //==============================================================================
  4. AudioPluginAudioProcessor::AudioPluginAudioProcessor()
  5. : AudioProcessor (BusesProperties()
  6. #if ! JucePlugin_IsMidiEffect
  7. #if ! JucePlugin_IsSynth
  8. .withInput ("Input", juce::AudioChannelSet::stereo(), true)
  9. #endif
  10. .withOutput ("Output", juce::AudioChannelSet::stereo(), true)
  11. #endif
  12. )
  13. {
  14. }
  15. AudioPluginAudioProcessor::~AudioPluginAudioProcessor()
  16. {
  17. }
  18. //==============================================================================
  19. const juce::String AudioPluginAudioProcessor::getName() const
  20. {
  21. return JucePlugin_Name;
  22. }
  23. bool AudioPluginAudioProcessor::acceptsMidi() const
  24. {
  25. #if JucePlugin_WantsMidiInput
  26. return true;
  27. #else
  28. return false;
  29. #endif
  30. }
  31. bool AudioPluginAudioProcessor::producesMidi() const
  32. {
  33. #if JucePlugin_ProducesMidiOutput
  34. return true;
  35. #else
  36. return false;
  37. #endif
  38. }
  39. bool AudioPluginAudioProcessor::isMidiEffect() const
  40. {
  41. #if JucePlugin_IsMidiEffect
  42. return true;
  43. #else
  44. return false;
  45. #endif
  46. }
  47. double AudioPluginAudioProcessor::getTailLengthSeconds() const
  48. {
  49. return 0.0;
  50. }
  51. int AudioPluginAudioProcessor::getNumPrograms()
  52. {
  53. return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
  54. // so this should be at least 1, even if you're not really implementing programs.
  55. }
  56. int AudioPluginAudioProcessor::getCurrentProgram()
  57. {
  58. return 0;
  59. }
  60. void AudioPluginAudioProcessor::setCurrentProgram (int index)
  61. {
  62. juce::ignoreUnused (index);
  63. }
  64. const juce::String AudioPluginAudioProcessor::getProgramName (int index)
  65. {
  66. juce::ignoreUnused (index);
  67. return {};
  68. }
  69. void AudioPluginAudioProcessor::changeProgramName (int index, const juce::String& newName)
  70. {
  71. juce::ignoreUnused (index, newName);
  72. }
  73. //==============================================================================
  74. void AudioPluginAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
  75. {
  76. // Use this method as the place to do any pre-playback
  77. // initialisation that you need..
  78. juce::ignoreUnused (sampleRate, samplesPerBlock);
  79. }
  80. void AudioPluginAudioProcessor::releaseResources()
  81. {
  82. // When playback stops, you can use this as an opportunity to free up any
  83. // spare memory, etc.
  84. }
  85. bool AudioPluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  86. {
  87. #if JucePlugin_IsMidiEffect
  88. juce::ignoreUnused (layouts);
  89. return true;
  90. #else
  91. // This is the place where you check if the layout is supported.
  92. // In this template code we only support mono or stereo.
  93. if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
  94. && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
  95. return false;
  96. // This checks if the input layout matches the output layout
  97. #if ! JucePlugin_IsSynth
  98. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  99. return false;
  100. #endif
  101. return true;
  102. #endif
  103. }
  104. void AudioPluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
  105. juce::MidiBuffer& midiMessages)
  106. {
  107. juce::ignoreUnused (midiMessages);
  108. juce::ScopedNoDenormals noDenormals;
  109. auto totalNumInputChannels = getTotalNumInputChannels();
  110. auto totalNumOutputChannels = getTotalNumOutputChannels();
  111. // In case we have more outputs than inputs, this code clears any output
  112. // channels that didn't contain input data, (because these aren't
  113. // guaranteed to be empty - they may contain garbage).
  114. // This is here to avoid people getting screaming feedback
  115. // when they first compile a plugin, but obviously you don't need to keep
  116. // this code if your algorithm always overwrites all the output channels.
  117. for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  118. buffer.clear (i, 0, buffer.getNumSamples());
  119. // This is the place where you'd normally do the guts of your plugin's
  120. // audio processing...
  121. // Make sure to reset the state if your inner loop is processing
  122. // the samples and the outer loop is handling the channels.
  123. // Alternatively, you can process the samples with the channels
  124. // interleaved by keeping the same state.
  125. for (int channel = 0; channel < totalNumInputChannels; ++channel)
  126. {
  127. auto* channelData = buffer.getWritePointer (channel);
  128. juce::ignoreUnused (channelData);
  129. // ..do something to the data...
  130. }
  131. }
  132. //==============================================================================
  133. bool AudioPluginAudioProcessor::hasEditor() const
  134. {
  135. return true; // (change this to false if you choose to not supply an editor)
  136. }
  137. juce::AudioProcessorEditor* AudioPluginAudioProcessor::createEditor()
  138. {
  139. return new AudioPluginAudioProcessorEditor (*this);
  140. }
  141. //==============================================================================
  142. void AudioPluginAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
  143. {
  144. // You should use this method to store your parameters in the memory block.
  145. // You could do that either as raw data, or use the XML or ValueTree classes
  146. // as intermediaries to make it easy to save and load complex data.
  147. juce::ignoreUnused (destData);
  148. }
  149. void AudioPluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  150. {
  151. // You should use this method to restore your parameters from this memory block,
  152. // whose contents will have been created by the getStateInformation() call.
  153. juce::ignoreUnused (data, sizeInBytes);
  154. }
  155. //==============================================================================
  156. // This creates new instances of the plugin..
  157. juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  158. {
  159. return new AudioPluginAudioProcessor();
  160. }