changeset 365:c32393c09304 tony_integration

Merge from branch "tonioni"
author Chris Cannam
date Tue, 17 Jun 2014 13:17:26 +0100
parents 8b631ce73b1c (current diff) f5c914661f6f (diff)
children f1cab64363d7
files
diffstat 5 files changed, 106 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/framework/Document.cpp	Tue Jun 17 13:16:38 2014 +0100
+++ b/framework/Document.cpp	Tue Jun 17 13:17:26 2014 +0100
@@ -275,24 +275,33 @@
         }
         vector<Layer *> layers = m_doc->createLayersForDerivedModels
             (models, names);
-        m_handler->layersCreated(m_primary, layers);
+        m_handler->layersCreated(this, m_primary, layers);
         delete this;
     }
 
     void
     noMoreModelsAvailable() {
         std::cerr << "AdditionalModelConverter::noMoreModelsAvailable" << std::endl;
-        m_handler->layersCreated(m_primary, vector<Layer *>());
+        m_handler->layersCreated(this, m_primary, vector<Layer *>());
         delete this;
     }
 
+    void cancel() {
+        foreach (Layer *layer, m_primary) {
+            Model *model = layer->getModel();
+            if (model) {
+                model->abandon();
+            }
+        }
+    }
+
 private:
     Document *m_doc;
     vector<Layer *> m_primary;
     Document::LayerCreationHandler *m_handler; //!!! how to handle destruction of this?
 };
 
-void
+Document::LayerCreationAsyncHandle
 Document::createDerivedLayersAsync(const Transforms &transforms,
                                    const ModelTransformer::Input &input,
                                    LayerCreationHandler *handler)
@@ -318,10 +327,21 @@
     if (newModels.empty()) {
         //!!! This identifier may be wrong!
         emit modelGenerationFailed(transforms[0].getIdentifier(), message);
+        //!!! what to do with amc?
     } else if (message != "") {
         //!!! This identifier may be wrong!
         emit modelGenerationWarning(transforms[0].getIdentifier(), message);
+        //!!! what to do with amc?
     }
+
+    return amc;
+}
+
+void
+Document::cancelAsyncLayerCreation(Document::LayerCreationAsyncHandle h)
+{
+    AdditionalModelConverter *conv = static_cast<AdditionalModelConverter *>(h);
+    conv->cancel();
 }
 
 vector<Layer *>
--- a/framework/Document.h	Tue Jun 17 13:16:38 2014 +0100
+++ b/framework/Document.h	Tue Jun 17 13:17:26 2014 +0100
@@ -128,6 +128,8 @@
     std::vector<Layer *> createDerivedLayers(const Transforms &,
                                              const ModelTransformer::Input &);
 
+    typedef void *LayerCreationAsyncHandle;
+
     class LayerCreationHandler {
     public:
         virtual ~LayerCreationHandler() { }
@@ -137,9 +139,12 @@
          * models, listed in the same order as the input models. The
          * additional layers vector contains any layers (from all
          * models) that were returned separately at the end of
-         * processing.
+         * processing. The handle indicates which async process this
+         * callback was initiated by. It must not be used again after
+         * this function returns.
          */
-        virtual void layersCreated(std::vector<Layer *> primary,
+        virtual void layersCreated(LayerCreationAsyncHandle handle,
+                                   std::vector<Layer *> primary,
                                    std::vector<Layer *> additional) = 0;
     };
 
@@ -148,11 +153,21 @@
      * identical apart from the output (i.e. must use the same plugin
      * and configuration). This method returns after initialising the
      * transformer process, and the layers are returned through a
-     * subsequent call to the provided handler (which must be non-null).
+     * subsequent call to the provided handler (which must be
+     * non-null). The handle returned will be passed through to the
+     * handler callback, and may be also used for cancelling the task.
      */
-    void createDerivedLayersAsync(const Transforms &,
-                                  const ModelTransformer::Input &,
-                                  LayerCreationHandler *handler);
+    LayerCreationAsyncHandle createDerivedLayersAsync(const Transforms &,
+                                                      const ModelTransformer::Input &,
+                                                      LayerCreationHandler *handler);
+
+    /**
+     * Indicate that the async layer creation task associated with the
+     * given handle should be cancelled. There is no guarantee about
+     * what this will mean, and the handler callback may still be
+     * called.
+     */
+    void cancelAsyncLayerCreation(LayerCreationAsyncHandle handle);
 
     /**
      * Delete the given layer, and also its associated model if no
--- a/framework/MainWindowBase.cpp	Tue Jun 17 13:16:38 2014 +0100
+++ b/framework/MainWindowBase.cpp	Tue Jun 17 13:17:26 2014 +0100
@@ -152,7 +152,9 @@
     m_openingAudioFile(false),
     m_abandoning(false),
     m_labeller(0),
-    m_lastPlayStatusSec(0)
+    m_lastPlayStatusSec(0),
+    m_initialDarkBackground(false),
+    m_defaultFfwdRwdStep(2, 0)
 {
     Profiler profiler("MainWindowBase::MainWindowBase");
 
@@ -281,7 +283,11 @@
 }
 
 void
-MainWindowBase::finaliseMenu(QMenu *menu)
+MainWindowBase::finaliseMenu(QMenu *
+#ifdef Q_OS_MAC
+                             menu
+#endif
+    )
 {
 #ifdef Q_OS_MAC
     // See https://bugreports.qt-project.org/browse/QTBUG-38256 and
@@ -368,26 +374,8 @@
 MainWindowBase::getOpenFileName(FileFinder::FileType type)
 {
     FileFinder *ff = FileFinder::getInstance();
-    switch (type) {
-    case FileFinder::SessionFile:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::AudioFile:
-        return ff->getOpenFileName(type, m_audioFile);
-    case FileFinder::LayerFile:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::LayerFileNoMidi:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::LayerFileNonSV:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::LayerFileNoMidiNonSV:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::SessionOrAudioFile:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::ImageFile:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::CSVFile:
-        return ff->getOpenFileName(type, m_sessionFile);
-    case FileFinder::AnyFile:
+
+    if (type == FileFinder::AnyFile) {
         if (getMainModel() != 0 &&
             m_paneStack != 0 &&
             m_paneStack->getCurrentPane() != 0) { // can import a layer
@@ -396,37 +384,28 @@
             return ff->getOpenFileName(FileFinder::SessionOrAudioFile,
                                        m_sessionFile);
         }
+    }        
+
+    QString lastPath = m_sessionFile;
+
+    if (type == FileFinder::AudioFile) {
+        lastPath = m_audioFile;
     }
-    return "";
+
+    return ff->getOpenFileName(type, lastPath);
 }
 
 QString
 MainWindowBase::getSaveFileName(FileFinder::FileType type)
 {
+    QString lastPath = m_sessionFile;
+
+    if (type == FileFinder::AudioFile) {
+        lastPath = m_audioFile;
+    }
+
     FileFinder *ff = FileFinder::getInstance();
-    switch (type) {
-    case FileFinder::SessionFile:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::AudioFile:
-        return ff->getSaveFileName(type, m_audioFile);
-    case FileFinder::LayerFile:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::LayerFileNoMidi:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::LayerFileNonSV:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::LayerFileNoMidiNonSV:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::SessionOrAudioFile:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::ImageFile:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::CSVFile:
-        return ff->getSaveFileName(type, m_sessionFile);
-    case FileFinder::AnyFile:
-        return ff->getSaveFileName(type, m_sessionFile);
-    }
-    return "";
+    return ff->getSaveFileName(type, lastPath);
 }
 
 void
@@ -549,6 +528,7 @@
     emit canClearSelection(haveSelection);
     emit canEditSelection(haveSelection && haveCurrentEditableLayer);
     emit canSave(m_sessionFile != "" && m_documentModified);
+    emit canSaveAs(haveMainModel);
     emit canSelectPreviousPane(havePrevPane);
     emit canSelectNextPane(haveNextPane);
     emit canSelectPreviousLayer(havePrevLayer);
@@ -822,7 +802,7 @@
         long offset = 0;
         if (firstEventFrame < 0) {
             offset = (long)pos - firstEventFrame;
-        } else if (firstEventFrame < pos) {
+        } else if ((unsigned long)firstEventFrame < pos) {
             offset = pos - (unsigned long)firstEventFrame;
         } else {
             offset = -((unsigned long)firstEventFrame - pos);
@@ -1239,7 +1219,9 @@
 
     size_t rate = 0;
 
-    if (Preferences::getInstance()->getResampleOnLoad()) {
+    if (Preferences::getInstance()->getFixedSampleRate() != 0) {
+        rate = Preferences::getInstance()->getFixedSampleRate();
+    } else if (Preferences::getInstance()->getResampleOnLoad()) {
         rate = m_playSource->getSourceSampleRate();
     }
 
@@ -1848,7 +1830,6 @@
 
     QXmlInputSource *inputSource = 0;
     QFile *file = 0;
-    bool isTemplate = false;
 
     file = new QFile(source.getLocalFilename());
     inputSource = new QXmlInputSource(file);
@@ -2549,7 +2530,7 @@
     if (!layer) {
 
         frame = RealTime::realTime2Frame
-            (RealTime::frame2RealTime(frame, sr) + RealTime(2, 0), sr);
+            (RealTime::frame2RealTime(frame, sr) + m_defaultFfwdRwdStep, sr);
         if (frame > int(getMainModel()->getEndFrame())) {
             frame = getMainModel()->getEndFrame();
         }
@@ -2574,7 +2555,7 @@
     
     m_viewManager->setPlaybackFrame(frame);
 
-    if (frame == getMainModel()->getEndFrame() &&
+    if (frame == (int)getMainModel()->getEndFrame() &&
         m_playSource &&
         m_playSource->isPlaying() &&
         !m_viewManager->getPlayLoopMode()) {
@@ -2611,8 +2592,6 @@
     if (!layer) { ffwd(); return; }
 
     Pane *pane = m_paneStack->getCurrentPane();
-    size_t sr = getMainModel()->getSampleRate();
-
     int frame = m_viewManager->getPlaybackFrame();
 
     size_t resolution = 0;
@@ -2632,7 +2611,7 @@
     
     m_viewManager->setPlaybackFrame(frame);
 
-    if (frame == getMainModel()->getEndFrame() &&
+    if (frame == (int)getMainModel()->getEndFrame() &&
         m_playSource &&
         m_playSource->isPlaying() &&
         !m_viewManager->getPlayLoopMode()) {
@@ -2649,15 +2628,16 @@
     if (frame > 0) --frame;
 
     Pane *pane = m_paneStack->getCurrentPane();
+    size_t sr = getMainModel()->getSampleRate();
+
     Layer *layer = getSnapLayer();
-    size_t sr = getMainModel()->getSampleRate();
     
     // when rewinding during playback, we want to allow a period
     // following a rewind target point at which the rewind will go to
     // the prior point instead of the immediately neighbouring one
     if (m_playSource && m_playSource->isPlaying()) {
         RealTime ct = RealTime::frame2RealTime(frame, sr);
-        ct = ct - RealTime::fromSeconds(0.25);
+        ct = ct - RealTime::fromSeconds(0.15);
         if (ct < RealTime::zeroTime) ct = RealTime::zeroTime;
         frame = RealTime::realTime2Frame(ct, sr);
     }
@@ -2665,7 +2645,7 @@
     if (!layer) {
         
         frame = RealTime::realTime2Frame
-            (RealTime::frame2RealTime(frame, sr) - RealTime(2, 0), sr);
+            (RealTime::frame2RealTime(frame, sr) - m_defaultFfwdRwdStep, sr);
         if (frame < int(getMainModel()->getStartFrame())) {
             frame = getMainModel()->getStartFrame();
         }
@@ -2714,8 +2694,6 @@
     if (!layer) { rewind(); return; }
 
     Pane *pane = m_paneStack->getCurrentPane();
-    size_t sr = getMainModel()->getSampleRate();
-
     int frame = m_viewManager->getPlaybackFrame();
 
     size_t resolution = 0;
@@ -3213,7 +3191,9 @@
 //    SVDEBUG << "MainWindowBase::mainModelChanged(" << model << ")" << endl;
     updateDescriptionLabel();
     if (model) m_viewManager->setMainModelSampleRate(model->getSampleRate());
-    if (model && !m_playTarget && m_audioOutput) createPlayTarget();
+    if (model && !m_playTarget && m_audioOutput) {
+        createPlayTarget();
+    }
 }
 
 void
@@ -3316,15 +3296,12 @@
     process->start("open", args);
 #else
 #ifdef Q_OS_WIN32
-
-	QString pf(getenv("ProgramFiles"));
-	QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
-
-	args.append(url);
-	process->start(command, args);
-
+    QString pf(getenv("ProgramFiles"));
+    QString command = pf + QString("\\Internet Explorer\\IEXPLORE.EXE");
+
+    args.append(url);
+    process->start(command, args);
 #else
-#ifdef Q_WS_X11
     if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
         args.append("exec");
         args.append(url);
@@ -3338,7 +3315,6 @@
     }
 #endif
 #endif
-#endif
 }
 
     
--- a/framework/MainWindowBase.h	Tue Jun 17 13:16:38 2014 +0100
+++ b/framework/MainWindowBase.h	Tue Jun 17 13:17:26 2014 +0100
@@ -112,6 +112,10 @@
     /// Implementation of FrameTimer interface method
     virtual unsigned long getFrame() const;
 
+    void setDefaultFfwdRwdStep(RealTime step) {
+        m_defaultFfwdRwdStep = step;
+    }
+
 signals:
     // Used to toggle the availability of menu actions
     void canAddPane(bool);
@@ -152,6 +156,7 @@
     void canSelectPreviousLayer(bool);
     void canSelectNextLayer(bool);
     void canSave(bool);
+    void canSaveAs(bool);
     void hideSplash();
     void sessionLoaded();
     void audioFileLoaded();
@@ -331,6 +336,8 @@
 
     bool                     m_initialDarkBackground;
 
+    RealTime                 m_defaultFfwdRwdStep;
+
     WaveFileModel *getMainModel();
     const WaveFileModel *getMainModel() const;
     void createDocument();
--- a/framework/SVFileReader.cpp	Tue Jun 17 13:16:38 2014 +0100
+++ b/framework/SVFileReader.cpp	Tue Jun 17 13:17:26 2014 +0100
@@ -300,7 +300,7 @@
     } else if (name == "derivation") {
 
         if (!m_currentDerivedModel) {
-            if (m_currentDerivedModel < 0) {
+            if (m_currentDerivedModelId < 0) {
                 cerr << "WARNING: SV-XML: Bad derivation output model id "
                           << m_currentDerivedModelId << endl;
             } else if (haveModel(m_currentDerivedModelId)) {
@@ -448,7 +448,7 @@
     READ_MANDATORY(int, sampleRate, toInt);
 
     QString type = attributes.value("type").trimmed();
-    bool mainModel = (attributes.value("mainModel").trimmed() == "true");
+    bool isMainModel = (attributes.value("mainModel").trimmed() == "true");
 
     if (type == "wavefile") {
 	
@@ -473,10 +473,13 @@
 
             file.waitForData();
 
-            size_t rate = 0;
+            size_t rate = sampleRate;
 
-            if (!mainModel &&
-                Preferences::getInstance()->getResampleOnLoad()) {
+            if (Preferences::getInstance()->getFixedSampleRate() != 0) {
+                rate = Preferences::getInstance()->getFixedSampleRate();
+            } else if (rate == 0 &&
+                       !isMainModel &&
+                       Preferences::getInstance()->getResampleOnLoad()) {
                 WaveFileModel *mm = m_document->getMainModel();
                 if (mm) rate = mm->getSampleRate();
             }
@@ -492,7 +495,7 @@
 
         model->setObjectName(name);
 	m_models[id] = model;
-	if (mainModel) {
+	if (isMainModel) {
 	    m_document->setMainModel(model);
 	    m_addedModels.insert(model);
 	}
@@ -1150,7 +1153,7 @@
 
 	for (QStringList::iterator i = data.begin(); i != data.end(); ++i) {
 
-	    if (values.size() == dtdm->getHeight()) {
+	    if (values.size() == (int)dtdm->getHeight()) {
 		if (!warned) {
 		    cerr << "WARNING: SV-XML: Too many y-bins in 3-D dataset row "
 			      << m_rowNumber << endl;