add_note_event() now uses add_song_ev(); everything is broken now.
[ahxm.git] / main.c
blob9d3309b8911dac8592b217e44547ce582fca0bcd
1 /*
3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2007 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 "ahxm.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-2007 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",
69 ss_master_volume);
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",
79 ss_page_size);
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");
83 printf
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");
87 printf("\n");
88 printf("Internal sample size: %d bytes (floating point)\n", (int) sizeof(sample_t));
90 return 1;
94 static int main_interactive(char *script_or_ins)
96 printf("UNIMPLEMENTED; use the 'midiin' program instead.\n");
97 return 0;
101 static int main_midi(char *script)
103 if (compile_ahs(script))
104 return 3;
106 if (midi_device_open(devfile) < 0) {
107 printf("Error: can't open MIDI device\n");
108 return 2;
111 midi_song_play(skip_secs);
113 midi_device_close();
115 return 0;
119 static int main_ss(char *script)
121 if (compile_ahs(script))
122 return 3;
124 ss_song_render(skip_secs, driver, devfile);
126 if (verbose >= 1)
127 printf("clipped: %d optimal volume: %f\n",
128 ss_output_clipped, ss_optimal_volume);
130 return 0;
134 static int ahxm_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 libpath_add("~/ahxmlib", 0);
151 /* specific converters */
152 transconv_add(".flac", ".wav", "flac -d -s -o '%s' '%s'");
153 transconv_add(".mp3", ".wav", "mpg321 -q -w '%s' '%s'");
155 /* fallout converter */
156 transconv_add(".*", ".wav", "ffmpeg '%s' -i '%s'");
158 while (n < argc - 1) {
159 opt = argv[n++];
161 if (strcmp(opt, "-o") == 0) {
162 /* set output device or file */
163 devfile = argv[n++];
165 else if (strcmp(opt, "-d") == 0) {
166 /* set driver */
167 driver = argv[n++];
169 else if (strcmp(opt, "-L") == 0) {
170 /* add path to library */
171 libpath_add(argv[n++], 0);
173 else if (strcmp(opt, "-r") == 0) {
174 /* set sampling rate */
175 ss_frequency = atoi(argv[n++]);
177 else if (strcmp(opt, "-c") == 0) {
178 /* set number of channels */
179 ss_nchannels = atoi(argv[n++]);
181 else if (strcmp(opt, "-v") == 0) {
182 /* set master volume */
183 ss_master_volume = (double) atof(argv[n++]);
185 else if (strcmp(opt, "-i") == 0) {
186 /* set interpolation type */
187 ss_interpolation = atoi(argv[n++]);
189 else if (strcmp(opt, "-s") == 0) {
190 /* seconds to skip */
191 skip_secs = atoi(argv[n++]);
193 else if (strcmp(opt, "-I") == 0) {
194 /* activate interactive mode */
195 interactive = 1;
197 else if (strcmp(opt, "-M") == 0) {
198 /* activate MIDI mode */
199 midi = 1;
201 else if (strcmp(opt, "-z") == 0) {
202 /* set solo track */
203 solo_track = atoi(argv[n++]);
205 else if (strcmp(opt, "-b") == 0) {
206 /* set page size */
207 ss_page_size = atoi(argv[n++]);
209 /* if it's -1, set as 'no limit' */
210 if (ss_page_size < 0)
211 ss_page_size = INT_MAX;
213 else if (strcmp(opt, "-D") == 0) {
214 /* debug information */
215 verbose = atoi(argv[n++]);
217 else if (strcmp(opt, "-C") == 0) {
218 /* set cue file name */
219 ss_cue_file_name = argv[n++];
221 else if (strcmp(opt, "-T") == 0)
222 trace = 1;
223 else
224 return main_usage();
228 script = argv[argc - 1];
230 if (*script == '-')
231 return main_usage();
233 if (interactive)
234 ret = main_interactive(script);
235 else if (midi)
236 ret = main_midi(script);
237 else
238 ret = main_ss(script);
240 return ret;
244 int main(int argc, char *argv[])
246 return ahxm_main(argc, argv);