Hi,
in order to keep the code lean and to reset patterns, I was hoping to store pattern values in an external file. I was messing around with a json file.
The Json file
{
"dis" :
{
"instrument": "dissent",
"dur": "1",
"degree": "Pseq([0, Pseq([Rest(0)], 7)], inf)",
}
}
With this code I load the file and parse it with parseYAML.
//the path to the json file
~jsonPath = "data/SynthJson01.json";
(
var f, file;
f = File(~jsonPath, "r");
~reset = Dictionary.new;
file = f.readAllString.parseYAML;
file.postln;
file["dis"].keysValuesDo{|k, v|
~reset.put(k.asSymbol, v);
};
//the pattern I want to build from the file
~dis = Pbindef(\dis, *~reset.asPairs);
)
parseYAML gives me a nice Dictionary and the patterns seem to be constructed. Since Json is based on Strings, I wonder how to control the values of the ~reset dictionary. For the numeric values I could use value.asFloat. But what about this pair?
"degree": "Pseq([0, Pseq([Rest(0)], 7)], inf)"
Pseq is a “Pseq” or a function. I cannot do value.asFunction. In the Dictionary the key-value pairs don’t have quotes but the Pbindef comes all in quotes and that does not work in the Pbindef.
-> Dictionary[ (instrument -> dissent), (sus -> 0.9), (degree -> a Function), (dur -> 1), (atk -> 1.5) ]
-> Pbindef('dis', "instrument", "dissent", "atk", "1.5", "dur", "1", "sus", "0.9", "degree", "Pseq([0, Pseq([Rest(0)], 7)], inf)", 'sus', "0.9", 'instrument', "dissent", 'degree', Pseq([0, Pseq([Rest(0)], 7)], inf) , 'dur', "1", 'atk', "1.5")
- Where can I transform the String values of the json file into workable values for the pattern?
- Vice verca: Is it possible to save a Dictionary into a Json File?
thank you for looking into it
Qoris