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