even more ALSA - should compile - 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: .rc-file '%s' doesn't exist, reverting to defaults\n", rc_name);
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=9;
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 #ifdef USE_OSS
122                 globals.audiodevice_type=TX_AUDIODEVICE_TYPE_OSS;               
123 #else
124 #ifdef USE_ALSA
125                 globals.audiodevice_type=TX_AUDIODEVICE_TYPE_ALSA;
126 #endif  
127 #endif          
128                 globals.audiodevice_buffersize=4096;
129                 strcpy(globals.audiodevice_oss_devicename, "/dev/dsp");
130                 globals.audiodevice_alsa_card=0;
131                 globals.audiodevice_alsa_pcm=0;         
132         }
133
134         /* i'll have to keep these as they're in the code
135           everywhere but I think it doesn't make sense resetting
136           to old values on startup....
137         */
138         globals.use_stdout_cmdline=0;
139         globals.current_path = NULL;
140         globals.pitch=1.0;
141         globals.volume=1.0;     
142         if (!globals.true_block_size) globals.true_block_size=1<globals.buff_size;
143 }
144
145 void store_globals()
146 {
147         char rc_name[PATH_MAX]="";
148         FILE *rc;
149         
150         if (globals.store_globals)
151         {
152
153                 get_rc_name(rc_name);
154
155                 rc=fopen(rc_name, "w");
156                 if (rc)
157                 {
158                         // doesn't really make sense to save pointers...
159                         globals.startup_set = NULL;
160                         globals.alternate_rc = NULL;
161                         globals.current_path = NULL; 
162                         
163                         if (globals.use_stdout_cmdline)
164                                 globals.use_stdout = globals.use_stdout_from_conf_file;
165                         fwrite(&globals, sizeof(tx_global), 1, rc);
166                         fclose(rc);
167                 }
168         }       
169 }