/[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 2717 by schoenebeck, Wed Jan 21 13:19:51 2015 UTC revision 3849 by capela, Thu Jan 7 16:18:02 2021 UTC
# Line 1  Line 1 
1  // qsamplerMainForm.cpp  // qsamplerMainForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2021, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, 2008 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    #pragma GCC diagnostic push
78    #pragma GCC diagnostic ignored "-Wunused-parameter"
79  #include <gig.h>  #include <gig.h>
80    #pragma GCC diagnostic pop
81  #endif  #endif
82    
83  // Needed for lroundf()  // Deprecated QTextStreamFunctions/Qt namespaces workaround.
84  #include <math.h>  #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
85    #define endl    Qt::endl
86    #endif
87    
88  #ifndef CONFIG_ROUND  // Needed for lroundf()
89    #ifdef CONFIG_ROUND
90    #include <cmath>
91    #else
92  static inline long lroundf ( float x )  static inline long lroundf ( float x )
93  {  {
94          if (x >= 0.0f)          if (x >= 0.0f)
# Line 91  static inline long lroundf ( float x ) Line 100  static inline long lroundf ( float x )
100    
101    
102  // All winsock apps needs this.  // All winsock apps needs this.
103  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
104  static WSADATA _wsaData;  static WSADATA _wsaData;
105    #undef HAVE_SIGNAL_H
106  #endif  #endif
107    
108    
# Line 103  static WSADATA _wsaData; Line 113  static WSADATA _wsaData;
113    
114  #include <QSocketNotifier>  #include <QSocketNotifier>
115    
116    #include <unistd.h>
117  #include <sys/types.h>  #include <sys/types.h>
118  #include <sys/socket.h>  #include <sys/socket.h>
   
119  #include <signal.h>  #include <signal.h>
120    
121  // File descriptor for SIGUSR1 notifier.  // File descriptor for SIGUSR1 notifier.
122  static int g_fdUsr1[2];  static int g_fdSigusr1[2] = { -1, -1 };
123    
124  // Unix SIGUSR1 signal handler.  // Unix SIGUSR1 signal handler.
125  static void qsampler_sigusr1_handler ( int /* signo */ )  static void qsampler_sigusr1_handler ( int /* signo */ )
126  {  {
127          char c = 1;          char c = 1;
128    
129          (::write(g_fdUsr1[0], &c, sizeof(c)) > 0);          (::write(g_fdSigusr1[0], &c, sizeof(c)) > 0);
130    }
131    
132    // File descriptor for SIGTERM notifier.
133    static int g_fdSigterm[2] = { -1, -1 };
134    
135    // Unix SIGTERM signal handler.
136    static void qsampler_sigterm_handler ( int /* signo */ )
137    {
138            char c = 1;
139    
140            (::write(g_fdSigterm[0], &c, sizeof(c)) > 0);
141  }  }
142    
143  #endif  // HAVE_SIGNAL_H  #endif  // HAVE_SIGNAL_H
144    
145    
146  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
147  // qsampler -- namespace  // QSampler -- namespace
148    
149    
150  namespace QSampler {  namespace QSampler {
# Line 143  namespace QSampler { Line 164  namespace QSampler {
164    
165    
166  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
167  // LscpEvent -- specialty for LSCP callback comunication.  // QSampler::LscpEvent -- specialty for LSCP callback comunication.
   
168    
169  class LscpEvent : public QEvent  class LscpEvent : public QEvent
170  {  {
# Line 159  public: Line 179  public:
179          }          }
180    
181          // Accessors.          // Accessors.
182          lscp_event_t event() { return m_event; }          lscp_event_t  event() { return m_event; }
183          QString&     data()  { return m_data;  }          const QString& data() { return m_data;  }
184    
185  private:  private:
186    
# Line 172  private: Line 192  private:
192    
193    
194  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
195  // qsamplerMainForm -- Main window form implementation.  // QSampler::Workspace -- Main window workspace (MDI Area) decl.
196    
197    class Workspace : public QMdiArea
198    {
199    public:
200    
201            Workspace(MainForm *pMainForm) : QMdiArea(pMainForm) {}
202    
203    protected:
204    
205            void resizeEvent(QResizeEvent *)
206            {
207                    MainForm *pMainForm = static_cast<MainForm *> (parentWidget());
208                    if (pMainForm)
209                            pMainForm->channelsArrangeAuto();
210            }
211    };
212    
213    
214    //-------------------------------------------------------------------------
215    // QSampler::MainForm -- Main window form implementation.
216    
217  // Kind of singleton reference.  // Kind of singleton reference.
218  MainForm* MainForm::g_pMainForm = NULL;  MainForm *MainForm::g_pMainForm = nullptr;
219    
220  MainForm::MainForm ( QWidget *pParent )  MainForm::MainForm ( QWidget *pParent )
221          : QMainWindow(pParent)          : QMainWindow(pParent)
# Line 186  MainForm::MainForm ( QWidget *pParent ) Line 226  MainForm::MainForm ( QWidget *pParent )
226          g_pMainForm = this;          g_pMainForm = this;
227    
228          // Initialize some pointer references.          // Initialize some pointer references.
229          m_pOptions = NULL;          m_pOptions = nullptr;
230    
231          // All child forms are to be created later, not earlier than setup.          // All child forms are to be created later, not earlier than setup.
232          m_pMessages = NULL;          m_pMessages = nullptr;
233          m_pInstrumentListForm = NULL;          m_pInstrumentListForm = nullptr;
234          m_pDeviceForm = NULL;          m_pDeviceForm = nullptr;
235    
236          // We'll start clean.          // We'll start clean.
237          m_iUntitled   = 0;          m_iUntitled   = 0;
238            m_iDirtySetup = 0;
239          m_iDirtyCount = 0;          m_iDirtyCount = 0;
240    
241          m_pServer = NULL;          m_pServer = nullptr;
242          m_pClient = NULL;          m_pClient = nullptr;
243    
244          m_iStartDelay = 0;          m_iStartDelay = 0;
245          m_iTimerDelay = 0;          m_iTimerDelay = 0;
# Line 213  MainForm::MainForm ( QWidget *pParent ) Line 254  MainForm::MainForm ( QWidget *pParent )
254          // LADISH Level 1 suport.          // LADISH Level 1 suport.
255    
256          // Initialize file descriptors for SIGUSR1 socket notifier.          // Initialize file descriptors for SIGUSR1 socket notifier.
257          ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdUsr1);          ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigusr1);
258          m_pUsr1Notifier          m_pSigusr1Notifier
259                  = new QSocketNotifier(g_fdUsr1[1], QSocketNotifier::Read, this);                  = new QSocketNotifier(g_fdSigusr1[1], QSocketNotifier::Read, this);
260    
261          QObject::connect(m_pUsr1Notifier,          QObject::connect(m_pSigusr1Notifier,
262                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
263                  SLOT(handle_sigusr1()));                  SLOT(handle_sigusr1()));
264    
265          // Install SIGUSR1 signal handler.          // Install SIGUSR1 signal handler.
266      struct sigaction usr1;          struct sigaction sigusr1;
267      usr1.sa_handler = qsampler_sigusr1_handler;          sigusr1.sa_handler = qsampler_sigusr1_handler;
268      sigemptyset(&usr1.sa_mask);          sigemptyset(&sigusr1.sa_mask);
269      usr1.sa_flags = 0;          sigusr1.sa_flags = 0;
270      usr1.sa_flags |= SA_RESTART;          sigusr1.sa_flags |= SA_RESTART;
271      ::sigaction(SIGUSR1, &usr1, NULL);          ::sigaction(SIGUSR1, &sigusr1, nullptr);
272    
273            // Initialize file descriptors for SIGTERM socket notifier.
274            ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdSigterm);
275            m_pSigtermNotifier
276                    = new QSocketNotifier(g_fdSigterm[1], QSocketNotifier::Read, this);
277    
278            QObject::connect(m_pSigtermNotifier,
279                    SIGNAL(activated(int)),
280                    SLOT(handle_sigterm()));
281    
282            // Install SIGTERM signal handler.
283            struct sigaction sigterm;
284            sigterm.sa_handler = qsampler_sigterm_handler;
285            sigemptyset(&sigterm.sa_mask);
286            sigterm.sa_flags = 0;
287            sigterm.sa_flags |= SA_RESTART;
288            ::sigaction(SIGTERM, &sigterm, nullptr);
289            ::sigaction(SIGQUIT, &sigterm, nullptr);
290    
291            // Ignore SIGHUP/SIGINT signals.
292            ::signal(SIGHUP, SIG_IGN);
293            ::signal(SIGINT, SIG_IGN);
294    
295  #else   // HAVE_SIGNAL_H  #else   // HAVE_SIGNAL_H
296    
297          m_pUsr1Notifier = NULL;          m_pSigusr1Notifier = nullptr;
298            m_pSigtermNotifier = nullptr;
299                    
300  #endif  // !HAVE_SIGNAL_H  #endif  // !HAVE_SIGNAL_H
301    
# Line 269  MainForm::MainForm ( QWidget *pParent ) Line 333  MainForm::MainForm ( QWidget *pParent )
333  #endif  #endif
334    
335          // Make it an MDI workspace.          // Make it an MDI workspace.
336          m_pWorkspace = new QMdiArea(this);          m_pWorkspace = new Workspace(this);
337          m_pWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);          m_pWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
338          m_pWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);          m_pWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
339          // Set the activation connection.          // Set the activation connection.
# Line 304  MainForm::MainForm ( QWidget *pParent ) Line 368  MainForm::MainForm ( QWidget *pParent )
368          m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;          m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;
369          statusBar()->addWidget(pLabel);          statusBar()->addWidget(pLabel);
370    
371  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
372          WSAStartup(MAKEWORD(1, 1), &_wsaData);          WSAStartup(MAKEWORD(1, 1), &_wsaData);
373  #endif  #endif
374    
# Line 405  MainForm::~MainForm() Line 469  MainForm::~MainForm()
469          // Do final processing anyway.          // Do final processing anyway.
470          processServerExit();          processServerExit();
471    
472  #if defined(WIN32)  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
473          WSACleanup();          WSACleanup();
474  #endif  #endif
475    
476  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
477          if (m_pUsr1Notifier)          if (m_pSigusr1Notifier)
478                  delete m_pUsr1Notifier;                  delete m_pSigusr1Notifier;
479            if (m_pSigtermNotifier)
480                    delete m_pSigtermNotifier;
481  #endif  #endif
482    
483          // Finally drop any widgets around...          // Finally drop any widgets around...
# Line 440  MainForm::~MainForm() Line 506  MainForm::~MainForm()
506  #endif  #endif
507    
508          // Pseudo-singleton reference shut-down.          // Pseudo-singleton reference shut-down.
509          g_pMainForm = NULL;          g_pMainForm = nullptr;
510  }  }
511    
512    
# Line 478  void MainForm::setup ( Options *pOptions Line 544  void MainForm::setup ( Options *pOptions
544          updateMessagesFont();          updateMessagesFont();
545          updateMessagesLimit();          updateMessagesLimit();
546          updateMessagesCapture();          updateMessagesCapture();
547    
548          // Set the visibility signal.          // Set the visibility signal.
549          QObject::connect(m_pMessages,          QObject::connect(m_pMessages,
550                  SIGNAL(visibilityChanged(bool)),                  SIGNAL(visibilityChanged(bool)),
# Line 543  bool MainForm::queryClose (void) Line 610  bool MainForm::queryClose (void)
610                                  || m_ui.channelsToolbar->isVisible());                                  || m_ui.channelsToolbar->isVisible());
611                          m_pOptions->bStatusbar = statusBar()->isVisible();                          m_pOptions->bStatusbar = statusBar()->isVisible();
612                          // Save the dock windows state.                          // Save the dock windows state.
                         const QString sDockables = saveState().toBase64().data();  
613                          m_pOptions->settings().setValue("/Layout/DockWindows", saveState());                          m_pOptions->settings().setValue("/Layout/DockWindows", saveState());
614                          // And the children, and the main windows state,.                          // And the children, and the main windows state,.
615                          m_pOptions->saveWidgetGeometry(m_pDeviceForm);                          m_pOptions->saveWidgetGeometry(m_pDeviceForm);
# Line 577  void MainForm::closeEvent ( QCloseEvent Line 643  void MainForm::closeEvent ( QCloseEvent
643  void MainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  void MainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
644  {  {
645          // Accept external drags only...          // Accept external drags only...
646          if (pDragEnterEvent->source() == NULL          if (pDragEnterEvent->source() == nullptr
647                  && pDragEnterEvent->mimeData()->hasUrls()) {                  && pDragEnterEvent->mimeData()->hasUrls()) {
648                  pDragEnterEvent->accept();                  pDragEnterEvent->accept();
649          } else {          } else {
# Line 586  void MainForm::dragEnterEvent ( QDragEnt Line 652  void MainForm::dragEnterEvent ( QDragEnt
652  }  }
653    
654    
655  void MainForm::dropEvent ( QDropEvent* pDropEvent )  void MainForm::dropEvent ( QDropEvent *pDropEvent )
656  {  {
657          // Accept externally originated drops only...          // Accept externally originated drops only...
658          if (pDropEvent->source())          if (pDropEvent->source())
# Line 601  void MainForm::dropEvent ( QDropEvent* p Line 667  void MainForm::dropEvent ( QDropEvent* p
667                          if (QFileInfo(sPath).exists()) {                          if (QFileInfo(sPath).exists()) {
668                                  // Try to create a new channel from instrument file...                                  // Try to create a new channel from instrument file...
669                                  Channel *pChannel = new Channel();                                  Channel *pChannel = new Channel();
670                                  if (pChannel == NULL)                                  if (pChannel == nullptr)
671                                          return;                                          return;
672                                  // Start setting the instrument filename...                                  // Start setting the instrument filename...
673                                  pChannel->setInstrument(sPath, 0);                                  pChannel->setInstrument(sPath, 0);
# Line 642  void MainForm::customEvent ( QEvent* pEv Line 708  void MainForm::customEvent ( QEvent* pEv
708                                  updateAllChannelStrips(true);                                  updateAllChannelStrips(true);
709                                  break;                                  break;
710                          case LSCP_EVENT_CHANNEL_INFO: {                          case LSCP_EVENT_CHANNEL_INFO: {
711                                  int iChannelID = pLscpEvent->data().toInt();                                  const int iChannelID = pLscpEvent->data().toInt();
712                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);
713                                  if (pChannelStrip)                                  if (pChannelStrip)
714                                          channelStripChanged(pChannelStrip);                                          channelStripChanged(pChannelStrip);
# Line 701  void MainForm::handle_sigusr1 (void) Line 767  void MainForm::handle_sigusr1 (void)
767    
768          char c;          char c;
769    
770          if (::read(g_fdUsr1[1], &c, sizeof(c)) > 0)          if (::read(g_fdSigusr1[1], &c, sizeof(c)) > 0)
771                  saveSession(false);                  saveSession(false);
772    
773  #endif  #endif
774  }  }
775    
776    
777    void MainForm::handle_sigterm (void)
778    {
779    #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
780    
781            char c;
782    
783            if (::read(g_fdSigterm[1], &c, sizeof(c)) > 0)
784                    close();
785    
786    #endif
787    }
788    
789    
790  void MainForm::updateViewMidiDeviceStatusMenu (void)  void MainForm::updateViewMidiDeviceStatusMenu (void)
791  {  {
792          m_ui.viewMidiDeviceStatusMenu->clear();          m_ui.viewMidiDeviceStatusMenu->clear();
# Line 733  void MainForm::contextMenuEvent( QContex Line 812  void MainForm::contextMenuEvent( QContex
812    
813    
814  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
815  // qsamplerMainForm -- Brainless public property accessors.  // QSampler::MainForm -- Brainless public property accessors.
816    
817  // The global options settings property.  // The global options settings property.
818  Options *MainForm::options (void) const  Options *MainForm::options (void) const
# Line 757  MainForm *MainForm::getInstance (void) Line 836  MainForm *MainForm::getInstance (void)
836    
837    
838  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
839  // qsamplerMainForm -- Session file stuff.  // QSampler::MainForm -- Session file stuff.
840    
841  // Format the displayable session filename.  // Format the displayable session filename.
842  QString MainForm::sessionName ( const QString& sFilename )  QString MainForm::sessionName ( const QString& sFilename )
843  {  {
844          bool bCompletePath = (m_pOptions && m_pOptions->bCompletePath);          const bool bCompletePath = (m_pOptions && m_pOptions->bCompletePath);
845          QString sSessionName = sFilename;          QString sSessionName = sFilename;
846          if (sSessionName.isEmpty())          if (sSessionName.isEmpty())
847                  sSessionName = tr("Untitled") + QString::number(m_iUntitled);                  sSessionName = tr("Untitled") + QString::number(m_iUntitled);
# Line 786  bool MainForm::newSession (void) Line 865  bool MainForm::newSession (void)
865          m_iUntitled++;          m_iUntitled++;
866    
867          // Stabilize form.          // Stabilize form.
868          m_sFilename = QString::null;          m_sFilename = QString();
869          m_iDirtyCount = 0;          m_iDirtyCount = 0;
870          appendMessages(tr("New session: \"%1\".").arg(sessionName(m_sFilename)));          appendMessages(tr("New session: \"%1\".").arg(sessionName(m_sFilename)));
871          stabilizeForm();          stabilizeForm();
# Line 798  bool MainForm::newSession (void) Line 877  bool MainForm::newSession (void)
877  // Open an existing sampler session.  // Open an existing sampler session.
878  bool MainForm::openSession (void)  bool MainForm::openSession (void)
879  {  {
880          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
881                  return false;                  return false;
882    
883          // Ask for the filename to open...          // Ask for the filename to open...
884          QString sFilename = QFileDialog::getOpenFileName(this,          QString sFilename = QFileDialog::getOpenFileName(this,
885                  QSAMPLER_TITLE ": " + tr("Open Session"), // Caption.                  tr("Open Session"),                       // Caption.
886                  m_pOptions->sSessionDir,                  // Start here.                  m_pOptions->sSessionDir,                  // Start here.
887                  tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)                  tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)
888          );          );
# Line 824  bool MainForm::openSession (void) Line 903  bool MainForm::openSession (void)
903  // Save current sampler session with another name.  // Save current sampler session with another name.
904  bool MainForm::saveSession ( bool bPrompt )  bool MainForm::saveSession ( bool bPrompt )
905  {  {
906          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
907                  return false;                  return false;
908    
909          QString sFilename = m_sFilename;          QString sFilename = m_sFilename;
# Line 836  bool MainForm::saveSession ( bool bPromp Line 915  bool MainForm::saveSession ( bool bPromp
915                          sFilename = m_pOptions->sSessionDir;                          sFilename = m_pOptions->sSessionDir;
916                  // Prompt the guy...                  // Prompt the guy...
917                  sFilename = QFileDialog::getSaveFileName(this,                  sFilename = QFileDialog::getSaveFileName(this,
918                          QSAMPLER_TITLE ": " + tr("Save Session"), // Caption.                          tr("Save Session"),                       // Caption.
919                          sFilename,                                // Start here.                          sFilename,                                // Start here.
920                          tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)                          tr("LSCP Session files") + " (*.lscp)"    // Filter (LSCP files)
921                  );                  );
# Line 846  bool MainForm::saveSession ( bool bPromp Line 925  bool MainForm::saveSession ( bool bPromp
925                  // Enforce .lscp extension...                  // Enforce .lscp extension...
926                  if (QFileInfo(sFilename).suffix().isEmpty())                  if (QFileInfo(sFilename).suffix().isEmpty())
927                          sFilename += ".lscp";                          sFilename += ".lscp";
928            #if 0
929                  // Check if already exists...                  // Check if already exists...
930                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {                  if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {
931                          if (QMessageBox::warning(this,                          if (QMessageBox::warning(this,
932                                  QSAMPLER_TITLE ": " + tr("Warning"),                                  tr("Warning"),
933                                  tr("The file already exists:\n\n"                                  tr("The file already exists:\n\n"
934                                  "\"%1\"\n\n"                                  "\"%1\"\n\n"
935                                  "Do you want to replace it?")                                  "Do you want to replace it?")
# Line 858  bool MainForm::saveSession ( bool bPromp Line 938  bool MainForm::saveSession ( bool bPromp
938                                  == QMessageBox::No)                                  == QMessageBox::No)
939                                  return false;                                  return false;
940                  }                  }
941            #endif
942          }          }
943    
944          // Save it right away.          // Save it right away.
# Line 873  bool MainForm::closeSession ( bool bForc Line 954  bool MainForm::closeSession ( bool bForc
954          // Are we dirty enough to prompt it?          // Are we dirty enough to prompt it?
955          if (m_iDirtyCount > 0) {          if (m_iDirtyCount > 0) {
956                  switch (QMessageBox::warning(this,                  switch (QMessageBox::warning(this,
957                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
958                          tr("The current session has been changed:\n\n"                          tr("The current session has been changed:\n\n"
959                          "\"%1\"\n\n"                          "\"%1\"\n\n"
960                          "Do you want to save the changes?")                          "Do you want to save the changes?")
# Line 896  bool MainForm::closeSession ( bool bForc Line 977  bool MainForm::closeSession ( bool bForc
977          if (bClose) {          if (bClose) {
978                  // Remove all channel strips from sight...                  // Remove all channel strips from sight...
979                  m_pWorkspace->setUpdatesEnabled(false);                  m_pWorkspace->setUpdatesEnabled(false);
980                  QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();                  const QList<QMdiSubWindow *>& wlist
981                  for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {                          = m_pWorkspace->subWindowList();
982                          ChannelStrip *pChannelStrip = NULL;                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
983                          QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                          ChannelStrip *pChannelStrip
984                          if (pMdiSubWindow)                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
985                          if (pChannelStrip) {                          if (pChannelStrip) {
986                                  Channel *pChannel = pChannelStrip->channel();                                  Channel *pChannel = pChannelStrip->channel();
987                                  if (bForce && pChannel)                                  if (bForce && pChannel)
988                                          pChannel->removeChannel();                                          pChannel->removeChannel();
989                                  delete pChannelStrip;                                  delete pChannelStrip;
990                          }                          }
991                          if (pMdiSubWindow)                          delete pMdiSubWindow;
                                 delete pMdiSubWindow;  
992                  }                  }
993                  m_pWorkspace->setUpdatesEnabled(true);                  m_pWorkspace->setUpdatesEnabled(true);
994                  // We're now clean, for sure.                  // We're now clean, for sure.
# Line 923  bool MainForm::closeSession ( bool bForc Line 1002  bool MainForm::closeSession ( bool bForc
1002  // Load a session from specific file path.  // Load a session from specific file path.
1003  bool MainForm::loadSessionFile ( const QString& sFilename )  bool MainForm::loadSessionFile ( const QString& sFilename )
1004  {  {
1005          if (m_pClient == NULL)          if (m_pClient == nullptr)
1006                  return false;                  return false;
1007    
1008          // Open and read from real file.          // Open and read from real file.
# Line 999  bool MainForm::loadSessionFile ( const Q Line 1078  bool MainForm::loadSessionFile ( const Q
1078  // Save current session to specific file path.  // Save current session to specific file path.
1079  bool MainForm::saveSessionFile ( const QString& sFilename )  bool MainForm::saveSessionFile ( const QString& sFilename )
1080  {  {
1081          if (m_pClient == NULL)          if (m_pClient == nullptr)
1082                  return false;                  return false;
1083    
1084          // Check whether server is apparently OK...          // Check whether server is apparently OK...
# Line 1021  bool MainForm::saveSessionFile ( const Q Line 1100  bool MainForm::saveSessionFile ( const Q
1100          QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));          QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
1101    
1102          // Write the file.          // Write the file.
1103          int  iErrors = 0;          int iErrors = 0;
1104          QTextStream ts(&file);          QTextStream ts(&file);
1105          ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;          ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;
1106          ts << "# " << tr("Version")          ts << "# " << tr("Version") << ": " CONFIG_BUILD_VERSION << endl;
1107          << ": " QSAMPLER_VERSION << endl;  //      ts << "# " << tr("Build") << ": " CONFIG_BUILD_DATE << endl;
         ts << "# " << tr("Build")  
         << ": " __DATE__ " " __TIME__ << endl;  
1108          ts << "#"  << endl;          ts << "#"  << endl;
1109          ts << "# " << tr("File")          ts << "# " << tr("File")
1110          << ": " << QFileInfo(sFilename).fileName() << endl;          << ": " << QFileInfo(sFilename).fileName() << endl;
# Line 1040  bool MainForm::saveSessionFile ( const Q Line 1117  bool MainForm::saveSessionFile ( const Q
1117          // It is assumed that this new kind of device+session file          // It is assumed that this new kind of device+session file
1118          // will be loaded from a complete initialized server...          // will be loaded from a complete initialized server...
1119          int *piDeviceIDs;          int *piDeviceIDs;
1120          int  iDevice;          int  i, iDevice;
1121          ts << "RESET" << endl;          ts << "RESET" << endl;
1122    
1123          // Audio device mapping.          // Audio device mapping.
1124          QMap<int, int> audioDeviceMap;          QMap<int, int> audioDeviceMap; iDevice = 0;
1125          piDeviceIDs = Device::getDevices(m_pClient, Device::Audio);          piDeviceIDs = Device::getDevices(m_pClient, Device::Audio);
1126          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
1127                  ts << endl;                  Device device(Device::Audio, piDeviceIDs[i]);
1128                  Device device(Device::Audio, piDeviceIDs[iDevice]);                  // Avoid plug-in driver devices...
1129                    if (device.driverName().toUpper() == "PLUGIN")
1130                            continue;
1131                  // Audio device specification...                  // Audio device specification...
1132                    ts << endl;
1133                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1134                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1135                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();
# Line 1080  bool MainForm::saveSessionFile ( const Q Line 1160  bool MainForm::saveSessionFile ( const Q
1160                          iPort++;                          iPort++;
1161                  }                  }
1162                  // Audio device index/id mapping.                  // Audio device index/id mapping.
1163                  audioDeviceMap[device.deviceID()] = iDevice;                  audioDeviceMap.insert(device.deviceID(), iDevice++);
1164                  // Try to keep it snappy :)                  // Try to keep it snappy :)
1165                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1166          }          }
1167    
1168          // MIDI device mapping.          // MIDI device mapping.
1169          QMap<int, int> midiDeviceMap;          QMap<int, int> midiDeviceMap; iDevice = 0;
1170          piDeviceIDs = Device::getDevices(m_pClient, Device::Midi);          piDeviceIDs = Device::getDevices(m_pClient, Device::Midi);
1171          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; ++i) {
1172                  ts << endl;                  Device device(Device::Midi, piDeviceIDs[i]);
1173                  Device device(Device::Midi, piDeviceIDs[iDevice]);                  // Avoid plug-in driver devices...
1174                    if (device.driverName().toUpper() == "PLUGIN")
1175                            continue;
1176                  // MIDI device specification...                  // MIDI device specification...
1177                    ts << endl;
1178                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1179                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1180                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();
# Line 1122  bool MainForm::saveSessionFile ( const Q Line 1205  bool MainForm::saveSessionFile ( const Q
1205                          iPort++;                          iPort++;
1206                  }                  }
1207                  // MIDI device index/id mapping.                  // MIDI device index/id mapping.
1208                  midiDeviceMap[device.deviceID()] = iDevice;                  midiDeviceMap.insert(device.deviceID(), iDevice++);
1209                  // Try to keep it snappy :)                  // Try to keep it snappy :)
1210                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
1211          }          }
# Line 1133  bool MainForm::saveSessionFile ( const Q Line 1216  bool MainForm::saveSessionFile ( const Q
1216          QMap<int, int> midiInstrumentMap;          QMap<int, int> midiInstrumentMap;
1217          int *piMaps = ::lscp_list_midi_instrument_maps(m_pClient);          int *piMaps = ::lscp_list_midi_instrument_maps(m_pClient);
1218          for (int iMap = 0; piMaps && piMaps[iMap] >= 0; iMap++) {          for (int iMap = 0; piMaps && piMaps[iMap] >= 0; iMap++) {
1219                  int iMidiMap = piMaps[iMap];                  const int iMidiMap = piMaps[iMap];
1220                  const char *pszMapName                  const char *pszMapName
1221                          = ::lscp_get_midi_instrument_map_name(m_pClient, iMidiMap);                          = ::lscp_get_midi_instrument_map_name(m_pClient, iMidiMap);
1222                  ts << "# " << tr("MIDI instrument map") << " " << iMap;                  ts << "# " << tr("MIDI instrument map") << " " << iMap;
# Line 1185  bool MainForm::saveSessionFile ( const Q Line 1268  bool MainForm::saveSessionFile ( const Q
1268                  }                  }
1269                  ts << endl;                  ts << endl;
1270                  // Check for errors...                  // Check for errors...
1271                  if (pInstrs == NULL && ::lscp_client_get_errno(m_pClient)) {                  if (pInstrs == nullptr && ::lscp_client_get_errno(m_pClient)) {
1272                          appendMessagesClient("lscp_list_midi_instruments");                          appendMessagesClient("lscp_list_midi_instruments");
1273                          iErrors++;                          iErrors++;
1274                  }                  }
1275                  // MIDI strument index/id mapping.                  // MIDI strument index/id mapping.
1276                  midiInstrumentMap[iMidiMap] = iMap;                  midiInstrumentMap.insert(iMidiMap, iMap);
1277          }          }
1278          // Check for errors...          // Check for errors...
1279          if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) {          if (piMaps == nullptr && ::lscp_client_get_errno(m_pClient)) {
1280                  appendMessagesClient("lscp_list_midi_instrument_maps");                  appendMessagesClient("lscp_list_midi_instrument_maps");
1281                  iErrors++;                  iErrors++;
1282          }          }
1283  #endif  // CONFIG_MIDI_INSTRUMENT  #endif  // CONFIG_MIDI_INSTRUMENT
1284    
1285          // Sampler channel mapping.          // Sampler channel mapping...
1286          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          int iChannelID = 0;
1287          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {          const QList<QMdiSubWindow *>& wlist
1288                  ChannelStrip *pChannelStrip = NULL;                  = m_pWorkspace->subWindowList();
1289                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1290                  if (pMdiSubWindow)                  ChannelStrip *pChannelStrip
1291                          pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
1292                  if (pChannelStrip) {                  if (pChannelStrip) {
1293                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
1294                          if (pChannel) {                          if (pChannel) {
1295                                  ts << "# " << tr("Channel") << " " << iChannel << endl;                                  // Avoid "artifial" plug-in devices...
1296                                    const int iAudioDevice = pChannel->audioDevice();
1297                                    if (!audioDeviceMap.contains(iAudioDevice))
1298                                            continue;
1299                                    const int iMidiDevice = pChannel->midiDevice();
1300                                    if (!midiDeviceMap.contains(iMidiDevice))
1301                                            continue;
1302                                    // Go for regular, canonical devices...
1303                                    ts << "# " << tr("Channel") << " " << iChannelID << endl;
1304                                  ts << "ADD CHANNEL" << endl;                                  ts << "ADD CHANNEL" << endl;
1305                                  if (audioDeviceMap.isEmpty()) {                                  if (audioDeviceMap.isEmpty()) {
1306                                          ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel                                          ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID
1307                                                  << " " << pChannel->audioDriver() << endl;                                                  << " " << pChannel->audioDriver() << endl;
1308                                  } else {                                  } else {
1309                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannel                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannelID
1310                                                  << " " << audioDeviceMap[pChannel->audioDevice()] << endl;                                                  << " " << audioDeviceMap.value(iAudioDevice) << endl;
1311                                  }                                  }
1312                                  if (midiDeviceMap.isEmpty()) {                                  if (midiDeviceMap.isEmpty()) {
1313                                          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel                                          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID
1314                                                  << " " << pChannel->midiDriver() << endl;                                                  << " " << pChannel->midiDriver() << endl;
1315                                  } else {                                  } else {
1316                                          ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannel                                          ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannelID
1317                                                  << " " << midiDeviceMap[pChannel->midiDevice()] << endl;                                                  << " " << midiDeviceMap.value(iMidiDevice) << endl;
1318                                  }                                  }
1319                                  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel                                  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID
1320                                          << " " << pChannel->midiPort() << endl;                                          << " " << pChannel->midiPort() << endl;
1321                                  ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " ";                                  ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " ";
1322                                  if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)                                  if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
1323                                          ts << "ALL";                                          ts << "ALL";
1324                                  else                                  else
1325                                          ts << pChannel->midiChannel();                                          ts << pChannel->midiChannel();
1326                                  ts << endl;                                  ts << endl;
1327                                  ts << "LOAD ENGINE " << pChannel->engineName()                                  ts << "LOAD ENGINE " << pChannel->engineName()
1328                                          << " " << iChannel << endl;                                          << " " << iChannelID << endl;
1329                                  if (pChannel->instrumentStatus() < 100) ts << "# ";                                  if (pChannel->instrumentStatus() < 100) ts << "# ";
1330                                  ts << "LOAD INSTRUMENT NON_MODAL '"                                  ts << "LOAD INSTRUMENT NON_MODAL '"
1331                                          << pChannel->instrumentFile() << "' "                                          << pChannel->instrumentFile() << "' "
1332                                          << pChannel->instrumentNr() << " " << iChannel << endl;                                          << pChannel->instrumentNr() << " " << iChannelID << endl;
1333                                  ChannelRoutingMap::ConstIterator audioRoute;                                  ChannelRoutingMap::ConstIterator audioRoute;
1334                                  for (audioRoute = pChannel->audioRouting().begin();                                  for (audioRoute = pChannel->audioRouting().begin();
1335                                                  audioRoute != pChannel->audioRouting().end();                                                  audioRoute != pChannel->audioRouting().end();
1336                                                          ++audioRoute) {                                                          ++audioRoute) {
1337                                          ts << "SET CHANNEL AUDIO_OUTPUT_CHANNEL " << iChannel                                          ts << "SET CHANNEL AUDIO_OUTPUT_CHANNEL " << iChannelID
1338                                                  << " " << audioRoute.key()                                                  << " " << audioRoute.key()
1339                                                  << " " << audioRoute.value() << endl;                                                  << " " << audioRoute.value() << endl;
1340                                  }                                  }
1341                                  ts << "SET CHANNEL VOLUME " << iChannel                                  ts << "SET CHANNEL VOLUME " << iChannelID
1342                                          << " " << pChannel->volume() << endl;                                          << " " << pChannel->volume() << endl;
1343                                  if (pChannel->channelMute())                                  if (pChannel->channelMute())
1344                                          ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl;                                          ts << "SET CHANNEL MUTE " << iChannelID << " 1" << endl;
1345                                  if (pChannel->channelSolo())                                  if (pChannel->channelSolo())
1346                                          ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl;                                          ts << "SET CHANNEL SOLO " << iChannelID << " 1" << endl;
1347                          #ifdef CONFIG_MIDI_INSTRUMENT                          #ifdef CONFIG_MIDI_INSTRUMENT
1348                                  if (pChannel->midiMap() >= 0) {                                  const int iMidiMap = pChannel->midiMap();
1349                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel                                  if (midiInstrumentMap.contains(iMidiMap)) {
1350                                                  << " " << midiInstrumentMap[pChannel->midiMap()] << endl;                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannelID
1351                                                    << " " << midiInstrumentMap.value(iMidiMap) << endl;
1352                                  }                                  }
1353                          #endif                          #endif
1354                          #ifdef CONFIG_FXSEND                          #ifdef CONFIG_FXSEND
                                 int iChannelID = pChannel->channelID();  
1355                                  int *piFxSends = ::lscp_list_fxsends(m_pClient, iChannelID);                                  int *piFxSends = ::lscp_list_fxsends(m_pClient, iChannelID);
1356                                  for (int iFxSend = 0;                                  for (int iFxSend = 0;
1357                                                  piFxSends && piFxSends[iFxSend] >= 0;                                                  piFxSends && piFxSends[iFxSend] >= 0;
# Line 1268  bool MainForm::saveSessionFile ( const Q Line 1359  bool MainForm::saveSessionFile ( const Q
1359                                          lscp_fxsend_info_t *pFxSendInfo = ::lscp_get_fxsend_info(                                          lscp_fxsend_info_t *pFxSendInfo = ::lscp_get_fxsend_info(
1360                                                  m_pClient, iChannelID, piFxSends[iFxSend]);                                                  m_pClient, iChannelID, piFxSends[iFxSend]);
1361                                          if (pFxSendInfo) {                                          if (pFxSendInfo) {
1362                                                  ts << "CREATE FX_SEND " << iChannel                                                  ts << "CREATE FX_SEND " << iChannelID
1363                                                          << " " << pFxSendInfo->midi_controller;                                                          << " " << pFxSendInfo->midi_controller;
1364                                                  if (pFxSendInfo->name)                                                  if (pFxSendInfo->name)
1365                                                          ts << " '" << pFxSendInfo->name << "'";                                                          ts << " '" << pFxSendInfo->name << "'";
# Line 1278  bool MainForm::saveSessionFile ( const Q Line 1369  bool MainForm::saveSessionFile ( const Q
1369                                                                  piRouting && piRouting[iAudioSrc] >= 0;                                                                  piRouting && piRouting[iAudioSrc] >= 0;
1370                                                                          iAudioSrc++) {                                                                          iAudioSrc++) {
1371                                                          ts << "SET FX_SEND AUDIO_OUTPUT_CHANNEL "                                                          ts << "SET FX_SEND AUDIO_OUTPUT_CHANNEL "
1372                                                                  << iChannel                                                                  << iChannelID
1373                                                                  << " " << iFxSend                                                                  << " " << iFxSend
1374                                                                  << " " << iAudioSrc                                                                  << " " << iAudioSrc
1375                                                                  << " " << piRouting[iAudioSrc] << endl;                                                                  << " " << piRouting[iAudioSrc] << endl;
1376                                                  }                                                  }
1377                                          #ifdef CONFIG_FXSEND_LEVEL                                          #ifdef CONFIG_FXSEND_LEVEL
1378                                                  ts << "SET FX_SEND LEVEL " << iChannel                                                  ts << "SET FX_SEND LEVEL " << iChannelID
1379                                                          << " " << iFxSend                                                          << " " << iFxSend
1380                                                          << " " << pFxSendInfo->level << endl;                                                          << " " << pFxSendInfo->level << endl;
1381                                          #endif                                          #endif
# Line 1296  bool MainForm::saveSessionFile ( const Q Line 1387  bool MainForm::saveSessionFile ( const Q
1387                                  }                                  }
1388                          #endif                          #endif
1389                                  ts << endl;                                  ts << endl;
1390                                    // Go for next channel...
1391                                    ++iChannelID;
1392                          }                          }
1393                  }                  }
1394                  // Try to keep it snappy :)                  // Try to keep it snappy :)
# Line 1347  void MainForm::sessionDirty (void) Line 1440  void MainForm::sessionDirty (void)
1440    
1441    
1442  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1443  // qsamplerMainForm -- File Action slots.  // QSampler::MainForm -- File Action slots.
1444    
1445  // Create a new sampler session.  // Create a new sampler session.
1446  void MainForm::fileNew (void)  void MainForm::fileNew (void)
# Line 1371  void MainForm::fileOpenRecent (void) Line 1464  void MainForm::fileOpenRecent (void)
1464          // Retrive filename index from action data...          // Retrive filename index from action data...
1465          QAction *pAction = qobject_cast<QAction *> (sender());          QAction *pAction = qobject_cast<QAction *> (sender());
1466          if (pAction && m_pOptions) {          if (pAction && m_pOptions) {
1467                  int iIndex = pAction->data().toInt();                  const int iIndex = pAction->data().toInt();
1468                  if (iIndex >= 0 && iIndex < m_pOptions->recentFiles.count()) {                  if (iIndex >= 0 && iIndex < m_pOptions->recentFiles.count()) {
1469                          QString sFilename = m_pOptions->recentFiles[iIndex];                          QString sFilename = m_pOptions->recentFiles[iIndex];
1470                          // Check if we can safely close the current session...                          // Check if we can safely close the current session...
# Line 1401  void MainForm::fileSaveAs (void) Line 1494  void MainForm::fileSaveAs (void)
1494  // Reset the sampler instance.  // Reset the sampler instance.
1495  void MainForm::fileReset (void)  void MainForm::fileReset (void)
1496  {  {
1497          if (m_pClient == NULL)          if (m_pClient == nullptr)
1498                  return;                  return;
1499    
1500          // Ask user whether he/she want's an internal sampler reset...          // Ask user whether he/she want's an internal sampler reset...
1501          if (QMessageBox::warning(this,          if (m_pOptions && m_pOptions->bConfirmReset) {
1502                  QSAMPLER_TITLE ": " + tr("Warning"),                  const QString& sTitle = tr("Warning");
1503                  tr("Resetting the sampler instance will close\n"                  const QString& sText = tr(
1504                  "all device and channel configurations.\n\n"                          "Resetting the sampler instance will close\n"
1505                  "Please note that this operation may cause\n"                          "all device and channel configurations.\n\n"
1506                  "temporary MIDI and Audio disruption.\n\n"                          "Please note that this operation may cause\n"
1507                  "Do you want to reset the sampler engine now?"),                          "temporary MIDI and Audio disruption.\n\n"
1508                  QMessageBox::Ok | QMessageBox::Cancel)                          "Do you want to reset the sampler engine now?");
1509                  == QMessageBox::Cancel)          #if 0
1510                  return;                  if (QMessageBox::warning(this, sTitle, sText,
1511                            QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
1512                            return;
1513            #else
1514                    QMessageBox mbox(this);
1515                    mbox.setIcon(QMessageBox::Warning);
1516                    mbox.setWindowTitle(sTitle);
1517                    mbox.setText(sText);
1518                    mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
1519                    QCheckBox cbox(tr("Don't ask this again"));
1520                    cbox.setChecked(false);
1521                    cbox.blockSignals(true);
1522                    mbox.addButton(&cbox, QMessageBox::ActionRole);
1523                    if (mbox.exec() == QMessageBox::Cancel)
1524                            return;
1525                    if (cbox.isChecked())
1526                            m_pOptions->bConfirmReset = false;
1527            #endif
1528            }
1529    
1530          // Trye closing the current session, first...          // Trye closing the current session, first...
1531          if (!closeSession(true))          if (!closeSession(true))
# Line 1439  void MainForm::fileReset (void) Line 1550  void MainForm::fileReset (void)
1550  // Restart the client/server instance.  // Restart the client/server instance.
1551  void MainForm::fileRestart (void)  void MainForm::fileRestart (void)
1552  {  {
1553          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1554                  return;                  return;
1555    
1556          bool bRestart = true;          bool bRestart = true;
1557    
1558          // Ask user whether he/she want's a complete restart...          // Ask user whether he/she want's a complete restart...
1559          // (if we're currently up and running)          // (if we're currently up and running)
1560          if (bRestart && m_pClient) {          if (m_pOptions && m_pOptions->bConfirmRestart) {
1561                  bRestart = (QMessageBox::warning(this,                  const QString& sTitle = tr("Warning");
1562                          QSAMPLER_TITLE ": " + tr("Warning"),                  const QString& sText = tr(
1563                          tr("New settings will be effective after\n"                          "New settings will be effective after\n"
1564                          "restarting the client/server connection.\n\n"                          "restarting the client/server connection.\n\n"
1565                          "Please note that this operation may cause\n"                          "Please note that this operation may cause\n"
1566                          "temporary MIDI and Audio disruption.\n\n"                          "temporary MIDI and Audio disruption.\n\n"
1567                          "Do you want to restart the connection now?"),                          "Do you want to restart the connection now?");
1568                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok);          #if 0
1569                    if (QMessageBox::warning(this, sTitle, sText,
1570                            QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
1571                            bRestart = false;
1572            #else
1573                    QMessageBox mbox(this);
1574                    mbox.setIcon(QMessageBox::Warning);
1575                    mbox.setWindowTitle(sTitle);
1576                    mbox.setText(sText);
1577                    mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
1578                    QCheckBox cbox(tr("Don't ask this again"));
1579                    cbox.setChecked(false);
1580                    cbox.blockSignals(true);
1581                    mbox.addButton(&cbox, QMessageBox::ActionRole);
1582                    if (mbox.exec() == QMessageBox::Cancel)
1583                            bRestart = false;
1584                    else
1585                    if (cbox.isChecked())
1586                            m_pOptions->bConfirmRestart = false;
1587            #endif
1588          }          }
1589    
1590          // Are we still for it?          // Are we still for it?
# Line 1476  void MainForm::fileExit (void) Line 1606  void MainForm::fileExit (void)
1606    
1607    
1608  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1609  // qsamplerMainForm -- Edit Action slots.  // QSampler::MainForm -- Edit Action slots.
1610    
1611  // Add a new sampler channel.  // Add a new sampler channel.
1612  void MainForm::editAddChannel (void)  void MainForm::editAddChannel (void)
1613  {  {
1614          if (m_pClient == NULL)          ++m_iDirtySetup;
1615            addChannelStrip();
1616            --m_iDirtySetup;
1617    }
1618    
1619    void MainForm::addChannelStrip (void)
1620    {
1621            if (m_pClient == nullptr)
1622                  return;                  return;
1623    
1624          // Just create the channel instance...          // Just create the channel instance...
1625          Channel *pChannel = new Channel();          Channel *pChannel = new Channel();
1626          if (pChannel == NULL)          if (pChannel == nullptr)
1627                  return;                  return;
1628    
1629          // Before we show it up, may be we'll          // Before we show it up, may be we'll
# Line 1504  void MainForm::editAddChannel (void) Line 1641  void MainForm::editAddChannel (void)
1641          }          }
1642    
1643          // Do we auto-arrange?          // Do we auto-arrange?
1644          if (m_pOptions && m_pOptions->bAutoArrange)          channelsArrangeAuto();
                 channelsArrange();  
1645    
1646          // Make that an overall update.          // Make that an overall update.
1647          m_iDirtyCount++;          m_iDirtyCount++;
# Line 1516  void MainForm::editAddChannel (void) Line 1652  void MainForm::editAddChannel (void)
1652  // Remove current sampler channel.  // Remove current sampler channel.
1653  void MainForm::editRemoveChannel (void)  void MainForm::editRemoveChannel (void)
1654  {  {
1655          if (m_pClient == NULL)          ++m_iDirtySetup;
1656            removeChannelStrip();
1657            --m_iDirtySetup;
1658    }
1659    
1660    void MainForm::removeChannelStrip (void)
1661    {
1662            if (m_pClient == nullptr)
1663                  return;                  return;
1664    
1665          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1666          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1667                  return;                  return;
1668    
1669          Channel *pChannel = pChannelStrip->channel();          Channel *pChannel = pChannelStrip->channel();
1670          if (pChannel == NULL)          if (pChannel == nullptr)
1671                  return;                  return;
1672    
1673          // Prompt user if he/she's sure about this...          // Prompt user if he/she's sure about this...
1674          if (m_pOptions && m_pOptions->bConfirmRemove) {          if (m_pOptions && m_pOptions->bConfirmRemove) {
1675                  if (QMessageBox::warning(this,                  const QString& sTitle = tr("Warning");
1676                          QSAMPLER_TITLE ": " + tr("Warning"),                  const QString& sText = tr(
1677                          tr("About to remove channel:\n\n"                          "About to remove channel:\n\n"
1678                          "%1\n\n"                          "%1\n\n"
1679                          "Are you sure?")                          "Are you sure?")
1680                          .arg(pChannelStrip->windowTitle()),                          .arg(pChannelStrip->windowTitle());
1681                          QMessageBox::Ok | QMessageBox::Cancel)          #if 0
1682                          == QMessageBox::Cancel)                  if (QMessageBox::warning(this, sTitle, sText,
1683                            QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel)
1684                          return;                          return;
1685            #else
1686                    QMessageBox mbox(this);
1687                    mbox.setIcon(QMessageBox::Warning);
1688                    mbox.setWindowTitle(sTitle);
1689                    mbox.setText(sText);
1690                    mbox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
1691                    QCheckBox cbox(tr("Don't ask this again"));
1692                    cbox.setChecked(false);
1693                    cbox.blockSignals(true);
1694                    mbox.addButton(&cbox, QMessageBox::ActionRole);
1695                    if (mbox.exec() == QMessageBox::Cancel)
1696                            return;
1697                    if (cbox.isChecked())
1698                            m_pOptions->bConfirmRemove = false;
1699            #endif
1700          }          }
1701    
1702          // Remove the existing sampler channel.          // Remove the existing sampler channel.
1703          if (!pChannel->removeChannel())          if (!pChannel->removeChannel())
1704                  return;                  return;
1705    
         // We'll be dirty, for sure...  
         m_iDirtyCount++;  
   
1706          // Just delete the channel strip.          // Just delete the channel strip.
1707          destroyChannelStrip(pChannelStrip);          destroyChannelStrip(pChannelStrip);
1708    
1709            // We'll be dirty, for sure...
1710            m_iDirtyCount++;
1711            stabilizeForm();
1712  }  }
1713    
1714    
1715  // Setup current sampler channel.  // Setup current sampler channel.
1716  void MainForm::editSetupChannel (void)  void MainForm::editSetupChannel (void)
1717  {  {
1718          if (m_pClient == NULL)          if (m_pClient == nullptr)
1719                  return;                  return;
1720    
1721          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1722          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1723                  return;                  return;
1724    
1725          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1570  void MainForm::editSetupChannel (void) Line 1730  void MainForm::editSetupChannel (void)
1730  // Edit current sampler channel.  // Edit current sampler channel.
1731  void MainForm::editEditChannel (void)  void MainForm::editEditChannel (void)
1732  {  {
1733          if (m_pClient == NULL)          if (m_pClient == nullptr)
1734                  return;                  return;
1735    
1736          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1737          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1738                  return;                  return;
1739    
1740          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1585  void MainForm::editEditChannel (void) Line 1745  void MainForm::editEditChannel (void)
1745  // Reset current sampler channel.  // Reset current sampler channel.
1746  void MainForm::editResetChannel (void)  void MainForm::editResetChannel (void)
1747  {  {
1748          if (m_pClient == NULL)          if (m_pClient == nullptr)
1749                  return;                  return;
1750    
1751          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1752          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
1753                  return;                  return;
1754    
1755          // Just invoque the channel strip procedure.          // Just invoque the channel strip procedure.
# Line 1600  void MainForm::editResetChannel (void) Line 1760  void MainForm::editResetChannel (void)
1760  // Reset all sampler channels.  // Reset all sampler channels.
1761  void MainForm::editResetAllChannels (void)  void MainForm::editResetAllChannels (void)
1762  {  {
1763          if (m_pClient == NULL)          if (m_pClient == nullptr)
1764                  return;                  return;
1765    
1766          // Invoque the channel strip procedure,          // Invoque the channel strip procedure,
1767          // for all channels out there...          // for all channels out there...
1768          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
1769          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
1770          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {                  = m_pWorkspace->subWindowList();
1771                  ChannelStrip *pChannelStrip = NULL;          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
1772                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                  ChannelStrip *pChannelStrip
1773                  if (pMdiSubWindow)                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
1774                  if (pChannelStrip)                  if (pChannelStrip)
1775                          pChannelStrip->channelReset();                          pChannelStrip->channelReset();
1776          }          }
# Line 1620  void MainForm::editResetAllChannels (voi Line 1779  void MainForm::editResetAllChannels (voi
1779    
1780    
1781  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1782  // qsamplerMainForm -- View Action slots.  // QSampler::MainForm -- View Action slots.
1783    
1784  // Show/hide the main program window menubar.  // Show/hide the main program window menubar.
1785  void MainForm::viewMenubar ( bool bOn )  void MainForm::viewMenubar ( bool bOn )
# Line 1670  void MainForm::viewMessages ( bool bOn ) Line 1829  void MainForm::viewMessages ( bool bOn )
1829  // Show/hide the MIDI instrument list-view form.  // Show/hide the MIDI instrument list-view form.
1830  void MainForm::viewInstruments (void)  void MainForm::viewInstruments (void)
1831  {  {
1832          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1833                  return;                  return;
1834    
1835          if (m_pInstrumentListForm) {          if (m_pInstrumentListForm) {
# Line 1689  void MainForm::viewInstruments (void) Line 1848  void MainForm::viewInstruments (void)
1848  // Show/hide the device configurator form.  // Show/hide the device configurator form.
1849  void MainForm::viewDevices (void)  void MainForm::viewDevices (void)
1850  {  {
1851          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1852                  return;                  return;
1853    
1854          if (m_pDeviceForm) {          if (m_pDeviceForm) {
# Line 1708  void MainForm::viewDevices (void) Line 1867  void MainForm::viewDevices (void)
1867  // Show options dialog.  // Show options dialog.
1868  void MainForm::viewOptions (void)  void MainForm::viewOptions (void)
1869  {  {
1870          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
1871                  return;                  return;
1872    
1873          OptionsForm* pOptionsForm = new OptionsForm(this);          OptionsForm* pOptionsForm = new OptionsForm(this);
# Line 1720  void MainForm::viewOptions (void) Line 1879  void MainForm::viewOptions (void)
1879                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1880                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();                          m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1881                  // To track down deferred or immediate changes.                  // To track down deferred or immediate changes.
1882                  QString sOldServerHost      = m_pOptions->sServerHost;                  const QString sOldServerHost       = m_pOptions->sServerHost;
1883                  int     iOldServerPort      = m_pOptions->iServerPort;                  const int     iOldServerPort       = m_pOptions->iServerPort;
1884                  int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  const int     iOldServerTimeout    = m_pOptions->iServerTimeout;
1885                  bool    bOldServerStart     = m_pOptions->bServerStart;                  const bool    bOldServerStart      = m_pOptions->bServerStart;
1886                  QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  const QString sOldServerCmdLine    = m_pOptions->sServerCmdLine;
1887                  bool    bOldMessagesLog     = m_pOptions->bMessagesLog;                  const bool    bOldMessagesLog      = m_pOptions->bMessagesLog;
1888                  QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;                  const QString sOldMessagesLogPath  = m_pOptions->sMessagesLogPath;
1889                  QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  const QString sOldDisplayFont      = m_pOptions->sDisplayFont;
1890                  bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  const bool    bOldDisplayEffect    = m_pOptions->bDisplayEffect;
1891                  int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  const int     iOldMaxVolume        = m_pOptions->iMaxVolume;
1892                  QString sOldMessagesFont    = m_pOptions->sMessagesFont;                  const QString sOldMessagesFont     = m_pOptions->sMessagesFont;
1893                  bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;                  const bool    bOldKeepOnTop        = m_pOptions->bKeepOnTop;
1894                  bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;                  const bool    bOldStdoutCapture    = m_pOptions->bStdoutCapture;
1895                  int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;                  const int     bOldMessagesLimit    = m_pOptions->bMessagesLimit;
1896                  int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;                  const int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1897                  bool    bOldCompletePath    = m_pOptions->bCompletePath;                  const bool    bOldCompletePath     = m_pOptions->bCompletePath;
1898                  bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  const bool    bOldInstrumentNames  = m_pOptions->bInstrumentNames;
1899                  int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  const int     iOldMaxRecentFiles   = m_pOptions->iMaxRecentFiles;
1900                  int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;                  const int     iOldBaseFontSize     = m_pOptions->iBaseFontSize;
1901                    const QString sOldCustomStyleTheme = m_pOptions->sCustomStyleTheme;
1902                    const QString sOldCustomColorTheme = m_pOptions->sCustomColorTheme;
1903                  // Load the current setup settings.                  // Load the current setup settings.
1904                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1905                  // Show the setup dialog...                  // Show the setup dialog...
1906                  if (pOptionsForm->exec()) {                  if (pOptionsForm->exec()) {
1907                          // Warn if something will be only effective on next run.                          // Warn if something will be only effective on next run.
1908                            int iNeedRestart = 0;
1909                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1910                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {
1911                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  updateMessagesCapture();
1912                                    ++iNeedRestart;
1913                            }
1914                            if (( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1915                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1916                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {                                  (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1917                                  QMessageBox::information(this,                                  ++iNeedRestart;
1918                                          QSAMPLER_TITLE ": " + tr("Information"),                          }
1919                                          tr("Some settings may be only effective\n"                          // Check whether restart is needed or whether
1920                                          "next time you start this program."));                          // custom options maybe set up immediately...
1921                                  updateMessagesCapture();                          if (m_pOptions->sCustomStyleTheme != sOldCustomStyleTheme) {
1922                                    if (m_pOptions->sCustomStyleTheme.isEmpty()) {
1923                                            ++iNeedRestart;
1924                                    } else {
1925                                            QApplication::setStyle(
1926                                                    QStyleFactory::create(m_pOptions->sCustomStyleTheme));
1927                                    }
1928                            }
1929                            if (m_pOptions->sCustomColorTheme != sOldCustomColorTheme) {
1930                                    if (m_pOptions->sCustomColorTheme.isEmpty()) {
1931                                            ++iNeedRestart;
1932                                    } else {
1933                                            QPalette pal;
1934                                            if (PaletteForm::namedPalette(
1935                                                            &m_pOptions->settings(), m_pOptions->sCustomColorTheme, pal))
1936                                                    QApplication::setPalette(pal);
1937                                    }
1938                          }                          }
1939                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1940                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||                          if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
# Line 1781  void MainForm::viewOptions (void) Line 1962  void MainForm::viewOptions (void)
1962                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||                                  (!bOldMessagesLimit &&  m_pOptions->bMessagesLimit) ||
1963                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))                                  (iOldMessagesLimitLines !=  m_pOptions->iMessagesLimitLines))
1964                                  updateMessagesLimit();                                  updateMessagesLimit();
1965                            // Show restart needed message...
1966                            if (iNeedRestart > 0) {
1967                                    QMessageBox::information(this,
1968                                            tr("Information"),
1969                                            tr("Some settings may be only effective\n"
1970                                            "next time you start this program."));
1971                            }
1972                          // And now the main thing, whether we'll do client/server recycling?                          // And now the main thing, whether we'll do client/server recycling?
1973                          if ((sOldServerHost != m_pOptions->sServerHost) ||                          if ((sOldServerHost != m_pOptions->sServerHost) ||
1974                                  (iOldServerPort != m_pOptions->iServerPort) ||                                  (iOldServerPort != m_pOptions->iServerPort) ||
# Line 1801  void MainForm::viewOptions (void) Line 1989  void MainForm::viewOptions (void)
1989    
1990    
1991  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1992  // qsamplerMainForm -- Channels action slots.  // QSampler::MainForm -- Channels action slots.
1993    
1994  // Arrange channel strips.  // Arrange channel strips.
1995  void MainForm::channelsArrange (void)  void MainForm::channelsArrange (void)
1996  {  {
1997          // Full width vertical tiling          // Full width vertical tiling
1998          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
1999                    = m_pWorkspace->subWindowList();
2000          if (wlist.isEmpty())          if (wlist.isEmpty())
2001                  return;                  return;
2002    
2003          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2004          int y = 0;          int y = 0;
2005          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2006                  ChannelStrip *pChannelStrip = NULL;                  pMdiSubWindow->adjustSize();
2007                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                  const QRect& frameRect
2008                  if (pMdiSubWindow)                          = pMdiSubWindow->frameGeometry();
2009                          pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  int w = m_pWorkspace->width();
2010                  if (pChannelStrip) {                  if (w < frameRect.width())
2011                  /*  if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) {                          w = frameRect.width();
2012                                  // Prevent flicker...                  const int h = frameRect.height();
2013                                  pChannelStrip->hide();                  pMdiSubWindow->setGeometry(0, y, w, h);
2014                                  pChannelStrip->showNormal();                  y += h;
                         }   */  
                         pChannelStrip->adjustSize();  
                         int iWidth  = m_pWorkspace->width();  
                         if (iWidth < pChannelStrip->width())  
                                 iWidth = pChannelStrip->width();  
                 //  int iHeight = pChannelStrip->height()  
                 //              + pChannelStrip->parentWidget()->baseSize().height();  
                         int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();  
                         pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);  
                         y += iHeight;  
                 }  
2015          }          }
2016          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
2017    
# Line 1844  void MainForm::channelsArrange (void) Line 2022  void MainForm::channelsArrange (void)
2022  // Auto-arrange channel strips.  // Auto-arrange channel strips.
2023  void MainForm::channelsAutoArrange ( bool bOn )  void MainForm::channelsAutoArrange ( bool bOn )
2024  {  {
2025          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2026                  return;                  return;
2027    
2028          // Toggle the auto-arrange flag.          // Toggle the auto-arrange flag.
2029          m_pOptions->bAutoArrange = bOn;          m_pOptions->bAutoArrange = bOn;
2030    
2031          // If on, update whole workspace...          // If on, update whole workspace...
2032          if (m_pOptions->bAutoArrange)          channelsArrangeAuto();
2033    }
2034    
2035    
2036    void MainForm::channelsArrangeAuto (void)
2037    {
2038            if (m_pOptions && m_pOptions->bAutoArrange)
2039                  channelsArrange();                  channelsArrange();
2040  }  }
2041    
2042    
2043  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2044  // qsamplerMainForm -- Help Action slots.  // QSampler::MainForm -- Help Action slots.
2045    
2046  // Show information about the Qt toolkit.  // Show information about the Qt toolkit.
2047  void MainForm::helpAboutQt (void)  void MainForm::helpAboutQt (void)
# Line 1869  void MainForm::helpAboutQt (void) Line 2053  void MainForm::helpAboutQt (void)
2053  // Show information about application program.  // Show information about application program.
2054  void MainForm::helpAbout (void)  void MainForm::helpAbout (void)
2055  {  {
2056          // 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";  
2057  #ifdef CONFIG_DEBUG  #ifdef CONFIG_DEBUG
2058          sText += "<small><font color=\"red\">";          list << tr("Debugging option enabled.");
         sText += tr("Debugging option enabled.");  
         sText += "</font></small><br />";  
2059  #endif  #endif
2060  #ifndef CONFIG_LIBGIG  #ifndef CONFIG_LIBGIG
2061          sText += "<small><font color=\"red\">";          list << tr("GIG (libgig) file support disabled.");
         sText += tr("GIG (libgig) file support disabled.");  
         sText += "</font></small><br />";  
2062  #endif  #endif
2063  #ifndef CONFIG_INSTRUMENT_NAME  #ifndef CONFIG_INSTRUMENT_NAME
2064          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 />";  
2065  #endif  #endif
2066  #ifndef CONFIG_MUTE_SOLO  #ifndef CONFIG_MUTE_SOLO
2067          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 />";  
2068  #endif  #endif
2069  #ifndef CONFIG_AUDIO_ROUTING  #ifndef CONFIG_AUDIO_ROUTING
2070          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 />";  
2071  #endif  #endif
2072  #ifndef CONFIG_FXSEND  #ifndef CONFIG_FXSEND
2073          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 />";  
2074  #endif  #endif
2075  #ifndef CONFIG_VOLUME  #ifndef CONFIG_VOLUME
2076          sText += "<small><font color=\"red\">";          list << tr("Global volume support disabled.");
         sText += tr("Global volume support disabled.");  
         sText += "</font></small><br />";  
2077  #endif  #endif
2078  #ifndef CONFIG_MIDI_INSTRUMENT  #ifndef CONFIG_MIDI_INSTRUMENT
2079          sText += "<small><font color=\"red\">";          list << tr("MIDI instrument mapping support disabled.");
         sText += tr("MIDI instrument mapping support disabled.");  
         sText += "</font></small><br />";  
2080  #endif  #endif
2081  #ifndef CONFIG_EDIT_INSTRUMENT  #ifndef CONFIG_EDIT_INSTRUMENT
2082          sText += "<small><font color=\"red\">";          list << tr("Instrument editing support disabled.");
         sText += tr("Instrument editing support disabled.");  
         sText += "</font></small><br />";  
2083  #endif  #endif
2084  #ifndef CONFIG_EVENT_CHANNEL_MIDI  #ifndef CONFIG_EVENT_CHANNEL_MIDI
2085          sText += "<small><font color=\"red\">";          list << tr("Channel MIDI event support disabled.");
         sText += tr("Channel MIDI event support disabled.");  
         sText += "</font></small><br />";  
2086  #endif  #endif
2087  #ifndef CONFIG_EVENT_DEVICE_MIDI  #ifndef CONFIG_EVENT_DEVICE_MIDI
2088          sText += "<small><font color=\"red\">";          list << tr("Device MIDI event support disabled.");
         sText += tr("Device MIDI event support disabled.");  
         sText += "</font></small><br />";  
2089  #endif  #endif
2090  #ifndef CONFIG_MAX_VOICES  #ifndef CONFIG_MAX_VOICES
2091          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 />";  
2092  #endif  #endif
2093    
2094            // Stuff the about box text...
2095            QString sText = "<p>\n";
2096            sText += "<b>" QSAMPLER_TITLE " - " + tr(QSAMPLER_SUBTITLE) + "</b><br />\n";
2097            sText += "<br />\n";
2098            sText += tr("Version") + ": <b>" CONFIG_BUILD_VERSION "</b><br />\n";
2099    //      sText += "<small>" + tr("Build") + ": " CONFIG_BUILD_DATE "</small><br />\n";
2100            if (!list.isEmpty()) {
2101                    sText += "<small><font color=\"red\">";
2102                    sText += list.join("<br />\n");
2103                    sText += "</font></small>";
2104            }
2105          sText += "<br />\n";          sText += "<br />\n";
2106          sText += tr("Using") + ": ";          sText += tr("Using: Qt %1").arg(qVersion());
2107    #if defined(QT_STATIC)
2108            sText += "-static";
2109    #endif
2110            sText += ", ";
2111          sText += ::lscp_client_package();          sText += ::lscp_client_package();
2112          sText += " ";          sText += " ";
2113          sText += ::lscp_client_version();          sText += ::lscp_client_version();
# Line 1959  void MainForm::helpAbout (void) Line 2130  void MainForm::helpAbout (void)
2130          sText += "</small>";          sText += "</small>";
2131          sText += "</p>\n";          sText += "</p>\n";
2132    
2133          QMessageBox::about(this, tr("About") + " " QSAMPLER_TITLE, sText);          QMessageBox::about(this, tr("About"), sText);
2134  }  }
2135    
2136    
2137  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2138  // qsamplerMainForm -- Main window stabilization.  // QSampler::MainForm -- Main window stabilization.
2139    
2140  void MainForm::stabilizeForm (void)  void MainForm::stabilizeForm (void)
2141  {  {
# Line 1972  void MainForm::stabilizeForm (void) Line 2143  void MainForm::stabilizeForm (void)
2143          QString sSessionName = sessionName(m_sFilename);          QString sSessionName = sessionName(m_sFilename);
2144          if (m_iDirtyCount > 0)          if (m_iDirtyCount > 0)
2145                  sSessionName += " *";                  sSessionName += " *";
2146          setWindowTitle(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));          setWindowTitle(sSessionName);
2147    
2148          // Update the main menu state...          // Update the main menu state...
2149          ChannelStrip *pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
2150          bool bHasClient = (m_pOptions != NULL && m_pClient != NULL);          const QList<QMdiSubWindow *>& wlist = m_pWorkspace->subWindowList();
2151          bool bHasChannel = (bHasClient && pChannelStrip != NULL);          const bool bHasClient = (m_pOptions != nullptr && m_pClient != nullptr);
2152          bool bHasChannels = (bHasClient && m_pWorkspace->subWindowList().count() > 0);          const bool bHasChannel = (bHasClient && pChannelStrip != nullptr);
2153            const bool bHasChannels = (bHasClient && wlist.count() > 0);
2154          m_ui.fileNewAction->setEnabled(bHasClient);          m_ui.fileNewAction->setEnabled(bHasClient);
2155          m_ui.fileOpenAction->setEnabled(bHasClient);          m_ui.fileOpenAction->setEnabled(bHasClient);
2156          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);
2157          m_ui.fileSaveAsAction->setEnabled(bHasClient);          m_ui.fileSaveAsAction->setEnabled(bHasClient);
2158          m_ui.fileResetAction->setEnabled(bHasClient);          m_ui.fileResetAction->setEnabled(bHasClient);
2159          m_ui.fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);          m_ui.fileRestartAction->setEnabled(bHasClient || m_pServer == nullptr);
2160          m_ui.editAddChannelAction->setEnabled(bHasClient);          m_ui.editAddChannelAction->setEnabled(bHasClient);
2161          m_ui.editRemoveChannelAction->setEnabled(bHasChannel);          m_ui.editRemoveChannelAction->setEnabled(bHasChannel);
2162          m_ui.editSetupChannelAction->setEnabled(bHasChannel);          m_ui.editSetupChannelAction->setEnabled(bHasChannel);
# Line 2058  void MainForm::volumeChanged ( int iVolu Line 2230  void MainForm::volumeChanged ( int iVolu
2230                  m_pVolumeSpinBox->setValue(iVolume);                  m_pVolumeSpinBox->setValue(iVolume);
2231    
2232          // Do it as commanded...          // Do it as commanded...
2233          float fVolume = 0.01f * float(iVolume);          const float fVolume = 0.01f * float(iVolume);
2234          if (::lscp_set_volume(m_pClient, fVolume) == LSCP_OK)          if (::lscp_set_volume(m_pClient, fVolume) == LSCP_OK)
2235                  appendMessages(QObject::tr("Volume: %1.").arg(fVolume));                  appendMessages(QObject::tr("Volume: %1.").arg(fVolume));
2236          else          else
# Line 2093  void MainForm::channelStripChanged ( Cha Line 2265  void MainForm::channelStripChanged ( Cha
2265  void MainForm::updateSession (void)  void MainForm::updateSession (void)
2266  {  {
2267  #ifdef CONFIG_VOLUME  #ifdef CONFIG_VOLUME
2268          int iVolume = ::lroundf(100.0f * ::lscp_get_volume(m_pClient));          const int iVolume = ::lroundf(100.0f * ::lscp_get_volume(m_pClient));
2269          m_iVolumeChanging++;          m_iVolumeChanging++;
2270          m_pVolumeSlider->setValue(iVolume);          m_pVolumeSlider->setValue(iVolume);
2271          m_pVolumeSpinBox->setValue(iVolume);          m_pVolumeSpinBox->setValue(iVolume);
# Line 2101  void MainForm::updateSession (void) Line 2273  void MainForm::updateSession (void)
2273  #endif  #endif
2274  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
2275          // FIXME: Make some room for default instrument maps...          // FIXME: Make some room for default instrument maps...
2276          int iMaps = ::lscp_get_midi_instrument_maps(m_pClient);          const int iMaps = ::lscp_get_midi_instrument_maps(m_pClient);
2277          if (iMaps < 0)          if (iMaps < 0)
2278                  appendMessagesClient("lscp_get_midi_instrument_maps");                  appendMessagesClient("lscp_get_midi_instrument_maps");
2279          else if (iMaps < 1) {          else if (iMaps < 1) {
# Line 2115  void MainForm::updateSession (void) Line 2287  void MainForm::updateSession (void)
2287          updateAllChannelStrips(false);          updateAllChannelStrips(false);
2288    
2289          // Do we auto-arrange?          // Do we auto-arrange?
2290          if (m_pOptions && m_pOptions->bAutoArrange)          channelsArrangeAuto();
                 channelsArrange();  
2291    
2292          // Remember to refresh devices and instruments...          // Remember to refresh devices and instruments...
2293          if (m_pInstrumentListForm)          if (m_pInstrumentListForm)
# Line 2128  void MainForm::updateSession (void) Line 2299  void MainForm::updateSession (void)
2299    
2300  void MainForm::updateAllChannelStrips ( bool bRemoveDeadStrips )  void MainForm::updateAllChannelStrips ( bool bRemoveDeadStrips )
2301  {  {
2302            // Skip if setting up a new channel strip...
2303            if (m_iDirtySetup > 0)
2304                    return;
2305    
2306          // Retrieve the current channel list.          // Retrieve the current channel list.
2307          int *piChannelIDs = ::lscp_list_channels(m_pClient);          int *piChannelIDs = ::lscp_list_channels(m_pClient);
2308          if (piChannelIDs == NULL) {          if (piChannelIDs == nullptr) {
2309                  if (::lscp_client_get_errno(m_pClient)) {                  if (::lscp_client_get_errno(m_pClient)) {
2310                          appendMessagesClient("lscp_list_channels");                          appendMessagesClient("lscp_list_channels");
2311                          appendMessagesError(                          appendMessagesError(
# Line 2145  void MainForm::updateAllChannelStrips ( Line 2320  void MainForm::updateAllChannelStrips (
2320                                  createChannelStrip(new Channel(piChannelIDs[iChannel]));                                  createChannelStrip(new Channel(piChannelIDs[iChannel]));
2321                  }                  }
2322                  // Do we auto-arrange?                  // Do we auto-arrange?
2323                  if (m_pOptions && m_pOptions->bAutoArrange)                  channelsArrangeAuto();
                         channelsArrange();  
2324                  // remove dead channel strips                  // remove dead channel strips
2325                  if (bRemoveDeadStrips) {                  if (bRemoveDeadStrips) {
2326                          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();                          const QList<QMdiSubWindow *>& wlist
2327                          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {                                  = m_pWorkspace->subWindowList();
2328                                  ChannelStrip *pChannelStrip = NULL;                          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2329                                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                                  ChannelStrip *pChannelStrip
2330                                  if (pMdiSubWindow)                                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2331                                  if (pChannelStrip) {                                  if (pChannelStrip) {
2332                                          bool bExists = false;                                          bool bExists = false;
2333                                          for (int j = 0; piChannelIDs[j] >= 0; ++j) {                                          for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {
2334                                                  if (!pChannelStrip->channel())                                                  Channel *pChannel = pChannelStrip->channel();
2335                                                    if (pChannel == nullptr)
2336                                                          break;                                                          break;
2337                                                  if (piChannelIDs[j] == pChannelStrip->channel()->channelID()) {                                                  if (piChannelIDs[iChannel] == pChannel->channelID()) {
2338                                                          // strip exists, don't touch it                                                          // strip exists, don't touch it
2339                                                          bExists = true;                                                          bExists = true;
2340                                                          break;                                                          break;
# Line 2181  void MainForm::updateAllChannelStrips ( Line 2355  void MainForm::updateAllChannelStrips (
2355  // Update the recent files list and menu.  // Update the recent files list and menu.
2356  void MainForm::updateRecentFiles ( const QString& sFilename )  void MainForm::updateRecentFiles ( const QString& sFilename )
2357  {  {
2358          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2359                  return;                  return;
2360    
2361          // Remove from list if already there (avoid duplicates)          // Remove from list if already there (avoid duplicates)
2362          int iIndex = m_pOptions->recentFiles.indexOf(sFilename);          const int iIndex = m_pOptions->recentFiles.indexOf(sFilename);
2363          if (iIndex >= 0)          if (iIndex >= 0)
2364                  m_pOptions->recentFiles.removeAt(iIndex);                  m_pOptions->recentFiles.removeAt(iIndex);
2365          // Put it to front...          // Put it to front...
# Line 2196  void MainForm::updateRecentFiles ( const Line 2370  void MainForm::updateRecentFiles ( const
2370  // Update the recent files list and menu.  // Update the recent files list and menu.
2371  void MainForm::updateRecentFilesMenu (void)  void MainForm::updateRecentFilesMenu (void)
2372  {  {
2373          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2374                  return;                  return;
2375    
2376          // Time to keep the list under limits.          // Time to keep the list under limits.
# Line 2224  void MainForm::updateRecentFilesMenu (vo Line 2398  void MainForm::updateRecentFilesMenu (vo
2398  void MainForm::updateInstrumentNames (void)  void MainForm::updateInstrumentNames (void)
2399  {  {
2400          // Full channel list update...          // Full channel list update...
2401          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
2402                    = m_pWorkspace->subWindowList();
2403          if (wlist.isEmpty())          if (wlist.isEmpty())
2404                  return;                  return;
2405    
2406          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2407          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2408                  ChannelStrip *pChannelStrip = (ChannelStrip *) wlist.at(iChannel);                  ChannelStrip *pChannelStrip
2409                            = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2410                  if (pChannelStrip)                  if (pChannelStrip)
2411                          pChannelStrip->updateInstrumentName(true);                          pChannelStrip->updateInstrumentName(true);
2412          }          }
# Line 2241  void MainForm::updateInstrumentNames (vo Line 2417  void MainForm::updateInstrumentNames (vo
2417  // Force update of the channels display font.  // Force update of the channels display font.
2418  void MainForm::updateDisplayFont (void)  void MainForm::updateDisplayFont (void)
2419  {  {
2420          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2421                  return;                  return;
2422    
2423          // Check if display font is legal.          // Check if display font is legal.
2424          if (m_pOptions->sDisplayFont.isEmpty())          if (m_pOptions->sDisplayFont.isEmpty())
2425                  return;                  return;
2426    
2427          // Realize it.          // Realize it.
2428          QFont font;          QFont font;
2429          if (!font.fromString(m_pOptions->sDisplayFont))          if (!font.fromString(m_pOptions->sDisplayFont))
2430                  return;                  return;
2431    
2432          // Full channel list update...          // Full channel list update...
2433          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
2434                    = m_pWorkspace->subWindowList();
2435          if (wlist.isEmpty())          if (wlist.isEmpty())
2436                  return;                  return;
2437    
2438          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2439          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2440                  ChannelStrip *pChannelStrip = NULL;                  ChannelStrip *pChannelStrip
2441                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2442                  if (pChannelStrip)                  if (pChannelStrip)
2443                          pChannelStrip->setDisplayFont(font);                          pChannelStrip->setDisplayFont(font);
2444          }          }
# Line 2274  void MainForm::updateDisplayFont (void) Line 2450  void MainForm::updateDisplayFont (void)
2450  void MainForm::updateDisplayEffect (void)  void MainForm::updateDisplayEffect (void)
2451  {  {
2452          // Full channel list update...          // Full channel list update...
2453          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
2454                    = m_pWorkspace->subWindowList();
2455          if (wlist.isEmpty())          if (wlist.isEmpty())
2456                  return;                  return;
2457    
2458          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2459          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2460                  ChannelStrip *pChannelStrip = NULL;                  ChannelStrip *pChannelStrip
2461                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2462                  if (pChannelStrip)                  if (pChannelStrip)
2463                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
2464          }          }
# Line 2294  void MainForm::updateDisplayEffect (void Line 2469  void MainForm::updateDisplayEffect (void
2469  // Force update of the channels maximum volume setting.  // Force update of the channels maximum volume setting.
2470  void MainForm::updateMaxVolume (void)  void MainForm::updateMaxVolume (void)
2471  {  {
2472          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2473                  return;                  return;
2474    
2475  #ifdef CONFIG_VOLUME  #ifdef CONFIG_VOLUME
# Line 2305  void MainForm::updateMaxVolume (void) Line 2480  void MainForm::updateMaxVolume (void)
2480  #endif  #endif
2481    
2482          // Full channel list update...          // Full channel list update...
2483          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
2484                    = m_pWorkspace->subWindowList();
2485          if (wlist.isEmpty())          if (wlist.isEmpty())
2486                  return;                  return;
2487    
2488          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2489          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2490                  ChannelStrip *pChannelStrip = NULL;                  ChannelStrip *pChannelStrip
2491                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2492                  if (pChannelStrip)                  if (pChannelStrip)
2493                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2494          }          }
# Line 2323  void MainForm::updateMaxVolume (void) Line 2497  void MainForm::updateMaxVolume (void)
2497    
2498    
2499  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2500  // qsamplerMainForm -- Messages window form handlers.  // QSampler::MainForm -- Messages window form handlers.
2501    
2502  // Messages output methods.  // Messages output methods.
2503  void MainForm::appendMessages( const QString& s )  void MainForm::appendMessages ( const QString& s )
2504  {  {
2505          if (m_pMessages)          if (m_pMessages)
2506                  m_pMessages->appendMessages(s);                  m_pMessages->appendMessages(s);
# Line 2334  void MainForm::appendMessages( const QSt Line 2508  void MainForm::appendMessages( const QSt
2508          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2509  }  }
2510    
2511  void MainForm::appendMessagesColor( const QString& s, const QString& c )  void MainForm::appendMessagesColor ( const QString& s, const QColor& rgb )
2512  {  {
2513          if (m_pMessages)          if (m_pMessages)
2514                  m_pMessages->appendMessagesColor(s, c);                  m_pMessages->appendMessagesColor(s, rgb);
2515    
2516          statusBar()->showMessage(s, 3000);          statusBar()->showMessage(s, 3000);
2517  }  }
2518    
2519  void MainForm::appendMessagesText( const QString& s )  void MainForm::appendMessagesText ( const QString& s )
2520  {  {
2521          if (m_pMessages)          if (m_pMessages)
2522                  m_pMessages->appendMessagesText(s);                  m_pMessages->appendMessagesText(s);
2523  }  }
2524    
2525  void MainForm::appendMessagesError( const QString& s )  void MainForm::appendMessagesError ( const QString& s )
2526  {  {
2527          if (m_pMessages)          if (m_pMessages)
2528                  m_pMessages->show();                  m_pMessages->show();
2529    
2530          appendMessagesColor(s.simplified(), "#ff0000");          appendMessagesColor(s.simplified(), Qt::red);
2531    
2532          // Make it look responsive...:)          // Make it look responsive...:)
2533          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2534    
2535          QMessageBox::critical(this,          if (m_pOptions && m_pOptions->bConfirmError) {
2536                  QSAMPLER_TITLE ": " + tr("Error"), s, QMessageBox::Cancel);                  const QString& sTitle = tr("Error");
2537            #if 0
2538                    QMessageBox::critical(this, sTitle, sText, QMessageBox::Cancel);
2539            #else
2540                    QMessageBox mbox(this);
2541                    mbox.setIcon(QMessageBox::Critical);
2542                    mbox.setWindowTitle(sTitle);
2543                    mbox.setText(s);
2544                    mbox.setStandardButtons(QMessageBox::Cancel);
2545                    QCheckBox cbox(tr("Don't show this again"));
2546                    cbox.setChecked(false);
2547                    cbox.blockSignals(true);
2548                    mbox.addButton(&cbox, QMessageBox::ActionRole);
2549                    if (mbox.exec() && cbox.isChecked())
2550                            m_pOptions->bConfirmError = false;
2551            #endif
2552            }
2553  }  }
2554    
2555    
2556  // This is a special message format, just for client results.  // This is a special message format, just for client results.
2557  void MainForm::appendMessagesClient( const QString& s )  void MainForm::appendMessagesClient( const QString& s )
2558  {  {
2559          if (m_pClient == NULL)          if (m_pClient == nullptr)
2560                  return;                  return;
2561    
2562          appendMessagesColor(s + QString(": %1 (errno=%2)")          appendMessagesColor(s + QString(": %1 (errno=%2)")
# Line 2381  void MainForm::appendMessagesClient( con Line 2571  void MainForm::appendMessagesClient( con
2571  // Force update of the messages font.  // Force update of the messages font.
2572  void MainForm::updateMessagesFont (void)  void MainForm::updateMessagesFont (void)
2573  {  {
2574          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2575                  return;                  return;
2576    
2577          if (m_pMessages && !m_pOptions->sMessagesFont.isEmpty()) {          if (m_pMessages && !m_pOptions->sMessagesFont.isEmpty()) {
# Line 2395  void MainForm::updateMessagesFont (void) Line 2585  void MainForm::updateMessagesFont (void)
2585  // Update messages window line limit.  // Update messages window line limit.
2586  void MainForm::updateMessagesLimit (void)  void MainForm::updateMessagesLimit (void)
2587  {  {
2588          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2589                  return;                  return;
2590    
2591          if (m_pMessages) {          if (m_pMessages) {
# Line 2410  void MainForm::updateMessagesLimit (void Line 2600  void MainForm::updateMessagesLimit (void
2600  // Enablement of the messages capture feature.  // Enablement of the messages capture feature.
2601  void MainForm::updateMessagesCapture (void)  void MainForm::updateMessagesCapture (void)
2602  {  {
2603          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2604                  return;                  return;
2605    
2606          if (m_pMessages)          if (m_pMessages)
# Line 2419  void MainForm::updateMessagesCapture (vo Line 2609  void MainForm::updateMessagesCapture (vo
2609    
2610    
2611  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2612  // qsamplerMainForm -- MDI channel strip management.  // QSampler::MainForm -- MDI channel strip management.
2613    
2614  // The channel strip creation executive.  // The channel strip creation executive.
2615  ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel )  ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel )
2616  {  {
2617          if (m_pClient == NULL || pChannel == NULL)          if (m_pClient == nullptr || pChannel == nullptr)
2618                  return NULL;                  return nullptr;
2619    
2620          // Add a new channel itema...          // Add a new channel itema...
2621          ChannelStrip *pChannelStrip = new ChannelStrip();          ChannelStrip *pChannelStrip = new ChannelStrip();
2622          if (pChannelStrip == NULL)          if (pChannelStrip == nullptr)
2623                  return NULL;                  return nullptr;
2624    
2625          // Set some initial channel strip options...          // Set some initial channel strip options...
2626          if (m_pOptions) {          if (m_pOptions) {
# Line 2438  ChannelStrip *MainForm::createChannelStr Line 2628  ChannelStrip *MainForm::createChannelStr
2628                  pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                  pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
2629                  // We'll need a display font.                  // We'll need a display font.
2630                  QFont font;                  QFont font;
2631                  if (font.fromString(m_pOptions->sDisplayFont))                  if (!m_pOptions->sDisplayFont.isEmpty() &&
2632                            font.fromString(m_pOptions->sDisplayFont))
2633                          pChannelStrip->setDisplayFont(font);                          pChannelStrip->setDisplayFont(font);
2634                  // Maximum allowed volume setting.                  // Maximum allowed volume setting.
2635                  pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                  pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2636          }          }
2637    
2638          // Add it to workspace...          // Add it to workspace...
2639          m_pWorkspace->addSubWindow(pChannelStrip,          QMdiSubWindow *pMdiSubWindow
2640                  Qt::SubWindow | Qt::FramelessWindowHint);                  = m_pWorkspace->addSubWindow(pChannelStrip,
2641                            Qt::SubWindow | Qt::FramelessWindowHint);
2642            pMdiSubWindow->setAttribute(Qt::WA_DeleteOnClose);
2643    
2644          // Actual channel strip setup...          // Actual channel strip setup...
2645          pChannelStrip->setup(pChannel);          pChannelStrip->setup(pChannel);
# Line 2470  void MainForm::destroyChannelStrip ( Cha Line 2663  void MainForm::destroyChannelStrip ( Cha
2663  {  {
2664          QMdiSubWindow *pMdiSubWindow          QMdiSubWindow *pMdiSubWindow
2665                  = static_cast<QMdiSubWindow *> (pChannelStrip->parentWidget());                  = static_cast<QMdiSubWindow *> (pChannelStrip->parentWidget());
2666          if (pMdiSubWindow == NULL)          if (pMdiSubWindow == nullptr)
2667                  return;                  return;
2668    
2669          // Just delete the channel strip.          // Just delete the channel strip.
# Line 2478  void MainForm::destroyChannelStrip ( Cha Line 2671  void MainForm::destroyChannelStrip ( Cha
2671          delete pMdiSubWindow;          delete pMdiSubWindow;
2672    
2673          // Do we auto-arrange?          // Do we auto-arrange?
2674          if (m_pOptions && m_pOptions->bAutoArrange)          channelsArrangeAuto();
                 channelsArrange();  
   
         stabilizeForm();  
2675  }  }
2676    
2677    
# Line 2492  ChannelStrip *MainForm::activeChannelStr Line 2682  ChannelStrip *MainForm::activeChannelStr
2682          if (pMdiSubWindow)          if (pMdiSubWindow)
2683                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2684          else          else
2685                  return NULL;                  return nullptr;
2686  }  }
2687    
2688    
2689  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
2690  ChannelStrip *MainForm::channelStripAt ( int iChannel )  ChannelStrip *MainForm::channelStripAt ( int iStrip )
2691  {  {
2692          if (!m_pWorkspace) return NULL;          if (!m_pWorkspace) return nullptr;
2693    
2694          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
2695                    = m_pWorkspace->subWindowList();
2696          if (wlist.isEmpty())          if (wlist.isEmpty())
2697                  return NULL;                  return nullptr;
2698    
2699          if (iChannel < 0 || iChannel >= wlist.size())          if (iStrip < 0 || iStrip >= wlist.count())
2700                  return NULL;                  return nullptr;
2701    
2702          QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);          QMdiSubWindow *pMdiSubWindow = wlist.at(iStrip);
2703          if (pMdiSubWindow)          if (pMdiSubWindow)
2704                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2705          else          else
2706                  return NULL;                  return nullptr;
2707  }  }
2708    
2709    
2710  // Retrieve a channel strip by sampler channel id.  // Retrieve a channel strip by sampler channel id.
2711  ChannelStrip *MainForm::channelStrip ( int iChannelID )  ChannelStrip *MainForm::channelStrip ( int iChannelID )
2712  {  {
2713          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
2714                    = m_pWorkspace->subWindowList();
2715          if (wlist.isEmpty())          if (wlist.isEmpty())
2716                  return NULL;                  return nullptr;
2717    
2718          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {          foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2719                  ChannelStrip *pChannelStrip = NULL;                  ChannelStrip *pChannelStrip
2720                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                          = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                 if (pMdiSubWindow)  
                         pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2721                  if (pChannelStrip) {                  if (pChannelStrip) {
2722                          Channel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
2723                          if (pChannel && pChannel->channelID() == iChannelID)                          if (pChannel && pChannel->channelID() == iChannelID)
# Line 2536  ChannelStrip *MainForm::channelStrip ( i Line 2726  ChannelStrip *MainForm::channelStrip ( i
2726          }          }
2727    
2728          // Not found.          // Not found.
2729          return NULL;          return nullptr;
2730  }  }
2731    
2732    
# Line 2547  void MainForm::channelsMenuAboutToShow ( Line 2737  void MainForm::channelsMenuAboutToShow (
2737          m_ui.channelsMenu->addAction(m_ui.channelsArrangeAction);          m_ui.channelsMenu->addAction(m_ui.channelsArrangeAction);
2738          m_ui.channelsMenu->addAction(m_ui.channelsAutoArrangeAction);          m_ui.channelsMenu->addAction(m_ui.channelsAutoArrangeAction);
2739    
2740          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();          const QList<QMdiSubWindow *>& wlist
2741                    = m_pWorkspace->subWindowList();
2742          if (!wlist.isEmpty()) {          if (!wlist.isEmpty()) {
2743                  m_ui.channelsMenu->addSeparator();                  m_ui.channelsMenu->addSeparator();
2744                  for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {                  int iStrip = 0;
2745                          ChannelStrip *pChannelStrip = NULL;                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2746                          QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                          ChannelStrip *pChannelStrip
2747                          if (pMdiSubWindow)                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2748                          if (pChannelStrip) {                          if (pChannelStrip) {
2749                                  QAction *pAction = m_ui.channelsMenu->addAction(                                  QAction *pAction = m_ui.channelsMenu->addAction(
2750                                          pChannelStrip->windowTitle(),                                          pChannelStrip->windowTitle(),
2751                                          this, SLOT(channelsMenuActivated()));                                          this, SLOT(channelsMenuActivated()));
2752                                  pAction->setCheckable(true);                                  pAction->setCheckable(true);
2753                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);                                  pAction->setChecked(activeChannelStrip() == pChannelStrip);
2754                                  pAction->setData(iChannel);                                  pAction->setData(iStrip);
2755                          }                          }
2756                            ++iStrip;
2757                  }                  }
2758          }          }
2759  }  }
# Line 2573  void MainForm::channelsMenuActivated (vo Line 2764  void MainForm::channelsMenuActivated (vo
2764  {  {
2765          // Retrive channel index from action data...          // Retrive channel index from action data...
2766          QAction *pAction = qobject_cast<QAction *> (sender());          QAction *pAction = qobject_cast<QAction *> (sender());
2767          if (pAction == NULL)          if (pAction == nullptr)
2768                  return;                  return;
2769    
2770          ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt());          ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt());
# Line 2585  void MainForm::channelsMenuActivated (vo Line 2776  void MainForm::channelsMenuActivated (vo
2776    
2777    
2778  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2779  // qsamplerMainForm -- Timer stuff.  // QSampler::MainForm -- Timer stuff.
2780    
2781  // Set the pseudo-timer delay schedule.  // Set the pseudo-timer delay schedule.
2782  void MainForm::startSchedule ( int iStartDelay )  void MainForm::startSchedule ( int iStartDelay )
# Line 2604  void MainForm::stopSchedule (void) Line 2795  void MainForm::stopSchedule (void)
2795  // Timer slot funtion.  // Timer slot funtion.
2796  void MainForm::timerSlot (void)  void MainForm::timerSlot (void)
2797  {  {
2798          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2799                  return;                  return;
2800    
2801          // 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 2626  void MainForm::timerSlot (void) Line 2817  void MainForm::timerSlot (void)
2817                          ChannelStrip *pChannelStrip = iter.next();                          ChannelStrip *pChannelStrip = iter.next();
2818                          // If successfull, remove from pending list...                          // If successfull, remove from pending list...
2819                          if (pChannelStrip->updateChannelInfo()) {                          if (pChannelStrip->updateChannelInfo()) {
2820                                  int iChannelStrip = m_changedStrips.indexOf(pChannelStrip);                                  const int iChannelStrip = m_changedStrips.indexOf(pChannelStrip);
2821                                  if (iChannelStrip >= 0)                                  if (iChannelStrip >= 0)
2822                                          m_changedStrips.removeAt(iChannelStrip);                                          m_changedStrips.removeAt(iChannelStrip);
2823                          }                          }
# Line 2637  void MainForm::timerSlot (void) Line 2828  void MainForm::timerSlot (void)
2828                          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {                          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {
2829                                  m_iTimerSlot = 0;                                  m_iTimerSlot = 0;
2830                                  // Update the channel stream usage for each strip...                                  // Update the channel stream usage for each strip...
2831                                  QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();                                  const QList<QMdiSubWindow *>& wlist
2832                                  for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {                                          = m_pWorkspace->subWindowList();
2833                                          ChannelStrip *pChannelStrip = NULL;                                  foreach (QMdiSubWindow *pMdiSubWindow, wlist) {
2834                                          QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);                                          ChannelStrip *pChannelStrip
2835                                          if (pMdiSubWindow)                                                  = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
                                                 pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());  
2836                                          if (pChannelStrip && pChannelStrip->isVisible())                                          if (pChannelStrip && pChannelStrip->isVisible())
2837                                                  pChannelStrip->updateChannelUsage();                                                  pChannelStrip->updateChannelUsage();
2838                                  }                                  }
2839                          }                          }
2840                  }                  }
2841    
2842            #if CONFIG_LSCP_CLIENT_CONNECTION_LOST
2843                    // If we lost connection to server: Try to automatically reconnect if we
2844                    // did not start the server.
2845                    //
2846                    // TODO: If we started the server, then we might inform the user that
2847                    // the server probably crashed and asking user ONCE whether we should
2848                    // restart the server.
2849                    if (lscp_client_connection_lost(m_pClient) && !m_pServer)
2850                            startAutoReconnectClient();
2851            #endif // CONFIG_LSCP_CLIENT_CONNECTION_LOST
2852          }          }
2853    
2854          // Register the next timer slot.          // Register the next timer slot.
# Line 2656  void MainForm::timerSlot (void) Line 2857  void MainForm::timerSlot (void)
2857    
2858    
2859  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
2860  // qsamplerMainForm -- Server stuff.  // QSampler::MainForm -- Server stuff.
2861    
2862  // Start linuxsampler server...  // Start linuxsampler server...
2863  void MainForm::startServer (void)  void MainForm::startServer (void)
2864  {  {
2865          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
2866                  return;                  return;
2867    
2868          // Aren't already a client, are we?          // Aren't already a client, are we?
# Line 2671  void MainForm::startServer (void) Line 2872  void MainForm::startServer (void)
2872          // Is the server process instance still here?          // Is the server process instance still here?
2873          if (m_pServer) {          if (m_pServer) {
2874                  if (QMessageBox::warning(this,                  if (QMessageBox::warning(this,
2875                          QSAMPLER_TITLE ": " + tr("Warning"),                          tr("Warning"),
2876                          tr("Could not start the LinuxSampler server.\n\n"                          tr("Could not start the LinuxSampler server.\n\n"
2877                          "Maybe it is already started."),                          "Maybe it is already started."),
2878                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
# Line 2690  void MainForm::startServer (void) Line 2891  void MainForm::startServer (void)
2891    
2892          // OK. Let's build the startup process...          // OK. Let's build the startup process...
2893          m_pServer = new QProcess();          m_pServer = new QProcess();
2894          bForceServerStop = true;          m_bForceServerStop = true;
2895    
2896          // Setup stdout/stderr capture...          // Setup stdout/stderr capture...
2897  //      if (m_pOptions->bStdoutCapture) {          m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);
2898                  m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);          QObject::connect(m_pServer,
2899                  QObject::connect(m_pServer,                  SIGNAL(readyReadStandardOutput()),
2900                          SIGNAL(readyReadStandardOutput()),                  SLOT(readServerStdout()));
2901                          SLOT(readServerStdout()));          QObject::connect(m_pServer,
2902                  QObject::connect(m_pServer,                  SIGNAL(readyReadStandardError()),
2903                          SIGNAL(readyReadStandardError()),                  SLOT(readServerStdout()));
                         SLOT(readServerStdout()));  
 //      }  
2904    
2905          // The unforgiveable signal communication...          // The unforgiveable signal communication...
2906          QObject::connect(m_pServer,          QObject::connect(m_pServer,
# Line 2726  void MainForm::startServer (void) Line 2925  void MainForm::startServer (void)
2925    
2926          // Show startup results...          // Show startup results...
2927          appendMessages(          appendMessages(
2928                  tr("Server was started with PID=%1.").arg((long) m_pServer->pid()));                  tr("Server was started with PID=%1.")
2929                    #if QT_VERSION < QT_VERSION_CHECK(5, 3, 0)
2930                            .arg(quint64(m_pServer->pid())));
2931                    #else
2932                            .arg(quint64(m_pServer->processId())));
2933                    #endif
2934    
2935          // Reset (yet again) the timer counters,          // Reset (yet again) the timer counters,
2936          // but this time is deferred as the user opted.          // but this time is deferred as the user opted.
# Line 2736  void MainForm::startServer (void) Line 2940  void MainForm::startServer (void)
2940    
2941    
2942  // Stop linuxsampler server...  // Stop linuxsampler server...
2943  void MainForm::stopServer (bool bInteractive)  void MainForm::stopServer ( bool bInteractive )
2944  {  {
2945          // Stop client code.          // Stop client code.
2946          stopClient();          stopClient();
2947    
2948          if (m_pServer && bInteractive) {          if (m_pServer && bInteractive) {
2949                  if (QMessageBox::question(this,                  if (QMessageBox::question(this,
2950                          QSAMPLER_TITLE ": " + tr("The backend's fate ..."),                          tr("The backend's fate ..."),
2951                          tr("You have the option to keep the sampler backend (LinuxSampler)\n"                          tr("You have the option to keep the sampler backend (LinuxSampler)\n"
2952                          "running in the background. The sampler would continue to work\n"                          "running in the background. The sampler would continue to work\n"
2953                          "according to your current sampler session and you could alter the\n"                          "according to your current sampler session and you could alter the\n"
2954                          "sampler session at any time by relaunching QSampler.\n\n"                          "sampler session at any time by relaunching QSampler.\n\n"
2955                          "Do you want LinuxSampler to stop?"),                          "Do you want LinuxSampler to stop?"),
2956                          QMessageBox::Yes | QMessageBox::No,                          QMessageBox::Yes | QMessageBox::No,
2957                          QMessageBox::Yes) == QMessageBox::No)                          QMessageBox::Yes) == QMessageBox::No) {
2958                  {                          m_bForceServerStop = false;
                         bForceServerStop = false;  
2959                  }                  }
2960          }          }
2961    
2962            bool bGraceWait = true;
2963    
2964          // And try to stop server.          // And try to stop server.
2965          if (m_pServer && bForceServerStop) {          if (m_pServer && m_bForceServerStop) {
2966                  appendMessages(tr("Server is stopping..."));                  appendMessages(tr("Server is stopping..."));
2967                  if (m_pServer->state() == QProcess::Running) {                  if (m_pServer->state() == QProcess::Running) {
2968                  #if defined(WIN32)                  #if defined(__WIN32__) || defined(_WIN32) || defined(WIN32)
2969                          // Try harder...                          // Try harder...
2970                          m_pServer->kill();                          m_pServer->kill();
2971                  #else                  #else
2972                          // Try softly...                          // Try softly...
2973                          m_pServer->terminate();                          m_pServer->terminate();
2974                            bool bFinished = m_pServer->waitForFinished(QSAMPLER_TIMER_MSECS * 1000);
2975                            if (bFinished) bGraceWait = false;
2976                  #endif                  #endif
2977                  }                  }
2978          }       // Do final processing anyway.          }       // Do final processing anyway.
2979          else processServerExit();          else processServerExit();
2980    
2981          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2982          QTime t;          if (bGraceWait) {
2983          t.start();                  QElapsedTimer timer;
2984          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                  timer.start();
2985                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
2986                            QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2987            }
2988  }  }
2989    
2990    
# Line 2797  void MainForm::processServerExit (void) Line 3006  void MainForm::processServerExit (void)
3006          if (m_pMessages)          if (m_pMessages)
3007                  m_pMessages->flushStdoutBuffer();                  m_pMessages->flushStdoutBuffer();
3008    
3009          if (m_pServer && bForceServerStop) {          if (m_pServer && m_bForceServerStop) {
3010                  if (m_pServer->state() != QProcess::NotRunning) {                  if (m_pServer->state() != QProcess::NotRunning) {
3011                          appendMessages(tr("Server is being forced..."));                          appendMessages(tr("Server is being forced..."));
3012                          // Force final server shutdown...                          // Force final server shutdown...
3013                          m_pServer->kill();                          m_pServer->kill();
3014                          // Give it some time to terminate gracefully and stabilize...                          // Give it some time to terminate gracefully and stabilize...
3015                          QTime t;                          QElapsedTimer timer;
3016                          t.start();                          timer.start();
3017                          while (t.elapsed() < QSAMPLER_TIMER_MSECS)                          while (timer.elapsed() < QSAMPLER_TIMER_MSECS)
3018                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
3019                  }                  }
3020                  // Force final server shutdown...                  // Force final server shutdown...
# Line 2813  void MainForm::processServerExit (void) Line 3022  void MainForm::processServerExit (void)
3022                          tr("Server was stopped with exit status %1.")                          tr("Server was stopped with exit status %1.")
3023                          .arg(m_pServer->exitStatus()));                          .arg(m_pServer->exitStatus()));
3024                  delete m_pServer;                  delete m_pServer;
3025                  m_pServer = NULL;                  m_pServer = nullptr;
3026          }          }
3027    
3028          // Again, make status visible stable.          // Again, make status visible stable.
# Line 2822  void MainForm::processServerExit (void) Line 3031  void MainForm::processServerExit (void)
3031    
3032    
3033  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
3034  // qsamplerMainForm -- Client stuff.  // QSampler::MainForm -- Client stuff.
3035    
3036  // The LSCP client callback procedure.  // The LSCP client callback procedure.
3037  lscp_status_t qsampler_client_callback ( lscp_client_t */*pClient*/,  lscp_status_t qsampler_client_callback ( lscp_client_t */*pClient*/,
3038          lscp_event_t event, const char *pchData, int cchData, void *pvData )          lscp_event_t event, const char *pchData, int cchData, void *pvData )
3039  {  {
3040          MainForm* pMainForm = (MainForm *) pvData;          MainForm* pMainForm = (MainForm *) pvData;
3041          if (pMainForm == NULL)          if (pMainForm == nullptr)
3042                  return LSCP_FAILED;                  return LSCP_FAILED;
3043    
3044          // ATTN: DO NOT EVER call any GUI code here,          // ATTN: DO NOT EVER call any GUI code here,
# Line 2843  lscp_status_t qsampler_client_callback ( Line 3052  lscp_status_t qsampler_client_callback (
3052    
3053    
3054  // Start our almighty client...  // Start our almighty client...
3055  bool MainForm::startClient (void)  bool MainForm::startClient (bool bReconnectOnly)
3056  {  {
3057          // Have it a setup?          // Have it a setup?
3058          if (m_pOptions == NULL)          if (m_pOptions == nullptr)
3059                  return false;                  return false;
3060    
3061          // Aren't we already started, are we?          // Aren't we already started, are we?
# Line 2860  bool MainForm::startClient (void) Line 3069  bool MainForm::startClient (void)
3069          m_pClient = ::lscp_client_create(          m_pClient = ::lscp_client_create(
3070                  m_pOptions->sServerHost.toUtf8().constData(),                  m_pOptions->sServerHost.toUtf8().constData(),
3071                  m_pOptions->iServerPort, qsampler_client_callback, this);                  m_pOptions->iServerPort, qsampler_client_callback, this);
3072          if (m_pClient == NULL) {          if (m_pClient == nullptr) {
3073                  // Is this the first try?                  // Is this the first try?
3074                  // maybe we need to start a local server...                  // maybe we need to start a local server...
3075                  if ((m_pServer && m_pServer->state() == QProcess::Running)                  if ((m_pServer && m_pServer->state() == QProcess::Running)
3076                          || !m_pOptions->bServerStart) {                          || !m_pOptions->bServerStart || bReconnectOnly)
3077                          appendMessagesError(                  {
3078                                  tr("Could not connect to server as client.\n\nSorry."));                          // if this method is called from autoReconnectClient()
3079                            // then don't bother user with an error message...
3080                            if (!bReconnectOnly) {
3081                                    appendMessagesError(
3082                                            tr("Could not connect to server as client.\n\nSorry.")
3083                                    );
3084                            }
3085                  } else {                  } else {
3086                          startServer();                          startServer();
3087                  }                  }
# Line 2874  bool MainForm::startClient (void) Line 3089  bool MainForm::startClient (void)
3089                  stabilizeForm();                  stabilizeForm();
3090                  return false;                  return false;
3091          }          }
3092    
3093          // Just set receive timeout value, blindly.          // Just set receive timeout value, blindly.
3094          ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);          ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);
3095          appendMessages(          appendMessages(
# Line 2929  bool MainForm::startClient (void) Line 3145  bool MainForm::startClient (void)
3145          if (!m_pOptions->sSessionFile.isEmpty()) {          if (!m_pOptions->sSessionFile.isEmpty()) {
3146                  // Just load the prabably startup session...                  // Just load the prabably startup session...
3147                  if (loadSessionFile(m_pOptions->sSessionFile)) {                  if (loadSessionFile(m_pOptions->sSessionFile)) {
3148                          m_pOptions->sSessionFile = QString::null;                          m_pOptions->sSessionFile = QString();
3149                          return true;                          return true;
3150                  }                  }
3151          }          }
# Line 2945  bool MainForm::startClient (void) Line 3161  bool MainForm::startClient (void)
3161  // Stop client...  // Stop client...
3162  void MainForm::stopClient (void)  void MainForm::stopClient (void)
3163  {  {
3164          if (m_pClient == NULL)          if (m_pClient == nullptr)
3165                  return;                  return;
3166    
3167          // Log prepare here.          // Log prepare here.
# Line 2977  void MainForm::stopClient (void) Line 3193  void MainForm::stopClient (void)
3193          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
3194          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);
3195          ::lscp_client_destroy(m_pClient);          ::lscp_client_destroy(m_pClient);
3196          m_pClient = NULL;          m_pClient = nullptr;
3197    
3198          // Hard-notify instrumnet and device configuration forms,          // Hard-notify instrumnet and device configuration forms,
3199          // if visible, that we're running out...          // if visible, that we're running out...
# Line 2994  void MainForm::stopClient (void) Line 3210  void MainForm::stopClient (void)
3210  }  }
3211    
3212    
3213    void MainForm::startAutoReconnectClient (void)
3214    {
3215            stopClient();
3216            appendMessages(tr("Trying to reconnect..."));
3217            QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3218    }
3219    
3220    
3221    void MainForm::autoReconnectClient (void)
3222    {
3223            const bool bSuccess = startClient(true);
3224            if (!bSuccess)
3225                    QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(autoReconnectClient()));
3226    }
3227    
3228    
3229  // Channel strip activation/selection.  // Channel strip activation/selection.
3230  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )  void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )
3231  {  {
3232          ChannelStrip *pChannelStrip = NULL;          ChannelStrip *pChannelStrip = nullptr;
3233          if (pMdiSubWindow)          if (pMdiSubWindow)
3234                  pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());                  pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
3235          if (pChannelStrip)          if (pChannelStrip)

Legend:
Removed from v.2717  
changed lines
  Added in v.3849

  ViewVC Help
Powered by ViewVC