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