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

« back to all changes in this revision

Viewing changes to midimatrix.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-2008 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 <stdlib.h>
21
 
#include <stdio.h>
22
 
 
23
 
#include "midimatrix.h"
24
 
#include "callbacks.h"
25
 
#include "messages.h"
26
 
#include "styles.h"
27
 
 
28
 
 
29
 
 
30
 
Midimatrix::Midimatrix (X_window *parent, X_callback *callb, int xp, int yp) :
31
 
    X_window (parent, xp, yp, 100, 100, Colors.midi_bg),
32
 
    _callb (callb),
33
 
    _mapped (false)
34
 
{
35
 
    x_add_events (ExposureMask | ButtonPressMask | StructureNotifyMask);
36
 
    x_set_bit_gravity (NorthWestGravity);
37
 
}
38
 
 
39
 
 
40
 
Midimatrix::~Midimatrix (void)
41
 
{
42
 
}
43
 
 
44
 
 
45
 
void Midimatrix::init (M_ifc_init *M)
46
 
{
47
 
    int i;
48
 
 
49
 
    _nkeybd = M->_nkeybd;
50
 
    _ndivis = 0;
51
 
    for (i = 0; i < M->_nkeybd; i++)
52
 
    {
53
 
        _label [i] = M->_keybdd [i]._label;
54
 
        _flags [i] = M->_keybdd [i]._flags;    
55
 
    }
56
 
    for (i = 0; i < M->_ndivis; i++)
57
 
    {
58
 
        if (M->_divisd [i]._flags)
59
 
        {
60
 
            _ndivis++;
61
 
            _label [_nkeybd + i] = M->_divisd [i]._label;
62
 
        }
63
 
    }
64
 
    for (i = 0; i < 16; i++) _chconf [i] = 0;
65
 
    _xs = XL + 16 * DX + XR;
66
 
    _ys = YT + (_nkeybd + _ndivis + 1) * DY + YB;
67
 
    x_resize (_xs, _ys);
68
 
    x_map ();
69
 
}
70
 
 
71
 
 
72
 
void Midimatrix::set_chconf (uint16_t *d)
73
 
{
74
 
    plot_allconn ();
75
 
    memcpy (_chconf, d, 16 * sizeof (uint16_t));
76
 
    plot_allconn ();
77
 
}
78
 
 
79
 
 
80
 
void Midimatrix::handle_event (XEvent *E)
81
 
{
82
 
    switch (E->type)
83
 
    {
84
 
    case MapNotify:
85
 
        _mapped = true;
86
 
        break;
87
 
 
88
 
    case UnmapNotify:
89
 
        _mapped = false;
90
 
        break;
91
 
 
92
 
    case Expose:
93
 
        expose ((XExposeEvent *) E);
94
 
        break;  
95
 
 
96
 
    case ButtonPress:
97
 
        bpress ((XButtonEvent *) E);
98
 
        break;
99
 
    }
100
 
}
101
 
 
102
 
 
103
 
void Midimatrix::expose (XExposeEvent *E)
104
 
{
105
 
    if (E->count) return;
106
 
    redraw ();
107
 
}
108
 
 
109
 
 
110
 
void Midimatrix::redraw (void)
111
 
{
112
 
    int     i, x, y, d;
113
 
    char    s [4];
114
 
    X_draw  D (dpy (), win (), dgc (), xft ());
115
 
 
116
 
    if (! _mapped) return;
117
 
    D.clearwin ();
118
 
    D.setfunc (GXcopy);
119
 
    D.setcolor (Colors.midi_gr1);
120
 
    for (i = 0, x = XL + DX; i < 16; i++, x += DX)
121
 
    {
122
 
        D.move (x, YT);
123
 
        D.draw (x, _ys - YT);
124
 
    }
125
 
    for (i = 0, y = YT; i <= _nkeybd + _ndivis + 1; i++, y += DY)
126
 
    {
127
 
        D.move (0, y);
128
 
        D.draw (_xs - XR, y);
129
 
    }
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)
134
 
    {
135
 
        D.move (XL - 40, y + d);
136
 
        D.drawstring (_label [i], 0);
137
 
    }
138
 
    x = XL + DX / 2;
139
 
    y += DY;
140
 
    for (i = 1; i <= 16; i++)
141
 
    {
142
 
        sprintf (s, "%d", i);
143
 
        D.move (x, y + d);
144
 
        D.drawstring (s, 0);
145
 
        x += DX;
146
 
    } 
147
 
    D.setcolor (Colors.midi_gr2);
148
 
    D.move (XL, YT);
149
 
    D.rdraw (0, _ys - 2 * YT);
150
 
    y = YT;
151
 
    D.move (XR, y);
152
 
    D.rdraw (_xs - 2 * XR, 0);
153
 
    D.setcolor (XftColors.midi_fg);
154
 
    D.move (10, y + d);
155
 
    D.drawstring ("Keyboards", -1);
156
 
    y += _nkeybd * DY;
157
 
    D.setcolor (Colors.midi_gr2);
158
 
    D.move (XR, y);
159
 
    D.rdraw (_xs - 2 * XR, 0);
160
 
    D.setcolor (XftColors.midi_fg);
161
 
    D.move (10, y + d);
162
 
    D.drawstring ("Divisions", -1);
163
 
    y += _ndivis * DY;
164
 
    D.setcolor (Colors.midi_gr2);
165
 
    D.move (XR, y);
166
 
    D.rdraw (_xs - 2 * XR, 0);
167
 
    D.setcolor (XftColors.midi_fg);
168
 
    D.move (10, y + d);
169
 
    D.drawstring ("Control", -1);
170
 
    y += DY;
171
 
    D.setcolor (Colors.midi_gr2);
172
 
    D.move (XR, y);
173
 
    D.rdraw (_xs - 2 * XR, 0);
174
 
    D.setcolor (Colors.midi_gr2);
175
 
    D.move (_xs - 1, 0);
176
 
    D.rdraw (0, _ys - 1);
177
 
    D.rdraw (1 - _xs, 0);
178
 
    plot_allconn ();
179
 
}
180
 
 
181
 
 
182
 
void Midimatrix::plot_allconn (void)
183
 
{
184
 
    int i, m;
185
 
       
186
 
    for (i = 0; i < 16; i++)
187
 
    {
188
 
        m = _chconf [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);
192
 
    }       
193
 
}
194
 
 
195
 
 
196
 
void Midimatrix::plot_conn (int x, int y)
197
 
{
198
 
    X_draw D (dpy (), win (), dgc (), 0);
199
 
 
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);
203
 
    D.setfunc (GXxor);
204
 
    x = XL + x * DX + 5;
205
 
    y = YT + y * DY + 5;
206
 
    D.fillrect (x, y, x + DX - 9, y + DY - 9);
207
 
}    
208
 
 
209
 
 
210
 
void Midimatrix::bpress (XButtonEvent *E)
211
 
{
212
 
    unsigned int i, j, k, x, y;
213
 
 
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;
219
 
    _chan = i; 
220
 
 
221
 
    if ((int) j < _nkeybd)
222
 
    {
223
 
        k = (_chconf [i] & 0x1000) ? (_chconf [i] & 7) : 8;
224
 
        _chconf [i] &= 0x6700; 
225
 
        if (k != j)
226
 
        {
227
 
            _chconf [i] |= 0x1000 | j;
228
 
            if (k < 8) plot_conn (i, k);
229
 
        }
230
 
        plot_conn (i, j);
231
 
    }
232
 
    else if ((int) j < _nkeybd + _ndivis)
233
 
    {
234
 
        j -= _nkeybd;
235
 
        k = (_chconf [i] & 0x2000) ? ((_chconf [i] >> 8) & 7) : 8;
236
 
        _chconf [i] &= 0x5007; 
237
 
        if (k != j)
238
 
        {
239
 
            _chconf [i] |= 0x2000 | (j << 8);
240
 
            if (k < 8) plot_conn (i, k + _nkeybd);
241
 
        }
242
 
        plot_conn (i, j + _nkeybd);
243
 
    }
244
 
    else
245
 
    {
246
 
        _chconf [i] ^= 0x4000;
247
 
        plot_conn (i, _nkeybd + _ndivis);
248
 
    }
249
 
 
250
 
    if (_callb) _callb->handle_callb (CB_MIDI_MODCONF, this, 0);
251
 
}
252
 
 
253