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>
40 #include <libxml/encoding.h>
43 #define TX_XML_RC_VERSION "1.0"
46 int _store_compress_xml=0;
48 void get_rc_name(char *buffer)
51 if (globals.alternate_rc)
53 strcpy(buffer, globals.alternate_rc);
59 strcpy(buffer, getenv("HOME"));
60 if (buffer[strlen(buffer)-1]!='/')
63 strcat(buffer, ".terminatorXrc");
67 void set_global_defaults() {
68 globals.startup_set = 0;
69 globals.store_globals = 1;
71 globals.alternate_rc = 0;
73 strcpy(globals.xinput_device, "");
74 globals.xinput_enable=0;
76 globals.update_idle=14;
77 globals.update_delay=1;
79 strcpy(globals.oss_device, "/dev/dsp");
80 globals.oss_buff_no=2;
81 globals.oss_buff_size=9;
82 globals.oss_samplerate=44100;
84 strcpy(globals.alsa_device, "00-00: Default");
85 globals.alsa_buffer_time=80000;
86 globals.alsa_period_time=20000;
87 globals.alsa_samplerate=44100;
89 globals.sense_cycles=80;
91 globals.mouse_speed=0.8;
99 globals.use_stdout_from_conf_file=0;
104 strcpy(globals.last_fn,"");
110 globals.flash_response=0.95;
112 globals.button_type=BUTTON_TYPE_BOTH;
114 globals.true_block_size=0;
116 strcpy(globals.tables_filename, "");
117 strcpy(globals.record_filename, "tX_record.wav");
118 strcpy(globals.file_editor, "");
121 globals.audiodevice_type=OSS;
124 globals.audiodevice_type=ALSA;
127 globals.use_stdout_cmdline=0;
128 globals.current_path = NULL;
132 strcpy(globals.lrdf_path, "/usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf");
133 globals.fullscreen_enabled=0;
134 globals.confirm_events=0;
135 globals.compress_set_files=0;
137 globals.vtt_inertia=10.0;
139 globals.alsa_free_hwstats=1;
140 globals.filename_length=20;
143 int load_globals_xml() {
144 char rc_name[PATH_MAX]="";
145 char device_type[16]="oss";
150 char tmp_xml_buffer[4096];
152 get_rc_name(rc_name);
154 doc = xmlParseFile(rc_name);
157 fprintf(stderr, "tX: err: Error parsing terminatorXrc.\n");
161 cur = xmlDocGetRootElement(doc);
164 fprintf(stderr,"tX: err: terminatorXrc contains no elements.\n");
169 if (xmlStrcmp(cur->name, (const xmlChar *) "terminatorXrc")) {
170 fprintf(stderr,"tX: err: This terminatorXrc is not a terminatorXrc.");
175 for (cur=cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
176 if (cur->type == XML_ELEMENT_NODE) {
179 restore_int("store_globals", globals.store_globals);
181 restore_string("audio_driver", device_type);
183 restore_string("oss_device", globals.oss_device);
184 restore_int("oss_buff_no", globals.oss_buff_no);
185 restore_int("oss_buff_size", globals.oss_buff_size);
186 restore_int("oss_samplerate", globals.oss_samplerate);
188 restore_string("alsa_device", globals.alsa_device);
189 restore_int("alsa_buffer_time", globals.alsa_buffer_time);
190 restore_int("alsa_period_time", globals.alsa_period_time);
191 restore_int("alsa_samplerate", globals.alsa_samplerate);
192 restore_int("alsa_free_hwstats", globals.alsa_free_hwstats);
194 restore_string("xinput_device", globals.xinput_device);
195 restore_int("xinput_enable", globals.xinput_enable);
196 restore_int("update_idle", globals.update_idle);
197 restore_int("update_delay", globals.update_delay);
198 restore_int("sense_cycles", globals.sense_cycles);
199 restore_float("mouse_speed", globals.mouse_speed);
200 restore_int("width", globals.width);
201 restore_int("height", globals.height);
202 restore_int("filename_length", globals.filename_length);
203 restore_int("tooltips", globals.tooltips);
204 restore_int("use_stdout", globals.use_stdout);
205 restore_int("show_nag", globals.show_nag);
206 restore_int("prelis", globals.prelis);
207 restore_string("last_fn", globals.last_fn);
208 restore_float("pitch", globals.pitch);
209 restore_float("volume", globals.volume);
210 restore_float("flash_response", globals.flash_response);
211 restore_int("button_type", globals.button_type);
212 restore_string("tables_filename", globals.tables_filename);
213 restore_string("record_filename", globals.record_filename);
214 restore_string("file_editor", globals.file_editor);
215 restore_string("lrdf_path", globals.lrdf_path);
217 restore_int("compress_set_files", globals.compress_set_files);
218 restore_int("fullscreen_enabled", globals.fullscreen_enabled);
219 restore_int("confirm_events", globals.confirm_events);
220 restore_float("vtt_inertia", globals.vtt_inertia);
223 fprintf(stderr, "tX: Unhandled XML element: \"%s\"\n", cur->name);
230 if (strcmp(device_type, "alsa")==0) globals.audiodevice_type=ALSA;
231 else if (strcmp(device_type, "jack")==0) globals.audiodevice_type=JACK;
232 else globals.audiodevice_type=OSS;
237 void store_globals() {
238 char rc_name[PATH_MAX]="";
239 char device_type[16];
243 char tmp_xml_buffer[4096];
244 _store_compress_xml=0;
246 get_rc_name(rc_name);
248 rc=fopen(rc_name, "w");
250 switch (globals.audiodevice_type) {
252 strcpy(device_type, "jack");
255 strcpy(device_type, "alsa");
259 strcpy(device_type, "oss");
264 fprintf(rc, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n");
265 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" );
266 fprintf(rc, "<terminatorXrc version=\"%s\">\n", TX_XML_RC_VERSION);
268 store_int("store_globals", globals.store_globals);
270 store_string("audio_driver", device_type);
272 store_string("oss_device", globals.oss_device);
273 store_int("oss_buff_no", globals.oss_buff_no);
274 store_int("oss_buff_size", globals.oss_buff_size);
275 store_int("oss_samplerate", globals.oss_samplerate);
277 store_string("alsa_device", globals.alsa_device);
278 store_int("alsa_buffer_time", globals.alsa_buffer_time);
279 store_int("alsa_period_time", globals.alsa_period_time);
280 store_int("alsa_samplerate", globals.alsa_samplerate);
281 store_int("alsa_free_hwstats", globals.alsa_free_hwstats);
283 store_string("xinput_device", globals.xinput_device);
284 store_int("xinput_enable", globals.xinput_enable);
285 store_int("update_idle", globals.update_idle);
286 store_int("update_delay", globals.update_delay);
287 store_int("sense_cycles", globals.sense_cycles);
288 store_float("mouse_speed", globals.mouse_speed);
289 store_int("width", globals.width);
290 store_int("height", globals.height);
291 store_int("filename_length", globals.filename_length);
292 store_int("tooltips", globals.tooltips);
293 store_int("use_stdout", globals.use_stdout);
294 // globals.use_stdout_from_conf_file=0; What the heck is this?
295 store_int("show_nag", globals.show_nag);
296 store_int("prelis", globals.prelis);
297 store_string("last_fn", globals.last_fn);
298 store_float("pitch", globals.pitch);
299 store_float("volume", globals.volume);
300 store_float("flash_response", globals.flash_response);
301 store_int("button_type", globals.button_type);
302 store_string("tables_filename", globals.tables_filename);
303 store_string("record_filename", globals.record_filename);
304 store_string("file_editor", globals.file_editor);
305 store_string("lrdf_path", globals.lrdf_path);
306 store_int("compress_set_files", globals.compress_set_files);
307 store_int("fullscreen_enabled", globals.fullscreen_enabled);
308 store_int("confirm_events", globals.confirm_events);
309 store_float("vtt_inertia", globals.vtt_inertia);
311 fprintf(rc,"</terminatorXrc>\n");
315 #ifdef ENABLE_TX_LEGACY
316 extern void load_globals_old();
319 void load_globals() {
320 set_global_defaults();
322 if (load_globals_xml()!=0) {
323 fprintf(stderr, "tX: Failed loading terminatorXrc - trying to load old binary rc.\n");
324 #ifdef ENABLE_TX_LEGACY
330 char *encode_xml(char *dest, const char *src) {
341 for (i=0; i<max; i++) {
343 case '<': tmp[t]=0; strcat(tmp, "<"); t+=4; break;
344 case '>': tmp[t]=0; strcat(tmp, ">"); t+=4; break;
345 case '&': tmp[t]=0; strcat(tmp, "&"); t+=5; break;
346 case '"': tmp[t]=0; strcat(tmp, """); t+=6; break;
347 case '\'': strcat(tmp, "'"); t+=7; break;
348 default: tmp[t]=src[i]; t++;
354 res=isolat1ToUTF8((unsigned char *) dest, &outlen, (unsigned char *) tmp, &inlen);
357 tX_error("failed to encode string (%s) to UTF-8.", src);
363 char *decode_xml(char *dest, const char *src) {
364 int inlen=strlen(src);
367 int res=UTF8Toisolat1(dest, &outlen, src, &inlen);
371 tX_error("failed to decode UTF-8 string (%s).", src);