/[gluid]/utils.c
ViewVC logotype

Contents of /utils.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 38 - (show annotations)
Wed Sep 30 20:32:22 2009 UTC (7 years, 8 months ago) by ben
File MIME type: text/plain
File size: 2999 byte(s)
rewrote instanciation: safer, simpler, no limit
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 #include "type.h"
11 #include "utils.h"
12
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 g_free(d->reverb);
19 g_free(d->chorus);
20 gtk_main_quit();
21 }
22
23 void read_config (AppData* d) {
24 GKeyFile* kf = NULL;
25 GError* error = NULL;
26
27 kf = g_key_file_new();
28 g_key_file_load_from_file(kf, d->config_path, G_KEY_FILE_NONE, &error);
29 if(error) {
30 g_free(d->sfpath);
31 d->sfpath = g_strdup("/usr/share/sf2");
32 g_free(d->audio);
33 d->audio = g_strdup("jack");
34 g_free(d->midi);
35 d->midi = g_strdup("jack");
36 g_free(d->reverb);
37 d->reverb = g_strdup("yes");
38 g_free(d->chorus);
39 d->chorus = g_strdup("yes");
40
41 write_config(d);
42 g_error_free(error);
43 error = NULL;
44 g_key_file_load_from_file(kf, d->config_path, G_KEY_FILE_NONE, &error);
45 }
46 d->sfpath = g_strdup(g_key_file_get_value (kf, "fluidsynth", "sfpath", &error));
47 if(error) {
48 g_warning("read_config: %s\n", error->message);
49 g_error_free(error);
50 error = NULL;
51 }
52 d->audio = g_key_file_get_value(kf, "fluidsynth", "audio", &error);
53 if(error) {
54 g_warning("read_config: %s\n", error->message);
55 g_error_free(error);
56 error = NULL;
57 }
58 d->midi = g_key_file_get_value(kf, "fluidsynth", "midi", &error);
59 if(error) {
60 g_warning("read_config: %s\n", error->message);
61 g_error_free(error);
62 error = NULL;
63 }
64 d->reverb = g_key_file_get_value(kf, "fluidsynth", "reverb", &error);
65 if(error) {
66 g_warning("read_config: %s\n", error->message);
67 g_error_free(error);
68 error = NULL;
69 }
70 d->chorus = g_key_file_get_value(kf, "fluidsynth", "chorus", &error);
71 if(error) {
72 g_warning("read_config: %s\n", error->message);
73 g_error_free(error);
74 error = NULL;
75 }
76 g_key_file_free(kf);
77
78 if (!d->sfpath || d->sfpath[0] == '\0') {
79 g_free(d->sfpath);
80 d->sfpath = g_strdup("/usr/share/sf2");
81 }
82 if (!d->audio || d->audio[0] == '\0') {
83 g_free(d->audio);
84 d->audio = g_strdup("jack");
85 }
86 if (!d->midi || d->midi[0] == '\0') {
87 g_free(d->midi);
88 d->midi = g_strdup("jack");
89 }
90 if (!d->reverb || d->reverb[0] == '\0') {
91 g_free(d->reverb);
92 d->reverb = g_strdup("yes");
93 }
94 if (!d->chorus || d->chorus[0] == '\0') {
95 g_free(d->chorus);
96 d->chorus = g_strdup("yes");
97 }
98 }
99
100 void write_config (AppData* d) {
101 GKeyFile* kf = NULL;
102 gchar* data = NULL;
103 gsize len;
104 FILE* fp = NULL;
105
106 kf = g_key_file_new();
107 g_key_file_set_value (kf, "fluidsynth", "sfpath", d->sfpath);
108 g_key_file_set_value (kf, "fluidsynth", "audio", d->audio);
109 g_key_file_set_value (kf, "fluidsynth", "midi", d->midi);
110 g_key_file_set_value (kf, "fluidsynth", "reverb", d->reverb);
111 g_key_file_set_value (kf, "fluidsynth", "chorus", d->chorus);
112 data = g_key_file_to_data(kf, &len, NULL);
113 fp = fopen(d->config_path, "w");
114 /* FIXME: check error (disk full, e.g.) */
115 fputs(data, fp);
116 fclose(fp);
117 g_free(data);
118 }
119

  ViewVC Help
Powered by ViewVC 1.1.26