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:
xenakios 2017-11-16 17:38:59 +02:00
parent 43be82edc8
commit aee132519a
3 changed files with 57 additions and 36 deletions

View File

@ -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<double> 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<float>& 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<double>, int) {};

View File

@ -15,6 +15,34 @@
#include <memory>
#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,
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)
};

View File

@ -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;