Menu

[729340]: / src / qsamplerDeviceStatusForm.cpp  Maximize  Restore  History

Download this file

268 lines (210 with data), 7.1 kB

  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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// qsamplerDeviceStatusForm.cpp
//
/****************************************************************************
Copyright (C) 2010-2020, rncbc aka Rui Nuno Capela. All rights reserved.
Copyright (C) 2008,2019 Christian Schoenebeck
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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
#include "qsamplerAbout.h"
#include "qsamplerDeviceStatusForm.h"
#include "qsamplerMainForm.h"
#include <QGridLayout>
#if QT_VERSION < QT_VERSION_CHECK(4, 5, 0)
namespace Qt {
const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);
}
#endif
namespace QSampler {
//-------------------------------------------------------------------------
// QSampler::MidiActivityLED -- Graphical indicator for MIDI activity.
//
// MIDI activity pixmap common resources.
int MidiActivityLED::g_iMidiActivityRefCount = 0;
QPixmap *MidiActivityLED::g_pMidiActivityLedOn = nullptr;
QPixmap *MidiActivityLED::g_pMidiActivityLedOff = nullptr;
MidiActivityLED::MidiActivityLED ( QString sText, QWidget *pParent )
: QLabel(sText, pParent)
{
if (++g_iMidiActivityRefCount == 1) {
g_pMidiActivityLedOn = new QPixmap(":/images/ledon1.png");
g_pMidiActivityLedOff = new QPixmap(":/images/ledoff1.png");
}
setPixmap(*g_pMidiActivityLedOff);
#ifndef CONFIG_EVENT_DEVICE_MIDI
setToolTip("MIDI Activity disabled");
#endif
m_timer.setSingleShot(true);
QObject::connect(&m_timer,
SIGNAL(timeout()),
SLOT(midiActivityLedOff())
);
}
MidiActivityLED::~MidiActivityLED (void)
{
if (--g_iMidiActivityRefCount == 0) {
if (g_pMidiActivityLedOn)
delete g_pMidiActivityLedOn;
g_pMidiActivityLedOn = nullptr;
if (g_pMidiActivityLedOff)
delete g_pMidiActivityLedOff;
g_pMidiActivityLedOff = nullptr;
}
}
void MidiActivityLED::midiActivityLedOn (void)
{
setPixmap(*g_pMidiActivityLedOn);
m_timer.start(100);
}
void MidiActivityLED::midiActivityLedOff (void)
{
setPixmap(*g_pMidiActivityLedOff);
}
//-------------------------------------------------------------------------
// QSampler::DeviceStatusForm -- Device status informations window.
//
std::map<int, DeviceStatusForm *> DeviceStatusForm::g_instances;
DeviceStatusForm::DeviceStatusForm (
int DeviceID, QWidget *pParent, Qt::WindowFlags wflags )
: QWidget(pParent, wflags)
{
m_pDevice = new Device(Device::Midi, DeviceID);
setLayout(new QGridLayout(/*this*/));
updateGUIPorts(); // build the GUI
m_pVisibleAction = new QAction(this);
m_pVisibleAction->setCheckable(true);
m_pVisibleAction->setChecked(false);
m_pVisibleAction->setText(m_pDevice->deviceName());
m_pVisibleAction->setToolTip(
QString("MIDI Device ID: ") +
QString::number(m_pDevice->deviceID())
);
QObject::connect(m_pVisibleAction,
SIGNAL(toggled(bool)),
SLOT(setVisible(bool))
);
setWindowTitle(tr("%1 Status").arg(m_pDevice->deviceName()));
}
void DeviceStatusForm::updateGUIPorts (void)
{
// refresh device informations
m_pDevice->setDevice(m_pDevice->deviceType(), m_pDevice->deviceID());
DevicePortList ports = m_pDevice->ports();
// clear the GUI
QGridLayout *pLayout = static_cast<QGridLayout *> (layout());
for (int i = pLayout->count() - 1; i >= 0; --i) {
QLayoutItem *pItem = pLayout->itemAt(i);
if (pItem) {
pLayout->removeItem(pItem);
if (pItem->widget())
delete pItem->widget();
delete pItem;
}
}
m_midiActivityLEDs.clear();
// rebuild the GUI
for (int i = 0; i < ports.size(); ++i) {
MidiActivityLED *pLED = new MidiActivityLED();
m_midiActivityLEDs.push_back(pLED);
pLayout->addWidget(pLED, i, 0);
QLabel *pLabel = new QLabel(
m_pDevice->deviceTypeName()
+ ' ' + m_pDevice->driverName()
+ ' ' + ports[i]->portName());
pLayout->addWidget(pLabel, i, 1, Qt::AlignLeft);
}
}
DeviceStatusForm::~DeviceStatusForm (void)
{
if (m_pDevice) delete m_pDevice;
}
QAction* DeviceStatusForm::visibleAction (void)
{
return m_pVisibleAction;
}
void DeviceStatusForm::closeEvent ( QCloseEvent *pCloseEvent )
{
m_pVisibleAction->setChecked(false);
pCloseEvent->accept();
}
void DeviceStatusForm::midiArrived ( int iPort )
{
if (uint(iPort) >= m_midiActivityLEDs.size())
return;
m_midiActivityLEDs[iPort]->midiActivityLedOn();
}
DeviceStatusForm *DeviceStatusForm::getInstance ( int iDeviceID )
{
std::map<int, DeviceStatusForm *>::iterator iter
= g_instances.find(iDeviceID);
return ((iter != g_instances.end()) ? iter->second : nullptr);
}
const std::map<int, DeviceStatusForm *>& DeviceStatusForm::getInstances (void)
{
return g_instances;
}
void DeviceStatusForm::deleteAllInstances (void)
{
std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
for ( ; iter != g_instances.end(); ++iter) {
iter->second->hide();
delete iter->second;
}
g_instances.clear();
}
void DeviceStatusForm::onDevicesChanged (void)
{
MainForm* pMainForm = MainForm::getInstance();
if (pMainForm && pMainForm->client()) {
std::set<int> deviceIDs
= Device::getDeviceIDs(pMainForm->client(), Device::Midi);
// hide and delete status forms whose device has been destroyed
std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
while (iter != g_instances.end()) {
if (deviceIDs.find(iter->first) == deviceIDs.end()) {
iter->second->hide();
delete iter->second;
// postfix increment here to avoid iterator invalidation (crash)
g_instances.erase(iter++);
} else ++iter;
}
// create status forms for new devices
std::set<int>::iterator it = deviceIDs.begin();
for ( ; it != deviceIDs.end(); ++it) {
if (g_instances.find(*it) == g_instances.end()) {
// What style do we create these forms?
Qt::WindowFlags wflags = Qt::Window
| Qt::CustomizeWindowHint
| Qt::WindowTitleHint
| Qt::WindowSystemMenuHint
| Qt::WindowMinMaxButtonsHint
| Qt::WindowCloseButtonHint;
Options *pOptions = pMainForm->options();
if (pOptions && pOptions->bKeepOnTop)
wflags |= Qt::Tool;
// Create the form, giving it the device id.
DeviceStatusForm *pStatusForm
= new DeviceStatusForm(*it, nullptr, wflags);
g_instances[*it] = pStatusForm;
}
}
}
}
void DeviceStatusForm::onDeviceChanged ( int iDeviceID )
{
DeviceStatusForm *pStatusForm
= DeviceStatusForm::getInstance(iDeviceID);
if (pStatusForm)
pStatusForm->updateGUIPorts();
}
} // namespace QSampler
// end of qsamplerDeviceStatusForm.cpp
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.