/[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 490 - (hide annotations) (download) (as text)
Fri Apr 1 00:34:58 2005 UTC (19 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 15480 byte(s)
* Device setup right from the sampler channel dialog gets cleaner.

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 capela 487 m_pMainForm = NULL;
40 capela 431 m_pClient = NULL;
41 capela 426 m_iDirtySetup = 0;
42 capela 488 m_iDirtyCount = 0;
43 capela 431 m_bNewDevice = false;
44 capela 436 m_deviceType = qsamplerDevice::None;
45 capela 442 m_pAudioItems = NULL;
46     m_pMidiItems = NULL;
47 capela 490 // No exclusive mode as default.
48     m_deviceTypeMode = qsamplerDevice::None;
49    
50 capela 433 // This an outsider (from designer), but rather important.
51     QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),
52 capela 463 this, SLOT(changeDeviceParam(int,int)));
53     QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),
54     this, SLOT(changeDevicePortParam(int,int)));
55    
56 capela 467 // Initial contents.
57     refreshDevices();
58 capela 431 // Try to restore normal window positioning.
59     adjustSize();
60 capela 426 }
61    
62    
63     // Kind of destructor.
64     void qsamplerDeviceForm::destroy (void)
65     {
66     }
67    
68    
69 capela 428 // Notify our parent that we're emerging.
70     void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )
71     {
72 capela 431 if (m_pMainForm)
73     m_pMainForm->stabilizeForm();
74 capela 428
75 capela 431 stabilizeForm();
76 capela 428
77 capela 431 QWidget::showEvent(pShowEvent);
78 capela 428 }
79    
80    
81     // Notify our parent that we're closing.
82     void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )
83     {
84 capela 431 QWidget::hideEvent(pHideEvent);
85 capela 428
86 capela 431 if (m_pMainForm)
87     m_pMainForm->stabilizeForm();
88 capela 490
89 capela 488 // Signal special whether we changed the device set.
90     if (m_iDirtyCount > 0) {
91     m_iDirtyCount = 0;
92     emit devicesChanged();
93     }
94 capela 428 }
95    
96    
97 capela 487 // Application main form settler (life depends on it).
98     void qsamplerDeviceForm::setMainForm ( qsamplerMainForm *pMainForm )
99     {
100 capela 490 m_pMainForm = pMainForm;
101 capela 487 }
102    
103    
104 capela 490 // Set device type spacial exclusive mode.
105     void qsamplerDeviceForm::setDeviceTypeMode (
106     qsamplerDevice::qsamplerDeviceType deviceTypeMode )
107     {
108     // If it has not changed, do nothing.
109     if (m_deviceTypeMode == deviceTypeMode)
110     return;
111    
112     m_deviceTypeMode = deviceTypeMode;
113    
114     // OK. Do a whole refresh around.
115     refreshDevices();
116     }
117    
118    
119 capela 426 // Device configuration dialog setup formal initializer.
120 capela 428 void qsamplerDeviceForm::setClient ( lscp_client_t *pClient )
121 capela 426 {
122 capela 428 // If it has not changed, do nothing.
123     if (m_pClient && m_pClient == pClient)
124 capela 431 return;
125 capela 426
126 capela 428 // Set new reference.
127     m_pClient = pClient;
128 capela 490
129 capela 428 // OK. Do a whole refresh around.
130     refreshDevices();
131     }
132    
133    
134 capela 490 // Device driver name setup formal initializer.
135     void qsamplerDeviceForm::setDriverName ( const QString& sDriverName )
136     {
137     if (DriverNameComboBox->listBox()->findItem(sDriverName,
138     Qt::ExactMatch | Qt::CaseSensitive) == NULL) {
139     DriverNameComboBox->insertItem(sDriverName);
140     }
141     DriverNameComboBox->setCurrentText(sDriverName);
142     }
143    
144    
145 capela 487 // Set current selected device by type and id.
146 capela 490 void qsamplerDeviceForm::setDevice ( qsamplerDevice *pDevice )
147 capela 487 {
148 capela 490 // In case no device is given...
149     qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;
150     if (pDevice)
151     deviceType = pDevice->deviceType();
152    
153 capela 487 // Get the device view root item...
154     qsamplerDeviceItem *pRootItem = NULL;
155     switch (deviceType) {
156     case qsamplerDevice::Audio:
157     pRootItem = m_pAudioItems;
158     break;
159     case qsamplerDevice::Midi:
160     pRootItem = m_pMidiItems;
161     break;
162     case qsamplerDevice::None:
163     break;
164     }
165 capela 490
166 capela 487 // Is the root present?
167     if (pRootItem == NULL)
168 capela 490 return;
169 capela 487
170 capela 490 // So there's no device huh?
171     if (pDevice == NULL) {
172     DeviceListView->setSelected(pRootItem, true);
173     return;
174     }
175    
176 capela 487 // For each child, test for identity...
177     qsamplerDeviceItem *pDeviceItem =
178     (qsamplerDeviceItem *) pRootItem->firstChild();
179     while (pDeviceItem) {
180     // If identities match, select as current device item.
181 capela 490 if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {
182 capela 487 DeviceListView->setSelected(pDeviceItem, true);
183     break;
184     }
185     pDeviceItem = (qsamplerDeviceItem *) pDeviceItem->nextSibling();
186     }
187     }
188    
189    
190    
191 capela 433 // Create a new device from current table view.
192     void qsamplerDeviceForm::createDevice (void)
193 capela 428 {
194 capela 487 if (m_pMainForm == NULL)
195 capela 490 return;
196 capela 487
197 capela 433 QListViewItem *pItem = DeviceListView->selectedItem();
198     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
199     return;
200 capela 428
201 capela 484 // About a brand new device instance...
202     qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device());
203     if (device.createDevice()) {
204     // Now it depends on the device type...
205     qsamplerDeviceItem *pRootItem = NULL;
206     switch (device.deviceType()) {
207     case qsamplerDevice::Audio:
208     pRootItem = m_pAudioItems;
209     break;
210     case qsamplerDevice::Midi:
211     pRootItem = m_pMidiItems;
212     break;
213     case qsamplerDevice::None:
214     break;
215     }
216 capela 442 // Append the new device item.
217     qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem,
218 capela 484 m_pMainForm, device.deviceType(), device.deviceID());
219 capela 442 // Just make it the new selection...
220     DeviceListView->setSelected(pDeviceItem, true);
221 capela 433 // Main session should be marked dirty.
222     m_pMainForm->sessionDirty();
223 capela 488 m_iDirtyCount++;
224 capela 433 }
225 capela 428 }
226    
227    
228     // Delete current device in table view.
229     void qsamplerDeviceForm::deleteDevice (void)
230     {
231 capela 487 if (m_pMainForm == NULL)
232 capela 490 return;
233 capela 487
234 capela 433 QListViewItem *pItem = DeviceListView->selectedItem();
235     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
236     return;
237    
238 capela 484 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
239 capela 433
240 capela 442 // Prompt user if this is for real...
241     qsamplerOptions *pOptions = m_pMainForm->options();
242 capela 448 if (pOptions && pOptions->bConfirmRemove) {
243     if (QMessageBox::warning(this, tr("Warning"),
244 capela 484 tr("Delete device:\n\n"
245     "%1\n\n"
246 capela 448 "Are you sure?")
247     .arg(device.deviceName()),
248     tr("OK"), tr("Cancel")) > 0)
249     return;
250     }
251 capela 442
252 capela 484 // Go and destroy...
253     if (device.deleteDevice()) {
254     // Remove it from the device view...
255 capela 442 delete pItem;
256 capela 433 // Main session should be marked dirty.
257     m_pMainForm->sessionDirty();
258 capela 488 m_iDirtyCount++;
259 capela 433 }
260 capela 428 }
261    
262    
263     // Refresh all device list and views.
264     void qsamplerDeviceForm::refreshDevices (void)
265     {
266 capela 487 if (m_pMainForm == NULL)
267 capela 490 return;
268 capela 487
269 capela 431 // Avoid nested changes.
270     m_iDirtySetup++;
271 capela 428
272     //
273 capela 442 // (Re)Load complete device configuration data ...
274 capela 431 //
275 capela 442 m_pAudioItems = NULL;
276     m_pMidiItems = NULL;
277 capela 431 DeviceListView->clear();
278     if (m_pClient) {
279 capela 429 int *piDeviceIDs;
280 capela 430 // Grab and pop Audio devices...
281 capela 490 if (m_deviceTypeMode == qsamplerDevice::None ||
282     m_deviceTypeMode == qsamplerDevice::Audio) {
283     m_pAudioItems = new qsamplerDeviceItem(DeviceListView,
284     m_pMainForm, qsamplerDevice::Audio);
285     }
286 capela 442 if (m_pAudioItems) {
287 capela 429 piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
288     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
289 capela 484 new qsamplerDeviceItem(m_pAudioItems, m_pMainForm,
290 capela 429 qsamplerDevice::Audio, piDeviceIDs[i]);
291     }
292 capela 442 m_pAudioItems->setOpen(true);
293 capela 428 }
294 capela 430 // Grab and pop MIDI devices...
295 capela 490 if (m_deviceTypeMode == qsamplerDevice::None ||
296     m_deviceTypeMode == qsamplerDevice::Midi) {
297     m_pMidiItems = new qsamplerDeviceItem(DeviceListView,
298     m_pMainForm, qsamplerDevice::Midi);
299     }
300 capela 442 if (m_pMidiItems) {
301 capela 429 piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
302     for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
303 capela 484 new qsamplerDeviceItem(m_pMidiItems, m_pMainForm,
304 capela 429 qsamplerDevice::Midi, piDeviceIDs[i]);
305     }
306 capela 442 m_pMidiItems->setOpen(true);
307 capela 429 }
308 capela 428 }
309    
310 capela 431 // Done.
311 capela 433 m_iDirtySetup--;
312 capela 436
313 capela 433 // Show something.
314 capela 431 selectDevice();
315 capela 428 }
316    
317 capela 430
318     // Driver selection slot.
319     void qsamplerDeviceForm::selectDriver ( const QString& sDriverName )
320     {
321 capela 433 if (m_iDirtySetup > 0)
322 capela 436 return;
323 capela 433
324 capela 430 //
325 capela 442 // Driver name has changed for a new device...
326 capela 430 //
327    
328 capela 431 QListViewItem *pItem = DeviceListView->selectedItem();
329     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
330     return;
331    
332     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
333 capela 436
334     // Driver change is only valid for scratch devices...
335 capela 431 if (m_bNewDevice) {
336 capela 442 m_iDirtySetup++;
337 capela 484 device.setDriver(sDriverName);
338 capela 462 DeviceParamTable->refresh(device.params(), m_bNewDevice);
339 capela 442 m_iDirtySetup--;
340 capela 436 // Done.
341     stabilizeForm();
342 capela 431 }
343 capela 430 }
344    
345    
346 capela 429 // Device selection slot.
347 capela 430 void qsamplerDeviceForm::selectDevice (void)
348 capela 429 {
349 capela 433 if (m_iDirtySetup > 0)
350 capela 436 return;
351 capela 433
352 capela 430 //
353 capela 442 // Device selection has changed...
354 capela 430 //
355 capela 428
356 capela 431 QListViewItem *pItem = DeviceListView->selectedItem();
357 capela 430 if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
358 capela 436 m_deviceType = qsamplerDevice::None;
359     DeviceNameTextLabel->setText(QString::null);
360     DeviceParamTable->setNumRows(0);
361 capela 468 DevicePortComboBox->clear();
362 capela 467 DevicePortParamTable->setNumRows(0);
363 capela 463 DevicePortComboBox->setEnabled(false);
364     DevicePortParamTable->setEnabled(false);
365 capela 430 stabilizeForm();
366     return;
367     }
368 capela 429
369 capela 431 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
370 capela 436
371 capela 463 m_iDirtySetup++;
372 capela 436 // Flag whether this is a new device.
373 capela 430 m_bNewDevice = (device.deviceID() < 0);
374    
375 capela 433 // Fill the device/driver heading...
376 capela 484 DeviceNameTextLabel->setText(device.deviceName());
377 capela 436 // The driver combobox is only rebuilt if device type has changed...
378     if (device.deviceType() != m_deviceType) {
379     DriverNameComboBox->clear();
380     DriverNameComboBox->insertStringList(
381     qsamplerDevice::getDrivers(m_pClient, device.deviceType()));
382     m_deviceType = device.deviceType();
383     }
384     // Do we need a driver name?
385     if (m_bNewDevice || device.driverName().isEmpty())
386 capela 484 device.setDriver(DriverNameComboBox->currentText());
387 capela 490 setDriverName(device.driverName());
388 capela 430 DriverNameTextLabel->setEnabled(m_bNewDevice);
389     DriverNameComboBox->setEnabled(m_bNewDevice);
390     // Fill the device parameter table...
391 capela 462 DeviceParamTable->refresh(device.params(), m_bNewDevice);
392 capela 463 // And now the device port/channel parameter table...
393     DevicePortComboBox->clear();
394     DevicePortParamTable->setNumRows(0);
395     if (m_bNewDevice) {
396     DevicePortComboBox->setEnabled(false);
397     DevicePortParamTable->setEnabled(false);
398     } else {
399     QPixmap pixmap;
400     switch (device.deviceType()) {
401     case qsamplerDevice::Audio:
402 capela 490 pixmap = QPixmap::fromMimeSource("audio2.png");
403     break;
404 capela 463 case qsamplerDevice::Midi:
405 capela 490 pixmap = QPixmap::fromMimeSource("midi2.png");
406     break;
407 capela 463 case qsamplerDevice::None:
408 capela 490 break;
409 capela 463 }
410     qsamplerDevicePortList& ports = device.ports();
411     qsamplerDevicePort *pPort;
412     for (pPort = ports.first(); pPort; pPort = ports.next()) {
413 capela 490 DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()
414 capela 484 + ' ' + device.driverName()
415     + ' ' + pPort->portName());
416 capela 463 }
417     bool bEnabled = (ports.count() > 0);
418     DevicePortComboBox->setEnabled(bEnabled);
419     DevicePortParamTable->setEnabled(bEnabled);
420     }
421 capela 430 // Done.
422 capela 442 m_iDirtySetup--;
423 capela 490
424 capela 463 // Make the device port/channel selection effective.
425     selectDevicePort(DevicePortComboBox->currentItem());
426     }
427    
428    
429     // Device port/channel selection slot.
430     void qsamplerDeviceForm::selectDevicePort ( int iPort )
431     {
432     if (m_iDirtySetup > 0)
433     return;
434    
435     //
436     // Device port/channel selection has changed...
437     //
438    
439     QListViewItem *pItem = DeviceListView->selectedItem();
440     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
441     return;
442    
443     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
444     qsamplerDevicePort *pPort = device.ports().at(iPort);
445     if (pPort) {
446     m_iDirtySetup++;
447 capela 465 DevicePortParamTable->refresh(pPort->params(), false);
448 capela 463 m_iDirtySetup--;
449     }
450     // Done.
451 capela 430 stabilizeForm();
452 capela 429 }
453    
454    
455 capela 463 // Device parameter value change slot.
456     void qsamplerDeviceForm::changeDeviceParam ( int iRow, int iCol )
457 capela 432 {
458 capela 487 if (m_pMainForm == NULL)
459 capela 490 return;
460 capela 442 if (m_iDirtySetup > 0)
461 capela 448 return;
462 capela 442 if (iRow < 0 || iCol < 0)
463 capela 448 return;
464 capela 490
465 capela 432 //
466 capela 442 // Device parameter change...
467 capela 432 //
468 capela 442
469 capela 432 QListViewItem *pItem = DeviceListView->selectedItem();
470     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
471     return;
472    
473     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
474    
475 capela 436 // Table 1st column has the parameter name;
476     const QString sParam = DeviceParamTable->text(iRow, 0);
477 capela 433 const QString sValue = DeviceParamTable->text(iRow, iCol);
478 capela 462 // Set the local device parameter value.
479 capela 484 if (device.setParam(sParam, sValue)) {
480 capela 467 selectDevice();
481 capela 484 } else {
482 capela 467 stabilizeForm();
483 capela 484 }
484 capela 433 // Main session should be dirtier...
485     m_pMainForm->sessionDirty();
486 capela 432 }
487    
488    
489 capela 463 // Device port/channel parameter value change slot.
490     void qsamplerDeviceForm::changeDevicePortParam ( int iRow, int iCol )
491     {
492 capela 487 if (m_pMainForm == NULL)
493 capela 490 return;
494 capela 463 if (m_iDirtySetup > 0)
495     return;
496     if (iRow < 0 || iCol < 0)
497     return;
498    
499     //
500     // Device port/channel parameter change...
501     //
502    
503     QListViewItem *pItem = DeviceListView->selectedItem();
504     if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
505     return;
506    
507     qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
508    
509     int iPort = DevicePortComboBox->currentItem();
510     qsamplerDevicePort *pPort = device.ports().at(iPort);
511     if (pPort == NULL)
512 capela 490 return;
513 capela 463
514     // Table 1st column has the parameter name;
515     const QString sParam = DevicePortParamTable->text(iRow, 0);
516     const QString sValue = DevicePortParamTable->text(iRow, iCol);
517     // Set the local device port/channel parameter value.
518     pPort->setParam(sParam, sValue);
519     // Done.
520     stabilizeForm();
521     // Main session should be dirtier...
522     m_pMainForm->sessionDirty();
523     }
524    
525    
526 capela 452 // Device list view context menu handler.
527     void qsamplerDeviceForm::contextMenu ( QListViewItem *pItem, const QPoint& pos, int )
528     {
529     int iItemID;
530 capela 490
531 capela 452 // Build the device context menu...
532     QPopupMenu* pContextMenu = new QPopupMenu(this);
533 capela 490
534 capela 452 bool bClient = (m_pClient != NULL);
535     bool bEnabled = (pItem != NULL);
536     iItemID = pContextMenu->insertItem(
537     QIconSet(QPixmap::fromMimeSource("deviceCreate.png")),
538 capela 463 tr("&Create device"), this, SLOT(createDevice()));
539 capela 452 pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));
540     iItemID = pContextMenu->insertItem(
541     QIconSet(QPixmap::fromMimeSource("deviceDelete.png")),
542 capela 463 tr("&Delete device"), this, SLOT(deleteDevice()));
543 capela 452 pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);
544     pContextMenu->insertSeparator();
545     iItemID = pContextMenu->insertItem(
546     QIconSet(QPixmap::fromMimeSource("formRefresh.png")),
547     tr("&Refresh"), this, SLOT(refreshDevices()));
548     pContextMenu->setItemEnabled(iItemID, bClient);
549 capela 490
550 capela 452 pContextMenu->exec(pos);
551 capela 490
552 capela 452 delete pContextMenu;
553     }
554    
555    
556 capela 426 // Stabilize current form state.
557     void qsamplerDeviceForm::stabilizeForm (void)
558     {
559 capela 431 QListViewItem *pItem = DeviceListView->selectedItem();
560 capela 452 bool bClient = (m_pClient != NULL);
561 capela 431 bool bEnabled = (pItem != NULL);
562 capela 433 DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
563     DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice);
564 capela 430 DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
565     DeviceParamTable->setEnabled(bEnabled);
566 capela 452 RefreshDevicesPushButton->setEnabled(bClient);
567     CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
568 capela 433 DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
569 capela 426 }
570    
571    
572     // end of qsamplerDeviceForm.ui.h

  ViewVC Help
Powered by ViewVC