Skip to content

Commit ecdd788

Browse files
committed
Small fixes for new settings format
1 parent 893946f commit ecdd788

File tree

4 files changed

+85
-63
lines changed

4 files changed

+85
-63
lines changed

Source/Sidebar/Palettes.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ class Palettes final : public Component
466466

467467
if (state.isEmpty()) {
468468
initialisePalettes(state);
469-
} else {
470-
populateValueTree(state);
471469
}
470+
471+
populateValueTree(state);
472472

473473
palettesTree.addListener(this);
474474

@@ -824,7 +824,9 @@ class Palettes final : public Component
824824
categoryObj->setProperty("items", items);
825825
categories.add(var(categoryObj));
826826
}
827+
827828
SettingsFile::getInstance()->setProperty("palettes", var(categories));
829+
SettingsFile::getInstance()->setProperty("palettes_version", var(paletteVersion));
828830
}
829831

830832
void generatePalettes()
@@ -992,6 +994,7 @@ class Palettes final : public Component
992994
} }
993995
};
994996

997+
static constexpr int paletteVersion = 1;
995998
bool showPalettes = false;
996999

9971000
class ResizerComponent final : public Component {

Source/Standalone/PlugDataWindow.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,14 @@ class StandalonePluginHolder final : private AudioIODeviceCallback
129129
return result;
130130
};
131131

132-
DynamicObject::Ptr audioSetup = new DynamicObject;
133-
auto const xml = deviceManager.createStateXml();
134-
for (int i = 0; i < xml->getNumAttributes(); i++) {
135-
auto const name = camelToSnake(xml->getAttributeName(i));
136-
audioSetup->setProperty(name, xml->getAttributeValue(i));
132+
if(auto const xml = deviceManager.createStateXml()) {
133+
DynamicObject::Ptr audioSetup = new DynamicObject();
134+
for (int i = 0; i < xml->getNumAttributes(); i++) {
135+
auto const name = camelToSnake(xml->getAttributeName(i));
136+
audioSetup->setProperty(name, xml->getAttributeValue(i));
137+
}
138+
SettingsFile::getInstance()->setProperty("audio_setup", var(audioSetup.get()));
137139
}
138-
SettingsFile::getInstance()->setProperty("audio_setup", var(audioSetup.get()));
139140
}
140141

141142
void reloadAudioDeviceState()
@@ -169,7 +170,7 @@ class StandalonePluginHolder final : private AudioIODeviceCallback
169170

170171
std::unique_ptr<XmlElement> savedState;
171172
auto audioSetup = SettingsFile::getInstance()->getDynamicObjectProperty("audio_setup");
172-
if(audioSetup) {
173+
if(audioSetup && audioSetup->getProperties().size()) {
173174
savedState = std::make_unique<XmlElement>("DEVICESETUP");
174175
for(auto& property : audioSetup->getProperties())
175176
{
@@ -490,8 +491,8 @@ class PlugDataWindow final : public DocumentWindow
490491
pluginHolder->stopPlaying();
491492
clearContentComponent();
492493

493-
SettingsFile::getInstance()->setProperty("audio_state", var());
494-
494+
SettingsFile::getInstance()->setProperty("audio_setup", var());
495+
495496
pluginHolder->createPlugin();
496497
setContentOwned(new MainContentComponent(*this, pluginHolder->processor->createEditorIfNeeded()), true);
497498
pluginHolder->startPlaying();

Source/Utility/SettingsFile.cpp

Lines changed: 64 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -67,101 +67,119 @@ static var convertFromLegacyFormat(ValueTree s)
6767
auto* root = new DynamicObject();
6868
var result(root);
6969

70-
auto copy = [&](char const* xmlName, char const* jsonName) {
70+
auto copyInt = [&](char const* xmlName, char const* jsonName) {
7171
if (s.hasProperty(xmlName))
72-
root->setProperty(jsonName, s[xmlName]);
72+
root->setProperty(jsonName, static_cast<int>(s[xmlName]));
7373
};
74-
7574
auto copyBool = [&](char const* xmlName, char const* jsonName) {
7675
if (s.hasProperty(xmlName))
7776
root->setProperty(jsonName, static_cast<bool>(static_cast<int>(s[xmlName])));
7877
};
78+
auto copyFloat = [&](char const* xmlName, char const* jsonName) {
79+
if (s.hasProperty(xmlName))
80+
root->setProperty(jsonName, static_cast<float>(s[xmlName]));
81+
};
82+
auto copyString = [&](char const* xmlName, char const* jsonName) {
83+
if (s.hasProperty(xmlName))
84+
root->setProperty(jsonName, s[xmlName].toString());
85+
};
7986

80-
copy("browser_path", "browser_path");
81-
copy("theme", "theme");
82-
copy("oversampling", "oversampling");
83-
copy("limiter_threshold", "limiter_threshold");
84-
copy("protected", "protected");
85-
copy("debug_connections", "debug_connections");
86-
copy("internal_synth", "internal_synth");
87-
copy("grid_enabled", "grid_enabled");
88-
copy("grid_type", "grid_type");
89-
copy("grid_size", "grid_size");
90-
copy("default_font", "default_font");
91-
copy("global_scale", "global_scale");
92-
copy("default_zoom", "default_zoom");
93-
copy("cpu_meter_mapping_mode", "cpu_meter_mapping_mode");
94-
copy("autosave_interval", "autosave_interval");
95-
copy("autosave_enabled", "autosave_enabled");
96-
copy("show_minimap", "show_minimap");
97-
copy("hvcc_mode", "hvcc_mode");
98-
copy("last_welcome_panel", "last_welcome_panel");
99-
copyBool("native_window", "native_window");
100-
copyBool("autoconnect", "autoconnect");
101-
copyBool("show_palettes", "show_palettes");
102-
copyBool("centre_resized_canvas", "centre_resized_canvas");
103-
copyBool("centre_sidepanel_buttons", "centre_sidepanel_buttons");
104-
copyBool("show_all_audio_device_rates", "show_all_audio_device_rates");
105-
copyBool("add_object_menu_pinned", "add_object_menu_pinned");
106-
copyBool("patch_downwards_only", "patch_downwards_only");
107-
copyBool("search_order", "search_order");
108-
copyBool("search_xy_show", "search_xy_show");
109-
copyBool("search_index_show", "search_index_show");
110-
copyBool("open_patches_in_window", "open_patches_in_window");
111-
copyBool("cmd_click_switches_mode", "cmd_click_switches_mode");
112-
copyBool("touch_mode", "touch_mode");
113-
87+
copyString("browser_path", "browser_path");
88+
copyString("theme", "theme");
89+
copyString("default_font", "default_font");
90+
91+
copyInt("oversampling", "oversampling");
92+
copyInt("limiter_threshold", "limiter_threshold");
93+
copyInt("internal_synth", "internal_synth");
94+
copyInt("grid_type", "grid_type");
95+
copyInt("grid_size", "grid_size");
96+
copyInt("cpu_meter_mapping_mode", "cpu_meter_mapping_mode");
97+
copyInt("autosave_interval", "autosave_interval");
98+
copyInt("show_minimap", "show_minimap");
99+
copyInt("hvcc_mode", "hvcc_mode");
100+
copyInt("last_welcome_panel", "last_welcome_panel");
101+
102+
copyFloat("global_scale", "global_scale");
103+
copyFloat("default_zoom", "default_zoom");
104+
105+
copyBool("protected", "protected");
106+
copyBool("debug_connections", "debug_connections");
107+
copyBool("grid_enabled", "grid_enabled");
108+
copyBool("native_window", "native_window");
109+
copyBool("native_file_dialog", "native_file_dialog");
110+
copyBool("autoconnect", "autoconnect");
111+
copyBool("show_palettes", "show_palettes");
112+
copyBool("centre_resized_canvas", "centre_resized_canvas");
113+
copyBool("centre_sidepanel_buttons", "centre_sidepanel_buttons");
114+
copyBool("show_all_audio_device_rates","show_all_audio_device_rates");
115+
copyBool("add_object_menu_pinned", "add_object_menu_pinned");
116+
copyBool("autosave_enabled", "autosave_enabled");
117+
copyBool("patch_downwards_only", "patch_downwards_only");
118+
copyBool("search_order", "search_order");
119+
copyBool("search_xy_show", "search_xy_show");
120+
copyBool("search_index_show", "search_index_show");
121+
copyBool("open_patches_in_window", "open_patches_in_window");
122+
copyBool("cmd_click_switches_mode", "cmd_click_switches_mode");
123+
copyBool("touch_mode", "touch_mode");
124+
125+
// Paths
114126
Array<var> paths;
115127
if (auto pathsTree = s.getChildWithName("Paths"); pathsTree.isValid())
116128
for (auto path : pathsTree)
117129
paths.add(path["Path"].toString());
118130
root->setProperty("paths", paths);
119131

132+
// Keymap
120133
if (auto keymapTree = s.getChildWithName("KeyMap"); keymapTree.isValid()) {
121134
auto keyxml = keymapTree["keyxml"].toString();
122135
auto encoded = Base64::toBase64(keyxml.toRawUTF8(), keyxml.getNumBytesAsUTF8());
123136
root->setProperty("keymap", encoded);
124137
}
125138

139+
// Themes
126140
Array<var> themes;
127-
if (auto colourThemes = s.getChildWithName("ColourThemes"); colourThemes.isValid()) {
128-
for (auto themeTree : colourThemes) {
141+
if (auto colourThemes = s.getChildWithName("ColourThemes"); colourThemes.isValid())
142+
for (auto themeTree : colourThemes)
129143
themes.add(var(SettingsFile::xmlThemeToJson(themeTree).get()));
130-
}
131-
}
132144
root->setProperty("themes", themes);
133145

146+
// Active themes
134147
if (auto sel = s.getChildWithName("SelectedThemes"); sel.isValid()) {
135148
Array<var> active;
136149
active.add(sel["first"].toString());
137150
active.add(sel["second"].toString());
138151
root->setProperty("active_themes", active);
139152
}
153+
154+
// Recently opened
140155
Array<var> recent;
141156
if (auto recentTree = s.getChildWithName("RecentlyOpened"); recentTree.isValid()) {
142157
for (auto item : recentTree) {
143158
auto* entry = new DynamicObject();
144159
entry->setProperty("path", item["Path"].toString());
145-
entry->setProperty("time", item["Time"]);
160+
entry->setProperty("time", static_cast<int64>(item["Time"]));
146161
recent.add(var(entry));
147162
}
148163
}
149164
root->setProperty("recently_opened", recent);
150165

166+
// Libraries
151167
Array<var> libraries;
152168
if (auto libTree = s.getChildWithName("Libraries"); libTree.isValid())
153169
for (auto lib : libTree)
154170
libraries.add(lib["Path"].toString());
155171
root->setProperty("libraries", libraries);
156172

173+
// Overlays
157174
if (auto overlaysTree = s.getChildWithName("Overlays"); overlaysTree.isValid()) {
158175
auto* overlays = new DynamicObject();
159-
overlays->setProperty("edit", overlaysTree["edit"]);
160-
overlays->setProperty("lock", overlaysTree["lock"]);
161-
overlays->setProperty("run", overlaysTree["run"]);
162-
overlays->setProperty("alt", overlaysTree["alt"]);
176+
overlays->setProperty("edit", static_cast<int>(overlaysTree["edit"]));
177+
overlays->setProperty("lock", static_cast<int>(overlaysTree["lock"]));
178+
overlays->setProperty("run", static_cast<int>(overlaysTree["run"]));
179+
overlays->setProperty("alt", static_cast<int>(overlaysTree["alt"]));
163180
root->setProperty("overlays", var(overlays));
164181
}
182+
165183
return result;
166184
}
167185

Source/Utility/SettingsFile.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ class SettingsFile final
136136
{ "theme", var("light") },
137137
{ "oversampling", var(0) },
138138
{ "limiter_threshold", var(1) },
139-
{ "protected", var(1) },
140-
{ "debug_connections", var(1) },
139+
{ "protected", var(true) },
140+
{ "debug_connections", var(true) },
141141
{ "internal_synth", var(0) },
142-
{ "grid_enabled", var(1) },
142+
{ "grid_enabled", var(true) },
143143
{ "grid_type", var(6) },
144144
{ "grid_size", var(25) },
145145
{ "default_font", var("Inter") },
@@ -155,17 +155,17 @@ class SettingsFile final
155155
{ "show_all_audio_device_rates", var(false) },
156156
{ "add_object_menu_pinned", var(false) },
157157
{ "autosave_interval", var(5) },
158-
{ "autosave_enabled", var(1) },
158+
{ "autosave_enabled", var(true) },
159159
{ "patch_downwards_only", var(false) },
160160
{ "search_order", var(true) },
161161
{ "search_xy_show", var(true) },
162162
{ "search_index_show", var(false) },
163163
{ "open_patches_in_window", var(false) },
164164
{ "cmd_click_switches_mode", var(true) },
165165
{ "show_minimap", var(2) },
166-
{ "hvcc_mode", var(0) },
166+
{ "hvcc_mode", var(false) },
167167
{ "heavy_state", var(0) },
168-
{ "touch_mode", var(0) },
168+
{ "touch_mode", var(false) },
169169
{ "keymap", var("") },
170170
{ "last_welcome_panel", var(0) },
171171
{ "active_themes", var(Array<var> { "light", "dark" }) },

0 commit comments

Comments
 (0)