~ubuntu-branches/ubuntu/intrepid/aeolus/intrepid

« back to all changes in this revision

Viewing changes to mainwin.cc

  • Committer: Bazaar Package Importer
  • Author(s): Free Ekanayaka
  • Date: 2007-05-14 22:18:54 UTC
  • Revision ID: james.westby@ubuntu.com-20070514221854-274rj6fqs5tegu7q
Tags: upstream-0.6.6+2
ImportĀ upstreamĀ versionĀ 0.6.6+2

Show diffs side-by-side

added added

removed removed

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