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 contains the main() function. All the initializing
26 19 Mar 1999: Applied a patch by Andrew C. Bul+hac?k (eMail: acb@zikzak.net)
27 that fixes wavfile reading routine for the overreading bug.
29 20 Mar 1999: Big endian support.
31 23 Mar 1999: display of new keys (<-, ->)
33 4 October 1999: Rewrite ;) - back to C++
36 #define TX_GTKRC "/usr/share/themes/terminatorX/gtk/gtkrc"
38 #define BENCH_CYCLES 100000
41 #include "tX_mastergui.h"
53 #include "tX_endian.h"
55 #include "tX_global.h"
56 #include "tX_audiodevice.h"
58 #include "tX_dialog.h"
62 #include "tX_ladspa.h"
63 #include "tX_ladspa_class.h"
64 #include "tX_engine.h"
65 #include "tX_capabilities.h"
67 #ifdef CREATE_BENCHMARK
76 if ((!tX_jack_client::get_instance()) && (globals.audiodevice_type==JACK)) {
77 tx_note("Couldn't connect to JACK server - JACK output not available.\n\nIf you want to use JACK, ensure the JACK daemon is running before you start terminatorX.", true);
87 time=g_timer_elapsed(my_time, &ms);
90 gtk_idle_remove(idle_tag);
91 g_timer_destroy(my_time);
106 usage: terminatorX [options]n\
108 -h, --help Display help info\n\
109 -f, --file Load saved terminatorX set file\n\
110 -r, --rc-file [file] Load alternate rc file\n\
111 -d, --dont-save Do not save settings at exit\n\
112 -s, --std-out Use stdout for sound output\n\
113 --device=[output device] Use alternate device for sound output\n\
117 int parse_args(int *argc, char **argv)
119 // pass over argv once to see if we need to load an alternate_rc file
120 for (int i = 1 ; i != *argc ; ++i ) {
121 if ((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--rc-file") == 0)) {
124 fprintf(stderr, "tX: Loading alternate rc file %s\n", argv[i]);
125 globals.alternate_rc = argv[i];
134 // load up the global values
137 // default the flag options, or they'll be set from last execution... (think globals.no_gui ;)
139 globals.alternate_rc = 0;
140 globals.store_globals = 1;
141 globals.startup_set = 0;
143 // then pass over again, this time setting passed values
144 for (int i = 1 ; i < *argc ; ++i ) {
145 if ((strcmp(argv[i], "-f") == 0) || (strcmp(argv[i], "--file") == 0)) {
147 globals.startup_set = argv[i];
148 } else if (((strcmp(argv[i], "-r") == 0) || (strcmp(argv[i], "--rc-file") == 0)) && (argv[i+1])) {
150 globals.alternate_rc = argv[i];
151 } else if ((strcmp(argv[i], "-d") == 0) || (strcmp(argv[i], "--dont-save") == 0)) {
152 fprintf(stderr, "tX: Do not save settings on exit\n");
153 globals.store_globals = 0;
155 } else if ((strcmp(argv[i], "-s") == 0) || (strcmp(argv[i], "--std-out") == 0)) {
156 globals.use_stdout_cmdline = 1;
157 globals.use_stdout = 1;
158 } else if ((strncmp(argv[i], "--device",8) == 0)) {
159 if (strlen(argv[i]+9)<=PATH_MAX)
160 strcpy(globals.oss_device,argv[i]+9);
173 void checkenv(const char *name) {
179 length=strnlen(value, PATH_MAX+1);
181 if (length>=PATH_MAX) {
182 tX_error("Your \"%s\" environment variable seems malicious (%i chars).", name, length);
183 tX_error("Please correct that and restart terminatorX.");
189 int main(int argc, char **argv)
191 fprintf(stderr, "%s - Copyright (C) 1999-2003 by Alexander König\n", VERSIONSTRING);
192 fprintf(stderr, "terminatorX comes with ABSOLUTELY NO WARRANTY - for details read the license.\n");
194 #ifdef USE_CAPABILITIES
196 if (prctl(PR_SET_KEEPCAPS, 1, -1, -1, -1)) {
197 tX_error("failed to keep capabilites.");
199 set_nice_capability(CAP_PERMITTED);
202 if ((!geteuid()) && (getuid() != geteuid())) {
203 tX_debug("main() - capabilites set, dropping root privileges.");
205 int result=setuid(getuid());
208 tX_error("main() Panic: can't drop root privileges.");
213 set_nice_capability(CAP_EFFECTIVE);
217 checkenv("XLOCALEDIR");
219 tX_engine *engine=tX_engine::get_instance();
221 gtk_init (&argc, &argv);
224 parse_args(&argc, argv);
226 if (globals.show_nag) {
229 my_time=g_timer_new();
230 g_timer_start(my_time);
232 idle_tag=gtk_idle_add((GtkFunction)idle, NULL);
235 LADSPA_Class::init();
236 LADSPA_Plugin::init();
238 tX_jack_client::init();
241 create_mastergui(globals.width, globals.height);
243 if (!globals.show_nag) {
250 if (globals.startup_set) {
251 while (gtk_events_pending()) gtk_main_iteration(); gdk_flush();
252 tX_cursor::set_cursor(tX_cursor::WAIT_CURSOR);
253 load_tt_part(globals.startup_set);
254 tX_cursor::reset_cursor();
257 #ifndef CREATE_BENCHMARK
264 if (tX_jack_client::get_instance()) {
265 delete tX_jack_client::get_instance();
269 fprintf(stderr, "Have a nice life.\n");
270 #else // CREATE_BENCHMARK
271 gtk_widget_hide(main_window);
272 while (gtk_events_pending()) gtk_main_iteration(); gdk_flush();
275 vtt_class::set_sample_rate(48000);
277 printf("\n* BENCHMARKING *\n");
279 GTimer *bench_time = g_timer_new();
283 list <vtt_class *> :: iterator vtt;
285 for (vtt=vtt_class::main_list.begin(); vtt!=vtt_class::main_list.end(); vtt++)
287 if ((*vtt)->autotrigger) (*vtt)->trigger();
291 g_timer_start(bench_time);
292 for (int i=0; i<BENCH_CYCLES; i++)
294 vtt_class::render_all_turntables();
296 g_timer_stop(bench_time);
297 res=g_timer_elapsed(bench_time, µs);
299 ratio=((double) BENCH_CYCLES)/res;
300 printf ("Rendered %i blocks in %f secons,\n=> %f blocks per second.\n\n", (long) BENCH_CYCLES, res, ratio);
301 #endif // CREATE_BENCHMARK