/[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 961 - (hide annotations) (download) (as text)
Sun Dec 3 18:26:13 2006 UTC (17 years, 5 months ago) by capela
File MIME type: text/x-c++hdr
File size: 16039 byte(s)
- Adding preliminary MIDI instrument mapping support; now
  with an instrument list widget and editing capabilities.

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

  ViewVC Help
Powered by ViewVC