1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/**************************************************************************
channel.cpp - The KMidChannel widget (with pure virtual members)
Copyright (C) 1998 Antonio Larrosa Jimenez
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Send comments and bug fixes to larrosa@kde.org
or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <qpainter.h>
#include <qcombobox.h>
#include <kglobal.h>
#include <kinstance.h>
#include <kconfig.h>
#include <klocale.h>
#include <kstandarddirs.h>
#include "kmidbutton.h"
#include "channel.h"
#include "instrname.h"
#include <kiconloader.h>
KMidChannel::KMidChannel(int chn,QWidget *parent) : QWidget (parent)
{
channel=chn;
replay=TRUE;
int i;
for (i=0;i<128;i++) pressed[i]=0;
keyboard = QPixmap(locate("appdata","icons/keyboard.xpm"));
penB = new QPen (black);
penW = new QPen (white);
penT = new QPen (colorGroup().background());
KConfig *kcfg=KGlobal::instance()->config();
kcfg->setGroup("KMid");
QFont *qtextfontdefault=new QFont("lucida",18,QFont::Bold,TRUE);
qcvfont=new QFont(kcfg->readFontEntry("ChannelViewFont",qtextfontdefault));
delete qtextfontdefault;
instrumentCombo = new QComboBox(FALSE,this,"instr");
instrumentCombo->setGeometry(160,2,200,20);
for (i=0;i<128;i++)
instrumentCombo->insertItem(i18n(instrumentName[i]),i);
connect(instrumentCombo,SIGNAL(activated(int)),this,SLOT(pgmChanged(int)));
forcepgm=new KMidButton(this,"forcepgm");
forcepgm->setGeometry(135,4,16,16);
forcepgm->setToggleButton(TRUE);
button1 = QPixmap(locate("appdata","icons/button1.xpm"));
button2 = QPixmap(locate("appdata","icons/button2.xpm"));
forcepgm->setPixmaps(button1,button2);
forcepgm->show();
connect(forcepgm,SIGNAL(toggled(bool)),this,SLOT(changeForcedState(bool)));
}
KMidChannel::~KMidChannel()
{
delete penB;
delete penW;
delete penT;
}
void KMidChannel::paintEvent( QPaintEvent * )
{
QPainter *qpaint=new QPainter(this);
QString tmp = i18n("Channel %1").arg(channel);
qpaint->setFont(*qcvfont);
qpaint->setPen(*penB);
qpaint->drawText(2,20,tmp);
qpaint->setPen(*penW);
qpaint->drawText(0,18,tmp);
drawKeyboard(qpaint);
drawPressedKeys(qpaint);
delete qpaint;
}
void KMidChannel::drawKeyboard(QPainter *qpaint)
{
int x=1;
for (int i=0;(i<12) && (x<width());i++,x+=63)
{
qpaint->drawPixmap(x,KEYBOARDY,keyboard);
};
qpaint->setPen(*penB);
qpaint->drawLine(0,KEYBOARDY,0,KEYBOARDY+44);
qpaint->setPen(*penT);
qpaint->drawLine(0,KEYBOARDY+45,x+63,KEYBOARDY+45);
}
void KMidChannel::drawPressedKeys(QPainter *qpaint)
{
for (int i=0;i<128;i++)
if (pressed[i]) drawKey(qpaint,i);
}
void KMidChannel::drawKey(QPainter *qpaint,int key)
{
int octave=key/12;
int note=key%12;
int x=octave*63+1;
switch (note)
{
case (0) : drawDo (qpaint,x,pressed[key]);break;
case (1) : drawDo__ (qpaint,x,pressed[key]);break;
case (2) : drawRe (qpaint,x,pressed[key]);break;
case (3) : drawRe__ (qpaint,x,pressed[key]);break;
case (4) : drawMi (qpaint,x,pressed[key]);break;
case (5) : drawFa (qpaint,x,pressed[key]);break;
case (6) : drawFa__ (qpaint,x,pressed[key]);break;
case (7) : drawSol (qpaint,x,pressed[key]);break;
case (8) : drawSol__(qpaint,x,pressed[key]);break;
case (9) : drawLa (qpaint,x,pressed[key]);break;
case (10) : drawLa__ (qpaint,x,pressed[key]);break;
case (11) : drawSi (qpaint,x,pressed[key]);break;
};
// qpaint->flush();
}
void KMidChannel::noteOn(int key)
{
pressed[key]=1;
QPainter *qpaint=new QPainter(this);
drawKey(qpaint,key);
delete qpaint;
}
void KMidChannel::noteOff(int key)
{
pressed[key]=0;
QPainter *qpaint=new QPainter(this);
drawKey(qpaint,key);
delete qpaint;
}
void KMidChannel::changeInstrument(int pgm)
{
instrumentCombo->setCurrentItem(pgm);
}
void KMidChannel::changeForceState(bool i)
{
replay=FALSE;
forcepgm->setOn(i);
replay=TRUE;
}
void KMidChannel::reset(int level)
{
for (int i=0;i<128;i++) pressed[i]=0;
if (level>=1)
{
instrumentCombo->setCurrentItem(0);
replay=FALSE;
forcepgm->setOn(FALSE);
replay=TRUE;
};
repaint(FALSE);
}
void KMidChannel::saveState(bool *p,int *pgm)
{
for (int i=0;i<128;i++) p[i]=pressed[i];
*pgm=instrumentCombo->currentItem();
}
void KMidChannel::loadState(bool *p,int *pgm)
{
for (int i=0;i<128;i++) pressed[i]=p[i];
instrumentCombo->setCurrentItem(*pgm);
repaint(FALSE);
}
void KMidChannel::pgmChanged(int i)
{
int data[4];
data[0]=CHN_CHANGE_PGM;
data[1]=channel;
data[2]=i;
data[3]=0;
replay=FALSE;
forcepgm->setOn(TRUE);
replay=TRUE;
emit signalToKMidClient(data);
}
void KMidChannel::changeForcedState(bool i)
{
int data[4];
data[0]=CHN_CHANGE_FORCED_STATE;
data[1]=channel;
data[2]=i;
data[3]=(replay)? 1 : 0;
emit signalToKMidClient(data);
}
#include "channel.moc"
|