/[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 344 by capela, Tue Jan 18 13:53:04 2005 UTC revision 400 by capela, Mon Feb 21 15:02:58 2005 UTC
# 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 107  void qsamplerMainForm::init (void) Line 108  void qsamplerMainForm::init (void)
108      m_pMessages = NULL;      m_pMessages = NULL;
109    
110      // We'll start clean.      // We'll start clean.
111      m_iUntitled    = 0;      m_iUntitled   = 0;
112      m_iDirtyCount  = 0;      m_iDirtyCount = 0;
     m_iChangeCount = 0;  
113    
114      m_pServer = NULL;      m_pServer = NULL;
115      m_pClient = NULL;      m_pClient = NULL;
# Line 294  void qsamplerMainForm::closeEvent ( QClo Line 294  void qsamplerMainForm::closeEvent ( QClo
294  }  }
295    
296    
297  // Window drag-n-drop event handlers.  // Drag'n'drop file handler.
298  void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  bool qsamplerMainForm::decodeDragFiles ( const QMimeSource *pEvent, QStringList& files )
299  {  {
300      bool bAccept = false;      bool bDecode = false;
301    
302      if (QTextDrag::canDecode(pDragEnterEvent)) {      if (QTextDrag::canDecode(pEvent)) {
303          QString sUrl;          QString sText;
304          if (QTextDrag::decode(pDragEnterEvent, sUrl) && m_pClient)          bDecode = QTextDrag::decode(pEvent, sText);
305              bAccept = QFileInfo(QUrl(sUrl).path()).exists();          if (bDecode) {
306                files = QStringList::split('\n', sText);
307                for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++)
308                    *iter = (*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null);
309            }
310      }      }
311    
312      pDragEnterEvent->accept(bAccept);      return bDecode;
313    }
314    
315    
316    // Window drag-n-drop event handlers.
317    void qsamplerMainForm::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
318    {
319            QStringList files;
320            pDragEnterEvent->accept(decodeDragFiles(pDragEnterEvent, files));
321  }  }
322    
323    
324  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )  void qsamplerMainForm::dropEvent ( QDropEvent* pDropEvent )
325  {  {
326      if (QTextDrag::canDecode(pDropEvent)) {      QStringList files;
327          QString sUrl;  
328          if (QTextDrag::decode(pDropEvent, sUrl) && closeSession(true))      if (!decodeDragFiles(pDropEvent, files))
329              loadSessionFile(QUrl(sUrl).path());          return;
330      }  
331        for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) {
332                    const QString& sPath = QUrl(*iter).path();
333                    if (qsamplerChannel::isInstrumentFile(sPath)) {
334                            // Try to create a new channel from instrument file...
335                        qsamplerChannel *pChannel = new qsamplerChannel(this);
336                        if (pChannel == NULL)
337                            return;
338                            // Start setting the instrument filename...
339                            pChannel->setInstrument(sPath, 0);
340                        // Before we show it up, may be we'll
341                        // better ask for some initial values?
342                        if (!pChannel->channelSetup(this)) {
343                            delete pChannel;
344                            return;
345                        }
346                        // Finally, give it to a new channel strip...
347                            if (!createChannelStrip(pChannel)) {
348                            delete pChannel;
349                            return;
350                            }
351                        // Make that an overall update.
352                        m_iDirtyCount++;
353                        stabilizeForm();
354                    }   // Otherwise, load an usual session file (LSCP script)...
355                    else if (closeSession(true))
356                            loadSessionFile(sPath);
357                    // Make it look responsive...:)
358                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
359            }
360  }  }
361    
362    
# Line 380  bool qsamplerMainForm::newSession (void) Line 421  bool qsamplerMainForm::newSession (void)
421      if (!closeSession(true))      if (!closeSession(true))
422          return false;          return false;
423    
424            // Give us what the server has, right now...
425            updateSession();
426    
427      // Ok increment untitled count.      // Ok increment untitled count.
428      m_iUntitled++;      m_iUntitled++;
429    
# Line 538  bool qsamplerMainForm::loadSessionFile ( Line 582  bool qsamplerMainForm::loadSessionFile (
582              if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {              if (::lscp_client_query(m_pClient, sCommand.latin1()) != LSCP_OK) {
583                  appendMessagesClient("lscp_client_query");                  appendMessagesClient("lscp_client_query");
584                  iErrors++;                  iErrors++;
585                    break;
586              }              }
587          }          }
588          // Try to make it snappy :)          // Try to make it snappy :)
# Line 549  bool qsamplerMainForm::loadSessionFile ( Line 594  bool qsamplerMainForm::loadSessionFile (
594    
595      // Have we any errors?      // Have we any errors?
596      if (iErrors > 0)      if (iErrors > 0)
597          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));
598    
599      // Now we'll try to create the whole GUI session.          // Now we'll try to create (update) the whole GUI session.
600      int *piChannelIDs = ::lscp_list_channels(m_pClient);          updateSession();
     if (piChannelIDs == NULL) {  
         appendMessagesClient("lscp_list_channels");  
         appendMessagesError(tr("Could not get current list of channels.\n\nSorry."));  
     }  
       
     // Try to (re)create each channel.  
     m_pWorkspace->setUpdatesEnabled(false);  
     for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) {  
         createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel]));  
         QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);  
     }  
     m_pWorkspace->setUpdatesEnabled(true);  
601    
602      // Save as default session directory.      // Save as default session directory.
603      if (m_pOptions)      if (m_pOptions)
# Line 577  bool qsamplerMainForm::loadSessionFile ( Line 610  bool qsamplerMainForm::loadSessionFile (
610      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));      appendMessages(tr("Open session: \"%1\".").arg(sessionName(m_sFilename)));
611            
612      // Make that an overall update.      // Make that an overall update.
     m_iChangeCount++;  
613      stabilizeForm();      stabilizeForm();
614      return true;      return true;
615  }  }
# Line 729  void qsamplerMainForm::fileReset (void) Line 761  void qsamplerMainForm::fileReset (void)
761    
762      // Log this.      // Log this.
763      appendMessages(tr("Sampler reset."));      appendMessages(tr("Sampler reset."));
764    
765            // Make it a new session...
766            newSession();
767  }  }
768    
769    
# Line 799  void qsamplerMainForm::editAddChannel (v Line 834  void qsamplerMainForm::editAddChannel (v
834    
835      // Make that an overall update.      // Make that an overall update.
836      m_iDirtyCount++;      m_iDirtyCount++;
     m_iChangeCount++;  
837      stabilizeForm();      stabilizeForm();
838  }  }
839    
# Line 871  void qsamplerMainForm::editResetChannel Line 905  void qsamplerMainForm::editResetChannel
905      if (pChannelStrip == NULL)      if (pChannelStrip == NULL)
906          return;          return;
907    
908      qsamplerChannel *pChannel = pChannelStrip->channel();      // Just invoque the channel strip procedure.
909      if (pChannel == NULL)      pChannelStrip->channelReset();
         return;  
   
     // Reset the existing sampler channel.  
     pChannel->resetChannel();  
   
     // And force a deferred update.  
     m_iChangeCount++;  
910  }  }
911    
912    
# Line 959  void qsamplerMainForm::viewOptions (void Line 986  void qsamplerMainForm::viewOptions (void
986          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;          int     bOldMessagesLimit   = m_pOptions->bMessagesLimit;
987          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;          int     iOldMessagesLimitLines = m_pOptions->iMessagesLimitLines;
988          bool    bOldCompletePath    = m_pOptions->bCompletePath;          bool    bOldCompletePath    = m_pOptions->bCompletePath;
989            bool    bOldInstrumentNames = m_pOptions->bInstrumentNames;
990          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;          int     iOldMaxRecentFiles  = m_pOptions->iMaxRecentFiles;
991          // Load the current setup settings.          // Load the current setup settings.
992          pOptionsForm->setup(m_pOptions);          pOptionsForm->setup(m_pOptions);
# Line 977  void qsamplerMainForm::viewOptions (void Line 1005  void qsamplerMainForm::viewOptions (void
1005                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||                  (!bOldCompletePath &&  m_pOptions->bCompletePath) ||
1006                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))                  (iOldMaxRecentFiles != m_pOptions->iMaxRecentFiles))
1007                  updateRecentFilesMenu();                  updateRecentFilesMenu();
1008                if (( bOldInstrumentNames && !m_pOptions->bInstrumentNames) ||
1009                    (!bOldInstrumentNames &&  m_pOptions->bInstrumentNames))
1010                    updateInstrumentNames();
1011              if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) ||              if (( bOldDisplayEffect && !m_pOptions->bDisplayEffect) ||
1012                  (!bOldDisplayEffect &&  m_pOptions->bDisplayEffect))                  (!bOldDisplayEffect &&  m_pOptions->bDisplayEffect))
1013                  updateDisplayEffect();                  updateDisplayEffect();
# Line 1087  void qsamplerMainForm::helpAbout (void) Line 1118  void qsamplerMainForm::helpAbout (void)
1118      sText += tr("GIG (libgig) file support disabled.");      sText += tr("GIG (libgig) file support disabled.");
1119      sText += "</font></small><br />";      sText += "</font></small><br />";
1120  #endif  #endif
1121    #ifndef CONFIG_INSTRUMENT_NAME
1122        sText += "<small><font color=\"red\">";
1123        sText += tr("LSCP (liblscp) instrument_name support disabled.");
1124        sText += "</font></small><br />";
1125    #endif
1126      sText += "<br />\n";      sText += "<br />\n";
1127      sText += tr("Using") + ": ";      sText += tr("Using") + ": ";
1128      sText += ::lscp_client_package();      sText += ::lscp_client_package();
# Line 1165  void qsamplerMainForm::stabilizeForm (vo Line 1201  void qsamplerMainForm::stabilizeForm (vo
1201    
1202    
1203  // Channel change receiver slot.  // Channel change receiver slot.
1204  void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip * )  void qsamplerMainForm::channelStripChanged( qsamplerChannelStrip *pChannelStrip )
1205  {  {
1206      // Flag that we're update those channel strips.          // Add this strip to the changed list...
1207      m_iChangeCount++;          if (m_changedStrips.containsRef(pChannelStrip) == 0)
1208                    m_changedStrips.append(pChannelStrip);
1209    
1210      // Just mark the dirty form.      // Just mark the dirty form.
1211      m_iDirtyCount++;      m_iDirtyCount++;
1212      // and update the form status...      // and update the form status...
# Line 1176  void qsamplerMainForm::channelStripChang Line 1214  void qsamplerMainForm::channelStripChang
1214  }  }
1215    
1216    
1217    // Grab and restore current sampler channels session.
1218    void qsamplerMainForm::updateSession (void)
1219    {
1220            // Retrieve the current channel list.
1221            int *piChannelIDs = ::lscp_list_channels(m_pClient);
1222            if (piChannelIDs == NULL) {
1223                    if (::lscp_client_get_errno(m_pClient)) {
1224                            appendMessagesClient("lscp_list_channels");
1225                            appendMessagesError(tr("Could not get current list of channels.\n\nSorry."));
1226                    }
1227                    return;
1228            }
1229    
1230            // Try to (re)create each channel.
1231            m_pWorkspace->setUpdatesEnabled(false);
1232            for (int iChannel = 0; piChannelIDs[iChannel] >= 0; iChannel++) {
1233                    // Check if theres already a channel strip for this one...
1234                    if (!channelStrip(piChannelIDs[iChannel]))
1235                            createChannelStrip(new qsamplerChannel(this, piChannelIDs[iChannel]));
1236                    // Make it visibly responsive...
1237                    QApplication::eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
1238            }
1239            m_pWorkspace->setUpdatesEnabled(true);
1240    }
1241    
1242    
1243  // Update the recent files list and menu.  // Update the recent files list and menu.
1244  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )  void qsamplerMainForm::updateRecentFiles ( const QString& sFilename )
1245  {  {
# Line 1220  void qsamplerMainForm::updateRecentFiles Line 1284  void qsamplerMainForm::updateRecentFiles
1284  }  }
1285    
1286    
1287    // Force update of the channels instrument names mode.
1288    void qsamplerMainForm::updateInstrumentNames (void)
1289    {
1290        // Full channel list update...
1291        QWidgetList wlist = m_pWorkspace->windowList();
1292        if (wlist.isEmpty())
1293            return;
1294    
1295        m_pWorkspace->setUpdatesEnabled(false);
1296        for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1297            qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1298            if (pChannelStrip)
1299                pChannelStrip->updateInstrumentName(true);
1300        }
1301        m_pWorkspace->setUpdatesEnabled(true);
1302    }
1303    
1304    
1305  // Force update of the channels display font.  // Force update of the channels display font.
1306  void qsamplerMainForm::updateDisplayFont (void)  void qsamplerMainForm::updateDisplayFont (void)
1307  {  {
# Line 1397  qsamplerChannelStrip *qsamplerMainForm:: Line 1479  qsamplerChannelStrip *qsamplerMainForm::
1479          QWidgetList wlist = m_pWorkspace->windowList();          QWidgetList wlist = m_pWorkspace->windowList();
1480          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {          for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1481              pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);              pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1482          //  y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();                          if (pChannelStrip) {
1483              y += pChannelStrip->parentWidget()->frameGeometry().height();                          //  y += pChannelStrip->height() + pChannelStrip->parentWidget()->baseSize().height();
1484                                    y += pChannelStrip->parentWidget()->frameGeometry().height();
1485                            }
1486          }          }
1487      }      }
1488    
# Line 1432  qsamplerChannelStrip *qsamplerMainForm:: Line 1516  qsamplerChannelStrip *qsamplerMainForm::
1516          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();          int iHeight = pChannelStrip->parentWidget()->frameGeometry().height();
1517          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);          pChannelStrip->parentWidget()->setGeometry(0, y, iWidth, iHeight);
1518      }      }
1519        
1520            // This is pretty new, so we'll watch for it closely.
1521            channelStripChanged(pChannelStrip);
1522    
1523      // Return our successful reference...      // Return our successful reference...
1524      return pChannelStrip;      return pChannelStrip;
1525  }  }
# Line 1450  qsamplerChannelStrip *qsamplerMainForm:: Line 1537  qsamplerChannelStrip *qsamplerMainForm::
1537  {  {
1538      QWidgetList wlist = m_pWorkspace->windowList();      QWidgetList wlist = m_pWorkspace->windowList();
1539      if (wlist.isEmpty())      if (wlist.isEmpty())
1540          return 0;          return NULL;
1541    
1542      return (qsamplerChannelStrip *) wlist.at(iChannel);      return (qsamplerChannelStrip *) wlist.at(iChannel);
1543  }  }
1544    
1545    
1546    // Retrieve a channel strip by sampler channel id.
1547    qsamplerChannelStrip *qsamplerMainForm::channelStrip ( int iChannelID )
1548    {
1549            QWidgetList wlist = m_pWorkspace->windowList();
1550            if (wlist.isEmpty())
1551                    return NULL;
1552            
1553            for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1554                    qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1555                    if (pChannelStrip) {
1556                            qsamplerChannel *pChannel = pChannelStrip->channel();
1557                            if (pChannel && pChannel->channelID() == iChannelID)
1558                                    return pChannelStrip;
1559                    }
1560            }
1561    
1562            // Not found.
1563            return NULL;
1564    }
1565    
1566    
1567  // Construct the windows menu.  // Construct the windows menu.
1568  void qsamplerMainForm::channelsMenuAboutToShow (void)  void qsamplerMainForm::channelsMenuAboutToShow (void)
1569  {  {
# Line 1524  void qsamplerMainForm::timerSlot (void) Line 1632  void qsamplerMainForm::timerSlot (void)
1632      }      }
1633            
1634          // Refresh each channel usage, on each period...          // Refresh each channel usage, on each period...
1635      if (m_pClient && (m_iChangeCount > 0 || m_pOptions->bAutoRefresh)) {      if (m_pClient && (m_changedStrips.count() > 0 || m_pOptions->bAutoRefresh)) {
1636          m_iTimerSlot += QSAMPLER_TIMER_MSECS;          m_iTimerSlot += QSAMPLER_TIMER_MSECS;
1637          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled())  {          if (m_iTimerSlot >= m_pOptions->iAutoRefreshTime && m_pWorkspace->isUpdatesEnabled())  {
1638              m_iTimerSlot = 0;              m_iTimerSlot = 0;
1639              m_iChangeCount = 0;              // Update the channel information for each pending strip...
1640                for (qsamplerChannelStrip *pChannelStrip = m_changedStrips.first();
1641                        pChannelStrip;
1642                                                    pChannelStrip = m_changedStrips.next()) {
1643                                    // If successfull, remove from pending list...
1644                                    if (pChannelStrip->updateChannelInfo())
1645                        m_changedStrips.remove(pChannelStrip);
1646                            }
1647                // Update the channel stream usage for each strip...
1648              QWidgetList wlist = m_pWorkspace->windowList();              QWidgetList wlist = m_pWorkspace->windowList();
1649              for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {              for (int iChannel = 0; iChannel < (int) wlist.count(); iChannel++) {
1650                  qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);                  qsamplerChannelStrip *pChannelStrip = (qsamplerChannelStrip *) wlist.at(iChannel);
1651                  if (pChannelStrip && pChannelStrip->isVisible()) {                  if (pChannelStrip && pChannelStrip->isVisible())
1652                      // If we can't make it clean, try next time.                      pChannelStrip->updateChannelUsage();
                     if (!pChannelStrip->updateChannelUsage())  
                         m_iChangeCount++;  
                 }  
1653              }              }
1654          }          }
1655      }      }

Legend:
Removed from v.344  
changed lines
  Added in v.400

  ViewVC Help
Powered by ViewVC