File: ambdec.cc

package info (click to toggle)
ambdec 0.4.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 540 kB
  • ctags: 710
  • sloc: cpp: 4,625; makefile: 47
file content (130 lines) | stat: -rw-r--r-- 3,593 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
/*
    Copyright (C) 2006-2009 Fons Adriaensen <fons@kokkinizita.net>
    
    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, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/


#include <stdlib.h>
#include <stdio.h>
#include <clthreads.h>
#include <sys/mman.h>
#include <signal.h>
#include "styles.h"
#include "jclient.h"
#include "mainwin.h"


#define NOPTS 4
#define CP (char *)


XrmOptionDescRec options [NOPTS] =
{
    {CP"-h", CP".help",    XrmoptionNoArg,   CP"true" },
    {CP"-c", CP".config",  XrmoptionSepArg,  0        },
    {CP"-p", CP".presets", XrmoptionSepArg,  CP"."    },
    {CP"-V", CP".volume",  XrmoptionSepArg,  CP"-60"  }
};



static Jclient  *jclient = 0;
static Mainwin  *mainwin = 0;



static void help (void)
{
    fprintf (stderr, "\nAmbDec-%s\n\n", VERSION);
    fprintf (stderr, "  (C) 2006-2009 Fons Adriaensen  <fons@kokkinizita.net>\n\n");
    fprintf (stderr, "Options:\n");
    fprintf (stderr, "  -h           Display this text\n");
    fprintf (stderr, "  -c <file>    Configuration file \n");
    fprintf (stderr, "  -p <path>    Preset directory\n");
    fprintf (stderr, "  -V <volume>  Initial volume in dB (-60)\n");
    exit (1);
}


static void sigint_handler (int)
{
    signal (SIGINT, SIG_IGN);
    mainwin->stop ();
}


int main (int ac, char *av [])
{
    X_resman       xresman;
    X_display     *display;
    X_handler     *handler;
    X_rootwin     *rootwin;
    int           e;

    xresman.init (&ac, av, CP"ambdec", options, NOPTS);
    if (xresman.getb (".help", 0)) help ();
            
    display = new X_display (xresman.get (".display", 0));
    if (display->dpy () == 0)
    {
	fprintf (stderr, "Can't open display.\n");
        delete display;
	exit (1);
    }

    styles_init (display, &xresman);

    jclient = new Jclient (xresman.rname ());
    rootwin = new X_rootwin (display);
    mainwin = new Mainwin (rootwin, &xresman, 100, 100, jclient);
    rootwin->handle_event ();
    handler = new X_handler (display, mainwin, EV_X11);
    handler->next_event ();
    XFlush (display->dpy ());

    ITC_ctrl::connect (mainwin, EV_GO_BYPASS,  jclient, EV_GO_BYPASS);
    ITC_ctrl::connect (mainwin, EV_GO_SILENCE, jclient, EV_GO_SILENCE);
    ITC_ctrl::connect (mainwin, EV_GO_PROCESS, jclient, EV_GO_PROCESS);
    ITC_ctrl::connect (jclient, EV_GO_BYPASS,  mainwin, EV_GO_BYPASS);
    ITC_ctrl::connect (jclient, EV_GO_SILENCE, mainwin, EV_GO_SILENCE);
    ITC_ctrl::connect (jclient, EV_GO_PROCESS, mainwin, EV_GO_PROCESS);
    ITC_ctrl::connect (jclient, EV_EXIT,       mainwin, EV_EXIT);

    if (mlockall (MCL_CURRENT | MCL_FUTURE)) fprintf (stderr, "Warning: memory lock failed.\n");
    signal (SIGINT, sigint_handler); 

    mainwin->loadconf ();
    do
    {
	e = mainwin->process ();
	if (e == EV_X11)
	{
	    rootwin->handle_event ();
	    handler->next_event ();
	}
    }
    while (e != EV_EXIT);	

    delete jclient;
    delete handler;
    delete rootwin;
    delete display;
   
    return 0;
}