Advertisement
Guest User

plugin processor.cpp

a guest
May 22nd, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.38 KB | None | 0 0
  1. /*
  2. ==============================================================================
  3.  
  4. This file was auto-generated!
  5.  
  6. It contains the basic framework code for a JUCE plugin processor.
  7.  
  8. ==============================================================================
  9. */
  10.  
  11. #include "PluginProcessor.h"
  12. #include "PluginEditor.h"
  13.  
  14. //==============================================================================
  15. NewProjectAudioProcessor::NewProjectAudioProcessor()
  16. #ifndef JucePlugin_PreferredChannelConfigurations
  17. : AudioProcessor (BusesProperties()
  18. #if ! JucePlugin_IsMidiEffect
  19. #if ! JucePlugin_IsSynth
  20. .withInput ("Input", AudioChannelSet::stereo(), true)
  21. #endif
  22. .withOutput ("Output", AudioChannelSet::stereo(), true)
  23. #endif
  24. )
  25. #endif
  26. {
  27. }
  28.  
  29. NewProjectAudioProcessor::~NewProjectAudioProcessor()
  30. {
  31. }
  32.  
  33. //==============================================================================
  34. const String NewProjectAudioProcessor::getName() const
  35. {
  36. return JucePlugin_Name;
  37. }
  38.  
  39. bool NewProjectAudioProcessor::acceptsMidi() const
  40. {
  41. #if JucePlugin_WantsMidiInput
  42. return true;
  43. #else
  44. return false;
  45. #endif
  46. }
  47.  
  48. bool NewProjectAudioProcessor::producesMidi() const
  49. {
  50. #if JucePlugin_ProducesMidiOutput
  51. return true;
  52. #else
  53. return false;
  54. #endif
  55. }
  56.  
  57. bool NewProjectAudioProcessor::isMidiEffect() const
  58. {
  59. #if JucePlugin_IsMidiEffect
  60. return true;
  61. #else
  62. return false;
  63. #endif
  64. }
  65.  
  66. double NewProjectAudioProcessor::getTailLengthSeconds() const
  67. {
  68. return 0.0;
  69. }
  70.  
  71. int NewProjectAudioProcessor::getNumPrograms()
  72. {
  73. return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
  74. // so this should be at least 1, even if you're not really implementing programs.
  75. }
  76.  
  77. int NewProjectAudioProcessor::getCurrentProgram()
  78. {
  79. return 0;
  80. }
  81.  
  82. void NewProjectAudioProcessor::setCurrentProgram (int index)
  83. {
  84. }
  85.  
  86. const String NewProjectAudioProcessor::getProgramName (int index)
  87. {
  88. return {};
  89. }
  90.  
  91. void NewProjectAudioProcessor::changeProgramName (int index, const String& newName)
  92. {
  93. }
  94.  
  95. //==============================================================================
  96. void NewProjectAudioProcessor::prepareToPlay (double sampleRate, int samplesPerBlock)
  97. {
  98. const int numInputChannels = getTotalNumInputChannels();
  99. const int delayBufferSize = 2 * (sampleRate + samplesPerBlock);
  100. mSampleRate = sampleRate;
  101.  
  102. mDelayBuffer.setSize(numInputChannels,delayBufferSize);
  103. }
  104.  
  105. void NewProjectAudioProcessor::releaseResources()
  106. {
  107. // When playback stops, you can use this as an opportunity to free up any
  108. // spare memory, etc.
  109. }
  110.  
  111. #ifndef JucePlugin_PreferredChannelConfigurations
  112. bool NewProjectAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  113. {
  114. #if JucePlugin_IsMidiEffect
  115. ignoreUnused (layouts);
  116. return true;
  117. #else
  118. // This is the place where you check if the layout is supported.
  119. // In this template code we only support mono or stereo.
  120. if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
  121. && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
  122. return false;
  123.  
  124. // This checks if the input layout matches the output layout
  125. #if ! JucePlugin_IsSynth
  126. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  127. return false;
  128. #endif
  129.  
  130. return true;
  131. #endif
  132. }
  133. #endif
  134.  
  135. void NewProjectAudioProcessor::processBlock (AudioBuffer<float>& buffer, MidiBuffer& midiMessages)
  136. {
  137. ScopedNoDenormals noDenormals;
  138. auto totalNumInputChannels = getTotalNumInputChannels();
  139. auto totalNumOutputChannels = getTotalNumOutputChannels();
  140.  
  141. for (auto i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  142. buffer.clear (i, 0, buffer.getNumSamples());
  143.  
  144. const int bufferLength = buffer.getNumSamples();
  145. const int delayBufferLength = mDelayBuffer.getNumSamples();
  146.  
  147. for (int channel = 0; channel < totalNumInputChannels; ++channel)
  148. {
  149. const float* bufferData = buffer.getReadPointer(channel);
  150. const float* delayBufferData = mDelayBuffer.getReadPointer(channel);
  151.  
  152. fillDelayBuffer(channel, bufferLength, delayBufferLength, bufferData, delayBufferData);
  153. getFromDelayBuffer(buffer, channel, bufferLength, delayBufferLength, bufferData, delayBufferData);
  154. }
  155. mWritePosition += bufferLength;
  156. mWritePosition %= delayBufferLength;
  157. }
  158.  
  159. void NewProjectAudioProcessor::fillDelayBuffer (int channel, const int bufferLength, const int delayBufferLength, const float* bufferData, const float* delayBufferData)
  160. {
  161. // copy data from the name buffer to the delay buffer.
  162. if (delayBufferLength > bufferLength + mWritePosition)
  163. {
  164. mDelayBuffer.copyFromWithRamp(channel, mWritePosition, bufferData, bufferLength, 0.8, 0.8);
  165. }
  166. else {
  167. const int bufferRemaining = delayBufferLength - mWritePosition;
  168.  
  169. mDelayBuffer.copyFromWithRamp(channel, mWritePosition, bufferData, bufferRemaining, 0.8, 0.8);
  170. mDelayBuffer.copyFromWithRamp(channel, 0, bufferData, bufferLength - bufferRemaining, 0.8, 0.8);
  171. }
  172. }
  173.  
  174. void NewProjectAudioProcessor::getFromDelayBuffer (AudioBuffer<float>& buffer, int channel, const int bufferLength, const int delayBufferLength, const float* bufferData, const float* delayBufferData)
  175. {
  176. int delayTime = 500;
  177. const int readPosition = static_cast<int> (delayBufferLength + mWritePosition - (mSampleRate * delayTime /1000)) % delayBufferLength;
  178.  
  179.  
  180. if (delayBufferLength > bufferLength + readPosition)
  181. {
  182. buffer.addFrom(channel, 0, delayBufferData + readPosition, bufferLength);
  183. }
  184. else {
  185. const int bufferRemaining = delayBufferLength - readPosition;
  186. buffer.addFrom(channel, 0, delayBufferData + readPosition, bufferRemaining);
  187. buffer.addFrom(channel, bufferRemaining, delayBufferData, bufferLength - bufferRemaining);
  188. }
  189.  
  190. }
  191.  
  192. //==============================================================================
  193. bool NewProjectAudioProcessor::hasEditor() const
  194. {
  195. return true; // (change this to false if you choose to not supply an editor)
  196. }
  197.  
  198. AudioProcessorEditor* NewProjectAudioProcessor::createEditor()
  199. {
  200. return new NewProjectAudioProcessorEditor (*this);
  201. }
  202.  
  203. //==============================================================================
  204. void NewProjectAudioProcessor::getStateInformation (MemoryBlock& destData)
  205. {
  206. // You should use this method to store your parameters in the memory block.
  207. // You could do that either as raw data, or use the XML or ValueTree classes
  208. // as intermediaries to make it easy to save and load complex data.
  209. }
  210.  
  211. void NewProjectAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  212. {
  213. // You should use this method to restore your parameters from this memory block,
  214. // whose contents will have been created by the getStateInformation() call.
  215. }
  216.  
  217. //==============================================================================
  218. // This creates new instances of the plugin..
  219. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  220. {
  221. return new NewProjectAudioProcessor();
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement