2017-11-13 15:06:08 +00:00
|
|
|
/*
|
|
|
|
|
2017-12-17 19:40:35 +00:00
|
|
|
Copyright (C) 2017 Xenakios
|
2017-11-13 15:06:08 +00:00
|
|
|
|
2017-12-17 19:40:35 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
2018-06-04 19:04:53 +00:00
|
|
|
it under the terms of version 3 of the GNU General Public License
|
2017-12-17 19:40:35 +00:00
|
|
|
as published by the Free Software Foundation.
|
2017-11-13 15:06:08 +00:00
|
|
|
|
2017-12-17 19:40:35 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-06-04 19:04:53 +00:00
|
|
|
GNU General Public License (version 3) for more details.
|
|
|
|
|
|
|
|
www.gnu.org/licenses
|
2017-12-17 19:40:35 +00:00
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PluginProcessor.h"
|
|
|
|
#include "PluginEditor.h"
|
2017-11-16 17:45:40 +00:00
|
|
|
#include <set>
|
2018-02-26 22:32:33 +00:00
|
|
|
#include <thread>
|
2017-11-16 17:45:40 +00:00
|
|
|
|
2017-11-25 19:25:46 +00:00
|
|
|
#ifdef WIN32
|
2017-11-15 15:52:47 +00:00
|
|
|
#undef min
|
|
|
|
#undef max
|
2017-11-25 19:25:46 +00:00
|
|
|
#endif
|
2017-11-13 15:06:08 +00:00
|
|
|
|
2017-11-20 22:39:07 +00:00
|
|
|
int get_optimized_updown(int n, bool up) {
|
|
|
|
int orig_n = n;
|
|
|
|
while (true) {
|
|
|
|
n = orig_n;
|
|
|
|
|
|
|
|
while (!(n % 11)) n /= 11;
|
|
|
|
while (!(n % 7)) n /= 7;
|
|
|
|
|
|
|
|
while (!(n % 5)) n /= 5;
|
|
|
|
while (!(n % 3)) n /= 3;
|
|
|
|
while (!(n % 2)) n /= 2;
|
|
|
|
if (n<2) break;
|
|
|
|
if (up) orig_n++;
|
|
|
|
else orig_n--;
|
|
|
|
if (orig_n<4) return 4;
|
|
|
|
};
|
|
|
|
return orig_n;
|
|
|
|
};
|
|
|
|
|
|
|
|
int optimizebufsize(int n) {
|
|
|
|
int n1 = get_optimized_updown(n, false);
|
|
|
|
int n2 = get_optimized_updown(n, true);
|
|
|
|
if ((n - n1)<(n2 - n)) return n1;
|
|
|
|
else return n2;
|
|
|
|
};
|
|
|
|
|
2018-02-01 18:09:12 +00:00
|
|
|
inline AudioParameterFloat* make_floatpar(String id, String name, float minv, float maxv, float defv, float step, float skew)
|
|
|
|
{
|
|
|
|
return new AudioParameterFloat(id, name, NormalisableRange<float>(minv, maxv, step, skew), defv);
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
//==============================================================================
|
|
|
|
PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor()
|
2017-11-20 22:39:07 +00:00
|
|
|
: m_bufferingthread("pspluginprebufferthread")
|
2017-11-13 15:06:08 +00:00
|
|
|
{
|
2019-01-21 14:10:17 +00:00
|
|
|
m_filechoose_callback = [this](const FileChooser& chooser)
|
|
|
|
{
|
|
|
|
File resu = chooser.getResult();
|
|
|
|
String pathname = resu.getFullPathName();
|
|
|
|
if (pathname.startsWith("/localhost"))
|
|
|
|
{
|
|
|
|
pathname = pathname.substring(10);
|
|
|
|
resu = File(pathname);
|
|
|
|
}
|
|
|
|
m_propsfile->m_props_file->setValue("importfilefolder", resu.getParentDirectory().getFullPathName());
|
|
|
|
String loaderr = setAudioFile(resu);
|
|
|
|
if (auto ed = dynamic_cast<PaulstretchpluginAudioProcessorEditor*>(getActiveEditor()); ed != nullptr)
|
|
|
|
{
|
|
|
|
ed->m_last_err = loaderr;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
2018-02-09 13:34:39 +00:00
|
|
|
m_playposinfo.timeInSeconds = 0.0;
|
2018-02-27 00:33:41 +00:00
|
|
|
|
|
|
|
m_free_filter_envelope = std::make_shared<breakpoint_envelope>();
|
2018-02-27 22:32:18 +00:00
|
|
|
m_free_filter_envelope->SetName("Free filter");
|
2018-02-27 13:21:36 +00:00
|
|
|
m_free_filter_envelope->AddNode({ 0.0,0.75 });
|
|
|
|
m_free_filter_envelope->AddNode({ 1.0,0.75 });
|
|
|
|
m_free_filter_envelope->set_reset_nodes(m_free_filter_envelope->get_all_nodes());
|
2018-02-27 00:33:41 +00:00
|
|
|
m_recbuffer.setSize(2, 44100);
|
2017-11-13 22:50:12 +00:00
|
|
|
m_recbuffer.clear();
|
2017-11-23 23:44:30 +00:00
|
|
|
if (m_afm->getNumKnownFormats()==0)
|
|
|
|
m_afm->registerBasicFormats();
|
2018-01-17 16:57:56 +00:00
|
|
|
m_thumb = std::make_unique<AudioThumbnail>(512, *m_afm, *m_thumbcache);
|
2018-03-16 16:40:59 +00:00
|
|
|
|
2018-04-26 18:45:37 +00:00
|
|
|
m_sm_enab_pars[0] = new AudioParameterBool("enab_specmodule0", "Enable harmonics", false);
|
|
|
|
m_sm_enab_pars[1] = new AudioParameterBool("enab_specmodule1", "Enable tonal vs noise", false);
|
|
|
|
m_sm_enab_pars[2] = new AudioParameterBool("enab_specmodule2", "Enable frequency shift", true);
|
|
|
|
m_sm_enab_pars[3] = new AudioParameterBool("enab_specmodule3", "Enable pitch shift", true);
|
|
|
|
m_sm_enab_pars[4] = new AudioParameterBool("enab_specmodule4", "Enable ratios", false);
|
|
|
|
m_sm_enab_pars[5] = new AudioParameterBool("enab_specmodule5", "Enable spread", false);
|
|
|
|
m_sm_enab_pars[6] = new AudioParameterBool("enab_specmodule6", "Enable filter", true);
|
|
|
|
m_sm_enab_pars[7] = new AudioParameterBool("enab_specmodule7", "Enable free filter", true);
|
|
|
|
m_sm_enab_pars[8] = new AudioParameterBool("enab_specmodule8", "Enable compressor", false);
|
2018-04-26 20:07:08 +00:00
|
|
|
|
2018-03-16 16:40:59 +00:00
|
|
|
|
2018-03-09 16:05:33 +00:00
|
|
|
m_stretch_source = std::make_unique<StretchAudioSource>(2, m_afm,m_sm_enab_pars);
|
2017-11-20 22:39:07 +00:00
|
|
|
|
|
|
|
m_stretch_source->setOnsetDetection(0.0);
|
|
|
|
m_stretch_source->setLoopingEnabled(true);
|
2017-11-28 18:46:04 +00:00
|
|
|
m_stretch_source->setFFTWindowingType(1);
|
2018-02-01 18:09:12 +00:00
|
|
|
addParameter(make_floatpar("mainvolume0", "Main volume", -24.0, 12.0, -3.0, 0.1, 1.0));
|
|
|
|
addParameter(make_floatpar("stretchamount0", "Stretch amount", 0.1, 1024.0, 2.0, 0.1, 0.25));
|
|
|
|
addParameter(make_floatpar("fftsize0", "FFT size", 0.0, 1.0, 0.7, 0.01, 1.0));
|
|
|
|
addParameter(make_floatpar("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f, 0.1,1.0)); // 3
|
|
|
|
addParameter(make_floatpar("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f, 1.0, 1.0)); // 4
|
|
|
|
addParameter(make_floatpar("playrange_start0", "Sound start", 0.0f, 1.0f, 0.0f, 0.0001,1.0)); // 5
|
|
|
|
addParameter(make_floatpar("playrange_end0", "Sound end", 0.0f, 1.0f, 1.0f, 0.0001,1.0)); // 6
|
2017-11-16 17:45:40 +00:00
|
|
|
addParameter(new AudioParameterBool("freeze0", "Freeze", false)); // 7
|
2018-02-01 18:09:12 +00:00
|
|
|
addParameter(make_floatpar("spread0", "Frequency spread", 0.0f, 1.0f, 0.0f, 0.001,1.0)); // 8
|
|
|
|
addParameter(make_floatpar("compress0", "Compress", 0.0f, 1.0f, 0.0f, 0.001,1.0)); // 9
|
|
|
|
addParameter(make_floatpar("loopxfadelen0", "Loop xfade length", 0.0f, 1.0f, 0.01f, 0.001, 1.0)); // 10
|
2018-01-30 16:56:00 +00:00
|
|
|
addParameter(new AudioParameterInt("numharmonics0", "Num harmonics", 1, 100, 10)); // 11
|
2018-02-01 18:09:12 +00:00
|
|
|
addParameter(make_floatpar("harmonicsfreq0", "Harmonics base freq", 1.0, 5000.0, 128.0, 0.1, 0.5));
|
|
|
|
addParameter(make_floatpar("harmonicsbw0", "Harmonics bandwidth", 0.1f, 200.0f, 25.0f, 0.01, 1.0)); // 13
|
2017-12-12 17:14:43 +00:00
|
|
|
addParameter(new AudioParameterBool("harmonicsgauss0", "Gaussian harmonics", false)); // 14
|
2018-02-01 18:09:12 +00:00
|
|
|
addParameter(make_floatpar("octavemixm2_0", "2 octaves down level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 15
|
|
|
|
addParameter(make_floatpar("octavemixm1_0", "Octave down level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 16
|
|
|
|
addParameter(make_floatpar("octavemix0_0", "Normal pitch level", 0.0f, 1.0f, 1.0f, 0.001, 1.0)); // 17
|
|
|
|
addParameter(make_floatpar("octavemix1_0", "1 octave up level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 18
|
|
|
|
addParameter(make_floatpar("octavemix15_0", "1 octave and fifth up level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 19
|
|
|
|
addParameter(make_floatpar("octavemix2_0", "2 octaves up level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 20
|
|
|
|
addParameter(make_floatpar("tonalvsnoisebw_0", "Tonal vs Noise BW", 0.74f, 1.0f, 0.74f, 0.001, 1.0)); // 21
|
|
|
|
addParameter(make_floatpar("tonalvsnoisepreserve_0", "Tonal vs Noise preserve", -1.0f, 1.0f, 0.5f, 0.001, 1.0)); // 22
|
2017-12-15 15:43:59 +00:00
|
|
|
auto filt_convertFrom0To1Func = [](float rangemin, float rangemax, float value)
|
|
|
|
{
|
|
|
|
if (value < 0.5f)
|
|
|
|
return jmap<float>(value, 0.0f, 0.5f, 20.0f, 1000.0f);
|
|
|
|
return jmap<float>(value, 0.5f, 1.0f, 1000.0f, 20000.0f);
|
|
|
|
};
|
|
|
|
auto filt_convertTo0To1Func = [](float rangemin, float rangemax, float value)
|
|
|
|
{
|
|
|
|
if (value < 1000.0f)
|
|
|
|
return jmap<float>(value, 20.0f, 1000.0f, 0.0f, 0.5f);
|
|
|
|
return jmap<float>(value, 1000.0f, 20000.0f, 0.5f, 1.0f);
|
|
|
|
};
|
2017-12-15 02:34:22 +00:00
|
|
|
addParameter(new AudioParameterFloat("filter_low_0", "Filter low",
|
2017-12-15 15:43:59 +00:00
|
|
|
NormalisableRange<float>(20.0f, 20000.0f,
|
|
|
|
filt_convertFrom0To1Func, filt_convertTo0To1Func), 20.0f)); // 23
|
2017-12-15 02:34:22 +00:00
|
|
|
addParameter(new AudioParameterFloat("filter_high_0", "Filter high",
|
2017-12-15 15:43:59 +00:00
|
|
|
NormalisableRange<float>(20.0f, 20000.0f,
|
|
|
|
filt_convertFrom0To1Func,filt_convertTo0To1Func), 20000.0f));; // 24
|
2018-02-01 18:09:12 +00:00
|
|
|
addParameter(make_floatpar("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f, 0.01, 1.0)); // 25
|
2017-12-13 16:30:09 +00:00
|
|
|
addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26
|
2018-02-13 13:47:17 +00:00
|
|
|
m_outchansparam = new AudioParameterInt("numoutchans0", "Num outs", 2, 8, 2); // 27
|
2017-12-13 22:19:46 +00:00
|
|
|
addParameter(m_outchansparam); // 27
|
2017-12-14 20:17:45 +00:00
|
|
|
addParameter(new AudioParameterBool("pause_enabled0", "Pause", false)); // 28
|
2017-12-18 17:48:40 +00:00
|
|
|
addParameter(new AudioParameterFloat("maxcapturelen_0", "Max capture length", 1.0f, 120.0f, 10.0f)); // 29
|
2017-12-22 20:35:02 +00:00
|
|
|
addParameter(new AudioParameterBool("passthrough0", "Pass input through", false)); // 30
|
2018-02-07 14:00:49 +00:00
|
|
|
addParameter(new AudioParameterBool("markdirty0", "Internal (don't use)", false)); // 31
|
2018-02-13 13:47:17 +00:00
|
|
|
m_inchansparam = new AudioParameterInt("numinchans0", "Num ins", 2, 8, 2); // 32
|
2018-02-12 14:44:21 +00:00
|
|
|
addParameter(m_inchansparam); // 32
|
2018-02-21 17:49:16 +00:00
|
|
|
addParameter(new AudioParameterBool("bypass_stretch0", "Bypass stretch", false)); // 33
|
2018-02-28 12:20:26 +00:00
|
|
|
addParameter(new AudioParameterFloat("freefilter_shiftx_0", "Free filter shift X", -1.0f, 1.0f, 0.0f)); // 34
|
|
|
|
addParameter(new AudioParameterFloat("freefilter_shifty_0", "Free filter shift Y", -1.0f, 1.0f, 0.0f)); // 35
|
2018-02-28 12:36:13 +00:00
|
|
|
addParameter(new AudioParameterFloat("freefilter_scaley_0", "Free filter scale Y", -1.0f, 1.0f, 1.0f)); // 36
|
|
|
|
addParameter(new AudioParameterFloat("freefilter_tilty_0", "Free filter tilt Y", -1.0f, 1.0f, 0.0f)); // 37
|
2018-03-03 15:22:23 +00:00
|
|
|
addParameter(new AudioParameterInt("freefilter_randomybands0", "Random bands", 2, 128, 16)); // 38
|
|
|
|
addParameter(new AudioParameterInt("freefilter_randomyrate0", "Random rate", 1, 32, 2)); // 39
|
|
|
|
addParameter(new AudioParameterFloat("freefilter_randomyamount0", "Random amount", 0.0, 1.0, 0.0)); // 40
|
2018-03-06 11:44:36 +00:00
|
|
|
for (int i = 0; i < 9; ++i) // 41-49
|
|
|
|
{
|
|
|
|
addParameter(m_sm_enab_pars[i]);
|
2018-04-26 20:07:08 +00:00
|
|
|
m_sm_enab_pars[i]->addListener(this);
|
2018-03-06 11:44:36 +00:00
|
|
|
}
|
2018-04-03 15:32:53 +00:00
|
|
|
|
|
|
|
addParameter(make_floatpar("octavemix_extra0_0", "Ratio mix 7 level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 50
|
|
|
|
addParameter(make_floatpar("octavemix_extra1_0", "Ratio mix 8 level", 0.0f, 1.0f, 0.0f, 0.001, 1.0)); // 51
|
|
|
|
|
2018-04-13 12:36:11 +00:00
|
|
|
std::array<double,8> initialratios{ 0.25,0.5,1.0,2.0,3.0,4.0,1.5,1.0 / 1.5 };
|
2018-04-03 15:32:53 +00:00
|
|
|
// 52-59
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
{
|
2018-04-13 12:36:11 +00:00
|
|
|
addParameter(make_floatpar("ratiomix_ratio_"+String(i)+"_0", "Ratio mix ratio "+String(i+1), 0.125f, 8.0f,
|
|
|
|
initialratios[i],
|
|
|
|
0.001,
|
|
|
|
1.0));
|
2018-04-03 15:32:53 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:33:06 +00:00
|
|
|
addParameter(new AudioParameterBool("loop_enabled0", "Loop", true)); // 60
|
2018-05-18 13:20:51 +00:00
|
|
|
addParameter(new AudioParameterBool("rewind0", "Rewind", false)); // 61
|
2018-08-21 08:49:28 +00:00
|
|
|
auto dprate_convertFrom0To1Func = [](float rangemin, float rangemax, float value)
|
|
|
|
{
|
|
|
|
if (value < 0.5f)
|
|
|
|
return jmap<float>(value, 0.0f, 0.5f, 0.1f, 1.0f);
|
|
|
|
return jmap<float>(value, 0.5f, 1.0f, 1.0f, 8.0f);
|
|
|
|
};
|
|
|
|
auto dprate_convertTo0To1Func = [](float rangemin, float rangemax, float value)
|
|
|
|
{
|
|
|
|
if (value < 1.0f)
|
|
|
|
return jmap<float>(value, 0.1f, 1.0f, 0.0f, 0.5f);
|
|
|
|
return jmap<float>(value, 1.0f, 8.0f, 0.5f, 1.0f);
|
|
|
|
};
|
|
|
|
addParameter(new AudioParameterFloat("dryplayrate0", "Dry playrate",
|
|
|
|
NormalisableRange<float>(0.1f, 8.0f,
|
|
|
|
dprate_convertFrom0To1Func, dprate_convertTo0To1Func), 1.0f)); // 62
|
2019-01-17 13:23:01 +00:00
|
|
|
|
2017-12-26 16:12:22 +00:00
|
|
|
auto& pars = getParameters();
|
|
|
|
for (const auto& p : pars)
|
|
|
|
m_reset_pars.push_back(p->getValue());
|
2017-12-20 01:58:50 +00:00
|
|
|
setPreBufferAmount(2);
|
|
|
|
startTimer(1, 50);
|
2018-02-13 15:52:45 +00:00
|
|
|
m_show_technical_info = m_propsfile->m_props_file->getBoolValue("showtechnicalinfo", false);
|
2018-02-21 17:49:16 +00:00
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
|
|
|
|
{
|
2018-08-07 21:10:27 +00:00
|
|
|
//Logger::writeToLog("PaulX AudioProcessor destroyed");
|
2018-01-20 20:54:26 +00:00
|
|
|
m_thumb->removeAllChangeListeners();
|
|
|
|
m_thumb = nullptr;
|
2017-11-20 22:39:07 +00:00
|
|
|
m_bufferingthread.stopThread(1000);
|
|
|
|
}
|
|
|
|
|
2017-12-26 16:12:22 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::resetParameters()
|
|
|
|
{
|
|
|
|
ScopedLock locker(m_cs);
|
|
|
|
for (int i = 0; i < m_reset_pars.size(); ++i)
|
|
|
|
{
|
|
|
|
if (i!=cpi_main_volume && i!=cpi_passthrough)
|
|
|
|
setParameter(i, m_reset_pars[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-20 22:39:07 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::setPreBufferAmount(int x)
|
|
|
|
{
|
|
|
|
int temp = jlimit(0, 5, x);
|
2017-12-20 01:58:50 +00:00
|
|
|
if (temp != m_prebuffer_amount || m_use_backgroundbuffering == false)
|
2017-11-20 22:39:07 +00:00
|
|
|
{
|
2017-12-20 01:58:50 +00:00
|
|
|
m_use_backgroundbuffering = true;
|
|
|
|
m_prebuffer_amount = temp;
|
2017-11-20 22:39:07 +00:00
|
|
|
m_recreate_buffering_source = true;
|
2017-12-20 01:58:50 +00:00
|
|
|
ScopedLock locker(m_cs);
|
2017-12-27 15:35:30 +00:00
|
|
|
m_prebuffering_inited = false;
|
2017-12-20 01:58:50 +00:00
|
|
|
m_cur_num_out_chans = *m_outchansparam;
|
|
|
|
//Logger::writeToLog("Switching to use " + String(m_cur_num_out_chans) + " out channels");
|
|
|
|
String err;
|
|
|
|
startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
|
|
|
|
m_cur_num_out_chans, m_curmaxblocksize, err);
|
2018-09-13 11:04:56 +00:00
|
|
|
|
|
|
|
m_prebuffering_inited = true;
|
2017-11-20 22:39:07 +00:00
|
|
|
}
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 20:35:02 +00:00
|
|
|
int PaulstretchpluginAudioProcessor::getPreBufferAmount()
|
|
|
|
{
|
|
|
|
if (m_use_backgroundbuffering == false)
|
|
|
|
return -1;
|
|
|
|
return m_prebuffer_amount;
|
|
|
|
}
|
|
|
|
|
2017-12-27 20:43:07 +00:00
|
|
|
ValueTree PaulstretchpluginAudioProcessor::getStateTree(bool ignoreoptions, bool ignorefile)
|
2017-12-27 20:20:44 +00:00
|
|
|
{
|
|
|
|
ValueTree paramtree("paulstretch3pluginstate");
|
2019-02-12 12:56:37 +00:00
|
|
|
storeToTreeProperties(paramtree, nullptr, getParameters(), { getBoolParameter(cpi_capture_trigger) });
|
2018-02-21 23:09:36 +00:00
|
|
|
if (m_current_file != File() && ignorefile == false)
|
2017-12-27 20:20:44 +00:00
|
|
|
{
|
|
|
|
paramtree.setProperty("importedfile", m_current_file.getFullPathName(), nullptr);
|
|
|
|
}
|
|
|
|
auto specorder = m_stretch_source->getSpectrumProcessOrder();
|
2018-03-21 11:15:48 +00:00
|
|
|
paramtree.setProperty("numspectralstagesb", (int)specorder.size(), nullptr);
|
2017-12-27 20:20:44 +00:00
|
|
|
for (int i = 0; i < specorder.size(); ++i)
|
|
|
|
{
|
2018-03-21 11:15:48 +00:00
|
|
|
paramtree.setProperty("specorderb" + String(i), specorder[i].m_index, nullptr);
|
2017-12-27 20:20:44 +00:00
|
|
|
}
|
2017-12-27 20:43:07 +00:00
|
|
|
if (ignoreoptions == false)
|
|
|
|
{
|
|
|
|
if (m_use_backgroundbuffering)
|
|
|
|
paramtree.setProperty("prebufamount", m_prebuffer_amount, nullptr);
|
|
|
|
else
|
|
|
|
paramtree.setProperty("prebufamount", -1, nullptr);
|
|
|
|
paramtree.setProperty("loadfilewithstate", m_load_file_with_state, nullptr);
|
2018-12-19 13:16:30 +00:00
|
|
|
storeToTreeProperties(paramtree, nullptr, "playwhenhostrunning", m_play_when_host_plays,
|
|
|
|
"capturewhenhostrunning", m_capture_when_host_plays,"savecapturedaudio",m_save_captured_audio,
|
|
|
|
"mutewhilecapturing",m_mute_while_capturing);
|
2017-12-27 20:43:07 +00:00
|
|
|
}
|
2018-06-29 12:13:49 +00:00
|
|
|
storeToTreeProperties(paramtree, nullptr, "tabaindex", m_cur_tab_index);
|
2018-02-14 16:38:54 +00:00
|
|
|
storeToTreeProperties(paramtree, nullptr, "waveviewrange", m_wave_view_range);
|
2018-02-27 01:41:54 +00:00
|
|
|
ValueTree freefilterstate = m_free_filter_envelope->saveState(Identifier("freefilter_envelope"));
|
|
|
|
paramtree.addChild(freefilterstate, -1, nullptr);
|
|
|
|
return paramtree;
|
2017-12-27 20:20:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree)
|
|
|
|
{
|
|
|
|
if (tree.isValid())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ScopedLock locker(m_cs);
|
2018-02-27 01:41:54 +00:00
|
|
|
ValueTree freefilterstate = tree.getChildWithName("freefilter_envelope");
|
|
|
|
m_free_filter_envelope->restoreState(freefilterstate);
|
|
|
|
m_load_file_with_state = tree.getProperty("loadfilewithstate", true);
|
2018-06-04 20:27:08 +00:00
|
|
|
getFromTreeProperties(tree, "playwhenhostrunning", m_play_when_host_plays,
|
2018-12-19 13:16:30 +00:00
|
|
|
"capturewhenhostrunning", m_capture_when_host_plays,"mutewhilecapturing",m_mute_while_capturing,
|
|
|
|
"savecapturedaudio",m_save_captured_audio);
|
2018-06-29 12:13:49 +00:00
|
|
|
getFromTreeProperties(tree, "tabaindex", m_cur_tab_index);
|
2018-03-21 11:15:48 +00:00
|
|
|
if (tree.hasProperty("numspectralstagesb"))
|
2017-12-27 20:20:44 +00:00
|
|
|
{
|
2018-03-21 11:15:48 +00:00
|
|
|
std::vector<SpectrumProcess> old_order = m_stretch_source->getSpectrumProcessOrder();
|
|
|
|
std::vector<SpectrumProcess> new_order;
|
|
|
|
int ordersize = tree.getProperty("numspectralstagesb");
|
|
|
|
if (ordersize == old_order.size())
|
2017-12-27 20:20:44 +00:00
|
|
|
{
|
2018-03-21 11:15:48 +00:00
|
|
|
for (int i = 0; i < ordersize; ++i)
|
|
|
|
{
|
2018-04-26 20:20:16 +00:00
|
|
|
int index = tree.getProperty("specorderb" + String(i));
|
2018-11-11 12:06:18 +00:00
|
|
|
new_order.push_back({ (SpectrumProcessType)index, old_order[index].m_enabled });
|
2018-03-21 11:15:48 +00:00
|
|
|
}
|
|
|
|
m_stretch_source->setSpectrumProcessOrder(new_order);
|
2017-12-27 20:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-14 16:38:54 +00:00
|
|
|
getFromTreeProperties(tree, "waveviewrange", m_wave_view_range);
|
2018-03-21 11:15:48 +00:00
|
|
|
getFromTreeProperties(tree, getParameters());
|
|
|
|
|
2018-02-21 23:09:36 +00:00
|
|
|
}
|
2017-12-27 20:20:44 +00:00
|
|
|
int prebufamt = tree.getProperty("prebufamount", 2);
|
|
|
|
if (prebufamt == -1)
|
|
|
|
m_use_backgroundbuffering = false;
|
|
|
|
else
|
|
|
|
setPreBufferAmount(prebufamt);
|
|
|
|
if (m_load_file_with_state == true)
|
|
|
|
{
|
|
|
|
String fn = tree.getProperty("importedfile");
|
|
|
|
if (fn.isEmpty() == false)
|
|
|
|
{
|
2018-11-08 18:22:26 +00:00
|
|
|
setAudioFile(File(fn));
|
|
|
|
}
|
2017-12-27 20:20:44 +00:00
|
|
|
}
|
2017-12-27 20:43:07 +00:00
|
|
|
m_state_dirty = true;
|
2017-12-27 20:20:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
//==============================================================================
|
|
|
|
const String PaulstretchpluginAudioProcessor::getName() const
|
|
|
|
{
|
|
|
|
return JucePlugin_Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PaulstretchpluginAudioProcessor::acceptsMidi() const
|
|
|
|
{
|
|
|
|
#if JucePlugin_WantsMidiInput
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PaulstretchpluginAudioProcessor::producesMidi() const
|
|
|
|
{
|
|
|
|
#if JucePlugin_ProducesMidiOutput
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PaulstretchpluginAudioProcessor::isMidiEffect() const
|
|
|
|
{
|
|
|
|
#if JucePlugin_IsMidiEffect
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
double PaulstretchpluginAudioProcessor::getTailLengthSeconds() const
|
|
|
|
{
|
2017-12-17 16:16:39 +00:00
|
|
|
return 0.0;
|
|
|
|
//return (double)m_bufamounts[m_prebuffer_amount]/getSampleRate();
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PaulstretchpluginAudioProcessor::getNumPrograms()
|
|
|
|
{
|
2018-02-07 14:55:48 +00:00
|
|
|
return 1;
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PaulstretchpluginAudioProcessor::getCurrentProgram()
|
|
|
|
{
|
2018-02-07 14:55:48 +00:00
|
|
|
return 0;
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::setCurrentProgram (int index)
|
|
|
|
{
|
2018-02-07 14:55:48 +00:00
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const String PaulstretchpluginAudioProcessor::getProgramName (int index)
|
|
|
|
{
|
2018-02-07 14:55:48 +00:00
|
|
|
return String();
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::changeProgramName (int index, const String& newName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-04-26 20:07:08 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::parameterValueChanged(int parameterIndex, float newValue)
|
|
|
|
{
|
|
|
|
if (parameterIndex >= cpi_enable_spec_module0 && parameterIndex <= cpi_enable_spec_module8)
|
|
|
|
{
|
|
|
|
m_stretch_source->setSpectralModuleEnabled(parameterIndex - cpi_enable_spec_module0, newValue >= 0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::parameterGestureChanged(int parameterIndex, bool gestureIsStarting)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-20 22:39:07 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::setFFTSize(double size)
|
|
|
|
{
|
|
|
|
if (m_prebuffer_amount == 5)
|
|
|
|
m_fft_size_to_use = pow(2, 7.0 + size * 14.5);
|
|
|
|
else m_fft_size_to_use = pow(2, 7.0 + size * 10.0); // chicken out from allowing huge FFT sizes if not enough prebuffering
|
|
|
|
int optim = optimizebufsize(m_fft_size_to_use);
|
|
|
|
m_fft_size_to_use = optim;
|
|
|
|
m_stretch_source->setFFTSize(optim);
|
|
|
|
//Logger::writeToLog(String(m_fft_size_to_use));
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:06:26 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::startplay(Range<double> playrange, int numoutchans, int maxBlockSize, String& err)
|
2017-11-20 22:39:07 +00:00
|
|
|
{
|
2018-05-18 13:20:51 +00:00
|
|
|
m_stretch_source->setPlayRange(playrange);
|
2018-02-27 13:02:34 +00:00
|
|
|
m_stretch_source->setFreeFilterEnvelope(m_free_filter_envelope);
|
2017-11-20 22:39:07 +00:00
|
|
|
int bufamt = m_bufamounts[m_prebuffer_amount];
|
|
|
|
|
|
|
|
if (m_buffering_source != nullptr && numoutchans != m_buffering_source->getNumberOfChannels())
|
|
|
|
m_recreate_buffering_source = true;
|
|
|
|
if (m_recreate_buffering_source == true)
|
|
|
|
{
|
|
|
|
m_buffering_source = std::make_unique<MyBufferingAudioSource>(m_stretch_source.get(),
|
|
|
|
m_bufferingthread, false, bufamt, numoutchans, false);
|
|
|
|
m_recreate_buffering_source = false;
|
|
|
|
}
|
|
|
|
if (m_bufferingthread.isThreadRunning() == false)
|
|
|
|
m_bufferingthread.startThread();
|
|
|
|
m_stretch_source->setNumOutChannels(numoutchans);
|
|
|
|
m_stretch_source->setFFTSize(m_fft_size_to_use);
|
|
|
|
m_stretch_source->setProcessParameters(&m_ppar);
|
2018-09-13 11:04:56 +00:00
|
|
|
m_stretch_source->m_prebuffersize = bufamt;
|
2017-11-20 22:39:07 +00:00
|
|
|
m_last_outpos_pos = 0.0;
|
|
|
|
m_last_in_pos = playrange.getStart()*m_stretch_source->getInfileLengthSeconds();
|
2017-12-17 16:16:39 +00:00
|
|
|
m_buffering_source->prepareToPlay(maxBlockSize, getSampleRateChecked());
|
|
|
|
}
|
2017-12-27 20:20:44 +00:00
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::setParameters(const std::vector<double>& pars)
|
|
|
|
{
|
|
|
|
ScopedLock locker(m_cs);
|
|
|
|
for (int i = 0; i < getNumParameters(); ++i)
|
|
|
|
{
|
|
|
|
if (i<pars.size())
|
|
|
|
setParameter(i, pars[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-26 14:34:13 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::updateStretchParametersFromPluginParameters(ProcessParameters & pars)
|
|
|
|
{
|
|
|
|
pars.pitch_shift.cents = *getFloatParameter(cpi_pitchshift) * 100.0;
|
|
|
|
pars.freq_shift.Hz = *getFloatParameter(cpi_frequencyshift);
|
|
|
|
|
|
|
|
pars.spread.bandwidth = *getFloatParameter(cpi_spreadamount);
|
|
|
|
|
|
|
|
pars.compressor.power = *getFloatParameter(cpi_compress);
|
|
|
|
|
|
|
|
pars.harmonics.nharmonics = *getIntParameter(cpi_numharmonics);
|
|
|
|
pars.harmonics.freq = *getFloatParameter(cpi_harmonicsfreq);
|
|
|
|
pars.harmonics.bandwidth = *getFloatParameter(cpi_harmonicsbw);
|
|
|
|
pars.harmonics.gauss = getParameter(cpi_harmonicsgauss);
|
|
|
|
|
|
|
|
pars.octave.om2 = *getFloatParameter(cpi_octavesm2);
|
|
|
|
pars.octave.om1 = *getFloatParameter(cpi_octavesm1);
|
|
|
|
pars.octave.o0 = *getFloatParameter(cpi_octaves0);
|
|
|
|
pars.octave.o1 = *getFloatParameter(cpi_octaves1);
|
|
|
|
pars.octave.o15 = *getFloatParameter(cpi_octaves15);
|
|
|
|
pars.octave.o2 = *getFloatParameter(cpi_octaves2);
|
|
|
|
|
2018-04-03 13:34:20 +00:00
|
|
|
pars.ratiomix.ratiolevels[0]= *getFloatParameter(cpi_octavesm2);
|
|
|
|
pars.ratiomix.ratiolevels[1] = *getFloatParameter(cpi_octavesm1);
|
|
|
|
pars.ratiomix.ratiolevels[2] = *getFloatParameter(cpi_octaves0);
|
|
|
|
pars.ratiomix.ratiolevels[3] = *getFloatParameter(cpi_octaves1);
|
|
|
|
pars.ratiomix.ratiolevels[4] = *getFloatParameter(cpi_octaves15);
|
|
|
|
pars.ratiomix.ratiolevels[5] = *getFloatParameter(cpi_octaves2);
|
2018-04-03 15:32:53 +00:00
|
|
|
pars.ratiomix.ratiolevels[6] = *getFloatParameter(cpi_octaves_extra1);
|
|
|
|
pars.ratiomix.ratiolevels[7] = *getFloatParameter(cpi_octaves_extra2);
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; ++i)
|
|
|
|
pars.ratiomix.ratios[i] = *getFloatParameter((int)cpi_octaves_ratio0 + i);
|
2018-04-03 13:34:20 +00:00
|
|
|
|
2018-02-26 14:34:13 +00:00
|
|
|
pars.filter.low = *getFloatParameter(cpi_filter_low);
|
|
|
|
pars.filter.high = *getFloatParameter(cpi_filter_high);
|
|
|
|
|
|
|
|
pars.tonal_vs_noise.bandwidth = *getFloatParameter(cpi_tonalvsnoisebw);
|
|
|
|
pars.tonal_vs_noise.preserve = *getFloatParameter(cpi_tonalvsnoisepreserve);
|
|
|
|
}
|
|
|
|
|
2018-11-08 18:22:26 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::saveCaptureBuffer()
|
|
|
|
{
|
|
|
|
auto task = [this]()
|
|
|
|
{
|
|
|
|
int inchans = *getIntParameter(cpi_num_inchans);
|
|
|
|
if (inchans < 1)
|
|
|
|
return;
|
|
|
|
Uuid uid;
|
|
|
|
WavAudioFormat wavformat;
|
2018-11-08 20:48:06 +00:00
|
|
|
String propsdir = m_propsfile->m_props_file->getFile().getParentDirectory().getFullPathName();
|
2018-12-19 13:25:52 +00:00
|
|
|
String outfn;
|
|
|
|
if (m_capture_location.isEmpty())
|
|
|
|
outfn = propsdir + "/paulxstretchaudiocaptures/" + uid.toString() + ".wav";
|
|
|
|
else
|
|
|
|
outfn = m_capture_location + "/pxscapture_" + uid.toString() + ".wav";
|
2018-11-08 18:22:26 +00:00
|
|
|
File outfile(outfn);
|
2018-11-08 20:18:50 +00:00
|
|
|
outfile.create();
|
|
|
|
if (outfile.existsAsFile())
|
2018-11-08 18:22:26 +00:00
|
|
|
{
|
2018-12-19 13:16:30 +00:00
|
|
|
m_capture_save_state = 1;
|
2018-11-08 20:18:50 +00:00
|
|
|
auto outstream = outfile.createOutputStream();
|
|
|
|
auto writer = unique_from_raw(wavformat.createWriterFor(outstream, getSampleRateChecked(),
|
|
|
|
inchans, 32, {}, 0));
|
|
|
|
if (writer != nullptr)
|
|
|
|
{
|
|
|
|
auto sourcebuffer = getStretchSource()->getSourceAudioBuffer();
|
|
|
|
jassert(sourcebuffer->getNumChannels() == inchans);
|
|
|
|
jassert(sourcebuffer->getNumSamples() > 0);
|
|
|
|
|
|
|
|
writer->writeFromAudioSampleBuffer(*sourcebuffer, 0, sourcebuffer->getNumSamples());
|
|
|
|
m_current_file = outfile;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger::writeToLog("Could not create wav writer");
|
|
|
|
delete outstream;
|
|
|
|
}
|
2018-11-08 18:22:26 +00:00
|
|
|
}
|
|
|
|
else
|
2018-11-08 20:18:50 +00:00
|
|
|
Logger::writeToLog("Could not create output file");
|
2018-12-19 13:16:30 +00:00
|
|
|
m_capture_save_state = 0;
|
2018-11-08 18:22:26 +00:00
|
|
|
};
|
2018-11-08 20:48:06 +00:00
|
|
|
m_threadpool->addJob(task);
|
2018-11-08 18:22:26 +00:00
|
|
|
}
|
|
|
|
|
2019-01-20 13:24:30 +00:00
|
|
|
String PaulstretchpluginAudioProcessor::offlineRender(OfflineRenderParams renderpars)
|
2018-02-26 15:49:19 +00:00
|
|
|
{
|
2019-01-20 13:24:30 +00:00
|
|
|
File outputfiletouse = renderpars.outputfile.getNonexistentSibling();
|
|
|
|
ValueTree state{ getStateTree(false, false) };
|
2018-07-09 17:21:06 +00:00
|
|
|
auto processor = std::make_shared<PaulstretchpluginAudioProcessor>();
|
2019-01-20 13:24:30 +00:00
|
|
|
|
2018-07-09 17:21:06 +00:00
|
|
|
processor->setStateFromTree(state);
|
2019-01-20 13:24:30 +00:00
|
|
|
double outsr{ renderpars.outsr };
|
|
|
|
if (outsr < 10.0)
|
|
|
|
outsr = processor->getStretchSource()->getInfileSamplerate();
|
|
|
|
Logger::writeToLog(outputfiletouse.getFullPathName() + " " + String(outsr) + " " + String(renderpars.outputformat));
|
2019-01-20 19:45:43 +00:00
|
|
|
int blocksize{ 1024 };
|
2018-07-09 17:21:06 +00:00
|
|
|
int numoutchans = *processor->getIntParameter(cpi_num_outchans);
|
2019-01-20 18:21:29 +00:00
|
|
|
processor->setPlayConfigDetails(0, numoutchans, outsr, blocksize);
|
2019-01-20 13:24:30 +00:00
|
|
|
processor->prepareToPlay(renderpars.outsr, blocksize);
|
|
|
|
|
2018-07-09 17:21:06 +00:00
|
|
|
double t0 = *processor->getFloatParameter(cpi_soundstart);
|
|
|
|
double t1 = *processor->getFloatParameter(cpi_soundend);
|
2018-02-26 15:49:19 +00:00
|
|
|
sanitizeTimeRange(t0, t1);
|
2019-01-20 13:24:30 +00:00
|
|
|
|
2019-01-20 18:21:29 +00:00
|
|
|
|
|
|
|
auto rendertask = [processor,outputfiletouse, renderpars,blocksize,numoutchans, outsr, this]()
|
2018-02-26 15:49:19 +00:00
|
|
|
{
|
2019-01-20 18:21:29 +00:00
|
|
|
WavAudioFormat wavformat;
|
|
|
|
FileOutputStream* outstream = outputfiletouse.createOutputStream();
|
|
|
|
if (outstream == nullptr)
|
|
|
|
{
|
|
|
|
jassert(false);
|
|
|
|
}
|
|
|
|
int oformattouse{ 16 };
|
|
|
|
bool clipoutput{ false };
|
|
|
|
if (renderpars.outputformat == 1)
|
|
|
|
oformattouse = 24;
|
|
|
|
if (renderpars.outputformat == 2)
|
|
|
|
oformattouse = 32;
|
|
|
|
if (renderpars.outputformat == 3)
|
|
|
|
{
|
|
|
|
oformattouse = 32;
|
|
|
|
clipoutput = true;
|
|
|
|
}
|
|
|
|
auto writer{ unique_from_raw(wavformat.createWriterFor(outstream, getSampleRateChecked(), numoutchans,
|
|
|
|
oformattouse, StringPairArray(), 0)) };
|
|
|
|
if (writer == nullptr)
|
|
|
|
{
|
|
|
|
delete outstream;
|
|
|
|
jassert(false);
|
|
|
|
}
|
|
|
|
AudioBuffer<float> renderbuffer{ numoutchans, blocksize };
|
2018-07-09 17:21:06 +00:00
|
|
|
MidiBuffer dummymidi;
|
2019-01-20 18:21:29 +00:00
|
|
|
auto sc = processor->getStretchSource();
|
|
|
|
double outlensecs = sc->getInfileLengthSeconds()*sc->getRate();
|
|
|
|
int64_t outlen = outlensecs * outsr;
|
|
|
|
int64_t outcounter{ 0 };
|
2018-02-26 17:55:32 +00:00
|
|
|
m_offline_render_state = 0;
|
2018-02-26 18:09:47 +00:00
|
|
|
m_offline_render_cancel_requested = false;
|
2019-01-20 18:21:29 +00:00
|
|
|
processor->setNonRealtime(true);
|
2018-02-26 17:55:32 +00:00
|
|
|
while (outcounter < outlen)
|
|
|
|
{
|
2018-02-26 18:09:47 +00:00
|
|
|
if (m_offline_render_cancel_requested == true)
|
|
|
|
break;
|
2018-07-09 17:21:06 +00:00
|
|
|
processor->processBlock(renderbuffer, dummymidi);
|
2018-02-26 17:55:32 +00:00
|
|
|
writer->writeFromAudioSampleBuffer(renderbuffer, 0, blocksize);
|
|
|
|
outcounter += blocksize;
|
|
|
|
m_offline_render_state = 100.0 / outlen * outcounter;
|
|
|
|
}
|
|
|
|
m_offline_render_state = 200;
|
2019-01-20 18:21:29 +00:00
|
|
|
Logger::writeToLog("Rendered ok!");
|
2018-02-26 17:55:32 +00:00
|
|
|
};
|
|
|
|
std::thread th(rendertask);
|
|
|
|
th.detach();
|
2018-02-26 15:49:19 +00:00
|
|
|
return "Rendered OK";
|
|
|
|
}
|
|
|
|
|
2017-12-17 16:16:39 +00:00
|
|
|
double PaulstretchpluginAudioProcessor::getSampleRateChecked()
|
|
|
|
{
|
2018-02-26 15:49:19 +00:00
|
|
|
if (m_cur_sr < 1.0 || m_cur_sr>1000000.0)
|
2017-12-17 16:16:39 +00:00
|
|
|
return 44100.0;
|
|
|
|
return m_cur_sr;
|
|
|
|
}
|
2017-11-20 22:39:07 +00:00
|
|
|
|
2017-11-13 16:15:07 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock)
|
|
|
|
{
|
2018-02-21 23:54:21 +00:00
|
|
|
++m_prepare_count;
|
|
|
|
ScopedLock locker(m_cs);
|
2019-01-17 17:47:56 +00:00
|
|
|
m_adsr.setSampleRate(sampleRate);
|
2017-12-17 16:16:39 +00:00
|
|
|
m_cur_sr = sampleRate;
|
2017-12-14 17:06:26 +00:00
|
|
|
m_curmaxblocksize = samplesPerBlock;
|
2018-02-12 14:44:21 +00:00
|
|
|
m_input_buffer.setSize(getMainBusNumInputChannels(), samplesPerBlock);
|
2018-05-18 13:20:51 +00:00
|
|
|
*getBoolParameter(cpi_rewind) = false;
|
2018-05-31 10:55:32 +00:00
|
|
|
m_lastrewind = false;
|
2017-12-13 22:19:46 +00:00
|
|
|
int numoutchans = *m_outchansparam;
|
|
|
|
if (numoutchans != m_cur_num_out_chans)
|
2017-12-27 15:35:30 +00:00
|
|
|
m_prebuffering_inited = false;
|
2017-11-13 22:50:12 +00:00
|
|
|
if (m_using_memory_buffer == true)
|
2017-11-13 23:50:44 +00:00
|
|
|
{
|
2017-12-20 18:33:34 +00:00
|
|
|
int len = jlimit(100,m_recbuffer.getNumSamples(),
|
|
|
|
int(getSampleRateChecked()*(*getFloatParameter(cpi_max_capture_len))));
|
2017-11-20 22:39:07 +00:00
|
|
|
m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer,
|
2017-12-17 16:16:39 +00:00
|
|
|
getSampleRateChecked(),
|
2017-11-13 23:50:44 +00:00
|
|
|
len);
|
2018-02-19 19:09:09 +00:00
|
|
|
//m_thumb->reset(m_recbuffer.getNumChannels(), sampleRate, len);
|
2017-11-13 23:50:44 +00:00
|
|
|
}
|
2017-12-27 15:35:30 +00:00
|
|
|
if (m_prebuffering_inited == false)
|
2017-11-13 21:42:13 +00:00
|
|
|
{
|
2017-12-14 17:57:14 +00:00
|
|
|
setFFTSize(*getFloatParameter(cpi_fftsize));
|
2017-11-20 22:39:07 +00:00
|
|
|
m_stretch_source->setProcessParameters(&m_ppar);
|
2017-12-14 20:17:45 +00:00
|
|
|
m_stretch_source->setFFTWindowingType(1);
|
2017-11-13 21:42:13 +00:00
|
|
|
String err;
|
2017-12-14 17:57:14 +00:00
|
|
|
startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
|
2017-12-14 17:06:26 +00:00
|
|
|
numoutchans, samplesPerBlock, err);
|
2017-12-13 22:19:46 +00:00
|
|
|
m_cur_num_out_chans = numoutchans;
|
2017-12-27 15:35:30 +00:00
|
|
|
m_prebuffering_inited = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_buffering_source->prepareToPlay(samplesPerBlock, getSampleRateChecked());
|
2017-11-13 21:42:13 +00:00
|
|
|
}
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::releaseResources()
|
|
|
|
{
|
2017-11-13 21:42:13 +00:00
|
|
|
//m_control->stopplay();
|
|
|
|
//m_ready_to_play = false;
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef JucePlugin_PreferredChannelConfigurations
|
|
|
|
bool PaulstretchpluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& layouts) const
|
|
|
|
{
|
|
|
|
#if JucePlugin_IsMidiEffect
|
|
|
|
ignoreUnused (layouts);
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
// This is the place where you check if the layout is supported.
|
|
|
|
// In this template code we only support mono or stereo.
|
|
|
|
if (layouts.getMainOutputChannelSet() != AudioChannelSet::mono()
|
|
|
|
&& layouts.getMainOutputChannelSet() != AudioChannelSet::stereo())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// This checks if the input layout matches the output layout
|
|
|
|
#if ! JucePlugin_IsSynth
|
|
|
|
if (layouts.getMainOutputChannelSet() != layouts.getMainInputChannelSet())
|
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-11-15 15:52:47 +00:00
|
|
|
void copyAudioBufferWrappingPosition(const AudioBuffer<float>& src, AudioBuffer<float>& dest, int destbufpos, int maxdestpos)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < dest.getNumChannels(); ++i)
|
|
|
|
{
|
|
|
|
int channel_to_copy = i % src.getNumChannels();
|
|
|
|
if (destbufpos + src.getNumSamples() > maxdestpos)
|
|
|
|
{
|
|
|
|
int wrappos = (destbufpos + src.getNumSamples()) % maxdestpos;
|
|
|
|
int partial_len = src.getNumSamples() - wrappos;
|
|
|
|
dest.copyFrom(channel_to_copy, destbufpos, src, channel_to_copy, 0, partial_len);
|
|
|
|
dest.copyFrom(channel_to_copy, partial_len, src, channel_to_copy, 0, wrappos);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dest.copyFrom(channel_to_copy, destbufpos, src, channel_to_copy, 0, src.getNumSamples());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-17 20:39:26 +00:00
|
|
|
/*
|
|
|
|
void PaulstretchpluginAudioProcessor::processBlock (AudioBuffer<double>& buffer, MidiBuffer&)
|
|
|
|
{
|
|
|
|
jassert(false);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
|
|
|
|
{
|
2018-10-15 16:21:11 +00:00
|
|
|
ScopedLock locker(m_cs);
|
2018-05-31 10:21:35 +00:00
|
|
|
const int totalNumInputChannels = getTotalNumInputChannels();
|
|
|
|
const int totalNumOutputChannels = getTotalNumOutputChannels();
|
2017-12-19 21:00:42 +00:00
|
|
|
AudioPlayHead* phead = getPlayHead();
|
|
|
|
if (phead != nullptr)
|
|
|
|
{
|
|
|
|
phead->getCurrentPosition(m_playposinfo);
|
|
|
|
}
|
2018-02-01 11:17:15 +00:00
|
|
|
else
|
|
|
|
m_playposinfo.isPlaying = false;
|
2017-11-13 23:50:44 +00:00
|
|
|
ScopedNoDenormals noDenormals;
|
2017-12-17 16:16:39 +00:00
|
|
|
double srtemp = getSampleRate();
|
|
|
|
if (srtemp != m_cur_sr)
|
|
|
|
m_cur_sr = srtemp;
|
2018-05-01 15:22:21 +00:00
|
|
|
m_prebufsmoother.setSlope(0.9, srtemp / buffer.getNumSamples());
|
|
|
|
m_smoothed_prebuffer_ready = m_prebufsmoother.process(m_buffering_source->getPercentReady());
|
2018-05-31 10:21:35 +00:00
|
|
|
|
2017-12-20 18:33:34 +00:00
|
|
|
for (int i = 0; i < totalNumInputChannels; ++i)
|
|
|
|
m_input_buffer.copyFrom(i, 0, buffer, i, 0, buffer.getNumSamples());
|
2017-11-13 15:06:08 +00:00
|
|
|
for (int i = totalNumInputChannels; i < totalNumOutputChannels; ++i)
|
|
|
|
buffer.clear (i, 0, buffer.getNumSamples());
|
2018-09-26 16:19:10 +00:00
|
|
|
if (m_previewcomponent != nullptr)
|
|
|
|
{
|
|
|
|
m_previewcomponent->processBlock(getSampleRate(), buffer);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-27 15:35:30 +00:00
|
|
|
if (m_prebuffering_inited == false)
|
2017-11-13 16:15:07 +00:00
|
|
|
return;
|
2017-11-13 19:21:30 +00:00
|
|
|
if (m_is_recording == true)
|
|
|
|
{
|
2017-12-20 18:33:34 +00:00
|
|
|
if (m_playposinfo.isPlaying == false && m_capture_when_host_plays == true)
|
|
|
|
return;
|
2017-11-15 15:52:47 +00:00
|
|
|
int recbuflenframes = m_max_reclen * getSampleRate();
|
|
|
|
copyAudioBufferWrappingPosition(buffer, m_recbuffer, m_rec_pos, recbuflenframes);
|
2018-01-17 19:53:26 +00:00
|
|
|
m_thumb->addBlock(m_rec_pos, buffer, 0, buffer.getNumSamples());
|
2017-11-15 15:52:47 +00:00
|
|
|
m_rec_pos = (m_rec_pos + buffer.getNumSamples()) % recbuflenframes;
|
2018-06-05 18:11:17 +00:00
|
|
|
m_rec_count += buffer.getNumSamples();
|
|
|
|
if (m_rec_count<recbuflenframes)
|
|
|
|
m_recorded_range = { 0, m_rec_count };
|
2018-06-01 13:31:31 +00:00
|
|
|
if (m_mute_while_capturing == true)
|
|
|
|
buffer.clear();
|
2017-11-13 19:21:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-11-20 22:39:07 +00:00
|
|
|
jassert(m_buffering_source != nullptr);
|
|
|
|
jassert(m_bufferingthread.isThreadRunning());
|
2018-05-18 13:20:51 +00:00
|
|
|
double t0 = *getFloatParameter(cpi_soundstart);
|
|
|
|
double t1 = *getFloatParameter(cpi_soundend);
|
|
|
|
sanitizeTimeRange(t0, t1);
|
|
|
|
m_stretch_source->setPlayRange({ t0,t1 });
|
2017-12-19 23:12:47 +00:00
|
|
|
if (m_last_host_playing == false && m_playposinfo.isPlaying)
|
|
|
|
{
|
|
|
|
m_stretch_source->seekPercent(*getFloatParameter(cpi_soundstart));
|
|
|
|
m_last_host_playing = true;
|
|
|
|
}
|
|
|
|
else if (m_last_host_playing == true && m_playposinfo.isPlaying == false)
|
|
|
|
{
|
|
|
|
m_last_host_playing = false;
|
|
|
|
}
|
|
|
|
if (m_play_when_host_plays == true && m_playposinfo.isPlaying == false)
|
|
|
|
return;
|
2018-02-28 12:20:26 +00:00
|
|
|
m_free_filter_envelope->m_transform_x_shift = *getFloatParameter(cpi_freefilter_shiftx);
|
|
|
|
m_free_filter_envelope->m_transform_y_shift = *getFloatParameter(cpi_freefilter_shifty);
|
2018-02-28 12:36:13 +00:00
|
|
|
m_free_filter_envelope->m_transform_y_scale = *getFloatParameter(cpi_freefilter_scaley);
|
|
|
|
m_free_filter_envelope->m_transform_y_tilt = *getFloatParameter(cpi_freefilter_tilty);
|
2018-03-03 15:22:23 +00:00
|
|
|
m_free_filter_envelope->m_transform_y_random_bands = *getIntParameter(cpi_freefilter_randomy_numbands);
|
|
|
|
m_free_filter_envelope->m_transform_y_random_rate = *getIntParameter(cpi_freefilter_randomy_rate);
|
|
|
|
m_free_filter_envelope->m_transform_y_random_amount = *getFloatParameter(cpi_freefilter_randomy_amount);
|
|
|
|
|
2019-01-17 13:23:01 +00:00
|
|
|
|
2018-11-15 18:14:56 +00:00
|
|
|
|
2018-04-26 20:07:08 +00:00
|
|
|
//m_stretch_source->setSpectralModulesEnabled(m_sm_enab_pars);
|
2018-03-06 11:44:36 +00:00
|
|
|
|
2018-05-09 09:33:06 +00:00
|
|
|
if (m_stretch_source->isLoopEnabled() != *getBoolParameter(cpi_looping_enabled))
|
|
|
|
m_stretch_source->setLoopingEnabled(*getBoolParameter(cpi_looping_enabled));
|
2018-05-18 13:20:51 +00:00
|
|
|
bool rew = *getBoolParameter(cpi_rewind);
|
2018-05-31 10:55:32 +00:00
|
|
|
if (rew != m_lastrewind)
|
2018-05-18 13:20:51 +00:00
|
|
|
{
|
|
|
|
if (rew == true)
|
|
|
|
{
|
|
|
|
*getBoolParameter(cpi_rewind) = false;
|
|
|
|
m_stretch_source->seekPercent(m_stretch_source->getPlayRange().getStart());
|
|
|
|
}
|
|
|
|
m_lastrewind = rew;
|
|
|
|
}
|
2018-05-09 09:33:06 +00:00
|
|
|
|
2017-12-14 17:57:14 +00:00
|
|
|
m_stretch_source->setMainVolume(*getFloatParameter(cpi_main_volume));
|
|
|
|
m_stretch_source->setRate(*getFloatParameter(cpi_stretchamount));
|
2018-02-21 17:49:16 +00:00
|
|
|
m_stretch_source->setPreviewDry(*getBoolParameter(cpi_bypass_stretch));
|
2018-08-20 12:49:51 +00:00
|
|
|
m_stretch_source->setDryPlayrate(*getFloatParameter(cpi_dryplayrate));
|
2017-12-12 21:38:24 +00:00
|
|
|
setFFTSize(*getFloatParameter(cpi_fftsize));
|
2018-01-30 15:54:06 +00:00
|
|
|
|
2018-02-26 14:34:13 +00:00
|
|
|
updateStretchParametersFromPluginParameters(m_ppar);
|
|
|
|
|
2017-12-13 16:30:09 +00:00
|
|
|
m_stretch_source->setOnsetDetection(*getFloatParameter(cpi_onsetdetection));
|
2017-12-12 18:00:51 +00:00
|
|
|
m_stretch_source->setLoopXFadeLength(*getFloatParameter(cpi_loopxfadelen));
|
2018-05-18 13:20:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-12 18:00:51 +00:00
|
|
|
m_stretch_source->setFreezing(getParameter(cpi_freeze));
|
2017-12-14 20:17:45 +00:00
|
|
|
m_stretch_source->setPaused(getParameter(cpi_pause_enabled));
|
2019-01-20 18:21:29 +00:00
|
|
|
if (m_midinote_control == true)
|
|
|
|
{
|
|
|
|
MidiBuffer::Iterator midi_it(midiMessages);
|
|
|
|
MidiMessage midi_msg;
|
|
|
|
int midi_msg_pos;
|
|
|
|
while (true)
|
2019-01-17 17:26:41 +00:00
|
|
|
{
|
2019-01-20 18:21:29 +00:00
|
|
|
if (midi_it.getNextEvent(midi_msg, midi_msg_pos) == false)
|
|
|
|
break;
|
|
|
|
if (midi_msg.isNoteOff() && midi_msg.getNoteNumber() == m_midinote_to_use)
|
|
|
|
{
|
|
|
|
m_adsr.noteOff();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (midi_msg.isNoteOn())
|
|
|
|
{
|
|
|
|
m_midinote_to_use = midi_msg.getNoteNumber();
|
|
|
|
m_adsr.setParameters({ 1.0,0.5,0.5,1.0 });
|
|
|
|
m_adsr.noteOn();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-01-17 17:26:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-17 17:47:56 +00:00
|
|
|
if (m_midinote_control == true && m_midinote_to_use >= 0)
|
2019-01-17 17:26:41 +00:00
|
|
|
{
|
|
|
|
int note_offset = m_midinote_to_use - 60;
|
|
|
|
m_ppar.pitch_shift.cents += 100.0*note_offset;
|
|
|
|
}
|
|
|
|
|
2017-11-20 22:39:07 +00:00
|
|
|
m_stretch_source->setProcessParameters(&m_ppar);
|
|
|
|
AudioSourceChannelInfo aif(buffer);
|
2017-12-20 01:58:50 +00:00
|
|
|
if (isNonRealtime() || m_use_backgroundbuffering == false)
|
2017-12-18 22:37:02 +00:00
|
|
|
{
|
|
|
|
m_stretch_source->getNextAudioBlock(aif);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_buffering_source->getNextAudioBlock(aif);
|
|
|
|
}
|
2018-06-01 13:31:31 +00:00
|
|
|
if (m_is_recording == false && getParameter(cpi_passthrough) > 0.5f)
|
2017-12-20 18:33:34 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < totalNumInputChannels; ++i)
|
|
|
|
{
|
|
|
|
buffer.addFrom(i, 0, m_input_buffer, i, 0, buffer.getNumSamples());
|
|
|
|
}
|
|
|
|
}
|
2018-08-21 09:17:34 +00:00
|
|
|
bool abnordetected = false;
|
2017-12-18 20:27:12 +00:00
|
|
|
for (int i = 0; i < buffer.getNumChannels(); ++i)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < buffer.getNumSamples(); ++j)
|
|
|
|
{
|
|
|
|
float sample = buffer.getSample(i,j);
|
|
|
|
if (std::isnan(sample) || std::isinf(sample))
|
2018-08-21 09:17:34 +00:00
|
|
|
{
|
2017-12-18 20:27:12 +00:00
|
|
|
++m_abnormal_output_samples;
|
2018-08-21 09:17:34 +00:00
|
|
|
abnordetected = true;
|
|
|
|
}
|
2017-12-18 20:27:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-21 09:17:34 +00:00
|
|
|
if (abnordetected)
|
|
|
|
{
|
|
|
|
buffer.clear();
|
|
|
|
}
|
2019-01-17 17:47:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (m_midinote_control == true)
|
|
|
|
{
|
|
|
|
m_adsr.applyEnvelopeToBuffer(buffer, 0, buffer.getNumSamples());
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 12:59:51 +00:00
|
|
|
/*
|
2019-01-17 16:30:40 +00:00
|
|
|
auto ed = dynamic_cast<PaulstretchpluginAudioProcessorEditor*>(getActiveEditor());
|
|
|
|
if (ed != nullptr)
|
|
|
|
{
|
|
|
|
ed->m_sonogram.addAudioBlock(buffer);
|
|
|
|
}
|
2019-02-12 12:59:51 +00:00
|
|
|
*/
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
bool PaulstretchpluginAudioProcessor::hasEditor() const
|
|
|
|
{
|
|
|
|
return true; // (change this to false if you choose to not supply an editor)
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioProcessorEditor* PaulstretchpluginAudioProcessor::createEditor()
|
|
|
|
{
|
2017-11-13 18:45:23 +00:00
|
|
|
return new PaulstretchpluginAudioProcessorEditor (*this);
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
void PaulstretchpluginAudioProcessor::getStateInformation (MemoryBlock& destData)
|
|
|
|
{
|
2017-12-27 20:43:07 +00:00
|
|
|
ValueTree paramtree = getStateTree(false,false);
|
2017-12-26 18:24:10 +00:00
|
|
|
MemoryOutputStream stream(destData,true);
|
2017-11-15 18:51:52 +00:00
|
|
|
paramtree.writeToStream(stream);
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int sizeInBytes)
|
|
|
|
{
|
2017-11-23 15:57:37 +00:00
|
|
|
ValueTree tree = ValueTree::readFromData(data, sizeInBytes);
|
2017-12-27 20:20:44 +00:00
|
|
|
setStateFromTree(tree);
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
2018-02-07 14:00:49 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::setDirty()
|
|
|
|
{
|
2018-02-13 17:41:52 +00:00
|
|
|
toggleBool(getBoolParameter(cpi_markdirty));
|
2018-02-07 14:00:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 19:21:30 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b)
|
|
|
|
{
|
2017-12-12 18:43:43 +00:00
|
|
|
ScopedLock locker(m_cs);
|
2017-12-17 16:16:39 +00:00
|
|
|
int lenbufframes = getSampleRateChecked()*m_max_reclen;
|
2017-11-13 19:21:30 +00:00
|
|
|
if (b == true)
|
|
|
|
{
|
2017-11-15 18:51:52 +00:00
|
|
|
m_using_memory_buffer = true;
|
|
|
|
m_current_file = File();
|
2018-02-13 13:37:16 +00:00
|
|
|
int numchans = *m_inchansparam;
|
|
|
|
m_recbuffer.setSize(numchans, m_max_reclen*getSampleRateChecked()+4096,false,false,true);
|
2017-11-13 20:35:36 +00:00
|
|
|
m_recbuffer.clear();
|
2017-11-13 19:21:30 +00:00
|
|
|
m_rec_pos = 0;
|
2018-01-17 19:53:26 +00:00
|
|
|
m_thumb->reset(m_recbuffer.getNumChannels(), getSampleRateChecked(), lenbufframes);
|
2017-11-14 00:30:18 +00:00
|
|
|
m_is_recording = true;
|
2018-06-05 18:11:17 +00:00
|
|
|
m_recorded_range = Range<int>();
|
|
|
|
m_rec_count = 0;
|
2017-11-13 19:21:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-13 21:42:13 +00:00
|
|
|
if (m_is_recording == true)
|
|
|
|
{
|
2017-11-15 15:52:47 +00:00
|
|
|
finishRecording(lenbufframes);
|
2017-11-13 21:42:13 +00:00
|
|
|
}
|
2017-11-13 19:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 20:35:36 +00:00
|
|
|
double PaulstretchpluginAudioProcessor::getRecordingPositionPercent()
|
|
|
|
{
|
|
|
|
if (m_is_recording==false)
|
|
|
|
return 0.0;
|
|
|
|
return 1.0 / m_recbuffer.getNumSamples()*m_rec_pos;
|
|
|
|
}
|
|
|
|
|
2017-11-14 16:14:14 +00:00
|
|
|
String PaulstretchpluginAudioProcessor::setAudioFile(File f)
|
|
|
|
{
|
2017-12-15 04:17:11 +00:00
|
|
|
auto ai = unique_from_raw(m_afm->createReaderFor(f));
|
2017-11-20 22:39:07 +00:00
|
|
|
if (ai != nullptr)
|
2017-11-14 16:14:14 +00:00
|
|
|
{
|
2018-02-19 19:12:54 +00:00
|
|
|
if (ai->numChannels > 8)
|
2017-11-20 22:39:07 +00:00
|
|
|
{
|
|
|
|
return "Too many channels in file "+f.getFullPathName();
|
|
|
|
}
|
|
|
|
if (ai->bitsPerSample>32)
|
|
|
|
{
|
|
|
|
return "Too high bit depth in file " + f.getFullPathName();
|
|
|
|
}
|
2018-01-17 16:57:56 +00:00
|
|
|
m_thumb->setSource(new FileInputSource(f));
|
2017-12-12 18:43:43 +00:00
|
|
|
ScopedLock locker(m_cs);
|
2017-11-24 22:22:07 +00:00
|
|
|
m_stretch_source->setAudioFile(f);
|
2018-01-30 15:32:23 +00:00
|
|
|
//Range<double> currange{ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) };
|
|
|
|
//if (currange.contains(m_stretch_source->getInfilePositionPercent())==false)
|
|
|
|
m_stretch_source->seekPercent(*getFloatParameter(cpi_soundstart));
|
2017-11-20 22:39:07 +00:00
|
|
|
m_current_file = f;
|
2017-12-15 04:17:11 +00:00
|
|
|
m_current_file_date = m_current_file.getLastModificationTime();
|
2017-11-20 22:39:07 +00:00
|
|
|
m_using_memory_buffer = false;
|
2018-02-07 14:00:49 +00:00
|
|
|
setDirty();
|
2017-11-20 22:39:07 +00:00
|
|
|
return String();
|
|
|
|
}
|
|
|
|
return "Could not open file " + f.getFullPathName();
|
2017-11-14 16:14:14 +00:00
|
|
|
}
|
|
|
|
|
2017-11-16 14:58:04 +00:00
|
|
|
Range<double> PaulstretchpluginAudioProcessor::getTimeSelection()
|
|
|
|
{
|
2017-12-14 17:57:14 +00:00
|
|
|
return { *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) };
|
2017-11-16 14:58:04 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 22:39:07 +00:00
|
|
|
double PaulstretchpluginAudioProcessor::getPreBufferingPercent()
|
|
|
|
{
|
|
|
|
if (m_buffering_source==nullptr)
|
|
|
|
return 0.0;
|
2018-05-01 15:22:21 +00:00
|
|
|
return m_smoothed_prebuffer_ready;
|
2017-11-20 22:39:07 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 16:30:09 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::timerCallback(int id)
|
|
|
|
{
|
|
|
|
if (id == 1)
|
|
|
|
{
|
2018-11-08 19:48:51 +00:00
|
|
|
bool capture = *getBoolParameter(cpi_capture_trigger);
|
2017-12-18 17:48:40 +00:00
|
|
|
if (capture == false && m_max_reclen != *getFloatParameter(cpi_max_capture_len))
|
|
|
|
{
|
|
|
|
m_max_reclen = *getFloatParameter(cpi_max_capture_len);
|
|
|
|
//Logger::writeToLog("Changing max capture len to " + String(m_max_reclen));
|
|
|
|
}
|
2017-12-13 16:30:09 +00:00
|
|
|
if (capture == true && m_is_recording == false)
|
|
|
|
{
|
|
|
|
setRecordingEnabled(true);
|
|
|
|
return;
|
|
|
|
}
|
2019-02-12 12:56:37 +00:00
|
|
|
if (capture == false && m_is_recording == true)
|
2017-12-13 16:30:09 +00:00
|
|
|
{
|
|
|
|
setRecordingEnabled(false);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-13 22:44:46 +00:00
|
|
|
if (m_cur_num_out_chans != *m_outchansparam)
|
|
|
|
{
|
2017-12-14 17:06:26 +00:00
|
|
|
jassert(m_curmaxblocksize > 0);
|
2017-12-13 22:44:46 +00:00
|
|
|
ScopedLock locker(m_cs);
|
2017-12-27 15:35:30 +00:00
|
|
|
m_prebuffering_inited = false;
|
2017-12-13 22:44:46 +00:00
|
|
|
m_cur_num_out_chans = *m_outchansparam;
|
|
|
|
//Logger::writeToLog("Switching to use " + String(m_cur_num_out_chans) + " out channels");
|
|
|
|
String err;
|
|
|
|
startplay({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) },
|
2017-12-14 17:06:26 +00:00
|
|
|
m_cur_num_out_chans, m_curmaxblocksize, err);
|
2017-12-27 15:35:30 +00:00
|
|
|
m_prebuffering_inited = true;
|
2017-12-13 22:44:46 +00:00
|
|
|
}
|
2017-12-13 16:30:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 16:19:10 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::setAudioPreview(AudioFilePreviewComponent * afpc)
|
|
|
|
{
|
|
|
|
ScopedLock locker(m_cs);
|
|
|
|
m_previewcomponent = afpc;
|
|
|
|
}
|
|
|
|
|
2018-04-25 12:25:29 +00:00
|
|
|
pointer_sized_int PaulstretchpluginAudioProcessor::handleVstPluginCanDo(int32 index, pointer_sized_int value, void * ptr, float opt)
|
|
|
|
{
|
|
|
|
if (strcmp((char*)ptr, "xenakios") == 0)
|
|
|
|
{
|
2018-04-26 11:01:46 +00:00
|
|
|
if (index == 0 && (void*)value!=nullptr)
|
2018-04-25 12:25:29 +00:00
|
|
|
{
|
|
|
|
double t0 = *getFloatParameter(cpi_soundstart);
|
|
|
|
double t1 = *getFloatParameter(cpi_soundend);
|
2018-04-26 11:01:46 +00:00
|
|
|
double outlen = (t1-t0)*m_stretch_source->getInfileLengthSeconds()*(*getFloatParameter(cpi_stretchamount));
|
|
|
|
//std::cout << "host requested output length, result " << outlen << "\n";
|
|
|
|
*((double*)value) = outlen;
|
2018-04-25 12:25:29 +00:00
|
|
|
}
|
|
|
|
if (index == 1 && (void*)value!=nullptr)
|
|
|
|
{
|
|
|
|
String fn(CharPointer_UTF8((char*)value));
|
2018-04-26 11:01:46 +00:00
|
|
|
//std::cout << "host requested to set audio file " << fn << "\n";
|
2018-04-25 12:25:29 +00:00
|
|
|
auto err = setAudioFile(File(fn));
|
2018-04-26 11:01:46 +00:00
|
|
|
if (err.isEmpty()==false)
|
|
|
|
std::cout << err << "\n";
|
2018-04-25 12:25:29 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pointer_sized_int();
|
|
|
|
}
|
|
|
|
|
|
|
|
pointer_sized_int PaulstretchpluginAudioProcessor::handleVstManufacturerSpecific(int32 index, pointer_sized_int value, void * ptr, float opt)
|
|
|
|
{
|
|
|
|
return pointer_sized_int();
|
|
|
|
}
|
|
|
|
|
2017-11-13 21:42:13 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording)
|
|
|
|
{
|
|
|
|
m_is_recording = false;
|
2018-11-08 18:22:26 +00:00
|
|
|
m_current_file = File();
|
2017-12-17 16:16:39 +00:00
|
|
|
m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRateChecked(), lenrecording);
|
2018-06-05 18:11:17 +00:00
|
|
|
*getFloatParameter(cpi_soundstart) = 0.0f;
|
|
|
|
*getFloatParameter(cpi_soundend) = jlimit<double>(0.01, 1.0, 1.0 / lenrecording * m_rec_count);
|
2018-12-19 13:16:30 +00:00
|
|
|
if (m_save_captured_audio == true)
|
|
|
|
{
|
|
|
|
saveCaptureBuffer();
|
|
|
|
}
|
2017-11-13 21:42:13 +00:00
|
|
|
}
|
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
|
|
|
{
|
|
|
|
return new PaulstretchpluginAudioProcessor();
|
|
|
|
}
|