1 |
capela |
1464 |
// qsamplerDeviceForm.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
|
|
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
Copyright (C) 2007, Christian Schoenebeck |
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 along |
18 |
|
|
with this program; if not, write to the Free Software Foundation, Inc., |
19 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
|
|
|
21 |
|
|
*****************************************************************************/ |
22 |
|
|
|
23 |
schoenebeck |
1461 |
#include "qsamplerDeviceForm.h" |
24 |
|
|
|
25 |
|
|
#include "qsamplerAbout.h" |
26 |
capela |
1473 |
#include "qsamplerMainForm.h" |
27 |
schoenebeck |
1461 |
|
28 |
|
|
namespace QSampler { |
29 |
|
|
|
30 |
|
|
DeviceForm::DeviceForm(QWidget* parent, Qt::WFlags f) : QDialog(parent, f) { |
31 |
|
|
ui.setupUi(this); |
32 |
|
|
|
33 |
|
|
// Initialize locals. |
34 |
|
|
m_iDirtySetup = 0; |
35 |
|
|
m_iDirtyCount = 0; |
36 |
|
|
m_bNewDevice = false; |
37 |
|
|
m_deviceType = qsamplerDevice::None; |
38 |
|
|
m_pAudioItems = NULL; |
39 |
|
|
m_pMidiItems = NULL; |
40 |
|
|
// No exclusive mode as default. |
41 |
|
|
m_deviceTypeMode = qsamplerDevice::None; |
42 |
|
|
|
43 |
|
|
ui.DeviceParamTable->setModel(&deviceParamModel); |
44 |
|
|
ui.DeviceParamTable->setItemDelegate(&deviceParamDelegate); |
45 |
|
|
|
46 |
|
|
ui.DevicePortParamTable->setModel(&devicePortParamModel); |
47 |
|
|
ui.DevicePortParamTable->setItemDelegate(&devicePortParamDelegate); |
48 |
|
|
|
49 |
|
|
// This an outsider (from designer), but rather important. |
50 |
|
|
//QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)), |
51 |
|
|
// this, SLOT(changeDeviceParam(int,int))); |
52 |
|
|
//QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)), |
53 |
|
|
// this, SLOT(changeDevicePortParam(int,int))); |
54 |
|
|
|
55 |
|
|
// Initial contents. |
56 |
|
|
refreshDevices(); |
57 |
|
|
// Try to restore normal window positioning. |
58 |
|
|
adjustSize(); |
59 |
capela |
1466 |
|
60 |
|
|
QObject::connect(ui.DeviceListView, |
61 |
schoenebeck |
1470 |
SIGNAL(itemSelectionChanged()), |
62 |
capela |
1466 |
SLOT(selectDevice())); |
63 |
|
|
QObject::connect(ui.DeviceListView, |
64 |
schoenebeck |
1470 |
SIGNAL(customContextMenuRequested(const QPoint&)), |
65 |
|
|
SLOT(deviceListViewContextMenu(const QPoint&))); |
66 |
capela |
1466 |
QObject::connect(ui.RefreshDevicesPushButton, |
67 |
|
|
SIGNAL(clicked()), |
68 |
|
|
SLOT(refreshDevices())); |
69 |
|
|
QObject::connect(ui.DriverNameComboBox, |
70 |
schoenebeck |
1470 |
SIGNAL(activated(const QString&)), |
71 |
|
|
SLOT(selectDriver(const QString&))); |
72 |
capela |
1466 |
QObject::connect(ui.DevicePortComboBox, |
73 |
|
|
SIGNAL(activated(int)), |
74 |
|
|
SLOT(selectDevicePort(int))); |
75 |
|
|
QObject::connect(ui.CreateDevicePushButton, |
76 |
|
|
SIGNAL(clicked()), |
77 |
|
|
SLOT(createDevice())); |
78 |
|
|
QObject::connect(ui.DeleteDevicePushButton, |
79 |
|
|
SIGNAL(clicked()), |
80 |
|
|
SLOT(deleteDevice())); |
81 |
|
|
QObject::connect(ui.ClosePushButton, |
82 |
|
|
SIGNAL(clicked()), |
83 |
|
|
SLOT(close())); |
84 |
schoenebeck |
1461 |
} |
85 |
|
|
|
86 |
|
|
DeviceForm::~DeviceForm() { |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
|
90 |
|
|
// Notify our parent that we're emerging. |
91 |
|
|
void DeviceForm::showEvent ( QShowEvent *pShowEvent ) |
92 |
|
|
{ |
93 |
|
|
MainForm* pMainForm = MainForm::getInstance(); |
94 |
|
|
if (pMainForm) |
95 |
|
|
pMainForm->stabilizeForm(); |
96 |
|
|
|
97 |
|
|
stabilizeForm(); |
98 |
|
|
|
99 |
|
|
QWidget::showEvent(pShowEvent); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
|
103 |
|
|
// Notify our parent that we're closing. |
104 |
|
|
void DeviceForm::hideEvent ( QHideEvent *pHideEvent ) |
105 |
|
|
{ |
106 |
|
|
QWidget::hideEvent(pHideEvent); |
107 |
|
|
|
108 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
109 |
|
|
if (pMainForm) |
110 |
|
|
pMainForm->stabilizeForm(); |
111 |
|
|
|
112 |
|
|
// Signal special whether we changed the device set. |
113 |
|
|
if (m_iDirtyCount > 0) { |
114 |
|
|
m_iDirtyCount = 0; |
115 |
|
|
emit devicesChanged(); |
116 |
|
|
} |
117 |
|
|
} |
118 |
|
|
|
119 |
|
|
|
120 |
|
|
// Set device type spacial exclusive mode. |
121 |
|
|
void DeviceForm::setDeviceTypeMode ( |
122 |
|
|
qsamplerDevice::qsamplerDeviceType deviceTypeMode ) |
123 |
|
|
{ |
124 |
|
|
// If it has not changed, do nothing. |
125 |
|
|
if (m_deviceTypeMode == deviceTypeMode) |
126 |
|
|
return; |
127 |
|
|
|
128 |
|
|
m_deviceTypeMode = deviceTypeMode; |
129 |
|
|
|
130 |
|
|
// OK. Do a whole refresh around. |
131 |
|
|
refreshDevices(); |
132 |
|
|
} |
133 |
|
|
|
134 |
|
|
|
135 |
|
|
// Device driver name setup formal initializer. |
136 |
|
|
void DeviceForm::setDriverName ( const QString& sDriverName ) |
137 |
|
|
{ |
138 |
schoenebeck |
1474 |
if (ui.DriverNameComboBox->findText(sDriverName) < 0) { |
139 |
schoenebeck |
1461 |
ui.DriverNameComboBox->insertItem(sDriverName); |
140 |
|
|
} |
141 |
|
|
ui.DriverNameComboBox->setCurrentText(sDriverName); |
142 |
|
|
} |
143 |
|
|
|
144 |
|
|
|
145 |
|
|
// Set current selected device by type and id. |
146 |
|
|
void DeviceForm::setDevice ( qsamplerDevice *pDevice ) |
147 |
|
|
{ |
148 |
|
|
// In case no device is given... |
149 |
|
|
qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode; |
150 |
|
|
if (pDevice) |
151 |
|
|
deviceType = pDevice->deviceType(); |
152 |
|
|
|
153 |
|
|
// Get the device view root item... |
154 |
|
|
qsamplerDeviceItem *pRootItem = NULL; |
155 |
|
|
switch (deviceType) { |
156 |
|
|
case qsamplerDevice::Audio: |
157 |
|
|
pRootItem = m_pAudioItems; |
158 |
|
|
break; |
159 |
|
|
case qsamplerDevice::Midi: |
160 |
|
|
pRootItem = m_pMidiItems; |
161 |
|
|
break; |
162 |
|
|
case qsamplerDevice::None: |
163 |
|
|
break; |
164 |
|
|
} |
165 |
|
|
|
166 |
|
|
// Is the root present? |
167 |
|
|
if (pRootItem == NULL) |
168 |
|
|
return; |
169 |
|
|
|
170 |
|
|
// So there's no device huh? |
171 |
|
|
if (pDevice == NULL) { |
172 |
|
|
ui.DeviceListView->setCurrentItem(pRootItem); |
173 |
|
|
return; |
174 |
|
|
} |
175 |
|
|
|
176 |
|
|
// For each child, test for identity... |
177 |
|
|
for (int i = 0; i < pRootItem->childCount(); i++) { |
178 |
|
|
qsamplerDeviceItem* pDeviceItem = |
179 |
|
|
(qsamplerDeviceItem*) pRootItem->child(i); |
180 |
|
|
|
181 |
|
|
// If identities match, select as current device item. |
182 |
|
|
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
183 |
|
|
pDeviceItem->setSelected(true); |
184 |
|
|
break; |
185 |
|
|
} |
186 |
|
|
} |
187 |
|
|
} |
188 |
|
|
|
189 |
|
|
|
190 |
|
|
|
191 |
|
|
// Create a new device from current table view. |
192 |
|
|
void DeviceForm::createDevice (void) |
193 |
|
|
{ |
194 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
195 |
|
|
if (pMainForm == NULL) |
196 |
|
|
return; |
197 |
|
|
|
198 |
|
|
QTreeWidgetItem *pItem = ui.DeviceListView->currentItem(); |
199 |
|
|
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
200 |
|
|
return; |
201 |
|
|
|
202 |
|
|
// About a brand new device instance... |
203 |
|
|
qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device()); |
204 |
|
|
if (device.createDevice()) { |
205 |
|
|
// Now it depends on the device type... |
206 |
|
|
qsamplerDeviceItem *pRootItem = NULL; |
207 |
|
|
switch (device.deviceType()) { |
208 |
|
|
case qsamplerDevice::Audio: |
209 |
|
|
pRootItem = m_pAudioItems; |
210 |
|
|
break; |
211 |
|
|
case qsamplerDevice::Midi: |
212 |
|
|
pRootItem = m_pMidiItems; |
213 |
|
|
break; |
214 |
|
|
case qsamplerDevice::None: |
215 |
|
|
break; |
216 |
|
|
} |
217 |
|
|
// Append the new device item. |
218 |
|
|
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
219 |
|
|
device.deviceType(), device.deviceID()); |
220 |
|
|
// Just make it the new selection... |
221 |
|
|
pDeviceItem->setSelected(true); |
222 |
|
|
// Main session should be marked dirty. |
223 |
|
|
pMainForm->sessionDirty(); |
224 |
|
|
m_iDirtyCount++; |
225 |
|
|
} |
226 |
|
|
} |
227 |
|
|
|
228 |
|
|
|
229 |
|
|
// Delete current device in table view. |
230 |
|
|
void DeviceForm::deleteDevice (void) |
231 |
|
|
{ |
232 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
233 |
|
|
if (pMainForm == NULL) |
234 |
|
|
return; |
235 |
|
|
|
236 |
|
|
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
237 |
|
|
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
238 |
|
|
return; |
239 |
|
|
|
240 |
|
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
241 |
|
|
|
242 |
|
|
// Prompt user if this is for real... |
243 |
|
|
qsamplerOptions *pOptions = pMainForm->options(); |
244 |
|
|
if (pOptions && pOptions->bConfirmRemove) { |
245 |
|
|
if (QMessageBox::warning(this, |
246 |
|
|
QSAMPLER_TITLE ": " + tr("Warning"), |
247 |
|
|
tr("Delete device:\n\n" |
248 |
|
|
"%1\n\n" |
249 |
|
|
"Are you sure?") |
250 |
|
|
.arg(device.deviceName()), |
251 |
|
|
tr("OK"), tr("Cancel")) > 0) |
252 |
|
|
return; |
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
// Go and destroy... |
256 |
|
|
if (device.deleteDevice()) { |
257 |
|
|
// Remove it from the device view... |
258 |
|
|
delete pItem; |
259 |
|
|
// Main session should be marked dirty. |
260 |
|
|
pMainForm->sessionDirty(); |
261 |
|
|
m_iDirtyCount++; |
262 |
|
|
} |
263 |
|
|
} |
264 |
|
|
|
265 |
|
|
|
266 |
|
|
// Refresh all device list and views. |
267 |
|
|
void DeviceForm::refreshDevices (void) |
268 |
|
|
{ |
269 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
270 |
|
|
if (pMainForm == NULL) |
271 |
|
|
return; |
272 |
|
|
|
273 |
|
|
// Avoid nested changes. |
274 |
|
|
m_iDirtySetup++; |
275 |
|
|
|
276 |
|
|
// |
277 |
|
|
// (Re)Load complete device configuration data ... |
278 |
|
|
// |
279 |
|
|
m_pAudioItems = NULL; |
280 |
|
|
m_pMidiItems = NULL; |
281 |
|
|
ui.DeviceListView->clear(); |
282 |
|
|
if (pMainForm->client()) { |
283 |
|
|
int *piDeviceIDs; |
284 |
|
|
// Grab and pop Audio devices... |
285 |
|
|
if (m_deviceTypeMode == qsamplerDevice::None || |
286 |
|
|
m_deviceTypeMode == qsamplerDevice::Audio) { |
287 |
|
|
m_pAudioItems = new qsamplerDeviceItem(ui.DeviceListView, |
288 |
|
|
qsamplerDevice::Audio); |
289 |
|
|
} |
290 |
|
|
if (m_pAudioItems) { |
291 |
|
|
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
292 |
|
|
qsamplerDevice::Audio); |
293 |
|
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
294 |
|
|
new qsamplerDeviceItem(m_pAudioItems, |
295 |
|
|
qsamplerDevice::Audio, piDeviceIDs[i]); |
296 |
|
|
} |
297 |
|
|
m_pAudioItems->setExpanded(true); |
298 |
|
|
} |
299 |
|
|
// Grab and pop MIDI devices... |
300 |
|
|
if (m_deviceTypeMode == qsamplerDevice::None || |
301 |
|
|
m_deviceTypeMode == qsamplerDevice::Midi) { |
302 |
|
|
m_pMidiItems = new qsamplerDeviceItem(ui.DeviceListView, |
303 |
|
|
qsamplerDevice::Midi); |
304 |
|
|
} |
305 |
|
|
if (m_pMidiItems) { |
306 |
|
|
piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), |
307 |
|
|
qsamplerDevice::Midi); |
308 |
|
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
309 |
|
|
new qsamplerDeviceItem(m_pMidiItems, |
310 |
|
|
qsamplerDevice::Midi, piDeviceIDs[i]); |
311 |
|
|
} |
312 |
|
|
m_pMidiItems->setExpanded(true); |
313 |
|
|
} |
314 |
|
|
} |
315 |
|
|
|
316 |
|
|
// Done. |
317 |
|
|
m_iDirtySetup--; |
318 |
|
|
|
319 |
|
|
// Show something. |
320 |
|
|
selectDevice(); |
321 |
|
|
} |
322 |
|
|
|
323 |
|
|
|
324 |
|
|
// Driver selection slot. |
325 |
|
|
void DeviceForm::selectDriver ( const QString& sDriverName ) |
326 |
|
|
{ |
327 |
|
|
if (m_iDirtySetup > 0) |
328 |
|
|
return; |
329 |
|
|
|
330 |
|
|
// |
331 |
|
|
// Driver name has changed for a new device... |
332 |
|
|
// |
333 |
|
|
|
334 |
|
|
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
335 |
|
|
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
336 |
|
|
return; |
337 |
|
|
|
338 |
|
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
339 |
|
|
|
340 |
|
|
// Driver change is only valid for scratch devices... |
341 |
|
|
if (m_bNewDevice) { |
342 |
|
|
m_iDirtySetup++; |
343 |
|
|
device.setDriver(sDriverName); |
344 |
|
|
deviceParamModel.refresh(device.params(), m_bNewDevice); |
345 |
|
|
m_iDirtySetup--; |
346 |
|
|
// Done. |
347 |
|
|
stabilizeForm(); |
348 |
|
|
} |
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
|
352 |
|
|
// Device selection slot. |
353 |
|
|
void DeviceForm::selectDevice (void) |
354 |
|
|
{ |
355 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
356 |
|
|
if (pMainForm == NULL) |
357 |
|
|
return; |
358 |
|
|
|
359 |
|
|
if (m_iDirtySetup > 0) |
360 |
|
|
return; |
361 |
|
|
|
362 |
|
|
// |
363 |
|
|
// Device selection has changed... |
364 |
|
|
// |
365 |
|
|
|
366 |
|
|
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
367 |
|
|
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) { |
368 |
|
|
m_deviceType = qsamplerDevice::None; |
369 |
|
|
ui.DeviceNameTextLabel->setText(QString::null); |
370 |
|
|
deviceParamModel.clear(); |
371 |
|
|
ui.DevicePortComboBox->clear(); |
372 |
|
|
devicePortParamModel.clear(); |
373 |
|
|
ui.DevicePortTextLabel->setEnabled(false); |
374 |
|
|
ui.DevicePortComboBox->setEnabled(false); |
375 |
|
|
ui.DevicePortParamTable->setEnabled(false); |
376 |
|
|
stabilizeForm(); |
377 |
|
|
return; |
378 |
|
|
} |
379 |
|
|
|
380 |
|
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
381 |
|
|
|
382 |
|
|
m_iDirtySetup++; |
383 |
|
|
// Flag whether this is a new device. |
384 |
|
|
m_bNewDevice = (device.deviceID() < 0); |
385 |
|
|
|
386 |
|
|
// Fill the device/driver heading... |
387 |
|
|
ui.DeviceNameTextLabel->setText(device.deviceName()); |
388 |
|
|
// The driver combobox is only rebuilt if device type has changed... |
389 |
|
|
if (device.deviceType() != m_deviceType) { |
390 |
|
|
ui.DriverNameComboBox->clear(); |
391 |
|
|
ui.DriverNameComboBox->insertStringList( |
392 |
|
|
qsamplerDevice::getDrivers(pMainForm->client(), device.deviceType())); |
393 |
|
|
m_deviceType = device.deviceType(); |
394 |
|
|
} |
395 |
|
|
// Do we need a driver name? |
396 |
|
|
if (m_bNewDevice || device.driverName().isEmpty()) |
397 |
|
|
device.setDriver(ui.DriverNameComboBox->currentText()); |
398 |
|
|
setDriverName(device.driverName()); |
399 |
|
|
ui.DriverNameTextLabel->setEnabled(m_bNewDevice); |
400 |
|
|
ui.DriverNameComboBox->setEnabled(m_bNewDevice); |
401 |
|
|
// Fill the device parameter table... |
402 |
|
|
deviceParamModel.refresh(device.params(), m_bNewDevice); |
403 |
|
|
// And now the device port/channel parameter table... |
404 |
|
|
switch (device.deviceType()) { |
405 |
|
|
case qsamplerDevice::Audio: |
406 |
|
|
ui.DevicePortTextLabel->setText(tr("Ch&annel:")); |
407 |
|
|
break; |
408 |
|
|
case qsamplerDevice::Midi: |
409 |
|
|
ui.DevicePortTextLabel->setText(tr("P&ort:")); |
410 |
|
|
break; |
411 |
|
|
case qsamplerDevice::None: |
412 |
|
|
break; |
413 |
|
|
} |
414 |
|
|
ui.DevicePortComboBox->clear(); |
415 |
|
|
devicePortParamModel.clear(); |
416 |
|
|
if (m_bNewDevice) { |
417 |
|
|
ui.DevicePortTextLabel->setEnabled(false); |
418 |
|
|
ui.DevicePortComboBox->setEnabled(false); |
419 |
|
|
ui.DevicePortParamTable->setEnabled(false); |
420 |
|
|
} else { |
421 |
|
|
QPixmap pixmap; |
422 |
|
|
switch (device.deviceType()) { |
423 |
|
|
case qsamplerDevice::Audio: |
424 |
|
|
pixmap = QPixmap(":/qsampler/pixmaps/audio2.png"); |
425 |
|
|
break; |
426 |
|
|
case qsamplerDevice::Midi: |
427 |
|
|
pixmap = QPixmap(":/qsampler/pixmaps/midi2.png"); |
428 |
|
|
break; |
429 |
|
|
case qsamplerDevice::None: |
430 |
|
|
break; |
431 |
|
|
} |
432 |
|
|
qsamplerDevicePortList& ports = device.ports(); |
433 |
|
|
qsamplerDevicePort *pPort; |
434 |
|
|
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
435 |
|
|
ui.DevicePortComboBox->insertItem(pixmap, device.deviceTypeName() |
436 |
|
|
+ ' ' + device.driverName() |
437 |
|
|
+ ' ' + pPort->portName()); |
438 |
|
|
} |
439 |
|
|
bool bEnabled = (ports.count() > 0); |
440 |
|
|
ui.DevicePortTextLabel->setEnabled(bEnabled); |
441 |
|
|
ui.DevicePortComboBox->setEnabled(bEnabled); |
442 |
|
|
ui.DevicePortParamTable->setEnabled(bEnabled); |
443 |
|
|
} |
444 |
|
|
// Done. |
445 |
|
|
m_iDirtySetup--; |
446 |
|
|
|
447 |
|
|
// Make the device port/channel selection effective. |
448 |
|
|
selectDevicePort(ui.DevicePortComboBox->currentItem()); |
449 |
|
|
} |
450 |
|
|
|
451 |
|
|
|
452 |
|
|
// Device port/channel selection slot. |
453 |
|
|
void DeviceForm::selectDevicePort ( int iPort ) |
454 |
|
|
{ |
455 |
|
|
if (m_iDirtySetup > 0) |
456 |
|
|
return; |
457 |
|
|
|
458 |
|
|
// |
459 |
|
|
// Device port/channel selection has changed... |
460 |
|
|
// |
461 |
|
|
|
462 |
|
|
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
463 |
|
|
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
464 |
|
|
return; |
465 |
|
|
|
466 |
|
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
467 |
|
|
qsamplerDevicePort *pPort = device.ports().at(iPort); |
468 |
|
|
if (pPort) { |
469 |
|
|
m_iDirtySetup++; |
470 |
|
|
devicePortParamModel.refresh(pPort->params(), false); |
471 |
|
|
m_iDirtySetup--; |
472 |
|
|
} |
473 |
|
|
// Done. |
474 |
|
|
stabilizeForm(); |
475 |
|
|
} |
476 |
|
|
|
477 |
|
|
|
478 |
|
|
// Device parameter value change slot. |
479 |
|
|
void DeviceForm::changeDeviceParam ( int iRow, int iCol ) |
480 |
|
|
{ |
481 |
|
|
if (m_iDirtySetup > 0) |
482 |
|
|
return; |
483 |
|
|
if (iRow < 0 || iCol < 0) |
484 |
|
|
return; |
485 |
|
|
|
486 |
|
|
// |
487 |
|
|
// Device parameter change... |
488 |
|
|
// |
489 |
|
|
|
490 |
|
|
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
491 |
|
|
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
492 |
|
|
return; |
493 |
|
|
|
494 |
|
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
495 |
|
|
|
496 |
|
|
// Table 1st column has the parameter name; |
497 |
|
|
//const QString sParam = ui.DeviceParamTable->text(iRow, 0); |
498 |
|
|
//const QString sValue = ui.DeviceParamTable->text(iRow, iCol); |
499 |
|
|
const QString sParam = deviceParamModel.data(deviceParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name; |
500 |
|
|
const QString sValue = deviceParamModel.data(deviceParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value; |
501 |
|
|
// Set the local device parameter value. |
502 |
|
|
if (device.setParam(sParam, sValue)) { |
503 |
|
|
selectDevice(); |
504 |
|
|
} else { |
505 |
|
|
stabilizeForm(); |
506 |
|
|
} |
507 |
|
|
|
508 |
|
|
// Main session should be dirtier... |
509 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
510 |
|
|
if (pMainForm) |
511 |
|
|
pMainForm->sessionDirty(); |
512 |
|
|
} |
513 |
|
|
|
514 |
|
|
|
515 |
|
|
// Device port/channel parameter value change slot. |
516 |
|
|
void DeviceForm::changeDevicePortParam ( int iRow, int iCol ) |
517 |
|
|
{ |
518 |
|
|
if (m_iDirtySetup > 0) |
519 |
|
|
return; |
520 |
|
|
if (iRow < 0 || iCol < 0) |
521 |
|
|
return; |
522 |
|
|
|
523 |
|
|
// |
524 |
|
|
// Device port/channel parameter change... |
525 |
|
|
// |
526 |
|
|
|
527 |
|
|
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
528 |
|
|
if (pItem == NULL || pItem->type() != QSAMPLER_DEVICE_ITEM) |
529 |
|
|
return; |
530 |
|
|
|
531 |
|
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
532 |
|
|
|
533 |
|
|
int iPort = ui.DevicePortComboBox->currentItem(); |
534 |
|
|
qsamplerDevicePort *pPort = device.ports().at(iPort); |
535 |
|
|
if (pPort == NULL) |
536 |
|
|
return; |
537 |
|
|
|
538 |
|
|
// Table 1st column has the parameter name; |
539 |
|
|
//const QString sParam = ui.DevicePortParamTable->text(iRow, 0); |
540 |
|
|
//const QString sValue = ui.DevicePortParamTable->text(iRow, iCol); |
541 |
|
|
const QString sParam = devicePortParamModel.data(devicePortParamModel.index(iRow, 0), Qt::DisplayRole).value<DeviceParameterRow>().name; |
542 |
|
|
const QString sValue = devicePortParamModel.data(devicePortParamModel.index(iRow, iCol), Qt::DisplayRole).value<DeviceParameterRow>().param.value; |
543 |
|
|
|
544 |
|
|
// Set the local device port/channel parameter value. |
545 |
|
|
pPort->setParam(sParam, sValue); |
546 |
|
|
// Done. |
547 |
|
|
stabilizeForm(); |
548 |
|
|
|
549 |
|
|
// Main session should be dirtier... |
550 |
|
|
MainForm* pMainForm = MainForm::getInstance(); |
551 |
|
|
if (pMainForm) |
552 |
|
|
pMainForm->sessionDirty(); |
553 |
|
|
} |
554 |
|
|
|
555 |
|
|
|
556 |
|
|
// Device list view context menu handler. |
557 |
schoenebeck |
1470 |
void DeviceForm::deviceListViewContextMenu ( const QPoint& pos ) |
558 |
schoenebeck |
1461 |
{ |
559 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
560 |
|
|
if (pMainForm == NULL) |
561 |
|
|
return; |
562 |
|
|
|
563 |
schoenebeck |
1470 |
QTreeWidgetItem* pItem = ui.DeviceListView->itemAt(pos); |
564 |
|
|
if (pItem == NULL) |
565 |
|
|
return; |
566 |
|
|
|
567 |
schoenebeck |
1461 |
int iItemID; |
568 |
|
|
|
569 |
|
|
// Build the device context menu... |
570 |
|
|
QMenu* pContextMenu = new QMenu(this); |
571 |
|
|
|
572 |
|
|
bool bClient = (pMainForm->client() != NULL); |
573 |
|
|
bool bEnabled = (pItem != NULL); |
574 |
|
|
iItemID = pContextMenu->insertItem( |
575 |
|
|
QIconSet(QPixmap(":/qsampler/pixmaps/deviceCreate.png")), |
576 |
|
|
tr("&Create device"), this, SLOT(createDevice())); |
577 |
|
|
pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice)); |
578 |
|
|
iItemID = pContextMenu->insertItem( |
579 |
|
|
QIconSet(QPixmap(":/qsampler/pixmaps/deviceDelete.png")), |
580 |
|
|
tr("&Delete device"), this, SLOT(deleteDevice())); |
581 |
|
|
pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice); |
582 |
|
|
pContextMenu->insertSeparator(); |
583 |
|
|
iItemID = pContextMenu->insertItem( |
584 |
|
|
QIconSet(QPixmap(":/qsampler/pixmaps/formRefresh.png")), |
585 |
|
|
tr("&Refresh"), this, SLOT(refreshDevices())); |
586 |
|
|
pContextMenu->setItemEnabled(iItemID, bClient); |
587 |
|
|
|
588 |
|
|
pContextMenu->exec(pos); |
589 |
|
|
|
590 |
|
|
delete pContextMenu; |
591 |
|
|
} |
592 |
|
|
|
593 |
|
|
|
594 |
|
|
// Stabilize current form state. |
595 |
|
|
void DeviceForm::stabilizeForm (void) |
596 |
|
|
{ |
597 |
|
|
MainForm* pMainForm = MainForm::getInstance(); |
598 |
|
|
QTreeWidgetItem* pItem = ui.DeviceListView->currentItem(); |
599 |
|
|
bool bClient = (pMainForm && pMainForm->client() != NULL); |
600 |
|
|
bool bEnabled = (pItem != NULL); |
601 |
|
|
ui.DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); |
602 |
|
|
ui.DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
603 |
|
|
ui.DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
604 |
|
|
ui.DeviceParamTable->setEnabled(bEnabled); |
605 |
|
|
ui.RefreshDevicesPushButton->setEnabled(bClient); |
606 |
|
|
ui.CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
607 |
|
|
ui.DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); |
608 |
|
|
} |
609 |
|
|
|
610 |
|
|
} // namespace QSampler |
611 |
capela |
1464 |
|
612 |
|
|
|
613 |
|
|
// end of qsamplerDeviceForm.cpp |