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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1698 - (show annotations) (download)
Sat Feb 16 19:41:05 2008 UTC (16 years, 2 months ago) by schoenebeck
File size: 4612 byte(s)
* implemented MIDI device activity windows, selectable from the "View"
  main menu, still quite ugly I admit ;-)
* bumped version to 0.2.1.7

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 MidiActivityLED::MidiActivityLED(QString text, QWidget* parent) : QLabel(text, parent) {
34 #if CONFIG_LSCP_DEVICE_MIDI
35 setPalette(MIDI_OFF_COLOR);
36 setAutoFillBackground(true);
37 #else
38 setText("X");
39 setTooltip("MIDI Activity Disabled");
40 #endif
41 timer.setSingleShot(true);
42 QObject::connect(
43 &timer, SIGNAL(timeout()),
44 this, SLOT(midiDataCeased())
45 );
46 }
47
48 void MidiActivityLED::midiDataArrived() {
49 setPalette(MIDI_ON_COLOR);
50 timer.start(50);
51 }
52
53 void MidiActivityLED::midiDataCeased() {
54 setPalette(MIDI_OFF_COLOR);
55 }
56
57
58 std::map<int, DeviceStatusForm*> DeviceStatusForm::instances;
59
60 DeviceStatusForm::DeviceStatusForm (
61 int DeviceID, QWidget* pParent, Qt::WindowFlags wflags )
62 : QMainWindow(pParent, wflags)
63 {
64 m_pDevice = new Device(Device::Midi, DeviceID);
65 DevicePortList ports = m_pDevice->ports();
66
67 if (!centralWidget()) setCentralWidget(new QWidget(this));
68
69 QGridLayout* pLayout = new QGridLayout(centralWidget());
70 for (int i = 0; i < ports.size(); ++i) {
71 QLabel* pLabel =
72 new QLabel(QString("MIDI port \"") + ports[i]->portName() + "\": ");
73 pLabel->setToolTip(QString("Device ID ") + QString::number(ports[i]->portID()));
74 pLayout->addWidget(pLabel, i, 0, Qt::AlignLeft);
75 MidiActivityLED* pLED = new MidiActivityLED();
76 midiActivityLEDs.push_back(pLED);
77 pLayout->addWidget(pLED, i, 1);
78 }
79 centralWidget()->setLayout(pLayout);
80
81 m_pVisibleAction = new QAction(this);
82 m_pVisibleAction->setCheckable(true);
83 m_pVisibleAction->setChecked(false);
84 m_pVisibleAction->setText(m_pDevice->deviceName());
85 m_pVisibleAction->setToolTip(
86 QString("MIDI Device ID: ") +
87 QString::number(m_pDevice->deviceID())
88 );
89 QObject::connect(
90 m_pVisibleAction, SIGNAL(toggled(bool)),
91 this, SLOT(setVisible(bool))
92 );
93
94 setWindowTitle(m_pDevice->deviceName() + " Status");
95 }
96
97 DeviceStatusForm::~DeviceStatusForm() {
98 if (m_pDevice) delete m_pDevice;
99 }
100
101 QAction* DeviceStatusForm::visibleAction() {
102 return m_pVisibleAction;
103 }
104
105 void DeviceStatusForm::closeEvent(QCloseEvent* event) {
106 m_pVisibleAction->setChecked(false);
107 event->accept();
108 }
109
110 void DeviceStatusForm::midiArrived(int iPort) {
111 if (uint(iPort) >= midiActivityLEDs.size()) return;
112 midiActivityLEDs[iPort]->midiDataArrived();
113 }
114
115 DeviceStatusForm* DeviceStatusForm::getInstance(int iDeviceID) {
116 std::map<int, DeviceStatusForm*>::iterator iter =
117 instances.find(iDeviceID);
118 return (iter != instances.end()) ? iter->second : NULL;
119 }
120
121 const std::map<int, DeviceStatusForm*>& DeviceStatusForm::getInstances() {
122 return instances;
123 }
124
125 void DeviceStatusForm::onDevicesChanged() {
126 MainForm* pMainForm = MainForm::getInstance();
127 if (pMainForm && pMainForm->client()) {
128 std::set<int> deviceIDs =
129 Device::getDeviceIDs(pMainForm->client(), Device::Midi);
130 // hide and delete status forms whose device has been destroyed
131 for (
132 std::map<int, DeviceStatusForm*>::iterator iter = instances.begin();
133 iter != instances.end(); ++iter
134 ) {
135 if (deviceIDs.find(iter->first) == deviceIDs.end()) {
136 iter->second->hide();
137 delete iter->second;
138 instances.erase(iter);
139 }
140 }
141 // create status forms for new devices
142 for (
143 std::set<int>::iterator iter = deviceIDs.begin();
144 iter != deviceIDs.end(); ++iter
145 ) {
146 if (instances.find(*iter) == instances.end()) {
147 DeviceStatusForm* pStatusForm =
148 new DeviceStatusForm(*iter, pMainForm);
149 instances[*iter] = pStatusForm;
150 }
151 }
152 }
153 }
154
155 } // namespace QSampler
156
157 // end of qsamplerDeviceStatusForm.cpp

  ViewVC Help
Powered by ViewVC