Last group part is also taken into account when calculating total
[ahxm.git] / main.c
blob8c7c3b8c67ba940a0f8c5ef067536c252c919dea
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 static char * devfile=NULL;
39 static char * driver="default";
41 /*******************
42 Code
43 ********************/
45 static void read_config(void)
50 static int main_usage(void)
52 printf("Ann Hell Ex Machina %s - Music Writing Software\n", VERSION);
53 printf("Copyright (C) 2003-2005 Angel Ortega <angel@triptico.com>\n");
54 printf("This software is covered by the GPL license. NO WARRANTY.\n\n");
55 printf("Usage: annhell [options] {script.ahs}\n\n");
56 printf("Options:\n\n");
57 printf("-o {output file or device} Set output file [default: driver dependent].\n");
58 printf("-d {driver} Output driver [default: 'default'].\n");
59 printf("-L {path} Add path to script / data library search path.\n");
60 printf("-r {sampling rate} Set sampling rate [default: 44100]\n");
61 printf("-c {# of channels} Set number of channels [default: 2]\n");
62 printf("-v {master volume} Set master volume [default: 0.5]\n");
63 printf("-i {interpolation} Set interpolation algorithm\n");
64 printf(" (0, none; 1, linear; 2, cubic spline,\n");
65 printf(" 3, Lagrange) [default: 3]\n");
66 printf("-M Output song to MIDI device instead of softsynth.\n");
67 printf("-I Interactive; read from MIDI device and\n");
68 printf(" use {script} as instrument.\n");
70 return(1);
74 static int main_interactive(char * script_or_ins)
76 return(0);
80 static int main_midi(char * script)
82 if(compile_file(script))
83 return(3);
85 midi_song_play();
87 return(0);
91 static int main_ss(char * script)
93 if(ss_output_open(driver, devfile) < 0)
95 printf("Error: can't init driver\n");
96 return(2);
99 if(compile_file(script))
100 return(3);
102 ss_song_render();
104 ss_output_close();
106 printf("clipped: %d optimal volume: %f\n",
107 ss_output_clipped, ss_optimal_volume);
109 return(0);
113 static int annhell_main(int argc, char * argv[])
115 int ret=1;
116 int n=1;
117 char * opt=NULL;
118 char * script=NULL;
119 int midi=0;
120 int interactive=0;
122 if(argc == 1)
123 return(main_usage());
125 read_config();
127 while(n < argc - 1)
129 opt=argv[n++];
131 if(strcmp(opt, "-o") == 0)
133 /* set output device of file */
134 devfile=argv[n++];
136 else
137 if(strcmp(opt, "-d") == 0)
139 /* set driver */
140 driver=argv[n++];
142 else
143 if(strcmp(opt, "-L") == 0)
145 /* add path to library */
146 add_to_library_path(argv[n++], 0);
148 else
149 if(strcmp(opt, "-r") == 0)
151 /* set sampling rate */
152 ss_frequency=atoi(argv[n++]);
154 else
155 if(strcmp(opt, "-c") == 0)
157 /* set number of channels */
158 ss_nchannels=atoi(argv[n++]);
160 else
161 if(strcmp(opt, "-v") == 0)
163 /* set master volume */
164 ss_master_volume=(double) atof(argv[n++]);
166 else
167 if(strcmp(opt, "-i") == 0)
169 /* set interpolation type */
170 ss_interpolation=atoi(argv[n++]);
172 else
173 if(strcmp(opt, "-I") == 0)
175 /* activate interactive mode */
176 interactive=1;
178 else
179 if(strcmp(opt, "-M") == 0)
181 /* activate MIDI mode */
182 midi=1;
184 else
185 return(main_usage());
188 script=argv[argc - 1];
190 if(*script == '-')
191 return(main_usage());
193 /* default path */
194 add_to_library_path("~/annhell", 0);
196 if(interactive)
197 ret=main_interactive(script);
198 else
199 if(midi)
200 ret=main_midi(script);
201 else
202 ret=main_ss(script);
204 return(ret);
208 int main(int argc, char * argv[])
210 return(annhell_main(argc, argv));