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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2039 - (show annotations) (download)
Thu Jan 7 19:39:47 2010 UTC (14 years, 2 months ago) by capela
File size: 6857 byte(s)
- Fixing last fixes :)

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
31 namespace QSampler {
32
33 //-------------------------------------------------------------------------
34 // QSampler::MidiActivityLED -- Graphical indicator for MIDI activity.
35 //
36
37 // MIDI activity pixmap common resources.
38 int MidiActivityLED::g_iMidiActivityRefCount = 0;
39 QPixmap *MidiActivityLED::g_pMidiActivityLedOn = NULL;
40 QPixmap *MidiActivityLED::g_pMidiActivityLedOff = NULL;
41
42
43 MidiActivityLED::MidiActivityLED ( QString sText, QWidget *pParent )
44 : QLabel(sText, pParent)
45 {
46 if (++g_iMidiActivityRefCount == 1) {
47 g_pMidiActivityLedOn = new QPixmap(":/icons/ledon1.png");
48 g_pMidiActivityLedOff = new QPixmap(":/icons/ledoff1.png");
49 }
50
51 setPixmap(*g_pMidiActivityLedOff);
52 #ifndef CONFIG_EVENT_DEVICE_MIDI
53 setToolTip("MIDI Activity disabled");
54 #endif
55 m_timer.setSingleShot(true);
56
57 QObject::connect(&m_timer,
58 SIGNAL(timeout()),
59 SLOT(midiActivityLedOff())
60 );
61 }
62
63 MidiActivityLED::~MidiActivityLED (void)
64 {
65 if (--g_iMidiActivityRefCount == 0) {
66 if (g_pMidiActivityLedOn)
67 delete g_pMidiActivityLedOn;
68 g_pMidiActivityLedOn = NULL;
69 if (g_pMidiActivityLedOff)
70 delete g_pMidiActivityLedOff;
71 g_pMidiActivityLedOff = NULL;
72 }
73 }
74
75
76 void MidiActivityLED::midiActivityLedOn (void)
77 {
78 setPixmap(*g_pMidiActivityLedOn);
79 m_timer.start(100);
80 }
81
82
83 void MidiActivityLED::midiActivityLedOff (void)
84 {
85 setPixmap(*g_pMidiActivityLedOff);
86 }
87
88
89 //-------------------------------------------------------------------------
90 // QSampler::DeviceStatusForm -- Device status informations window.
91 //
92
93 std::map<int, DeviceStatusForm *> DeviceStatusForm::g_instances;
94
95
96 DeviceStatusForm::DeviceStatusForm (
97 int DeviceID, QWidget *pParent, Qt::WindowFlags wflags )
98 : QWidget(pParent, wflags)
99 {
100 m_pDevice = new Device(Device::Midi, DeviceID);
101
102 setLayout(new QGridLayout(/*this*/));
103 updateGUIPorts(); // build the GUI
104
105 m_pVisibleAction = new QAction(this);
106 m_pVisibleAction->setCheckable(true);
107 m_pVisibleAction->setChecked(false);
108 m_pVisibleAction->setText(m_pDevice->deviceName());
109 m_pVisibleAction->setToolTip(
110 QString("MIDI Device ID: ") +
111 QString::number(m_pDevice->deviceID())
112 );
113
114 QObject::connect(m_pVisibleAction,
115 SIGNAL(toggled(bool)),
116 SLOT(setVisible(bool))
117 );
118
119 setWindowTitle(tr("%1 Status").arg(m_pDevice->deviceName()));
120 }
121
122
123 void DeviceStatusForm::updateGUIPorts (void)
124 {
125 // refresh device informations
126 m_pDevice->setDevice(m_pDevice->deviceType(), m_pDevice->deviceID());
127 DevicePortList ports = m_pDevice->ports();
128
129 // clear the GUI
130 QGridLayout *pLayout = static_cast<QGridLayout *> (layout());
131 for (int i = pLayout->count() - 1; i >= 0; --i) {
132 QLayoutItem *pItem = pLayout->itemAt(i);
133 if (pItem) {
134 pLayout->removeItem(pItem);
135 if (pItem->widget())
136 delete pItem->widget();
137 delete pItem;
138 }
139 }
140
141 m_midiActivityLEDs.clear();
142
143 // rebuild the GUI
144 for (int i = 0; i < ports.size(); ++i) {
145 MidiActivityLED *pLED = new MidiActivityLED();
146 m_midiActivityLEDs.push_back(pLED);
147 pLayout->addWidget(pLED, i, 0);
148 QLabel *pLabel = new QLabel(
149 m_pDevice->deviceTypeName()
150 + ' ' + m_pDevice->driverName()
151 + ' ' + ports[i]->portName());
152 pLayout->addWidget(pLabel, i, 1, Qt::AlignLeft);
153 }
154 }
155
156
157 DeviceStatusForm::~DeviceStatusForm (void)
158 {
159 if (m_pDevice) delete m_pDevice;
160 }
161
162
163 QAction* DeviceStatusForm::visibleAction (void)
164 {
165 return m_pVisibleAction;
166 }
167
168 void DeviceStatusForm::closeEvent ( QCloseEvent *pCloseEvent )
169 {
170 m_pVisibleAction->setChecked(false);
171
172 pCloseEvent->accept();
173 }
174
175
176 void DeviceStatusForm::midiArrived ( int iPort )
177 {
178 if (uint(iPort) >= m_midiActivityLEDs.size())
179 return;
180
181 m_midiActivityLEDs[iPort]->midiActivityLedOn();
182 }
183
184
185 DeviceStatusForm *DeviceStatusForm::getInstance ( int iDeviceID )
186 {
187 std::map<int, DeviceStatusForm *>::iterator iter
188 = g_instances.find(iDeviceID);
189 return ((iter != g_instances.end()) ? iter->second : NULL);
190 }
191
192
193 const std::map<int, DeviceStatusForm *>& DeviceStatusForm::getInstances (void)
194 {
195 return g_instances;
196 }
197
198 void DeviceStatusForm::deleteAllInstances (void)
199 {
200 std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
201 for ( ; iter != g_instances.end(); ++iter) {
202 iter->second->hide();
203 delete iter->second;
204 }
205
206 g_instances.clear();
207 }
208
209
210 void DeviceStatusForm::onDevicesChanged (void)
211 {
212 MainForm* pMainForm = MainForm::getInstance();
213 if (pMainForm && pMainForm->client()) {
214 std::set<int> deviceIDs
215 = Device::getDeviceIDs(pMainForm->client(), Device::Midi);
216 // hide and delete status forms whose device has been destroyed
217 std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
218 for ( ; iter != g_instances.end(); ++iter) {
219 if (deviceIDs.find(iter->first) == deviceIDs.end()) {
220 iter->second->hide();
221 delete iter->second;
222 g_instances.erase(iter);
223 }
224 }
225 // create status forms for new devices
226 std::set<int>::iterator it = deviceIDs.begin();
227 for ( ; it != deviceIDs.end(); ++it) {
228 if (g_instances.find(*it) == g_instances.end()) {
229 // What style do we create these forms?
230 Qt::WindowFlags wflags = Qt::Window
231 | Qt::CustomizeWindowHint
232 | Qt::WindowTitleHint
233 | Qt::WindowSystemMenuHint
234 | Qt::WindowMinMaxButtonsHint
235 | Qt::WindowCloseButtonHint;
236 Options *pOptions = pMainForm->options();
237 if (pOptions && pOptions->bKeepOnTop)
238 wflags |= Qt::Tool;
239 // Create the form, giving it the device id.
240 DeviceStatusForm *pStatusForm
241 = new DeviceStatusForm(*it, NULL, wflags);
242 g_instances[*it] = pStatusForm;
243 }
244 }
245 }
246 }
247
248
249 void DeviceStatusForm::onDeviceChanged ( int iDeviceID )
250 {
251 DeviceStatusForm *pStatusForm
252 = DeviceStatusForm::getInstance(iDeviceID);
253 if (pStatusForm)
254 pStatusForm->updateGUIPorts();
255 }
256
257
258 } // namespace QSampler
259
260 // end of qsamplerDeviceStatusForm.cpp

  ViewVC Help
Powered by ViewVC