File: jaaa.cc

package info (click to toggle)
jaaa 0.9.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 232 kB
  • sloc: cpp: 2,210; makefile: 41
file content (174 lines) | stat: -rw-r--r-- 5,389 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// ----------------------------------------------------------------------------
//
//  Copyright (C) 2004-2018 Fons Adriaensen <fons@linuxaudio.org>
//    
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// ----------------------------------------------------------------------------


#include <stdlib.h>
#include <stdio.h>
#include <clthreads.h>
#include <clxclient.h>
#include <sys/mman.h>
#include "messages.h"
#include "mainwin.h"
#include "audio.h"


#define NOPTS 10
#define CP (char *)


XrmOptionDescRec options [NOPTS] =
{
    {CP"-h",   CP".help",      XrmoptionNoArg,  CP"true"  },
    {CP"-J",   CP".jack",      XrmoptionNoArg,  CP"true"  },
    {CP"-s",   CP".server",    XrmoptionSepArg,  0        },
    {CP"-A",   CP".alsa",      XrmoptionNoArg,  CP"true"  },
    {CP"-d",   CP".device",    XrmoptionSepArg,  0        },
    {CP"-C",   CP".capture",   XrmoptionSepArg,  0        },
    {CP"-P",   CP".playback",  XrmoptionSepArg,  0        },
    {CP"-r",   CP".fsamp",     XrmoptionSepArg,  0        },
    {CP"-p",   CP".period",    XrmoptionSepArg,  0        },
    {CP"-n",   CP".nfrags",    XrmoptionSepArg,  0        }
};


static void help (void)
{
    fprintf (stderr, "\nJaaa-%s\n\n", VERSION);
    fprintf (stderr, "  (C) 2004-2010 Fons Adriaensen  <fons@kokkinizita.net>\n\n");
    fprintf (stderr, "Options:\n");
    fprintf (stderr, "  -h                 Display this text\n");
    fprintf (stderr, "  -name <name>       Jack and X11 name\n");
    fprintf (stderr, "  -J                 Use JACK, with options:\n");
    fprintf (stderr, "    -s <server>        Select Jack server\n");
    fprintf (stderr, "  -A                 Use ALSA, with options:\n");
    fprintf (stderr, "    -d <device>        Alsa device [hw:0]\n");
    fprintf (stderr, "    -C <device>        Capture device\n");
    fprintf (stderr, "    -P <device>        Playback device\n");
    fprintf (stderr, "    -r <rate>          Sample frequency [48000]\n");
    fprintf (stderr, "    -p <period>        Period size [1024]\n");
    fprintf (stderr, "    -n <nfrags>        Number of fragments [2]\n\n");
    fprintf (stderr, "  Either -J or -A is required.\n\n");
    exit (1);
}


int main (int argc, char *argv [])
{
    X_resman       xrm;
    X_display     *display;
    X_handler     *xhandler;
    X_rootwin     *rootwin;
    Mainwin       *mainwin;
    Audio         *driver;
    ITC_ctrl       itcc;

    // Initialse resource database
    xrm.init (&argc, argv, CP"jaaa", options, NOPTS);
    if (xrm.getb (".help", 0)) help ();
            
    // Open display
    display = new X_display (xrm.get (".display", 0));
    if (display->dpy () == 0)
    {
	fprintf (stderr, "Can't open display !\n");
        delete display;
	exit (1);
    }
    // Open audio interface
    driver = new Audio (&itcc, xrm.rname ());

    if (xrm.getb (".jack", 0))
    {
        driver->init_jack (xrm.get (".server", 0));
    }
    else if (xrm.getb (".alsa", 0))
    {
	const char *p, *adev, *capt, *play;
        int  fsamp, period, nfrags;

        p = xrm.get (".fsamp", 0);
        if (! p || sscanf (p, "%d", &fsamp) != 1) fsamp = 48000;
        p = xrm.get (".period", 0);
        if (! p || sscanf (p, "%d", &period) != 1) period = 1024;
        p = xrm.get (".nfrags", 0);
        if (! p || sscanf (p, "%d", &nfrags) != 1) nfrags = 2;
        adev = xrm.get (".device", "hw:0");
        capt = xrm.get (".capture", 0);
        play = xrm.get (".playback", 0);
	if (!capt && !play) capt = play = adev;
        driver->init_alsa (play, capt, fsamp, period, nfrags, 4, 4);
    }
    else help ();

    // Initialise resources and create windows
    init_styles (display, &xrm);
    rootwin = new X_rootwin (display);
    mainwin = new Mainwin (rootwin, &xrm, driver);

    // Create X handler
    xhandler = new X_handler (display, &itcc, EV_X11);
    xhandler->next_event ();
    XFlush (display->dpy ());

    // Try to lock memory
    if (mlockall (MCL_CURRENT | MCL_FUTURE))
    {
        fprintf (stderr, "Warning: memory lock failed.\n");
    }

    // Enter main loop
    while (mainwin->running ())
    {
	switch (itcc.get_event ())
	{
        case EV_TRIG:
            mainwin->handle_trig ();
	    rootwin->handle_event ();
            XFlush (display->dpy ());
            break;

        case EV_JACK:
            mainwin->handle_term ();
            break;

        case EV_MESG:
            mainwin->handle_mesg (itcc.get_message ());
	    rootwin->handle_event ();
            XFlush (display->dpy ());
            break;

	case EV_X11:
	    rootwin->handle_event ();
	    xhandler->next_event ();
            break;
	}
    }

    // Cleanup
    delete xhandler;
    delete driver;
    delete mainwin; 
    delete rootwin;
    delete display;

    return 0;
}