/[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 3559 by capela, Thu Aug 22 18:58:38 2019 UTC revision 3789 by capela, Thu Jun 11 19:26:44 2020 UTC
# Line 1  Line 1 
1  // qsamplerMainForm.cpp  // qsamplerMainForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2020, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007,2008,2015 Christian Schoenebeck     Copyright (C) 2007-2019 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 35  Line 35 
35  #include "qsamplerOptionsForm.h"  #include "qsamplerOptionsForm.h"
36  #include "qsamplerDeviceStatusForm.h"  #include "qsamplerDeviceStatusForm.h"
37    
38    #include "qsamplerPaletteForm.h"
39    
40    #include <QStyleFactory>
41    
42  #include <QMdiArea>  #include <QMdiArea>
43  #include <QMdiSubWindow>  #include <QMdiSubWindow>
44    
# Line 58  Line 62 
62  #include <QTimer>  #include <QTimer>
63  #include <QDateTime>  #include <QDateTime>
64    
65    #include <QElapsedTimer>
66    
67  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
68  #include <QMimeData>  #include <QMimeData>
69  #endif  #endif
# Line 72  const WindowFlags WindowCloseButtonHint Line 78  const WindowFlags WindowCloseButtonHint
78  #include <gig.h>  #include <gig.h>
79  #endif  #endif
80    
81    // Deprecated QTextStreamFunctions/Qt namespaces workaround.
82    #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
83    #define endl    Qt::endl
84    #endif
85    
86  // Needed for lroundf()  // Needed for lroundf()
87  #include <math.h>  #include <math.h>
88    
# Line 966  bool MainForm::closeSession ( bool bForc Line 977  bool MainForm::closeSession ( bool bForc
977                  m_pWorkspace->setUpdatesEnabled(false);                  m_pWorkspace->setUpdatesEnabled(false);
978                  const QList<QMdiSubWindow *>& wlist                  const QList<QMdiSubWindow *>& wlist
979                          = m_pWorkspace->subWindowList();                          = m_pWorkspace->subWindowList();
980                  const int iStripCount = wlist.count();                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
981                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                          ChannelStrip *pChannelStrip
982                          ChannelStrip *pChannelStrip = nullptr;                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
983                          if (pChannelStrip) {                          if (pChannelStrip) {
984                                  Channel *pChannel = pChannelStrip->channel();                                  Channel *pChannel = pChannelStrip->channel();
985                                  if (bForce && pChannel)                                  if (bForce && pChannel)
986                                          pChannel->removeChannel();                                          pChannel->removeChannel();
987                                  delete pChannelStrip;                                  delete pChannelStrip;
988                          }                          }
989                          if (pMdiSubWindow)                          delete pMdiSubWindow;
                                 delete pMdiSubWindow;  
990                  }                  }
991                  m_pWorkspace->setUpdatesEnabled(true);                  m_pWorkspace->setUpdatesEnabled(true);
992                  // We're now clean, for sure.                  // We're now clean, for sure.
# Line 1277  bool MainForm::saveSessionFile ( const Q Line 1284  bool MainForm::saveSessionFile ( const Q
1284          int iChannelID = 0;          int iChannelID = 0;
1285          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1286                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1287          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1288          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1289                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1290                  if (pChannelStrip) {                  if (pChannelStrip) {
1291                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
1292                          if (pChannel) {                          if (pChannel) {
# Line 1762  void MainForm::editResetAllChannels (voi Line 1766  void MainForm::editResetAllChannels (voi
1766          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
1767          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1768                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1769          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1770          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1771                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1772                  if (pChannelStrip)                  if (pChannelStrip)
1773                          pChannelStrip->channelReset();                          pChannelStrip->channelReset();
1774          }          }
# Line 1876  void MainForm::viewOptions (void) Line 1877  void MainForm::viewOptions (void)
1877                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1878                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1879                  // To track down deferred or immediate changes.                  // To track down deferred or immediate changes.
1880                  const QString sOldServerHost      = m_pOptions->sServerHost;                  const QString sOldServerHost       = m_pOptions->sServerHost;
1881                  const int     iOldServerPort      = m_pOptions->iServerPort;                  const int     iOldServerPort       = m_pOptions->iServerPort;
1882                  const int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  const int     iOldServerTimeout    = m_pOptions->iServerTimeout;
1883                  const bool    bOldServerStart     = m_pOptions->bServerStart;                  const bool    bOldServerStart      = m_pOptions->bServerStart;
1884                  const QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  const QString sOldServerCmdLine    = m_pOptions->sServerCmdLine;
1885                  const bool    bOldMessagesLog     = m_pOptions->bMessagesLog;                  const bool    bOldMessagesLog      = m_pOptions->bMessagesLog;
1886                  const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;                  const QString sOldMessagesLogPath  = m_pOptions->sMessagesLogPath;
1887                  const QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  const QString sOldDisplayFont      = m_pOptions->sDisplayFont;
1888                  const bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  const bool    bOldDisplayEffect    = m_pOptions->bDisplayEffect;
1889                  const int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  const int     iOldMaxVolume        = m_pOptions->iMaxVolume;
1890                  const QString sOldMessagesFont    = m_pOptions->sMessagesFont;                  const QString sOldMessagesFont     = m_pOptions->sMessagesFont;
1891                  const bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;                  const bool    bOldKeepOnTop        = m_pOptions->bKeepOnTop;
1892                  const bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;                  const bool    bOldStdoutCapture    = m_pOptions->bStdoutCapture;
1893                  const int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;                  const int     bOldMessagesLimit    = m_pOptions->bMessagesLimit;
1894                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1895                  const bool    bOldCompletePath    = m_pOptions->bCompletePath;                  const bool    bOldCompletePath     = m_pOptions->bCompletePath;
1896                  const bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  const bool    bOldInstrumentNames  = m_pOptions->bInstrumentNames;
1897                  const int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  const int     iOldMaxRecentFiles   = m_pOptions->iMaxRecentFiles;
1898                  const int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;                  const int     iOldBaseFontSize     = m_pOptions->iBaseFontSize;
1899                    const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme;
1900                    const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme;
1901                  // Load the current setup settings.                  // Load the current setup settings.
1902                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1903                  // Show the setup dialog...                  // Show the setup dialog...
1904                  if (pOptionsForm->exec()) {                  if (pOptionsForm->exec()) {
1905                          // Warn if something will be only effective on next run.                          // Warn if something will be only effective on next run.
1906                            int iNeedRestart = 0;
1907                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1908                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {
1909                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  updateMessagesCapture();
1910                                    ++iNeedRestart;
1911                            }
1912                            if (( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1913                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1914                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1915                                  QMessageBox::information(this,                                  ++iNeedRestart;
1916                                          tr("Information"),                          }
1917                                          tr("Some settings may be only effective\n"                          // Check whether restart is needed or whether
1918                                          "next time you start this program."));                          // custom options maybe set up immediately...
1919                                  updateMessagesCapture();                          if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) {
1920                                    if (m_pOptions->sCustomStyleTheme.isEmpty()) {
1921                                            ++iNeedRestart;
1922                                    } else {
1923                                            QApplication::setStyle(
1924                                                    QStyleFactory::create(m_pOptions->sCustomStyleTheme));
1925                                    }
1926                            }
1927                            if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) {
1928                                    if (m_pOptions->sCustomColorTheme.isEmpty()) {
1929                                            ++iNeedRestart;
1930                                    } else {
1931                                            QPalette pal;
1932                                            if (PaletteForm::namedPalette(
1933                                                            &m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal))
1934                                                    QApplication::setPalette(pal);
1935                                    }
1936                          }                          }
1937                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1938                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
# Line 1937  void MainForm::viewOptions (void) Line 1960  void MainForm::viewOptions (void)
1960                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||
1961                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))
1962                                  updateMessagesLimit();                                  updateMessagesLimit();
1963                            // Show restart needed message...
1964                            if (iNeedRestart > 0) {
1965                                    QMessageBox::information(this,
1966                                            tr("Information"),
1967                                            tr("Some settings may be only effective\n"
1968                                            "next time you start this program."));
1969                            }
1970                          // And now the main thing, whether we'll do client/server recycling?                          // And now the main thing, whether we'll do client/server recycling?
1971                          if ((sOldServerHost != m_pOptions->sServerHost) ||                          if ((sOldServerHost != m_pOptions->sServerHost) ||
1972                                  (iOldServerPort != m_pOptions->iServerPort) ||                                  (iOldServerPort != m_pOptions->iServerPort) ||
# Line 1970  void MainForm::channelsArrange (void) Line 2000  void MainForm::channelsArrange (void)
2000    
2001          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2002          int y = 0;          int y = 0;
2003          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2004          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  pMdiSubWindow->adjustSize();
2005                  QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                  const QRect& frameRect
2006                  if (pMdiSubWindow) {                          = pMdiSubWindow->frameGeometry();
2007                          pMdiSubWindow->adjustSize();                  int w = m_pWorkspace->width();
2008                          int iWidth = m_pWorkspace->width();                  if (w < frameRect.width())
2009                          if (iWidth < pMdiSubWindow->width())                          w = frameRect.width();
2010                                  iWidth = pMdiSubWindow->width();                  const int h = frameRect.height();
2011                          const int iHeight = pMdiSubWindow->frameGeometry().height();                  pMdiSubWindow->setGeometry(0, y, w, h);
2012                          pMdiSubWindow->setGeometry(0, y, iWidth, iHeight);                  y += h;
                         y += iHeight;  
                 }  
2013          }          }
2014          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
2015    
# Line 2291  void MainForm::updateAllChannelStrips ( Line 2319  void MainForm::updateAllChannelStrips (
2319                  if (bRemoveDeadStrips) {                  if (bRemoveDeadStrips) {
2320                          const QList<QMdiSubWindow *>& wlist                          const QList<QMdiSubWindow *>& wlist
2321                                  = m_pWorkspace->subWindowList();                                  = m_pWorkspace->subWindowList();
2322                          const int iStripCount = wlist.count();                          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2323                          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                  ChannelStrip *pChannelStrip
2324                                  ChannelStrip *pChannelStrip = nullptr;                                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                 if (pMdiSubWindow)  
                                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2325                                  if (pChannelStrip) {                                  if (pChannelStrip) {
2326                                          bool bExists = false;                                          bool bExists = false;
2327                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {
# Line 2373  void MainForm::updateInstrumentNames (vo Line 2398  void MainForm::updateInstrumentNames (vo
2398                  return;                  return;
2399    
2400          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2401          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2402          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2403                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2404                  if (pChannelStrip)                  if (pChannelStrip)
2405                          pChannelStrip->updateInstrumentName(true);                          pChannelStrip->updateInstrumentName(true);
2406          }          }
# Line 2408  void MainForm::updateDisplayFont (void) Line 2430  void MainForm::updateDisplayFont (void)
2430                  return;                  return;
2431    
2432          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2433          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2434          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2435                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2436                  if (pChannelStrip)                  if (pChannelStrip)
2437                          pChannelStrip->setDisplayFont(font);                          pChannelStrip->setDisplayFont(font);
2438          }          }
# Line 2431  void MainForm::updateDisplayEffect (void Line 2450  void MainForm::updateDisplayEffect (void
2450                  return;                  return;
2451    
2452          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2453          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2454          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2455                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2456                  if (pChannelStrip)                  if (pChannelStrip)
2457                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
2458          }          }
# Line 2464  void MainForm::updateMaxVolume (void) Line 2480  void MainForm::updateMaxVolume (void)
2480                  return;                  return;
2481    
2482          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2483          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2484          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2485                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2486                  if (pChannelStrip)                  if (pChannelStrip)
2487                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2488          }          }
# Line 2481  void MainForm::updateMaxVolume (void) Line 2494  void MainForm::updateMaxVolume (void)
2494  // QSampler::MainForm -- Messages window form handlers.  // QSampler::MainForm -- Messages window form handlers.
2495    
2496  // Messages output methods.  // Messages output methods.
2497  void MainForm::appendMessages( const QString& s )  void MainForm::appendMessages ( const QString& s )
2498  {  {
2499          if (m_pMessages)          if (m_pMessages)
2500                  m_pMessages->appendMessages(s);                  m_pMessages->appendMessages(s);
# Line 2489  void MainForm::appendMessages( const QSt Line 2502  void MainForm::appendMessages( const QSt
2502          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2503  }  }
2504    
2505  void MainForm::appendMessagesColor( const QString& s, const QString& c )  void MainForm::appendMessagesColor ( const QString& s, const QColor& rgb )
2506  {  {
2507          if (m_pMessages)          if (m_pMessages)
2508                  m_pMessages->appendMessagesColor(s, c);                  m_pMessages->appendMessagesColor(s, rgb);
2509    
2510          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2511  }  }
2512    
2513  void MainForm::appendMessagesText( const QString& s )  void MainForm::appendMessagesText ( const QString& s )
2514  {  {
2515          if (m_pMessages)          if (m_pMessages)
2516                  m_pMessages->appendMessagesText(s);                  m_pMessages->appendMessagesText(s);
2517  }  }
2518    
2519  void MainForm::appendMessagesError( const QString& sText )  void MainForm::appendMessagesError ( const QString& s )
2520  {  {
2521          if (m_pMessages)          if (m_pMessages)
2522                  m_pMessages->show();                  m_pMessages->show();
2523    
2524          appendMessagesColor(sText.simplified(), "#ff0000");          appendMessagesColor(s.simplified(), Qt::red);
2525    
2526          // Make it look responsive...:)          // Make it look responsive...:)
2527          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
# Line 2521  void MainForm::appendMessagesError( cons Line 2534  void MainForm::appendMessagesError( cons
2534                  QMessageBox mbox(this);                  QMessageBox mbox(this);
2535                  mbox.setIcon(QMessageBox::Critical);                  mbox.setIcon(QMessageBox::Critical);
2536                  mbox.setWindowTitle(sTitle);                  mbox.setWindowTitle(sTitle);
2537                  mbox.setText(sText);                  mbox.setText(s);
2538                  mbox.setStandardButtons(QMessageBox::Cancel);                  mbox.setStandardButtons(QMessageBox::Cancel);
2539                  QCheckBox cbox(tr("Don't show this again"));                  QCheckBox cbox(tr("Don't show this again"));
2540                  cbox.setChecked(false);                  cbox.setChecked(false);
# Line 2617  ChannelStrip *MainForm::createChannelStr Line 2630  ChannelStrip *MainForm::createChannelStr
2630          }          }
2631    
2632          // Add it to workspace...          // Add it to workspace...
2633          m_pWorkspace->addSubWindow(pChannelStrip,          QMdiSubWindow *pMdiSubWindow
2634                  Qt::SubWindow | Qt::FramelessWindowHint);                  = m_pWorkspace->addSubWindow(pChannelStrip,
2635                            Qt::SubWindow | Qt::FramelessWindowHint);
2636            pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose);
2637    
2638          // Actual channel strip setup...          // Actual channel strip setup...
2639          pChannelStrip->setup(pChannel);          pChannelStrip->setup(pChannel);
# Line 2694  ChannelStrip *MainForm::channelStrip ( i Line 2709  ChannelStrip *MainForm::channelStrip ( i
2709          if (wlist.isEmpty())          if (wlist.isEmpty())
2710                  return nullptr;                  return nullptr;
2711    
2712          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2713          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2714                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2715                  if (pChannelStrip) {                  if (pChannelStrip) {
2716                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
2717                          if (pChannel && pChannel->channelID() == iChannelID)                          if (pChannel && pChannel->channelID() == iChannelID)
# Line 2723  void MainForm::channelsMenuAboutToShow ( Line 2735  void MainForm::channelsMenuAboutToShow (
2735                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2736          if (!wlist.isEmpty()) {          if (!wlist.isEmpty()) {
2737                  m_ui.channelsMenu->addSeparator();                  m_ui.channelsMenu->addSeparator();
2738                  const int iStripCount = wlist.count();                  int iStrip = 0;
2739                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2740                          ChannelStrip *pChannelStrip = nullptr;                          ChannelStrip *pChannelStrip
2741                          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2742                          if (pChannelStrip) {                          if (pChannelStrip) {
2743                                  QAction *pAction = m_ui.channelsMenu->addAction(                                  QAction *pAction = m_ui.channelsMenu->addAction(
2744                                          pChannelStrip->windowTitle(),                                          pChannelStrip->windowTitle(),
# Line 2737  void MainForm::channelsMenuAboutToShow ( Line 2747  void MainForm::channelsMenuAboutToShow (
2747                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);
2748                                  pAction->setData(iStrip);                                  pAction->setData(iStrip);
2749                          }                          }
2750                            ++iStrip;
2751                  }                  }
2752          }          }
2753  }  }
# Line 2813  void MainForm::timerSlot (void) Line 2824  void MainForm::timerSlot (void)
2824                                  // Update the channel stream usage for each strip...                                  // Update the channel stream usage for each strip...
2825                                  const QList<QMdiSubWindow *>& wlist                                  const QList<QMdiSubWindow *>& wlist
2826                                          = m_pWorkspace->subWindowList();                                          = m_pWorkspace->subWindowList();
2827                                  const int iStripCount = wlist.count();                                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2828                                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                          ChannelStrip *pChannelStrip
2829                                          ChannelStrip *pChannelStrip = nullptr;                                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                         if (pMdiSubWindow)  
                                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2830                                          if (pChannelStrip && pChannelStrip->isVisible())                                          if (pChannelStrip && pChannelStrip->isVisible())
2831                                                  pChannelStrip->updateChannelUsage();                                                  pChannelStrip->updateChannelUsage();
2832                                  }                                  }
2833                          }                          }
2834                  }                  }
2835    
2836            #if CONFIG_LSCP_CLIENT_CONNECTION_LOST
2837                    // If we lost connection to server: Try to automatically reconnect if we
2838                    // did not start the server.
2839                    //
2840                    // TODO: If we started the server, then we might inform the user that
2841                    // the server probably crashed and asking user ONCE whether we should
2842                    // restart the server.
2843                    if (lscp_client_connection_lost(m_pClient) && !m_pServer)
2844                            startAutoReconnectClient();
2845            #endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST
2846          }          }
2847    
2848          // Register the next timer slot.          // Register the next timer slot.
# Line 2950  void MainForm::stopServer ( bool bIntera Line 2969  void MainForm::stopServer ( bool bIntera
2969    
2970          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2971          if (bGraceWait) {          if (bGraceWait) {
2972                  QTime t;                  QElapsedTimer timer;
2973                  t.start();                  timer.start();
2974                  while (t.elapsed() < QSAMPLER_TIMER_MSECS)                  while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
2975                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2976          }          }
2977  }  }
# Line 2982  void MainForm::processServerExit (void) Line 3001  void MainForm::processServerExit (void)
3001                          // Force final server shutdown...                          // Force final server shutdown...
3002                          m_pServer->kill();                          m_pServer->kill();
3003                          // Give it some time to terminate gracefully and stabilize...                          // Give it some time to terminate gracefully and stabilize...
3004                          QTime t;                          QElapsedTimer timer;
3005                          t.start();                          timer.start();
3006                          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                          while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
3007                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
3008                  }                  }
3009                  // Force final server shutdown...                  // Force final server shutdown...
# Line 3022  lscp_status_t qsampler_client_callback ( Line 3041  lscp_status_t qsampler_client_callback (
3041    
3042    
3043  // Start our almighty client...  // Start our almighty client...
3044  bool MainForm::startClient (void)  bool MainForm::startClient (bool bReconnectOnly)
3045  {  {
3046          // Have it a setup?          // Have it a setup?
3047          if (m_pOptions == nullptr)          if (m_pOptions == nullptr)
# Line 3043  bool MainForm::startClient (void) Line 3062  bool MainForm::startClient (void)
3062                  // Is this the first try?                  // Is this the first try?
3063                  // maybe we need to start a local server...                  // maybe we need to start a local server...
3064                  if ((m_pServer && m_pServer->state() == QProcess::Running)                  if ((m_pServer && m_pServer->state() == QProcess::Running)
3065                          || !m_pOptions->bServerStart) {                          || !m_pOptions->bServerStart || bReconnectOnly)
3066                          appendMessagesError(                  {
3067                                  tr("Could not connect to server as client.\n\nSorry."));                          // if this method is called from autoReconnectClient()
3068                            // then don't bother user with an error message...
3069                            if (!bReconnectOnly) {
3070                                    appendMessagesError(
3071                                            tr("Could not connect to server as client.\n\nSorry.")
3072                                    );
3073                            }
3074                  } else {                  } else {
3075                          startServer();                          startServer();
3076                  }                  }
# Line 3174  void MainForm::stopClient (void) Line 3199  void MainForm::stopClient (void)
3199  }  }
3200    
3201    
3202    void MainForm::startAutoReconnectClient (void)
3203    {
3204            stopClient();
3205            appendMessages(tr("Trying to reconnect..."));
3206            QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3207    }
3208    
3209    
3210    void MainForm::autoReconnectClient (void)
3211    {
3212            const bool bSuccess = startClient(true);
3213            if (!bSuccess)
3214                    QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3215    }
3216    
3217    
3218  // Channel strip activation/selection.  // Channel strip activation/selection.
3219  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )
3220  {  {

Legend:
Removed from v.3559  
changed lines
  Added in v.3789

  ViewVC Help
Powered by ViewVC