milkytracker / MilkyTracker

An FT2 compatible music tracker
http://milkytracker.github.io/
Other
1.7k stars 162 forks source link

Plain text config file #30

Open Deltafire opened 9 years ago

Deltafire commented 9 years ago

Replace the binary config file with plain text, allowing easier configuration and enabling additional options without requiring complication of the config panels.

Something similar to:

# This is a comment
key = value

Would be a good starting point (for more complex configuration we could look at yaml or tcl).

Deltafire commented 9 years ago

Possible libraries we could use:

libconfig boost/program_options json-parser

TOML configuration file format, using cpptoml

mbionchi commented 8 years ago

Hey, I'd like to jump in on that.

dwhinham commented 8 years ago

Awesome! :smiley:

I've been using YAML at work recently for server config files, and I quite like it - easily parsable and very human-readable/editable. An example config file in YAML could look something like this: 2015-12-15-015840_731x912_scrot

What do you think?

mbionchi commented 8 years ago

I think it's good. Originally I was thinking JSON, but there's probably no need for such complications; YAML sounds like a perfect fit.

farvardin commented 8 years ago

yes, YAML would be great. Binarie config are not easy to use.

MBeijer commented 5 years ago

@Deltafire So have we decided for YAML? Or does simple .ini type settings file work as well?

If this work should be done, we need to be able to support the old style format so we can convert it on the fly, so people don't need to set up their configuration from scratch.

I usually prefer not to add external dependencies, so if there's an easy way to add something like YAML without too much work, I'd prefer that.

I'm willing to take on the task if no one else is arsed enough to do it.

Shoozza commented 5 years ago

If ini files are sufficient for the use case, following ini-parser could of interest: https://github.com/benhoyt/inih

exelotl commented 4 years ago

Bumping to say I'd advise against YAML, it's too clever for its own good. I think ini/cfg should do nicely. TOML might also be good, it's well standardised but has a bunch of features we don't really need.

Whichever solution is picked, it would be nice if milky can update the file while still preserving comments.

caseyjoy commented 2 years ago

As a midway step between a full featured config file, and the mostly binary output format we have now, I'm looking into modifying the current system to save and load the config data as strings.

I figured out you can serialize the data out like this:

VERSION = 66304
BUFFERSIZE = 2048
MIXERVOLUME = 256
MIXERSHIFT = 1
RAMPING = 1
INTERPOLATION = 1
MIXERFREQ = 48000
FORCEPOWEROFTWOBUFFERSIZE = 0
AUDIODRIVER = SDLAudio
PLAYMODEKEEPSETTINGS = 0
PLAYMODE = FASTTRACKER2
PLAYMODE_ADVANCED_ALLOW8xx = 1
PLAYMODE_ADVANCED_ALLOWE8x = 0
PLAYMODE_ADVANCED_PTPITCHLIMIT = 1

by modifying the existing TrackerSettingsDatabase::serialize function, and then likely serialize it back in the same way (still working on that part, though).

Why this will likely work (and why it's possible to dump everything out as strings easily in the first place) is that the PPDictionary class it's based on uses PPDictionaryKey, which seems to store everything as a PPString, and then expects you to convert data back to what it's supposed to be later from getStringValue and getIntValue (i.e. BOOL allowExternalKeys = theKey->getIntValue();)

The lucky part about that though, is it means that when serializing everything back in, it should probably be possible to put the string from the file back in, and then have everything keep converting it out again as expected.

Some downsides of a minimal modification approach:

caseyjoy commented 2 years ago

It's looking like this approach works, at least so far - the data will save and load now, and it appears to also load the old style of data. I added a 0 size dword at the beginning in the new format to make it clear to 1.03 that it should treat it as empty and replace the data, as otherwise it'd try to parse it if you rolled back to 1.03 from a version using the new style.

Changing the filename to avoid that kind of thing would also be possible, but that would involve modifying how it selects the config filename: System::getConfigFileName() appears to have different behavior on different systems, so if that gets changed it needs to happen for each platform that currently does different things / has different hardcoded filenames - and it'd need to look for the old one if it can't find the new one, in the places it looks for the standard location currently.

It probably also still needs a dialog to show when the config file has errors in it, as if it's intentionally user editable it's more likely there's going to be typos - probably asking whether the user wants to ignore it, or shut down without replacing the file so they can fix it.