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.

196 lines
5.7KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "IAAEffectProcessor.h"
  20. #include "IAAEffectEditor.h"
  21. IAAEffectProcessor::IAAEffectProcessor()
  22. : AudioProcessor (BusesProperties()
  23. .withInput ("Input", AudioChannelSet::stereo(), true)
  24. .withOutput ("Output", AudioChannelSet::stereo(), true)),
  25. parameters (*this, nullptr)
  26. {
  27. parameters.createAndAddParameter ("gain",
  28. "Gain",
  29. String(),
  30. NormalisableRange<float> (0.0f, 1.0f),
  31. (float) (1.0 / 3.14),
  32. nullptr,
  33. nullptr);
  34. parameters.state = ValueTree (Identifier ("InterAppAudioEffect"));
  35. }
  36. IAAEffectProcessor::~IAAEffectProcessor()
  37. {
  38. }
  39. //==============================================================================
  40. const String IAAEffectProcessor::getName() const
  41. {
  42. return JucePlugin_Name;
  43. }
  44. bool IAAEffectProcessor::acceptsMidi() const
  45. {
  46. return false;
  47. }
  48. bool IAAEffectProcessor::producesMidi() const
  49. {
  50. return false;
  51. }
  52. double IAAEffectProcessor::getTailLengthSeconds() const
  53. {
  54. return 0.0;
  55. }
  56. int IAAEffectProcessor::getNumPrograms()
  57. {
  58. return 1;
  59. }
  60. int IAAEffectProcessor::getCurrentProgram()
  61. {
  62. return 0;
  63. }
  64. void IAAEffectProcessor::setCurrentProgram (int)
  65. {
  66. }
  67. const String IAAEffectProcessor::getProgramName (int)
  68. {
  69. return String();
  70. }
  71. void IAAEffectProcessor::changeProgramName (int, const String&)
  72. {
  73. }
  74. //==============================================================================
  75. void IAAEffectProcessor::prepareToPlay (double, int)
  76. {
  77. previousGain = *parameters.getRawParameterValue ("gain");
  78. }
  79. void IAAEffectProcessor::releaseResources()
  80. {
  81. }
  82. bool IAAEffectProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  83. {
  84. if (layouts.getMainInputChannelSet() != AudioChannelSet::stereo())
  85. return false;
  86. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  87. return false;
  88. return true;
  89. }
  90. void IAAEffectProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer&)
  91. {
  92. const float gain = *parameters.getRawParameterValue ("gain");
  93. const int totalNumInputChannels = getTotalNumInputChannels();
  94. const int totalNumOutputChannels = getTotalNumOutputChannels();
  95. const int numSamples = buffer.getNumSamples();
  96. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  97. buffer.clear (i, 0, buffer.getNumSamples());
  98. // Apply the gain to the samples using a ramp to avoid discontinuities in
  99. // the audio between processed buffers.
  100. for (int channel = 0; channel < totalNumInputChannels; ++channel)
  101. {
  102. buffer.applyGainRamp (channel, 0, numSamples, previousGain, gain);
  103. meterListeners.call (&IAAEffectProcessor::MeterListener::handleNewMeterValue,
  104. channel,
  105. buffer.getMagnitude (channel, 0, numSamples));
  106. }
  107. previousGain = gain;
  108. // Now ask the host for the current time so we can store it to be displayed later.
  109. updateCurrentTimeInfoFromHost (lastPosInfo);
  110. }
  111. //==============================================================================
  112. bool IAAEffectProcessor::hasEditor() const
  113. {
  114. return true;
  115. }
  116. AudioProcessorEditor* IAAEffectProcessor::createEditor()
  117. {
  118. return new IAAEffectEditor (*this, parameters);
  119. }
  120. //==============================================================================
  121. void IAAEffectProcessor::getStateInformation (MemoryBlock& destData)
  122. {
  123. auto xml = std::unique_ptr<XmlElement> (parameters.state.createXml());
  124. copyXmlToBinary (*xml, destData);
  125. }
  126. void IAAEffectProcessor::setStateInformation (const void* data, int sizeInBytes)
  127. {
  128. auto xmlState = std::unique_ptr<XmlElement> (getXmlFromBinary (data, sizeInBytes));
  129. if (xmlState.get() != nullptr)
  130. if (xmlState->hasTagName (parameters.state.getType()))
  131. parameters.state = ValueTree::fromXml (*xmlState);
  132. }
  133. bool IAAEffectProcessor::updateCurrentTimeInfoFromHost (AudioPlayHead::CurrentPositionInfo &posInfo)
  134. {
  135. if (AudioPlayHead* ph = getPlayHead())
  136. {
  137. AudioPlayHead::CurrentPositionInfo newTime;
  138. if (ph->getCurrentPosition (newTime))
  139. {
  140. posInfo = newTime; // Successfully got the current time from the host.
  141. return true;
  142. }
  143. }
  144. // If the host fails to provide the current time, we'll just reset our copy to a default.
  145. lastPosInfo.resetToDefault();
  146. return false;
  147. }
  148. //==============================================================================
  149. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  150. {
  151. return new IAAEffectProcessor();
  152. }