2017-11-13 15:06:08 +00:00
|
|
|
/*
|
2017-12-17 19:40:35 +00:00
|
|
|
Copyright (C) 2006-2011 Nasca Octavian Paul
|
|
|
|
Author: Nasca Octavian Paul
|
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
|
|
|
|
it under the terms of version 2 of the GNU General Public License
|
|
|
|
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
|
|
|
|
GNU General Public License (version 2) for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License (version 2)
|
|
|
|
along with this program; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
2017-11-13 15:06:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "PluginProcessor.h"
|
|
|
|
#include "PluginEditor.h"
|
2017-11-16 17:45:40 +00:00
|
|
|
#include <set>
|
|
|
|
|
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
|
|
|
|
2018-01-08 16:04:28 +00:00
|
|
|
String g_plugintitle{ "PaulXStretch 1.0.0 preview 5" };
|
2017-12-24 14:56:22 +00:00
|
|
|
|
2017-11-16 17:45:40 +00:00
|
|
|
std::set<PaulstretchpluginAudioProcessor*> g_activeprocessors;
|
|
|
|
|
2017-12-27 20:20:44 +00:00
|
|
|
struct PresetEntry
|
|
|
|
{
|
|
|
|
PresetEntry(String name, String data) : m_name(name), m_data(data) {}
|
|
|
|
String m_name;
|
|
|
|
String m_data;
|
|
|
|
};
|
|
|
|
|
2017-12-27 20:56:27 +00:00
|
|
|
const int g_num_presets = 4;
|
|
|
|
|
|
|
|
static const PresetEntry g_presets[g_num_presets] =
|
2017-12-27 20:20:44 +00:00
|
|
|
{
|
|
|
|
{"Factory reset","cGF1bHN0cmV0Y2gzcGx1Z2luc3RhdGUAASZtYWludm9sdW1lMAABCQQAAACAi1cewHN0cmV0Y2hhbW91bnQwAAEJBAAAACAAAPA/ZmZ0c2l6ZTAAAQkEAAAAYGZm5j9waXRjaHNoaWZ0MAABCQQAAAAAAAAAAGZyZXFzaGlmdDAAAQkEAAAAAAAAAABwbGF5cmFuZ2Vfc3RhcnQwAAEJBAAAAAAAAAAAcGxheXJhbmdlX2VuZDAAAQkEAAAAAAAA8D9zcHJlYWQwAAEJBAAAAAAAAAAAY29tcHJlc3MwAAEJBAAAAAAAAAAAbG9vcHhmYWRlbGVuMAABCQQAAABA4XqEP251bWhhcm1vbmljczAAAQkEAAAAAABAWUBoYXJtb25pY3NmcmVxMAABCQQAAAAAAABgQGhhcm1vbmljc2J3MAABCQQAAAAAAAA5QG9jdGF2ZW1peG0yXzAAAQkEAAAAAAAAAABvY3RhdmVtaXhtMV8wAAEJBAAAAAAAAAAAb2N0YXZlbWl4MF8wAAEJBAAAAAAAAPA/b2N0YXZlbWl4MV8wAAEJBAAAAAAAAAAAb2N0YXZlbWl4MTVfMAABCQQAAAAAAAAAAG9jdGF2ZW1peDJfMAABCQQAAAAAAAAAAHRvbmFsdnNub2lzZWJ3XzAAAQkEAAAAgBSu5z90b25hbHZzbm9pc2VwcmVzZXJ2ZV8wAAEJBAAAAAAAAOA/ZmlsdGVyX2xvd18wAAEJBAAAAAAAADRAZmlsdGVyX2hpZ2hfMAABCQQAAAAAAIjTQG9uc2V0ZGV0ZWN0XzAAAQkEAAAAAAAAAABtYXhjYXB0dXJl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AAQkEAAAAAABAWUBoYXJtb25pY3NmcmVxMAABCQQAAAAAAABgQGhhcm1vbmljc2J3MAABCQQAAAAAAAA5QG9jdGF2ZW1peG0yXzAAAQkEAAAAAAAAAABvY3RhdmVtaXhtMV8wAAEJBAAAAAAAAAAAb2N0YXZlbWl4MF8wAAEJBAAAAAAAAPA/b2N0YXZlbWl4MV8wAAEJBAAAAAAAAAAAb2N0YXZlbWl4MTVfMAABCQQAAAAAAAAAAG9jdGF2ZW1peDJfMAABCQQAAAAAAAAAAHRvbmFsdnNub2lzZWJ3XzAAAQkEAAAAgBSu5z90b25hbHZzbm9pc2VwcmVzZXJ2ZV8wAAEJBAAAAAAAAOA/ZmlsdGVyX2xvd18wAAEJBAAAAAAAADRAZmlsdGVyX2hpZ2hfMAABCQQAAABgAHCXQG9uc2V0ZGV0ZWN0XzAAAQkEAAAAAAAAAABtYXhjYXB0dXJlbGVuXzAAAQkEAAAAAAAAJEBudW1vdXRjaGFuczAAAQUBAgAAAG51bXNwZWN0cmFsc3RhZ2VzAAEFAQgAAABzcGVjb3JkZXIwAAEFAQMAAABzcGVjb3JkZXIxAAEFAQAAAABzcGVjb3JkZXIyAAEFAQEAAABzcGVjb3JkZXIzAAEFAQIAAABzcGVjb3JkZXI0AAEFAQQAAABzcGVjb3JkZXI1AAEFAQUAAABzcGVjb3JkZXI2AAEFAQYAAABzcGVjb3JkZXI3AAEFAQcAAAAAzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N"}
|
2017-12-27 20:20:44 +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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
#ifndef JucePlugin_PreferredChannelConfigurations
|
|
|
|
: AudioProcessor (BusesProperties()
|
|
|
|
#if ! JucePlugin_IsMidiEffect
|
|
|
|
#if ! JucePlugin_IsSynth
|
|
|
|
.withInput ("Input", AudioChannelSet::stereo(), true)
|
|
|
|
#endif
|
|
|
|
.withOutput ("Output", AudioChannelSet::stereo(), true)
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
#endif
|
|
|
|
{
|
2017-12-19 03:24:27 +00:00
|
|
|
|
|
|
|
g_activeprocessors.insert(this);
|
2018-01-17 16:57:56 +00:00
|
|
|
|
2017-11-13 22:50:12 +00:00
|
|
|
m_recbuffer.setSize(2, 44100);
|
|
|
|
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-01-20 19:27:29 +00:00
|
|
|
// The default priority of 2 is a bit too low in some cases, it seems...
|
|
|
|
m_thumbcache->getTimeSliceThread().setPriority(3);
|
2017-11-23 23:44:30 +00:00
|
|
|
m_stretch_source = std::make_unique<StretchAudioSource>(2, m_afm);
|
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);
|
2017-11-16 17:45:40 +00:00
|
|
|
addParameter(new AudioParameterFloat("mainvolume0", "Main volume", -24.0f, 12.0f, -3.0f)); // 0
|
2017-11-24 22:22:07 +00:00
|
|
|
addParameter(new AudioParameterFloat("stretchamount0", "Stretch amount",
|
2017-12-15 19:00:15 +00:00
|
|
|
NormalisableRange<float>(0.1f, 1024.0f, 0.01f, 0.25),1.0f)); // 1
|
2017-11-16 17:45:40 +00:00
|
|
|
addParameter(new AudioParameterFloat("fftsize0", "FFT size", 0.0f, 1.0f, 0.7f)); // 2
|
|
|
|
addParameter(new AudioParameterFloat("pitchshift0", "Pitch shift", -24.0f, 24.0f, 0.0f)); // 3
|
|
|
|
addParameter(new AudioParameterFloat("freqshift0", "Frequency shift", -1000.0f, 1000.0f, 0.0f)); // 4
|
|
|
|
addParameter(new AudioParameterFloat("playrange_start0", "Sound start", 0.0f, 1.0f, 0.0f)); // 5
|
|
|
|
addParameter(new AudioParameterFloat("playrange_end0", "Sound end", 0.0f, 1.0f, 1.0f)); // 6
|
|
|
|
addParameter(new AudioParameterBool("freeze0", "Freeze", false)); // 7
|
2017-11-24 22:22:07 +00:00
|
|
|
addParameter(new AudioParameterFloat("spread0", "Frequency spread", 0.0f, 1.0f, 0.0f)); // 8
|
2017-11-25 19:25:46 +00:00
|
|
|
addParameter(new AudioParameterFloat("compress0", "Compress", 0.0f, 1.0f, 0.0f)); // 9
|
2017-12-26 18:24:10 +00:00
|
|
|
addParameter(new AudioParameterFloat("loopxfadelen0", "Loop xfade length", 0.0f, 1.0f, 0.01f)); // 10
|
2018-01-30 16:56:00 +00:00
|
|
|
addParameter(new AudioParameterInt("numharmonics0", "Num harmonics", 1, 100, 10)); // 11
|
2017-12-12 17:54:54 +00:00
|
|
|
addParameter(new AudioParameterFloat("harmonicsfreq0", "Harmonics base freq",
|
|
|
|
NormalisableRange<float>(1.0f, 5000.0f, 1.00f, 0.5), 128.0f)); // 12
|
2017-12-12 17:14:43 +00:00
|
|
|
addParameter(new AudioParameterFloat("harmonicsbw0", "Harmonics bandwidth", 0.1f, 200.0f, 25.0f)); // 13
|
|
|
|
addParameter(new AudioParameterBool("harmonicsgauss0", "Gaussian harmonics", false)); // 14
|
|
|
|
addParameter(new AudioParameterFloat("octavemixm2_0", "2 octaves down level", 0.0f, 1.0f, 0.0f)); // 15
|
|
|
|
addParameter(new AudioParameterFloat("octavemixm1_0", "Octave down level", 0.0f, 1.0f, 0.0f)); // 16
|
2017-12-12 21:38:24 +00:00
|
|
|
addParameter(new AudioParameterFloat("octavemix0_0", "Normal pitch level", 0.0f, 1.0f, 1.0f)); // 17
|
2017-12-12 17:14:43 +00:00
|
|
|
addParameter(new AudioParameterFloat("octavemix1_0", "1 octave up level", 0.0f, 1.0f, 0.0f)); // 18
|
|
|
|
addParameter(new AudioParameterFloat("octavemix15_0", "1 octave and fifth up level", 0.0f, 1.0f, 0.0f)); // 19
|
|
|
|
addParameter(new AudioParameterFloat("octavemix2_0", "2 octaves up level", 0.0f, 1.0f, 0.0f)); // 20
|
2017-12-13 16:30:09 +00:00
|
|
|
addParameter(new AudioParameterFloat("tonalvsnoisebw_0", "Tonal vs Noise BW", 0.74f, 1.0f, 0.74f)); // 21
|
|
|
|
addParameter(new AudioParameterFloat("tonalvsnoisepreserve_0", "Tonal vs Noise preserve", -1.0f, 1.0f, 0.5f)); // 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
|
2017-12-13 16:30:09 +00:00
|
|
|
addParameter(new AudioParameterFloat("onsetdetect_0", "Onset detection", 0.0f, 1.0f, 0.0f)); // 25
|
|
|
|
addParameter(new AudioParameterBool("capture_enabled0", "Capture", false)); // 26
|
2017-12-14 20:17:45 +00:00
|
|
|
m_outchansparam = new AudioParameterInt("numoutchans0", "Num output channels", 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
|
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);
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PaulstretchpluginAudioProcessor::~PaulstretchpluginAudioProcessor()
|
|
|
|
{
|
2017-11-16 17:45:40 +00:00
|
|
|
g_activeprocessors.erase(this);
|
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);
|
2017-12-27 15:35:30 +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");
|
|
|
|
for (int i = 0; i<getNumParameters(); ++i)
|
|
|
|
{
|
|
|
|
auto par = getFloatParameter(i);
|
|
|
|
if (par != nullptr)
|
|
|
|
{
|
|
|
|
paramtree.setProperty(par->paramID, (double)*par, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
paramtree.setProperty(m_outchansparam->paramID, (int)*m_outchansparam, nullptr);
|
2017-12-27 20:43:07 +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();
|
|
|
|
paramtree.setProperty("numspectralstages", (int)specorder.size(), nullptr);
|
|
|
|
for (int i = 0; i < specorder.size(); ++i)
|
|
|
|
{
|
2018-01-30 15:32:23 +00:00
|
|
|
paramtree.setProperty("specorder" + String(i), specorder[i].m_index, nullptr);
|
|
|
|
paramtree.setProperty("specstepenabled" + String(i), specorder[i].m_enabled, 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);
|
|
|
|
}
|
2017-12-27 20:20:44 +00:00
|
|
|
return paramtree;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::setStateFromTree(ValueTree tree)
|
|
|
|
{
|
|
|
|
if (tree.isValid())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ScopedLock locker(m_cs);
|
|
|
|
m_load_file_with_state = tree.getProperty("loadfilewithstate", true);
|
|
|
|
if (tree.hasProperty("numspectralstages"))
|
|
|
|
{
|
2018-01-30 15:32:23 +00:00
|
|
|
std::vector<SpectrumProcess> order;
|
2017-12-27 20:20:44 +00:00
|
|
|
int ordersize = tree.getProperty("numspectralstages");
|
|
|
|
for (int i = 0; i < ordersize; ++i)
|
|
|
|
{
|
2018-01-30 15:32:23 +00:00
|
|
|
bool step_enabled = tree.getProperty("specstepenabled" + String(i));
|
|
|
|
order.push_back({ (int)tree.getProperty("specorder" + String(i)), step_enabled });
|
2017-12-27 20:20:44 +00:00
|
|
|
}
|
|
|
|
m_stretch_source->setSpectrumProcessOrder(order);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < getNumParameters(); ++i)
|
|
|
|
{
|
|
|
|
auto par = getFloatParameter(i);
|
|
|
|
if (par != nullptr)
|
|
|
|
{
|
|
|
|
double parval = tree.getProperty(par->paramID, (double)*par);
|
|
|
|
*par = parval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tree.hasProperty(m_outchansparam->paramID))
|
|
|
|
*m_outchansparam = tree.getProperty(m_outchansparam->paramID, 2);
|
|
|
|
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
File f(fn);
|
|
|
|
setAudioFile(f);
|
|
|
|
}
|
|
|
|
}
|
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()
|
|
|
|
{
|
2017-12-27 20:56:27 +00:00
|
|
|
return g_num_presets;
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int PaulstretchpluginAudioProcessor::getCurrentProgram()
|
|
|
|
{
|
2017-12-27 20:20:44 +00:00
|
|
|
return m_cur_program;
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::setCurrentProgram (int index)
|
|
|
|
{
|
2017-12-27 20:56:27 +00:00
|
|
|
index = jlimit(0, g_num_presets-1, index);
|
2017-12-27 20:20:44 +00:00
|
|
|
m_cur_program = index;
|
|
|
|
bool temp = m_load_file_with_state;
|
|
|
|
m_load_file_with_state = false;
|
|
|
|
MemoryBlock mb;
|
|
|
|
MemoryOutputStream stream(mb, true);
|
|
|
|
if (Base64::convertFromBase64(stream, g_presets[index].m_data)==true)
|
|
|
|
{
|
|
|
|
ValueTree tree = ValueTree::readFromData(mb.getData(), mb.getSize());
|
|
|
|
tree.setProperty("loadfilewithstate", false, nullptr);
|
|
|
|
setStateFromTree(tree);
|
|
|
|
}
|
|
|
|
m_load_file_with_state = temp;
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const String PaulstretchpluginAudioProcessor::getProgramName (int index)
|
|
|
|
{
|
2017-12-27 20:56:27 +00:00
|
|
|
index = jlimit(0, g_num_presets-1, index);
|
2017-12-27 20:20:44 +00:00
|
|
|
return g_presets[index].m_name;
|
2017-11-13 15:06:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PaulstretchpluginAudioProcessor::changeProgramName (int index, const String& newName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-11-24 22:22:07 +00:00
|
|
|
m_stretch_source->setPlayRange(playrange, true);
|
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);
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-17 16:16:39 +00:00
|
|
|
double PaulstretchpluginAudioProcessor::getSampleRateChecked()
|
|
|
|
{
|
|
|
|
if (m_cur_sr < 1.0)
|
|
|
|
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)
|
|
|
|
{
|
2017-12-12 18:43:43 +00:00
|
|
|
ScopedLock locker(m_cs);
|
2017-12-17 16:16:39 +00:00
|
|
|
m_cur_sr = sampleRate;
|
2017-12-14 17:06:26 +00:00
|
|
|
m_curmaxblocksize = samplesPerBlock;
|
2017-12-20 18:33:34 +00:00
|
|
|
m_input_buffer.setSize(2, samplesPerBlock);
|
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-01-17 19:53:26 +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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
|
|
|
|
{
|
2017-12-12 18:43:43 +00:00
|
|
|
ScopedLock locker(m_cs);
|
2017-12-19 21:00:42 +00:00
|
|
|
AudioPlayHead* phead = getPlayHead();
|
|
|
|
if (phead != nullptr)
|
|
|
|
{
|
|
|
|
phead->getCurrentPosition(m_playposinfo);
|
|
|
|
}
|
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;
|
2017-11-13 15:06:08 +00:00
|
|
|
const int totalNumInputChannels = getTotalNumInputChannels();
|
|
|
|
const int totalNumOutputChannels = getTotalNumOutputChannels();
|
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());
|
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;
|
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());
|
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;
|
2017-12-14 17:57:14 +00:00
|
|
|
m_stretch_source->setMainVolume(*getFloatParameter(cpi_main_volume));
|
|
|
|
m_stretch_source->setRate(*getFloatParameter(cpi_stretchamount));
|
2017-11-25 19:25:46 +00:00
|
|
|
|
2017-12-12 21:38:24 +00:00
|
|
|
setFFTSize(*getFloatParameter(cpi_fftsize));
|
2017-12-12 18:00:51 +00:00
|
|
|
m_ppar.pitch_shift.cents = *getFloatParameter(cpi_pitchshift) * 100.0;
|
|
|
|
m_ppar.freq_shift.Hz = *getFloatParameter(cpi_frequencyshift);
|
2018-01-30 15:54:06 +00:00
|
|
|
|
2017-12-12 18:00:51 +00:00
|
|
|
m_ppar.spread.bandwidth = *getFloatParameter(cpi_spreadamount);
|
2018-01-30 15:54:06 +00:00
|
|
|
|
2017-12-14 03:02:04 +00:00
|
|
|
m_ppar.compressor.power = *getFloatParameter(cpi_compress);
|
2018-01-30 15:54:06 +00:00
|
|
|
|
2018-01-30 16:07:47 +00:00
|
|
|
m_ppar.harmonics.nharmonics = *getIntParameter(cpi_numharmonics);
|
2017-12-12 18:00:51 +00:00
|
|
|
m_ppar.harmonics.freq = *getFloatParameter(cpi_harmonicsfreq);
|
2017-12-14 03:02:04 +00:00
|
|
|
m_ppar.harmonics.bandwidth = *getFloatParameter(cpi_harmonicsbw);
|
|
|
|
m_ppar.harmonics.gauss = getParameter(cpi_harmonicsgauss);
|
2018-01-30 15:54:06 +00:00
|
|
|
|
2017-12-12 18:00:51 +00:00
|
|
|
m_ppar.octave.om2 = *getFloatParameter(cpi_octavesm2);
|
|
|
|
m_ppar.octave.om1 = *getFloatParameter(cpi_octavesm1);
|
|
|
|
m_ppar.octave.o0 = *getFloatParameter(cpi_octaves0);
|
|
|
|
m_ppar.octave.o1 = *getFloatParameter(cpi_octaves1);
|
|
|
|
m_ppar.octave.o15 = *getFloatParameter(cpi_octaves15);
|
|
|
|
m_ppar.octave.o2 = *getFloatParameter(cpi_octaves2);
|
2018-01-30 15:54:06 +00:00
|
|
|
|
2017-12-13 16:30:09 +00:00
|
|
|
m_ppar.filter.low = *getFloatParameter(cpi_filter_low);
|
|
|
|
m_ppar.filter.high = *getFloatParameter(cpi_filter_high);
|
2018-01-30 15:54:06 +00:00
|
|
|
|
2017-12-13 16:30:09 +00:00
|
|
|
m_ppar.tonal_vs_noise.bandwidth = *getFloatParameter(cpi_tonalvsnoisebw);
|
|
|
|
m_ppar.tonal_vs_noise.preserve = *getFloatParameter(cpi_tonalvsnoisepreserve);
|
|
|
|
m_stretch_source->setOnsetDetection(*getFloatParameter(cpi_onsetdetection));
|
2017-12-12 18:00:51 +00:00
|
|
|
m_stretch_source->setLoopXFadeLength(*getFloatParameter(cpi_loopxfadelen));
|
|
|
|
double t0 = *getFloatParameter(cpi_soundstart);
|
|
|
|
double t1 = *getFloatParameter(cpi_soundend);
|
2017-11-13 19:21:30 +00:00
|
|
|
if (t0 > t1)
|
|
|
|
std::swap(t0, t1);
|
|
|
|
if (t1 - t0 < 0.001)
|
|
|
|
t1 = t0 + 0.001;
|
2017-11-20 22:39:07 +00:00
|
|
|
m_stretch_source->setPlayRange({ t0,t1 }, true);
|
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));
|
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);
|
|
|
|
}
|
2017-12-23 05:23:38 +00:00
|
|
|
if (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());
|
|
|
|
}
|
|
|
|
}
|
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))
|
|
|
|
++m_abnormal_output_samples;
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
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();
|
2017-12-17 16:16:39 +00:00
|
|
|
m_recbuffer.setSize(2, 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;
|
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
|
|
|
//if (f==File())
|
|
|
|
// return String();
|
|
|
|
//if (f==m_current_file && f.getLastModificationTime()==m_current_file_date)
|
|
|
|
// return String();
|
|
|
|
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
|
|
|
{
|
2017-11-20 22:39:07 +00:00
|
|
|
if (ai->numChannels > 32)
|
|
|
|
{
|
|
|
|
//MessageManager::callAsync([cb, file]() { cb("Too many channels in file " + file.getFullPathName()); });
|
|
|
|
return "Too many channels in file "+f.getFullPathName();
|
|
|
|
}
|
|
|
|
if (ai->bitsPerSample>32)
|
|
|
|
{
|
|
|
|
//MessageManager::callAsync([cb, file]() { cb("Too high bit depth in file " + file.getFullPathName()); });
|
|
|
|
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;
|
|
|
|
return String();
|
|
|
|
//MessageManager::callAsync([cb, file]() { cb(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;
|
|
|
|
return m_buffering_source->getPercentReady();
|
|
|
|
}
|
|
|
|
|
2017-12-13 16:30:09 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::timerCallback(int id)
|
|
|
|
{
|
|
|
|
if (id == 1)
|
|
|
|
{
|
|
|
|
bool capture = getParameter(cpi_capture_enabled);
|
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;
|
|
|
|
}
|
|
|
|
if (capture == false && m_is_recording == true)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 21:42:13 +00:00
|
|
|
void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording)
|
|
|
|
{
|
|
|
|
m_is_recording = false;
|
2017-12-17 16:16:39 +00:00
|
|
|
m_stretch_source->setAudioBufferAsInputSource(&m_recbuffer, getSampleRateChecked(), lenrecording);
|
2017-12-14 17:57:14 +00:00
|
|
|
m_stretch_source->setPlayRange({ *getFloatParameter(cpi_soundstart),*getFloatParameter(cpi_soundend) }, true);
|
2017-11-13 21:42:13 +00:00
|
|
|
auto ed = dynamic_cast<PaulstretchpluginAudioProcessorEditor*>(getActiveEditor());
|
|
|
|
if (ed)
|
|
|
|
{
|
2017-11-15 15:52:47 +00:00
|
|
|
//ed->setAudioBuffer(&m_recbuffer, getSampleRate(), lenrecording);
|
2017-11-13 21:42:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
//==============================================================================
|
|
|
|
// This creates new instances of the plugin..
|
|
|
|
AudioProcessor* JUCE_CALLTYPE createPluginFilter()
|
|
|
|
{
|
|
|
|
return new PaulstretchpluginAudioProcessor();
|
|
|
|
}
|