guileconfig provides a fairly generic format for integrating Guile as the configuration engine for audio apps. Right now it's a little entangled with Paul Barton-Davis's audiohw and soundcard and midi libs, but I expect that will change soon.
If you want to use the guileconfig setup with your app, you need to do a few things:
- rename your main() function to guile_main() and make main() be this function:
int
main(int argc, char ** argv) {
gh_enter(argc, argv, guile_main); }
2. create an instance of the guileconfig class. You can either make a child class called something like my_app_config : public guileconfig or just use the guileconfig class directly. There's a member variable called "variables" which maps variable names to void *'s. You need to allocate storage for each configuration variable and then point the map to it:
int config_num_of_foo;
int config_num_of_bar;
char * config_file_name;
guileconfig config("appname"); // appname determines where to find .apprc
config.variables["num-of-foo"] = &config_num_of_foo; config.variables["num-of-bar"] = &config_num_of_bar; config.variables["file-name"] = &config_file_name;
3. On the Scheme side, call make-config-variable for each named variable. make-config-variable knows about the types, so you will get some type checking. (the void * thing is inherently unsafe but this is a quick hack).
(define num-of-foo (make-config-variable "num-of-foo" 'integer)) (define num-of-bar (make-config-variable "num-of-bar" 'integer)) (define file-name (make-config-variable "file-name" 'string))
Then the user can do stuff like
(set-config-var num-of-foo 2)
and
(get-config-var file-name)
in the .apprc file.
