/[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 1512 by capela, Thu Nov 22 22:17:43 2007 UTC revision 2717 by schoenebeck, Wed Jan 21 13:19:51 2015 UTC
# Line 1  Line 1 
1  // qsamplerMainForm.cpp  // qsamplerMainForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, 2008 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 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
25    
 #include "qsamplerAbout.h"  
26  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
27  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
28  #include "qsamplerMessages.h"  #include "qsamplerMessages.h"
# Line 33  Line 33 
33  #include "qsamplerInstrumentListForm.h"  #include "qsamplerInstrumentListForm.h"
34  #include "qsamplerDeviceForm.h"  #include "qsamplerDeviceForm.h"
35  #include "qsamplerOptionsForm.h"  #include "qsamplerOptionsForm.h"
36    #include "qsamplerDeviceStatusForm.h"
37    
38    #include <QMdiArea>
39    #include <QMdiSubWindow>
40    
41  #include <QApplication>  #include <QApplication>
 #include <QWorkspace>  
42  #include <QProcess>  #include <QProcess>
43  #include <QMessageBox>  #include <QMessageBox>
44    
# Line 55  Line 58 
58  #include <QTimer>  #include <QTimer>
59  #include <QDateTime>  #include <QDateTime>
60    
61    #if QT_VERSION >= 0x050000
62    #include <QMimeData>
63    #endif
64    
65    #if QT_VERSION < 0x040500
66    namespace Qt {
67    const WindowFlags WindowCloseButtonHint = WindowFlags(0x08000000);
68    }
69    #endif
70    
71  #ifdef HAVE_SIGNAL_H  #ifdef HAVE_SIGNAL_H
72  #include <signal.h>  #include <signal.h>
# Line 77  static inline long lroundf ( float x ) Line 89  static inline long lroundf ( float x )
89  }  }
90  #endif  #endif
91    
92    
93    // All winsock apps needs this.
94    #if defined(WIN32)
95    static WSADATA _wsaData;
96    #endif
97    
98    
99    //-------------------------------------------------------------------------
100    // LADISH Level 1 support stuff.
101    
102    #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
103    
104    #include <QSocketNotifier>
105    
106    #include <sys/types.h>
107    #include <sys/socket.h>
108    
109    #include <signal.h>
110    
111    // File descriptor for SIGUSR1 notifier.
112    static int g_fdUsr1[2];
113    
114    // Unix SIGUSR1 signal handler.
115    static void qsampler_sigusr1_handler ( int /* signo */ )
116    {
117            char c = 1;
118    
119            (::write(g_fdUsr1[0], &c, sizeof(c)) > 0);
120    }
121    
122    #endif  // HAVE_SIGNAL_H
123    
124    
125    //-------------------------------------------------------------------------
126    // qsampler -- namespace
127    
128    
129    namespace QSampler {
130    
131  // Timer constant stuff.  // Timer constant stuff.
132  #define QSAMPLER_TIMER_MSECS    200  #define QSAMPLER_TIMER_MSECS    200
133    
# Line 87  static inline long lroundf ( float x ) Line 138  static inline long lroundf ( float x )
138  #define QSAMPLER_STATUS_SESSION 3       // Current session modification state.  #define QSAMPLER_STATUS_SESSION 3       // Current session modification state.
139    
140    
141  // All winsock apps needs this.  // Specialties for thread-callback comunication.
142  #if defined(WIN32)  #define QSAMPLER_LSCP_EVENT   QEvent::Type(QEvent::User + 1)
 static WSADATA _wsaData;  
 #endif  
143    
144    
145  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
146  // qsamplerCustomEvent -- specialty for callback comunication.  // LscpEvent -- specialty for LSCP callback comunication.
147    
 #define QSAMPLER_CUSTOM_EVENT   QEvent::Type(QEvent::User + 0)  
148    
149  class qsamplerCustomEvent : public QEvent  class LscpEvent : public QEvent
150  {  {
151  public:  public:
152    
153          // Constructor.          // Constructor.
154          qsamplerCustomEvent(lscp_event_t event, const char *pchData, int cchData)          LscpEvent(lscp_event_t event, const char *pchData, int cchData)
155                  : QEvent(QSAMPLER_CUSTOM_EVENT)                  : QEvent(QSAMPLER_LSCP_EVENT)
156          {          {
157                  m_event = event;                  m_event = event;
158                  m_data  = QString::fromUtf8(pchData, cchData);                  m_data  = QString::fromUtf8(pchData, cchData);
# Line 126  private: Line 174  private:
174  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
175  // qsamplerMainForm -- Main window form implementation.  // qsamplerMainForm -- Main window form implementation.
176    
 namespace QSampler {  
   
177  // Kind of singleton reference.  // Kind of singleton reference.
178  MainForm* MainForm::g_pMainForm = NULL;  MainForm* MainForm::g_pMainForm = NULL;
179    
# Line 159  MainForm::MainForm ( QWidget *pParent ) Line 205  MainForm::MainForm ( QWidget *pParent )
205    
206          m_iTimerSlot = 0;          m_iTimerSlot = 0;
207    
208  #ifdef HAVE_SIGNAL_H  #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
209    
210          // Set to ignore any fatal "Broken pipe" signals.          // Set to ignore any fatal "Broken pipe" signals.
211          ::signal(SIGPIPE, SIG_IGN);          ::signal(SIGPIPE, SIG_IGN);
212  #endif  
213            // LADISH Level 1 suport.
214    
215            // Initialize file descriptors for SIGUSR1 socket notifier.
216            ::socketpair(AF_UNIX, SOCK_STREAM, 0, g_fdUsr1);
217            m_pUsr1Notifier
218                    = new QSocketNotifier(g_fdUsr1[1], QSocketNotifier::Read, this);
219    
220            QObject::connect(m_pUsr1Notifier,
221                    SIGNAL(activated(int)),
222                    SLOT(handle_sigusr1()));
223    
224            // Install SIGUSR1 signal handler.
225        struct sigaction usr1;
226        usr1.sa_handler = qsampler_sigusr1_handler;
227        sigemptyset(&usr1.sa_mask);
228        usr1.sa_flags = 0;
229        usr1.sa_flags |= SA_RESTART;
230        ::sigaction(SIGUSR1, &usr1, NULL);
231    
232    #else   // HAVE_SIGNAL_H
233    
234            m_pUsr1Notifier = NULL;
235            
236    #endif  // !HAVE_SIGNAL_H
237    
238  #ifdef CONFIG_VOLUME  #ifdef CONFIG_VOLUME
239          // Make some extras into the toolbar...          // Make some extras into the toolbar...
# Line 171  MainForm::MainForm ( QWidget *pParent ) Line 242  MainForm::MainForm ( QWidget *pParent )
242          // Volume slider...          // Volume slider...
243          m_ui.channelsToolbar->addSeparator();          m_ui.channelsToolbar->addSeparator();
244          m_pVolumeSlider = new QSlider(Qt::Horizontal, m_ui.channelsToolbar);          m_pVolumeSlider = new QSlider(Qt::Horizontal, m_ui.channelsToolbar);
245          m_pVolumeSlider->setTickPosition(QSlider::TicksBelow);          m_pVolumeSlider->setTickPosition(QSlider::TicksBothSides);
246          m_pVolumeSlider->setTickInterval(10);          m_pVolumeSlider->setTickInterval(10);
247          m_pVolumeSlider->setPageStep(10);          m_pVolumeSlider->setPageStep(10);
248          m_pVolumeSlider->setSingleStep(10);          m_pVolumeSlider->setSingleStep(10);
# Line 183  MainForm::MainForm ( QWidget *pParent ) Line 254  MainForm::MainForm ( QWidget *pParent )
254          QObject::connect(m_pVolumeSlider,          QObject::connect(m_pVolumeSlider,
255                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
256                  SLOT(volumeChanged(int)));                  SLOT(volumeChanged(int)));
         //m_ui.channelsToolbar->setHorizontallyStretchable(true);  
         //m_ui.channelsToolbar->setStretchableWidget(m_pVolumeSlider);  
257          m_ui.channelsToolbar->addWidget(m_pVolumeSlider);          m_ui.channelsToolbar->addWidget(m_pVolumeSlider);
258          // Volume spin-box          // Volume spin-box
259          m_ui.channelsToolbar->addSeparator();          m_ui.channelsToolbar->addSeparator();
# Line 200  MainForm::MainForm ( QWidget *pParent ) Line 269  MainForm::MainForm ( QWidget *pParent )
269  #endif  #endif
270    
271          // Make it an MDI workspace.          // Make it an MDI workspace.
272          m_pWorkspace = new QWorkspace(this);          m_pWorkspace = new QMdiArea(this);
273          m_pWorkspace->setScrollBarsEnabled(true);          m_pWorkspace->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
274            m_pWorkspace->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
275          // Set the activation connection.          // Set the activation connection.
276          QObject::connect(m_pWorkspace,          QObject::connect(m_pWorkspace,
277                  SIGNAL(windowActivated(QWidget *)),                  SIGNAL(subWindowActivated(QMdiSubWindow *)),
278                  SLOT(stabilizeForm()));                  SLOT(activateStrip(QMdiSubWindow *)));
279          // Make it shine :-)          // Make it shine :-)
280          setCentralWidget(m_pWorkspace);          setCentralWidget(m_pWorkspace);
281    
# Line 322  MainForm::MainForm ( QWidget *pParent ) Line 392  MainForm::MainForm ( QWidget *pParent )
392          QObject::connect(m_ui.channelsMenu,          QObject::connect(m_ui.channelsMenu,
393                  SIGNAL(aboutToShow()),                  SIGNAL(aboutToShow()),
394                  SLOT(channelsMenuAboutToShow()));                  SLOT(channelsMenuAboutToShow()));
395    #ifdef CONFIG_VOLUME
396            QObject::connect(m_ui.channelsToolbar,
397                    SIGNAL(orientationChanged(Qt::Orientation)),
398                    SLOT(channelsToolbarOrientation(Qt::Orientation)));
399    #endif
400  }  }
401    
402  // Destructor.  // Destructor.
# Line 334  MainForm::~MainForm() Line 409  MainForm::~MainForm()
409          WSACleanup();          WSACleanup();
410  #endif  #endif
411    
412    #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
413            if (m_pUsr1Notifier)
414                    delete m_pUsr1Notifier;
415    #endif
416    
417          // Finally drop any widgets around...          // Finally drop any widgets around...
418          if (m_pDeviceForm)          if (m_pDeviceForm)
419                  delete m_pDeviceForm;                  delete m_pDeviceForm;
# Line 365  MainForm::~MainForm() Line 445  MainForm::~MainForm()
445    
446    
447  // Make and set a proper setup options step.  // Make and set a proper setup options step.
448  void MainForm::setup ( qsamplerOptions *pOptions )  void MainForm::setup ( Options *pOptions )
449  {  {
450          // We got options?          // We got options?
451          m_pOptions = pOptions;          m_pOptions = pOptions;
452    
453          // What style do we create these forms?          // What style do we create these forms?
454          Qt::WindowFlags wflags = Qt::Window          Qt::WindowFlags wflags = Qt::Window
 #if QT_VERSION >= 0x040200  
455                  | Qt::CustomizeWindowHint                  | Qt::CustomizeWindowHint
 #endif  
456                  | Qt::WindowTitleHint                  | Qt::WindowTitleHint
457                  | Qt::WindowSystemMenuHint                  | Qt::WindowSystemMenuHint
458                  | Qt::WindowMinMaxButtonsHint;                  | Qt::WindowMinMaxButtonsHint
459                    | Qt::WindowCloseButtonHint;
460          if (m_pOptions->bKeepOnTop)          if (m_pOptions->bKeepOnTop)
461                  wflags |= Qt::Tool;                  wflags |= Qt::Tool;
462    
463          // Some child forms are to be created right now.          // Some child forms are to be created right now.
464          m_pMessages = new qsamplerMessages(this);          m_pMessages = new Messages(this);
465          m_pDeviceForm = new DeviceForm(this, wflags);          m_pDeviceForm = new DeviceForm(this, wflags);
466  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
467          m_pInstrumentListForm = new InstrumentListForm(this, wflags);          m_pInstrumentListForm = new InstrumentListForm(this, wflags);
468  #else  #else
469          viewInstrumentsAction->setEnabled(false);          m_ui.viewInstrumentsAction->setEnabled(false);
470  #endif  #endif
471    
472            // Setup messages logging appropriately...
473            m_pMessages->setLogging(
474                    m_pOptions->bMessagesLog,
475                    m_pOptions->sMessagesLogPath);
476    
477          // Set message defaults...          // Set message defaults...
478          updateMessagesFont();          updateMessagesFont();
479          updateMessagesLimit();          updateMessagesLimit();
# Line 418  void MainForm::setup ( qsamplerOptions * Line 504  void MainForm::setup ( qsamplerOptions *
504          }          }
505    
506          // Try to restore old window positioning and initial visibility.          // Try to restore old window positioning and initial visibility.
507          m_pOptions->loadWidgetGeometry(this);          m_pOptions->loadWidgetGeometry(this, true);
508          m_pOptions->loadWidgetGeometry(m_pInstrumentListForm);          m_pOptions->loadWidgetGeometry(m_pInstrumentListForm);
509          m_pOptions->loadWidgetGeometry(m_pDeviceForm);          m_pOptions->loadWidgetGeometry(m_pDeviceForm);
510    
# Line 462  bool MainForm::queryClose (void) Line 548  bool MainForm::queryClose (void)
548                          // And the children, and the main windows state,.                          // And the children, and the main windows state,.
549                          m_pOptions->saveWidgetGeometry(m_pDeviceForm);                          m_pOptions->saveWidgetGeometry(m_pDeviceForm);
550                          m_pOptions->saveWidgetGeometry(m_pInstrumentListForm);                          m_pOptions->saveWidgetGeometry(m_pInstrumentListForm);
551                          m_pOptions->saveWidgetGeometry(this);                          m_pOptions->saveWidgetGeometry(this, true);
552                          // Close popup widgets.                          // Close popup widgets.
553                          if (m_pInstrumentListForm)                          if (m_pInstrumentListForm)
554                                  m_pInstrumentListForm->close();                                  m_pInstrumentListForm->close();
555                          if (m_pDeviceForm)                          if (m_pDeviceForm)
556                                  m_pDeviceForm->close();                                  m_pDeviceForm->close();
557                          // Stop client and/or server, gracefully.                          // Stop client and/or server, gracefully.
558                          stopServer();                          stopServer(true /*interactive*/);
559                  }                  }
560          }          }
561    
# Line 479  bool MainForm::queryClose (void) Line 565  bool MainForm::queryClose (void)
565    
566  void MainForm::closeEvent ( QCloseEvent *pCloseEvent )  void MainForm::closeEvent ( QCloseEvent *pCloseEvent )
567  {  {
568          if (queryClose())          if (queryClose()) {
569                    DeviceStatusForm::deleteAllInstances();
570                  pCloseEvent->accept();                  pCloseEvent->accept();
571          else          } else
572                  pCloseEvent->ignore();                  pCloseEvent->ignore();
573  }  }
574    
# Line 510  void MainForm::dropEvent ( QDropEvent* p Line 597  void MainForm::dropEvent ( QDropEvent* p
597                  QListIterator<QUrl> iter(pMimeData->urls());                  QListIterator<QUrl> iter(pMimeData->urls());
598                  while (iter.hasNext()) {                  while (iter.hasNext()) {
599                          const QString& sPath = iter.next().toLocalFile();                          const QString& sPath = iter.next().toLocalFile();
600                          if (qsamplerChannel::isInstrumentFile(sPath)) {                  //      if (Channel::isDlsInstrumentFile(sPath)) {
601                            if (QFileInfo(sPath).exists()) {
602                                  // Try to create a new channel from instrument file...                                  // Try to create a new channel from instrument file...
603                                  qsamplerChannel *pChannel = new qsamplerChannel();                                  Channel *pChannel = new Channel();
604                                  if (pChannel == NULL)                                  if (pChannel == NULL)
605                                          return;                                          return;
606                                  // Start setting the instrument filename...                                  // Start setting the instrument filename...
# Line 544  void MainForm::dropEvent ( QDropEvent* p Line 632  void MainForm::dropEvent ( QDropEvent* p
632    
633    
634  // Custome event handler.  // Custome event handler.
635  void MainForm::customEvent(QEvent* pCustomEvent)  void MainForm::customEvent ( QEvent* pEvent )
636  {  {
637          // For the time being, just pump it to messages.          // For the time being, just pump it to messages.
638          if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {          if (pEvent->type() == QSAMPLER_LSCP_EVENT) {
639                  qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent;                  LscpEvent *pLscpEvent = static_cast<LscpEvent *> (pEvent);
640                  if (pEvent->event() == LSCP_EVENT_CHANNEL_INFO) {                  switch (pLscpEvent->event()) {
641                          int iChannelID = pEvent->data().toInt();                          case LSCP_EVENT_CHANNEL_COUNT:
642                          ChannelStrip *pChannelStrip = channelStrip(iChannelID);                                  updateAllChannelStrips(true);
643                          if (pChannelStrip)                                  break;
644                                  channelStripChanged(pChannelStrip);                          case LSCP_EVENT_CHANNEL_INFO: {
645                  } else {                                  int iChannelID = pLscpEvent->data().toInt();
646                          appendMessagesColor(tr("Notify event: %1 data: %2")                                  ChannelStrip *pChannelStrip = channelStrip(iChannelID);
647                                  .arg(::lscp_event_to_text(pEvent->event()))                                  if (pChannelStrip)
648                                  .arg(pEvent->data()), "#996699");                                          channelStripChanged(pChannelStrip);
649                                    break;
650                            }
651                            case LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT:
652                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
653                                    DeviceStatusForm::onDevicesChanged();
654                                    updateViewMidiDeviceStatusMenu();
655                                    break;
656                            case LSCP_EVENT_MIDI_INPUT_DEVICE_INFO: {
657                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
658                                    const int iDeviceID = pLscpEvent->data().section(' ', 0, 0).toInt();
659                                    DeviceStatusForm::onDeviceChanged(iDeviceID);
660                                    break;
661                            }
662                            case LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT:
663                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
664                                    break;
665                            case LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO:
666                                    if (m_pDeviceForm) m_pDeviceForm->refreshDevices();
667                                    break;
668                    #if CONFIG_EVENT_CHANNEL_MIDI
669                            case LSCP_EVENT_CHANNEL_MIDI: {
670                                    const int iChannelID = pLscpEvent->data().section(' ', 0, 0).toInt();
671                                    ChannelStrip *pChannelStrip = channelStrip(iChannelID);
672                                    if (pChannelStrip)
673                                            pChannelStrip->midiActivityLedOn();
674                                    break;
675                            }
676                    #endif
677                    #if CONFIG_EVENT_DEVICE_MIDI
678                            case LSCP_EVENT_DEVICE_MIDI: {
679                                    const int iDeviceID = pLscpEvent->data().section(' ', 0, 0).toInt();
680                                    const int iPortID   = pLscpEvent->data().section(' ', 1, 1).toInt();
681                                    DeviceStatusForm *pDeviceStatusForm
682                                            = DeviceStatusForm::getInstance(iDeviceID);
683                                    if (pDeviceStatusForm)
684                                            pDeviceStatusForm->midiArrived(iPortID);
685                                    break;
686                            }
687                    #endif
688                            default:
689                                    appendMessagesColor(tr("LSCP Event: %1 data: %2")
690                                            .arg(::lscp_event_to_text(pLscpEvent->event()))
691                                            .arg(pLscpEvent->data()), "#996699");
692                  }                  }
693          }          }
694  }  }
695    
696    
697    // LADISH Level 1 -- SIGUSR1 signal handler.
698    void MainForm::handle_sigusr1 (void)
699    {
700    #if defined(HAVE_SIGNAL_H) && defined(HAVE_SYS_SOCKET_H)
701    
702            char c;
703    
704            if (::read(g_fdUsr1[1], &c, sizeof(c)) > 0)
705                    saveSession(false);
706    
707    #endif
708    }
709    
710    
711    void MainForm::updateViewMidiDeviceStatusMenu (void)
712    {
713            m_ui.viewMidiDeviceStatusMenu->clear();
714            const std::map<int, DeviceStatusForm *> statusForms
715                    = DeviceStatusForm::getInstances();
716            std::map<int, DeviceStatusForm *>::const_iterator iter
717                    = statusForms.begin();
718            for ( ; iter != statusForms.end(); ++iter) {
719                    DeviceStatusForm *pStatusForm = iter->second;
720                    m_ui.viewMidiDeviceStatusMenu->addAction(
721                            pStatusForm->visibleAction());
722            }
723    }
724    
725    
726  // Context menu event handler.  // Context menu event handler.
727  void MainForm::contextMenuEvent( QContextMenuEvent *pEvent )  void MainForm::contextMenuEvent( QContextMenuEvent *pEvent )
728  {  {
# Line 575  void MainForm::contextMenuEvent( QContex Line 736  void MainForm::contextMenuEvent( QContex
736  // qsamplerMainForm -- Brainless public property accessors.  // qsamplerMainForm -- Brainless public property accessors.
737    
738  // The global options settings property.  // The global options settings property.
739  qsamplerOptions *MainForm::options (void) const  Options *MainForm::options (void) const
740  {  {
741          return m_pOptions;          return m_pOptions;
742  }  }
# Line 693  bool MainForm::saveSession ( bool bPromp Line 854  bool MainForm::saveSession ( bool bPromp
854                                  "\"%1\"\n\n"                                  "\"%1\"\n\n"
855                                  "Do you want to replace it?")                                  "Do you want to replace it?")
856                                  .arg(sFilename),                                  .arg(sFilename),
857                                  tr("Replace"), tr("Cancel")) > 0)                                  QMessageBox::Yes | QMessageBox::No)
858                                    == QMessageBox::No)
859                                  return false;                                  return false;
860                  }                  }
861          }          }
# Line 716  bool MainForm::closeSession ( bool bForc Line 878  bool MainForm::closeSession ( bool bForc
878                          "\"%1\"\n\n"                          "\"%1\"\n\n"
879                          "Do you want to save the changes?")                          "Do you want to save the changes?")
880                          .arg(sessionName(m_sFilename)),                          .arg(sessionName(m_sFilename)),
881                          tr("Save"), tr("Discard"), tr("Cancel"))) {                          QMessageBox::Save |
882                  case 0:     // Save...                          QMessageBox::Discard |
883                            QMessageBox::Cancel)) {
884                    case QMessageBox::Save:
885                          bClose = saveSession(false);                          bClose = saveSession(false);
886                          // Fall thru....                          // Fall thru....
887                  case 1:     // Discard                  case QMessageBox::Discard:
888                          break;                          break;
889                  default:    // Cancel.                  default:    // Cancel.
890                          bClose = false;                          bClose = false;
# Line 732  bool MainForm::closeSession ( bool bForc Line 896  bool MainForm::closeSession ( bool bForc
896          if (bClose) {          if (bClose) {
897                  // Remove all channel strips from sight...                  // Remove all channel strips from sight...
898                  m_pWorkspace->setUpdatesEnabled(false);                  m_pWorkspace->setUpdatesEnabled(false);
899                  QWidgetList wlist = m_pWorkspace->windowList();                  QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
900                  for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {                  for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
901                          ChannelStrip *pChannelStrip = (ChannelStrip*) wlist.at(iChannel);                          ChannelStrip *pChannelStrip = NULL;
902                            QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
903                            if (pMdiSubWindow)
904                                    pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
905                          if (pChannelStrip) {                          if (pChannelStrip) {
906                                  qsamplerChannel *pChannel = pChannelStrip->channel();                                  Channel *pChannel = pChannelStrip->channel();
907                                  if (bForce && pChannel)                                  if (bForce && pChannel)
908                                          pChannel->removeChannel();                                          pChannel->removeChannel();
909                                  delete pChannelStrip;                                  delete pChannelStrip;
910                          }                          }
911                            if (pMdiSubWindow)
912                                    delete pMdiSubWindow;
913                  }                  }
914                  m_pWorkspace->setUpdatesEnabled(true);                  m_pWorkspace->setUpdatesEnabled(true);
915                  // We're now clean, for sure.                  // We're now clean, for sure.
# Line 876  bool MainForm::saveSessionFile ( const Q Line 1045  bool MainForm::saveSessionFile ( const Q
1045    
1046          // Audio device mapping.          // Audio device mapping.
1047          QMap<int, int> audioDeviceMap;          QMap<int, int> audioDeviceMap;
1048          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);          piDeviceIDs = Device::getDevices(m_pClient, Device::Audio);
1049          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {
1050                  ts << endl;                  ts << endl;
1051                  qsamplerDevice device(qsamplerDevice::Audio, piDeviceIDs[iDevice]);                  Device device(Device::Audio, piDeviceIDs[iDevice]);
1052                  // Audio device specification...                  // Audio device specification...
1053                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1054                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1055                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();                  ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();
1056                  qsamplerDeviceParamMap::ConstIterator deviceParam;                  DeviceParamMap::ConstIterator deviceParam;
1057                  for (deviceParam = device.params().begin();                  for (deviceParam = device.params().begin();
1058                                  deviceParam != device.params().end();                                  deviceParam != device.params().end();
1059                                          ++deviceParam) {                                          ++deviceParam) {
1060                          const qsamplerDeviceParam& param = deviceParam.value();                          const DeviceParam& param = deviceParam.value();
1061                          if (param.value.isEmpty()) ts << "# ";                          if (param.value.isEmpty()) ts << "# ";
1062                          ts << " " << deviceParam.key() << "='" << param.value << "'";                          ts << " " << deviceParam.key() << "='" << param.value << "'";
1063                  }                  }
1064                  ts << endl;                  ts << endl;
1065                  // Audio channel parameters...                  // Audio channel parameters...
1066                  int iPort = 0;                  int iPort = 0;
1067                  QListIterator<qsamplerDevicePort *> iter(device.ports());                  QListIterator<DevicePort *> iter(device.ports());
1068                  while (iter.hasNext()) {                  while (iter.hasNext()) {
1069                          qsamplerDevicePort *pPort = iter.next();                          DevicePort *pPort = iter.next();
1070                          qsamplerDeviceParamMap::ConstIterator portParam;                          DeviceParamMap::ConstIterator portParam;
1071                          for (portParam = pPort->params().begin();                          for (portParam = pPort->params().begin();
1072                                          portParam != pPort->params().end();                                          portParam != pPort->params().end();
1073                                                  ++portParam) {                                                  ++portParam) {
1074                                  const qsamplerDeviceParam& param = portParam.value();                                  const DeviceParam& param = portParam.value();
1075                                  if (param.fix || param.value.isEmpty()) ts << "# ";                                  if (param.fix || param.value.isEmpty()) ts << "# ";
1076                                  ts << "SET AUDIO_OUTPUT_CHANNEL_PARAMETER " << iDevice                                  ts << "SET AUDIO_OUTPUT_CHANNEL_PARAMETER " << iDevice
1077                                          << " " << iPort << " " << portParam.key()                                          << " " << iPort << " " << portParam.key()
# Line 918  bool MainForm::saveSessionFile ( const Q Line 1087  bool MainForm::saveSessionFile ( const Q
1087    
1088          // MIDI device mapping.          // MIDI device mapping.
1089          QMap<int, int> midiDeviceMap;          QMap<int, int> midiDeviceMap;
1090          piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);          piDeviceIDs = Device::getDevices(m_pClient, Device::Midi);
1091          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {          for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {
1092                  ts << endl;                  ts << endl;
1093                  qsamplerDevice device(qsamplerDevice::Midi, piDeviceIDs[iDevice]);                  Device device(Device::Midi, piDeviceIDs[iDevice]);
1094                  // MIDI device specification...                  // MIDI device specification...
1095                  ts << "# " << device.deviceTypeName() << " " << device.driverName()                  ts << "# " << device.deviceTypeName() << " " << device.driverName()
1096                          << " " << tr("Device") << " " << iDevice << endl;                          << " " << tr("Device") << " " << iDevice << endl;
1097                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();                  ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();
1098                  qsamplerDeviceParamMap::ConstIterator deviceParam;                  DeviceParamMap::ConstIterator deviceParam;
1099                  for (deviceParam = device.params().begin();                  for (deviceParam = device.params().begin();
1100                                  deviceParam != device.params().end();                                  deviceParam != device.params().end();
1101                                          ++deviceParam) {                                          ++deviceParam) {
1102                          const qsamplerDeviceParam& param = deviceParam.value();                          const DeviceParam& param = deviceParam.value();
1103                          if (param.value.isEmpty()) ts << "# ";                          if (param.value.isEmpty()) ts << "# ";
1104                          ts << " " << deviceParam.key() << "='" << param.value << "'";                          ts << " " << deviceParam.key() << "='" << param.value << "'";
1105                  }                  }
1106                  ts << endl;                  ts << endl;
1107                  // MIDI port parameters...                  // MIDI port parameters...
1108                  int iPort = 0;                  int iPort = 0;
1109                  QListIterator<qsamplerDevicePort *> iter(device.ports());                  QListIterator<DevicePort *> iter(device.ports());
1110                  while (iter.hasNext()) {                  while (iter.hasNext()) {
1111                          qsamplerDevicePort *pPort = iter.next();                          DevicePort *pPort = iter.next();
1112                          qsamplerDeviceParamMap::ConstIterator portParam;                          DeviceParamMap::ConstIterator portParam;
1113                          for (portParam = pPort->params().begin();                          for (portParam = pPort->params().begin();
1114                                          portParam != pPort->params().end();                                          portParam != pPort->params().end();
1115                                                  ++portParam) {                                                  ++portParam) {
1116                                  const qsamplerDeviceParam& param = portParam.value();                                  const DeviceParam& param = portParam.value();
1117                                  if (param.fix || param.value.isEmpty()) ts << "# ";                                  if (param.fix || param.value.isEmpty()) ts << "# ";
1118                                  ts << "SET MIDI_INPUT_PORT_PARAMETER " << iDevice                                  ts << "SET MIDI_INPUT_PORT_PARAMETER " << iDevice
1119                                  << " " << iPort << " " << portParam.key()                                  << " " << iPort << " " << portParam.key()
# Line 1031  bool MainForm::saveSessionFile ( const Q Line 1200  bool MainForm::saveSessionFile ( const Q
1200  #endif  // CONFIG_MIDI_INSTRUMENT  #endif  // CONFIG_MIDI_INSTRUMENT
1201    
1202          // Sampler channel mapping.          // Sampler channel mapping.
1203          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
1204          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
1205                  ChannelStrip* pChannelStrip                  ChannelStrip *pChannelStrip = NULL;
1206                          = static_cast<ChannelStrip *> (wlist.at(iChannel));                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
1207                    if (pMdiSubWindow)
1208                            pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
1209                  if (pChannelStrip) {                  if (pChannelStrip) {
1210                          qsamplerChannel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
1211                          if (pChannel) {                          if (pChannel) {
1212                                  ts << "# " << tr("Channel") << " " << iChannel << endl;                                  ts << "# " << tr("Channel") << " " << iChannel << endl;
1213                                  ts << "ADD CHANNEL" << endl;                                  ts << "ADD CHANNEL" << endl;
# Line 1068  bool MainForm::saveSessionFile ( const Q Line 1239  bool MainForm::saveSessionFile ( const Q
1239                                  ts << "LOAD INSTRUMENT NON_MODAL '"                                  ts << "LOAD INSTRUMENT NON_MODAL '"
1240                                          << pChannel->instrumentFile() << "' "                                          << pChannel->instrumentFile() << "' "
1241                                          << pChannel->instrumentNr() << " " << iChannel << endl;                                          << pChannel->instrumentNr() << " " << iChannel << endl;
1242                                  qsamplerChannelRoutingMap::ConstIterator audioRoute;                                  ChannelRoutingMap::ConstIterator audioRoute;
1243                                  for (audioRoute = pChannel->audioRouting().begin();                                  for (audioRoute = pChannel->audioRouting().begin();
1244                                                  audioRoute != pChannel->audioRouting().end();                                                  audioRoute != pChannel->audioRouting().end();
1245                                                          ++audioRoute) {                                                          ++audioRoute) {
# Line 1082  bool MainForm::saveSessionFile ( const Q Line 1253  bool MainForm::saveSessionFile ( const Q
1253                                          ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl;                                          ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl;
1254                                  if (pChannel->channelSolo())                                  if (pChannel->channelSolo())
1255                                          ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl;                                          ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl;
1256  #ifdef CONFIG_MIDI_INSTRUMENT                          #ifdef CONFIG_MIDI_INSTRUMENT
1257                                  if (pChannel->midiMap() >= 0) {                                  if (pChannel->midiMap() >= 0) {
1258                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel                                          ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel
1259                                                  << " " << midiInstrumentMap[pChannel->midiMap()] << endl;                                                  << " " << midiInstrumentMap[pChannel->midiMap()] << endl;
1260                                  }                                  }
1261  #endif                          #endif
1262  #ifdef CONFIG_FXSEND                          #ifdef CONFIG_FXSEND
1263                                  int iChannelID = pChannel->channelID();                                  int iChannelID = pChannel->channelID();
1264                                  int *piFxSends = ::lscp_list_fxsends(m_pClient, iChannelID);                                  int *piFxSends = ::lscp_list_fxsends(m_pClient, iChannelID);
1265                                  for (int iFxSend = 0;                                  for (int iFxSend = 0;
# Line 1112  bool MainForm::saveSessionFile ( const Q Line 1283  bool MainForm::saveSessionFile ( const Q
1283                                                                  << " " << iAudioSrc                                                                  << " " << iAudioSrc
1284                                                                  << " " << piRouting[iAudioSrc] << endl;                                                                  << " " << piRouting[iAudioSrc] << endl;
1285                                                  }                                                  }
1286  #ifdef CONFIG_FXSEND_LEVEL                                          #ifdef CONFIG_FXSEND_LEVEL
1287                                                  ts << "SET FX_SEND LEVEL " << iChannel                                                  ts << "SET FX_SEND LEVEL " << iChannel
1288                                                          << " " << iFxSend                                                          << " " << iFxSend
1289                                                          << " " << pFxSendInfo->level << endl;                                                          << " " << pFxSendInfo->level << endl;
1290  #endif                                          #endif
1291                                          }       // Check for errors...                                          }       // Check for errors...
1292                                          else if (::lscp_client_get_errno(m_pClient)) {                                          else if (::lscp_client_get_errno(m_pClient)) {
1293                                                  appendMessagesClient("lscp_get_fxsend_info");                                                  appendMessagesClient("lscp_get_fxsend_info");
1294                                                  iErrors++;                                                  iErrors++;
1295                                          }                                          }
1296                                  }                                  }
1297  #endif                          #endif
1298                                  ts << endl;                                  ts << endl;
1299                          }                          }
1300                  }                  }
# Line 1241  void MainForm::fileReset (void) Line 1412  void MainForm::fileReset (void)
1412                  "Please note that this operation may cause\n"                  "Please note that this operation may cause\n"
1413                  "temporary MIDI and Audio disruption.\n\n"                  "temporary MIDI and Audio disruption.\n\n"
1414                  "Do you want to reset the sampler engine now?"),                  "Do you want to reset the sampler engine now?"),
1415                  tr("Reset"), tr("Cancel")) > 0)                  QMessageBox::Ok | QMessageBox::Cancel)
1416                    == QMessageBox::Cancel)
1417                  return;                  return;
1418    
1419          // Trye closing the current session, first...          // Trye closing the current session, first...
# Line 1282  void MainForm::fileRestart (void) Line 1454  void MainForm::fileRestart (void)
1454                          "Please note that this operation may cause\n"                          "Please note that this operation may cause\n"
1455                          "temporary MIDI and Audio disruption.\n\n"                          "temporary MIDI and Audio disruption.\n\n"
1456                          "Do you want to restart the connection now?"),                          "Do you want to restart the connection now?"),
1457                          tr("Restart"), tr("Cancel")) == 0);                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok);
1458          }          }
1459    
1460          // Are we still for it?          // Are we still for it?
# Line 1313  void MainForm::editAddChannel (void) Line 1485  void MainForm::editAddChannel (void)
1485                  return;                  return;
1486    
1487          // Just create the channel instance...          // Just create the channel instance...
1488          qsamplerChannel *pChannel = new qsamplerChannel();          Channel *pChannel = new Channel();
1489          if (pChannel == NULL)          if (pChannel == NULL)
1490                  return;                  return;
1491    
# Line 1331  void MainForm::editAddChannel (void) Line 1503  void MainForm::editAddChannel (void)
1503                  return;                  return;
1504          }          }
1505    
1506            // Do we auto-arrange?
1507            if (m_pOptions && m_pOptions->bAutoArrange)
1508                    channelsArrange();
1509    
1510          // Make that an overall update.          // Make that an overall update.
1511          m_iDirtyCount++;          m_iDirtyCount++;
1512          stabilizeForm();          stabilizeForm();
# Line 1343  void MainForm::editRemoveChannel (void) Line 1519  void MainForm::editRemoveChannel (void)
1519          if (m_pClient == NULL)          if (m_pClient == NULL)
1520                  return;                  return;
1521    
1522          ChannelStrip* pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1523          if (pChannelStrip == NULL)          if (pChannelStrip == NULL)
1524                  return;                  return;
1525    
1526          qsamplerChannel *pChannel = pChannelStrip->channel();          Channel *pChannel = pChannelStrip->channel();
1527          if (pChannel == NULL)          if (pChannel == NULL)
1528                  return;                  return;
1529    
# Line 1359  void MainForm::editRemoveChannel (void) Line 1535  void MainForm::editRemoveChannel (void)
1535                          "%1\n\n"                          "%1\n\n"
1536                          "Are you sure?")                          "Are you sure?")
1537                          .arg(pChannelStrip->windowTitle()),                          .arg(pChannelStrip->windowTitle()),
1538                          tr("OK"), tr("Cancel")) > 0)                          QMessageBox::Ok | QMessageBox::Cancel)
1539                            == QMessageBox::Cancel)
1540                          return;                          return;
1541          }          }
1542    
# Line 1367  void MainForm::editRemoveChannel (void) Line 1544  void MainForm::editRemoveChannel (void)
1544          if (!pChannel->removeChannel())          if (!pChannel->removeChannel())
1545                  return;                  return;
1546    
         // Just delete the channel strip.  
         delete pChannelStrip;  
   
         // Do we auto-arrange?  
         if (m_pOptions && m_pOptions->bAutoArrange)  
                 channelsArrange();  
   
1547          // We'll be dirty, for sure...          // We'll be dirty, for sure...
1548          m_iDirtyCount++;          m_iDirtyCount++;
1549          stabilizeForm();  
1550            // Just delete the channel strip.
1551            destroyChannelStrip(pChannelStrip);
1552  }  }
1553    
1554    
# Line 1386  void MainForm::editSetupChannel (void) Line 1558  void MainForm::editSetupChannel (void)
1558          if (m_pClient == NULL)          if (m_pClient == NULL)
1559                  return;                  return;
1560    
1561          ChannelStrip* pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1562          if (pChannelStrip == NULL)          if (pChannelStrip == NULL)
1563                  return;                  return;
1564    
# Line 1401  void MainForm::editEditChannel (void) Line 1573  void MainForm::editEditChannel (void)
1573          if (m_pClient == NULL)          if (m_pClient == NULL)
1574                  return;                  return;
1575    
1576          ChannelStrip* pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1577          if (pChannelStrip == NULL)          if (pChannelStrip == NULL)
1578                  return;                  return;
1579    
# Line 1416  void MainForm::editResetChannel (void) Line 1588  void MainForm::editResetChannel (void)
1588          if (m_pClient == NULL)          if (m_pClient == NULL)
1589                  return;                  return;
1590    
1591          ChannelStrip* pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1592          if (pChannelStrip == NULL)          if (pChannelStrip == NULL)
1593                  return;                  return;
1594    
# Line 1434  void MainForm::editResetAllChannels (voi Line 1606  void MainForm::editResetAllChannels (voi
1606          // Invoque the channel strip procedure,          // Invoque the channel strip procedure,
1607          // for all channels out there...          // for all channels out there...
1608          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
1609          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
1610          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
1611                  ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel);                  ChannelStrip *pChannelStrip = NULL;
1612                    QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
1613                    if (pMdiSubWindow)
1614                            pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
1615                  if (pChannelStrip)                  if (pChannelStrip)
1616                          pChannelStrip->channelReset();                          pChannelStrip->channelReset();
1617          }          }
# Line 1539  void MainForm::viewOptions (void) Line 1714  void MainForm::viewOptions (void)
1714          OptionsForm* pOptionsForm = new OptionsForm(this);          OptionsForm* pOptionsForm = new OptionsForm(this);
1715          if (pOptionsForm) {          if (pOptionsForm) {
1716                  // Check out some initial nullities(tm)...                  // Check out some initial nullities(tm)...
1717                  ChannelStrip* pChannelStrip = activeChannelStrip();                  ChannelStrip *pChannelStrip = activeChannelStrip();
1718                  if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip)                  if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip)
1719                          m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString();                          m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString();
1720                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)                  if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
# Line 1550  void MainForm::viewOptions (void) Line 1725  void MainForm::viewOptions (void)
1725                  int     iOldServerTimeout   = m_pOptions->iServerTimeout;                  int     iOldServerTimeout   = m_pOptions->iServerTimeout;
1726                  bool    bOldServerStart     = m_pOptions->bServerStart;                  bool    bOldServerStart     = m_pOptions->bServerStart;
1727                  QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;                  QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;
1728                    bool    bOldMessagesLog     = m_pOptions->bMessagesLog;
1729                    QString sOldMessagesLogPath = m_pOptions->sMessagesLogPath;
1730                  QString sOldDisplayFont     = m_pOptions->sDisplayFont;                  QString sOldDisplayFont     = m_pOptions->sDisplayFont;
1731                  bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;                  bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;
1732                  int     iOldMaxVolume       = m_pOptions->iMaxVolume;                  int     iOldMaxVolume       = m_pOptions->iMaxVolume;
# Line 1561  void MainForm::viewOptions (void) Line 1738  void MainForm::viewOptions (void)
1738                  bool    bOldCompletePath    = m_pOptions->bCompletePath;                  bool    bOldCompletePath    = m_pOptions->bCompletePath;
1739                  bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;                  bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;
1740                  int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;                  int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;
1741                    int     iOldBaseFontSize    = m_pOptions->iBaseFontSize;
1742                  // Load the current setup settings.                  // Load the current setup settings.
1743                  pOptionsForm->setup(m_pOptions);                  pOptionsForm->setup(m_pOptions);
1744                  // Show the setup dialog...                  // Show the setup dialog...
# Line 1569  void MainForm::viewOptions (void) Line 1747  void MainForm::viewOptions (void)
1747                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||                          if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1748                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||                                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||
1749                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||                                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1750                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)) {                                  (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)     ||
1751                                    (iOldBaseFontSize   !=  m_pOptions->iBaseFontSize)) {
1752                                  QMessageBox::information(this,                                  QMessageBox::information(this,
1753                                          QSAMPLER_TITLE ": " + tr("Information"),                                          QSAMPLER_TITLE ": " + tr("Information"),
1754                                          tr("Some settings may be only effective\n"                                          tr("Some settings may be only effective\n"
1755                                          "next time you start this program."), tr("OK"));                                          "next time you start this program."));
1756                                  updateMessagesCapture();                                  updateMessagesCapture();
1757                          }                          }
1758                          // Check wheather something immediate has changed.                          // Check wheather something immediate has changed.
1759                            if (( bOldMessagesLog && !m_pOptions->bMessagesLog) ||
1760                                    (!bOldMessagesLog &&  m_pOptions->bMessagesLog) ||
1761                                    (sOldMessagesLogPath != m_pOptions->sMessagesLogPath))
1762                                    m_pMessages->setLogging(
1763                                            m_pOptions->bMessagesLog, m_pOptions->sMessagesLogPath);
1764                          if (( bOldCompletePath && !m_pOptions->bCompletePath) ||                          if (( bOldCompletePath && !m_pOptions->bCompletePath) ||
1765                                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||                                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||
1766                                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))                                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))
# Line 1623  void MainForm::viewOptions (void) Line 1807  void MainForm::viewOptions (void)
1807  void MainForm::channelsArrange (void)  void MainForm::channelsArrange (void)
1808  {  {
1809          // Full width vertical tiling          // Full width vertical tiling
1810          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
1811          if (wlist.isEmpty())          if (wlist.isEmpty())
1812                  return;                  return;
1813    
1814          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
1815          int y = 0;          int y = 0;
1816          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
1817                  ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel);                  ChannelStrip *pChannelStrip = NULL;
1818          /*  if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) {                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
1819                          // Prevent flicker...                  if (pMdiSubWindow)
1820                          pChannelStrip->hide();                          pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
1821                          pChannelStrip->showNormal();                  if (pChannelStrip) {
1822                  }   */                  /*  if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) {
1823                  pChannelStrip->adjustSize();                                  // Prevent flicker...
1824                  int iWidth  = m_pWorkspace->width();                                  pChannelStrip->hide();
1825                  if (iWidth < pChannelStrip->width())                                  pChannelStrip->showNormal();
1826                          iWidth = pChannelStrip->width();                          }   */
1827          //  int iHeight = pChannelStrip->height()                          pChannelStrip->adjustSize();
1828          //              + pChannelStrip->parentWidget()->baseSize().height();                          int iWidth  = m_pWorkspace->width();
1829                  int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();                          if (iWidth < pChannelStrip->width())
1830                  pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);                                  iWidth = pChannelStrip->width();
1831                  y += iHeight;                  //  int iHeight = pChannelStrip->height()
1832                    //              + pChannelStrip->parentWidget()->baseSize().height();
1833                            int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1834                            pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1835                            y += iHeight;
1836                    }
1837          }          }
1838          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
1839    
# Line 1731  void MainForm::helpAbout (void) Line 1920  void MainForm::helpAbout (void)
1920          sText += tr("Instrument editing support disabled.");          sText += tr("Instrument editing support disabled.");
1921          sText += "</font></small><br />";          sText += "</font></small><br />";
1922  #endif  #endif
1923    #ifndef CONFIG_EVENT_CHANNEL_MIDI
1924            sText += "<small><font color=\"red\">";
1925            sText += tr("Channel MIDI event support disabled.");
1926            sText += "</font></small><br />";
1927    #endif
1928    #ifndef CONFIG_EVENT_DEVICE_MIDI
1929            sText += "<small><font color=\"red\">";
1930            sText += tr("Device MIDI event support disabled.");
1931            sText += "</font></small><br />";
1932    #endif
1933    #ifndef CONFIG_MAX_VOICES
1934            sText += "<small><font color=\"red\">";
1935            sText += tr("Runtime max. voices / disk streams support disabled.");
1936            sText += "</font></small><br />";
1937    #endif
1938          sText += "<br />\n";          sText += "<br />\n";
1939          sText += tr("Using") + ": ";          sText += tr("Using") + ": ";
1940          sText += ::lscp_client_package();          sText += ::lscp_client_package();
# Line 1771  void MainForm::stabilizeForm (void) Line 1975  void MainForm::stabilizeForm (void)
1975          setWindowTitle(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));          setWindowTitle(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));
1976    
1977          // Update the main menu state...          // Update the main menu state...
1978          ChannelStrip* pChannelStrip = activeChannelStrip();          ChannelStrip *pChannelStrip = activeChannelStrip();
1979          bool bHasClient  = (m_pOptions != NULL && m_pClient != NULL);          bool bHasClient = (m_pOptions != NULL && m_pClient != NULL);
1980          bool bHasChannel = (bHasClient && pChannelStrip != NULL);          bool bHasChannel = (bHasClient && pChannelStrip != NULL);
1981            bool bHasChannels = (bHasClient && m_pWorkspace->subWindowList().count() > 0);
1982          m_ui.fileNewAction->setEnabled(bHasClient);          m_ui.fileNewAction->setEnabled(bHasClient);
1983          m_ui.fileOpenAction->setEnabled(bHasClient);          m_ui.fileOpenAction->setEnabled(bHasClient);
1984          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);          m_ui.fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);
# Line 1789  void MainForm::stabilizeForm (void) Line 1994  void MainForm::stabilizeForm (void)
1994          m_ui.editEditChannelAction->setEnabled(false);          m_ui.editEditChannelAction->setEnabled(false);
1995  #endif  #endif
1996          m_ui.editResetChannelAction->setEnabled(bHasChannel);          m_ui.editResetChannelAction->setEnabled(bHasChannel);
1997          m_ui.editResetAllChannelsAction->setEnabled(bHasChannel);          m_ui.editResetAllChannelsAction->setEnabled(bHasChannels);
1998          m_ui.viewMessagesAction->setChecked(m_pMessages && m_pMessages->isVisible());          m_ui.viewMessagesAction->setChecked(m_pMessages && m_pMessages->isVisible());
1999  #ifdef CONFIG_MIDI_INSTRUMENT  #ifdef CONFIG_MIDI_INSTRUMENT
2000          m_ui.viewInstrumentsAction->setChecked(m_pInstrumentListForm          m_ui.viewInstrumentsAction->setChecked(m_pInstrumentListForm
# Line 1801  void MainForm::stabilizeForm (void) Line 2006  void MainForm::stabilizeForm (void)
2006          m_ui.viewDevicesAction->setChecked(m_pDeviceForm          m_ui.viewDevicesAction->setChecked(m_pDeviceForm
2007                  && m_pDeviceForm->isVisible());                  && m_pDeviceForm->isVisible());
2008          m_ui.viewDevicesAction->setEnabled(bHasClient);          m_ui.viewDevicesAction->setEnabled(bHasClient);
2009          m_ui.channelsArrangeAction->setEnabled(bHasChannel);          m_ui.viewMidiDeviceStatusMenu->setEnabled(
2010                    DeviceStatusForm::getInstances().size() > 0);
2011            m_ui.channelsArrangeAction->setEnabled(bHasChannels);
2012    
2013  #ifdef CONFIG_VOLUME  #ifdef CONFIG_VOLUME
2014          // Toolbar widgets are also affected...          // Toolbar widgets are also affected...
# Line 1867  void MainForm::volumeChanged ( int iVolu Line 2074  void MainForm::volumeChanged ( int iVolu
2074    
2075    
2076  // Channel change receiver slot.  // Channel change receiver slot.
2077  void MainForm::channelStripChanged(ChannelStrip* pChannelStrip)  void MainForm::channelStripChanged ( ChannelStrip *pChannelStrip )
2078  {  {
2079          // Add this strip to the changed list...          // Add this strip to the changed list...
2080          if (!m_changedStrips.contains(pChannelStrip)) {          if (!m_changedStrips.contains(pChannelStrip)) {
# Line 1905  void MainForm::updateSession (void) Line 2112  void MainForm::updateSession (void)
2112          }          }
2113  #endif  #endif
2114    
2115            updateAllChannelStrips(false);
2116    
2117            // Do we auto-arrange?
2118            if (m_pOptions && m_pOptions->bAutoArrange)
2119                    channelsArrange();
2120    
2121            // Remember to refresh devices and instruments...
2122            if (m_pInstrumentListForm)
2123                    m_pInstrumentListForm->refreshInstruments();
2124            if (m_pDeviceForm)
2125                    m_pDeviceForm->refreshDevices();
2126    }
2127    
2128    
2129    void MainForm::updateAllChannelStrips ( bool bRemoveDeadStrips )
2130    {
2131          // Retrieve the current channel list.          // Retrieve the current channel list.
2132          int *piChannelIDs = ::lscp_list_channels(m_pClient);          int *piChannelIDs = ::lscp_list_channels(m_pClient);
2133          if (piChannelIDs == NULL) {          if (piChannelIDs == NULL) {
# Line 1916  void MainForm::updateSession (void) Line 2139  void MainForm::updateSession (void)
2139          } else {          } else {
2140                  // Try to (re)create each channel.                  // Try to (re)create each channel.
2141                  m_pWorkspace->setUpdatesEnabled(false);                  m_pWorkspace->setUpdatesEnabled(false);
2142                  for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) {                  for (int iChannel = 0; piChannelIDs[iChannel] >= 0; ++iChannel) {
2143                          // Check if theres already a channel strip for this one...                          // Check if theres already a channel strip for this one...
2144                          if (!channelStrip(piChannelIDs[iChannel]))                          if (!channelStrip(piChannelIDs[iChannel]))
2145                                  createChannelStrip(new qsamplerChannel(piChannelIDs[iChannel]));                                  createChannelStrip(new Channel(piChannelIDs[iChannel]));
2146                    }
2147                    // Do we auto-arrange?
2148                    if (m_pOptions && m_pOptions->bAutoArrange)
2149                            channelsArrange();
2150                    // remove dead channel strips
2151                    if (bRemoveDeadStrips) {
2152                            QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2153                            for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2154                                    ChannelStrip *pChannelStrip = NULL;
2155                                    QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2156                                    if (pMdiSubWindow)
2157                                            pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2158                                    if (pChannelStrip) {
2159                                            bool bExists = false;
2160                                            for (int j = 0; piChannelIDs[j] >= 0; ++j) {
2161                                                    if (!pChannelStrip->channel())
2162                                                            break;
2163                                                    if (piChannelIDs[j] == pChannelStrip->channel()->channelID()) {
2164                                                            // strip exists, don't touch it
2165                                                            bExists = true;
2166                                                            break;
2167                                                    }
2168                                            }
2169                                            if (!bExists)
2170                                                    destroyChannelStrip(pChannelStrip);
2171                                    }
2172                            }
2173                  }                  }
2174                  m_pWorkspace->setUpdatesEnabled(true);                  m_pWorkspace->setUpdatesEnabled(true);
2175          }          }
2176    
2177          // Do we auto-arrange?          stabilizeForm();
         if (m_pOptions && m_pOptions->bAutoArrange)  
                 channelsArrange();  
   
         // Remember to refresh devices and instruments...  
         if (m_pInstrumentListForm)  
                 m_pInstrumentListForm->refreshInstruments();  
         if (m_pDeviceForm)  
                 m_pDeviceForm->refreshDevices();  
2178  }  }
2179    
2180    
# Line 1982  void MainForm::updateRecentFilesMenu (vo Line 2224  void MainForm::updateRecentFilesMenu (vo
2224  void MainForm::updateInstrumentNames (void)  void MainForm::updateInstrumentNames (void)
2225  {  {
2226          // Full channel list update...          // Full channel list update...
2227          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2228          if (wlist.isEmpty())          if (wlist.isEmpty())
2229                  return;                  return;
2230    
2231          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2232          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2233                  ChannelStrip *pChannelStrip = (ChannelStrip *) wlist.at(iChannel);                  ChannelStrip *pChannelStrip = (ChannelStrip *) wlist.at(iChannel);
2234                  if (pChannelStrip)                  if (pChannelStrip)
2235                          pChannelStrip->updateInstrumentName(true);                          pChannelStrip->updateInstrumentName(true);
# Line 2011  void MainForm::updateDisplayFont (void) Line 2253  void MainForm::updateDisplayFont (void)
2253                  return;                  return;
2254    
2255          // Full channel list update...          // Full channel list update...
2256          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2257          if (wlist.isEmpty())          if (wlist.isEmpty())
2258                  return;                  return;
2259    
2260          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2261          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2262                  ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel);                  ChannelStrip *pChannelStrip = NULL;
2263                    QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2264                    if (pMdiSubWindow)
2265                            pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2266                  if (pChannelStrip)                  if (pChannelStrip)
2267                          pChannelStrip->setDisplayFont(font);                          pChannelStrip->setDisplayFont(font);
2268          }          }
# Line 2029  void MainForm::updateDisplayFont (void) Line 2274  void MainForm::updateDisplayFont (void)
2274  void MainForm::updateDisplayEffect (void)  void MainForm::updateDisplayEffect (void)
2275  {  {
2276          // Full channel list update...          // Full channel list update...
2277          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2278          if (wlist.isEmpty())          if (wlist.isEmpty())
2279                  return;                  return;
2280    
2281          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2282          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2283                  ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel);                  ChannelStrip *pChannelStrip = NULL;
2284                    QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2285                    if (pMdiSubWindow)
2286                            pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2287                  if (pChannelStrip)                  if (pChannelStrip)
2288                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
2289          }          }
# Line 2057  void MainForm::updateMaxVolume (void) Line 2305  void MainForm::updateMaxVolume (void)
2305  #endif  #endif
2306    
2307          // Full channel list update...          // Full channel list update...
2308          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2309          if (wlist.isEmpty())          if (wlist.isEmpty())
2310                  return;                  return;
2311    
2312          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
2313          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2314                  ChannelStrip* pChannelStrip = (ChannelStrip*) wlist.at(iChannel);                  ChannelStrip *pChannelStrip = NULL;
2315                    QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2316                    if (pMdiSubWindow)
2317                            pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2318                  if (pChannelStrip)                  if (pChannelStrip)
2319                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                          pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2320          }          }
# Line 2108  void MainForm::appendMessagesError( cons Line 2359  void MainForm::appendMessagesError( cons
2359          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);          QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2360    
2361          QMessageBox::critical(this,          QMessageBox::critical(this,
2362                  QSAMPLER_TITLE ": " + tr("Error"), s, tr("Cancel"));                  QSAMPLER_TITLE ": " + tr("Error"), s, QMessageBox::Cancel);
2363  }  }
2364    
2365    
# Line 2171  void MainForm::updateMessagesCapture (vo Line 2422  void MainForm::updateMessagesCapture (vo
2422  // qsamplerMainForm -- MDI channel strip management.  // qsamplerMainForm -- MDI channel strip management.
2423    
2424  // The channel strip creation executive.  // The channel strip creation executive.
2425  ChannelStrip* MainForm::createChannelStrip(qsamplerChannel* pChannel)  ChannelStrip *MainForm::createChannelStrip ( Channel *pChannel )
2426  {  {
2427          if (m_pClient == NULL || pChannel == NULL)          if (m_pClient == NULL || pChannel == NULL)
2428                  return NULL;                  return NULL;
2429    
         // Prepare for auto-arrange?  
         ChannelStrip* pChannelStrip = NULL;  
         int y = 0;  
         if (m_pOptions && m_pOptions->bAutoArrange) {  
                 QWidgetList wlist = m_pWorkspace->windowList();  
                 for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {  
                         pChannelStrip = static_cast<ChannelStrip *> (wlist.at(iChannel));  
                         if (pChannelStrip) {  
                         //  y += pChannelStrip->height()  
                         //              + pChannelStrip->parentWidget()->baseSize().height();  
                                 y += pChannelStrip->parentWidget()->frameGeometry().height();  
                         }  
                 }  
         }  
   
2430          // Add a new channel itema...          // Add a new channel itema...
2431          pChannelStrip = new ChannelStrip();          ChannelStrip *pChannelStrip = new ChannelStrip();
2432          if (pChannelStrip == NULL)          if (pChannelStrip == NULL)
2433                  return NULL;                  return NULL;
2434    
2435          m_pWorkspace->addWindow(pChannelStrip, Qt::FramelessWindowHint);          // Set some initial channel strip options...
   
         // Actual channel strip setup...  
         pChannelStrip->setup(pChannel);  
         QObject::connect(pChannelStrip,  
                 SIGNAL(channelChanged(ChannelStrip*)),  
                 SLOT(channelStripChanged(ChannelStrip*)));  
         // Set some initial aesthetic options...  
2436          if (m_pOptions) {          if (m_pOptions) {
2437                  // Background display effect...                  // Background display effect...
2438                  pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);                  pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
# Line 2215  ChannelStrip* MainForm::createChannelStr Line 2444  ChannelStrip* MainForm::createChannelStr
2444                  pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);                  pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
2445          }          }
2446    
2447            // Add it to workspace...
2448            m_pWorkspace->addSubWindow(pChannelStrip,
2449                    Qt::SubWindow | Qt::FramelessWindowHint);
2450    
2451            // Actual channel strip setup...
2452            pChannelStrip->setup(pChannel);
2453    
2454            QObject::connect(pChannelStrip,
2455                    SIGNAL(channelChanged(ChannelStrip *)),
2456                    SLOT(channelStripChanged(ChannelStrip *)));
2457    
2458          // Now we show up us to the world.          // Now we show up us to the world.
2459          pChannelStrip->show();          pChannelStrip->show();
         // Only then, we'll auto-arrange...  
         if (m_pOptions && m_pOptions->bAutoArrange) {  
                 int iWidth  = m_pWorkspace->width();  
         //  int iHeight = pChannel->height()  
         //              + pChannel->parentWidget()->baseSize().height();  
                 int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();  
                 pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);  
         }  
2460    
2461          // This is pretty new, so we'll watch for it closely.          // This is pretty new, so we'll watch for it closely.
2462          channelStripChanged(pChannelStrip);          channelStripChanged(pChannelStrip);
# Line 2234  ChannelStrip* MainForm::createChannelStr Line 2466  ChannelStrip* MainForm::createChannelStr
2466  }  }
2467    
2468    
2469    void MainForm::destroyChannelStrip ( ChannelStrip *pChannelStrip )
2470    {
2471            QMdiSubWindow *pMdiSubWindow
2472                    = static_cast<QMdiSubWindow *> (pChannelStrip->parentWidget());
2473            if (pMdiSubWindow == NULL)
2474                    return;
2475    
2476            // Just delete the channel strip.
2477            delete pChannelStrip;
2478            delete pMdiSubWindow;
2479    
2480            // Do we auto-arrange?
2481            if (m_pOptions && m_pOptions->bAutoArrange)
2482                    channelsArrange();
2483    
2484            stabilizeForm();
2485    }
2486    
2487    
2488  // Retrieve the active channel strip.  // Retrieve the active channel strip.
2489  ChannelStrip* MainForm::activeChannelStrip (void)  ChannelStrip *MainForm::activeChannelStrip (void)
2490  {  {
2491          return static_cast<ChannelStrip *> (m_pWorkspace->activeWindow());          QMdiSubWindow *pMdiSubWindow = m_pWorkspace->activeSubWindow();
2492            if (pMdiSubWindow)
2493                    return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2494            else
2495                    return NULL;
2496  }  }
2497    
2498    
2499  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
2500  ChannelStrip* MainForm::channelStripAt ( int iChannel )  ChannelStrip *MainForm::channelStripAt ( int iChannel )
2501  {  {
2502          QWidgetList wlist = m_pWorkspace->windowList();          if (!m_pWorkspace) return NULL;
2503    
2504            QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2505          if (wlist.isEmpty())          if (wlist.isEmpty())
2506                  return NULL;                  return NULL;
2507    
2508          return static_cast<ChannelStrip *> (wlist.at(iChannel));          if (iChannel < 0 || iChannel >= wlist.size())
2509                    return NULL;
2510    
2511            QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2512            if (pMdiSubWindow)
2513                    return static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2514            else
2515                    return NULL;
2516  }  }
2517    
2518    
2519  // Retrieve a channel strip by sampler channel id.  // Retrieve a channel strip by sampler channel id.
2520  ChannelStrip* MainForm::channelStrip ( int iChannelID )  ChannelStrip *MainForm::channelStrip ( int iChannelID )
2521  {  {
2522          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2523          if (wlist.isEmpty())          if (wlist.isEmpty())
2524                  return NULL;                  return NULL;
2525    
2526          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2527                  ChannelStrip* pChannelStrip                  ChannelStrip *pChannelStrip = NULL;
2528                          = static_cast<ChannelStrip*> (wlist.at(iChannel));                  QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2529                    if (pMdiSubWindow)
2530                            pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2531                  if (pChannelStrip) {                  if (pChannelStrip) {
2532                          qsamplerChannel *pChannel = pChannelStrip->channel();                          Channel *pChannel = pChannelStrip->channel();
2533                          if (pChannel && pChannel->channelID() == iChannelID)                          if (pChannel && pChannel->channelID() == iChannelID)
2534                                  return pChannelStrip;                                  return pChannelStrip;
2535                  }                  }
# Line 2281  void MainForm::channelsMenuAboutToShow ( Line 2547  void MainForm::channelsMenuAboutToShow (
2547          m_ui.channelsMenu->addAction(m_ui.channelsArrangeAction);          m_ui.channelsMenu->addAction(m_ui.channelsArrangeAction);
2548          m_ui.channelsMenu->addAction(m_ui.channelsAutoArrangeAction);          m_ui.channelsMenu->addAction(m_ui.channelsAutoArrangeAction);
2549    
2550          QWidgetList wlist = m_pWorkspace->windowList();          QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2551          if (!wlist.isEmpty()) {          if (!wlist.isEmpty()) {
2552                  m_ui.channelsMenu->addSeparator();                  m_ui.channelsMenu->addSeparator();
2553                  for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {                  for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2554                          ChannelStrip* pChannelStrip                          ChannelStrip *pChannelStrip = NULL;
2555                                  = static_cast<ChannelStrip*> (wlist.at(iChannel));                          QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2556                            if (pMdiSubWindow)
2557                                    pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2558                          if (pChannelStrip) {                          if (pChannelStrip) {
2559                                  QAction *pAction = m_ui.channelsMenu->addAction(                                  QAction *pAction = m_ui.channelsMenu->addAction(
2560                                          pChannelStrip->windowTitle(),                                          pChannelStrip->windowTitle(),
# Line 2308  void MainForm::channelsMenuActivated (vo Line 2576  void MainForm::channelsMenuActivated (vo
2576          if (pAction == NULL)          if (pAction == NULL)
2577                  return;                  return;
2578    
2579          ChannelStrip* pChannelStrip = channelStripAt(pAction->data().toInt());          ChannelStrip *pChannelStrip = channelStripAt(pAction->data().toInt());
2580          if (pChannelStrip) {          if (pChannelStrip) {
2581                  pChannelStrip->showNormal();                  pChannelStrip->showNormal();
2582                  pChannelStrip->setFocus();                  pChannelStrip->setFocus();
# Line 2369  void MainForm::timerSlot (void) Line 2637  void MainForm::timerSlot (void)
2637                          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {                          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {
2638                                  m_iTimerSlot = 0;                                  m_iTimerSlot = 0;
2639                                  // Update the channel stream usage for each strip...                                  // Update the channel stream usage for each strip...
2640                                  QWidgetList wlist = m_pWorkspace->windowList();                                  QList<QMdiSubWindow *> wlist = m_pWorkspace->subWindowList();
2641                                  for (int iChannel = 0;                                  for (int iChannel = 0; iChannel < (int) wlist.count(); ++iChannel) {
2642                                                  iChannel < (int) wlist.count(); iChannel++) {                                          ChannelStrip *pChannelStrip = NULL;
2643                                          ChannelStrip* pChannelStrip                                          QMdiSubWindow *pMdiSubWindow = wlist.at(iChannel);
2644                                                  = (ChannelStrip*) wlist.at(iChannel);                                          if (pMdiSubWindow)
2645                                                    pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
2646                                          if (pChannelStrip && pChannelStrip->isVisible())                                          if (pChannelStrip && pChannelStrip->isVisible())
2647                                                  pChannelStrip->updateChannelUsage();                                                  pChannelStrip->updateChannelUsage();
2648                                  }                                  }
# Line 2401  void MainForm::startServer (void) Line 2670  void MainForm::startServer (void)
2670    
2671          // Is the server process instance still here?          // Is the server process instance still here?
2672          if (m_pServer) {          if (m_pServer) {
2673                  switch (QMessageBox::warning(this,                  if (QMessageBox::warning(this,
2674                          QSAMPLER_TITLE ": " + tr("Warning"),                          QSAMPLER_TITLE ": " + tr("Warning"),
2675                          tr("Could not start the LinuxSampler server.\n\n"                          tr("Could not start the LinuxSampler server.\n\n"
2676                          "Maybe it ss already started."),                          "Maybe it is already started."),
2677                          tr("Stop"), tr("Kill"), tr("Cancel"))) {                          QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok) {
                 case 0:  
2678                          m_pServer->terminate();                          m_pServer->terminate();
                         break;  
                 case 1:  
2679                          m_pServer->kill();                          m_pServer->kill();
                         break;  
2680                  }                  }
2681                  return;                  return;
2682          }          }
# Line 2424  void MainForm::startServer (void) Line 2689  void MainForm::startServer (void)
2689                  return;                  return;
2690    
2691          // OK. Let's build the startup process...          // OK. Let's build the startup process...
2692          m_pServer = new QProcess(this);          m_pServer = new QProcess();
2693            bForceServerStop = true;
2694    
2695          // Setup stdout/stderr capture...          // Setup stdout/stderr capture...
2696  //      if (m_pOptions->bStdoutCapture) {  //      if (m_pOptions->bStdoutCapture) {
2697                  //m_pServer->setProcessChannelMode(                  m_pServer->setProcessChannelMode(QProcess::ForwardedChannels);
                 //      QProcess::StandardOutput);  
2698                  QObject::connect(m_pServer,                  QObject::connect(m_pServer,
2699                          SIGNAL(readyReadStandardOutput()),                          SIGNAL(readyReadStandardOutput()),
2700                          SLOT(readServerStdout()));                          SLOT(readServerStdout()));
# Line 2440  void MainForm::startServer (void) Line 2705  void MainForm::startServer (void)
2705    
2706          // The unforgiveable signal communication...          // The unforgiveable signal communication...
2707          QObject::connect(m_pServer,          QObject::connect(m_pServer,
2708                  SIGNAL(finished(int,QProcess::ExitStatus)),                  SIGNAL(finished(int, QProcess::ExitStatus)),
2709                  SLOT(processServerExit()));                  SLOT(processServerExit()));
2710    
2711          // Build process arguments...          // Build process arguments...
# Line 2471  void MainForm::startServer (void) Line 2736  void MainForm::startServer (void)
2736    
2737    
2738  // Stop linuxsampler server...  // Stop linuxsampler server...
2739  void MainForm::stopServer (void)  void MainForm::stopServer (bool bInteractive)
2740  {  {
2741          // Stop client code.          // Stop client code.
2742          stopClient();          stopClient();
2743    
2744            if (m_pServer && bInteractive) {
2745                    if (QMessageBox::question(this,
2746                            QSAMPLER_TITLE ": " + tr("The backend's fate ..."),
2747                            tr("You have the option to keep the sampler backend (LinuxSampler)\n"
2748                            "running in the background. The sampler would continue to work\n"
2749                            "according to your current sampler session and you could alter the\n"
2750                            "sampler session at any time by relaunching QSampler.\n\n"
2751                            "Do you want LinuxSampler to stop?"),
2752                            QMessageBox::Yes | QMessageBox::No,
2753                            QMessageBox::Yes) == QMessageBox::No)
2754                    {
2755                            bForceServerStop = false;
2756                    }
2757            }
2758    
2759          // And try to stop server.          // And try to stop server.
2760          if (m_pServer) {          if (m_pServer && bForceServerStop) {
2761                  appendMessages(tr("Server is stopping..."));                  appendMessages(tr("Server is stopping..."));
2762                  if (m_pServer->state() == QProcess::Running)                  if (m_pServer->state() == QProcess::Running) {
2763                    #if defined(WIN32)
2764                            // Try harder...
2765                            m_pServer->kill();
2766                    #else
2767                            // Try softly...
2768                          m_pServer->terminate();                          m_pServer->terminate();
2769          }                  #endif
2770                    }
2771            }       // Do final processing anyway.
2772            else processServerExit();
2773    
2774          // Give it some time to terminate gracefully and stabilize...          // Give it some time to terminate gracefully and stabilize...
2775          QTime t;          QTime t;
2776          t.start();          t.start();
2777          while (t.elapsed() < QSAMPLER_TIMER_MSECS)          while (t.elapsed() < QSAMPLER_TIMER_MSECS)
2778                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);                  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
   
         // Do final processing anyway.  
         processServerExit();  
2779  }  }
2780    
2781    
# Line 2512  void MainForm::processServerExit (void) Line 2797  void MainForm::processServerExit (void)
2797          if (m_pMessages)          if (m_pMessages)
2798                  m_pMessages->flushStdoutBuffer();                  m_pMessages->flushStdoutBuffer();
2799    
2800          if (m_pServer) {          if (m_pServer && bForceServerStop) {
2801                    if (m_pServer->state() != QProcess::NotRunning) {
2802                            appendMessages(tr("Server is being forced..."));
2803                            // Force final server shutdown...
2804                            m_pServer->kill();
2805                            // Give it some time to terminate gracefully and stabilize...
2806                            QTime t;
2807                            t.start();
2808                            while (t.elapsed() < QSAMPLER_TIMER_MSECS)
2809                                    QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
2810                    }
2811                  // Force final server shutdown...                  // Force final server shutdown...
2812                  appendMessages(                  appendMessages(
2813                          tr("Server was stopped with exit status %1.")                          tr("Server was stopped with exit status %1.")
2814                          .arg(m_pServer->exitStatus()));                          .arg(m_pServer->exitStatus()));
                 m_pServer->terminate();  
                 if (!m_pServer->waitForFinished(2000))  
                         m_pServer->kill();  
                 // Destroy it.  
2815                  delete m_pServer;                  delete m_pServer;
2816                  m_pServer = NULL;                  m_pServer = NULL;
2817          }          }
# Line 2545  lscp_status_t qsampler_client_callback ( Line 2836  lscp_status_t qsampler_client_callback (
2836          // as this is run under some other thread context.          // as this is run under some other thread context.
2837          // A custom event must be posted here...          // A custom event must be posted here...
2838          QApplication::postEvent(pMainForm,          QApplication::postEvent(pMainForm,
2839                  new qsamplerCustomEvent(event, pchData, cchData));                  new LscpEvent(event, pchData, cchData));
2840    
2841          return LSCP_OK;          return LSCP_OK;
2842  }  }
# Line 2590  bool MainForm::startClient (void) Line 2881  bool MainForm::startClient (void)
2881                  .arg(::lscp_client_get_timeout(m_pClient)));                  .arg(::lscp_client_get_timeout(m_pClient)));
2882    
2883          // Subscribe to channel info change notifications...          // Subscribe to channel info change notifications...
2884            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT) != LSCP_OK)
2885                    appendMessagesClient("lscp_client_subscribe(CHANNEL_COUNT)");
2886          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)          if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)
2887                  appendMessagesClient("lscp_client_subscribe");                  appendMessagesClient("lscp_client_subscribe(CHANNEL_INFO)");
2888    
2889            DeviceStatusForm::onDevicesChanged(); // initialize
2890            updateViewMidiDeviceStatusMenu();
2891            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT) != LSCP_OK)
2892                    appendMessagesClient("lscp_client_subscribe(MIDI_INPUT_DEVICE_COUNT)");
2893            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO) != LSCP_OK)
2894                    appendMessagesClient("lscp_client_subscribe(MIDI_INPUT_DEVICE_INFO)");
2895            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT) != LSCP_OK)
2896                    appendMessagesClient("lscp_client_subscribe(AUDIO_OUTPUT_DEVICE_COUNT)");
2897            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO) != LSCP_OK)
2898                    appendMessagesClient("lscp_client_subscribe(AUDIO_OUTPUT_DEVICE_INFO)");
2899    
2900    #if CONFIG_EVENT_CHANNEL_MIDI
2901            // Subscribe to channel MIDI data notifications...
2902            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI) != LSCP_OK)
2903                    appendMessagesClient("lscp_client_subscribe(CHANNEL_MIDI)");
2904    #endif
2905    
2906    #if CONFIG_EVENT_DEVICE_MIDI
2907            // Subscribe to channel MIDI data notifications...
2908            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI) != LSCP_OK)
2909                    appendMessagesClient("lscp_client_subscribe(DEVICE_MIDI)");
2910    #endif
2911    
2912          // We may stop scheduling around.          // We may stop scheduling around.
2913          stopSchedule();          stopSchedule();
# Line 2618  bool MainForm::startClient (void) Line 2934  bool MainForm::startClient (void)
2934                  }                  }
2935          }          }
2936    
2937            // send the current / loaded fine tuning settings to the sampler
2938            m_pOptions->sendFineTuningSettings();
2939    
2940          // Make a new session          // Make a new session
2941          return newSession();          return newSession();
2942  }  }
# Line 2645  void MainForm::stopClient (void) Line 2964  void MainForm::stopClient (void)
2964          closeSession(false);          closeSession(false);
2965    
2966          // Close us as a client...          // Close us as a client...
2967    #if CONFIG_EVENT_DEVICE_MIDI
2968            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_DEVICE_MIDI);
2969    #endif
2970    #if CONFIG_EVENT_CHANNEL_MIDI
2971            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_MIDI);
2972    #endif
2973            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_INFO);
2974            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_AUDIO_OUTPUT_DEVICE_COUNT);
2975            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_INFO);
2976            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_MIDI_INPUT_DEVICE_COUNT);
2977          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
2978            ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_COUNT);
2979          ::lscp_client_destroy(m_pClient);          ::lscp_client_destroy(m_pClient);
2980          m_pClient = NULL;          m_pClient = NULL;
2981    
# Line 2663  void MainForm::stopClient (void) Line 2993  void MainForm::stopClient (void)
2993          stabilizeForm();          stabilizeForm();
2994  }  }
2995    
2996    
2997    // Channel strip activation/selection.
2998    void MainForm::activateStrip ( QMdiSubWindow *pMdiSubWindow )
2999    {
3000            ChannelStrip *pChannelStrip = NULL;
3001            if (pMdiSubWindow)
3002                    pChannelStrip = static_cast<ChannelStrip *> (pMdiSubWindow->widget());
3003            if (pChannelStrip)
3004                    pChannelStrip->setSelected(true);
3005    
3006            stabilizeForm();
3007    }
3008    
3009    
3010    // Channel toolbar orientation change.
3011    void MainForm::channelsToolbarOrientation ( Qt::Orientation orientation )
3012    {
3013    #ifdef CONFIG_VOLUME
3014            m_pVolumeSlider->setOrientation(orientation);
3015            if (orientation == Qt::Horizontal) {
3016                    m_pVolumeSlider->setMinimumHeight(24);
3017                    m_pVolumeSlider->setMaximumHeight(32);
3018                    m_pVolumeSlider->setMinimumWidth(120);
3019                    m_pVolumeSlider->setMaximumWidth(640);
3020                    m_pVolumeSpinBox->setMaximumWidth(64);
3021                    m_pVolumeSpinBox->setButtonSymbols(QSpinBox::UpDownArrows);
3022            } else {
3023                    m_pVolumeSlider->setMinimumHeight(120);
3024                    m_pVolumeSlider->setMaximumHeight(480);
3025                    m_pVolumeSlider->setMinimumWidth(24);
3026                    m_pVolumeSlider->setMaximumWidth(32);
3027                    m_pVolumeSpinBox->setMaximumWidth(32);
3028                    m_pVolumeSpinBox->setButtonSymbols(QSpinBox::NoButtons);
3029            }
3030    #endif
3031    }
3032    
3033    
3034  } // namespace QSampler  } // namespace QSampler
3035    
3036    

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

  ViewVC Help
Powered by ViewVC