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