changeset 368:f1cab64363d7 warnfix_no_size_t

Merge from branch tony_integration
author Chris Cannam
date Wed, 18 Jun 2014 08:45:13 +0100
parents 1e4fa2007e61 (current diff) c32393c09304 (diff)
children b3b673d133a0 dfcc5b355f33
files framework/Document.cpp framework/MainWindowBase.cpp framework/MainWindowBase.h framework/SVFileReader.cpp
diffstat 5 files changed, 97 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/framework/Document.cpp	Tue Jun 17 17:00:26 2014 +0100
+++ b/framework/Document.cpp	Wed Jun 18 08:45:13 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 17:00:26 2014 +0100
+++ b/framework/Document.h	Wed Jun 18 08:45:13 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 17:00:26 2014 +0100
+++ b/framework/MainWindowBase.cpp	Wed Jun 18 08:45:13 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");
 
@@ -372,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
@@ -400,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
@@ -553,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);
@@ -1243,7 +1219,9 @@
 
     int rate = 0;
 
-    if (Preferences::getInstance()->getResampleOnLoad()) {
+    if (Preferences::getInstance()->getFixedSampleRate() != 0) {
+        rate = Preferences::getInstance()->getFixedSampleRate();
+    } else if (Preferences::getInstance()->getResampleOnLoad()) {
         rate = m_playSource->getSourceSampleRate();
     }
 
@@ -2552,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();
         }
@@ -2577,7 +2555,7 @@
     
     m_viewManager->setPlaybackFrame(frame);
 
-    if (frame == getMainModel()->getEndFrame() &&
+    if (frame == (int)getMainModel()->getEndFrame() &&
         m_playSource &&
         m_playSource->isPlaying() &&
         !m_viewManager->getPlayLoopMode()) {
@@ -2614,7 +2592,6 @@
     if (!layer) { ffwd(); return; }
 
     Pane *pane = m_paneStack->getCurrentPane();
-
     int frame = m_viewManager->getPlaybackFrame();
 
     int resolution = 0;
@@ -2634,7 +2611,7 @@
     
     m_viewManager->setPlaybackFrame(frame);
 
-    if (frame == getMainModel()->getEndFrame() &&
+    if (frame == (int)getMainModel()->getEndFrame() &&
         m_playSource &&
         m_playSource->isPlaying() &&
         !m_viewManager->getPlayLoopMode()) {
@@ -2659,7 +2636,7 @@
     // 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);
     }
@@ -2667,7 +2644,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();
         }
@@ -2716,7 +2693,6 @@
     if (!layer) { rewind(); return; }
 
     Pane *pane = m_paneStack->getCurrentPane();
-
     int frame = m_viewManager->getPlaybackFrame();
 
     int resolution = 0;
@@ -3214,7 +3190,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
@@ -3317,13 +3295,11 @@
     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
     if (!qgetenv("KDE_FULL_SESSION").isEmpty()) {
         args.append("exec");
--- a/framework/MainWindowBase.h	Tue Jun 17 17:00:26 2014 +0100
+++ b/framework/MainWindowBase.h	Wed Jun 18 08:45:13 2014 +0100
@@ -112,6 +112,10 @@
     /// Implementation of FrameTimer interface method
     virtual int 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 17:00:26 2014 +0100
+++ b/framework/SVFileReader.cpp	Wed Jun 18 08:45:13 2014 +0100
@@ -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();
 
-            int rate = 0;
+            int 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;