/[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 3855 by capela, Thu Feb 4 10:09:42 2021 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-2021, 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 42  Line 46 
46  #include <QProcess>  #include <QProcess>
47  #include <QMessageBox>  #include <QMessageBox>
48    
 #include <QRegExp>  
49  #include <QTextStream>  #include <QTextStream>
50  #include <QFileDialog>  #include <QFileDialog>
51  #include <QFileInfo>  #include <QFileInfo>
# Line 58  Line 61 
61  #include <QTimer>  #include <QTimer>
62  #include <QDateTime>  #include <QDateTime>
63    
64    #include <QElapsedTimer>
65    
66  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)  #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
67  #include <QMimeData>  #include <QMimeData>
68  #endif  #endif
# Line 69  const WindowFlags WindowCloseButtonHint Line 74  const WindowFlags WindowCloseButtonHint
74  #endif  #endif
75    
76  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
77    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
78    #pragma GCC diagnostic push
79    #pragma GCC diagnostic ignored "-Wunused-parameter"
80    #endif
81  #include <gig.h>  #include <gig.h>
82    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
83    #pragma GCC diagnostic pop
84    #endif
85  #endif  #endif
86    
87  // Needed for lroundf()  // Deprecated QTextStreamFunctions/Qt namespaces workaround.
88  #include <math.h>  #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
89    #define endl    Qt::endl
90    #endif
91    
92  #ifndef CONFIG_ROUND  // Needed for lroundf()
93    #ifdef CONFIG_ROUND
94    #include <cmath>
95    #else
96  static inline long lroundf ( float x )  static inline long lroundf ( float x )
97  {  {
98          if (x >= 0.0f)          if (x >= 0.0f)
# Line 966  bool MainForm::closeSession ( bool bForc Line 983  bool MainForm::closeSession ( bool bForc
983                  m_pWorkspace->setUpdatesEnabled(false);                  m_pWorkspace->setUpdatesEnabled(false);
984                  const QList<QMdiSubWindow *>& wlist                  const QList<QMdiSubWindow *>& wlist
985                          = m_pWorkspace->subWindowList();                          = m_pWorkspace->subWindowList();
986                  const int iStripCount = wlist.count();                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
987                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                          ChannelStrip *pChannelStrip
988                          ChannelStrip *pChannelStrip = nullptr;                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
989                          if (pChannelStrip) {                          if (pChannelStrip) {
990                                  Channel *pChannel = pChannelStrip->channel();                                  Channel *pChannel = pChannelStrip->channel();
991                                  if (bForce && pChannel)                                  if (bForce && pChannel)
992                                          pChannel->removeChannel();                                          pChannel->removeChannel();
993                                  delete pChannelStrip;                                  delete pChannelStrip;
994                          }                          }
995                          if (pMdiSubWindow)                          delete pMdiSubWindow;
                                 delete pMdiSubWindow;  
996                  }                  }
997                  m_pWorkspace->setUpdatesEnabled(true);                  m_pWorkspace->setUpdatesEnabled(true);
998                  // We're now clean, for sure.                  // We're now clean, for sure.
# Line 1277  bool MainForm::saveSessionFile ( const Q Line 1290  bool MainForm::saveSessionFile ( const Q
1290          int iChannelID = 0;          int iChannelID = 0;
1291          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1292                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1293          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1294          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1295                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1296                  if (pChannelStrip) {                  if (pChannelStrip) {
1297                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
1298                          if (pChannel) {                          if (pChannel) {
# Line 1762  void MainForm::editResetAllChannels (voi Line 1772  void MainForm::editResetAllChannels (voi
1772          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
1773          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1774                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1775          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1776          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1777                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1778                  if (pChannelStrip)                  if (pChannelStrip)
1779                          pChannelStrip->channelReset();                          pChannelStrip->channelReset();
1780          }          }
# Line 1876  void MainForm::viewOptions (void) Line 1883  void MainForm::viewOptions (void)
1883                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1884                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1885                  // To track down deferred or immediate changes.                  // To track down deferred or immediate changes.
1886                  const QString sOldServerHost      = m_pOptions->sServerHost;                  const QString sOldServerHost       = m_pOptions->sServerHost;
1887                  const int     iOldServerPort      = m_pOptions->iServerPort;                  const int     iOldServerPort       = m_pOptions->iServerPort;
1888                  const int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  const int     iOldServerTimeout    = m_pOptions->iServerTimeout;
1889                  const bool    bOldServerStart     = m_pOptions->bServerStart;                  const bool    bOldServerStart      = m_pOptions->bServerStart;
1890                  const QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  const QString sOldServerCmdLine    = m_pOptions->sServerCmdLine;
1891                  const bool    bOldMessagesLog     = m_pOptions->bMessagesLog;                  const bool    bOldMessagesLog      = m_pOptions->bMessagesLog;
1892                  const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;                  const QString sOldMessagesLogPath  = m_pOptions->sMessagesLogPath;
1893                  const QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  const QString sOldDisplayFont      = m_pOptions->sDisplayFont;
1894                  const bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  const bool    bOldDisplayEffect    = m_pOptions->bDisplayEffect;
1895                  const int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  const int     iOldMaxVolume        = m_pOptions->iMaxVolume;
1896                  const QString sOldMessagesFont    = m_pOptions->sMessagesFont;                  const QString sOldMessagesFont     = m_pOptions->sMessagesFont;
1897                  const bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;                  const bool    bOldKeepOnTop        = m_pOptions->bKeepOnTop;
1898                  const bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;                  const bool    bOldStdoutCapture    = m_pOptions->bStdoutCapture;
1899                  const int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;                  const int     bOldMessagesLimit    = m_pOptions->bMessagesLimit;
1900                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1901                  const bool    bOldCompletePath    = m_pOptions->bCompletePath;                  const bool    bOldCompletePath     = m_pOptions->bCompletePath;
1902                  const bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  const bool    bOldInstrumentNames  = m_pOptions->bInstrumentNames;
1903                  const int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  const int     iOldMaxRecentFiles   = m_pOptions->iMaxRecentFiles;
1904                  const int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;                  const int     iOldBaseFontSize     = m_pOptions->iBaseFontSize;
1905                    const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme;
1906                    const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme;
1907                  // Load the current setup settings.                  // Load the current setup settings.
1908                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1909                  // Show the setup dialog...                  // Show the setup dialog...
1910                  if (pOptionsForm->exec()) {                  if (pOptionsForm->exec()) {
1911                          // Warn if something will be only effective on next run.                          // Warn if something will be only effective on next run.
1912                            int iNeedRestart = 0;
1913                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1914                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {
1915                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  updateMessagesCapture();
1916                                    ++iNeedRestart;
1917                            }
1918                            if (( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1919                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1920                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1921                                  QMessageBox::information(this,                                  ++iNeedRestart;
1922                                          tr("Information"),                          }
1923                                          tr("Some settings may be only effective\n"                          // Check whether restart is needed or whether
1924                                          "next time you start this program."));                          // custom options maybe set up immediately...
1925                                  updateMessagesCapture();                          if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) {
1926                                    if (m_pOptions->sCustomStyleTheme.isEmpty()) {
1927                                            ++iNeedRestart;
1928                                    } else {
1929                                            QApplication::setStyle(
1930                                                    QStyleFactory::create(m_pOptions->sCustomStyleTheme));
1931                                    }
1932                            }
1933                            if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) {
1934                                    if (m_pOptions->sCustomColorTheme.isEmpty()) {
1935                                            ++iNeedRestart;
1936                                    } else {
1937                                            QPalette pal;
1938                                            if (PaletteForm::namedPalette(
1939                                                            &m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal))
1940                                                    QApplication::setPalette(pal);
1941                                    }
1942                          }                          }
1943                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1944                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
# Line 1937  void MainForm::viewOptions (void) Line 1966  void MainForm::viewOptions (void)
1966                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||
1967                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))
1968                                  updateMessagesLimit();                                  updateMessagesLimit();
1969                            // Show restart needed message...
1970                            if (iNeedRestart > 0) {
1971                                    QMessageBox::information(this,
1972                                            tr("Information"),
1973                                            tr("Some settings may be only effective\n"
1974                                            "next time you start this program."));
1975                            }
1976                          // And now the main thing, whether we'll do client/server recycling?                          // And now the main thing, whether we'll do client/server recycling?
1977                          if ((sOldServerHost != m_pOptions->sServerHost) ||                          if ((sOldServerHost != m_pOptions->sServerHost) ||
1978                                  (iOldServerPort != m_pOptions->iServerPort) ||                                  (iOldServerPort != m_pOptions->iServerPort) ||
# Line 1970  void MainForm::channelsArrange (void) Line 2006  void MainForm::channelsArrange (void)
2006    
2007          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2008          int y = 0;          int y = 0;
2009          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2010          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  pMdiSubWindow->adjustSize();
2011                  QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                  const QRect& frameRect
2012                  if (pMdiSubWindow) {                          = pMdiSubWindow->frameGeometry();
2013                          pMdiSubWindow->adjustSize();                  int w = m_pWorkspace->width();
2014                          int iWidth = m_pWorkspace->width();                  if (w < frameRect.width())
2015                          if (iWidth < pMdiSubWindow->width())                          w = frameRect.width();
2016                                  iWidth = pMdiSubWindow->width();                  const int h = frameRect.height();
2017                          const int iHeight = pMdiSubWindow->frameGeometry().height();                  pMdiSubWindow->setGeometry(0, y, w, h);
2018                          pMdiSubWindow->setGeometry(0, y, iWidth, iHeight);                  y += h;
                         y += iHeight;  
                 }  
2019          }          }
2020          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
2021    
# Line 2073  void MainForm::helpAbout (void) Line 2107  void MainForm::helpAbout (void)
2107                  sText += "</font></small>";                  sText += "</font></small>";
2108          }          }
2109          sText += "<br />\n";          sText += "<br />\n";
2110          sText += tr("Using") + ": ";          sText += tr("Using: Qt %1").arg(qVersion());
2111    #if defined(QT_STATIC)
2112            sText += "-static";
2113    #endif
2114            sText += ", ";
2115          sText += ::lscp_client_package();          sText += ::lscp_client_package();
2116          sText += " ";          sText += " ";
2117          sText += ::lscp_client_version();          sText += ::lscp_client_version();
# Line 2291  void MainForm::updateAllChannelStrips ( Line 2329  void MainForm::updateAllChannelStrips (
2329                  if (bRemoveDeadStrips) {                  if (bRemoveDeadStrips) {
2330                          const QList<QMdiSubWindow *>& wlist                          const QList<QMdiSubWindow *>& wlist
2331                                  = m_pWorkspace->subWindowList();                                  = m_pWorkspace->subWindowList();
2332                          const int iStripCount = wlist.count();                          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2333                          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                  ChannelStrip *pChannelStrip
2334                                  ChannelStrip *pChannelStrip = nullptr;                                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                 if (pMdiSubWindow)  
                                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2335                                  if (pChannelStrip) {                                  if (pChannelStrip) {
2336                                          bool bExists = false;                                          bool bExists = false;
2337                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {
# Line 2373  void MainForm::updateInstrumentNames (vo Line 2408  void MainForm::updateInstrumentNames (vo
2408                  return;                  return;
2409    
2410          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2411          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2412          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2413                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2414                  if (pChannelStrip)                  if (pChannelStrip)
2415                          pChannelStrip->updateInstrumentName(true);                          pChannelStrip->updateInstrumentName(true);
2416          }          }
# Line 2408  void MainForm::updateDisplayFont (void) Line 2440  void MainForm::updateDisplayFont (void)
2440                  return;                  return;
2441    
2442          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2443          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2444          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2445                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2446                  if (pChannelStrip)                  if (pChannelStrip)
2447                          pChannelStrip->setDisplayFont(font);                          pChannelStrip->setDisplayFont(font);
2448          }          }
# Line 2431  void MainForm::updateDisplayEffect (void Line 2460  void MainForm::updateDisplayEffect (void
2460                  return;                  return;
2461    
2462          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2463          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2464          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2465                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2466                  if (pChannelStrip)                  if (pChannelStrip)
2467                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
2468          }          }
# Line 2464  void MainForm::updateMaxVolume (void) Line 2490  void MainForm::updateMaxVolume (void)
2490                  return;                  return;
2491    
2492          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2493          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2494          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2495                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2496                  if (pChannelStrip)                  if (pChannelStrip)
2497                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2498          }          }
# Line 2481  void MainForm::updateMaxVolume (void) Line 2504  void MainForm::updateMaxVolume (void)
2504  // QSampler::MainForm -- Messages window form handlers.  // QSampler::MainForm -- Messages window form handlers.
2505    
2506  // Messages output methods.  // Messages output methods.
2507  void MainForm::appendMessages( const QString& s )  void MainForm::appendMessages ( const QString& s )
2508  {  {
2509          if (m_pMessages)          if (m_pMessages)
2510                  m_pMessages->appendMessages(s);                  m_pMessages->appendMessages(s);
# Line 2489  void MainForm::appendMessages( const QSt Line 2512  void MainForm::appendMessages( const QSt
2512          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2513  }  }
2514    
2515  void MainForm::appendMessagesColor( const QString& s, const QString& c )  void MainForm::appendMessagesColor ( const QString& s, const QColor& rgb )
2516  {  {
2517          if (m_pMessages)          if (m_pMessages)
2518                  m_pMessages->appendMessagesColor(s, c);                  m_pMessages->appendMessagesColor(s, rgb);
2519    
2520          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2521  }  }
2522    
2523  void MainForm::appendMessagesText( const QString& s )  void MainForm::appendMessagesText ( const QString& s )
2524  {  {
2525          if (m_pMessages)          if (m_pMessages)
2526                  m_pMessages->appendMessagesText(s);                  m_pMessages->appendMessagesText(s);
2527  }  }
2528    
2529  void MainForm::appendMessagesError( const QString& sText )  void MainForm::appendMessagesError ( const QString& s )
2530  {  {
2531          if (m_pMessages)          if (m_pMessages)
2532                  m_pMessages->show();                  m_pMessages->show();
2533    
2534          appendMessagesColor(sText.simplified(), "#ff0000");          appendMessagesColor(s.simplified(), Qt::red);
2535    
2536          // Make it look responsive...:)          // Make it look responsive...:)
2537          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
# Line 2521  void MainForm::appendMessagesError( cons Line 2544  void MainForm::appendMessagesError( cons
2544                  QMessageBox mbox(this);                  QMessageBox mbox(this);
2545                  mbox.setIcon(QMessageBox::Critical);                  mbox.setIcon(QMessageBox::Critical);
2546                  mbox.setWindowTitle(sTitle);                  mbox.setWindowTitle(sTitle);
2547                  mbox.setText(sText);                  mbox.setText(s);
2548                  mbox.setStandardButtons(QMessageBox::Cancel);                  mbox.setStandardButtons(QMessageBox::Cancel);
2549                  QCheckBox cbox(tr("Don't show this again"));                  QCheckBox cbox(tr("Don't show this again"));
2550                  cbox.setChecked(false);                  cbox.setChecked(false);
# Line 2617  ChannelStrip *MainForm::createChannelStr Line 2640  ChannelStrip *MainForm::createChannelStr
2640          }          }
2641    
2642          // Add it to workspace...          // Add it to workspace...
2643          m_pWorkspace->addSubWindow(pChannelStrip,          QMdiSubWindow *pMdiSubWindow
2644                  Qt::SubWindow | Qt::FramelessWindowHint);                  = m_pWorkspace->addSubWindow(pChannelStrip,
2645                            Qt::SubWindow | Qt::FramelessWindowHint);
2646            pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose);
2647    
2648          // Actual channel strip setup...          // Actual channel strip setup...
2649          pChannelStrip->setup(pChannel);          pChannelStrip->setup(pChannel);
# Line 2694  ChannelStrip *MainForm::channelStrip ( i Line 2719  ChannelStrip *MainForm::channelStrip ( i
2719          if (wlist.isEmpty())          if (wlist.isEmpty())
2720                  return nullptr;                  return nullptr;
2721    
2722          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2723          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2724                  ChannelStrip *pChannelStrip = nullptr;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2725                  if (pChannelStrip) {                  if (pChannelStrip) {
2726                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
2727                          if (pChannel && pChannel->channelID() == iChannelID)                          if (pChannel && pChannel->channelID() == iChannelID)
# Line 2723  void MainForm::channelsMenuAboutToShow ( Line 2745  void MainForm::channelsMenuAboutToShow (
2745                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2746          if (!wlist.isEmpty()) {          if (!wlist.isEmpty()) {
2747                  m_ui.channelsMenu->addSeparator();                  m_ui.channelsMenu->addSeparator();
2748                  const int iStripCount = wlist.count();                  int iStrip = 0;
2749                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2750                          ChannelStrip *pChannelStrip = nullptr;                          ChannelStrip *pChannelStrip
2751                          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2752                          if (pChannelStrip) {                          if (pChannelStrip) {
2753                                  QAction *pAction = m_ui.channelsMenu->addAction(                                  QAction *pAction = m_ui.channelsMenu->addAction(
2754                                          pChannelStrip->windowTitle(),                                          pChannelStrip->windowTitle(),
# Line 2737  void MainForm::channelsMenuAboutToShow ( Line 2757  void MainForm::channelsMenuAboutToShow (
2757                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);
2758                                  pAction->setData(iStrip);                                  pAction->setData(iStrip);
2759                          }                          }
2760                            ++iStrip;
2761                  }                  }
2762          }          }
2763  }  }
# Line 2813  void MainForm::timerSlot (void) Line 2834  void MainForm::timerSlot (void)
2834                                  // Update the channel stream usage for each strip...                                  // Update the channel stream usage for each strip...
2835                                  const QList<QMdiSubWindow *>& wlist                                  const QList<QMdiSubWindow *>& wlist
2836                                          = m_pWorkspace->subWindowList();                                          = m_pWorkspace->subWindowList();
2837                                  const int iStripCount = wlist.count();                                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2838                                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                          ChannelStrip *pChannelStrip
2839                                          ChannelStrip *pChannelStrip = nullptr;                                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                         if (pMdiSubWindow)  
                                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2840                                          if (pChannelStrip && pChannelStrip->isVisible())                                          if (pChannelStrip && pChannelStrip->isVisible())
2841                                                  pChannelStrip->updateChannelUsage();                                                  pChannelStrip->updateChannelUsage();
2842                                  }                                  }
2843                          }                          }
2844                  }                  }
2845    
2846            #if CONFIG_LSCP_CLIENT_CONNECTION_LOST
2847                    // If we lost connection to server: Try to automatically reconnect if we
2848                    // did not start the server.
2849                    //
2850                    // TODO: If we started the server, then we might inform the user that
2851                    // the server probably crashed and asking user ONCE whether we should
2852                    // restart the server.
2853                    if (lscp_client_connection_lost(m_pClient) && !m_pServer)
2854                            startAutoReconnectClient();
2855            #endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST
2856          }          }
2857    
2858          // Register the next timer slot.          // Register the next timer slot.
# Line 2900  void MainForm::startServer (void) Line 2929  void MainForm::startServer (void)
2929    
2930          // Show startup results...          // Show startup results...
2931          appendMessages(          appendMessages(
2932                  tr("Server was started with PID=%1.").arg((long) m_pServer->pid()));                  tr("Server was started with PID=%1.")
2933                    #if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
2934                            .arg(quint64(m_pServer->pid())));
2935                    #else
2936                            .arg(quint64(m_pServer->processId())));
2937                    #endif
2938    
2939          // Reset (yet again) the timer counters,          // Reset (yet again) the timer counters,
2940          // but this time is deferred as the user opted.          // but this time is deferred as the user opted.
# Line 2950  void MainForm::stopServer ( bool bIntera Line 2984  void MainForm::stopServer ( bool bIntera
2984    
2985          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2986          if (bGraceWait) {          if (bGraceWait) {
2987                  QTime t;                  QElapsedTimer timer;
2988                  t.start();                  timer.start();
2989                  while (t.elapsed() < QSAMPLER_TIMER_MSECS)                  while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
2990                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2991          }          }
2992  }  }
# Line 2982  void MainForm::processServerExit (void) Line 3016  void MainForm::processServerExit (void)
3016                          // Force final server shutdown...                          // Force final server shutdown...
3017                          m_pServer->kill();                          m_pServer->kill();
3018                          // Give it some time to terminate gracefully and stabilize...                          // Give it some time to terminate gracefully and stabilize...
3019                          QTime t;                          QElapsedTimer timer;
3020                          t.start();                          timer.start();
3021                          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                          while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
3022                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
3023                  }                  }
3024                  // Force final server shutdown...                  // Force final server shutdown...
# Line 3022  lscp_status_t qsampler_client_callback ( Line 3056  lscp_status_t qsampler_client_callback (
3056    
3057    
3058  // Start our almighty client...  // Start our almighty client...
3059  bool MainForm::startClient (void)  bool MainForm::startClient (bool bReconnectOnly)
3060  {  {
3061          // Have it a setup?          // Have it a setup?
3062          if (m_pOptions == nullptr)          if (m_pOptions == nullptr)
# Line 3043  bool MainForm::startClient (void) Line 3077  bool MainForm::startClient (void)
3077                  // Is this the first try?                  // Is this the first try?
3078                  // maybe we need to start a local server...                  // maybe we need to start a local server...
3079                  if ((m_pServer && m_pServer->state() == QProcess::Running)                  if ((m_pServer && m_pServer->state() == QProcess::Running)
3080                          || !m_pOptions->bServerStart) {                          || !m_pOptions->bServerStart || bReconnectOnly)
3081                          appendMessagesError(                  {
3082                                  tr("Could not connect to server as client.\n\nSorry."));                          // if this method is called from autoReconnectClient()
3083                            // then don't bother user with an error message...
3084                            if (!bReconnectOnly) {
3085                                    appendMessagesError(
3086                                            tr("Could not connect to server as client.\n\nSorry.")
3087                                    );
3088                            }
3089                  } else {                  } else {
3090                          startServer();                          startServer();
3091                  }                  }
# Line 3174  void MainForm::stopClient (void) Line 3214  void MainForm::stopClient (void)
3214  }  }
3215    
3216    
3217    void MainForm::startAutoReconnectClient (void)
3218    {
3219            stopClient();
3220            appendMessages(tr("Trying to reconnect..."));
3221            QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3222    }
3223    
3224    
3225    void MainForm::autoReconnectClient (void)
3226    {
3227            const bool bSuccess = startClient(true);
3228            if (!bSuccess)
3229                    QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3230    }
3231    
3232    
3233  // Channel strip activation/selection.  // Channel strip activation/selection.
3234  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )
3235  {  {

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

  ViewVC Help
Powered by ViewVC