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
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "PS_Source/PaulStretchControl.h"
|
2022-04-12 22:47:43 +00:00
|
|
|
|
|
|
|
#include "../JuceLibraryCode/JuceHeader.h"
|
2018-02-27 00:33:41 +00:00
|
|
|
#include "jcdp_envelope.h"
|
2018-03-06 11:44:36 +00:00
|
|
|
#include <array>
|
2017-11-13 15:06:08 +00:00
|
|
|
|
2017-11-23 17:36:46 +00:00
|
|
|
class MyThumbCache;
|
2018-09-26 16:19:10 +00:00
|
|
|
class AudioFilePreviewComponent;
|
2017-11-23 17:36:46 +00:00
|
|
|
|
2017-12-12 17:14:43 +00:00
|
|
|
const int cpi_main_volume = 0;
|
|
|
|
const int cpi_stretchamount = 1;
|
|
|
|
const int cpi_fftsize = 2;
|
|
|
|
const int cpi_pitchshift = 3;
|
|
|
|
const int cpi_frequencyshift = 4;
|
|
|
|
const int cpi_soundstart = 5;
|
|
|
|
const int cpi_soundend = 6;
|
|
|
|
const int cpi_freeze = 7;
|
|
|
|
const int cpi_spreadamount = 8;
|
|
|
|
const int cpi_compress = 9;
|
|
|
|
const int cpi_loopxfadelen = 10;
|
|
|
|
const int cpi_numharmonics = 11;
|
|
|
|
const int cpi_harmonicsfreq = 12;
|
|
|
|
const int cpi_harmonicsbw = 13;
|
|
|
|
const int cpi_harmonicsgauss = 14;
|
|
|
|
const int cpi_octavesm2 = 15;
|
|
|
|
const int cpi_octavesm1 = 16;
|
|
|
|
const int cpi_octaves0 = 17;
|
|
|
|
const int cpi_octaves1 = 18;
|
|
|
|
const int cpi_octaves15 = 19;
|
|
|
|
const int cpi_octaves2 = 20;
|
|
|
|
const int cpi_tonalvsnoisebw = 21;
|
|
|
|
const int cpi_tonalvsnoisepreserve = 22;
|
|
|
|
const int cpi_filter_low = 23;
|
|
|
|
const int cpi_filter_high = 24;
|
2017-12-13 16:30:09 +00:00
|
|
|
const int cpi_onsetdetection = 25;
|
2018-11-08 19:48:51 +00:00
|
|
|
const int cpi_capture_trigger = 26;
|
2017-12-13 22:19:46 +00:00
|
|
|
const int cpi_num_outchans = 27;
|
2017-12-14 20:17:45 +00:00
|
|
|
const int cpi_pause_enabled = 28;
|
2017-12-18 17:48:40 +00:00
|
|
|
const int cpi_max_capture_len = 29;
|
2017-12-22 20:35:02 +00:00
|
|
|
const int cpi_passthrough = 30;
|
2018-02-07 14:00:49 +00:00
|
|
|
const int cpi_markdirty = 31;
|
2018-02-12 14:44:21 +00:00
|
|
|
const int cpi_num_inchans = 32;
|
2018-02-21 17:49:16 +00:00
|
|
|
const int cpi_bypass_stretch = 33;
|
2018-02-28 12:20:26 +00:00
|
|
|
const int cpi_freefilter_shiftx = 34;
|
|
|
|
const int cpi_freefilter_shifty = 35;
|
2018-02-28 12:36:13 +00:00
|
|
|
const int cpi_freefilter_scaley = 36;
|
|
|
|
const int cpi_freefilter_tilty = 37;
|
2018-03-03 15:22:23 +00:00
|
|
|
const int cpi_freefilter_randomy_numbands = 38;
|
|
|
|
const int cpi_freefilter_randomy_rate = 39;
|
|
|
|
const int cpi_freefilter_randomy_amount = 40;
|
2018-03-06 11:44:36 +00:00
|
|
|
const int cpi_enable_spec_module0 = 41;
|
|
|
|
const int cpi_enable_spec_module1 = 42;
|
|
|
|
const int cpi_enable_spec_module2 = 43;
|
|
|
|
const int cpi_enable_spec_module3 = 44;
|
|
|
|
const int cpi_enable_spec_module4 = 45;
|
|
|
|
const int cpi_enable_spec_module5 = 46;
|
|
|
|
const int cpi_enable_spec_module6 = 47;
|
|
|
|
const int cpi_enable_spec_module7 = 48;
|
|
|
|
const int cpi_enable_spec_module8 = 49;
|
2018-04-03 15:32:53 +00:00
|
|
|
const int cpi_octaves_extra1 = 50;
|
|
|
|
const int cpi_octaves_extra2 = 51;
|
|
|
|
const int cpi_octaves_ratio0 = 52;
|
|
|
|
const int cpi_octaves_ratio1 = 53;
|
|
|
|
const int cpi_octaves_ratio2 = 54;
|
|
|
|
const int cpi_octaves_ratio3 = 55;
|
|
|
|
const int cpi_octaves_ratio4 = 56;
|
|
|
|
const int cpi_octaves_ratio5 = 57;
|
|
|
|
const int cpi_octaves_ratio6 = 58;
|
|
|
|
const int cpi_octaves_ratio7 = 59;
|
2018-05-09 09:33:06 +00:00
|
|
|
const int cpi_looping_enabled = 60;
|
2018-05-18 13:20:51 +00:00
|
|
|
const int cpi_rewind = 61;
|
2018-08-20 12:49:51 +00:00
|
|
|
const int cpi_dryplayrate = 62;
|
2017-11-23 23:44:30 +00:00
|
|
|
|
2018-11-08 20:48:06 +00:00
|
|
|
class MyThreadPool : public ThreadPool
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyThreadPool() : ThreadPool(2) {}
|
|
|
|
};
|
|
|
|
|
2017-12-19 03:24:27 +00:00
|
|
|
class MyPropertiesFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyPropertiesFile()
|
|
|
|
{
|
|
|
|
|
|
|
|
PropertiesFile::Options poptions;
|
|
|
|
poptions.applicationName = "PaulXStretch3";
|
2018-02-06 15:04:36 +00:00
|
|
|
poptions.folderName = "PaulXStretch3";
|
|
|
|
poptions.commonToAllUsers = false;
|
|
|
|
poptions.doNotSave = false;
|
|
|
|
poptions.storageFormat = PropertiesFile::storeAsXML;
|
|
|
|
poptions.millisecondsBeforeSaving = 1000;
|
|
|
|
poptions.ignoreCaseOfKeyNames = false;
|
|
|
|
poptions.processLock = nullptr;
|
|
|
|
poptions.filenameSuffix = ".xml";
|
|
|
|
poptions.osxLibrarySubFolder = "Application Support";
|
2017-12-19 03:24:27 +00:00
|
|
|
m_props_file = std::make_unique<PropertiesFile>(poptions);
|
|
|
|
|
|
|
|
}
|
|
|
|
std::unique_ptr<PropertiesFile> m_props_file;
|
|
|
|
};
|
|
|
|
|
2018-01-05 15:49:54 +00:00
|
|
|
class PaulstretchpluginAudioProcessorEditor;
|
|
|
|
|
2019-01-20 13:24:30 +00:00
|
|
|
struct OfflineRenderParams
|
|
|
|
{
|
2022-04-12 22:47:43 +00:00
|
|
|
OfflineRenderParams(File ofile, double osr, int oformat, double omaxdur, int onumloops, CallOutBox* ocb=nullptr, std::function<void(bool,File file)> completion=nullptr) :
|
|
|
|
outputfile(ofile), outsr(osr), maxoutdur(omaxdur), numloops(onumloops), outputformat(oformat), cbox(ocb), completionHandler(completion)
|
2019-01-20 13:24:30 +00:00
|
|
|
{}
|
|
|
|
File outputfile;
|
|
|
|
double outsr = 44100.0;
|
|
|
|
double maxoutdur = 3600.0;
|
|
|
|
int numloops = 1;
|
|
|
|
int outputformat = 0; // 0=16 bit pcm, 1=24 bit pcm, 2=32 bit float, 3=32 bit float clipped
|
|
|
|
CallOutBox* cbox = nullptr;
|
2022-04-12 22:47:43 +00:00
|
|
|
std::function<void(bool,File file)> completionHandler;
|
2019-01-20 13:24:30 +00:00
|
|
|
};
|
|
|
|
|
2017-12-26 16:12:22 +00:00
|
|
|
class PaulstretchpluginAudioProcessor : public AudioProcessor,
|
2018-04-26 20:07:08 +00:00
|
|
|
public MultiTimer, public VSTCallbackHandler, public AudioProcessorParameter::Listener
|
2017-11-13 15:06:08 +00:00
|
|
|
{
|
|
|
|
public:
|
2018-01-05 15:49:54 +00:00
|
|
|
using EditorType = PaulstretchpluginAudioProcessorEditor;
|
2019-03-29 14:37:36 +00:00
|
|
|
PaulstretchpluginAudioProcessor(bool is_stand_alone_offline=false);
|
|
|
|
~PaulstretchpluginAudioProcessor();
|
2017-11-13 15:06:08 +00:00
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
void prepareToPlay (double sampleRate, int samplesPerBlock) override;
|
|
|
|
void releaseResources() override;
|
|
|
|
|
|
|
|
#ifndef JucePlugin_PreferredChannelConfigurations
|
|
|
|
bool isBusesLayoutSupported (const BusesLayout& layouts) const override;
|
|
|
|
#endif
|
|
|
|
|
2018-03-26 16:31:23 +00:00
|
|
|
void processBlock (AudioSampleBuffer&, MidiBuffer&) override;
|
2018-04-17 20:39:26 +00:00
|
|
|
//void processBlock (AudioBuffer<double>&, MidiBuffer&) override;
|
|
|
|
//bool supportsDoublePrecisionProcessing() const override { return true; }
|
2017-11-13 15:06:08 +00:00
|
|
|
//==============================================================================
|
|
|
|
AudioProcessorEditor* createEditor() override;
|
|
|
|
bool hasEditor() const override;
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
const String getName() const override;
|
|
|
|
|
|
|
|
bool acceptsMidi() const override;
|
|
|
|
bool producesMidi() const override;
|
|
|
|
bool isMidiEffect () const override;
|
|
|
|
double getTailLengthSeconds() const override;
|
|
|
|
|
|
|
|
//==============================================================================
|
|
|
|
int getNumPrograms() override;
|
|
|
|
int getCurrentProgram() override;
|
|
|
|
void setCurrentProgram (int index) override;
|
|
|
|
const String getProgramName (int index) override;
|
|
|
|
void changeProgramName (int index, const String& newName) override;
|
|
|
|
|
2018-04-26 20:07:08 +00:00
|
|
|
void parameterValueChanged(int parameterIndex, float newValue) override;
|
|
|
|
void parameterGestureChanged(int parameterIndex, bool gestureIsStarting) override;
|
|
|
|
|
2022-04-11 22:50:55 +00:00
|
|
|
|
2017-11-13 15:06:08 +00:00
|
|
|
//==============================================================================
|
|
|
|
void getStateInformation (MemoryBlock& destData) override;
|
|
|
|
void setStateInformation (const void* data, int sizeInBytes) override;
|
2017-11-13 18:45:23 +00:00
|
|
|
AudioParameterFloat* getFloatParameter(int index)
|
|
|
|
{
|
|
|
|
return dynamic_cast<AudioParameterFloat*>(getParameters()[index]);
|
|
|
|
}
|
2018-01-30 16:07:47 +00:00
|
|
|
AudioParameterInt* getIntParameter(int index)
|
|
|
|
{
|
|
|
|
return dynamic_cast<AudioParameterInt*>(getParameters()[index]);
|
|
|
|
}
|
2018-02-07 14:00:49 +00:00
|
|
|
AudioParameterBool* getBoolParameter(int index)
|
|
|
|
{
|
|
|
|
return dynamic_cast<AudioParameterBool*>(getParameters()[index]);
|
|
|
|
}
|
2022-04-11 22:50:55 +00:00
|
|
|
void setLastPluginBounds(juce::Rectangle<int> bounds) { mPluginWindowWidth = bounds.getWidth(); mPluginWindowHeight = bounds.getHeight();}
|
|
|
|
juce::Rectangle<int> getLastPluginBounds() const { return juce::Rectangle<int>(0,0,mPluginWindowWidth, mPluginWindowHeight); }
|
|
|
|
|
|
|
|
|
2018-02-07 14:00:49 +00:00
|
|
|
void setDirty();
|
2017-11-13 19:21:30 +00:00
|
|
|
void setRecordingEnabled(bool b);
|
2017-11-13 20:35:36 +00:00
|
|
|
bool isRecordingEnabled() { return m_is_recording; }
|
|
|
|
double getRecordingPositionPercent();
|
2022-04-13 17:48:09 +00:00
|
|
|
String setAudioFile(const URL& url);
|
|
|
|
URL getAudioFile() { return m_current_file; }
|
2017-11-16 14:58:04 +00:00
|
|
|
Range<double> getTimeSelection();
|
2017-11-23 23:44:30 +00:00
|
|
|
SharedResourcePointer<AudioFormatManager> m_afm;
|
2017-12-19 03:24:27 +00:00
|
|
|
SharedResourcePointer<MyPropertiesFile> m_propsfile;
|
2017-11-20 22:39:07 +00:00
|
|
|
StretchAudioSource* getStretchSource() { return m_stretch_source.get(); }
|
|
|
|
double getPreBufferingPercent();
|
2017-12-13 16:30:09 +00:00
|
|
|
void timerCallback(int id) override;
|
2017-12-17 16:16:39 +00:00
|
|
|
double getSampleRateChecked();
|
2017-12-18 20:27:12 +00:00
|
|
|
int m_abnormal_output_samples = 0;
|
2017-12-19 21:00:42 +00:00
|
|
|
AudioPlayHead::CurrentPositionInfo m_playposinfo;
|
2017-12-19 23:12:47 +00:00
|
|
|
bool m_play_when_host_plays = false;
|
|
|
|
bool m_capture_when_host_plays = false;
|
2018-06-01 13:31:31 +00:00
|
|
|
bool m_mute_while_capturing = false;
|
2022-04-02 16:45:02 +00:00
|
|
|
bool m_mute_processed_while_capturing = false;
|
2017-12-20 01:58:50 +00:00
|
|
|
bool m_use_backgroundbuffering = true;
|
2017-12-26 16:12:22 +00:00
|
|
|
void resetParameters();
|
2017-12-20 01:58:50 +00:00
|
|
|
void setPreBufferAmount(int x);
|
2017-12-22 20:35:02 +00:00
|
|
|
int getPreBufferAmount();
|
2017-12-26 18:24:10 +00:00
|
|
|
bool m_load_file_with_state = true;
|
2017-12-27 20:43:07 +00:00
|
|
|
ValueTree getStateTree(bool ignoreoptions, bool ignorefile);
|
2017-12-27 20:20:44 +00:00
|
|
|
void setStateFromTree(ValueTree tree);
|
2019-01-20 13:24:30 +00:00
|
|
|
String offlineRender(OfflineRenderParams renderpars);
|
2018-02-26 17:55:32 +00:00
|
|
|
std::atomic<int> m_offline_render_state{ -1 };
|
2018-02-26 18:09:47 +00:00
|
|
|
std::atomic<bool> m_offline_render_cancel_requested{ false };
|
2018-12-19 13:16:30 +00:00
|
|
|
std::atomic<int> m_capture_save_state{ 0 };
|
2017-12-27 20:43:07 +00:00
|
|
|
bool m_state_dirty = false;
|
2018-01-17 16:57:56 +00:00
|
|
|
std::unique_ptr<AudioThumbnail> m_thumb;
|
2018-02-13 14:51:57 +00:00
|
|
|
bool m_show_technical_info = false;
|
2018-02-14 16:38:54 +00:00
|
|
|
Range<double> m_wave_view_range;
|
2018-02-21 23:54:21 +00:00
|
|
|
int m_prepare_count = 0;
|
2018-02-27 13:02:34 +00:00
|
|
|
shared_envelope m_free_filter_envelope;
|
2018-03-03 20:19:02 +00:00
|
|
|
bool m_import_dlg_open = false;
|
2018-09-26 16:19:10 +00:00
|
|
|
void setAudioPreview(AudioFilePreviewComponent* afpc);
|
|
|
|
CriticalSection& getCriticalSection() { return m_cs; }
|
2018-04-25 12:25:29 +00:00
|
|
|
pointer_sized_int handleVstPluginCanDo(int32 index,
|
|
|
|
pointer_sized_int value,
|
|
|
|
void* ptr,
|
|
|
|
float opt) override;
|
|
|
|
|
|
|
|
pointer_sized_int handleVstManufacturerSpecific(int32 index,
|
|
|
|
pointer_sized_int value,
|
|
|
|
void* ptr,
|
|
|
|
float opt) override;
|
2018-06-29 12:13:49 +00:00
|
|
|
int m_cur_tab_index = 0;
|
2019-02-12 12:56:37 +00:00
|
|
|
|
2018-12-19 13:16:30 +00:00
|
|
|
bool m_save_captured_audio = true;
|
2018-12-19 13:25:52 +00:00
|
|
|
String m_capture_location;
|
2019-01-17 20:15:46 +00:00
|
|
|
bool m_midinote_control = false;
|
2019-01-21 14:10:17 +00:00
|
|
|
std::function<void(const FileChooser&)> m_filechoose_callback;
|
2017-11-13 22:50:12 +00:00
|
|
|
private:
|
2017-12-27 15:35:30 +00:00
|
|
|
bool m_prebuffering_inited = false;
|
2017-11-13 19:21:30 +00:00
|
|
|
AudioBuffer<float> m_recbuffer;
|
2017-11-25 19:25:46 +00:00
|
|
|
double m_max_reclen = 10.0;
|
2017-11-13 19:21:30 +00:00
|
|
|
int m_rec_pos = 0;
|
2018-06-05 18:11:17 +00:00
|
|
|
int m_rec_count = 0;
|
|
|
|
Range<int> m_recorded_range;
|
2017-11-13 21:42:13 +00:00
|
|
|
void finishRecording(int lenrecorded);
|
2017-11-16 14:58:04 +00:00
|
|
|
bool m_using_memory_buffer = true;
|
2017-11-14 01:13:32 +00:00
|
|
|
int m_cur_num_out_chans = 2;
|
2017-12-12 18:43:43 +00:00
|
|
|
CriticalSection m_cs;
|
2022-04-13 17:48:09 +00:00
|
|
|
URL m_current_file;
|
2017-12-15 04:17:11 +00:00
|
|
|
Time m_current_file_date;
|
2019-02-12 12:56:37 +00:00
|
|
|
bool m_is_recording = false;
|
2017-11-20 22:39:07 +00:00
|
|
|
TimeSliceThread m_bufferingthread;
|
|
|
|
std::unique_ptr<StretchAudioSource> m_stretch_source;
|
|
|
|
std::unique_ptr<MyBufferingAudioSource> m_buffering_source;
|
|
|
|
int m_prebuffer_amount = 1;
|
|
|
|
bool m_recreate_buffering_source = true;
|
2018-05-01 15:22:21 +00:00
|
|
|
double m_smoothed_prebuffer_ready = 0.0;
|
|
|
|
SignalSmoother m_prebufsmoother;
|
2017-11-20 22:39:07 +00:00
|
|
|
int m_fft_size_to_use = 1024;
|
|
|
|
double m_last_outpos_pos = 0.0;
|
|
|
|
double m_last_in_pos = 0.0;
|
|
|
|
std::vector<int> m_bufamounts{ 4096,8192,16384,32768,65536,262144 };
|
|
|
|
ProcessParameters m_ppar;
|
2022-04-12 22:47:43 +00:00
|
|
|
int mPluginWindowWidth = 820;
|
2022-04-14 07:26:26 +00:00
|
|
|
int mPluginWindowHeight = 710;
|
2022-04-11 22:50:55 +00:00
|
|
|
|
2017-11-20 22:39:07 +00:00
|
|
|
void setFFTSize(double size);
|
2017-12-14 17:06:26 +00:00
|
|
|
void startplay(Range<double> playrange, int numoutchans, int maxBlockSize, String& err);
|
2017-11-23 17:36:46 +00:00
|
|
|
SharedResourcePointer<MyThumbCache> m_thumbcache;
|
2017-12-13 22:19:46 +00:00
|
|
|
AudioParameterInt* m_outchansparam = nullptr;
|
2018-02-12 14:44:21 +00:00
|
|
|
AudioParameterInt* m_inchansparam = nullptr;
|
2017-12-14 17:06:26 +00:00
|
|
|
int m_curmaxblocksize = 0;
|
2017-12-17 16:16:39 +00:00
|
|
|
double m_cur_sr = 0.0;
|
2017-12-19 23:12:47 +00:00
|
|
|
bool m_last_host_playing = false;
|
2017-12-20 18:33:34 +00:00
|
|
|
AudioBuffer<float> m_input_buffer;
|
2017-12-26 16:12:22 +00:00
|
|
|
std::vector<float> m_reset_pars;
|
2017-12-27 20:20:44 +00:00
|
|
|
int m_cur_program = 0;
|
|
|
|
void setParameters(const std::vector<double>& pars);
|
2018-02-15 14:03:00 +00:00
|
|
|
float m_cur_playrangeoffset = 0.0;
|
2018-02-26 14:34:13 +00:00
|
|
|
void updateStretchParametersFromPluginParameters(ProcessParameters& pars);
|
2018-03-06 11:44:36 +00:00
|
|
|
std::array<AudioParameterBool*, 9> m_sm_enab_pars;
|
2018-05-18 13:20:51 +00:00
|
|
|
bool m_lastrewind = false;
|
2018-09-26 16:19:10 +00:00
|
|
|
AudioFilePreviewComponent* m_previewcomponent = nullptr;
|
2018-11-08 18:22:26 +00:00
|
|
|
void saveCaptureBuffer();
|
2018-11-08 20:48:06 +00:00
|
|
|
SharedResourcePointer<MyThreadPool> m_threadpool;
|
2019-01-17 17:26:41 +00:00
|
|
|
int m_midinote_to_use = -1;
|
2019-01-17 17:47:56 +00:00
|
|
|
ADSR m_adsr;
|
2019-03-29 14:37:36 +00:00
|
|
|
bool m_is_stand_alone_offline = false;
|
2017-11-13 21:42:13 +00:00
|
|
|
//==============================================================================
|
2017-11-13 15:06:08 +00:00
|
|
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor)
|
|
|
|
};
|