Use Jules's neat way to attach button callbacks. Separate method in editor to choose file to load. Revert change to resample.cpp.
This commit is contained in:
parent
43be82edc8
commit
aee132519a
@ -21,7 +21,8 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa
|
|||||||
{
|
{
|
||||||
addAndMakeVisible(&m_import_button);
|
addAndMakeVisible(&m_import_button);
|
||||||
m_import_button.setButtonText("Import file...");
|
m_import_button.setButtonText("Import file...");
|
||||||
m_import_button.addListener(this);
|
attachCallback(m_import_button, [this]() { chooseFile(); });
|
||||||
|
|
||||||
addAndMakeVisible(&m_info_label);
|
addAndMakeVisible(&m_info_label);
|
||||||
addAndMakeVisible(&m_wavecomponent);
|
addAndMakeVisible(&m_wavecomponent);
|
||||||
const auto& pars = processor.getParameters();
|
const auto& pars = processor.getParameters();
|
||||||
@ -33,7 +34,8 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa
|
|||||||
}
|
}
|
||||||
addAndMakeVisible(&m_rec_enable);
|
addAndMakeVisible(&m_rec_enable);
|
||||||
m_rec_enable.setButtonText("Capture");
|
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);
|
setSize (700, pars.size()*25+200);
|
||||||
m_wavecomponent.TimeSelectionChangedCallback = [this](Range<double> range, int which)
|
m_wavecomponent.TimeSelectionChangedCallback = [this](Range<double> range, int which)
|
||||||
{
|
{
|
||||||
@ -48,40 +50,13 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor (Pa
|
|||||||
startTimer(1, 100);
|
startTimer(1, 100);
|
||||||
startTimer(2, 1000);
|
startTimer(2, 1000);
|
||||||
m_wavecomponent.startTimer(100);
|
m_wavecomponent.startTimer(100);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PaulstretchpluginAudioProcessorEditor::~PaulstretchpluginAudioProcessorEditor()
|
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)
|
void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g)
|
||||||
{
|
{
|
||||||
g.fillAll(Colours::darkgrey);
|
g.fillAll(Colours::darkgrey);
|
||||||
@ -147,6 +122,26 @@ void PaulstretchpluginAudioProcessorEditor::addAudioBlock(AudioBuffer<float>& bu
|
|||||||
m_wavecomponent.addAudioBlock(buf, samplerate, pos);
|
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)
|
WaveformComponent::WaveformComponent(AudioFormatManager* afm) : m_thumbcache(100)
|
||||||
{
|
{
|
||||||
TimeSelectionChangedCallback = [](Range<double>, int) {};
|
TimeSelectionChangedCallback = [](Range<double>, int) {};
|
||||||
|
@ -15,6 +15,34 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
inline void attachCallback(Button& button, std::function<void()> callback)
|
||||||
|
{
|
||||||
|
struct ButtonCallback : public Button::Listener,
|
||||||
|
private ComponentListener
|
||||||
|
{
|
||||||
|
ButtonCallback(Button& b, std::function<void()> 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<void()> fn;
|
||||||
|
|
||||||
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ButtonCallback)
|
||||||
|
};
|
||||||
|
|
||||||
|
new ButtonCallback(button, callback);
|
||||||
|
}
|
||||||
|
|
||||||
class ParameterComponent : public Component,
|
class ParameterComponent : public Component,
|
||||||
public Slider::Listener
|
public Slider::Listener
|
||||||
{
|
{
|
||||||
@ -136,14 +164,12 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor,
|
class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor,
|
||||||
public MultiTimer, public Button::Listener
|
public MultiTimer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&);
|
PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&);
|
||||||
~PaulstretchpluginAudioProcessorEditor();
|
~PaulstretchpluginAudioProcessorEditor();
|
||||||
void buttonClicked(Button* but) override;
|
void paint (Graphics&) override;
|
||||||
//==============================================================================
|
|
||||||
void paint (Graphics&) override;
|
|
||||||
void resized() override;
|
void resized() override;
|
||||||
void timerCallback(int id) override;
|
void timerCallback(int id) override;
|
||||||
void setAudioFile(File f);
|
void setAudioFile(File f);
|
||||||
@ -157,6 +183,6 @@ private:
|
|||||||
ToggleButton m_rec_enable;
|
ToggleButton m_rec_enable;
|
||||||
TextButton m_import_button;
|
TextButton m_import_button;
|
||||||
Label m_info_label;
|
Label m_info_label;
|
||||||
|
void chooseFile();
|
||||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
|
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
|
||||||
};
|
};
|
||||||
|
@ -632,7 +632,7 @@ int WDL_Resampler::ResampleOut(WDL_ResampleSample *out, int nsamples_in, int nsa
|
|||||||
m_samples_in_rsinbuf -= isrcpos;
|
m_samples_in_rsinbuf -= isrcpos;
|
||||||
if (m_samples_in_rsinbuf <= 0) m_samples_in_rsinbuf=0;
|
if (m_samples_in_rsinbuf <= 0) m_samples_in_rsinbuf=0;
|
||||||
else
|
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;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user