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