/[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 448 by capela, Thu Mar 10 21:40:11 2005 UTC revision 467 by capela, Tue Mar 15 23:54:14 2005 UTC
# Line 24  Line 24 
24  #include <qfiledialog.h>  #include <qfiledialog.h>
25  #include <qfileinfo.h>  #include <qfileinfo.h>
26  #include <qlistbox.h>  #include <qlistbox.h>
27    #include <qptrlist.h>
28    #include <qpopupmenu.h>
29    
30  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
31    
# Line 44  void qsamplerDeviceForm::init (void) Line 46  void qsamplerDeviceForm::init (void)
46    
47          // This an outsider (from designer), but rather important.          // This an outsider (from designer), but rather important.
48          QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),          QObject::connect(DeviceParamTable, SIGNAL(valueChanged(int,int)),
49                  this, SLOT(changeValue(int,int)));                  this, SLOT(changeDeviceParam(int,int)));
50                    QObject::connect(DevicePortParamTable, SIGNAL(valueChanged(int,int)),
51                    this, SLOT(changeDevicePortParam(int,int)));
52    
53            // Initial contents.
54            refreshDevices();
55          // Try to restore normal window positioning.          // Try to restore normal window positioning.
56          adjustSize();          adjustSize();
57  }  }
# Line 101  void qsamplerDeviceForm::createDevice (v Line 107  void qsamplerDeviceForm::createDevice (v
107          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
108                  return;                  return;
109    
110          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
111    
112          // Build the parameter list...          // Build the parameter list...
113          qsamplerDeviceParamMap& params = device.params();          const qsamplerDeviceParamMap& params = device.params();
114          lscp_param_t *pParams = new lscp_param_t [params.count() + 1];          lscp_param_t *pParams = new lscp_param_t [params.count() + 1];
115          int iParam = 0;          int iParam = 0;
116          qsamplerDeviceParamMap::ConstIterator iter;          qsamplerDeviceParamMap::ConstIterator iter;
# Line 148  void qsamplerDeviceForm::createDevice (v Line 154  void qsamplerDeviceForm::createDevice (v
154                  // Just make it the new selection...                  // Just make it the new selection...
155                  DeviceListView->setSelected(pDeviceItem, true);                  DeviceListView->setSelected(pDeviceItem, true);
156                  // Done.                  // Done.
157                  m_pMainForm->appendMessages(pDeviceItem->device().deviceName() + ' '                  m_pMainForm->appendMessages(pDeviceItem->device().deviceTypeName()
158                          + tr("created."));                          + ' ' + pDeviceItem->device().deviceName()
159                            + ' ' + tr("created."));
160                  // Main session should be marked dirty.                  // Main session should be marked dirty.
161                  m_pMainForm->sessionDirty();                  m_pMainForm->sessionDirty();
162          }          }
# Line 163  void qsamplerDeviceForm::deleteDevice (v Line 170  void qsamplerDeviceForm::deleteDevice (v
170          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
171                  return;                  return;
172    
173          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
174    
175          // Prompt user if this is for real...          // Prompt user if this is for real...
176          qsamplerOptions *pOptions = m_pMainForm->options();          qsamplerOptions *pOptions = m_pMainForm->options();
# Line 198  void qsamplerDeviceForm::deleteDevice (v Line 205  void qsamplerDeviceForm::deleteDevice (v
205          // Show result.          // Show result.
206          if (ret == LSCP_OK) {          if (ret == LSCP_OK) {
207                  // Show log message before loosing it.                  // Show log message before loosing it.
208                  m_pMainForm->appendMessages(device.deviceName() + ' '                  m_pMainForm->appendMessages(device.deviceTypeName()
209                          + tr("deleted."));                          + ' ' + device.deviceName()
210                            + ' ' + tr("deleted."));
211                  // Done.                  // Done.
212                  delete pItem;                  delete pItem;
213                  // Main session should be marked dirty.                  // Main session should be marked dirty.
# Line 276  void qsamplerDeviceForm::selectDriver ( Line 284  void qsamplerDeviceForm::selectDriver (
284          if (m_bNewDevice) {          if (m_bNewDevice) {
285                  m_iDirtySetup++;                  m_iDirtySetup++;
286                  device.setDriver(m_pClient, sDriverName);                  device.setDriver(m_pClient, sDriverName);
287                  DeviceParamTable->refresh(device);                  DeviceParamTable->refresh(device.params(), m_bNewDevice);
288                  m_iDirtySetup--;                  m_iDirtySetup--;
289                  // Done.                  // Done.
290                  stabilizeForm();                  stabilizeForm();
# Line 299  void qsamplerDeviceForm::selectDevice (v Line 307  void qsamplerDeviceForm::selectDevice (v
307                  m_deviceType = qsamplerDevice::None;                  m_deviceType = qsamplerDevice::None;
308                  DeviceNameTextLabel->setText(QString::null);                  DeviceNameTextLabel->setText(QString::null);
309                  DeviceParamTable->setNumRows(0);                  DeviceParamTable->setNumRows(0);
310                    DevicePortParamTable->setNumRows(0);
311                    DevicePortComboBox->setEnabled(false);
312                    DevicePortParamTable->setEnabled(false);
313                  stabilizeForm();                  stabilizeForm();
314                  return;                  return;
315          }          }
316    
         m_iDirtySetup++;  
317          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
318    
319            m_iDirtySetup++;
320          // Flag whether this is a new device.          // Flag whether this is a new device.
321          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
322    
323          // Fill the device/driver heading...          // Fill the device/driver heading...
324          DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName());          QString sPrefix;
325            if (!m_bNewDevice)
326                    sPrefix += device.deviceTypeName() + ' ';
327            DeviceNameTextLabel->setText(sPrefix + device.deviceName());
328          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
329          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
330                  DriverNameComboBox->clear();                  DriverNameComboBox->clear();
# Line 328  void qsamplerDeviceForm::selectDevice (v Line 342  void qsamplerDeviceForm::selectDevice (v
342          DriverNameTextLabel->setEnabled(m_bNewDevice);          DriverNameTextLabel->setEnabled(m_bNewDevice);
343          DriverNameComboBox->setEnabled(m_bNewDevice);          DriverNameComboBox->setEnabled(m_bNewDevice);
344          // Fill the device parameter table...          // Fill the device parameter table...
345          DeviceParamTable->refresh(device);          DeviceParamTable->refresh(device.params(), m_bNewDevice);
346            // And now the device port/channel parameter table...
347            DevicePortComboBox->clear();
348            DevicePortParamTable->setNumRows(0);
349            if (m_bNewDevice) {
350                    DevicePortComboBox->setEnabled(false);
351                    DevicePortParamTable->setEnabled(false);
352            } else {
353                    QPixmap pixmap;
354                    switch (device.deviceType()) {
355                    case qsamplerDevice::Audio:
356                        pixmap = QPixmap::fromMimeSource("audio2.png");
357                        break;
358                    case qsamplerDevice::Midi:
359                        pixmap = QPixmap::fromMimeSource("midi2.png");
360                        break;
361                    case qsamplerDevice::None:
362                        break;
363                    }
364                    qsamplerDevicePortList& ports = device.ports();
365                    qsamplerDevicePort *pPort;
366                    for (pPort = ports.first(); pPort; pPort = ports.next()) {
367                DevicePortComboBox->insertItem(pixmap,
368                                    device.deviceTypeName() + ' ' + pPort->portName());
369                    }
370                    bool bEnabled = (ports.count() > 0);
371                    DevicePortComboBox->setEnabled(bEnabled);
372                    DevicePortParamTable->setEnabled(bEnabled);
373            }
374          // Done.          // Done.
375          m_iDirtySetup--;          m_iDirtySetup--;
376            
377            // Make the device port/channel selection effective.
378            selectDevicePort(DevicePortComboBox->currentItem());
379    }
380    
381    
382    // Device port/channel selection slot.
383    void qsamplerDeviceForm::selectDevicePort ( int iPort )
384    {
385            if (m_iDirtySetup > 0)
386                    return;
387    
388            //
389            //  Device port/channel selection has changed...
390            //
391    
392            QListViewItem *pItem = DeviceListView->selectedItem();
393            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
394                    return;
395    
396            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
397            qsamplerDevicePort *pPort = device.ports().at(iPort);
398            if (pPort) {
399                    m_iDirtySetup++;
400                    DevicePortParamTable->refresh(pPort->params(), false);
401                    m_iDirtySetup--;
402            }
403            // Done.
404          stabilizeForm();          stabilizeForm();
405  }  }
406    
407    
408  // parameter value change slot.  // Device parameter value change slot.
409  void qsamplerDeviceForm::changeValue ( int iRow, int iCol )  void qsamplerDeviceForm::changeDeviceParam ( int iRow, int iCol )
410  {  {
411          if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
412                  return;                  return;
# Line 351  void qsamplerDeviceForm::changeValue ( i Line 421  void qsamplerDeviceForm::changeValue ( i
421          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
422                  return;                  return;
423    
         m_iDirtySetup++;  
424          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
425    
426            m_iDirtySetup++;
427          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
         qsamplerDeviceParamMap& params = device.params();  
428          const QString sParam = DeviceParamTable->text(iRow, 0);          const QString sParam = DeviceParamTable->text(iRow, 0);
429          const QString sValue = DeviceParamTable->text(iRow, iCol);          const QString sValue = DeviceParamTable->text(iRow, iCol);
430          params[sParam].value = sValue;          int iRefresh = 0;
431            
432            // Set the local device parameter value.
433            device.setParam(sParam, sValue);
434    
435          // Set proper device parameter, on existing device ...          // Set proper device parameter, on existing device ...
436          if (device.deviceID() >= 0) {          if (device.deviceID() >= 0) {
# Line 370  void qsamplerDeviceForm::changeValue ( i Line 442  void qsamplerDeviceForm::changeValue ( i
442                  lscp_status_t ret = LSCP_FAILED;                  lscp_status_t ret = LSCP_FAILED;
443                  switch (device.deviceType()) {                  switch (device.deviceType()) {
444                  case qsamplerDevice::Audio:                  case qsamplerDevice::Audio:
445                        if (sParam == "CHANNELS") iRefresh++;
446                          if ((ret = ::lscp_set_audio_device_param(m_pClient,                          if ((ret = ::lscp_set_audio_device_param(m_pClient,
447                                          device.deviceID(), &param)) != LSCP_OK)                                          device.deviceID(), &param)) != LSCP_OK)
448                                  m_pMainForm->appendMessagesClient("lscp_set_audio_device_param");                                  m_pMainForm->appendMessagesClient("lscp_set_audio_device_param");
449                          break;                          break;
450                  case qsamplerDevice::Midi:                  case qsamplerDevice::Midi:
451                        if (sParam == "PORTS") iRefresh++;
452                          if ((ret = ::lscp_set_midi_device_param(m_pClient,                          if ((ret = ::lscp_set_midi_device_param(m_pClient,
453                                          device.deviceID(), &param)) != LSCP_OK)                                          device.deviceID(), &param)) != LSCP_OK)
454                                  m_pMainForm->appendMessagesClient("lscp_set_midi_device_param");                                  m_pMainForm->appendMessagesClient("lscp_set_midi_device_param");
# Line 384  void qsamplerDeviceForm::changeValue ( i Line 458  void qsamplerDeviceForm::changeValue ( i
458                  }                  }
459                  // Show result.                  // Show result.
460                  if (ret == LSCP_OK) {                  if (ret == LSCP_OK) {
461                          m_pMainForm->appendMessages(device.deviceName() + ' '                          m_pMainForm->appendMessages(device.deviceTypeName()
462                                  + QString("%1: %2.").arg(sParam).arg(sValue));                                  + ' ' + device.deviceName()
463                                    + ' ' + QString("%1: %2.").arg(sParam).arg(sValue));
464                            // Special care for specific parameter changes...
465                            if (iRefresh > 0)
466                                    iRefresh += device.refreshPorts(m_pClient);
467                            iRefresh += device.refreshDepends(m_pClient, sParam);
468                    }
469            }
470    
471            // Done.
472            m_iDirtySetup--;
473            // Finally, we might need refreshing...
474            if (iRefresh > 0)
475                    selectDevice();
476            else
477                    stabilizeForm();
478            // Main session should be dirtier...
479            m_pMainForm->sessionDirty();
480    }
481    
482    
483    // Device port/channel parameter value change slot.
484    void qsamplerDeviceForm::changeDevicePortParam ( int iRow, int iCol )
485    {
486            if (m_iDirtySetup > 0)
487                    return;
488            if (iRow < 0 || iCol < 0)
489                    return;
490    
491            //
492            //  Device port/channel parameter change...
493            //
494    
495            QListViewItem *pItem = DeviceListView->selectedItem();
496            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
497                    return;
498    
499            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
500    
501            int iPort = DevicePortComboBox->currentItem();
502            qsamplerDevicePort *pPort = device.ports().at(iPort);
503            if (pPort == NULL)
504                return;
505    
506            m_iDirtySetup++;
507            // Table 1st column has the parameter name;
508            const QString sParam = DevicePortParamTable->text(iRow, 0);
509            const QString sValue = DevicePortParamTable->text(iRow, iCol);
510    
511            // Set the local device port/channel parameter value.
512            pPort->setParam(sParam, sValue);
513    
514            // Set proper device port/channel parameter, if any...
515            if (device.deviceID() >= 0 && pPort->portID() >= 0) {
516                    // Prepare parameter struct.
517                    lscp_param_t param;
518                    param.key   = (char *) sParam.latin1();
519                    param.value = (char *) sValue.latin1();
520                    // Now it depends on the device type...
521                    lscp_status_t ret = LSCP_FAILED;
522                    switch (device.deviceType()) {
523                    case qsamplerDevice::Audio:
524                            if ((ret = ::lscp_set_audio_channel_param(m_pClient,
525                                            device.deviceID(), pPort->portID(), &param)) != LSCP_OK)
526                                    m_pMainForm->appendMessagesClient("lscp_set_audio_channel_param");
527                            break;
528                    case qsamplerDevice::Midi:
529                            if ((ret = ::lscp_set_midi_port_param(m_pClient,
530                                            device.deviceID(), pPort->portID(), &param)) != LSCP_OK)
531                                    m_pMainForm->appendMessagesClient("lscp_set_midi_port_param");
532                            break;
533                    case qsamplerDevice::None:
534                            break;
535                    }
536                    // Show result.
537                    if (ret == LSCP_OK) {
538                            m_pMainForm->appendMessages(device.deviceTypeName()
539                                    + ' ' + device.deviceName() + ' ' + pPort->portName()
540                                    + ' ' + QString("%1: %2.").arg(sParam).arg(sValue));
541                  }                  }
542          }          }
543    
# Line 397  void qsamplerDeviceForm::changeValue ( i Line 549  void qsamplerDeviceForm::changeValue ( i
549  }  }
550    
551    
552    // Device list view context menu handler.
553    void qsamplerDeviceForm::contextMenu ( QListViewItem *pItem, const QPoint& pos, int )
554    {
555            int iItemID;
556            
557            // Build the device context menu...
558            QPopupMenu* pContextMenu = new QPopupMenu(this);
559            
560            bool bClient = (m_pClient != NULL);
561            bool bEnabled = (pItem != NULL);
562            iItemID = pContextMenu->insertItem(
563                    QIconSet(QPixmap::fromMimeSource("deviceCreate.png")),
564                    tr("&Create device"), this, SLOT(createDevice()));
565            pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));
566            iItemID = pContextMenu->insertItem(
567                    QIconSet(QPixmap::fromMimeSource("deviceDelete.png")),
568                    tr("&Delete device"), this, SLOT(deleteDevice()));
569            pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);
570            pContextMenu->insertSeparator();
571            iItemID = pContextMenu->insertItem(
572                    QIconSet(QPixmap::fromMimeSource("formRefresh.png")),
573                    tr("&Refresh"), this, SLOT(refreshDevices()));
574            pContextMenu->setItemEnabled(iItemID, bClient);
575            
576            pContextMenu->exec(pos);
577            
578            delete pContextMenu;
579    }
580    
581    
582  // Stabilize current form state.  // Stabilize current form state.
583  void qsamplerDeviceForm::stabilizeForm (void)  void qsamplerDeviceForm::stabilizeForm (void)
584  {  {
585          QListViewItem *pItem = DeviceListView->selectedItem();          QListViewItem *pItem = DeviceListView->selectedItem();
586            bool bClient = (m_pClient != NULL);
587          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
588          DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
589          DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
590          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
591          DeviceParamTable->setEnabled(bEnabled);          DeviceParamTable->setEnabled(bEnabled);
592          CreateDevicePushButton->setEnabled(bEnabled ||  m_bNewDevice);          RefreshDevicesPushButton->setEnabled(bClient);
593            CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
594          DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
595  }  }
596    
597    
598  // end of qsamplerDeviceForm.ui.h  // end of qsamplerDeviceForm.ui.h
599    
600    
601    

Legend:
Removed from v.448  
changed lines
  Added in v.467

  ViewVC Help
Powered by ViewVC