move soundFont to its own tag. remove extraneous valueTree. listen directly to relevant part of tree.

This commit is contained in:
Alex Birch 2019-07-10 23:13:58 +01:00
parent 568495ea74
commit d972a23ce8
No known key found for this signature in database
GPG Key ID: 305EB1F98D44ACBA
3 changed files with 47 additions and 22 deletions

View File

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

View File

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

View File

@ -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<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) {
// 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<float>(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());
}
}