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 |
|
|
39 |
m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); |
m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); |
40 |
m_pClient = NULL; |
m_pClient = NULL; |
41 |
m_iDirtySetup = 0; |
m_iDirtySetup = 0; |
|
m_iDirtyCount = 0; |
|
|
m_iUntitled = 1; |
|
42 |
m_bNewDevice = false; |
m_bNewDevice = false; |
43 |
|
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. |
// Try to restore normal window positioning. |
54 |
adjustSize(); |
adjustSize(); |
98 |
} |
} |
99 |
|
|
100 |
|
|
101 |
// Format the displayable device configuration filename. |
// Create a new device from current table view. |
102 |
QString qsamplerDeviceForm::devicesName ( const QString& sFilename ) |
void qsamplerDeviceForm::createDevice (void) |
|
{ |
|
|
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) |
|
103 |
{ |
{ |
104 |
if (m_iDirtySetup > 0) |
QListViewItem *pItem = DeviceListView->selectedItem(); |
105 |
|
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
106 |
return; |
return; |
107 |
|
|
108 |
m_iDirtyCount++; |
const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
|
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. |
|
|
); |
|
109 |
|
|
110 |
if (sFilename.isEmpty()) |
// Build the parameter list... |
111 |
return; |
const qsamplerDeviceParamMap& params = device.params(); |
112 |
|
lscp_param_t *pParams = new lscp_param_t [params.count() + 1]; |
113 |
|
int iParam = 0; |
114 |
|
qsamplerDeviceParamMap::ConstIterator iter; |
115 |
|
for (iter = params.begin(); iter != params.end(); ++iter) { |
116 |
|
pParams[iParam].key = (char *) iter.key().latin1(); |
117 |
|
pParams[iParam].value = (char *) iter.data().value.latin1(); |
118 |
|
++iParam; |
119 |
|
} |
120 |
|
// Null terminated. |
121 |
|
pParams[iParam].key = NULL; |
122 |
|
pParams[iParam].value = NULL; |
123 |
|
|
124 |
|
// Now it depends on the device type... |
125 |
|
qsamplerDeviceItem *pRootItem = NULL; |
126 |
|
int iDeviceID = -1; |
127 |
|
switch (device.deviceType()) { |
128 |
|
case qsamplerDevice::Audio: |
129 |
|
pRootItem = m_pAudioItems; |
130 |
|
if ((iDeviceID = ::lscp_create_audio_device(m_pClient, |
131 |
|
device.driverName().latin1(), pParams)) < 0) |
132 |
|
m_pMainForm->appendMessagesClient("lscp_create_audio_device"); |
133 |
|
break; |
134 |
|
case qsamplerDevice::Midi: |
135 |
|
pRootItem = m_pMidiItems; |
136 |
|
if ((iDeviceID = ::lscp_create_midi_device(m_pClient, |
137 |
|
device.driverName().latin1(), pParams)) < 0) |
138 |
|
m_pMainForm->appendMessagesClient("lscp_create_midi_device"); |
139 |
|
break; |
140 |
|
case qsamplerDevice::None: |
141 |
|
break; |
142 |
|
} |
143 |
|
|
144 |
// Check if we're going to discard safely the current one... |
// Free used parameter array. |
145 |
if (!queryClose()) |
delete pParams; |
|
return; |
|
146 |
|
|
147 |
// Load it right away... |
// We're on to create the new device item. |
148 |
loadDevicesFile(sFilename); |
if (iDeviceID >= 0) { |
149 |
|
// Append the new device item. |
150 |
|
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
151 |
|
m_pClient, device.deviceType(), iDeviceID); |
152 |
|
// Just make it the new selection... |
153 |
|
DeviceListView->setSelected(pDeviceItem, true); |
154 |
|
// Done. |
155 |
|
m_pMainForm->appendMessages(pDeviceItem->device().deviceName() + ' ' |
156 |
|
+ tr("created.")); |
157 |
|
// Main session should be marked dirty. |
158 |
|
m_pMainForm->sessionDirty(); |
159 |
|
} |
160 |
} |
} |
161 |
|
|
162 |
|
|
163 |
// Save device configuration slot. |
// Delete current device in table view. |
164 |
void qsamplerDeviceForm::saveDevices (void) |
void qsamplerDeviceForm::deleteDevice (void) |
165 |
{ |
{ |
166 |
QString sFilename = QFileDialog::getSaveFileName( |
QListViewItem *pItem = DeviceListView->selectedItem(); |
167 |
m_sFilename, // Start here. |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
|
tr("Device Configuration files") + " (*.lscp)", // Filter (XML files) |
|
|
this, 0, // Parent and name (none) |
|
|
tr("Save Device Configuration") // Caption. |
|
|
); |
|
|
|
|
|
if (sFilename.isEmpty()) |
|
168 |
return; |
return; |
169 |
|
|
170 |
// Enforce .xml extension... |
const 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(); |
|
|
} |
|
171 |
|
|
172 |
|
// Prompt user if this is for real... |
173 |
|
qsamplerOptions *pOptions = m_pMainForm->options(); |
174 |
|
if (pOptions && pOptions->bConfirmRemove) { |
175 |
|
if (QMessageBox::warning(this, tr("Warning"), |
176 |
|
tr("Delete %1 device:\n\n" |
177 |
|
"%2\n\n" |
178 |
|
"Are you sure?") |
179 |
|
.arg(device.deviceTypeName()) |
180 |
|
.arg(device.deviceName()), |
181 |
|
tr("OK"), tr("Cancel")) > 0) |
182 |
|
return; |
183 |
|
} |
184 |
|
|
185 |
// Delete current device in table view. |
// Now it depends on the device type... |
186 |
void qsamplerDeviceForm::deleteDevice (void) |
lscp_status_t ret = LSCP_FAILED; |
187 |
{ |
switch (device.deviceType()) { |
188 |
// |
case qsamplerDevice::Audio: |
189 |
// TODO: Delete current device in table view... |
if ((ret = ::lscp_destroy_audio_device(m_pClient, |
190 |
// |
device.deviceID())) != LSCP_OK) |
191 |
m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()..."); |
m_pMainForm->appendMessagesClient("lscp_destroy_audio_device"); |
192 |
|
break; |
193 |
|
case qsamplerDevice::Midi: |
194 |
|
if ((ret = ::lscp_destroy_midi_device(m_pClient, |
195 |
|
device.deviceID())) != LSCP_OK) |
196 |
|
m_pMainForm->appendMessagesClient("lscp_destroy_midi_device"); |
197 |
|
break; |
198 |
|
case qsamplerDevice::None: |
199 |
|
break; |
200 |
|
} |
201 |
|
|
202 |
m_iDirtyCount++; |
// Show result. |
203 |
stabilizeForm(); |
if (ret == LSCP_OK) { |
204 |
|
// Show log message before loosing it. |
205 |
|
m_pMainForm->appendMessages(device.deviceName() + ' ' |
206 |
|
+ tr("deleted.")); |
207 |
|
// Done. |
208 |
|
delete pItem; |
209 |
|
// Main session should be marked dirty. |
210 |
|
m_pMainForm->sessionDirty(); |
211 |
|
} |
212 |
} |
} |
213 |
|
|
214 |
|
|
219 |
m_iDirtySetup++; |
m_iDirtySetup++; |
220 |
|
|
221 |
// |
// |
222 |
// TODO: Load device configuration data ... |
// (Re)Load complete device configuration data ... |
223 |
// |
// |
224 |
m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()"); |
m_pAudioItems = NULL; |
225 |
|
m_pMidiItems = NULL; |
226 |
DeviceListView->clear(); |
DeviceListView->clear(); |
227 |
if (m_pClient) { |
if (m_pClient) { |
|
qsamplerDeviceItem *pItem; |
|
228 |
int *piDeviceIDs; |
int *piDeviceIDs; |
229 |
// Grab and pop Audio devices... |
// Grab and pop Audio devices... |
230 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
m_pAudioItems = new qsamplerDeviceItem(DeviceListView, m_pClient, |
231 |
qsamplerDevice::Audio); |
qsamplerDevice::Audio); |
232 |
if (pItem) { |
if (m_pAudioItems) { |
233 |
pItem->setText(0, tr("Audio")); |
m_pAudioItems->setText(0, tr("Audio")); |
234 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
235 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
236 |
new qsamplerDeviceItem(pItem, m_pClient, |
new qsamplerDeviceItem(m_pAudioItems, m_pClient, |
237 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
qsamplerDevice::Audio, piDeviceIDs[i]); |
238 |
} |
} |
239 |
pItem->setOpen(true); |
m_pAudioItems->setOpen(true); |
240 |
} |
} |
241 |
// Grab and pop MIDI devices... |
// Grab and pop MIDI devices... |
242 |
pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, |
m_pMidiItems = new qsamplerDeviceItem(DeviceListView, m_pClient, |
243 |
qsamplerDevice::Midi); |
qsamplerDevice::Midi); |
244 |
if (pItem) { |
if (m_pMidiItems) { |
245 |
pItem->setText(0, tr("MIDI")); |
m_pMidiItems->setText(0, tr("MIDI")); |
246 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
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_pMidiItems, m_pClient, |
249 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
qsamplerDevice::Midi, piDeviceIDs[i]); |
250 |
} |
} |
251 |
pItem->setOpen(true); |
m_pMidiItems->setOpen(true); |
252 |
} |
} |
253 |
} |
} |
254 |
|
|
255 |
// Done. |
// Done. |
|
selectDevice(); |
|
256 |
m_iDirtySetup--; |
m_iDirtySetup--; |
257 |
|
|
258 |
|
// Show something. |
259 |
|
selectDevice(); |
260 |
} |
} |
261 |
|
|
262 |
|
|
263 |
// Driver selection slot. |
// Driver selection slot. |
264 |
void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) |
void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) |
265 |
{ |
{ |
266 |
|
if (m_iDirtySetup > 0) |
267 |
|
return; |
268 |
|
|
269 |
// |
// |
270 |
// TODO: Driver name has changed for a new device... |
// Driver name has changed for a new device... |
271 |
// |
// |
|
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver(\"" + sDriverName + "\")"); |
|
272 |
|
|
273 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
274 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
275 |
return; |
return; |
276 |
|
|
277 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
278 |
|
|
279 |
|
// Driver change is only valid for scratch devices... |
280 |
if (m_bNewDevice) { |
if (m_bNewDevice) { |
281 |
|
m_iDirtySetup++; |
282 |
device.setDriver(m_pClient, sDriverName); |
device.setDriver(m_pClient, sDriverName); |
283 |
m_iDirtyCount++; |
DeviceParamTable->refresh(device.params(), m_bNewDevice); |
284 |
|
m_iDirtySetup--; |
285 |
|
// Done. |
286 |
|
stabilizeForm(); |
287 |
} |
} |
|
|
|
|
// Done. |
|
|
stabilizeForm(); |
|
288 |
} |
} |
289 |
|
|
290 |
|
|
291 |
// Device selection slot. |
// Device selection slot. |
292 |
void qsamplerDeviceForm::selectDevice (void) |
void qsamplerDeviceForm::selectDevice (void) |
293 |
{ |
{ |
294 |
|
if (m_iDirtySetup > 0) |
295 |
|
return; |
296 |
|
|
297 |
// |
// |
298 |
// TODO: Device selection has changed... |
// Device selection has changed... |
299 |
// |
// |
|
m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()"); |
|
300 |
|
|
301 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
302 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { |
303 |
|
m_deviceType = qsamplerDevice::None; |
304 |
|
DeviceNameTextLabel->setText(QString::null); |
305 |
|
DeviceParamTable->setNumRows(0); |
306 |
|
DevicePortComboBox->setEnabled(false); |
307 |
|
DevicePortParamTable->setEnabled(false); |
308 |
stabilizeForm(); |
stabilizeForm(); |
309 |
return; |
return; |
310 |
} |
} |
311 |
|
|
312 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
313 |
|
|
314 |
|
m_iDirtySetup++; |
315 |
|
// Flag whether this is a new device. |
316 |
m_bNewDevice = (device.deviceID() < 0); |
m_bNewDevice = (device.deviceID() < 0); |
317 |
|
|
318 |
// Fill the device heading... |
// Fill the device/driver heading... |
319 |
DeviceNameTextLabel->setText(' ' + device.deviceName()); |
QString sPrefix; |
320 |
DriverNameComboBox->clear(); |
if (!m_bNewDevice) |
321 |
DriverNameComboBox->insertStringList( |
sPrefix += device.deviceTypeName() + ' '; |
322 |
qsamplerDevice::getDrivers(m_pClient, device.deviceType())); |
DeviceNameTextLabel->setText(sPrefix + device.deviceName()); |
323 |
const QString& sDriverName = device.driverName(); |
// The driver combobox is only rebuilt if device type has changed... |
324 |
if (m_bNewDevice || sDriverName.isEmpty()) { |
if (device.deviceType() != m_deviceType) { |
325 |
device.setDriver(m_pClient, DriverNameComboBox->currentText()); |
DriverNameComboBox->clear(); |
326 |
} else { |
DriverNameComboBox->insertStringList( |
327 |
if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL) |
qsamplerDevice::getDrivers(m_pClient, device.deviceType())); |
328 |
DriverNameComboBox->insertItem(sDriverName); |
m_deviceType = device.deviceType(); |
|
DriverNameComboBox->setCurrentText(sDriverName); |
|
329 |
} |
} |
330 |
|
// Do we need a driver name? |
331 |
|
if (m_bNewDevice || device.driverName().isEmpty()) |
332 |
|
device.setDriver(m_pClient, DriverNameComboBox->currentText()); |
333 |
|
const QString& sDriverName = device.driverName(); |
334 |
|
if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL) |
335 |
|
DriverNameComboBox->insertItem(sDriverName); |
336 |
|
DriverNameComboBox->setCurrentText(sDriverName); |
337 |
DriverNameTextLabel->setEnabled(m_bNewDevice); |
DriverNameTextLabel->setEnabled(m_bNewDevice); |
338 |
DriverNameComboBox->setEnabled(m_bNewDevice); |
DriverNameComboBox->setEnabled(m_bNewDevice); |
|
|
|
339 |
// Fill the device parameter table... |
// Fill the device parameter table... |
340 |
DeviceParamTable->refresh(device); |
DeviceParamTable->refresh(device.params(), m_bNewDevice); |
341 |
|
// And now the device port/channel parameter table... |
342 |
|
DevicePortComboBox->clear(); |
343 |
|
DevicePortParamTable->setNumRows(0); |
344 |
|
if (m_bNewDevice) { |
345 |
|
DevicePortComboBox->setEnabled(false); |
346 |
|
DevicePortParamTable->setEnabled(false); |
347 |
|
} else { |
348 |
|
QPixmap pixmap; |
349 |
|
switch (device.deviceType()) { |
350 |
|
case qsamplerDevice::Audio: |
351 |
|
pixmap = QPixmap::fromMimeSource("audio2.png"); |
352 |
|
break; |
353 |
|
case qsamplerDevice::Midi: |
354 |
|
pixmap = QPixmap::fromMimeSource("midi2.png"); |
355 |
|
break; |
356 |
|
case qsamplerDevice::None: |
357 |
|
break; |
358 |
|
} |
359 |
|
qsamplerDevicePortList& ports = device.ports(); |
360 |
|
qsamplerDevicePort *pPort; |
361 |
|
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
362 |
|
DevicePortComboBox->insertItem(pixmap, |
363 |
|
device.deviceTypeName() + ' ' + pPort->portName()); |
364 |
|
} |
365 |
|
bool bEnabled = (ports.count() > 0); |
366 |
|
DevicePortComboBox->setEnabled(bEnabled); |
367 |
|
DevicePortParamTable->setEnabled(bEnabled); |
368 |
|
} |
369 |
|
// Done. |
370 |
|
m_iDirtySetup--; |
371 |
|
|
372 |
|
// Make the device port/channel selection effective. |
373 |
|
selectDevicePort(DevicePortComboBox->currentItem()); |
374 |
|
} |
375 |
|
|
376 |
|
|
377 |
|
// Device port/channel selection slot. |
378 |
|
void qsamplerDeviceForm::selectDevicePort ( int iPort ) |
379 |
|
{ |
380 |
|
if (m_iDirtySetup > 0) |
381 |
|
return; |
382 |
|
|
383 |
|
// |
384 |
|
// Device port/channel selection has changed... |
385 |
|
// |
386 |
|
|
387 |
|
QListViewItem *pItem = DeviceListView->selectedItem(); |
388 |
|
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
389 |
|
return; |
390 |
|
|
391 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
392 |
|
qsamplerDevicePort *pPort = device.ports().at(iPort); |
393 |
|
if (pPort) { |
394 |
|
m_iDirtySetup++; |
395 |
|
DevicePortParamTable->refresh(pPort->params(), true); |
396 |
|
m_iDirtySetup--; |
397 |
|
} |
398 |
// Done. |
// Done. |
399 |
stabilizeForm(); |
stabilizeForm(); |
400 |
} |
} |
401 |
|
|
402 |
|
|
403 |
// Stabilize current form state. |
// Device parameter value change slot. |
404 |
void qsamplerDeviceForm::stabilizeForm (void) |
void qsamplerDeviceForm::changeDeviceParam ( int iRow, int iCol ) |
405 |
{ |
{ |
406 |
// Update the main caption... |
if (m_iDirtySetup > 0) |
407 |
QString sDevicesName = devicesName(m_sFilename); |
return; |
408 |
if (m_iDirtyCount > 0) |
if (iRow < 0 || iCol < 0) |
409 |
sDevicesName += '*'; |
return; |
410 |
setCaption(tr("Devices - [%1]").arg(sDevicesName)); |
|
411 |
|
// |
412 |
|
// Device parameter change... |
413 |
|
// |
414 |
|
|
415 |
|
QListViewItem *pItem = DeviceListView->selectedItem(); |
416 |
|
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
417 |
|
return; |
418 |
|
|
419 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
420 |
|
|
421 |
|
m_iDirtySetup++; |
422 |
|
// Table 1st column has the parameter name; |
423 |
|
const qsamplerDeviceParamMap& params = device.params(); |
424 |
|
const QString sParam = DeviceParamTable->text(iRow, 0); |
425 |
|
const QString sValue = DeviceParamTable->text(iRow, iCol); |
426 |
|
|
427 |
|
// Set the local device parameter value. |
428 |
|
device.setParam(sParam, sValue); |
429 |
|
|
430 |
|
// Set proper device parameter, on existing device ... |
431 |
|
if (device.deviceID() >= 0) { |
432 |
|
// Prepare parameter struct. |
433 |
|
lscp_param_t param; |
434 |
|
param.key = (char *) sParam.latin1(); |
435 |
|
param.value = (char *) sValue.latin1(); |
436 |
|
// Now it depends on the device type... |
437 |
|
bool bRefresh = false; |
438 |
|
lscp_status_t ret = LSCP_FAILED; |
439 |
|
switch (device.deviceType()) { |
440 |
|
case qsamplerDevice::Audio: |
441 |
|
bRefresh = (sParam == "CHANNELS"); |
442 |
|
if ((ret = ::lscp_set_audio_device_param(m_pClient, |
443 |
|
device.deviceID(), ¶m)) != LSCP_OK) |
444 |
|
m_pMainForm->appendMessagesClient("lscp_set_audio_device_param"); |
445 |
|
break; |
446 |
|
case qsamplerDevice::Midi: |
447 |
|
bRefresh = (sParam == "PORTS"); |
448 |
|
if ((ret = ::lscp_set_midi_device_param(m_pClient, |
449 |
|
device.deviceID(), ¶m)) != LSCP_OK) |
450 |
|
m_pMainForm->appendMessagesClient("lscp_set_midi_device_param"); |
451 |
|
break; |
452 |
|
case qsamplerDevice::None: |
453 |
|
break; |
454 |
|
} |
455 |
|
// Show result. |
456 |
|
if (ret == LSCP_OK) { |
457 |
|
m_pMainForm->appendMessages(device.deviceName() + ' ' |
458 |
|
+ QString("%1: %2.").arg(sParam).arg(sValue)); |
459 |
|
// Special care for specific parameter changes... |
460 |
|
if (bRefresh) |
461 |
|
device.refresh(m_pClient); |
462 |
|
} |
463 |
|
} |
464 |
|
|
465 |
|
// Done. |
466 |
|
m_iDirtySetup--; |
467 |
|
stabilizeForm(); |
468 |
|
// Main session should be dirtier... |
469 |
|
m_pMainForm->sessionDirty(); |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
|
// Device port/channel parameter value change slot. |
474 |
|
void qsamplerDeviceForm::changeDevicePortParam ( int iRow, int iCol ) |
475 |
|
{ |
476 |
|
if (m_iDirtySetup > 0) |
477 |
|
return; |
478 |
|
if (iRow < 0 || iCol < 0) |
479 |
|
return; |
480 |
|
|
481 |
// |
// |
482 |
// TODO: Enable/disable available command buttons. |
// Device port/channel parameter change... |
483 |
// |
// |
|
m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()"); |
|
484 |
|
|
485 |
SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
486 |
|
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
487 |
|
return; |
488 |
|
|
489 |
|
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
490 |
|
|
491 |
|
int iPort = DevicePortComboBox->currentItem(); |
492 |
|
qsamplerDevicePort *pPort = device.ports().at(iPort); |
493 |
|
if (pPort == NULL) |
494 |
|
return; |
495 |
|
|
496 |
|
m_iDirtySetup++; |
497 |
|
// Table 1st column has the parameter name; |
498 |
|
const qsamplerDeviceParamMap& params = pPort->params(); |
499 |
|
const QString sParam = DevicePortParamTable->text(iRow, 0); |
500 |
|
const QString sValue = DevicePortParamTable->text(iRow, iCol); |
501 |
|
|
502 |
|
// Set the local device port/channel parameter value. |
503 |
|
pPort->setParam(sParam, sValue); |
504 |
|
|
505 |
|
// Set proper device port/channel parameter, if any... |
506 |
|
if (device.deviceID() >= 0 && pPort->portID() >= 0) { |
507 |
|
// Prepare parameter struct. |
508 |
|
lscp_param_t param; |
509 |
|
param.key = (char *) sParam.latin1(); |
510 |
|
param.value = (char *) sValue.latin1(); |
511 |
|
// Now it depends on the device type... |
512 |
|
lscp_status_t ret = LSCP_FAILED; |
513 |
|
switch (device.deviceType()) { |
514 |
|
case qsamplerDevice::Audio: |
515 |
|
if ((ret = ::lscp_set_audio_channel_param(m_pClient, |
516 |
|
device.deviceID(), pPort->portID(), ¶m)) != LSCP_OK) |
517 |
|
m_pMainForm->appendMessagesClient("lscp_set_audio_channel_param"); |
518 |
|
break; |
519 |
|
case qsamplerDevice::Midi: |
520 |
|
if ((ret = ::lscp_set_midi_port_param(m_pClient, |
521 |
|
device.deviceID(), pPort->portID(), ¶m)) != LSCP_OK) |
522 |
|
m_pMainForm->appendMessagesClient("lscp_set_midi_port_param"); |
523 |
|
break; |
524 |
|
case qsamplerDevice::None: |
525 |
|
break; |
526 |
|
} |
527 |
|
// Show result. |
528 |
|
if (ret == LSCP_OK) { |
529 |
|
m_pMainForm->appendMessages(device.deviceName() + ' ' |
530 |
|
+ pPort->portName() + ' ' |
531 |
|
+ QString("%1: %2.").arg(sParam).arg(sValue)); |
532 |
|
} |
533 |
|
} |
534 |
|
|
535 |
|
// Done. |
536 |
|
m_iDirtySetup--; |
537 |
|
stabilizeForm(); |
538 |
|
// Main session should be dirtier... |
539 |
|
m_pMainForm->sessionDirty(); |
540 |
|
} |
541 |
|
|
542 |
|
|
543 |
|
// Device list view context menu handler. |
544 |
|
void qsamplerDeviceForm::contextMenu ( QListViewItem *pItem, const QPoint& pos, int ) |
545 |
|
{ |
546 |
|
int iItemID; |
547 |
|
|
548 |
|
// Build the device context menu... |
549 |
|
QPopupMenu* pContextMenu = new QPopupMenu(this); |
550 |
|
|
551 |
|
bool bClient = (m_pClient != NULL); |
552 |
|
bool bEnabled = (pItem != NULL); |
553 |
|
iItemID = pContextMenu->insertItem( |
554 |
|
QIconSet(QPixmap::fromMimeSource("deviceCreate.png")), |
555 |
|
tr("&Create device"), this, SLOT(createDevice())); |
556 |
|
pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice)); |
557 |
|
iItemID = pContextMenu->insertItem( |
558 |
|
QIconSet(QPixmap::fromMimeSource("deviceDelete.png")), |
559 |
|
tr("&Delete device"), this, SLOT(deleteDevice())); |
560 |
|
pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice); |
561 |
|
pContextMenu->insertSeparator(); |
562 |
|
iItemID = pContextMenu->insertItem( |
563 |
|
QIconSet(QPixmap::fromMimeSource("formRefresh.png")), |
564 |
|
tr("&Refresh"), this, SLOT(refreshDevices())); |
565 |
|
pContextMenu->setItemEnabled(iItemID, bClient); |
566 |
|
|
567 |
|
pContextMenu->exec(pos); |
568 |
|
|
569 |
|
delete pContextMenu; |
570 |
|
} |
571 |
|
|
572 |
|
|
573 |
|
// Stabilize current form state. |
574 |
|
void qsamplerDeviceForm::stabilizeForm (void) |
575 |
|
{ |
576 |
QListViewItem *pItem = DeviceListView->selectedItem(); |
QListViewItem *pItem = DeviceListView->selectedItem(); |
577 |
|
bool bClient = (m_pClient != NULL); |
578 |
bool bEnabled = (pItem != NULL); |
bool bEnabled = (pItem != NULL); |
579 |
DeviceNameTextLabel->setEnabled(bEnabled); |
DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); |
580 |
DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); |
581 |
DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); |
582 |
DeviceParamTable->setEnabled(bEnabled); |
DeviceParamTable->setEnabled(bEnabled); |
583 |
CreateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 || m_bNewDevice)); |
RefreshDevicesPushButton->setEnabled(bClient); |
584 |
UpdateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice)); |
CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice)); |
585 |
DeleteDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice)); |
DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); |
586 |
} |
} |
587 |
|
|
588 |
|
|
589 |
// end of qsamplerDeviceForm.ui.h |
// end of qsamplerDeviceForm.ui.h |
590 |
|
|
591 |
|
|
592 |
|
|