/[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 436 - (hide annotations) (download) (as text)
Wed Mar 9 20:55:04 2005 UTC (19 years, 1 month ago) by capela
File MIME type: text/x-c++hdr
File size: 11314 byte(s)
Device configuration is now partially functional (2nd.fix).

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

  ViewVC Help
Powered by ViewVC