/[svn]/qsampler/trunk/src/qsamplerMainForm.ui.h
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerMainForm.ui.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 149 by capela, Sat Jun 26 14:27:25 2004 UTC revision 987 by capela, Tue Dec 19 11:19:55 2006 UTC
# Line 2  Line 2 
2  //  //
3  // ui.h extension file, included from the uic-generated form implementation.  // ui.h extension file, included from the uic-generated form implementation.
4  /****************************************************************************  /****************************************************************************
5     Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2006, rncbc aka Rui Nuno Capela. All rights reserved.
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 14  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
# Line 26  Line 26 
26  #include <qprocess.h>  #include <qprocess.h>
27  #include <qmessagebox.h>  #include <qmessagebox.h>
28  #include <qdragobject.h>  #include <qdragobject.h>
29    #include <qregexp.h>
30  #include <qfiledialog.h>  #include <qfiledialog.h>
31  #include <qfileinfo.h>  #include <qfileinfo.h>
32  #include <qfile.h>  #include <qfile.h>
# Line 36  Line 37 
37    
38  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
39  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
40    #include "qsamplerChannel.h"
41  #include "qsamplerMessages.h"  #include "qsamplerMessages.h"
42    
43  #include "qsamplerChannelStrip.h"  #include "qsamplerChannelStrip.h"
44    #include "qsamplerInstrumentList.h"
45    
46    #include "qsamplerInstrumentListForm.h"
47    #include "qsamplerDeviceForm.h"
48  #include "qsamplerOptionsForm.h"  #include "qsamplerOptionsForm.h"
49    
50  #include "config.h"  #ifdef HAVE_SIGNAL_H
51    #include <signal.h>
52    #endif
53    
54    #ifdef CONFIG_LIBGIG
55    #include <gig.h>
56    #endif
57    
58  // Timer constant stuff.  // Timer constant stuff.
59  #define QSAMPLER_TIMER_MSECS    200  #define QSAMPLER_TIMER_MSECS    200
# Line 93  private: Line 104  private:
104  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
105  // qsamplerMainForm -- Main window form implementation.  // qsamplerMainForm -- Main window form implementation.
106    
107    // Kind of singleton reference.
108    qsamplerMainForm *qsamplerMainForm::g_pMainForm = NULL;
109    
110    
111  // Kind of constructor.  // Kind of constructor.
112  void qsamplerMainForm::init (void)  void qsamplerMainForm::init (void)
113  {  {
114            // Pseudo-singleton reference setup.
115            g_pMainForm = this;
116    
117      // Initialize some pointer references.      // Initialize some pointer references.
118      m_pOptions = NULL;      m_pOptions = NULL;
119    
120      // All child forms are to be created later, not earlier than setup.      // All child forms are to be created later, not earlier than setup.
121      m_pMessages = NULL;      m_pMessages = NULL;
122        m_pInstrumentListForm = NULL;
123        m_pDeviceForm = NULL;
124    
125      // We'll start clean.      // We'll start clean.
126      m_iUntitled = 0;      m_iUntitled   = 0;
127      m_iDirtyCount = 0;      m_iDirtyCount = 0;
128    
129      m_pServer = NULL;      m_pServer = NULL;
# Line 114  void qsamplerMainForm::init (void) Line 134  void qsamplerMainForm::init (void)
134    
135      m_iTimerSlot = 0;      m_iTimerSlot = 0;
136    
137    #ifdef HAVE_SIGNAL_H
138            // Set to ignore any fatal "Broken pipe" signals.
139            ::signal(SIGPIPE, SIG_IGN);
140    #endif
141    
142      // Make it an MDI workspace.      // Make it an MDI workspace.
143      m_pWorkspace = new QWorkspace(this);      m_pWorkspace = new QWorkspace(this);
144      m_pWorkspace->setScrollBarsEnabled(true);      m_pWorkspace->setScrollBarsEnabled(true);
# Line 128  void qsamplerMainForm::init (void) Line 153  void qsamplerMainForm::init (void)
153      pLabel = new QLabel(tr("Connected"), this);      pLabel = new QLabel(tr("Connected"), this);
154      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
155      pLabel->setMinimumSize(pLabel->sizeHint());      pLabel->setMinimumSize(pLabel->sizeHint());
156      m_status[QSAMPLER_STATUS_CLIENT] = pLabel;      m_statusItem[QSAMPLER_STATUS_CLIENT] = pLabel;
157      statusBar()->addWidget(pLabel);      statusBar()->addWidget(pLabel);
158      // Server address.      // Server address.
159      pLabel = new QLabel(this);      pLabel = new QLabel(this);
160      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
161      m_status[QSAMPLER_STATUS_SERVER] = pLabel;      m_statusItem[QSAMPLER_STATUS_SERVER] = pLabel;
162      statusBar()->addWidget(pLabel, 1);      statusBar()->addWidget(pLabel, 1);
163      // Channel title.      // Channel title.
164      pLabel = new QLabel(this);      pLabel = new QLabel(this);
165      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
166      m_status[QSAMPLER_STATUS_CHANNEL] = pLabel;      m_statusItem[QSAMPLER_STATUS_CHANNEL] = pLabel;
167      statusBar()->addWidget(pLabel, 2);      statusBar()->addWidget(pLabel, 2);
168      // Session modification status.      // Session modification status.
169      pLabel = new QLabel(tr("MOD"), this);      pLabel = new QLabel(tr("MOD"), this);
170      pLabel->setAlignment(Qt::AlignHCenter);      pLabel->setAlignment(Qt::AlignHCenter);
171      pLabel->setMinimumSize(pLabel->sizeHint());      pLabel->setMinimumSize(pLabel->sizeHint());
172      m_status[QSAMPLER_STATUS_SESSION] = pLabel;      m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;
173      statusBar()->addWidget(pLabel);      statusBar()->addWidget(pLabel);
174    
175      // Create the recent files sub-menu.      // Create the recent files sub-menu.
# Line 163  void qsamplerMainForm::destroy (void) Line 188  void qsamplerMainForm::destroy (void)
188  {  {
189      // Do final processing anyway.      // Do final processing anyway.
190      processServerExit();      processServerExit();
191        
192      // Delete recentfiles menu.  #if defined(WIN32)
193      if (m_pRecentFilesMenu)      WSACleanup();
194          delete m_pRecentFilesMenu;  #endif
     // Delete status item labels one by one.  
     if (m_status[QSAMPLER_STATUS_CLIENT])  
         delete m_status[QSAMPLER_STATUS_CLIENT];  
     if (m_status[QSAMPLER_STATUS_SERVER])  
         delete m_status[QSAMPLER_STATUS_SERVER];  
     if (m_status[QSAMPLER_STATUS_CHANNEL])  
         delete m_status[QSAMPLER_STATUS_CHANNEL];  
     if (m_status[QSAMPLER_STATUS_SESSION])  
         delete m_status[QSAMPLER_STATUS_SESSION];  
195    
196      // Finally drop any widgets around...      // Finally drop any widgets around...
197        if (m_pDeviceForm)
198            delete m_pDeviceForm;
199        if (m_pInstrumentListForm)
200            delete m_pInstrumentListForm;
201      if (m_pMessages)      if (m_pMessages)
202          delete m_pMessages;          delete m_pMessages;
203      if (m_pWorkspace)      if (m_pWorkspace)
204          delete m_pWorkspace;          delete m_pWorkspace;
205    
206  #if defined(WIN32)      // Delete status item labels one by one.
207      WSACleanup();      if (m_statusItem[QSAMPLER_STATUS_CLIENT])
208  #endif          delete m_statusItem[QSAMPLER_STATUS_CLIENT];
209        if (m_statusItem[QSAMPLER_STATUS_SERVER])
210            delete m_statusItem[QSAMPLER_STATUS_SERVER];
211        if (m_statusItem[QSAMPLER_STATUS_CHANNEL])
212            delete m_statusItem[QSAMPLER_STATUS_CHANNEL];
213        if (m_statusItem[QSAMPLER_STATUS_SESSION])
214            delete m_statusItem[QSAMPLER_STATUS_SESSION];
215    
216        // Delete recentfiles menu.
217        if (m_pRecentFilesMenu)
218            delete m_pRecentFilesMenu;
219    
220            // Pseudo-singleton reference shut-down.
221            g_pMainForm = NULL;
222  }  }
223    
224    
# Line 195  void qsamplerMainForm::setup ( qsamplerO Line 228  void qsamplerMainForm::setup ( qsamplerO
228      // We got options?      // We got options?
229      m_pOptions = pOptions;      m_pOptions = pOptions;
230    
231        // What style do we create these forms?
232            Qt::WFlags wflags = Qt::WStyle_Customize
233                    | Qt::WStyle_NormalBorder
234                    | Qt::WStyle_Title
235                    | Qt::WStyle_SysMenu
236                    | Qt::WStyle_MinMax
237                    | Qt::WType_TopLevel;
238        if (m_pOptions->bKeepOnTop)
239            wflags |= Qt::WStyle_Tool;
240      // Some child forms are to be created right now.      // Some child forms are to be created right now.
241      m_pMessages = new qsamplerMessages(this);      m_pMessages = new qsamplerMessages(this);
242        m_pDeviceForm = new qsamplerDeviceForm(this, 0, wflags);
243    #ifdef CONFIG_MIDI_INSTRUMENT
244        m_pInstrumentListForm = new qsamplerInstrumentListForm(this, 0, wflags);
245            QObject::connect(m_pInstrumentListForm->InstrumentList,
246                    SIGNAL(instrumentsChanged()),
247                    SLOT(sessionDirty()));
248    #else
249            viewInstrumentsAction->setEnabled(false);
250    #endif
251      // Set message defaults...      // Set message defaults...
252      updateMessagesFont();      updateMessagesFont();
253      updateMessagesLimit();      updateMessagesLimit();
254      updateMessagesCapture();      updateMessagesCapture();
255      // Set the visibility signal.      // Set the visibility signal.
256      QObject::connect(m_pMessages, SIGNAL(visibilityChanged(bool)), this, SLOT(stabilizeForm()));      QObject::connect(m_pMessages,
257                    SIGNAL(visibilityChanged(bool)),
258                    SLOT(stabilizeForm()));
259    
260      // Initial decorations toggle state.      // Initial decorations toggle state.
261      viewMenubarAction->setOn(m_pOptions->bMenubar);      viewMenubarAction->setOn(m_pOptions->bMenubar);
# Line 225  void qsamplerMainForm::setup ( qsamplerO Line 278  void qsamplerMainForm::setup ( qsamplerO
278          QTextIStream istr(&sDockables);          QTextIStream istr(&sDockables);
279          istr >> *this;          istr >> *this;
280      }      }
281      // Try to restore old window positioning.      // Try to restore old window positioning and initial visibility.
282      m_pOptions->loadWidgetGeometry(this);      m_pOptions->loadWidgetGeometry(this);
283        m_pOptions->loadWidgetGeometry(m_pInstrumentListForm);
284        m_pOptions->loadWidgetGeometry(m_pDeviceForm);
285    
286      // Final startup stabilization...      // Final startup stabilization...
287      updateRecentFilesMenu();      updateRecentFilesMenu();
# Line 264  bool qsamplerMainForm::queryClose (void) Line 319  bool qsamplerMainForm::queryClose (void)
319              QTextOStream ostr(&sDockables);              QTextOStream ostr(&sDockables);
320              ostr << *this;              ostr << *this;
321              m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables);              m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables);
322              // And the main windows state.              // And the children, and the main windows state,.
323              m_pOptions->saveWidgetGeometry(this);                          m_pOptions->saveWidgetGeometry(m_pDeviceForm);
324                            m_pOptions->saveWidgetGeometry(m_pInstrumentListForm);
325                            m_pOptions->saveWidgetGeometry(this);
326                            // Close popup widgets.
327                            if (m_pInstrumentListForm)
328                                    m_pInstrumentListForm->close();
329                            if (m_pDeviceForm)
330                                    m_pDeviceForm->close();
331              // Stop client and/or server, gracefully.              // Stop client and/or server, gracefully.
332              stopServer();              stopServer();
333          }          }
# Line 284  void qsamplerMainForm::closeEvent ( QClo Line 346  void qsamplerMainForm::closeEvent ( QClo
346  }  }
347    
348    
349  // Window drag-n-drop event handlers.  // Drag'n'drop file handler.
350  void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files )
351  {  {
352      bool bAccept = false;      bool bDecode = false;
353    
354      if (QTextDrag::canDecode(pDragEnterEvent)) {      if (QTextDrag::canDecode(pEvent)) {
355          QString sUrl;          QString sText;
356          if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient)          bDecode = QTextDrag::decode(pEvent, sText);
357              bAccept = QFileInfo(QUrl(sUrl).path()).exists();          if (bDecode) {
358                files = QStringList::split('\n', sText);
359                for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++)
360                    *iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path();
361            }
362      }      }
363    
364      pDragEnterEvent->accept(bAccept);      return bDecode;
365    }
366    
367    
368    // Window drag-n-drop event handlers.
369    void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
370    {
371            QStringList files;
372            pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files));
373  }  }
374    
375    
376  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )
377  {  {
378      if (QTextDrag::canDecode(pDropEvent)) {      QStringList files;
379          QString sUrl;  
380          if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true))      if (!decodeDragFiles(pDropEvent, files))
381              loadSessionFile(QUrl(sUrl).path());          return;
382      }  
383            for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) {
384                    const QString& sPath = *iter;
385                    if (qsamplerChannel::isInstrumentFile(sPath)) {
386                            // Try to create a new channel from instrument file...
387                            qsamplerChannel *pChannel = new qsamplerChannel();
388                            if (pChannel == NULL)
389                                    return;
390                            // Start setting the instrument filename...
391                            pChannel->setInstrument(sPath, 0);
392                            // Before we show it up, may be we'll
393                            // better ask for some initial values?
394                            if (!pChannel->channelSetup(this)) {
395                                    delete pChannel;
396                                    return;
397                            }
398                            // Finally, give it to a new channel strip...
399                            if (!createChannelStrip(pChannel)) {
400                                    delete pChannel;
401                                    return;
402                            }
403                            // Make that an overall update.
404                            m_iDirtyCount++;
405                            stabilizeForm();
406                    }   // Otherwise, load an usual session file (LSCP script)...
407                    else if (closeSession(true)) {
408                            loadSessionFile(sPath);
409                            break;
410                    }
411                    // Make it look responsive...:)
412                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
413            }
414  }  }
415    
416    
# Line 315  void qsamplerMainForm::customEvent ( QCu Line 420  void qsamplerMainForm::customEvent ( QCu
420      // For the time being, just pump it to messages.      // For the time being, just pump it to messages.
421      if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {      if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {
422          qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent;          qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent;
423          appendMessagesColor(tr("Notify event: %1 data: %2")                  if (pEvent->event() == LSCP_EVENT_CHANNEL_INFO) {
424              .arg(::lscp_event_to_text(pEvent->event()))                          int iChannelID = pEvent->data().toInt();
425              .arg(pEvent->data()), "#996699");                          qsamplerChannelStrip *pChannelStrip = channelStrip(iChannelID);
426                            if (pChannelStrip)
427                                    channelStripChanged(pChannelStrip);
428                    } else {
429                            appendMessagesColor(tr("Notify event: %1 data: %2")
430                                    .arg(::lscp_event_to_text(pEvent->event()))
431                                    .arg(pEvent->data()), "#996699");
432                    }
433      }      }
434  }  }
435    
# Line 326  void qsamplerMainForm::customEvent ( QCu Line 438  void qsamplerMainForm::customEvent ( QCu
438  void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent )
439  {  {
440      stabilizeForm();      stabilizeForm();
441        
442      editMenu->exec(pEvent->globalPos());      editMenu->exec(pEvent->globalPos());
443  }  }
444    
# Line 340  qsamplerOptions *qsamplerMainForm::optio Line 452  qsamplerOptions *qsamplerMainForm::optio
452      return m_pOptions;      return m_pOptions;
453  }  }
454    
455    
456  // The LSCP client descriptor property.  // The LSCP client descriptor property.
457  lscp_client_t *qsamplerMainForm::client (void)  lscp_client_t *qsamplerMainForm::client (void)
458  {  {
# Line 347  lscp_client_t *qsamplerMainForm::client Line 460  lscp_client_t *qsamplerMainForm::client
460  }  }
461    
462    
463    // The pseudo-singleton instance accessor.
464    qsamplerMainForm *qsamplerMainForm::getInstance (void)
465    {
466            return g_pMainForm;
467    }
468    
469    
470  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
471  // qsamplerMainForm -- Session file stuff.  // qsamplerMainForm -- Session file stuff.
472    
# Line 370  bool qsamplerMainForm::newSession (void) Line 490  bool qsamplerMainForm::newSession (void)
490      if (!closeSession(true))      if (!closeSession(true))
491          return false;          return false;
492    
493            // Give us what the server has, right now...
494            updateSession();
495    
496      // Ok increment untitled count.      // Ok increment untitled count.
497      m_iUntitled++;      m_iUntitled++;
498    
# Line 391  bool qsamplerMainForm::openSession (void Line 514  bool qsamplerMainForm::openSession (void
514    
515      // Ask for the filename to open...      // Ask for the filename to open...
516      QString sFilename = QFileDialog::getOpenFileName(      QString sFilename = QFileDialog::getOpenFileName(
517              m_pOptions->sSessionDir,                // Start here.                  m_pOptions->sSessionDir,                // Start here.
518              tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)                  tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)
519              this, 0,                                // Parent and name (none)                  this, 0,                                // Parent and name (none)
520              tr("Open Session")                      // Caption.                  QSAMPLER_TITLE ": " + tr("Open Session")        // Caption.
521      );      );
522    
523      // Have we cancelled?      // Have we cancelled?
# Line 425  bool qsamplerMainForm::saveSession ( boo Line 548  bool qsamplerMainForm::saveSession ( boo
548              sFilename = m_pOptions->sSessionDir;              sFilename = m_pOptions->sSessionDir;
549          // Prompt the guy...          // Prompt the guy...
550          sFilename = QFileDialog::getSaveFileName(          sFilename = QFileDialog::getSaveFileName(
551                  sFilename,                              // Start here.                          sFilename,                              // Start here.
552                  tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)                          tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)
553                  this, 0,                                // Parent and name (none)                          this, 0,                                // Parent and name (none)
554                  tr("Save Session")                      // Caption.                          QSAMPLER_TITLE ": " + tr("Save Session")        // Caption.
555          );          );
556          // Have we cancelled it?          // Have we cancelled it?
557          if (sFilename.isEmpty())          if (sFilename.isEmpty())
# Line 438  bool qsamplerMainForm::saveSession ( boo Line 561  bool qsamplerMainForm::saveSession ( boo
561              sFilename += ".lscp";              sFilename += ".lscp";
562          // Check if already exists...          // Check if already exists...
563          if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {          if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {
564              if (QMessageBox::warning(this, tr("Warning"),              if (QMessageBox::warning(this,
565                                    QSAMPLER_TITLE ": " + tr("Warning"),
566                  tr("The file already exists:\n\n"                  tr("The file already exists:\n\n"
567                     "\"%1\"\n\n"                     "\"%1\"\n\n"
568                     "Do you want to replace it?")                     "Do you want to replace it?")
# Line 460  bool qsamplerMainForm::closeSession ( bo Line 584  bool qsamplerMainForm::closeSession ( bo
584    
585      // Are we dirty enough to prompt it?      // Are we dirty enough to prompt it?
586      if (m_iDirtyCount > 0) {      if (m_iDirtyCount > 0) {
587          switch (QMessageBox::warning(this, tr("Warning"),          switch (QMessageBox::warning(this,
588                            QSAMPLER_TITLE ": " + tr("Warning"),
589              tr("The current session has been changed:\n\n"              tr("The current session has been changed:\n\n"
590              "\"%1\"\n\n"              "\"%1\"\n\n"
591              "Do you want to save the changes?")              "Do you want to save the changes?")
# Line 483  bool qsamplerMainForm::closeSession ( bo Line 608  bool qsamplerMainForm::closeSession ( bo
608          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
609          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
610          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
611              qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
612              if (bForce && ::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK)              if (pChannelStrip) {
613                  appendMessagesClient("lscp_remove_channel");                  qsamplerChannel *pChannel = pChannelStrip->channel();
614              delete pChannel;                  if (bForce && pChannel)
615                        pChannel->removeChannel();
616                    delete pChannelStrip;
617                }
618          }          }
619          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
620          // We're now clean, for sure.          // We're now clean, for sure.
# Line 510  bool qsamplerMainForm::loadSessionFile ( Line 638  bool qsamplerMainForm::loadSessionFile (
638          return false;          return false;
639      }      }
640    
641            // Tell the world we'll take some time...
642            QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
643    
644      // Read the file.      // Read the file.
645            int iLine = 0;
646      int iErrors = 0;      int iErrors = 0;
647      QTextStream ts(&file);      QTextStream ts(&file);
648      while (!ts.atEnd()) {      while (!ts.atEnd()) {
649          // Read the line.          // Read the line.
650          QString sCommand = ts.readLine().simplifyWhiteSpace();          QString sCommand = ts.readLine().stripWhiteSpace();
651                    iLine++;
652          // If not empty, nor a comment, call the server...          // If not empty, nor a comment, call the server...
653          if (!sCommand.isEmpty() && sCommand[0] != '#') {          if (!sCommand.isEmpty() && sCommand[0] != '#') {
             appendMessagesColor(sCommand, "#996633");  
654              // Remember that, no matter what,              // Remember that, no matter what,
655              // all LSCP commands are CR/LF terminated.              // all LSCP commands are CR/LF terminated.
656              sCommand += "\r\n";              sCommand += "\r\n";
657              if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {              if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {
658                                    appendMessagesColor(QString("%1(%2): %3")
659                                            .arg(QFileInfo(sFilename).fileName()).arg(iLine)
660                                            .arg(sCommand.simplifyWhiteSpace()), "#996633");
661                  appendMessagesClient("lscp_client_query");                  appendMessagesClient("lscp_client_query");
662                  iErrors++;                  iErrors++;
663              }              }
# Line 534  bool qsamplerMainForm::loadSessionFile ( Line 669  bool qsamplerMainForm::loadSessionFile (
669      // Ok. we've read it.      // Ok. we've read it.
670      file.close();      file.close();
671    
672      // Have we any errors?          // Now we'll try to create (update) the whole GUI session.
673      if (iErrors > 0)          updateSession();
         appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename));  
674    
675      // Now we'll try to create the whole GUI session.          // We're fornerly done.
676      int iChannels = ::lscp_get_channels(m_pClient);          QApplication::restoreOverrideCursor();
677      if (iChannels < 0) {  
678          appendMessagesClient("lscp_get_channels");          // Have we any errors?
679          appendMessagesError(tr("Could not get current number of channels.\n\nSorry."));          if (iErrors > 0)
680      }                  appendMessagesError(tr("Session loaded with errors\nfrom \"%1\".\n\nSorry.").arg(sFilename));
       
     // Try to (re)create each channel.  
     m_pWorkspace->setUpdatesEnabled(false);  
     for (int iChannelID = 0; iChannelID < iChannels; iChannelID++) {  
         createChannel(iChannelID, false);  
         QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);  
     }  
     m_pWorkspace->setUpdatesEnabled(true);  
681    
682      // Save as default session directory.      // Save as default session directory.
683      if (m_pOptions)      if (m_pOptions)
684          m_pOptions->sSessionDir = QFileInfo(sFilename).dirPath(true);          m_pOptions->sSessionDir = QFileInfo(sFilename).dirPath(true);
685      // We're not dirty anymore.          // We're not dirty anymore, if loaded without errors,
686      m_iDirtyCount = 0;          m_iDirtyCount = iErrors;
687      // Stabilize form...      // Stabilize form...
688      m_sFilename = sFilename;      m_sFilename = sFilename;
689      updateRecentFiles(sFilename);      updateRecentFiles(sFilename);
690      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));
691    
692        // Make that an overall update.
693      stabilizeForm();      stabilizeForm();
694      return true;      return true;
695  }  }
# Line 570  bool qsamplerMainForm::loadSessionFile ( Line 698  bool qsamplerMainForm::loadSessionFile (
698  // Save current session to specific file path.  // Save current session to specific file path.
699  bool qsamplerMainForm::saveSessionFile ( const QString& sFilename )  bool qsamplerMainForm::saveSessionFile ( const QString& sFilename )
700  {  {
701            if (m_pClient == NULL)
702                    return false;
703    
704            // Check whether server is apparently OK...
705            if (::lscp_get_channels(m_pClient) < 0) {
706                    appendMessagesClient("lscp_get_channels");
707                    return false;
708            }
709    
710      // Open and write into real file.      // Open and write into real file.
711      QFile file(sFilename);      QFile file(sFilename);
712      if (!file.open(IO_WriteOnly | IO_Truncate)) {      if (!file.open(IO_WriteOnly | IO_Truncate)) {
# Line 577  bool qsamplerMainForm::saveSessionFile ( Line 714  bool qsamplerMainForm::saveSessionFile (
714          return false;          return false;
715      }      }
716    
717            // Tell the world we'll take some time...
718            QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
719    
720      // Write the file.      // Write the file.
721      int iErrors = 0;      int  iErrors = 0;
722      QTextStream ts(&file);      QTextStream ts(&file);
723      ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;      ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;
724      ts << "# " << tr("Version")      ts << "# " << tr("Version")
# Line 589  bool qsamplerMainForm::saveSessionFile ( Line 729  bool qsamplerMainForm::saveSessionFile (
729      ts << "# " << tr("File")      ts << "# " << tr("File")
730         << ": " << QFileInfo(sFilename).fileName() << endl;         << ": " << QFileInfo(sFilename).fileName() << endl;
731      ts << "# " << tr("Date")      ts << "# " << tr("Date")
732         << ": " << QDate::currentDate().toString("MMMM dd yyyy")         << ": " << QDate::currentDate().toString("MMM dd yyyy")
733         << " "  << QTime::currentTime().toString("hh:mm:ss") << endl;         << " "  << QTime::currentTime().toString("hh:mm:ss") << endl;
734      ts << "#"  << endl;      ts << "#"  << endl;
735      ts << endl;      ts << endl;
736    
737            // It is assumed that this new kind of device+session file
738            // will be loaded from a complete initialized server...
739            int *piDeviceIDs;
740            int  iDevice;
741            ts << "RESET" << endl;
742    
743            // Audio device mapping.
744            QMap<int, int> audioDeviceMap;
745            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
746            for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {
747                    ts << endl;
748                    qsamplerDevice device(qsamplerDevice::Audio, piDeviceIDs[iDevice]);
749                    // Audio device specification...
750                    ts << "# " << device.deviceTypeName() << " " << device.driverName()
751                            << " " << tr("Device") << " " << iDevice << endl;
752                    ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();
753                    qsamplerDeviceParamMap::ConstIterator deviceParam;
754                    for (deviceParam = device.params().begin();
755                                    deviceParam != device.params().end();
756                                            ++deviceParam) {
757                            const qsamplerDeviceParam& param = deviceParam.data();
758                            if (param.value.isEmpty()) ts << "# ";
759                            ts << " " << deviceParam.key() << "='" << param.value << "'";
760                    }
761                    ts << endl;
762                    // Audio channel parameters...
763                    int iPort = 0;
764                    for (qsamplerDevicePort *pPort = device.ports().first();
765                                    pPort;
766                                            pPort = device.ports().next(), ++iPort) {
767                            qsamplerDeviceParamMap::ConstIterator portParam;
768                            for (portParam = pPort->params().begin();
769                                            portParam != pPort->params().end();
770                                                    ++portParam) {
771                                    const qsamplerDeviceParam& param = portParam.data();
772                                    if (param.fix || param.value.isEmpty()) ts << "# ";
773                                    ts << "SET AUDIO_OUTPUT_CHANNEL_PARAMETER " << iDevice
774                                            << " " << iPort << " " << portParam.key()
775                                            << "='" << param.value << "'" << endl;
776                            }
777                    }
778                    // Audio device index/id mapping.
779                    audioDeviceMap[device.deviceID()] = iDevice;
780                    // Try to keep it snappy :)
781                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
782            }
783    
784            // MIDI device mapping.
785            QMap<int, int> midiDeviceMap;
786            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
787            for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {
788                    ts << endl;
789                    qsamplerDevice device(qsamplerDevice::Midi, piDeviceIDs[iDevice]);
790                    // MIDI device specification...
791                    ts << "# " << device.deviceTypeName() << " " << device.driverName()
792                            << " " << tr("Device") << " " << iDevice << endl;
793                    ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();
794                    qsamplerDeviceParamMap::ConstIterator deviceParam;
795                    for (deviceParam = device.params().begin();
796                                    deviceParam != device.params().end();
797                                            ++deviceParam) {
798                            const qsamplerDeviceParam& param = deviceParam.data();
799                            if (param.value.isEmpty()) ts << "# ";
800                            ts << " " << deviceParam.key() << "='" << param.value << "'";
801                    }
802                    ts << endl;
803                    // MIDI port parameters...
804                    int iPort = 0;
805                    for (qsamplerDevicePort *pPort = device.ports().first();
806                                    pPort;
807                                            pPort = device.ports().next(), ++iPort) {
808                            qsamplerDeviceParamMap::ConstIterator portParam;
809                            for (portParam = pPort->params().begin();
810                                            portParam != pPort->params().end();
811                                                    ++portParam) {
812                                    const qsamplerDeviceParam& param = portParam.data();
813                                    if (param.fix || param.value.isEmpty()) ts << "# ";
814                                    ts << "SET MIDI_INPUT_PORT_PARAMETER " << iDevice
815                                       << " " << iPort << " " << portParam.key()
816                                       << "='" << param.value << "'" << endl;
817                            }
818                    }
819                    // MIDI device index/id mapping.
820                    midiDeviceMap[device.deviceID()] = iDevice;
821                    // Try to keep it snappy :)
822                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
823            }
824            ts << endl;
825    
826    #ifdef CONFIG_MIDI_INSTRUMENT
827            // MIDI instrument mapping...
828            QMap<int, int> midiInstrumentMap;
829            int *piMaps = ::lscp_list_midi_instrument_maps(m_pClient);
830            for (int iMap = 0; piMaps && piMaps[iMap] >= 0; iMap++) {
831                    int iMidiMap = piMaps[iMap];
832                    const char *pszMapName
833                            = ::lscp_get_midi_instrument_map_name(m_pClient, iMidiMap);
834                    ts << "# " << tr("MIDI instrument map") << " " << iMap;
835                    if (pszMapName)
836                            ts << " - " << pszMapName;
837                    ts << endl;
838                    ts << "ADD MIDI_INSTRUMENT_MAP";
839                    if (pszMapName)
840                            ts << " '" << pszMapName << "'";
841                    ts << endl;
842                    // MIDI instrument mapping...
843                    lscp_midi_instrument_t *pInstrs
844                            = ::lscp_list_midi_instruments(m_pClient, iMidiMap);
845                    for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; iInstr++) {
846                            lscp_midi_instrument_info_t *pInstrInfo
847                                    = ::lscp_get_midi_instrument_info(m_pClient, &pInstrs[iInstr]);
848                            if (pInstrInfo) {
849                                    ts << "MAP MIDI_INSTRUMENT "
850                                            << iMap                        << " "
851                                            << pInstrs[iInstr].bank        << " "
852                                            << pInstrs[iInstr].prog        << " "
853                                            << pInstrInfo->engine_name     << " '"
854                                            << pInstrInfo->instrument_file << "' "
855                                            << pInstrInfo->instrument_nr   << " "
856                                            << pInstrInfo->volume          << " ";
857                                    switch (pInstrInfo->load_mode) {
858                                            case LSCP_LOAD_PERSISTENT:
859                                                    ts << "PERSISTENT";
860                                                    break;
861                                            case LSCP_LOAD_ON_DEMAND_HOLD:
862                                                    ts << "ON_DEMAND_HOLD";
863                                                    break;
864                                            case LSCP_LOAD_ON_DEMAND:
865                                            case LSCP_LOAD_DEFAULT:
866                                            default:
867                                                    ts << "ON_DEMAND";
868                                                    break;
869                                    }
870                                    if (pInstrInfo->name)
871                                            ts << " '" << pInstrInfo->name << "'";
872                                    ts << endl;
873                            }       // Check for errors...
874                            else if (::lscp_client_get_errno(m_pClient)) {
875                                    appendMessagesClient("lscp_get_midi_instrument_info");
876                                    iErrors++;
877                            }
878                            // MIDI device index/id mapping.
879                            midiInstrumentMap[iMidiMap] = iMap;
880                            // Try to keep it snappy :)
881                            QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
882                    }
883                    // Check for errors...
884                    if (pInstrs)
885                            ts << endl;
886                    else if (::lscp_client_get_errno(m_pClient)) {
887                            appendMessagesClient("lscp_list_midi_instruments");
888                            iErrors++;
889                    }
890            }
891            // Check for errors...
892            if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) {
893                    appendMessagesClient("lscp_list_midi_instrument_maps");
894                    iErrors++;
895            }
896    #endif //  CONFIG_MIDI_INSTRUMENT
897    
898            // Sampler channel mapping.
899      QWidgetList wlist = m_pWorkspace->windowList();      QWidgetList wlist = m_pWorkspace->windowList();
900      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
901          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
902          int iChannelID = pChannel->channelID();          if (pChannelStrip) {
903          ts << "# " << pChannel->caption() << endl;              qsamplerChannel *pChannel = pChannelStrip->channel();
904          ts << "ADD CHANNEL" << endl;              if (pChannel) {
905          ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl;                  ts << "# " << tr("Channel") << " " << iChannel << endl;
906          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl;                  ts << "ADD CHANNEL" << endl;
907      //  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl;                                  if (audioDeviceMap.isEmpty()) {
908          ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " " << pChannel->midiChannel() << endl;                                          ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel
909          ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl;                                                  << " " << pChannel->audioDriver() << endl;
910          ts << "LOAD INSTRUMENT NON_MODAL " << pChannel->instrumentFile() << " " << pChannel->instrumentNr() << " " << iChannelID << endl;                                  } else {
911          ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl;                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannel
912          ts << endl;                                                  << " " << audioDeviceMap[pChannel->audioDevice()] << endl;
913                                    }
914                                    if (midiDeviceMap.isEmpty()) {
915                                            ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel
916                                                    << " " << pChannel->midiDriver() << endl;
917                                    } else {
918                                            ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannel
919                                                    << " " << midiDeviceMap[pChannel->midiDevice()] << endl;
920                                    }
921                                    ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel
922                                            << " " << pChannel->midiPort() << endl;
923                    ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " ";
924                    if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
925                        ts << "ALL";
926                    else
927                        ts << pChannel->midiChannel();
928                    ts << endl;
929                    ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl;
930                                    if (pChannel->instrumentStatus() < 100) ts << "# ";
931                                    ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' "
932                                            << pChannel->instrumentNr() << " " << iChannel << endl;
933                                    qsamplerChannelRoutingMap::ConstIterator audioRoute;
934                                    for (audioRoute = pChannel->audioRouting().begin();
935                                                    audioRoute != pChannel->audioRouting().end();
936                                                            ++audioRoute) {
937                                            ts << "SET CHANNEL AUDIO_OUTPUT_CHANNEL " << iChannel
938                                                    << " " << audioRoute.key()
939                                                    << " " << audioRoute.data() << endl;
940                                    }
941                                    ts << "SET CHANNEL VOLUME " << iChannel
942                                            << " " << pChannel->volume() << endl;
943                                    if (pChannel->channelMute())
944                                            ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl;
945                                    if (pChannel->channelSolo())
946                                            ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl;
947    #ifdef CONFIG_MIDI_INSTRUMENT
948                                    if (pChannel->midiMap() >= 0) {
949                                            ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel
950                                                    << " " << midiInstrumentMap[pChannel->midiMap()] << endl;
951                                    }
952    #endif
953                    ts << endl;
954                }
955            }
956          // Try to keep it snappy :)          // Try to keep it snappy :)
957          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
958      }      }
# Line 614  bool qsamplerMainForm::saveSessionFile ( Line 960  bool qsamplerMainForm::saveSessionFile (
960      // Ok. we've wrote it.      // Ok. we've wrote it.
961      file.close();      file.close();
962    
963            // We're fornerly done.
964            QApplication::restoreOverrideCursor();
965    
966      // Have we any errors?      // Have we any errors?
967      if (iErrors > 0)      if (iErrors > 0)
968          appendMessagesError(tr("Some settings could not be saved\nto \"%1\" session file.\n\nSorry.").arg(sFilename));          appendMessagesError(tr("Some settings could not be saved\nto \"%1\" session file.\n\nSorry.").arg(sFilename));
# Line 632  bool qsamplerMainForm::saveSessionFile ( Line 981  bool qsamplerMainForm::saveSessionFile (
981  }  }
982    
983    
984    // Session change receiver slot.
985    void qsamplerMainForm::sessionDirty (void)
986    {
987        // Just mark the dirty form.
988        m_iDirtyCount++;
989        // and update the form status...
990        stabilizeForm();
991    }
992    
993    
994  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
995  // qsamplerMainForm -- File Action slots.  // qsamplerMainForm -- File Action slots.
996    
# Line 678  void qsamplerMainForm::fileSaveAs (void) Line 1037  void qsamplerMainForm::fileSaveAs (void)
1037  }  }
1038    
1039    
1040    // Reset the sampler instance.
1041    void qsamplerMainForm::fileReset (void)
1042    {
1043        if (m_pClient == NULL)
1044            return;
1045    
1046        // Ask user whether he/she want's an internal sampler reset...
1047        if (QMessageBox::warning(this,
1048                    QSAMPLER_TITLE ": " + tr("Warning"),
1049            tr("Resetting the sampler instance will close\n"
1050               "all device and channel configurations.\n\n"
1051               "Please note that this operation may cause\n"
1052               "temporary MIDI and Audio disruption.\n\n"
1053               "Do you want to reset the sampler engine now?"),
1054            tr("Reset"), tr("Cancel")) > 0)
1055            return;
1056    
1057        // Just do the reset, after closing down current session...
1058        if (closeSession(true) && ::lscp_reset_sampler(m_pClient) != LSCP_OK) {
1059            appendMessagesClient("lscp_reset_sampler");
1060            appendMessagesError(tr("Could not reset sampler instance.\n\nSorry."));
1061            return;
1062        }
1063    
1064        // Log this.
1065        appendMessages(tr("Sampler reset."));
1066    
1067            // Make it a new session...
1068            newSession();
1069    }
1070    
1071    
1072  // Restart the client/server instance.  // Restart the client/server instance.
1073  void qsamplerMainForm::fileRestart (void)  void qsamplerMainForm::fileRestart (void)
1074  {  {
1075      if (m_pOptions == NULL)      if (m_pOptions == NULL)
1076          return;          return;
1077            
1078      bool bRestart = true;      bool bRestart = true;
1079        
1080      // Ask user whether he/she want's a complete restart...      // Ask user whether he/she want's a complete restart...
1081      // (if we're currently up and running)      // (if we're currently up and running)
1082      if (bRestart && m_pClient) {      if (bRestart && m_pClient) {
1083          bRestart = (QMessageBox::warning(this, tr("Warning"),          bRestart = (QMessageBox::warning(this,
1084                            QSAMPLER_TITLE ": " + tr("Warning"),
1085              tr("New settings will be effective after\n"              tr("New settings will be effective after\n"
1086                 "restarting the client/server connection.\n\n"                 "restarting the client/server connection.\n\n"
1087                 "Please note that this operation may cause\n"                 "Please note that this operation may cause\n"
1088                 "temporary MIDI and Audio disruption\n\n"                 "temporary MIDI and Audio disruption.\n\n"
1089                 "Do you want to restart the connection now?"),                 "Do you want to restart the connection now?"),
1090              tr("Restart"), tr("Cancel")) == 0);              tr("Restart"), tr("Cancel")) == 0);
1091      }      }
# Line 725  void qsamplerMainForm::editAddChannel (v Line 1117  void qsamplerMainForm::editAddChannel (v
1117      if (m_pClient == NULL)      if (m_pClient == NULL)
1118          return;          return;
1119    
1120      // Create the new sampler channel.      // Just create the channel instance...
1121      int iChannelID = ::lscp_add_channel(m_pClient);      qsamplerChannel *pChannel = new qsamplerChannel();
1122      if (iChannelID < 0) {      if (pChannel == NULL)
         appendMessagesClient("lscp_add_channel");  
         appendMessagesError(tr("Could not create the new channel.\n\nSorry."));  
1123          return;          return;
     }  
1124    
1125      // Log this happening.      // Before we show it up, may be we'll
1126      appendMessages(tr("Channel %1 created.").arg(iChannelID));      // better ask for some initial values?
1127        if (!pChannel->channelSetup(this)) {
1128            delete pChannel;
1129            return;
1130        }
1131    
1132      // Just create the channel strip with given id.      // And give it to the strip (will own the channel instance, if successful).
1133      createChannel(iChannelID, true);      if (!createChannelStrip(pChannel)) {
1134            delete pChannel;
1135            return;
1136        }
1137    
1138      // We'll be dirty, for sure...      // Make that an overall update.
1139      m_iDirtyCount++;      m_iDirtyCount++;
     // Stabilize form anyway.  
1140      stabilizeForm();      stabilizeForm();
1141  }  }
1142    
# Line 752  void qsamplerMainForm::editRemoveChannel Line 1147  void qsamplerMainForm::editRemoveChannel
1147      if (m_pClient == NULL)      if (m_pClient == NULL)
1148          return;          return;
1149    
1150      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1151        if (pChannelStrip == NULL)
1152            return;
1153    
1154        qsamplerChannel *pChannel = pChannelStrip->channel();
1155      if (pChannel == NULL)      if (pChannel == NULL)
1156          return;          return;
1157    
1158      // Prompt user if he/she's sure about this...      // Prompt user if he/she's sure about this...
1159      if (m_pOptions && m_pOptions->bConfirmRemove) {      if (m_pOptions && m_pOptions->bConfirmRemove) {
1160          if (QMessageBox::warning(this, tr("Warning"),          if (QMessageBox::warning(this,
1161                            QSAMPLER_TITLE ": " + tr("Warning"),
1162              tr("About to remove channel:\n\n"              tr("About to remove channel:\n\n"
1163                 "%1\n\n"                 "%1\n\n"
1164                 "Are you sure?")                 "Are you sure?")
1165                 .arg(pChannel->caption()),                 .arg(pChannelStrip->caption()),
1166              tr("OK"), tr("Cancel")) > 0)              tr("OK"), tr("Cancel")) > 0)
1167              return;              return;
1168      }      }
1169    
1170      // Remove the existing sampler channel.      // Remove the existing sampler channel.
1171      if (::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK) {      if (!pChannel->removeChannel())
         appendMessagesClient("lscp_remove_channel");  
         appendMessagesError(tr("Could not remove channel.\n\nSorry."));  
1172          return;          return;
     }  
1173    
     // Log this happening.  
     appendMessages(tr("Channel %1 removed.").arg(pChannel->channelID()));  
       
1174      // Just delete the channel strip.      // Just delete the channel strip.
1175      delete pChannel;      delete pChannelStrip;
1176    
1177      // Do we auto-arrange?      // Do we auto-arrange?
1178      if (m_pOptions && m_pOptions->bAutoArrange)      if (m_pOptions && m_pOptions->bAutoArrange)
1179          channelsArrange();          channelsArrange();
# Line 795  void qsamplerMainForm::editSetupChannel Line 1190  void qsamplerMainForm::editSetupChannel
1190      if (m_pClient == NULL)      if (m_pClient == NULL)
1191          return;          return;
1192    
1193      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1194      if (pChannel == NULL)      if (pChannelStrip == NULL)
1195          return;          return;
1196    
1197      // Just invoque the channel strip procedure.      // Just invoque the channel strip procedure.
1198      pChannel->channelSetup();      pChannelStrip->channelSetup();
1199  }  }
1200    
1201    
# Line 810  void qsamplerMainForm::editResetChannel Line 1205  void qsamplerMainForm::editResetChannel
1205      if (m_pClient == NULL)      if (m_pClient == NULL)
1206          return;          return;
1207    
1208      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1209      if (pChannel == NULL)      if (pChannelStrip == NULL)
1210          return;          return;
1211    
1212      // Remove the existing sampler channel.      // Just invoque the channel strip procedure.
1213      if (::lscp_reset_channel(m_pClient, pChannel->channelID()) != LSCP_OK) {      pChannelStrip->channelReset();
1214          appendMessagesClient("lscp_reset_channel");  }
         appendMessagesError(tr("Could not reset channel.\n\nSorry."));  
         return;  
     }  
1215    
     // Log this.  
     appendMessages(tr("Channel %1 reset.").arg(pChannel->channelID()));  
1216    
1217      // Refresh channel strip info.  // Reset all sampler channels.
1218      pChannel->updateChannelInfo();  void qsamplerMainForm::editResetAllChannels (void)
1219    {
1220            if (m_pClient == NULL)
1221                    return;
1222    
1223            // Invoque the channel strip procedure,
1224            // for all channels out there...
1225            m_pWorkspace->setUpdatesEnabled(false);
1226            QWidgetList wlist = m_pWorkspace->windowList();
1227            for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1228                    qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1229                    if (pChannelStrip)
1230                            pChannelStrip->channelReset();
1231            }
1232            m_pWorkspace->setUpdatesEnabled(true);
1233  }  }
1234    
1235    
# Line 877  void qsamplerMainForm::viewMessages ( bo Line 1281  void qsamplerMainForm::viewMessages ( bo
1281  }  }
1282    
1283    
1284    // Show/hide the MIDI instrument list-view form.
1285    void qsamplerMainForm::viewInstruments (void)
1286    {
1287            if (m_pOptions == NULL)
1288                    return;
1289    
1290            if (m_pInstrumentListForm) {
1291                    m_pOptions->saveWidgetGeometry(m_pInstrumentListForm);
1292                    if (m_pInstrumentListForm->isVisible()) {
1293                            m_pInstrumentListForm->hide();
1294                    } else {
1295                            m_pInstrumentListForm->show();
1296                            m_pInstrumentListForm->raise();
1297                            m_pInstrumentListForm->setActiveWindow();
1298                    }
1299            }
1300    }
1301    
1302    
1303    // Show/hide the device configurator form.
1304    void qsamplerMainForm::viewDevices (void)
1305    {
1306            if (m_pOptions == NULL)
1307                    return;
1308    
1309            if (m_pDeviceForm) {
1310                    m_pOptions->saveWidgetGeometry(m_pDeviceForm);
1311                    if (m_pDeviceForm->isVisible()) {
1312                            m_pDeviceForm->hide();
1313                    } else {
1314                            m_pDeviceForm->show();
1315                            m_pDeviceForm->raise();
1316                            m_pDeviceForm->setActiveWindow();
1317                    }
1318            }
1319    }
1320    
1321    
1322  // Show options dialog.  // Show options dialog.
1323  void qsamplerMainForm::viewOptions (void)  void qsamplerMainForm::viewOptions (void)
1324  {  {
# Line 886  void qsamplerMainForm::viewOptions (void Line 1328  void qsamplerMainForm::viewOptions (void
1328      qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this);      qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this);
1329      if (pOptionsForm) {      if (pOptionsForm) {
1330          // Check out some initial nullities(tm)...          // Check out some initial nullities(tm)...
1331          qsamplerChannelStrip *pChannel = activeChannel();          qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1332          if (m_pOptions->sDisplayFont.isEmpty() && pChannel)          if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip)
1333              m_pOptions->sDisplayFont = pChannel->displayFont().toString();              m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString();
1334          if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)          if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1335              m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();              m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1336          // To track down deferred or immediate changes.          // To track down deferred or immediate changes.
# Line 898  void qsamplerMainForm::viewOptions (void Line 1340  void qsamplerMainForm::viewOptions (void
1340          bool    bOldServerStart     = m_pOptions->bServerStart;          bool    bOldServerStart     = m_pOptions->bServerStart;
1341          QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;          QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;
1342          QString sOldDisplayFont     = m_pOptions->sDisplayFont;          QString sOldDisplayFont     = m_pOptions->sDisplayFont;
1343            bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;
1344          int     iOldMaxVolume       = m_pOptions->iMaxVolume;          int     iOldMaxVolume       = m_pOptions->iMaxVolume;
1345          QString sOldMessagesFont    = m_pOptions->sMessagesFont;          QString sOldMessagesFont    = m_pOptions->sMessagesFont;
1346            bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;
1347          bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;          bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;
1348          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;
1349          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1350          bool    bOldCompletePath    = m_pOptions->bCompletePath;          bool    bOldCompletePath    = m_pOptions->bCompletePath;
1351            bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;
1352          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;
1353          // Load the current setup settings.          // Load the current setup settings.
1354          pOptionsForm->setup(m_pOptions);          pOptionsForm->setup(m_pOptions);
# Line 911  void qsamplerMainForm::viewOptions (void Line 1356  void qsamplerMainForm::viewOptions (void
1356          if (pOptionsForm->exec()) {          if (pOptionsForm->exec()) {
1357              // Warn if something will be only effective on next run.              // Warn if something will be only effective on next run.
1358              if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||              if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1359                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||
1360                  QMessageBox::information(this, tr("Information"),                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1361                    (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)) {
1362                    QMessageBox::information(this,
1363                                            QSAMPLER_TITLE ": " + tr("Information"),
1364                      tr("Some settings may be only effective\n"                      tr("Some settings may be only effective\n"
1365                         "next time you start this program."), tr("OK"));                         "next time you start this program."), tr("OK"));
1366                  updateMessagesCapture();                  updateMessagesCapture();
# Line 922  void qsamplerMainForm::viewOptions (void Line 1370  void qsamplerMainForm::viewOptions (void
1370                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||
1371                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))
1372                  updateRecentFilesMenu();                  updateRecentFilesMenu();
1373                if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) ||
1374                    (!bOldInstrumentNames &&  m_pOptions->bInstrumentNames))
1375                    updateInstrumentNames();
1376                if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) ||
1377                    (!bOldDisplayEffect &&  m_pOptions->bDisplayEffect))
1378                    updateDisplayEffect();
1379              if (sOldDisplayFont != m_pOptions->sDisplayFont)              if (sOldDisplayFont != m_pOptions->sDisplayFont)
1380                  updateDisplayFont();                  updateDisplayFont();
1381              if (iOldMaxVolume != m_pOptions->iMaxVolume)              if (iOldMaxVolume != m_pOptions->iMaxVolume)
# Line 964  void qsamplerMainForm::channelsArrange ( Line 1418  void qsamplerMainForm::channelsArrange (
1418      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1419      int y = 0;      int y = 0;
1420      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1421          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1422      /*  if (pChannel->testWState(WState_Maximized | WState_Minimized)) {      /*  if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) {
1423              // Prevent flicker...              // Prevent flicker...
1424              pChannel->hide();              pChannelStrip->hide();
1425              pChannel->showNormal();              pChannelStrip->showNormal();
1426          }   */          }   */
1427          pChannel->adjustSize();          pChannelStrip->adjustSize();
1428          int iWidth  = m_pWorkspace->width();          int iWidth  = m_pWorkspace->width();
1429          if (iWidth < pChannel->width())          if (iWidth < pChannelStrip->width())
1430              iWidth = pChannel->width();              iWidth = pChannelStrip->width();
1431      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();      //  int iHeight = pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();
1432          int iHeight = pChannel->parentWidget()->frameGeometry().height();          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1433          pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight);          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1434          y += iHeight;          y += iHeight;
1435      }      }
1436      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1437        
1438      stabilizeForm();      stabilizeForm();
1439  }  }
1440    
# Line 1024  void qsamplerMainForm::helpAbout (void) Line 1478  void qsamplerMainForm::helpAbout (void)
1478      sText += tr("Debugging option enabled.");      sText += tr("Debugging option enabled.");
1479      sText += "</font></small><br />";      sText += "</font></small><br />";
1480  #endif  #endif
1481    #ifndef CONFIG_LIBGIG
1482        sText += "<small><font color=\"red\">";
1483        sText += tr("GIG (libgig) file support disabled.");
1484        sText += "</font></small><br />";
1485    #endif
1486    #ifndef CONFIG_INSTRUMENT_NAME
1487        sText += "<small><font color=\"red\">";
1488        sText += tr("LSCP (liblscp) instrument_name support disabled.");
1489        sText += "</font></small><br />";
1490    #endif
1491    #ifndef CONFIG_MUTE_SOLO
1492        sText += "<small><font color=\"red\">";
1493        sText += tr("Sampler channel Mute/Solo support disabled.");
1494        sText += "</font></small><br />";
1495    #endif
1496    #ifndef CONFIG_MIDI_INSTRUMENT
1497        sText += "<small><font color=\"red\">";
1498        sText += tr("MIDI instrument mapping support disabled.");
1499        sText += "</font></small><br />";
1500    #endif
1501      sText += "<br />\n";      sText += "<br />\n";
1502      sText += tr("Using") + ": ";      sText += tr("Using") + ": ";
1503      sText += ::lscp_client_package();      sText += ::lscp_client_package();
1504      sText += " ";      sText += " ";
1505      sText += ::lscp_client_version();      sText += ::lscp_client_version();
1506    #ifdef CONFIG_LIBGIG
1507        sText += ", ";
1508        sText += gig::libraryName().c_str();
1509        sText += " ";
1510        sText += gig::libraryVersion().c_str();
1511    #endif
1512      sText += "<br />\n";      sText += "<br />\n";
1513      sText += "<br />\n";      sText += "<br />\n";
1514      sText += tr("Website") + ": <a href=\"" QSAMPLER_WEBSITE "\">" QSAMPLER_WEBSITE "</a><br />\n";      sText += tr("Website") + ": <a href=\"" QSAMPLER_WEBSITE "\">" QSAMPLER_WEBSITE "</a><br />\n";
# Line 1051  void qsamplerMainForm::helpAbout (void) Line 1531  void qsamplerMainForm::helpAbout (void)
1531  void qsamplerMainForm::stabilizeForm (void)  void qsamplerMainForm::stabilizeForm (void)
1532  {  {
1533      // Update the main application caption...      // Update the main application caption...
1534      QString sSessioName = sessionName(m_sFilename);      QString sSessionName = sessionName(m_sFilename);
1535      if (m_iDirtyCount > 0)      if (m_iDirtyCount > 0)
1536          sSessioName += '*';          sSessionName += " *";
1537      setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName));      setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));
1538    
1539      // Update the main menu state...      // Update the main menu state...
1540      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1541      bool bHasClient  = (m_pOptions != NULL && m_pClient != NULL);      bool bHasClient  = (m_pOptions != NULL && m_pClient != NULL);
1542      bool bHasChannel = (bHasClient && pChannel != NULL);      bool bHasChannel = (bHasClient && pChannelStrip != NULL);
1543      fileNewAction->setEnabled(bHasClient);      fileNewAction->setEnabled(bHasClient);
1544      fileOpenAction->setEnabled(bHasClient);      fileOpenAction->setEnabled(bHasClient);
1545      fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);      fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);
1546      fileSaveAsAction->setEnabled(bHasClient);      fileSaveAsAction->setEnabled(bHasClient);
1547        fileResetAction->setEnabled(bHasClient);
1548      fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);      fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);
1549      editAddChannelAction->setEnabled(bHasClient);      editAddChannelAction->setEnabled(bHasClient);
1550      editRemoveChannelAction->setEnabled(bHasChannel);      editRemoveChannelAction->setEnabled(bHasChannel);
1551      editSetupChannelAction->setEnabled(bHasChannel);      editSetupChannelAction->setEnabled(bHasChannel);
1552      editResetChannelAction->setEnabled(bHasChannel);      editResetChannelAction->setEnabled(bHasChannel);
1553      channelsArrangeAction->setEnabled(bHasChannel);      editResetAllChannelsAction->setEnabled(bHasChannel);
1554      viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible());      viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible());
1555    #ifdef CONFIG_MIDI_INSTRUMENT
1556            viewInstrumentsAction->setOn(m_pInstrumentListForm
1557                    && m_pInstrumentListForm->isVisible());
1558            viewInstrumentsAction->setEnabled(bHasClient);
1559    #endif
1560            viewDevicesAction->setOn(m_pDeviceForm
1561                    && m_pDeviceForm->isVisible());
1562        viewDevicesAction->setEnabled(bHasClient);
1563        channelsArrangeAction->setEnabled(bHasChannel);
1564    
1565      // Client/Server status...      // Client/Server status...
1566      if (bHasClient) {      if (bHasClient) {
1567          m_status[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected"));          m_statusItem[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected"));
1568          m_status[QSAMPLER_STATUS_SERVER]->setText(m_pOptions->sServerHost + ":" + QString::number(m_pOptions->iServerPort));          m_statusItem[QSAMPLER_STATUS_SERVER]->setText(m_pOptions->sServerHost + ":" + QString::number(m_pOptions->iServerPort));
1569      } else {      } else {
1570          m_status[QSAMPLER_STATUS_CLIENT]->clear();          m_statusItem[QSAMPLER_STATUS_CLIENT]->clear();
1571          m_status[QSAMPLER_STATUS_SERVER]->clear();          m_statusItem[QSAMPLER_STATUS_SERVER]->clear();
1572      }      }
1573      // Channel status...      // Channel status...
1574      if (bHasChannel)      if (bHasChannel)
1575          m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannel->caption());          m_statusItem[QSAMPLER_STATUS_CHANNEL]->setText(pChannelStrip->caption());
1576      else      else
1577          m_status[QSAMPLER_STATUS_CHANNEL]->clear();          m_statusItem[QSAMPLER_STATUS_CHANNEL]->clear();
1578      // Session status...      // Session status...
1579      if (m_iDirtyCount > 0)      if (m_iDirtyCount > 0)
1580          m_status[QSAMPLER_STATUS_SESSION]->setText(tr("MOD"));          m_statusItem[QSAMPLER_STATUS_SESSION]->setText(tr("MOD"));
1581      else      else
1582          m_status[QSAMPLER_STATUS_SESSION]->clear();          m_statusItem[QSAMPLER_STATUS_SESSION]->clear();
1583    
1584      // Recent files menu.      // Recent files menu.
1585      m_pRecentFilesMenu->setEnabled(bHasClient && m_pOptions->recentFiles.count() > 0);      m_pRecentFilesMenu->setEnabled(bHasClient && m_pOptions->recentFiles.count() > 0);
# Line 1101  void qsamplerMainForm::stabilizeForm (vo Line 1591  void qsamplerMainForm::stabilizeForm (vo
1591    
1592    
1593  // Channel change receiver slot.  // Channel change receiver slot.
1594  void qsamplerMainForm::channelChanged( qsamplerChannelStrip * )  void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip )
1595  {  {
1596            // Add this strip to the changed list...
1597            if (m_changedStrips.containsRef(pChannelStrip) == 0) {
1598                    m_changedStrips.append(pChannelStrip);
1599                    pChannelStrip->resetErrorCount();
1600            }
1601    
1602      // Just mark the dirty form.      // Just mark the dirty form.
1603      m_iDirtyCount++;      m_iDirtyCount++;
1604      // and update the form status...      // and update the form status...
# Line 1110  void qsamplerMainForm::channelChanged( q Line 1606  void qsamplerMainForm::channelChanged( q
1606  }  }
1607    
1608    
1609    // Grab and restore current sampler channels session.
1610    void qsamplerMainForm::updateSession (void)
1611    {
1612    #ifdef CONFIG_MIDI_INSTRUMENT
1613            // FIXME Make some room for default instrument maps...
1614            int iMaps = ::lscp_get_midi_instrument_maps(m_pClient);
1615            if (iMaps < 0)
1616                    appendMessagesClient("lscp_get_midi_instrument_maps");
1617            else if (iMaps < 1) {
1618                    ::lscp_add_midi_instrument_map(m_pClient, tr("Chromatic").latin1());
1619                    ::lscp_add_midi_instrument_map(m_pClient, tr("Drum Kits").latin1());
1620            }
1621    #endif
1622    
1623            // Retrieve the current channel list.
1624            int *piChannelIDs = ::lscp_list_channels(m_pClient);
1625            if (piChannelIDs == NULL) {
1626                    if (::lscp_client_get_errno(m_pClient)) {
1627                            appendMessagesClient("lscp_list_channels");
1628                            appendMessagesError(tr("Could not get current list of channels.\n\nSorry."));
1629                    }
1630            } else {
1631                    // Try to (re)create each channel.
1632                    m_pWorkspace->setUpdatesEnabled(false);
1633                    for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) {
1634                            // Check if theres already a channel strip for this one...
1635                            if (!channelStrip(piChannelIDs[iChannel]))
1636                                    createChannelStrip(new qsamplerChannel(piChannelIDs[iChannel]));
1637                    }
1638                    m_pWorkspace->setUpdatesEnabled(true);
1639            }
1640    
1641        // Do we auto-arrange?
1642        if (m_pOptions && m_pOptions->bAutoArrange)
1643            channelsArrange();
1644    
1645            // Remember to refresh devices and instruments...
1646            if (m_pInstrumentListForm)
1647                m_pInstrumentListForm->refreshInstruments();
1648            if (m_pDeviceForm)
1649                m_pDeviceForm->refreshDevices();
1650    }
1651    
1652    
1653  // Update the recent files list and menu.  // Update the recent files list and menu.
1654  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )
1655  {  {
# Line 1154  void qsamplerMainForm::updateRecentFiles Line 1694  void qsamplerMainForm::updateRecentFiles
1694  }  }
1695    
1696    
1697    // Force update of the channels instrument names mode.
1698    void qsamplerMainForm::updateInstrumentNames (void)
1699    {
1700        // Full channel list update...
1701        QWidgetList wlist = m_pWorkspace->windowList();
1702        if (wlist.isEmpty())
1703            return;
1704    
1705        m_pWorkspace->setUpdatesEnabled(false);
1706        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1707            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1708            if (pChannelStrip)
1709                pChannelStrip->updateInstrumentName(true);
1710        }
1711        m_pWorkspace->setUpdatesEnabled(true);
1712    }
1713    
1714    
1715  // Force update of the channels display font.  // Force update of the channels display font.
1716  void qsamplerMainForm::updateDisplayFont (void)  void qsamplerMainForm::updateDisplayFont (void)
1717  {  {
# Line 1175  void qsamplerMainForm::updateDisplayFont Line 1733  void qsamplerMainForm::updateDisplayFont
1733    
1734      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1735      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1736          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1737          pChannel->setDisplayFont(font);          if (pChannelStrip)
1738                pChannelStrip->setDisplayFont(font);
1739        }
1740        m_pWorkspace->setUpdatesEnabled(true);
1741    }
1742    
1743    
1744    // Update channel strips background effect.
1745    void qsamplerMainForm::updateDisplayEffect (void)
1746    {
1747       QPixmap pm;
1748        if (m_pOptions->bDisplayEffect)
1749            pm = QPixmap::fromMimeSource("displaybg1.png");
1750    
1751        // Full channel list update...
1752        QWidgetList wlist = m_pWorkspace->windowList();
1753        if (wlist.isEmpty())
1754            return;
1755    
1756        m_pWorkspace->setUpdatesEnabled(false);
1757        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1758            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1759            if (pChannelStrip)
1760                pChannelStrip->setDisplayBackground(pm);
1761      }      }
1762      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1763  }  }
# Line 1195  void qsamplerMainForm::updateMaxVolume ( Line 1776  void qsamplerMainForm::updateMaxVolume (
1776    
1777      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1778      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1779          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1780          pChannel->setMaxVolume(m_pOptions->iMaxVolume);          if (pChannelStrip)
1781                pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
1782      }      }
1783      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1784  }  }
# Line 1235  void qsamplerMainForm::appendMessagesErr Line 1817  void qsamplerMainForm::appendMessagesErr
1817    
1818      appendMessagesColor(s.simplifyWhiteSpace(), "#ff0000");      appendMessagesColor(s.simplifyWhiteSpace(), "#ff0000");
1819    
1820      QMessageBox::critical(this, tr("Error"), s, tr("Cancel"));          // Make it look responsive...:)
1821            QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
1822    
1823        QMessageBox::critical(this,
1824                    QSAMPLER_TITLE ": " + tr("Error"), s, tr("Cancel"));
1825  }  }
1826    
1827    
# Line 1248  void qsamplerMainForm::appendMessagesCli Line 1834  void qsamplerMainForm::appendMessagesCli
1834      appendMessagesColor(s + QString(": %1 (errno=%2)")      appendMessagesColor(s + QString(": %1 (errno=%2)")
1835          .arg(::lscp_client_get_result(m_pClient))          .arg(::lscp_client_get_result(m_pClient))
1836          .arg(::lscp_client_get_errno(m_pClient)), "#996666");          .arg(::lscp_client_get_errno(m_pClient)), "#996666");
1837    
1838            // Make it look responsive...:)
1839            QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
1840  }  }
1841    
1842    
# Line 1275  void qsamplerMainForm::updateMessagesLim Line 1864  void qsamplerMainForm::updateMessagesLim
1864          if (m_pOptions->bMessagesLimit)          if (m_pOptions->bMessagesLimit)
1865              m_pMessages->setMessagesLimit(m_pOptions->iMessagesLimitLines);              m_pMessages->setMessagesLimit(m_pOptions->iMessagesLimitLines);
1866          else          else
1867              m_pMessages->setMessagesLimit(0);              m_pMessages->setMessagesLimit(-1);
1868      }      }
1869  }  }
1870    
# Line 1295  void qsamplerMainForm::updateMessagesCap Line 1884  void qsamplerMainForm::updateMessagesCap
1884  // qsamplerMainForm -- MDI channel strip management.  // qsamplerMainForm -- MDI channel strip management.
1885    
1886  // The channel strip creation executive.  // The channel strip creation executive.
1887  void qsamplerMainForm::createChannel ( int iChannelID, bool bPrompt )  qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( qsamplerChannel *pChannel )
1888  {  {
1889      if (m_pClient == NULL)      if (m_pClient == NULL || pChannel == NULL)
1890          return;          return NULL;
1891    
1892      // Prepare for auto-arrange?      // Prepare for auto-arrange?
1893      qsamplerChannelStrip *pChannel = NULL;      qsamplerChannelStrip *pChannelStrip = NULL;
1894      int y = 0;      int y = 0;
1895      if (m_pOptions && m_pOptions->bAutoArrange) {      if (m_pOptions && m_pOptions->bAutoArrange) {
1896          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
1897          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1898              pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1899          //  y += pChannel->height() + pChannel->parentWidget()->baseSize().height();                          if (pChannelStrip) {
1900              y += pChannel->parentWidget()->frameGeometry().height();                          //  y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();
1901                                    y += pChannelStrip->parentWidget()->frameGeometry().height();
1902                            }
1903          }          }
1904      }      }
1905    
1906      // Add a new channel itema...      // Add a new channel itema...
1907      WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder;      WFlags wflags = Qt::WStyle_Customize | Qt::WStyle_Tool | Qt::WStyle_Title | Qt::WStyle_NoBorder;
1908      pChannel = new qsamplerChannelStrip(m_pWorkspace, 0, wflags);      pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags);
1909      pChannel->setMaxVolume(m_pOptions->iMaxVolume);      if (pChannelStrip == NULL)
1910      pChannel->setup(this, iChannelID);          return NULL;
1911      // We'll need a display font.  
1912      QFont font;      // Actual channel strip setup...
1913      if (m_pOptions && font.fromString(m_pOptions->sDisplayFont))      pChannelStrip->setup(pChannel);
1914          pChannel->setDisplayFont(font);      QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *)));
1915      // Track channel setup changes.      // Set some initial aesthetic options...
1916      QObject::connect(pChannel, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelChanged(qsamplerChannelStrip *)));      if (m_pOptions) {
1917      // Before we show it up, may be we'll          // Background display effect...
1918      // better ask for some initial values?          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
1919      if (bPrompt)          // We'll need a display font.
1920          pChannel->channelSetup();                QFont font;
1921            if (font.fromString(m_pOptions->sDisplayFont))
1922                pChannelStrip->setDisplayFont(font);
1923            // Maximum allowed volume setting.
1924            pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
1925        }
1926    
1927      // Now we show up us to the world.      // Now we show up us to the world.
1928      pChannel->show();      pChannelStrip->show();
1929      // Only then, we'll auto-arrange...      // Only then, we'll auto-arrange...
1930      if (m_pOptions && m_pOptions->bAutoArrange) {      if (m_pOptions && m_pOptions->bAutoArrange) {
1931          int iWidth  = m_pWorkspace->width();          int iWidth  = m_pWorkspace->width();
1932      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();
1933          int iHeight = pChannel->parentWidget()->frameGeometry().height();          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1934          pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight);          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1935      }      }
1936    
1937            // This is pretty new, so we'll watch for it closely.
1938            channelStripChanged(pChannelStrip);
1939    
1940        // Return our successful reference...
1941        return pChannelStrip;
1942  }  }
1943    
1944    
1945  // Retrieve the active channel strip.  // Retrieve the active channel strip.
1946  qsamplerChannelStrip *qsamplerMainForm::activeChannel (void)  qsamplerChannelStrip *qsamplerMainForm::activeChannelStrip (void)
1947  {  {
1948      return (qsamplerChannelStrip *) m_pWorkspace->activeWindow();      return (qsamplerChannelStrip *) m_pWorkspace->activeWindow();
1949  }  }
1950    
1951    
1952  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
1953  qsamplerChannelStrip *qsamplerMainForm::channelAt ( int iChannel )  qsamplerChannelStrip *qsamplerMainForm::channelStripAt ( int iChannel )
1954  {  {
1955      QWidgetList wlist = m_pWorkspace->windowList();      QWidgetList wlist = m_pWorkspace->windowList();
1956      if (wlist.isEmpty())      if (wlist.isEmpty())
1957          return 0;          return NULL;
1958    
1959      return (qsamplerChannelStrip *) wlist.at(iChannel);      return (qsamplerChannelStrip *) wlist.at(iChannel);
1960  }  }
1961    
1962    
1963    // Retrieve a channel strip by sampler channel id.
1964    qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID )
1965    {
1966            QWidgetList wlist = m_pWorkspace->windowList();
1967            if (wlist.isEmpty())
1968                    return NULL;
1969    
1970            for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1971                    qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1972                    if (pChannelStrip) {
1973                            qsamplerChannel *pChannel = pChannelStrip->channel();
1974                            if (pChannel && pChannel->channelID() == iChannelID)
1975                                    return pChannelStrip;
1976                    }
1977            }
1978    
1979            // Not found.
1980            return NULL;
1981    }
1982    
1983    
1984  // Construct the windows menu.  // Construct the windows menu.
1985  void qsamplerMainForm::channelsMenuAboutToShow (void)  void qsamplerMainForm::channelsMenuAboutToShow (void)
1986  {  {
# Line 1368  void qsamplerMainForm::channelsMenuAbout Line 1992  void qsamplerMainForm::channelsMenuAbout
1992      if (!wlist.isEmpty()) {      if (!wlist.isEmpty()) {
1993          channelsMenu->insertSeparator();          channelsMenu->insertSeparator();
1994          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1995              qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1996              int iItemID = channelsMenu->insertItem(pChannel->caption(), this, SLOT(channelsMenuActivated(int)));              if (pChannelStrip) {
1997              channelsMenu->setItemParameter(iItemID, iChannel);                  int iItemID = channelsMenu->insertItem(pChannelStrip->caption(), this, SLOT(channelsMenuActivated(int)));
1998              channelsMenu->setItemChecked(iItemID, activeChannel() == pChannel);                  channelsMenu->setItemParameter(iItemID, iChannel);
1999                    channelsMenu->setItemChecked(iItemID, activeChannelStrip() == pChannelStrip);
2000                }
2001          }          }
2002      }      }
2003  }  }
# Line 1380  void qsamplerMainForm::channelsMenuAbout Line 2006  void qsamplerMainForm::channelsMenuAbout
2006  // Windows menu activation slot  // Windows menu activation slot
2007  void qsamplerMainForm::channelsMenuActivated ( int iChannel )  void qsamplerMainForm::channelsMenuActivated ( int iChannel )
2008  {  {
2009      qsamplerChannelStrip *pChannel = channelAt(iChannel);      qsamplerChannelStrip *pChannelStrip = channelStripAt(iChannel);
2010      if (pChannel)      if (pChannelStrip)
2011          pChannel->showNormal();          pChannelStrip->showNormal();
2012      pChannel->setFocus();      pChannelStrip->setFocus();
2013  }  }
2014    
2015    
# Line 1421  void qsamplerMainForm::timerSlot (void) Line 2047  void qsamplerMainForm::timerSlot (void)
2047              }              }
2048          }          }
2049      }      }
2050        
2051          // Refresh each channel usage, on each period...          if (m_pClient) {
2052      if (m_pClient && m_pOptions->bAutoRefresh && m_pWorkspace->isUpdatesEnabled()) {                  // Update the channel information for each pending strip...
2053          m_iTimerSlot += QSAMPLER_TIMER_MSECS;                  if (m_changedStrips.count() > 0) {
2054          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {                          for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first();
2055              m_iTimerSlot = 0;                                          pChannelStrip; pChannelStrip = m_changedStrips.next()) {
2056              QWidgetList wlist = m_pWorkspace->windowList();                                  // If successfull, remove from pending list...
2057              for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {                                  if (pChannelStrip->updateChannelInfo())
2058                  qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);                                          m_changedStrips.remove(pChannelStrip);
2059                  if (pChannel->isVisible())                          }
2060                      pChannel->updateChannelUsage();                  }
2061              }                  // Refresh each channel usage, on each period...
2062          }                  if (m_pOptions->bAutoRefresh) {
2063      }                          m_iTimerSlot += QSAMPLER_TIMER_MSECS;
2064                            if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {
2065                                    m_iTimerSlot = 0;
2066                                    // Update the channel stream usage for each strip...
2067                                    QWidgetList wlist = m_pWorkspace->windowList();
2068                                    for (int iChannel = 0;
2069                                                    iChannel < (int) wlist.count(); iChannel++) {
2070                                            qsamplerChannelStrip *pChannelStrip
2071                                                    = (qsamplerChannelStrip *) wlist.at(iChannel);
2072                                            if (pChannelStrip && pChannelStrip->isVisible())
2073                                                    pChannelStrip->updateChannelUsage();
2074                                    }
2075                            }
2076                    }
2077            }
2078    
2079      // Register the next timer slot.      // Register the next timer slot.
2080      QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(timerSlot()));      QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(timerSlot()));
# Line 1456  void qsamplerMainForm::startServer (void Line 2096  void qsamplerMainForm::startServer (void
2096    
2097      // Is the server process instance still here?      // Is the server process instance still here?
2098      if (m_pServer) {      if (m_pServer) {
2099          switch (QMessageBox::warning(this, tr("Warning"),          switch (QMessageBox::warning(this,
2100                            QSAMPLER_TITLE ": " + tr("Warning"),
2101              tr("Could not start the LinuxSampler server.\n\n"              tr("Could not start the LinuxSampler server.\n\n"
2102                 "Maybe it ss already started."),                 "Maybe it ss already started."),
2103              tr("Stop"), tr("Kill"), tr("Cancel"))) {              tr("Stop"), tr("Kill"), tr("Cancel"))) {
# Line 1615  bool qsamplerMainForm::startClient (void Line 2256  bool qsamplerMainForm::startClient (void
2256      ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);      ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);
2257      appendMessages(tr("Client receive timeout is set to %1 msec.").arg(::lscp_client_get_timeout(m_pClient)));      appendMessages(tr("Client receive timeout is set to %1 msec.").arg(::lscp_client_get_timeout(m_pClient)));
2258    
2259            // Subscribe to channel info change notifications...
2260            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)
2261                    appendMessagesClient("lscp_client_subscribe");
2262    
2263      // We may stop scheduling around.      // We may stop scheduling around.
2264      stopSchedule();      stopSchedule();
2265    
# Line 1624  bool qsamplerMainForm::startClient (void Line 2269  bool qsamplerMainForm::startClient (void
2269      // Log success here.      // Log success here.
2270      appendMessages(tr("Client connected."));      appendMessages(tr("Client connected."));
2271    
2272            // Hard-notify instrumnet and device configuration forms,
2273            // if visible, that we're ready...
2274            if (m_pInstrumentListForm)
2275                m_pInstrumentListForm->refreshInstruments();
2276            if (m_pDeviceForm)
2277                m_pDeviceForm->refreshDevices();
2278    
2279      // Is any session pending to be loaded?      // Is any session pending to be loaded?
2280      if (!m_pOptions->sSessionFile.isEmpty()) {      if (!m_pOptions->sSessionFile.isEmpty()) {
2281          // Just load the prabably startup session...          // Just load the prabably startup session...
# Line 1658  void qsamplerMainForm::stopClient (void) Line 2310  void qsamplerMainForm::stopClient (void)
2310      // channels from the back-end server.      // channels from the back-end server.
2311      m_iDirtyCount = 0;      m_iDirtyCount = 0;
2312      closeSession(false);      closeSession(false);
2313        
2314      // Close us as a client...      // Close us as a client...
2315      lscp_client_destroy(m_pClient);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
2316        ::lscp_client_destroy(m_pClient);
2317      m_pClient = NULL;      m_pClient = NULL;
2318    
2319            // Hard-notify instrumnet and device configuration forms,
2320            // if visible, that we're running out...
2321            if (m_pInstrumentListForm)
2322                m_pInstrumentListForm->refreshInstruments();
2323            if (m_pDeviceForm)
2324                m_pDeviceForm->refreshDevices();
2325    
2326      // Log final here.      // Log final here.
2327      appendMessages(tr("Client disconnected."));      appendMessages(tr("Client disconnected."));
2328    

Legend:
Removed from v.149  
changed lines
  Added in v.987

  ViewVC Help
Powered by ViewVC