/[gluid]/controller.c
ViewVC logotype

Contents of /controller.c

Parent Directory Parent Directory | Revision Log Revision Log


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

  ViewVC Help
Powered by ViewVC 1.1.26