/[svn]/qsampler/trunk/src/qsamplerMainForm.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerMainForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1691 by schoenebeck, Thu Feb 14 22:31:26 2008 UTC revision 1815 by capela, Mon Dec 22 10:04:59 2008 UTC
# Line 1  Line 1 
1  // qsamplerMainForm.cpp  // qsamplerMainForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2008, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, 2008 Christian Schoenebeck
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 33  Line 33 
33  #include "qsamplerInstrumentListForm.h"  #include "qsamplerInstrumentListForm.h"
34  #include "qsamplerDeviceForm.h"  #include "qsamplerDeviceForm.h"
35  #include "qsamplerOptionsForm.h"  #include "qsamplerOptionsForm.h"
36    #include "qsamplerDeviceStatusForm.h"
37    
38  #include <QApplication>  #include <QApplication>
39  #include <QWorkspace>  #include <QWorkspace>
# Line 390  void MainForm::setup ( Options *pOptions Line 391  void MainForm::setup ( Options *pOptions
391  #else  #else
392          viewInstrumentsAction->setEnabled(false);          viewInstrumentsAction->setEnabled(false);
393  #endif  #endif
394            // Setup messages logging appropriately...
395            m_pMessages->setLogging(
396                    m_pOptions->bMessagesLog,
397                    m_pOptions->sMessagesLogPath);
398          // Set message defaults...          // Set message defaults...
399          updateMessagesFont();          updateMessagesFont();
400          updateMessagesLimit();          updateMessagesLimit();
# Line 481  bool MainForm::queryClose (void) Line 486  bool MainForm::queryClose (void)
486    
487  void MainForm::closeEvent ( QCloseEvent *pCloseEvent )  void MainForm::closeEvent ( QCloseEvent *pCloseEvent )
488  {  {
489          if (queryClose())          if (queryClose()) {
490                    DeviceStatusForm::deleteAllInstances();
491                  pCloseEvent->accept();                  pCloseEvent->accept();
492          else          } else
493                  pCloseEvent->ignore();                  pCloseEvent->ignore();
494  }  }
495    
# Line 552  void MainForm::customEvent(QEvent* pCust Line 558  void MainForm::customEvent(QEvent* pCust
558          if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {          if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {
559                  CustomEvent *pEvent = static_cast<CustomEvent *> (pCustomEvent);                  CustomEvent *pEvent = static_cast<CustomEvent *> (pCustomEvent);
560                  switch (pEvent->event()) {                  switch (pEvent->event()) {
561                            case LSCP_EVENT_CHANNEL_COUNT:
562                                    updateAllChannelStrips(true);
563                                    break;
564                          case LSCP_EVENT_CHANNEL_INFO: {                          case LSCP_EVENT_CHANNEL_INFO: {
565                                  int iChannelID = pEvent->data().toInt();                                  int iChannelID = pEvent->data().toInt();
566                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);
# Line 559  void MainForm::customEvent(QEvent* pCust Line 568  void MainForm::customEvent(QEvent* pCust
568                                          channelStripChanged(pChannelStrip);                                          channelStripChanged(pChannelStrip);
569                                  break;                                  break;
570                          }                          }
571  #if CONFIG_LSCP_CHANNEL_MIDI                          case LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT:
572                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
573                                    DeviceStatusForm::onDevicesChanged();
574                                    updateViewMidiDeviceStatusMenu();
575                                    break;
576                            case LSCP_EVENT_MIDI_INPUT_DEVICE_INFO: {
577                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
578                                    const int iDeviceID = pEvent->data().section(' ', 0, 0).toInt();
579                                    DeviceStatusForm::onDeviceChanged(iDeviceID);
580                                    break;
581                            }
582                            case LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT:
583                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
584                                    break;
585                            case LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO:
586                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
587                                    break;
588    #if CONFIG_EVENT_CHANNEL_MIDI
589                          case LSCP_EVENT_CHANNEL_MIDI: {                          case LSCP_EVENT_CHANNEL_MIDI: {
590                                  int iChannelID = pEvent->data().toInt();                                  const int iChannelID = pEvent->data().section(' ', 0, 0).toInt();
591                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);
592                                  if (pChannelStrip)                                  if (pChannelStrip)
593                                          pChannelStrip->midiArrived();                                          pChannelStrip->midiArrived();
594                                  break;                                  break;
595                          }                          }
596  #endif  #endif
597    #if CONFIG_EVENT_DEVICE_MIDI
598                            case LSCP_EVENT_DEVICE_MIDI: {
599                                    const int iDeviceID = pEvent->data().section(' ', 0, 0).toInt();
600                                    const int iPortID   = pEvent->data().section(' ', 1, 1).toInt();
601                                    DeviceStatusForm* pDeviceStatusForm =
602                                            DeviceStatusForm::getInstance(iDeviceID);
603                                    if (pDeviceStatusForm)
604                                            pDeviceStatusForm->midiArrived(iPortID);
605                                    break;
606                            }
607    #endif
608                          default:                          default:
609                                  appendMessagesColor(tr("Notify event: %1 data: %2")                                  appendMessagesColor(tr("Notify event: %1 data: %2")
610                                          .arg(::lscp_event_to_text(pEvent->event()))                                          .arg(::lscp_event_to_text(pEvent->event()))
# Line 576  void MainForm::customEvent(QEvent* pCust Line 613  void MainForm::customEvent(QEvent* pCust
613          }          }
614  }  }
615    
616    void MainForm::updateViewMidiDeviceStatusMenu() {
617            m_ui.viewMidiDeviceStatusMenu->clear();
618            const std::map<int, DeviceStatusForm*> statusForms =
619                    DeviceStatusForm::getInstances();
620            for (
621                    std::map<int, DeviceStatusForm*>::const_iterator iter = statusForms.begin();
622                    iter != statusForms.end(); ++iter
623            ) {
624                    DeviceStatusForm* pForm = iter->second;
625                    m_ui.viewMidiDeviceStatusMenu->addAction(
626                            pForm->visibleAction()
627                    );
628            }
629    }
630    
631  // Context menu event handler.  // Context menu event handler.
632  void MainForm::contextMenuEvent( QContextMenuEvent *pEvent )  void MainForm::contextMenuEvent( QContextMenuEvent *pEvent )
633  {  {
# Line 1568  void MainForm::viewOptions (void) Line 1620  void MainForm::viewOptions (void)
1620                  int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  int     iOldServerTimeout   = m_pOptions->iServerTimeout;
1621                  bool    bOldServerStart     = m_pOptions->bServerStart;                  bool    bOldServerStart     = m_pOptions->bServerStart;
1622                  QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;
1623                    bool    bOldMessagesLog     = m_pOptions->bMessagesLog;
1624                    QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;
1625                  QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  QString sOldDisplayFont     = m_pOptions->sDisplayFont;
1626                  bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;
1627                  int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  int     iOldMaxVolume       = m_pOptions->iMaxVolume;
# Line 1579  void MainForm::viewOptions (void) Line 1633  void MainForm::viewOptions (void)
1633                  bool    bOldCompletePath    = m_pOptions->bCompletePath;                  bool    bOldCompletePath    = m_pOptions->bCompletePath;
1634                  bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;
1635                  int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;
1636                    int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;
1637                  // Load the current setup settings.                  // Load the current setup settings.
1638                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1639                  // Show the setup dialog...                  // Show the setup dialog...
# Line 1587  void MainForm::viewOptions (void) Line 1642  void MainForm::viewOptions (void)
1642                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1643                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||
1644                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1645                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)) {                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1646                                    (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1647                                  QMessageBox::information(this,                                  QMessageBox::information(this,
1648                                          QSAMPLER_TITLE ": " + tr("Information"),                                          QSAMPLER_TITLE ": " + tr("Information"),
1649                                          tr("Some settings may be only effective\n"                                          tr("Some settings may be only effective\n"
# Line 1595  void MainForm::viewOptions (void) Line 1651  void MainForm::viewOptions (void)
1651                                  updateMessagesCapture();                                  updateMessagesCapture();
1652                          }                          }
1653                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1654                            if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
1655                                    (!bOldMessagesLog &&  m_pOptions->bMessagesLog) ||
1656                                    (sOldMessagesLogPath != m_pOptions->sMessagesLogPath))
1657                                    m_pMessages->setLogging(
1658                                            m_pOptions->bMessagesLog, m_pOptions->sMessagesLogPath);
1659                          if (( bOldCompletePath && !m_pOptions->bCompletePath) ||                          if (( bOldCompletePath && !m_pOptions->bCompletePath) ||
1660                                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||                                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||
1661                                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))                                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))
# Line 1749  void MainForm::helpAbout (void) Line 1810  void MainForm::helpAbout (void)
1810          sText += tr("Instrument editing support disabled.");          sText += tr("Instrument editing support disabled.");
1811          sText += "</font></small><br />";          sText += "</font></small><br />";
1812  #endif  #endif
1813    #ifndef CONFIG_EVENT_CHANNEL_MIDI
1814            sText += "<small><font color=\"red\">";
1815            sText += tr("Channel MIDI event support disabled.");
1816            sText += "</font></small><br />";
1817    #endif
1818    #ifndef CONFIG_EVENT_DEVICE_MIDI
1819            sText += "<small><font color=\"red\">";
1820            sText += tr("Device MIDI event support disabled.");
1821            sText += "</font></small><br />";
1822    #endif
1823    #ifndef CONFIG_MAX_VOICES
1824            sText += "<small><font color=\"red\">";
1825            sText += tr("Runtime max. voices / disk streams support disabled.");
1826            sText += "</font></small><br />";
1827    #endif
1828          sText += "<br />\n";          sText += "<br />\n";
1829          sText += tr("Using") + ": ";          sText += tr("Using") + ": ";
1830          sText += ::lscp_client_package();          sText += ::lscp_client_package();
# Line 1923  void MainForm::updateSession (void) Line 1999  void MainForm::updateSession (void)
1999          }          }
2000  #endif  #endif
2001    
2002            updateAllChannelStrips(false);
2003    
2004            // Do we auto-arrange?
2005            if (m_pOptions && m_pOptions->bAutoArrange)
2006                    channelsArrange();
2007    
2008            // Remember to refresh devices and instruments...
2009            if (m_pInstrumentListForm)
2010                    m_pInstrumentListForm->refreshInstruments();
2011            if (m_pDeviceForm)
2012                    m_pDeviceForm->refreshDevices();
2013    }
2014    
2015    void MainForm::updateAllChannelStrips(bool bRemoveDeadStrips) {
2016          // Retrieve the current channel list.          // Retrieve the current channel list.
2017          int *piChannelIDs = ::lscp_list_channels(m_pClient);          int *piChannelIDs = ::lscp_list_channels(m_pClient);
2018          if (piChannelIDs == NULL) {          if (piChannelIDs == NULL) {
# Line 1939  void MainForm::updateSession (void) Line 2029  void MainForm::updateSession (void)
2029                          if (!channelStrip(piChannelIDs[iChannel]))                          if (!channelStrip(piChannelIDs[iChannel]))
2030                                  createChannelStrip(new Channel(piChannelIDs[iChannel]));                                  createChannelStrip(new Channel(piChannelIDs[iChannel]));
2031                  }                  }
                 m_pWorkspace->setUpdatesEnabled(true);  
         }  
2032    
2033          // Do we auto-arrange?                  // Do we auto-arrange?
2034          if (m_pOptions && m_pOptions->bAutoArrange)                  if (m_pOptions && m_pOptions->bAutoArrange)
2035                  channelsArrange();                          channelsArrange();
2036    
2037          // Remember to refresh devices and instruments...                  stabilizeForm();
         if (m_pInstrumentListForm)  
                 m_pInstrumentListForm->refreshInstruments();  
         if (m_pDeviceForm)  
                 m_pDeviceForm->refreshDevices();  
 }  
2038    
2039                    // remove dead channel strips
2040                    if (bRemoveDeadStrips) {
2041                            for (int i = 0; channelStripAt(i); ++i) {
2042                                    ChannelStrip* pChannelStrip = channelStripAt(i);
2043                                    bool bExists = false;
2044                                    for (int j = 0; piChannelIDs[j] >= 0; ++j) {
2045                                            if (!pChannelStrip->channel()) break;
2046                                            if (piChannelIDs[j] == pChannelStrip->channel()->channelID()) {
2047                                                    // strip exists, don't touch it
2048                                                    bExists = true;
2049                                                    break;
2050                                            }
2051                                    }
2052                                    if (!bExists) destroyChannelStrip(pChannelStrip);
2053                            }
2054                    }
2055                    m_pWorkspace->setUpdatesEnabled(true);
2056            }
2057    }
2058    
2059  // Update the recent files list and menu.  // Update the recent files list and menu.
2060  void MainForm::updateRecentFiles ( const QString& sFilename )  void MainForm::updateRecentFiles ( const QString& sFilename )
# Line 2231  ChannelStrip* MainForm::createChannelStr Line 2333  ChannelStrip* MainForm::createChannelStr
2333          return pChannelStrip;          return pChannelStrip;
2334  }  }
2335    
2336    void MainForm::destroyChannelStrip(ChannelStrip* pChannelStrip) {
2337            // Just delete the channel strip.
2338            delete pChannelStrip;
2339    
2340            // Do we auto-arrange?
2341            if (m_pOptions && m_pOptions->bAutoArrange)
2342                    channelsArrange();
2343    
2344            stabilizeForm();
2345    }
2346    
2347  // Retrieve the active channel strip.  // Retrieve the active channel strip.
2348  ChannelStrip* MainForm::activeChannelStrip (void)  ChannelStrip* MainForm::activeChannelStrip (void)
# Line 2242  ChannelStrip* MainForm::activeChannelStr Line 2354  ChannelStrip* MainForm::activeChannelStr
2354  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
2355  ChannelStrip* MainForm::channelStripAt ( int iChannel )  ChannelStrip* MainForm::channelStripAt ( int iChannel )
2356  {  {
2357            if (!m_pWorkspace) return NULL;
2358    
2359          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
2360          if (wlist.isEmpty())          if (wlist.isEmpty())
2361                  return NULL;                  return NULL;
2362    
2363          return static_cast<ChannelStrip *> (wlist.at(iChannel));          if (iChannel < 0 || iChannel >= wlist.size())
2364                    return NULL;
2365    
2366            return dynamic_cast<ChannelStrip *> (wlist.at(iChannel));
2367  }  }
2368    
2369    
# Line 2616  bool MainForm::startClient (void) Line 2733  bool MainForm::startClient (void)
2733                  .arg(::lscp_client_get_timeout(m_pClient)));                  .arg(::lscp_client_get_timeout(m_pClient)));
2734    
2735          // Subscribe to channel info change notifications...          // Subscribe to channel info change notifications...
2736            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT) != LSCP_OK)
2737                    appendMessagesClient("lscp_client_subscribe(CHANNEL_COUNT)");
2738          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)
2739                  appendMessagesClient("lscp_client_subscribe(CHANNEL_INFO)");                  appendMessagesClient("lscp_client_subscribe(CHANNEL_INFO)");
2740    
2741  #if CONFIG_LSCP_CHANNEL_MIDI          DeviceStatusForm::onDevicesChanged(); // initialize
2742            updateViewMidiDeviceStatusMenu();
2743            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT) != LSCP_OK)
2744                    appendMessagesClient("lscp_client_subscribe(MIDI_INPUT_DEVICE_COUNT)");
2745            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO) != LSCP_OK)
2746                    appendMessagesClient("lscp_client_subscribe(MIDI_INPUT_DEVICE_INFO)");
2747            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT) != LSCP_OK)
2748                    appendMessagesClient("lscp_client_subscribe(AUDIO_OUTPUT_DEVICE_COUNT)");
2749            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO) != LSCP_OK)
2750                    appendMessagesClient("lscp_client_subscribe(AUDIO_OUTPUT_DEVICE_INFO)");
2751    
2752    #if CONFIG_EVENT_CHANNEL_MIDI
2753          // Subscribe to channel MIDI data notifications...          // Subscribe to channel MIDI data notifications...
2754          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI) != LSCP_OK)          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI) != LSCP_OK)
2755                  appendMessagesClient("lscp_client_subscribe(CHANNEL_MIDI)");                  appendMessagesClient("lscp_client_subscribe(CHANNEL_MIDI)");
2756  #endif  #endif
2757    
2758    #if CONFIG_EVENT_DEVICE_MIDI
2759            // Subscribe to channel MIDI data notifications...
2760            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI) != LSCP_OK)
2761                    appendMessagesClient("lscp_client_subscribe(DEVICE_MIDI)");
2762    #endif
2763    
2764          // We may stop scheduling around.          // We may stop scheduling around.
2765          stopSchedule();          stopSchedule();
2766    
# Line 2650  bool MainForm::startClient (void) Line 2786  bool MainForm::startClient (void)
2786                  }                  }
2787          }          }
2788    
2789            // send the current / loaded fine tuning settings to the sampler
2790            m_pOptions->sendFineTuningSettings();
2791    
2792          // Make a new session          // Make a new session
2793          return newSession();          return newSession();
2794  }  }
# Line 2677  void MainForm::stopClient (void) Line 2816  void MainForm::stopClient (void)
2816          closeSession(false);          closeSession(false);
2817    
2818          // Close us as a client...          // Close us as a client...
2819  #if CONFIG_LSCP_CHANNEL_MIDI  #if CONFIG_EVENT_DEVICE_MIDI
2820            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI);
2821    #endif
2822    #if CONFIG_EVENT_CHANNEL_MIDI
2823          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI);
2824  #endif  #endif
2825            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
2826            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
2827            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
2828            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
2829          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
2830            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);
2831          ::lscp_client_destroy(m_pClient);          ::lscp_client_destroy(m_pClient);
2832          m_pClient = NULL;          m_pClient = NULL;
2833    

Legend:
Removed from v.1691  
changed lines
  Added in v.1815

  ViewVC Help
Powered by ViewVC