onlaj / Piano-LED-Visualizer

Piano LED Visualizer: Connect an LED strip to your Raspberry Pi and create an immersive visual experience for your piano playing
MIT License
494 stars 107 forks source link

UserSettings: Supported nested structure, dict conversion, fast lookups #483

Closed stephen322 closed 8 months ago

stephen322 commented 8 months ago

Support nested UserSettings for eventual color_mode_settings structure. Adjusted to copy missing defaults on initialization rather than inserting unknown settings during run-time.

On a side note, any objections if I were to change the settings file format to say, YAML, rather than XML at some point in the future? It could make things easier code-wise -- just serialize and de-serialize dict.

onlaj commented 8 months ago

any objections if I were to change the settings file format to say, YAML, rather than XML at some point in the future?

I wouldn't mind at all, but there has to be some kind of conversion tool to maintain compatibility with legacy files. This tool would allow us to retain users' settings and ensure seamless updates. Since version 1.5, I've made it a priority to keep it possible to update without the need to install a new image or start the installation from scratch.

I assume you would only change the settings file, right? Refactoring the menu.xml would be a painful task. I admit that dealing with lib/menulcd.py is not pleasant.

stephen322 commented 8 months ago

The rationale was that this idea is a first step to simplify passing config data around the application, rather than custom code to process each setting at various locations. There could be a ledsettings.config dict for the live config, and pass the whole structure to web UI/menulcd. Naturally, color_mode_settings could be passed directly to the ColorMode class. If it were YAML there also wouldn't be a need to convert int/float types. An additional settings_attrib file could hold additional data if needed for min/max checking, etc.

I wasn't thinking menu.xml, but considered sequences.xml -- if it also loaded as a dict, can just update the portion of ledsettings live config.

I haven't thought about profiles or how that would fit in with the above.