~ubuntu-branches/ubuntu/vivid/aeolus/vivid

« back to all changes in this revision

Viewing changes to source/xiface.cc

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-04-19 19:12:51 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100419191251-hgarjfcdfl7c0ryl
Tags: 0.8.4-3
debian/patches/01-makefile.patch: Drop -march=native flag, it isn't valid
for Debian packages as the results are unpredictable, thanks to
Bastian Blank for reporting this (Closes: #578278).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Copyright (C) 2003-2010 Fons Adriaensen <fons@kokkinizita.net>
 
3
    
 
4
    This program is free software; you can redistribute it and/or modify
 
5
    it under the terms of the GNU General Public License as published by
 
6
    the Free Software Foundation; either version 2 of the License, or
 
7
    (at your option) any later version.
 
8
 
 
9
    This program is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
    GNU General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU General Public License
 
15
    along with this program; if not, write to the Free Software
 
16
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
*/
 
18
 
 
19
 
 
20
#include <stdlib.h>
 
21
#include <stdio.h>
 
22
#include <clthreads.h>
 
23
#include "xiface.h"
 
24
#include "styles.h"
 
25
#include "callbacks.h"
 
26
 
 
27
 
 
28
 
 
29
extern "C" Iface *create_iface (int ac, char *av [])
 
30
{
 
31
    return new Xiface (ac, av);
 
32
}
 
33
 
 
34
 
 
35
 
 
36
Xiface::Xiface (int ac, char *av [])
 
37
{
 
38
    _xresm.init (&ac, av, (char *)"aeolus", 0, 0);
 
39
    _disp = new X_display (_xresm.get (".display", 0));
 
40
    if (_disp->dpy () == 0)
 
41
    {
 
42
        fprintf (stderr, "Can't open display !\n");
 
43
        delete _disp;
 
44
        exit (1);
 
45
    }
 
46
    init_styles (_disp, &_xresm);
 
47
    _root = new X_rootwin (_disp);
 
48
    _xhan = new X_handler (_disp, this, EV_XWIN);
 
49
    _xhan->next_event ();
 
50
    _aupar = 0;
 
51
    _dipar = 0;
 
52
    _editp = 0;
 
53
}
 
54
 
 
55
 
 
56
Xiface::~Xiface (void)
 
57
{
 
58
    delete _mainwin;
 
59
    delete _audiowin;
 
60
    delete _instrwin;
 
61
    delete _editwin;
 
62
    delete _xhan;
 
63
    delete _root;
 
64
    delete _disp;
 
65
}
 
66
 
 
67
 
 
68
void Xiface::stop (void)
 
69
{
 
70
    _stop = true;
 
71
}
 
72
 
 
73
 
 
74
void Xiface::thr_main (void)
 
75
{
 
76
    _stop  = false;
 
77
    _ready = false;
 
78
    set_time (0);
 
79
    inc_time (125000);
 
80
    while (! _stop)
 
81
    {
 
82
        switch (get_event_timed ())
 
83
        {
 
84
        case EV_TIME:
 
85
            handle_time ();
 
86
            XFlush (_disp->dpy ());
 
87
            inc_time (125000);
 
88
            break;
 
89
 
 
90
        case FM_MODEL:
 
91
            handle_mesg (get_message ()); 
 
92
            XFlush (_disp->dpy ());
 
93
            break;
 
94
 
 
95
        case EV_XWIN:
 
96
            _root->handle_event ();
 
97
            _xhan->next_event ();
 
98
            break;
 
99
 
 
100
        case EV_EXIT:
 
101
            return;
 
102
        }
 
103
    }
 
104
    send_event (EV_EXIT, 1);
 
105
}
 
106
 
 
107
 
 
108
void Xiface::handle_time (void)
 
109
{
 
110
    if (_ready)
 
111
    {
 
112
        _mainwin->handle_time ();
 
113
        _editwin->handle_time ();
 
114
    }
 
115
    if (_aupar)
 
116
    {        
 
117
        send_event (TO_MODEL, _aupar);
 
118
        _aupar = 0;
 
119
    }
 
120
    if (_dipar)
 
121
    {        
 
122
        send_event (TO_MODEL, _dipar);
 
123
        _dipar = 0;
 
124
    }
 
125
}
 
126
 
 
127
 
 
128
void Xiface::handle_mesg (ITC_mesg *M)
 
129
{
 
130
    switch (M->type ())
 
131
    {
 
132
    case MT_IFC_INIT:
 
133
    {
 
134
        M_ifc_init *X = (M_ifc_init *) M;
 
135
        _mainwin  = new Mainwin (_root, this, 100, 100, &_xresm);           
 
136
        _midiwin  = new Midiwin (_root, this, 120, 120, &_xresm);           
 
137
        _audiowin = new Audiowin (_root, this, 140, 140, &_xresm);           
 
138
        _instrwin = new Instrwin (_root, this, 160, 160, &_xresm);           
 
139
        _editwin  = new Editwin (_root, this, 180, 180, &_xresm);
 
140
        _mainwin->setup (X);
 
141
        _midiwin->setup (X);
 
142
        _audiowin->setup (X);
 
143
        _instrwin->setup (X);
 
144
        _editwin->sdir (X->_stops);
 
145
        _editwin->wdir (X->_waves);
 
146
        _ready = true;         
 
147
        break;
 
148
    }
 
149
    case MT_IFC_READY:
 
150
        _mainwin->set_ready ();
 
151
        _editwin->lock (0);
 
152
        break;
 
153
 
 
154
    case MT_IFC_ELSET:
 
155
    case MT_IFC_ELCLR:
 
156
    case MT_IFC_ELATT:
 
157
    case MT_IFC_GRCLR:
 
158
    {
 
159
        M_ifc_ifelm *X = (M_ifc_ifelm *) M;
 
160
        _mainwin->set_ifelm (X);
 
161
        break;
 
162
    }
 
163
    case MT_IFC_PRRCL:
 
164
    {
 
165
        M_ifc_preset *X = (M_ifc_preset *) M;
 
166
        _mainwin->set_state (X);
 
167
        break;
 
168
    }
 
169
    case MT_IFC_AUPAR:
 
170
    {
 
171
        M_ifc_aupar *X = (M_ifc_aupar *) M;
 
172
        if (X->_srcid != SRC_GUI_DRAG) _audiowin->set_aupar (X);
 
173
        break;
 
174
    }
 
175
    case MT_IFC_DIPAR:
 
176
    {
 
177
        M_ifc_dipar *X = (M_ifc_dipar *) M;
 
178
        if (X->_srcid != SRC_GUI_DRAG) _instrwin->set_dipar (X);
 
179
        break;
 
180
    }
 
181
    case MT_IFC_RETUNE:
 
182
        _instrwin->set_tuning ((M_ifc_retune *) M);
 
183
        break;
 
184
 
 
185
    case MT_IFC_EDIT:
 
186
        if (! _editp)
 
187
        {
 
188
            _editp = (M_ifc_edit *) M;
 
189
            _editwin->init (_editp->_synth);
 
190
            _editwin->x_mapraised ();
 
191
            M = 0;
 
192
        }  
 
193
        break;
 
194
 
 
195
    case MT_IFC_MCSET:
 
196
        _midiwin->setconf ((M_ifc_chconf *) M);
 
197
        break;
 
198
 
 
199
    default:
 
200
        ;
 
201
    }
 
202
    if (M) M->recover ();
 
203
}
 
204
 
 
205
 
 
206
void Xiface::handle_callb (int k, X_window *W, XEvent *E)
 
207
{
 
208
    switch (k)
 
209
    {
 
210
    case CB_SHOW_AUDW:
 
211
        _audiowin->x_mapraised ();
 
212
        break;
 
213
 
 
214
    case CB_SHOW_MIDW:
 
215
        _midiwin->x_mapraised ();
 
216
        break;
 
217
 
 
218
    case CB_SHOW_INSW:
 
219
        _instrwin->x_mapraised ();
 
220
        break;
 
221
 
 
222
    case CB_GLOB_SAVE:
 
223
        send_event (TO_MODEL, new ITC_mesg (MT_IFC_SAVE));
 
224
        break;
 
225
 
 
226
    case CB_GLOB_MOFF:
 
227
        send_event (TO_MODEL, new M_ifc_anoff (127));
 
228
        break;
 
229
 
 
230
    case CB_MAIN_MSG:
 
231
        send_event (TO_MODEL, _mainwin->mesg ());
 
232
        break;
 
233
 
 
234
    case CB_MAIN_END:
 
235
        stop ();
 
236
        break;
 
237
 
 
238
    case CB_AUDIO_ACT:
 
239
        if (_aupar) _aupar->_value = _audiowin->value ();
 
240
        else _aupar = new M_ifc_aupar (SRC_GUI_DRAG, _audiowin->asect (), _audiowin->parid (), _audiowin->value ());
 
241
        if (_audiowin->final ())
 
242
        {        
 
243
            _aupar->_srcid = SRC_GUI_DONE;
 
244
            send_event (TO_MODEL, _aupar);
 
245
            _aupar = 0;
 
246
        }
 
247
        break;
 
248
 
 
249
    case CB_DIVIS_ACT:
 
250
        if (_dipar) _dipar->_value = _instrwin->value ();
 
251
        else _dipar = new M_ifc_dipar (SRC_GUI_DRAG, _instrwin->divis (), _instrwin->parid (), _instrwin->value ());
 
252
        if (_instrwin->final ())
 
253
        {        
 
254
            _dipar->_srcid = SRC_GUI_DONE;
 
255
            send_event (TO_MODEL, _dipar);
 
256
            _dipar = 0;
 
257
        }
 
258
        break;
 
259
 
 
260
    case CB_RETUNE:
 
261
        send_event (TO_MODEL, new M_ifc_retune (_instrwin->freq (), _instrwin->temp ()));
 
262
        break;
 
263
 
 
264
    case CB_MIDI_SETCONF:
 
265
        send_event (TO_MODEL, new M_ifc_chconf (MT_IFC_MCSET, _midiwin->preset (), _midiwin->chconf ()));
 
266
        break;
 
267
 
 
268
    case CB_MIDI_GETCONF:
 
269
        send_event (TO_MODEL, new M_ifc_chconf (MT_IFC_MCGET, _midiwin->preset (), 0));
 
270
        break;
 
271
 
 
272
    case CB_EDIT_APP:
 
273
        send_event (TO_MODEL, new M_ifc_edit (MT_IFC_APPLY, _editp->_group, _editp->_ifelm, 0));
 
274
        _mainwin->set_label (_editp->_group, _editp->_ifelm, _editp->_synth->_stopname);
 
275
        _editwin->lock (true);
 
276
        break;
 
277
 
 
278
    case CB_EDIT_END:
 
279
        _editwin->x_unmap ();
 
280
        _editp->recover ();
 
281
        _editp = 0;
 
282
        break;
 
283
    }
 
284
}
 
285