move soundFont to its own tag. remove extraneous valueTree. listen directly to relevant part of tree.
This commit is contained in:
		@ -11,12 +11,12 @@
 | 
				
			|||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FluidSynthModel::FluidSynthModel(
 | 
					FluidSynthModel::FluidSynthModel(
 | 
				
			||||||
    AudioProcessorValueTreeState& valueTreeState,
 | 
					    AudioProcessorValueTreeState& valueTreeState
 | 
				
			||||||
    ValueTree& valueTree
 | 
					    // ValueTree& valueTree
 | 
				
			||||||
    // SharesParams& sharedParams
 | 
					    // SharesParams& sharedParams
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
: valueTreeState{valueTreeState}
 | 
					: valueTreeState{valueTreeState}
 | 
				
			||||||
, valueTree{valueTree}
 | 
					// , valueTree{valueTree}
 | 
				
			||||||
// , sharedParams{sharedParams}
 | 
					// , sharedParams{sharedParams}
 | 
				
			||||||
//, synth{nullptr}
 | 
					//, synth{nullptr}
 | 
				
			||||||
, settings{nullptr, nullptr}
 | 
					, settings{nullptr, nullptr}
 | 
				
			||||||
@ -27,11 +27,11 @@ FluidSynthModel::FluidSynthModel(
 | 
				
			|||||||
, channel{0}/*,
 | 
					, channel{0}/*,
 | 
				
			||||||
mod(nullptr)*/
 | 
					mod(nullptr)*/
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    valueTree.addListener(this);
 | 
					    valueTreeState.state.getChildWithName("soundFont").addListener(this);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FluidSynthModel::~FluidSynthModel() {
 | 
					FluidSynthModel::~FluidSynthModel() {
 | 
				
			||||||
    valueTree.removeListener(this);
 | 
					    valueTreeState.state.getChildWithName("soundFont").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("soundFontPath");
 | 
					    valueTreeState.state.sendPropertyChangeMessage("soundFont");
 | 
				
			||||||
    // valueTree.sendPropertyChangeMessage("soundFontPath");
 | 
					    // valueTree.sendPropertyChangeMessage("soundFontPath");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // initialised = true;
 | 
					    // initialised = true;
 | 
				
			||||||
@ -204,14 +204,15 @@ void FluidSynthModel::initialise() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void FluidSynthModel::valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged,
 | 
					void FluidSynthModel::valueTreePropertyChanged(ValueTree& treeWhosePropertyHasChanged,
 | 
				
			||||||
                                               const Identifier& property) {
 | 
					                                               const Identifier& property) {
 | 
				
			||||||
 | 
					    if (treeWhosePropertyHasChanged.getType() == StringRef("soundFont")) {
 | 
				
			||||||
    // if (&treeWhosePropertyHasChanged == &valueTree) {
 | 
					    // if (&treeWhosePropertyHasChanged == &valueTree) {
 | 
				
			||||||
        if (property == Identifier("soundFontPath")) {
 | 
					        if (property == StringRef("path")) {
 | 
				
			||||||
            String soundFontPath{treeWhosePropertyHasChanged.getProperty("soundFontPath", "")};
 | 
					            String soundFontPath{treeWhosePropertyHasChanged.getProperty("path", "")};
 | 
				
			||||||
            if (soundFontPath.isNotEmpty()) {
 | 
					            if (soundFontPath.isNotEmpty()) {
 | 
				
			||||||
                loadFont(soundFontPath);
 | 
					                loadFont(soundFontPath);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    // }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void FluidSynthModel::setControllerValue(int controller, int value) {
 | 
					void FluidSynthModel::setControllerValue(int controller, int value) {
 | 
				
			||||||
@ -319,7 +320,8 @@ void FluidSynthModel::onFileNameChanged(const String &absPath, int bank, int pre
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    unloadAndLoadFont(absPath);
 | 
					    unloadAndLoadFont(absPath);
 | 
				
			||||||
    changePreset(bank, preset);
 | 
					    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);
 | 
					    // valueTree.setPropertyExcludingListener(this, "soundFontPath", absPath, nullptr);
 | 
				
			||||||
//    sharedParams.setSoundFontPath(absPath);
 | 
					//    sharedParams.setSoundFontPath(absPath);
 | 
				
			||||||
    eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath);
 | 
					    eventListeners.call(&FluidSynthModel::Listener::fontChanged, this, absPath);
 | 
				
			||||||
 | 
				
			|||||||
@ -20,9 +20,9 @@ using namespace std;
 | 
				
			|||||||
class FluidSynthModel: public ValueTree::Listener {
 | 
					class FluidSynthModel: public ValueTree::Listener {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
    FluidSynthModel(
 | 
					    FluidSynthModel(
 | 
				
			||||||
        AudioProcessorValueTreeState& valueTreeState,
 | 
					        AudioProcessorValueTreeState& valueTreeState
 | 
				
			||||||
        // SharesParams& sharedParams
 | 
					        // SharesParams& sharedParams
 | 
				
			||||||
        ValueTree& valueTree
 | 
					        // ValueTree& valueTree
 | 
				
			||||||
        );
 | 
					        );
 | 
				
			||||||
     ~FluidSynthModel();
 | 
					     ~FluidSynthModel();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -106,7 +106,7 @@ private:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    AudioProcessorValueTreeState& valueTreeState;
 | 
					    AudioProcessorValueTreeState& valueTreeState;
 | 
				
			||||||
    // SharesParams& sharedParams;
 | 
					    // SharesParams& sharedParams;
 | 
				
			||||||
    ValueTree& valueTree;
 | 
					    // ValueTree& valueTree;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // https://stackoverflow.com/questions/38980315/is-stdunique-ptr-deletion-order-guaranteed
 | 
					    // https://stackoverflow.com/questions/38980315/is-stdunique-ptr-deletion-order-guaranteed
 | 
				
			||||||
    // members are destroyed in reverse of the order they're declared
 | 
					    // members are destroyed in reverse of the order they're declared
 | 
				
			||||||
 | 
				
			|||||||
@ -35,7 +35,7 @@ JuicySFAudioProcessor::JuicySFAudioProcessor()
 | 
				
			|||||||
    nullptr,
 | 
					    nullptr,
 | 
				
			||||||
    "MYPLUGINSETTINGS",
 | 
					    "MYPLUGINSETTINGS",
 | 
				
			||||||
    createParameterLayout()}
 | 
					    createParameterLayout()}
 | 
				
			||||||
, fluidSynthModel{valueTreeState, valueTree}
 | 
					, fluidSynthModel{valueTreeState}
 | 
				
			||||||
//, fluidSynthModel{*this}
 | 
					//, fluidSynthModel{*this}
 | 
				
			||||||
//, pluginEditor(nullptr)
 | 
					//, pluginEditor(nullptr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
@ -43,7 +43,10 @@ JuicySFAudioProcessor::JuicySFAudioProcessor()
 | 
				
			|||||||
            { "width", GuiConstants::minWidth },
 | 
					            { "width", GuiConstants::minWidth },
 | 
				
			||||||
            { "height", GuiConstants::minHeight }
 | 
					            { "height", GuiConstants::minHeight }
 | 
				
			||||||
        }, {} }, nullptr);
 | 
					        }, {} }, nullptr);
 | 
				
			||||||
    valueTreeState.state.setProperty("soundFontPath", "", nullptr);
 | 
					    valueTreeState.state.appendChild({ "soundFont", {
 | 
				
			||||||
 | 
					        { "path", "" },
 | 
				
			||||||
 | 
					    }, {} }, nullptr);
 | 
				
			||||||
 | 
					    // valueTreeState.state.setProperty("soundFontPath", "", nullptr);
 | 
				
			||||||
//    valueTreeState.state.appendChild({ "soundFontPath", {} }, nullptr);
 | 
					//    valueTreeState.state.appendChild({ "soundFontPath", {} }, nullptr);
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    initialiseSynth();
 | 
					    initialiseSynth();
 | 
				
			||||||
@ -407,7 +410,20 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
 | 
				
			|||||||
    // This getXmlFromBinary() helper function retrieves our XML from the binary blob..
 | 
					    // This getXmlFromBinary() helper function retrieves our XML from the binary blob..
 | 
				
			||||||
    shared_ptr<XmlElement> xmlState{getXmlFromBinary(data, sizeInBytes)};
 | 
					    shared_ptr<XmlElement> xmlState{getXmlFromBinary(data, sizeInBytes)};
 | 
				
			||||||
//    unique_ptr<XmlElement> xmlState{getXmlFromBinary(data, sizeInBytes)};
 | 
					//    unique_ptr<XmlElement> xmlState{getXmlFromBinary(data, sizeInBytes)};
 | 
				
			||||||
 | 
					    DEBUG_PRINT(xmlState->createDocument("",false,false));
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 <MYPLUGINSETTINGS soundFontPath="">
 | 
				
			||||||
 | 
					 <PARAM id="attack" value="0.0"/>
 | 
				
			||||||
 | 
					 <PARAM id="bank" value="0.0"/>
 | 
				
			||||||
 | 
					 <PARAM id="decay" value="0.0"/>
 | 
				
			||||||
 | 
					 <PARAM id="filterCutOff" value="0.0"/>
 | 
				
			||||||
 | 
					 <PARAM id="filterResonance" value="0.0"/>
 | 
				
			||||||
 | 
					 <PARAM id="preset" value="0.0"/>
 | 
				
			||||||
 | 
					 <PARAM id="release" value="0.0"/>
 | 
				
			||||||
 | 
					 <PARAM id="sustain" value="0.0"/>
 | 
				
			||||||
 | 
					 <uiState width="722" height="300"/>
 | 
				
			||||||
 | 
					 </MYPLUGINSETTINGS>
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
    if (xmlState.get() != nullptr) {
 | 
					    if (xmlState.get() != nullptr) {
 | 
				
			||||||
        // make sure that it's actually our type of XML object..
 | 
					        // make sure that it's actually our type of XML object..
 | 
				
			||||||
//        if (xmlState->hasTagName ("MYPLUGINSETTINGS")) {
 | 
					//        if (xmlState->hasTagName ("MYPLUGINSETTINGS")) {
 | 
				
			||||||
@ -418,8 +434,15 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
 | 
				
			|||||||
                    p->setValue(static_cast<float>(xmlState->getDoubleAttribute(p->paramID, p->getValue())));
 | 
					                    p->setValue(static_cast<float>(xmlState->getDoubleAttribute(p->paramID, p->getValue())));
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Value value{valueTreeState.state.getPropertyAsValue("soundFontPath", nullptr)};
 | 
					                // Value value{valueTreeState.state.getPropertyAsValue("soundFontPath", nullptr)};
 | 
				
			||||||
                value = xmlState->getStringAttribute("soundFontPath", value.getValue());
 | 
					                // 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()
 | 
				
			||||||
                // valueTreeState.getParameter("soundFontPath")->getValue();
 | 
					                // valueTreeState.getParameter("soundFontPath")->getValue();
 | 
				
			||||||
                // RangedAudioParameter *param {valueTreeState.getParameter("release")};
 | 
					                // RangedAudioParameter *param {valueTreeState.getParameter("release")};
 | 
				
			||||||
@ -429,15 +452,15 @@ void JuicySFAudioProcessor::setStateInformation (const void* data, int sizeInByt
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                ValueTree tree{valueTreeState.state.getChildWithName("uiState")};
 | 
					                ValueTree tree{valueTreeState.state.getChildWithName("uiState")};
 | 
				
			||||||
                XmlElement* uiState{xmlState->getChildByName("uiState")};
 | 
					                XmlElement* xmlElement{xmlState->getChildByName("uiState")};
 | 
				
			||||||
                if (uiState) {
 | 
					                if (xmlElement) {
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        Value value{tree.getPropertyAsValue("width", nullptr)};
 | 
					                        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 value{tree.getPropertyAsValue("height", nullptr)};
 | 
				
			||||||
                        value = uiState->getIntAttribute("height", value.getValue());
 | 
					                        value = xmlElement->getIntAttribute("height", value.getValue());
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user