Re: Saving and loading presets for a gui
[email protected] Tue, 27 Apr 2021 12:07:18 +0200
| Newsgroups | gmane.comp.audio.supercollider.user |
|---|---|
| Message-ID | <[email protected]> |
hi
not sure if this is the best solution but I do something like this
( // to save data
var data = Dictionary.new,
data.put("whatever", 333);
data.writeArchive("path/to/file/filename.txt");
)
( // to read data
var data = Object.readArchive("path/to/file/filename.txt");
data.keysValuesDo{ |key, value|
[key, value].postln;
}
)
In the case of storing the state of a GUI I keep a dictionary containing
key,instance for each of the widgets as I construct them
(
var w = Window.new.front;
var controls = Dictionary.new;
controls[\tremolo] = EZSlider( w,
100@30,
"freq",
ControlSpec(0.001, 50, \lin, 0.001, 0.1),
{ |ez| ez.value.postln }
);
)
then when I want to save the GUI state I loop the controls dict storing
the key,value for each widget
(
var data = Dictionary.new,
controls.keysValuesDo { |key, widget|
data.put(key, widget.value)
};
data.writeArchive("path/to/file/filename.txt");
)
and finally to restore the GUI to a particular state
(
var data = Object.readArchive("path/to/file/filename.txt");
data.keysValuesDo{ |key, value|
{controls[key].valueAction = value}.defer
}
)
This code is just copy paste from a big project so I am not sure it runs
properly but I guess you get the idea from it.
enrike
21/4/26 22:53(e)an, [email protected] igorleak idatzi zuen:
> Hi everybody,
>
> I have been trying to figure out a way to save and load presets of a
> gui, but haven't had any luck. Does anyone have any experience with this?
>
> Thank you,
>
> Drew
_______________________________________________
sc-users mailing list
info (subscription, etc.): http://www.birmingham.ac.uk/facilities/ea-studios/research/supercollider/mailinglist.aspx
archive: http://www.listarc.bham.ac.uk/marchives/sc-users/
search: http://www.listarc.bham.ac.uk/lists/sc-users/search/