/[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 464 by capela, Tue Mar 15 15:38:26 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          // Try to restore normal window positioning.          // Try to restore normal window positioning.
54          adjustSize();          adjustSize();
55  }  }
# Line 101  void qsamplerDeviceForm::createDevice (v Line 105  void qsamplerDeviceForm::createDevice (v
105          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
106                  return;                  return;
107    
108          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
109    
110          // Build the parameter list...          // Build the parameter list...
111          qsamplerDeviceParamMap& params = device.params();          const qsamplerDeviceParamMap& params = device.params();
112          lscp_param_t *pParams = new lscp_param_t [params.count() + 1];          lscp_param_t *pParams = new lscp_param_t [params.count() + 1];
113          int iParam = 0;          int iParam = 0;
114          qsamplerDeviceParamMap::ConstIterator iter;          qsamplerDeviceParamMap::ConstIterator iter;
# Line 163  void qsamplerDeviceForm::deleteDevice (v Line 167  void qsamplerDeviceForm::deleteDevice (v
167          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
168                  return;                  return;
169    
170          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          const qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
171    
172          // Prompt user if this is for real...          // Prompt user if this is for real...
173          qsamplerOptions *pOptions = m_pMainForm->options();          qsamplerOptions *pOptions = m_pMainForm->options();
# Line 276  void qsamplerDeviceForm::selectDriver ( Line 280  void qsamplerDeviceForm::selectDriver (
280          if (m_bNewDevice) {          if (m_bNewDevice) {
281                  m_iDirtySetup++;                  m_iDirtySetup++;
282                  device.setDriver(m_pClient, sDriverName);                  device.setDriver(m_pClient, sDriverName);
283                  DeviceParamTable->refresh(device);                  DeviceParamTable->refresh(device.params(), m_bNewDevice);
284                  m_iDirtySetup--;                  m_iDirtySetup--;
285                  // Done.                  // Done.
286                  stabilizeForm();                  stabilizeForm();
# Line 299  void qsamplerDeviceForm::selectDevice (v Line 303  void qsamplerDeviceForm::selectDevice (v
303                  m_deviceType = qsamplerDevice::None;                  m_deviceType = qsamplerDevice::None;
304                  DeviceNameTextLabel->setText(QString::null);                  DeviceNameTextLabel->setText(QString::null);
305                  DeviceParamTable->setNumRows(0);                  DeviceParamTable->setNumRows(0);
306                    DevicePortComboBox->setEnabled(false);
307                    DevicePortParamTable->setEnabled(false);
308                  stabilizeForm();                  stabilizeForm();
309                  return;                  return;
310          }          }
311    
         m_iDirtySetup++;  
312          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
313    
314            m_iDirtySetup++;
315          // Flag whether this is a new device.          // Flag whether this is a new device.
316          m_bNewDevice = (device.deviceID() < 0);          m_bNewDevice = (device.deviceID() < 0);
317    
318          // Fill the device/driver heading...          // Fill the device/driver heading...
319          DeviceNameTextLabel->setText(device.deviceTypeName() + ' ' + device.deviceName());          QString sPrefix;
320            if (!m_bNewDevice)
321                    sPrefix += device.deviceTypeName() + ' ';
322            DeviceNameTextLabel->setText(sPrefix + device.deviceName());
323          // The driver combobox is only rebuilt if device type has changed...          // The driver combobox is only rebuilt if device type has changed...
324          if (device.deviceType() != m_deviceType) {          if (device.deviceType() != m_deviceType) {
325                  DriverNameComboBox->clear();                  DriverNameComboBox->clear();
# Line 328  void qsamplerDeviceForm::selectDevice (v Line 337  void qsamplerDeviceForm::selectDevice (v
337          DriverNameTextLabel->setEnabled(m_bNewDevice);          DriverNameTextLabel->setEnabled(m_bNewDevice);
338          DriverNameComboBox->setEnabled(m_bNewDevice);          DriverNameComboBox->setEnabled(m_bNewDevice);
339          // Fill the device parameter table...          // Fill the device parameter table...
340          DeviceParamTable->refresh(device);          DeviceParamTable->refresh(device.params(), m_bNewDevice);
341            // And now the device port/channel parameter table...
342            DevicePortComboBox->clear();
343            DevicePortParamTable->setNumRows(0);
344            if (m_bNewDevice) {
345                    DevicePortComboBox->setEnabled(false);
346                    DevicePortParamTable->setEnabled(false);
347            } else {
348                    QPixmap pixmap;
349                    switch (device.deviceType()) {
350                    case qsamplerDevice::Audio:
351                        pixmap = QPixmap::fromMimeSource("audio2.png");
352                        break;
353                    case qsamplerDevice::Midi:
354                        pixmap = QPixmap::fromMimeSource("midi2.png");
355                        break;
356                    case qsamplerDevice::None:
357                        break;
358                    }
359                    qsamplerDevicePortList& ports = device.ports();
360                    qsamplerDevicePort *pPort;
361                    for (pPort = ports.first(); pPort; pPort = ports.next()) {
362                DevicePortComboBox->insertItem(pixmap,
363                                    device.deviceTypeName() + ' ' + pPort->portName());
364                    }
365                    bool bEnabled = (ports.count() > 0);
366                    DevicePortComboBox->setEnabled(bEnabled);
367                    DevicePortParamTable->setEnabled(bEnabled);
368            }
369          // Done.          // Done.
370          m_iDirtySetup--;          m_iDirtySetup--;
371            
372            // Make the device port/channel selection effective.
373            selectDevicePort(DevicePortComboBox->currentItem());
374    }
375    
376    
377    // Device port/channel selection slot.
378    void qsamplerDeviceForm::selectDevicePort ( int iPort )
379    {
380            if (m_iDirtySetup > 0)
381                    return;
382    
383            //
384            //  Device port/channel selection has changed...
385            //
386    
387            QListViewItem *pItem = DeviceListView->selectedItem();
388            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
389                    return;
390    
391            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
392            qsamplerDevicePort *pPort = device.ports().at(iPort);
393            if (pPort) {
394                    m_iDirtySetup++;
395                    DevicePortParamTable->refresh(pPort->params(), true);
396                    m_iDirtySetup--;
397            }
398            // Done.
399          stabilizeForm();          stabilizeForm();
400  }  }
401    
402    
403  // parameter value change slot.  // Device parameter value change slot.
404  void qsamplerDeviceForm::changeValue ( int iRow, int iCol )  void qsamplerDeviceForm::changeDeviceParam ( int iRow, int iCol )
405  {  {
406          if (m_iDirtySetup > 0)          if (m_iDirtySetup > 0)
407                  return;                  return;
# Line 351  void qsamplerDeviceForm::changeValue ( i Line 416  void qsamplerDeviceForm::changeValue ( i
416          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)          if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
417                  return;                  return;
418    
         m_iDirtySetup++;  
419          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();          qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
420    
421            m_iDirtySetup++;
422          // Table 1st column has the parameter name;          // Table 1st column has the parameter name;
         qsamplerDeviceParamMap& params = device.params();  
423          const QString sParam = DeviceParamTable->text(iRow, 0);          const QString sParam = DeviceParamTable->text(iRow, 0);
424          const QString sValue = DeviceParamTable->text(iRow, iCol);          const QString sValue = DeviceParamTable->text(iRow, iCol);
425          params[sParam].value = sValue;          
426            // Set the local device parameter value.
427            device.setParam(sParam, sValue);
428    
429          // Set proper device parameter, on existing device ...          // Set proper device parameter, on existing device ...
430          if (device.deviceID() >= 0) {          if (device.deviceID() >= 0) {
# Line 367  void qsamplerDeviceForm::changeValue ( i Line 433  void qsamplerDeviceForm::changeValue ( i
433                  param.key   = (char *) sParam.latin1();                  param.key   = (char *) sParam.latin1();
434                  param.value = (char *) sValue.latin1();                  param.value = (char *) sValue.latin1();
435                  // Now it depends on the device type...                  // Now it depends on the device type...
436                    bool bRefresh = false;
437                  lscp_status_t ret = LSCP_FAILED;                  lscp_status_t ret = LSCP_FAILED;
438                  switch (device.deviceType()) {                  switch (device.deviceType()) {
439                  case qsamplerDevice::Audio:                  case qsamplerDevice::Audio:
440                        bRefresh = (sParam == "CHANNELS");
441                          if ((ret = ::lscp_set_audio_device_param(m_pClient,                          if ((ret = ::lscp_set_audio_device_param(m_pClient,
442                                          device.deviceID(), &param)) != LSCP_OK)                                          device.deviceID(), &param)) != LSCP_OK)
443                                  m_pMainForm->appendMessagesClient("lscp_set_audio_device_param");                                  m_pMainForm->appendMessagesClient("lscp_set_audio_device_param");
444                          break;                          break;
445                  case qsamplerDevice::Midi:                  case qsamplerDevice::Midi:
446                        bRefresh = (sParam == "PORTS");
447                          if ((ret = ::lscp_set_midi_device_param(m_pClient,                          if ((ret = ::lscp_set_midi_device_param(m_pClient,
448                                          device.deviceID(), &param)) != LSCP_OK)                                          device.deviceID(), &param)) != LSCP_OK)
449                                  m_pMainForm->appendMessagesClient("lscp_set_midi_device_param");                                  m_pMainForm->appendMessagesClient("lscp_set_midi_device_param");
# Line 386  void qsamplerDeviceForm::changeValue ( i Line 455  void qsamplerDeviceForm::changeValue ( i
455                  if (ret == LSCP_OK) {                  if (ret == LSCP_OK) {
456                          m_pMainForm->appendMessages(device.deviceName() + ' '                          m_pMainForm->appendMessages(device.deviceName() + ' '
457                                  + QString("%1: %2.").arg(sParam).arg(sValue));                                  + QString("%1: %2.").arg(sParam).arg(sValue));
458                            // Special care for specific parameter changes...
459                            if (bRefresh)
460                                device.refresh(m_pClient);
461                    }
462            }
463    
464            // Done.
465            m_iDirtySetup--;
466            stabilizeForm();
467            // Main session should be dirtier...
468            m_pMainForm->sessionDirty();
469    }
470    
471    
472    // Device port/channel parameter value change slot.
473    void qsamplerDeviceForm::changeDevicePortParam ( int iRow, int iCol )
474    {
475            if (m_iDirtySetup > 0)
476                    return;
477            if (iRow < 0 || iCol < 0)
478                    return;
479    
480            //
481            //  Device port/channel parameter change...
482            //
483    
484            QListViewItem *pItem = DeviceListView->selectedItem();
485            if (pItem == NULL || pItem->rtti() != QSAMPLER_DEVICE_ITEM)
486                    return;
487    
488            qsamplerDevice& device = ((qsamplerDeviceItem *) pItem)->device();
489    
490            int iPort = DevicePortComboBox->currentItem();
491            qsamplerDevicePort *pPort = device.ports().at(iPort);
492            if (pPort == NULL)
493                return;
494    
495            m_iDirtySetup++;
496            // Table 1st column has the parameter name;
497            const QString sParam = DevicePortParamTable->text(iRow, 0);
498            const QString sValue = DevicePortParamTable->text(iRow, iCol);
499    
500            // Set the local device port/channel parameter value.
501            pPort->setParam(sParam, sValue);
502    
503            // Set proper device port/channel parameter, if any...
504            if (device.deviceID() >= 0 && pPort->portID() >= 0) {
505                    // Prepare parameter struct.
506                    lscp_param_t param;
507                    param.key   = (char *) sParam.latin1();
508                    param.value = (char *) sValue.latin1();
509                    // Now it depends on the device type...
510                    lscp_status_t ret = LSCP_FAILED;
511                    switch (device.deviceType()) {
512                    case qsamplerDevice::Audio:
513                            if ((ret = ::lscp_set_audio_channel_param(m_pClient,
514                                            device.deviceID(), pPort->portID(), &param)) != LSCP_OK)
515                                    m_pMainForm->appendMessagesClient("lscp_set_audio_channel_param");
516                            break;
517                    case qsamplerDevice::Midi:
518                            if ((ret = ::lscp_set_midi_port_param(m_pClient,
519                                            device.deviceID(), pPort->portID(), &param)) != LSCP_OK)
520                                    m_pMainForm->appendMessagesClient("lscp_set_midi_port_param");
521                            break;
522                    case qsamplerDevice::None:
523                            break;
524                    }
525                    // Show result.
526                    if (ret == LSCP_OK) {
527                            m_pMainForm->appendMessages(device.deviceName() + ' '
528                                    + pPort->portName()     + ' '
529                                    + QString("%1: %2.").arg(sParam).arg(sValue));
530                  }                  }
531          }          }
532    
# Line 397  void qsamplerDeviceForm::changeValue ( i Line 538  void qsamplerDeviceForm::changeValue ( i
538  }  }
539    
540    
541    // Device list view context menu handler.
542    void qsamplerDeviceForm::contextMenu ( QListViewItem *pItem, const QPoint& pos, int )
543    {
544            int iItemID;
545            
546            // Build the device context menu...
547            QPopupMenu* pContextMenu = new QPopupMenu(this);
548            
549            bool bClient = (m_pClient != NULL);
550            bool bEnabled = (pItem != NULL);
551            iItemID = pContextMenu->insertItem(
552                    QIconSet(QPixmap::fromMimeSource("deviceCreate.png")),
553                    tr("&Create device"), this, SLOT(createDevice()));
554            pContextMenu->setItemEnabled(iItemID, bEnabled || (bClient && m_bNewDevice));
555            iItemID = pContextMenu->insertItem(
556                    QIconSet(QPixmap::fromMimeSource("deviceDelete.png")),
557                    tr("&Delete device"), this, SLOT(deleteDevice()));
558            pContextMenu->setItemEnabled(iItemID, bEnabled && !m_bNewDevice);
559            pContextMenu->insertSeparator();
560            iItemID = pContextMenu->insertItem(
561                    QIconSet(QPixmap::fromMimeSource("formRefresh.png")),
562                    tr("&Refresh"), this, SLOT(refreshDevices()));
563            pContextMenu->setItemEnabled(iItemID, bClient);
564            
565            pContextMenu->exec(pos);
566            
567            delete pContextMenu;
568    }
569    
570    
571  // Stabilize current form state.  // Stabilize current form state.
572  void qsamplerDeviceForm::stabilizeForm (void)  void qsamplerDeviceForm::stabilizeForm (void)
573  {  {
574          QListViewItem *pItem = DeviceListView->selectedItem();          QListViewItem *pItem = DeviceListView->selectedItem();
575            bool bClient = (m_pClient != NULL);
576          bool bEnabled = (pItem != NULL);          bool bEnabled = (pItem != NULL);
577          DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);          DeviceNameTextLabel->setEnabled(bEnabled && !m_bNewDevice);
578          DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);          DriverNameTextLabel->setEnabled(bEnabled &&  m_bNewDevice);
579          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);          DriverNameComboBox->setEnabled(bEnabled && m_bNewDevice);
580          DeviceParamTable->setEnabled(bEnabled);          DeviceParamTable->setEnabled(bEnabled);
581          CreateDevicePushButton->setEnabled(bEnabled ||  m_bNewDevice);          RefreshDevicesPushButton->setEnabled(bClient);
582            CreateDevicePushButton->setEnabled(bEnabled || (bClient && m_bNewDevice));
583          DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);          DeleteDevicePushButton->setEnabled(bEnabled && !m_bNewDevice);
584  }  }
585    
586    
587  // end of qsamplerDeviceForm.ui.h  // end of qsamplerDeviceForm.ui.h
588    
589    
590    

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

  ViewVC Help
Powered by ViewVC