From d972a23ce8fc55369605e85ef86b6f6cda0644a6 Mon Sep 17 00:00:00 2001 From: Alex Birch Date: Wed, 10 Jul 2019 23:13:58 +0100 Subject: [PATCH] move soundFont to its own tag. remove extraneous valueTree. listen directly to relevant part of tree. --- Source/FluidSynthModel.cpp | 22 ++++++++++---------- Source/FluidSynthModel.h | 6 +++--- Source/PluginProcessor.cpp | 41 +++++++++++++++++++++++++++++--------- 3 files changed, 47 insertions(+), 22 deletions(-) diff --git a/Source/FluidSynthModel.cpp b/Source/FluidSynthModel.cpp index 23f2794..b9725b2 100644 --- a/Source/FluidSynthModel.cpp +++ b/Source/FluidSynthModel.cpp @@ -11,12 +11,12 @@ using namespace std; FluidSynthModel::FluidSynthModel( - AudioProcessorValueTreeState& valueTreeState, - ValueTree& valueTree + AudioProcessorValueTreeState& valueTreeState + // ValueTree& valueTree // SharesParams& sharedParams ) : valueTreeState{valueTreeState} -, valueTree{valueTree} +// , valueTree{valueTree} // , sharedParams{sharedParams} //, synth{nullptr} , settings{nullptr, nullptr} @@ -27,11 +27,11 @@ FluidSynthModel::FluidSynthModel( , channel{0}/*, mod(nullptr)*/ { - valueTree.addListener(this); + valueTreeState.state.getChildWithName("soundFont").addListener(this); } FluidSynthModel::~FluidSynthModel() { - valueTree.removeListener(this); + valueTreeState.state.getChildWithName("soundFont").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("soundFontPath"); + valueTreeState.state.sendPropertyChangeMessage("soundFont"); // valueTree.sendPropertyChangeMessage("soundFontPath"); // initialised = true; @@ -204,14 +204,15 @@ void FluidSynthModel::initialise() { void FluidSynthModel::valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged, const Identifier& property) { + if (treeWhosePropertyHasChanged.getType() == StringRef("soundFont")) { // if (&treeWhosePropertyHasChanged == &valueTree) { - if (property == Identifier("soundFontPath")) { - String soundFontPath{treeWhosePropertyHasChanged.getProperty("soundFontPath", "")}; + if (property == StringRef("path")) { + String soundFontPath{treeWhosePropertyHasChanged.getProperty("path", "")}; if (soundFontPath.isNotEmpty()) { loadFont(soundFontPath); } } - // } + } } void FluidSynthModel::setControllerValue(int controller, int value) { @@ -319,7 +320,8 @@ void FluidSynthModel::onFileNameChanged(const String &absPath, int bank, int pre } unloadAndLoadFont(absPath); changePreset(bank, preset); - valueTreeState.state.setPropertyExcludingListener(this, "soundFontPath", absPath, nullptr); + ValueTree valueTree{valueTreeState.state.getChildWithName("soundFont")}; + valueTree.setPropertyExcludingListener(this, "path", absPath, nullptr); // valueTree.setPropertyExcludingListener(this, "soundFontPath", absPath, nullptr); // sharedParams.setSoundFontPath(absPath); eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath); diff --git a/Source/FluidSynthModel.h b/Source/FluidSynthModel.h index a5f2c05..9f08a4b 100644 --- a/Source/FluidSynthModel.h +++ b/Source/FluidSynthModel.h @@ -20,9 +20,9 @@ using namespace std; class FluidSynthModel: public ValueTree::Listener { public: FluidSynthModel( - AudioProcessorValueTreeState& valueTreeState, + AudioProcessorValueTreeState& valueTreeState // SharesParams& sharedParams - ValueTree& valueTree + // ValueTree& valueTree ); ~FluidSynthModel(); @@ -106,7 +106,7 @@ private: AudioProcessorValueTreeState& valueTreeState; // SharesParams& sharedParams; - ValueTree& valueTree; + // ValueTree& valueTree; // https://stackoverflow.com/questions/38980315/is-stdunique-ptr-deletion-order-guaranteed // members are destroyed in reverse of the order they're declared diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index d683e70..8211184 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -35,7 +35,7 @@ JuicySFAudioProcessor::JuicySFAudioProcessor() nullptr, "MYPLUGINSETTINGS", createParameterLayout()} -, fluidSynthModel{valueTreeState, valueTree} +, fluidSynthModel{valueTreeState} //, fluidSynthModel{*this} //, pluginEditor(nullptr) { @@ -43,7 +43,10 @@ JuicySFAudioProcessor::JuicySFAudioProcessor() { "width", GuiConstants::minWidth }, { "height", GuiConstants::minHeight } }, {} }, nullptr); - valueTreeState.state.setProperty("soundFontPath", "", nullptr); + valueTreeState.state.appendChild({ "soundFont", { + { "path", "" }, + }, {} }, nullptr); + // valueTreeState.state.setProperty("soundFontPath", "", nullptr); // valueTreeState.state.appendChild({ "soundFontPath", {} }, nullptr); initialiseSynth(); @@ -407,7 +410,20 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt // This getXmlFromBinary() helper function retrieves our XML from the binary blob.. shared_ptr xmlState{getXmlFromBinary(data, sizeInBytes)}; // unique_ptr xmlState{getXmlFromBinary(data, sizeInBytes)}; - + DEBUG_PRINT(xmlState->createDocument("",false,false)); +/* + + + + + + + + + + + + */ if (xmlState.get() != nullptr) { // make sure that it's actually our type of XML object.. // if (xmlState->hasTagName ("MYPLUGINSETTINGS")) { @@ -418,8 +434,15 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt p->setValue(static_cast(xmlState->getDoubleAttribute(p->paramID, p->getValue()))); { - Value value{valueTreeState.state.getPropertyAsValue("soundFontPath", nullptr)}; - value = xmlState->getStringAttribute("soundFontPath", value.getValue()); + // Value value{valueTreeState.state.getPropertyAsValue("soundFontPath", nullptr)}; + // value = xmlState->getStringAttribute("soundFontPath", value.getValue()); + ValueTree tree{valueTreeState.state.getChildWithName("soundFont")}; + XmlElement* xmlElement{xmlState->getChildByName("soundFont")}; + if (xmlElement) { + Value value{tree.getPropertyAsValue("path", nullptr)}; + value = xmlState->getStringAttribute("path", value.getValue()); + } + // valueTreeState.getParameter("soundFontPath")->getValue() // valueTreeState.getParameter("soundFontPath")->getValue(); // RangedAudioParameter *param {valueTreeState.getParameter("release")}; @@ -429,15 +452,15 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt } { ValueTree tree{valueTreeState.state.getChildWithName("uiState")}; - XmlElement* uiState{xmlState->getChildByName("uiState")}; - if (uiState) { + XmlElement* xmlElement{xmlState->getChildByName("uiState")}; + if (xmlElement) { { Value value{tree.getPropertyAsValue("width", nullptr)}; - value = uiState->getIntAttribute("width", value.getValue()); + value = xmlElement->getIntAttribute("width", value.getValue()); } { Value value{tree.getPropertyAsValue("height", nullptr)}; - value = uiState->getIntAttribute("height", value.getValue()); + value = xmlElement->getIntAttribute("height", value.getValue()); } }