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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 961 - (show annotations) (download) (as text)
Sun Dec 3 18:26:13 2006 UTC (17 years, 4 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 // qsamplerDeviceForm.ui.h
2 //
3 // ui.h extension file, included from the uic-generated form implementation.
4 /****************************************************************************
5 Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.
6
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 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
21 *****************************************************************************/
22
23 #include "qsamplerAbout.h"
24 #include "qsamplerMainForm.h"
25
26 #include <qmessagebox.h>
27 #include <qfiledialog.h>
28 #include <qfileinfo.h>
29 #include <qlistbox.h>
30 #include <qptrlist.h>
31 #include <qpopupmenu.h>
32
33
34 // Kind of constructor.
35 void qsamplerDeviceForm::init (void)
36 {
37 // Initialize locals.
38 m_iDirtySetup = 0;
39 m_iDirtyCount = 0;
40 m_bNewDevice = false;
41 m_deviceType = qsamplerDevice::None;
42 m_pAudioItems = NULL;
43 m_pMidiItems = NULL;
44 // No exclusive mode as default.
45 m_deviceTypeMode = qsamplerDevice::None;
46
47 // This an outsider (from designer), but rather important.
48 QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),
49 this, SLOT(changeDeviceParam(int,int)));
50 QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),
51 this, SLOT(changeDevicePortParam(int,int)));
52
53 // Initial contents.
54 refreshDevices();
55 // Try to restore normal window positioning.
56 adjustSize();
57 }
58
59
60 // Kind of destructor.
61 void qsamplerDeviceForm::destroy (void)
62 {
63 }
64
65
66 // Notify our parent that we're emerging.
67 void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )
68 {
69 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
70 if (pMainForm)
71 pMainForm->stabilizeForm();
72
73 stabilizeForm();
74
75 QWidget::showEvent(pShowEvent);
76 }
77
78
79 // Notify our parent that we're closing.
80 void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )
81 {
82 QWidget::hideEvent(pHideEvent);
83
84 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
85 if (pMainForm)
86 pMainForm->stabilizeForm();
87
88 // Signal special whether we changed the device set.
89 if (m_iDirtyCount > 0) {
90 m_iDirtyCount = 0;
91 emit devicesChanged();
92 }
93 }
94
95
96 // 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 // Set current selected device by type and id.
123 void qsamplerDeviceForm::setDevice ( qsamplerDevice *pDevice )
124 {
125 // In case no device is given...
126 qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode;
127 if (pDevice)
128 deviceType = pDevice->deviceType();
129
130 // 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
143 // Is the root present?
144 if (pRootItem == NULL)
145 return;
146
147 // So there's no device huh?
148 if (pDevice == NULL) {
149 DeviceListView->setSelected(pRootItem, true);
150 return;
151 }
152
153 // 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 if (pDeviceItem->device().deviceID() == pDevice->deviceID()) {
159 DeviceListView->setSelected(pDeviceItem, true);
160 break;
161 }
162 pDeviceItem = (qsamplerDeviceItem *) pDeviceItem->nextSibling();
163 }
164 }
165
166
167
168 // Create a new device from current table view.
169 void qsamplerDeviceForm::createDevice (void)
170 {
171 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
172 if (pMainForm == NULL)
173 return;
174
175 QListViewItem *pItem = DeviceListView->selectedItem();
176 if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
177 return;
178
179 // 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 // Append the new device item.
195 qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem,
196 device.deviceType(), device.deviceID());
197 // Just make it the new selection...
198 DeviceListView->setSelected(pDeviceItem, true);
199 // Main session should be marked dirty.
200 pMainForm->sessionDirty();
201 m_iDirtyCount++;
202 }
203 }
204
205
206 // Delete current device in table view.
207 void qsamplerDeviceForm::deleteDevice (void)
208 {
209 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
210 if (pMainForm == NULL)
211 return;
212
213 QListViewItem *pItem = DeviceListView->selectedItem();
214 if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
215 return;
216
217 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
218
219 // Prompt user if this is for real...
220 qsamplerOptions *pOptions = pMainForm->options();
221 if (pOptions && pOptions->bConfirmRemove) {
222 if (QMessageBox::warning(this,
223 QSAMPLER_TITLE ": " + tr("Warning"),
224 tr("Delete device:\n\n"
225 "%1\n\n"
226 "Are you sure?")
227 .arg(device.deviceName()),
228 tr("OK"), tr("Cancel")) > 0)
229 return;
230 }
231
232 // Go and destroy...
233 if (device.deleteDevice()) {
234 // Remove it from the device view...
235 delete pItem;
236 // Main session should be marked dirty.
237 pMainForm->sessionDirty();
238 m_iDirtyCount++;
239 }
240 }
241
242
243 // Refresh all device list and views.
244 void qsamplerDeviceForm::refreshDevices (void)
245 {
246 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
247 if (pMainForm == NULL)
248 return;
249
250 // Avoid nested changes.
251 m_iDirtySetup++;
252
253 //
254 // (Re)Load complete device configuration data ...
255 //
256 m_pAudioItems = NULL;
257 m_pMidiItems = NULL;
258 DeviceListView->clear();
259 if (pMainForm->client()) {
260 int *piDeviceIDs;
261 // Grab and pop Audio devices...
262 if (m_deviceTypeMode == qsamplerDevice::None ||
263 m_deviceTypeMode == qsamplerDevice::Audio) {
264 m_pAudioItems = new qsamplerDeviceItem(DeviceListView,
265 qsamplerDevice::Audio);
266 }
267 if (m_pAudioItems) {
268 piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
269 qsamplerDevice::Audio);
270 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
271 new qsamplerDeviceItem(m_pAudioItems,
272 qsamplerDevice::Audio, piDeviceIDs[i]);
273 }
274 m_pAudioItems->setOpen(true);
275 }
276 // Grab and pop MIDI devices...
277 if (m_deviceTypeMode == qsamplerDevice::None ||
278 m_deviceTypeMode == qsamplerDevice::Midi) {
279 m_pMidiItems = new qsamplerDeviceItem(DeviceListView,
280 qsamplerDevice::Midi);
281 }
282 if (m_pMidiItems) {
283 piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(),
284 qsamplerDevice::Midi);
285 for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
286 new qsamplerDeviceItem(m_pMidiItems,
287 qsamplerDevice::Midi, piDeviceIDs[i]);
288 }
289 m_pMidiItems->setOpen(true);
290 }
291 }
292
293 // Done.
294 m_iDirtySetup--;
295
296 // Show something.
297 selectDevice();
298 }
299
300
301 // Driver selection slot.
302 void qsamplerDeviceForm::selectDriver ( const QString& sDriverName )
303 {
304 if (m_iDirtySetup > 0)
305 return;
306
307 //
308 // Driver name has changed for a new device...
309 //
310
311 QListViewItem *pItem = DeviceListView->selectedItem();
312 if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
313 return;
314
315 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
316
317 // Driver change is only valid for scratch devices...
318 if (m_bNewDevice) {
319 m_iDirtySetup++;
320 device.setDriver(sDriverName);
321 DeviceParamTable->refresh(device.params(), m_bNewDevice);
322 m_iDirtySetup--;
323 // Done.
324 stabilizeForm();
325 }
326 }
327
328
329 // Device selection slot.
330 void qsamplerDeviceForm::selectDevice (void)
331 {
332 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
333 if (pMainForm == NULL)
334 return;
335
336 if (m_iDirtySetup > 0)
337 return;
338
339 //
340 // Device selection has changed...
341 //
342
343 QListViewItem *pItem = DeviceListView->selectedItem();
344 if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
345 m_deviceType = qsamplerDevice::None;
346 DeviceNameTextLabel->setText(QString::null);
347 DeviceParamTable->setNumRows(0);
348 DevicePortComboBox->clear();
349 DevicePortParamTable->setNumRows(0);
350 DevicePortTextLabel->setEnabled(false);
351 DevicePortComboBox->setEnabled(false);
352 DevicePortParamTable->setEnabled(false);
353 stabilizeForm();
354 return;
355 }
356
357 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
358
359 m_iDirtySetup++;
360 // Flag whether this is a new device.
361 m_bNewDevice = (device.deviceID() < 0);
362
363 // Fill the device/driver heading...
364 DeviceNameTextLabel->setText(device.deviceName());
365 // The driver combobox is only rebuilt if device type has changed...
366 if (device.deviceType() != m_deviceType) {
367 DriverNameComboBox->clear();
368 DriverNameComboBox->insertStringList(
369 qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType()));
370 m_deviceType = device.deviceType();
371 }
372 // Do we need a driver name?
373 if (m_bNewDevice || device.driverName().isEmpty())
374 device.setDriver(DriverNameComboBox->currentText());
375 setDriverName(device.driverName());
376 DriverNameTextLabel->setEnabled(m_bNewDevice);
377 DriverNameComboBox->setEnabled(m_bNewDevice);
378 // Fill the device parameter table...
379 DeviceParamTable->refresh(device.params(), m_bNewDevice);
380 // And now the device port/channel parameter table...
381 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 DevicePortComboBox->clear();
392 DevicePortParamTable->setNumRows(0);
393 if (m_bNewDevice) {
394 DevicePortTextLabel->setEnabled(false);
395 DevicePortComboBox->setEnabled(false);
396 DevicePortParamTable->setEnabled(false);
397 } else {
398 QPixmap pixmap;
399 switch (device.deviceType()) {
400 case qsamplerDevice::Audio:
401 pixmap = QPixmap::fromMimeSource("audio2.png");
402 break;
403 case qsamplerDevice::Midi:
404 pixmap = QPixmap::fromMimeSource("midi2.png");
405 break;
406 case qsamplerDevice::None:
407 break;
408 }
409 qsamplerDevicePortList& ports = device.ports();
410 qsamplerDevicePort *pPort;
411 for (pPort = ports.first(); pPort; pPort = ports.next()) {
412 DevicePortComboBox->insertItem(pixmap, device.deviceTypeName()
413 + ' ' + device.driverName()
414 + ' ' + pPort->portName());
415 }
416 bool bEnabled = (ports.count() > 0);
417 DevicePortTextLabel->setEnabled(bEnabled);
418 DevicePortComboBox->setEnabled(bEnabled);
419 DevicePortParamTable->setEnabled(bEnabled);
420 }
421 // Done.
422 m_iDirtySetup--;
423
424 // 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 DevicePortParamTable->refresh(pPort->params(), false);
448 m_iDirtySetup--;
449 }
450 // Done.
451 stabilizeForm();
452 }
453
454
455 // Device parameter value change slot.
456 void qsamplerDeviceForm::changeDeviceParam ( int iRow, int iCol )
457 {
458 if (m_iDirtySetup > 0)
459 return;
460 if (iRow < 0 || iCol < 0)
461 return;
462
463 //
464 // Device parameter change...
465 //
466
467 QListViewItem *pItem = DeviceListView->selectedItem();
468 if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
469 return;
470
471 qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
472
473 // Table 1st column has the parameter name;
474 const QString sParam = DeviceParamTable->text(iRow, 0);
475 const QString sValue = DeviceParamTable->text(iRow, iCol);
476 // Set the local device parameter value.
477 if (device.setParam(sParam, sValue)) {
478 selectDevice();
479 } else {
480 stabilizeForm();
481 }
482
483 // Main session should be dirtier...
484 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
485 if (pMainForm)
486 pMainForm->sessionDirty();
487 }
488
489
490 // 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 return;
512
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
521 // Main session should be dirtier...
522 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
523 if (pMainForm)
524 pMainForm->sessionDirty();
525 }
526
527
528 // Device list view context menu handler.
529 void qsamplerDeviceForm::contextMenu ( QListViewItem *pItem, const QPoint& pos, int )
530 {
531 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
532 if (pMainForm == NULL)
533 return;
534
535 int iItemID;
536
537 // Build the device context menu...
538 QPopupMenu* pContextMenu = new QPopupMenu(this);
539
540 bool bClient = (pMainForm->client() != NULL);
541 bool bEnabled = (pItem != NULL);
542 iItemID = pContextMenu->insertItem(
543 QIconSet(QPixmap::fromMimeSource("deviceCreate.png")),
544 tr("&Create device"), this, SLOT(createDevice()));
545 pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));
546 iItemID = pContextMenu->insertItem(
547 QIconSet(QPixmap::fromMimeSource("deviceDelete.png")),
548 tr("&Delete device"), this, SLOT(deleteDevice()));
549 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
556 pContextMenu->exec(pos);
557
558 delete pContextMenu;
559 }
560
561
562 // Stabilize current form state.
563 void qsamplerDeviceForm::stabilizeForm (void)
564 {
565 qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
566 QListViewItem *pItem = DeviceListView->selectedItem();
567 bool bClient = (pMainForm && pMainForm->client() != NULL);
568 bool bEnabled = (pItem != NULL);
569 DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
570 DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice);
571 DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
572 DeviceParamTable->setEnabled(bEnabled);
573 RefreshDevicesPushButton->setEnabled(bClient);
574 CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
575 DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
576 }
577
578
579 // end of qsamplerDeviceForm.ui.h

  ViewVC Help
Powered by ViewVC