/[svn]/qsampler/trunk/src/qsamplerDeviceStatusForm.cpp
ViewVC logotype

Contents of /qsampler/trunk/src/qsamplerDeviceStatusForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2042 - (show annotations) (download)
Fri Jan 8 19:20:37 2010 UTC (10 years, 9 months ago) by capela
File size: 7075 byte(s)
- Fixed DeviceStatusForm compilation for Qt4 < 4.4.

1 // qsamplerDeviceStatusForm.cpp
2 //
3 /****************************************************************************
4 Copyright (C) 2008, Christian Schoenebeck
5 Copyright (C) 2010, rncbc aka Rui Nuno Capela. All rights reserved.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
21 *****************************************************************************/
22
23 #include "qsamplerAbout.h"
24 #include "qsamplerDeviceStatusForm.h"
25
26 #include "qsamplerMainForm.h"
27
28 #include <QGridLayout>
29
30 #if QT_VERSION < 0x040500
31 namespace Qt {
32 const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);
33 #if QT_VERSION < 0x040200
34 const WindowFlags CustomizeWindowHint = WindowFlags(0x02000000);
35 #endif
36 }
37 #endif
38
39
40 namespace QSampler {
41
42 //-------------------------------------------------------------------------
43 // QSampler::MidiActivityLED -- Graphical indicator for MIDI activity.
44 //
45
46 // MIDI activity pixmap common resources.
47 int MidiActivityLED::g_iMidiActivityRefCount = 0;
48 QPixmap *MidiActivityLED::g_pMidiActivityLedOn = NULL;
49 QPixmap *MidiActivityLED::g_pMidiActivityLedOff = NULL;
50
51
52 MidiActivityLED::MidiActivityLED ( QString sText, QWidget *pParent )
53 : QLabel(sText, pParent)
54 {
55 if (++g_iMidiActivityRefCount == 1) {
56 g_pMidiActivityLedOn = new QPixmap(":/icons/ledon1.png");
57 g_pMidiActivityLedOff = new QPixmap(":/icons/ledoff1.png");
58 }
59
60 setPixmap(*g_pMidiActivityLedOff);
61 #ifndef CONFIG_EVENT_DEVICE_MIDI
62 setToolTip("MIDI Activity disabled");
63 #endif
64 m_timer.setSingleShot(true);
65
66 QObject::connect(&m_timer,
67 SIGNAL(timeout()),
68 SLOT(midiActivityLedOff())
69 );
70 }
71
72 MidiActivityLED::~MidiActivityLED (void)
73 {
74 if (--g_iMidiActivityRefCount == 0) {
75 if (g_pMidiActivityLedOn)
76 delete g_pMidiActivityLedOn;
77 g_pMidiActivityLedOn = NULL;
78 if (g_pMidiActivityLedOff)
79 delete g_pMidiActivityLedOff;
80 g_pMidiActivityLedOff = NULL;
81 }
82 }
83
84
85 void MidiActivityLED::midiActivityLedOn (void)
86 {
87 setPixmap(*g_pMidiActivityLedOn);
88 m_timer.start(100);
89 }
90
91
92 void MidiActivityLED::midiActivityLedOff (void)
93 {
94 setPixmap(*g_pMidiActivityLedOff);
95 }
96
97
98 //-------------------------------------------------------------------------
99 // QSampler::DeviceStatusForm -- Device status informations window.
100 //
101
102 std::map<int, DeviceStatusForm *> DeviceStatusForm::g_instances;
103
104
105 DeviceStatusForm::DeviceStatusForm (
106 int DeviceID, QWidget *pParent, Qt::WindowFlags wflags )
107 : QWidget(pParent, wflags)
108 {
109 m_pDevice = new Device(Device::Midi, DeviceID);
110
111 setLayout(new QGridLayout(/*this*/));
112 updateGUIPorts(); // build the GUI
113
114 m_pVisibleAction = new QAction(this);
115 m_pVisibleAction->setCheckable(true);
116 m_pVisibleAction->setChecked(false);
117 m_pVisibleAction->setText(m_pDevice->deviceName());
118 m_pVisibleAction->setToolTip(
119 QString("MIDI Device ID: ") +
120 QString::number(m_pDevice->deviceID())
121 );
122
123 QObject::connect(m_pVisibleAction,
124 SIGNAL(toggled(bool)),
125 SLOT(setVisible(bool))
126 );
127
128 setWindowTitle(tr("%1 Status").arg(m_pDevice->deviceName()));
129 }
130
131
132 void DeviceStatusForm::updateGUIPorts (void)
133 {
134 // refresh device informations
135 m_pDevice->setDevice(m_pDevice->deviceType(), m_pDevice->deviceID());
136 DevicePortList ports = m_pDevice->ports();
137
138 // clear the GUI
139 QGridLayout *pLayout = static_cast<QGridLayout *> (layout());
140 for (int i = pLayout->count() - 1; i >= 0; --i) {
141 QLayoutItem *pItem = pLayout->itemAt(i);
142 if (pItem) {
143 pLayout->removeItem(pItem);
144 if (pItem->widget())
145 delete pItem->widget();
146 delete pItem;
147 }
148 }
149
150 m_midiActivityLEDs.clear();
151
152 // rebuild the GUI
153 for (int i = 0; i < ports.size(); ++i) {
154 MidiActivityLED *pLED = new MidiActivityLED();
155 m_midiActivityLEDs.push_back(pLED);
156 pLayout->addWidget(pLED, i, 0);
157 QLabel *pLabel = new QLabel(
158 m_pDevice->deviceTypeName()
159 + ' ' + m_pDevice->driverName()
160 + ' ' + ports[i]->portName());
161 pLayout->addWidget(pLabel, i, 1, Qt::AlignLeft);
162 }
163 }
164
165
166 DeviceStatusForm::~DeviceStatusForm (void)
167 {
168 if (m_pDevice) delete m_pDevice;
169 }
170
171
172 QAction* DeviceStatusForm::visibleAction (void)
173 {
174 return m_pVisibleAction;
175 }
176
177 void DeviceStatusForm::closeEvent ( QCloseEvent *pCloseEvent )
178 {
179 m_pVisibleAction->setChecked(false);
180
181 pCloseEvent->accept();
182 }
183
184
185 void DeviceStatusForm::midiArrived ( int iPort )
186 {
187 if (uint(iPort) >= m_midiActivityLEDs.size())
188 return;
189
190 m_midiActivityLEDs[iPort]->midiActivityLedOn();
191 }
192
193
194 DeviceStatusForm *DeviceStatusForm::getInstance ( int iDeviceID )
195 {
196 std::map<int, DeviceStatusForm *>::iterator iter
197 = g_instances.find(iDeviceID);
198 return ((iter != g_instances.end()) ? iter->second : NULL);
199 }
200
201
202 const std::map<int, DeviceStatusForm *>& DeviceStatusForm::getInstances (void)
203 {
204 return g_instances;
205 }
206
207 void DeviceStatusForm::deleteAllInstances (void)
208 {
209 std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
210 for ( ; iter != g_instances.end(); ++iter) {
211 iter->second->hide();
212 delete iter->second;
213 }
214
215 g_instances.clear();
216 }
217
218
219 void DeviceStatusForm::onDevicesChanged (void)
220 {
221 MainForm* pMainForm = MainForm::getInstance();
222 if (pMainForm && pMainForm->client()) {
223 std::set<int> deviceIDs
224 = Device::getDeviceIDs(pMainForm->client(), Device::Midi);
225 // hide and delete status forms whose device has been destroyed
226 std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
227 for ( ; iter != g_instances.end(); ++iter) {
228 if (deviceIDs.find(iter->first) == deviceIDs.end()) {
229 iter->second->hide();
230 delete iter->second;
231 g_instances.erase(iter);
232 }
233 }
234 // create status forms for new devices
235 std::set<int>::iterator it = deviceIDs.begin();
236 for ( ; it != deviceIDs.end(); ++it) {
237 if (g_instances.find(*it) == g_instances.end()) {
238 // What style do we create these forms?
239 Qt::WindowFlags wflags = Qt::Window
240 | Qt::CustomizeWindowHint
241 | Qt::WindowTitleHint
242 | Qt::WindowSystemMenuHint
243 | Qt::WindowMinMaxButtonsHint
244 | Qt::WindowCloseButtonHint;
245 Options *pOptions = pMainForm->options();
246 if (pOptions && pOptions->bKeepOnTop)
247 wflags |= Qt::Tool;
248 // Create the form, giving it the device id.
249 DeviceStatusForm *pStatusForm
250 = new DeviceStatusForm(*it, NULL, wflags);
251 g_instances[*it] = pStatusForm;
252 }
253 }
254 }
255 }
256
257
258 void DeviceStatusForm::onDeviceChanged ( int iDeviceID )
259 {
260 DeviceStatusForm *pStatusForm
261 = DeviceStatusForm::getInstance(iDeviceID);
262 if (pStatusForm)
263 pStatusForm->updateGUIPorts();
264 }
265
266
267 } // namespace QSampler
268
269 // end of qsamplerDeviceStatusForm.cpp

  ViewVC Help
Powered by ViewVC