diff options
author | David Runge <dave@sleepmap.de> | 2016-07-06 19:38:54 +0200 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2016-07-06 19:38:54 +0200 |
commit | 8641328aa6eba6b24391dca1d7f6516beaea8d04 (patch) | |
tree | 3c245760349fc2b7bbbaeeeb370e145a69bfc7c5 /classes | |
parent | 83729188d938756c60458e0722bcb58e27e11736 (diff) | |
download | bowelyzer-8641328aa6eba6b24391dca1d7f6516beaea8d04.tar.gz bowelyzer-8641328aa6eba6b24391dca1d7f6516beaea8d04.tar.bz2 bowelyzer-8641328aa6eba6b24391dca1d7f6516beaea8d04.tar.xz bowelyzer-8641328aa6eba6b24391dca1d7f6516beaea8d04.zip |
classes/BowelyzerConfig.sc: Adding writeConfigurationFile functionality (valid JSON, yay). Adding global configFilePath. Updating hfThreshold ControlSpec to default to 1.0. Removing obsolete comments.0.5
Diffstat (limited to 'classes')
-rw-r--r-- | classes/BowelyzerConfig.sc | 103 |
1 files changed, 100 insertions, 3 deletions
diff --git a/classes/BowelyzerConfig.sc b/classes/BowelyzerConfig.sc index 287aad4..1a4ce87 100644 --- a/classes/BowelyzerConfig.sc +++ b/classes/BowelyzerConfig.sc @@ -66,6 +66,7 @@ BowelyzerConfig{ ]; var <config, + <configFilePath, <defaultConfig, <defaultControls, <changed = false; @@ -97,10 +98,13 @@ BowelyzerConfig{ if(this.readConfigurationFile(configFile).not,{ error("Reading of configuration file failed. Using default."); config = defaultConfig; + },{ + configFilePath = configFile; }); },{ ("No configuration file provided. Using default.").postln; config = defaultConfig; + configFilePath = ""; }); this.showConfig; } @@ -111,7 +115,7 @@ BowelyzerConfig{ ControlSpec.specs[\amplitudeReleaseTime] = ControlSpec(0.001, 10, \lin, 0.001, 0.01, units: "s"); ControlSpec.specs[\hfHainsworth] = ControlSpec(0.0, 1.0, \lin, 0.001, 1.0, units: ""); ControlSpec.specs[\hfFoote] = ControlSpec(0.0, 1.0, \lin, 0.001, 0.0, units: ""); - ControlSpec.specs[\hfThreshold] = ControlSpec(0.0, 1.0, \lin, 0.001, 1.0, units: ""); + ControlSpec.specs[\hfThreshold] = ControlSpec(0.0, 10.0, \lin, 0.001, 1.0, units: ""); ControlSpec.specs[\hfWaitTime] = ControlSpec(0.0, 1.0, \lin, 0.001, 0.04, units: "s"); ControlSpec.specs[\pitchInitFreq] = ControlSpec(20.0, 20000.0, \exp, 0.01, 440.0, units: "Hz"); ControlSpec.specs[\pitchMinFreq] = ControlSpec(20.0, 20000.0, \exp, 0.01, 60.0, units: "Hz"); @@ -153,7 +157,6 @@ BowelyzerConfig{ \left -> 0, \right -> 1 ]), - //names -> [left, right], \synthServerAddress -> "127.0.0.1", \synthServerPort -> 57110, \hubAddress -> "127.0.0.1", @@ -230,7 +233,100 @@ BowelyzerConfig{ }); } - //TODO: add writeConfigurationFile + // write a valid JSON file from configuration + writeConfigurationFile{ + arg fileName; + var configFile, + path, + overwriteConfigFilePath = false, + writeFinished = false; + configFilePath.postln; + fileName.postln; + if(fileName.isNil, { + if(configFilePath.notNil, { + path = configFilePath; + },{ + "No configuration file defined!".error; + }); + },{ + path = fileName; + overwriteConfigFilePath = true; + }); + if(path != "",{ + path.postln; + try{ + configFile = File.use( + path.asString, + "w", + {|configFile| + var controlNamesSize = config.at(\controls).size, + currentControlName = 0, + controlsSize = defaultControls.size, + currentControl = 0, + inputsSize = config.at(\inputs).size, + currentInput = 0; + configFile.write("{\n"); + // global settings + config.pairsDo({|key, value| + if(key != \controls && key != \inputs, { + if(hasToBeString.includes(key), { + configFile.write(" \""++key++"\": \""++value++"\",\n"); + }); + if(hasToBeInteger.includes(key),{ + configFile.write(" \""++key++"\": "++value++",\n"); + }); + }); + }); + // controls + configFile.write(" \"controls\": {\n"); + config.at(\controls).pairsDo({|key, value| + currentControlName = currentControlName+1; + configFile.write(" \""++key++"\": {\n"); + value.pairsDo({|control, controlValue| + currentControl = currentControl+1; + if(currentControl == controlsSize,{ + configFile.write(" \""++control++"\": "++controlValue++"\n"); + },{ + configFile.write(" \""++control++"\": "++controlValue++",\n"); + }); + }); + // closing brace + if(currentControlName == controlNamesSize,{ + configFile.write(" }\n"); + },{ + configFile.write(" },\n"); + }); + currentControl = 0; + }); + // closing brace for controls + configFile.write(" },\n"); + // inputs + configFile.write(" \"inputs\": {\n"); + config.at(\inputs).pairsDo({|key, value| + currentInput = currentInput+1; + if(currentInput == inputsSize,{ + configFile.write(" \""++key++"\": "++value++"\n"); + },{ + configFile.write(" \""++key++"\": "++value++",\n"); + }); + }); + // closing brace for inputs + configFile.write(" }\n"); + // closing brace for notation + configFile.write("}\n"); + configFile.close; + writeFinished = true; + } + ); + }{ + ("Failed writing the file: "++path).error; + ^false; + } + }); + if(writeFinished && overwriteConfigFilePath, { + configFilePath = fileName; + }); + } // return a control value as correct type and within its defined ControlSpec range getControlValue{ @@ -275,6 +371,7 @@ BowelyzerConfig{ var broken = false; //fail if there are no inputs defined if(config.includesKey(\inputs).not,{ + "No inputs defined!".error; ^false; }); // if there are no controls defined at all, add at least a Dictionary for them |