/[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 2978 by capela, Mon Aug 15 19:10:16 2016 UTC revision 3832 by capela, Mon Oct 19 17:08:56 2020 UTC
# Line 1  Line 1 
1  // qsamplerMainForm.cpp  // qsamplerMainForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2016, 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 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  #if QT_VERSION >= 0x050000  #include <QElapsedTimer>
65    
66    #if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
67  #include <QMimeData>  #include <QMimeData>
68  #endif  #endif
69    
70  #if QT_VERSION < 0x040500  #if QT_VERSION < QT_VERSION_CHECK(4, 5, 0)
71  namespace Qt {  namespace Qt {
72  const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);  const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);
73  }  }
74  #endif  #endif
75    
 #ifdef HAVE_SIGNAL_H  
 #include <signal.h>  
 #endif  
   
76  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
77  #include <gig.h>  #include <gig.h>
78  #endif  #endif
79    
80    // Deprecated QTextStreamFunctions/Qt namespaces workaround.
81    #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
82    #define endl    Qt::endl
83    #endif
84    
85  // Needed for lroundf()  // Needed for lroundf()
86  #include <math.h>  #include <math.h>
87    
# Line 91  static inline long lroundf ( float x ) Line 97  static inline long lroundf ( float x )
97    
98    
99  // All winsock apps needs this.  // All winsock apps needs this.
100  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
101  static WSADATA _wsaData;  static WSADATA _wsaData;
102    #undef HAVE_SIGNAL_H
103  #endif  #endif
104    
105    
# Line 103  static WSADATA _wsaData; Line 110  static WSADATA _wsaData;
110    
111  #include <QSocketNotifier>  #include <QSocketNotifier>
112    
113    #include <unistd.h>
114  #include <sys/types.h>  #include <sys/types.h>
115  #include <sys/socket.h>  #include <sys/socket.h>
   
116  #include <signal.h>  #include <signal.h>
117    
118  // File descriptor for SIGUSR1 notifier.  // File descriptor for SIGUSR1 notifier.
119  static int g_fdUsr1[2];  static int g_fdSigusr1[2] = { -1, -1 };
120    
121  // Unix SIGUSR1 signal handler.  // Unix SIGUSR1 signal handler.
122  static void qsampler_sigusr1_handler ( int /* signo */ )  static void qsampler_sigusr1_handler ( int /* signo */ )
123  {  {
124          char c = 1;          char c = 1;
125    
126          (::write(g_fdUsr1[0], &c, sizeof(c)) > 0);          (::write(g_fdSigusr1[0], &c, sizeof(c)) > 0);
127    }
128    
129    // File descriptor for SIGTERM notifier.
130    static int g_fdSigterm[2] = { -1, -1 };
131    
132    // Unix SIGTERM signal handler.
133    static void qsampler_sigterm_handler ( int /* signo */ )
134    {
135            char c = 1;
136    
137            (::write(g_fdSigterm[0], &c, sizeof(c)) > 0);
138  }  }
139    
140  #endif  // HAVE_SIGNAL_H  #endif  // HAVE_SIGNAL_H
141    
142    
143  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
144  // qsampler -- namespace  // QSampler -- namespace
145    
146    
147  namespace QSampler {  namespace QSampler {
# Line 143  namespace QSampler { Line 161  namespace QSampler {
161    
162    
163  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
164  // LscpEvent -- specialty for LSCP callback comunication.  // QSampler::LscpEvent -- specialty for LSCP callback comunication.
   
165    
166  class LscpEvent : public QEvent  class LscpEvent : public QEvent
167  {  {
# Line 159  public: Line 176  public:
176          }          }
177    
178          // Accessors.          // Accessors.
179          lscp_event_t event() { return m_event; }          lscp_event_t  event() { return m_event; }
180          QString&     data()  { return m_data;  }          const QString& data() { return m_data;  }
181    
182  private:  private:
183    
# Line 172  private: Line 189  private:
189    
190    
191  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
192  // qsamplerMainForm -- Main window form implementation.  // QSampler::Workspace -- Main window workspace (MDI Area) decl.
193    
194    class Workspace : public QMdiArea
195    {
196    public:
197    
198            Workspace(MainForm *pMainForm) : QMdiArea(pMainForm) {}
199    
200    protected:
201    
202            void resizeEvent(QResizeEvent *)
203            {
204                    MainForm *pMainForm = static_cast<MainForm *> (parentWidget());
205                    if (pMainForm)
206                            pMainForm->channelsArrangeAuto();
207            }
208    };
209    
210    
211    //-------------------------------------------------------------------------
212    // QSampler::MainForm -- Main window form implementation.
213    
214  // Kind of singleton reference.  // Kind of singleton reference.
215  MainForm* MainForm::g_pMainForm = NULL;  MainForm *MainForm::g_pMainForm = nullptr;
216    
217  MainForm::MainForm ( QWidget *pParent )  MainForm::MainForm ( QWidget *pParent )
218          : QMainWindow(pParent)          : QMainWindow(pParent)
# Line 186  MainForm::MainForm ( QWidget *pParent ) Line 223  MainForm::MainForm ( QWidget *pParent )
223          g_pMainForm = this;          g_pMainForm = this;
224    
225          // Initialize some pointer references.          // Initialize some pointer references.
226          m_pOptions = NULL;          m_pOptions = nullptr;
227    
228          // All child forms are to be created later, not earlier than setup.          // All child forms are to be created later, not earlier than setup.
229          m_pMessages = NULL;          m_pMessages = nullptr;
230          m_pInstrumentListForm = NULL;          m_pInstrumentListForm = nullptr;
231          m_pDeviceForm = NULL;          m_pDeviceForm = nullptr;
232    
233          // We'll start clean.          // We'll start clean.
234          m_iUntitled   = 0;          m_iUntitled   = 0;
235          m_iDirtySetup = 0;          m_iDirtySetup = 0;
236          m_iDirtyCount = 0;          m_iDirtyCount = 0;
237    
238          m_pServer = NULL;          m_pServer = nullptr;
239          m_pClient = NULL;          m_pClient = nullptr;
240    
241          m_iStartDelay = 0;          m_iStartDelay = 0;
242          m_iTimerDelay = 0;          m_iTimerDelay = 0;
# Line 214  MainForm::MainForm ( QWidget *pParent ) Line 251  MainForm::MainForm ( QWidget *pParent )
251          // LADISH Level 1 suport.          // LADISH Level 1 suport.
252    
253          // Initialize file descriptors for SIGUSR1 socket notifier.          // Initialize file descriptors for SIGUSR1 socket notifier.
254          ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdUsr1);          ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigusr1);
255          m_pUsr1Notifier          m_pSigusr1Notifier
256                  = new QSocketNotifier(g_fdUsr1[1], QSocketNotifier::Read, this);                  = new QSocketNotifier(g_fdSigusr1[1], QSocketNotifier::Read, this);
257    
258          QObject::connect(m_pUsr1Notifier,          QObject::connect(m_pSigusr1Notifier,
259                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
260                  SLOT(handle_sigusr1()));                  SLOT(handle_sigusr1()));
261    
262          // Install SIGUSR1 signal handler.          // Install SIGUSR1 signal handler.
263      struct sigaction usr1;          struct sigaction sigusr1;
264      usr1.sa_handler = qsampler_sigusr1_handler;          sigusr1.sa_handler = qsampler_sigusr1_handler;
265      sigemptyset(&usr1.sa_mask);          sigemptyset(&sigusr1.sa_mask);
266      usr1.sa_flags = 0;          sigusr1.sa_flags = 0;
267      usr1.sa_flags |= SA_RESTART;          sigusr1.sa_flags |= SA_RESTART;
268      ::sigaction(SIGUSR1, &usr1, NULL);          ::sigaction(SIGUSR1, &sigusr1, nullptr);
269    
270            // Initialize file descriptors for SIGTERM socket notifier.
271            ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigterm);
272            m_pSigtermNotifier
273                    = new QSocketNotifier(g_fdSigterm[1], QSocketNotifier::Read, this);
274    
275            QObject::connect(m_pSigtermNotifier,
276                    SIGNAL(activated(int)),
277                    SLOT(handle_sigterm()));
278    
279            // Install SIGTERM signal handler.
280            struct sigaction sigterm;
281            sigterm.sa_handler = qsampler_sigterm_handler;
282            sigemptyset(&sigterm.sa_mask);
283            sigterm.sa_flags = 0;
284            sigterm.sa_flags |= SA_RESTART;
285            ::sigaction(SIGTERM, &sigterm, nullptr);
286            ::sigaction(SIGQUIT, &sigterm, nullptr);
287    
288            // Ignore SIGHUP/SIGINT signals.
289            ::signal(SIGHUP, SIG_IGN);
290            ::signal(SIGINT, SIG_IGN);
291    
292  #else   // HAVE_SIGNAL_H  #else   // HAVE_SIGNAL_H
293    
294          m_pUsr1Notifier = NULL;          m_pSigusr1Notifier = nullptr;
295            m_pSigtermNotifier = nullptr;
296                    
297  #endif  // !HAVE_SIGNAL_H  #endif  // !HAVE_SIGNAL_H
298    
# Line 270  MainForm::MainForm ( QWidget *pParent ) Line 330  MainForm::MainForm ( QWidget *pParent )
330  #endif  #endif
331    
332          // Make it an MDI workspace.          // Make it an MDI workspace.
333          m_pWorkspace = new QMdiArea(this);          m_pWorkspace = new Workspace(this);
334          m_pWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);          m_pWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
335          m_pWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);          m_pWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
336          // Set the activation connection.          // Set the activation connection.
# Line 305  MainForm::MainForm ( QWidget *pParent ) Line 365  MainForm::MainForm ( QWidget *pParent )
365          m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;          m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;
366          statusBar()->addWidget(pLabel);          statusBar()->addWidget(pLabel);
367    
368  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
369          WSAStartup(MAKEWORD(1, 1), &_wsaData);          WSAStartup(MAKEWORD(1, 1), &_wsaData);
370  #endif  #endif
371    
# Line 406  MainForm::~MainForm() Line 466  MainForm::~MainForm()
466          // Do final processing anyway.          // Do final processing anyway.
467          processServerExit();          processServerExit();
468    
469  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
470          WSACleanup();          WSACleanup();
471  #endif  #endif
472    
473  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
474          if (m_pUsr1Notifier)          if (m_pSigusr1Notifier)
475                  delete m_pUsr1Notifier;                  delete m_pSigusr1Notifier;
476            if (m_pSigtermNotifier)
477                    delete m_pSigtermNotifier;
478  #endif  #endif
479    
480          // Finally drop any widgets around...          // Finally drop any widgets around...
# Line 441  MainForm::~MainForm() Line 503  MainForm::~MainForm()
503  #endif  #endif
504    
505          // Pseudo-singleton reference shut-down.          // Pseudo-singleton reference shut-down.
506          g_pMainForm = NULL;          g_pMainForm = nullptr;
507  }  }
508    
509    
# Line 578  void MainForm::closeEvent ( QCloseEvent Line 640  void MainForm::closeEvent ( QCloseEvent
640  void MainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  void MainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
641  {  {
642          // Accept external drags only...          // Accept external drags only...
643          if (pDragEnterEvent->source() == NULL          if (pDragEnterEvent->source() == nullptr
644                  && pDragEnterEvent->mimeData()->hasUrls()) {                  && pDragEnterEvent->mimeData()->hasUrls()) {
645                  pDragEnterEvent->accept();                  pDragEnterEvent->accept();
646          } else {          } else {
# Line 602  void MainForm::dropEvent ( QDropEvent *p Line 664  void MainForm::dropEvent ( QDropEvent *p
664                          if (QFileInfo(sPath).exists()) {                          if (QFileInfo(sPath).exists()) {
665                                  // Try to create a new channel from instrument file...                                  // Try to create a new channel from instrument file...
666                                  Channel *pChannel = new Channel();                                  Channel *pChannel = new Channel();
667                                  if (pChannel == NULL)                                  if (pChannel == nullptr)
668                                          return;                                          return;
669                                  // Start setting the instrument filename...                                  // Start setting the instrument filename...
670                                  pChannel->setInstrument(sPath, 0);                                  pChannel->setInstrument(sPath, 0);
# Line 695  void MainForm::customEvent ( QEvent* pEv Line 757  void MainForm::customEvent ( QEvent* pEv
757  }  }
758    
759    
760  // Window resize event handler.  // LADISH Level 1 -- SIGUSR1 signal handler.
761  void MainForm::resizeEvent ( QResizeEvent * )  void MainForm::handle_sigusr1 (void)
762  {  {
763          if (m_pOptions->bAutoArrange)  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
764                  channelsArrange();  
765            char c;
766    
767            if (::read(g_fdSigusr1[1], &c, sizeof(c)) > 0)
768                    saveSession(false);
769    
770    #endif
771  }  }
772    
773    
774  // LADISH Level 1 -- SIGUSR1 signal handler.  void MainForm::handle_sigterm (void)
 void MainForm::handle_sigusr1 (void)  
775  {  {
776  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
777    
778          char c;          char c;
779    
780          if (::read(g_fdUsr1[1], &c, sizeof(c)) > 0)          if (::read(g_fdSigterm[1], &c, sizeof(c)) > 0)
781                  saveSession(false);                  close();
782    
783  #endif  #endif
784  }  }
# Line 742  void MainForm::contextMenuEvent( QContex Line 809  void MainForm::contextMenuEvent( QContex
809    
810    
811  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
812  // qsamplerMainForm -- Brainless public property accessors.  // QSampler::MainForm -- Brainless public property accessors.
813    
814  // The global options settings property.  // The global options settings property.
815  Options *MainForm::options (void) const  Options *MainForm::options (void) const
# Line 766  MainForm *MainForm::getInstance (void) Line 833  MainForm *MainForm::getInstance (void)
833    
834    
835  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
836  // qsamplerMainForm -- Session file stuff.  // QSampler::MainForm -- Session file stuff.
837    
838  // Format the displayable session filename.  // Format the displayable session filename.
839  QString MainForm::sessionName ( const QString& sFilename )  QString MainForm::sessionName ( const QString& sFilename )
# Line 795  bool MainForm::newSession (void) Line 862  bool MainForm::newSession (void)
862          m_iUntitled++;          m_iUntitled++;
863    
864          // Stabilize form.          // Stabilize form.
865          m_sFilename = QString::null;          m_sFilename = QString();
866          m_iDirtyCount = 0;          m_iDirtyCount = 0;
867          appendMessages(tr("New session: \"%1\".").arg(sessionName(m_sFilename)));          appendMessages(tr("New session: \"%1\".").arg(sessionName(m_sFilename)));
868          stabilizeForm();          stabilizeForm();
# Line 807  bool MainForm::newSession (void) Line 874  bool MainForm::newSession (void)
874  // Open an existing sampler session.  // Open an existing sampler session.
875  bool MainForm::openSession (void)  bool MainForm::openSession (void)
876  {  {
877          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
878                  return false;                  return false;
879    
880          // Ask for the filename to open...          // Ask for the filename to open...
881          QString sFilename = QFileDialog::getOpenFileName(this,          QString sFilename = QFileDialog::getOpenFileName(this,
882                  QSAMPLER_TITLE ": " + tr("Open Session"), // Caption.                  tr("Open Session"),                       // Caption.
883                  m_pOptions->sSessionDir,                  // Start here.                  m_pOptions->sSessionDir,                  // Start here.
884                  tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)                  tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)
885          );          );
# Line 833  bool MainForm::openSession (void) Line 900  bool MainForm::openSession (void)
900  // Save current sampler session with another name.  // Save current sampler session with another name.
901  bool MainForm::saveSession ( bool bPrompt )  bool MainForm::saveSession ( bool bPrompt )
902  {  {
903          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
904                  return false;                  return false;
905    
906          QString sFilename = m_sFilename;          QString sFilename = m_sFilename;
# Line 845  bool MainForm::saveSession ( bool bPromp Line 912  bool MainForm::saveSession ( bool bPromp
912                          sFilename = m_pOptions->sSessionDir;                          sFilename = m_pOptions->sSessionDir;
913                  // Prompt the guy...                  // Prompt the guy...
914                  sFilename = QFileDialog::getSaveFileName(this,                  sFilename = QFileDialog::getSaveFileName(this,
915                          QSAMPLER_TITLE ": " + tr("Save Session"), // Caption.                          tr("Save Session"),                       // Caption.
916                          sFilename,                                // Start here.                          sFilename,                                // Start here.
917                          tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)                          tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)
918                  );                  );
# Line 855  bool MainForm::saveSession ( bool bPromp Line 922  bool MainForm::saveSession ( bool bPromp
922                  // Enforce .lscp extension...                  // Enforce .lscp extension...
923                  if (QFileInfo(sFilename).suffix().isEmpty())                  if (QFileInfo(sFilename).suffix().isEmpty())
924                          sFilename += ".lscp";                          sFilename += ".lscp";
925            #if 0
926                  // Check if already exists...                  // Check if already exists...
927                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {
928                          if (QMessageBox::warning(this,                          if (QMessageBox::warning(this,
929                                  QSAMPLER_TITLE ": " + tr("Warning"),                                  tr("Warning"),
930                                  tr("The file already exists:\n\n"                                  tr("The file already exists:\n\n"
931                                  "\"%1\"\n\n"                                  "\"%1\"\n\n"
932                                  "Do you want to replace it?")                                  "Do you want to replace it?")
# Line 867  bool MainForm::saveSession ( bool bPromp Line 935  bool MainForm::saveSession ( bool bPromp
935                                  == QMessageBox::No)                                  == QMessageBox::No)
936                                  return false;                                  return false;
937                  }                  }
938            #endif
939          }          }
940    
941          // Save it right away.          // Save it right away.
# Line 882  bool MainForm::closeSession ( bool bForc Line 951  bool MainForm::closeSession ( bool bForc
951          // Are we dirty enough to prompt it?          // Are we dirty enough to prompt it?
952          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
953                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
954                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
955                          tr("The current session has been changed:\n\n"                          tr("The current session has been changed:\n\n"
956                          "\"%1\"\n\n"                          "\"%1\"\n\n"
957                          "Do you want to save the changes?")                          "Do you want to save the changes?")
# Line 907  bool MainForm::closeSession ( bool bForc Line 976  bool MainForm::closeSession ( bool bForc
976                  m_pWorkspace->setUpdatesEnabled(false);                  m_pWorkspace->setUpdatesEnabled(false);
977                  const QList<QMdiSubWindow *>& wlist                  const QList<QMdiSubWindow *>& wlist
978                          = m_pWorkspace->subWindowList();                          = m_pWorkspace->subWindowList();
979                  const int iStripCount = wlist.count();                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
980                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                          ChannelStrip *pChannelStrip
981                          ChannelStrip *pChannelStrip = NULL;                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
982                          if (pChannelStrip) {                          if (pChannelStrip) {
983                                  Channel *pChannel = pChannelStrip->channel();                                  Channel *pChannel = pChannelStrip->channel();
984                                  if (bForce && pChannel)                                  if (bForce && pChannel)
985                                          pChannel->removeChannel();                                          pChannel->removeChannel();
986                                  delete pChannelStrip;                                  delete pChannelStrip;
987                          }                          }
988                          if (pMdiSubWindow)                          delete pMdiSubWindow;
                                 delete pMdiSubWindow;  
989                  }                  }
990                  m_pWorkspace->setUpdatesEnabled(true);                  m_pWorkspace->setUpdatesEnabled(true);
991                  // We're now clean, for sure.                  // We're now clean, for sure.
# Line 934  bool MainForm::closeSession ( bool bForc Line 999  bool MainForm::closeSession ( bool bForc
999  // Load a session from specific file path.  // Load a session from specific file path.
1000  bool MainForm::loadSessionFile ( const QString& sFilename )  bool MainForm::loadSessionFile ( const QString& sFilename )
1001  {  {
1002          if (m_pClient == NULL)          if (m_pClient == nullptr)
1003                  return false;                  return false;
1004    
1005          // Open and read from real file.          // Open and read from real file.
# Line 1010  bool MainForm::loadSessionFile ( const Q Line 1075  bool MainForm::loadSessionFile ( const Q
1075  // Save current session to specific file path.  // Save current session to specific file path.
1076  bool MainForm::saveSessionFile ( const QString& sFilename )  bool MainForm::saveSessionFile ( const QString& sFilename )
1077  {  {
1078          if (m_pClient == NULL)          if (m_pClient == nullptr)
1079                  return false;                  return false;
1080    
1081          // Check whether server is apparently OK...          // Check whether server is apparently OK...
# Line 1035  bool MainForm::saveSessionFile ( const Q Line 1100  bool MainForm::saveSessionFile ( const Q
1100          int iErrors = 0;          int iErrors = 0;
1101          QTextStream ts(&file);          QTextStream ts(&file);
1102          ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;          ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;
1103          ts << "# " << tr("Version")          ts << "# " << tr("Version") << ": " CONFIG_BUILD_VERSION << endl;
1104          << ": " QSAMPLER_VERSION << endl;  //      ts << "# " << tr("Build") << ": " CONFIG_BUILD_DATE << endl;
         ts << "# " << tr("Build")  
         << ": " __DATE__ " " __TIME__ << endl;  
1105          ts << "#"  << endl;          ts << "#"  << endl;
1106          ts << "# " << tr("File")          ts << "# " << tr("File")
1107          << ": " << QFileInfo(sFilename).fileName() << endl;          << ": " << QFileInfo(sFilename).fileName() << endl;
# Line 1051  bool MainForm::saveSessionFile ( const Q Line 1114  bool MainForm::saveSessionFile ( const Q
1114          // It is assumed that this new kind of device+session file          // It is assumed that this new kind of device+session file
1115          // will be loaded from a complete initialized server...          // will be loaded from a complete initialized server...
1116          int *piDeviceIDs;          int *piDeviceIDs;
1117          int  iDevice;          int  i, iDevice;
1118          ts << "RESET" << endl;          ts << "RESET" << endl;
1119    
1120          // Audio device mapping.          // Audio device mapping.
1121          QMap<int, int> audioDeviceMap;          QMap<int, int> audioDeviceMap; iDevice = 0;
1122          piDeviceIDs = Device::getDevices(m_pClient, Device::Audio);          piDeviceIDs = Device::getDevices(m_pClient, Device::Audio);
1123          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
1124                  ts << endl;                  Device device(Device::Audio, piDeviceIDs[i]);
1125                  Device device(Device::Audio, piDeviceIDs[iDevice]);                  // Avoid plug-in driver devices...
1126                    if (device.driverName().toUpper() == "PLUGIN")
1127                            continue;
1128                  // Audio device specification...                  // Audio device specification...
1129                    ts << endl;
1130                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1131                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1132                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();
# Line 1091  bool MainForm::saveSessionFile ( const Q Line 1157  bool MainForm::saveSessionFile ( const Q
1157                          iPort++;                          iPort++;
1158                  }                  }
1159                  // Audio device index/id mapping.                  // Audio device index/id mapping.
1160                  audioDeviceMap[device.deviceID()] = iDevice;                  audioDeviceMap.insert(device.deviceID(), iDevice++);
1161                  // Try to keep it snappy :)                  // Try to keep it snappy :)
1162                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1163          }          }
1164    
1165          // MIDI device mapping.          // MIDI device mapping.
1166          QMap<int, int> midiDeviceMap;          QMap<int, int> midiDeviceMap; iDevice = 0;
1167          piDeviceIDs = Device::getDevices(m_pClient, Device::Midi);          piDeviceIDs = Device::getDevices(m_pClient, Device::Midi);
1168          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
1169                  ts << endl;                  Device device(Device::Midi, piDeviceIDs[i]);
1170                  Device device(Device::Midi, piDeviceIDs[iDevice]);                  // Avoid plug-in driver devices...
1171                    if (device.driverName().toUpper() == "PLUGIN")
1172                            continue;
1173                  // MIDI device specification...                  // MIDI device specification...
1174                    ts << endl;
1175                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1176                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1177                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();
# Line 1133  bool MainForm::saveSessionFile ( const Q Line 1202  bool MainForm::saveSessionFile ( const Q
1202                          iPort++;                          iPort++;
1203                  }                  }
1204                  // MIDI device index/id mapping.                  // MIDI device index/id mapping.
1205                  midiDeviceMap[device.deviceID()] = iDevice;                  midiDeviceMap.insert(device.deviceID(), iDevice++);
1206                  // Try to keep it snappy :)                  // Try to keep it snappy :)
1207                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1208          }          }
# Line 1196  bool MainForm::saveSessionFile ( const Q Line 1265  bool MainForm::saveSessionFile ( const Q
1265                  }                  }
1266                  ts << endl;                  ts << endl;
1267                  // Check for errors...                  // Check for errors...
1268                  if (pInstrs == NULL && ::lscp_client_get_errno(m_pClient)) {                  if (pInstrs == nullptr && ::lscp_client_get_errno(m_pClient)) {
1269                          appendMessagesClient("lscp_list_midi_instruments");                          appendMessagesClient("lscp_list_midi_instruments");
1270                          iErrors++;                          iErrors++;
1271                  }                  }
1272                  // MIDI strument index/id mapping.                  // MIDI strument index/id mapping.
1273                  midiInstrumentMap[iMidiMap] = iMap;                  midiInstrumentMap.insert(iMidiMap, iMap);
1274          }          }
1275          // Check for errors...          // Check for errors...
1276          if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) {          if (piMaps == nullptr && ::lscp_client_get_errno(m_pClient)) {
1277                  appendMessagesClient("lscp_list_midi_instrument_maps");                  appendMessagesClient("lscp_list_midi_instrument_maps");
1278                  iErrors++;                  iErrors++;
1279          }          }
1280  #endif  // CONFIG_MIDI_INSTRUMENT  #endif  // CONFIG_MIDI_INSTRUMENT
1281    
1282          // Sampler channel mapping.          // Sampler channel mapping...
1283            int iChannelID = 0;
1284          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1285                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1286          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1287          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1288                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1289                  if (pChannelStrip) {                  if (pChannelStrip) {
1290                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
1291                          if (pChannel) {                          if (pChannel) {
1292                                  const int iChannelID = pChannel->channelID();                                  // Avoid "artifial" plug-in devices...
1293                                    const int iAudioDevice = pChannel->audioDevice();
1294                                    if (!audioDeviceMap.contains(iAudioDevice))
1295                                            continue;
1296                                    const int iMidiDevice = pChannel->midiDevice();
1297                                    if (!midiDeviceMap.contains(iMidiDevice))
1298                                            continue;
1299                                    // Go for regular, canonical devices...
1300                                  ts << "# " << tr("Channel") << " " << iChannelID << endl;                                  ts << "# " << tr("Channel") << " " << iChannelID << endl;
1301                                  ts << "ADD CHANNEL" << endl;                                  ts << "ADD CHANNEL" << endl;
1302                                  if (audioDeviceMap.isEmpty()) {                                  if (audioDeviceMap.isEmpty()) {
# Line 1230  bool MainForm::saveSessionFile ( const Q Line 1304  bool MainForm::saveSessionFile ( const Q
1304                                                  << " " << pChannel->audioDriver() << endl;                                                  << " " << pChannel->audioDriver() << endl;
1305                                  } else {                                  } else {
1306                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannelID                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannelID
1307                                                  << " " << audioDeviceMap[pChannel->audioDevice()] << endl;                                                  << " " << audioDeviceMap.value(iAudioDevice) << endl;
1308                                  }                                  }
1309                                  if (midiDeviceMap.isEmpty()) {                                  if (midiDeviceMap.isEmpty()) {
1310                                          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID                                          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID
1311                                                  << " " << pChannel->midiDriver() << endl;                                                  << " " << pChannel->midiDriver() << endl;
1312                                  } else {                                  } else {
1313                                          ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannelID                                          ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannelID
1314                                                  << " " << midiDeviceMap[pChannel->midiDevice()] << endl;                                                  << " " << midiDeviceMap.value(iMidiDevice) << endl;
1315                                  }                                  }
1316                                  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID                                  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID
1317                                          << " " << pChannel->midiPort() << endl;                                          << " " << pChannel->midiPort() << endl;
# Line 1268  bool MainForm::saveSessionFile ( const Q Line 1342  bool MainForm::saveSessionFile ( const Q
1342                                  if (pChannel->channelSolo())                                  if (pChannel->channelSolo())
1343                                          ts << "SET CHANNEL SOLO " << iChannelID << " 1" << endl;                                          ts << "SET CHANNEL SOLO " << iChannelID << " 1" << endl;
1344                          #ifdef CONFIG_MIDI_INSTRUMENT                          #ifdef CONFIG_MIDI_INSTRUMENT
1345                                  if (pChannel->midiMap() >= 0) {                                  const int iMidiMap = pChannel->midiMap();
1346                                    if (midiInstrumentMap.contains(iMidiMap)) {
1347                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannelID                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannelID
1348                                                  << " " << midiInstrumentMap[pChannel->midiMap()] << endl;                                                  << " " << midiInstrumentMap.value(iMidiMap) << endl;
1349                                  }                                  }
1350                          #endif                          #endif
1351                          #ifdef CONFIG_FXSEND                          #ifdef CONFIG_FXSEND
# Line 1309  bool MainForm::saveSessionFile ( const Q Line 1384  bool MainForm::saveSessionFile ( const Q
1384                                  }                                  }
1385                          #endif                          #endif
1386                                  ts << endl;                                  ts << endl;
1387                                    // Go for next channel...
1388                                    ++iChannelID;
1389                          }                          }
1390                  }                  }
1391                  // Try to keep it snappy :)                  // Try to keep it snappy :)
# Line 1360  void MainForm::sessionDirty (void) Line 1437  void MainForm::sessionDirty (void)
1437    
1438    
1439  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1440  // qsamplerMainForm -- File Action slots.  // QSampler::MainForm -- File Action slots.
1441    
1442  // Create a new sampler session.  // Create a new sampler session.
1443  void MainForm::fileNew (void)  void MainForm::fileNew (void)
# Line 1414  void MainForm::fileSaveAs (void) Line 1491  void MainForm::fileSaveAs (void)
1491  // Reset the sampler instance.  // Reset the sampler instance.
1492  void MainForm::fileReset (void)  void MainForm::fileReset (void)
1493  {  {
1494          if (m_pClient == NULL)          if (m_pClient == nullptr)
1495                  return;                  return;
1496    
1497          // Ask user whether he/she want's an internal sampler reset...          // Ask user whether he/she want's an internal sampler reset...
1498          if (m_pOptions && m_pOptions->bConfirmReset) {          if (m_pOptions && m_pOptions->bConfirmReset) {
1499                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");                  const QString& sTitle = tr("Warning");
1500                  const QString& sText = tr(                  const QString& sText = tr(
1501                          "Resetting the sampler instance will close\n"                          "Resetting the sampler instance will close\n"
1502                          "all device and channel configurations.\n\n"                          "all device and channel configurations.\n\n"
# Line 1470  void MainForm::fileReset (void) Line 1547  void MainForm::fileReset (void)
1547  // Restart the client/server instance.  // Restart the client/server instance.
1548  void MainForm::fileRestart (void)  void MainForm::fileRestart (void)
1549  {  {
1550          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1551                  return;                  return;
1552    
1553          bool bRestart = true;          bool bRestart = true;
# Line 1478  void MainForm::fileRestart (void) Line 1555  void MainForm::fileRestart (void)
1555          // Ask user whether he/she want's a complete restart...          // Ask user whether he/she want's a complete restart...
1556          // (if we're currently up and running)          // (if we're currently up and running)
1557          if (m_pOptions && m_pOptions->bConfirmRestart) {          if (m_pOptions && m_pOptions->bConfirmRestart) {
1558                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");                  const QString& sTitle = tr("Warning");
1559                  const QString& sText = tr(                  const QString& sText = tr(
1560                          "New settings will be effective after\n"                          "New settings will be effective after\n"
1561                          "restarting the client/server connection.\n\n"                          "restarting the client/server connection.\n\n"
# Line 1526  void MainForm::fileExit (void) Line 1603  void MainForm::fileExit (void)
1603    
1604    
1605  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1606  // qsamplerMainForm -- Edit Action slots.  // QSampler::MainForm -- Edit Action slots.
1607    
1608  // Add a new sampler channel.  // Add a new sampler channel.
1609  void MainForm::editAddChannel (void)  void MainForm::editAddChannel (void)
# Line 1538  void MainForm::editAddChannel (void) Line 1615  void MainForm::editAddChannel (void)
1615    
1616  void MainForm::addChannelStrip (void)  void MainForm::addChannelStrip (void)
1617  {  {
1618          if (m_pClient == NULL)          if (m_pClient == nullptr)
1619                  return;                  return;
1620    
1621          // Just create the channel instance...          // Just create the channel instance...
1622          Channel *pChannel = new Channel();          Channel *pChannel = new Channel();
1623          if (pChannel == NULL)          if (pChannel == nullptr)
1624                  return;                  return;
1625    
1626          // Before we show it up, may be we'll          // Before we show it up, may be we'll
# Line 1561  void MainForm::addChannelStrip (void) Line 1638  void MainForm::addChannelStrip (void)
1638          }          }
1639    
1640          // Do we auto-arrange?          // Do we auto-arrange?
1641          if (m_pOptions && m_pOptions->bAutoArrange)          channelsArrangeAuto();
                 channelsArrange();  
1642    
1643          // Make that an overall update.          // Make that an overall update.
1644          m_iDirtyCount++;          m_iDirtyCount++;
# Line 1580  void MainForm::editRemoveChannel (void) Line 1656  void MainForm::editRemoveChannel (void)
1656    
1657  void MainForm::removeChannelStrip (void)  void MainForm::removeChannelStrip (void)
1658  {  {
1659          if (m_pClient == NULL)          if (m_pClient == nullptr)
1660                  return;                  return;
1661    
1662          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1663          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1664                  return;                  return;
1665    
1666          Channel *pChannel = pChannelStrip->channel();          Channel *pChannel = pChannelStrip->channel();
1667          if (pChannel == NULL)          if (pChannel == nullptr)
1668                  return;                  return;
1669    
1670          // Prompt user if he/she's sure about this...          // Prompt user if he/she's sure about this...
1671          if (m_pOptions && m_pOptions->bConfirmRemove) {          if (m_pOptions && m_pOptions->bConfirmRemove) {
1672                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Warning");                  const QString& sTitle = tr("Warning");
1673                  const QString& sText = tr(                  const QString& sText = tr(
1674                          "About to remove channel:\n\n"                          "About to remove channel:\n\n"
1675                          "%1\n\n"                          "%1\n\n"
# Line 1636  void MainForm::removeChannelStrip (void) Line 1712  void MainForm::removeChannelStrip (void)
1712  // Setup current sampler channel.  // Setup current sampler channel.
1713  void MainForm::editSetupChannel (void)  void MainForm::editSetupChannel (void)
1714  {  {
1715          if (m_pClient == NULL)          if (m_pClient == nullptr)
1716                  return;                  return;
1717    
1718          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1719          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1720                  return;                  return;
1721    
1722          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1651  void MainForm::editSetupChannel (void) Line 1727  void MainForm::editSetupChannel (void)
1727  // Edit current sampler channel.  // Edit current sampler channel.
1728  void MainForm::editEditChannel (void)  void MainForm::editEditChannel (void)
1729  {  {
1730          if (m_pClient == NULL)          if (m_pClient == nullptr)
1731                  return;                  return;
1732    
1733          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1734          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1735                  return;                  return;
1736    
1737          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1666  void MainForm::editEditChannel (void) Line 1742  void MainForm::editEditChannel (void)
1742  // Reset current sampler channel.  // Reset current sampler channel.
1743  void MainForm::editResetChannel (void)  void MainForm::editResetChannel (void)
1744  {  {
1745          if (m_pClient == NULL)          if (m_pClient == nullptr)
1746                  return;                  return;
1747    
1748          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1749          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1750                  return;                  return;
1751    
1752          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1681  void MainForm::editResetChannel (void) Line 1757  void MainForm::editResetChannel (void)
1757  // Reset all sampler channels.  // Reset all sampler channels.
1758  void MainForm::editResetAllChannels (void)  void MainForm::editResetAllChannels (void)
1759  {  {
1760          if (m_pClient == NULL)          if (m_pClient == nullptr)
1761                  return;                  return;
1762    
1763          // Invoque the channel strip procedure,          // Invoque the channel strip procedure,
# Line 1689  void MainForm::editResetAllChannels (voi Line 1765  void MainForm::editResetAllChannels (voi
1765          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
1766          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
1767                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
1768          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1769          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
1770                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1771                  if (pChannelStrip)                  if (pChannelStrip)
1772                          pChannelStrip->channelReset();                          pChannelStrip->channelReset();
1773          }          }
# Line 1703  void MainForm::editResetAllChannels (voi Line 1776  void MainForm::editResetAllChannels (voi
1776    
1777    
1778  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1779  // qsamplerMainForm -- View Action slots.  // QSampler::MainForm -- View Action slots.
1780    
1781  // Show/hide the main program window menubar.  // Show/hide the main program window menubar.
1782  void MainForm::viewMenubar ( bool bOn )  void MainForm::viewMenubar ( bool bOn )
# Line 1753  void MainForm::viewMessages ( bool bOn ) Line 1826  void MainForm::viewMessages ( bool bOn )
1826  // Show/hide the MIDI instrument list-view form.  // Show/hide the MIDI instrument list-view form.
1827  void MainForm::viewInstruments (void)  void MainForm::viewInstruments (void)
1828  {  {
1829          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1830                  return;                  return;
1831    
1832          if (m_pInstrumentListForm) {          if (m_pInstrumentListForm) {
# Line 1772  void MainForm::viewInstruments (void) Line 1845  void MainForm::viewInstruments (void)
1845  // Show/hide the device configurator form.  // Show/hide the device configurator form.
1846  void MainForm::viewDevices (void)  void MainForm::viewDevices (void)
1847  {  {
1848          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1849                  return;                  return;
1850    
1851          if (m_pDeviceForm) {          if (m_pDeviceForm) {
# Line 1791  void MainForm::viewDevices (void) Line 1864  void MainForm::viewDevices (void)
1864  // Show options dialog.  // Show options dialog.
1865  void MainForm::viewOptions (void)  void MainForm::viewOptions (void)
1866  {  {
1867          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1868                  return;                  return;
1869    
1870          OptionsForm* pOptionsForm = new OptionsForm(this);          OptionsForm* pOptionsForm = new OptionsForm(this);
# Line 1803  void MainForm::viewOptions (void) Line 1876  void MainForm::viewOptions (void)
1876                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1877                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1878                  // To track down deferred or immediate changes.                  // To track down deferred or immediate changes.
1879                  const QString sOldServerHost      = m_pOptions->sServerHost;                  const QString sOldServerHost       = m_pOptions->sServerHost;
1880                  const int     iOldServerPort      = m_pOptions->iServerPort;                  const int     iOldServerPort       = m_pOptions->iServerPort;
1881                  const int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  const int     iOldServerTimeout    = m_pOptions->iServerTimeout;
1882                  const bool    bOldServerStart     = m_pOptions->bServerStart;                  const bool    bOldServerStart      = m_pOptions->bServerStart;
1883                  const QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  const QString sOldServerCmdLine    = m_pOptions->sServerCmdLine;
1884                  const bool    bOldMessagesLog     = m_pOptions->bMessagesLog;                  const bool    bOldMessagesLog      = m_pOptions->bMessagesLog;
1885                  const QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;                  const QString sOldMessagesLogPath  = m_pOptions->sMessagesLogPath;
1886                  const QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  const QString sOldDisplayFont      = m_pOptions->sDisplayFont;
1887                  const bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  const bool    bOldDisplayEffect    = m_pOptions->bDisplayEffect;
1888                  const int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  const int     iOldMaxVolume        = m_pOptions->iMaxVolume;
1889                  const QString sOldMessagesFont    = m_pOptions->sMessagesFont;                  const QString sOldMessagesFont     = m_pOptions->sMessagesFont;
1890                  const bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;                  const bool    bOldKeepOnTop        = m_pOptions->bKeepOnTop;
1891                  const bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;                  const bool    bOldStdoutCapture    = m_pOptions->bStdoutCapture;
1892                  const int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;                  const int     bOldMessagesLimit    = m_pOptions->bMessagesLimit;
1893                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1894                  const bool    bOldCompletePath    = m_pOptions->bCompletePath;                  const bool    bOldCompletePath     = m_pOptions->bCompletePath;
1895                  const bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  const bool    bOldInstrumentNames  = m_pOptions->bInstrumentNames;
1896                  const int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  const int     iOldMaxRecentFiles   = m_pOptions->iMaxRecentFiles;
1897                  const int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;                  const int     iOldBaseFontSize     = m_pOptions->iBaseFontSize;
1898                    const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme;
1899                    const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme;
1900                  // Load the current setup settings.                  // Load the current setup settings.
1901                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1902                  // Show the setup dialog...                  // Show the setup dialog...
1903                  if (pOptionsForm->exec()) {                  if (pOptionsForm->exec()) {
1904                          // Warn if something will be only effective on next run.                          // Warn if something will be only effective on next run.
1905                            int iNeedRestart = 0;
1906                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1907                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {
1908                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  updateMessagesCapture();
1909                                    ++iNeedRestart;
1910                            }
1911                            if (( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1912                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1913                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1914                                  QMessageBox::information(this,                                  ++iNeedRestart;
1915                                          QSAMPLER_TITLE ": " + tr("Information"),                          }
1916                                          tr("Some settings may be only effective\n"                          // Check whether restart is needed or whether
1917                                          "next time you start this program."));                          // custom options maybe set up immediately...
1918                                  updateMessagesCapture();                          if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) {
1919                                    if (m_pOptions->sCustomStyleTheme.isEmpty()) {
1920                                            ++iNeedRestart;
1921                                    } else {
1922                                            QApplication::setStyle(
1923                                                    QStyleFactory::create(m_pOptions->sCustomStyleTheme));
1924                                    }
1925                            }
1926                            if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) {
1927                                    if (m_pOptions->sCustomColorTheme.isEmpty()) {
1928                                            ++iNeedRestart;
1929                                    } else {
1930                                            QPalette pal;
1931                                            if (PaletteForm::namedPalette(
1932                                                            &m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal))
1933                                                    QApplication::setPalette(pal);
1934                                    }
1935                          }                          }
1936                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1937                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
# Line 1864  void MainForm::viewOptions (void) Line 1959  void MainForm::viewOptions (void)
1959                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||
1960                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))
1961                                  updateMessagesLimit();                                  updateMessagesLimit();
1962                            // Show restart needed message...
1963                            if (iNeedRestart > 0) {
1964                                    QMessageBox::information(this,
1965                                            tr("Information"),
1966                                            tr("Some settings may be only effective\n"
1967                                            "next time you start this program."));
1968                            }
1969                          // And now the main thing, whether we'll do client/server recycling?                          // And now the main thing, whether we'll do client/server recycling?
1970                          if ((sOldServerHost != m_pOptions->sServerHost) ||                          if ((sOldServerHost != m_pOptions->sServerHost) ||
1971                                  (iOldServerPort != m_pOptions->iServerPort) ||                                  (iOldServerPort != m_pOptions->iServerPort) ||
# Line 1884  void MainForm::viewOptions (void) Line 1986  void MainForm::viewOptions (void)
1986    
1987    
1988  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1989  // qsamplerMainForm -- Channels action slots.  // QSampler::MainForm -- Channels action slots.
1990    
1991  // Arrange channel strips.  // Arrange channel strips.
1992  void MainForm::channelsArrange (void)  void MainForm::channelsArrange (void)
# Line 1897  void MainForm::channelsArrange (void) Line 1999  void MainForm::channelsArrange (void)
1999    
2000          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2001          int y = 0;          int y = 0;
2002          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2003          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  pMdiSubWindow->adjustSize();
2004                  QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                  const QRect& frameRect
2005                  if (pMdiSubWindow) {                          = pMdiSubWindow->frameGeometry();
2006                          pMdiSubWindow->adjustSize();                  int w = m_pWorkspace->width();
2007                          int iWidth = m_pWorkspace->width();                  if (w < frameRect.width())
2008                          if (iWidth < pMdiSubWindow->width())                          w = frameRect.width();
2009                                  iWidth = pMdiSubWindow->width();                  const int h = frameRect.height();
2010                          const int iHeight = pMdiSubWindow->frameGeometry().height();                  pMdiSubWindow->setGeometry(0, y, w, h);
2011                          pMdiSubWindow->setGeometry(0, y, iWidth, iHeight);                  y += h;
                         y += iHeight;  
                 }  
2012          }          }
2013          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
2014    
# Line 1919  void MainForm::channelsArrange (void) Line 2019  void MainForm::channelsArrange (void)
2019  // Auto-arrange channel strips.  // Auto-arrange channel strips.
2020  void MainForm::channelsAutoArrange ( bool bOn )  void MainForm::channelsAutoArrange ( bool bOn )
2021  {  {
2022          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2023                  return;                  return;
2024    
2025          // Toggle the auto-arrange flag.          // Toggle the auto-arrange flag.
2026          m_pOptions->bAutoArrange = bOn;          m_pOptions->bAutoArrange = bOn;
2027    
2028          // If on, update whole workspace...          // If on, update whole workspace...
2029          if (m_pOptions->bAutoArrange)          channelsArrangeAuto();
2030    }
2031    
2032    
2033    void MainForm::channelsArrangeAuto (void)
2034    {
2035            if (m_pOptions && m_pOptions->bAutoArrange)
2036                  channelsArrange();                  channelsArrange();
2037  }  }
2038    
2039    
2040  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2041  // qsamplerMainForm -- Help Action slots.  // QSampler::MainForm -- Help Action slots.
2042    
2043  // Show information about the Qt toolkit.  // Show information about the Qt toolkit.
2044  void MainForm::helpAboutQt (void)  void MainForm::helpAboutQt (void)
# Line 1944  void MainForm::helpAboutQt (void) Line 2050  void MainForm::helpAboutQt (void)
2050  // Show information about application program.  // Show information about application program.
2051  void MainForm::helpAbout (void)  void MainForm::helpAbout (void)
2052  {  {
2053          // Stuff the about box text...          QStringList list;
         QString sText = "<p>\n";  
         sText += "<b>" QSAMPLER_TITLE " - " + tr(QSAMPLER_SUBTITLE) + "</b><br />\n";  
         sText += "<br />\n";  
         sText += tr("Version") + ": <b>" QSAMPLER_VERSION "</b><br />\n";  
         sText += "<small>" + tr("Build") + ": " __DATE__ " " __TIME__ "</small><br />\n";  
2054  #ifdef CONFIG_DEBUG  #ifdef CONFIG_DEBUG
2055          sText += "<small><font color=\"red\">";          list << tr("Debugging option enabled.");
         sText += tr("Debugging option enabled.");  
         sText += "</font></small><br />";  
2056  #endif  #endif
2057  #ifndef CONFIG_LIBGIG  #ifndef CONFIG_LIBGIG
2058          sText += "<small><font color=\"red\">";          list << tr("GIG (libgig) file support disabled.");
         sText += tr("GIG (libgig) file support disabled.");  
         sText += "</font></small><br />";  
2059  #endif  #endif
2060  #ifndef CONFIG_INSTRUMENT_NAME  #ifndef CONFIG_INSTRUMENT_NAME
2061          sText += "<small><font color=\"red\">";          list << tr("LSCP (liblscp) instrument_name support disabled.");
         sText += tr("LSCP (liblscp) instrument_name support disabled.");  
         sText += "</font></small><br />";  
2062  #endif  #endif
2063  #ifndef CONFIG_MUTE_SOLO  #ifndef CONFIG_MUTE_SOLO
2064          sText += "<small><font color=\"red\">";          list << tr("Sampler channel Mute/Solo support disabled.");
         sText += tr("Sampler channel Mute/Solo support disabled.");  
         sText += "</font></small><br />";  
2065  #endif  #endif
2066  #ifndef CONFIG_AUDIO_ROUTING  #ifndef CONFIG_AUDIO_ROUTING
2067          sText += "<small><font color=\"red\">";          list << tr("LSCP (liblscp) audio_routing support disabled.");
         sText += tr("LSCP (liblscp) audio_routing support disabled.");  
         sText += "</font></small><br />";  
2068  #endif  #endif
2069  #ifndef CONFIG_FXSEND  #ifndef CONFIG_FXSEND
2070          sText += "<small><font color=\"red\">";          list << tr("Sampler channel Effect Sends support disabled.");
         sText += tr("Sampler channel Effect Sends support disabled.");  
         sText += "</font></small><br />";  
2071  #endif  #endif
2072  #ifndef CONFIG_VOLUME  #ifndef CONFIG_VOLUME
2073          sText += "<small><font color=\"red\">";          list << tr("Global volume support disabled.");
         sText += tr("Global volume support disabled.");  
         sText += "</font></small><br />";  
2074  #endif  #endif
2075  #ifndef CONFIG_MIDI_INSTRUMENT  #ifndef CONFIG_MIDI_INSTRUMENT
2076          sText += "<small><font color=\"red\">";          list << tr("MIDI instrument mapping support disabled.");
         sText += tr("MIDI instrument mapping support disabled.");  
         sText += "</font></small><br />";  
2077  #endif  #endif
2078  #ifndef CONFIG_EDIT_INSTRUMENT  #ifndef CONFIG_EDIT_INSTRUMENT
2079          sText += "<small><font color=\"red\">";          list << tr("Instrument editing support disabled.");
         sText += tr("Instrument editing support disabled.");  
         sText += "</font></small><br />";  
2080  #endif  #endif
2081  #ifndef CONFIG_EVENT_CHANNEL_MIDI  #ifndef CONFIG_EVENT_CHANNEL_MIDI
2082          sText += "<small><font color=\"red\">";          list << tr("Channel MIDI event support disabled.");
         sText += tr("Channel MIDI event support disabled.");  
         sText += "</font></small><br />";  
2083  #endif  #endif
2084  #ifndef CONFIG_EVENT_DEVICE_MIDI  #ifndef CONFIG_EVENT_DEVICE_MIDI
2085          sText += "<small><font color=\"red\">";          list << tr("Device MIDI event support disabled.");
         sText += tr("Device MIDI event support disabled.");  
         sText += "</font></small><br />";  
2086  #endif  #endif
2087  #ifndef CONFIG_MAX_VOICES  #ifndef CONFIG_MAX_VOICES
2088          sText += "<small><font color=\"red\">";          list << tr("Runtime max. voices / disk streams support disabled.");
         sText += tr("Runtime max. voices / disk streams support disabled.");  
         sText += "</font></small><br />";  
2089  #endif  #endif
2090    
2091            // Stuff the about box text...
2092            QString sText = "<p>\n";
2093            sText += "<b>" QSAMPLER_TITLE " - " + tr(QSAMPLER_SUBTITLE) + "</b><br />\n";
2094            sText += "<br />\n";
2095            sText += tr("Version") + ": <b>" CONFIG_BUILD_VERSION "</b><br />\n";
2096    //      sText += "<small>" + tr("Build") + ": " CONFIG_BUILD_DATE "</small><br />\n";
2097            if (!list.isEmpty()) {
2098                    sText += "<small><font color=\"red\">";
2099                    sText += list.join("<br />\n");
2100                    sText += "</font></small>";
2101            }
2102          sText += "<br />\n";          sText += "<br />\n";
2103          sText += tr("Using") + ": ";          sText += tr("Using") + ": ";
2104          sText += ::lscp_client_package();          sText += ::lscp_client_package();
# Line 2034  void MainForm::helpAbout (void) Line 2123  void MainForm::helpAbout (void)
2123          sText += "</small>";          sText += "</small>";
2124          sText += "</p>\n";          sText += "</p>\n";
2125    
2126          QMessageBox::about(this, tr("About") + " " QSAMPLER_TITLE, sText);          QMessageBox::about(this, tr("About"), sText);
2127  }  }
2128    
2129    
2130  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2131  // qsamplerMainForm -- Main window stabilization.  // QSampler::MainForm -- Main window stabilization.
2132    
2133  void MainForm::stabilizeForm (void)  void MainForm::stabilizeForm (void)
2134  {  {
# Line 2047  void MainForm::stabilizeForm (void) Line 2136  void MainForm::stabilizeForm (void)
2136          QString sSessionName = sessionName(m_sFilename);          QString sSessionName = sessionName(m_sFilename);
2137          if (m_iDirtyCount > 0)          if (m_iDirtyCount > 0)
2138                  sSessionName += " *";                  sSessionName += " *";
2139          setWindowTitle(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));          setWindowTitle(sSessionName);
2140    
2141          // Update the main menu state...          // Update the main menu state...
2142          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
2143          const QList<QMdiSubWindow *>& wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist = m_pWorkspace->subWindowList();
2144          const bool bHasClient = (m_pOptions != NULL && m_pClient != NULL);          const bool bHasClient = (m_pOptions != nullptr && m_pClient != nullptr);
2145          const bool bHasChannel = (bHasClient && pChannelStrip != NULL);          const bool bHasChannel = (bHasClient && pChannelStrip != nullptr);
2146          const bool bHasChannels = (bHasClient && wlist.count() > 0);          const bool bHasChannels = (bHasClient && wlist.count() > 0);
2147          m_ui.fileNewAction->setEnabled(bHasClient);          m_ui.fileNewAction->setEnabled(bHasClient);
2148          m_ui.fileOpenAction->setEnabled(bHasClient);          m_ui.fileOpenAction->setEnabled(bHasClient);
2149          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);
2150          m_ui.fileSaveAsAction->setEnabled(bHasClient);          m_ui.fileSaveAsAction->setEnabled(bHasClient);
2151          m_ui.fileResetAction->setEnabled(bHasClient);          m_ui.fileResetAction->setEnabled(bHasClient);
2152          m_ui.fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);          m_ui.fileRestartAction->setEnabled(bHasClient || m_pServer == nullptr);
2153          m_ui.editAddChannelAction->setEnabled(bHasClient);          m_ui.editAddChannelAction->setEnabled(bHasClient);
2154          m_ui.editRemoveChannelAction->setEnabled(bHasChannel);          m_ui.editRemoveChannelAction->setEnabled(bHasChannel);
2155          m_ui.editSetupChannelAction->setEnabled(bHasChannel);          m_ui.editSetupChannelAction->setEnabled(bHasChannel);
# Line 2191  void MainForm::updateSession (void) Line 2280  void MainForm::updateSession (void)
2280          updateAllChannelStrips(false);          updateAllChannelStrips(false);
2281    
2282          // Do we auto-arrange?          // Do we auto-arrange?
2283          if (m_pOptions && m_pOptions->bAutoArrange)          channelsArrangeAuto();
                 channelsArrange();  
2284    
2285          // Remember to refresh devices and instruments...          // Remember to refresh devices and instruments...
2286          if (m_pInstrumentListForm)          if (m_pInstrumentListForm)
# Line 2210  void MainForm::updateAllChannelStrips ( Line 2298  void MainForm::updateAllChannelStrips (
2298    
2299          // Retrieve the current channel list.          // Retrieve the current channel list.
2300          int *piChannelIDs = ::lscp_list_channels(m_pClient);          int *piChannelIDs = ::lscp_list_channels(m_pClient);
2301          if (piChannelIDs == NULL) {          if (piChannelIDs == nullptr) {
2302                  if (::lscp_client_get_errno(m_pClient)) {                  if (::lscp_client_get_errno(m_pClient)) {
2303                          appendMessagesClient("lscp_list_channels");                          appendMessagesClient("lscp_list_channels");
2304                          appendMessagesError(                          appendMessagesError(
# Line 2225  void MainForm::updateAllChannelStrips ( Line 2313  void MainForm::updateAllChannelStrips (
2313                                  createChannelStrip(new Channel(piChannelIDs[iChannel]));                                  createChannelStrip(new Channel(piChannelIDs[iChannel]));
2314                  }                  }
2315                  // Do we auto-arrange?                  // Do we auto-arrange?
2316                  if (m_pOptions && m_pOptions->bAutoArrange)                  channelsArrangeAuto();
                         channelsArrange();  
2317                  // remove dead channel strips                  // remove dead channel strips
2318                  if (bRemoveDeadStrips) {                  if (bRemoveDeadStrips) {
2319                          const QList<QMdiSubWindow *>& wlist                          const QList<QMdiSubWindow *>& wlist
2320                                  = m_pWorkspace->subWindowList();                                  = m_pWorkspace->subWindowList();
2321                          const int iStripCount = wlist.count();                          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2322                          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                  ChannelStrip *pChannelStrip
2323                                  ChannelStrip *pChannelStrip = NULL;                                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                 if (pMdiSubWindow)  
                                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2324                                  if (pChannelStrip) {                                  if (pChannelStrip) {
2325                                          bool bExists = false;                                          bool bExists = false;
2326                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {
2327                                                  Channel *pChannel = pChannelStrip->channel();                                                  Channel *pChannel = pChannelStrip->channel();
2328                                                  if (pChannel == NULL)                                                  if (pChannel == nullptr)
2329                                                          break;                                                          break;
2330                                                  if (piChannelIDs[iChannel] == pChannel->channelID()) {                                                  if (piChannelIDs[iChannel] == pChannel->channelID()) {
2331                                                          // strip exists, don't touch it                                                          // strip exists, don't touch it
# Line 2264  void MainForm::updateAllChannelStrips ( Line 2348  void MainForm::updateAllChannelStrips (
2348  // Update the recent files list and menu.  // Update the recent files list and menu.
2349  void MainForm::updateRecentFiles ( const QString& sFilename )  void MainForm::updateRecentFiles ( const QString& sFilename )
2350  {  {
2351          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2352                  return;                  return;
2353    
2354          // Remove from list if already there (avoid duplicates)          // Remove from list if already there (avoid duplicates)
# Line 2279  void MainForm::updateRecentFiles ( const Line 2363  void MainForm::updateRecentFiles ( const
2363  // Update the recent files list and menu.  // Update the recent files list and menu.
2364  void MainForm::updateRecentFilesMenu (void)  void MainForm::updateRecentFilesMenu (void)
2365  {  {
2366          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2367                  return;                  return;
2368    
2369          // Time to keep the list under limits.          // Time to keep the list under limits.
# Line 2313  void MainForm::updateInstrumentNames (vo Line 2397  void MainForm::updateInstrumentNames (vo
2397                  return;                  return;
2398    
2399          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2400          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2401          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2402                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2403                  if (pChannelStrip)                  if (pChannelStrip)
2404                          pChannelStrip->updateInstrumentName(true);                          pChannelStrip->updateInstrumentName(true);
2405          }          }
# Line 2329  void MainForm::updateInstrumentNames (vo Line 2410  void MainForm::updateInstrumentNames (vo
2410  // Force update of the channels display font.  // Force update of the channels display font.
2411  void MainForm::updateDisplayFont (void)  void MainForm::updateDisplayFont (void)
2412  {  {
2413          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2414                  return;                  return;
2415    
2416          // Check if display font is legal.          // Check if display font is legal.
# Line 2348  void MainForm::updateDisplayFont (void) Line 2429  void MainForm::updateDisplayFont (void)
2429                  return;                  return;
2430    
2431          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2432          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2433          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2434                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2435                  if (pChannelStrip)                  if (pChannelStrip)
2436                          pChannelStrip->setDisplayFont(font);                          pChannelStrip->setDisplayFont(font);
2437          }          }
# Line 2371  void MainForm::updateDisplayEffect (void Line 2449  void MainForm::updateDisplayEffect (void
2449                  return;                  return;
2450    
2451          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2452          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2453          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2454                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2455                  if (pChannelStrip)                  if (pChannelStrip)
2456                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
2457          }          }
# Line 2387  void MainForm::updateDisplayEffect (void Line 2462  void MainForm::updateDisplayEffect (void
2462  // Force update of the channels maximum volume setting.  // Force update of the channels maximum volume setting.
2463  void MainForm::updateMaxVolume (void)  void MainForm::updateMaxVolume (void)
2464  {  {
2465          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2466                  return;                  return;
2467    
2468  #ifdef CONFIG_VOLUME  #ifdef CONFIG_VOLUME
# Line 2404  void MainForm::updateMaxVolume (void) Line 2479  void MainForm::updateMaxVolume (void)
2479                  return;                  return;
2480    
2481          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2482          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2483          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2484                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2485                  if (pChannelStrip)                  if (pChannelStrip)
2486                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2487          }          }
# Line 2418  void MainForm::updateMaxVolume (void) Line 2490  void MainForm::updateMaxVolume (void)
2490    
2491    
2492  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2493  // qsamplerMainForm -- Messages window form handlers.  // QSampler::MainForm -- Messages window form handlers.
2494    
2495  // Messages output methods.  // Messages output methods.
2496  void MainForm::appendMessages( const QString& s )  void MainForm::appendMessages ( const QString& s )
2497  {  {
2498          if (m_pMessages)          if (m_pMessages)
2499                  m_pMessages->appendMessages(s);                  m_pMessages->appendMessages(s);
# Line 2429  void MainForm::appendMessages( const QSt Line 2501  void MainForm::appendMessages( const QSt
2501          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2502  }  }
2503    
2504  void MainForm::appendMessagesColor( const QString& s, const QString& c )  void MainForm::appendMessagesColor ( const QString& s, const QColor& rgb )
2505  {  {
2506          if (m_pMessages)          if (m_pMessages)
2507                  m_pMessages->appendMessagesColor(s, c);                  m_pMessages->appendMessagesColor(s, rgb);
2508    
2509          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2510  }  }
2511    
2512  void MainForm::appendMessagesText( const QString& s )  void MainForm::appendMessagesText ( const QString& s )
2513  {  {
2514          if (m_pMessages)          if (m_pMessages)
2515                  m_pMessages->appendMessagesText(s);                  m_pMessages->appendMessagesText(s);
2516  }  }
2517    
2518  void MainForm::appendMessagesError( const QString& sText )  void MainForm::appendMessagesError ( const QString& s )
2519  {  {
2520          if (m_pMessages)          if (m_pMessages)
2521                  m_pMessages->show();                  m_pMessages->show();
2522    
2523          appendMessagesColor(sText.simplified(), "#ff0000");          appendMessagesColor(s.simplified(), Qt::red);
2524    
2525          // Make it look responsive...:)          // Make it look responsive...:)
2526          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2527    
2528          if (m_pOptions && m_pOptions->bConfirmError) {          if (m_pOptions && m_pOptions->bConfirmError) {
2529                  const QString& sTitle = QSAMPLER_TITLE ": " + tr("Error");                  const QString& sTitle = tr("Error");
2530          #if 0          #if 0
2531                  QMessageBox::critical(this, sTitle, sText, QMessageBox::Cancel);                  QMessageBox::critical(this, sTitle, sText, QMessageBox::Cancel);
2532          #else          #else
2533                  QMessageBox mbox(this);                  QMessageBox mbox(this);
2534                  mbox.setIcon(QMessageBox::Critical);                  mbox.setIcon(QMessageBox::Critical);
2535                  mbox.setWindowTitle(sTitle);                  mbox.setWindowTitle(sTitle);
2536                  mbox.setText(sText);                  mbox.setText(s);
2537                  mbox.setStandardButtons(QMessageBox::Cancel);                  mbox.setStandardButtons(QMessageBox::Cancel);
2538                  QCheckBox cbox(tr("Don't show this again"));                  QCheckBox cbox(tr("Don't show this again"));
2539                  cbox.setChecked(false);                  cbox.setChecked(false);
# Line 2477  void MainForm::appendMessagesError( cons Line 2549  void MainForm::appendMessagesError( cons
2549  // This is a special message format, just for client results.  // This is a special message format, just for client results.
2550  void MainForm::appendMessagesClient( const QString& s )  void MainForm::appendMessagesClient( const QString& s )
2551  {  {
2552          if (m_pClient == NULL)          if (m_pClient == nullptr)
2553                  return;                  return;
2554    
2555          appendMessagesColor(s + QString(": %1 (errno=%2)")          appendMessagesColor(s + QString(": %1 (errno=%2)")
# Line 2492  void MainForm::appendMessagesClient( con Line 2564  void MainForm::appendMessagesClient( con
2564  // Force update of the messages font.  // Force update of the messages font.
2565  void MainForm::updateMessagesFont (void)  void MainForm::updateMessagesFont (void)
2566  {  {
2567          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2568                  return;                  return;
2569    
2570          if (m_pMessages && !m_pOptions->sMessagesFont.isEmpty()) {          if (m_pMessages && !m_pOptions->sMessagesFont.isEmpty()) {
# Line 2506  void MainForm::updateMessagesFont (void) Line 2578  void MainForm::updateMessagesFont (void)
2578  // Update messages window line limit.  // Update messages window line limit.
2579  void MainForm::updateMessagesLimit (void)  void MainForm::updateMessagesLimit (void)
2580  {  {
2581          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2582                  return;                  return;
2583    
2584          if (m_pMessages) {          if (m_pMessages) {
# Line 2521  void MainForm::updateMessagesLimit (void Line 2593  void MainForm::updateMessagesLimit (void
2593  // Enablement of the messages capture feature.  // Enablement of the messages capture feature.
2594  void MainForm::updateMessagesCapture (void)  void MainForm::updateMessagesCapture (void)
2595  {  {
2596          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2597                  return;                  return;
2598    
2599          if (m_pMessages)          if (m_pMessages)
# Line 2530  void MainForm::updateMessagesCapture (vo Line 2602  void MainForm::updateMessagesCapture (vo
2602    
2603    
2604  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2605  // qsamplerMainForm -- MDI channel strip management.  // QSampler::MainForm -- MDI channel strip management.
2606    
2607  // The channel strip creation executive.  // The channel strip creation executive.
2608  ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel )  ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel )
2609  {  {
2610          if (m_pClient == NULL || pChannel == NULL)          if (m_pClient == nullptr || pChannel == nullptr)
2611                  return NULL;                  return nullptr;
2612    
2613          // Add a new channel itema...          // Add a new channel itema...
2614          ChannelStrip *pChannelStrip = new ChannelStrip();          ChannelStrip *pChannelStrip = new ChannelStrip();
2615          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
2616                  return NULL;                  return nullptr;
2617    
2618          // Set some initial channel strip options...          // Set some initial channel strip options...
2619          if (m_pOptions) {          if (m_pOptions) {
# Line 2557  ChannelStrip *MainForm::createChannelStr Line 2629  ChannelStrip *MainForm::createChannelStr
2629          }          }
2630    
2631          // Add it to workspace...          // Add it to workspace...
2632          m_pWorkspace->addSubWindow(pChannelStrip,          QMdiSubWindow *pMdiSubWindow
2633                  Qt::SubWindow | Qt::FramelessWindowHint);                  = m_pWorkspace->addSubWindow(pChannelStrip,
2634                            Qt::SubWindow | Qt::FramelessWindowHint);
2635            pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose);
2636    
2637          // Actual channel strip setup...          // Actual channel strip setup...
2638          pChannelStrip->setup(pChannel);          pChannelStrip->setup(pChannel);
# Line 2582  void MainForm::destroyChannelStrip ( Cha Line 2656  void MainForm::destroyChannelStrip ( Cha
2656  {  {
2657          QMdiSubWindow *pMdiSubWindow          QMdiSubWindow *pMdiSubWindow
2658                  = static_cast<QMdiSubWindow *> (pChannelStrip->parentWidget());                  = static_cast<QMdiSubWindow *> (pChannelStrip->parentWidget());
2659          if (pMdiSubWindow == NULL)          if (pMdiSubWindow == nullptr)
2660                  return;                  return;
2661    
2662          // Just delete the channel strip.          // Just delete the channel strip.
# Line 2590  void MainForm::destroyChannelStrip ( Cha Line 2664  void MainForm::destroyChannelStrip ( Cha
2664          delete pMdiSubWindow;          delete pMdiSubWindow;
2665    
2666          // Do we auto-arrange?          // Do we auto-arrange?
2667          if (m_pOptions && m_pOptions->bAutoArrange)          channelsArrangeAuto();
                 channelsArrange();  
2668  }  }
2669    
2670    
# Line 2602  ChannelStrip *MainForm::activeChannelStr Line 2675  ChannelStrip *MainForm::activeChannelStr
2675          if (pMdiSubWindow)          if (pMdiSubWindow)
2676                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2677          else          else
2678                  return NULL;                  return nullptr;
2679  }  }
2680    
2681    
2682  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
2683  ChannelStrip *MainForm::channelStripAt ( int iStrip )  ChannelStrip *MainForm::channelStripAt ( int iStrip )
2684  {  {
2685          if (!m_pWorkspace) return NULL;          if (!m_pWorkspace) return nullptr;
2686    
2687          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
2688                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2689          if (wlist.isEmpty())          if (wlist.isEmpty())
2690                  return NULL;                  return nullptr;
2691    
2692          if (iStrip < 0 || iStrip >= wlist.count())          if (iStrip < 0 || iStrip >= wlist.count())
2693                  return NULL;                  return nullptr;
2694    
2695          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);
2696          if (pMdiSubWindow)          if (pMdiSubWindow)
2697                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2698          else          else
2699                  return NULL;                  return nullptr;
2700  }  }
2701    
2702    
# Line 2633  ChannelStrip *MainForm::channelStrip ( i Line 2706  ChannelStrip *MainForm::channelStrip ( i
2706          const QList<QMdiSubWindow *>& wlist          const QList<QMdiSubWindow *>& wlist
2707                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2708          if (wlist.isEmpty())          if (wlist.isEmpty())
2709                  return NULL;                  return nullptr;
2710    
2711          const int iStripCount = wlist.count();          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2712          for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  ChannelStrip *pChannelStrip
2713                  ChannelStrip *pChannelStrip = NULL;                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2714                  if (pChannelStrip) {                  if (pChannelStrip) {
2715                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
2716                          if (pChannel && pChannel->channelID() == iChannelID)                          if (pChannel && pChannel->channelID() == iChannelID)
# Line 2649  ChannelStrip *MainForm::channelStrip ( i Line 2719  ChannelStrip *MainForm::channelStrip ( i
2719          }          }
2720    
2721          // Not found.          // Not found.
2722          return NULL;          return nullptr;
2723  }  }
2724    
2725    
# Line 2664  void MainForm::channelsMenuAboutToShow ( Line 2734  void MainForm::channelsMenuAboutToShow (
2734                  = m_pWorkspace->subWindowList();                  = m_pWorkspace->subWindowList();
2735          if (!wlist.isEmpty()) {          if (!wlist.isEmpty()) {
2736                  m_ui.channelsMenu->addSeparator();                  m_ui.channelsMenu->addSeparator();
2737                  const int iStripCount = wlist.count();                  int iStrip = 0;
2738                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2739                          ChannelStrip *pChannelStrip = NULL;                          ChannelStrip *pChannelStrip
2740                          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         if (pMdiSubWindow)  
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2741                          if (pChannelStrip) {                          if (pChannelStrip) {
2742                                  QAction *pAction = m_ui.channelsMenu->addAction(                                  QAction *pAction = m_ui.channelsMenu->addAction(
2743                                          pChannelStrip->windowTitle(),                                          pChannelStrip->windowTitle(),
# Line 2678  void MainForm::channelsMenuAboutToShow ( Line 2746  void MainForm::channelsMenuAboutToShow (
2746                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);
2747                                  pAction->setData(iStrip);                                  pAction->setData(iStrip);
2748                          }                          }
2749                            ++iStrip;
2750                  }                  }
2751          }          }
2752  }  }
# Line 2688  void MainForm::channelsMenuActivated (vo Line 2757  void MainForm::channelsMenuActivated (vo
2757  {  {
2758          // Retrive channel index from action data...          // Retrive channel index from action data...
2759          QAction *pAction = qobject_cast<QAction *> (sender());          QAction *pAction = qobject_cast<QAction *> (sender());
2760          if (pAction == NULL)          if (pAction == nullptr)
2761                  return;                  return;
2762    
2763          ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt());          ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt());
# Line 2700  void MainForm::channelsMenuActivated (vo Line 2769  void MainForm::channelsMenuActivated (vo
2769    
2770    
2771  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2772  // qsamplerMainForm -- Timer stuff.  // QSampler::MainForm -- Timer stuff.
2773    
2774  // Set the pseudo-timer delay schedule.  // Set the pseudo-timer delay schedule.
2775  void MainForm::startSchedule ( int iStartDelay )  void MainForm::startSchedule ( int iStartDelay )
# Line 2719  void MainForm::stopSchedule (void) Line 2788  void MainForm::stopSchedule (void)
2788  // Timer slot funtion.  // Timer slot funtion.
2789  void MainForm::timerSlot (void)  void MainForm::timerSlot (void)
2790  {  {
2791          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2792                  return;                  return;
2793    
2794          // 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 2754  void MainForm::timerSlot (void) Line 2823  void MainForm::timerSlot (void)
2823                                  // Update the channel stream usage for each strip...                                  // Update the channel stream usage for each strip...
2824                                  const QList<QMdiSubWindow *>& wlist                                  const QList<QMdiSubWindow *>& wlist
2825                                          = m_pWorkspace->subWindowList();                                          = m_pWorkspace->subWindowList();
2826                                  const int iStripCount = wlist.count();                                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2827                                  for (int iStrip = 0; iStrip < iStripCount; ++iStrip) {                                          ChannelStrip *pChannelStrip
2828                                          ChannelStrip *pChannelStrip = NULL;                                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                         QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);  
                                         if (pMdiSubWindow)  
                                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2829                                          if (pChannelStrip && pChannelStrip->isVisible())                                          if (pChannelStrip && pChannelStrip->isVisible())
2830                                                  pChannelStrip->updateChannelUsage();                                                  pChannelStrip->updateChannelUsage();
2831                                  }                                  }
2832                          }                          }
2833                  }                  }
2834    
2835            #if CONFIG_LSCP_CLIENT_CONNECTION_LOST
2836                    // If we lost connection to server: Try to automatically reconnect if we
2837                    // did not start the server.
2838                    //
2839                    // TODO: If we started the server, then we might inform the user that
2840                    // the server probably crashed and asking user ONCE whether we should
2841                    // restart the server.
2842                    if (lscp_client_connection_lost(m_pClient) && !m_pServer)
2843                            startAutoReconnectClient();
2844            #endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST
2845          }          }
2846    
2847          // Register the next timer slot.          // Register the next timer slot.
# Line 2773  void MainForm::timerSlot (void) Line 2850  void MainForm::timerSlot (void)
2850    
2851    
2852  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2853  // qsamplerMainForm -- Server stuff.  // QSampler::MainForm -- Server stuff.
2854    
2855  // Start linuxsampler server...  // Start linuxsampler server...
2856  void MainForm::startServer (void)  void MainForm::startServer (void)
2857  {  {
2858          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2859                  return;                  return;
2860    
2861          // Aren't already a client, are we?          // Aren't already a client, are we?
# Line 2788  void MainForm::startServer (void) Line 2865  void MainForm::startServer (void)
2865          // Is the server process instance still here?          // Is the server process instance still here?
2866          if (m_pServer) {          if (m_pServer) {
2867                  if (QMessageBox::warning(this,                  if (QMessageBox::warning(this,
2868                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
2869                          tr("Could not start the LinuxSampler server.\n\n"                          tr("Could not start the LinuxSampler server.\n\n"
2870                          "Maybe it is already started."),                          "Maybe it is already started."),
2871                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
# Line 2807  void MainForm::startServer (void) Line 2884  void MainForm::startServer (void)
2884    
2885          // OK. Let's build the startup process...          // OK. Let's build the startup process...
2886          m_pServer = new QProcess();          m_pServer = new QProcess();
2887          bForceServerStop = true;          m_bForceServerStop = true;
2888    
2889          // Setup stdout/stderr capture...          // Setup stdout/stderr capture...
2890          m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);          m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);
# Line 2841  void MainForm::startServer (void) Line 2918  void MainForm::startServer (void)
2918    
2919          // Show startup results...          // Show startup results...
2920          appendMessages(          appendMessages(
2921                  tr("Server was started with PID=%1.").arg((long) m_pServer->pid()));                  tr("Server was started with PID=%1.")
2922                    #if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
2923                            .arg(quint64(m_pServer->pid())));
2924                    #else
2925                            .arg(quint64(m_pServer->processId())));
2926                    #endif
2927    
2928          // Reset (yet again) the timer counters,          // Reset (yet again) the timer counters,
2929          // but this time is deferred as the user opted.          // but this time is deferred as the user opted.
# Line 2851  void MainForm::startServer (void) Line 2933  void MainForm::startServer (void)
2933    
2934    
2935  // Stop linuxsampler server...  // Stop linuxsampler server...
2936  void MainForm::stopServer (bool bInteractive)  void MainForm::stopServer ( bool bInteractive )
2937  {  {
2938          // Stop client code.          // Stop client code.
2939          stopClient();          stopClient();
2940    
2941          if (m_pServer && bInteractive) {          if (m_pServer && bInteractive) {
2942                  if (QMessageBox::question(this,                  if (QMessageBox::question(this,
2943                          QSAMPLER_TITLE ": " + tr("The backend's fate ..."),                          tr("The backend's fate ..."),
2944                          tr("You have the option to keep the sampler backend (LinuxSampler)\n"                          tr("You have the option to keep the sampler backend (LinuxSampler)\n"
2945                          "running in the background. The sampler would continue to work\n"                          "running in the background. The sampler would continue to work\n"
2946                          "according to your current sampler session and you could alter the\n"                          "according to your current sampler session and you could alter the\n"
2947                          "sampler session at any time by relaunching QSampler.\n\n"                          "sampler session at any time by relaunching QSampler.\n\n"
2948                          "Do you want LinuxSampler to stop?"),                          "Do you want LinuxSampler to stop?"),
2949                          QMessageBox::Yes | QMessageBox::No,                          QMessageBox::Yes | QMessageBox::No,
2950                          QMessageBox::Yes) == QMessageBox::No)                          QMessageBox::Yes) == QMessageBox::No) {
2951                  {                          m_bForceServerStop = false;
                         bForceServerStop = false;  
2952                  }                  }
2953          }          }
2954    
2955            bool bGraceWait = true;
2956    
2957          // And try to stop server.          // And try to stop server.
2958          if (m_pServer && bForceServerStop) {          if (m_pServer && m_bForceServerStop) {
2959                  appendMessages(tr("Server is stopping..."));                  appendMessages(tr("Server is stopping..."));
2960                  if (m_pServer->state() == QProcess::Running) {                  if (m_pServer->state() == QProcess::Running) {
2961                  #if defined(WIN32)                  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
2962                          // Try harder...                          // Try harder...
2963                          m_pServer->kill();                          m_pServer->kill();
2964                  #else                  #else
2965                          // Try softly...                          // Try softly...
2966                          m_pServer->terminate();                          m_pServer->terminate();
2967                            bool bFinished = m_pServer->waitForFinished(QSAMPLER_TIMER_MSECS * 1000);
2968                            if (bFinished) bGraceWait = false;
2969                  #endif                  #endif
2970                  }                  }
2971          }       // Do final processing anyway.          }       // Do final processing anyway.
2972          else processServerExit();          else processServerExit();
2973    
2974          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2975          QTime t;          if (bGraceWait) {
2976          t.start();                  QElapsedTimer timer;
2977          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                  timer.start();
2978                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
2979                            QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2980            }
2981  }  }
2982    
2983    
# Line 2912  void MainForm::processServerExit (void) Line 2999  void MainForm::processServerExit (void)
2999          if (m_pMessages)          if (m_pMessages)
3000                  m_pMessages->flushStdoutBuffer();                  m_pMessages->flushStdoutBuffer();
3001    
3002          if (m_pServer && bForceServerStop) {          if (m_pServer && m_bForceServerStop) {
3003                  if (m_pServer->state() != QProcess::NotRunning) {                  if (m_pServer->state() != QProcess::NotRunning) {
3004                          appendMessages(tr("Server is being forced..."));                          appendMessages(tr("Server is being forced..."));
3005                          // Force final server shutdown...                          // Force final server shutdown...
3006                          m_pServer->kill();                          m_pServer->kill();
3007                          // Give it some time to terminate gracefully and stabilize...                          // Give it some time to terminate gracefully and stabilize...
3008                          QTime t;                          QElapsedTimer timer;
3009                          t.start();                          timer.start();
3010                          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                          while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
3011                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
3012                  }                  }
3013                  // Force final server shutdown...                  // Force final server shutdown...
# Line 2928  void MainForm::processServerExit (void) Line 3015  void MainForm::processServerExit (void)
3015                          tr("Server was stopped with exit status %1.")                          tr("Server was stopped with exit status %1.")
3016                          .arg(m_pServer->exitStatus()));                          .arg(m_pServer->exitStatus()));
3017                  delete m_pServer;                  delete m_pServer;
3018                  m_pServer = NULL;                  m_pServer = nullptr;
3019          }          }
3020    
3021          // Again, make status visible stable.          // Again, make status visible stable.
# Line 2937  void MainForm::processServerExit (void) Line 3024  void MainForm::processServerExit (void)
3024    
3025    
3026  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
3027  // qsamplerMainForm -- Client stuff.  // QSampler::MainForm -- Client stuff.
3028    
3029  // The LSCP client callback procedure.  // The LSCP client callback procedure.
3030  lscp_status_t qsampler_client_callback ( lscp_client_t */*pClient*/,  lscp_status_t qsampler_client_callback ( lscp_client_t */*pClient*/,
3031          lscp_event_t event, const char *pchData, int cchData, void *pvData )          lscp_event_t event, const char *pchData, int cchData, void *pvData )
3032  {  {
3033          MainForm* pMainForm = (MainForm *) pvData;          MainForm* pMainForm = (MainForm *) pvData;
3034          if (pMainForm == NULL)          if (pMainForm == nullptr)
3035                  return LSCP_FAILED;                  return LSCP_FAILED;
3036    
3037          // ATTN: DO NOT EVER call any GUI code here,          // ATTN: DO NOT EVER call any GUI code here,
# Line 2958  lscp_status_t qsampler_client_callback ( Line 3045  lscp_status_t qsampler_client_callback (
3045    
3046    
3047  // Start our almighty client...  // Start our almighty client...
3048  bool MainForm::startClient (void)  bool MainForm::startClient (bool bReconnectOnly)
3049  {  {
3050          // Have it a setup?          // Have it a setup?
3051          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
3052                  return false;                  return false;
3053    
3054          // Aren't we already started, are we?          // Aren't we already started, are we?
# Line 2975  bool MainForm::startClient (void) Line 3062  bool MainForm::startClient (void)
3062          m_pClient = ::lscp_client_create(          m_pClient = ::lscp_client_create(
3063                  m_pOptions->sServerHost.toUtf8().constData(),                  m_pOptions->sServerHost.toUtf8().constData(),
3064                  m_pOptions->iServerPort, qsampler_client_callback, this);                  m_pOptions->iServerPort, qsampler_client_callback, this);
3065          if (m_pClient == NULL) {          if (m_pClient == nullptr) {
3066                  // Is this the first try?                  // Is this the first try?
3067                  // maybe we need to start a local server...                  // maybe we need to start a local server...
3068                  if ((m_pServer && m_pServer->state() == QProcess::Running)                  if ((m_pServer && m_pServer->state() == QProcess::Running)
3069                          || !m_pOptions->bServerStart) {                          || !m_pOptions->bServerStart || bReconnectOnly)
3070                          appendMessagesError(                  {
3071                                  tr("Could not connect to server as client.\n\nSorry."));                          // if this method is called from autoReconnectClient()
3072                            // then don't bother user with an error message...
3073                            if (!bReconnectOnly) {
3074                                    appendMessagesError(
3075                                            tr("Could not connect to server as client.\n\nSorry.")
3076                                    );
3077                            }
3078                  } else {                  } else {
3079                          startServer();                          startServer();
3080                  }                  }
# Line 2989  bool MainForm::startClient (void) Line 3082  bool MainForm::startClient (void)
3082                  stabilizeForm();                  stabilizeForm();
3083                  return false;                  return false;
3084          }          }
3085    
3086          // Just set receive timeout value, blindly.          // Just set receive timeout value, blindly.
3087          ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);          ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);
3088          appendMessages(          appendMessages(
# Line 3044  bool MainForm::startClient (void) Line 3138  bool MainForm::startClient (void)
3138          if (!m_pOptions->sSessionFile.isEmpty()) {          if (!m_pOptions->sSessionFile.isEmpty()) {
3139                  // Just load the prabably startup session...                  // Just load the prabably startup session...
3140                  if (loadSessionFile(m_pOptions->sSessionFile)) {                  if (loadSessionFile(m_pOptions->sSessionFile)) {
3141                          m_pOptions->sSessionFile = QString::null;                          m_pOptions->sSessionFile = QString();
3142                          return true;                          return true;
3143                  }                  }
3144          }          }
# Line 3060  bool MainForm::startClient (void) Line 3154  bool MainForm::startClient (void)
3154  // Stop client...  // Stop client...
3155  void MainForm::stopClient (void)  void MainForm::stopClient (void)
3156  {  {
3157          if (m_pClient == NULL)          if (m_pClient == nullptr)
3158                  return;                  return;
3159    
3160          // Log prepare here.          // Log prepare here.
# Line 3092  void MainForm::stopClient (void) Line 3186  void MainForm::stopClient (void)
3186          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
3187          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);
3188          ::lscp_client_destroy(m_pClient);          ::lscp_client_destroy(m_pClient);
3189          m_pClient = NULL;          m_pClient = nullptr;
3190    
3191          // Hard-notify instrumnet and device configuration forms,          // Hard-notify instrumnet and device configuration forms,
3192          // if visible, that we're running out...          // if visible, that we're running out...
# Line 3109  void MainForm::stopClient (void) Line 3203  void MainForm::stopClient (void)
3203  }  }
3204    
3205    
3206    void MainForm::startAutoReconnectClient (void)
3207    {
3208            stopClient();
3209            appendMessages(tr("Trying to reconnect..."));
3210            QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3211    }
3212    
3213    
3214    void MainForm::autoReconnectClient (void)
3215    {
3216            const bool bSuccess = startClient(true);
3217            if (!bSuccess)
3218                    QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3219    }
3220    
3221    
3222  // Channel strip activation/selection.  // Channel strip activation/selection.
3223  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )
3224  {  {
3225          ChannelStrip *pChannelStrip = NULL;          ChannelStrip *pChannelStrip = nullptr;
3226          if (pMdiSubWindow)          if (pMdiSubWindow)
3227                  pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
3228          if (pChannelStrip)          if (pChannelStrip)

Legend:
Removed from v.2978  
changed lines
  Added in v.3832

  ViewVC Help
Powered by ViewVC