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