/[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 452 - (hide annotations) (download) (as text)
Sun Mar 13 22:06:59 2005 UTC (19 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 12963 byte(s)
* Device managament gets prettier with new icons.
* Channel device selection is now implemented.

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

  ViewVC Help
Powered by ViewVC