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