2
Copyright (C) 2003-2010 Fons Adriaensen <fons@kokkinizita.net>
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) 2003-2010 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),
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);
92
for (i = 0; i < NGROUP; i++)
100
Mainwin::~Mainwin (void)
105
void Mainwin::handle_event (XEvent *E)
110
expose ((XExposeEvent *) E);
114
xcmesg ((XClientMessageEvent *) E);
120
void Mainwin::expose (XExposeEvent *E)
124
X_draw D (dpy (), win (), dgc (), xft ());
126
if (E->count) return;
128
D.setfont (XftFonts.large);
130
for (g = 0; g < _ngroup; 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);
141
D.rdraw (30 - _xsize, 0);
146
void Mainwin::xcmesg (XClientMessageEvent *E)
148
_callb->handle_callb (CB_MAIN_END, 0, 0);
153
void Mainwin::handle_callb (int k, X_window *W, XEvent *E)
160
if (k == (BUTTON | X_button::PRESS))
165
if (k >= CB_GLOB_SAVE) _callb->handle_callb (k, this, E);
166
else if (k < GROUP_STEP)
171
if (_local) { if (_b_loc > 0) _b_loc--; }
172
else { if (_b_mod > 0) _b_mod--; }
177
if (_local) { if (_b_loc < NBANK - 1) _b_loc++; }
178
else { if (_b_mod < NBANK - 1) _b_mod++; }
183
if (_local) { if (_p_loc > 0) _p_loc--; }
184
else { if (_p_mod > 0) _p_mod--; }
189
if (_local) { if (_p_loc < NPRES - 1) _p_loc++; }
190
else { if (_p_mod < NPRES - 1) _p_mod++; }
195
_mesg = new M_ifc_preset (MT_IFC_PRRCL, _b_mod, _p_mod, 0, 0);
196
_callb->handle_callb (CB_MAIN_MSG, this, 0);
200
_mesg = new ITC_mesg (MT_IFC_PRDEC);
201
_callb->handle_callb (CB_MAIN_MSG, this, 0);
205
_mesg = new ITC_mesg (MT_IFC_PRINC);
206
_callb->handle_callb (CB_MAIN_MSG, this, 0);
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);
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);
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 ("");
230
for (g = 0; g < _ngroup; g++)
234
clr_group (_groups + g);
239
_mesg = new M_ifc_ifelm (MT_IFC_GRCLR, g, 0);
240
_callb->handle_callb (CB_MAIN_MSG, this, 0);
243
_t_comm->set_text ("");
249
g = (k >> GROUP_BIT0) - 1;
256
_st_loc [g] &= ~(1 << i);
261
_st_loc [g] |= (1 << i);
266
Z = (XButtonEvent *) E;
267
if (Z->state & ControlMask)
269
_mesg = new M_ifc_edit (MT_IFC_EDIT, g, i, 0);
270
_callb->handle_callb (CB_MAIN_MSG, this, 0);
274
if (Z->button == Button3)
276
_mesg = new M_ifc_ifelm (MT_IFC_GRCLR, g, 0);
277
_callb->handle_callb (CB_MAIN_MSG, this, 0);
279
_mesg = new M_ifc_ifelm (MT_IFC_ELXOR, g, i);
280
_callb->handle_callb (CB_MAIN_MSG, this, 0);
288
void Mainwin::handle_time (void)
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);
296
void Mainwin::setup (M_ifc_init *M)
304
_ngroup = M->_ngroup;
306
for (g = 0; g < _ngroup; g++)
310
G->_label = M->_groupd [g]._label;
311
G->_nifelm = M->_groupd [g]._nifelm;
314
for (i = 0; i < G->_nifelm; i++)
316
switch (M->_groupd [g]._ifelmd [i]._type)
318
case 0: S = &ife0; break;
319
case 1: S = &ife1; break;
320
case 2: S = &ife2; break;
321
case 3: S = &ife3; break;
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 ();
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 ();
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 ();
365
if (_ysize < Splashwin::YSIZE + 20) _ysize = Splashwin::YSIZE + 20;
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);
375
sprintf (s, "%s Aeolus-%s [%d:%d]", M->_appid, VERSION, M->_client, M->_ipport);
377
x_resize (_xsize, _ysize);
378
_splash = new Splashwin (this, (_xsize - Splashwin::XSIZE) / 2, (_ysize - Splashwin::YSIZE) / 2);
389
void Mainwin::set_ifelm (M_ifc_ifelm *M)
391
Group *G = _groups + M->_group;
396
_st_mod [M->_group] = 0;
397
if (! _local) clr_group (G);
398
_t_comm->set_text ("");
402
_st_mod [M->_group] &= ~(1 << M->_ifelm);
403
if (! _local) G->_butt [M->_ifelm]->set_stat (0);
404
_t_comm->set_text ("");
408
_st_mod [M->_group] |= (1 << M->_ifelm);
409
if (! _local) G->_butt [M->_ifelm]->set_stat (1);
410
_t_comm->set_text ("");
414
if (!_local && _flashb) _flashb->set_stat ((_st_mod [_flashg] >> _flashi) & 1);
415
_flashb = G->_butt [M->_ifelm];
423
void Mainwin::set_state (M_ifc_preset *M)
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 ();
435
sprintf (s, "%d:%d Empty", M->_bank + 1, M->_pres + 1);
436
_t_comm->set_text (s);
438
_t_comm->set_text (s);
441
if (!_local) upd_pres ();
445
void Mainwin::clr_group (Group *G)
447
for (int i = 0; i < G->_nifelm; i++) G->_butt [i]->set_stat (0);
451
void Mainwin::set_ready (void)
453
if (!_local && _flashb)
455
_flashb->set_stat ((_st_mod [_flashg] >> _flashi) & 1);
461
void Mainwin::set_butt (void)
467
s = _local ? _st_loc : _st_mod;
468
for (g = 0, G = _groups; g < _ngroup; g++, G++)
470
for (i = 0, b = *s++; i < G->_nifelm; i++, b >>= 1)
472
G->_butt [i]->set_stat (b & 1);
478
void Mainwin::upd_pres (void)
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);
489
void Mainwin::set_label (int group, int ifelm, const char *label)
496
_groups [group]._butt [ifelm]->set_text (p, q);
500
void Mainwin::add_text (int xp, int yp, int xs, int ys, const char *text, X_textln_style *style)
502
(new X_textln (this, style, xp, yp, xs, ys, text, -1))->x_map ();