diff --git a/Source/FilePicker.cpp b/Source/FilePicker.cpp index 6ddf8ab..46d1aa5 100644 --- a/Source/FilePicker.cpp +++ b/Source/FilePicker.cpp @@ -4,6 +4,7 @@ #include "FilePicker.h" #include "MyColours.h" +#include "Util.h" FilePicker::FilePicker( AudioProcessorValueTreeState& valueTreeState, @@ -25,13 +26,17 @@ FilePicker::FilePicker( // faster (rounded edges introduce transparency) setOpaque (true); - setDisplayedFilePath(fluidSynthModel.getCurrentSoundFontAbsPath()); + // setDisplayedFilePath(fluidSynthModel.getCurrentSoundFontAbsPath()); + setDisplayedFilePath(""); addAndMakeVisible (fileChooser); fileChooser.addListener (this); + valueTreeState.state.addListener(this); + valueTreeState.state.getChildWithName("soundFont").sendPropertyChangeMessage("path"); } FilePicker::~FilePicker() { fileChooser.removeListener (this); + valueTreeState.state.removeListener(this); } void FilePicker::resized() { @@ -48,15 +53,31 @@ void FilePicker::paint(Graphics& g) } void FilePicker::filenameComponentChanged (FilenameComponent*) { - currentPath = fileChooser.getCurrentFile().getFullPathName(); - fluidSynthModel.onFileNameChanged(fileChooser.getCurrentFile().getFullPathName(), -1, -1); + // currentPath = fileChooser.getCurrentFile().getFullPathName(); + // 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) { - if (!shouldChangeDisplayedFilePath(path)) { - return; - } - currentPath = path; + // if (!shouldChangeDisplayedFilePath(path)) { + // return; + // } + // currentPath = path; fileChooser.setCurrentFile(File(path), true, dontSendNotification); } @@ -68,4 +89,4 @@ bool FilePicker::shouldChangeDisplayedFilePath(const String &path) { return false; } return true; -} \ No newline at end of file +} diff --git a/Source/FilePicker.h b/Source/FilePicker.h index c187724..1c3e39d 100644 --- a/Source/FilePicker.h +++ b/Source/FilePicker.h @@ -10,6 +10,7 @@ class FilePicker: public Component, public FilePickerFragment, + public ValueTree::Listener, private FilenameComponentListener { public: @@ -23,6 +24,19 @@ public: void paint (Graphics& g) 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: FilenameComponent fileChooser; diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index b9725b2..976352e 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -27,11 +27,11 @@ FluidSynthModel::FluidSynthModel( , channel{0}/*, mod(nullptr)*/ { - valueTreeState.state.getChildWithName("soundFont").addListener(this); + valueTreeState.state.addListener(this); } FluidSynthModel::~FluidSynthModel() { - valueTreeState.state.getChildWithName("soundFont").removeListener(this); + valueTreeState.state.removeListener(this); // if (initialised) { // delete_fluid_audio_driver(driver); // delete_fluid_synth(synth); @@ -196,7 +196,7 @@ void FluidSynthModel::initialise() { fluid_mod_set_amount(mod.get(), 1000.0f); 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"); // initialised = true; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index 08a7c41..d3cfdca 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -76,7 +76,7 @@ private: // Params sharedParams; AudioProcessorValueTreeState valueTreeState; - ValueTree valueTree; + // ValueTree valueTree; FluidSynthModel fluidSynthModel; // fluid_synth_t* fluidSynth;