2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2004 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 #ifdef USE_ALSA_MIDI_IN
49 extern void tX_midiin_store_connections(FILE *rc, char *indent);
50 extern void tX_midiin_restore_connections(xmlNodePtr node);
53 void get_rc_name(char *buffer)
56 if (globals.alternate_rc) {
57 strcpy(buffer, globals.alternate_rc);
60 strcpy(buffer, getenv("HOME"));
61 if (buffer[strlen(buffer)-1]!='/')
64 strcat(buffer, ".terminatorXrc");
68 void set_global_defaults() {
69 globals.startup_set = 0;
70 globals.store_globals = 1;
72 globals.alternate_rc = 0;
74 strcpy(globals.xinput_device, "");
75 globals.xinput_enable=0;
77 globals.update_idle=14;
78 globals.update_delay=1;
80 strcpy(globals.oss_device, "/dev/dsp");
81 globals.oss_buff_no=2;
82 globals.oss_buff_size=9;
83 globals.oss_samplerate=44100;
85 strcpy(globals.alsa_device_id, "hw:0,0");
86 globals.alsa_buffer_time=80000;
87 globals.alsa_period_time=20000;
88 globals.alsa_samplerate=44100;
90 globals.sense_cycles=80;
92 globals.mouse_speed=0.8;
100 globals.use_stdout_from_conf_file=0;
105 strcpy(globals.last_fn,"");
111 globals.flash_response=0.95;
113 globals.button_type=BUTTON_TYPE_BOTH;
115 globals.true_block_size=0;
117 strcpy(globals.tables_filename, "");
118 strcpy(globals.record_filename, "tX_record.wav");
119 strcpy(globals.file_editor, "");
122 globals.audiodevice_type=OSS;
125 globals.audiodevice_type=ALSA;
128 globals.use_stdout_cmdline=0;
129 strcpy(globals.current_path, "");
130 strcpy(globals.lrdf_path, "/usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf");
131 globals.fullscreen_enabled=0;
132 globals.confirm_events=0;
133 globals.compress_set_files=0;
135 globals.vtt_inertia=10.0;
137 globals.alsa_free_hwstats=0;
138 globals.filename_length=20;
139 globals.restore_midi_connections=1;
141 strcpy(globals.wav_display_bg_focus, "#00004C");
142 strcpy(globals.wav_display_bg_no_focus, "#000000");
144 strcpy(globals.wav_display_fg_focus, "#FFFF00");
145 strcpy(globals.wav_display_fg_no_focus, "#00FF00");
147 strcpy(globals.wav_display_cursor, "#FF6666");
148 strcpy(globals.wav_display_cursor_mute, "#FFFFFF");
150 strcpy(globals.vu_meter_bg, "#000000");
151 strcpy(globals.vu_meter_loud, "#FF0000");
152 strcpy(globals.vu_meter_normal, "#00FF00");
153 globals.vu_meter_border_intensity=0.7;
154 globals.quit_confirm=1;
155 globals.use_realtime=1;
156 globals.auto_assign_midi=0;
159 int load_globals_xml() {
160 char rc_name[PATH_MAX]="";
161 char device_type[16]="oss";
166 char tmp_xml_buffer[4096];
168 get_rc_name(rc_name);
170 doc = xmlParseFile(rc_name);
173 fprintf(stderr, "tX: err: Error parsing terminatorXrc.\n");
177 cur = xmlDocGetRootElement(doc);
180 fprintf(stderr,"tX: err: terminatorXrc contains no elements.\n");
185 if (xmlStrcmp(cur->name, (const xmlChar *) "terminatorXrc")) {
186 fprintf(stderr,"tX: err: This terminatorXrc is not a terminatorXrc.");
191 for (cur=cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
192 if (cur->type == XML_ELEMENT_NODE) {
195 restore_int("store_globals", globals.store_globals);
197 restore_string("audio_driver", device_type);
199 restore_string("oss_device", globals.oss_device);
200 restore_int("oss_buff_no", globals.oss_buff_no);
201 restore_int("oss_buff_size", globals.oss_buff_size);
202 restore_int("oss_samplerate", globals.oss_samplerate);
204 restore_string("alsa_device_id", globals.alsa_device_id);
205 restore_int("alsa_buffer_time", globals.alsa_buffer_time);
206 restore_int("alsa_period_time", globals.alsa_period_time);
207 restore_int("alsa_samplerate", globals.alsa_samplerate);
208 restore_int("alsa_free_hwstats", globals.alsa_free_hwstats);
210 restore_string("xinput_device", globals.xinput_device);
211 restore_int("xinput_enable", globals.xinput_enable);
212 restore_int("update_idle", globals.update_idle);
213 restore_int("update_delay", globals.update_delay);
214 restore_int("sense_cycles", globals.sense_cycles);
215 restore_float("mouse_speed", globals.mouse_speed);
216 restore_int("width", globals.width);
217 restore_int("height", globals.height);
218 restore_int("filename_length", globals.filename_length);
219 restore_int("tooltips", globals.tooltips);
220 restore_int("use_stdout", globals.use_stdout);
221 restore_int("show_nag", globals.show_nag);
222 restore_int("prelis", globals.prelis);
223 restore_string("last_fn", globals.last_fn);
224 restore_float("pitch", globals.pitch);
225 restore_float("volume", globals.volume);
226 restore_float("flash_response", globals.flash_response);
227 restore_int("button_type", globals.button_type);
228 restore_string("tables_filename", globals.tables_filename);
229 restore_string("record_filename", globals.record_filename);
230 restore_string("file_editor", globals.file_editor);
231 restore_string("lrdf_path", globals.lrdf_path);
232 restore_string("last_path", globals.current_path);
234 restore_int("compress_set_files", globals.compress_set_files);
235 restore_int("fullscreen_enabled", globals.fullscreen_enabled);
236 restore_int("confirm_events", globals.confirm_events);
237 restore_float("vtt_inertia", globals.vtt_inertia);
238 restore_int("restore_midi_connections", globals.restore_midi_connections);
240 restore_string("wav_display_bg_focus", globals.wav_display_bg_focus);
241 restore_string("wav_display_bg_no_focus", globals.wav_display_bg_no_focus);
242 restore_string("wav_display_fg_focus", globals.wav_display_fg_focus);
243 restore_string("wav_display_fg_no_focus", globals.wav_display_fg_no_focus);
244 restore_string("wav_display_cursor", globals.wav_display_cursor);
245 restore_string("wav_display_cursor_mute", globals.wav_display_cursor_mute);
247 restore_string("vu_meter_bg", globals.vu_meter_bg);
248 restore_string("vu_meter_normal", globals.vu_meter_normal);
249 restore_string("vu_meter_loud", globals.vu_meter_loud);
251 restore_float("vu_meter_border_intensity", globals.vu_meter_border_intensity);
253 restore_int("quit_confirm", globals.quit_confirm);
254 restore_int("use_realtime", globals.use_realtime);
255 restore_int("auto_assign_midi", globals.auto_assign_midi);
257 #ifdef USE_ALSA_MIDI_IN
258 if (!elementFound && (xmlStrcmp(cur->name, (xmlChar *) "midi_connections")==0)) {
259 if (globals.restore_midi_connections) {
260 tX_midiin_restore_connections(cur);
267 fprintf(stderr, "tX: Unhandled XML element: \"%s\"\n", cur->name);
274 if (strcmp(device_type, "alsa")==0) globals.audiodevice_type=ALSA;
275 else if (strcmp(device_type, "jack")==0) globals.audiodevice_type=JACK;
276 else globals.audiodevice_type=OSS;
281 void store_globals() {
282 char rc_name[PATH_MAX+256]="";
283 char device_type[16];
284 char indent[32]="\t";
287 char tmp_xml_buffer[4096];
288 _store_compress_xml=0;
290 get_rc_name(rc_name);
292 rc=fopen(rc_name, "w");
294 switch (globals.audiodevice_type) {
296 strcpy(device_type, "jack");
299 strcpy(device_type, "alsa");
303 strcpy(device_type, "oss");
307 fprintf(rc, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n");
308 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" );
309 fprintf(rc, "<terminatorXrc version=\"%s\">\n", TX_XML_RC_VERSION);
311 store_int("store_globals", globals.store_globals);
313 store_string("audio_driver", device_type);
315 store_string("oss_device", globals.oss_device);
316 store_int("oss_buff_no", globals.oss_buff_no);
317 store_int("oss_buff_size", globals.oss_buff_size);
318 store_int("oss_samplerate", globals.oss_samplerate);
320 store_string("alsa_device_id", globals.alsa_device_id);
321 store_int("alsa_buffer_time", globals.alsa_buffer_time);
322 store_int("alsa_period_time", globals.alsa_period_time);
323 store_int("alsa_samplerate", globals.alsa_samplerate);
324 store_int("alsa_free_hwstats", globals.alsa_free_hwstats);
326 store_string("xinput_device", globals.xinput_device);
327 store_int("xinput_enable", globals.xinput_enable);
328 store_int("update_idle", globals.update_idle);
329 store_int("update_delay", globals.update_delay);
330 store_int("sense_cycles", globals.sense_cycles);
331 store_float("mouse_speed", globals.mouse_speed);
332 store_int("width", globals.width);
333 store_int("height", globals.height);
334 store_int("filename_length", globals.filename_length);
335 store_int("tooltips", globals.tooltips);
336 store_int("use_stdout", globals.use_stdout);
337 // globals.use_stdout_from_conf_file=0; What the heck is this?
338 store_int("show_nag", globals.show_nag);
339 store_int("prelis", globals.prelis);
340 store_string("last_fn", globals.last_fn);
341 store_float("pitch", globals.pitch);
342 store_float("volume", globals.volume);
343 store_float("flash_response", globals.flash_response);
344 store_int("button_type", globals.button_type);
345 store_string("tables_filename", globals.tables_filename);
346 store_string("record_filename", globals.record_filename);
347 store_string("file_editor", globals.file_editor);
348 store_string("lrdf_path", globals.lrdf_path);
349 store_int("compress_set_files", globals.compress_set_files);
350 store_int("fullscreen_enabled", globals.fullscreen_enabled);
351 store_int("confirm_events", globals.confirm_events);
352 store_float("vtt_inertia", globals.vtt_inertia);
354 store_string("last_path", globals.current_path);
355 store_int("restore_midi_connections", globals.restore_midi_connections);
357 store_string("wav_display_bg_focus", globals.wav_display_bg_focus);
358 store_string("wav_display_bg_no_focus", globals.wav_display_bg_no_focus);
359 store_string("wav_display_fg_focus", globals.wav_display_fg_focus);
360 store_string("wav_display_fg_no_focus", globals.wav_display_fg_no_focus);
361 store_string("wav_display_cursor", globals.wav_display_cursor);
362 store_string("wav_display_cursor_mute", globals.wav_display_cursor_mute);
364 store_string("vu_meter_bg", globals.vu_meter_bg);
365 store_string("vu_meter_normal", globals.vu_meter_normal);
366 store_string("vu_meter_loud", globals.vu_meter_loud);
368 store_float("vu_meter_border_intensity", globals.vu_meter_border_intensity);
370 store_int("quit_confirm", globals.quit_confirm);
371 store_int("use_realtime", globals.use_realtime);
372 store_int("auto_assign_midi", globals.auto_assign_midi);
374 #ifdef USE_ALSA_MIDI_IN
375 tX_midiin_store_connections(rc, indent);
378 fprintf(rc,"</terminatorXrc>\n");
382 #ifdef ENABLE_TX_LEGACY
383 extern void load_globals_old();
386 void load_globals() {
387 set_global_defaults();
389 if (load_globals_xml()!=0) {
390 fprintf(stderr, "tX: Failed loading terminatorXrc - trying to load old binary rc.\n");
391 #ifdef ENABLE_TX_LEGACY
397 char *encode_xml(char *dest, const char *src) {
408 for (i=0; i<max; i++) {
410 case '<': tmp[t]=0; strcat(tmp, "<"); t+=4; break;
411 case '>': tmp[t]=0; strcat(tmp, ">"); t+=4; break;
412 case '&': tmp[t]=0; strcat(tmp, "&"); t+=5; break;
413 case '"': tmp[t]=0; strcat(tmp, """); t+=6; break;
414 case '\'': strcat(tmp, "'"); t+=7; break;
415 default: tmp[t]=src[i]; t++;
421 res=isolat1ToUTF8((unsigned char *) dest, &outlen, (unsigned char *) tmp, &inlen);
424 tX_error("failed to encode string (%s) to UTF-8.", src);
430 char *decode_xml(char *dest, const char *src) {
431 int inlen=strlen(src);
434 int res=UTF8Toisolat1(dest, &outlen, src, &inlen);
438 tX_error("failed to decode UTF-8 string (%s).", src);