/[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 428 by capela, Mon Mar 7 17:05:55 2005 UTC revision 436 by capela, Wed Mar 9 20:55:04 2005 UTC
# Line 2  Line 2 
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
# Line 23  Line 23 
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    
28  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
29    
# Line 32  Line 33 
33  // Kind of constructor.  // Kind of constructor.
34  void qsamplerDeviceForm::init (void)  void qsamplerDeviceForm::init (void)
35  {  {
36      // Initialize locals.          // Initialize locals.
37      m_pMainForm   = (qsamplerMainForm *) QWidget::parentWidget();          m_pMainForm   = (qsamplerMainForm *) QWidget::parentWidget();
38      m_pClient     = NULL;          m_pClient     = NULL;
39          m_iDirtySetup = 0;          m_iDirtySetup = 0;
40      m_iDirtyCount = 0;          m_iDirtyCount = 0;
41      m_iUntitled   = 1;          m_bNewDevice  = false;
42            m_deviceType  = qsamplerDevice::None;
43    
44      // Try to restore normal window positioning.          // This an outsider (from designer), but rather important.
45      adjustSize();          QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),
46                    this, SLOT(changeValue(int,int)));
47            
48            // Try to restore normal window positioning.
49            adjustSize();
50  }  }
51    
52    
# Line 53  void qsamplerDeviceForm::destroy (void) Line 59  void qsamplerDeviceForm::destroy (void)
59  // Notify our parent that we're emerging.  // Notify our parent that we're emerging.
60  void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )  void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )
61  {  {
62      if (m_pMainForm)          if (m_pMainForm)
63          m_pMainForm->stabilizeForm();                  m_pMainForm->stabilizeForm();
64    
65      stabilizeForm();          stabilizeForm();
66    
67      QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
68  }  }
69    
70    
71  // Notify our parent that we're closing.  // Notify our parent that we're closing.
72  void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )  void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )
73  {  {
74      QWidget::hideEvent(pHideEvent);          QWidget::hideEvent(pHideEvent);
75    
76      if (m_pMainForm)          if (m_pMainForm)
77          m_pMainForm->stabilizeForm();                  m_pMainForm->stabilizeForm();
78  }  }
79    
80    
# Line 77  void qsamplerDeviceForm::setClient ( lsc Line 83  void qsamplerDeviceForm::setClient ( lsc
83  {  {
84          // If it has not changed, do nothing.          // If it has not changed, do nothing.
85          if (m_pClient && m_pClient == pClient)          if (m_pClient && m_pClient == pClient)
86              return;                  return;
87    
88          // Set new reference.          // Set new reference.
89          m_pClient = pClient;          m_pClient = pClient;
90                    
         // Set our main client reference.  
     DeviceParameterTable->setClient(m_pClient);  
   
91          // OK. Do a whole refresh around.          // OK. Do a whole refresh around.
92          refreshDevices();          refreshDevices();
93  }  }
94    
95    
96  // Format the displayable device configuration filename.  // Create a new device from current table view.
97  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)  
98  {  {
99      bool bQueryClose = true;          //
100            // TODO: Create a new device from current table view...
101      if (m_iDirtyCount > 0) {          //
102          switch (QMessageBox::warning(this, tr("Warning"),          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()");
             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;  
 }  
   
103    
104            QListViewItem *pItem = DeviceListView->selectedItem();
105            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
106                    return;
107    
108            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
109    
110            // Build the parameter list...
111            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  // Dirty up settings.          // Free used parameter array.
142  void qsamplerDeviceForm::contentsChanged (void)          delete pParams;
 {  
     if (m_iDirtySetup > 0)  
         return;  
143    
144      m_iDirtyCount++;          // Show result.
145      stabilizeForm();          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    
155  // Load device configuration slot.  // Delete current device in table view.
156  void qsamplerDeviceForm::loadDevices (void)  void qsamplerDeviceForm::deleteDevice (void)
157  {  {
158      QString sFilename = QFileDialog::getOpenFileName(          //
159              m_sFilename,                                    // Start here.          // TODO: Delete current device in table view...
160              tr("Device Configuration files") + " (*.lscp)", // Filter (XML files)          //
161              this, 0,                                        // Parent and name (none)          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()");
             tr("Load Device Configuration")                 // Caption.  
     );  
   
     if (sFilename.isEmpty())  
         return;  
162    
163      // Check if we're going to discard safely the current one...          QListViewItem *pItem = DeviceListView->selectedItem();
164      if (!queryClose())          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
165          return;                  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      // Load it right away...          // Show result.
187      loadDevicesFile(sFilename);          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    
197  // Save device configuration slot.  // Refresh all device list and views.
198  void qsamplerDeviceForm::saveDevices (void)  void qsamplerDeviceForm::refreshDevices (void)
199  {  {
200      QString sFilename = QFileDialog::getSaveFileName(          // Avoid nested changes.
201              m_sFilename,                                    // Start here.          m_iDirtySetup++;
             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);  
 }  
202    
   
 // Load device configuration from file.  
 void qsamplerDeviceForm::loadDevicesFile ( const QString& sFilename )  
 {  
203          //          //
204      // TODO: Load device configuration from file...          // TODO: Load device configuration data ...
205          //          //
206          m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")...");          m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");
207    
208          m_sFilename   = sFilename;          DeviceListView->clear();
209            if (m_pClient) {
210                    qsamplerDeviceItem *pItem;
211                    int *piDeviceIDs;
212                    // Grab and pop Audio devices...
213                    pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
214                            qsamplerDevice::Audio);
215                    if (pItem) {
216                            pItem->setText(0, tr("Audio"));
217                            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
218                            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
219                                    new qsamplerDeviceItem(pItem, m_pClient,
220                                            qsamplerDevice::Audio, piDeviceIDs[i]);
221                            }
222                            pItem->setOpen(true);
223                    }
224                    // Grab and pop MIDI devices...
225                    pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
226                            qsamplerDevice::Midi);
227                    if (pItem) {
228                            pItem->setText(0, tr("MIDI"));
229                            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
230                            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
231                                    new qsamplerDeviceItem(pItem, m_pClient,
232                                            qsamplerDevice::Midi, piDeviceIDs[i]);
233                            }
234                            pItem->setOpen(true);
235                    }
236            }
237    
238            // Done.
239          m_iDirtyCount = 0;          m_iDirtyCount = 0;
240            m_iDirtySetup--;
241    
242          refreshDevices();          // Show something.
243            selectDevice();
244  }  }
245    
246    
247  // Save device configuration into file.  // Driver selection slot.
248  void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename )  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...
255          //          //
256      // TODO: Save device configuration into file...          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver()");
     //  
         m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")...");  
257    
258          m_sFilename   = sFilename;          QListViewItem *pItem = DeviceListView->selectedItem();
259          m_iDirtyCount = 0;          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
260          stabilizeForm();                  return;
261    
262            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
263    
264            // Driver change is only valid for scratch devices...
265            if (m_bNewDevice) {
266                    device.setDriver(m_pClient, sDriverName);
267                    DeviceParamTable->refresh(device);
268                    m_iDirtyCount++;
269                    // Done.
270                    stabilizeForm();
271            }
272  }  }
273    
274    
275  // Create a new device from current table view.  // Device selection slot.
276  void qsamplerDeviceForm::createDevice (void)  void qsamplerDeviceForm::selectDevice (void)
277  {  {
278            if (m_iDirtySetup > 0)
279                    return;
280    
281          //          //
282      // TODO: Create a new device from current table view...          //  TODO: Device selection has changed...
283      //          //
284          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()...");          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()");
 }  
285    
286            QListViewItem *pItem = DeviceListView->selectedItem();
287            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
288                    m_deviceType = qsamplerDevice::None;
289                    DeviceNameTextLabel->setText(QString::null);
290                    DeviceParamTable->setNumRows(0);
291                    stabilizeForm();
292                    return;
293            }
294    
295  // 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()...");  
 }  
296    
297            // Flag whether this is a new device.
298            m_bNewDevice = (device.deviceID() < 0);
299    
300  // Delete current device in table view.          // Fill the device/driver heading...
301  void qsamplerDeviceForm::deleteDevice (void)          DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName());
302  {          // The driver combobox is only rebuilt if device type has changed...
303          //          if (device.deviceType() != m_deviceType) {
304      // TODO: Delete current device in table view...                  DriverNameComboBox->clear();
305      //                  DriverNameComboBox->insertStringList(
306          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()...");                          qsamplerDevice::getDrivers(m_pClient, device.deviceType()));
307                    m_deviceType = device.deviceType();
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);
317            DriverNameComboBox->setEnabled(m_bNewDevice);
318            // Fill the device parameter table...
319            DeviceParamTable->refresh(device);
320            // Done.
321            stabilizeForm();
322  }  }
323    
324    
325  // Refresh all device list and views.  // parameter value change slot.
326  void qsamplerDeviceForm::refreshDevices (void)  void qsamplerDeviceForm::changeValue ( int iRow, int iCol )
327  {  {
     // Avoid nested changes.  
     m_iDirtySetup++;  
   
     DeviceListView->clear();  
     if (m_pClient)  
         new QListViewItem(DeviceListView, tr("<New device>"));  
   
328          //          //
329      // TODO: Load device configuration data ...          //  TODO: Device parameter change...
330      //          //
331          m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");          m_pMainForm->appendMessages("qsamplerDeviceForm::changeValue()");
332            
333          DeviceParameterTable->setNumRows(0);          QListViewItem *pItem = DeviceListView->selectedItem();
334          if (m_pClient) {          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
335                  DeviceParameterTable->insertRows(0, 3);                  return;
336                  for (int c = 0; c < DeviceParameterTable->numCols(); c++) {  
337                          for (int r = 0; r < DeviceParameterTable->numRows(); r++)          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
338                                  DeviceParameterTable->setText(r, c, QString("R%1C%1").arg(r).arg(c));  
339                          DeviceParameterTable->adjustColumn(c);          // 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.          // Done.
375      m_iDirtySetup--;          m_iDirtyCount++;
376  //  stabilizeForm();          stabilizeForm();
377            // Main session should be dirtier...
378            m_pMainForm->sessionDirty();
379  }  }
380    
381    
382  // Stabilize current form state.  // Stabilize current form state.
383  void qsamplerDeviceForm::stabilizeForm (void)  void qsamplerDeviceForm::stabilizeForm (void)
384  {  {
385      // Update the main caption...          QListViewItem *pItem = DeviceListView->selectedItem();
386      QString sDevicesName = devicesName(m_sFilename);          bool bEnabled = (pItem != NULL);
387      if (m_iDirtyCount > 0)          DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
388          sDevicesName += '*';          DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
389      setCaption(tr("Devices - [%1]").arg(sDevicesName));          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
390            DeviceParamTable->setEnabled(bEnabled);
391          //          CreateDevicePushButton->setEnabled(bEnabled ||  m_bNewDevice);
392          // TODO: Enable/disable available command buttons.          DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
         //  
         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);  
393  }  }
394    
395    
396  // end of qsamplerDeviceForm.ui.h  // end of qsamplerDeviceForm.ui.h
   

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

  ViewVC Help
Powered by ViewVC