/[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 487 - (hide annotations) (download) (as text)
Thu Mar 31 14:17:19 2005 UTC (19 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 14360 byte(s)
* Device setup is now also accessible from the sampler channel dialog.

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

  ViewVC Help
Powered by ViewVC