107 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
108 |
return; |
return; |
109 |
|
|
110 |
const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
// About a brand new device instance... |
111 |
|
qsamplerDevice device(((qsamplerDeviceItem *) pItem)->device()); |
112 |
// Build the parameter list... |
if (device.createDevice()) { |
113 |
const qsamplerDeviceParamMap& params = device.params(); |
// Now it depends on the device type... |
114 |
lscp_param_t *pParams = new lscp_param_t [params.count() + 1]; |
qsamplerDeviceItem *pRootItem = NULL; |
115 |
int iParam = 0; |
switch (device.deviceType()) { |
116 |
qsamplerDeviceParamMap::ConstIterator iter; |
case qsamplerDevice::Audio: |
117 |
for (iter = params.begin(); iter != params.end(); ++iter) { |
pRootItem = m_pAudioItems; |
118 |
pParams[iParam].key = (char *) iter.key().latin1(); |
break; |
119 |
pParams[iParam].value = (char *) iter.data().value.latin1(); |
case qsamplerDevice::Midi: |
120 |
++iParam; |
pRootItem = m_pMidiItems; |
121 |
} |
break; |
122 |
// Null terminated. |
case qsamplerDevice::None: |
123 |
pParams[iParam].key = NULL; |
break; |
124 |
pParams[iParam].value = NULL; |
} |
|
|
|
|
// Now it depends on the device type... |
|
|
qsamplerDeviceItem *pRootItem = NULL; |
|
|
int iDeviceID = -1; |
|
|
switch (device.deviceType()) { |
|
|
case qsamplerDevice::Audio: |
|
|
pRootItem = m_pAudioItems; |
|
|
if ((iDeviceID = ::lscp_create_audio_device(m_pClient, |
|
|
device.driverName().latin1(), pParams)) < 0) |
|
|
m_pMainForm->appendMessagesClient("lscp_create_audio_device"); |
|
|
break; |
|
|
case qsamplerDevice::Midi: |
|
|
pRootItem = m_pMidiItems; |
|
|
if ((iDeviceID = ::lscp_create_midi_device(m_pClient, |
|
|
device.driverName().latin1(), pParams)) < 0) |
|
|
m_pMainForm->appendMessagesClient("lscp_create_midi_device"); |
|
|
break; |
|
|
case qsamplerDevice::None: |
|
|
break; |
|
|
} |
|
|
|
|
|
// Free used parameter array. |
|
|
delete pParams; |
|
|
|
|
|
// We're on to create the new device item. |
|
|
if (iDeviceID >= 0) { |
|
125 |
// Append the new device item. |
// Append the new device item. |
126 |
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
qsamplerDeviceItem *pDeviceItem = new qsamplerDeviceItem(pRootItem, |
127 |
m_pClient, device.deviceType(), iDeviceID); |
m_pMainForm, device.deviceType(), device.deviceID()); |
128 |
// Just make it the new selection... |
// Just make it the new selection... |
129 |
DeviceListView->setSelected(pDeviceItem, true); |
DeviceListView->setSelected(pDeviceItem, true); |
|
// Done. |
|
|
m_pMainForm->appendMessages(pDeviceItem->device().deviceTypeName() |
|
|
+ ' ' + pDeviceItem->device().deviceName() |
|
|
+ ' ' + tr("created.")); |
|
130 |
// Main session should be marked dirty. |
// Main session should be marked dirty. |
131 |
m_pMainForm->sessionDirty(); |
m_pMainForm->sessionDirty(); |
132 |
} |
} |
140 |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) |
141 |
return; |
return; |
142 |
|
|
143 |
const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
144 |
|
|
145 |
// Prompt user if this is for real... |
// Prompt user if this is for real... |
146 |
qsamplerOptions *pOptions = m_pMainForm->options(); |
qsamplerOptions *pOptions = m_pMainForm->options(); |
147 |
if (pOptions && pOptions->bConfirmRemove) { |
if (pOptions && pOptions->bConfirmRemove) { |
148 |
if (QMessageBox::warning(this, tr("Warning"), |
if (QMessageBox::warning(this, tr("Warning"), |
149 |
tr("Delete %1 device:\n\n" |
tr("Delete device:\n\n" |
150 |
"%2\n\n" |
"%1\n\n" |
151 |
"Are you sure?") |
"Are you sure?") |
|
.arg(device.deviceTypeName()) |
|
152 |
.arg(device.deviceName()), |
.arg(device.deviceName()), |
153 |
tr("OK"), tr("Cancel")) > 0) |
tr("OK"), tr("Cancel")) > 0) |
154 |
return; |
return; |
155 |
} |
} |
156 |
|
|
157 |
// Now it depends on the device type... |
// Go and destroy... |
158 |
lscp_status_t ret = LSCP_FAILED; |
if (device.deleteDevice()) { |
159 |
switch (device.deviceType()) { |
// Remove it from the device view... |
|
case qsamplerDevice::Audio: |
|
|
if ((ret = ::lscp_destroy_audio_device(m_pClient, |
|
|
device.deviceID())) != LSCP_OK) |
|
|
m_pMainForm->appendMessagesClient("lscp_destroy_audio_device"); |
|
|
break; |
|
|
case qsamplerDevice::Midi: |
|
|
if ((ret = ::lscp_destroy_midi_device(m_pClient, |
|
|
device.deviceID())) != LSCP_OK) |
|
|
m_pMainForm->appendMessagesClient("lscp_destroy_midi_device"); |
|
|
break; |
|
|
case qsamplerDevice::None: |
|
|
break; |
|
|
} |
|
|
|
|
|
// Show result. |
|
|
if (ret == LSCP_OK) { |
|
|
// Show log message before loosing it. |
|
|
m_pMainForm->appendMessages(device.deviceTypeName() |
|
|
+ ' ' + device.deviceName() |
|
|
+ ' ' + tr("deleted.")); |
|
|
// Done. |
|
160 |
delete pItem; |
delete pItem; |
161 |
// Main session should be marked dirty. |
// Main session should be marked dirty. |
162 |
m_pMainForm->sessionDirty(); |
m_pMainForm->sessionDirty(); |
179 |
if (m_pClient) { |
if (m_pClient) { |
180 |
int *piDeviceIDs; |
int *piDeviceIDs; |
181 |
// Grab and pop Audio devices... |
// Grab and pop Audio devices... |
182 |
m_pAudioItems = new qsamplerDeviceItem(DeviceListView, m_pClient, |
m_pAudioItems = new qsamplerDeviceItem(DeviceListView, m_pMainForm, |
183 |
qsamplerDevice::Audio); |
qsamplerDevice::Audio); |
184 |
if (m_pAudioItems) { |
if (m_pAudioItems) { |
185 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); |
186 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
187 |
new qsamplerDeviceItem(m_pAudioItems, m_pClient, |
new qsamplerDeviceItem(m_pAudioItems, m_pMainForm, |
188 |
qsamplerDevice::Audio, piDeviceIDs[i]); |
qsamplerDevice::Audio, piDeviceIDs[i]); |
189 |
} |
} |
190 |
m_pAudioItems->setOpen(true); |
m_pAudioItems->setOpen(true); |
191 |
} |
} |
192 |
// Grab and pop MIDI devices... |
// Grab and pop MIDI devices... |
193 |
m_pMidiItems = new qsamplerDeviceItem(DeviceListView, m_pClient, |
m_pMidiItems = new qsamplerDeviceItem(DeviceListView, m_pMainForm, |
194 |
qsamplerDevice::Midi); |
qsamplerDevice::Midi); |
195 |
if (m_pMidiItems) { |
if (m_pMidiItems) { |
196 |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); |
197 |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { |
198 |
new qsamplerDeviceItem(m_pMidiItems, m_pClient, |
new qsamplerDeviceItem(m_pMidiItems, m_pMainForm, |
199 |
qsamplerDevice::Midi, piDeviceIDs[i]); |
qsamplerDevice::Midi, piDeviceIDs[i]); |
200 |
} |
} |
201 |
m_pMidiItems->setOpen(true); |
m_pMidiItems->setOpen(true); |
229 |
// Driver change is only valid for scratch devices... |
// Driver change is only valid for scratch devices... |
230 |
if (m_bNewDevice) { |
if (m_bNewDevice) { |
231 |
m_iDirtySetup++; |
m_iDirtySetup++; |
232 |
device.setDriver(m_pClient, sDriverName); |
device.setDriver(sDriverName); |
233 |
DeviceParamTable->refresh(device.params(), m_bNewDevice); |
DeviceParamTable->refresh(device.params(), m_bNewDevice); |
234 |
m_iDirtySetup--; |
m_iDirtySetup--; |
235 |
// Done. |
// Done. |
268 |
m_bNewDevice = (device.deviceID() < 0); |
m_bNewDevice = (device.deviceID() < 0); |
269 |
|
|
270 |
// Fill the device/driver heading... |
// Fill the device/driver heading... |
271 |
QString sPrefix; |
DeviceNameTextLabel->setText(device.deviceName()); |
|
if (!m_bNewDevice) |
|
|
sPrefix += device.deviceTypeName() + ' '; |
|
|
DeviceNameTextLabel->setText(sPrefix + device.deviceName()); |
|
272 |
// The driver combobox is only rebuilt if device type has changed... |
// The driver combobox is only rebuilt if device type has changed... |
273 |
if (device.deviceType() != m_deviceType) { |
if (device.deviceType() != m_deviceType) { |
274 |
DriverNameComboBox->clear(); |
DriverNameComboBox->clear(); |
278 |
} |
} |
279 |
// Do we need a driver name? |
// Do we need a driver name? |
280 |
if (m_bNewDevice || device.driverName().isEmpty()) |
if (m_bNewDevice || device.driverName().isEmpty()) |
281 |
device.setDriver(m_pClient, DriverNameComboBox->currentText()); |
device.setDriver(DriverNameComboBox->currentText()); |
282 |
const QString& sDriverName = device.driverName(); |
const QString& sDriverName = device.driverName(); |
283 |
if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL) |
if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL) |
284 |
DriverNameComboBox->insertItem(sDriverName); |
DriverNameComboBox->insertItem(sDriverName); |
308 |
qsamplerDevicePortList& ports = device.ports(); |
qsamplerDevicePortList& ports = device.ports(); |
309 |
qsamplerDevicePort *pPort; |
qsamplerDevicePort *pPort; |
310 |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
311 |
DevicePortComboBox->insertItem(pixmap, |
DevicePortComboBox->insertItem(pixmap, device.deviceTypeName() |
312 |
device.deviceTypeName() + ' ' + pPort->portName()); |
+ ' ' + device.driverName() |
313 |
|
+ ' ' + pPort->portName()); |
314 |
} |
} |
315 |
bool bEnabled = (ports.count() > 0); |
bool bEnabled = (ports.count() > 0); |
316 |
DevicePortComboBox->setEnabled(bEnabled); |
DevicePortComboBox->setEnabled(bEnabled); |
368 |
|
|
369 |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); |
370 |
|
|
|
m_iDirtySetup++; |
|
371 |
// Table 1st column has the parameter name; |
// Table 1st column has the parameter name; |
372 |
const QString sParam = DeviceParamTable->text(iRow, 0); |
const QString sParam = DeviceParamTable->text(iRow, 0); |
373 |
const QString sValue = DeviceParamTable->text(iRow, iCol); |
const QString sValue = DeviceParamTable->text(iRow, iCol); |
|
int iRefresh = 0; |
|
|
|
|
374 |
// Set the local device parameter value. |
// Set the local device parameter value. |
375 |
device.setParam(sParam, sValue); |
if (device.setParam(sParam, sValue)) { |
|
|
|
|
// Set proper device parameter, on existing device ... |
|
|
if (device.deviceID() >= 0) { |
|
|
// Prepare parameter struct. |
|
|
lscp_param_t param; |
|
|
param.key = (char *) sParam.latin1(); |
|
|
param.value = (char *) sValue.latin1(); |
|
|
// Now it depends on the device type... |
|
|
lscp_status_t ret = LSCP_FAILED; |
|
|
switch (device.deviceType()) { |
|
|
case qsamplerDevice::Audio: |
|
|
if (sParam == "CHANNELS") iRefresh++; |
|
|
if ((ret = ::lscp_set_audio_device_param(m_pClient, |
|
|
device.deviceID(), ¶m)) != LSCP_OK) |
|
|
m_pMainForm->appendMessagesClient("lscp_set_audio_device_param"); |
|
|
break; |
|
|
case qsamplerDevice::Midi: |
|
|
if (sParam == "PORTS") iRefresh++; |
|
|
if ((ret = ::lscp_set_midi_device_param(m_pClient, |
|
|
device.deviceID(), ¶m)) != LSCP_OK) |
|
|
m_pMainForm->appendMessagesClient("lscp_set_midi_device_param"); |
|
|
break; |
|
|
case qsamplerDevice::None: |
|
|
break; |
|
|
} |
|
|
// Show result. |
|
|
if (ret == LSCP_OK) { |
|
|
m_pMainForm->appendMessages(device.deviceTypeName() |
|
|
+ ' ' + device.deviceName() |
|
|
+ ' ' + QString("%1: %2.").arg(sParam).arg(sValue)); |
|
|
// Special care for specific parameter changes... |
|
|
if (iRefresh > 0) |
|
|
iRefresh += device.refreshPorts(m_pClient); |
|
|
iRefresh += device.refreshDepends(m_pClient, sParam); |
|
|
} |
|
|
} |
|
|
|
|
|
// Done. |
|
|
m_iDirtySetup--; |
|
|
// Finally, we might need refreshing... |
|
|
if (iRefresh > 0) |
|
376 |
selectDevice(); |
selectDevice(); |
377 |
else |
} else { |
378 |
stabilizeForm(); |
stabilizeForm(); |
379 |
|
} |
380 |
// Main session should be dirtier... |
// Main session should be dirtier... |
381 |
m_pMainForm->sessionDirty(); |
m_pMainForm->sessionDirty(); |
382 |
} |
} |
405 |
if (pPort == NULL) |
if (pPort == NULL) |
406 |
return; |
return; |
407 |
|
|
|
m_iDirtySetup++; |
|
408 |
// Table 1st column has the parameter name; |
// Table 1st column has the parameter name; |
409 |
const QString sParam = DevicePortParamTable->text(iRow, 0); |
const QString sParam = DevicePortParamTable->text(iRow, 0); |
410 |
const QString sValue = DevicePortParamTable->text(iRow, iCol); |
const QString sValue = DevicePortParamTable->text(iRow, iCol); |
|
|
|
411 |
// Set the local device port/channel parameter value. |
// Set the local device port/channel parameter value. |
412 |
pPort->setParam(sParam, sValue); |
pPort->setParam(sParam, sValue); |
|
|
|
|
// Set proper device port/channel parameter, if any... |
|
|
if (device.deviceID() >= 0 && pPort->portID() >= 0) { |
|
|
// Prepare parameter struct. |
|
|
lscp_param_t param; |
|
|
param.key = (char *) sParam.latin1(); |
|
|
param.value = (char *) sValue.latin1(); |
|
|
// Now it depends on the device type... |
|
|
lscp_status_t ret = LSCP_FAILED; |
|
|
switch (device.deviceType()) { |
|
|
case qsamplerDevice::Audio: |
|
|
if ((ret = ::lscp_set_audio_channel_param(m_pClient, |
|
|
device.deviceID(), pPort->portID(), ¶m)) != LSCP_OK) |
|
|
m_pMainForm->appendMessagesClient("lscp_set_audio_channel_param"); |
|
|
break; |
|
|
case qsamplerDevice::Midi: |
|
|
if ((ret = ::lscp_set_midi_port_param(m_pClient, |
|
|
device.deviceID(), pPort->portID(), ¶m)) != LSCP_OK) |
|
|
m_pMainForm->appendMessagesClient("lscp_set_midi_port_param"); |
|
|
break; |
|
|
case qsamplerDevice::None: |
|
|
break; |
|
|
} |
|
|
// Show result. |
|
|
if (ret == LSCP_OK) { |
|
|
m_pMainForm->appendMessages(device.deviceTypeName() |
|
|
+ ' ' + device.deviceName() + ' ' + pPort->portName() |
|
|
+ ' ' + QString("%1: %2.").arg(sParam).arg(sValue)); |
|
|
} |
|
|
} |
|
|
|
|
413 |
// Done. |
// Done. |
|
m_iDirtySetup--; |
|
414 |
stabilizeForm(); |
stabilizeForm(); |
415 |
// Main session should be dirtier... |
// Main session should be dirtier... |
416 |
m_pMainForm->sessionDirty(); |
m_pMainForm->sessionDirty(); |