2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2016 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, see <http://www.gnu.org/licenses/>.
20 Description: This file contains the routines for handling the
21 "globals" block. Intializing, reading setup from
29 #include "tX_global.h"
31 #include <libxml/xmlmemory.h>
32 #include <libxml/parser.h>
33 #include <libxml/encoding.h>
36 #define TX_XML_RC_VERSION "1.0"
39 int _store_compress_xml=0;
41 #ifdef USE_ALSA_MIDI_IN
42 extern void tX_midiin_store_connections(FILE *rc, char *indent);
43 extern void tX_midiin_restore_connections(xmlNodePtr node);
46 void get_rc_name(char *buffer, int length)
48 strncpy(buffer,"", length);
49 if (globals.alternate_rc) {
50 strncpy(buffer, globals.alternate_rc, length);
53 strncpy(buffer, getenv("HOME"), length-16);
54 if (buffer[strlen(buffer)-1]!='/')
57 strcat(buffer, ".terminatorXrc");
61 void set_global_defaults() {
62 globals.startup_set = 0;
63 globals.store_globals = 1;
65 globals.alternate_rc = 0;
67 strcpy(globals.xinput_device, "");
68 globals.xinput_enable=0;
70 globals.update_idle=14;
71 globals.update_delay=1;
73 strcpy(globals.oss_device, "/dev/dsp");
74 globals.oss_buff_no=2;
75 globals.oss_buff_size=9;
76 globals.oss_samplerate=44100;
78 strcpy(globals.alsa_device_id, "hw:0,0");
79 globals.alsa_buffer_time=80000;
80 globals.alsa_period_time=20000;
81 globals.alsa_samplerate=44100;
83 globals.pulse_buffer_length=320;
85 globals.sense_cycles=80;
87 globals.mouse_speed=0.8;
95 globals.use_stdout_from_conf_file=0;
98 globals.input_fallback_warning=1;
101 strcpy(globals.last_fn,"");
107 globals.flash_response=0.95;
108 globals.knob_size_override=0;
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=ALSA;
122 globals.audiodevice_type=ALSA;
125 globals.audiodevice_type=OSS;
129 globals.use_stdout_cmdline=0;
130 strcpy(globals.current_path, "");
131 strcpy(globals.lrdf_path, "/usr/share/ladspa/rdf:/usr/local/share/ladspa/rdf");
132 globals.fullscreen_enabled=0;
133 globals.confirm_events=0;
134 globals.compress_set_files=0;
136 globals.vtt_inertia=10.0;
138 globals.alsa_free_hwstats=0;
139 globals.filename_length=20;
140 globals.restore_midi_connections=1;
142 globals.wav_display_history=1;
144 strcpy(globals.wav_display_bg_focus, "#00004C");
145 strcpy(globals.wav_display_bg_no_focus, "#000000");
147 strcpy(globals.wav_display_fg_focus, "#FFFF00");
148 strcpy(globals.wav_display_fg_no_focus, "#00FF00");
150 strcpy(globals.wav_display_cursor, "#FF6666");
151 strcpy(globals.wav_display_cursor_mute, "#FFFFFF");
153 strcpy(globals.vu_meter_bg, "#000000");
154 strcpy(globals.vu_meter_loud, "#FF0000");
155 strcpy(globals.vu_meter_normal, "#00FF00");
156 globals.vu_meter_border_intensity=0.7;
157 globals.quit_confirm=1;
158 globals.use_realtime=1;
159 globals.auto_assign_midi=0;
161 globals.verbose_plugin_loading=0;
162 globals.force_nonrt_plugins=0;
165 int load_globals_xml() {
166 char rc_name[PATH_MAX]="";
167 char device_type[16]="oss";
172 char tmp_xml_buffer[4096];
174 get_rc_name(rc_name, sizeof(rc_name));
176 doc = xmlParseFile(rc_name);
179 fprintf(stderr, "tX: err: Error parsing terminatorXrc.\n");
183 cur = xmlDocGetRootElement(doc);
186 fprintf(stderr,"tX: err: terminatorXrc contains no elements.\n");
191 if (xmlStrcmp(cur->name, (const xmlChar *) "terminatorXrc")) {
192 fprintf(stderr,"tX: err: This terminatorXrc is not a terminatorXrc.");
197 for (cur=cur->xmlChildrenNode; cur != NULL; cur = cur->next) {
198 if (cur->type == XML_ELEMENT_NODE) {
201 restore_int("store_globals", globals.store_globals);
203 restore_string("audio_driver", device_type);
205 restore_string("oss_device", globals.oss_device);
206 restore_int("oss_buff_no", globals.oss_buff_no);
207 restore_int("oss_buff_size", globals.oss_buff_size);
208 restore_int("oss_samplerate", globals.oss_samplerate);
210 restore_string("alsa_device_id", globals.alsa_device_id);
211 restore_int("alsa_buffer_time", globals.alsa_buffer_time);
212 restore_int("alsa_period_time", globals.alsa_period_time);
213 restore_int("alsa_samplerate", globals.alsa_samplerate);
214 restore_int("alsa_free_hwstats", globals.alsa_free_hwstats);
216 restore_int("pulse_buffer_length", globals.pulse_buffer_length);
218 restore_string("xinput_device", globals.xinput_device);
219 restore_int("xinput_enable", globals.xinput_enable);
220 restore_int("update_idle", globals.update_idle);
221 restore_int("update_delay", globals.update_delay);
222 restore_int("sense_cycles", globals.sense_cycles);
223 restore_float("mouse_speed", globals.mouse_speed);
224 restore_int("width", globals.width);
225 restore_int("height", globals.height);
226 restore_int("filename_length", globals.filename_length);
227 restore_int("tooltips", globals.tooltips);
228 restore_int("use_stdout", globals.use_stdout);
229 restore_int("show_nag", globals.show_nag);
230 restore_int("input_fallback_warning", globals.input_fallback_warning);
231 restore_int("prelis", globals.prelis);
232 restore_string("last_fn", globals.last_fn);
233 restore_float("pitch", globals.pitch);
234 restore_float("volume", globals.volume);
235 restore_float("flash_response", globals.flash_response);
236 restore_int("knob_size_override", globals.knob_size_override);
237 restore_int("button_type", globals.button_type);
238 restore_string("tables_filename", globals.tables_filename);
239 restore_string("record_filename", globals.record_filename);
240 restore_string("file_editor", globals.file_editor);
241 restore_string("lrdf_path", globals.lrdf_path);
242 restore_string("last_path", globals.current_path);
244 restore_int("compress_set_files", globals.compress_set_files);
245 restore_int("fullscreen_enabled", globals.fullscreen_enabled);
246 restore_int("confirm_events", globals.confirm_events);
247 restore_float("vtt_inertia", globals.vtt_inertia);
248 restore_int("restore_midi_connections", globals.restore_midi_connections);
250 restore_int("wav_display_history", globals.wav_display_history);
251 restore_string("wav_display_bg_focus", globals.wav_display_bg_focus);
252 restore_string("wav_display_bg_no_focus", globals.wav_display_bg_no_focus);
253 restore_string("wav_display_fg_focus", globals.wav_display_fg_focus);
254 restore_string("wav_display_fg_no_focus", globals.wav_display_fg_no_focus);
255 restore_string("wav_display_cursor", globals.wav_display_cursor);
256 restore_string("wav_display_cursor_mute", globals.wav_display_cursor_mute);
258 restore_string("vu_meter_bg", globals.vu_meter_bg);
259 restore_string("vu_meter_normal", globals.vu_meter_normal);
260 restore_string("vu_meter_loud", globals.vu_meter_loud);
262 restore_float("vu_meter_border_intensity", globals.vu_meter_border_intensity);
264 restore_int("quit_confirm", globals.quit_confirm);
265 restore_int("use_realtime", globals.use_realtime);
266 restore_int("auto_assign_midi", globals.auto_assign_midi);
267 restore_int("force_nonrt_plugins", globals.force_nonrt_plugins);
268 restore_int("verbose_plugin_loading", globals.verbose_plugin_loading);
270 #ifdef USE_ALSA_MIDI_IN
271 if (!elementFound && (xmlStrcmp(cur->name, (xmlChar *) "midi_connections")==0)) {
272 if (globals.restore_midi_connections) {
273 tX_midiin_restore_connections(cur);
280 fprintf(stderr, "tX: Unhandled XML element: \"%s\"\n", cur->name);
287 if (strcmp(device_type, "alsa")==0) { globals.audiodevice_type=ALSA; }
288 else if (strcmp(device_type, "jack")==0) { globals.audiodevice_type=JACK; }
289 else if (strcmp(device_type, "pulse")==0) { globals.audiodevice_type=PULSE; }
290 else globals.audiodevice_type=OSS;
295 void store_globals() {
296 char rc_name[PATH_MAX+256]="";
297 char device_type[16];
298 char indent[32]="\t";
301 char tmp_xml_buffer[4096];
302 _store_compress_xml=0;
304 get_rc_name(rc_name, sizeof(rc_name));
306 rc=fopen(rc_name, "w");
308 switch (globals.audiodevice_type) {
310 strcpy(device_type, "pulse");
313 strcpy(device_type, "jack");
316 strcpy(device_type, "alsa");
320 strcpy(device_type, "oss");
324 fprintf(rc, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n\n");
325 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" );
326 fprintf(rc, "<terminatorXrc version=\"%s\">\n", TX_XML_RC_VERSION);
328 store_int("store_globals", globals.store_globals);
330 store_string("audio_driver", device_type);
332 store_string("oss_device", globals.oss_device);
333 store_int("oss_buff_no", globals.oss_buff_no);
334 store_int("oss_buff_size", globals.oss_buff_size);
335 store_int("oss_samplerate", globals.oss_samplerate);
337 store_string("alsa_device_id", globals.alsa_device_id);
338 store_int("alsa_buffer_time", globals.alsa_buffer_time);
339 store_int("alsa_period_time", globals.alsa_period_time);
340 store_int("alsa_samplerate", globals.alsa_samplerate);
341 store_int("alsa_free_hwstats", globals.alsa_free_hwstats);
343 store_int("pulse_buffer_length", globals.pulse_buffer_length);
345 store_string("xinput_device", globals.xinput_device);
346 store_int("xinput_enable", globals.xinput_enable);
347 store_int("update_idle", globals.update_idle);
348 store_int("update_delay", globals.update_delay);
349 store_int("sense_cycles", globals.sense_cycles);
350 store_float("mouse_speed", globals.mouse_speed);
351 store_int("width", globals.width);
352 store_int("height", globals.height);
353 store_int("filename_length", globals.filename_length);
354 store_int("tooltips", globals.tooltips);
355 store_int("use_stdout", globals.use_stdout);
356 // globals.use_stdout_from_conf_file=0; What the heck is this?
357 store_int("show_nag", globals.show_nag);
358 store_int("input_fallback_warning", globals.input_fallback_warning);
359 store_int("prelis", globals.prelis);
360 store_string("last_fn", globals.last_fn);
361 store_float("pitch", globals.pitch);
362 store_float("volume", globals.volume);
363 store_float("flash_response", globals.flash_response);
364 store_int("knob_size_override", globals.knob_size_override);
365 store_int("button_type", globals.button_type);
366 store_string("tables_filename", globals.tables_filename);
367 store_string("record_filename", globals.record_filename);
368 store_string("file_editor", globals.file_editor);
369 store_string("lrdf_path", globals.lrdf_path);
370 store_int("compress_set_files", globals.compress_set_files);
371 store_int("fullscreen_enabled", globals.fullscreen_enabled);
372 store_int("confirm_events", globals.confirm_events);
373 store_float("vtt_inertia", globals.vtt_inertia);
375 store_string("last_path", globals.current_path);
376 store_int("restore_midi_connections", globals.restore_midi_connections);
378 store_int("wav_display_history", globals.wav_display_history);
379 store_string("wav_display_bg_focus", globals.wav_display_bg_focus);
380 store_string("wav_display_bg_no_focus", globals.wav_display_bg_no_focus);
381 store_string("wav_display_fg_focus", globals.wav_display_fg_focus);
382 store_string("wav_display_fg_no_focus", globals.wav_display_fg_no_focus);
383 store_string("wav_display_cursor", globals.wav_display_cursor);
384 store_string("wav_display_cursor_mute", globals.wav_display_cursor_mute);
386 store_string("vu_meter_bg", globals.vu_meter_bg);
387 store_string("vu_meter_normal", globals.vu_meter_normal);
388 store_string("vu_meter_loud", globals.vu_meter_loud);
390 store_float("vu_meter_border_intensity", globals.vu_meter_border_intensity);
392 store_int("quit_confirm", globals.quit_confirm);
393 store_int("use_realtime", globals.use_realtime);
394 store_int("auto_assign_midi", globals.auto_assign_midi);
396 store_int("verbose_plugin_loading", globals.verbose_plugin_loading);
397 store_int("force_nonrt_plugins", globals.force_nonrt_plugins);
399 #ifdef USE_ALSA_MIDI_IN
400 tX_midiin_store_connections(rc, indent);
403 fprintf(rc,"</terminatorXrc>\n");
407 #ifdef ENABLE_TX_LEGACY
408 extern void load_globals_old();
411 void load_globals() {
412 set_global_defaults();
414 if (load_globals_xml()!=0) {
415 fprintf(stderr, "tX: Failed loading terminatorXrc - trying to load old binary rc.\n");
416 #ifdef ENABLE_TX_LEGACY
422 char *encode_xml(char *dest, const char *src) {
433 for (i=0; i<max; i++) {
435 case '<': tmp[t]=0; strcat(tmp, "<"); t+=4; break;
436 case '>': tmp[t]=0; strcat(tmp, ">"); t+=4; break;
437 case '&': tmp[t]=0; strcat(tmp, "&"); t+=5; break;
438 case '"': tmp[t]=0; strcat(tmp, """); t+=6; break;
439 case '\'': strcat(tmp, "'"); t+=7; break;
440 default: tmp[t]=src[i]; t++;
446 res=isolat1ToUTF8((unsigned char *) dest, &outlen, (unsigned char *) tmp, &inlen);
449 tX_error("failed to encode string (%s) to UTF-8.", src);
455 char *decode_xml(char *dest, const char *src) {
456 int inlen=strlen(src);
459 int res=UTF8Toisolat1((unsigned char *) dest, &outlen, (const unsigned char *) src, &inlen);
463 tX_error("failed to decode UTF-8 string (%s).", src);