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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 schoenebeck 1698 // qsamplerDeviceStatusForm.cpp
2     //
3     /****************************************************************************
4     Copyright (C) 2008, Christian Schoenebeck
5 capela 2038 Copyright (C) 2010, rncbc aka Rui Nuno Capela. All rights reserved.
6 schoenebeck 1698
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 capela 2038
26 schoenebeck 1698 #include "qsamplerMainForm.h"
27    
28     #include <QGridLayout>
29    
30    
31     namespace QSampler {
32    
33 schoenebeck 1699 //-------------------------------------------------------------------------
34     // QSampler::MidiActivityLED -- Graphical indicator for MIDI activity.
35     //
36    
37 capela 2038 // 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 schoenebeck 1698 #endif
55 capela 2038 m_timer.setSingleShot(true);
56    
57     QObject::connect(&m_timer,
58     SIGNAL(timeout()),
59     SLOT(midiActivityLedOff())
60 schoenebeck 1698 );
61     }
62    
63 capela 2038 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 schoenebeck 1698 }
74    
75 capela 2038
76     void MidiActivityLED::midiActivityLedOn (void)
77     {
78     setPixmap(*g_pMidiActivityLedOn);
79     m_timer.start(100);
80 schoenebeck 1698 }
81    
82 capela 2038
83     void MidiActivityLED::midiActivityLedOff (void)
84     {
85     setPixmap(*g_pMidiActivityLedOff);
86     }
87    
88    
89 schoenebeck 1699 //-------------------------------------------------------------------------
90     // QSampler::DeviceStatusForm -- Device status informations window.
91     //
92 schoenebeck 1698
93 capela 2038 std::map<int, DeviceStatusForm *> DeviceStatusForm::g_instances;
94 schoenebeck 1698
95 capela 2038
96 schoenebeck 1698 DeviceStatusForm::DeviceStatusForm (
97 capela 2038 int DeviceID, QWidget *pParent, Qt::WindowFlags wflags )
98     : QWidget(pParent, wflags)
99 schoenebeck 1698 {
100     m_pDevice = new Device(Device::Midi, DeviceID);
101    
102 capela 2038 setLayout(new QGridLayout(/*this*/));
103 schoenebeck 1699 updateGUIPorts(); // build the GUI
104 schoenebeck 1698
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 capela 2038
114     QObject::connect(m_pVisibleAction,
115     SIGNAL(toggled(bool)),
116     SLOT(setVisible(bool))
117 schoenebeck 1698 );
118    
119 capela 2038 setWindowTitle(tr("%1 Status").arg(m_pDevice->deviceName()));
120 schoenebeck 1698 }
121    
122 capela 2038
123     void DeviceStatusForm::updateGUIPorts (void)
124     {
125 schoenebeck 1699 // 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 capela 2038 QGridLayout *pLayout = static_cast<QGridLayout *> (layout());
131 schoenebeck 1699 for (int i = pLayout->count() - 1; i >= 0; --i) {
132 capela 2038 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 schoenebeck 1699 }
140    
141 capela 2038 m_midiActivityLEDs.clear();
142    
143 schoenebeck 1699 // rebuild the GUI
144     for (int i = 0; i < ports.size(); ++i) {
145 capela 2038 MidiActivityLED *pLED = new MidiActivityLED();
146     m_midiActivityLEDs.push_back(pLED);
147 capela 2039 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 schoenebeck 1699 }
154     }
155    
156 capela 2038
157     DeviceStatusForm::~DeviceStatusForm (void)
158     {
159 schoenebeck 1698 if (m_pDevice) delete m_pDevice;
160     }
161    
162 capela 2038
163     QAction* DeviceStatusForm::visibleAction (void)
164     {
165 schoenebeck 1698 return m_pVisibleAction;
166     }
167    
168 capela 2038 void DeviceStatusForm::closeEvent ( QCloseEvent *pCloseEvent )
169     {
170 schoenebeck 1698 m_pVisibleAction->setChecked(false);
171 capela 2038
172     pCloseEvent->accept();
173 schoenebeck 1698 }
174    
175 capela 2038
176     void DeviceStatusForm::midiArrived ( int iPort )
177     {
178     if (uint(iPort) >= m_midiActivityLEDs.size())
179     return;
180    
181     m_midiActivityLEDs[iPort]->midiActivityLedOn();
182 schoenebeck 1698 }
183    
184 capela 2038
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 schoenebeck 1698 }
191    
192 capela 2038
193     const std::map<int, DeviceStatusForm *>& DeviceStatusForm::getInstances (void)
194     {
195     return g_instances;
196 schoenebeck 1698 }
197    
198 capela 2038 void DeviceStatusForm::deleteAllInstances (void)
199     {
200     std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
201     for ( ; iter != g_instances.end(); ++iter) {
202 schoenebeck 1699 iter->second->hide();
203     delete iter->second;
204     }
205 capela 2038
206     g_instances.clear();
207 schoenebeck 1699 }
208    
209 capela 2038
210     void DeviceStatusForm::onDevicesChanged (void)
211     {
212 schoenebeck 1698 MainForm* pMainForm = MainForm::getInstance();
213     if (pMainForm && pMainForm->client()) {
214 capela 2038 std::set<int> deviceIDs
215     = Device::getDeviceIDs(pMainForm->client(), Device::Midi);
216 schoenebeck 1698 // hide and delete status forms whose device has been destroyed
217 capela 2038 std::map<int, DeviceStatusForm *>::iterator iter = g_instances.begin();
218     for ( ; iter != g_instances.end(); ++iter) {
219 schoenebeck 1698 if (deviceIDs.find(iter->first) == deviceIDs.end()) {
220     iter->second->hide();
221     delete iter->second;
222 capela 2038 g_instances.erase(iter);
223 schoenebeck 1698 }
224     }
225     // create status forms for new devices
226 capela 2038 std::set<int>::iterator it = deviceIDs.begin();
227 capela 2039 for ( ; it != deviceIDs.end(); ++it) {
228 capela 2038 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 schoenebeck 1698 }
244     }
245     }
246     }
247    
248 capela 2038
249     void DeviceStatusForm::onDeviceChanged ( int iDeviceID )
250     {
251     DeviceStatusForm *pStatusForm
252     = DeviceStatusForm::getInstance(iDeviceID);
253     if (pStatusForm)
254     pStatusForm->updateGUIPorts();
255 schoenebeck 1699 }
256    
257 capela 2038
258 schoenebeck 1698 } // namespace QSampler
259    
260     // end of qsamplerDeviceStatusForm.cpp

  ViewVC Help
Powered by ViewVC