1 |
// qsamplerDeviceForm.ui.h |
2 |
// |
3 |
// ui.h extension file, included from the uic-generated form implementation. |
4 |
/**************************************************************************** |
5 |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
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 |
#include <qfiledialog.h> |
25 |
#include <qfileinfo.h> |
26 |
#include <qlistbox.h> |
27 |
|
28 |
#include "qsamplerMainForm.h" |
29 |
|
30 |
#include "config.h" |
31 |
|
32 |
|
33 |
// Kind of constructor. |
34 |
void qsamplerDeviceForm::init (void) |
35 |
{ |
36 |
// Initialize locals. |
37 |
m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); |
38 |
m_pClient = NULL; |
39 |
m_iDirtySetup = 0; |
40 |
m_iDirtyCount = 0; |
41 |
m_bNewDevice = false; |
42 |
|
43 |
// This an outsider (from designer), but rather important. |
44 |
QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)), |
45 |
this, SLOT(changeValue(int,int))); |
46 |
|
47 |
// Try to restore normal window positioning. |
48 |
adjustSize(); |
49 |
} |
50 |
|
51 |
|
52 |
// Kind of destructor. |
53 |
void qsamplerDeviceForm::destroy (void) |
54 |
{ |
55 |
} |
56 |
|
57 |
|
58 |
// Notify our parent that we're emerging. |
59 |
void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent ) |
60 |
{ |
61 |
if (m_pMainForm) |
62 |
m_pMainForm->stabilizeForm(); |
63 |
|
64 |
stabilizeForm(); |
65 |
|
66 |
QWidget::showEvent(pShowEvent); |
67 |
} |
68 |
|
69 |
|
70 |
// Notify our parent that we're closing. |
71 |
void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent ) |
72 |
{ |
73 |
QWidget::hideEvent(pHideEvent); |
74 |
|
75 |
if (m_pMainForm) |
76 |
m_pMainForm->stabilizeForm(); |
77 |
} |
78 |
|
79 |
|
80 |
// Device configuration dialog setup formal initializer. |
81 |
void qsamplerDeviceForm::setClient ( lscp_client_t *pClient ) |
82 |
{ |
83 |
// If it has not changed, do nothing. |
84 |
if (m_pClient && m_pClient == pClient) |
85 |
return; |
86 |
|
87 |
// Set new reference. |
88 |
m_pClient = pClient; |
89 |
|
90 |
// OK. Do a whole refresh around. |
91 |
refreshDevices(); |
92 |
} |
93 |
|
94 |
|
95 |
// Create a new device from current table view. |
96 |
void qsamplerDeviceForm::createDevice (void) |
97 |
{ |
98 |
// |
99 |
// TODO: Create a new device from current table view... |
100 |
// |
101 |
m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()"); |
102 |
|
103 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
104 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
105 |
return; |
106 |
|
107 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
108 |
|
109 |
// 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 |
|
122 |
// 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 |
|
137 |
// Free used parameter array. |
138 |
delete [] pParams; |
139 |
|
140 |
// 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 |
} |
149 |
|
150 |
|
151 |
// Delete current device in table view. |
152 |
void qsamplerDeviceForm::deleteDevice (void) |
153 |
{ |
154 |
// |
155 |
// TODO: Delete current device in table view... |
156 |
// |
157 |
m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()"); |
158 |
|
159 |
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 |
} |
189 |
|
190 |
|
191 |
// Refresh all device list and views. |
192 |
void qsamplerDeviceForm::refreshDevices (void) |
193 |
{ |
194 |
// Avoid nested changes. |
195 |
m_iDirtySetup++; |
196 |
|
197 |
// |
198 |
// TODO: Load device configuration data ... |
199 |
// |
200 |
m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()"); |
201 |
|
202 |
DeviceListView->clear(); |
203 |
if (m_pClient) { |
204 |
qsamplerDeviceItem *pItem; |
205 |
int *piDeviceIDs; |
206 |
// Grab and pop Audio devices... |
207 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
208 |
qsamplerDevice::Audio); |
209 |
if (pItem) { |
210 |
pItem->setText(0, tr("Audio")); |
211 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
212 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
213 |
new qsamplerDeviceItem(pItem, m_pClient, |
214 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
215 |
} |
216 |
pItem->setOpen(true); |
217 |
} |
218 |
// Grab and pop MIDI devices... |
219 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
220 |
qsamplerDevice::Midi); |
221 |
if (pItem) { |
222 |
pItem->setText(0, tr("MIDI")); |
223 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
224 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
225 |
new qsamplerDeviceItem(pItem, m_pClient, |
226 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
227 |
} |
228 |
pItem->setOpen(true); |
229 |
} |
230 |
} |
231 |
|
232 |
// Done. |
233 |
m_iDirtyCount = 0; |
234 |
m_iDirtySetup--; |
235 |
|
236 |
// Show something. |
237 |
selectDevice(); |
238 |
} |
239 |
|
240 |
|
241 |
// Driver selection slot. |
242 |
void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) |
243 |
{ |
244 |
if (m_iDirtySetup > 0) |
245 |
return; |
246 |
|
247 |
// |
248 |
// TODO: Driver name has changed for a new device... |
249 |
// |
250 |
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver()"); |
251 |
|
252 |
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 |
stabilizeForm(); |
264 |
} |
265 |
|
266 |
|
267 |
// Device selection slot. |
268 |
void qsamplerDeviceForm::selectDevice (void) |
269 |
{ |
270 |
if (m_iDirtySetup > 0) |
271 |
return; |
272 |
|
273 |
// |
274 |
// TODO: Device selection has changed... |
275 |
// |
276 |
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()"); |
277 |
|
278 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
279 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { |
280 |
DeviceNameTextLabel->setText(QString::null); |
281 |
DeviceParamTable->setNumRows(0); |
282 |
stabilizeForm(); |
283 |
return; |
284 |
} |
285 |
|
286 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
287 |
m_bNewDevice = (device.deviceID() < 0); |
288 |
|
289 |
// Fill the device/driver heading... |
290 |
DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName()); |
291 |
DriverNameComboBox->clear(); |
292 |
DriverNameComboBox->insertStringList( |
293 |
qsamplerDevice::getDrivers(m_pClient, device.deviceType())); |
294 |
const QString& sDriverName = device.driverName(); |
295 |
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 |
DriverNameTextLabel->setEnabled(m_bNewDevice); |
303 |
DriverNameComboBox->setEnabled(m_bNewDevice); |
304 |
|
305 |
// Fill the device parameter table... |
306 |
DeviceParamTable->refresh(device); |
307 |
|
308 |
// Done. |
309 |
stabilizeForm(); |
310 |
} |
311 |
|
312 |
|
313 |
// 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 |
const QString sParam = DeviceParamTable->text(iRow, 2); |
330 |
const QString sValue = DeviceParamTable->text(iRow, iCol); |
331 |
params[sParam].value = sValue; |
332 |
|
333 |
// 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(), ¶m)) != 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(), ¶m)) != 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 |
m_iDirtyCount++; |
362 |
stabilizeForm(); |
363 |
// Main session should be dirtier... |
364 |
m_pMainForm->sessionDirty(); |
365 |
} |
366 |
|
367 |
|
368 |
// Stabilize current form state. |
369 |
void qsamplerDeviceForm::stabilizeForm (void) |
370 |
{ |
371 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
372 |
bool bEnabled = (pItem != NULL); |
373 |
DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); |
374 |
DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
375 |
DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
376 |
DeviceParamTable->setEnabled(bEnabled); |
377 |
CreateDevicePushButton->setEnabled(bEnabled || m_bNewDevice); |
378 |
DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); |
379 |
} |
380 |
|
381 |
|
382 |
// end of qsamplerDeviceForm.ui.h |
383 |
|