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
39 /* output information */
41 static char *devfile
= NULL
;
42 static char *driver
= "default";
45 static int skip_secs
= 0;
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-2008 Angel Ortega <angel@triptico.com>\n");
60 printf("This software is covered by the GPL license. NO WARRANTY.\n\n");
61 printf("Usage: ahxm [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: %d]\n", ss_frequency
);
67 printf("-c {# of channels} Force number of channels [default: use all]\n");
68 printf("-v {master volume} Set master volume [default: %02.02f]\n",
70 printf("-s {seconds to skip} Seconds to skip from the start of the song.\n");
71 printf(" [default: 0, start from the beginning]\n");
72 printf("-z {track number} Play track number in a solo\n");
73 printf("-i {interpolation} Set interpolation algorithm\n");
74 printf(" (0, none; 1, linear; 2, cubic spline,\n");
75 printf(" 3, Lagrange) [default: %d]\n", ss_interpolation
);
76 printf("-b {size in frames} Set maximum wave buffer size in frames, so\n");
77 printf(" wave files bigger than this will be paged\n");
78 printf(" (-1, load full wave in memory) [default: %d]\n",
80 printf("-D {number} Verbosity level (0-3) [default: %d].\n", verbose
);
81 printf("-C {cue file name} Generate .cue file.\n");
82 printf("-T Show tracing information.\n");
84 ("-M Output song to MIDI device instead of softsynth.\n");
85 printf("-I Interactive; read from MIDI device and\n");
86 printf(" use {script} as instrument (UNIMPLEMENTED).\n");
88 printf("Internal sample size: %d bytes (floating point)\n", (int) sizeof(sample_t
));
94 static int main_interactive(char *script_or_ins
)
96 printf("UNIMPLEMENTED; use the 'midiin' program instead.\n");
101 static int main_midi(char *script
)
103 if (compile_ahs(script
))
106 if (midi_device_open(devfile
) < 0) {
107 printf("Error: can't open MIDI device\n");
111 midi_song_play(skip_secs
);
119 static int main_ss(char *script
)
123 /* is it an .sf2? create an ad-hoc mini program to list it */
124 if ((ptr
= strrchr(script
, '.')) != NULL
&& strcmp(ptr
, ".sf2") == 0) {
127 snprintf(tmp
, sizeof(tmp
), "{ sf2 \"%s\" }", script
);
128 if (compile_ahs_string(tmp
))
132 if (compile_ahs(script
))
135 ss_song_render(skip_secs
, driver
, devfile
);
138 printf("clipped: %d optimal volume: %f\n",
139 ss_output_clipped
, ss_optimal_volume
);
145 static int ahxm_main(int argc
, char *argv
[])
160 libpath_add("~/ahxmlib", 0);
162 /* specific converters */
163 transconv_add(".flac", ".wav", "flac -d -s -o '%s' '%s'");
164 transconv_add(".mp3", ".wav", "mpg321 -q -w '%s' '%s'");
166 /* fallout converter */
167 transconv_add(".*", ".wav", "ffmpeg '%s' -i '%s'");
169 while (n
< argc
- 1) {
172 if (strcmp(opt
, "-o") == 0) {
173 /* set output device or file */
176 else if (strcmp(opt
, "-d") == 0) {
180 else if (strcmp(opt
, "-L") == 0) {
181 /* add path to library */
182 libpath_add(argv
[n
++], 0);
184 else if (strcmp(opt
, "-r") == 0) {
185 /* set sampling rate */
186 ss_frequency
= atoi(argv
[n
++]);
188 else if (strcmp(opt
, "-c") == 0) {
189 /* set number of channels */
190 ss_nchannels
= atoi(argv
[n
++]);
192 else if (strcmp(opt
, "-v") == 0) {
193 /* set master volume */
194 ss_master_volume
= (double) atof(argv
[n
++]);
196 else if (strcmp(opt
, "-i") == 0) {
197 /* set interpolation type */
198 ss_interpolation
= atoi(argv
[n
++]);
200 else if (strcmp(opt
, "-s") == 0) {
201 /* seconds to skip */
202 skip_secs
= atoi(argv
[n
++]);
204 else if (strcmp(opt
, "-I") == 0) {
205 /* activate interactive mode */
208 else if (strcmp(opt
, "-M") == 0) {
209 /* activate MIDI mode */
212 else if (strcmp(opt
, "-z") == 0) {
214 solo_track
= atoi(argv
[n
++]);
216 else if (strcmp(opt
, "-b") == 0) {
218 ss_page_size
= atoi(argv
[n
++]);
220 /* if it's -1, set as 'no limit' */
221 if (ss_page_size
< 0)
222 ss_page_size
= INT_MAX
;
224 else if (strcmp(opt
, "-D") == 0) {
225 /* debug information */
226 verbose
= atoi(argv
[n
++]);
228 else if (strcmp(opt
, "-C") == 0) {
229 /* set cue file name */
230 ss_cue_file_name
= argv
[n
++];
232 else if (strcmp(opt
, "-T") == 0)
239 script
= argv
[argc
- 1];
245 ret
= main_interactive(script
);
247 ret
= main_midi(script
);
249 ret
= main_ss(script
);
255 int main(int argc
, char *argv
[])
257 return ahxm_main(argc
, argv
);