2
Copyright (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>
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>
37
static char *options = "htuAJBM:N:S:I:W:d:r:p:n:";
39
static char *options = "htuJBM:N:S:I:W:";
41
static char optline [1024];
42
static bool t_opt = false;
43
static bool u_opt = false;
44
static bool A_opt = false;
45
static bool B_opt = false;
46
static int r_val = 48000;
47
static int p_val = 1024;
49
static const char *N_val = "aeolus";
50
static const char *S_val = "stops";
51
static const char *I_val = "Aeolus";
52
static const char *W_val = "waves";
53
static const char *d_val = "default";
54
static Lfq_u32 note_queue (256);
55
static Lfq_u32 comm_queue (256);
56
static Lfq_u8 midi_queue (1024);
60
static void help (void)
62
fprintf (stderr, "\nAeolus %s\n\n",VERSION);
63
fprintf (stderr, " (C) 2003-2008 Fons Adriaensen <fons@kokkinizita.net>\n");
64
fprintf (stderr, "Options:\n");
65
fprintf (stderr, " -h Display this text\n");
66
fprintf (stderr, " -t Text mode user interface\n");
67
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");
71
fprintf (stderr, " -N <name> Name to use as JACK and CoreMIDI client [aeolus]\n");
73
fprintf (stderr, " -S <stops> Name of stops directory [stops]\n");
74
fprintf (stderr, " -I <instr> Name of instrument directory [Aeolus]\n");
75
fprintf (stderr, " -W <waves> Name of waves directory [waves]\n");
76
fprintf (stderr, " -B Ambisonics B format output (JACK only)\n");
77
fprintf (stderr, " -J Use JACK (default)\n");
79
fprintf (stderr, " -A Use ALSA, with options:\n");
80
fprintf (stderr, " -d <device> Alsa device [default]\n");
81
fprintf (stderr, " -r <rate> Sample frequency [48000]\n");
82
fprintf (stderr, " -p <period> Period size [1024]\n");
83
fprintf (stderr, " -n <nfrags> Number of fragments [2]\n\n");
89
static void procoptions (int ac, char *av [], const char *where)
95
while ((k = getopt (ac, av, options)) != -1)
97
if (optarg && (*optarg == '-'))
99
fprintf (stderr, "\n%s\n", where);
100
fprintf (stderr, " Missing argument for '-%c' option.\n", k);
101
fprintf (stderr, " Use '-h' to see all options.\n");
106
case 'h' : help (); exit (0);
107
case 't' : t_opt = true; break;
108
case 'u' : u_opt = true; break;
109
case 'A' : A_opt = true; break;
110
case 'J' : A_opt = false; break;
111
case 'B' : B_opt = true; break;
112
case 'r' : r_val = atoi (optarg); break;
113
case 'p' : p_val = atoi (optarg); break;
114
case 'n' : n_val = atoi (optarg); break;
115
case 'N' : N_val = optarg; break;
116
case 'S' : S_val = optarg; break;
117
case 'I' : I_val = optarg; break;
118
case 'W' : W_val = optarg; break;
119
case 'd' : d_val = optarg; break;
121
fprintf (stderr, "\n%s\n", where);
122
if (optopt != ':' && strchr (options, optopt)) fprintf (stderr, " Missing argument for '-%c' option.\n", optopt);
123
else if (isprint (optopt)) fprintf (stderr, " Unknown option '-%c'.\n", optopt);
124
else fprintf (stderr, " Unknown option character '0x%02x'.\n", optopt & 255);
125
fprintf (stderr, " Use '-h' to see all options.\n");
134
static int readconfig (const char *path)
144
if ((F = fopen (path, "r")))
146
while (fgets (optline, 1024, F) && (ac == 1))
148
p = strtok (optline, " \t\n");
149
if (*p == '#') continue;
150
while (p && (ac < 30))
153
p = strtok (0, " \t\n");
157
sprintf (s, "In file '%s':", path);
158
procoptions (ac, av, s);
165
static void sigint_handler (int)
167
signal (SIGINT, SIG_IGN);
172
int main (int ac, char *av [])
186
if (p) sprintf (s, "%s/.aeolusrc", p);
187
else strcpy (s, ".aeolusrc");
188
if (readconfig (s)) readconfig ("/etc/aeolus.conf");
189
procoptions (ac, av, "On command line:");
191
if (mlockall (MCL_CURRENT | MCL_FUTURE)) fprintf (stderr, "Warning: memory lock failed.\n");
193
if (t_opt) sprintf (s, "%s/aeolus_txt.so", LIBDIR);
194
else sprintf (s, "%s/aeolus_x11.so", LIBDIR);
195
so_handle = dlopen (s, RTLD_NOW);
198
fprintf (stderr, "Error: can't open user interface plugin: %s.\n", dlerror ());
201
so_create = (iface_cr *) dlsym (so_handle, "create_iface");
204
fprintf (stderr, "Error: can't create user interface plugin: %s.\n", dlerror ());
209
audio = new Audio (N_val, ¬e_queue, &comm_queue);
211
if (A_opt) audio->init_alsa (d_val, r_val, p_val, n_val);
212
else audio->init_jack (B_opt, &midi_queue);
214
audio->init_jack (B_opt, &midi_queue);
216
model = new Model (&comm_queue, &midi_queue, audio->midimap (), audio->appname (), S_val, I_val, W_val, u_opt);
217
imidi = new Imidi (¬e_queue, &midi_queue, audio->midimap (), audio->appname ());
218
slave = new Slave ();
219
iface = so_create (ac, av);
221
ITC_ctrl::connect (audio, EV_EXIT, &itcc, EV_EXIT);
222
ITC_ctrl::connect (audio, EV_QMIDI, model, EV_QMIDI);
223
ITC_ctrl::connect (audio, TO_MODEL, model, FM_AUDIO);
224
ITC_ctrl::connect (imidi, EV_EXIT, &itcc, EV_EXIT);
225
ITC_ctrl::connect (imidi, EV_QMIDI, model, EV_QMIDI);
226
ITC_ctrl::connect (imidi, TO_MODEL, model, FM_IMIDI);
227
ITC_ctrl::connect (model, EV_EXIT, &itcc, EV_EXIT);
228
ITC_ctrl::connect (model, TO_AUDIO, audio, FM_MODEL);
229
ITC_ctrl::connect (model, TO_SLAVE, slave, FM_MODEL);
230
ITC_ctrl::connect (model, TO_IFACE, iface, FM_MODEL);
231
ITC_ctrl::connect (slave, EV_EXIT, &itcc, EV_EXIT);
232
ITC_ctrl::connect (slave, TO_AUDIO, audio, FM_SLAVE);
233
ITC_ctrl::connect (slave, TO_MODEL, model, FM_SLAVE);
234
ITC_ctrl::connect (iface, EV_EXIT, &itcc, EV_EXIT);
235
ITC_ctrl::connect (iface, TO_MODEL, model, FM_IFACE);
238
if (imidi->thr_start (SCHED_FIFO, audio->relpri () - 20, 0x00010000))
240
fprintf (stderr, "Warning: can't run midi thread in RT mode.\n");
241
imidi->thr_start (SCHED_OTHER, 0, 0x00010000);
243
if (model->thr_start (SCHED_FIFO, audio->relpri () - 30, 0x00010000))
245
fprintf (stderr, "Warning: can't run model thread in RT mode.\n");
246
model->thr_start (SCHED_OTHER, 0, 0x00010000);
248
slave->thr_start (SCHED_OTHER, 0, 0x00010000);
249
iface->thr_start (SCHED_OTHER, 0, 0x00010000);
251
signal (SIGINT, sigint_handler);
255
itcc.get_event (1 << EV_EXIT);