/[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 3518 by capela, Sun Jun 30 16:58:30 2019 UTC revision 3761 by capela, Tue Mar 31 11:06:16 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  #if QT_VERSION >= 0x050000  #include <QElapsedTimer>
66    
67    #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
68  #include <QMimeData>  #include <QMimeData>
69  #endif  #endif
70    
71  #if QT_VERSION < 0x040500  #if QT_VERSION < QT_VERSION_CHECK(4, 5, 0)
72  namespace Qt {  namespace Qt {
73  const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);  const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);
74  }  }
75  #endif  #endif
76    
77    // Deprecated QTextStreamFunctions/Qt namespaces workaround.
78    #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
79    #define endl    Qt::endl
80    #endif
81    
82    
83  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
84  #include <gig.h>  #include <gig.h>
85  #endif  #endif
# Line 202  protected: Line 214  protected:
214  // QSampler::MainForm -- Main window form implementation.  // QSampler::MainForm -- Main window form implementation.
215    
216  // Kind of singleton reference.  // Kind of singleton reference.
217  MainForm *MainForm::g_pMainForm = NULL;  MainForm *MainForm::g_pMainForm = nullptr;
218    
219  MainForm::MainForm ( QWidget *pParent )  MainForm::MainForm ( QWidget *pParent )
220          : QMainWindow(pParent)          : QMainWindow(pParent)
# Line 213  MainForm::MainForm ( QWidget *pParent ) Line 225  MainForm::MainForm ( QWidget *pParent )
225          g_pMainForm = this;          g_pMainForm = this;
226    
227          // Initialize some pointer references.          // Initialize some pointer references.
228          m_pOptions = NULL;          m_pOptions = nullptr;
229    
230          // All child forms are to be created later, not earlier than setup.          // All child forms are to be created later, not earlier than setup.
231          m_pMessages = NULL;          m_pMessages = nullptr;
232          m_pInstrumentListForm = NULL;          m_pInstrumentListForm = nullptr;
233          m_pDeviceForm = NULL;          m_pDeviceForm = nullptr;
234    
235          // We'll start clean.          // We'll start clean.
236          m_iUntitled   = 0;          m_iUntitled   = 0;
237          m_iDirtySetup = 0;          m_iDirtySetup = 0;
238          m_iDirtyCount = 0;          m_iDirtyCount = 0;
239    
240          m_pServer = NULL;          m_pServer = nullptr;
241          m_pClient = NULL;          m_pClient = nullptr;
242    
243          m_iStartDelay = 0;          m_iStartDelay = 0;
244          m_iTimerDelay = 0;          m_iTimerDelay = 0;
# Line 255  MainForm::MainForm ( QWidget *pParent ) Line 267  MainForm::MainForm ( QWidget *pParent )
267          sigemptyset(&sigusr1.sa_mask);          sigemptyset(&sigusr1.sa_mask);
268          sigusr1.sa_flags = 0;          sigusr1.sa_flags = 0;
269          sigusr1.sa_flags |= SA_RESTART;          sigusr1.sa_flags |= SA_RESTART;
270          ::sigaction(SIGUSR1, &sigusr1, NULL);          ::sigaction(SIGUSR1, &sigusr1, nullptr);
271    
272          // Initialize file descriptors for SIGTERM socket notifier.          // Initialize file descriptors for SIGTERM socket notifier.
273          ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigterm);          ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigterm);
# Line 269  MainForm::MainForm ( QWidget *pParent ) Line 281  MainForm::MainForm ( QWidget *pParent )
281          // Install SIGTERM signal handler.          // Install SIGTERM signal handler.
282          struct sigaction sigterm;          struct sigaction sigterm;
283          sigterm.sa_handler = qsampler_sigterm_handler;          sigterm.sa_handler = qsampler_sigterm_handler;
284          ::sigemptyset(&sigterm.sa_mask);          sigemptyset(&sigterm.sa_mask);
285          sigterm.sa_flags = 0;          sigterm.sa_flags = 0;
286          sigterm.sa_flags |= SA_RESTART;          sigterm.sa_flags |= SA_RESTART;
287          ::sigaction(SIGTERM, &sigterm, NULL);          ::sigaction(SIGTERM, &sigterm, nullptr);
288          ::sigaction(SIGQUIT, &sigterm, NULL);          ::sigaction(SIGQUIT, &sigterm, nullptr);
289    
290          // Ignore SIGHUP/SIGINT signals.          // Ignore SIGHUP/SIGINT signals.
291          ::signal(SIGHUP, SIG_IGN);          ::signal(SIGHUP, SIG_IGN);
# Line 281  MainForm::MainForm ( QWidget *pParent ) Line 293  MainForm::MainForm ( QWidget *pParent )
293    
294  #else   // HAVE_SIGNAL_H  #else   // HAVE_SIGNAL_H
295    
296          m_pSigusr1Notifier = NULL;          m_pSigusr1Notifier = nullptr;
297          m_pSigtermNotifier = NULL;          m_pSigtermNotifier = nullptr;
298                    
299  #endif  // !HAVE_SIGNAL_H  #endif  // !HAVE_SIGNAL_H
300    
# Line 493  MainForm::~MainForm() Line 505  MainForm::~MainForm()
505  #endif  #endif
506    
507          // Pseudo-singleton reference shut-down.          // Pseudo-singleton reference shut-down.
508          g_pMainForm = NULL;          g_pMainForm = nullptr;
509  }  }
510    
511    
# Line 630  void MainForm::closeEvent ( QCloseEvent Line 642  void MainForm::closeEvent ( QCloseEvent
642  void MainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  void MainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
643  {  {
644          // Accept external drags only...          // Accept external drags only...
645          if (pDragEnterEvent->source() == NULL          if (pDragEnterEvent->source() == nullptr
646                  && pDragEnterEvent->mimeData()->hasUrls()) {                  && pDragEnterEvent->mimeData()->hasUrls()) {
647                  pDragEnterEvent->accept();                  pDragEnterEvent->accept();
648          } else {          } else {
# Line 654  void MainForm::dropEvent ( QDropEvent *p Line 666  void MainForm::dropEvent ( QDropEvent *p
666                          if (QFileInfo(sPath).exists()) {                          if (QFileInfo(sPath).exists()) {
667                                  // Try to create a new channel from instrument file...                                  // Try to create a new channel from instrument file...
668                                  Channel *pChannel = new Channel();                                  Channel *pChannel = new Channel();
669                                  if (pChannel == NULL)                                  if (pChannel == nullptr)
670                                          return;                                          return;
671                                  // Start setting the instrument filename...                                  // Start setting the instrument filename...
672                                  pChannel->setInstrument(sPath, 0);                                  pChannel->setInstrument(sPath, 0);
# Line 864  bool MainForm::newSession (void) Line 876  bool MainForm::newSession (void)
876  // Open an existing sampler session.  // Open an existing sampler session.
877  bool MainForm::openSession (void)  bool MainForm::openSession (void)
878  {  {
879          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
880                  return false;                  return false;
881    
882          // Ask for the filename to open...          // Ask for the filename to open...
883          QString sFilename = QFileDialog::getOpenFileName(this,          QString sFilename = QFileDialog::getOpenFileName(this,
884                  QSAMPLER_TITLE ": " + tr("Open Session"), // Caption.                  tr("Open Session"),                       // Caption.
885                  m_pOptions->sSessionDir,                  // Start here.                  m_pOptions->sSessionDir,                  // Start here.
886                  tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)                  tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)
887          );          );
# Line 890  bool MainForm::openSession (void) Line 902  bool MainForm::openSession (void)
902  // Save current sampler session with another name.  // Save current sampler session with another name.
903  bool MainForm::saveSession ( bool bPrompt )  bool MainForm::saveSession ( bool bPrompt )
904  {  {
905          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
906                  return false;                  return false;
907    
908          QString sFilename = m_sFilename;          QString sFilename = m_sFilename;
# Line 902  bool MainForm::saveSession ( bool bPromp Line 914  bool MainForm::saveSession ( bool bPromp
914                          sFilename = m_pOptions->sSessionDir;                          sFilename = m_pOptions->sSessionDir;
915                  // Prompt the guy...                  // Prompt the guy...
916                  sFilename = QFileDialog::getSaveFileName(this,                  sFilename = QFileDialog::getSaveFileName(this,
917                          QSAMPLER_TITLE ": " + tr("Save Session"), // Caption.                          tr("Save Session"),                       // Caption.
918                          sFilename,                                // Start here.                          sFilename,                                // Start here.
919                          tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)                          tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)
920                  );                  );
# Line 916  bool MainForm::saveSession ( bool bPromp Line 928  bool MainForm::saveSession ( bool bPromp
928                  // Check if already exists...                  // Check if already exists...
929                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {
930                          if (QMessageBox::warning(this,                          if (QMessageBox::warning(this,
931                                  QSAMPLER_TITLE ": " + tr("Warning"),                                  tr("Warning"),
932                                  tr("The file already exists:\n\n"                                  tr("The file already exists:\n\n"
933                                  "\"%1\"\n\n"                                  "\"%1\"\n\n"
934                                  "Do you want to replace it?")                                  "Do you want to replace it?")
# Line 941  bool MainForm::closeSession ( bool bForc Line 953  bool MainForm::closeSession ( bool bForc
953          // Are we dirty enough to prompt it?          // Are we dirty enough to prompt it?
954          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
955                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
956                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
957                          tr("The current session has been changed:\n\n"                          tr("The current session has been changed:\n\n"
958                          "\"%1\"\n\n"                          "\"%1\"\n\n"
959                          "Do you want to save the changes?")                          "Do you want to save the changes?")
# Line 966  bool MainForm::closeSession ( bool bForc Line 978  bool MainForm::closeSession ( bool bForc
978                  m_pWorkspace->setUpdatesEnabled(false);                  m_pWorkspace->setUpdatesEnabled(false);
979                  const QList<QMdiSubWindow *>& wlist                  const QList<QMdiSubWindow *>& wlist
980                          = m_pWorkspace->subWindowList();                          = m_pWorkspace->subWindowList();
981                  const int iStripCount = wlist.count();                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
982                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                          ChannelStrip *pChannelStrip
983                          ChannelStrip *pChannelStrip = NULL;                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
984                          if (pChannelStrip) {                          if (pChannelStrip) {
985                                  Channel *pChannel = pChannelStrip->channel();                                  Channel *pChannel = pChannelStrip->channel();
986                                  if (bForce && pChannel)                                  if (bForce && pChannel)
987                                          pChannel->removeChannel();                                          pChannel->removeChannel();
988                                  delete pChannelStrip;                                  delete pChannelStrip;
989                          }                          }
990                          if (pMdiSubWindow)                          delete pMdiSubWindow;
                                 delete pMdiSubWindow;  
991                  }                  }
992                  m_pWorkspace->setUpdatesEnabled(true);                  m_pWorkspace->setUpdatesEnabled(true);
993                  // We're now clean, for sure.                  // We're now clean, for sure.
# Line 993  bool MainForm::closeSession ( bool bForc Line 1001  bool MainForm::closeSession ( bool bForc
1001  // Load a session from specific file path.  // Load a session from specific file path.
1002  bool MainForm::loadSessionFile ( const QString& sFilename )  bool MainForm::loadSessionFile ( const QString& sFilename )
1003  {  {
1004          if (m_pClient == NULL)          if (m_pClient == nullptr)
1005                  return false;                  return false;
1006    
1007          // Open and read from real file.          // Open and read from real file.
# Line 1069  bool MainForm::loadSessionFile ( const Q Line 1077  bool MainForm::loadSessionFile ( const Q
1077  // Save current session to specific file path.  // Save current session to specific file path.
1078  bool MainForm::saveSessionFile ( const QString& sFilename )  bool MainForm::saveSessionFile ( const QString& sFilename )
1079  {  {
1080          if (m_pClient == NULL)          if (m_pClient == nullptr)
1081                  return false;                  return false;
1082    
1083          // Check whether server is apparently OK...          // Check whether server is apparently OK...
# Line 1259  bool MainForm::saveSessionFile ( const Q Line 1267  bool MainForm::saveSessionFile ( const Q
1267                  }                  }
1268                  ts << endl;                  ts << endl;
1269                  // Check for errors...                  // Check for errors...
1270                  if (pInstrs == NULL && ::lscp_client_get_errno(m_pClient)) {                  if (pInstrs == nullptr && ::lscp_client_get_errno(m_pClient)) {
1271                          appendMessagesClient("lscp_list_midi_instruments");                          appendMessagesClient("lscp_list_midi_instruments");
1272                          iErrors++;                          iErrors++;
1273                  }                  }
# Line 1267  bool MainForm::saveSessionFile ( const Q Line 1275  bool MainForm::saveSessionFile ( const Q
1275                  midiInstrumentMap.insert(iMidiMap, iMap);                  midiInstrumentMap.insert(iMidiMap, iMap);
1276          }          }
1277          // Check for errors...          // Check for errors...
1278          if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) {          if (piMaps == nullptr && ::lscp_client_get_errno(m_pClient)) {
1279                  appendMessagesClient("lscp_list_midi_instrument_maps");                  appendMessagesClient("lscp_list_midi_instrument_maps");
1280                  iErrors++;                  iErrors++;
1281          }          }
# Line 1277  bool MainForm::saveSessionFile ( const Q Line 1285  bool MainForm::saveSessionFile ( const Q
1285          int iChannelID = 0;          int iChannelID = 0;
1286          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1287                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1288          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1289          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1290                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1291                  if (pChannelStrip) {                  if (pChannelStrip) {
1292                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
1293                          if (pChannel) {                          if (pChannel) {
# Line 1488  void MainForm::fileSaveAs (void) Line 1493  void MainForm::fileSaveAs (void)
1493  // Reset the sampler instance.  // Reset the sampler instance.
1494  void MainForm::fileReset (void)  void MainForm::fileReset (void)
1495  {  {
1496          if (m_pClient == NULL)          if (m_pClient == nullptr)
1497                  return;                  return;
1498    
1499          // Ask user whether he/she want's an internal sampler reset...          // Ask user whether he/she want's an internal sampler reset...
1500          if (m_pOptions && m_pOptions->bConfirmReset) {          if (m_pOptions && m_pOptions->bConfirmReset) {
1501                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");                  const QString& sTitle = tr("Warning");
1502                  const QString& sText = tr(                  const QString& sText = tr(
1503                          "Resetting the sampler instance will close\n"                          "Resetting the sampler instance will close\n"
1504                          "all device and channel configurations.\n\n"                          "all device and channel configurations.\n\n"
# Line 1544  void MainForm::fileReset (void) Line 1549  void MainForm::fileReset (void)
1549  // Restart the client/server instance.  // Restart the client/server instance.
1550  void MainForm::fileRestart (void)  void MainForm::fileRestart (void)
1551  {  {
1552          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1553                  return;                  return;
1554    
1555          bool bRestart = true;          bool bRestart = true;
# Line 1552  void MainForm::fileRestart (void) Line 1557  void MainForm::fileRestart (void)
1557          // Ask user whether he/she want's a complete restart...          // Ask user whether he/she want's a complete restart...
1558          // (if we're currently up and running)          // (if we're currently up and running)
1559          if (m_pOptions && m_pOptions->bConfirmRestart) {          if (m_pOptions && m_pOptions->bConfirmRestart) {
1560                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");                  const QString& sTitle = tr("Warning");
1561                  const QString& sText = tr(                  const QString& sText = tr(
1562                          "New settings will be effective after\n"                          "New settings will be effective after\n"
1563                          "restarting the client/server connection.\n\n"                          "restarting the client/server connection.\n\n"
# Line 1612  void MainForm::editAddChannel (void) Line 1617  void MainForm::editAddChannel (void)
1617    
1618  void MainForm::addChannelStrip (void)  void MainForm::addChannelStrip (void)
1619  {  {
1620          if (m_pClient == NULL)          if (m_pClient == nullptr)
1621                  return;                  return;
1622    
1623          // Just create the channel instance...          // Just create the channel instance...
1624          Channel *pChannel = new Channel();          Channel *pChannel = new Channel();
1625          if (pChannel == NULL)          if (pChannel == nullptr)
1626                  return;                  return;
1627    
1628          // Before we show it up, may be we'll          // Before we show it up, may be we'll
# Line 1653  void MainForm::editRemoveChannel (void) Line 1658  void MainForm::editRemoveChannel (void)
1658    
1659  void MainForm::removeChannelStrip (void)  void MainForm::removeChannelStrip (void)
1660  {  {
1661          if (m_pClient == NULL)          if (m_pClient == nullptr)
1662                  return;                  return;
1663    
1664          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1665          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1666                  return;                  return;
1667    
1668          Channel *pChannel = pChannelStrip->channel();          Channel *pChannel = pChannelStrip->channel();
1669          if (pChannel == NULL)          if (pChannel == nullptr)
1670                  return;                  return;
1671    
1672          // Prompt user if he/she's sure about this...          // Prompt user if he/she's sure about this...
1673          if (m_pOptions && m_pOptions->bConfirmRemove) {          if (m_pOptions && m_pOptions->bConfirmRemove) {
1674                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");                  const QString& sTitle = tr("Warning");
1675                  const QString& sText = tr(                  const QString& sText = tr(
1676                          "About to remove channel:\n\n"                          "About to remove channel:\n\n"
1677                          "%1\n\n"                          "%1\n\n"
# Line 1709  void MainForm::removeChannelStrip (void) Line 1714  void MainForm::removeChannelStrip (void)
1714  // Setup current sampler channel.  // Setup current sampler channel.
1715  void MainForm::editSetupChannel (void)  void MainForm::editSetupChannel (void)
1716  {  {
1717          if (m_pClient == NULL)          if (m_pClient == nullptr)
1718                  return;                  return;
1719    
1720          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1721          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1722                  return;                  return;
1723    
1724          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1724  void MainForm::editSetupChannel (void) Line 1729  void MainForm::editSetupChannel (void)
1729  // Edit current sampler channel.  // Edit current sampler channel.
1730  void MainForm::editEditChannel (void)  void MainForm::editEditChannel (void)
1731  {  {
1732          if (m_pClient == NULL)          if (m_pClient == nullptr)
1733                  return;                  return;
1734    
1735          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1736          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1737                  return;                  return;
1738    
1739          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1739  void MainForm::editEditChannel (void) Line 1744  void MainForm::editEditChannel (void)
1744  // Reset current sampler channel.  // Reset current sampler channel.
1745  void MainForm::editResetChannel (void)  void MainForm::editResetChannel (void)
1746  {  {
1747          if (m_pClient == NULL)          if (m_pClient == nullptr)
1748                  return;                  return;
1749    
1750          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1751          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1752                  return;                  return;
1753    
1754          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1754  void MainForm::editResetChannel (void) Line 1759  void MainForm::editResetChannel (void)
1759  // Reset all sampler channels.  // Reset all sampler channels.
1760  void MainForm::editResetAllChannels (void)  void MainForm::editResetAllChannels (void)
1761  {  {
1762          if (m_pClient == NULL)          if (m_pClient == nullptr)
1763                  return;                  return;
1764    
1765          // Invoque the channel strip procedure,          // Invoque the channel strip procedure,
# Line 1762  void MainForm::editResetAllChannels (voi Line 1767  void MainForm::editResetAllChannels (voi
1767          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
1768          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1769                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1770          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1771          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1772                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1773                  if (pChannelStrip)                  if (pChannelStrip)
1774                          pChannelStrip->channelReset();                          pChannelStrip->channelReset();
1775          }          }
# Line 1826  void MainForm::viewMessages ( bool bOn ) Line 1828  void MainForm::viewMessages ( bool bOn )
1828  // Show/hide the MIDI instrument list-view form.  // Show/hide the MIDI instrument list-view form.
1829  void MainForm::viewInstruments (void)  void MainForm::viewInstruments (void)
1830  {  {
1831          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1832                  return;                  return;
1833    
1834          if (m_pInstrumentListForm) {          if (m_pInstrumentListForm) {
# Line 1845  void MainForm::viewInstruments (void) Line 1847  void MainForm::viewInstruments (void)
1847  // Show/hide the device configurator form.  // Show/hide the device configurator form.
1848  void MainForm::viewDevices (void)  void MainForm::viewDevices (void)
1849  {  {
1850          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1851                  return;                  return;
1852    
1853          if (m_pDeviceForm) {          if (m_pDeviceForm) {
# Line 1864  void MainForm::viewDevices (void) Line 1866  void MainForm::viewDevices (void)
1866  // Show options dialog.  // Show options dialog.
1867  void MainForm::viewOptions (void)  void MainForm::viewOptions (void)
1868  {  {
1869          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1870                  return;                  return;
1871    
1872          OptionsForm* pOptionsForm = new OptionsForm(this);          OptionsForm* pOptionsForm = new OptionsForm(this);
# Line 1876  void MainForm::viewOptions (void) Line 1878  void MainForm::viewOptions (void)
1878                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1879                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1880                  // To track down deferred or immediate changes.                  // To track down deferred or immediate changes.
1881                  const QString sOldServerHost      = m_pOptions->sServerHost;                  const QString sOldServerHost       = m_pOptions->sServerHost;
1882                  const int     iOldServerPort      = m_pOptions->iServerPort;                  const int     iOldServerPort       = m_pOptions->iServerPort;
1883                  const int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  const int     iOldServerTimeout    = m_pOptions->iServerTimeout;
1884                  const bool    bOldServerStart     = m_pOptions->bServerStart;                  const bool    bOldServerStart      = m_pOptions->bServerStart;
1885                  const QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  const QString sOldServerCmdLine    = m_pOptions->sServerCmdLine;
1886                  const bool    bOldMessagesLog     = m_pOptions->bMessagesLog;                  const bool    bOldMessagesLog      = m_pOptions->bMessagesLog;
1887                  const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;                  const QString sOldMessagesLogPath  = m_pOptions->sMessagesLogPath;
1888                  const QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  const QString sOldDisplayFont      = m_pOptions->sDisplayFont;
1889                  const bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  const bool    bOldDisplayEffect    = m_pOptions->bDisplayEffect;
1890                  const int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  const int     iOldMaxVolume        = m_pOptions->iMaxVolume;
1891                  const QString sOldMessagesFont    = m_pOptions->sMessagesFont;                  const QString sOldMessagesFont     = m_pOptions->sMessagesFont;
1892                  const bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;                  const bool    bOldKeepOnTop        = m_pOptions->bKeepOnTop;
1893                  const bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;                  const bool    bOldStdoutCapture    = m_pOptions->bStdoutCapture;
1894                  const int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;                  const int     bOldMessagesLimit    = m_pOptions->bMessagesLimit;
1895                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1896                  const bool    bOldCompletePath    = m_pOptions->bCompletePath;                  const bool    bOldCompletePath     = m_pOptions->bCompletePath;
1897                  const bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  const bool    bOldInstrumentNames  = m_pOptions->bInstrumentNames;
1898                  const int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  const int     iOldMaxRecentFiles   = m_pOptions->iMaxRecentFiles;
1899                  const int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;                  const int     iOldBaseFontSize     = m_pOptions->iBaseFontSize;
1900                    const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme;
1901                    const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme;
1902                  // Load the current setup settings.                  // Load the current setup settings.
1903                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1904                  // Show the setup dialog...                  // Show the setup dialog...
1905                  if (pOptionsForm->exec()) {                  if (pOptionsForm->exec()) {
1906                          // Warn if something will be only effective on next run.                          // Warn if something will be only effective on next run.
1907                            int iNeedRestart = 0;
1908                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1909                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {
1910                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  updateMessagesCapture();
1911                                    ++iNeedRestart;
1912                            }
1913                            if (( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1914                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1915                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1916                                  QMessageBox::information(this,                                  ++iNeedRestart;
1917                                          QSAMPLER_TITLE ": " + tr("Information"),                          }
1918                                          tr("Some settings may be only effective\n"                          // Check whether restart is needed or whether
1919                                          "next time you start this program."));                          // custom options maybe set up immediately...
1920                                  updateMessagesCapture();                          if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) {
1921                                    if (m_pOptions->sCustomStyleTheme.isEmpty()) {
1922                                            ++iNeedRestart;
1923                                    } else {
1924                                            QApplication::setStyle(
1925                                                    QStyleFactory::create(m_pOptions->sCustomStyleTheme));
1926                                    }
1927                            }
1928                            if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) {
1929                                    if (m_pOptions->sCustomColorTheme.isEmpty()) {
1930                                            ++iNeedRestart;
1931                                    } else {
1932                                            QPalette pal;
1933                                            if (PaletteForm::namedPalette(
1934                                                            &m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal))
1935                                                    QApplication::setPalette(pal);
1936                                    }
1937                          }                          }
1938                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1939                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
# Line 1937  void MainForm::viewOptions (void) Line 1961  void MainForm::viewOptions (void)
1961                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||
1962                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))
1963                                  updateMessagesLimit();                                  updateMessagesLimit();
1964                            // Show restart needed message...
1965                            if (iNeedRestart > 0) {
1966                                    QMessageBox::information(this,
1967                                            tr("Information"),
1968                                            tr("Some settings may be only effective\n"
1969                                            "next time you start this program."));
1970                            }
1971                          // And now the main thing, whether we'll do client/server recycling?                          // And now the main thing, whether we'll do client/server recycling?
1972                          if ((sOldServerHost != m_pOptions->sServerHost) ||                          if ((sOldServerHost != m_pOptions->sServerHost) ||
1973                                  (iOldServerPort != m_pOptions->iServerPort) ||                                  (iOldServerPort != m_pOptions->iServerPort) ||
# Line 1970  void MainForm::channelsArrange (void) Line 2001  void MainForm::channelsArrange (void)
2001    
2002          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2003          int y = 0;          int y = 0;
2004          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2005          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  pMdiSubWindow->adjustSize();
2006                  QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                  const QRect& frameRect
2007                  if (pMdiSubWindow) {                          = pMdiSubWindow->frameGeometry();
2008                          pMdiSubWindow->adjustSize();                  int w = m_pWorkspace->width();
2009                          int iWidth = m_pWorkspace->width();                  if (w < frameRect.width())
2010                          if (iWidth < pMdiSubWindow->width())                          w = frameRect.width();
2011                                  iWidth = pMdiSubWindow->width();                  const int h = frameRect.height();
2012                          const int iHeight = pMdiSubWindow->frameGeometry().height();                  pMdiSubWindow->setGeometry(0, y, w, h);
2013                          pMdiSubWindow->setGeometry(0, y, iWidth, iHeight);                  y += h;
                         y += iHeight;  
                 }  
2014          }          }
2015          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
2016    
# Line 1992  void MainForm::channelsArrange (void) Line 2021  void MainForm::channelsArrange (void)
2021  // Auto-arrange channel strips.  // Auto-arrange channel strips.
2022  void MainForm::channelsAutoArrange ( bool bOn )  void MainForm::channelsAutoArrange ( bool bOn )
2023  {  {
2024          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2025                  return;                  return;
2026    
2027          // Toggle the auto-arrange flag.          // Toggle the auto-arrange flag.
# Line 2096  void MainForm::helpAbout (void) Line 2125  void MainForm::helpAbout (void)
2125          sText += "</small>";          sText += "</small>";
2126          sText += "</p>\n";          sText += "</p>\n";
2127    
2128          QMessageBox::about(this, tr("About") + " " QSAMPLER_TITLE, sText);          QMessageBox::about(this, tr("About"), sText);
2129  }  }
2130    
2131    
# Line 2109  void MainForm::stabilizeForm (void) Line 2138  void MainForm::stabilizeForm (void)
2138          QString sSessionName = sessionName(m_sFilename);          QString sSessionName = sessionName(m_sFilename);
2139          if (m_iDirtyCount > 0)          if (m_iDirtyCount > 0)
2140                  sSessionName += " *";                  sSessionName += " *";
2141          setWindowTitle(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));          setWindowTitle(sSessionName);
2142    
2143          // Update the main menu state...          // Update the main menu state...
2144          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
2145          const QList<QMdiSubWindow *>& wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist = m_pWorkspace->subWindowList();
2146          const bool bHasClient = (m_pOptions != NULL && m_pClient != NULL);          const bool bHasClient = (m_pOptions != nullptr && m_pClient != nullptr);
2147          const bool bHasChannel = (bHasClient && pChannelStrip != NULL);          const bool bHasChannel = (bHasClient && pChannelStrip != nullptr);
2148          const bool bHasChannels = (bHasClient && wlist.count() > 0);          const bool bHasChannels = (bHasClient && wlist.count() > 0);
2149          m_ui.fileNewAction->setEnabled(bHasClient);          m_ui.fileNewAction->setEnabled(bHasClient);
2150          m_ui.fileOpenAction->setEnabled(bHasClient);          m_ui.fileOpenAction->setEnabled(bHasClient);
2151          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);
2152          m_ui.fileSaveAsAction->setEnabled(bHasClient);          m_ui.fileSaveAsAction->setEnabled(bHasClient);
2153          m_ui.fileResetAction->setEnabled(bHasClient);          m_ui.fileResetAction->setEnabled(bHasClient);
2154          m_ui.fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);          m_ui.fileRestartAction->setEnabled(bHasClient || m_pServer == nullptr);
2155          m_ui.editAddChannelAction->setEnabled(bHasClient);          m_ui.editAddChannelAction->setEnabled(bHasClient);
2156          m_ui.editRemoveChannelAction->setEnabled(bHasChannel);          m_ui.editRemoveChannelAction->setEnabled(bHasChannel);
2157          m_ui.editSetupChannelAction->setEnabled(bHasChannel);          m_ui.editSetupChannelAction->setEnabled(bHasChannel);
# Line 2271  void MainForm::updateAllChannelStrips ( Line 2300  void MainForm::updateAllChannelStrips (
2300    
2301          // Retrieve the current channel list.          // Retrieve the current channel list.
2302          int *piChannelIDs = ::lscp_list_channels(m_pClient);          int *piChannelIDs = ::lscp_list_channels(m_pClient);
2303          if (piChannelIDs == NULL) {          if (piChannelIDs == nullptr) {
2304                  if (::lscp_client_get_errno(m_pClient)) {                  if (::lscp_client_get_errno(m_pClient)) {
2305                          appendMessagesClient("lscp_list_channels");                          appendMessagesClient("lscp_list_channels");
2306                          appendMessagesError(                          appendMessagesError(
# Line 2291  void MainForm::updateAllChannelStrips ( Line 2320  void MainForm::updateAllChannelStrips (
2320                  if (bRemoveDeadStrips) {                  if (bRemoveDeadStrips) {
2321                          const QList<QMdiSubWindow *>& wlist                          const QList<QMdiSubWindow *>& wlist
2322                                  = m_pWorkspace->subWindowList();                                  = m_pWorkspace->subWindowList();
2323                          const int iStripCount = wlist.count();                          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2324                          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                  ChannelStrip *pChannelStrip
2325                                  ChannelStrip *pChannelStrip = NULL;                                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                 if (pMdiSubWindow)  
                                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2326                                  if (pChannelStrip) {                                  if (pChannelStrip) {
2327                                          bool bExists = false;                                          bool bExists = false;
2328                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {
2329                                                  Channel *pChannel = pChannelStrip->channel();                                                  Channel *pChannel = pChannelStrip->channel();
2330                                                  if (pChannel == NULL)                                                  if (pChannel == nullptr)
2331                                                          break;                                                          break;
2332                                                  if (piChannelIDs[iChannel] == pChannel->channelID()) {                                                  if (piChannelIDs[iChannel] == pChannel->channelID()) {
2333                                                          // strip exists, don't touch it                                                          // strip exists, don't touch it
# Line 2324  void MainForm::updateAllChannelStrips ( Line 2350  void MainForm::updateAllChannelStrips (
2350  // Update the recent files list and menu.  // Update the recent files list and menu.
2351  void MainForm::updateRecentFiles ( const QString& sFilename )  void MainForm::updateRecentFiles ( const QString& sFilename )
2352  {  {
2353          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2354                  return;                  return;
2355    
2356          // Remove from list if already there (avoid duplicates)          // Remove from list if already there (avoid duplicates)
# Line 2339  void MainForm::updateRecentFiles ( const Line 2365  void MainForm::updateRecentFiles ( const
2365  // Update the recent files list and menu.  // Update the recent files list and menu.
2366  void MainForm::updateRecentFilesMenu (void)  void MainForm::updateRecentFilesMenu (void)
2367  {  {
2368          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2369                  return;                  return;
2370    
2371          // Time to keep the list under limits.          // Time to keep the list under limits.
# Line 2373  void MainForm::updateInstrumentNames (vo Line 2399  void MainForm::updateInstrumentNames (vo
2399                  return;                  return;
2400    
2401          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2402          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2403          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2404                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2405                  if (pChannelStrip)                  if (pChannelStrip)
2406                          pChannelStrip->updateInstrumentName(true);                          pChannelStrip->updateInstrumentName(true);
2407          }          }
# Line 2389  void MainForm::updateInstrumentNames (vo Line 2412  void MainForm::updateInstrumentNames (vo
2412  // Force update of the channels display font.  // Force update of the channels display font.
2413  void MainForm::updateDisplayFont (void)  void MainForm::updateDisplayFont (void)
2414  {  {
2415          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2416                  return;                  return;
2417    
2418          // Check if display font is legal.          // Check if display font is legal.
# Line 2408  void MainForm::updateDisplayFont (void) Line 2431  void MainForm::updateDisplayFont (void)
2431                  return;                  return;
2432    
2433          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2434          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2435          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2436                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2437                  if (pChannelStrip)                  if (pChannelStrip)
2438                          pChannelStrip->setDisplayFont(font);                          pChannelStrip->setDisplayFont(font);
2439          }          }
# Line 2431  void MainForm::updateDisplayEffect (void Line 2451  void MainForm::updateDisplayEffect (void
2451                  return;                  return;
2452    
2453          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2454          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2455          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2456                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2457                  if (pChannelStrip)                  if (pChannelStrip)
2458                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
2459          }          }
# Line 2447  void MainForm::updateDisplayEffect (void Line 2464  void MainForm::updateDisplayEffect (void
2464  // Force update of the channels maximum volume setting.  // Force update of the channels maximum volume setting.
2465  void MainForm::updateMaxVolume (void)  void MainForm::updateMaxVolume (void)
2466  {  {
2467          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2468                  return;                  return;
2469    
2470  #ifdef CONFIG_VOLUME  #ifdef CONFIG_VOLUME
# Line 2464  void MainForm::updateMaxVolume (void) Line 2481  void MainForm::updateMaxVolume (void)
2481                  return;                  return;
2482    
2483          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2484          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2485          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2486                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2487                  if (pChannelStrip)                  if (pChannelStrip)
2488                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2489          }          }
# Line 2514  void MainForm::appendMessagesError( cons Line 2528  void MainForm::appendMessagesError( cons
2528          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2529    
2530          if (m_pOptions && m_pOptions->bConfirmError) {          if (m_pOptions && m_pOptions->bConfirmError) {
2531                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Error");                  const QString& sTitle = tr("Error");
2532          #if 0          #if 0
2533                  QMessageBox::critical(this, sTitle, sText, QMessageBox::Cancel);                  QMessageBox::critical(this, sTitle, sText, QMessageBox::Cancel);
2534          #else          #else
# Line 2537  void MainForm::appendMessagesError( cons Line 2551  void MainForm::appendMessagesError( cons
2551  // This is a special message format, just for client results.  // This is a special message format, just for client results.
2552  void MainForm::appendMessagesClient( const QString& s )  void MainForm::appendMessagesClient( const QString& s )
2553  {  {
2554          if (m_pClient == NULL)          if (m_pClient == nullptr)
2555                  return;                  return;
2556    
2557          appendMessagesColor(s + QString(": %1 (errno=%2)")          appendMessagesColor(s + QString(": %1 (errno=%2)")
# Line 2552  void MainForm::appendMessagesClient( con Line 2566  void MainForm::appendMessagesClient( con
2566  // Force update of the messages font.  // Force update of the messages font.
2567  void MainForm::updateMessagesFont (void)  void MainForm::updateMessagesFont (void)
2568  {  {
2569          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2570                  return;                  return;
2571    
2572          if (m_pMessages && !m_pOptions->sMessagesFont.isEmpty()) {          if (m_pMessages && !m_pOptions->sMessagesFont.isEmpty()) {
# Line 2566  void MainForm::updateMessagesFont (void) Line 2580  void MainForm::updateMessagesFont (void)
2580  // Update messages window line limit.  // Update messages window line limit.
2581  void MainForm::updateMessagesLimit (void)  void MainForm::updateMessagesLimit (void)
2582  {  {
2583          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2584                  return;                  return;
2585    
2586          if (m_pMessages) {          if (m_pMessages) {
# Line 2581  void MainForm::updateMessagesLimit (void Line 2595  void MainForm::updateMessagesLimit (void
2595  // Enablement of the messages capture feature.  // Enablement of the messages capture feature.
2596  void MainForm::updateMessagesCapture (void)  void MainForm::updateMessagesCapture (void)
2597  {  {
2598          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2599                  return;                  return;
2600    
2601          if (m_pMessages)          if (m_pMessages)
# Line 2595  void MainForm::updateMessagesCapture (vo Line 2609  void MainForm::updateMessagesCapture (vo
2609  // The channel strip creation executive.  // The channel strip creation executive.
2610  ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel )  ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel )
2611  {  {
2612          if (m_pClient == NULL || pChannel == NULL)          if (m_pClient == nullptr || pChannel == nullptr)
2613                  return NULL;                  return nullptr;
2614    
2615          // Add a new channel itema...          // Add a new channel itema...
2616          ChannelStrip *pChannelStrip = new ChannelStrip();          ChannelStrip *pChannelStrip = new ChannelStrip();
2617          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
2618                  return NULL;                  return nullptr;
2619    
2620          // Set some initial channel strip options...          // Set some initial channel strip options...
2621          if (m_pOptions) {          if (m_pOptions) {
# Line 2617  ChannelStrip *MainForm::createChannelStr Line 2631  ChannelStrip *MainForm::createChannelStr
2631          }          }
2632    
2633          // Add it to workspace...          // Add it to workspace...
2634          m_pWorkspace->addSubWindow(pChannelStrip,          QMdiSubWindow *pMdiSubWindow
2635                  Qt::SubWindow | Qt::FramelessWindowHint);                  = m_pWorkspace->addSubWindow(pChannelStrip,
2636                            Qt::SubWindow | Qt::FramelessWindowHint);
2637            pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose);
2638    
2639          // Actual channel strip setup...          // Actual channel strip setup...
2640          pChannelStrip->setup(pChannel);          pChannelStrip->setup(pChannel);
# Line 2642  void MainForm::destroyChannelStrip ( Cha Line 2658  void MainForm::destroyChannelStrip ( Cha
2658  {  {
2659          QMdiSubWindow *pMdiSubWindow          QMdiSubWindow *pMdiSubWindow
2660                  = static_cast<QMdiSubWindow *> (pChannelStrip->parentWidget());                  = static_cast<QMdiSubWindow *> (pChannelStrip->parentWidget());
2661          if (pMdiSubWindow == NULL)          if (pMdiSubWindow == nullptr)
2662                  return;                  return;
2663    
2664          // Just delete the channel strip.          // Just delete the channel strip.
# Line 2661  ChannelStrip *MainForm::activeChannelStr Line 2677  ChannelStrip *MainForm::activeChannelStr
2677          if (pMdiSubWindow)          if (pMdiSubWindow)
2678                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2679          else          else
2680                  return NULL;                  return nullptr;
2681  }  }
2682    
2683    
2684  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
2685  ChannelStrip *MainForm::channelStripAt ( int iStrip )  ChannelStrip *MainForm::channelStripAt ( int iStrip )
2686  {  {
2687          if (!m_pWorkspace) return NULL;          if (!m_pWorkspace) return nullptr;
2688    
2689          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
2690                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2691          if (wlist.isEmpty())          if (wlist.isEmpty())
2692                  return NULL;                  return nullptr;
2693    
2694          if (iStrip < 0 || iStrip >= wlist.count())          if (iStrip < 0 || iStrip >= wlist.count())
2695                  return NULL;                  return nullptr;
2696    
2697          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);
2698          if (pMdiSubWindow)          if (pMdiSubWindow)
2699                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2700          else          else
2701                  return NULL;                  return nullptr;
2702  }  }
2703    
2704    
# Line 2692  ChannelStrip *MainForm::channelStrip ( i Line 2708  ChannelStrip *MainForm::channelStrip ( i
2708          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
2709                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2710          if (wlist.isEmpty())          if (wlist.isEmpty())
2711                  return NULL;                  return nullptr;
2712    
2713          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2714          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2715                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2716                  if (pChannelStrip) {                  if (pChannelStrip) {
2717                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
2718                          if (pChannel && pChannel->channelID() == iChannelID)                          if (pChannel && pChannel->channelID() == iChannelID)
# Line 2708  ChannelStrip *MainForm::channelStrip ( i Line 2721  ChannelStrip *MainForm::channelStrip ( i
2721          }          }
2722    
2723          // Not found.          // Not found.
2724          return NULL;          return nullptr;
2725  }  }
2726    
2727    
# Line 2723  void MainForm::channelsMenuAboutToShow ( Line 2736  void MainForm::channelsMenuAboutToShow (
2736                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2737          if (!wlist.isEmpty()) {          if (!wlist.isEmpty()) {
2738                  m_ui.channelsMenu->addSeparator();                  m_ui.channelsMenu->addSeparator();
2739                  const int iStripCount = wlist.count();                  int iStrip = 0;
2740                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2741                          ChannelStrip *pChannelStrip = NULL;                          ChannelStrip *pChannelStrip
2742                          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2743                          if (pChannelStrip) {                          if (pChannelStrip) {
2744                                  QAction *pAction = m_ui.channelsMenu->addAction(                                  QAction *pAction = m_ui.channelsMenu->addAction(
2745                                          pChannelStrip->windowTitle(),                                          pChannelStrip->windowTitle(),
# Line 2737  void MainForm::channelsMenuAboutToShow ( Line 2748  void MainForm::channelsMenuAboutToShow (
2748                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);
2749                                  pAction->setData(iStrip);                                  pAction->setData(iStrip);
2750                          }                          }
2751                            ++iStrip;
2752                  }                  }
2753          }          }
2754  }  }
# Line 2747  void MainForm::channelsMenuActivated (vo Line 2759  void MainForm::channelsMenuActivated (vo
2759  {  {
2760          // Retrive channel index from action data...          // Retrive channel index from action data...
2761          QAction *pAction = qobject_cast<QAction *> (sender());          QAction *pAction = qobject_cast<QAction *> (sender());
2762          if (pAction == NULL)          if (pAction == nullptr)
2763                  return;                  return;
2764    
2765          ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt());          ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt());
# Line 2778  void MainForm::stopSchedule (void) Line 2790  void MainForm::stopSchedule (void)
2790  // Timer slot funtion.  // Timer slot funtion.
2791  void MainForm::timerSlot (void)  void MainForm::timerSlot (void)
2792  {  {
2793          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2794                  return;                  return;
2795    
2796          // Is it the first shot on server start after a few delay?          // Is it the first shot on server start after a few delay?
# Line 2813  void MainForm::timerSlot (void) Line 2825  void MainForm::timerSlot (void)
2825                                  // Update the channel stream usage for each strip...                                  // Update the channel stream usage for each strip...
2826                                  const QList<QMdiSubWindow *>& wlist                                  const QList<QMdiSubWindow *>& wlist
2827                                          = m_pWorkspace->subWindowList();                                          = m_pWorkspace->subWindowList();
2828                                  const int iStripCount = wlist.count();                                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2829                                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                          ChannelStrip *pChannelStrip
2830                                          ChannelStrip *pChannelStrip = NULL;                                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                         if (pMdiSubWindow)  
                                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2831                                          if (pChannelStrip && pChannelStrip->isVisible())                                          if (pChannelStrip && pChannelStrip->isVisible())
2832                                                  pChannelStrip->updateChannelUsage();                                                  pChannelStrip->updateChannelUsage();
2833                                  }                                  }
2834                          }                          }
2835                  }                  }
2836    
2837            #if CONFIG_LSCP_CLIENT_CONNECTION_LOST
2838                    // If we lost connection to server: Try to automatically reconnect if we
2839                    // did not start the server.
2840                    //
2841                    // TODO: If we started the server, then we might inform the user that
2842                    // the server probably crashed and asking user ONCE whether we should
2843                    // restart the server.
2844                    if (lscp_client_connection_lost(m_pClient) && !m_pServer)
2845                            startAutoReconnectClient();
2846            #endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST
2847          }          }
2848    
2849          // Register the next timer slot.          // Register the next timer slot.
# Line 2837  void MainForm::timerSlot (void) Line 2857  void MainForm::timerSlot (void)
2857  // Start linuxsampler server...  // Start linuxsampler server...
2858  void MainForm::startServer (void)  void MainForm::startServer (void)
2859  {  {
2860          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2861                  return;                  return;
2862    
2863          // Aren't already a client, are we?          // Aren't already a client, are we?
# Line 2847  void MainForm::startServer (void) Line 2867  void MainForm::startServer (void)
2867          // Is the server process instance still here?          // Is the server process instance still here?
2868          if (m_pServer) {          if (m_pServer) {
2869                  if (QMessageBox::warning(this,                  if (QMessageBox::warning(this,
2870                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
2871                          tr("Could not start the LinuxSampler server.\n\n"                          tr("Could not start the LinuxSampler server.\n\n"
2872                          "Maybe it is already started."),                          "Maybe it is already started."),
2873                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
# Line 2917  void MainForm::stopServer ( bool bIntera Line 2937  void MainForm::stopServer ( bool bIntera
2937    
2938          if (m_pServer && bInteractive) {          if (m_pServer && bInteractive) {
2939                  if (QMessageBox::question(this,                  if (QMessageBox::question(this,
2940                          QSAMPLER_TITLE ": " + tr("The backend's fate ..."),                          tr("The backend's fate ..."),
2941                          tr("You have the option to keep the sampler backend (LinuxSampler)\n"                          tr("You have the option to keep the sampler backend (LinuxSampler)\n"
2942                          "running in the background. The sampler would continue to work\n"                          "running in the background. The sampler would continue to work\n"
2943                          "according to your current sampler session and you could alter the\n"                          "according to your current sampler session and you could alter the\n"
# Line 2950  void MainForm::stopServer ( bool bIntera Line 2970  void MainForm::stopServer ( bool bIntera
2970    
2971          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2972          if (bGraceWait) {          if (bGraceWait) {
2973                  QTime t;                  QElapsedTimer timer;
2974                  t.start();                  timer.start();
2975                  while (t.elapsed() < QSAMPLER_TIMER_MSECS)                  while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
2976                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2977          }          }
2978  }  }
# Line 2982  void MainForm::processServerExit (void) Line 3002  void MainForm::processServerExit (void)
3002                          // Force final server shutdown...                          // Force final server shutdown...
3003                          m_pServer->kill();                          m_pServer->kill();
3004                          // Give it some time to terminate gracefully and stabilize...                          // Give it some time to terminate gracefully and stabilize...
3005                          QTime t;                          QElapsedTimer timer;
3006                          t.start();                          timer.start();
3007                          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                          while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
3008                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
3009                  }                  }
3010                  // Force final server shutdown...                  // Force final server shutdown...
# Line 2992  void MainForm::processServerExit (void) Line 3012  void MainForm::processServerExit (void)
3012                          tr("Server was stopped with exit status %1.")                          tr("Server was stopped with exit status %1.")
3013                          .arg(m_pServer->exitStatus()));                          .arg(m_pServer->exitStatus()));
3014                  delete m_pServer;                  delete m_pServer;
3015                  m_pServer = NULL;                  m_pServer = nullptr;
3016          }          }
3017    
3018          // Again, make status visible stable.          // Again, make status visible stable.
# Line 3008  lscp_status_t qsampler_client_callback ( Line 3028  lscp_status_t qsampler_client_callback (
3028          lscp_event_t event, const char *pchData, int cchData, void *pvData )          lscp_event_t event, const char *pchData, int cchData, void *pvData )
3029  {  {
3030          MainForm* pMainForm = (MainForm *) pvData;          MainForm* pMainForm = (MainForm *) pvData;
3031          if (pMainForm == NULL)          if (pMainForm == nullptr)
3032                  return LSCP_FAILED;                  return LSCP_FAILED;
3033    
3034          // ATTN: DO NOT EVER call any GUI code here,          // ATTN: DO NOT EVER call any GUI code here,
# Line 3022  lscp_status_t qsampler_client_callback ( Line 3042  lscp_status_t qsampler_client_callback (
3042    
3043    
3044  // Start our almighty client...  // Start our almighty client...
3045  bool MainForm::startClient (void)  bool MainForm::startClient (bool bReconnectOnly)
3046  {  {
3047          // Have it a setup?          // Have it a setup?
3048          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
3049                  return false;                  return false;
3050    
3051          // Aren't we already started, are we?          // Aren't we already started, are we?
# Line 3039  bool MainForm::startClient (void) Line 3059  bool MainForm::startClient (void)
3059          m_pClient = ::lscp_client_create(          m_pClient = ::lscp_client_create(
3060                  m_pOptions->sServerHost.toUtf8().constData(),                  m_pOptions->sServerHost.toUtf8().constData(),
3061                  m_pOptions->iServerPort, qsampler_client_callback, this);                  m_pOptions->iServerPort, qsampler_client_callback, this);
3062          if (m_pClient == NULL) {          if (m_pClient == nullptr) {
3063                  // Is this the first try?                  // Is this the first try?
3064                  // maybe we need to start a local server...                  // maybe we need to start a local server...
3065                  if ((m_pServer && m_pServer->state() == QProcess::Running)                  if ((m_pServer && m_pServer->state() == QProcess::Running)
3066                          || !m_pOptions->bServerStart) {                          || !m_pOptions->bServerStart || bReconnectOnly)
3067                          appendMessagesError(                  {
3068                                  tr("Could not connect to server as client.\n\nSorry."));                          // if this method is called from autoReconnectClient()
3069                            // then don't bother user with an error message...
3070                            if (!bReconnectOnly) {
3071                                    appendMessagesError(
3072                                            tr("Could not connect to server as client.\n\nSorry.")
3073                                    );
3074                            }
3075                  } else {                  } else {
3076                          startServer();                          startServer();
3077                  }                  }
# Line 3125  bool MainForm::startClient (void) Line 3151  bool MainForm::startClient (void)
3151  // Stop client...  // Stop client...
3152  void MainForm::stopClient (void)  void MainForm::stopClient (void)
3153  {  {
3154          if (m_pClient == NULL)          if (m_pClient == nullptr)
3155                  return;                  return;
3156    
3157          // Log prepare here.          // Log prepare here.
# Line 3157  void MainForm::stopClient (void) Line 3183  void MainForm::stopClient (void)
3183          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
3184          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);
3185          ::lscp_client_destroy(m_pClient);          ::lscp_client_destroy(m_pClient);
3186          m_pClient = NULL;          m_pClient = nullptr;
3187    
3188          // Hard-notify instrumnet and device configuration forms,          // Hard-notify instrumnet and device configuration forms,
3189          // if visible, that we're running out...          // if visible, that we're running out...
# Line 3174  void MainForm::stopClient (void) Line 3200  void MainForm::stopClient (void)
3200  }  }
3201    
3202    
3203    void MainForm::startAutoReconnectClient (void)
3204    {
3205            stopClient();
3206            appendMessages(tr("Trying to reconnect..."));
3207            QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3208    }
3209    
3210    
3211    void MainForm::autoReconnectClient (void)
3212    {
3213            const bool bSuccess = startClient(true);
3214            if (!bSuccess)
3215                    QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3216    }
3217    
3218    
3219  // Channel strip activation/selection.  // Channel strip activation/selection.
3220  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )
3221  {  {
3222          ChannelStrip *pChannelStrip = NULL;          ChannelStrip *pChannelStrip = nullptr;
3223          if (pMdiSubWindow)          if (pMdiSubWindow)
3224                  pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
3225          if (pChannelStrip)          if (pChannelStrip)

Legend:
Removed from v.3518  
changed lines
  Added in v.3761

  ViewVC Help
Powered by ViewVC