2
Copyright (C) 2003-2008 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.
23
#include "midimatrix.h"
24
#include "callbacks.h"
30
Midimatrix::Midimatrix (X_window *parent, X_callback *callb, int xp, int yp) :
31
X_window (parent, xp, yp, 100, 100, Colors.midi_bg),
35
x_add_events (ExposureMask | ButtonPressMask | StructureNotifyMask);
36
x_set_bit_gravity (NorthWestGravity);
40
Midimatrix::~Midimatrix (void)
45
void Midimatrix::init (M_ifc_init *M)
51
for (i = 0; i < M->_nkeybd; i++)
53
_label [i] = M->_keybdd [i]._label;
54
_flags [i] = M->_keybdd [i]._flags;
56
for (i = 0; i < M->_ndivis; i++)
58
if (M->_divisd [i]._flags)
61
_label [_nkeybd + i] = M->_divisd [i]._label;
64
for (i = 0; i < 16; i++) _chconf [i] = 0;
65
_xs = XL + 16 * DX + XR;
66
_ys = YT + (_nkeybd + _ndivis + 1) * DY + YB;
72
void Midimatrix::set_chconf (uint16_t *d)
75
memcpy (_chconf, d, 16 * sizeof (uint16_t));
80
void Midimatrix::handle_event (XEvent *E)
93
expose ((XExposeEvent *) E);
97
bpress ((XButtonEvent *) E);
103
void Midimatrix::expose (XExposeEvent *E)
105
if (E->count) return;
110
void Midimatrix::redraw (void)
114
X_draw D (dpy (), win (), dgc (), xft ());
116
if (! _mapped) return;
119
D.setcolor (Colors.midi_gr1);
120
for (i = 0, x = XL + DX; i < 16; i++, x += DX)
123
D.draw (x, _ys - YT);
125
for (i = 0, y = YT; i <= _nkeybd + _ndivis + 1; i++, y += DY)
128
D.draw (_xs - XR, y);
130
D.setcolor (XftColors.midi_fg);
131
D.setfont (XftFonts.midimt);
132
d = (DY + D.textascent () - D.textdescent ()) / 2;
133
for (i = 0, y = YT; i < _nkeybd + _ndivis; i++, y += DY)
135
D.move (XL - 40, y + d);
136
D.drawstring (_label [i], 0);
140
for (i = 1; i <= 16; i++)
142
sprintf (s, "%d", i);
147
D.setcolor (Colors.midi_gr2);
149
D.rdraw (0, _ys - 2 * YT);
152
D.rdraw (_xs - 2 * XR, 0);
153
D.setcolor (XftColors.midi_fg);
155
D.drawstring ("Keyboards", -1);
157
D.setcolor (Colors.midi_gr2);
159
D.rdraw (_xs - 2 * XR, 0);
160
D.setcolor (XftColors.midi_fg);
162
D.drawstring ("Divisions", -1);
164
D.setcolor (Colors.midi_gr2);
166
D.rdraw (_xs - 2 * XR, 0);
167
D.setcolor (XftColors.midi_fg);
169
D.drawstring ("Control", -1);
171
D.setcolor (Colors.midi_gr2);
173
D.rdraw (_xs - 2 * XR, 0);
174
D.setcolor (Colors.midi_gr2);
176
D.rdraw (0, _ys - 1);
177
D.rdraw (1 - _xs, 0);
182
void Midimatrix::plot_allconn (void)
186
for (i = 0; i < 16; i++)
189
if (m & 0x1000) plot_conn (i, m & 7);
190
if (m & 0x2000) plot_conn (i, _nkeybd + ((m >> 8) & 7));
191
if (m & 0x4000) plot_conn (i, _nkeybd + _ndivis);
196
void Midimatrix::plot_conn (int x, int y)
198
X_draw D (dpy (), win (), dgc (), 0);
200
if (y < _nkeybd) D.setcolor (Colors.midi_bg ^ Colors.midi_co1);
201
else if (y < _nkeybd + _ndivis) D.setcolor (Colors.midi_bg ^ Colors.midi_co2);
202
else D.setcolor (Colors.midi_bg ^ Colors.midi_co3);
206
D.fillrect (x, y, x + DX - 9, y + DY - 9);
210
void Midimatrix::bpress (XButtonEvent *E)
212
unsigned int i, j, k, x, y;
214
i = (E->x - XL) / DX;
215
j = (E->y - YT) / DY;
216
x = E->x - XL - 4 - i * DX;
217
y = E->y - YT - 4 - j * DY;
218
if ((i > 15) || ((int) j > _nkeybd + _ndivis) || (x > DX - 2) || (y > DY - 2)) return;
221
if ((int) j < _nkeybd)
223
k = (_chconf [i] & 0x1000) ? (_chconf [i] & 7) : 8;
224
_chconf [i] &= 0x6700;
227
_chconf [i] |= 0x1000 | j;
228
if (k < 8) plot_conn (i, k);
232
else if ((int) j < _nkeybd + _ndivis)
235
k = (_chconf [i] & 0x2000) ? ((_chconf [i] >> 8) & 7) : 8;
236
_chconf [i] &= 0x5007;
239
_chconf [i] |= 0x2000 | (j << 8);
240
if (k < 8) plot_conn (i, k + _nkeybd);
242
plot_conn (i, j + _nkeybd);
246
_chconf [i] ^= 0x4000;
247
plot_conn (i, _nkeybd + _ndivis);
250
if (_callb) _callb->handle_callb (CB_MIDI_MODCONF, this, 0);