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
|
#include <cstdio>
#include <QCheckBox>
#include <QPushButton>
#include <QComboBox>
#include "qmpchannelswindow.hpp"
#include "ui_qmpchannelswindow.h"
#include "qmpmainwindow.hpp"
qmpChannelsWindow::qmpChannelsWindow(QWidget *parent) :
QDialog(parent),
ui(new Ui::qmpChannelsWindow)
{
ui->setupUi(this);
pselectw=new qmpPresetSelector(this);
ceditw=new qmpChannelEditor(this);
connect(this,SIGNAL(dialogClosing()),parent,SLOT(dialogClosed()));
mapper=qmpMainWindow::getInstance()->getPlayer()->getMidiMapper();
cha=new QPixmap(":/img/ledon.png");chi=new QPixmap(":/img/ledoff.png");
cb=new qmpCWNoteOnCB();fused=callbacksc=cbcnt=0;
qmpMainWindow::getInstance()->getPlayer()->setNoteOnCallBack(cb,NULL);
connect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity()));
int devc=mapper->enumDevices();
//We setup default output here...
//Pretty strange...
for(int i=0;i<devc;++i)
{
qmpSettingsWindow::getDefaultOutWidget()->addItem(mapper->deviceName(i).c_str());
if(!QString(mapper->deviceName(i).c_str()).compare(qmpSettingsWindow::getSettingsIntf()->
value("Midi/DefaultOutput","Internal FluidSynth").toString()))
qmpSettingsWindow::getDefaultOutWidget()->setCurrentIndex(i+1);
}
qmpSettingsWindow::getSettingsIntf()->setValue("Midi/DefaultOutput",
qmpSettingsWindow::getDefaultOutWidget()->currentText());
qmpSettingsWindow::getSettingsIntf();
for(int i=0;i<16;++i)
{
ui->twChannels->setItem(i,0,new QTableWidgetItem());
ui->twChannels->item(i,0)->setIcon(*chi);
ui->twChannels->item(i,0)->setFlags(ui->twChannels->item(i,0)->flags()^Qt::ItemIsEditable);
ui->twChannels->setCellWidget(i,1,new QCheckBox(""));
connect(ui->twChannels->cellWidget(i,1),SIGNAL(stateChanged(int)),this,SLOT(channelMSChanged()));
ui->twChannels->setCellWidget(i,2,new QCheckBox(""));
connect(ui->twChannels->cellWidget(i,2),SIGNAL(stateChanged(int)),this,SLOT(channelMSChanged()));
ui->twChannels->setCellWidget(i,3,new QDCComboBox());
QDCComboBox *cb=(QDCComboBox*)ui->twChannels->cellWidget(i,3);
cb->addItem("Internal FluidSynth");cb->setID(i);
for(int j=0;j<devc;++j)
{
cb->addItem(mapper->deviceName(j).c_str());
if(!qmpSettingsWindow::getSettingsIntf()->
value("Midi/DefaultOutput","Internal FluidSynth").toString().compare(
QString(mapper->deviceName(j).c_str())))
{
cb->setCurrentIndex(j+1);
changeMidiMapping(i,j+1);
}
}
if(qmpSettingsWindow::getSettingsIntf()->value("Midi/DisableMapping",0).toInt())
cb->setEnabled(false);
connect(cb,SIGNAL(onChange(int,int)),this,SLOT(changeMidiMapping(int,int)));
ui->twChannels->setCellWidget(i,4,new QDCLabel(""));
((QDCLabel*)ui->twChannels->cellWidget(i,4))->setID(i);
connect(ui->twChannels->cellWidget(i,4),SIGNAL(onDoubleClick(int)),this,SLOT(showPresetWindow(int)));
ui->twChannels->setCellWidget(i,5,new QDCPushButton("..."));
((QDCLabel*)ui->twChannels->cellWidget(i,5))->setID(i);
connect(ui->twChannels->cellWidget(i,5),SIGNAL(onClick(int)),this,SLOT(showChannelEditorWindow(int)));
}
ui->twChannels->setColumnWidth(0,24);
ui->twChannels->setColumnWidth(1,32);
ui->twChannels->setColumnWidth(2,32);
ui->twChannels->setColumnWidth(3,192);
ui->twChannels->setColumnWidth(4,192);
ui->twChannels->setColumnWidth(5,32);
}
void qmpChannelsWindow::showEvent(QShowEvent *event)
{
if(qmpSettingsWindow::getSettingsIntf()->value("Behavior/DialogStatus","").toInt())
{
qmpSettingsWindow::getSettingsIntf()->setValue("DialogStatus/ChnlWShown",1);
}
event->accept();
}
void qmpChannelsWindow::closeEvent(QCloseEvent *event)
{
setVisible(false);
if(!qmpMainWindow::getInstance()->isFinalizing()&&qmpSettingsWindow::getSettingsIntf()->value("Behavior/DialogStatus","").toInt())
{
qmpSettingsWindow::getSettingsIntf()->setValue("DialogStatus/ChnlWShown",0);
}
emit dialogClosing();
event->accept();
}
void qmpChannelsWindow::moveEvent(QMoveEvent *event)
{
if(qmpSettingsWindow::getSettingsIntf()->value("Behavior/DialogStatus","").toInt())
{
qmpSettingsWindow::getSettingsIntf()->setValue("DialogStatus/ChnlW",event->pos());
}
}
void qmpChannelsWindow::resetAcitivity()
{
for(int i=0;i<16;++i)ui->twChannels->item(i,0)->setIcon(*chi);
}
void qmpChannelsWindow::updateChannelActivity()
{
++callbacksc;
for(int i=0;i<16;++i)
ui->twChannels->item(i,0)->setIcon(
qmpMainWindow::getInstance()->getPlayer()->getChstates()[i]?*cha:*chi);
}
void qmpChannelsWindow::channelWindowsUpdate()
{
if(qmpMainWindow::getInstance()->getPlayer()->isFinished())
{
for(int i=0;i<16;++i)
((QLabel*)ui->twChannels->cellWidget(i,4))->setText("");
connect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity()));
fused=0;return;
}
++cbcnt;
if(cbcnt>15)
{
if(callbacksc>8192)
{
disconnect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity()));
fprintf(stderr,"Fuse!\n");fused=1;
}
cbcnt=0;
callbacksc=0;
}
for(int i=0;i<16;++i)
{
char data[128],nm[24];
int b,p;
qmpMainWindow::getInstance()->getPlayer()->getChannelPreset(i,&b,&p,nm);
sprintf(data,"%d:%d %s",b,p,nm);
if(fused)
{
if(strcmp(((QLabel*)ui->twChannels->cellWidget(i,4))->
text().toStdString().c_str(),data))
{
connect(cb,SIGNAL(onNoteOn()),this,SLOT(updateChannelActivity()));
fused=0;
}
}
((QLabel*)ui->twChannels->cellWidget(i,4))->setText(data);
ui->twChannels->item(i,0)->setIcon(
qmpMainWindow::getInstance()->getPlayer()->getChstates()[i]?*cha:*chi);
if(qmpMainWindow::getInstance()->getPlayer()->getChstates()[i])
qmpMainWindow::getInstance()->getPlayer()->getChstates()[i]=0;
}
}
void qmpChannelsWindow::channelMSChanged()
{
for(int i=0;i<16;++i)
{
QCheckBox *m,*s;
m=(QCheckBox*)ui->twChannels->cellWidget(i,1);
s=(QCheckBox*)ui->twChannels->cellWidget(i,2);
if(m->isChecked()&&s->isChecked())s->setChecked(false);
qmpMainWindow::getInstance()->getPlayer()->setMute(i,m->isChecked());
qmpMainWindow::getInstance()->getPlayer()->setSolo(i,s->isChecked());
}
}
qmpChannelsWindow::~qmpChannelsWindow()
{
delete chi;delete cha;
delete cb;delete ui;
}
void qmpChannelsWindow::on_pbUnmute_clicked()
{
for(int i=0;i<16;++i)
{
((QCheckBox*)ui->twChannels->cellWidget(i,1))->setChecked(false);
qmpMainWindow::getInstance()->getPlayer()->setMute(i,false);
}
}
void qmpChannelsWindow::on_pbUnsolo_clicked()
{
for(int i=0;i<16;++i)
{
((QCheckBox*)ui->twChannels->cellWidget(i,2))->setChecked(false);
qmpMainWindow::getInstance()->getPlayer()->setSolo(i,false);
}
}
void qmpChannelsWindow::showPresetWindow(int chid)
{
pselectw->show();
pselectw->setupWindow(chid);
}
void qmpChannelsWindow::showChannelEditorWindow(int chid)
{
ceditw->show();
ceditw->setupWindow(chid);
}
void qmpChannelsWindow::changeMidiMapping(int chid,int idx)
{
qmpMainWindow::getInstance()->getPlayer()->setChannelOutput(chid,idx);
}
|