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.
24
#include <readline/readline.h>
25
#include <readline/history.h>
30
extern "C" Iface *create_iface (int ac, char *av [])
32
return new Tiface (ac, av);
38
Reader::Reader (Edest *edest, int ipind) :
39
H_thread (edest, ipind)
44
Reader::~Reader (void)
49
void Reader::read (void)
51
put_event (0, new M_ifc_txtip);
55
void Reader::thr_main (void)
63
M = (M_ifc_txtip *) get_message ();
64
M->_line = readline ("Aeolus> ");
65
if (M->_line) add_history (M->_line);
73
Tiface::Tiface (int ac, char *av []) :
74
_reader (this, FM_TXTIP),
82
for (i = 0; i < NGROUP; i++) _ifelms [i] = 0;
86
Tiface::~Tiface (void)
91
void Tiface::stop (void)
96
void Tiface::thr_main (void)
103
switch (get_event ())
107
handle_mesg (get_message ());
114
send_event (EV_EXIT, 1);
118
void Tiface::handle_mesg (ITC_mesg *M)
123
handle_ifc_init ((M_ifc_init *) M);
132
handle_ifc_elclr ((M_ifc_ifelm *) M);
136
handle_ifc_elset ((M_ifc_ifelm *) M);
140
handle_ifc_elatt ((M_ifc_ifelm *) M);
144
handle_ifc_grclr ((M_ifc_ifelm *) M);
154
handle_ifc_retune ((M_ifc_retune *) M);
158
handle_ifc_mcset ((M_ifc_chconf *) M);
163
handle_ifc_txtip ((M_ifc_txtip *) M);
170
printf ("Received message of unknown type %5ld\n", M->type ());
172
if (M) M->recover ();
176
void Tiface::handle_ifc_ready (void)
180
printf ("Aeolus is ready.\n");
182
_reader.thr_start (SCHED_OTHER, 0, 0x10000);
189
void Tiface::handle_ifc_init (M_ifc_init *M)
191
if (_initdata) _initdata ->recover ();
196
void Tiface::handle_ifc_mcset (M_ifc_chconf *M)
198
if (_mididata) _mididata ->recover ();
200
if (!_init) print_midimap ();
204
void Tiface::handle_ifc_retune (M_ifc_retune *M)
206
printf ("Retuning Aeolus, A = %3.1lf Hz, %s (%s)\n",
208
_initdata->_temped [M->_temp]._label,
209
_initdata->_temped [M->_temp]._mnemo);
213
void Tiface::handle_ifc_grclr (M_ifc_ifelm *M)
215
_ifelms [M->_group] = 0;
219
void Tiface::handle_ifc_elclr (M_ifc_ifelm *M)
221
_ifelms [M->_group] &= ~(1 << M->_ifelm);
225
void Tiface::handle_ifc_elset (M_ifc_ifelm *M)
227
_ifelms [M->_group] |= (1 << M->_ifelm);
231
void Tiface::handle_ifc_elatt (M_ifc_ifelm *M)
233
rewrite_label (_initdata->_groupd [M->_group]._ifelmd [M->_ifelm]._label);
234
printf ("Retuning %7s %-1s (%s)\n",
235
_initdata->_groupd [M->_group]._label,
237
_initdata->_groupd [M->_group]._ifelmd [M->_ifelm]._mnemo);
241
void Tiface::handle_ifc_txtip (M_ifc_txtip *M)
245
send_event (EV_EXIT, 1);
248
parse_command (M->_line);
253
void Tiface::print_info (void)
255
printf ("Application id: %s\n", _initdata->_appid);
256
printf ("Stops directory: %s\n", _initdata->_stops);
257
printf ("Instrument: %s\n", _initdata->_instr);
258
printf ("ALSA Midi port: %d:%d\n", _initdata->_client, _initdata->_ipport);
265
void Tiface::print_keybdd (void)
269
printf ("Keyboards:\n");
270
for (k = 0; k < NKEYBD; k++)
273
if (_initdata->_keybdd [k]._label [0])
275
printf (" %-7s midi", _initdata->_keybdd [k]._label);
276
for (i = 0; i < 16; i++)
278
b = _mididata->_bits [i];
279
if ((b & 0x1000) && ((b & 7) == k))
281
printf (" %2d", i + 1);
285
if (!n) printf (" -");
292
void Tiface::print_divisd (void)
296
printf ("Divisions:\n");
297
for (k = 0; k < NDIVIS; k++)
300
if (_initdata->_divisd [k]._label [0])
302
printf (" %-7s midi", _initdata->_divisd [k]._label);
303
for (i = 0; i < 16; i++)
305
b = _mididata->_bits [i];
306
if ((b & 0x2000) && (((b >> 8) & 7) == k))
308
printf (" %2d", i + 1);
312
if (!n) printf (" -");
319
void Tiface::print_midimap (void)
323
printf ("Midi routing:\n");
325
for (c = 0; c < 16; c++)
327
f = _mididata->_bits [c];
334
printf (" %2d ", c + 1);
335
if (f & 1) printf ("keybd %-7s", _initdata->_keybdd [k]._label);
336
if (f & 2) printf ("divis %-7s", _initdata->_divisd [k]._label);
337
if (f & 4) printf ("instr");
342
if (n == 0) printf (" No channels are assigned.\n");
346
void Tiface::print_stops_short (int group)
351
rewrite_label (_initdata->_groupd [group]._label);
352
printf ("Stops in group %s\n", _tempstr);
354
n = _initdata->_groupd [group]._nifelm;
355
for (i = 0; i < n; i++)
357
printf (" %c %-8s", (m & 1) ? '+' : '-',
358
_initdata->_groupd [group]._ifelmd [i]._mnemo);
359
if ((i % 5) == 4) printf ("\n");
362
if (n % 5) printf ("\n");
366
void Tiface::print_stops_long (int group)
371
rewrite_label (_initdata->_groupd [group]._label);
372
printf ("Stops in group %s\n", _tempstr);
374
n = _initdata->_groupd [group]._nifelm;
375
for (i = 0; i < n; i++)
377
rewrite_label (_initdata->_groupd [group]._ifelmd [i]._label);
378
printf (" %c %-7s %-1s\n", (m & 1) ? '+' : '-',
379
_initdata->_groupd [group]._ifelmd [i]._mnemo, _tempstr);
385
void Tiface::rewrite_label (const char *p)
389
strcpy (_tempstr, p);
390
t = strstr (_tempstr, "-$");
391
if (t) strcpy (t, t + 2);
394
t = strchr (_tempstr, '$');
400
void Tiface::parse_command (const char *p)
404
while (isspace (*p)) p++;
408
if (c2 && !isspace (c2))
410
printf ("Bad command\n");
427
send_event (TO_MODEL, new ITC_mesg (MT_IFC_SAVE));
431
printf ("Unknown command '%c'\n", c1);
436
void Tiface::command_s (const char *p)
441
if ( (sscanf (p, "%s%n", s, &n) != 1)
442
|| ((g = find_group (s)) < 0))
444
printf ("Expected a group name, ? or ??\n");
450
for (i = 0; i < _initdata->_ngroup; i++) print_stops_short (i);
455
for (i = 0; i < _initdata->_ngroup; i++) print_stops_long (i);
458
if ( (sscanf (p, "%s%n", s, &n) != 1)
459
|| ((k = comm1 (s)) < 0))
461
printf ("Expected one of ? ?? + - =\n");
467
print_stops_short (g);
472
print_stops_long (g);
477
send_event (TO_MODEL, new M_ifc_ifelm (MT_IFC_GRCLR, g, 0));
480
if (k == 2) k = MT_IFC_ELSET;
481
else k = MT_IFC_ELCLR;
482
while (sscanf (p, "%s%n", s, &n) == 1)
484
i = find_ifelm (s, g);
485
if (i < 0) printf ("No stop '%s' in this group\n", s);
486
else send_event (TO_MODEL, new M_ifc_ifelm (k, g, i));
492
int Tiface::find_group (const char *p)
496
if (! strcmp (p, "?")) return NGROUP + 1;
497
if (! strcmp (p, "??")) return NGROUP + 2;
498
for (g = 0; g < _initdata->_ngroup; g++)
500
if (! strcmp (p, _initdata->_groupd [g]._label)) return g;
506
int Tiface::find_ifelm (const char *p, int g)
510
n = _initdata->_groupd [g]._nifelm;
511
for (i = 0; i < n; i++)
513
if (! strcmp (p, _initdata->_groupd [g]._ifelmd [i]._mnemo)) return i;
519
int Tiface::comm1 (const char *p)
521
if (! strcmp (p, "?")) return 0;
522
if (! strcmp (p, "??")) return 1;
523
if (! strcmp (p, "+")) return 2;
524
if (! strcmp (p, "-")) return 3;
525
if (! strcmp (p, "=")) return 4;