/[svn]/qsampler/trunk/src/qsamplerDeviceForm.ui.h
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerDeviceForm.ui.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 484 - (hide annotations) (download) (as text)
Tue Mar 22 12:55:29 2005 UTC (19 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 13156 byte(s)
* Device management classes rearrangement for local messages support.

1 capela 426 // qsamplerDeviceForm.ui.h
2     //
3     // ui.h extension file, included from the uic-generated form implementation.
4     /****************************************************************************
5 capela 430 Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved.
6 capela 426
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 <qmessagebox.h>
24 capela 428 #include <qfiledialog.h>
25     #include <qfileinfo.h>
26 capela 430 #include <qlistbox.h>
27 capela 463 #include <qptrlist.h>
28 capela 452 #include <qpopupmenu.h>
29 capela 426
30     #include "qsamplerMainForm.h"
31    
32     #include "config.h"
33    
34    
35     // Kind of constructor.
36     void qsamplerDeviceForm::init (void)
37     {
38 capela 431 // Initialize locals.
39     m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget();
40     m_pClient = NULL;
41 capela 426 m_iDirtySetup = 0;
42 capela 431 m_bNewDevice = false;
43 capela 436 m_deviceType = qsamplerDevice::None;
44 capela 442 m_pAudioItems = NULL;
45     m_pMidiItems = NULL;
46 capela 426
47 capela 433 // This an outsider (from designer), but rather important.
48     QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),
49 capela 463 this, SLOT(changeDeviceParam(int,int)));
50     QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),
51     this, SLOT(changeDevicePortParam(int,int)));
52    
53 capela 467 // Initial contents.
54     refreshDevices();
55 capela 431 // Try to restore normal window positioning.
56     adjustSize();
57 capela 426 }
58    
59    
60     // Kind of destructor.
61     void qsamplerDeviceForm::destroy (void)
62     {
63     }
64    
65    
66 capela 428 // Notify our parent that we're emerging.
67     void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )
68     {
69 capela 431 if (m_pMainForm)
70     m_pMainForm->stabilizeForm();
71 capela 428
72 capela 431 stabilizeForm();
73 capela 428
74 capela 431 QWidget::showEvent(pShowEvent);
75 capela 428 }
76    
77    
78     // Notify our parent that we're closing.
79     void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )
80     {
81 capela 431 QWidget::hideEvent(pHideEvent);
82 capela 428
83 capela 431 if (m_pMainForm)
84     m_pMainForm->stabilizeForm();
85 capela 428 }
86    
87    
88 capela 426 // Device configuration dialog setup formal initializer.
89 capela 428 void qsamplerDeviceForm::setClient ( lscp_client_t *pClient )
90 capela 426 {
91 capela 428 // If it has not changed, do nothing.
92     if (m_pClient && m_pClient == pClient)
93 capela 431 return;
94 capela 426
95 capela 428 // Set new reference.
96     m_pClient = pClient;
97    
98     // OK. Do a whole refresh around.
99     refreshDevices();
100     }
101    
102    
103 capela 433 // Create a new device from current table view.
104     void qsamplerDeviceForm::createDevice (void)
105 capela 428 {
106 capela 433 QListViewItem *pItem = DeviceListView->selectedItem();
107     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
108     return;
109 capela 428
110 capela 484 // About a brand new device instance...
111     qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device());
112     if (device.createDevice()) {
113     // Now it depends on the device type...
114     qsamplerDeviceItem *pRootItem = NULL;
115     switch (device.deviceType()) {
116     case qsamplerDevice::Audio:
117     pRootItem = m_pAudioItems;
118     break;
119     case qsamplerDevice::Midi:
120     pRootItem = m_pMidiItems;
121     break;
122     case qsamplerDevice::None:
123     break;
124     }
125 capela 442 // Append the new device item.
126     qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem,
127 capela 484 m_pMainForm, device.deviceType(), device.deviceID());
128 capela 442 // Just make it the new selection...
129     DeviceListView->setSelected(pDeviceItem, true);
130 capela 433 // Main session should be marked dirty.
131     m_pMainForm->sessionDirty();
132     }
133 capela 428 }
134    
135    
136     // Delete current device in table view.
137     void qsamplerDeviceForm::deleteDevice (void)
138     {
139 capela 433 QListViewItem *pItem = DeviceListView->selectedItem();
140     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
141     return;
142    
143 capela 484 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
144 capela 433
145 capela 442 // Prompt user if this is for real...
146     qsamplerOptions *pOptions = m_pMainForm->options();
147 capela 448 if (pOptions && pOptions->bConfirmRemove) {
148     if (QMessageBox::warning(this, tr("Warning"),
149 capela 484 tr("Delete device:\n\n"
150     "%1\n\n"
151 capela 448 "Are you sure?")
152     .arg(device.deviceName()),
153     tr("OK"), tr("Cancel")) > 0)
154     return;
155     }
156 capela 442
157 capela 484 // Go and destroy...
158     if (device.deleteDevice()) {
159     // Remove it from the device view...
160 capela 442 delete pItem;
161 capela 433 // Main session should be marked dirty.
162     m_pMainForm->sessionDirty();
163     }
164 capela 428 }
165    
166    
167     // Refresh all device list and views.
168     void qsamplerDeviceForm::refreshDevices (void)
169     {
170 capela 431 // Avoid nested changes.
171     m_iDirtySetup++;
172 capela 428
173     //
174 capela 442 // (Re)Load complete device configuration data ...
175 capela 431 //
176 capela 442 m_pAudioItems = NULL;
177     m_pMidiItems = NULL;
178 capela 431 DeviceListView->clear();
179     if (m_pClient) {
180 capela 429 int *piDeviceIDs;
181 capela 430 // Grab and pop Audio devices...
182 capela 484 m_pAudioItems = new qsamplerDeviceItem(DeviceListView, m_pMainForm,
183 capela 429 qsamplerDevice::Audio);
184 capela 442 if (m_pAudioItems) {
185 capela 429 piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
186     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
187 capela 484 new qsamplerDeviceItem(m_pAudioItems, m_pMainForm,
188 capela 429 qsamplerDevice::Audio, piDeviceIDs[i]);
189     }
190 capela 442 m_pAudioItems->setOpen(true);
191 capela 428 }
192 capela 430 // Grab and pop MIDI devices...
193 capela 484 m_pMidiItems = new qsamplerDeviceItem(DeviceListView, m_pMainForm,
194 capela 429 qsamplerDevice::Midi);
195 capela 442 if (m_pMidiItems) {
196 capela 429 piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
197     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
198 capela 484 new qsamplerDeviceItem(m_pMidiItems, m_pMainForm,
199 capela 429 qsamplerDevice::Midi, piDeviceIDs[i]);
200     }
201 capela 442 m_pMidiItems->setOpen(true);
202 capela 429 }
203 capela 428 }
204    
205 capela 431 // Done.
206 capela 433 m_iDirtySetup--;
207 capela 436
208 capela 433 // Show something.
209 capela 431 selectDevice();
210 capela 428 }
211    
212 capela 430
213     // Driver selection slot.
214     void qsamplerDeviceForm::selectDriver ( const QString& sDriverName )
215     {
216 capela 433 if (m_iDirtySetup > 0)
217 capela 436 return;
218 capela 433
219 capela 430 //
220 capela 442 // Driver name has changed for a new device...
221 capela 430 //
222    
223 capela 431 QListViewItem *pItem = DeviceListView->selectedItem();
224     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
225     return;
226    
227     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
228 capela 436
229     // Driver change is only valid for scratch devices...
230 capela 431 if (m_bNewDevice) {
231 capela 442 m_iDirtySetup++;
232 capela 484 device.setDriver(sDriverName);
233 capela 462 DeviceParamTable->refresh(device.params(), m_bNewDevice);
234 capela 442 m_iDirtySetup--;
235 capela 436 // Done.
236     stabilizeForm();
237 capela 431 }
238 capela 430 }
239    
240    
241 capela 429 // Device selection slot.
242 capela 430 void qsamplerDeviceForm::selectDevice (void)
243 capela 429 {
244 capela 433 if (m_iDirtySetup > 0)
245 capela 436 return;
246 capela 433
247 capela 430 //
248 capela 442 // Device selection has changed...
249 capela 430 //
250 capela 428
251 capela 431 QListViewItem *pItem = DeviceListView->selectedItem();
252 capela 430 if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
253 capela 436 m_deviceType = qsamplerDevice::None;
254     DeviceNameTextLabel->setText(QString::null);
255     DeviceParamTable->setNumRows(0);
256 capela 468 DevicePortComboBox->clear();
257 capela 467 DevicePortParamTable->setNumRows(0);
258 capela 463 DevicePortComboBox->setEnabled(false);
259     DevicePortParamTable->setEnabled(false);
260 capela 430 stabilizeForm();
261     return;
262     }
263 capela 429
264 capela 431 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
265 capela 436
266 capela 463 m_iDirtySetup++;
267 capela 436 // Flag whether this is a new device.
268 capela 430 m_bNewDevice = (device.deviceID() < 0);
269    
270 capela 433 // Fill the device/driver heading...
271 capela 484 DeviceNameTextLabel->setText(device.deviceName());
272 capela 436 // The driver combobox is only rebuilt if device type has changed...
273     if (device.deviceType() != m_deviceType) {
274     DriverNameComboBox->clear();
275     DriverNameComboBox->insertStringList(
276     qsamplerDevice::getDrivers(m_pClient, device.deviceType()));
277     m_deviceType = device.deviceType();
278     }
279     // Do we need a driver name?
280     if (m_bNewDevice || device.driverName().isEmpty())
281 capela 484 device.setDriver(DriverNameComboBox->currentText());
282 capela 430 const QString& sDriverName = device.driverName();
283 capela 436 if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL)
284     DriverNameComboBox->insertItem(sDriverName);
285     DriverNameComboBox->setCurrentText(sDriverName);
286 capela 430 DriverNameTextLabel->setEnabled(m_bNewDevice);
287     DriverNameComboBox->setEnabled(m_bNewDevice);
288     // Fill the device parameter table...
289 capela 462 DeviceParamTable->refresh(device.params(), m_bNewDevice);
290 capela 463 // And now the device port/channel parameter table...
291     DevicePortComboBox->clear();
292     DevicePortParamTable->setNumRows(0);
293     if (m_bNewDevice) {
294     DevicePortComboBox->setEnabled(false);
295     DevicePortParamTable->setEnabled(false);
296     } else {
297     QPixmap pixmap;
298     switch (device.deviceType()) {
299     case qsamplerDevice::Audio:
300     pixmap = QPixmap::fromMimeSource("audio2.png");
301     break;
302     case qsamplerDevice::Midi:
303     pixmap = QPixmap::fromMimeSource("midi2.png");
304     break;
305     case qsamplerDevice::None:
306     break;
307     }
308     qsamplerDevicePortList& ports = device.ports();
309     qsamplerDevicePort *pPort;
310     for (pPort = ports.first(); pPort; pPort = ports.next()) {
311 capela 484 DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()
312     + ' ' + device.driverName()
313     + ' ' + pPort->portName());
314 capela 463 }
315     bool bEnabled = (ports.count() > 0);
316     DevicePortComboBox->setEnabled(bEnabled);
317     DevicePortParamTable->setEnabled(bEnabled);
318     }
319 capela 430 // Done.
320 capela 442 m_iDirtySetup--;
321 capela 463
322     // Make the device port/channel selection effective.
323     selectDevicePort(DevicePortComboBox->currentItem());
324     }
325    
326    
327     // Device port/channel selection slot.
328     void qsamplerDeviceForm::selectDevicePort ( int iPort )
329     {
330     if (m_iDirtySetup > 0)
331     return;
332    
333     //
334     // Device port/channel selection has changed...
335     //
336    
337     QListViewItem *pItem = DeviceListView->selectedItem();
338     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
339     return;
340    
341     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
342     qsamplerDevicePort *pPort = device.ports().at(iPort);
343     if (pPort) {
344     m_iDirtySetup++;
345 capela 465 DevicePortParamTable->refresh(pPort->params(), false);
346 capela 463 m_iDirtySetup--;
347     }
348     // Done.
349 capela 430 stabilizeForm();
350 capela 429 }
351    
352    
353 capela 463 // Device parameter value change slot.
354     void qsamplerDeviceForm::changeDeviceParam ( int iRow, int iCol )
355 capela 432 {
356 capela 442 if (m_iDirtySetup > 0)
357 capela 448 return;
358 capela 442 if (iRow < 0 || iCol < 0)
359 capela 448 return;
360    
361 capela 432 //
362 capela 442 // Device parameter change...
363 capela 432 //
364 capela 442
365 capela 432 QListViewItem *pItem = DeviceListView->selectedItem();
366     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
367     return;
368    
369     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
370    
371 capela 436 // Table 1st column has the parameter name;
372     const QString sParam = DeviceParamTable->text(iRow, 0);
373 capela 433 const QString sValue = DeviceParamTable->text(iRow, iCol);
374 capela 462 // Set the local device parameter value.
375 capela 484 if (device.setParam(sParam, sValue)) {
376 capela 467 selectDevice();
377 capela 484 } else {
378 capela 467 stabilizeForm();
379 capela 484 }
380 capela 433 // Main session should be dirtier...
381     m_pMainForm->sessionDirty();
382 capela 432 }
383    
384    
385 capela 463 // Device port/channel parameter value change slot.
386     void qsamplerDeviceForm::changeDevicePortParam ( int iRow, int iCol )
387     {
388     if (m_iDirtySetup > 0)
389     return;
390     if (iRow < 0 || iCol < 0)
391     return;
392    
393     //
394     // Device port/channel parameter change...
395     //
396    
397     QListViewItem *pItem = DeviceListView->selectedItem();
398     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
399     return;
400    
401     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
402    
403     int iPort = DevicePortComboBox->currentItem();
404     qsamplerDevicePort *pPort = device.ports().at(iPort);
405     if (pPort == NULL)
406     return;
407    
408     // Table 1st column has the parameter name;
409     const QString sParam = DevicePortParamTable->text(iRow, 0);
410     const QString sValue = DevicePortParamTable->text(iRow, iCol);
411     // Set the local device port/channel parameter value.
412     pPort->setParam(sParam, sValue);
413     // Done.
414     stabilizeForm();
415     // Main session should be dirtier...
416     m_pMainForm->sessionDirty();
417     }
418    
419    
420 capela 452 // Device list view context menu handler.
421     void qsamplerDeviceForm::contextMenu ( QListViewItem *pItem, const QPoint& pos, int )
422     {
423     int iItemID;
424    
425     // Build the device context menu...
426     QPopupMenu* pContextMenu = new QPopupMenu(this);
427    
428     bool bClient = (m_pClient != NULL);
429     bool bEnabled = (pItem != NULL);
430     iItemID = pContextMenu->insertItem(
431     QIconSet(QPixmap::fromMimeSource("deviceCreate.png")),
432 capela 463 tr("&Create device"), this, SLOT(createDevice()));
433 capela 452 pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));
434     iItemID = pContextMenu->insertItem(
435     QIconSet(QPixmap::fromMimeSource("deviceDelete.png")),
436 capela 463 tr("&Delete device"), this, SLOT(deleteDevice()));
437 capela 452 pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);
438     pContextMenu->insertSeparator();
439     iItemID = pContextMenu->insertItem(
440     QIconSet(QPixmap::fromMimeSource("formRefresh.png")),
441     tr("&Refresh"), this, SLOT(refreshDevices()));
442     pContextMenu->setItemEnabled(iItemID, bClient);
443    
444     pContextMenu->exec(pos);
445    
446     delete pContextMenu;
447     }
448    
449    
450 capela 426 // Stabilize current form state.
451     void qsamplerDeviceForm::stabilizeForm (void)
452     {
453 capela 431 QListViewItem *pItem = DeviceListView->selectedItem();
454 capela 452 bool bClient = (m_pClient != NULL);
455 capela 431 bool bEnabled = (pItem != NULL);
456 capela 433 DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
457     DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice);
458 capela 430 DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
459     DeviceParamTable->setEnabled(bEnabled);
460 capela 452 RefreshDevicesPushButton->setEnabled(bClient);
461     CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
462 capela 433 DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
463 capela 426 }
464    
465    
466     // end of qsamplerDeviceForm.ui.h
467 capela 463
468    
469    

  ViewVC Help
Powered by ViewVC