Mema
Memory Matrix — multi-channel audio matrix monitor and router
Loading...
Searching...
No Matches
MemaReAppConfiguration.cpp
Go to the documentation of this file.
1/* Copyright (c) 2025, 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
21
23 : JUCEAppBasics::AppConfigurationBase()
24{
25 InitializeBase(file, JUCEAppBasics::AppConfigurationBase::Version::FromString(Mema_CONFIG_VERSION));
26}
27
31
33{
34 return isValid(m_xml);
35}
36
37bool MemaReAppConfiguration::isValid(const std::unique_ptr<juce::XmlElement>& xmlConfig)
38{
39 if (!JUCEAppBasics::AppConfigurationBase::isValid(xmlConfig))
40 return false;
41
42 auto connectionConfigSectionElement = xmlConfig->getChildByName(MemaReAppConfiguration::getTagName(MemaReAppConfiguration::TagID::CONNECTIONCONFIG));
43 if (connectionConfigSectionElement)
44 {
45 auto serviceDescriptonXmlElement = connectionConfigSectionElement->getChildByName(MemaReAppConfiguration::getTagName(MemaReAppConfiguration::TagID::SERVICEDESCRIPTION));
46 if (serviceDescriptonXmlElement)
47 {
48 //validate
49 }
50 else
51 return false;
52 }
53 else
54 return false;
55
56 auto visuConfigSectionElement = xmlConfig->getChildByName(MemaReAppConfiguration::getTagName(MemaReAppConfiguration::TagID::VISUCONFIG));
57 if (visuConfigSectionElement)
58 {
59 auto outputPanningXmlElement = visuConfigSectionElement->getChildByName(MemaReAppConfiguration::getTagName(MemaReAppConfiguration::TagID::CONTROLFORMAT));
60 if (outputPanningXmlElement)
61 {
62 //validate
63 }
64 else
65 return false;
66
67 auto panningColourXmlElement = visuConfigSectionElement->getChildByName(MemaReAppConfiguration::getTagName(MemaReAppConfiguration::TagID::CONTROLCOLOUR));
68 if (panningColourXmlElement)
69 {
70 // validate
71 }
72 else
73 return false;
74
75 auto lookAndFeelXmlElement = visuConfigSectionElement->getChildByName(MemaReAppConfiguration::getTagName(MemaReAppConfiguration::TagID::LOOKANDFEEL));
76 if (lookAndFeelXmlElement)
77 {
78 // validate
79 }
80 else
81 return false;
82 }
83 else
84 return false;
85
86 return true;
87}
88
90{
91 auto xmlConfig = juce::parseXML(juce::String(BinaryData::MemaReDefault_config, BinaryData::MemaReDefault_configSize));
92 if (xmlConfig)
93 {
94
96 {
97
98 SetFlushAndUpdateDisabled();
99 if (resetConfigState(std::move(xmlConfig)))
100 {
101 ResetFlushAndUpdateDisabled();
102 return true;
103 }
104 else
105 {
106 jassertfalse; // stop here when debugging, since invalid configurations often lead to endless debugging sessions until this simple explanation was found...
107 ResetFlushAndUpdateDisabled();
108
109 // ...and trigger generation of a valid config if not.
110 triggerConfigurationDump();
111 }
112 }
113 else
114 {
115 jassertfalse; // stop here when debugging, since invalid configurations often lead to endless debugging sessions until this simple explanation was found...
116
117 // ...and trigger generation of a valid config if not.
118 triggerConfigurationDump();
119 }
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
125 // ...and trigger generation of a valid config if not.
126 triggerConfigurationDump();
127 }
128
129 return false;
130}
131
132bool MemaReAppConfiguration::HandleConfigVersionConflict(const JUCEAppBasics::AppConfigurationBase::Version& configVersionFound)
133{
134 if (configVersionFound != JUCEAppBasics::AppConfigurationBase::Version::FromString(Mema_CONFIG_VERSION))
135 {
136 auto conflictTitle = "Incompatible configuration version";
137 auto conflictInfo = "The configuration file version detected\ncannot be handled by this version of " + juce::JUCEApplication::getInstance()->getApplicationName();
138#ifdef DEBUG
139 conflictInfo << "\n(Found " + configVersionFound.ToString() + ", expected " + Mema_CONFIG_VERSION + ")";
140#endif
141 juce::AlertWindow::showOkCancelBox(juce::MessageBoxIconType::WarningIcon, conflictTitle, conflictInfo, "Reset to default", "Quit", nullptr, juce::ModalCallbackFunction::create([this](int result) {
142 if (1 == result)
143 {
145 }
146 else
147 {
148 juce::JUCEApplication::getInstance()->quit();
149 }
150 }));
151
152 return false;
153 }
154 else
155 return true;
156}
157
#define Mema_CONFIG_VERSION
@ CONTROLFORMAT
Active control mode (faderbank, 2-D panning layout, plugin parameters).
@ VISUCONFIG
Root element for visualisation/control settings.
@ LOOKANDFEEL
Active look-and-feel (follow host / dark / light).
@ CONNECTIONCONFIG
Root element for TCP connection settings.
@ SERVICEDESCRIPTION
Stored multicast service descriptor of the last connected Mema instance.
@ CONTROLCOLOUR
User-selected accent colour for control elements.
bool ResetToDefault()
Resets every configuration value to its factory default and triggers a dump.
MemaReAppConfiguration(const File &file)
Constructs the configuration, loading from or creating the given XML file.
static juce::String getTagName(TagID ID)
bool HandleConfigVersionConflict(const Version &configVersionFound) override
Called when the persisted config version differs from the current app version.
bool isValid() override
Returns true when the loaded XML contains all required Mema.Re configuration nodes.