start hooking up fileChooser to use valueTree instead of coupling to fluidSynth model

This commit is contained in:
Alex Birch 2019-07-10 23:52:15 +01:00
parent d972a23ce8
commit e02188b7f4
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
4 changed files with 47 additions and 12 deletions

View File

@ -4,6 +4,7 @@
#include "FilePicker.h" #include "FilePicker.h"
#include "MyColours.h" #include "MyColours.h"
#include "Util.h"
FilePicker::FilePicker( FilePicker::FilePicker(
AudioProcessorValueTreeState& valueTreeState, AudioProcessorValueTreeState& valueTreeState,
@ -25,13 +26,17 @@ FilePicker::FilePicker(
// faster (rounded edges introduce transparency) // faster (rounded edges introduce transparency)
setOpaque (true); setOpaque (true);
setDisplayedFilePath(fluidSynthModel.getCurrentSoundFontAbsPath()); // setDisplayedFilePath(fluidSynthModel.getCurrentSoundFontAbsPath());
setDisplayedFilePath("");
addAndMakeVisible (fileChooser); addAndMakeVisible (fileChooser);
fileChooser.addListener (this); fileChooser.addListener (this);
valueTreeState.state.addListener(this);
valueTreeState.state.getChildWithName("soundFont").sendPropertyChangeMessage("path");
} }
FilePicker::~FilePicker() { FilePicker::~FilePicker() {
fileChooser.removeListener (this); fileChooser.removeListener (this);
valueTreeState.state.removeListener(this);
} }
void FilePicker::resized() { void FilePicker::resized() {
@ -48,15 +53,31 @@ void FilePicker::paint(Graphics& g)
} }
void FilePicker::filenameComponentChanged (FilenameComponent*) { void FilePicker::filenameComponentChanged (FilenameComponent*) {
currentPath = fileChooser.getCurrentFile().getFullPathName(); // currentPath = fileChooser.getCurrentFile().getFullPathName();
fluidSynthModel.onFileNameChanged(fileChooser.getCurrentFile().getFullPathName(), -1, -1); // fluidSynthModel.onFileNameChanged(fileChooser.getCurrentFile().getFullPathName(), -1, -1);
Value value{valueTreeState.state.getChildWithName("soundFont").getPropertyAsValue("path", nullptr)};
value = fileChooser.getCurrentFile().getFullPathName();
}
void FilePicker::valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) {
if (treeWhosePropertyHasChanged.getType() == StringRef("soundFont")) {
// if (&treeWhosePropertyHasChanged == &valueTree) {
if (property == StringRef("path")) {
String soundFontPath{treeWhosePropertyHasChanged.getProperty("path", "")};
DEBUG_PRINT(soundFontPath);
// if (soundFontPath.isNotEmpty()) {
// loadFont(soundFontPath);
// }
}
}
} }
void FilePicker::setDisplayedFilePath(const String& path) { void FilePicker::setDisplayedFilePath(const String& path) {
if (!shouldChangeDisplayedFilePath(path)) { // if (!shouldChangeDisplayedFilePath(path)) {
return; // return;
} // }
currentPath = path; // currentPath = path;
fileChooser.setCurrentFile(File(path), true, dontSendNotification); fileChooser.setCurrentFile(File(path), true, dontSendNotification);
} }

View File

@ -10,6 +10,7 @@
class FilePicker: public Component, class FilePicker: public Component,
public FilePickerFragment, public FilePickerFragment,
public ValueTree::Listener,
private FilenameComponentListener private FilenameComponentListener
{ {
public: public:
@ -23,6 +24,19 @@ public:
void paint (Graphics& g) override; void paint (Graphics& g) override;
virtual void setDisplayedFilePath(const String&) override; virtual void setDisplayedFilePath(const String&) override;
virtual void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged,
const Identifier& property) override;
inline virtual void valueTreeChildAdded (ValueTree& parentTree,
ValueTree& childWhichHasBeenAdded) override {};
inline virtual void valueTreeChildRemoved (ValueTree& parentTree,
ValueTree& childWhichHasBeenRemoved,
int indexFromWhichChildWasRemoved) override {};
inline virtual void valueTreeChildOrderChanged (ValueTree& parentTreeWhoseChildrenHaveMoved,
int oldIndex, int newIndex) override {};
inline virtual void valueTreeParentChanged (ValueTree& treeWhoseParentHasChanged) override {};
inline virtual void valueTreeRedirected (ValueTree& treeWhichHasBeenChanged) override {};
private: private:
FilenameComponent fileChooser; FilenameComponent fileChooser;

View File

@ -27,11 +27,11 @@ FluidSynthModel::FluidSynthModel(
, channel{0}/*, , channel{0}/*,
mod(nullptr)*/ mod(nullptr)*/
{ {
valueTreeState.state.getChildWithName("soundFont").addListener(this); valueTreeState.state.addListener(this);
} }
FluidSynthModel::~FluidSynthModel() { FluidSynthModel::~FluidSynthModel() {
valueTreeState.state.getChildWithName("soundFont").removeListener(this); valueTreeState.state.removeListener(this);
// if (initialised) { // if (initialised) {
// delete_fluid_audio_driver(driver); // delete_fluid_audio_driver(driver);
// delete_fluid_synth(synth); // delete_fluid_synth(synth);
@ -196,7 +196,7 @@ void FluidSynthModel::initialise() {
fluid_mod_set_amount(mod.get(), 1000.0f); fluid_mod_set_amount(mod.get(), 1000.0f);
fluid_synth_add_default_mod(synth.get(), mod.get(), FLUID_SYNTH_ADD); fluid_synth_add_default_mod(synth.get(), mod.get(), FLUID_SYNTH_ADD);
valueTreeState.state.sendPropertyChangeMessage("soundFont"); valueTreeState.state.getChildWithName("soundFont").sendPropertyChangeMessage("path");
// valueTree.sendPropertyChangeMessage("soundFontPath"); // valueTree.sendPropertyChangeMessage("soundFontPath");
// initialised = true; // initialised = true;

View File

@ -76,7 +76,7 @@ private:
// Params sharedParams; // Params sharedParams;
AudioProcessorValueTreeState valueTreeState; AudioProcessorValueTreeState valueTreeState;
ValueTree valueTree; // ValueTree valueTree;
FluidSynthModel fluidSynthModel; FluidSynthModel fluidSynthModel;
// fluid_synth_t* fluidSynth; // fluid_synth_t* fluidSynth;