2 |
// |
// |
3 |
// ui.h extension file, included from the uic-generated form implementation. |
// ui.h extension file, included from the uic-generated form implementation. |
4 |
/**************************************************************************** |
/**************************************************************************** |
5 |
Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
|
#include "qsamplerMainForm.h" |
25 |
|
|
26 |
#include <qmessagebox.h> |
#include <qmessagebox.h> |
27 |
#include <qfiledialog.h> |
#include <qfiledialog.h> |
28 |
#include <qfileinfo.h> |
#include <qfileinfo.h> |
29 |
|
#include <qlistbox.h> |
30 |
#include "qsamplerMainForm.h" |
#include <qptrlist.h> |
31 |
|
#include <qpopupmenu.h> |
|
#include "config.h" |
|
32 |
|
|
33 |
|
|
34 |
// Kind of constructor. |
// Kind of constructor. |
35 |
void qsamplerDeviceForm::init (void) |
void qsamplerDeviceForm::init (void) |
36 |
{ |
{ |
37 |
// Initialize locals. |
// Initialize locals. |
38 |
m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); |
m_pMainForm = NULL; |
39 |
m_pClient = NULL; |
m_pClient = NULL; |
40 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
41 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
42 |
m_iUntitled = 1; |
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 |
|
// 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 |
// Try to restore normal window positioning. |
// Initial contents. |
56 |
adjustSize(); |
refreshDevices(); |
57 |
|
// Try to restore normal window positioning. |
58 |
|
adjustSize(); |
59 |
} |
} |
60 |
|
|
61 |
|
|
68 |
// Notify our parent that we're emerging. |
// Notify our parent that we're emerging. |
69 |
void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent ) |
void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent ) |
70 |
{ |
{ |
71 |
if (m_pMainForm) |
if (m_pMainForm) |
72 |
m_pMainForm->stabilizeForm(); |
m_pMainForm->stabilizeForm(); |
73 |
|
|
74 |
stabilizeForm(); |
stabilizeForm(); |
75 |
|
|
76 |
QWidget::showEvent(pShowEvent); |
QWidget::showEvent(pShowEvent); |
77 |
} |
} |
78 |
|
|
79 |
|
|
80 |
// Notify our parent that we're closing. |
// Notify our parent that we're closing. |
81 |
void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent ) |
void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent ) |
82 |
{ |
{ |
83 |
QWidget::hideEvent(pHideEvent); |
QWidget::hideEvent(pHideEvent); |
84 |
|
|
85 |
|
if (m_pMainForm) |
86 |
|
m_pMainForm->stabilizeForm(); |
87 |
|
|
88 |
|
// Signal special whether we changed the device set. |
89 |
|
if (m_iDirtyCount > 0) { |
90 |
|
m_iDirtyCount = 0; |
91 |
|
emit devicesChanged(); |
92 |
|
} |
93 |
|
} |
94 |
|
|
95 |
|
|
96 |
|
// Application main form settler (life depends on it). |
97 |
|
void qsamplerDeviceForm::setMainForm ( qsamplerMainForm *pMainForm ) |
98 |
|
{ |
99 |
|
m_pMainForm = pMainForm; |
100 |
|
} |
101 |
|
|
102 |
|
|
103 |
|
// Set device type spacial exclusive mode. |
104 |
|
void qsamplerDeviceForm::setDeviceTypeMode ( |
105 |
|
qsamplerDevice::qsamplerDeviceType deviceTypeMode ) |
106 |
|
{ |
107 |
|
// If it has not changed, do nothing. |
108 |
|
if (m_deviceTypeMode == deviceTypeMode) |
109 |
|
return; |
110 |
|
|
111 |
|
m_deviceTypeMode = deviceTypeMode; |
112 |
|
|
113 |
if (m_pMainForm) |
// OK. Do a whole refresh around. |
114 |
m_pMainForm->stabilizeForm(); |
refreshDevices(); |
115 |
} |
} |
116 |
|
|
117 |
|
|
120 |
{ |
{ |
121 |
// If it has not changed, do nothing. |
// If it has not changed, do nothing. |
122 |
if (m_pClient && m_pClient == pClient) |
if (m_pClient && m_pClient == pClient) |
123 |
return; |
return; |
124 |
|
|
125 |
// Set new reference. |
// Set new reference. |
126 |
m_pClient = pClient; |
m_pClient = pClient; |
127 |
|
|
128 |
// OK. Do a whole refresh around. |
// OK. Do a whole refresh around. |
129 |
refreshDevices(); |
refreshDevices(); |
130 |
} |
} |
131 |
|
|
132 |
|
|
133 |
// Format the displayable device configuration filename. |
// Device driver name setup formal initializer. |
134 |
QString qsamplerDeviceForm::devicesName ( const QString& sFilename ) |
void qsamplerDeviceForm::setDriverName ( const QString& sDriverName ) |
135 |
{ |
{ |
136 |
QString sDevicesName = sFilename; |
if (DriverNameComboBox->listBox()->findItem(sDriverName, |
137 |
qsamplerOptions *pOptions = m_pMainForm->options(); |
Qt::ExactMatch | Qt::CaseSensitive) == NULL) { |
138 |
if (pOptions) { |
DriverNameComboBox->insertItem(sDriverName); |
|
bool bCompletePath = (pOptions && pOptions->bCompletePath); |
|
|
if (sDevicesName.isEmpty()) |
|
|
sDevicesName = tr("Untitled") + QString::number(m_iUntitled); |
|
|
else if (!bCompletePath) |
|
|
sDevicesName = QFileInfo(sDevicesName).fileName(); |
|
139 |
} |
} |
140 |
return sDevicesName; |
DriverNameComboBox->setCurrentText(sDriverName); |
141 |
} |
} |
142 |
|
|
143 |
|
|
144 |
// Window close event handlers. |
// Set current selected device by type and id. |
145 |
bool qsamplerDeviceForm::queryClose (void) |
void qsamplerDeviceForm::setDevice ( qsamplerDevice *pDevice ) |
146 |
{ |
{ |
147 |
bool bQueryClose = true; |
// In case no device is given... |
148 |
|
qsamplerDevice::qsamplerDeviceType deviceType = m_deviceTypeMode; |
149 |
|
if (pDevice) |
150 |
|
deviceType = pDevice->deviceType(); |
151 |
|
|
152 |
|
// Get the device view root item... |
153 |
|
qsamplerDeviceItem *pRootItem = NULL; |
154 |
|
switch (deviceType) { |
155 |
|
case qsamplerDevice::Audio: |
156 |
|
pRootItem = m_pAudioItems; |
157 |
|
break; |
158 |
|
case qsamplerDevice::Midi: |
159 |
|
pRootItem = m_pMidiItems; |
160 |
|
break; |
161 |
|
case qsamplerDevice::None: |
162 |
|
break; |
163 |
|
} |
164 |
|
|
165 |
if (m_iDirtyCount > 0) { |
// Is the root present? |
166 |
switch (QMessageBox::warning(this, tr("Warning"), |
if (pRootItem == NULL) |
167 |
tr("The device configuration has been changed.\n\n" |
return; |
168 |
"\"%1\"\n\n" |
|
169 |
"Do you want to save the changes?") |
// So there's no device huh? |
170 |
.arg(devicesName(m_sFilename)), |
if (pDevice == NULL) { |
171 |
tr("Save"), tr("Discard"), tr("Cancel"))) { |
DeviceListView->setSelected(pRootItem, true); |
172 |
case 0: // Save... |
return; |
173 |
saveDevices(); |
} |
|
// Fall thru.... |
|
|
case 1: // Discard |
|
|
break; |
|
|
default: // Cancel. |
|
|
bQueryClose = false; |
|
|
} |
|
|
} |
|
174 |
|
|
175 |
return bQueryClose; |
// For each child, test for identity... |
176 |
|
qsamplerDeviceItem *pDeviceItem = |
177 |
|
(qsamplerDeviceItem *) pRootItem->firstChild(); |
178 |
|
while (pDeviceItem) { |
179 |
|
// If identities match, select as current device item. |
180 |
|
if (pDeviceItem->device().deviceID() == pDevice->deviceID()) { |
181 |
|
DeviceListView->setSelected(pDeviceItem, true); |
182 |
|
break; |
183 |
|
} |
184 |
|
pDeviceItem = (qsamplerDeviceItem *) pDeviceItem->nextSibling(); |
185 |
|
} |
186 |
} |
} |
187 |
|
|
188 |
|
|
189 |
|
|
190 |
// Dirty up settings. |
// Create a new device from current table view. |
191 |
void qsamplerDeviceForm::contentsChanged (void) |
void qsamplerDeviceForm::createDevice (void) |
192 |
{ |
{ |
193 |
if (m_iDirtySetup > 0) |
if (m_pMainForm == NULL) |
194 |
return; |
return; |
195 |
|
|
196 |
m_iDirtyCount++; |
QListViewItem *pItem = DeviceListView->selectedItem(); |
197 |
stabilizeForm(); |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
198 |
|
return; |
199 |
|
|
200 |
|
// About a brand new device instance... |
201 |
|
qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device()); |
202 |
|
if (device.createDevice()) { |
203 |
|
// Now it depends on the device type... |
204 |
|
qsamplerDeviceItem *pRootItem = NULL; |
205 |
|
switch (device.deviceType()) { |
206 |
|
case qsamplerDevice::Audio: |
207 |
|
pRootItem = m_pAudioItems; |
208 |
|
break; |
209 |
|
case qsamplerDevice::Midi: |
210 |
|
pRootItem = m_pMidiItems; |
211 |
|
break; |
212 |
|
case qsamplerDevice::None: |
213 |
|
break; |
214 |
|
} |
215 |
|
// Append the new device item. |
216 |
|
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
217 |
|
m_pMainForm, device.deviceType(), device.deviceID()); |
218 |
|
// Just make it the new selection... |
219 |
|
DeviceListView->setSelected(pDeviceItem, true); |
220 |
|
// Main session should be marked dirty. |
221 |
|
m_pMainForm->sessionDirty(); |
222 |
|
m_iDirtyCount++; |
223 |
|
} |
224 |
} |
} |
225 |
|
|
226 |
|
|
227 |
// Load device configuration slot. |
// Delete current device in table view. |
228 |
void qsamplerDeviceForm::loadDevices (void) |
void qsamplerDeviceForm::deleteDevice (void) |
229 |
{ |
{ |
230 |
QString sFilename = QFileDialog::getOpenFileName( |
if (m_pMainForm == NULL) |
231 |
m_sFilename, // Start here. |
return; |
|
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
|
|
this, 0, // Parent and name (none) |
|
|
tr("Load Device Configuration") // Caption. |
|
|
); |
|
|
|
|
|
if (sFilename.isEmpty()) |
|
|
return; |
|
232 |
|
|
233 |
// Check if we're going to discard safely the current one... |
QListViewItem *pItem = DeviceListView->selectedItem(); |
234 |
if (!queryClose()) |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
235 |
return; |
return; |
236 |
|
|
237 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
238 |
|
|
239 |
|
// Prompt user if this is for real... |
240 |
|
qsamplerOptions *pOptions = m_pMainForm->options(); |
241 |
|
if (pOptions && pOptions->bConfirmRemove) { |
242 |
|
if (QMessageBox::warning(this, |
243 |
|
QSAMPLER_TITLE ": " + tr("Warning"), |
244 |
|
tr("Delete device:\n\n" |
245 |
|
"%1\n\n" |
246 |
|
"Are you sure?") |
247 |
|
.arg(device.deviceName()), |
248 |
|
tr("OK"), tr("Cancel")) > 0) |
249 |
|
return; |
250 |
|
} |
251 |
|
|
252 |
// Load it right away... |
// Go and destroy... |
253 |
loadDevicesFile(sFilename); |
if (device.deleteDevice()) { |
254 |
|
// Remove it from the device view... |
255 |
|
delete pItem; |
256 |
|
// Main session should be marked dirty. |
257 |
|
m_pMainForm->sessionDirty(); |
258 |
|
m_iDirtyCount++; |
259 |
|
} |
260 |
} |
} |
261 |
|
|
262 |
|
|
263 |
// Save device configuration slot. |
// Refresh all device list and views. |
264 |
void qsamplerDeviceForm::saveDevices (void) |
void qsamplerDeviceForm::refreshDevices (void) |
265 |
{ |
{ |
266 |
QString sFilename = QFileDialog::getSaveFileName( |
if (m_pMainForm == NULL) |
267 |
m_sFilename, // Start here. |
return; |
|
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
|
|
this, 0, // Parent and name (none) |
|
|
tr("Save Device Configuration") // Caption. |
|
|
); |
|
268 |
|
|
269 |
if (sFilename.isEmpty()) |
// Avoid nested changes. |
270 |
return; |
m_iDirtySetup++; |
271 |
|
|
272 |
|
// |
273 |
|
// (Re)Load complete device configuration data ... |
274 |
|
// |
275 |
|
m_pAudioItems = NULL; |
276 |
|
m_pMidiItems = NULL; |
277 |
|
DeviceListView->clear(); |
278 |
|
if (m_pClient) { |
279 |
|
int *piDeviceIDs; |
280 |
|
// Grab and pop Audio devices... |
281 |
|
if (m_deviceTypeMode == qsamplerDevice::None || |
282 |
|
m_deviceTypeMode == qsamplerDevice::Audio) { |
283 |
|
m_pAudioItems = new qsamplerDeviceItem(DeviceListView, |
284 |
|
m_pMainForm, qsamplerDevice::Audio); |
285 |
|
} |
286 |
|
if (m_pAudioItems) { |
287 |
|
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
288 |
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
289 |
|
new qsamplerDeviceItem(m_pAudioItems, m_pMainForm, |
290 |
|
qsamplerDevice::Audio, piDeviceIDs[i]); |
291 |
|
} |
292 |
|
m_pAudioItems->setOpen(true); |
293 |
|
} |
294 |
|
// Grab and pop MIDI devices... |
295 |
|
if (m_deviceTypeMode == qsamplerDevice::None || |
296 |
|
m_deviceTypeMode == qsamplerDevice::Midi) { |
297 |
|
m_pMidiItems = new qsamplerDeviceItem(DeviceListView, |
298 |
|
m_pMainForm, qsamplerDevice::Midi); |
299 |
|
} |
300 |
|
if (m_pMidiItems) { |
301 |
|
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
302 |
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
303 |
|
new qsamplerDeviceItem(m_pMidiItems, m_pMainForm, |
304 |
|
qsamplerDevice::Midi, piDeviceIDs[i]); |
305 |
|
} |
306 |
|
m_pMidiItems->setOpen(true); |
307 |
|
} |
308 |
|
} |
309 |
|
|
310 |
// Enforce .xml extension... |
// Done. |
311 |
if (QFileInfo(sFilename).extension().isEmpty()) |
m_iDirtySetup--; |
|
sFilename += ".lscp"; |
|
312 |
|
|
313 |
// Save it right away... |
// Show something. |
314 |
saveDevicesFile(sFilename); |
selectDevice(); |
315 |
} |
} |
316 |
|
|
317 |
|
|
318 |
// Load device configuration from file. |
// Driver selection slot. |
319 |
void qsamplerDeviceForm::loadDevicesFile ( const QString& sFilename ) |
void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) |
320 |
{ |
{ |
321 |
|
if (m_iDirtySetup > 0) |
322 |
|
return; |
323 |
|
|
324 |
// |
// |
325 |
// TODO: Load device configuration from file... |
// Driver name has changed for a new device... |
326 |
// |
// |
|
m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")..."); |
|
|
|
|
|
m_sFilename = sFilename; |
|
|
m_iDirtyCount = 0; |
|
327 |
|
|
328 |
refreshDevices(); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
329 |
|
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
330 |
|
return; |
331 |
|
|
332 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
333 |
|
|
334 |
|
// Driver change is only valid for scratch devices... |
335 |
|
if (m_bNewDevice) { |
336 |
|
m_iDirtySetup++; |
337 |
|
device.setDriver(sDriverName); |
338 |
|
DeviceParamTable->refresh(device.params(), m_bNewDevice); |
339 |
|
m_iDirtySetup--; |
340 |
|
// Done. |
341 |
|
stabilizeForm(); |
342 |
|
} |
343 |
} |
} |
344 |
|
|
345 |
|
|
346 |
// Save device configuration into file. |
// Device selection slot. |
347 |
void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename ) |
void qsamplerDeviceForm::selectDevice (void) |
348 |
{ |
{ |
349 |
|
if (m_iDirtySetup > 0) |
350 |
|
return; |
351 |
|
|
352 |
|
// |
353 |
|
// Device selection has changed... |
354 |
// |
// |
|
// TODO: Save device configuration into file... |
|
|
// |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")..."); |
|
355 |
|
|
356 |
m_sFilename = sFilename; |
QListViewItem *pItem = DeviceListView->selectedItem(); |
357 |
m_iDirtyCount = 0; |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { |
358 |
stabilizeForm(); |
m_deviceType = qsamplerDevice::None; |
359 |
} |
DeviceNameTextLabel->setText(QString::null); |
360 |
|
DeviceParamTable->setNumRows(0); |
361 |
|
DevicePortComboBox->clear(); |
362 |
|
DevicePortParamTable->setNumRows(0); |
363 |
|
DevicePortTextLabel->setEnabled(false); |
364 |
|
DevicePortComboBox->setEnabled(false); |
365 |
|
DevicePortParamTable->setEnabled(false); |
366 |
|
stabilizeForm(); |
367 |
|
return; |
368 |
|
} |
369 |
|
|
370 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
371 |
|
|
372 |
// Create a new device from current table view. |
m_iDirtySetup++; |
373 |
void qsamplerDeviceForm::createDevice (void) |
// Flag whether this is a new device. |
374 |
{ |
m_bNewDevice = (device.deviceID() < 0); |
375 |
// |
|
376 |
// TODO: Create a new device from current table view... |
// Fill the device/driver heading... |
377 |
// |
DeviceNameTextLabel->setText(device.deviceName()); |
378 |
m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()..."); |
// The driver combobox is only rebuilt if device type has changed... |
379 |
|
if (device.deviceType() != m_deviceType) { |
380 |
|
DriverNameComboBox->clear(); |
381 |
|
DriverNameComboBox->insertStringList( |
382 |
|
qsamplerDevice::getDrivers(m_pClient, device.deviceType())); |
383 |
|
m_deviceType = device.deviceType(); |
384 |
|
} |
385 |
|
// Do we need a driver name? |
386 |
|
if (m_bNewDevice || device.driverName().isEmpty()) |
387 |
|
device.setDriver(DriverNameComboBox->currentText()); |
388 |
|
setDriverName(device.driverName()); |
389 |
|
DriverNameTextLabel->setEnabled(m_bNewDevice); |
390 |
|
DriverNameComboBox->setEnabled(m_bNewDevice); |
391 |
|
// Fill the device parameter table... |
392 |
|
DeviceParamTable->refresh(device.params(), m_bNewDevice); |
393 |
|
// And now the device port/channel parameter table... |
394 |
|
switch (device.deviceType()) { |
395 |
|
case qsamplerDevice::Audio: |
396 |
|
DevicePortTextLabel->setText(tr("Ch&annel:")); |
397 |
|
break; |
398 |
|
case qsamplerDevice::Midi: |
399 |
|
DevicePortTextLabel->setText(tr("P&ort:")); |
400 |
|
break; |
401 |
|
case qsamplerDevice::None: |
402 |
|
break; |
403 |
|
} |
404 |
|
DevicePortComboBox->clear(); |
405 |
|
DevicePortParamTable->setNumRows(0); |
406 |
|
if (m_bNewDevice) { |
407 |
|
DevicePortTextLabel->setEnabled(false); |
408 |
|
DevicePortComboBox->setEnabled(false); |
409 |
|
DevicePortParamTable->setEnabled(false); |
410 |
|
} else { |
411 |
|
QPixmap pixmap; |
412 |
|
switch (device.deviceType()) { |
413 |
|
case qsamplerDevice::Audio: |
414 |
|
pixmap = QPixmap::fromMimeSource("audio2.png"); |
415 |
|
break; |
416 |
|
case qsamplerDevice::Midi: |
417 |
|
pixmap = QPixmap::fromMimeSource("midi2.png"); |
418 |
|
break; |
419 |
|
case qsamplerDevice::None: |
420 |
|
break; |
421 |
|
} |
422 |
|
qsamplerDevicePortList& ports = device.ports(); |
423 |
|
qsamplerDevicePort *pPort; |
424 |
|
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
425 |
|
DevicePortComboBox->insertItem(pixmap, device.deviceTypeName() |
426 |
|
+ ' ' + device.driverName() |
427 |
|
+ ' ' + pPort->portName()); |
428 |
|
} |
429 |
|
bool bEnabled = (ports.count() > 0); |
430 |
|
DevicePortTextLabel->setEnabled(bEnabled); |
431 |
|
DevicePortComboBox->setEnabled(bEnabled); |
432 |
|
DevicePortParamTable->setEnabled(bEnabled); |
433 |
|
} |
434 |
|
// Done. |
435 |
|
m_iDirtySetup--; |
436 |
|
|
437 |
|
// Make the device port/channel selection effective. |
438 |
|
selectDevicePort(DevicePortComboBox->currentItem()); |
439 |
} |
} |
440 |
|
|
441 |
|
|
442 |
// Update current device in table view. |
// Device port/channel selection slot. |
443 |
void qsamplerDeviceForm::updateDevice (void) |
void qsamplerDeviceForm::selectDevicePort ( int iPort ) |
444 |
{ |
{ |
445 |
|
if (m_iDirtySetup > 0) |
446 |
|
return; |
447 |
|
|
448 |
|
// |
449 |
|
// Device port/channel selection has changed... |
450 |
// |
// |
451 |
// TODO: Update current device in table view... |
|
452 |
// |
QListViewItem *pItem = DeviceListView->selectedItem(); |
453 |
m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()..."); |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
454 |
|
return; |
455 |
|
|
456 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
457 |
|
qsamplerDevicePort *pPort = device.ports().at(iPort); |
458 |
|
if (pPort) { |
459 |
|
m_iDirtySetup++; |
460 |
|
DevicePortParamTable->refresh(pPort->params(), false); |
461 |
|
m_iDirtySetup--; |
462 |
|
} |
463 |
|
// Done. |
464 |
|
stabilizeForm(); |
465 |
} |
} |
466 |
|
|
467 |
|
|
468 |
// Delete current device in table view. |
// Device parameter value change slot. |
469 |
void qsamplerDeviceForm::deleteDevice (void) |
void qsamplerDeviceForm::changeDeviceParam ( int iRow, int iCol ) |
470 |
{ |
{ |
471 |
|
if (m_pMainForm == NULL) |
472 |
|
return; |
473 |
|
if (m_iDirtySetup > 0) |
474 |
|
return; |
475 |
|
if (iRow < 0 || iCol < 0) |
476 |
|
return; |
477 |
|
|
478 |
|
// |
479 |
|
// Device parameter change... |
480 |
// |
// |
481 |
// TODO: Delete current device in table view... |
|
482 |
// |
QListViewItem *pItem = DeviceListView->selectedItem(); |
483 |
m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()..."); |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
484 |
|
return; |
485 |
|
|
486 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
487 |
|
|
488 |
|
// Table 1st column has the parameter name; |
489 |
|
const QString sParam = DeviceParamTable->text(iRow, 0); |
490 |
|
const QString sValue = DeviceParamTable->text(iRow, iCol); |
491 |
|
// Set the local device parameter value. |
492 |
|
if (device.setParam(sParam, sValue)) { |
493 |
|
selectDevice(); |
494 |
|
} else { |
495 |
|
stabilizeForm(); |
496 |
|
} |
497 |
|
// Main session should be dirtier... |
498 |
|
m_pMainForm->sessionDirty(); |
499 |
} |
} |
500 |
|
|
501 |
|
|
502 |
// Refresh all device list and views. |
// Device port/channel parameter value change slot. |
503 |
void qsamplerDeviceForm::refreshDevices (void) |
void qsamplerDeviceForm::changeDevicePortParam ( int iRow, int iCol ) |
504 |
{ |
{ |
505 |
// Avoid nested changes. |
if (m_pMainForm == NULL) |
506 |
m_iDirtySetup++; |
return; |
507 |
|
if (m_iDirtySetup > 0) |
508 |
|
return; |
509 |
|
if (iRow < 0 || iCol < 0) |
510 |
|
return; |
511 |
|
|
512 |
// |
// |
513 |
// TODO: Load device configuration data ... |
// Device port/channel parameter change... |
514 |
// |
// |
|
|
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()"); |
|
|
|
|
|
DeviceListView->clear(); |
|
|
if (m_pClient) { |
|
|
qsamplerDeviceItem *pItem; |
|
|
int *piDeviceIDs; |
|
|
// Grab audio devices... |
|
|
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
|
|
qsamplerDevice::Audio); |
|
|
if (pItem) { |
|
|
pItem->setText(0, tr("Audio")); |
|
|
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
|
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
|
|
new qsamplerDeviceItem(pItem, m_pClient, |
|
|
qsamplerDevice::Audio, piDeviceIDs[i]); |
|
|
} |
|
|
} |
|
|
// Grab MIDI devices... |
|
|
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
|
|
qsamplerDevice::Midi); |
|
|
if (pItem) { |
|
|
pItem->setText(0, tr("MIDI")); |
|
|
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
|
|
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
|
|
new qsamplerDeviceItem(pItem, m_pClient, |
|
|
qsamplerDevice::Midi, piDeviceIDs[i]); |
|
|
} |
|
|
} |
|
|
} |
|
515 |
|
|
516 |
// Done. |
QListViewItem *pItem = DeviceListView->selectedItem(); |
517 |
m_iDirtySetup--; |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
518 |
// stabilizeForm(); |
return; |
519 |
|
|
520 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
521 |
|
|
522 |
|
int iPort = DevicePortComboBox->currentItem(); |
523 |
|
qsamplerDevicePort *pPort = device.ports().at(iPort); |
524 |
|
if (pPort == NULL) |
525 |
|
return; |
526 |
|
|
527 |
|
// Table 1st column has the parameter name; |
528 |
|
const QString sParam = DevicePortParamTable->text(iRow, 0); |
529 |
|
const QString sValue = DevicePortParamTable->text(iRow, iCol); |
530 |
|
// Set the local device port/channel parameter value. |
531 |
|
pPort->setParam(sParam, sValue); |
532 |
|
// Done. |
533 |
|
stabilizeForm(); |
534 |
|
// Main session should be dirtier... |
535 |
|
m_pMainForm->sessionDirty(); |
536 |
} |
} |
537 |
|
|
538 |
// Device selection slot. |
|
539 |
void qsamplerDeviceForm::selectDevice ( QListViewItem *pItem ) |
// Device list view context menu handler. |
540 |
|
void qsamplerDeviceForm::contextMenu ( QListViewItem *pItem, const QPoint& pos, int ) |
541 |
{ |
{ |
542 |
if (pItem == NULL) |
int iItemID; |
543 |
return; |
|
544 |
if (pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
// Build the device context menu... |
545 |
return; |
QPopupMenu* pContextMenu = new QPopupMenu(this); |
546 |
|
|
547 |
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice(" + pItem->text(0) + ")"); |
bool bClient = (m_pClient != NULL); |
548 |
|
bool bEnabled = (pItem != NULL); |
549 |
const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
iItemID = pContextMenu->insertItem( |
550 |
DeviceParamTable->setDevice(m_pClient, |
QIconSet(QPixmap::fromMimeSource("deviceCreate.png")), |
551 |
device.deviceType(), device.deviceID()); |
tr("&Create device"), this, SLOT(createDevice())); |
552 |
|
pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice)); |
553 |
|
iItemID = pContextMenu->insertItem( |
554 |
|
QIconSet(QPixmap::fromMimeSource("deviceDelete.png")), |
555 |
|
tr("&Delete device"), this, SLOT(deleteDevice())); |
556 |
|
pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice); |
557 |
|
pContextMenu->insertSeparator(); |
558 |
|
iItemID = pContextMenu->insertItem( |
559 |
|
QIconSet(QPixmap::fromMimeSource("formRefresh.png")), |
560 |
|
tr("&Refresh"), this, SLOT(refreshDevices())); |
561 |
|
pContextMenu->setItemEnabled(iItemID, bClient); |
562 |
|
|
563 |
|
pContextMenu->exec(pos); |
564 |
|
|
565 |
|
delete pContextMenu; |
566 |
} |
} |
567 |
|
|
568 |
|
|
569 |
// Stabilize current form state. |
// Stabilize current form state. |
570 |
void qsamplerDeviceForm::stabilizeForm (void) |
void qsamplerDeviceForm::stabilizeForm (void) |
571 |
{ |
{ |
572 |
// Update the main caption... |
QListViewItem *pItem = DeviceListView->selectedItem(); |
573 |
QString sDevicesName = devicesName(m_sFilename); |
bool bClient = (m_pClient != NULL); |
574 |
if (m_iDirtyCount > 0) |
bool bEnabled = (pItem != NULL); |
575 |
sDevicesName += '*'; |
DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); |
576 |
setCaption(tr("Devices - [%1]").arg(sDevicesName)); |
DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
577 |
|
DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
578 |
// |
DeviceParamTable->setEnabled(bEnabled); |
579 |
// TODO: Enable/disable available command buttons. |
RefreshDevicesPushButton->setEnabled(bClient); |
580 |
// |
CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
581 |
m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()"); |
DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); |
|
|
|
|
SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0); |
|
|
|
|
|
CreateDevicePushButton->setEnabled(m_iDirtyCount > 0); |
|
|
UpdateDevicePushButton->setEnabled(m_iDirtyCount > 0); |
|
|
DeleteDevicePushButton->setEnabled(m_iDirtyCount > 0); |
|
582 |
} |
} |
583 |
|
|
584 |
|
|
585 |
// end of qsamplerDeviceForm.ui.h |
// end of qsamplerDeviceForm.ui.h |
|
|
|