/[gluid]/utils.c
ViewVC logotype

Annotation of /utils.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (hide annotations)
Fri Sep 25 22:05:38 2009 UTC (10 years, 8 months ago) by ben
File MIME type: text/plain
File size: 2134 byte(s)
use a file chooserf for soundfont selection
1 ben 1 #include <stdlib.h>
2     #include <stdio.h>
3     #include <glib.h>
4     #include <gtk/gtk.h>
5     #include <sys/socket.h>
6     #include <unistd.h>
7     #include <arpa/inet.h>
8     #include <netinet/in.h>
9     #include <string.h>
10 ben 10 #include "type.h"
11     #include "utils.h"
12 ben 1
13     void quit(AppData* d) {
14     g_free(d->config_path);
15     g_free(d->sfpath);
16     g_free(d->audio);
17     g_free(d->midi);
18     gtk_main_quit();
19     }
20    
21     void read_config (AppData* d) {
22     GKeyFile* kf = NULL;
23     GError* error = NULL;
24    
25     kf = g_key_file_new();
26     g_key_file_load_from_file(kf, d->config_path, G_KEY_FILE_NONE, &error);
27     if(error) {
28     g_free(d->sfpath);
29     d->sfpath = g_strdup("/usr/share/sf2");
30     g_free(d->audio);
31     d->audio = g_strdup("jack");
32     g_free(d->midi);
33     d->midi = g_strdup("jack");
34     write_config(d);
35     g_error_free(error);
36     error = NULL;
37     g_key_file_load_from_file(kf, d->config_path, G_KEY_FILE_NONE, &error);
38     }
39     d->sfpath = g_strdup(g_key_file_get_value (kf, "fluidsynth", "sfpath", &error));
40     if(error) {
41     g_warning("read_config: %s\n", error->message);
42     g_error_free(error);
43     error = NULL;
44     }
45     d->audio = g_key_file_get_value(kf, "fluidsynth", "audio", &error);
46     if(error) {
47     g_warning("read_config: %s\n", error->message);
48     g_error_free(error);
49     error = NULL;
50     }
51     d->midi = g_key_file_get_value(kf, "fluidsynth", "midi", &error);
52     if(error) {
53     g_warning("read_config: %s\n", error->message);
54     g_error_free(error);
55     error = NULL;
56     }
57     g_key_file_free(kf);
58     if (!d->sfpath || d->sfpath[0] == '\0') {
59     g_free(d->sfpath);
60     d->sfpath = g_strdup("/usr/share/sf2");
61     }
62     if (!d->audio) {
63     g_free(d->audio);
64     d->audio = g_strdup("jack");
65     }
66     if (!d->midi) {
67     g_free(d->midi);
68     d->midi = g_strdup("jack");
69     }
70     }
71    
72     void write_config (AppData* d) {
73     GKeyFile* kf = NULL;
74     gchar* data = NULL;
75     gsize len;
76     FILE* fp = NULL;
77    
78     kf = g_key_file_new();
79     g_key_file_set_value (kf, "fluidsynth", "sfpath", d->sfpath);
80     g_key_file_set_value (kf, "fluidsynth", "audio", d->audio);
81     g_key_file_set_value (kf, "fluidsynth", "midi", d->midi);
82     data = g_key_file_to_data(kf, &len, NULL);
83     fp = fopen(d->config_path, "w");
84     /* FIXME: check error (disk full, e.g.) */
85     fputs(data, fp);
86     fclose(fp);
87     g_free(data);
88     }
89    

  ViewVC Help
Powered by ViewVC 1.1.26