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.

170 lines
4.8KB

  1. #include "IAAEffectProcessor.h"
  2. #include "IAAEffectEditor.h"
  3. IAAEffectProcessor::IAAEffectProcessor()
  4. : AudioProcessor (BusesProperties()
  5. .withInput ("Input", AudioChannelSet::stereo(), true)
  6. .withOutput ("Output", AudioChannelSet::stereo(), true)),
  7. parameters (*this, nullptr)
  8. {
  9. parameters.createAndAddParameter ("gain",
  10. "Gain",
  11. String(),
  12. NormalisableRange<float> (0.0f, 1.0f),
  13. (float) (1.0 / 3.14),
  14. nullptr,
  15. nullptr);
  16. parameters.state = ValueTree (Identifier ("InterAppAudioEffect"));
  17. }
  18. IAAEffectProcessor::~IAAEffectProcessor()
  19. {
  20. }
  21. //==============================================================================
  22. const String IAAEffectProcessor::getName() const
  23. {
  24. return JucePlugin_Name;
  25. }
  26. bool IAAEffectProcessor::acceptsMidi() const
  27. {
  28. return false;
  29. }
  30. bool IAAEffectProcessor::producesMidi() const
  31. {
  32. return false;
  33. }
  34. double IAAEffectProcessor::getTailLengthSeconds() const
  35. {
  36. return 0.0;
  37. }
  38. int IAAEffectProcessor::getNumPrograms()
  39. {
  40. return 1;
  41. }
  42. int IAAEffectProcessor::getCurrentProgram()
  43. {
  44. return 0;
  45. }
  46. void IAAEffectProcessor::setCurrentProgram (int)
  47. {
  48. }
  49. const String IAAEffectProcessor::getProgramName (int)
  50. {
  51. return String();
  52. }
  53. void IAAEffectProcessor::changeProgramName (int, const String&)
  54. {
  55. }
  56. //==============================================================================
  57. void IAAEffectProcessor::prepareToPlay (double, int)
  58. {
  59. previousGain = *parameters.getRawParameterValue ("gain");
  60. }
  61. void IAAEffectProcessor::releaseResources()
  62. {
  63. }
  64. bool IAAEffectProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  65. {
  66. if (layouts.getMainInputChannelSet() != AudioChannelSet::stereo())
  67. return false;
  68. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  69. return false;
  70. return true;
  71. }
  72. void IAAEffectProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer&)
  73. {
  74. const float gain = *parameters.getRawParameterValue ("gain");
  75. const int totalNumInputChannels = getTotalNumInputChannels();
  76. const int totalNumOutputChannels = getTotalNumOutputChannels();
  77. const int numSamples = buffer.getNumSamples();
  78. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  79. buffer.clear (i, 0, buffer.getNumSamples());
  80. // Apply the gain to the samples using a ramp to avoid discontinuities in
  81. // the audio between processed buffers.
  82. for (int channel = 0; channel < totalNumInputChannels; ++channel)
  83. {
  84. buffer.applyGainRamp (channel, 0, numSamples, previousGain, gain);
  85. meterListeners.call (&IAAEffectProcessor::MeterListener::handleNewMeterValue,
  86. channel,
  87. buffer.getMagnitude (channel, 0, numSamples));
  88. }
  89. previousGain = gain;
  90. // Now ask the host for the current time so we can store it to be displayed later.
  91. updateCurrentTimeInfoFromHost (lastPosInfo);
  92. }
  93. //==============================================================================
  94. bool IAAEffectProcessor::hasEditor() const
  95. {
  96. return true;
  97. }
  98. AudioProcessorEditor* IAAEffectProcessor::createEditor()
  99. {
  100. return new IAAEffectEditor (*this, parameters);
  101. }
  102. //==============================================================================
  103. void IAAEffectProcessor::getStateInformation (MemoryBlock& destData)
  104. {
  105. auto xml = std::unique_ptr<XmlElement> (parameters.state.createXml());
  106. copyXmlToBinary (*xml, destData);
  107. }
  108. void IAAEffectProcessor::setStateInformation (const void* data, int sizeInBytes)
  109. {
  110. auto xmlState = std::unique_ptr<XmlElement> (getXmlFromBinary (data, sizeInBytes));
  111. if (xmlState.get() != nullptr)
  112. if (xmlState->hasTagName (parameters.state.getType()))
  113. parameters.state = ValueTree::fromXml (*xmlState);
  114. }
  115. bool IAAEffectProcessor::updateCurrentTimeInfoFromHost (AudioPlayHead::CurrentPositionInfo &posInfo)
  116. {
  117. if (AudioPlayHead* ph = getPlayHead())
  118. {
  119. AudioPlayHead::CurrentPositionInfo newTime;
  120. if (ph->getCurrentPosition (newTime))
  121. {
  122. posInfo = newTime; // Successfully got the current time from the host.
  123. return true;
  124. }
  125. }
  126. // If the host fails to provide the current time, we'll just reset our copy to a default.
  127. lastPosInfo.resetToDefault();
  128. return false;
  129. }
  130. //==============================================================================
  131. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  132. {
  133. return new IAAEffectProcessor();
  134. }