2
Copyright (C) 2003-2005 Fons Adriaensen <fons.adriaensen@skynet.be>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program; if not, write to the Free Software
16
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27
#include <clthreads.h>
36
#define SVNREV "$Revision: 17 $"
37
#define SVNDATE "$Date: 2006-06-10 14:46:07 +0200 (Sat, 10 Jun 2006) $"
38
#define RELEASE "0.6.6-2.beta"
41
static char *options = "htuAJBN:C:S:I:W:d:r:p:n:";
42
static char optline [1024];
43
static bool t_opt = false;
44
static bool u_opt = false;
45
static bool A_opt = false;
46
static bool B_opt = false;
48
static int r_val = 48000;
49
static int p_val = 1024;
51
static const char *N_val = "aeolus";
52
static const char *S_val = "stops";
53
static const char *I_val = "Aeolus";
54
static const char *W_val = "waves";
55
static const char *d_val = "default";
60
static void help (void)
62
fprintf (stderr, "\nAeolus %s\n\n",VERSION);
63
fprintf (stderr, " (C) 2003-2006 Fons Adriaensen <fons.adriaensen@skynet.be>\n");
64
fprintf (stderr, " %s, %s\n\n", SVNREV, SVNDATE);
65
fprintf (stderr, "Options:\n");
66
fprintf (stderr, " -h Display this text\n");
67
fprintf (stderr, " -t Text mode user interface\n");
68
fprintf (stderr, " -u Use presets file in user's home dir\n");
69
fprintf (stderr, " -N <name> Name to use as JACK and ALSA client [aeolus]\n");
70
fprintf (stderr, " -S <stops> Name of stops directory [stops]\n");
71
fprintf (stderr, " -I <instr> Name of instrument directory [Aeolus]\n");
72
fprintf (stderr, " -W <waves> Name of waves directory [waves]\n");
73
fprintf (stderr, " -B Ambisonics B format output\n");
74
fprintf (stderr, " -C <nchan> Number of channels (2,4,8) [2]\n");
75
fprintf (stderr, " -J Use JACK (default)\n");
76
fprintf (stderr, " -A Use ALSA, with options:\n");
77
fprintf (stderr, " -d <device> Alsa device [default]\n");
78
fprintf (stderr, " -r <rate> Sample frequency [48000]\n");
79
fprintf (stderr, " -p <period> Period size [1024]\n");
80
fprintf (stderr, " -n <nfrags> Number of fragments [2]\n\n");
85
static void procoptions (int ac, char *av [], const char *where)
91
while ((k = getopt (ac, av, options)) != -1)
93
if (optarg && (*optarg == '-'))
95
fprintf (stderr, "\n%s\n", where);
96
fprintf (stderr, " Missing argument for '-%c' option.\n", k);
97
fprintf (stderr, " Use '-h' to see all options.\n");
102
case 'h' : help (); exit (0);
103
case 't' : t_opt = true; break;
104
case 'u' : u_opt = true; break;
105
case 'A' : A_opt = true; break;
106
case 'J' : A_opt = false; break;
107
case 'B' : B_opt = true; break;
108
case 'C' : C_val = atoi (optarg); break;
109
case 'r' : r_val = atoi (optarg); break;
110
case 'p' : p_val = atoi (optarg); break;
111
case 'n' : n_val = atoi (optarg); break;
112
case 'N' : N_val = optarg; break;
113
case 'S' : S_val = optarg; break;
114
case 'I' : I_val = optarg; break;
115
case 'W' : W_val = optarg; break;
116
case 'd' : d_val = optarg; break;
118
fprintf (stderr, "\n%s\n", where);
119
if (optopt != ':' && strchr (options, optopt)) fprintf (stderr, " Missing argument for '-%c' option.\n", optopt);
120
else if (isprint (optopt)) fprintf (stderr, " Unknown option '-%c'.\n", optopt);
121
else fprintf (stderr, " Unknown option character '0x%02x'.\n", optopt & 255);
122
fprintf (stderr, " Use '-h' to see all options.\n");
131
static int readconfig (const char *path)
141
if ((F = fopen (path, "r")))
143
while (fgets (optline, 1024, F) && (ac == 1))
145
p = strtok (optline, " \t\n");
146
if (*p == '#') continue;
147
while (p && (ac < 30))
150
p = strtok (0, " \t\n");
154
sprintf (s, "In file '%s':", path);
155
procoptions (ac, av, s);
162
static void sigint_handler (int)
164
signal (SIGINT, SIG_IGN);
169
int main (int ac, char *av [])
183
if (p) sprintf (s, "%s/.aeolusrc", p);
184
else strcpy (s, ".aeolusrc");
185
if (readconfig (s)) readconfig ("/etc/aeolus.conf");
186
procoptions (ac, av, "On command line:");
188
if (mlockall (MCL_CURRENT | MCL_FUTURE)) fprintf (stderr, "Warning: memory lock failed.\n");
190
if (t_opt) sprintf (s, "%s/aeolus_txt.so", LIBDIR);
191
else sprintf (s, "%s/aeolus_x11.so", LIBDIR);
192
so_handle = dlopen (s, RTLD_NOW);
195
fprintf (stderr, "Error: can't open user interface plugin: %s.\n", dlerror ());
198
so_create = (iface_cr *) dlsym (so_handle, "create_iface");
201
fprintf (stderr, "Error: can't create user interface plugin: %s.\n", dlerror ());
206
audio = new Audio (N_val);
207
model = new Model (audio->qcomm (), N_val, S_val, I_val, W_val, u_opt);
208
imidi = new Imidi (audio->qnote (), N_val, model->chconf ());
209
slave = new Slave ();
210
iface = so_create (ac, av);
212
ITC_ctrl::connect (audio, EV_EXIT, &itcc, EV_EXIT);
213
ITC_ctrl::connect (audio, TO_MODEL, model, FM_AUDIO);
214
ITC_ctrl::connect (imidi, EV_EXIT, &itcc, EV_EXIT);
215
ITC_ctrl::connect (imidi, TO_MODEL, model, FM_IMIDI);
216
ITC_ctrl::connect (model, EV_EXIT, &itcc, EV_EXIT);
217
ITC_ctrl::connect (model, TO_AUDIO, audio, FM_MODEL);
218
ITC_ctrl::connect (model, TO_SLAVE, slave, FM_MODEL);
219
ITC_ctrl::connect (model, TO_IFACE, iface, FM_MODEL);
220
ITC_ctrl::connect (slave, EV_EXIT, &itcc, EV_EXIT);
221
ITC_ctrl::connect (slave, TO_AUDIO, audio, FM_SLAVE);
222
ITC_ctrl::connect (slave, TO_IFACE, iface, FM_SLAVE);
223
ITC_ctrl::connect (iface, EV_EXIT, &itcc, EV_EXIT);
224
ITC_ctrl::connect (iface, TO_MODEL, model, FM_IFACE);
226
if (A_opt) audio->init_alsa (0, C_val, B_opt, d_val, r_val, p_val, n_val);
227
else audio->init_jack (0, C_val, B_opt);
229
if (imidi->thr_start (SCHED_FIFO, audio->prioty () - 10, 0x00010000))
231
fprintf (stderr, "Warning: can't run midi thread in RT mode.\n");
232
imidi->thr_start (SCHED_OTHER, 0, 0x00010000);
234
if (model->thr_start (SCHED_FIFO, audio->prioty () - 20, 0x00010000))
236
fprintf (stderr, "Warning: can't run model thread in RT mode.\n");
237
model->thr_start (SCHED_OTHER, 0, 0x00010000);
240
slave->thr_start (SCHED_OTHER, 0, 0x00010000);
241
iface->thr_start (SCHED_OTHER, 0, 0x00010000);
243
signal (SIGINT, sigint_handler);
247
itcc.get_event (1 << EV_EXIT);