1
/****************************************************************************
2
** $Id: table.cpp,v 1.8 2001/04/12 09:08:31 garbanzo Exp $
4
** Copyright (C) 1992-1999 Troll Tech AS. All rights reserved.
6
** This file is part of an example program for Qt. This example
7
** program may be used, distributed and modified without limitation.
9
*****************************************************************************/
11
#include <sys/types.h>
21
static const int NUMCOLS = 9;
22
static const int NUMROWS = 17;
25
Constructs a Table widget.
28
Table::Table( int width, int height, QWidget *parent, const char *name, WFlags f)
29
: QTableView(parent,name,f)
34
setFocusPolicy( NoFocus );
35
setBackgroundMode( PaletteBase ); // set widgets background
36
setNumCols( NUMCOLS ); // set number of col's in table
37
setNumRows( NUMROWS ); // set number of rows in table
38
setCellHeight( height/NUMROWS ); // set height of cell in pixels
44
for (n=3; n<8; n++) cell_width[n] = (width - (20+100+27+27)) / 5;
46
setTableFlags( Tbl_clipCellPainting ); // avoid drawing outside cell
47
resize( width, height ); // set default size in pixels
49
contents = new QString[ NUMROWS * NUMCOLS ]; // make room for contents
51
for (n=1; n<NUMROWS; n++) contents[indexOf( n, 0 )].setNum(n);
53
contents[indexOf(0,0)] = QString("C");
54
contents[indexOf(0,1)] = QString("Patch");
55
contents[indexOf(0,2)] = QString("Pr");
56
contents[indexOf(0,3)] = QString("Exp");
57
contents[indexOf(0,4)] = QString("Pan");
58
contents[indexOf(0,5)] = QString("Rev");
59
contents[indexOf(0,6)] = QString("Chor");
60
contents[indexOf(0,7)] = QString("Vol");
61
contents[indexOf(0,8)] = QString("Bank");
63
for (n=0; n<16; n++) {
67
t_reverberation[n] = 0;
75
Destructor: deallocates memory for contents
80
delete[] contents; // deallocation
83
int Table::cellWidth( int col )
85
return cell_width[col];
88
void Table::clearChannels( void )
91
for (chan = 1; chan < NUMROWS; chan++) {
92
contents[indexOf( chan, 1 )] = QString::null;
93
contents[indexOf( chan, 2 )] = QString::null;
94
contents[indexOf( chan, 3 )] = QString::null;
95
contents[indexOf( chan, 4 )] = QString::null;
96
contents[indexOf( chan, 5 )] = QString::null;
97
contents[indexOf( chan, 6 )] = QString::null;
98
contents[indexOf( chan, 7 )] = QString::null;
99
contents[indexOf( chan, 8 )] = QString::null;
100
t_expression[chan-1] = 0;
102
t_panning[chan-1] = 0;
103
t_reverberation[chan-1] = 0;
104
t_chorusdepth[chan-1] = 0;
105
t_volume[chan-1] = 0;
106
updateCell( chan, 1 );
107
updateCell( chan, 2 );
108
updateCell( chan, 3 );
109
updateCell( chan, 4 );
110
updateCell( chan, 5 );
111
updateCell( chan, 6 );
112
updateCell( chan, 7 );
113
updateCell( chan, 8 );
117
void Table::setProgram( int chan, int val, const char *inst, int bank, int variationbank )
119
if (chan < 0 || chan > 15) return;
121
contents[indexOf( chan, 1 )] = QString(inst);
122
contents[indexOf( chan, 2 )].setNum(val);
123
updateCell( chan, 1 );
124
updateCell( chan, 2 );
125
if (variationbank) contents[indexOf( chan, 8 )].setNum(variationbank);
126
else contents[indexOf( chan, 8 )].setNum(bank);
127
updateCell( chan, 8 );
131
void Table::setExpression( int chan, int val )
133
if (chan < 0 || chan > 15) return;
134
int wid = (cell_width[3]-8)*val/128;
136
contents[indexOf( chan+1, 3 )].setNum(wid);
137
t_expression[chan] = wid;
138
updateCell( chan+1, 3, false );
141
void Table::setPanning( int chan, int val )
143
if (chan < 0 || chan > 15) return;
144
int wid = (cell_width[4]/2 - 4)*(val - 64)/64;
145
contents[indexOf( chan+1, 4 )].setNum(wid);
146
t_panning[chan] = wid;
147
updateCell( chan+1, 4, false );
150
void Table::setReverberation( int chan, int val )
152
if (chan < 0 || chan > 15) return;
153
int wid = (cell_width[5]-8)*val/128;
154
contents[indexOf( chan+1, 5 )].setNum(wid);
155
t_reverberation[chan] = wid;
156
updateCell( chan+1, 5, false );
159
void Table::setChorusDepth( int chan, int val )
161
if (chan < 0 || chan > 15) return;
162
int wid = (cell_width[6]-8)*val/128;
163
contents[indexOf( chan+1, 6 )].setNum(wid);
164
t_chorusdepth[chan] = wid;
165
updateCell( chan+1, 6, false );
168
void Table::setVolume( int chan, int val )
170
if (chan < 0 || chan > 15) return;
171
int wid = (cell_width[7]-8)*val/128;
172
contents[indexOf( chan+1, 7 )].setNum(wid);
173
t_volume[chan] = wid;
174
updateCell( chan+1, 7, false );
178
Return content of cell
181
QString Table::cellContent( int row, int col ) const
183
return contents[indexOf( row, col )]; // contents array lookup
191
void Table::setCellContent( int row, int col, const char* c )
193
contents[indexOf( row, col )] = c; // contents lookup and assign
194
updateCell( row, col ); // show new content
199
Handles cell painting for the Table widget.
202
void Table::paintCell( QPainter* p, int row, int col )
204
int w = cellWidth( col ); // width of cell in pixels
205
int h = cellHeight( row ); // height of cell in pixels
211
Draw our part of cell frame.
213
p->drawLine( x2, 0, x2, y2 ); // draw vertical line on right
214
p->drawLine( 0, y2, x2, y2 ); // draw horiz. line at bottom
216
if (!row) p->drawLine( 0, 0, x2, 0 ); // horiz. at top
217
if (!col) p->drawLine( 0, 0, 0, y2 ); // vert. on left
220
Draw cell content (text)
223
if (row==0 || col==0 || col==2 || col==8)
224
p->drawText( 0, 0, w, h, AlignCenter, contents[indexOf(row,col)] );
227
p->drawText( 3, 0, w, h, AlignLeft, contents[indexOf(row,col)] );
230
int wid = t_expression[chan];
231
if (wid < w-8) p->fillRect(4+wid,4,w-8-wid,h-8, backgroundColor());
233
if (c_flags[chan] & FLAG_PERCUSSION)
234
p->fillRect(4,4,wid,h-8, QColor("yellow"));
235
else p->fillRect(4,4,wid,h-8, QColor("orange"));
239
int wid = t_panning[chan];
241
p->fillRect(4,4,(w-8)/2,h-8, backgroundColor());
242
if (wid < w/2-4) p->fillRect(w/2+wid,4,w/2-4-wid,h-8, backgroundColor());
243
p->fillRect(w/2,4,wid,h-8, QColor("green"));
246
p->fillRect(w/2,4,(w-8)/2,h-8, backgroundColor());
247
if (-wid < w/2-4) p->fillRect(4,4,w/2-4+wid,h-8, backgroundColor());
248
p->fillRect(w/2 + wid,4,-wid,h-8, QColor("blue"));
250
else p->fillRect(4,4,w-8,h-8, backgroundColor());
253
int wid = t_reverberation[chan];
254
if (wid < w-8) p->fillRect(4+wid,4,w-8-wid,h-8, backgroundColor());
256
p->fillRect(4,4,wid,h-8, QColor("SlateBlue2"));
260
int wid = t_chorusdepth[chan];
261
if (wid < w-8) p->fillRect(4+wid,4,w-8-wid,h-8, backgroundColor());
263
p->fillRect(4,4,wid,h-8, QColor("coral2"));
267
int wid = t_volume[chan];
268
if (wid < w-8) p->fillRect(4+wid,4,w-8-wid,h-8, backgroundColor());
270
if (c_flags[chan] & FLAG_PERCUSSION)
271
p->fillRect(4,4,wid,h-8, QColor("yellow"));
272
else p->fillRect(4,4,wid,h-8, QColor("white"));
278
Utility function for mapping from 2D table to 1D array
281
int Table::indexOf( int row, int col ) const
283
return (row * numCols()) + col;