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.

205 lines
6.4KB

  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->ppar.pitch_shift.enabled = true;
  27. m_control->ppar.freq_shift.enabled = true;
  28. m_control->getStretchAudioSource()->setLoopingEnabled(true);
  29. addParameter(new AudioParameterFloat("mainvolume0", "Main volume", -24.0f, 12.0f, -3.0f));
  30. addParameter(new AudioParameterFloat("stretchamount0", "Stretch amount", 0.1f, 128.0f, 1.0f));
  31. addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.6f));
  32. addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f));
  33. addParameter(new AudioParameterFloat("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f));
  34. }
  35. PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
  36. {
  37. m_control->stopplay();
  38. }
  39. //==============================================================================
  40. const String PaulstretchpluginAudioProcessor::getName() const
  41. {
  42. return JucePlugin_Name;
  43. }
  44. bool PaulstretchpluginAudioProcessor::acceptsMidi() const
  45. {
  46. #if JucePlugin_WantsMidiInput
  47. return true;
  48. #else
  49. return false;
  50. #endif
  51. }
  52. bool PaulstretchpluginAudioProcessor::producesMidi() const
  53. {
  54. #if JucePlugin_ProducesMidiOutput
  55. return true;
  56. #else
  57. return false;
  58. #endif
  59. }
  60. bool PaulstretchpluginAudioProcessor::isMidiEffect() const
  61. {
  62. #if JucePlugin_IsMidiEffect
  63. return true;
  64. #else
  65. return false;
  66. #endif
  67. }
  68. double PaulstretchpluginAudioProcessor::getTailLengthSeconds() const
  69. {
  70. return 0.0;
  71. }
  72. int PaulstretchpluginAudioProcessor::getNumPrograms()
  73. {
  74. return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
  75. // so this should be at least 1, even if you're not really implementing programs.
  76. }
  77. int PaulstretchpluginAudioProcessor::getCurrentProgram()
  78. {
  79. return 0;
  80. }
  81. void PaulstretchpluginAudioProcessor::setCurrentProgram (int index)
  82. {
  83. }
  84. const String PaulstretchpluginAudioProcessor::getProgramName (int index)
  85. {
  86. return {};
  87. }
  88. void PaulstretchpluginAudioProcessor::changeProgramName (int index, const String& newName)
  89. {
  90. }
  91. //==============================================================================
  92. void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
  93. {
  94. m_ready_to_play = false;
  95. m_control->set_input_file(File("C:/MusicAudio/sourcesamples/sheila.wav"), [this](String cberr)
  96. {
  97. if (cberr.isEmpty())
  98. {
  99. m_ready_to_play = true;
  100. String err;
  101. m_control->update_player_stretch();
  102. m_control->update_process_parameters();
  103. m_control->startplay(false, true, { 0.0,1.0 }, 2, err);
  104. }
  105. else m_ready_to_play = false;
  106. });
  107. }
  108. void PaulstretchpluginAudioProcessor::releaseResources()
  109. {
  110. m_control->stopplay();
  111. }
  112. #ifndef JucePlugin_PreferredChannelConfigurations
  113. bool PaulstretchpluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  114. {
  115. #if JucePlugin_IsMidiEffect
  116. ignoreUnused (layouts);
  117. return true;
  118. #else
  119. // This is the place where you check if the layout is supported.
  120. // In this template code we only support mono or stereo.
  121. if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
  122. && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
  123. return false;
  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. return true;
  130. #endif
  131. }
  132. #endif
  133. void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  134. {
  135. ScopedNoDenormals noDenormals;
  136. const int totalNumInputChannels = getTotalNumInputChannels();
  137. const int totalNumOutputChannels = getTotalNumOutputChannels();
  138. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  139. buffer.clear (i, 0, buffer.getNumSamples());
  140. if (m_ready_to_play == false)
  141. return;
  142. m_control->getStretchAudioSource()->setRate(*getFloatParameter(1));
  143. //m_control->setFFTSize(*getFloatParameter(2));
  144. m_control->ppar.pitch_shift.cents = *getFloatParameter(3) * 100.0;
  145. m_control->ppar.freq_shift.Hz = *getFloatParameter(4);
  146. m_control->update_process_parameters();
  147. m_control->processAudio(buffer);
  148. }
  149. //==============================================================================
  150. bool PaulstretchpluginAudioProcessor::hasEditor() const
  151. {
  152. return true; // (change this to false if you choose to not supply an editor)
  153. }
  154. AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor()
  155. {
  156. return new PaulstretchpluginAudioProcessorEditor (*this);
  157. }
  158. //==============================================================================
  159. void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData)
  160. {
  161. // You should use this method to store your parameters in the memory block.
  162. // You could do that either as raw data, or use the XML or ValueTree classes
  163. // as intermediaries to make it easy to save and load complex data.
  164. }
  165. void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  166. {
  167. // You should use this method to restore your parameters from this memory block,
  168. // whose contents will have been created by the getStateInformation() call.
  169. }
  170. //==============================================================================
  171. // This creates new instances of the plugin..
  172. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  173. {
  174. return new PaulstretchpluginAudioProcessor();
  175. }