/[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 442 - (hide annotations) (download) (as text)
Thu Mar 10 15:48:38 2005 UTC (16 years, 10 months ago) by capela
File MIME type: text/x-c++hdr
File size: 11871 byte(s)
Refinements on the device list view and parameter table editing.

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

  ViewVC Help
Powered by ViewVC