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