2018-02-27 08:25:20 +08:00
|
|
|
//
|
|
|
|
// Created by Alex Birch on 03/10/2017.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "FilePicker.h"
|
|
|
|
#include "MyColours.h"
|
|
|
|
|
|
|
|
FilePicker::FilePicker(
|
|
|
|
FluidSynthModel* fluidSynthModel
|
|
|
|
)
|
|
|
|
: fileChooser(
|
|
|
|
"File",
|
|
|
|
File(),
|
|
|
|
true,
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
"*.sf2;*.sf3",
|
|
|
|
String(),
|
|
|
|
"Choose a Soundfont file to load into the synthesizer"
|
|
|
|
),
|
2018-04-11 07:52:44 +08:00
|
|
|
fluidSynthModel(fluidSynthModel),
|
|
|
|
currentPath() {
|
2018-02-27 08:25:20 +08:00
|
|
|
// faster (rounded edges introduce transparency)
|
|
|
|
setOpaque (true);
|
|
|
|
|
2018-04-11 07:52:44 +08:00
|
|
|
setDisplayedFilePath(fluidSynthModel->getCurrentSoundFontAbsPath());
|
2018-04-11 07:08:15 +08:00
|
|
|
|
2018-02-27 08:25:20 +08:00
|
|
|
addAndMakeVisible (fileChooser);
|
|
|
|
fileChooser.addListener (this);
|
|
|
|
}
|
|
|
|
FilePicker::~FilePicker() {
|
|
|
|
fileChooser.removeListener (this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilePicker::resized() {
|
|
|
|
Rectangle<int> r (getLocalBounds());
|
|
|
|
fileChooser.setBounds (r);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is required to support setOpaque(true)
|
|
|
|
*/
|
|
|
|
void FilePicker::paint(Graphics& g)
|
|
|
|
{
|
|
|
|
g.fillAll(MyColours::getUIColourIfAvailable(LookAndFeel_V4::ColourScheme::UIColour::windowBackground, Colours::lightgrey));
|
|
|
|
}
|
|
|
|
|
|
|
|
void FilePicker::filenameComponentChanged (FilenameComponent*) {
|
2018-04-11 07:52:44 +08:00
|
|
|
currentPath = fileChooser.getCurrentFile().getFullPathName();
|
2018-04-11 06:29:32 +08:00
|
|
|
fluidSynthModel->onFileNameChanged(fileChooser.getCurrentFile().getFullPathName());
|
2018-04-11 07:52:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FilePicker::setDisplayedFilePath(const String& path) {
|
|
|
|
if (!shouldChangeDisplayedFilePath(path)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currentPath = path;
|
|
|
|
fileChooser.setCurrentFile(File(path), true, dontSendNotification);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FilePicker::shouldChangeDisplayedFilePath(const String &path) {
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (path == currentPath) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2018-02-27 08:25:20 +08:00
|
|
|
}
|