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 "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);
}

View File

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

View File

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

View File

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