/[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 119 by capela, Wed Jun 9 20:24:48 2004 UTC revision 454 by capela, Mon Mar 14 10:59:57 2005 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-2005, 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 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    
45    #include "qsamplerDeviceForm.h"
46  #include "qsamplerOptionsForm.h"  #include "qsamplerOptionsForm.h"
47    
48  #include "config.h"  #include "config.h"
49    
50    #ifdef HAVE_SIGNAL_H
51    #include <signal.h>
52    #endif
53    
54  // Timer constant stuff.  // Timer constant stuff.
55  #define QSAMPLER_TIMER_MSECS    200  #define QSAMPLER_TIMER_MSECS    200
# Line 54  Line 61 
61  #define QSAMPLER_STATUS_SESSION 3       // Current session modification state.  #define QSAMPLER_STATUS_SESSION 3       // Current session modification state.
62    
63    
64    // All winsock apps needs this.
65  #if defined(WIN32)  #if defined(WIN32)
66  static WSADATA _wsaData;  static WSADATA _wsaData;
67  #endif  #endif
68    
69    
70    //-------------------------------------------------------------------------
71    // qsamplerCustomEvent -- specialty for callback comunication.
72    
73    #define QSAMPLER_CUSTOM_EVENT   1000
74    
75    class qsamplerCustomEvent : public QCustomEvent
76    {
77    public:
78    
79        // Constructor.
80        qsamplerCustomEvent(lscp_event_t event, const char *pchData, int cchData)
81            : QCustomEvent(QSAMPLER_CUSTOM_EVENT)
82        {
83            m_event = event;
84            m_data.setLatin1(pchData, cchData);
85        }
86    
87        // Accessors.
88        lscp_event_t event() { return m_event; }
89        QString&     data()  { return m_data;  }
90    
91    private:
92    
93        // The proper event type.
94        lscp_event_t m_event;
95        // The event data as a string.
96        QString      m_data;
97    };
98    
99    
100  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
101  // qsamplerMainForm -- Main window form implementation.  // qsamplerMainForm -- Main window form implementation.
102    
# Line 68  void qsamplerMainForm::init (void) Line 107  void qsamplerMainForm::init (void)
107      m_pOptions = NULL;      m_pOptions = NULL;
108    
109      // All child forms are to be created later, not earlier than setup.      // All child forms are to be created later, not earlier than setup.
110      m_pMessages = NULL;      m_pMessages   = NULL;
111        m_pDeviceForm = NULL;
112    
113      // We'll start clean.      // We'll start clean.
114      m_iUntitled = 0;      m_iUntitled   = 0;
115      m_iDirtyCount = 0;      m_iDirtyCount = 0;
116    
117      m_pServer = NULL;      m_pServer = NULL;
# Line 82  void qsamplerMainForm::init (void) Line 122  void qsamplerMainForm::init (void)
122    
123      m_iTimerSlot = 0;      m_iTimerSlot = 0;
124    
125    #ifdef HAVE_SIGNAL_H
126            // Set to ignore any fatal "Broken pipe" signals.
127            ::signal(SIGPIPE, SIG_IGN);
128    #endif
129    
130      // Make it an MDI workspace.      // Make it an MDI workspace.
131      m_pWorkspace = new QWorkspace(this);      m_pWorkspace = new QWorkspace(this);
132      m_pWorkspace->setScrollBarsEnabled(true);      m_pWorkspace->setScrollBarsEnabled(true);
# Line 96  void qsamplerMainForm::init (void) Line 141  void qsamplerMainForm::init (void)
141      pLabel = new QLabel(tr("Connected"), this);      pLabel = new QLabel(tr("Connected"), this);
142      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
143      pLabel->setMinimumSize(pLabel->sizeHint());      pLabel->setMinimumSize(pLabel->sizeHint());
144      m_status[QSAMPLER_STATUS_CLIENT] = pLabel;      m_statusItem[QSAMPLER_STATUS_CLIENT] = pLabel;
145      statusBar()->addWidget(pLabel);      statusBar()->addWidget(pLabel);
146      // Server address.      // Server address.
147      pLabel = new QLabel(this);      pLabel = new QLabel(this);
148      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
149      m_status[QSAMPLER_STATUS_SERVER] = pLabel;      m_statusItem[QSAMPLER_STATUS_SERVER] = pLabel;
150      statusBar()->addWidget(pLabel, 1);      statusBar()->addWidget(pLabel, 1);
151      // Channel title.      // Channel title.
152      pLabel = new QLabel(this);      pLabel = new QLabel(this);
153      pLabel->setAlignment(Qt::AlignLeft);      pLabel->setAlignment(Qt::AlignLeft);
154      m_status[QSAMPLER_STATUS_CHANNEL] = pLabel;      m_statusItem[QSAMPLER_STATUS_CHANNEL] = pLabel;
155      statusBar()->addWidget(pLabel, 2);      statusBar()->addWidget(pLabel, 2);
156      // Session modification status.      // Session modification status.
157      pLabel = new QLabel(tr("MOD"), this);      pLabel = new QLabel(tr("MOD"), this);
158      pLabel->setAlignment(Qt::AlignHCenter);      pLabel->setAlignment(Qt::AlignHCenter);
159      pLabel->setMinimumSize(pLabel->sizeHint());      pLabel->setMinimumSize(pLabel->sizeHint());
160      m_status[QSAMPLER_STATUS_SESSION] = pLabel;      m_statusItem[QSAMPLER_STATUS_SESSION] = pLabel;
161      statusBar()->addWidget(pLabel);      statusBar()->addWidget(pLabel);
162    
163      // Create the recent files sub-menu.      // Create the recent files sub-menu.
# Line 131  void qsamplerMainForm::destroy (void) Line 176  void qsamplerMainForm::destroy (void)
176  {  {
177      // Do final processing anyway.      // Do final processing anyway.
178      processServerExit();      processServerExit();
179        
180      // Delete recentfiles menu.  #if defined(WIN32)
181      if (m_pRecentFilesMenu)      WSACleanup();
182          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];  
183    
184      // Finally drop any widgets around...      // Finally drop any widgets around...
185        if (m_pDeviceForm)
186            delete m_pDeviceForm;
187      if (m_pMessages)      if (m_pMessages)
188          delete m_pMessages;          delete m_pMessages;
189      if (m_pWorkspace)      if (m_pWorkspace)
190          delete m_pWorkspace;          delete m_pWorkspace;
191    
192  #if defined(WIN32)      // Delete status item labels one by one.
193      WSACleanup();      if (m_statusItem[QSAMPLER_STATUS_CLIENT])
194  #endif          delete m_statusItem[QSAMPLER_STATUS_CLIENT];
195        if (m_statusItem[QSAMPLER_STATUS_SERVER])
196            delete m_statusItem[QSAMPLER_STATUS_SERVER];
197        if (m_statusItem[QSAMPLER_STATUS_CHANNEL])
198            delete m_statusItem[QSAMPLER_STATUS_CHANNEL];
199        if (m_statusItem[QSAMPLER_STATUS_SESSION])
200            delete m_statusItem[QSAMPLER_STATUS_SESSION];
201    
202        // Delete recentfiles menu.
203        if (m_pRecentFilesMenu)
204            delete m_pRecentFilesMenu;
205  }  }
206    
207    
# Line 163  void qsamplerMainForm::setup ( qsamplerO Line 211  void qsamplerMainForm::setup ( qsamplerO
211      // We got options?      // We got options?
212      m_pOptions = pOptions;      m_pOptions = pOptions;
213    
214        // What style do we create these forms?
215        WFlags wflags = Qt::WType_TopLevel;
216        if (m_pOptions->bKeepOnTop)
217            wflags |= Qt::WStyle_Tool;
218      // Some child forms are to be created right now.      // Some child forms are to be created right now.
219      m_pMessages = new qsamplerMessages(this);      m_pMessages = new qsamplerMessages(this);
220        m_pDeviceForm = new qsamplerDeviceForm(this, 0, wflags);
221      // Set message defaults...      // Set message defaults...
222      updateMessagesFont();      updateMessagesFont();
223      updateMessagesLimit();      updateMessagesLimit();
# Line 193  void qsamplerMainForm::setup ( qsamplerO Line 246  void qsamplerMainForm::setup ( qsamplerO
246          QTextIStream istr(&sDockables);          QTextIStream istr(&sDockables);
247          istr >> *this;          istr >> *this;
248      }      }
249      // Try to restore old window positioning.      // Try to restore old window positioning and initial visibility.
250      m_pOptions->loadWidgetGeometry(this);      m_pOptions->loadWidgetGeometry(this);
251        m_pOptions->loadWidgetGeometry(m_pDeviceForm);
252    
253      // Final startup stabilization...      // Final startup stabilization...
254      updateRecentFilesMenu();      updateRecentFilesMenu();
# Line 232  bool qsamplerMainForm::queryClose (void) Line 286  bool qsamplerMainForm::queryClose (void)
286              QTextOStream ostr(&sDockables);              QTextOStream ostr(&sDockables);
287              ostr << *this;              ostr << *this;
288              m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables);              m_pOptions->settings().writeEntry("/Layout/DockWindows", sDockables);
289              // And the main windows state.              // And the children, and the main windows state,.
290                    m_pOptions->saveWidgetGeometry(m_pDeviceForm);
291              m_pOptions->saveWidgetGeometry(this);              m_pOptions->saveWidgetGeometry(this);
292                    // Close popup widgets.
293                    if (m_pDeviceForm)
294                        m_pDeviceForm->close();
295              // Stop client and/or server, gracefully.              // Stop client and/or server, gracefully.
296              stopServer();              stopServer();
297          }          }
# Line 252  void qsamplerMainForm::closeEvent ( QClo Line 310  void qsamplerMainForm::closeEvent ( QClo
310  }  }
311    
312    
313  void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  // Drag'n'drop file handler.
314    bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files )
315  {  {
316      bool bAccept = false;      bool bDecode = false;
317    
318      if (QTextDrag::canDecode(pDragEnterEvent)) {      if (QTextDrag::canDecode(pEvent)) {
319          QString sUrl;          QString sText;
320          if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient)          bDecode = QTextDrag::decode(pEvent, sText);
321              bAccept = QFileInfo(QUrl(sUrl).path()).exists();          if (bDecode) {
322                files = QStringList::split('\n', sText);
323                for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++)
324                    *iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path();
325            }
326      }      }
327    
328      pDragEnterEvent->accept(bAccept);      return bDecode;
329    }
330    
331    
332    // Window drag-n-drop event handlers.
333    void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
334    {
335            QStringList files;
336            pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files));
337  }  }
338    
339    
340  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )
341  {  {
342      if (QTextDrag::canDecode(pDropEvent)) {      QStringList files;
343          QString sUrl;  
344          if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true))      if (!decodeDragFiles(pDropEvent, files))
345              loadSessionFile(QUrl(sUrl).path());          return;
346    
347        for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) {
348                    const QString& sPath = *iter;
349                    if (qsamplerChannel::isInstrumentFile(sPath)) {
350                            // Try to create a new channel from instrument file...
351                        qsamplerChannel *pChannel = new qsamplerChannel(this);
352                        if (pChannel == NULL)
353                            return;
354                            // Start setting the instrument filename...
355                            pChannel->setInstrument(sPath, 0);
356                        // Before we show it up, may be we'll
357                        // better ask for some initial values?
358                        if (!pChannel->channelSetup(this)) {
359                            delete pChannel;
360                            return;
361                        }
362                        // Finally, give it to a new channel strip...
363                            if (!createChannelStrip(pChannel)) {
364                            delete pChannel;
365                            return;
366                            }
367                        // Make that an overall update.
368                        m_iDirtyCount++;
369                        stabilizeForm();
370                    }   // Otherwise, load an usual session file (LSCP script)...
371                    else if (closeSession(true))
372                            loadSessionFile(sPath);
373                    // Make it look responsive...:)
374                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
375            }
376    }
377    
378    
379    // Custome event handler.
380    void qsamplerMainForm::customEvent ( QCustomEvent *pCustomEvent )
381    {
382        // For the time being, just pump it to messages.
383        if (pCustomEvent->type() == QSAMPLER_CUSTOM_EVENT) {
384            qsamplerCustomEvent *pEvent = (qsamplerCustomEvent *) pCustomEvent;
385            appendMessagesColor(tr("Notify event: %1 data: %2")
386                .arg(::lscp_event_to_text(pEvent->event()))
387                .arg(pEvent->data()), "#996699");
388      }      }
389  }  }
390    
391    
392    // Context menu event handler.
393    void qsamplerMainForm::contextMenuEvent( QContextMenuEvent *pEvent )
394    {
395        stabilizeForm();
396        
397        editMenu->exec(pEvent->globalPos());
398    }
399    
400    
401  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
402  // qsamplerMainForm -- Brainless public property accessors.  // qsamplerMainForm -- Brainless public property accessors.
403    
# Line 315  bool qsamplerMainForm::newSession (void) Line 437  bool qsamplerMainForm::newSession (void)
437      if (!closeSession(true))      if (!closeSession(true))
438          return false;          return false;
439    
440            // Give us what the server has, right now...
441            updateSession();
442    
443      // Ok increment untitled count.      // Ok increment untitled count.
444      m_iUntitled++;      m_iUntitled++;
445    
# Line 428  bool qsamplerMainForm::closeSession ( bo Line 553  bool qsamplerMainForm::closeSession ( bo
553          m_pWorkspace->setUpdatesEnabled(false);          m_pWorkspace->setUpdatesEnabled(false);
554          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
555          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
556              qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
557              if (bForce && ::lscp_remove_channel(m_pClient, pChannel->channelID()) != LSCP_OK)              if (pChannelStrip) {
558                  appendMessagesClient("lscp_remove_channel");                  qsamplerChannel *pChannel = pChannelStrip->channel();
559              delete pChannel;                  if (bForce && pChannel)
560                        pChannel->removeChannel();
561                    delete pChannelStrip;
562                }
563          }          }
564          m_pWorkspace->setUpdatesEnabled(true);          m_pWorkspace->setUpdatesEnabled(true);
565          // We're now clean, for sure.          // We're now clean, for sure.
# Line 470  bool qsamplerMainForm::loadSessionFile ( Line 598  bool qsamplerMainForm::loadSessionFile (
598              if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {              if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {
599                  appendMessagesClient("lscp_client_query");                  appendMessagesClient("lscp_client_query");
600                  iErrors++;                  iErrors++;
601                    break;
602              }              }
603          }          }
604          // Try to make it snappy :)          // Try to make it snappy :)
# Line 481  bool qsamplerMainForm::loadSessionFile ( Line 610  bool qsamplerMainForm::loadSessionFile (
610    
611      // Have we any errors?      // Have we any errors?
612      if (iErrors > 0)      if (iErrors > 0)
613          appendMessagesError(tr("Some setttings could not be loaded\nfrom \"%1\" session file.\n\nSorry.").arg(sFilename));          appendMessagesError(tr("Session could not be loaded\nfrom \"%1\".\n\nSorry.").arg(sFilename));
614    
615      // Now we'll try to create the whole GUI session.          // Now we'll try to create (update) the whole GUI session.
616      int iChannels = ::lscp_get_channels(m_pClient);          updateSession();
     if (iChannels < 0) {  
         appendMessagesClient("lscp_get_channels");  
         appendMessagesError(tr("Could not get current number of channels.\n\nSorry."));  
     }  
       
     // 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);  
617    
618      // Save as default session directory.      // Save as default session directory.
619      if (m_pOptions)      if (m_pOptions)
# Line 507  bool qsamplerMainForm::loadSessionFile ( Line 624  bool qsamplerMainForm::loadSessionFile (
624      m_sFilename = sFilename;      m_sFilename = sFilename;
625      updateRecentFiles(sFilename);      updateRecentFiles(sFilename);
626      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));
627        
628        // Make that an overall update.
629      stabilizeForm();      stabilizeForm();
630      return true;      return true;
631  }  }
# Line 540  bool qsamplerMainForm::saveSessionFile ( Line 659  bool qsamplerMainForm::saveSessionFile (
659      ts << endl;      ts << endl;
660      QWidgetList wlist = m_pWorkspace->windowList();      QWidgetList wlist = m_pWorkspace->windowList();
661      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
662          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
663          int iChannelID = pChannel->channelID();          if (pChannelStrip) {
664          ts << "# " << pChannel->caption() << endl;              qsamplerChannel *pChannel = pChannelStrip->channel();
665          ts << "ADD CHANNEL" << endl;              if (pChannel) {
666          ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannelID << " " << pChannel->audioDriver() << endl;                  ts << "# Channel " << iChannel << endl;
667          ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannelID << " " << pChannel->midiDriver() << endl;                  ts << "ADD CHANNEL" << endl;
668      //  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannelID << " " << pChannel->midiPort() << endl;                  ts << "SET CHANNEL AUDIO_OUTPUT_TYPE " << iChannel << " " << pChannel->audioDriver() << endl;
669          ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannelID << " " << pChannel->midiChannel() << endl;                  ts << "SET CHANNEL MIDI_INPUT_TYPE " << iChannel << " " << pChannel->midiDriver() << endl;
670          ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannelID << endl;              //  ts << "SET CHANNEL MIDI_INPUT_PORT " << iChannel << " " << pChannel->midiPort() << endl;
671          ts << "LOAD INSTRUMENT " << pChannel->instrumentFile() << " " << pChannel->instrumentNr() << " " << iChannelID << endl;                  ts << "SET CHANNEL MIDI_INPUT_CHANNEL " << iChannel << " ";
672          ts << "SET CHANNEL VOLUME " << iChannelID << " " << pChannel->volume() << endl;                  if (pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
673          ts << endl;                      ts << "ALL";
674                    else
675                        ts << pChannel->midiChannel();
676                    ts << endl;
677                    ts << "LOAD ENGINE " << pChannel->engineName() << " " << iChannel << endl;
678                    ts << "LOAD INSTRUMENT NON_MODAL '" << pChannel->instrumentFile() << "' " << pChannel->instrumentNr() << " " << iChannel << endl;
679                    ts << "SET CHANNEL VOLUME " << iChannel << " " << pChannel->volume() << endl;
680                    ts << endl;
681                }
682            }
683          // Try to keep it snappy :)          // Try to keep it snappy :)
684          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);          QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
685      }      }
# Line 577  bool qsamplerMainForm::saveSessionFile ( Line 705  bool qsamplerMainForm::saveSessionFile (
705  }  }
706    
707    
708    // Session change receiver slot.
709    void qsamplerMainForm::sessionDirty (void)
710    {
711        // Just mark the dirty form.
712        m_iDirtyCount++;
713        // and update the form status...
714        stabilizeForm();
715    }
716    
717    
718  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
719  // qsamplerMainForm -- File Action slots.  // qsamplerMainForm -- File Action slots.
720    
# Line 623  void qsamplerMainForm::fileSaveAs (void) Line 761  void qsamplerMainForm::fileSaveAs (void)
761  }  }
762    
763    
764    // Reset the sampler instance.
765    void qsamplerMainForm::fileReset (void)
766    {
767        if (m_pClient == NULL)
768            return;
769    
770        // Ask user whether he/she want's an internal sampler reset...
771        if (QMessageBox::warning(this, tr("Warning"),
772            tr("Resetting the sampler instance will close\n"
773               "all device and channel configurations.\n\n"
774               "Please note that this operation may cause\n"
775               "temporary MIDI and Audio disruption\n\n"
776               "Do you want to reset the sampler engine now?"),
777            tr("Reset"), tr("Cancel")) > 0)
778            return;
779    
780        // Just do the reset, after closing down current session...
781        if (closeSession(true) && ::lscp_reset_sampler(m_pClient) != LSCP_OK) {
782            appendMessagesClient("lscp_reset_sampler");
783            appendMessagesError(tr("Could not reset sampler instance.\n\nSorry."));
784            return;
785        }
786    
787        // Log this.
788        appendMessages(tr("Sampler reset."));
789    
790            // Make it a new session...
791            newSession();
792    }
793    
794    
795  // Restart the client/server instance.  // Restart the client/server instance.
796  void qsamplerMainForm::fileRestart (void)  void qsamplerMainForm::fileRestart (void)
797  {  {
# Line 670  void qsamplerMainForm::editAddChannel (v Line 839  void qsamplerMainForm::editAddChannel (v
839      if (m_pClient == NULL)      if (m_pClient == NULL)
840          return;          return;
841    
842      // Create the new sampler channel.      // Just create the channel instance...
843      int iChannelID = ::lscp_add_channel(m_pClient);      qsamplerChannel *pChannel = new qsamplerChannel(this);
844      if (iChannelID < 0) {      if (pChannel == NULL)
         appendMessagesClient("lscp_add_channel");  
         appendMessagesError(tr("Could not create the new channel.\n\nSorry."));  
845          return;          return;
     }  
   
     // Log this happening.  
     appendMessages(tr("Channel %1 created.").arg(iChannelID));  
846    
847      // Just create the channel strip with given id.      // Before we show it up, may be we'll
848      createChannel(iChannelID, true);      // better ask for some initial values?
849        if (!pChannel->channelSetup(this)) {
850            delete pChannel;
851            return;
852        }
853        
854        // And give it to the strip (will own the channel instance, if successful).
855        if (!createChannelStrip(pChannel)) {
856            delete pChannel;
857            return;
858        }
859    
860      // We'll be dirty, for sure...      // Make that an overall update.
861      m_iDirtyCount++;      m_iDirtyCount++;
     // Stabilize form anyway.  
862      stabilizeForm();      stabilizeForm();
863  }  }
864    
# Line 697  void qsamplerMainForm::editRemoveChannel Line 869  void qsamplerMainForm::editRemoveChannel
869      if (m_pClient == NULL)      if (m_pClient == NULL)
870          return;          return;
871    
872      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
873        if (pChannelStrip == NULL)
874            return;
875            
876        qsamplerChannel *pChannel = pChannelStrip->channel();
877      if (pChannel == NULL)      if (pChannel == NULL)
878          return;          return;
879    
# Line 707  void qsamplerMainForm::editRemoveChannel Line 883  void qsamplerMainForm::editRemoveChannel
883              tr("About to remove channel:\n\n"              tr("About to remove channel:\n\n"
884                 "%1\n\n"                 "%1\n\n"
885                 "Are you sure?")                 "Are you sure?")
886                 .arg(pChannel->caption()),                 .arg(pChannelStrip->caption()),
887              tr("OK"), tr("Cancel")) > 0)              tr("OK"), tr("Cancel")) > 0)
888              return;              return;
889      }      }
890    
891      // Remove the existing sampler channel.      // Remove the existing sampler channel.
892      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."));  
893          return;          return;
     }  
894    
     // Log this happening.  
     appendMessages(tr("Channel %1 removed.").arg(pChannel->channelID()));  
       
895      // Just delete the channel strip.      // Just delete the channel strip.
896      delete pChannel;      delete pChannelStrip;
897        
898      // Do we auto-arrange?      // Do we auto-arrange?
899      if (m_pOptions && m_pOptions->bAutoArrange)      if (m_pOptions && m_pOptions->bAutoArrange)
900          channelsArrange();          channelsArrange();
# Line 740  void qsamplerMainForm::editSetupChannel Line 911  void qsamplerMainForm::editSetupChannel
911      if (m_pClient == NULL)      if (m_pClient == NULL)
912          return;          return;
913    
914      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
915      if (pChannel == NULL)      if (pChannelStrip == NULL)
916          return;          return;
917    
918      // Just invoque the channel strip procedure.      // Just invoque the channel strip procedure.
919      pChannel->channelSetup();      pChannelStrip->channelSetup();
920  }  }
921    
922    
# Line 755  void qsamplerMainForm::editResetChannel Line 926  void qsamplerMainForm::editResetChannel
926      if (m_pClient == NULL)      if (m_pClient == NULL)
927          return;          return;
928    
929      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
930      if (pChannel == NULL)      if (pChannelStrip == NULL)
931          return;          return;
932    
933      // Remove the existing sampler channel.      // Just invoque the channel strip procedure.
934      if (::lscp_reset_channel(m_pClient, pChannel->channelID()) != LSCP_OK) {      pChannelStrip->channelReset();
935          appendMessagesClient("lscp_reset_channel");  }
         appendMessagesError(tr("Could not reset channel.\n\nSorry."));  
         return;  
     }  
936    
     // Log this.  
     appendMessages(tr("Channel %1 reset.").arg(pChannel->channelID()));  
937    
938      // Refresh channel strip info.  // Reset all sampler channels.
939      pChannel->updateChannelInfo();  void qsamplerMainForm::editResetAllChannels (void)
940    {
941        if (m_pClient == NULL)
942            return;
943    
944        // Invoque the channel strip procedure,
945            // for all channels out there...
946        m_pWorkspace->setUpdatesEnabled(false);
947        QWidgetList wlist = m_pWorkspace->windowList();
948        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
949            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
950            if (pChannelStrip)
951                    pChannelStrip->channelReset();
952        }
953        m_pWorkspace->setUpdatesEnabled(true);
954  }  }
955    
956    
# Line 822  void qsamplerMainForm::viewMessages ( bo Line 1002  void qsamplerMainForm::viewMessages ( bo
1002  }  }
1003    
1004    
1005    // Show/hide the device configurator form.
1006    void qsamplerMainForm::viewDevices (void)
1007    {
1008        if (m_pOptions == NULL)
1009            return;
1010    
1011        if (m_pDeviceForm) {
1012            m_pOptions->saveWidgetGeometry(m_pDeviceForm);
1013                    m_pDeviceForm->setClient(m_pClient);
1014            if (m_pDeviceForm->isVisible()) {
1015                m_pDeviceForm->hide();
1016            } else {
1017                m_pDeviceForm->show();
1018                m_pDeviceForm->raise();
1019                m_pDeviceForm->setActiveWindow();
1020            }
1021        }
1022    }
1023    
1024    
1025  // Show options dialog.  // Show options dialog.
1026  void qsamplerMainForm::viewOptions (void)  void qsamplerMainForm::viewOptions (void)
1027  {  {
# Line 831  void qsamplerMainForm::viewOptions (void Line 1031  void qsamplerMainForm::viewOptions (void
1031      qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this);      qsamplerOptionsForm *pOptionsForm = new qsamplerOptionsForm(this);
1032      if (pOptionsForm) {      if (pOptionsForm) {
1033          // Check out some initial nullities(tm)...          // Check out some initial nullities(tm)...
1034          qsamplerChannelStrip *pChannel = activeChannel();          qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1035          if (m_pOptions->sDisplayFont.isEmpty() && pChannel)          if (m_pOptions->sDisplayFont.isEmpty() && pChannelStrip)
1036              m_pOptions->sDisplayFont = pChannel->displayFont().toString();              m_pOptions->sDisplayFont = pChannelStrip->displayFont().toString();
1037          if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)          if (m_pOptions->sMessagesFont.isEmpty() && m_pMessages)
1038              m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();              m_pOptions->sMessagesFont = m_pMessages->messagesFont().toString();
1039          // To track down deferred or immediate changes.          // To track down deferred or immediate changes.
# Line 843  void qsamplerMainForm::viewOptions (void Line 1043  void qsamplerMainForm::viewOptions (void
1043          bool    bOldServerStart     = m_pOptions->bServerStart;          bool    bOldServerStart     = m_pOptions->bServerStart;
1044          QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;          QString sOldServerCmdLine   = m_pOptions->sServerCmdLine;
1045          QString sOldDisplayFont     = m_pOptions->sDisplayFont;          QString sOldDisplayFont     = m_pOptions->sDisplayFont;
1046            bool    bOldDisplayEffect   = m_pOptions->bDisplayEffect;
1047          int     iOldMaxVolume       = m_pOptions->iMaxVolume;          int     iOldMaxVolume       = m_pOptions->iMaxVolume;
1048          QString sOldMessagesFont    = m_pOptions->sMessagesFont;          QString sOldMessagesFont    = m_pOptions->sMessagesFont;
1049            bool    bOldKeepOnTop       = m_pOptions->bKeepOnTop;
1050          bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;          bool    bOldStdoutCapture   = m_pOptions->bStdoutCapture;
1051          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;
1052          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
1053          bool    bOldCompletePath    = m_pOptions->bCompletePath;          bool    bOldCompletePath    = m_pOptions->bCompletePath;
1054            bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;
1055          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;
1056          // Load the current setup settings.          // Load the current setup settings.
1057          pOptionsForm->setup(m_pOptions);          pOptionsForm->setup(m_pOptions);
# Line 856  void qsamplerMainForm::viewOptions (void Line 1059  void qsamplerMainForm::viewOptions (void
1059          if (pOptionsForm->exec()) {          if (pOptionsForm->exec()) {
1060              // Warn if something will be only effective on next run.              // Warn if something will be only effective on next run.
1061              if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||              if (( bOldStdoutCapture && !m_pOptions->bStdoutCapture) ||
1062                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture)) {                  (!bOldStdoutCapture &&  m_pOptions->bStdoutCapture) ||
1063                    ( bOldKeepOnTop     && !m_pOptions->bKeepOnTop)     ||
1064                    (!bOldKeepOnTop     &&  m_pOptions->bKeepOnTop)) {
1065                  QMessageBox::information(this, tr("Information"),                  QMessageBox::information(this, tr("Information"),
1066                      tr("Some settings may be only effective\n"                      tr("Some settings may be only effective\n"
1067                         "next time you start this program."), tr("OK"));                         "next time you start this program."), tr("OK"));
# Line 867  void qsamplerMainForm::viewOptions (void Line 1072  void qsamplerMainForm::viewOptions (void
1072                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||
1073                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))
1074                  updateRecentFilesMenu();                  updateRecentFilesMenu();
1075                if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) ||
1076                    (!bOldInstrumentNames &&  m_pOptions->bInstrumentNames))
1077                    updateInstrumentNames();
1078                if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) ||
1079                    (!bOldDisplayEffect &&  m_pOptions->bDisplayEffect))
1080                    updateDisplayEffect();
1081              if (sOldDisplayFont != m_pOptions->sDisplayFont)              if (sOldDisplayFont != m_pOptions->sDisplayFont)
1082                  updateDisplayFont();                  updateDisplayFont();
1083              if (iOldMaxVolume != m_pOptions->iMaxVolume)              if (iOldMaxVolume != m_pOptions->iMaxVolume)
# Line 909  void qsamplerMainForm::channelsArrange ( Line 1120  void qsamplerMainForm::channelsArrange (
1120      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1121      int y = 0;      int y = 0;
1122      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1123          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1124      /*  if (pChannel->testWState(WState_Maximized | WState_Minimized)) {      /*  if (pChannelStrip->testWState(WState_Maximized | WState_Minimized)) {
1125              // Prevent flicker...              // Prevent flicker...
1126              pChannel->hide();              pChannelStrip->hide();
1127              pChannel->showNormal();              pChannelStrip->showNormal();
1128          }   */          }   */
1129          pChannel->adjustSize();          pChannelStrip->adjustSize();
1130          int iWidth  = m_pWorkspace->width();          int iWidth  = m_pWorkspace->width();
1131          if (iWidth < pChannel->width())          if (iWidth < pChannelStrip->width())
1132              iWidth = pChannel->width();              iWidth = pChannelStrip->width();
1133      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();      //  int iHeight = pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();
1134          int iHeight = pChannel->parentWidget()->frameGeometry().height();          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1135          pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight);          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1136          y += iHeight;          y += iHeight;
1137      }      }
1138      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
# Line 969  void qsamplerMainForm::helpAbout (void) Line 1180  void qsamplerMainForm::helpAbout (void)
1180      sText += tr("Debugging option enabled.");      sText += tr("Debugging option enabled.");
1181      sText += "</font></small><br />";      sText += "</font></small><br />";
1182  #endif  #endif
1183    #ifndef CONFIG_LIBGIG
1184        sText += "<small><font color=\"red\">";
1185        sText += tr("GIG (libgig) file support disabled.");
1186        sText += "</font></small><br />";
1187    #endif
1188    #ifndef CONFIG_INSTRUMENT_NAME
1189        sText += "<small><font color=\"red\">";
1190        sText += tr("LSCP (liblscp) instrument_name support disabled.");
1191        sText += "</font></small><br />";
1192    #endif
1193      sText += "<br />\n";      sText += "<br />\n";
1194      sText += tr("Using") + ": ";      sText += tr("Using") + ": ";
1195      sText += ::lscp_client_package();      sText += ::lscp_client_package();
# Line 996  void qsamplerMainForm::helpAbout (void) Line 1217  void qsamplerMainForm::helpAbout (void)
1217  void qsamplerMainForm::stabilizeForm (void)  void qsamplerMainForm::stabilizeForm (void)
1218  {  {
1219      // Update the main application caption...      // Update the main application caption...
1220      QString sSessioName = sessionName(m_sFilename);      QString sSessionName = sessionName(m_sFilename);
1221      if (m_iDirtyCount > 0)      if (m_iDirtyCount > 0)
1222          sSessioName += '*';          sSessionName += '*';
1223      setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessioName));      setCaption(tr(QSAMPLER_TITLE " - [%1]").arg(sSessionName));
1224    
1225      // Update the main menu state...      // Update the main menu state...
1226      qsamplerChannelStrip *pChannel = activeChannel();      qsamplerChannelStrip *pChannelStrip = activeChannelStrip();
1227      bool bHasClient  = (m_pOptions != NULL && m_pClient != NULL);      bool bHasClient  = (m_pOptions != NULL && m_pClient != NULL);
1228      bool bHasChannel = (bHasClient && pChannel != NULL);      bool bHasChannel = (bHasClient && pChannelStrip != NULL);
1229      fileNewAction->setEnabled(bHasClient);      fileNewAction->setEnabled(bHasClient);
1230      fileOpenAction->setEnabled(bHasClient);      fileOpenAction->setEnabled(bHasClient);
1231      fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);      fileSaveAction->setEnabled(bHasClient && m_iDirtyCount > 0);
1232      fileSaveAsAction->setEnabled(bHasClient);      fileSaveAsAction->setEnabled(bHasClient);
1233        fileResetAction->setEnabled(bHasClient);
1234      fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);      fileRestartAction->setEnabled(bHasClient || m_pServer == NULL);
1235      editAddChannelAction->setEnabled(bHasClient);      editAddChannelAction->setEnabled(bHasClient);
1236      editRemoveChannelAction->setEnabled(bHasChannel);      editRemoveChannelAction->setEnabled(bHasChannel);
1237      editSetupChannelAction->setEnabled(bHasChannel);      editSetupChannelAction->setEnabled(bHasChannel);
1238      editResetChannelAction->setEnabled(bHasChannel);      editResetChannelAction->setEnabled(bHasChannel);
1239      channelsArrangeAction->setEnabled(bHasChannel);      editResetAllChannelsAction->setEnabled(bHasChannel);
1240      viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible());      viewMessagesAction->setOn(m_pMessages && m_pMessages->isVisible());
1241        viewDevicesAction->setOn(m_pDeviceForm && m_pDeviceForm->isVisible());
1242        viewDevicesAction->setEnabled(bHasClient);
1243        channelsArrangeAction->setEnabled(bHasChannel);
1244    
1245      // Client/Server status...      // Client/Server status...
1246      if (bHasClient) {      if (bHasClient) {
1247          m_status[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected"));          m_statusItem[QSAMPLER_STATUS_CLIENT]->setText(tr("Connected"));
1248          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));
1249      } else {      } else {
1250          m_status[QSAMPLER_STATUS_CLIENT]->clear();          m_statusItem[QSAMPLER_STATUS_CLIENT]->clear();
1251          m_status[QSAMPLER_STATUS_SERVER]->clear();          m_statusItem[QSAMPLER_STATUS_SERVER]->clear();
1252      }      }
1253      // Channel status...      // Channel status...
1254      if (bHasChannel)      if (bHasChannel)
1255          m_status[QSAMPLER_STATUS_CHANNEL]->setText(pChannel->caption());          m_statusItem[QSAMPLER_STATUS_CHANNEL]->setText(pChannelStrip->caption());
1256      else      else
1257          m_status[QSAMPLER_STATUS_CHANNEL]->clear();          m_statusItem[QSAMPLER_STATUS_CHANNEL]->clear();
1258      // Session status...      // Session status...
1259      if (m_iDirtyCount > 0)      if (m_iDirtyCount > 0)
1260          m_status[QSAMPLER_STATUS_SESSION]->setText(tr("MOD"));          m_statusItem[QSAMPLER_STATUS_SESSION]->setText(tr("MOD"));
1261      else      else
1262          m_status[QSAMPLER_STATUS_SESSION]->clear();          m_statusItem[QSAMPLER_STATUS_SESSION]->clear();
1263    
1264      // Recent files menu.      // Recent files menu.
1265      m_pRecentFilesMenu->setEnabled(bHasClient && m_pOptions->recentFiles.count() > 0);      m_pRecentFilesMenu->setEnabled(bHasClient && m_pOptions->recentFiles.count() > 0);
# Line 1046  void qsamplerMainForm::stabilizeForm (vo Line 1271  void qsamplerMainForm::stabilizeForm (vo
1271    
1272    
1273  // Channel change receiver slot.  // Channel change receiver slot.
1274  void qsamplerMainForm::channelChanged( qsamplerChannelStrip * )  void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip )
1275  {  {
1276            // Add this strip to the changed list...
1277            if (m_changedStrips.containsRef(pChannelStrip) == 0)
1278                    m_changedStrips.append(pChannelStrip);
1279    
1280      // Just mark the dirty form.      // Just mark the dirty form.
1281      m_iDirtyCount++;      m_iDirtyCount++;
1282      // and update the form status...      // and update the form status...
# Line 1055  void qsamplerMainForm::channelChanged( q Line 1284  void qsamplerMainForm::channelChanged( q
1284  }  }
1285    
1286    
1287    // Grab and restore current sampler channels session.
1288    void qsamplerMainForm::updateSession (void)
1289    {
1290            // Retrieve the current channel list.
1291            int *piChannelIDs = ::lscp_list_channels(m_pClient);
1292            if (piChannelIDs == NULL) {
1293                    if (::lscp_client_get_errno(m_pClient)) {
1294                            appendMessagesClient("lscp_list_channels");
1295                            appendMessagesError(tr("Could not get current list of channels.\n\nSorry."));
1296                    }
1297                    return;
1298            }
1299    
1300            // Try to (re)create each channel.
1301            m_pWorkspace->setUpdatesEnabled(false);
1302            for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) {
1303                    // Check if theres already a channel strip for this one...
1304                    if (!channelStrip(piChannelIDs[iChannel]))
1305                            createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel]));
1306                    // Make it visibly responsive...
1307                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
1308            }
1309            m_pWorkspace->setUpdatesEnabled(true);
1310    }
1311    
1312    
1313  // Update the recent files list and menu.  // Update the recent files list and menu.
1314  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )
1315  {  {
# Line 1099  void qsamplerMainForm::updateRecentFiles Line 1354  void qsamplerMainForm::updateRecentFiles
1354  }  }
1355    
1356    
1357    // Force update of the channels instrument names mode.
1358    void qsamplerMainForm::updateInstrumentNames (void)
1359    {
1360        // Full channel list update...
1361        QWidgetList wlist = m_pWorkspace->windowList();
1362        if (wlist.isEmpty())
1363            return;
1364    
1365        m_pWorkspace->setUpdatesEnabled(false);
1366        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1367            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1368            if (pChannelStrip)
1369                pChannelStrip->updateInstrumentName(true);
1370        }
1371        m_pWorkspace->setUpdatesEnabled(true);
1372    }
1373    
1374    
1375  // Force update of the channels display font.  // Force update of the channels display font.
1376  void qsamplerMainForm::updateDisplayFont (void)  void qsamplerMainForm::updateDisplayFont (void)
1377  {  {
# Line 1120  void qsamplerMainForm::updateDisplayFont Line 1393  void qsamplerMainForm::updateDisplayFont
1393    
1394      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1395      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1396          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1397          pChannel->setDisplayFont(font);          if (pChannelStrip)
1398                pChannelStrip->setDisplayFont(font);
1399        }
1400        m_pWorkspace->setUpdatesEnabled(true);
1401    }
1402    
1403    
1404    // Update channel strips background effect.
1405    void qsamplerMainForm::updateDisplayEffect (void)
1406    {
1407       QPixmap pm;
1408        if (m_pOptions->bDisplayEffect)
1409            pm = QPixmap::fromMimeSource("displaybg1.png");
1410    
1411        // Full channel list update...
1412        QWidgetList wlist = m_pWorkspace->windowList();
1413        if (wlist.isEmpty())
1414            return;
1415    
1416        m_pWorkspace->setUpdatesEnabled(false);
1417        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1418            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1419            if (pChannelStrip)
1420                pChannelStrip->setDisplayBackground(pm);
1421      }      }
1422      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1423  }  }
# Line 1140  void qsamplerMainForm::updateMaxVolume ( Line 1436  void qsamplerMainForm::updateMaxVolume (
1436    
1437      m_pWorkspace->setUpdatesEnabled(false);      m_pWorkspace->setUpdatesEnabled(false);
1438      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {      for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1439          qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);          qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1440          pChannel->setMaxVolume(m_pOptions->iMaxVolume);          if (pChannelStrip)
1441                pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
1442      }      }
1443      m_pWorkspace->setUpdatesEnabled(true);      m_pWorkspace->setUpdatesEnabled(true);
1444  }  }
# Line 1240  void qsamplerMainForm::updateMessagesCap Line 1537  void qsamplerMainForm::updateMessagesCap
1537  // qsamplerMainForm -- MDI channel strip management.  // qsamplerMainForm -- MDI channel strip management.
1538    
1539  // The channel strip creation executive.  // The channel strip creation executive.
1540  void qsamplerMainForm::createChannel ( int iChannelID, bool bPrompt )  qsamplerChannelStrip *qsamplerMainForm::createChannelStrip ( qsamplerChannel *pChannel )
1541  {  {
1542      if (m_pClient == NULL)      if (m_pClient == NULL || pChannel == NULL)
1543          return;          return NULL;
1544    
1545      // Prepare for auto-arrange?      // Prepare for auto-arrange?
1546      qsamplerChannelStrip *pChannel = NULL;      qsamplerChannelStrip *pChannelStrip = NULL;
1547      int y = 0;      int y = 0;
1548      if (m_pOptions && m_pOptions->bAutoArrange) {      if (m_pOptions && m_pOptions->bAutoArrange) {
1549          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
1550          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1551              pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1552          //  y += pChannel->height() + pChannel->parentWidget()->baseSize().height();                          if (pChannelStrip) {
1553              y += pChannel->parentWidget()->frameGeometry().height();                          //  y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();
1554                                    y += pChannelStrip->parentWidget()->frameGeometry().height();
1555                            }
1556          }          }
1557      }      }
1558    
1559      // Add a new channel itema...      // Add a new channel itema...
1560      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;
1561      pChannel = new qsamplerChannelStrip(m_pWorkspace, 0, wflags);      pChannelStrip = new qsamplerChannelStrip(m_pWorkspace, 0, wflags);
1562      pChannel->setMaxVolume(m_pOptions->iMaxVolume);      if (pChannelStrip == NULL)
1563      pChannel->setup(this, iChannelID);          return NULL;
1564      // We'll need a display font.          
1565      QFont font;      // Actual channel strip setup...
1566      if (m_pOptions && font.fromString(m_pOptions->sDisplayFont))      pChannelStrip->setup(pChannel);
1567          pChannel->setDisplayFont(font);      QObject::connect(pChannelStrip, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelStripChanged(qsamplerChannelStrip *)));
1568      // Track channel setup changes.      // Set some initial aesthetic options...
1569      QObject::connect(pChannel, SIGNAL(channelChanged(qsamplerChannelStrip *)), this, SLOT(channelChanged(qsamplerChannelStrip *)));      if (m_pOptions) {
1570      // Before we show it up, may be we'll          // Background display effect...
1571      // better ask for some initial values?          pChannelStrip->setDisplayEffect(m_pOptions->bDisplayEffect);
1572      if (bPrompt)          // We'll need a display font.
1573          pChannel->channelSetup();                QFont font;
1574            if (font.fromString(m_pOptions->sDisplayFont))
1575                pChannelStrip->setDisplayFont(font);
1576            // Maximum allowed volume setting.
1577            pChannelStrip->setMaxVolume(m_pOptions->iMaxVolume);
1578        }
1579    
1580      // Now we show up us to the world.      // Now we show up us to the world.
1581      pChannel->show();      pChannelStrip->show();
1582      // Only then, we'll auto-arrange...      // Only then, we'll auto-arrange...
1583      if (m_pOptions && m_pOptions->bAutoArrange) {      if (m_pOptions && m_pOptions->bAutoArrange) {
1584          int iWidth  = m_pWorkspace->width();          int iWidth  = m_pWorkspace->width();
1585      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();      //  int iHeight = pChannel->height() + pChannel->parentWidget()->baseSize().height();
1586          int iHeight = pChannel->parentWidget()->frameGeometry().height();          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1587          pChannel->parentWidget()->setGeometry(0, y, iWidth, iHeight);          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1588      }      }
1589    
1590            // This is pretty new, so we'll watch for it closely.
1591            channelStripChanged(pChannelStrip);
1592    
1593        // Return our successful reference...
1594        return pChannelStrip;
1595  }  }
1596    
1597    
1598  // Retrieve the active channel strip.  // Retrieve the active channel strip.
1599  qsamplerChannelStrip *qsamplerMainForm::activeChannel (void)  qsamplerChannelStrip *qsamplerMainForm::activeChannelStrip (void)
1600  {  {
1601      return (qsamplerChannelStrip *) m_pWorkspace->activeWindow();      return (qsamplerChannelStrip *) m_pWorkspace->activeWindow();
1602  }  }
1603    
1604    
1605  // Retrieve a channel strip by index.  // Retrieve a channel strip by index.
1606  qsamplerChannelStrip *qsamplerMainForm::channelAt ( int iChannel )  qsamplerChannelStrip *qsamplerMainForm::channelStripAt ( int iChannel )
1607  {  {
1608      QWidgetList wlist = m_pWorkspace->windowList();      QWidgetList wlist = m_pWorkspace->windowList();
1609      if (wlist.isEmpty())      if (wlist.isEmpty())
1610          return 0;          return NULL;
1611    
1612      return (qsamplerChannelStrip *) wlist.at(iChannel);      return (qsamplerChannelStrip *) wlist.at(iChannel);
1613  }  }
1614    
1615    
1616    // Retrieve a channel strip by sampler channel id.
1617    qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID )
1618    {
1619            QWidgetList wlist = m_pWorkspace->windowList();
1620            if (wlist.isEmpty())
1621                    return NULL;
1622            
1623            for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1624                    qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1625                    if (pChannelStrip) {
1626                            qsamplerChannel *pChannel = pChannelStrip->channel();
1627                            if (pChannel && pChannel->channelID() == iChannelID)
1628                                    return pChannelStrip;
1629                    }
1630            }
1631    
1632            // Not found.
1633            return NULL;
1634    }
1635    
1636    
1637  // Construct the windows menu.  // Construct the windows menu.
1638  void qsamplerMainForm::channelsMenuAboutToShow (void)  void qsamplerMainForm::channelsMenuAboutToShow (void)
1639  {  {
# Line 1313  void qsamplerMainForm::channelsMenuAbout Line 1645  void qsamplerMainForm::channelsMenuAbout
1645      if (!wlist.isEmpty()) {      if (!wlist.isEmpty()) {
1646          channelsMenu->insertSeparator();          channelsMenu->insertSeparator();
1647          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1648              qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);              qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1649              int iItemID = channelsMenu->insertItem(pChannel->caption(), this, SLOT(channelsMenuActivated(int)));              if (pChannelStrip) {
1650              channelsMenu->setItemParameter(iItemID, iChannel);                  int iItemID = channelsMenu->insertItem(pChannelStrip->caption(), this, SLOT(channelsMenuActivated(int)));
1651              channelsMenu->setItemChecked(iItemID, activeChannel() == pChannel);                  channelsMenu->setItemParameter(iItemID, iChannel);
1652                    channelsMenu->setItemChecked(iItemID, activeChannelStrip() == pChannelStrip);
1653                }
1654          }          }
1655      }      }
1656  }  }
# Line 1325  void qsamplerMainForm::channelsMenuAbout Line 1659  void qsamplerMainForm::channelsMenuAbout
1659  // Windows menu activation slot  // Windows menu activation slot
1660  void qsamplerMainForm::channelsMenuActivated ( int iChannel )  void qsamplerMainForm::channelsMenuActivated ( int iChannel )
1661  {  {
1662      qsamplerChannelStrip *pChannel = channelAt(iChannel);      qsamplerChannelStrip *pChannelStrip = channelStripAt(iChannel);
1663      if (pChannel)      if (pChannelStrip)
1664          pChannel->showNormal();          pChannelStrip->showNormal();
1665      pChannel->setFocus();      pChannelStrip->setFocus();
1666  }  }
1667    
1668    
# Line 1368  void qsamplerMainForm::timerSlot (void) Line 1702  void qsamplerMainForm::timerSlot (void)
1702      }      }
1703            
1704          // Refresh each channel usage, on each period...          // Refresh each channel usage, on each period...
1705      if (m_pClient && m_pOptions->bAutoRefresh && m_pWorkspace->isUpdatesEnabled()) {      if (m_pClient && (m_changedStrips.count() > 0 || m_pOptions->bAutoRefresh)) {
1706          m_iTimerSlot += QSAMPLER_TIMER_MSECS;          m_iTimerSlot += QSAMPLER_TIMER_MSECS;
1707          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime)  {          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled())  {
1708              m_iTimerSlot = 0;              m_iTimerSlot = 0;
1709                // Update the channel information for each pending strip...
1710                for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first();
1711                        pChannelStrip;
1712                                                    pChannelStrip = m_changedStrips.next()) {
1713                                    // If successfull, remove from pending list...
1714                                    if (pChannelStrip->updateChannelInfo())
1715                        m_changedStrips.remove(pChannelStrip);
1716                            }
1717                // Update the channel stream usage for each strip...
1718              QWidgetList wlist = m_pWorkspace->windowList();              QWidgetList wlist = m_pWorkspace->windowList();
1719              for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {              for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1720                  qsamplerChannelStrip *pChannel = (qsamplerChannelStrip *) wlist.at(iChannel);                  qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1721                  if (pChannel->isVisible())                  if (pChannelStrip && pChannelStrip->isVisible())
1722                      pChannel->updateChannelUsage();                      pChannelStrip->updateChannelUsage();
1723              }              }
1724          }          }
1725      }      }
# Line 1462  void qsamplerMainForm::stopServer (void) Line 1805  void qsamplerMainForm::stopServer (void)
1805      // And try to stop server.      // And try to stop server.
1806      if (m_pServer) {      if (m_pServer) {
1807          appendMessages(tr("Server is stopping..."));          appendMessages(tr("Server is stopping..."));
1808          if (m_pServer->isRunning()) {          if (m_pServer->isRunning())
1809              m_pServer->tryTerminate();              m_pServer->tryTerminate();
             return;  
         }  
1810       }       }
1811    
1812        // Give it some time to terminate gracefully and stabilize...
1813        QTime t;
1814        t.start();
1815        while (t.elapsed() < QSAMPLER_TIMER_MSECS)
1816            QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
1817    
1818       // Do final processing anyway.       // Do final processing anyway.
1819       processServerExit();       processServerExit();
1820  }  }
# Line 1509  void qsamplerMainForm::processServerExit Line 1856  void qsamplerMainForm::processServerExit
1856  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1857  // qsamplerMainForm -- Client stuff.  // qsamplerMainForm -- Client stuff.
1858    
   
1859  // The LSCP client callback procedure.  // The LSCP client callback procedure.
1860  lscp_status_t qsampler_client_callback ( lscp_client_t *pClient, const char *pchBuffer, int cchBuffer, void *pvData )  lscp_status_t qsampler_client_callback ( lscp_client_t */*pClient*/, lscp_event_t event, const char *pchData, int cchData, void *pvData )
1861  {  {
1862      qsamplerMainForm *pMainForm = (qsamplerMainForm *) pvData;      qsamplerMainForm *pMainForm = (qsamplerMainForm *) pvData;
1863      if (pMainForm == NULL)      if (pMainForm == NULL)
1864          return LSCP_FAILED;          return LSCP_FAILED;
1865    
1866      char *pszBuffer = (char *) malloc(cchBuffer + 1);      // ATTN: DO NOT EVER call any GUI code here,
1867      if (pszBuffer == NULL)      // as this is run under some other thread context.
1868          return LSCP_FAILED;      // A custom event must be posted here...
1869        QApplication::postEvent(pMainForm, new qsamplerCustomEvent(event, pchData, cchData));
     memcpy(pszBuffer, pchBuffer, cchBuffer);  
     pszBuffer[cchBuffer] = (char) 0;  
     pMainForm->appendMessagesColor(pszBuffer, "#996699");  
     free(pszBuffer);  
1870    
1871      return LSCP_OK;      return LSCP_OK;
1872  }  }
# Line 1570  bool qsamplerMainForm::startClient (void Line 1912  bool qsamplerMainForm::startClient (void
1912      // Log success here.      // Log success here.
1913      appendMessages(tr("Client connected."));      appendMessages(tr("Client connected."));
1914    
1915            // Hard-notify device configuration form,
1916            // if visible, that we're ready...
1917            if (m_pDeviceForm && m_pDeviceForm->isVisible())
1918                m_pDeviceForm->setClient(m_pClient);
1919                
1920      // Is any session pending to be loaded?      // Is any session pending to be loaded?
1921      if (!m_pOptions->sSessionFile.isEmpty()) {      if (!m_pOptions->sSessionFile.isEmpty()) {
1922          // Just load the prabably startup session...          // Just load the prabably startup session...
# Line 1590  void qsamplerMainForm::stopClient (void) Line 1937  void qsamplerMainForm::stopClient (void)
1937      if (m_pClient == NULL)      if (m_pClient == NULL)
1938          return;          return;
1939    
1940            // Hard-notify device configuration form,
1941            // if visible, that we're running out...
1942            if (m_pDeviceForm && m_pDeviceForm->isVisible())
1943                m_pDeviceForm->setClient(NULL);
1944    
1945      // Log prepare here.      // Log prepare here.
1946      appendMessages(tr("Client disconnecting..."));      appendMessages(tr("Client disconnecting..."));
1947    

Legend:
Removed from v.119  
changed lines
  Added in v.454

  ViewVC Help
Powered by ViewVC