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.

189 lines
6.2KB

  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. // Some plugin hosts, such as certain GarageBand versions, will only
  94. // load plugins that support stereo bus layouts.
  95. if (layouts.getMainOutputChannelSet() != juce::AudioChannelSet::mono()
  96. && layouts.getMainOutputChannelSet() != juce::AudioChannelSet::stereo())
  97. return false;
  98. // This checks if the input layout matches the output layout
  99. #if ! JucePlugin_IsSynth
  100. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  101. return false;
  102. #endif
  103. return true;
  104. #endif
  105. }
  106. void AudioPluginAudioProcessor::processBlock (juce::AudioBuffer<float>& buffer,
  107. juce::MidiBuffer& midiMessages)
  108. {
  109. juce::ignoreUnused (midiMessages);
  110. juce::ScopedNoDenormals noDenormals;
  111. auto totalNumInputChannels = getTotalNumInputChannels();
  112. auto totalNumOutputChannels = getTotalNumOutputChannels();
  113. // In case we have more outputs than inputs, this code clears any output
  114. // channels that didn't contain input data, (because these aren't
  115. // guaranteed to be empty - they may contain garbage).
  116. // This is here to avoid people getting screaming feedback
  117. // when they first compile a plugin, but obviously you don't need to keep
  118. // this code if your algorithm always overwrites all the output channels.
  119. for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  120. buffer.clear (i, 0, buffer.getNumSamples());
  121. // This is the place where you'd normally do the guts of your plugin's
  122. // audio processing...
  123. // Make sure to reset the state if your inner loop is processing
  124. // the samples and the outer loop is handling the channels.
  125. // Alternatively, you can process the samples with the channels
  126. // interleaved by keeping the same state.
  127. for (int channel = 0; channel < totalNumInputChannels; ++channel)
  128. {
  129. auto* channelData = buffer.getWritePointer (channel);
  130. juce::ignoreUnused (channelData);
  131. // ..do something to the data...
  132. }
  133. }
  134. //==============================================================================
  135. bool AudioPluginAudioProcessor::hasEditor() const
  136. {
  137. return true; // (change this to false if you choose to not supply an editor)
  138. }
  139. juce::AudioProcessorEditor* AudioPluginAudioProcessor::createEditor()
  140. {
  141. return new AudioPluginAudioProcessorEditor (*this);
  142. }
  143. //==============================================================================
  144. void AudioPluginAudioProcessor::getStateInformation (juce::MemoryBlock& destData)
  145. {
  146. // You should use this method to store your parameters in the memory block.
  147. // You could do that either as raw data, or use the XML or ValueTree classes
  148. // as intermediaries to make it easy to save and load complex data.
  149. juce::ignoreUnused (destData);
  150. }
  151. void AudioPluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  152. {
  153. // You should use this method to restore your parameters from this memory block,
  154. // whose contents will have been created by the getStateInformation() call.
  155. juce::ignoreUnused (data, sizeInBytes);
  156. }
  157. //==============================================================================
  158. // This creates new instances of the plugin..
  159. juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  160. {
  161. return new AudioPluginAudioProcessor();
  162. }