~ubuntu-branches/ubuntu/wily/japa/wily

« back to all changes in this revision

Viewing changes to japa.cc

  • Committer: Package Import Robot
  • Author(s): Jaromír Mikeš
  • Date: 2013-08-07 02:19:42 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20130807021942-1rdfsndm8ga103f5
Tags: 0.8.4-1
* New upstream release.
* Fixed URL in watch file.
* Fixed URL and upstream email.
* Fixed homepage URL.
* Set dh/compat 9
* Tighten build-dep on libclthreads.
* Tighten build-dep on libclxclient.
* Bump standards.
* Fix VCS canonical URLs.
* Set Priority optional.
* Don't sign tags.
* Update copyright file.
* Added Keywords entry to desktop files.
* Tune gitignore file to handle rather dir.
* Update man pages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -------------------------------------------------------------------------
2
 
//
3
 
//  Copyright (C) 2004-2010 Fons Adriaensen <fons@kokkinizita.net>
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 2 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, write to the Free Software
17
 
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
 
//
19
 
// -------------------------------------------------------------------------
20
 
 
21
 
 
22
 
#include <stdlib.h>
23
 
#include <stdio.h>
24
 
#include <clthreads.h>
25
 
#include <clxclient.h>
26
 
#include <sys/mman.h>
27
 
#include "messages.h"
28
 
#include "mainwin.h"
29
 
#include "audio.h"
30
 
 
31
 
 
32
 
#define NOPTS 10
33
 
#define CP (char *)
34
 
 
35
 
 
36
 
XrmOptionDescRec options [NOPTS] =
37
 
{
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        }
48
 
};
49
 
 
50
 
 
51
 
static void help (void)
52
 
{
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");
68
 
    exit (1);
69
 
}
70
 
 
71
 
 
72
 
int main (int argc, char *argv [])
73
 
{
74
 
    X_resman       xrm;
75
 
    X_display     *display;
76
 
    X_handler     *xhandler;
77
 
    X_rootwin     *rootwin;
78
 
    Mainwin       *mainwin;
79
 
    Audio         *driver;
80
 
    ITC_ctrl       itcc;
81
 
 
82
 
    // Initialse resource database
83
 
    xrm.init (&argc, argv, CP"japa", options, NOPTS);
84
 
    if (xrm.getb (".help", 0)) help ();
85
 
            
86
 
    // Open display
87
 
    display = new X_display (xrm.get (".display", 0));
88
 
    if (display->dpy () == 0)
89
 
    {
90
 
        fprintf (stderr, "Can't open display !\n");
91
 
        delete display;
92
 
        exit (1);
93
 
    }
94
 
    // Open audio interface
95
 
    driver = new Audio (&itcc, xrm.rname ());
96
 
 
97
 
    if (xrm.getb (".jack", 0))
98
 
    {
99
 
        driver->init_jack (xrm.get (".server", 0));
100
 
    }
101
 
    else if (xrm.getb (".alsa", 0))
102
 
    {
103
 
        const char *p, *adev, *capt, *play;
104
 
        int  fsamp, period, nfrags;
105
 
 
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);
117
 
    }
118
 
    else help ();
119
 
 
120
 
    // Initialise resources and create windows
121
 
    init_styles (display, &xrm);
122
 
    rootwin = new X_rootwin (display);
123
 
    mainwin = new Mainwin (rootwin, &xrm, driver);
124
 
 
125
 
    // Create X handler
126
 
    xhandler = new X_handler (display, &itcc, EV_X11);
127
 
    xhandler->next_event ();
128
 
    XFlush (display->dpy ());
129
 
 
130
 
    // Try to lock memory
131
 
    if (mlockall (MCL_CURRENT | MCL_FUTURE))
132
 
    {
133
 
        fprintf (stderr, "Warning: memory lock failed.\n");
134
 
    }
135
 
 
136
 
    // Enter main loop
137
 
    while (mainwin->running ())
138
 
    {
139
 
        switch (itcc.get_event ())
140
 
        {
141
 
        case EV_TRIG:
142
 
            mainwin->handle_trig ();
143
 
            rootwin->handle_event ();
144
 
            XFlush (display->dpy ());
145
 
            break;
146
 
 
147
 
        case EV_JACK:
148
 
            mainwin->handle_term ();
149
 
            break;
150
 
 
151
 
        case EV_MESG:
152
 
            mainwin->handle_mesg (itcc.get_message ());
153
 
            rootwin->handle_event ();
154
 
            XFlush (display->dpy ());
155
 
            break;
156
 
 
157
 
        case EV_X11:
158
 
            rootwin->handle_event ();
159
 
            xhandler->next_event ();
160
 
            break;
161
 
        }
162
 
    }
163
 
 
164
 
    // Cleanup
165
 
    delete xhandler;
166
 
    delete driver;
167
 
    delete mainwin;
168
 
    delete rootwin;
169
 
    delete display;
170
 
   
171
 
    return 0;
172
 
}
173
 
 
174
 
 
175