/[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 176 by capela, Tue Jul 6 10:54:45 2004 UTC revision 1018 by capela, Wed Jan 10 19:39:00 2007 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-2007, 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);
145      // Set the activation connection.          // Set the activation connection.
146      QObject::connect(m_pWorkspace, SIGNAL(windowActivated(QWidget *)), this, SLOT(stabilizeForm()));          QObject::connect(m_pWorkspace,
147                    SIGNAL(windowActivated(QWidget *)),
148                    SLOT(stabilizeForm()));
149      // Make it shine :-)      // Make it shine :-)
150      setCentralWidget(m_pWorkspace);      setCentralWidget(m_pWorkspace);
151    
# Line 128  void qsamplerMainForm::init (void) Line 155  void qsamplerMainForm::init (void)
155      pLabel = new QLabel(tr("Connected"), this);      pLabel = new QLabel(tr("Connected"), this);
156      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
157      pLabel->setMinimumSize(pLabel->sizeHint());      pLabel->setMinimumSize(pLabel->sizeHint());
158      m_status[QSAMPLER_STATUS_CLIENT] = pLabel;      m_statusItem[QSAMPLER_STATUS_CLIENT] = pLabel;
159      statusBar()->addWidget(pLabel);      statusBar()->addWidget(pLabel);
160      // Server address.      // Server address.
161      pLabel = new QLabel(this);      pLabel = new QLabel(this);
162      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
163      m_status[QSAMPLER_STATUS_SERVER] = pLabel;      m_statusItem[QSAMPLER_STATUS_SERVER] = pLabel;
164      statusBar()->addWidget(pLabel, 1);      statusBar()->addWidget(pLabel, 1);
165      // Channel title.      // Channel title.
166      pLabel = new QLabel(this);      pLabel = new QLabel(this);
167      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
168      m_status[QSAMPLER_STATUS_CHANNEL] = pLabel;      m_statusItem[QSAMPLER_STATUS_CHANNEL] = pLabel;
169      statusBar()->addWidget(pLabel, 2);      statusBar()->addWidget(pLabel, 2);
170      // Session modification status.      // Session modification status.
171      pLabel = new QLabel(tr("MOD"), this);      pLabel = new QLabel(tr("MOD"), this);
172      pLabel->setAlignment(Qt::AlignHCenter);      pLabel->setAlignment(Qt::AlignHCenter);
173      pLabel->setMinimumSize(pLabel->sizeHint());      pLabel->setMinimumSize(pLabel->sizeHint());
174      m_status[QSAMPLER_STATUS_SESSION] = pLabel;      m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;
175      statusBar()->addWidget(pLabel);      statusBar()->addWidget(pLabel);
176    
177      // Create the recent files sub-menu.      // Create the recent files sub-menu.
# Line 163  void qsamplerMainForm::destroy (void) Line 190  void qsamplerMainForm::destroy (void)
190  {  {
191      // Do final processing anyway.      // Do final processing anyway.
192      processServerExit();      processServerExit();
193        
194      // Delete recentfiles menu.  #if defined(WIN32)
195      if (m_pRecentFilesMenu)      WSACleanup();
196          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];  
197    
198      // Finally drop any widgets around...      // Finally drop any widgets around...
199        if (m_pDeviceForm)
200            delete m_pDeviceForm;
201        if (m_pInstrumentListForm)
202            delete m_pInstrumentListForm;
203      if (m_pMessages)      if (m_pMessages)
204          delete m_pMessages;          delete m_pMessages;
205      if (m_pWorkspace)      if (m_pWorkspace)
206          delete m_pWorkspace;          delete m_pWorkspace;
207    
208  #if defined(WIN32)      // Delete status item labels one by one.
209      WSACleanup();      if (m_statusItem[QSAMPLER_STATUS_CLIENT])
210  #endif          delete m_statusItem[QSAMPLER_STATUS_CLIENT];
211        if (m_statusItem[QSAMPLER_STATUS_SERVER])
212            delete m_statusItem[QSAMPLER_STATUS_SERVER];
213        if (m_statusItem[QSAMPLER_STATUS_CHANNEL])
214            delete m_statusItem[QSAMPLER_STATUS_CHANNEL];
215        if (m_statusItem[QSAMPLER_STATUS_SESSION])
216            delete m_statusItem[QSAMPLER_STATUS_SESSION];
217    
218        // Delete recentfiles menu.
219        if (m_pRecentFilesMenu)
220            delete m_pRecentFilesMenu;
221    
222            // Pseudo-singleton reference shut-down.
223            g_pMainForm = NULL;
224  }  }
225    
226    
# Line 195  void qsamplerMainForm::setup ( qsamplerO Line 230  void qsamplerMainForm::setup ( qsamplerO
230      // We got options?      // We got options?
231      m_pOptions = pOptions;      m_pOptions = pOptions;
232    
233        // What style do we create these forms?
234            Qt::WFlags wflags = Qt::WStyle_Customize
235                    | Qt::WStyle_NormalBorder
236                    | Qt::WStyle_Title
237                    | Qt::WStyle_SysMenu
238                    | Qt::WStyle_MinMax
239                    | Qt::WType_TopLevel;
240        if (m_pOptions->bKeepOnTop)
241            wflags |= Qt::WStyle_Tool;
242      // Some child forms are to be created right now.      // Some child forms are to be created right now.
243      m_pMessages = new qsamplerMessages(this);      m_pMessages = new qsamplerMessages(this);
244        m_pDeviceForm = new qsamplerDeviceForm(this, 0, wflags);
245    #ifdef CONFIG_MIDI_INSTRUMENT
246        m_pInstrumentListForm = new qsamplerInstrumentListForm(this, 0, wflags);
247            QObject::connect(m_pInstrumentListForm->InstrumentList,
248                    SIGNAL(instrumentsChanged()),
249                    SLOT(sessionDirty()));
250    #else
251            viewInstrumentsAction->setEnabled(false);
252    #endif
253      // Set message defaults...      // Set message defaults...
254      updateMessagesFont();      updateMessagesFont();
255      updateMessagesLimit();      updateMessagesLimit();
256      updateMessagesCapture();      updateMessagesCapture();
257      // Set the visibility signal.      // Set the visibility signal.
258      QObject::connect(m_pMessages, SIGNAL(visibilityChanged(bool)), this, SLOT(stabilizeForm()));          QObject::connect(m_pMessages,
259                    SIGNAL(visibilityChanged(bool)),
260                    SLOT(stabilizeForm()));
261    
262      // Initial decorations toggle state.      // Initial decorations toggle state.
263      viewMenubarAction->setOn(m_pOptions->bMenubar);      viewMenubarAction->setOn(m_pOptions->bMenubar);
# Line 225  void qsamplerMainForm::setup ( qsamplerO Line 280  void qsamplerMainForm::setup ( qsamplerO
280          QTextIStream istr(&sDockables);          QTextIStream istr(&sDockables);
281          istr >> *this;          istr >> *this;
282      }      }
283      // Try to restore old window positioning.      // Try to restore old window positioning and initial visibility.
284      m_pOptions->loadWidgetGeometry(this);      m_pOptions->loadWidgetGeometry(this);
285        m_pOptions->loadWidgetGeometry(m_pInstrumentListForm);
286        m_pOptions->loadWidgetGeometry(m_pDeviceForm);
287    
288      // Final startup stabilization...      // Final startup stabilization...
289      updateRecentFilesMenu();      updateRecentFilesMenu();
# Line 264  bool qsamplerMainForm::queryClose (void) Line 321  bool qsamplerMainForm::queryClose (void)
321              QTextOStream ostr(&sDockables);              QTextOStream ostr(&sDockables);
322              ostr << *this;              ostr << *this;
323              m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables);              m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables);
324              // And the main windows state.              // And the children, and the main windows state,.
325              m_pOptions->saveWidgetGeometry(this);                          m_pOptions->saveWidgetGeometry(m_pDeviceForm);
326                            m_pOptions->saveWidgetGeometry(m_pInstrumentListForm);
327                            m_pOptions->saveWidgetGeometry(this);
328                            // Close popup widgets.
329                            if (m_pInstrumentListForm)
330                                    m_pInstrumentListForm->close();
331                            if (m_pDeviceForm)
332                                    m_pDeviceForm->close();
333              // Stop client and/or server, gracefully.              // Stop client and/or server, gracefully.
334              stopServer();              stopServer();
335          }          }
# Line 284  void qsamplerMainForm::closeEvent ( QClo Line 348  void qsamplerMainForm::closeEvent ( QClo
348  }  }
349    
350    
351  // Window drag-n-drop event handlers.  // Drag'n'drop file handler.
352  void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files )
353  {  {
354      bool bAccept = false;      bool bDecode = false;
355    
356      if (QTextDrag::canDecode(pDragEnterEvent)) {      if (QTextDrag::canDecode(pEvent)) {
357          QString sUrl;          QString sText;
358          if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient)          bDecode = QTextDrag::decode(pEvent, sText);
359              bAccept = QFileInfo(QUrl(sUrl).path()).exists();          if (bDecode) {
360                files = QStringList::split('\n', sText);
361                for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++)
362                    *iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path();
363            }
364      }      }
365    
366      pDragEnterEvent->accept(bAccept);      return bDecode;
367    }
368    
369    
370    // Window drag-n-drop event handlers.
371    void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
372    {
373            QStringList files;
374            pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files));
375  }  }
376    
377    
378  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )
379  {  {
380      if (QTextDrag::canDecode(pDropEvent)) {      QStringList files;
381          QString sUrl;  
382          if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true))      if (!decodeDragFiles(pDropEvent, files))
383              loadSessionFile(QUrl(sUrl).path());          return;
384      }  
385            for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) {
386                    const QString& sPath = *iter;
387                    if (qsamplerChannel::isInstrumentFile(sPath)) {
388                            // Try to create a new channel from instrument file...
389                            qsamplerChannel *pChannel = new qsamplerChannel();
390                            if (pChannel == NULL)
391                                    return;
392                            // Start setting the instrument filename...
393                            pChannel->setInstrument(sPath, 0);
394                            // Before we show it up, may be we'll
395                            // better ask for some initial values?
396                            if (!pChannel->channelSetup(this)) {
397                                    delete pChannel;
398                                    return;
399                            }
400                            // Finally, give it to a new channel strip...
401                            if (!createChannelStrip(pChannel)) {
402                                    delete pChannel;
403                                    return;
404                            }
405                            // Make that an overall update.
406                            m_iDirtyCount++;
407                            stabilizeForm();
408                    }   // Otherwise, load an usual session file (LSCP script)...
409                    else if (closeSession(true)) {
410                            loadSessionFile(sPath);
411                            break;
412                    }
413                    // Make it look responsive...:)
414                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
415            }
416  }  }
417    
418    
# Line 315  void qsamplerMainForm::customEvent ( QCu Line 422  void qsamplerMainForm::customEvent ( QCu
422      // For the time being, just pump it to messages.      // For the time being, just pump it to messages.
423      if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {      if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {
424          qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent;          qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent;
425          appendMessagesColor(tr("Notify event: %1 data: %2")                  if (pEvent->event() == LSCP_EVENT_CHANNEL_INFO) {
426              .arg(::lscp_event_to_text(pEvent->event()))                          int iChannelID = pEvent->data().toInt();
427              .arg(pEvent->data()), "#996699");                          qsamplerChannelStrip *pChannelStrip = channelStrip(iChannelID);
428                            if (pChannelStrip)
429                                    channelStripChanged(pChannelStrip);
430                    } else {
431                            appendMessagesColor(tr("Notify event: %1 data: %2")
432                                    .arg(::lscp_event_to_text(pEvent->event()))
433                                    .arg(pEvent->data()), "#996699");
434                    }
435      }      }
436  }  }
437    
# Line 326  void qsamplerMainForm::customEvent ( QCu Line 440  void qsamplerMainForm::customEvent ( QCu
440  void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent )
441  {  {
442      stabilizeForm();      stabilizeForm();
443        
444      editMenu->exec(pEvent->globalPos());      editMenu->exec(pEvent->globalPos());
445  }  }
446    
# Line 340  qsamplerOptions *qsamplerMainForm::optio Line 454  qsamplerOptions *qsamplerMainForm::optio
454      return m_pOptions;      return m_pOptions;
455  }  }
456    
457    
458  // The LSCP client descriptor property.  // The LSCP client descriptor property.
459  lscp_client_t *qsamplerMainForm::client (void)  lscp_client_t *qsamplerMainForm::client (void)
460  {  {
# Line 347  lscp_client_t *qsamplerMainForm::client Line 462  lscp_client_t *qsamplerMainForm::client
462  }  }
463    
464    
465    // The pseudo-singleton instance accessor.
466    qsamplerMainForm *qsamplerMainForm::getInstance (void)
467    {
468            return g_pMainForm;
469    }
470    
471    
472  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
473  // qsamplerMainForm -- Session file stuff.  // qsamplerMainForm -- Session file stuff.
474    
# Line 370  bool qsamplerMainForm::newSession (void) Line 492  bool qsamplerMainForm::newSession (void)
492      if (!closeSession(true))      if (!closeSession(true))
493          return false;          return false;
494    
495            // Give us what the server has, right now...
496            updateSession();
497    
498      // Ok increment untitled count.      // Ok increment untitled count.
499      m_iUntitled++;      m_iUntitled++;
500    
# Line 391  bool qsamplerMainForm::openSession (void Line 516  bool qsamplerMainForm::openSession (void
516    
517      // Ask for the filename to open...      // Ask for the filename to open...
518      QString sFilename = QFileDialog::getOpenFileName(      QString sFilename = QFileDialog::getOpenFileName(
519              m_pOptions->sSessionDir,                // Start here.                  m_pOptions->sSessionDir,                // Start here.
520              tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)                  tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)
521              this, 0,                                // Parent and name (none)                  this, 0,                                // Parent and name (none)
522              tr("Open Session")                      // Caption.                  QSAMPLER_TITLE ": " + tr("Open Session")        // Caption.
523      );      );
524    
525      // Have we cancelled?      // Have we cancelled?
# Line 425  bool qsamplerMainForm::saveSession ( boo Line 550  bool qsamplerMainForm::saveSession ( boo
550              sFilename = m_pOptions->sSessionDir;              sFilename = m_pOptions->sSessionDir;
551          // Prompt the guy...          // Prompt the guy...
552          sFilename = QFileDialog::getSaveFileName(          sFilename = QFileDialog::getSaveFileName(
553                  sFilename,                              // Start here.                          sFilename,                              // Start here.
554                  tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)                          tr("LSCP Session files") + " (*.lscp)", // Filter (LSCP files)
555                  this, 0,                                // Parent and name (none)                          this, 0,                                // Parent and name (none)
556                  tr("Save Session")                      // Caption.                          QSAMPLER_TITLE ": " + tr("Save Session")        // Caption.
557          );          );
558          // Have we cancelled it?          // Have we cancelled it?
559          if (sFilename.isEmpty())          if (sFilename.isEmpty())
# Line 438  bool qsamplerMainForm::saveSession ( boo Line 563  bool qsamplerMainForm::saveSession ( boo
563              sFilename += ".lscp";              sFilename += ".lscp";
564          // Check if already exists...          // Check if already exists...
565          if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {          if (sFilename != m_sFilename && QFileInfo(sFilename).exists()) {
566              if (QMessageBox::warning(this, tr("Warning"),              if (QMessageBox::warning(this,
567                                    QSAMPLER_TITLE ": " + tr("Warning"),
568                  tr("The file already exists:\n\n"                  tr("The file already exists:\n\n"
569                     "\"%1\"\n\n"                     "\"%1\"\n\n"
570                     "Do you want to replace it?")                     "Do you want to replace it?")
# Line 460  bool qsamplerMainForm::closeSession ( bo Line 586  bool qsamplerMainForm::closeSession ( bo
586    
587      // Are we dirty enough to prompt it?      // Are we dirty enough to prompt it?
588      if (m_iDirtyCount > 0) {      if (m_iDirtyCount > 0) {
589          switch (QMessageBox::warning(this, tr("Warning"),          switch (QMessageBox::warning(this,
590                            QSAMPLER_TITLE ": " + tr("Warning"),
591              tr("The current session has been changed:\n\n"              tr("The current session has been changed:\n\n"
592              "\"%1\"\n\n"              "\"%1\"\n\n"
593              "Do you want to save the changes?")              "Do you want to save the changes?")
# Line 483  bool qsamplerMainForm::closeSession ( bo Line 610  bool qsamplerMainForm::closeSession ( bo
610          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
611          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
612          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
613              qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
614              if (bForce && ::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK)              if (pChannelStrip) {
615                  appendMessagesClient("lscp_remove_channel");                  qsamplerChannel *pChannel = pChannelStrip->channel();
616              delete pChannel;                  if (bForce && pChannel)
617                        pChannel->removeChannel();
618                    delete pChannelStrip;
619                }
620          }          }
621          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
622          // We're now clean, for sure.          // We're now clean, for sure.
# Line 510  bool qsamplerMainForm::loadSessionFile ( Line 640  bool qsamplerMainForm::loadSessionFile (
640          return false;          return false;
641      }      }
642    
643            // Tell the world we'll take some time...
644            QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
645    
646      // Read the file.      // Read the file.
647            int iLine = 0;
648      int iErrors = 0;      int iErrors = 0;
649      QTextStream ts(&file);      QTextStream ts(&file);
650      while (!ts.atEnd()) {      while (!ts.atEnd()) {
651          // Read the line.          // Read the line.
652          QString sCommand = ts.readLine().simplifyWhiteSpace();          QString sCommand = ts.readLine().stripWhiteSpace();
653                    iLine++;
654          // If not empty, nor a comment, call the server...          // If not empty, nor a comment, call the server...
655          if (!sCommand.isEmpty() && sCommand[0] != '#') {          if (!sCommand.isEmpty() && sCommand[0] != '#') {
656              appendMessagesColor(sCommand, "#996633");                          // Remember that, no matter what,
657              // Remember that, no matter what,                          // all LSCP commands are CR/LF terminated.
658              // all LSCP commands are CR/LF terminated.                          sCommand += "\r\n";
659              sCommand += "\r\n";                          if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {
660              if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {                                  appendMessagesColor(QString("%1(%2): %3")
661                  appendMessagesClient("lscp_client_query");                                          .arg(QFileInfo(sFilename).fileName()).arg(iLine)
662                  iErrors++;                                          .arg(sCommand.simplifyWhiteSpace()), "#996633");
663              }                                  appendMessagesClient("lscp_client_query");
664                                    iErrors++;
665                            }
666          }          }
667          // Try to make it snappy :)          // Try to make it snappy :)
668          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
# Line 534  bool qsamplerMainForm::loadSessionFile ( Line 671  bool qsamplerMainForm::loadSessionFile (
671      // Ok. we've read it.      // Ok. we've read it.
672      file.close();      file.close();
673    
674      // Have we any errors?          // Now we'll try to create (update) the whole GUI session.
675      if (iErrors > 0)          updateSession();
         appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename));  
676    
677      // Now we'll try to create the whole GUI session.          // We're fornerly done.
678      int iChannels = ::lscp_get_channels(m_pClient);          QApplication::restoreOverrideCursor();
679      if (iChannels < 0) {  
680          appendMessagesClient("lscp_get_channels");          // Have we any errors?
681          appendMessagesError(tr("Could not get current number of channels.\n\nSorry."));          if (iErrors > 0)
682      }                  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);  
683    
684      // Save as default session directory.      // Save as default session directory.
685      if (m_pOptions)      if (m_pOptions)
686          m_pOptions->sSessionDir = QFileInfo(sFilename).dirPath(true);          m_pOptions->sSessionDir = QFileInfo(sFilename).dirPath(true);
687      // We're not dirty anymore.          // We're not dirty anymore, if loaded without errors,
688      m_iDirtyCount = 0;          m_iDirtyCount = iErrors;
689      // Stabilize form...      // Stabilize form...
690      m_sFilename = sFilename;      m_sFilename = sFilename;
691      updateRecentFiles(sFilename);      updateRecentFiles(sFilename);
692      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));
693    
694        // Make that an overall update.
695      stabilizeForm();      stabilizeForm();
696      return true;      return true;
697  }  }
# Line 570  bool qsamplerMainForm::loadSessionFile ( Line 700  bool qsamplerMainForm::loadSessionFile (
700  // Save current session to specific file path.  // Save current session to specific file path.
701  bool qsamplerMainForm::saveSessionFile ( const QString& sFilename )  bool qsamplerMainForm::saveSessionFile ( const QString& sFilename )
702  {  {
703            if (m_pClient == NULL)
704                    return false;
705    
706            // Check whether server is apparently OK...
707            if (::lscp_get_channels(m_pClient) < 0) {
708                    appendMessagesClient("lscp_get_channels");
709                    return false;
710            }
711    
712      // Open and write into real file.      // Open and write into real file.
713      QFile file(sFilename);      QFile file(sFilename);
714      if (!file.open(IO_WriteOnly | IO_Truncate)) {      if (!file.open(IO_WriteOnly | IO_Truncate)) {
# Line 577  bool qsamplerMainForm::saveSessionFile ( Line 716  bool qsamplerMainForm::saveSessionFile (
716          return false;          return false;
717      }      }
718    
719            // Tell the world we'll take some time...
720            QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
721    
722      // Write the file.      // Write the file.
723      int iErrors = 0;      int  iErrors = 0;
724      QTextStream ts(&file);      QTextStream ts(&file);
725      ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;      ts << "# " << QSAMPLER_TITLE " - " << tr(QSAMPLER_SUBTITLE) << endl;
726      ts << "# " << tr("Version")      ts << "# " << tr("Version")
# Line 589  bool qsamplerMainForm::saveSessionFile ( Line 731  bool qsamplerMainForm::saveSessionFile (
731      ts << "# " << tr("File")      ts << "# " << tr("File")
732         << ": " << QFileInfo(sFilename).fileName() << endl;         << ": " << QFileInfo(sFilename).fileName() << endl;
733      ts << "# " << tr("Date")      ts << "# " << tr("Date")
734         << ": " << QDate::currentDate().toString("MMMM dd yyyy")         << ": " << QDate::currentDate().toString("MMM dd yyyy")
735         << " "  << QTime::currentTime().toString("hh:mm:ss") << endl;         << " "  << QTime::currentTime().toString("hh:mm:ss") << endl;
736      ts << "#"  << endl;      ts << "#"  << endl;
737      ts << endl;      ts << endl;
738    
739            // It is assumed that this new kind of device+session file
740            // will be loaded from a complete initialized server...
741            int *piDeviceIDs;
742            int  iDevice;
743            ts << "RESET" << endl;
744    
745            // Audio device mapping.
746            QMap<int, int> audioDeviceMap;
747            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Audio);
748            for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {
749                    ts << endl;
750                    qsamplerDevice device(qsamplerDevice::Audio, piDeviceIDs[iDevice]);
751                    // Audio device specification...
752                    ts << "# " << device.deviceTypeName() << " " << device.driverName()
753                            << " " << tr("Device") << " " << iDevice << endl;
754                    ts << "CREATE AUDIO_OUTPUT_DEVICE " << device.driverName();
755                    qsamplerDeviceParamMap::ConstIterator deviceParam;
756                    for (deviceParam = device.params().begin();
757                                    deviceParam != device.params().end();
758                                            ++deviceParam) {
759                            const qsamplerDeviceParam& param = deviceParam.data();
760                            if (param.value.isEmpty()) ts << "# ";
761                            ts << " " << deviceParam.key() << "='" << param.value << "'";
762                    }
763                    ts << endl;
764                    // Audio channel parameters...
765                    int iPort = 0;
766                    for (qsamplerDevicePort *pPort = device.ports().first();
767                                    pPort;
768                                            pPort = device.ports().next(), ++iPort) {
769                            qsamplerDeviceParamMap::ConstIterator portParam;
770                            for (portParam = pPort->params().begin();
771                                            portParam != pPort->params().end();
772                                                    ++portParam) {
773                                    const qsamplerDeviceParam& param = portParam.data();
774                                    if (param.fix || param.value.isEmpty()) ts << "# ";
775                                    ts << "SET AUDIO_OUTPUT_CHANNEL_PARAMETER " << iDevice
776                                            << " " << iPort << " " << portParam.key()
777                                            << "='" << param.value << "'" << endl;
778                            }
779                    }
780                    // Audio device index/id mapping.
781                    audioDeviceMap[device.deviceID()] = iDevice;
782                    // Try to keep it snappy :)
783                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
784            }
785    
786            // MIDI device mapping.
787            QMap<int, int> midiDeviceMap;
788            piDeviceIDs = qsamplerDevice::getDevices(m_pClient, qsamplerDevice::Midi);
789            for (iDevice = 0; piDeviceIDs && piDeviceIDs[iDevice] >= 0; iDevice++) {
790                    ts << endl;
791                    qsamplerDevice device(qsamplerDevice::Midi, piDeviceIDs[iDevice]);
792                    // MIDI device specification...
793                    ts << "# " << device.deviceTypeName() << " " << device.driverName()
794                            << " " << tr("Device") << " " << iDevice << endl;
795                    ts << "CREATE MIDI_INPUT_DEVICE " << device.driverName();
796                    qsamplerDeviceParamMap::ConstIterator deviceParam;
797                    for (deviceParam = device.params().begin();
798                                    deviceParam != device.params().end();
799                                            ++deviceParam) {
800                            const qsamplerDeviceParam& param = deviceParam.data();
801                            if (param.value.isEmpty()) ts << "# ";
802                            ts << " " << deviceParam.key() << "='" << param.value << "'";
803                    }
804                    ts << endl;
805                    // MIDI port parameters...
806                    int iPort = 0;
807                    for (qsamplerDevicePort *pPort = device.ports().first();
808                                    pPort;
809                                            pPort = device.ports().next(), ++iPort) {
810                            qsamplerDeviceParamMap::ConstIterator portParam;
811                            for (portParam = pPort->params().begin();
812                                            portParam != pPort->params().end();
813                                                    ++portParam) {
814                                    const qsamplerDeviceParam& param = portParam.data();
815                                    if (param.fix || param.value.isEmpty()) ts << "# ";
816                                    ts << "SET MIDI_INPUT_PORT_PARAMETER " << iDevice
817                                       << " " << iPort << " " << portParam.key()
818                                       << "='" << param.value << "'" << endl;
819                            }
820                    }
821                    // MIDI device index/id mapping.
822                    midiDeviceMap[device.deviceID()] = iDevice;
823                    // Try to keep it snappy :)
824                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
825            }
826            ts << endl;
827    
828    #ifdef CONFIG_MIDI_INSTRUMENT
829            // MIDI instrument mapping...
830            QMap<int, int> midiInstrumentMap;
831            int *piMaps = ::lscp_list_midi_instrument_maps(m_pClient);
832            for (int iMap = 0; piMaps && piMaps[iMap] >= 0; iMap++) {
833                    int iMidiMap = piMaps[iMap];
834                    const char *pszMapName
835                            = ::lscp_get_midi_instrument_map_name(m_pClient, iMidiMap);
836                    ts << "# " << tr("MIDI instrument map") << " " << iMap;
837                    if (pszMapName)
838                            ts << " - " << pszMapName;
839                    ts << endl;
840                    ts << "ADD MIDI_INSTRUMENT_MAP";
841                    if (pszMapName)
842                            ts << " '" << pszMapName << "'";
843                    ts << endl;
844                    // MIDI instrument mapping...
845                    lscp_midi_instrument_t *pInstrs
846                            = ::lscp_list_midi_instruments(m_pClient, iMidiMap);
847                    for (int iInstr = 0; pInstrs && pInstrs[iInstr].map >= 0; iInstr++) {
848                            lscp_midi_instrument_info_t *pInstrInfo
849                                    = ::lscp_get_midi_instrument_info(m_pClient, &pInstrs[iInstr]);
850                            if (pInstrInfo) {
851                                    ts << "MAP MIDI_INSTRUMENT "
852                                            << iMap                        << " "
853                                            << pInstrs[iInstr].bank        << " "
854                                            << pInstrs[iInstr].prog        << " "
855                                            << pInstrInfo->engine_name     << " '"
856                                            << pInstrInfo->instrument_file << "' "
857                                            << pInstrInfo->instrument_nr   << " "
858                                            << pInstrInfo->volume          << " ";
859                                    switch (pInstrInfo->load_mode) {
860                                            case LSCP_LOAD_PERSISTENT:
861                                                    ts << "PERSISTENT";
862                                                    break;
863                                            case LSCP_LOAD_ON_DEMAND_HOLD:
864                                                    ts << "ON_DEMAND_HOLD";
865                                                    break;
866                                            case LSCP_LOAD_ON_DEMAND:
867                                            case LSCP_LOAD_DEFAULT:
868                                            default:
869                                                    ts << "ON_DEMAND";
870                                                    break;
871                                    }
872                                    if (pInstrInfo->name)
873                                            ts << " '" << pInstrInfo->name << "'";
874                                    ts << endl;
875                            }       // Check for errors...
876                            else if (::lscp_client_get_errno(m_pClient)) {
877                                    appendMessagesClient("lscp_get_midi_instrument_info");
878                                    iErrors++;
879                            }
880                            // Try to keep it snappy :)
881                            QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
882                    }
883                    ts << endl;
884                    // Check for errors...
885                    if (pInstrs == NULL && ::lscp_client_get_errno(m_pClient)) {
886                            appendMessagesClient("lscp_list_midi_instruments");
887                            iErrors++;
888                    }
889                    // MIDI strument index/id mapping.
890                    midiInstrumentMap[iMidiMap] = iMap;
891            }
892            // Check for errors...
893            if (piMaps == NULL && ::lscp_client_get_errno(m_pClient)) {
894                    appendMessagesClient("lscp_list_midi_instrument_maps");
895                    iErrors++;
896            }
897    #endif  // CONFIG_MIDI_INSTRUMENT
898    
899            // Sampler channel mapping.
900      QWidgetList wlist = m_pWorkspace->windowList();      QWidgetList wlist = m_pWorkspace->windowList();
901      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
902          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
903          int iChannelID = pChannel->channelID();          if (pChannelStrip) {
904          ts << "# " << pChannel->caption() << endl;              qsamplerChannel *pChannel = pChannelStrip->channel();
905          ts << "ADD CHANNEL" << endl;              if (pChannel) {
906          ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl;                  ts << "# " << tr("Channel") << " " << iChannel << endl;
907          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl;                  ts << "ADD CHANNEL" << endl;
908          ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl;                                  if (audioDeviceMap.isEmpty()) {
909          ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " " << pChannel->midiChannel() << endl;                                          ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel
910          ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl;                                                  << " " << pChannel->audioDriver() << endl;
911          ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannelID << endl;                                  } else {
912          ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl;                                          ts << "SET CHANNEL AUDIO_OUTPUT_DEVICE " << iChannel
913          ts << endl;                                                  << " " << audioDeviceMap[pChannel->audioDevice()] << endl;
914                                    }
915                                    if (midiDeviceMap.isEmpty()) {
916                                            ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel
917                                                    << " " << pChannel->midiDriver() << endl;
918                                    } else {
919                                            ts << "SET CHANNEL MIDI_INPUT_DEVICE " << iChannel
920                                                    << " " << midiDeviceMap[pChannel->midiDevice()] << endl;
921                                    }
922                                    ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel
923                                            << " " << pChannel->midiPort() << endl;
924                    ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " ";
925                    if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
926                        ts << "ALL";
927                    else
928                        ts << pChannel->midiChannel();
929                    ts << endl;
930                    ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl;
931                                    if (pChannel->instrumentStatus() < 100) ts << "# ";
932                                    ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' "
933                                            << pChannel->instrumentNr() << " " << iChannel << endl;
934                                    qsamplerChannelRoutingMap::ConstIterator audioRoute;
935                                    for (audioRoute = pChannel->audioRouting().begin();
936                                                    audioRoute != pChannel->audioRouting().end();
937                                                            ++audioRoute) {
938                                            ts << "SET CHANNEL AUDIO_OUTPUT_CHANNEL " << iChannel
939                                                    << " " << audioRoute.key()
940                                                    << " " << audioRoute.data() << endl;
941                                    }
942                                    ts << "SET CHANNEL VOLUME " << iChannel
943                                            << " " << pChannel->volume() << endl;
944                                    if (pChannel->channelMute())
945                                            ts << "SET CHANNEL MUTE " << iChannel << " 1" << endl;
946                                    if (pChannel->channelSolo())
947                                            ts << "SET CHANNEL SOLO " << iChannel << " 1" << endl;
948    #ifdef CONFIG_MIDI_INSTRUMENT
949                                    if (pChannel->midiMap() >= 0) {
950                                            ts << "SET CHANNEL MIDI_INSTRUMENT_MAP " << iChannel
951                                                    << " " << midiInstrumentMap[pChannel->midiMap()] << endl;
952                                    }
953    #endif
954                    ts << endl;
955                }
956            }
957          // Try to keep it snappy :)          // Try to keep it snappy :)
958          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
959      }      }
# Line 614  bool qsamplerMainForm::saveSessionFile ( Line 961  bool qsamplerMainForm::saveSessionFile (
961      // Ok. we've wrote it.      // Ok. we've wrote it.
962      file.close();      file.close();
963    
964            // We're fornerly done.
965            QApplication::restoreOverrideCursor();
966    
967      // Have we any errors?      // Have we any errors?
968      if (iErrors > 0)      if (iErrors > 0)
969          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 982  bool qsamplerMainForm::saveSessionFile (
982  }  }
983    
984    
985    // Session change receiver slot.
986    void qsamplerMainForm::sessionDirty (void)
987    {
988        // Just mark the dirty form.
989        m_iDirtyCount++;
990        // and update the form status...
991        stabilizeForm();
992    }
993    
994    
995  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
996  // qsamplerMainForm -- File Action slots.  // qsamplerMainForm -- File Action slots.
997    
# Line 678  void qsamplerMainForm::fileSaveAs (void) Line 1038  void qsamplerMainForm::fileSaveAs (void)
1038  }  }
1039    
1040    
1041    // Reset the sampler instance.
1042    void qsamplerMainForm::fileReset (void)
1043    {
1044        if (m_pClient == NULL)
1045            return;
1046    
1047        // Ask user whether he/she want's an internal sampler reset...
1048        if (QMessageBox::warning(this,
1049                    QSAMPLER_TITLE ": " + tr("Warning"),
1050            tr("Resetting the sampler instance will close\n"
1051               "all device and channel configurations.\n\n"
1052               "Please note that this operation may cause\n"
1053               "temporary MIDI and Audio disruption.\n\n"
1054               "Do you want to reset the sampler engine now?"),
1055            tr("Reset"), tr("Cancel")) > 0)
1056            return;
1057    
1058            // Trye closing the current session, first...
1059            if (!closeSession(true))
1060                    return;
1061    
1062        // Just do the reset, after closing down current session...
1063            // Do the actual sampler reset...
1064            if (::lscp_reset_sampler(m_pClient) != LSCP_OK) {
1065                    appendMessagesClient("lscp_reset_sampler");
1066                    appendMessagesError(tr("Could not reset sampler instance.\n\nSorry."));
1067                    return;
1068            }
1069    
1070        // Log this.
1071        appendMessages(tr("Sampler reset."));
1072    
1073            // Make it a new session...
1074            newSession();
1075    }
1076    
1077    
1078  // Restart the client/server instance.  // Restart the client/server instance.
1079  void qsamplerMainForm::fileRestart (void)  void qsamplerMainForm::fileRestart (void)
1080  {  {
1081      if (m_pOptions == NULL)      if (m_pOptions == NULL)
1082          return;          return;
1083            
1084      bool bRestart = true;      bool bRestart = true;
1085        
1086      // Ask user whether he/she want's a complete restart...      // Ask user whether he/she want's a complete restart...
1087      // (if we're currently up and running)      // (if we're currently up and running)
1088      if (bRestart && m_pClient) {      if (bRestart && m_pClient) {
1089          bRestart = (QMessageBox::warning(this, tr("Warning"),          bRestart = (QMessageBox::warning(this,
1090                            QSAMPLER_TITLE ": " + tr("Warning"),
1091              tr("New settings will be effective after\n"              tr("New settings will be effective after\n"
1092                 "restarting the client/server connection.\n\n"                 "restarting the client/server connection.\n\n"
1093                 "Please note that this operation may cause\n"                 "Please note that this operation may cause\n"
1094                 "temporary MIDI and Audio disruption\n\n"                 "temporary MIDI and Audio disruption.\n\n"
1095                 "Do you want to restart the connection now?"),                 "Do you want to restart the connection now?"),
1096              tr("Restart"), tr("Cancel")) == 0);              tr("Restart"), tr("Cancel")) == 0);
1097      }      }
# Line 725  void qsamplerMainForm::editAddChannel (v Line 1123  void qsamplerMainForm::editAddChannel (v
1123      if (m_pClient == NULL)      if (m_pClient == NULL)
1124          return;          return;
1125    
1126      // Create the new sampler channel.      // Just create the channel instance...
1127      int iChannelID = ::lscp_add_channel(m_pClient);      qsamplerChannel *pChannel = new qsamplerChannel();
1128      if (iChannelID < 0) {      if (pChannel == NULL)
         appendMessagesClient("lscp_add_channel");  
         appendMessagesError(tr("Could not create the new channel.\n\nSorry."));  
1129          return;          return;
     }  
1130    
1131      // Log this happening.      // Before we show it up, may be we'll
1132      appendMessages(tr("Channel %1 created.").arg(iChannelID));      // better ask for some initial values?
1133        if (!pChannel->channelSetup(this)) {
1134            delete pChannel;
1135            return;
1136        }
1137    
1138      // Just create the channel strip with given id.      // And give it to the strip (will own the channel instance, if successful).
1139      createChannel(iChannelID, true);      if (!createChannelStrip(pChannel)) {
1140            delete pChannel;
1141            return;
1142        }
1143    
1144      // We'll be dirty, for sure...      // Make that an overall update.
1145      m_iDirtyCount++;      m_iDirtyCount++;
     // Stabilize form anyway.  
1146      stabilizeForm();      stabilizeForm();
1147  }  }
1148    
# Line 752  void qsamplerMainForm::editRemoveChannel Line 1153  void qsamplerMainForm::editRemoveChannel
1153      if (m_pClient == NULL)      if (m_pClient == NULL)
1154          return;          return;
1155    
1156      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1157        if (pChannelStrip == NULL)
1158            return;
1159    
1160        qsamplerChannel *pChannel = pChannelStrip->channel();
1161      if (pChannel == NULL)      if (pChannel == NULL)
1162          return;          return;
1163    
1164      // Prompt user if he/she's sure about this...      // Prompt user if he/she's sure about this...
1165      if (m_pOptions && m_pOptions->bConfirmRemove) {      if (m_pOptions && m_pOptions->bConfirmRemove) {
1166          if (QMessageBox::warning(this, tr("Warning"),          if (QMessageBox::warning(this,
1167                            QSAMPLER_TITLE ": " + tr("Warning"),
1168              tr("About to remove channel:\n\n"              tr("About to remove channel:\n\n"
1169                 "%1\n\n"                 "%1\n\n"
1170                 "Are you sure?")                 "Are you sure?")
1171                 .arg(pChannel->caption()),                 .arg(pChannelStrip->caption()),
1172              tr("OK"), tr("Cancel")) > 0)              tr("OK"), tr("Cancel")) > 0)
1173              return;              return;
1174      }      }
1175    
1176      // Remove the existing sampler channel.      // Remove the existing sampler channel.
1177      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."));  
1178          return;          return;
     }  
1179    
     // Log this happening.  
     appendMessages(tr("Channel %1 removed.").arg(pChannel->channelID()));  
       
1180      // Just delete the channel strip.      // Just delete the channel strip.
1181      delete pChannel;      delete pChannelStrip;
1182    
1183      // Do we auto-arrange?      // Do we auto-arrange?
1184      if (m_pOptions && m_pOptions->bAutoArrange)      if (m_pOptions && m_pOptions->bAutoArrange)
1185          channelsArrange();          channelsArrange();
# Line 795  void qsamplerMainForm::editSetupChannel Line 1196  void qsamplerMainForm::editSetupChannel
1196      if (m_pClient == NULL)      if (m_pClient == NULL)
1197          return;          return;
1198    
1199      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1200      if (pChannel == NULL)      if (pChannelStrip == NULL)
1201          return;          return;
1202    
1203      // Just invoque the channel strip procedure.      // Just invoque the channel strip procedure.
1204      pChannel->channelSetup(false);      pChannelStrip->channelSetup();
1205  }  }
1206    
1207    
# Line 810  void qsamplerMainForm::editResetChannel Line 1211  void qsamplerMainForm::editResetChannel
1211      if (m_pClient == NULL)      if (m_pClient == NULL)
1212          return;          return;
1213    
1214      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1215      if (pChannel == NULL)      if (pChannelStrip == NULL)
1216          return;          return;
1217    
1218      // Remove the existing sampler channel.      // Just invoque the channel strip procedure.
1219      if (::lscp_reset_channel(m_pClient, pChannel->channelID()) != LSCP_OK) {      pChannelStrip->channelReset();
1220          appendMessagesClient("lscp_reset_channel");  }
         appendMessagesError(tr("Could not reset channel.\n\nSorry."));  
         return;  
     }  
1221    
     // Log this.  
     appendMessages(tr("Channel %1 reset.").arg(pChannel->channelID()));  
1222    
1223      // Refresh channel strip info.  // Reset all sampler channels.
1224      pChannel->updateChannelInfo();  void qsamplerMainForm::editResetAllChannels (void)
1225    {
1226            if (m_pClient == NULL)
1227                    return;
1228    
1229            // Invoque the channel strip procedure,
1230            // for all channels out there...
1231            m_pWorkspace->setUpdatesEnabled(false);
1232            QWidgetList wlist = m_pWorkspace->windowList();
1233            for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1234                    qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1235                    if (pChannelStrip)
1236                            pChannelStrip->channelReset();
1237            }
1238            m_pWorkspace->setUpdatesEnabled(true);
1239  }  }
1240    
1241    
# Line 877  void qsamplerMainForm::viewMessages ( bo Line 1287  void qsamplerMainForm::viewMessages ( bo
1287  }  }
1288    
1289    
1290    // Show/hide the MIDI instrument list-view form.
1291    void qsamplerMainForm::viewInstruments (void)
1292    {
1293            if (m_pOptions == NULL)
1294                    return;
1295    
1296            if (m_pInstrumentListForm) {
1297                    m_pOptions->saveWidgetGeometry(m_pInstrumentListForm);
1298                    if (m_pInstrumentListForm->isVisible()) {
1299                            m_pInstrumentListForm->hide();
1300                    } else {
1301                            m_pInstrumentListForm->show();
1302                            m_pInstrumentListForm->raise();
1303                            m_pInstrumentListForm->setActiveWindow();
1304                    }
1305            }
1306    }
1307    
1308    
1309    // Show/hide the device configurator form.
1310    void qsamplerMainForm::viewDevices (void)
1311    {
1312            if (m_pOptions == NULL)
1313                    return;
1314    
1315            if (m_pDeviceForm) {
1316                    m_pOptions->saveWidgetGeometry(m_pDeviceForm);
1317                    if (m_pDeviceForm->isVisible()) {
1318                            m_pDeviceForm->hide();
1319                    } else {
1320                            m_pDeviceForm->show();
1321                            m_pDeviceForm->raise();
1322                            m_pDeviceForm->setActiveWindow();
1323                    }
1324            }
1325    }
1326    
1327    
1328  // Show options dialog.  // Show options dialog.
1329  void qsamplerMainForm::viewOptions (void)  void qsamplerMainForm::viewOptions (void)
1330  {  {
# Line 886  void qsamplerMainForm::viewOptions (void Line 1334  void qsamplerMainForm::viewOptions (void
1334      qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this);      qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this);
1335      if (pOptionsForm) {      if (pOptionsForm) {
1336          // Check out some initial nullities(tm)...          // Check out some initial nullities(tm)...
1337          qsamplerChannelStrip *pChannel = activeChannel();          qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1338          if (m_pOptions->sDisplayFont.isEmpty() && pChannel)          if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip)
1339              m_pOptions->sDisplayFont = pChannel->displayFont().toString();              m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString();
1340          if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)          if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1341              m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();              m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1342          // To track down deferred or immediate changes.          // To track down deferred or immediate changes.
# Line 898  void qsamplerMainForm::viewOptions (void Line 1346  void qsamplerMainForm::viewOptions (void
1346          bool    bOldServerStart     = m_pOptions->bServerStart;          bool    bOldServerStart     = m_pOptions->bServerStart;
1347          QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;          QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;
1348          QString sOldDisplayFont     = m_pOptions->sDisplayFont;          QString sOldDisplayFont     = m_pOptions->sDisplayFont;
1349            bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;
1350          int     iOldMaxVolume       = m_pOptions->iMaxVolume;          int     iOldMaxVolume       = m_pOptions->iMaxVolume;
1351          QString sOldMessagesFont    = m_pOptions->sMessagesFont;          QString sOldMessagesFont    = m_pOptions->sMessagesFont;
1352            bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;
1353          bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;          bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;
1354          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;
1355          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1356          bool    bOldCompletePath    = m_pOptions->bCompletePath;          bool    bOldCompletePath    = m_pOptions->bCompletePath;
1357            bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;
1358          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;
1359          // Load the current setup settings.          // Load the current setup settings.
1360          pOptionsForm->setup(m_pOptions);          pOptionsForm->setup(m_pOptions);
# Line 911  void qsamplerMainForm::viewOptions (void Line 1362  void qsamplerMainForm::viewOptions (void
1362          if (pOptionsForm->exec()) {          if (pOptionsForm->exec()) {
1363              // Warn if something will be only effective on next run.              // Warn if something will be only effective on next run.
1364              if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||              if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1365                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||
1366                  QMessageBox::information(this, tr("Information"),                  ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1367                    (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)) {
1368                    QMessageBox::information(this,
1369                                            QSAMPLER_TITLE ": " + tr("Information"),
1370                      tr("Some settings may be only effective\n"                      tr("Some settings may be only effective\n"
1371                         "next time you start this program."), tr("OK"));                         "next time you start this program."), tr("OK"));
1372                  updateMessagesCapture();                  updateMessagesCapture();
# Line 922  void qsamplerMainForm::viewOptions (void Line 1376  void qsamplerMainForm::viewOptions (void
1376                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||
1377                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))
1378                  updateRecentFilesMenu();                  updateRecentFilesMenu();
1379                if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) ||
1380                    (!bOldInstrumentNames &&  m_pOptions->bInstrumentNames))
1381                    updateInstrumentNames();
1382                if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) ||
1383                    (!bOldDisplayEffect &&  m_pOptions->bDisplayEffect))
1384                    updateDisplayEffect();
1385              if (sOldDisplayFont != m_pOptions->sDisplayFont)              if (sOldDisplayFont != m_pOptions->sDisplayFont)
1386                  updateDisplayFont();                  updateDisplayFont();
1387              if (iOldMaxVolume != m_pOptions->iMaxVolume)              if (iOldMaxVolume != m_pOptions->iMaxVolume)
# Line 964  void qsamplerMainForm::channelsArrange ( Line 1424  void qsamplerMainForm::channelsArrange (
1424      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1425      int y = 0;      int y = 0;
1426      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1427          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1428      /*  if (pChannel->testWState(WState_Maximized | WState_Minimized)) {      /*  if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) {
1429              // Prevent flicker...              // Prevent flicker...
1430              pChannel->hide();              pChannelStrip->hide();
1431              pChannel->showNormal();              pChannelStrip->showNormal();
1432          }   */          }   */
1433          pChannel->adjustSize();          pChannelStrip->adjustSize();
1434          int iWidth  = m_pWorkspace->width();          int iWidth  = m_pWorkspace->width();
1435          if (iWidth < pChannel->width())          if (iWidth < pChannelStrip->width())
1436              iWidth = pChannel->width();              iWidth = pChannelStrip->width();
1437      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();      //  int iHeight = pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();
1438          int iHeight = pChannel->parentWidget()->frameGeometry().height();          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1439          pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight);          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1440          y += iHeight;          y += iHeight;
1441      }      }
1442      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1443        
1444      stabilizeForm();      stabilizeForm();
1445  }  }
1446    
# Line 1029  void qsamplerMainForm::helpAbout (void) Line 1489  void qsamplerMainForm::helpAbout (void)
1489      sText += tr("GIG (libgig) file support disabled.");      sText += tr("GIG (libgig) file support disabled.");
1490      sText += "</font></small><br />";      sText += "</font></small><br />";
1491  #endif  #endif
1492    #ifndef CONFIG_INSTRUMENT_NAME
1493        sText += "<small><font color=\"red\">";
1494        sText += tr("LSCP (liblscp) instrument_name support disabled.");
1495        sText += "</font></small><br />";
1496    #endif
1497    #ifndef CONFIG_MUTE_SOLO
1498        sText += "<small><font color=\"red\">";
1499        sText += tr("Sampler channel Mute/Solo support disabled.");
1500        sText += "</font></small><br />";
1501    #endif
1502    #ifndef CONFIG_MIDI_INSTRUMENT
1503        sText += "<small><font color=\"red\">";
1504        sText += tr("MIDI instrument mapping support disabled.");
1505        sText += "</font></small><br />";
1506    #endif
1507      sText += "<br />\n";      sText += "<br />\n";
1508      sText += tr("Using") + ": ";      sText += tr("Using") + ": ";
1509      sText += ::lscp_client_package();      sText += ::lscp_client_package();
1510      sText += " ";      sText += " ";
1511      sText += ::lscp_client_version();      sText += ::lscp_client_version();
1512    #ifdef CONFIG_LIBGIG
1513        sText += ", ";
1514        sText += gig::libraryName().c_str();
1515        sText += " ";
1516        sText += gig::libraryVersion().c_str();
1517    #endif
1518      sText += "<br />\n";      sText += "<br />\n";
1519      sText += "<br />\n";      sText += "<br />\n";
1520      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 1056  void qsamplerMainForm::helpAbout (void) Line 1537  void qsamplerMainForm::helpAbout (void)
1537  void qsamplerMainForm::stabilizeForm (void)  void qsamplerMainForm::stabilizeForm (void)
1538  {  {
1539      // Update the main application caption...      // Update the main application caption...
1540      QString sSessioName = sessionName(m_sFilename);      QString sSessionName = sessionName(m_sFilename);
1541      if (m_iDirtyCount > 0)      if (m_iDirtyCount > 0)
1542          sSessioName += '*';          sSessionName += " *";
1543      setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName));      setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));
1544    
1545      // Update the main menu state...      // Update the main menu state...
1546      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1547      bool bHasClient  = (m_pOptions != NULL && m_pClient != NULL);      bool bHasClient  = (m_pOptions != NULL && m_pClient != NULL);
1548      bool bHasChannel = (bHasClient && pChannel != NULL);      bool bHasChannel = (bHasClient && pChannelStrip != NULL);
1549      fileNewAction->setEnabled(bHasClient);      fileNewAction->setEnabled(bHasClient);
1550      fileOpenAction->setEnabled(bHasClient);      fileOpenAction->setEnabled(bHasClient);
1551      fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);      fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);
1552      fileSaveAsAction->setEnabled(bHasClient);      fileSaveAsAction->setEnabled(bHasClient);
1553        fileResetAction->setEnabled(bHasClient);
1554      fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);      fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);
1555      editAddChannelAction->setEnabled(bHasClient);      editAddChannelAction->setEnabled(bHasClient);
1556      editRemoveChannelAction->setEnabled(bHasChannel);      editRemoveChannelAction->setEnabled(bHasChannel);
1557      editSetupChannelAction->setEnabled(bHasChannel);      editSetupChannelAction->setEnabled(bHasChannel);
1558      editResetChannelAction->setEnabled(bHasChannel);      editResetChannelAction->setEnabled(bHasChannel);
1559      channelsArrangeAction->setEnabled(bHasChannel);      editResetAllChannelsAction->setEnabled(bHasChannel);
1560      viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible());      viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible());
1561    #ifdef CONFIG_MIDI_INSTRUMENT
1562            viewInstrumentsAction->setOn(m_pInstrumentListForm
1563                    && m_pInstrumentListForm->isVisible());
1564            viewInstrumentsAction->setEnabled(bHasClient);
1565    #endif
1566            viewDevicesAction->setOn(m_pDeviceForm
1567                    && m_pDeviceForm->isVisible());
1568        viewDevicesAction->setEnabled(bHasClient);
1569        channelsArrangeAction->setEnabled(bHasChannel);
1570    
1571      // Client/Server status...      // Client/Server status...
1572      if (bHasClient) {      if (bHasClient) {
1573          m_status[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected"));          m_statusItem[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected"));
1574          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));
1575      } else {      } else {
1576          m_status[QSAMPLER_STATUS_CLIENT]->clear();          m_statusItem[QSAMPLER_STATUS_CLIENT]->clear();
1577          m_status[QSAMPLER_STATUS_SERVER]->clear();          m_statusItem[QSAMPLER_STATUS_SERVER]->clear();
1578      }      }
1579      // Channel status...      // Channel status...
1580      if (bHasChannel)      if (bHasChannel)
1581          m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannel->caption());          m_statusItem[QSAMPLER_STATUS_CHANNEL]->setText(pChannelStrip->caption());
1582      else      else
1583          m_status[QSAMPLER_STATUS_CHANNEL]->clear();          m_statusItem[QSAMPLER_STATUS_CHANNEL]->clear();
1584      // Session status...      // Session status...
1585      if (m_iDirtyCount > 0)      if (m_iDirtyCount > 0)
1586          m_status[QSAMPLER_STATUS_SESSION]->setText(tr("MOD"));          m_statusItem[QSAMPLER_STATUS_SESSION]->setText(tr("MOD"));
1587      else      else
1588          m_status[QSAMPLER_STATUS_SESSION]->clear();          m_statusItem[QSAMPLER_STATUS_SESSION]->clear();
1589    
1590      // Recent files menu.      // Recent files menu.
1591      m_pRecentFilesMenu->setEnabled(bHasClient && m_pOptions->recentFiles.count() > 0);      m_pRecentFilesMenu->setEnabled(bHasClient && m_pOptions->recentFiles.count() > 0);
# Line 1106  void qsamplerMainForm::stabilizeForm (vo Line 1597  void qsamplerMainForm::stabilizeForm (vo
1597    
1598    
1599  // Channel change receiver slot.  // Channel change receiver slot.
1600  void qsamplerMainForm::channelChanged( qsamplerChannelStrip * )  void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip )
1601  {  {
1602            // Add this strip to the changed list...
1603            if (m_changedStrips.containsRef(pChannelStrip) == 0) {
1604                    m_changedStrips.append(pChannelStrip);
1605                    pChannelStrip->resetErrorCount();
1606            }
1607    
1608      // Just mark the dirty form.      // Just mark the dirty form.
1609      m_iDirtyCount++;      m_iDirtyCount++;
1610      // and update the form status...      // and update the form status...
# Line 1115  void qsamplerMainForm::channelChanged( q Line 1612  void qsamplerMainForm::channelChanged( q
1612  }  }
1613    
1614    
1615    // Grab and restore current sampler channels session.
1616    void qsamplerMainForm::updateSession (void)
1617    {
1618    #ifdef CONFIG_MIDI_INSTRUMENT
1619            // FIXME: Make some room for default instrument maps...
1620            int iMaps = ::lscp_get_midi_instrument_maps(m_pClient);
1621            if (iMaps < 0)
1622                    appendMessagesClient("lscp_get_midi_instrument_maps");
1623            else if (iMaps < 1) {
1624                    ::lscp_add_midi_instrument_map(m_pClient, tr("Chromatic").latin1());
1625                    ::lscp_add_midi_instrument_map(m_pClient, tr("Drum Kits").latin1());
1626            }
1627    #endif
1628    
1629            // Retrieve the current channel list.
1630            int *piChannelIDs = ::lscp_list_channels(m_pClient);
1631            if (piChannelIDs == NULL) {
1632                    if (::lscp_client_get_errno(m_pClient)) {
1633                            appendMessagesClient("lscp_list_channels");
1634                            appendMessagesError(tr("Could not get current list of channels.\n\nSorry."));
1635                    }
1636            } else {
1637                    // Try to (re)create each channel.
1638                    m_pWorkspace->setUpdatesEnabled(false);
1639                    for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) {
1640                            // Check if theres already a channel strip for this one...
1641                            if (!channelStrip(piChannelIDs[iChannel]))
1642                                    createChannelStrip(new qsamplerChannel(piChannelIDs[iChannel]));
1643                    }
1644                    m_pWorkspace->setUpdatesEnabled(true);
1645            }
1646    
1647        // Do we auto-arrange?
1648        if (m_pOptions && m_pOptions->bAutoArrange)
1649            channelsArrange();
1650    
1651            // Remember to refresh devices and instruments...
1652            if (m_pInstrumentListForm)
1653                m_pInstrumentListForm->refreshInstruments();
1654            if (m_pDeviceForm)
1655                m_pDeviceForm->refreshDevices();
1656    }
1657    
1658    
1659  // Update the recent files list and menu.  // Update the recent files list and menu.
1660  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )
1661  {  {
# Line 1159  void qsamplerMainForm::updateRecentFiles Line 1700  void qsamplerMainForm::updateRecentFiles
1700  }  }
1701    
1702    
1703    // Force update of the channels instrument names mode.
1704    void qsamplerMainForm::updateInstrumentNames (void)
1705    {
1706        // Full channel list update...
1707        QWidgetList wlist = m_pWorkspace->windowList();
1708        if (wlist.isEmpty())
1709            return;
1710    
1711        m_pWorkspace->setUpdatesEnabled(false);
1712        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1713            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1714            if (pChannelStrip)
1715                pChannelStrip->updateInstrumentName(true);
1716        }
1717        m_pWorkspace->setUpdatesEnabled(true);
1718    }
1719    
1720    
1721  // Force update of the channels display font.  // Force update of the channels display font.
1722  void qsamplerMainForm::updateDisplayFont (void)  void qsamplerMainForm::updateDisplayFont (void)
1723  {  {
# Line 1180  void qsamplerMainForm::updateDisplayFont Line 1739  void qsamplerMainForm::updateDisplayFont
1739    
1740      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1741      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1742          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1743          pChannel->setDisplayFont(font);          if (pChannelStrip)
1744                pChannelStrip->setDisplayFont(font);
1745        }
1746        m_pWorkspace->setUpdatesEnabled(true);
1747    }
1748    
1749    
1750    // Update channel strips background effect.
1751    void qsamplerMainForm::updateDisplayEffect (void)
1752    {
1753       QPixmap pm;
1754        if (m_pOptions->bDisplayEffect)
1755            pm = QPixmap::fromMimeSource("displaybg1.png");
1756    
1757        // Full channel list update...
1758        QWidgetList wlist = m_pWorkspace->windowList();
1759        if (wlist.isEmpty())
1760            return;
1761    
1762        m_pWorkspace->setUpdatesEnabled(false);
1763        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1764            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1765            if (pChannelStrip)
1766                pChannelStrip->setDisplayBackground(pm);
1767      }      }
1768      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1769  }  }
# Line 1200  void qsamplerMainForm::updateMaxVolume ( Line 1782  void qsamplerMainForm::updateMaxVolume (
1782    
1783      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1784      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1785          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1786          pChannel->setMaxVolume(m_pOptions->iMaxVolume);          if (pChannelStrip)
1787                pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
1788      }      }
1789      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1790  }  }
# Line 1240  void qsamplerMainForm::appendMessagesErr Line 1823  void qsamplerMainForm::appendMessagesErr
1823    
1824      appendMessagesColor(s.simplifyWhiteSpace(), "#ff0000");      appendMessagesColor(s.simplifyWhiteSpace(), "#ff0000");
1825    
1826      QMessageBox::critical(this, tr("Error"), s, tr("Cancel"));          // Make it look responsive...:)
1827            QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
1828    
1829        QMessageBox::critical(this,
1830                    QSAMPLER_TITLE ": " + tr("Error"), s, tr("Cancel"));
1831  }  }
1832    
1833    
# Line 1253  void qsamplerMainForm::appendMessagesCli Line 1840  void qsamplerMainForm::appendMessagesCli
1840      appendMessagesColor(s + QString(": %1 (errno=%2)")      appendMessagesColor(s + QString(": %1 (errno=%2)")
1841          .arg(::lscp_client_get_result(m_pClient))          .arg(::lscp_client_get_result(m_pClient))
1842          .arg(::lscp_client_get_errno(m_pClient)), "#996666");          .arg(::lscp_client_get_errno(m_pClient)), "#996666");
1843    
1844            // Make it look responsive...:)
1845            QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
1846  }  }
1847    
1848    
# Line 1280  void qsamplerMainForm::updateMessagesLim Line 1870  void qsamplerMainForm::updateMessagesLim
1870          if (m_pOptions->bMessagesLimit)          if (m_pOptions->bMessagesLimit)
1871              m_pMessages->setMessagesLimit(m_pOptions->iMessagesLimitLines);              m_pMessages->setMessagesLimit(m_pOptions->iMessagesLimitLines);
1872          else          else
1873              m_pMessages->setMessagesLimit(0);              m_pMessages->setMessagesLimit(-1);
1874      }      }
1875  }  }
1876    
# Line 1300  void qsamplerMainForm::updateMessagesCap Line 1890  void qsamplerMainForm::updateMessagesCap
1890  // qsamplerMainForm -- MDI channel strip management.  // qsamplerMainForm -- MDI channel strip management.
1891    
1892  // The channel strip creation executive.  // The channel strip creation executive.
1893  void qsamplerMainForm::createChannel ( int iChannelID, bool bPrompt )  qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( qsamplerChannel *pChannel )
1894  {  {
1895      if (m_pClient == NULL)      if (m_pClient == NULL || pChannel == NULL)
1896          return;          return NULL;
1897    
1898      // Prepare for auto-arrange?      // Prepare for auto-arrange?
1899      qsamplerChannelStrip *pChannel = NULL;      qsamplerChannelStrip *pChannelStrip = NULL;
1900      int y = 0;      int y = 0;
1901      if (m_pOptions && m_pOptions->bAutoArrange) {      if (m_pOptions && m_pOptions->bAutoArrange) {
1902          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
1903          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1904              pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1905          //  y += pChannel->height() + pChannel->parentWidget()->baseSize().height();                          if (pChannelStrip) {
1906              y += pChannel->parentWidget()->frameGeometry().height();                          //  y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();
1907                                    y += pChannelStrip->parentWidget()->frameGeometry().height();
1908                            }
1909          }          }
1910      }      }
1911    
1912      // Add a new channel itema...      // Add a new channel itema...
1913      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;
1914      pChannel = new qsamplerChannelStrip(m_pWorkspace, 0, wflags);      pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags);
1915      pChannel->setMaxVolume(m_pOptions->iMaxVolume);      if (pChannelStrip == NULL)
1916      pChannel->setup(this, iChannelID);          return NULL;
1917      // We'll need a display font.  
1918      QFont font;      // Actual channel strip setup...
1919      if (m_pOptions && font.fromString(m_pOptions->sDisplayFont))      pChannelStrip->setup(pChannel);
1920          pChannel->setDisplayFont(font);          QObject::connect(pChannelStrip,
1921      // Track channel setup changes.                  SIGNAL(channelChanged(qsamplerChannelStrip *)),
1922      QObject::connect(pChannel, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelChanged(qsamplerChannelStrip *)));                  SLOT(channelStripChanged(qsamplerChannelStrip *)));
1923      // Before we show it up, may be we'll      // Set some initial aesthetic options...
1924      // better ask for some initial values?      if (m_pOptions) {
1925      if (bPrompt)          // Background display effect...
1926          pChannel->channelSetup(true);          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
1927            // We'll need a display font.
1928            QFont font;
1929            if (font.fromString(m_pOptions->sDisplayFont))
1930                pChannelStrip->setDisplayFont(font);
1931            // Maximum allowed volume setting.
1932            pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
1933        }
1934    
1935      // Now we show up us to the world.      // Now we show up us to the world.
1936      pChannel->show();      pChannelStrip->show();
1937      // Only then, we'll auto-arrange...      // Only then, we'll auto-arrange...
1938      if (m_pOptions && m_pOptions->bAutoArrange) {      if (m_pOptions && m_pOptions->bAutoArrange) {
1939          int iWidth  = m_pWorkspace->width();          int iWidth  = m_pWorkspace->width();
1940      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();
1941          int iHeight = pChannel->parentWidget()->frameGeometry().height();          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1942          pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight);          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1943      }      }
1944    
1945            // This is pretty new, so we'll watch for it closely.
1946            channelStripChanged(pChannelStrip);
1947    
1948        // Return our successful reference...
1949        return pChannelStrip;
1950  }  }
1951    
1952    
1953  // Retrieve the active channel strip.  // Retrieve the active channel strip.
1954  qsamplerChannelStrip *qsamplerMainForm::activeChannel (void)  qsamplerChannelStrip *qsamplerMainForm::activeChannelStrip (void)
1955  {  {
1956      return (qsamplerChannelStrip *) m_pWorkspace->activeWindow();      return (qsamplerChannelStrip *) m_pWorkspace->activeWindow();
1957  }  }
1958    
1959    
1960  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
1961  qsamplerChannelStrip *qsamplerMainForm::channelAt ( int iChannel )  qsamplerChannelStrip *qsamplerMainForm::channelStripAt ( int iChannel )
1962  {  {
1963      QWidgetList wlist = m_pWorkspace->windowList();      QWidgetList wlist = m_pWorkspace->windowList();
1964      if (wlist.isEmpty())      if (wlist.isEmpty())
1965          return 0;          return NULL;
1966    
1967      return (qsamplerChannelStrip *) wlist.at(iChannel);      return (qsamplerChannelStrip *) wlist.at(iChannel);
1968  }  }
1969    
1970    
1971    // Retrieve a channel strip by sampler channel id.
1972    qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID )
1973    {
1974            QWidgetList wlist = m_pWorkspace->windowList();
1975            if (wlist.isEmpty())
1976                    return NULL;
1977    
1978            for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1979                    qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1980                    if (pChannelStrip) {
1981                            qsamplerChannel *pChannel = pChannelStrip->channel();
1982                            if (pChannel && pChannel->channelID() == iChannelID)
1983                                    return pChannelStrip;
1984                    }
1985            }
1986    
1987            // Not found.
1988            return NULL;
1989    }
1990    
1991    
1992  // Construct the windows menu.  // Construct the windows menu.
1993  void qsamplerMainForm::channelsMenuAboutToShow (void)  void qsamplerMainForm::channelsMenuAboutToShow (void)
1994  {  {
# Line 1373  void qsamplerMainForm::channelsMenuAbout Line 2000  void qsamplerMainForm::channelsMenuAbout
2000      if (!wlist.isEmpty()) {      if (!wlist.isEmpty()) {
2001          channelsMenu->insertSeparator();          channelsMenu->insertSeparator();
2002          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
2003              qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
2004              int iItemID = channelsMenu->insertItem(pChannel->caption(), this, SLOT(channelsMenuActivated(int)));              if (pChannelStrip) {
2005              channelsMenu->setItemParameter(iItemID, iChannel);                  int iItemID = channelsMenu->insertItem(pChannelStrip->caption(), this, SLOT(channelsMenuActivated(int)));
2006              channelsMenu->setItemChecked(iItemID, activeChannel() == pChannel);                  channelsMenu->setItemParameter(iItemID, iChannel);
2007                    channelsMenu->setItemChecked(iItemID, activeChannelStrip() == pChannelStrip);
2008                }
2009          }          }
2010      }      }
2011  }  }
# Line 1385  void qsamplerMainForm::channelsMenuAbout Line 2014  void qsamplerMainForm::channelsMenuAbout
2014  // Windows menu activation slot  // Windows menu activation slot
2015  void qsamplerMainForm::channelsMenuActivated ( int iChannel )  void qsamplerMainForm::channelsMenuActivated ( int iChannel )
2016  {  {
2017      qsamplerChannelStrip *pChannel = channelAt(iChannel);      qsamplerChannelStrip *pChannelStrip = channelStripAt(iChannel);
2018      if (pChannel)      if (pChannelStrip)
2019          pChannel->showNormal();          pChannelStrip->showNormal();
2020      pChannel->setFocus();      pChannelStrip->setFocus();
2021  }  }
2022    
2023    
# Line 1426  void qsamplerMainForm::timerSlot (void) Line 2055  void qsamplerMainForm::timerSlot (void)
2055              }              }
2056          }          }
2057      }      }
2058        
2059          // Refresh each channel usage, on each period...          if (m_pClient) {
2060      if (m_pClient && m_pOptions->bAutoRefresh && m_pWorkspace->isUpdatesEnabled()) {                  // Update the channel information for each pending strip...
2061          m_iTimerSlot += QSAMPLER_TIMER_MSECS;                  if (m_changedStrips.count() > 0) {
2062          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {                          for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first();
2063              m_iTimerSlot = 0;                                          pChannelStrip; pChannelStrip = m_changedStrips.next()) {
2064              QWidgetList wlist = m_pWorkspace->windowList();                                  // If successfull, remove from pending list...
2065              for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {                                  if (pChannelStrip->updateChannelInfo())
2066                  qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);                                          m_changedStrips.remove(pChannelStrip);
2067                  if (pChannel->isVisible())                          }
2068                      pChannel->updateChannelUsage();                  }
2069              }                  // Refresh each channel usage, on each period...
2070          }                  if (m_pOptions->bAutoRefresh) {
2071      }                          m_iTimerSlot += QSAMPLER_TIMER_MSECS;
2072                            if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {
2073                                    m_iTimerSlot = 0;
2074                                    // Update the channel stream usage for each strip...
2075                                    QWidgetList wlist = m_pWorkspace->windowList();
2076                                    for (int iChannel = 0;
2077                                                    iChannel < (int) wlist.count(); iChannel++) {
2078                                            qsamplerChannelStrip *pChannelStrip
2079                                                    = (qsamplerChannelStrip *) wlist.at(iChannel);
2080                                            if (pChannelStrip && pChannelStrip->isVisible())
2081                                                    pChannelStrip->updateChannelUsage();
2082                                    }
2083                            }
2084                    }
2085            }
2086    
2087      // Register the next timer slot.      // Register the next timer slot.
2088      QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(timerSlot()));      QTimer::singleShot(QSAMPLER_TIMER_MSECS, this, SLOT(timerSlot()));
# Line 1461  void qsamplerMainForm::startServer (void Line 2104  void qsamplerMainForm::startServer (void
2104    
2105      // Is the server process instance still here?      // Is the server process instance still here?
2106      if (m_pServer) {      if (m_pServer) {
2107          switch (QMessageBox::warning(this, tr("Warning"),          switch (QMessageBox::warning(this,
2108                            QSAMPLER_TITLE ": " + tr("Warning"),
2109              tr("Could not start the LinuxSampler server.\n\n"              tr("Could not start the LinuxSampler server.\n\n"
2110                 "Maybe it ss already started."),                 "Maybe it ss already started."),
2111              tr("Stop"), tr("Kill"), tr("Cancel"))) {              tr("Stop"), tr("Kill"), tr("Cancel"))) {
# Line 1482  void qsamplerMainForm::startServer (void Line 2126  void qsamplerMainForm::startServer (void
2126      m_pServer = new QProcess(this);      m_pServer = new QProcess(this);
2127    
2128      // Setup stdout/stderr capture...      // Setup stdout/stderr capture...
2129      //if (m_pOptions->bStdoutCapture) {          //      if (m_pOptions->bStdoutCapture) {
2130          m_pServer->setCommunication(QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr);                  m_pServer->setCommunication(
2131          QObject::connect(m_pServer, SIGNAL(readyReadStdout()), this, SLOT(readServerStdout()));                          QProcess::Stdout | QProcess::Stderr | QProcess::DupStderr);
2132          QObject::connect(m_pServer, SIGNAL(readyReadStderr()), this, SLOT(readServerStdout()));                  QObject::connect(m_pServer,
2133      //}                          SIGNAL(readyReadStdout()),
2134      // The unforgiveable signal communication...                          SLOT(readServerStdout()));
2135      QObject::connect(m_pServer, SIGNAL(processExited()), this, SLOT(processServerExit()));                  QObject::connect(m_pServer,
2136                            SIGNAL(readyReadStderr()),
2137                            SLOT(readServerStdout()));
2138            //      }
2139            // The unforgiveable signal communication...
2140            QObject::connect(m_pServer,
2141                    SIGNAL(processExited()),
2142                    SLOT(processServerExit()));
2143    
2144      // Build process arguments...      // Build process arguments...
2145      m_pServer->setArguments(QStringList::split(' ', m_pOptions->sServerCmdLine));      m_pServer->setArguments(QStringList::split(' ', m_pOptions->sServerCmdLine));
# Line 1620  bool qsamplerMainForm::startClient (void Line 2271  bool qsamplerMainForm::startClient (void
2271      ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);      ::lscp_client_set_timeout(m_pClient, m_pOptions->iServerTimeout);
2272      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)));
2273    
2274            // Subscribe to channel info change notifications...
2275            if (::lscp_client_subscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO) != LSCP_OK)
2276                    appendMessagesClient("lscp_client_subscribe");
2277    
2278      // We may stop scheduling around.      // We may stop scheduling around.
2279      stopSchedule();      stopSchedule();
2280    
# Line 1629  bool qsamplerMainForm::startClient (void Line 2284  bool qsamplerMainForm::startClient (void
2284      // Log success here.      // Log success here.
2285      appendMessages(tr("Client connected."));      appendMessages(tr("Client connected."));
2286    
2287            // Hard-notify instrumnet and device configuration forms,
2288            // if visible, that we're ready...
2289            if (m_pInstrumentListForm)
2290                m_pInstrumentListForm->refreshInstruments();
2291            if (m_pDeviceForm)
2292                m_pDeviceForm->refreshDevices();
2293    
2294      // Is any session pending to be loaded?      // Is any session pending to be loaded?
2295      if (!m_pOptions->sSessionFile.isEmpty()) {      if (!m_pOptions->sSessionFile.isEmpty()) {
2296          // Just load the prabably startup session...          // Just load the prabably startup session...
# Line 1663  void qsamplerMainForm::stopClient (void) Line 2325  void qsamplerMainForm::stopClient (void)
2325      // channels from the back-end server.      // channels from the back-end server.
2326      m_iDirtyCount = 0;      m_iDirtyCount = 0;
2327      closeSession(false);      closeSession(false);
2328        
2329      // Close us as a client...      // Close us as a client...
2330      lscp_client_destroy(m_pClient);          ::lscp_client_unsubscribe(m_pClient, LSCP_EVENT_CHANNEL_INFO);
2331        ::lscp_client_destroy(m_pClient);
2332      m_pClient = NULL;      m_pClient = NULL;
2333    
2334            // Hard-notify instrumnet and device configuration forms,
2335            // if visible, that we're running out...
2336            if (m_pInstrumentListForm)
2337                m_pInstrumentListForm->refreshInstruments();
2338            if (m_pDeviceForm)
2339                m_pDeviceForm->refreshDevices();
2340    
2341      // Log final here.      // Log final here.
2342      appendMessages(tr("Client disconnected."));      appendMessages(tr("Client disconnected."));
2343    

Legend:
Removed from v.176  
changed lines
  Added in v.1018

  ViewVC Help
Powered by ViewVC