Branch annhell-branch-paged MERGED.
[ahxm.git] / main.c
blob818863c072524bca4cdfc4b9e3a8dd62f0c17662
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>
31 #include <limits.h>
33 #include "annhell.h"
35 /*******************
36 Data
37 ********************/
39 /* output information */
41 static char * devfile = NULL;
42 static char * driver = "default";
44 /* seconds to skip */
45 static int skip_secs = 0;
47 /*******************
48 Code
49 ********************/
51 static void read_config(void)
56 static int main_usage(void)
58 printf("Ann Hell Ex Machina %s - Music Writing Software\n", VERSION);
59 printf("Copyright (C) 2003-2005 Angel Ortega <angel@triptico.com>\n");
60 printf("This software is covered by the GPL license. NO WARRANTY.\n\n");
61 printf("Usage: annhell [options] {script.ahs}\n\n");
62 printf("Options:\n\n");
63 printf("-o {output file or device} Set output file [default: driver dependent].\n");
64 printf("-d {driver} Output driver [default: 'default'].\n");
65 printf("-L {path} Add path to script / data library search path.\n");
66 printf("-r {sampling rate} Set sampling rate [default: 44100]\n");
67 printf("-c {# of channels} Set number of channels [default: 2]\n");
68 printf("-v {master volume} Set master volume [default: 0.5]\n");
69 printf("-s {seconds to skip} Seconds to skip from the start of the song.\n");
70 printf(" [default: 0, start from the beginning]\n");
71 printf("-z {track number} Play track number in a solo\n");
72 printf("-i {interpolation} Set interpolation algorithm\n");
73 printf(" (0, none; 1, linear; 2, cubic spline,\n");
74 printf("-b {size in frames} Set maximum wave buffer size in frames, so\n");
75 printf(" wave files bigger than this will be paged\n");
76 printf(" (-1, load full wave in memory) [default: 441000]\n");
77 printf(" 3, Lagrange) [default: 3]\n");
78 printf("-P Show progress.\n");
79 printf("-D Show debugging information.\n");
80 printf("-T Show tracing information.\n");
81 printf("-M Output song to MIDI device instead of softsynth.\n");
82 printf("-I Interactive; read from MIDI device and\n");
83 printf(" use {script} as instrument (UNIMPLEMENTED).\n");
84 printf("\n");
85 printf("Internal sample size: %d bits (floating point)\n", sizeof(sample_t) * 8);
87 return(1);
91 static int main_interactive(char * script_or_ins)
93 printf("UNIMPLEMENTED; use the 'midiin' program instead.\n");
94 return(0);
98 static int main_midi(char * script)
100 if(compile_ahs(script))
101 return(3);
103 if(midi_device_open(devfile) < 0)
105 printf("Error: can't open MIDI device\n");
106 return(2);
109 midi_song_play(skip_secs);
111 midi_device_close();
113 return(0);
117 static int main_ss(char * script)
119 if(ss_output_open(driver, devfile) < 0)
121 printf("Error: can't init driver\n");
122 return(2);
125 if(compile_ahs(script))
126 return(3);
128 ss_song_render(skip_secs);
130 ss_output_close();
132 printf("clipped: %d optimal volume: %f\n",
133 ss_output_clipped, ss_optimal_volume);
135 return(0);
139 static int annhell_main(int argc, char * argv[])
141 int ret = 1;
142 int n = 1;
143 char * opt = NULL;
144 char * script = NULL;
145 int midi = 0;
146 int interactive = 0;
148 if(argc == 1)
149 return(main_usage());
151 read_config();
153 /* default path */
154 add_to_library_path("~/annhell", 0);
156 while(n < argc - 1)
158 opt = argv[n++];
160 if(strcmp(opt, "-o") == 0)
162 /* set output device or file */
163 devfile = argv[n++];
165 else
166 if(strcmp(opt, "-d") == 0)
168 /* set driver */
169 driver = argv[n++];
171 else
172 if(strcmp(opt, "-L") == 0)
174 /* add path to library */
175 add_to_library_path(argv[n++], 0);
177 else
178 if(strcmp(opt, "-r") == 0)
180 /* set sampling rate */
181 ss_frequency = atoi(argv[n++]);
183 else
184 if(strcmp(opt, "-c") == 0)
186 /* set number of channels */
187 ss_nchannels = atoi(argv[n++]);
189 else
190 if(strcmp(opt, "-v") == 0)
192 /* set master volume */
193 ss_master_volume = (double) atof(argv[n++]);
195 else
196 if(strcmp(opt, "-i") == 0)
198 /* set interpolation type */
199 ss_interpolation = atoi(argv[n++]);
201 else
202 if(strcmp(opt, "-s") == 0)
204 /* seconds to skip */
205 skip_secs = atoi(argv[n++]);
207 else
208 if(strcmp(opt, "-I") == 0)
210 /* activate interactive mode */
211 interactive = 1;
213 else
214 if(strcmp(opt, "-M") == 0)
216 /* activate MIDI mode */
217 midi = 1;
219 else
220 if(strcmp(opt, "-z") == 0)
222 /* set solo track */
223 solo_track = atoi(argv[n++]);
225 else
226 if(strcmp(opt, "-b") == 0)
228 /* set page size */
229 ss_page_size = atoi(argv[n++]);
231 /* if it's -1, set as 'no limit' */
232 if(ss_page_size < 0)
233 ss_page_size = INT_MAX;
235 else
236 if(strcmp(opt, "-D") == 0)
237 debug = 1;
238 else
239 if(strcmp(opt, "-T") == 0)
240 trace = 1;
241 else
242 if(strcmp(opt, "-P") == 0)
243 show_progress = 1;
244 else
245 return(main_usage());
249 script = argv[argc - 1];
251 if(*script == '-')
252 return(main_usage());
254 if(interactive)
255 ret = main_interactive(script);
256 else
257 if(midi)
258 ret = main_midi(script);
259 else
260 ret = main_ss(script);
262 return(ret);
266 int main(int argc, char * argv[])
268 return(annhell_main(argc, argv));