/[svn]/qsampler/trunk/src/qsamplerDeviceForm.ui.h
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerDeviceForm.ui.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 431 by capela, Tue Mar 8 20:12:08 2005 UTC revision 436 by capela, Wed Mar 9 20:55:04 2005 UTC
# Line 38  void qsamplerDeviceForm::init (void) Line 38  void qsamplerDeviceForm::init (void)
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            m_deviceType  = qsamplerDevice::None;
43    
44            // This an outsider (from designer), but rather important.
45            QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),
46                    this, SLOT(changeValue(int,int)));
47            
48          // Try to restore normal window positioning.          // Try to restore normal window positioning.
49          adjustSize();          adjustSize();
50  }  }
# Line 89  void qsamplerDeviceForm::setClient ( lsc Line 93  void qsamplerDeviceForm::setClient ( lsc
93  }  }
94    
95    
 // 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();  
 }  
   
   
96  // Create a new device from current table view.  // Create a new device from current table view.
97  void qsamplerDeviceForm::createDevice (void)  void qsamplerDeviceForm::createDevice (void)
98  {  {
99          //          //
100          // TODO: Create a new device from current table view...          // TODO: Create a new device from current table view...
101          //          //
102          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()...");          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()");
           
         m_iDirtyCount++;  
         stabilizeForm();  
 }  
103    
104            QListViewItem *pItem = DeviceListView->selectedItem();
105            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
106                    return;
107    
108  // 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()...");  
109    
110          m_iDirtyCount++;          // Build the parameter list...
111          stabilizeForm();          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            int iDeviceID = -1;
126            switch (device.deviceType()) {
127            case qsamplerDevice::Audio:
128                    if ((iDeviceID = ::lscp_create_audio_device(m_pClient,
129                                    device.driverName().latin1(), pParams)) < 0)
130                            m_pMainForm->appendMessagesClient("lscp_create_audio_device");
131                    break;
132            case qsamplerDevice::Midi:
133                    if ((iDeviceID = ::lscp_create_midi_device(m_pClient,
134                                    device.driverName().latin1(), pParams)) < 0)
135                            m_pMainForm->appendMessagesClient("lscp_create_midi_device");
136                    break;
137            case qsamplerDevice::None:
138                    break;
139            }
140    
141            // Free used parameter array.
142            delete pParams;
143    
144            // Show result.
145            if (iDeviceID >= 0) {
146                    m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("created."));
147                    // Done.
148                    refreshDevices();
149                    // Main session should be marked dirty.
150                    m_pMainForm->sessionDirty();
151            }
152  }  }
153    
154    
# Line 248  void qsamplerDeviceForm::deleteDevice (v Line 158  void qsamplerDeviceForm::deleteDevice (v
158          //          //
159          // TODO: Delete current device in table view...          // TODO: Delete current device in table view...
160          //          //
161          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()...");          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()");
162    
163          m_iDirtyCount++;          QListViewItem *pItem = DeviceListView->selectedItem();
164          stabilizeForm();          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
165                    return;
166    
167            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
168    
169            // Now it depends on the device type...
170            lscp_status_t ret = LSCP_FAILED;
171            switch (device.deviceType()) {
172            case qsamplerDevice::Audio:
173                    if ((ret = ::lscp_destroy_audio_device(m_pClient,
174                                    device.deviceID())) != LSCP_OK)
175                            m_pMainForm->appendMessagesClient("lscp_destroy_audio_device");
176                    break;
177            case qsamplerDevice::Midi:
178                    if ((ret = ::lscp_destroy_midi_device(m_pClient,
179                                    device.deviceID())) != LSCP_OK)
180                            m_pMainForm->appendMessagesClient("lscp_destroy_midi_device");
181                    break;
182            case qsamplerDevice::None:
183                    break;
184            }
185    
186            // Show result.
187            if (ret == LSCP_OK) {
188                    m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("deleted."));
189                    // Done.
190                    refreshDevices();
191                    // Main session should be marked dirty.
192                    m_pMainForm->sessionDirty();
193            }
194  }  }
195    
196    
# Line 297  void qsamplerDeviceForm::refreshDevices Line 236  void qsamplerDeviceForm::refreshDevices
236          }          }
237    
238          // Done.          // Done.
239          selectDevice();          m_iDirtyCount = 0;
240          m_iDirtySetup--;          m_iDirtySetup--;
241    
242            // Show something.
243            selectDevice();
244  }  }
245    
246    
247  // Driver selection slot.  // Driver selection slot.
248  void qsamplerDeviceForm::selectDriver ( const QString& sDriverName )  void qsamplerDeviceForm::selectDriver ( const QString& sDriverName )
249  {  {
250            if (m_iDirtySetup > 0)
251                    return;
252    
253          //          //
254          //  TODO: Driver name has changed for a new device...          //  TODO: Driver name has changed for a new device...
255          //          //
256          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver(\"" + sDriverName + "\")");          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver()");
257    
258          QListViewItem *pItem = DeviceListView->selectedItem();          QListViewItem *pItem = DeviceListView->selectedItem();
259          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
260                  return;                  return;
261    
262          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
263    
264            // Driver change is only valid for scratch devices...
265          if (m_bNewDevice) {          if (m_bNewDevice) {
266                  device.setDriver(m_pClient, sDriverName);                  device.setDriver(m_pClient, sDriverName);
267                    DeviceParamTable->refresh(device);
268                  m_iDirtyCount++;                  m_iDirtyCount++;
269                    // Done.
270                    stabilizeForm();
271          }          }
   
         // Done.  
         stabilizeForm();  
272  }  }
273    
274    
275  // Device selection slot.  // Device selection slot.
276  void qsamplerDeviceForm::selectDevice (void)  void qsamplerDeviceForm::selectDevice (void)
277  {  {
278            if (m_iDirtySetup > 0)
279                    return;
280    
281          //          //
282          //  TODO: Device selection has changed...          //  TODO: Device selection has changed...
283          //          //
# Line 335  void qsamplerDeviceForm::selectDevice (v Line 285  void qsamplerDeviceForm::selectDevice (v
285    
286          QListViewItem *pItem = DeviceListView->selectedItem();          QListViewItem *pItem = DeviceListView->selectedItem();
287          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
288                    m_deviceType = qsamplerDevice::None;
289                    DeviceNameTextLabel->setText(QString::null);
290                    DeviceParamTable->setNumRows(0);
291                  stabilizeForm();                  stabilizeForm();
292                  return;                  return;
293          }          }
294    
295          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
296    
297            // Flag whether this is a new device.
298          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
299    
300          // Fill the device heading...          // Fill the device/driver heading...
301          DeviceNameTextLabel->setText(' ' + device.deviceName());          DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName());
302          DriverNameComboBox->clear();          // The driver combobox is only rebuilt if device type has changed...
303          DriverNameComboBox->insertStringList(          if (device.deviceType() != m_deviceType) {
304                  qsamplerDevice::getDrivers(m_pClient, device.deviceType()));                  DriverNameComboBox->clear();
305          const QString& sDriverName = device.driverName();                  DriverNameComboBox->insertStringList(
306          if (m_bNewDevice || sDriverName.isEmpty()) {                          qsamplerDevice::getDrivers(m_pClient, device.deviceType()));
307                  device.setDriver(m_pClient, DriverNameComboBox->currentText());                  m_deviceType = device.deviceType();
         } else {  
                 if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL)  
                         DriverNameComboBox->insertItem(sDriverName);  
                 DriverNameComboBox->setCurrentText(sDriverName);  
308          }          }
309            // Do we need a driver name?
310            if (m_bNewDevice || device.driverName().isEmpty())
311                    device.setDriver(m_pClient, DriverNameComboBox->currentText());
312            const QString& sDriverName = device.driverName();
313            if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL)
314                    DriverNameComboBox->insertItem(sDriverName);
315            DriverNameComboBox->setCurrentText(sDriverName);
316          DriverNameTextLabel->setEnabled(m_bNewDevice);          DriverNameTextLabel->setEnabled(m_bNewDevice);
317          DriverNameComboBox->setEnabled(m_bNewDevice);          DriverNameComboBox->setEnabled(m_bNewDevice);
           
318          // Fill the device parameter table...          // Fill the device parameter table...
319          DeviceParamTable->refresh(device);          DeviceParamTable->refresh(device);
   
320          // Done.          // Done.
321          stabilizeForm();          stabilizeForm();
322  }  }
323    
324    
325  // Stabilize current form state.  // parameter value change slot.
326  void qsamplerDeviceForm::stabilizeForm (void)  void qsamplerDeviceForm::changeValue ( int iRow, int iCol )
327  {  {
         // Update the main caption...  
         QString sDevicesName = devicesName(m_sFilename);  
         if (m_iDirtyCount > 0)  
                 sDevicesName += '*';  
         setCaption(tr("Devices - [%1]").arg(sDevicesName));  
   
328          //          //
329          // TODO: Enable/disable available command buttons.          //  TODO: Device parameter change...
330          //          //
331          m_pMainForm->appendMessages("qsamplerDeviceForm::stabilizeForm()");          m_pMainForm->appendMessages("qsamplerDeviceForm::changeValue()");
332            
333            QListViewItem *pItem = DeviceListView->selectedItem();
334            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
335                    return;
336    
337            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
338    
339          SaveDevicesPushButton->setEnabled(m_iDirtyCount > 0);          // Table 1st column has the parameter name;
340            qsamplerDeviceParamMap& params = device.params();
341            const QString sParam = DeviceParamTable->text(iRow, 0);
342            const QString sValue = DeviceParamTable->text(iRow, iCol);
343            params[sParam].value = sValue;
344    
345            // Set proper device parameter, on existing device ...
346            if (device.deviceID() >= 0) {
347                    // Prepare parameter struct.
348                    lscp_param_t param;
349                    param.key   = (char *) sParam.latin1();
350                    param.value = (char *) sValue.latin1();
351                    // Now it depends on the device type...
352                    lscp_status_t ret = LSCP_FAILED;
353                    switch (device.deviceType()) {
354                    case qsamplerDevice::Audio:
355                            if ((ret = ::lscp_set_audio_device_param(m_pClient,
356                                            device.deviceID(), &param)) != LSCP_OK)
357                                    m_pMainForm->appendMessagesClient("lscp_set_audio_device_param");
358                            break;
359                    case qsamplerDevice::Midi:
360                            if ((ret = ::lscp_set_midi_device_param(m_pClient,
361                                            device.deviceID(), &param)) != LSCP_OK)
362                                    m_pMainForm->appendMessagesClient("lscp_set_midi_device_param");
363                            break;
364                    case qsamplerDevice::None:
365                            break;
366                    }
367                    // Show result.
368                    if (ret == LSCP_OK) {
369                            m_pMainForm->appendMessages(device.deviceName() + ' ' +
370                                    QString("%1: %2.").arg(sParam).arg(sValue));
371                    }
372            }
373    
374            // Done.
375            m_iDirtyCount++;
376            stabilizeForm();
377            // Main session should be dirtier...
378            m_pMainForm->sessionDirty();
379    }
380    
381    
382    // Stabilize current form state.
383    void qsamplerDeviceForm::stabilizeForm (void)
384    {
385          QListViewItem *pItem = DeviceListView->selectedItem();          QListViewItem *pItem = DeviceListView->selectedItem();
386          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
387          DeviceNameTextLabel->setEnabled(bEnabled);          DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
388          DriverNameTextLabel->setEnabled(bEnabled && m_bNewDevice);          DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
389          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
390          DeviceParamTable->setEnabled(bEnabled);          DeviceParamTable->setEnabled(bEnabled);
391          CreateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 ||  m_bNewDevice));          CreateDevicePushButton->setEnabled(bEnabled ||  m_bNewDevice);
392          UpdateDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice));          DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
         DeleteDevicePushButton->setEnabled(bEnabled && (m_iDirtyCount > 0 && !m_bNewDevice));  
393  }  }
394    
395    
396  // end of qsamplerDeviceForm.ui.h  // end of qsamplerDeviceForm.ui.h
   

Legend:
Removed from v.431  
changed lines
  Added in v.436

  ViewVC Help
Powered by ViewVC