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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1716 - (show annotations) (download)
Tue Mar 11 16:01:44 2008 UTC (16 years, 1 month ago) by schoenebeck
File size: 5933 byte(s)
* fixed autoconf preprocessor macro bug regarding the new device status
  dialog

1 // qsamplerDeviceStatusForm.cpp
2 //
3 /****************************************************************************
4 Copyright (C) 2008, Christian Schoenebeck
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 *****************************************************************************/
21
22 #include "qsamplerAbout.h"
23 #include "qsamplerDeviceStatusForm.h"
24 #include "qsamplerMainForm.h"
25
26 #include <QGridLayout>
27
28 #define MIDI_OFF_COLOR Qt::darkGreen
29 #define MIDI_ON_COLOR Qt::green
30
31 namespace QSampler {
32
33 //-------------------------------------------------------------------------
34 // QSampler::MidiActivityLED -- Graphical indicator for MIDI activity.
35 //
36
37 MidiActivityLED::MidiActivityLED(QString text, QWidget* parent) : QLabel(text, parent) {
38 #if CONFIG_EVENT_DEVICE_MIDI
39 setPalette(MIDI_OFF_COLOR);
40 setAutoFillBackground(true);
41 #else
42 setText("X");
43 setToolTip("MIDI Activity Disabled\n(at compile time)");
44 #endif
45 timer.setSingleShot(true);
46 QObject::connect(
47 &timer, SIGNAL(timeout()),
48 this, SLOT(midiDataCeased())
49 );
50 }
51
52 void MidiActivityLED::midiDataArrived() {
53 #if CONFIG_EVENT_DEVICE_MIDI
54 setPalette(MIDI_ON_COLOR);
55 timer.start(50);
56 #endif
57 }
58
59 void MidiActivityLED::midiDataCeased() {
60 #if CONFIG_EVENT_DEVICE_MIDI
61 setPalette(MIDI_OFF_COLOR);
62 #endif
63 }
64
65 //-------------------------------------------------------------------------
66 // QSampler::DeviceStatusForm -- Device status informations window.
67 //
68
69 std::map<int, DeviceStatusForm*> DeviceStatusForm::instances;
70
71 DeviceStatusForm::DeviceStatusForm (
72 int DeviceID, QWidget* pParent, Qt::WindowFlags wflags )
73 : QMainWindow(pParent, wflags)
74 {
75 m_pDevice = new Device(Device::Midi, DeviceID);
76
77 if (!centralWidget()) setCentralWidget(new QWidget(this));
78
79 QGridLayout* pLayout = new QGridLayout(centralWidget());
80 centralWidget()->setLayout(pLayout);
81 updateGUIPorts(); // build the GUI
82
83 m_pVisibleAction = new QAction(this);
84 m_pVisibleAction->setCheckable(true);
85 m_pVisibleAction->setChecked(false);
86 m_pVisibleAction->setText(m_pDevice->deviceName());
87 m_pVisibleAction->setToolTip(
88 QString("MIDI Device ID: ") +
89 QString::number(m_pDevice->deviceID())
90 );
91 QObject::connect(
92 m_pVisibleAction, SIGNAL(toggled(bool)),
93 this, SLOT(setVisible(bool))
94 );
95
96 setWindowTitle(m_pDevice->deviceName() + " Status");
97 }
98
99 void DeviceStatusForm::updateGUIPorts() {
100 // refresh device informations
101 m_pDevice->setDevice(m_pDevice->deviceType(), m_pDevice->deviceID());
102 DevicePortList ports = m_pDevice->ports();
103
104 // clear the GUI
105 QGridLayout* pLayout = (QGridLayout*) centralWidget()->layout();
106 for (int i = pLayout->count() - 1; i >= 0; --i) {
107 QLayoutItem* pItem = pLayout->itemAt(i);
108 if (!pItem) continue;
109 pLayout->removeItem(pItem);
110 if (pItem->widget()) delete pItem->widget();
111 delete pItem;
112 }
113 midiActivityLEDs.clear();
114
115 // rebuild the GUI
116 for (int i = 0; i < ports.size(); ++i) {
117 QLabel* pLabel =
118 new QLabel(QString("MIDI port \"") + ports[i]->portName() + "\": ");
119 pLabel->setToolTip(QString("Device ID ") + QString::number(ports[i]->portID()));
120 pLayout->addWidget(pLabel, i, 0, Qt::AlignLeft);
121 MidiActivityLED* pLED = new MidiActivityLED();
122 midiActivityLEDs.push_back(pLED);
123 pLayout->addWidget(pLED, i, 1);
124 }
125 }
126
127 DeviceStatusForm::~DeviceStatusForm() {
128 if (m_pDevice) delete m_pDevice;
129 }
130
131 QAction* DeviceStatusForm::visibleAction() {
132 return m_pVisibleAction;
133 }
134
135 void DeviceStatusForm::closeEvent(QCloseEvent* event) {
136 m_pVisibleAction->setChecked(false);
137 event->accept();
138 }
139
140 void DeviceStatusForm::midiArrived(int iPort) {
141 if (uint(iPort) >= midiActivityLEDs.size()) return;
142 midiActivityLEDs[iPort]->midiDataArrived();
143 }
144
145 DeviceStatusForm* DeviceStatusForm::getInstance(int iDeviceID) {
146 std::map<int, DeviceStatusForm*>::iterator iter =
147 instances.find(iDeviceID);
148 return (iter != instances.end()) ? iter->second : NULL;
149 }
150
151 const std::map<int, DeviceStatusForm*>& DeviceStatusForm::getInstances() {
152 return instances;
153 }
154
155 void DeviceStatusForm::deleteAllInstances() {
156 for (
157 std::map<int, DeviceStatusForm*>::iterator iter = instances.begin();
158 iter != instances.end(); ++iter
159 ) {
160 iter->second->hide();
161 delete iter->second;
162 }
163 instances.clear();
164 }
165
166 void DeviceStatusForm::onDevicesChanged() {
167 MainForm* pMainForm = MainForm::getInstance();
168 if (pMainForm && pMainForm->client()) {
169 std::set<int> deviceIDs =
170 Device::getDeviceIDs(pMainForm->client(), Device::Midi);
171 // hide and delete status forms whose device has been destroyed
172 for (
173 std::map<int, DeviceStatusForm*>::iterator iter = instances.begin();
174 iter != instances.end(); ++iter
175 ) {
176 if (deviceIDs.find(iter->first) == deviceIDs.end()) {
177 iter->second->hide();
178 delete iter->second;
179 instances.erase(iter);
180 }
181 }
182 // create status forms for new devices
183 for (
184 std::set<int>::iterator iter = deviceIDs.begin();
185 iter != deviceIDs.end(); ++iter
186 ) {
187 if (instances.find(*iter) == instances.end()) {
188 DeviceStatusForm* pStatusForm =
189 new DeviceStatusForm(*iter);
190 instances[*iter] = pStatusForm;
191 }
192 }
193 }
194 }
195
196 void DeviceStatusForm::onDeviceChanged(int iDeviceID) {
197 DeviceStatusForm* pForm = DeviceStatusForm::getInstance(iDeviceID);
198 if (!pForm) return;
199 pForm->updateGUIPorts();
200 }
201
202 } // namespace QSampler
203
204 // end of qsamplerDeviceStatusForm.cpp

  ViewVC Help
Powered by ViewVC