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

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

  ViewVC Help
Powered by ViewVC