2
Copyright (C) 2005-2006 Fons Adriaensen <fons.adriaensen@skynet.be>
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.
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.
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.
22
#include "callbacks.h"
26
Splashwin::Splashwin (X_window *parent, int xp, int yp) :
27
X_window (parent, xp, yp, XSIZE, YSIZE, Colors.spla_bg, Colors.black, 2)
29
x_add_events (ExposureMask);
33
Splashwin::~Splashwin (void)
38
void Splashwin::handle_event (XEvent *E)
43
expose ((XExposeEvent *) E);
49
void Splashwin::expose (XExposeEvent *E)
53
X_draw D (dpy (), win (), dgc (), xft ());
59
sprintf (s, "Aeolus-%s", VERSION);
61
D.setfont (XftFonts.spla1);
62
D.setcolor (XftColors.spla_fg);
65
D.setfont (XftFonts.spla2);
67
D.drawstring ("(C) 2005-2006 Fons Adriaensen", 0);
69
D.drawstring ("This is free software, and you are welcome to distribute it", 0);
71
D.drawstring ("under certain conditions. See the file COPYING for details.", 0);
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),
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);
92
Mainwin::~Mainwin (void)
97
void Mainwin::handle_event (XEvent *E)
102
expose ((XExposeEvent *) E);
106
xcmesg ((XClientMessageEvent *) E);
112
void Mainwin::expose (XExposeEvent *E)
116
X_draw D (dpy (), win (), dgc (), xft ());
118
if (E->count) return;
120
D.setfont (XftFonts.large);
122
for (g = 0; g < _ngroup; 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);
133
D.rdraw (30 - _xsize, 0);
138
void Mainwin::xcmesg (XClientMessageEvent *E)
140
_callb->handle_callb (CB_MAIN_END, 0, 0);
145
void Mainwin::handle_callb (int k, X_window *W, XEvent *E)
152
if (k == (BUTTON | X_button::PRESS))
157
if (k >= CB_GLOB_SAVE) _callb->handle_callb (k, this, E);
158
else if (k < GROUP_STEP)
163
if (_local) { if (_b_loc > 0) _b_loc--; }
164
else { if (_b_mod > 0) _b_mod--; }
169
if (_local) { if (_b_loc < NBANK - 1) _b_loc++; }
170
else { if (_b_mod < NBANK - 1) _b_mod++; }
175
if (_local) { if (_p_loc > 0) _p_loc--; }
176
else { if (_p_mod > 0) _p_mod--; }
181
if (_local) { if (_p_loc < NPRES - 1) _p_loc++; }
182
else { if (_p_mod < NPRES - 1) _p_mod++; }
187
_mesg = new M_ifc_preset (MT_IFC_PRRCL, _b_mod, _p_mod, 0, 0);
188
_callb->handle_callb (CB_MAIN_MSG, this, 0);
192
_mesg = new ITC_mesg (MT_IFC_PRDEC);
193
_callb->handle_callb (CB_MAIN_MSG, this, 0);
197
_mesg = new ITC_mesg (MT_IFC_PRINC);
198
_callb->handle_callb (CB_MAIN_MSG, this, 0);
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);
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);
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 ("");
222
for (g = 0; g < _ngroup; g++)
226
clr_group (_groups + g);
231
_mesg = new M_ifc_ifelm (MT_IFC_GRCLR, g, 0);
232
_callb->handle_callb (CB_MAIN_MSG, this, 0);
235
_t_comm->set_text ("");
241
g = (k >> GROUP_BIT0) - 1;
248
_st_loc [g] &= ~(1 << i);
253
_st_loc [g] |= (1 << i);
258
Z = (XButtonEvent *) E;
259
if (Z->state & ControlMask)
261
_mesg = new M_ifc_edit (MT_IFC_EDIT, g, i, 0);
262
_callb->handle_callb (CB_MAIN_MSG, this, 0);
266
if (Z->button == Button3)
268
_mesg = new M_ifc_ifelm (MT_IFC_GRCLR, g, 0);
269
_callb->handle_callb (CB_MAIN_MSG, this, 0);
271
_mesg = new M_ifc_ifelm (MT_IFC_ELXOR, g, i);
272
_callb->handle_callb (CB_MAIN_MSG, this, 0);
280
void Mainwin::handle_time (void)
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);
288
void Mainwin::setup (M_ifc_init *M)
296
_ngroup = M->_ngroup;
298
for (g = 0; g < _ngroup; g++)
302
G->_label = M->_groupd [g]._label;
303
G->_nifelm = M->_groupd [g]._nifelm;
306
for (i = 0; i < G->_nifelm; i++)
308
switch (M->_groupd [g]._ifelmd [i]._type)
310
case 0: S = &ife0; break;
311
case 1: S = &ife1; break;
312
case 2: S = &ife2; break;
313
case 3: S = &ife3; break;
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 ();
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 ();
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 ();
357
if (_ysize < Splashwin::YSIZE + 20) _ysize = Splashwin::YSIZE + 20;
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);
367
sprintf (s, "%s Aeolus-%s [%d:%d]", M->_appid, VERSION, M->_client, M->_ipport);
369
x_resize (_xsize, _ysize);
370
_splash = new Splashwin (this, (_xsize - Splashwin::XSIZE) / 2, (_ysize - Splashwin::YSIZE) / 2);
381
void Mainwin::set_ifelm (M_ifc_ifelm *M)
383
Group *G = _groups + M->_group;
388
_st_mod [M->_group] = 0;
389
if (! _local) clr_group (G);
390
_t_comm->set_text ("");
394
_st_mod [M->_group] &= ~(1 << M->_ifelm);
395
if (! _local) G->_butt [M->_ifelm]->set_stat (0);
396
_t_comm->set_text ("");
400
_st_mod [M->_group] |= (1 << M->_ifelm);
401
if (! _local) G->_butt [M->_ifelm]->set_stat (1);
402
_t_comm->set_text ("");
406
if (!_local && _flashb) _flashb->set_stat ((_st_mod [_flashg] >> _flashi) & 1);
407
_flashb = G->_butt [M->_ifelm];
415
void Mainwin::set_state (M_ifc_preset *M)
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 ();
427
sprintf (s, "%d:%d Empty", M->_bank + 1, M->_pres + 1);
428
_t_comm->set_text (s);
430
_t_comm->set_text (s);
433
if (!_local) upd_pres ();
437
void Mainwin::clr_group (Group *G)
439
for (int i = 0; i < G->_nifelm; i++) G->_butt [i]->set_stat (0);
443
void Mainwin::set_ready (void)
445
if (!_local && _flashb)
447
_flashb->set_stat ((_st_mod [_flashg] >> _flashi) & 1);
453
void Mainwin::set_butt (void)
459
s = _local ? _st_loc : _st_mod;
460
for (g = 0, G = _groups; g < _ngroup; g++, G++)
462
for (i = 0, b = *s++; i < G->_nifelm; i++, b >>= 1)
464
G->_butt [i]->set_stat (b & 1);
470
void Mainwin::upd_pres (void)
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);
481
void Mainwin::set_label (int group, int ifelm, const char *label)
488
_groups [group]._butt [ifelm]->set_text (p, q);
492
void Mainwin::add_text (int xp, int yp, int xs, int ys, const char *text, X_textln_style *style)
494
(new X_textln (this, style, xp, yp, xs, ys, text, -1))->x_map ();