Ditch the file open dialog in favor of an overlaid FileBrowserComponent. Should be much nicer to use anyway...

This commit is contained in:
xenakios 2019-01-21 19:25:27 +02:00
parent 409c053057
commit 3ee6f44b16
2 changed files with 56 additions and 36 deletions

View File

@ -32,8 +32,19 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau
m_wavecomponent(p.m_afm,p.m_thumb.get(), p.getStretchSource()), m_wavecomponent(p.m_afm,p.m_thumb.get(), p.getStretchSource()),
processor(p), m_perfmeter(&p), processor(p), m_perfmeter(&p),
m_free_filter_component(&p), m_free_filter_component(&p),
m_wavefilter_tab(p.m_cur_tab_index) m_wavefilter_tab(p.m_cur_tab_index),
m_filefilter(p.m_afm->getWildcardForAllFormats(),String(),String())
{ {
String initiallocfn = processor.m_propsfile->m_props_file->getValue("importfilefolder",
File::getSpecialLocation(File::userHomeDirectory).getFullPathName());
File initialloc(initiallocfn);
String filterstring = processor.m_afm->getWildcardForAllFormats();
m_filechooser = std::make_unique<FileBrowserComponent>(1|4,
initialloc, &m_filefilter, nullptr);
m_filechooser->addListener(this);
setWantsKeyboardFocus(true); setWantsKeyboardFocus(true);
m_wave_container = new Component; m_wave_container = new Component;
m_free_filter_component.getEnvelopeComponent()->set_envelope(processor.m_free_filter_envelope); m_free_filter_component.getEnvelopeComponent()->set_envelope(processor.m_free_filter_envelope);
@ -51,8 +62,16 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau
addAndMakeVisible(&m_perfmeter); addAndMakeVisible(&m_perfmeter);
addAndMakeVisible(&m_import_button); addAndMakeVisible(&m_import_button);
m_import_button.setButtonText("Import file..."); m_import_button.setButtonText("Show browser");
m_import_button.onClick = [this]() { chooseFile(); }; m_import_button.onClick = [this]()
{
m_filechooser->setBounds(0, 50, getWidth(), getHeight() - 60);
m_filechooser->setVisible(!m_filechooser->isVisible());
if (m_filechooser->isVisible())
m_import_button.setButtonText("Hide browser");
else
m_import_button.setButtonText("Show browser");
};
addAndMakeVisible(&m_settings_button); addAndMakeVisible(&m_settings_button);
m_settings_button.setButtonText("Settings..."); m_settings_button.setButtonText("Settings...");
@ -237,6 +256,7 @@ PaulstretchpluginAudioProcessorEditor::PaulstretchpluginAudioProcessorEditor(Pau
startTimer(2, 1000); startTimer(2, 1000);
startTimer(3, 200); startTimer(3, 200);
m_wavecomponent.startTimer(100); m_wavecomponent.startTimer(100);
addChildComponent(m_filechooser.get());
} }
PaulstretchpluginAudioProcessorEditor::~PaulstretchpluginAudioProcessorEditor() PaulstretchpluginAudioProcessorEditor::~PaulstretchpluginAudioProcessorEditor()
@ -303,6 +323,24 @@ void PaulstretchpluginAudioProcessorEditor::executeModalMenuAction(int menuid, i
} }
} }
void PaulstretchpluginAudioProcessorEditor::selectionChanged()
{
}
void PaulstretchpluginAudioProcessorEditor::fileClicked(const File & file, const MouseEvent & e)
{
}
void PaulstretchpluginAudioProcessorEditor::fileDoubleClicked(const File & file)
{
processor.setAudioFile(file);
processor.m_propsfile->m_props_file->setValue("importfilefolder", file.getParentDirectory().getFullPathName());
}
void PaulstretchpluginAudioProcessorEditor::browserRootChanged(const File & newRoot)
{
}
void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g) void PaulstretchpluginAudioProcessorEditor::paint (Graphics& g)
{ {
g.fillAll(Colours::darkgrey); g.fillAll(Colours::darkgrey);
@ -512,39 +550,10 @@ bool PaulstretchpluginAudioProcessorEditor::keyPressed(const KeyPress & press)
{ {
std::function<bool(void)> action; std::function<bool(void)> action;
if (press == 'I') if (press == 'I')
action = [this]() { chooseFile(); return true; }; action = [this]() { m_import_button.onClick(); ; return true; };
return action && action(); return action && action();
} }
void PaulstretchpluginAudioProcessorEditor::chooseFile()
{
String initiallocfn = processor.m_propsfile->m_props_file->getValue("importfilefolder",
File::getSpecialLocation(File::userHomeDirectory).getFullPathName());
File initialloc(initiallocfn);
String filterstring = processor.m_afm->getWildcardForAllFormats();
//auto prevcomp = std::make_unique<AudioFilePreviewComponent>(&processor);
//processor.setAudioPreview(prevcomp.get());
m_filechooser = std::make_unique<FileChooser>("Please select audio file...",
initialloc,
filterstring,true,false,this);
m_filechooser->launchAsync(0, processor.m_filechoose_callback);
return;
//if (m_filechooser->launchAsync(0,processor.m_filechoose_callback))
{
File resu = m_filechooser->getResult();
String pathname = resu.getFullPathName();
if (pathname.startsWith("/localhost"))
{
pathname = pathname.substring(10);
resu = File(pathname);
}
processor.m_propsfile->m_props_file->setValue("importfilefolder", resu.getParentDirectory().getFullPathName());
m_last_err = processor.setAudioFile(resu);
}
//processor.setAudioPreview(nullptr);
//toFront(true);
}
void PaulstretchpluginAudioProcessorEditor::showSettingsMenu() void PaulstretchpluginAudioProcessorEditor::showSettingsMenu()
{ {
PopupMenu m_settings_menu; PopupMenu m_settings_menu;

View File

@ -417,7 +417,7 @@ private:
}; };
class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor, class PaulstretchpluginAudioProcessorEditor : public AudioProcessorEditor,
public MultiTimer, public FileDragAndDropTarget, public DragAndDropContainer public MultiTimer, public FileDragAndDropTarget, public DragAndDropContainer, public FileBrowserListener
{ {
public: public:
PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&); PaulstretchpluginAudioProcessorEditor (PaulstretchpluginAudioProcessor&);
@ -432,11 +432,21 @@ public:
bool keyPressed(const KeyPress& press) override; bool keyPressed(const KeyPress& press) override;
WaveformComponent m_wavecomponent; WaveformComponent m_wavecomponent;
void chooseFile();
void showRenderDialog(); void showRenderDialog();
void executeModalMenuAction(int menuid, int actionid); void executeModalMenuAction(int menuid, int actionid);
SimpleFFTComponent m_sonogram; SimpleFFTComponent m_sonogram;
String m_last_err; String m_last_err;
void selectionChanged() override;
/** Callback when the user clicks on a file in the browser. */
void fileClicked(const File& file, const MouseEvent& e) override;
/** Callback when the user double-clicks on a file in the browser. */
void fileDoubleClicked(const File& file) override;
/** Callback when the browser's root folder changes. */
void browserRootChanged(const File& newRoot) override;
private: private:
PaulstretchpluginAudioProcessor& processor; PaulstretchpluginAudioProcessor& processor;
uptrvec<ParameterComponent> m_parcomps; uptrvec<ParameterComponent> m_parcomps;
@ -460,7 +470,8 @@ private:
void showAbout(); void showAbout();
std::vector<int> m_capturelens{ 2,5,10,30,60,120 }; std::vector<int> m_capturelens{ 2,5,10,30,60,120 };
std::unique_ptr<FileChooser> m_filechooser; std::unique_ptr<FileBrowserComponent> m_filechooser;
WildcardFileFilter m_filefilter;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor) JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PaulstretchpluginAudioProcessorEditor)
}; };