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

« back to all changes in this revision

Viewing changes to source/mainwin.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 "mainwin.h"
 
21
#include "messages.h"
 
22
#include "callbacks.h"
 
23
#include "styles.h"
 
24
 
 
25
 
 
26
Splashwin::Splashwin (X_window *parent, int xp, int yp) :
 
27
    X_window (parent, xp, yp, XSIZE, YSIZE, Colors.spla_bg, Colors.black, 2)
 
28
{
 
29
    x_add_events (ExposureMask); 
 
30
}
 
31
 
 
32
 
 
33
Splashwin::~Splashwin (void)
 
34
{
 
35
}
 
36
 
 
37
 
 
38
void Splashwin::handle_event (XEvent *E)
 
39
{
 
40
    switch (E->type)
 
41
    {
 
42
    case Expose:
 
43
        expose ((XExposeEvent *) E);
 
44
        break;  
 
45
    }
 
46
}
 
47
 
 
48
 
 
49
void Splashwin::expose (XExposeEvent *E)
 
50
{
 
51
    int     x, y;
 
52
    char    s [256];
 
53
    X_draw  D (dpy (), win (), dgc (), xft ());
 
54
 
 
55
    if (E->count) return;
 
56
    x = XSIZE / 2;
 
57
    y = YSIZE / 2;
 
58
 
 
59
    sprintf (s, "Aeolus-%s", VERSION);
 
60
    D.setfunc (GXcopy);
 
61
    D.setfont (XftFonts.spla1);
 
62
    D.setcolor (XftColors.spla_fg);
 
63
    D.move (x, y - 50);
 
64
    D.drawstring (s, 0); 
 
65
    D.setfont (XftFonts.spla2);
 
66
    D.move (x, y);
 
67
    D.drawstring ("(C) 2003-2010 Fons Adriaensen", 0); 
 
68
    D.move (x, y + 50);
 
69
    D.drawstring ("This is free software, and you are welcome to distribute it", 0); 
 
70
    D.move (x, y + 70);
 
71
    D.drawstring ("under certain conditions. See the file COPYING for details.", 0); 
 
72
}
 
73
 
 
74
 
 
75
 
 
76
Mainwin::Mainwin (X_window *parent, X_callback *callb, int xp, int yp, X_resman *xresm) :
 
77
    X_window (parent, xp, yp, 100, 100, Colors.main_bg),
 
78
    _callb (callb),
 
79
    _xresm (xresm),
 
80
    _count (0),
 
81
    _flashb (0),
 
82
    _local (false)
 
83
{
 
84
    int i;
 
85
 
 
86
    _atom = XInternAtom (dpy (), "WM_DELETE_WINDOW", True);
 
87
    XSetWMProtocols (dpy (), win (), &_atom, 1);
 
88
    _atom = XInternAtom (dpy (), "WM_PROTOCOLS", True);
 
89
    x_add_events (ExposureMask); 
 
90
    x_set_bit_gravity (NorthWestGravity);
 
91
 
 
92
    for (i = 0; i < NGROUP; i++)
 
93
    {
 
94
        _st_mod [i] = 0;
 
95
        _st_loc [i] = 0;
 
96
    }
 
97
}
 
98
 
 
99
 
 
100
Mainwin::~Mainwin (void)
 
101
{
 
102
}
 
103
 
 
104
 
 
105
void Mainwin::handle_event (XEvent *E)
 
106
{
 
107
    switch (E->type)
 
108
    {
 
109
    case Expose:
 
110
        expose ((XExposeEvent *) E);
 
111
        break;  
 
112
 
 
113
    case ClientMessage:
 
114
        xcmesg ((XClientMessageEvent *) E);
 
115
        break;
 
116
    }
 
117
}
 
118
 
 
119
 
 
120
void Mainwin::expose (XExposeEvent *E)
 
121
{
 
122
    int     g;
 
123
    Group   *G;
 
124
    X_draw  D (dpy (), win (), dgc (), xft ());
 
125
 
 
126
    if (E->count) return;
 
127
 
 
128
    D.setfont (XftFonts.large);
 
129
    D.setfunc (GXcopy);  
 
130
    for (g = 0; g < _ngroup; g++)
 
131
    {
 
132
        G = _groups + g; 
 
133
        D.move (10, G->_ylabel );
 
134
        D.setcolor (XftColors.main_fg);
 
135
        D.drawstring (G->_label, -1);
 
136
        D.setcolor (Colors.main_ls);
 
137
        D.move (15, G->_ydivid);
 
138
        D.rdraw (_xsize - 30, 0);     
 
139
        D.setcolor (Colors.main_ds);
 
140
        D.rmove (0, -1);
 
141
        D.rdraw (30 - _xsize, 0);     
 
142
    }
 
143
}
 
144
 
 
145
 
 
146
void Mainwin::xcmesg (XClientMessageEvent *E)
 
147
{
 
148
    _callb->handle_callb (CB_MAIN_END, 0, 0);
 
149
}
 
150
 
 
151
 
 
152
 
 
153
void Mainwin::handle_callb (int k, X_window *W, XEvent *E)
 
154
{
 
155
    int          g, i;
 
156
    X_button     *B;
 
157
    XButtonEvent *Z;
 
158
    char         s [24];
 
159
 
 
160
    if (k == (BUTTON | X_button::PRESS))
 
161
    {
 
162
        B = (X_button *) W;
 
163
        k = B->cbid ();
 
164
 
 
165
        if (k >= CB_GLOB_SAVE) _callb->handle_callb (k, this, E);
 
166
        else if (k < GROUP_STEP)
 
167
        {
 
168
            switch (k)
 
169
            {
 
170
            case B_DECB:
 
171
                if (_local) { if (_b_loc > 0) _b_loc--; }
 
172
                else        { if (_b_mod > 0) _b_mod--; }                
 
173
                upd_pres ();
 
174
                break;
 
175
 
 
176
            case B_INCB:
 
177
                if (_local) { if (_b_loc < NBANK - 1) _b_loc++; }
 
178
                else        { if (_b_mod < NBANK - 1) _b_mod++; }                
 
179
                upd_pres ();
 
180
                break;
 
181
 
 
182
            case B_DECM:
 
183
                if (_local) { if (_p_loc > 0) _p_loc--; }
 
184
                else        { if (_p_mod > 0) _p_mod--; }                
 
185
                upd_pres ();
 
186
                break;
 
187
 
 
188
            case B_INCM:
 
189
                if (_local) { if (_p_loc < NPRES - 1) _p_loc++; }
 
190
                else        { if (_p_mod < NPRES - 1) _p_mod++; }                
 
191
                upd_pres ();
 
192
                break;
 
193
 
 
194
            case B_MRCL:
 
195
                _mesg = new M_ifc_preset (MT_IFC_PRRCL, _b_mod, _p_mod, 0, 0);
 
196
                _callb->handle_callb (CB_MAIN_MSG, this, 0); 
 
197
                break;
 
198
 
 
199
            case B_PREV:
 
200
                _mesg = new ITC_mesg (MT_IFC_PRDEC);
 
201
                _callb->handle_callb (CB_MAIN_MSG, this, 0); 
 
202
                break;
 
203
 
 
204
            case B_NEXT:
 
205
                _mesg = new ITC_mesg (MT_IFC_PRINC);
 
206
                _callb->handle_callb (CB_MAIN_MSG, this, 0); 
 
207
                break;
 
208
 
 
209
            case B_MSTO:
 
210
                _mesg = new M_ifc_preset (MT_IFC_PRSTO, _b_mod, _p_mod, _ngroup, _st_mod);
 
211
                _callb->handle_callb (CB_MAIN_MSG, this, 0); 
 
212
                sprintf (s, "%d:%d  Stored", _b_mod + 1, _p_mod + 1);
 
213
                _t_comm->set_text (s); 
 
214
                break;
 
215
 
 
216
            case B_MINS:
 
217
                _mesg = new M_ifc_preset (MT_IFC_PRINS, _b_mod, _p_mod, _ngroup, _st_mod);
 
218
                _callb->handle_callb (CB_MAIN_MSG, this, 0); 
 
219
                sprintf (s, "%d:%d  Stored", _b_mod + 1, _p_mod + 1);
 
220
                _t_comm->set_text (s); 
 
221
                break;
 
222
 
 
223
            case B_MDEL:
 
224
                _mesg = new M_ifc_preset (MT_IFC_PRDEL, _b_mod, _p_mod, 0, 0);
 
225
                _callb->handle_callb (CB_MAIN_MSG, this, 0); 
 
226
                _t_comm->set_text (""); 
 
227
                break;
 
228
 
 
229
            case B_CANC:
 
230
                for (g = 0; g < _ngroup; g++)
 
231
                {
 
232
                    if (_local)
 
233
                    {
 
234
                        clr_group (_groups + g);
 
235
                        _st_loc [g] = 0;
 
236
                    }
 
237
                    else
 
238
                    {
 
239
                        _mesg = new M_ifc_ifelm (MT_IFC_GRCLR, g, 0);
 
240
                        _callb->handle_callb (CB_MAIN_MSG, this, 0);
 
241
                    } 
 
242
                }
 
243
                _t_comm->set_text (""); 
 
244
                break;
 
245
            } 
 
246
        }
 
247
        else
 
248
        {
 
249
            g = (k >> GROUP_BIT0) - 1;
 
250
            i = k & GROUP_MASK;
 
251
            if (_local)
 
252
            {
 
253
                if (B->stat ())
 
254
                {
 
255
                    B->set_stat (0);
 
256
                    _st_loc [g] &= ~(1 << i);
 
257
                }
 
258
                else
 
259
                {
 
260
                    B->set_stat (1);
 
261
                    _st_loc [g] |= (1 << i);
 
262
                }
 
263
            }
 
264
            else
 
265
            {
 
266
                Z = (XButtonEvent *) E;
 
267
                if (Z->state & ControlMask)
 
268
                {
 
269
                    _mesg = new M_ifc_edit (MT_IFC_EDIT, g, i, 0);
 
270
                    _callb->handle_callb (CB_MAIN_MSG, this, 0);
 
271
                }
 
272
                else
 
273
                {
 
274
                    if (Z->button == Button3)
 
275
                    {
 
276
                        _mesg = new M_ifc_ifelm (MT_IFC_GRCLR, g, 0);
 
277
                        _callb->handle_callb (CB_MAIN_MSG, this, 0);
 
278
                    }
 
279
                    _mesg = new M_ifc_ifelm (MT_IFC_ELXOR, g, i);
 
280
                    _callb->handle_callb (CB_MAIN_MSG, this, 0);
 
281
                }
 
282
            }
 
283
        }
 
284
    }
 
285
}
 
286
 
 
287
 
 
288
void Mainwin::handle_time (void)
 
289
{
 
290
    if (_count == 30) _splash->x_mapraised ();
 
291
    if (_count && ! --_count) _splash->x_unmap ();
 
292
    if (!_local && _flashb) _flashb->set_stat (_flashb->stat () ? 0 : 1);
 
293
}
 
294
 
 
295
 
 
296
void Mainwin::setup (M_ifc_init *M)
 
297
{
 
298
    int             g, i, x, y;
 
299
    Group           *G;
 
300
    X_button_style  *S;
 
301
    X_hints         H;
 
302
    char            s [256];
 
303
 
 
304
    _ngroup = M->_ngroup;
 
305
    y = 15;
 
306
    for (g = 0; g < _ngroup; g++)
 
307
    {
 
308
        G = _groups + g;
 
309
        G->_ylabel = y + 20;
 
310
        G->_label  = M->_groupd [g]._label;
 
311
        G->_nifelm = M->_groupd [g]._nifelm;
 
312
        x = 95;
 
313
        S = &ife0;
 
314
        for (i = 0; i < G->_nifelm; i++)
 
315
        {        
 
316
            switch (M->_groupd [g]._ifelmd [i]._type)
 
317
            {
 
318
            case 0: S = &ife0; break;
 
319
            case 1: S = &ife1; break;
 
320
            case 2: S = &ife2; break;
 
321
            case 3: S = &ife3; break;
 
322
            }
 
323
            if (i == 10) { x = 35; y += S->size.y + 4; }                
 
324
            if (i == 20) { x = 65; y += S->size.y + 4; }                
 
325
            G->_butt [i] = new X_tbutton (this, this, S, x, y, 0, 0, (g + 1) * GROUP_STEP + i);
 
326
            set_label (g, i, M->_groupd [g]._ifelmd [i]._label);
 
327
            G->_butt [i]->x_map ();              
 
328
            x += S->size.x + 4;             
 
329
        }
 
330
        y += S->size.y + 15;
 
331
        G->_ydivid = y;
 
332
        y += 15;    
 
333
    }
 
334
 
 
335
    x = _xsize = 990;
 
336
 
 
337
    but2.size.x = 17;
 
338
    but2.size.y = 17;
 
339
    add_text (15, y + 2,  60, 20, "Preset",   &text0);
 
340
    add_text (15, y + 24, 60, 20, "Bank",     &text0);
 
341
    (_t_pres = new X_textip  (this,    0, &text0, 80, y + 2,  40, 20,  7))->x_map ();
 
342
    (_t_bank = new X_textip  (this,    0, &text0, 80, y + 24, 40, 20,  7))->x_map ();
 
343
    (_b_decm = new X_ibutton (this, this, &but2, 125, y + 2,  disp ()->image1515 (X_display::IMG_LT), B_DECM))->x_map ();
 
344
    (_b_incm = new X_ibutton (this, this, &but2, 143, y + 2,  disp ()->image1515 (X_display::IMG_RT), B_INCM))->x_map ();
 
345
    (_b_decb = new X_ibutton (this, this, &but2, 125, y + 24, disp ()->image1515 (X_display::IMG_LT), B_DECB))->x_map ();
 
346
    (_b_incb = new X_ibutton (this, this, &but2, 143, y + 24, disp ()->image1515 (X_display::IMG_RT), B_INCB))->x_map ();
 
347
 
 
348
    but1.size.x = 80;
 
349
    but1.size.y = 20;
 
350
    (_b_mrcl = new X_tbutton (this, this, &but1, 244, y,      "Recall", 0, B_MRCL))->x_map ();
 
351
    (_b_prev = new X_tbutton (this, this, &but1, 328, y,      "Prev",   0, B_PREV))->x_map ();
 
352
    (_b_next = new X_tbutton (this, this, &but1, 412, y,      "Next",   0, B_NEXT))->x_map ();
 
353
    (_b_msto = new X_tbutton (this, this, &but1, 244, y + 25, "Store",  0, B_MSTO))->x_map ();
 
354
    (_b_mins = new X_tbutton (this, this, &but1, 328, y + 25, "Insert", 0, B_MINS))->x_map ();
 
355
    (_b_mdel = new X_tbutton (this, this, &but1, 412, y + 25, "Delete", 0, B_MDEL))->x_map ();
 
356
    (_b_canc = new X_tbutton (this, this, &but1, 532, y + 25, "Cancel", 0, B_CANC))->x_map ();
 
357
    (_b_save = new X_tbutton (this, this, &but1, x - 180, y,      "Save",     0, CB_GLOB_SAVE))->x_map ();
 
358
    (_b_moff = new X_tbutton (this, this, &but1, x -  96, y,      "Midi off", 0, CB_GLOB_MOFF))->x_map ();
 
359
    (_b_insw = new X_tbutton (this, this, &but1, x - 264, y + 25, "Instrum",  0, CB_SHOW_INSW))->x_map ();
 
360
    (_b_audw = new X_tbutton (this, this, &but1, x - 180, y + 25, "Audio",    0, CB_SHOW_AUDW))->x_map ();
 
361
    (_b_midw = new X_tbutton (this, this, &but1, x -  96, y + 25, "Midi",     0, CB_SHOW_MIDW))->x_map ();
 
362
    (_t_comm = new X_textip  (this,    0, &text0, 500, y, 160, 20, 15))->x_map ();
 
363
 
 
364
   _ysize = y + 55;
 
365
    if (_ysize < Splashwin::YSIZE + 20) _ysize = Splashwin::YSIZE + 20;
 
366
 
 
367
    H.position (100, 100);
 
368
    H.minsize (200, 100);
 
369
    H.maxsize (_xsize, _ysize);
 
370
    H.rname (_xresm->rname ());
 
371
    H.rclas (_xresm->rclas ());
 
372
    if (_xresm->getb (".iconic", 0)) H.state (IconicState);
 
373
    x_apply (&H); 
 
374
 
 
375
    sprintf (s, "%s   Aeolus-%s  [%d:%d]", M->_appid, VERSION, M->_client, M->_ipport);
 
376
    x_set_title (s);
 
377
    x_resize (_xsize, _ysize);
 
378
    _splash = new Splashwin (this, (_xsize - Splashwin::XSIZE) / 2, (_ysize - Splashwin::YSIZE) / 2); 
 
379
 
 
380
    _b_loc = _b_mod = 0;
 
381
    _p_loc = _p_mod = 0;
 
382
    upd_pres ();
 
383
 
 
384
    _count = 30;
 
385
    x_mapraised ();
 
386
}
 
387
 
 
388
 
 
389
void Mainwin::set_ifelm (M_ifc_ifelm *M)
 
390
{
 
391
    Group *G = _groups + M->_group;
 
392
 
 
393
    switch (M->type ())
 
394
    {
 
395
    case MT_IFC_GRCLR:
 
396
        _st_mod [M->_group] = 0;
 
397
        if (! _local) clr_group (G);
 
398
        _t_comm->set_text ("");
 
399
        break;
 
400
 
 
401
    case MT_IFC_ELCLR:
 
402
        _st_mod [M->_group] &= ~(1 << M->_ifelm);
 
403
        if (! _local) G->_butt [M->_ifelm]->set_stat (0);
 
404
        _t_comm->set_text ("");
 
405
        break;
 
406
 
 
407
    case MT_IFC_ELSET:
 
408
        _st_mod [M->_group] |= (1 << M->_ifelm);
 
409
        if (! _local) G->_butt [M->_ifelm]->set_stat (1);
 
410
        _t_comm->set_text ("");
 
411
        break;
 
412
 
 
413
    case MT_IFC_ELATT:
 
414
        if (!_local && _flashb) _flashb->set_stat ((_st_mod [_flashg] >> _flashi) & 1);
 
415
        _flashb = G->_butt [M->_ifelm]; 
 
416
        _flashg = M->_group;
 
417
        _flashi = M->_ifelm;
 
418
        break;
 
419
    }
 
420
}
 
421
 
 
422
 
 
423
void Mainwin::set_state (M_ifc_preset *M)
 
424
{
 
425
    char s [24];
 
426
  
 
427
    if (M->_stat)
 
428
    {
 
429
        memcpy (_st_mod, M->_bits, NGROUP * sizeof (uint32_t));
 
430
        sprintf (s, "%d:%d  Loaded", M->_bank + 1, M->_pres + 1);
 
431
        if (!_local) set_butt ();
 
432
    }
 
433
    else
 
434
    {
 
435
        sprintf (s, "%d:%d  Empty", M->_bank + 1, M->_pres + 1);
 
436
        _t_comm->set_text (s);
 
437
    }      
 
438
    _t_comm->set_text (s);
 
439
    _b_mod = M->_bank; 
 
440
    _p_mod = M->_pres; 
 
441
    if (!_local) upd_pres ();
 
442
}
 
443
 
 
444
 
 
445
void Mainwin::clr_group (Group *G)
 
446
{
 
447
    for (int i = 0; i < G->_nifelm; i++) G->_butt [i]->set_stat (0);
 
448
}
 
449
 
 
450
 
 
451
void Mainwin::set_ready (void)
 
452
{
 
453
    if (!_local && _flashb)
 
454
    {
 
455
        _flashb->set_stat ((_st_mod [_flashg] >> _flashi) & 1);
 
456
    }
 
457
    _flashb = 0;
 
458
}
 
459
 
 
460
 
 
461
void Mainwin::set_butt (void)
 
462
{
 
463
    int        g, i;
 
464
    uint32_t   b, *s;
 
465
    Group      *G;
 
466
 
 
467
    s = _local ? _st_loc : _st_mod;
 
468
    for (g = 0, G = _groups; g < _ngroup; g++, G++)
 
469
    {
 
470
        for (i = 0, b = *s++; i < G->_nifelm; i++, b >>= 1)
 
471
        {
 
472
            G->_butt [i]->set_stat (b & 1);
 
473
        }
 
474
    }
 
475
}
 
476
 
 
477
 
 
478
void Mainwin::upd_pres (void)
 
479
{
 
480
    char s [8];
 
481
 
 
482
    sprintf (s, "%d", (_local ? _b_loc : _b_mod) + 1);
 
483
    _t_bank->set_text (s);
 
484
    sprintf (s, "%d", (_local ? _p_loc : _p_mod) + 1);
 
485
    _t_pres->set_text (s);
 
486
}
 
487
 
 
488
 
 
489
void Mainwin::set_label (int group, int ifelm, const char *label)
 
490
{
 
491
    char p [32], *q;
 
492
 
 
493
    strcpy (p, label);
 
494
    q = strchr (p, '$');
 
495
    if (q) *q++ = 0; 
 
496
    _groups [group]._butt [ifelm]->set_text (p, q);
 
497
}
 
498
 
 
499
 
 
500
void Mainwin::add_text (int xp, int yp, int xs, int ys, const char *text, X_textln_style *style)
 
501
{
 
502
    (new X_textln (this, style, xp, yp, xs, ys, text, -1))->x_map ();
 
503
}