/[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 429 by capela, Tue Mar 8 14:56:05 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;
# Line 87  void qsamplerDeviceForm::setClient ( lsc Line 92  void qsamplerDeviceForm::setClient ( lsc
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)  
 {  
     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 )  
97  {  {
98          //          //
99      // TODO: Load device configuration from file...          // TODO: Create a new device from current table view...
100          //          //
101          m_pMainForm->appendMessages("qsamplerDeviceForm::loadDevicesFile(\"" + sFilename + "\")...");          m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()");
   
         m_sFilename   = sFilename;  
         m_iDirtyCount = 0;  
   
         refreshDevices();  
 }  
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  // Save device configuration into file.          // Free used parameter array.
138  void qsamplerDeviceForm::saveDevicesFile ( const QString& sFilename )          delete [] pParams;
 {  
         //  
     // TODO: Save device configuration into file...  
     //  
         m_pMainForm->appendMessages("qsamplerDeviceForm::saveDevicesFile(\"" + sFilename + "\")...");  
139    
140          m_sFilename   = sFilename;          // Show result.
141          m_iDirtyCount = 0;          if (iDeviceID >= 0) {
142          stabilizeForm();                  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  // Create a new device from current table view.  // Delete current device in table view.
152  void qsamplerDeviceForm::createDevice (void)  void qsamplerDeviceForm::deleteDevice (void)
153  {  {
154          //          //
155      // TODO: Create a new device from current table view...          // TODO: Delete current device in table view...
     //  
         m_pMainForm->appendMessages("qsamplerDeviceForm::createDevice()...");  
 }  
   
   
 // Update current device in table view.  
 void qsamplerDeviceForm::updateDevice (void)  
 {  
156          //          //
157      // TODO: Update current device in table view...          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()");
     //  
         m_pMainForm->appendMessages("qsamplerDeviceForm::updateDevice()...");  
 }  
158    
159            QListViewItem *pItem = DeviceListView->selectedItem();
160            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
161                    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  // Delete current device in table view.          // Show result.
181  void qsamplerDeviceForm::deleteDevice (void)          if (ret == LSCP_OK) {
182  {                  m_pMainForm->appendMessages(device.deviceName() + ' ' + tr("deleted."));
183          //                  // Done.
184      // TODO: Delete current device in table view...                  refreshDevices();
185      //                  // Main session should be marked dirty.
186          m_pMainForm->appendMessages("qsamplerDeviceForm::deleteDevice()...");                  m_pMainForm->sessionDirty();
187            }
188  }  }
189    
190    
191  // Refresh all device list and views.  // Refresh all device list and views.
192  void qsamplerDeviceForm::refreshDevices (void)  void qsamplerDeviceForm::refreshDevices (void)
193  {  {
194      // Avoid nested changes.          // Avoid nested changes.
195      m_iDirtySetup++;          m_iDirtySetup++;
196    
197          //          //
198      // TODO: Load device configuration data ...          // TODO: Load device configuration data ...
199      //          //
       
200          m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");          m_pMainForm->appendMessages("qsamplerDeviceForm::refreshDevices()");
201    
202      DeviceListView->clear();          DeviceListView->clear();
203      if (m_pClient) {          if (m_pClient) {
204                  qsamplerDeviceItem *pItem;                  qsamplerDeviceItem *pItem;
205                  int *piDeviceIDs;                  int *piDeviceIDs;
206                  // Grab audio devices...                  // Grab and pop Audio devices...
207          pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,                  pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
208                          qsamplerDevice::Audio);                          qsamplerDevice::Audio);
209          if (pItem) {                  if (pItem) {
210                          pItem->setText(0, tr("Audio"));                          pItem->setText(0, tr("Audio"));
211                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
212                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
213                              new qsamplerDeviceItem(pItem, m_pClient,                                  new qsamplerDeviceItem(pItem, m_pClient,
214                                          qsamplerDevice::Audio, piDeviceIDs[i]);                                          qsamplerDevice::Audio, piDeviceIDs[i]);
215                          }                          }
216                            pItem->setOpen(true);
217                  }                  }
218                  // Grab MIDI devices...                  // Grab and pop MIDI devices...
219          pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,                  pItem = new qsamplerDeviceItem(DeviceListView, m_pClient,
220                          qsamplerDevice::Midi);                          qsamplerDevice::Midi);
221          if (pItem) {                  if (pItem) {
222                          pItem->setText(0, tr("MIDI"));                          pItem->setText(0, tr("MIDI"));
223                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);                          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
224                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {                          for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) {
225                              new qsamplerDeviceItem(pItem, m_pClient,                                  new qsamplerDeviceItem(pItem, m_pClient,
226                                          qsamplerDevice::Midi, piDeviceIDs[i]);                                          qsamplerDevice::Midi, piDeviceIDs[i]);
227                          }                          }
228                            pItem->setOpen(true);
229                  }                  }
230          }          }
231    
232      // Done.          // Done.
233      m_iDirtySetup--;          m_iDirtyCount = 0;
234  //  stabilizeForm();          m_iDirtySetup--;
235            
236            // Show something.
237            selectDevice();
238  }  }
239    
240  // Device selection slot.  
241  void qsamplerDeviceForm::selectDevice ( QListViewItem *pItem )  // Driver selection slot.
242    void qsamplerDeviceForm::selectDriver ( const QString& sDriverName )
243  {  {
244          if (pItem == NULL)          if (m_iDirtySetup > 0)
245              return;              return;
246          if (pItem->rtti() != QSAMPLER_DEVICE_ITEM)  
247            //
248            //  TODO: Driver name has changed for a new device...
249            //
250            m_pMainForm->appendMessages("qsamplerDeviceForm::selectDriver()");
251    
252            QListViewItem *pItem = DeviceListView->selectedItem();
253            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            // Done.
263            stabilizeForm();
264    }
265    
266    
267    // Device selection slot.
268    void qsamplerDeviceForm::selectDevice (void)
269    {
270            if (m_iDirtySetup > 0)
271              return;              return;
272    
273          m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice(" + pItem->text(0) + ")");          //
274            //  TODO: Device selection has changed...
275            //
276            m_pMainForm->appendMessages("qsamplerDeviceForm::selectDevice()");
277    
278          const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          QListViewItem *pItem = DeviceListView->selectedItem();
279          DeviceParamTable->setDevice(m_pClient,          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM) {
280              device.deviceType(), device.deviceID());              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            // Fill the device/driver heading...
290            DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName());
291            DriverNameComboBox->clear();
292            DriverNameComboBox->insertStringList(
293                    qsamplerDevice::getDrivers(m_pClient, device.deviceType()));
294            const QString& sDriverName = device.driverName();
295            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            // Done.
309            stabilizeForm();
310    }
311    
312    
313    // parameter value change slot.
314    void qsamplerDeviceForm::changeValue ( int iRow, int iCol )
315    {
316            //
317            //  TODO: Device parameter change...
318            //
319            m_pMainForm->appendMessages("qsamplerDeviceForm::changeValue()");
320            
321            QListViewItem *pItem = DeviceListView->selectedItem();
322            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
323                    return;
324    
325            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
326    
327            // Table 3rd column has the parameter name;
328            qsamplerDeviceParamMap& params = device.params();
329            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.
361            m_iDirtyCount++;
362            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.429  
changed lines
  Added in v.433

  ViewVC Help
Powered by ViewVC