38 |
m_pClient = NULL; |
m_pClient = NULL; |
39 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
40 |
m_iDirtyCount = 0; |
m_iDirtyCount = 0; |
|
m_iUntitled = 1; |
|
41 |
m_bNewDevice = false; |
m_bNewDevice = false; |
42 |
|
|
43 |
|
// This an outsider (from designer), but rather important. |
44 |
|
QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)), |
45 |
|
this, SLOT(changeValue(int,int))); |
46 |
|
|
47 |
// Try to restore normal window positioning. |
// Try to restore normal window positioning. |
48 |
adjustSize(); |
adjustSize(); |
49 |
} |
} |
92 |
} |
} |
93 |
|
|
94 |
|
|
|
// Format the displayable device configuration filename. |
|
|
QString qsamplerDeviceForm::devicesName ( const QString& sFilename ) |
|
|
{ |
|
|
QString sDevicesName = sFilename; |
|
|
qsamplerOptions *pOptions = m_pMainForm->options(); |
|
|
if (pOptions) { |
|
|
bool bCompletePath = (pOptions && pOptions->bCompletePath); |
|
|
if (sDevicesName.isEmpty()) |
|
|
sDevicesName = tr("Untitled") + QString::number(m_iUntitled); |
|
|
else if (!bCompletePath) |
|
|
sDevicesName = QFileInfo(sDevicesName).fileName(); |
|
|
} |
|
|
return sDevicesName; |
|
|
} |
|
|
|
|
|
|
|
|
// Window close event handlers. |
|
|
bool qsamplerDeviceForm::queryClose (void) |
|
|
{ |
|
|
bool bQueryClose = true; |
|
|
|
|
|
if (m_iDirtyCount > 0) { |
|
|
switch (QMessageBox::warning(this, tr("Warning"), |
|
|
tr("The device configuration has been changed.\n\n" |
|
|
"\"%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 |
|
|
break; |
|
|
default: // Cancel. |
|
|
bQueryClose = false; |
|
|
} |
|
|
} |
|
|
|
|
|
return bQueryClose; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Dirty up settings. |
|
|
void qsamplerDeviceForm::contentsChanged (void) |
|
|
{ |
|
|
if (m_iDirtySetup > 0) |
|
|
return; |
|
|
|
|
|
m_iDirtyCount++; |
|
|
stabilizeForm(); |
|
|
} |
|
|
|
|
|
|
|
|
// Load device configuration slot. |
|
|
void qsamplerDeviceForm::loadDevices (void) |
|
|
{ |
|
|
QString sFilename = QFileDialog::getOpenFileName( |
|
|
m_sFilename, // Start here. |
|
|
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
|
|
this, 0, // Parent and name (none) |
|
|
tr("Load Device Configuration") // Caption. |
|
|
); |
|
|
|
|
|
if (sFilename.isEmpty()) |
|
|
return; |
|
|
|
|
|
// Check if we're going to discard safely the current one... |
|
|
if (!queryClose()) |
|
|
return; |
|
|
|
|
|
// Load it right away... |
|
|
loadDevicesFile(sFilename); |
|
|
} |
|
|
|
|
|
|
|
|
// Save device configuration slot. |
|
|
void qsamplerDeviceForm::saveDevices (void) |
|
|
{ |
|
|
QString sFilename = QFileDialog::getSaveFileName( |
|
|
m_sFilename, // Start here. |
|
|
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
|
|
this, 0, // Parent and name (none) |
|
|
tr("Save Device Configuration") // Caption. |
|
|
); |
|
|
|
|
|
if (sFilename.isEmpty()) |
|
|
return; |
|
|
|
|
|
// Enforce .xml extension... |
|
|
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(); |
|
|
} |
|
|
|
|
|
|
|
95 |
// Create a new device from current table view. |
// Create a new device from current table view. |
96 |
void qsamplerDeviceForm::createDevice (void) |
void qsamplerDeviceForm::createDevice (void) |
97 |
{ |
{ |
98 |
// |
// |
99 |
// TODO: Create a new device from current table view... |
// TODO: Create a new device from current table view... |
100 |
// |
// |
101 |
m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()..."); |
m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()"); |
|
|
|
|
m_iDirtyCount++; |
|
|
stabilizeForm(); |
|
|
} |
|
102 |
|
|
103 |
|
QListViewItem *pItem = DeviceListView->selectedItem(); |
104 |
|
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
105 |
|
return; |
106 |
|
|
107 |
// Update current device in table view. |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
|
void qsamplerDeviceForm::updateDevice (void) |
|
|
{ |
|
|
// |
|
|
// TODO: Update current device in table view... |
|
|
// |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()..."); |
|
108 |
|
|
109 |
m_iDirtyCount++; |
// Build the parameter list... |
110 |
stabilizeForm(); |
qsamplerDeviceParamMap& params = device.params(); |
111 |
|
lscp_param_t *pParams = new lscp_param_t [params.count() + 1]; |
112 |
|
int i = 0; |
113 |
|
qsamplerDeviceParamMap::ConstIterator iter; |
114 |
|
for (iter = params.begin(); iter != params.end(); ++iter) { |
115 |
|
pParams[i].key = (char *) iter.key().latin1(); |
116 |
|
pParams[i].value = (char *) iter.data().value.latin1(); |
117 |
|
} |
118 |
|
// Null terminated. |
119 |
|
pParams[i].key = NULL; |
120 |
|
pParams[i].value = NULL; |
121 |
|
|
122 |
|
// Now it depends on the device type... |
123 |
|
int iDeviceID = -1; |
124 |
|
switch (device.deviceType()) { |
125 |
|
case qsamplerDevice::Audio: |
126 |
|
if ((iDeviceID = ::lscp_create_audio_device(m_pClient, |
127 |
|
device.driverName().latin1(), pParams)) < 0) |
128 |
|
m_pMainForm->appendMessagesClient("lscp_create_audio_device"); |
129 |
|
break; |
130 |
|
case qsamplerDevice::Midi: |
131 |
|
if ((iDeviceID = ::lscp_create_midi_device(m_pClient, |
132 |
|
device.driverName().latin1(), pParams)) < 0) |
133 |
|
m_pMainForm->appendMessagesClient("lscp_create_midi_device"); |
134 |
|
break; |
135 |
|
} |
136 |
|
|
137 |
|
// Free used parameter array. |
138 |
|
delete [] pParams; |
139 |
|
|
140 |
|
// Show result. |
141 |
|
if (iDeviceID >= 0) { |
142 |
|
m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("created.")); |
143 |
|
// Done. |
144 |
|
refreshDevices(); |
145 |
|
// Main session should be marked dirty. |
146 |
|
m_pMainForm->sessionDirty(); |
147 |
|
} |
148 |
} |
} |
149 |
|
|
150 |
|
|
154 |
// |
// |
155 |
// TODO: Delete current device in table view... |
// TODO: Delete current device in table view... |
156 |
// |
// |
157 |
m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()..."); |
m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()"); |
158 |
|
|
159 |
m_iDirtyCount++; |
QListViewItem *pItem = DeviceListView->selectedItem(); |
160 |
stabilizeForm(); |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
161 |
|
return; |
162 |
|
|
163 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
164 |
|
|
165 |
|
// Now it depends on the device type... |
166 |
|
lscp_status_t ret = LSCP_FAILED; |
167 |
|
switch (device.deviceType()) { |
168 |
|
case qsamplerDevice::Audio: |
169 |
|
if ((ret = ::lscp_destroy_audio_device(m_pClient, |
170 |
|
device.deviceID())) != LSCP_OK) |
171 |
|
m_pMainForm->appendMessagesClient("lscp_destroy_audio_device"); |
172 |
|
break; |
173 |
|
case qsamplerDevice::Midi: |
174 |
|
if ((ret = ::lscp_destroy_midi_device(m_pClient, |
175 |
|
device.deviceID())) != LSCP_OK) |
176 |
|
m_pMainForm->appendMessagesClient("lscp_destroy_midi_device"); |
177 |
|
break; |
178 |
|
} |
179 |
|
|
180 |
|
// Show result. |
181 |
|
if (ret == LSCP_OK) { |
182 |
|
m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("deleted.")); |
183 |
|
// Done. |
184 |
|
refreshDevices(); |
185 |
|
// Main session should be marked dirty. |
186 |
|
m_pMainForm->sessionDirty(); |
187 |
|
} |
188 |
} |
} |
189 |
|
|
190 |
|
|
230 |
} |
} |
231 |
|
|
232 |
// Done. |
// Done. |
233 |
selectDevice(); |
m_iDirtyCount = 0; |
234 |
m_iDirtySetup--; |
m_iDirtySetup--; |
235 |
|
|
236 |
|
// Show something. |
237 |
|
selectDevice(); |
238 |
} |
} |
239 |
|
|
240 |
|
|
241 |
// Driver selection slot. |
// Driver selection slot. |
242 |
void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) |
void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) |
243 |
{ |
{ |
244 |
|
if (m_iDirtySetup > 0) |
245 |
|
return; |
246 |
|
|
247 |
// |
// |
248 |
// TODO: Driver name has changed for a new device... |
// TODO: Driver name has changed for a new device... |
249 |
// |
// |
250 |
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver(\"" + sDriverName + "\")"); |
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver()"); |
251 |
|
|
252 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
253 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
267 |
// Device selection slot. |
// Device selection slot. |
268 |
void qsamplerDeviceForm::selectDevice (void) |
void qsamplerDeviceForm::selectDevice (void) |
269 |
{ |
{ |
270 |
|
if (m_iDirtySetup > 0) |
271 |
|
return; |
272 |
|
|
273 |
// |
// |
274 |
// TODO: Device selection has changed... |
// TODO: Device selection has changed... |
275 |
// |
// |
277 |
|
|
278 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
279 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { |
280 |
|
DeviceNameTextLabel->setText(QString::null); |
281 |
|
DeviceParamTable->setNumRows(0); |
282 |
stabilizeForm(); |
stabilizeForm(); |
283 |
return; |
return; |
284 |
} |
} |
286 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
287 |
m_bNewDevice = (device.deviceID() < 0); |
m_bNewDevice = (device.deviceID() < 0); |
288 |
|
|
289 |
// Fill the device heading... |
// Fill the device/driver heading... |
290 |
DeviceNameTextLabel->setText(' ' + device.deviceName()); |
DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName()); |
291 |
DriverNameComboBox->clear(); |
DriverNameComboBox->clear(); |
292 |
DriverNameComboBox->insertStringList( |
DriverNameComboBox->insertStringList( |
293 |
qsamplerDevice::getDrivers(m_pClient, device.deviceType())); |
qsamplerDevice::getDrivers(m_pClient, device.deviceType())); |
301 |
} |
} |
302 |
DriverNameTextLabel->setEnabled(m_bNewDevice); |
DriverNameTextLabel->setEnabled(m_bNewDevice); |
303 |
DriverNameComboBox->setEnabled(m_bNewDevice); |
DriverNameComboBox->setEnabled(m_bNewDevice); |
304 |
|
|
305 |
// Fill the device parameter table... |
// Fill the device parameter table... |
306 |
DeviceParamTable->refresh(device); |
DeviceParamTable->refresh(device); |
307 |
|
|
326 |
|
|
327 |
// Table 3rd column has the parameter name; |
// Table 3rd column has the parameter name; |
328 |
qsamplerDeviceParamMap& params = device.params(); |
qsamplerDeviceParamMap& params = device.params(); |
329 |
QString sParam = DeviceParamTable->text(iRow, 2); |
const QString sParam = DeviceParamTable->text(iRow, 2); |
330 |
params[sParam].value = DeviceParamTable->text(iRow, iCol); |
const QString sValue = DeviceParamTable->text(iRow, iCol); |
331 |
|
params[sParam].value = sValue; |
332 |
|
|
333 |
|
// Set proper device parameter, on existing device ... |
334 |
|
if (device.deviceID() >= 0) { |
335 |
|
// Prepare parameter struct. |
336 |
|
lscp_param_t param; |
337 |
|
param.key = (char *) sParam.latin1(); |
338 |
|
param.value = (char *) sValue.latin1(); |
339 |
|
// Now it depends on the device type... |
340 |
|
lscp_status_t ret = LSCP_FAILED; |
341 |
|
switch (device.deviceType()) { |
342 |
|
case qsamplerDevice::Audio: |
343 |
|
if ((ret = ::lscp_set_audio_device_param(m_pClient, |
344 |
|
device.deviceID(), ¶m)) != LSCP_OK) |
345 |
|
m_pMainForm->appendMessagesClient("lscp_set_audio_device_param"); |
346 |
|
break; |
347 |
|
case qsamplerDevice::Midi: |
348 |
|
if ((ret = ::lscp_set_midi_device_param(m_pClient, |
349 |
|
device.deviceID(), ¶m)) != LSCP_OK) |
350 |
|
m_pMainForm->appendMessagesClient("lscp_set_midi_device_param"); |
351 |
|
break; |
352 |
|
} |
353 |
|
// Show result. |
354 |
|
if (ret == LSCP_OK) { |
355 |
|
m_pMainForm->appendMessages(device.deviceName() + ' ' + |
356 |
|
QString("%1: %2.").arg(sParam).arg(sValue)); |
357 |
|
} |
358 |
|
} |
359 |
|
|
360 |
|
// Done. |
361 |
m_iDirtyCount++; |
m_iDirtyCount++; |
362 |
stabilizeForm(); |
stabilizeForm(); |
363 |
|
// Main session should be dirtier... |
364 |
|
m_pMainForm->sessionDirty(); |
365 |
} |
} |
366 |
|
|
367 |
|
|
368 |
// Stabilize current form state. |
// Stabilize current form state. |
369 |
void qsamplerDeviceForm::stabilizeForm (void) |
void qsamplerDeviceForm::stabilizeForm (void) |
370 |
{ |
{ |
|
// Update the main caption... |
|
|
QString sDevicesName = devicesName(m_sFilename); |
|
|
if (m_iDirtyCount > 0) |
|
|
sDevicesName += '*'; |
|
|
setCaption(tr("Devices - [%1]").arg(sDevicesName)); |
|
|
|
|
|
// |
|
|
// TODO: Enable/disable available command buttons. |
|
|
// |
|
|
m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()"); |
|
|
|
|
|
SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0); |
|
|
|
|
371 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
372 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != NULL); |
373 |
DeviceNameTextLabel->setEnabled(bEnabled); |
DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); |
374 |
DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
375 |
DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
376 |
DeviceParamTable->setEnabled(bEnabled); |
DeviceParamTable->setEnabled(bEnabled); |
377 |
CreateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 || m_bNewDevice)); |
CreateDevicePushButton->setEnabled(bEnabled || m_bNewDevice); |
378 |
UpdateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice)); |
DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); |
|
DeleteDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice)); |
|
379 |
} |
} |
380 |
|
|
381 |
|
|