Adrian's patches and experimental Stereo stuff - Alex
[terminatorX.git] / src / tX_global.c
1 /*
2     terminatorX - realtime audio scratching software
3     Copyright (C) 1999, 2000  Alexander K├Ânig
4  
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.
9  
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.
14  
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.
18  
19     File: tX_global.c
20  
21     Description:  This file contains the routines for handling the
22                   "globals" block. Intializing, reading setup from
23                   disk and storing it.
24                   
25     Changes:
26     
27     21 Jul 1999: introduced the lowpass globals.                          
28 */    
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include "tX_types.h"
33 #include "tX_global.h"
34 #include "string.h"
35
36 tx_global globals;
37
38 void get_rc_name(char *buffer)
39 {
40         strcpy(buffer,"");
41         if (globals.alternate_rc)
42         {
43                 strcpy(buffer, globals.alternate_rc);
44         }
45         else 
46         {
47                 if (getenv("HOME"))
48                 {
49                         strcpy(buffer, getenv("HOME"));
50                         if (buffer[strlen(buffer)-1]!='/')
51                         strcat(buffer, "/");
52                 }
53                 strcat(buffer, ".terminatorX3rc.bin");
54         }
55 }
56
57 void load_globals()
58 {
59         char rc_name[PATH_MAX]="";
60         FILE *rc;
61
62         get_rc_name(rc_name);
63         
64         rc=fopen(rc_name, "r");
65         if (rc)
66         {
67                 fread(&globals, sizeof(tx_global), 1, rc);
68                 fclose(rc);
69         }
70         else
71         {
72                 fprintf(stderr, "tX: Alternate rc file doesn't exist, reverting to defaults");
73
74                 globals.startup_set = 0;
75                 globals.store_globals = 1;
76                 globals.no_gui = 0;
77                 globals.alternate_rc = 0;
78         
79                 strcpy(globals.audio_device, "/dev/dsp");
80         
81                 strcpy(globals.xinput_device, "");
82                 globals.xinput_enable=0;
83         
84                 globals.update_idle=18;
85                 globals.update_delay=1;
86         
87                 globals.buff_no=2;
88                 globals.buff_size=8;
89                 
90                 globals.sense_cycles=12;
91         
92                 globals.mouse_speed=0.8;
93         
94                 globals.width=800;
95                 globals.height=440;     
96         
97                 globals.tooltips=1;
98         
99                 globals.use_stdout=0;
100                 globals.use_stdout_from_conf_file=0;
101         
102                 globals.show_nag=1;
103                 globals.prelis=1;
104         
105                 strcpy(globals.last_fn,"");
106         
107                 globals.pitch=1.0;
108                 globals.volume=1.0;
109                 globals.gui_wrap=3;
110         
111                 globals.flash_response=0.95;
112         
113                 globals.button_type=BUTTON_TYPE_BOTH;
114                 
115                 globals.true_block_size=0;
116         
117                 strcpy(globals.tables_filename, "");
118                 strcpy(globals.record_filename, "tX_record.wav");
119                 strcpy(globals.file_editor, "");
120         }
121
122         /* i'll have to keep these as they're in the code
123           everywhere but I think it doesn't make sense resetting
124           to old values on startup....
125         */
126         globals.use_stdout_cmdline=0;
127         globals.current_path = NULL;
128         globals.pitch=1.0;
129         globals.volume=1.0;     
130         if (!globals.true_block_size) globals.true_block_size=1<globals.buff_size;
131 }
132
133 void store_globals()
134 {
135         char rc_name[PATH_MAX]="";
136         FILE *rc;
137         
138         if (globals.store_globals)
139         {
140
141                 get_rc_name(rc_name);
142
143                 rc=fopen(rc_name, "w");
144                 if (rc)
145                 {
146                         // doesn't really make sense to save pointers...
147                         globals.startup_set = NULL;
148                         globals.alternate_rc = NULL;
149                         globals.current_path = NULL; 
150                         
151                         if (globals.use_stdout_cmdline)
152                                 globals.use_stdout = globals.use_stdout_from_conf_file;
153                         fwrite(&globals, sizeof(tx_global), 1, rc);
154                         fclose(rc);
155                 }
156         }       
157 }