Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
MemaAppConfiguration.cpp
Go to the documentation of this file.
1/* Copyright (c) 2024, Christian Ahrens
2 *
3 * This file is part of Mema <https://github.com/ChristianAhrens/Mema>
4 *
5 * This tool is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 3.0 as published
7 * by the Free Software Foundation.
8 *
9 * This tool is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this tool; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
20
21namespace Mema
22{
23
25 : JUCEAppBasics::AppConfigurationBase()
26{
27 InitializeBase(file, JUCEAppBasics::AppConfigurationBase::Version::FromString(Mema_CONFIG_VERSION));
28}
29
33
35{
36 return isValid(m_xml);
37}
38
39bool MemaAppConfiguration::isValid(const std::unique_ptr<juce::XmlElement>& xmlConfig)
40{
41 if (!JUCEAppBasics::AppConfigurationBase::isValid(xmlConfig))
42 return false;
43
44 auto editorCfgSectionElement = xmlConfig->getChildByName(MemaAppConfiguration::getTagName(MemaAppConfiguration::TagID::UICONFIG));
45 if (editorCfgSectionElement)
46 {
47 // validate
48 }
49 else
50 return false;
51
52 auto processorSectionElement = xmlConfig->getChildByName(MemaAppConfiguration::getTagName(MemaAppConfiguration::TagID::PROCESSORCONFIG));
53 if (processorSectionElement)
54 {
55 auto devSectionElement = processorSectionElement->getChildByName(MemaAppConfiguration::getTagName(MemaAppConfiguration::TagID::DEVCONFIG));
56 if (devSectionElement)
57 {
58 // validate
59 }
60 else
61 return false;
62
63 auto plginSectionElement = processorSectionElement->getChildByName(MemaAppConfiguration::getTagName(MemaAppConfiguration::TagID::PLUGINCONFIG));
64 if (plginSectionElement)
65 {
67 return false;
69 return false;
70
71 // validate
72 }
73 else
74 return false;
75
76 auto inputMutesSectionElement = processorSectionElement->getChildByName(MemaAppConfiguration::getTagName(MemaAppConfiguration::TagID::INPUTMUTES));
77 if (inputMutesSectionElement)
78 {
79 // validate
80 }
81 else
82 return false;
83
84 auto crosspointGainsSectionElement = processorSectionElement->getChildByName(MemaAppConfiguration::getTagName(MemaAppConfiguration::TagID::CROSSPOINTGAINS));
85 if (crosspointGainsSectionElement)
86 {
87 // validate
88 }
89 else
90 return false;
91
92 auto outputMutesSectionElement = processorSectionElement->getChildByName(MemaAppConfiguration::getTagName(MemaAppConfiguration::TagID::OUTPUTMUTES));
93 if (outputMutesSectionElement)
94 {
95 // validate
96 }
97 else
98 return false;
99 }
100 else
101 return false;
102
103 return true;
104}
105
107{
108 auto xmlConfig = juce::parseXML(juce::String(BinaryData::MemaDefault_config, BinaryData::MemaDefault_configSize));
109 if (xmlConfig)
110 {
111
113 {
114
115 SetFlushAndUpdateDisabled();
116 if (resetConfigState(std::move(xmlConfig)))
117 {
118 ResetFlushAndUpdateDisabled();
119 return true;
120 }
121 else
122 {
123 jassertfalse; // stop here when debugging, since invalid configurations often lead to endless debugging sessions until this simple explanation was found...
124 ResetFlushAndUpdateDisabled();
125
126 // ...and trigger generation of a valid config if not.
127 triggerConfigurationDump();
128 }
129 }
130 else
131 {
132 jassertfalse; // stop here when debugging, since invalid configurations often lead to endless debugging sessions until this simple explanation was found...
133
134 // ...and trigger generation of a valid config if not.
135 triggerConfigurationDump();
136 }
137 }
138 else
139 {
140 jassertfalse; // stop here when debugging, since invalid configurations often lead to endless debugging sessions until this simple explanation was found...
141
142 // ...and trigger generation of a valid config if not.
143 triggerConfigurationDump();
144 }
145
146 return false;
147}
148
149bool MemaAppConfiguration::HandleConfigVersionConflict(const JUCEAppBasics::AppConfigurationBase::Version& configVersionFound)
150{
151 if (configVersionFound != JUCEAppBasics::AppConfigurationBase::Version::FromString(Mema_CONFIG_VERSION))
152 {
153 auto conflictTitle = "Incompatible configuration version";
154 auto conflictInfo = "The configuration file version detected\ncannot be handled by this version of " + juce::JUCEApplication::getInstance()->getApplicationName();
155#ifdef DEBUG
156 conflictInfo << "\n(Found " + configVersionFound.ToString() + ", expected " + Mema_CONFIG_VERSION + ")";
157#endif
158 juce::AlertWindow::showOkCancelBox(juce::MessageBoxIconType::WarningIcon, conflictTitle, conflictInfo, "Reset to default", "Quit", nullptr, juce::ModalCallbackFunction::create([this](int result) {
159 if (1 == result)
160 {
162 }
163 else
164 {
165 juce::JUCEApplication::getInstance()->quit();
166 }
167 }));
168
169 return false;
170 }
171 else
172 return true;
173}
174
175
176} // namespace Mema
#define Mema_CONFIG_VERSION
static juce::String getTagName(TagID ID)
@ PLUGINCONFIG
Plugin host settings.
@ PROCESSORCONFIG
Audio processor settings.
@ CROSSPOINTGAINS
Crosspoint matrix gain values.
@ DEVCONFIG
Audio device configuration.
@ OUTPUTMUTES
Per-channel output mute states.
@ UICONFIG
UI layout and appearance.
@ INPUTMUTES
Per-channel input mute states.
bool ResetToDefault()
Resets every value to factory defaults and triggers a dump.
static juce::String getAttributeName(AttributeID ID)
MemaAppConfiguration(const File &file)
Constructs the configuration, loading from or creating the given XML file.
@ ENABLED
Boolean enabled flag.
@ POST
Post-matrix plugin insertion flag.
bool isValid() override
Returns true when the loaded XML contains all required configuration nodes.
bool HandleConfigVersionConflict(const Version &configVersionFound) override
Called when the persisted config version differs from the current app version.
Definition Mema.cpp:27