2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2003 Alexander König
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Description: This file contains the routines for handling the
22 "globals" block. Intializing, reading setup from
27 21 Jul 1999: introduced the lowpass globals.
28 There were some changes in between...
29 14 Jul 2002: switched to libxml instead of binary saving.
36 #include "tX_global.h"
38 #include <libxml/xmlmemory.h>
39 #include <libxml/parser.h>
41 #define TX_XML_RC_VERSION "1.0"
45 void get_rc_name(char *buffer)
48 if (globals.alternate_rc)
50 strcpy(buffer, globals.alternate_rc);
56 strcpy(buffer, getenv("HOME"));
57 if (buffer[strlen(buffer)-1]!='/')
60 strcat(buffer, ".terminatorXrc");
64 void set_global_defaults() {
65 globals.startup_set = 0;
66 globals.store_globals = 1;
68 globals.alternate_rc = 0;
71 strcpy(globals.xinput_device, "");
72 globals.xinput_enable=0;
74 globals.update_idle=18;
75 globals.update_delay=1;
77 strcpy(globals.oss_device, "/dev/dsp");
78 globals.oss_buff_no=2;
79 globals.oss_buff_size=9;
80 globals.oss_samplerate=44100;
82 strcpy(globals.alsa_device, "hw:0,0");
83 globals.alsa_buff_no=2;
84 globals.alsa_buff_size=1024;
85 globals.alsa_samplerate=44100;
87 globals.sense_cycles=12;
89 globals.mouse_speed=0.8;
97 globals.use_stdout_from_conf_file=0;
102 strcpy(globals.last_fn,"");
108 globals.flash_response=0.95;
110 globals.button_type=BUTTON_TYPE_BOTH;
112 globals.true_block_size=0;
114 strcpy(globals.tables_filename, "");
115 strcpy(globals.record_filename, "tX_record.wav");
116 strcpy(globals.file_editor, "");
119 globals.audiodevice_type=OSS;
122 globals.audiodevice_type=ALSA;
125 globals.use_stdout_cmdline=0;
126 globals.current_path = NULL;
130 strcpy(globals.lrdf_path, "/usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf");
131 globals.fullscreen_enabled=1;
133 if (!globals.true_block_size) globals.true_block_size=1<globals.oss_buff_size;
136 int load_globals_xml() {
137 char rc_name[PATH_MAX]="";
138 char device_type[16]="oss";
144 get_rc_name(rc_name);
146 doc = xmlParseFile(rc_name);
149 fprintf(stderr, "tX: err: Error parsing terminatorXrc.\n");
153 cur = xmlDocGetRootElement(doc);
156 fprintf(stderr,"tX: err: terminatorXrc contains no elements.\n");
161 if (xmlStrcmp(cur->name, (const xmlChar *) "terminatorXrc")) {
162 fprintf(stderr,"tX: err: This terminatorXrc is not a terminatorXrc.");
167 for (cur=cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
168 if (cur->type == XML_ELEMENT_NODE) {
171 restore_int("store_globals", globals.store_globals);
173 restore_string("audio_driver", device_type);
175 restore_string("oss_device", globals.oss_device);
176 restore_int("oss_buff_no", globals.oss_buff_no);
177 restore_int("oss_buff_size", globals.oss_buff_size);
178 restore_int("oss_samplerate", globals.oss_samplerate);
180 restore_string("alsa_device", globals.alsa_device);
181 restore_int("alsa_buff_no", globals.alsa_buff_no);
182 restore_int("alsa_buff_size", globals.alsa_buff_size);
183 restore_int("alsa_samplerate", globals.alsa_samplerate);
185 restore_string("xinput_device", globals.xinput_device);
186 restore_int("xinput_enable", globals.xinput_enable);
187 restore_int("update_idle", globals.update_idle);
188 restore_int("update_delay", globals.update_delay);
189 restore_int("sense_cycles", globals.sense_cycles);
190 restore_float("mouse_speed", globals.mouse_speed);
191 restore_int("width", globals.width);
192 restore_int("height", globals.height);
193 restore_int("tooltips", globals.tooltips);
194 restore_int("use_stdout", globals.use_stdout);
195 restore_int("show_nag", globals.show_nag);
196 restore_int("prelis", globals.prelis);
197 restore_string("last_fn", globals.last_fn);
198 restore_float("pitch", globals.pitch);
199 restore_float("volume", globals.volume);
200 restore_float("flash_response", globals.flash_response);
201 restore_int("button_type", globals.button_type);
202 restore_int("true_block_size", globals.true_block_size);
203 restore_string("tables_filename", globals.tables_filename);
204 restore_string("record_filename", globals.record_filename);
205 restore_string("file_editor", globals.file_editor);
206 restore_string("lrdf_path", globals.lrdf_path);
208 restore_int("fullscreen_enabled", globals.fullscreen_enabled);
211 fprintf(stderr, "tX: Unhandled XML element: \"%s\"\n", cur->name);
218 if (strcmp(device_type, "alsa")==0) globals.audiodevice_type=ALSA;
219 else if (strcmp(device_type, "jack")==0) globals.audiodevice_type=JACK;
220 else globals.audiodevice_type=OSS;
225 void store_globals() {
226 char rc_name[PATH_MAX]="";
227 char device_type[16];
230 char tmp_xml_buffer[4096];
232 get_rc_name(rc_name);
234 rc=fopen(rc_name, "w");
236 switch (globals.audiodevice_type) {
238 strcpy(device_type, "jack");
241 strcpy(device_type, "alsa");
245 strcpy(device_type, "oss");
250 fprintf(rc, "<?xml version=\"1.0\" encoding=\"US-ASCII\"?>\n\n");
251 fprintf(rc, "<!-- Warning: this file will be rewritten by terminatorX on exit!\n Don\'t waste your time adding comments - they will be erased -->\n\n" );
252 fprintf(rc, "<terminatorXrc version=\"%s\">\n", TX_XML_RC_VERSION);
254 store_int("store_globals", globals.store_globals);
256 store_string("audio_driver", device_type);
258 store_string("oss_device", globals.oss_device);
259 store_int("oss_buff_no", globals.oss_buff_no);
260 store_int("oss_buff_size", globals.oss_buff_size);
261 store_int("oss_samplerate", globals.oss_samplerate);
263 store_string("alsa_device", globals.alsa_device);
264 store_int("alsa_buff_no", globals.alsa_buff_no);
265 store_int("alsa_buff_size", globals.alsa_buff_size);
266 store_int("alsa_samplerate", globals.alsa_samplerate);
268 store_string("xinput_device", globals.xinput_device);
269 store_int("xinput_enable", globals.xinput_enable);
270 store_int("update_idle", globals.update_idle);
271 store_int("update_delay", globals.update_delay);
272 store_int("sense_cycles", globals.sense_cycles);
273 store_float("mouse_speed", globals.mouse_speed);
274 store_int("width", globals.width);
275 store_int("height", globals.height);
276 store_int("tooltips", globals.tooltips);
277 store_int("use_stdout", globals.use_stdout);
278 // globals.use_stdout_from_conf_file=0; What the heck is this?
279 store_int("show_nag", globals.show_nag);
280 store_int("prelis", globals.prelis);
281 store_string("last_fn", globals.last_fn);
282 store_float("pitch", globals.pitch);
283 store_float("volume", globals.volume);
284 store_float("flash_response", globals.flash_response);
285 store_int("button_type", globals.button_type);
286 store_int("true_block_size", globals.true_block_size);
287 store_string("tables_filename", globals.tables_filename);
288 store_string("record_filename", globals.record_filename);
289 store_string("file_editor", globals.file_editor);
290 store_string("lrdf_path", globals.lrdf_path);
291 store_int("fullscreen_enabled", globals.fullscreen_enabled);
293 fprintf(rc,"</terminatorXrc>\n");
297 #ifdef ENABLE_TX_LEGACY
298 extern void load_globals_old();
301 void load_globals() {
302 set_global_defaults();
304 if (load_globals_xml()!=0) {
305 fprintf(stderr, "tX: Failed loading terminatorXrc - trying to load old binary rc.\n");
306 #ifdef ENABLE_TX_LEGACY
312 char *encode_xml(char *dest, const char *src) {
319 for (i=0; i<max; i++) {
321 case '<': dest[t]=0; strcat(dest, "<"); t+=4; break;
322 case '>': dest[t]=0; strcat(dest, ">"); t+=4; break;
323 case '&': dest[t]=0; strcat(dest, "&"); t+=5; break;
324 case '"': dest[t]=0; strcat(dest, """); t+=6; break;
325 case '\'': strcat(dest, "'"); t+=7; break;
326 default: dest[t]=src[i]; t++;
331 //tX_debug("encode_xml: from \"%s\" to \"%s\".", src, dest);