--- qsampler/trunk/src/qsamplerDeviceForm.ui.h 2005/03/08 14:56:05 429 +++ qsampler/trunk/src/qsamplerDeviceForm.ui.h 2005/03/09 16:44:04 433 @@ -2,7 +2,7 @@ // // ui.h extension file, included from the uic-generated form implementation. /**************************************************************************** - Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2005, rncbc aka Rui Nuno Capela. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -23,6 +23,7 @@ #include #include #include +#include #include "qsamplerMainForm.h" @@ -32,15 +33,19 @@ // Kind of constructor. void qsamplerDeviceForm::init (void) { - // Initialize locals. - m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); - m_pClient = NULL; + // Initialize locals. + m_pMainForm = (qsamplerMainForm *) QWidget::parentWidget(); + m_pClient = NULL; m_iDirtySetup = 0; - m_iDirtyCount = 0; - m_iUntitled = 1; + m_iDirtyCount = 0; + m_bNewDevice = false; - // Try to restore normal window positioning. - adjustSize(); + // This an outsider (from designer), but rather important. + QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)), + this, SLOT(changeValue(int,int))); + + // Try to restore normal window positioning. + adjustSize(); } @@ -53,22 +58,22 @@ // Notify our parent that we're emerging. void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent ) { - if (m_pMainForm) - m_pMainForm->stabilizeForm(); + if (m_pMainForm) + m_pMainForm->stabilizeForm(); - stabilizeForm(); + stabilizeForm(); - QWidget::showEvent(pShowEvent); + QWidget::showEvent(pShowEvent); } // Notify our parent that we're closing. void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent ) { - QWidget::hideEvent(pHideEvent); + QWidget::hideEvent(pHideEvent); - if (m_pMainForm) - m_pMainForm->stabilizeForm(); + if (m_pMainForm) + m_pMainForm->stabilizeForm(); } @@ -77,7 +82,7 @@ { // If it has not changed, do nothing. if (m_pClient && m_pClient == pClient) - return; + return; // Set new reference. m_pClient = pClient; @@ -87,243 +92,290 @@ } -// 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 ) +// Create a new device from current table view. +void qsamplerDeviceForm::createDevice (void) { // - // TODO: Load device configuration from file... + // TODO: Create a new device from current table view... // - m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")..."); - - m_sFilename = sFilename; - m_iDirtyCount = 0; - - refreshDevices(); -} + m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()"); + QListViewItem *pItem = DeviceListView->selectedItem(); + if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) + return; + + qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); + + // Build the parameter list... + qsamplerDeviceParamMap& params = device.params(); + lscp_param_t *pParams = new lscp_param_t [params.count() + 1]; + int i = 0; + qsamplerDeviceParamMap::ConstIterator iter; + for (iter = params.begin(); iter != params.end(); ++iter) { + pParams[i].key = (char *) iter.key().latin1(); + pParams[i].value = (char *) iter.data().value.latin1(); + } + // Null terminated. + pParams[i].key = NULL; + pParams[i].value = NULL; + + // Now it depends on the device type... + int iDeviceID = -1; + switch (device.deviceType()) { + case qsamplerDevice::Audio: + if ((iDeviceID = ::lscp_create_audio_device(m_pClient, + device.driverName().latin1(), pParams)) < 0) + m_pMainForm->appendMessagesClient("lscp_create_audio_device"); + break; + case qsamplerDevice::Midi: + if ((iDeviceID = ::lscp_create_midi_device(m_pClient, + device.driverName().latin1(), pParams)) < 0) + m_pMainForm->appendMessagesClient("lscp_create_midi_device"); + break; + } -// Save device configuration into file. -void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename ) -{ - // - // TODO: Save device configuration into file... - // - m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")..."); + // Free used parameter array. + delete [] pParams; - m_sFilename = sFilename; - m_iDirtyCount = 0; - stabilizeForm(); + // Show result. + if (iDeviceID >= 0) { + m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("created.")); + // Done. + refreshDevices(); + // Main session should be marked dirty. + m_pMainForm->sessionDirty(); + } } -// Create a new device from current table view. -void qsamplerDeviceForm::createDevice (void) +// Delete current device in table view. +void qsamplerDeviceForm::deleteDevice (void) { // - // TODO: Create a new device from current table view... - // - m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()..."); -} - - -// Update current device in table view. -void qsamplerDeviceForm::updateDevice (void) -{ + // TODO: Delete current device in table view... // - // TODO: Update current device in table view... - // - m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()..."); -} + m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()"); + QListViewItem *pItem = DeviceListView->selectedItem(); + if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) + return; + + qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); + + // Now it depends on the device type... + lscp_status_t ret = LSCP_FAILED; + switch (device.deviceType()) { + 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; + } -// Delete current device in table view. -void qsamplerDeviceForm::deleteDevice (void) -{ - // - // TODO: Delete current device in table view... - // - m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()..."); + // Show result. + if (ret == LSCP_OK) { + m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("deleted.")); + // Done. + refreshDevices(); + // Main session should be marked dirty. + m_pMainForm->sessionDirty(); + } } // Refresh all device list and views. void qsamplerDeviceForm::refreshDevices (void) { - // Avoid nested changes. - m_iDirtySetup++; + // Avoid nested changes. + m_iDirtySetup++; // - // TODO: Load device configuration data ... - // - + // TODO: Load device configuration data ... + // m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()"); - DeviceListView->clear(); - if (m_pClient) { + DeviceListView->clear(); + if (m_pClient) { qsamplerDeviceItem *pItem; int *piDeviceIDs; - // Grab audio devices... - pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, + // Grab and pop Audio devices... + pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, qsamplerDevice::Audio); - if (pItem) { + if (pItem) { pItem->setText(0, tr("Audio")); piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio); for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { - new qsamplerDeviceItem(pItem, m_pClient, + new qsamplerDeviceItem(pItem, m_pClient, qsamplerDevice::Audio, piDeviceIDs[i]); } + pItem->setOpen(true); } - // Grab MIDI devices... - pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, + // Grab and pop MIDI devices... + pItem = new qsamplerDeviceItem(DeviceListView, m_pClient, qsamplerDevice::Midi); - if (pItem) { + if (pItem) { pItem->setText(0, tr("MIDI")); piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi); for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { - new qsamplerDeviceItem(pItem, m_pClient, + new qsamplerDeviceItem(pItem, m_pClient, qsamplerDevice::Midi, piDeviceIDs[i]); } + pItem->setOpen(true); } } - // Done. - m_iDirtySetup--; -// stabilizeForm(); + // Done. + m_iDirtyCount = 0; + m_iDirtySetup--; + + // Show something. + selectDevice(); } -// Device selection slot. -void qsamplerDeviceForm::selectDevice ( QListViewItem *pItem ) + +// Driver selection slot. +void qsamplerDeviceForm::selectDriver ( const QString& sDriverName ) { - if (pItem == NULL) + if (m_iDirtySetup > 0) return; - if (pItem->rtti() != QSAMPLER_DEVICE_ITEM) + + // + // TODO: Driver name has changed for a new device... + // + m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver()"); + + QListViewItem *pItem = DeviceListView->selectedItem(); + if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) + return; + + qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); + if (m_bNewDevice) { + device.setDriver(m_pClient, sDriverName); + m_iDirtyCount++; + } + + // Done. + stabilizeForm(); +} + + +// Device selection slot. +void qsamplerDeviceForm::selectDevice (void) +{ + if (m_iDirtySetup > 0) return; - m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice(" + pItem->text(0) + ")"); + // + // TODO: Device selection has changed... + // + m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()"); - const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); - DeviceParamTable->setDevice(m_pClient, - device.deviceType(), device.deviceID()); + QListViewItem *pItem = DeviceListView->selectedItem(); + if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) { + DeviceNameTextLabel->setText(QString::null); + DeviceParamTable->setNumRows(0); + stabilizeForm(); + return; + } + + qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); + m_bNewDevice = (device.deviceID() < 0); + + // Fill the device/driver heading... + DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName()); + DriverNameComboBox->clear(); + DriverNameComboBox->insertStringList( + qsamplerDevice::getDrivers(m_pClient, device.deviceType())); + const QString& sDriverName = device.driverName(); + if (m_bNewDevice || sDriverName.isEmpty()) { + device.setDriver(m_pClient, DriverNameComboBox->currentText()); + } else { + if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL) + DriverNameComboBox->insertItem(sDriverName); + DriverNameComboBox->setCurrentText(sDriverName); + } + DriverNameTextLabel->setEnabled(m_bNewDevice); + DriverNameComboBox->setEnabled(m_bNewDevice); + + // Fill the device parameter table... + DeviceParamTable->refresh(device); + + // Done. + stabilizeForm(); +} + + +// parameter value change slot. +void qsamplerDeviceForm::changeValue ( int iRow, int iCol ) +{ + // + // TODO: Device parameter change... + // + m_pMainForm->appendMessages("qsamplerDeviceForm::changeValue()"); + + QListViewItem *pItem = DeviceListView->selectedItem(); + if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) + return; + + qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device(); + + // Table 3rd column has the parameter name; + qsamplerDeviceParamMap& params = device.params(); + const QString sParam = DeviceParamTable->text(iRow, 2); + const QString sValue = DeviceParamTable->text(iRow, iCol); + params[sParam].value = 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 ((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 ((ret = ::lscp_set_midi_device_param(m_pClient, + device.deviceID(), ¶m)) != LSCP_OK) + m_pMainForm->appendMessagesClient("lscp_set_midi_device_param"); + break; + } + // Show result. + if (ret == LSCP_OK) { + m_pMainForm->appendMessages(device.deviceName() + ' ' + + QString("%1: %2.").arg(sParam).arg(sValue)); + } + } + + // Done. + m_iDirtyCount++; + stabilizeForm(); + // Main session should be dirtier... + m_pMainForm->sessionDirty(); } // Stabilize current form state. void qsamplerDeviceForm::stabilizeForm (void) { - // 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); - - CreateDevicePushButton->setEnabled(m_iDirtyCount > 0); - UpdateDevicePushButton->setEnabled(m_iDirtyCount > 0); - DeleteDevicePushButton->setEnabled(m_iDirtyCount > 0); + QListViewItem *pItem = DeviceListView->selectedItem(); + bool bEnabled = (pItem != NULL); + DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice); + DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice); + DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice); + DeviceParamTable->setEnabled(bEnabled); + CreateDevicePushButton->setEnabled(bEnabled || m_bNewDevice); + DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice); }