3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2008 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
38 /* output information */
40 static char *devfile
= NULL
;
41 static char *driver
= "default";
44 static int skip_secs
= 0;
49 static void read_config(void)
54 static int main_usage(void)
56 printf("Ann Hell Ex Machina %s - Music Writing Software\n", VERSION
);
57 printf("Copyright (C) 2003-2008 Angel Ortega <angel@triptico.com>\n");
58 printf("This software is covered by the GPL license. NO WARRANTY.\n\n");
59 printf("Usage: ahxm [options] {script.ahs}\n\n");
60 printf("Options:\n\n");
61 printf("-o {output file or device} Set output file [default: driver dependent].\n");
62 printf("-d {driver} Output driver [default: 'default'].\n");
63 printf("-L {path} Add path to script / data library search path.\n");
64 printf("-r {sampling rate} Set sampling rate [default: %d]\n",
66 printf("-c {# of channels} Force number of channels [default: use all]\n");
67 printf("-v {master volume} Set master volume [default: %02.02f]\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(" 3, Lagrange) [default: %d]\n",
77 ("-b {size in frames} Set maximum wave buffer size in frames, so\n");
79 (" wave files bigger than this will be paged\n");
81 (" (-1, load full wave in memory) [default: %d]\n",
84 ("-D {number} Verbosity level (0-3) [default: %d].\n",
86 printf("-C {cue file name} Generate .cue file.\n");
87 printf("-T Show tracing information.\n");
89 ("-M Output song to MIDI device instead of softsynth.\n");
91 ("-I Interactive; read from MIDI device and\n");
93 (" use {script} as instrument (UNIMPLEMENTED).\n");
95 printf("Internal sample size: %d bytes (floating point)\n",
96 (int) sizeof(sample_t
));
97 printf("Library path: ");
105 static int main_interactive(char *script_or_ins
)
107 printf("UNIMPLEMENTED; use the 'midiin' program instead.\n");
112 static int main_midi(char *script
)
114 if (compile_ahs(script
))
117 if (midi_device_open(devfile
) < 0) {
118 printf("Error: can't open MIDI device\n");
122 midi_song_play(skip_secs
);
130 static int main_ss(char *script
)
134 /* is it an .sf2? create an ad-hoc mini program to list it */
135 if ((ptr
= strrchr(script
, '.')) != NULL
&& strcmp(ptr
, ".sf2") == 0) {
138 snprintf(tmp
, sizeof(tmp
), "{ sf2 \"%s\" }", script
);
139 if (compile_ahs_string(tmp
))
143 if (compile_ahs(script
))
146 ss_song_render(skip_secs
, driver
, devfile
);
149 printf("clipped: %d optimal volume: %f\n",
150 ss_output_clipped
, ss_optimal_volume
);
156 static int ahxm_main(int argc
, char *argv
[])
168 libpath_add("~/ahxmlib", 0);
170 /* specific converters */
171 transconv_add(".flac", ".wav", "flac -d -s -o '%s' '%s'");
172 transconv_add(".mp3", ".wav", "mpg321 -q -w '%s' '%s'");
174 /* fallout converter */
175 transconv_add(".*", ".wav", "ffmpeg '%s' -i '%s'");
180 while (n
< argc
- 1) {
183 if (strcmp(opt
, "-o") == 0) {
184 /* set output device or file */
188 if (strcmp(opt
, "-d") == 0) {
193 if (strcmp(opt
, "-L") == 0) {
194 /* add path to library */
195 libpath_add(argv
[n
++], 0);
198 if (strcmp(opt
, "-r") == 0) {
199 /* set sampling rate */
200 ss_frequency
= atoi(argv
[n
++]);
203 if (strcmp(opt
, "-c") == 0) {
204 /* set number of channels */
205 ss_nchannels
= atoi(argv
[n
++]);
208 if (strcmp(opt
, "-v") == 0) {
209 /* set master volume */
210 ss_master_volume
= (double) atof(argv
[n
++]);
213 if (strcmp(opt
, "-i") == 0) {
214 /* set interpolation type */
215 ss_interpolation
= atoi(argv
[n
++]);
218 if (strcmp(opt
, "-s") == 0) {
219 /* seconds to skip */
220 skip_secs
= atoi(argv
[n
++]);
223 if (strcmp(opt
, "-I") == 0) {
224 /* activate interactive mode */
228 if (strcmp(opt
, "-M") == 0) {
229 /* activate MIDI mode */
233 if (strcmp(opt
, "-z") == 0) {
235 solo_track
= atoi(argv
[n
++]);
238 if (strcmp(opt
, "-b") == 0) {
240 ss_page_size
= atoi(argv
[n
++]);
242 /* if it's -1, set as 'no limit' */
243 if (ss_page_size
< 0)
244 ss_page_size
= INT_MAX
;
247 if (strcmp(opt
, "-D") == 0) {
248 /* debug information */
249 verbose
= atoi(argv
[n
++]);
252 if (strcmp(opt
, "-C") == 0) {
253 /* set cue file name */
254 ss_cue_file_name
= argv
[n
++];
257 if (strcmp(opt
, "-T") == 0)
263 script
= argv
[argc
- 1];
269 ret
= main_interactive(script
);
272 ret
= main_midi(script
);
274 ret
= main_ss(script
);
280 int main(int argc
, char *argv
[])
282 return ahxm_main(argc
, argv
);