| 1 |
// ---------------------------------------------------------------------------- |
| 2 |
// |
| 3 |
// Copyright (C) 2003-2013 Fons Adriaensen <[email protected]> |
| 4 |
// |
| 5 |
// This program is free software; you can redistribute it and/or modify |
| 6 |
// it under the terms of the GNU General Public License as published by |
| 7 |
// the Free Software Foundation; either version 3 of the License, or |
| 8 |
// (at your option) any later version. |
| 9 |
// |
| 10 |
// This program is distributed in the hope that it will be useful, |
| 11 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
// GNU General Public License for more details. |
| 14 |
// |
| 15 |
// You should have received a copy of the GNU General Public License |
| 16 |
// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
// |
| 18 |
// ---------------------------------------------------------------------------- |
| 19 |
|
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <stdio.h> |
| 23 |
#include <clthreads.h> |
| 24 |
#include <signal.h> |
| 25 |
#include "styles.h" |
| 26 |
#include "control.h" |
| 27 |
#include "calcthr.h" |
| 28 |
|
| 29 |
|
| 30 |
#define NOPTS 8 |
| 31 |
|
| 32 |
#define CP (char *) |
| 33 |
|
| 34 |
XrmOptionDescRec options [NOPTS] = |
| 35 |
{ |
| 36 |
{CP"-h", CP".help", XrmoptionNoArg, CP"true" }, |
| 37 |
{CP"-J", CP".jack", XrmoptionNoArg, CP"true" }, |
| 38 |
{CP"-A", CP".alsa", XrmoptionNoArg, CP"true" }, |
| 39 |
{CP"-E", CP".rtexec", XrmoptionSepArg, 0 }, |
| 40 |
{CP"-d", CP".device", XrmoptionSepArg, 0 }, |
| 41 |
{CP"-r", CP".fsamp", XrmoptionSepArg, 0 }, |
| 42 |
{CP"-p", CP".period", XrmoptionSepArg, 0 }, |
| 43 |
{CP"-n", CP".nfrags", XrmoptionSepArg, 0 } |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
static void help (void) |
| 48 |
{ |
| 49 |
fprintf (stderr, "Aliki-%s\n (C) Fons Adriaensen\n <[email protected]>\n\n", VERSION); |
| 50 |
fprintf (stderr, "-h Display this text\n"); |
| 51 |
fprintf (stderr, "-J Use JACK\n"); |
| 52 |
fprintf (stderr, "-A Use ALSA, with options:\n"); |
| 53 |
fprintf (stderr, " -d <device> Alsa device [hw:0,0]\n"); |
| 54 |
fprintf (stderr, " -r <rate> Sample frequency [48000]\n"); |
| 55 |
fprintf (stderr, " -p <period> Period size [1024]\n"); |
| 56 |
fprintf (stderr, " -n <nfrags> Number of fragments [2]\n"); |
| 57 |
fprintf (stderr, "-E <prefix> Prefix for audio process, e.g. sudo\n\n"); |
| 58 |
fprintf (stderr, "Without either -J or -A only the file processing functions are available.\n\n"); |
| 59 |
exit (1); |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
static X_resman resman; |
| 64 |
static Control *control; |
| 65 |
static Calcthr *calcthr; |
| 66 |
|
| 67 |
|
| 68 |
static void sigint_handler (int) |
| 69 |
{ |
| 70 |
signal (SIGINT, SIG_IGN); |
| 71 |
control->stop (); |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
int main (int argc, char *argv []) |
| 76 |
{ |
| 77 |
X_display *display; |
| 78 |
|
| 79 |
resman.init (&argc, argv, CP"aliki", options, NOPTS); |
| 80 |
if (resman.getb (".help", 0)) help (); |
| 81 |
|
| 82 |
display = new X_display (resman.get (".display", 0)); |
| 83 |
if (display->dpy () == 0) |
| 84 |
{ |
| 85 |
fprintf (stderr, "Can't open display !\n"); |
| 86 |
delete display; |
| 87 |
exit (1); |
| 88 |
} |
| 89 |
|
| 90 |
init_styles (display, &resman); |
| 91 |
control = new Control (display, &resman); |
| 92 |
calcthr = new Calcthr (); |
| 93 |
calcthr->thr_start (SCHED_OTHER, 0, 0x00010000); |
| 94 |
|
| 95 |
ITC_ctrl::connect (control, TO_CALC, calcthr, TO_CALC); |
| 96 |
ITC_ctrl::connect (calcthr, TO_CTRL, control, TO_CTRL); |
| 97 |
ITC_ctrl::connect (calcthr, EV_PROG, control, EV_PROG); |
| 98 |
|
| 99 |
signal (SIGINT, sigint_handler); |
| 100 |
signal (SIGFPE, sigint_handler); |
| 101 |
signal (SIGSEGV, sigint_handler); |
| 102 |
|
| 103 |
control->thr_main (); |
| 104 |
|
| 105 |
delete control; |
| 106 |
delete display; |
| 107 |
|
| 108 |
return 0; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|