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.

210 lines
6.6KB

  1. /*
  2. ==============================================================================
  3. This file was auto-generated!
  4. It contains the basic framework code for a JUCE plugin processor.
  5. ==============================================================================
  6. */
  7. #include "PluginProcessor.h"
  8. #include "PluginEditor.h"
  9. std::unique_ptr<PropertiesFile> g_propsfile;
  10. //==============================================================================
  11. PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
  12. #ifndef JucePlugin_PreferredChannelConfigurations
  13. : AudioProcessor (BusesProperties()
  14. #if ! JucePlugin_IsMidiEffect
  15. #if ! JucePlugin_IsSynth
  16. .withInput ("Input", AudioChannelSet::stereo(), true)
  17. #endif
  18. .withOutput ("Output", AudioChannelSet::stereo(), true)
  19. #endif
  20. )
  21. #endif
  22. {
  23. m_afm = std::make_unique<AudioFormatManager>();
  24. m_afm->registerBasicFormats();
  25. m_control = std::make_unique<Control>(m_afm.get());
  26. m_control->getStretchAudioSource()->setLoopingEnabled(true);
  27. addParameter(new AudioParameterFloat("mainvolume0", "Main volume", -24.0f, 12.0f, -3.0f));
  28. addParameter(new AudioParameterFloat("stretchamount0", "Stretch amount", 0.1f, 128.0f, 1.0f));
  29. addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f));
  30. }
  31. PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
  32. {
  33. }
  34. //==============================================================================
  35. const String PaulstretchpluginAudioProcessor::getName() const
  36. {
  37. return JucePlugin_Name;
  38. }
  39. bool PaulstretchpluginAudioProcessor::acceptsMidi() const
  40. {
  41. #if JucePlugin_WantsMidiInput
  42. return true;
  43. #else
  44. return false;
  45. #endif
  46. }
  47. bool PaulstretchpluginAudioProcessor::producesMidi() const
  48. {
  49. #if JucePlugin_ProducesMidiOutput
  50. return true;
  51. #else
  52. return false;
  53. #endif
  54. }
  55. bool PaulstretchpluginAudioProcessor::isMidiEffect() const
  56. {
  57. #if JucePlugin_IsMidiEffect
  58. return true;
  59. #else
  60. return false;
  61. #endif
  62. }
  63. double PaulstretchpluginAudioProcessor::getTailLengthSeconds() const
  64. {
  65. return 0.0;
  66. }
  67. int PaulstretchpluginAudioProcessor::getNumPrograms()
  68. {
  69. return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
  70. // so this should be at least 1, even if you're not really implementing programs.
  71. }
  72. int PaulstretchpluginAudioProcessor::getCurrentProgram()
  73. {
  74. return 0;
  75. }
  76. void PaulstretchpluginAudioProcessor::setCurrentProgram (int index)
  77. {
  78. }
  79. const String PaulstretchpluginAudioProcessor::getProgramName (int index)
  80. {
  81. return {};
  82. }
  83. void PaulstretchpluginAudioProcessor::changeProgramName (int index, const String& newName)
  84. {
  85. }
  86. //==============================================================================
  87. void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
  88. {
  89. m_ready_to_play = false;
  90. m_control->set_input_file(File("C:/MusicAudio/sourcesamples/sheila.wav"), [this](String cberr)
  91. {
  92. if (cberr.isEmpty())
  93. {
  94. m_ready_to_play = true;
  95. String err;
  96. m_control->update_player_stretch();
  97. m_control->update_process_parameters();
  98. m_control->startplay(false, true, { 0.0,1.0 }, 2, err);
  99. }
  100. else m_ready_to_play = false;
  101. });
  102. }
  103. void PaulstretchpluginAudioProcessor::releaseResources()
  104. {
  105. m_control->stopplay();
  106. }
  107. #ifndef JucePlugin_PreferredChannelConfigurations
  108. bool PaulstretchpluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  109. {
  110. #if JucePlugin_IsMidiEffect
  111. ignoreUnused (layouts);
  112. return true;
  113. #else
  114. // This is the place where you check if the layout is supported.
  115. // In this template code we only support mono or stereo.
  116. if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
  117. && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
  118. return false;
  119. // This checks if the input layout matches the output layout
  120. #if ! JucePlugin_IsSynth
  121. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  122. return false;
  123. #endif
  124. return true;
  125. #endif
  126. }
  127. #endif
  128. void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  129. {
  130. ScopedNoDenormals noDenormals;
  131. const int totalNumInputChannels = getTotalNumInputChannels();
  132. const int totalNumOutputChannels = getTotalNumOutputChannels();
  133. // In case we have more outputs than inputs, this code clears any output
  134. // channels that didn't contain input data, (because these aren't
  135. // guaranteed to be empty - they may contain garbage).
  136. // This is here to avoid people getting screaming feedback
  137. // when they first compile a plugin, but obviously you don't need to keep
  138. // this code if your algorithm always overwrites all the output channels.
  139. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  140. buffer.clear (i, 0, buffer.getNumSamples());
  141. if (m_ready_to_play == false)
  142. return;
  143. auto& params = getParameters();
  144. AudioParameterFloat* par = (AudioParameterFloat*)params[1];
  145. m_control->getStretchAudioSource()->setRate(*par);
  146. par = (AudioParameterFloat*)params[2];
  147. m_control->ppar.pitch_shift.enabled = true;
  148. m_control->ppar.pitch_shift.cents = *par * 100.0;
  149. m_control->update_process_parameters();
  150. m_control->processAudio(buffer);
  151. }
  152. //==============================================================================
  153. bool PaulstretchpluginAudioProcessor::hasEditor() const
  154. {
  155. return true; // (change this to false if you choose to not supply an editor)
  156. }
  157. AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor()
  158. {
  159. return new GenericAudioProcessorEditor(this);
  160. //return new PaulstretchpluginAudioProcessorEditor (*this);
  161. }
  162. //==============================================================================
  163. void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData)
  164. {
  165. // You should use this method to store your parameters in the memory block.
  166. // You could do that either as raw data, or use the XML or ValueTree classes
  167. // as intermediaries to make it easy to save and load complex data.
  168. }
  169. void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  170. {
  171. // You should use this method to restore your parameters from this memory block,
  172. // whose contents will have been created by the getStateInformation() call.
  173. }
  174. //==============================================================================
  175. // This creates new instances of the plugin..
  176. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  177. {
  178. return new PaulstretchpluginAudioProcessor();
  179. }