/[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 433 by capela, Wed Mar 9 16:44: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    
43      // Try to restore normal window positioning.          // This an outsider (from designer), but rather important.
44      adjustSize();          QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),
45                this, SLOT(changeValue(int,int)));
46            
47            // Try to restore normal window positioning.
48            adjustSize();
49  }  }
50    
51    
# Line 53  void qsamplerDeviceForm::destroy (void) Line 58  void qsamplerDeviceForm::destroy (void)
58  // Notify our parent that we're emerging.  // Notify our parent that we're emerging.
59  void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )  void qsamplerDeviceForm::showEvent ( QShowEvent *pShowEvent )
60  {  {
61      if (m_pMainForm)          if (m_pMainForm)
62          m_pMainForm->stabilizeForm();                  m_pMainForm->stabilizeForm();
63    
64      stabilizeForm();          stabilizeForm();
65    
66      QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
67  }  }
68    
69    
70  // Notify our parent that we're closing.  // Notify our parent that we're closing.
71  void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )  void qsamplerDeviceForm::hideEvent ( QHideEvent *pHideEvent )
72  {  {
73      QWidget::hideEvent(pHideEvent);          QWidget::hideEvent(pHideEvent);
74    
75      if (m_pMainForm)          if (m_pMainForm)
76          m_pMainForm->stabilizeForm();                  m_pMainForm->stabilizeForm();
77  }  }
78    
79    
# Line 77  void qsamplerDeviceForm::setClient ( lsc Line 82  void qsamplerDeviceForm::setClient ( lsc
82  {  {
83          // If it has not changed, do nothing.          // If it has not changed, do nothing.
84          if (m_pClient && m_pClient == pClient)          if (m_pClient && m_pClient == pClient)
85              return;                  return;
86    
87          // Set new reference.          // Set new reference.
88          m_pClient = pClient;          m_pClient = pClient;
89                    
         // Set our main client reference.  
     DeviceParameterTable->setClient(m_pClient);  
   
90          // OK. Do a whole refresh around.          // OK. Do a whole refresh around.
91          refreshDevices();          refreshDevices();
92  }  }
93    
94    
95  // Format the displayable device configuration filename.  // Create a new device from current table view.
96  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)  
97  {  {
98      bool bQueryClose = true;          //
99            // TODO: Create a new device from current table view...
100      if (m_iDirtyCount > 0) {          //
101          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;  
 }  
   
102    
103            QListViewItem *pItem = DeviceListView->selectedItem();
104            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
105                    return;
106    
107            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
108    
109            // Build the parameter list...
110            qsamplerDeviceParamMap& params = device.params();
111            lscp_param_t *pParams = new lscp_param_t [params.count() + 1];
112            int i = 0;
113            qsamplerDeviceParamMap::ConstIterator iter;
114            for (iter = params.begin(); iter != params.end(); ++iter) {
115                    pParams[i].key   = (char *) iter.key().latin1();
116                    pParams[i].value = (char *) iter.data().value.latin1();
117            }
118            // Null terminated.
119            pParams[i].key   = NULL;
120            pParams[i].value = NULL;
121    
122            // Now it depends on the device type...
123            int iDeviceID = -1;
124            switch (device.deviceType()) {
125            case qsamplerDevice::Audio:
126                if ((iDeviceID = ::lscp_create_audio_device(m_pClient,
127                                    device.driverName().latin1(), pParams)) < 0)
128                            m_pMainForm->appendMessagesClient("lscp_create_audio_device");
129                    break;
130            case qsamplerDevice::Midi:
131                if ((iDeviceID = ::lscp_create_midi_device(m_pClient,
132                                    device.driverName().latin1(), pParams)) < 0)
133                            m_pMainForm->appendMessagesClient("lscp_create_midi_device");
134                    break;
135            }
136    
137  // Dirty up settings.          // Free used parameter array.
138  void qsamplerDeviceForm::contentsChanged (void)          delete [] pParams;
 {  
     if (m_iDirtySetup > 0)  
         return;  
139    
140      m_iDirtyCount++;          // Show result.
141      stabilizeForm();          if (iDeviceID >= 0) {
142                    m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("created."));
143                    // Done.
144                    refreshDevices();
145                    // Main session should be marked dirty.
146                    m_pMainForm->sessionDirty();
147            }
148  }  }
149    
150    
151  // Load device configuration slot.  // Delete current device in table view.
152  void qsamplerDeviceForm::loadDevices (void)  void qsamplerDeviceForm::deleteDevice (void)
153  {  {
154      QString sFilename = QFileDialog::getOpenFileName(          //
155              m_sFilename,                                    // Start here.          // TODO: Delete current device in table view...
156              tr("Device Configuration files") + " (*.lscp)", // Filter (XML files)          //
157              this, 0,                                        // Parent and name (none)          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()");
             tr("Load Device Configuration")                 // Caption.  
     );  
   
     if (sFilename.isEmpty())  
         return;  
158    
159      // Check if we're going to discard safely the current one...          QListViewItem *pItem = DeviceListView->selectedItem();
160      if (!queryClose())          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
161          return;                  return;
162    
163            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
164    
165            // Now it depends on the device type...
166            lscp_status_t ret = LSCP_FAILED;
167            switch (device.deviceType()) {
168            case qsamplerDevice::Audio:
169                if ((ret = ::lscp_destroy_audio_device(m_pClient,
170                                    device.deviceID())) != LSCP_OK)
171                            m_pMainForm->appendMessagesClient("lscp_destroy_audio_device");
172                    break;
173            case qsamplerDevice::Midi:
174                if ((ret = ::lscp_destroy_midi_device(m_pClient,
175                                    device.deviceID())) != LSCP_OK)
176                            m_pMainForm->appendMessagesClient("lscp_destroy_midi_device");
177                    break;
178            }
179    
180      // Load it right away...          // Show result.
181      loadDevicesFile(sFilename);          if (ret == LSCP_OK) {
182                    m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("deleted."));
183                    // Done.
184                    refreshDevices();
185                    // Main session should be marked dirty.
186                    m_pMainForm->sessionDirty();
187            }
188  }  }
189    
190    
191  // Save device configuration slot.  // Refresh all device list and views.
192  void qsamplerDeviceForm::saveDevices (void)  void qsamplerDeviceForm::refreshDevices (void)
193  {  {
194      QString sFilename = QFileDialog::getSaveFileName(          // Avoid nested changes.
195              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.  
     );  
196    
197      if (sFilename.isEmpty())          //
198          return;          // TODO: Load device configuration data ...
199            //
200            m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");
201    
202      // Enforce .xml extension...          DeviceListView->clear();
203      if (QFileInfo(sFilename).extension().isEmpty())          if (m_pClient) {
204          sFilename += ".lscp";                  qsamplerDeviceItem *pItem;
205                    int *piDeviceIDs;
206                    // Grab and pop Audio devices...
207                    pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
208                            qsamplerDevice::Audio);
209                    if (pItem) {
210                            pItem->setText(0, tr("Audio"));
211                            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
212                            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
213                                    new qsamplerDeviceItem(pItem, m_pClient,
214                                            qsamplerDevice::Audio, piDeviceIDs[i]);
215                            }
216                            pItem->setOpen(true);
217                    }
218                    // Grab and pop MIDI devices...
219                    pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
220                            qsamplerDevice::Midi);
221                    if (pItem) {
222                            pItem->setText(0, tr("MIDI"));
223                            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
224                            for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
225                                    new qsamplerDeviceItem(pItem, m_pClient,
226                                            qsamplerDevice::Midi, piDeviceIDs[i]);
227                            }
228                            pItem->setOpen(true);
229                    }
230            }
231    
232      // Save it right away...          // Done.
233      saveDevicesFile(sFilename);          m_iDirtyCount = 0;
234            m_iDirtySetup--;
235            
236            // Show something.
237            selectDevice();
238  }  }
239    
240    
241  // Load device configuration from file.  // Driver selection slot.
242  void qsamplerDeviceForm::loadDevicesFile ( const QString& sFilename )  void qsamplerDeviceForm::selectDriver ( const QString& sDriverName )
243  {  {
244            if (m_iDirtySetup > 0)
245                return;
246    
247          //          //
248      // TODO: Load device configuration from file...          //  TODO: Driver name has changed for a new device...
249          //          //
250          m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")...");          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver()");
251    
252          m_sFilename   = sFilename;          QListViewItem *pItem = DeviceListView->selectedItem();
253          m_iDirtyCount = 0;          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
254                    return;
255    
256            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
257            if (m_bNewDevice) {
258                    device.setDriver(m_pClient, sDriverName);
259                    m_iDirtyCount++;
260            }
261    
262          refreshDevices();          // Done.
263            stabilizeForm();
264  }  }
265    
266    
267  // Save device configuration into file.  // Device selection slot.
268  void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename )  void qsamplerDeviceForm::selectDevice (void)
269  {  {
270            if (m_iDirtySetup > 0)
271                return;
272    
273          //          //
274      // TODO: Save device configuration into file...          //  TODO: Device selection has changed...
275      //          //
276          m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")...");          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()");
277    
278          m_sFilename   = sFilename;          QListViewItem *pItem = DeviceListView->selectedItem();
279          m_iDirtyCount = 0;          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
280          stabilizeForm();              DeviceNameTextLabel->setText(QString::null);
281  }              DeviceParamTable->setNumRows(0);
282                    stabilizeForm();
283                    return;
284            }
285    
286            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
287            m_bNewDevice = (device.deviceID() < 0);
288    
289  // Create a new device from current table view.          // Fill the device/driver heading...
290  void qsamplerDeviceForm::createDevice (void)          DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName());
291  {          DriverNameComboBox->clear();
292          //          DriverNameComboBox->insertStringList(
293      // TODO: Create a new device from current table view...                  qsamplerDevice::getDrivers(m_pClient, device.deviceType()));
294      //          const QString& sDriverName = device.driverName();
295          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()...");          if (m_bNewDevice || sDriverName.isEmpty()) {
296  }                  device.setDriver(m_pClient, DriverNameComboBox->currentText());
297            } else {
298                    if (DriverNameComboBox->listBox()->findItem(sDriverName, Qt::ExactMatch) == NULL)
299                            DriverNameComboBox->insertItem(sDriverName);
300                    DriverNameComboBox->setCurrentText(sDriverName);
301            }
302            DriverNameTextLabel->setEnabled(m_bNewDevice);
303            DriverNameComboBox->setEnabled(m_bNewDevice);
304    
305            // Fill the device parameter table...
306            DeviceParamTable->refresh(device);
307    
308  // Update current device in table view.          // Done.
309  void qsamplerDeviceForm::updateDevice (void)          stabilizeForm();
 {  
         //  
     // TODO: Update current device in table view...  
     //  
         m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()...");  
310  }  }
311    
312    
313  // Delete current device in table view.  // parameter value change slot.
314  void qsamplerDeviceForm::deleteDevice (void)  void qsamplerDeviceForm::changeValue ( int iRow, int iCol )
315  {  {
316          //          //
317      // TODO: Delete current device in table view...          //  TODO: Device parameter change...
     //  
         m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()...");  
 }  
   
   
 // Refresh all device list and views.  
 void qsamplerDeviceForm::refreshDevices (void)  
 {  
     // Avoid nested changes.  
     m_iDirtySetup++;  
   
     DeviceListView->clear();  
     if (m_pClient)  
         new QListViewItem(DeviceListView, tr("<New device>"));  
   
318          //          //
319      // TODO: Load device configuration data ...          m_pMainForm->appendMessages("qsamplerDeviceForm::changeValue()");
320      //          
321          m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");          QListViewItem *pItem = DeviceListView->selectedItem();
322            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
323          DeviceParameterTable->setNumRows(0);                  return;
324          if (m_pClient) {  
325                  DeviceParameterTable->insertRows(0, 3);          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
326                  for (int c = 0; c < DeviceParameterTable->numCols(); c++) {  
327                          for (int r = 0; r < DeviceParameterTable->numRows(); r++)          // Table 3rd column has the parameter name;
328                                  DeviceParameterTable->setText(r, c, QString("R%1C%1").arg(r).arg(c));          qsamplerDeviceParamMap& params = device.params();
329                          DeviceParameterTable->adjustColumn(c);          const QString sParam = DeviceParamTable->text(iRow, 2);
330            const QString sValue = DeviceParamTable->text(iRow, iCol);
331            params[sParam].value = sValue;
332    
333            // Set proper device parameter, on existing device ...
334            if (device.deviceID() >= 0) {
335                    // Prepare parameter struct.
336                    lscp_param_t param;
337                    param.key   = (char *) sParam.latin1();
338                    param.value = (char *) sValue.latin1();
339                    // Now it depends on the device type...
340                    lscp_status_t ret = LSCP_FAILED;
341                    switch (device.deviceType()) {
342                    case qsamplerDevice::Audio:
343                        if ((ret = ::lscp_set_audio_device_param(m_pClient,
344                                            device.deviceID(), &param)) != LSCP_OK)
345                                    m_pMainForm->appendMessagesClient("lscp_set_audio_device_param");
346                            break;
347                    case qsamplerDevice::Midi:
348                        if ((ret = ::lscp_set_midi_device_param(m_pClient,
349                                            device.deviceID(), &param)) != LSCP_OK)
350                                    m_pMainForm->appendMessagesClient("lscp_set_midi_device_param");
351                            break;
352                    }
353                    // Show result.
354                    if (ret == LSCP_OK) {
355                            m_pMainForm->appendMessages(device.deviceName() + ' ' +
356                                    QString("%1: %2.").arg(sParam).arg(sValue));
357                  }                  }
358          }          }
359            
360      // Done.          // Done.
361      m_iDirtySetup--;          m_iDirtyCount++;
362  //  stabilizeForm();          stabilizeForm();
363            // Main session should be dirtier...
364            m_pMainForm->sessionDirty();
365  }  }
366    
367    
368  // Stabilize current form state.  // Stabilize current form state.
369  void qsamplerDeviceForm::stabilizeForm (void)  void qsamplerDeviceForm::stabilizeForm (void)
370  {  {
371      // Update the main caption...          QListViewItem *pItem = DeviceListView->selectedItem();
372      QString sDevicesName = devicesName(m_sFilename);          bool bEnabled = (pItem != NULL);
373      if (m_iDirtyCount > 0)          DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
374          sDevicesName += '*';          DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
375      setCaption(tr("Devices - [%1]").arg(sDevicesName));          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
376            DeviceParamTable->setEnabled(bEnabled);
377          //          CreateDevicePushButton->setEnabled(bEnabled ||  m_bNewDevice);
378          // 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);  
379  }  }
380    
381    

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

  ViewVC Help
Powered by ViewVC