1
// -------------------------------------------------------------------------
3
// Copyright (C) 2004-2010 Fons Adriaensen <fons@kokkinizita.net>
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 2 of the License, or
8
// (at your option) any later version.
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.
15
// You should have received a copy of the GNU General Public License
16
// along with this program; if not, write to the Free Software
17
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
// -------------------------------------------------------------------------
24
#include <clthreads.h>
25
#include <clxclient.h>
36
XrmOptionDescRec options [NOPTS] =
38
{CP"-h", CP".help", XrmoptionNoArg, CP"true" },
39
{CP"-J", CP".jack", XrmoptionNoArg, CP"true" },
40
{CP"-s", CP".server", XrmoptionSepArg, 0 },
41
{CP"-A", CP".alsa", XrmoptionNoArg, CP"true" },
42
{CP"-d", CP".device", XrmoptionSepArg, 0 },
43
{CP"-C", CP".capture", XrmoptionSepArg, 0 },
44
{CP"-P", CP".playback", XrmoptionSepArg, 0 },
45
{CP"-r", CP".fsamp", XrmoptionSepArg, 0 },
46
{CP"-p", CP".period", XrmoptionSepArg, 0 },
47
{CP"-n", CP".nfrags", XrmoptionSepArg, 0 }
51
static void help (void)
53
fprintf (stderr, "\nJapa-%s\n\n", VERSION);
54
fprintf (stderr, " (C) 2004-2010 Fons Adriaensen <fons@kokkinizita.net>\n\n");
55
fprintf (stderr, "Options:\n");
56
fprintf (stderr, " -h Display this text\n");
57
fprintf (stderr, " -name <name> Jack and X11 name\n");
58
fprintf (stderr, " -J Use JACK, with options:\n");
59
fprintf (stderr, " -s <server> Select Jack server\n");
60
fprintf (stderr, " -A Use ALSA, with options:\n");
61
fprintf (stderr, " -d <device> Alsa device [hw:0]\n");
62
fprintf (stderr, " -C <device> Capture device\n");
63
fprintf (stderr, " -P <device> Playback device\n");
64
fprintf (stderr, " -r <rate> Sample frequency [48000]\n");
65
fprintf (stderr, " -p <period> Period size [1024]\n");
66
fprintf (stderr, " -n <nfrags> Number of fragments [2]\n\n");
67
fprintf (stderr, " Either -J or -A is required.\n\n");
72
int main (int argc, char *argv [])
82
// Initialse resource database
83
xrm.init (&argc, argv, CP"japa", options, NOPTS);
84
if (xrm.getb (".help", 0)) help ();
87
display = new X_display (xrm.get (".display", 0));
88
if (display->dpy () == 0)
90
fprintf (stderr, "Can't open display !\n");
94
// Open audio interface
95
driver = new Audio (&itcc, xrm.rname ());
97
if (xrm.getb (".jack", 0))
99
driver->init_jack (xrm.get (".server", 0));
101
else if (xrm.getb (".alsa", 0))
103
const char *p, *adev, *capt, *play;
104
int fsamp, period, nfrags;
106
p = xrm.get (".fsamp", 0);
107
if (!p || sscanf (p, "%d", &fsamp) != 1) fsamp = 48000;
108
p = xrm.get (".period", 0);
109
if (!p || sscanf (p, "%d", &period) != 1) period = 1024;
110
p = xrm.get (".nfrags", 0);
111
if (!p || sscanf (p, "%d", &nfrags) != 1) nfrags = 2;
112
adev = xrm.get (".device", "hw:0");
113
capt = xrm.get (".capture", 0);
114
play = xrm.get (".playback", 0);
115
if (!capt && !play) capt = play = adev;
116
driver->init_alsa (play, capt, fsamp, period, nfrags);
120
// Initialise resources and create windows
121
init_styles (display, &xrm);
122
rootwin = new X_rootwin (display);
123
mainwin = new Mainwin (rootwin, &xrm, driver);
126
xhandler = new X_handler (display, &itcc, EV_X11);
127
xhandler->next_event ();
128
XFlush (display->dpy ());
130
// Try to lock memory
131
if (mlockall (MCL_CURRENT | MCL_FUTURE))
133
fprintf (stderr, "Warning: memory lock failed.\n");
137
while (mainwin->running ())
139
switch (itcc.get_event ())
142
mainwin->handle_trig ();
143
rootwin->handle_event ();
144
XFlush (display->dpy ());
148
mainwin->handle_term ();
152
mainwin->handle_mesg (itcc.get_message ());
153
rootwin->handle_event ();
154
XFlush (display->dpy ());
158
rootwin->handle_event ();
159
xhandler->next_event ();