diff --git a/Source/PS_Source/PaulStretchControl.h b/Source/PS_Source/PaulStretchControl.h index e3070ad..ef51239 100644 --- a/Source/PS_Source/PaulStretchControl.h +++ b/Source/PS_Source/PaulStretchControl.h @@ -119,7 +119,7 @@ public: int getPrebufferThreadPriority() { return m_prebufthreadprior; } private: REALTYPE volume; - int m_prebufthreadprior = 5; + int m_prebufthreadprior = 4; int get_optimized_updown(int n,bool up); int optimizebufsize(int bufsize); std::string getfftsizestr(int fftsize); diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index 01435e0..4245782 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -141,7 +141,7 @@ void StretchAudioSource::getNextAudioBlock(const AudioSourceChannelInfo & buffer for (auto& e : m_stretchers) e->set_freezing(m_freezing); } - double maingain = 0.5; // Decibels::decibelsToGain((double)val_MainVolume.getValue()); + double maingain = Decibels::decibelsToGain((double)val_MainVolume.getValue()); if (m_vol_smoother.getTargetValue() != maingain) m_vol_smoother.setValue(maingain); FloatVectorOperations::disableDenormalisedNumberSupport(); diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 0b49af1..0a56e27 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -16,6 +16,9 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor& p) : AudioProcessorEditor (&p), processor (p), m_wavecomponent(p.m_afm.get()) { + addAndMakeVisible(&m_import_button); + m_import_button.setButtonText("Import file..."); + m_import_button.addListener(this); addAndMakeVisible(&m_info_label); addAndMakeVisible(&m_wavecomponent); const auto& pars = processor.getParameters(); @@ -53,6 +56,20 @@ void PaulstretchpluginAudioProcessorEditor::buttonClicked(Button * but) { processor.setRecordingEnabled(but->getToggleState()); } + if (but == &m_import_button) + { + FileChooser myChooser("Please select audio file...", + File("C:/MusicAudio/sourcesamples"), + "*.wav"); + if (myChooser.browseForFileToOpen()) + { + processor.setAudioFile(myChooser.getResult()); + if (processor.getAudioFile() != File()) + { + m_wavecomponent.setAudioFile(processor.getAudioFile()); + } + } + } } //============================================================================== @@ -66,6 +83,8 @@ void PaulstretchpluginAudioProcessorEditor::resized() m_rec_enable.setBounds(1, m_parcomps.back()->getBottom()+1, 10, 24); m_rec_enable.changeWidthToFitText(); m_info_label.setBounds(m_rec_enable.getRight() + 1, m_rec_enable.getY(), 60, 24); + m_import_button.setBounds(m_info_label.getRight() + 1, m_rec_enable.getY(), 60, 24); + m_import_button.changeWidthToFitText(); m_wavecomponent.setBounds(1, m_info_label.getBottom()+1, getWidth()-2, getHeight()-1-m_info_label.getBottom()); } @@ -206,6 +225,8 @@ void WaveformComponent::setAudioFile(File f) m_waveimage = Image(); if (m_thumb != nullptr && f == m_curfile) // reloading same file, might happen that the overview needs to be redone... m_thumbcache.removeThumb(m_thumb->getHashCode()); + if (m_thumb != nullptr) + m_thumb->reset(0, 0.0); m_thumb->setSource(new FileInputSource(f)); m_curfile = f; } @@ -213,7 +234,7 @@ void WaveformComponent::setAudioFile(File f) { m_thumb->setSource(nullptr); } - + repaint(); } void WaveformComponent::setAudioBuffer(AudioBuffer* buf, int samplerate, int len) diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 3e1e750..8ccb01d 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -144,6 +144,7 @@ private: PaulstretchpluginAudioProcessor& processor; std::vector> m_parcomps; ToggleButton m_rec_enable; + TextButton m_import_button; Label m_info_label; WaveformComponent m_wavecomponent; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index 4617b50..312a9cb 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -30,6 +30,7 @@ PaulstretchpluginAudioProcessor::PaulstretchpluginAudioProcessor() m_afm = std::make_unique(); m_afm->registerBasicFormats(); m_control = std::make_unique(m_afm.get()); + m_control->setPreBufferAmount(3); m_control->ppar.pitch_shift.enabled = true; m_control->ppar.freq_shift.enabled = true; m_control->setOnsetDetection(0.0); @@ -121,11 +122,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl m_control->getStretchAudioSource()->setAudioBufferAsInputSource(&m_recbuffer, getSampleRate(), len); - auto ed = dynamic_cast(getActiveEditor()); - if (ed) - { - ed->setAudioBuffer(&m_recbuffer, getSampleRate(), len); - } + callGUI([this,len](auto ed) { ed->setAudioBuffer(&m_recbuffer, getSampleRate(), len); },false); } if (m_ready_to_play == false) { @@ -136,7 +133,7 @@ void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int sampl String err; m_control->startplay(false, true, { *getFloatParameter(5),*getFloatParameter(6) }, - this->getNumOutputChannels(), err); + 2, err); m_cur_num_out_chans = getNumOutputChannels(); m_ready_to_play = true; } @@ -197,6 +194,7 @@ void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, M } return; } + m_control->getStretchAudioSource()->val_MainVolume = (float)*getFloatParameter(0); m_control->getStretchAudioSource()->setRate(*getFloatParameter(1)); m_control->getStretchAudioSource()->val_XFadeLen = 0.1; //m_control->setFFTSize(*getFloatParameter(2)); @@ -264,6 +262,17 @@ double PaulstretchpluginAudioProcessor::getRecordingPositionPercent() return 1.0 / m_recbuffer.getNumSamples()*m_rec_pos; } +String PaulstretchpluginAudioProcessor::setAudioFile(File f) +{ + std::lock_guard locker(m_mutex); + m_control->set_input_file(f, [this,f](String) + { + + }); + m_current_file = f; + return String(); +} + void PaulstretchpluginAudioProcessor::finishRecording(int lenrecording) { m_is_recording = false; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index ef9b754..4744651 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -62,6 +62,8 @@ public: void setRecordingEnabled(bool b); bool isRecordingEnabled() { return m_is_recording; } double getRecordingPositionPercent(); + String setAudioFile(File f); + File getAudioFile() { return m_current_file; } std::unique_ptr m_afm; std::unique_ptr m_control; private: @@ -76,6 +78,19 @@ private: bool m_using_memory_buffer = true; int m_cur_num_out_chans = 2; std::mutex m_mutex; + File m_current_file; + template + void callGUI(F&& f, bool async) + { + auto ed = dynamic_cast(getActiveEditor()); + if (ed) + { + if (async == false) + f(ed); + else + MessageManager::callAsync([ed,f]() { f(ed); }); + } + } //============================================================================== JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessor) }; diff --git a/paulstretchplugin.jucer b/paulstretchplugin.jucer index a4dca06..2081e70 100644 --- a/paulstretchplugin.jucer +++ b/paulstretchplugin.jucer @@ -81,11 +81,11 @@ + headerPath="Source/PS_Source Source/WDL " vstBinaryLocation="C:\VSTPlugins"/> + linkTimeOptimisation="0" isDebug="0" optimisation="3" targetName="paulstretchplugin" + headerPath="Source/PS_Source Source/WDL " vstBinaryLocation="C:\VSTPlugins"/>