diff --git a/Source/PluginEditor.cpp b/Source/PluginEditor.cpp index 11df881..44b5af5 100644 --- a/Source/PluginEditor.cpp +++ b/Source/PluginEditor.cpp @@ -21,7 +21,8 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa { addAndMakeVisible(&m_import_button); m_import_button.setButtonText("Import file..."); - m_import_button.addListener(this); + attachCallback(m_import_button, [this]() { chooseFile(); }); + addAndMakeVisible(&m_info_label); addAndMakeVisible(&m_wavecomponent); const auto& pars = processor.getParameters(); @@ -33,7 +34,8 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa } addAndMakeVisible(&m_rec_enable); m_rec_enable.setButtonText("Capture"); - m_rec_enable.addListener(this); + attachCallback(m_rec_enable, [this]() { processor.setRecordingEnabled(m_rec_enable.getToggleState()); }); + setSize (700, pars.size()*25+200); m_wavecomponent.TimeSelectionChangedCallback = [this](Range range, int which) { @@ -48,40 +50,13 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa startTimer(1, 100); startTimer(2, 1000); m_wavecomponent.startTimer(100); + } PaulstretchpluginAudioProcessorEditor::~PaulstretchpluginAudioProcessorEditor() { } -void PaulstretchpluginAudioProcessorEditor::buttonClicked(Button * but) -{ - if (but == &m_rec_enable) - { - processor.setRecordingEnabled(but->getToggleState()); - } - if (but == &m_import_button) - { -#ifdef WIN32 - File initialloc("C:/MusicAudio/sourcesamples"); -#else - File initialloc("/Users/teemu/AudioProjects/sourcesamples"); -#endif - FileChooser myChooser("Please select audio file...", - initialloc, - "*.wav"); - if (myChooser.browseForFileToOpen()) - { - processor.setAudioFile(myChooser.getResult()); - if (processor.getAudioFile() != File()) - { - m_wavecomponent.setAudioFile(processor.getAudioFile()); - } - } - } -} - -//============================================================================== void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g) { g.fillAll(Colours::darkgrey); @@ -147,6 +122,26 @@ void PaulstretchpluginAudioProcessorEditor::addAudioBlock(AudioBuffer& bu m_wavecomponent.addAudioBlock(buf, samplerate, pos); } +void PaulstretchpluginAudioProcessorEditor::chooseFile() +{ +#ifdef WIN32 + File initialloc("C:/MusicAudio/sourcesamples"); +#else + File initialloc("/Users/teemu/AudioProjects/sourcesamples"); +#endif + FileChooser myChooser("Please select audio file...", + initialloc, + "*.wav"); + if (myChooser.browseForFileToOpen()) + { + processor.setAudioFile(myChooser.getResult()); + if (processor.getAudioFile() != File()) + { + m_wavecomponent.setAudioFile(processor.getAudioFile()); + } + } +} + WaveformComponent::WaveformComponent(AudioFormatManager* afm) : m_thumbcache(100) { TimeSelectionChangedCallback = [](Range, int) {}; diff --git a/Source/PluginEditor.h b/Source/PluginEditor.h index 95d654d..eb26c2e 100644 --- a/Source/PluginEditor.h +++ b/Source/PluginEditor.h @@ -15,6 +15,34 @@ #include #include +inline void attachCallback(Button& button, std::function callback) +{ + struct ButtonCallback : public Button::Listener, + private ComponentListener + { + ButtonCallback(Button& b, std::function f) : target(b), fn(f) + { + target.addListener(this); + target.addComponentListener(this); + } + + ~ButtonCallback() + { + target.removeListener(this); + } + + void componentBeingDeleted(Component&) override { delete this; } + void buttonClicked(Button*) override { fn(); } + + Button& target; + std::function fn; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ButtonCallback) + }; + + new ButtonCallback(button, callback); +} + class ParameterComponent : public Component, public Slider::Listener { @@ -136,14 +164,12 @@ private: class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor, - public MultiTimer, public Button::Listener + public MultiTimer { public: PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&); ~PaulstretchpluginAudioProcessorEditor(); - void buttonClicked(Button* but) override; - //============================================================================== - void paint (Graphics&) override; + void paint (Graphics&) override; void resized() override; void timerCallback(int id) override; void setAudioFile(File f); @@ -157,6 +183,6 @@ private: ToggleButton m_rec_enable; TextButton m_import_button; Label m_info_label; - + void chooseFile(); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor) }; diff --git a/Source/WDL/resample.cpp b/Source/WDL/resample.cpp index bb9f985..9892413 100644 --- a/Source/WDL/resample.cpp +++ b/Source/WDL/resample.cpp @@ -632,7 +632,7 @@ int WDL_Resampler::ResampleOut(WDL_ResampleSample *out, int nsamples_in, int nsa m_samples_in_rsinbuf -= isrcpos; if (m_samples_in_rsinbuf <= 0) m_samples_in_rsinbuf=0; else - memmove(localin, localin + isrcpos*nch,m_samples_in_rsinbuf*sizeof(WDL_ResampleSample)*nch); + memcpy(localin, localin + isrcpos*nch,m_samples_in_rsinbuf*sizeof(WDL_ResampleSample)*nch); return ret;