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