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.

571 lines
19KB

  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. #include <set>
  10. #ifdef WIN32
  11. #undef min
  12. #undef max
  13. #endif
  14. std::set<PaulstretchpluginAudioProcessor*> g_activeprocessors;
  15. template<typename F>
  16. void callGUI(AudioProcessor* ap, F&& f, bool async)
  17. {
  18. auto ed = dynamic_cast<PaulstretchpluginAudioProcessorEditor*>(ap->getActiveEditor());
  19. if (ed)
  20. {
  21. if (async == false)
  22. f(ed);
  23. else
  24. MessageManager::callAsync([ed,f]() { f(ed); });
  25. }
  26. }
  27. int get_optimized_updown(int n, bool up) {
  28. int orig_n = n;
  29. while (true) {
  30. n = orig_n;
  31. while (!(n % 11)) n /= 11;
  32. while (!(n % 7)) n /= 7;
  33. while (!(n % 5)) n /= 5;
  34. while (!(n % 3)) n /= 3;
  35. while (!(n % 2)) n /= 2;
  36. if (n<2) break;
  37. if (up) orig_n++;
  38. else orig_n--;
  39. if (orig_n<4) return 4;
  40. };
  41. return orig_n;
  42. };
  43. int optimizebufsize(int n) {
  44. int n1 = get_optimized_updown(n, false);
  45. int n2 = get_optimized_updown(n, true);
  46. if ((n - n1)<(n2 - n)) return n1;
  47. else return n2;
  48. };
  49. //==============================================================================
  50. PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
  51. : m_bufferingthread("pspluginprebufferthread")
  52. #ifndef JucePlugin_PreferredChannelConfigurations
  53. : AudioProcessor (BusesProperties()
  54. #if ! JucePlugin_IsMidiEffect
  55. #if ! JucePlugin_IsSynth
  56. .withInput ("Input", AudioChannelSet::stereo(), true)
  57. #endif
  58. .withOutput ("Output", AudioChannelSet::stereo(), true)
  59. #endif
  60. )
  61. #endif
  62. {
  63. g_activeprocessors.insert(this);
  64. m_recbuffer.setSize(2, 44100);
  65. m_recbuffer.clear();
  66. if (m_afm->getNumKnownFormats()==0)
  67. m_afm->registerBasicFormats();
  68. m_stretch_source = std::make_unique<StretchAudioSource>(2, m_afm);
  69. setPreBufferAmount(2);
  70. m_ppar.pitch_shift.enabled = true;
  71. m_ppar.freq_shift.enabled = true;
  72. m_ppar.filter.enabled = true;
  73. m_ppar.compressor.enabled = true;
  74. m_stretch_source->setOnsetDetection(0.0);
  75. m_stretch_source->setLoopingEnabled(true);
  76. m_stretch_source->setFFTWindowingType(1);
  77. addParameter(new AudioParameterFloat("mainvolume0", "Main volume", -24.0f, 12.0f, -3.0f)); // 0
  78. addParameter(new AudioParameterFloat("stretchamount0", "Stretch amount",
  79. NormalisableRange<float>(0.1f, 128.0f, 0.01f, 0.5),1.0f)); // 1
  80. addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.7f)); // 2
  81. addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f)); // 3
  82. addParameter(new AudioParameterFloat("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f)); // 4
  83. addParameter(new AudioParameterFloat("playrange_start0", "Sound start", 0.0f, 1.0f, 0.0f)); // 5
  84. addParameter(new AudioParameterFloat("playrange_end0", "Sound end", 0.0f, 1.0f, 1.0f)); // 6
  85. addParameter(new AudioParameterBool("freeze0", "Freeze", false)); // 7
  86. addParameter(new AudioParameterFloat("spread0", "Frequency spread", 0.0f, 1.0f, 0.0f)); // 8
  87. addParameter(new AudioParameterFloat("compress0", "Compress", 0.0f, 1.0f, 0.0f)); // 9
  88. addParameter(new AudioParameterFloat("loopxfadelen0", "Loop xfade length", 0.0f, 1.0f, 0.0f)); // 10
  89. addParameter(new AudioParameterFloat("numharmonics0", "Num harmonics", 0.0f, 100.0f, 0.0f)); // 11
  90. addParameter(new AudioParameterFloat("harmonicsfreq0", "Harmonics base freq",
  91. NormalisableRange<float>(1.0f, 5000.0f, 1.00f, 0.5), 128.0f)); // 12
  92. addParameter(new AudioParameterFloat("harmonicsbw0", "Harmonics bandwidth", 0.1f, 200.0f, 25.0f)); // 13
  93. addParameter(new AudioParameterBool("harmonicsgauss0", "Gaussian harmonics", false)); // 14
  94. addParameter(new AudioParameterFloat("octavemixm2_0", "2 octaves down level", 0.0f, 1.0f, 0.0f)); // 15
  95. addParameter(new AudioParameterFloat("octavemixm1_0", "Octave down level", 0.0f, 1.0f, 0.0f)); // 16
  96. addParameter(new AudioParameterFloat("octavemix0_0", "Normal pitch level", 0.0f, 1.0f, 1.0f)); // 17
  97. addParameter(new AudioParameterFloat("octavemix1_0", "1 octave up level", 0.0f, 1.0f, 0.0f)); // 18
  98. addParameter(new AudioParameterFloat("octavemix15_0", "1 octave and fifth up level", 0.0f, 1.0f, 0.0f)); // 19
  99. addParameter(new AudioParameterFloat("octavemix2_0", "2 octaves up level", 0.0f, 1.0f, 0.0f)); // 20
  100. addParameter(new AudioParameterFloat("tonalvsnoisebw_0", "Tonal vs Noise BW", 0.74f, 1.0f, 0.74f)); // 21
  101. addParameter(new AudioParameterFloat("tonalvsnoisepreserve_0", "Tonal vs Noise preserve", -1.0f, 1.0f, 0.5f)); // 22
  102. addParameter(new AudioParameterFloat("filter_low_0", "Filter low",
  103. NormalisableRange<float>(20.0f, 10000.0f, 1.0f, 0.3), 20.0f)); // 23
  104. addParameter(new AudioParameterFloat("filter_high_0", "Filter high",
  105. NormalisableRange<float>(100.0f, 20000.0f, 1.0f, 0.3), 20000.0f));; // 24
  106. addParameter(new AudioParameterFloat("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f)); // 25
  107. addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26
  108. m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 2, 8, 2); // 27
  109. addParameter(m_outchansparam); // 27
  110. addParameter(new AudioParameterBool("pause_enabled0", "Pause", false)); // 28
  111. startTimer(1, 50);
  112. }
  113. PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
  114. {
  115. g_activeprocessors.erase(this);
  116. m_bufferingthread.stopThread(1000);
  117. }
  118. void PaulstretchpluginAudioProcessor::setPreBufferAmount(int x)
  119. {
  120. int temp = jlimit(0, 5, x);
  121. if (temp != m_prebuffer_amount)
  122. {
  123. m_prebuffer_amount = temp;
  124. m_recreate_buffering_source = true;
  125. }
  126. }
  127. //==============================================================================
  128. const String PaulstretchpluginAudioProcessor::getName() const
  129. {
  130. return JucePlugin_Name;
  131. }
  132. bool PaulstretchpluginAudioProcessor::acceptsMidi() const
  133. {
  134. #if JucePlugin_WantsMidiInput
  135. return true;
  136. #else
  137. return false;
  138. #endif
  139. }
  140. bool PaulstretchpluginAudioProcessor::producesMidi() const
  141. {
  142. #if JucePlugin_ProducesMidiOutput
  143. return true;
  144. #else
  145. return false;
  146. #endif
  147. }
  148. bool PaulstretchpluginAudioProcessor::isMidiEffect() const
  149. {
  150. #if JucePlugin_IsMidiEffect
  151. return true;
  152. #else
  153. return false;
  154. #endif
  155. }
  156. double PaulstretchpluginAudioProcessor::getTailLengthSeconds() const
  157. {
  158. return (double)m_bufamounts[m_prebuffer_amount]/getSampleRate();
  159. }
  160. int PaulstretchpluginAudioProcessor::getNumPrograms()
  161. {
  162. return 1; // NB: some hosts don't cope very well if you tell them there are 0 programs,
  163. // so this should be at least 1, even if you're not really implementing programs.
  164. }
  165. int PaulstretchpluginAudioProcessor::getCurrentProgram()
  166. {
  167. return 0;
  168. }
  169. void PaulstretchpluginAudioProcessor::setCurrentProgram (int index)
  170. {
  171. }
  172. const String PaulstretchpluginAudioProcessor::getProgramName (int index)
  173. {
  174. return {};
  175. }
  176. void PaulstretchpluginAudioProcessor::changeProgramName (int index, const String& newName)
  177. {
  178. }
  179. void PaulstretchpluginAudioProcessor::setFFTSize(double size)
  180. {
  181. if (m_prebuffer_amount == 5)
  182. m_fft_size_to_use = pow(2, 7.0 + size * 14.5);
  183. else m_fft_size_to_use = pow(2, 7.0 + size * 10.0); // chicken out from allowing huge FFT sizes if not enough prebuffering
  184. int optim = optimizebufsize(m_fft_size_to_use);
  185. m_fft_size_to_use = optim;
  186. m_stretch_source->setFFTSize(optim);
  187. //Logger::writeToLog(String(m_fft_size_to_use));
  188. }
  189. void PaulstretchpluginAudioProcessor::startplay(Range<double> playrange, int numoutchans, int maxBlockSize, String& err)
  190. {
  191. m_stretch_source->setPlayRange(playrange, true);
  192. int bufamt = m_bufamounts[m_prebuffer_amount];
  193. if (m_buffering_source != nullptr && numoutchans != m_buffering_source->getNumberOfChannels())
  194. m_recreate_buffering_source = true;
  195. if (m_recreate_buffering_source == true)
  196. {
  197. m_buffering_source = std::make_unique<MyBufferingAudioSource>(m_stretch_source.get(),
  198. m_bufferingthread, false, bufamt, numoutchans, false);
  199. m_recreate_buffering_source = false;
  200. }
  201. if (m_bufferingthread.isThreadRunning() == false)
  202. m_bufferingthread.startThread();
  203. m_stretch_source->setNumOutChannels(numoutchans);
  204. m_stretch_source->setFFTSize(m_fft_size_to_use);
  205. m_stretch_source->setProcessParameters(&m_ppar);
  206. m_last_outpos_pos = 0.0;
  207. m_last_in_pos = playrange.getStart()*m_stretch_source->getInfileLengthSeconds();
  208. m_buffering_source->prepareToPlay(maxBlockSize, getSampleRate());
  209. };
  210. void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
  211. {
  212. ScopedLock locker(m_cs);
  213. m_curmaxblocksize = samplesPerBlock;
  214. int numoutchans = *m_outchansparam;
  215. if (numoutchans != m_cur_num_out_chans)
  216. m_ready_to_play = false;
  217. if (m_using_memory_buffer == true)
  218. {
  219. int len = jlimit(100,m_recbuffer.getNumSamples(), m_rec_pos);
  220. m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer,
  221. getSampleRate(),
  222. len);
  223. callGUI(this,[this,len](auto ed) { ed->setAudioBuffer(&m_recbuffer, getSampleRate(), len); },false);
  224. }
  225. if (m_ready_to_play == false)
  226. {
  227. setFFTSize(*getFloatParameter(cpi_fftsize));
  228. m_stretch_source->setProcessParameters(&m_ppar);
  229. m_stretch_source->setFFTWindowingType(1);
  230. String err;
  231. startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
  232. numoutchans, samplesPerBlock, err);
  233. m_cur_num_out_chans = numoutchans;
  234. m_ready_to_play = true;
  235. }
  236. }
  237. void PaulstretchpluginAudioProcessor::releaseResources()
  238. {
  239. //m_control->stopplay();
  240. //m_ready_to_play = false;
  241. }
  242. #ifndef JucePlugin_PreferredChannelConfigurations
  243. bool PaulstretchpluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
  244. {
  245. #if JucePlugin_IsMidiEffect
  246. ignoreUnused (layouts);
  247. return true;
  248. #else
  249. // This is the place where you check if the layout is supported.
  250. // In this template code we only support mono or stereo.
  251. if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
  252. && layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
  253. return false;
  254. // This checks if the input layout matches the output layout
  255. #if ! JucePlugin_IsSynth
  256. if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
  257. return false;
  258. #endif
  259. return true;
  260. #endif
  261. }
  262. #endif
  263. void copyAudioBufferWrappingPosition(const AudioBuffer<float>& src, AudioBuffer<float>& dest, int destbufpos, int maxdestpos)
  264. {
  265. for (int i = 0; i < dest.getNumChannels(); ++i)
  266. {
  267. int channel_to_copy = i % src.getNumChannels();
  268. if (destbufpos + src.getNumSamples() > maxdestpos)
  269. {
  270. int wrappos = (destbufpos + src.getNumSamples()) % maxdestpos;
  271. int partial_len = src.getNumSamples() - wrappos;
  272. dest.copyFrom(channel_to_copy, destbufpos, src, channel_to_copy, 0, partial_len);
  273. dest.copyFrom(channel_to_copy, partial_len, src, channel_to_copy, 0, wrappos);
  274. }
  275. else
  276. {
  277. dest.copyFrom(channel_to_copy, destbufpos, src, channel_to_copy, 0, src.getNumSamples());
  278. }
  279. }
  280. }
  281. void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  282. {
  283. ScopedLock locker(m_cs);
  284. ScopedNoDenormals noDenormals;
  285. const int totalNumInputChannels = getTotalNumInputChannels();
  286. const int totalNumOutputChannels = getTotalNumOutputChannels();
  287. for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
  288. buffer.clear (i, 0, buffer.getNumSamples());
  289. if (m_ready_to_play == false)
  290. return;
  291. if (m_is_recording == true)
  292. {
  293. int recbuflenframes = m_max_reclen * getSampleRate();
  294. copyAudioBufferWrappingPosition(buffer, m_recbuffer, m_rec_pos, recbuflenframes);
  295. callGUI(this,[this, &buffer](PaulstretchpluginAudioProcessorEditor*ed)
  296. {
  297. ed->addAudioBlock(buffer, getSampleRate(), m_rec_pos);
  298. }, false);
  299. m_rec_pos = (m_rec_pos + buffer.getNumSamples()) % recbuflenframes;
  300. return;
  301. }
  302. jassert(m_buffering_source != nullptr);
  303. jassert(m_bufferingthread.isThreadRunning());
  304. m_stretch_source->setMainVolume(*getFloatParameter(cpi_main_volume));
  305. m_stretch_source->setRate(*getFloatParameter(cpi_stretchamount));
  306. setFFTSize(*getFloatParameter(cpi_fftsize));
  307. m_ppar.pitch_shift.cents = *getFloatParameter(cpi_pitchshift) * 100.0;
  308. m_ppar.freq_shift.Hz = *getFloatParameter(cpi_frequencyshift);
  309. m_ppar.spread.enabled = *getFloatParameter(cpi_spreadamount) > 0.0f;
  310. m_ppar.spread.bandwidth = *getFloatParameter(cpi_spreadamount);
  311. m_ppar.compressor.enabled = *getFloatParameter(cpi_compress)>0.0f;
  312. m_ppar.compressor.power = *getFloatParameter(cpi_compress);
  313. m_ppar.harmonics.enabled = *getFloatParameter(cpi_numharmonics)>=1.0;
  314. m_ppar.harmonics.nharmonics = *getFloatParameter(cpi_numharmonics);
  315. m_ppar.harmonics.freq = *getFloatParameter(cpi_harmonicsfreq);
  316. m_ppar.harmonics.bandwidth = *getFloatParameter(cpi_harmonicsbw);
  317. m_ppar.harmonics.gauss = getParameter(cpi_harmonicsgauss);
  318. m_ppar.octave.om2 = *getFloatParameter(cpi_octavesm2);
  319. m_ppar.octave.om1 = *getFloatParameter(cpi_octavesm1);
  320. m_ppar.octave.o0 = *getFloatParameter(cpi_octaves0);
  321. m_ppar.octave.o1 = *getFloatParameter(cpi_octaves1);
  322. m_ppar.octave.o15 = *getFloatParameter(cpi_octaves15);
  323. m_ppar.octave.o2 = *getFloatParameter(cpi_octaves2);
  324. m_ppar.octave.enabled = true;
  325. m_ppar.filter.low = *getFloatParameter(cpi_filter_low);
  326. m_ppar.filter.high = *getFloatParameter(cpi_filter_high);
  327. m_ppar.tonal_vs_noise.enabled = (*getFloatParameter(cpi_tonalvsnoisebw)) > 0.75;
  328. m_ppar.tonal_vs_noise.bandwidth = *getFloatParameter(cpi_tonalvsnoisebw);
  329. m_ppar.tonal_vs_noise.preserve = *getFloatParameter(cpi_tonalvsnoisepreserve);
  330. m_stretch_source->setOnsetDetection(*getFloatParameter(cpi_onsetdetection));
  331. m_stretch_source->setLoopXFadeLength(*getFloatParameter(cpi_loopxfadelen));
  332. double t0 = *getFloatParameter(cpi_soundstart);
  333. double t1 = *getFloatParameter(cpi_soundend);
  334. if (t0 > t1)
  335. std::swap(t0, t1);
  336. if (t1 - t0 < 0.001)
  337. t1 = t0 + 0.001;
  338. m_stretch_source->setPlayRange({ t0,t1 }, true);
  339. m_stretch_source->setFreezing(getParameter(cpi_freeze));
  340. m_stretch_source->setPaused(getParameter(cpi_pause_enabled));
  341. m_stretch_source->setProcessParameters(&m_ppar);
  342. AudioSourceChannelInfo aif(buffer);
  343. m_buffering_source->getNextAudioBlock(aif);
  344. }
  345. //==============================================================================
  346. bool PaulstretchpluginAudioProcessor::hasEditor() const
  347. {
  348. return true; // (change this to false if you choose to not supply an editor)
  349. }
  350. AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor()
  351. {
  352. return new PaulstretchpluginAudioProcessorEditor (*this);
  353. }
  354. //==============================================================================
  355. void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData)
  356. {
  357. ValueTree paramtree("paulstretch3pluginstate");
  358. for (int i=0;i<getNumParameters();++i)
  359. {
  360. auto par = getFloatParameter(i);
  361. if (par != nullptr)
  362. {
  363. paramtree.setProperty(par->paramID, (double)*par, nullptr);
  364. }
  365. }
  366. paramtree.setProperty(m_outchansparam->paramID, (int)*m_outchansparam, nullptr);
  367. if (m_current_file != File())
  368. {
  369. paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr);
  370. }
  371. MemoryOutputStream stream(destData,true);
  372. paramtree.writeToStream(stream);
  373. }
  374. void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
  375. {
  376. ValueTree tree = ValueTree::readFromData(data, sizeInBytes);
  377. if (tree.isValid())
  378. {
  379. {
  380. ScopedLock locker(m_cs);
  381. for (int i = 0; i < getNumParameters(); ++i)
  382. {
  383. auto par = getFloatParameter(i);
  384. if (par != nullptr)
  385. {
  386. double parval = tree.getProperty(par->paramID, (double)*par);
  387. *par = parval;
  388. }
  389. }
  390. if (tree.hasProperty(m_outchansparam->paramID))
  391. *m_outchansparam = tree.getProperty(m_outchansparam->paramID, 2);
  392. }
  393. String fn = tree.getProperty("importedfile");
  394. if (fn.isEmpty() == false)
  395. {
  396. File f(fn);
  397. setAudioFile(f);
  398. }
  399. }
  400. }
  401. void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b)
  402. {
  403. ScopedLock locker(m_cs);
  404. int lenbufframes = getSampleRate()*m_max_reclen;
  405. if (b == true)
  406. {
  407. m_using_memory_buffer = true;
  408. m_current_file = File();
  409. m_recbuffer.setSize(2, m_max_reclen*getSampleRate()+4096,false,false,true);
  410. m_recbuffer.clear();
  411. m_rec_pos = 0;
  412. callGUI(this,[this,lenbufframes](PaulstretchpluginAudioProcessorEditor* ed)
  413. {
  414. ed->beginAddingAudioBlocks(2, getSampleRate(), lenbufframes);
  415. },false);
  416. m_is_recording = true;
  417. }
  418. else
  419. {
  420. if (m_is_recording == true)
  421. {
  422. finishRecording(lenbufframes);
  423. }
  424. }
  425. }
  426. double PaulstretchpluginAudioProcessor::getRecordingPositionPercent()
  427. {
  428. if (m_is_recording==false)
  429. return 0.0;
  430. return 1.0 / m_recbuffer.getNumSamples()*m_rec_pos;
  431. }
  432. String PaulstretchpluginAudioProcessor::setAudioFile(File f)
  433. {
  434. //if (f==File())
  435. // return String();
  436. //if (f==m_current_file && f.getLastModificationTime()==m_current_file_date)
  437. // return String();
  438. auto ai = unique_from_raw(m_afm->createReaderFor(f));
  439. if (ai != nullptr)
  440. {
  441. if (ai->numChannels > 32)
  442. {
  443. //MessageManager::callAsync([cb, file]() { cb("Too many channels in file " + file.getFullPathName()); });
  444. return "Too many channels in file "+f.getFullPathName();
  445. }
  446. if (ai->bitsPerSample>32)
  447. {
  448. //MessageManager::callAsync([cb, file]() { cb("Too high bit depth in file " + file.getFullPathName()); });
  449. return "Too high bit depth in file " + f.getFullPathName();
  450. }
  451. ScopedLock locker(m_cs);
  452. m_stretch_source->setAudioFile(f);
  453. m_current_file = f;
  454. m_current_file_date = m_current_file.getLastModificationTime();
  455. m_using_memory_buffer = false;
  456. return String();
  457. //MessageManager::callAsync([cb, file]() { cb(String()); });
  458. }
  459. return "Could not open file " + f.getFullPathName();
  460. }
  461. Range<double> PaulstretchpluginAudioProcessor::getTimeSelection()
  462. {
  463. return { *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) };
  464. }
  465. double PaulstretchpluginAudioProcessor::getPreBufferingPercent()
  466. {
  467. if (m_buffering_source==nullptr)
  468. return 0.0;
  469. return m_buffering_source->getPercentReady();
  470. }
  471. void PaulstretchpluginAudioProcessor::timerCallback(int id)
  472. {
  473. if (id == 1)
  474. {
  475. bool capture = getParameter(cpi_capture_enabled);
  476. if (capture == true && m_is_recording == false)
  477. {
  478. setRecordingEnabled(true);
  479. return;
  480. }
  481. if (capture == false && m_is_recording == true)
  482. {
  483. setRecordingEnabled(false);
  484. return;
  485. }
  486. if (m_cur_num_out_chans != *m_outchansparam)
  487. {
  488. jassert(m_curmaxblocksize > 0);
  489. ScopedLock locker(m_cs);
  490. m_ready_to_play = false;
  491. m_cur_num_out_chans = *m_outchansparam;
  492. //Logger::writeToLog("Switching to use " + String(m_cur_num_out_chans) + " out channels");
  493. String err;
  494. startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
  495. m_cur_num_out_chans, m_curmaxblocksize, err);
  496. m_ready_to_play = true;
  497. }
  498. }
  499. }
  500. void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording)
  501. {
  502. m_is_recording = false;
  503. m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRate(), lenrecording);
  504. m_stretch_source->setPlayRange({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, true);
  505. auto ed = dynamic_cast<PaulstretchpluginAudioProcessorEditor*>(getActiveEditor());
  506. if (ed)
  507. {
  508. //ed->setAudioBuffer(&m_recbuffer, getSampleRate(), lenrecording);
  509. }
  510. }
  511. //==============================================================================
  512. // This creates new instances of the plugin..
  513. AudioProcessor* JUCE_CALLTYPE createPluginFilter()
  514. {
  515. return new PaulstretchpluginAudioProcessor();
  516. }