New command line switch, -T, for tracing event (and other) information.
[ahxm.git] / main.c
blobf162eac99ab670683bbf4eb273968f3b515e81fa
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 Angel Ortega <angel@triptico.com>
6 main.c - Miscellaneous functions and startup
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
26 #include "config.h"
28 #include <stdio.h>
29 #include <string.h>
30 #include <stdlib.h>
32 #include "annhell.h"
34 /*******************
35 Data
36 ********************/
38 /* output information */
40 static char * devfile=NULL;
41 static char * driver="default";
43 /* seconds to skip */
44 static int skip_secs=0;
46 /*******************
47 Code
48 ********************/
50 static void read_config(void)
55 static int main_usage(void)
57 printf("Ann Hell Ex Machina %s - Music Writing Software\n", VERSION);
58 printf("Copyright (C) 2003-2005 Angel Ortega <angel@triptico.com>\n");
59 printf("This software is covered by the GPL license. NO WARRANTY.\n\n");
60 printf("Usage: annhell [options] {script.ahs}\n\n");
61 printf("Options:\n\n");
62 printf("-o {output file or device} Set output file [default: driver dependent].\n");
63 printf("-d {driver} Output driver [default: 'default'].\n");
64 printf("-L {path} Add path to script / data library search path.\n");
65 printf("-r {sampling rate} Set sampling rate [default: 44100]\n");
66 printf("-c {# of channels} Set number of channels [default: 2]\n");
67 printf("-v {master volume} Set master volume [default: 0.5]\n");
68 printf("-s {seconds to skip} Seconds to skip from the start of the song.\n");
69 printf(" [default: 0, start from the beginning]\n");
70 printf("-z {track number} Play track number in a solo\n");
71 printf("-i {interpolation} Set interpolation algorithm\n");
72 printf(" (0, none; 1, linear; 2, cubic spline,\n");
73 printf(" 3, Lagrange) [default: 3]\n");
74 printf("-D Show debugging information.\n");
75 printf("-T Show tracing information.\n");
76 printf("-M Output song to MIDI device instead of softsynth.\n");
77 printf("-I Interactive; read from MIDI device and\n");
78 printf(" use {script} as instrument (UNIMPLEMENTED).\n");
79 printf("\n");
80 printf("Internal sample size: %d bits (floating point)\n", sizeof(sample_t) * 8);
82 return(1);
86 static int main_interactive(char * script_or_ins)
88 printf("UNIMPLEMENTED; use the 'midiin' program instead.\n");
89 return(0);
93 static int main_midi(char * script)
95 if(compile_ahs(script))
96 return(3);
98 if(midi_device_open(devfile) < 0)
100 printf("Error: can't open MIDI device\n");
101 return(2);
104 midi_song_play(skip_secs);
106 midi_device_close();
108 return(0);
112 static int main_ss(char * script)
114 if(ss_output_open(driver, devfile) < 0)
116 printf("Error: can't init driver\n");
117 return(2);
120 if(compile_ahs(script))
121 return(3);
123 ss_song_render(skip_secs);
125 ss_output_close();
127 printf("clipped: %d optimal volume: %f\n",
128 ss_output_clipped, ss_optimal_volume);
130 return(0);
134 static int annhell_main(int argc, char * argv[])
136 int ret=1;
137 int n=1;
138 char * opt=NULL;
139 char * script=NULL;
140 int midi=0;
141 int interactive=0;
143 if(argc == 1)
144 return(main_usage());
146 read_config();
148 /* default path */
149 add_to_library_path("~/annhell", 0);
151 while(n < argc - 1)
153 opt=argv[n++];
155 if(strcmp(opt, "-o") == 0)
157 /* set output device or file */
158 devfile=argv[n++];
160 else
161 if(strcmp(opt, "-d") == 0)
163 /* set driver */
164 driver=argv[n++];
166 else
167 if(strcmp(opt, "-L") == 0)
169 /* add path to library */
170 add_to_library_path(argv[n++], 0);
172 else
173 if(strcmp(opt, "-r") == 0)
175 /* set sampling rate */
176 ss_frequency=atoi(argv[n++]);
178 else
179 if(strcmp(opt, "-c") == 0)
181 /* set number of channels */
182 ss_nchannels=atoi(argv[n++]);
184 else
185 if(strcmp(opt, "-v") == 0)
187 /* set master volume */
188 ss_master_volume=(double) atof(argv[n++]);
190 else
191 if(strcmp(opt, "-i") == 0)
193 /* set interpolation type */
194 ss_interpolation=atoi(argv[n++]);
196 else
197 if(strcmp(opt, "-s") == 0)
199 /* seconds to skip */
200 skip_secs=atoi(argv[n++]);
202 else
203 if(strcmp(opt, "-I") == 0)
205 /* activate interactive mode */
206 interactive=1;
208 else
209 if(strcmp(opt, "-M") == 0)
211 /* activate MIDI mode */
212 midi=1;
214 else
215 if(strcmp(opt, "-z") == 0)
217 /* set solo track */
218 solo_track = atoi(argv[n++]);
220 else
221 if(strcmp(opt, "-D") == 0)
222 debug = 1;
223 else
224 if(strcmp(opt, "-T") == 0)
225 trace = 1;
226 else
227 return(main_usage());
231 script=argv[argc - 1];
233 if(*script == '-')
234 return(main_usage());
236 if(interactive)
237 ret=main_interactive(script);
238 else
239 if(midi)
240 ret=main_midi(script);
241 else
242 ret=main_ss(script);
244 return(ret);
248 int main(int argc, char * argv[])
250 return(annhell_main(argc, argv));