changeset 1134:f8604a7c4660 3.0-integration

Merge from branch "tony-2.0-integration"
author Chris Cannam
date Wed, 14 Oct 2015 10:12:14 +0100
parents 0cb263a2f52c (current diff) e994747fb9dd (diff)
children 7fb1a7199e5b 1309b66eff53
files
diffstat 7 files changed, 90 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/MIDIFileWriter.cpp	Mon Oct 12 15:06:15 2015 +0100
+++ b/data/fileio/MIDIFileWriter.cpp	Wed Oct 14 10:12:14 2015 +0100
@@ -27,9 +27,13 @@
 
 #include "base/Pitch.h"
 
+#include <QCoreApplication>
+
 #include <algorithm>
 #include <fstream>
 
+//#define DEBUG_MIDI_FILE_WRITER 1
+
 using std::ofstream;
 using std::string;
 using std::ios;
@@ -320,12 +324,9 @@
 
     MIDIEvent *event;
 
-    event = new MIDIEvent(0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT,
-                          "Exported from Sonic Visualiser");
-    m_midiComposition[track].push_back(event);
-
-    event = new MIDIEvent(0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT,
-                          "http://www.sonicvisualiser.org/");
+    event = new MIDIEvent
+        (0, MIDI_FILE_META_EVENT, MIDI_CUE_POINT,
+         ("Exported from " + qApp->applicationName()).toStdString());
     m_midiComposition[track].push_back(event);
 
     long tempoValue = long(60000000.0 / m_tempo + 0.01);
@@ -384,6 +385,10 @@
                               127); // loudest silence you can muster
 
         m_midiComposition[track].push_back(event);
+
+#ifdef DEBUG_MIDI_FILE_WRITER
+        cerr << "midiTime = " << midiTime << ", endTime = " << endTime << endl;
+#endif
     }
     
     // Now gnash through the MIDI events and turn the absolute times
@@ -404,6 +409,9 @@
         for (MIDITrack::iterator it = m_midiComposition[i].begin();
              it != m_midiComposition[i].end(); it++) {
             unsigned long deltaTime = (*it)->getTime() - lastMidiTime;
+#ifdef DEBUG_MIDI_FILE_WRITER
+            cerr << "time = " << (*it)->getTime() << ", lastMidiTime = " << lastMidiTime << ", deltaTime = " << deltaTime << endl;
+#endif
             lastMidiTime = (*it)->getTime();
             (*it)->setTime(deltaTime);
         }
--- a/data/model/FFTModel.cpp	Mon Oct 12 15:06:15 2015 +0100
+++ b/data/model/FFTModel.cpp	Wed Oct 14 10:12:14 2015 +0100
@@ -51,6 +51,10 @@
              << ") must be at least FFT size (" << m_fftSize << ")" << endl;
         throw invalid_argument("FFTModel window size must be at least FFT size");
     }
+
+    connect(model, SIGNAL(modelChanged()), this, SIGNAL(modelChanged()));
+    connect(model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
+            this, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)));
 }
 
 FFTModel::~FFTModel()
--- a/data/model/Model.h	Mon Oct 12 15:06:15 2015 +0100
+++ b/data/model/Model.h	Wed Oct 14 10:12:14 2015 +0100
@@ -121,7 +121,8 @@
      * through it an estimated percentage value showing how far
      * through the background operation it thinks it is (for progress
      * reporting).  If it has no way to calculate progress, it may
-     * return the special value COMPLETION_UNKNOWN.
+     * return the special value COMPLETION_UNKNOWN.  See also
+     * getCompletion().
      */
     virtual bool isReady(int *completion = 0) const {
 	bool ok = isOK();
--- a/data/model/WritableWaveFileModel.cpp	Mon Oct 12 15:06:15 2015 +0100
+++ b/data/model/WritableWaveFileModel.cpp	Wed Oct 14 10:12:14 2015 +0100
@@ -32,6 +32,8 @@
 
 using namespace std;
 
+const int WritableWaveFileModel::PROPORTION_UNKNOWN = -1;
+
 //#define DEBUG_WRITABLE_WAVE_FILE_MODEL 1
 
 WritableWaveFileModel::WritableWaveFileModel(sv_samplerate_t sampleRate,
@@ -44,7 +46,7 @@
     m_channels(channels),
     m_frameCount(0),
     m_startFrame(0),
-    m_completion(0)
+    m_proportion(PROPORTION_UNKNOWN)
 {
     if (path.isEmpty()) {
         try {
@@ -153,17 +155,30 @@
 bool
 WritableWaveFileModel::isReady(int *completion) const
 {
-    if (completion) *completion = m_completion;
-    return (m_completion == 100);
+    int c = getCompletion();
+    if (completion) *completion = c;
+    if (!isOK()) return false;
+    return (c == 100);
 }
 
 void
-WritableWaveFileModel::setCompletion(int completion)
+WritableWaveFileModel::setWriteProportion(int proportion)
 {
-    m_completion = completion;
-    if (completion == 100) {
-        if (m_reader) m_reader->updateDone();
-    }
+    m_proportion = proportion;
+}
+
+int
+WritableWaveFileModel::getWriteProportion() const
+{
+    return m_proportion;
+}
+
+void
+WritableWaveFileModel::writeComplete()
+{
+    if (m_reader) m_reader->updateDone();
+    m_proportion = 100;
+    emit modelChanged();
 }
 
 sv_frame_t
--- a/data/model/WritableWaveFileModel.h	Mon Oct 12 15:06:15 2015 +0100
+++ b/data/model/WritableWaveFileModel.h	Wed Oct 14 10:12:14 2015 +0100
@@ -33,17 +33,51 @@
 
     /**
      * Call addSamples to append a block of samples to the end of the
-     * file.  Caller should also call setCompletion to update the
-     * progress of this file, if it has a known end point, and should
-     * call setCompletion(100) when the file has been written.
+     * file.  Caller should also call setWriteProportion() to update
+     * the progress of this file, if it has a known end point, and
+     * should call writeComplete() when the file has been written.
      */
     virtual bool addSamples(float **samples, sv_frame_t count);
+
+    /**
+     * Set the proportion of the file which has been written so far,
+     * as a percentage. This may be used to indicate progress.
+     *
+     * Note that this differs from the "completion" percentage
+     * reported through isReady()/getCompletion(). That percentage is
+     * updated when "internal processing has advanced... but the model
+     * has not changed externally", i.e. it reports progress in
+     * calculating the initial state of a model. In contrast, an
+     * update to setWriteProportion corresponds to a change in the
+     * externally visible state of the model (i.e. it contains more
+     * data than before).
+     */
+    void setWriteProportion(int proportion);
+
+    /**
+     * Indicate that writing is complete. You should call this even if
+     * you have never called setWriteProportion().
+     */
+    void writeComplete();
+
+    static const int PROPORTION_UNKNOWN;
+    
+    /**
+     * Get the proportion of the file which has been written so far,
+     * as a percentage. Return PROPORTION_UNKNOWN if unknown.
+     */
+    int getWriteProportion() const;
     
     bool isOK() const;
     bool isReady(int *) const;
-
-    virtual void setCompletion(int completion); // percentage
-    virtual int getCompletion() const { return m_completion; }
+    
+    /**
+     * Return the generation completion percentage of this model. This
+     * is always 100, because the model is always in a complete state
+     * -- it just contains varying amounts of data depending on how
+     * much has been written.
+     */
+    virtual int getCompletion() const { return 100; }
 
     const ZoomConstraint *getZoomConstraint() const {
         static PowerOfSqrtTwoZoomConstraint zc;
@@ -101,7 +135,7 @@
     int m_channels;
     sv_frame_t m_frameCount;
     sv_frame_t m_startFrame;
-    int m_completion;
+    int m_proportion;
 };
 
 #endif
--- a/transform/FeatureWriter.h	Mon Oct 12 15:06:15 2015 +0100
+++ b/transform/FeatureWriter.h	Wed Oct 14 10:12:14 2015 +0100
@@ -42,9 +42,11 @@
     virtual string getDescription() const = 0;
 
     struct Parameter { // parameter of the writer, not the plugin
+        Parameter() : hasArg(false), mandatory(false) { }
         string name;
         string description;
         bool hasArg;
+        bool mandatory;
     };
     typedef vector<Parameter> ParameterList;
     virtual ParameterList getSupportedParameters() const {
--- a/transform/RealTimeEffectModelTransformer.cpp	Mon Oct 12 15:06:15 2015 +0100
+++ b/transform/RealTimeEffectModelTransformer.cpp	Wed Oct 14 10:12:14 2015 +0100
@@ -282,8 +282,10 @@
         }
 
 	if (blockFrame == contextStart || completion > prevCompletion) {
+            // This setCompletion is probably misusing the completion
+            // terminology, just as it was for WritableWaveFileModel
 	    if (stvm) stvm->setCompletion(completion);
-	    if (wwfm) wwfm->setCompletion(completion);
+	    if (wwfm) wwfm->setWriteProportion(completion);
 	    prevCompletion = completion;
 	}
         
@@ -293,6 +295,6 @@
     if (m_abandoned) return;
     
     if (stvm) stvm->setCompletion(100);
-    if (wwfm) wwfm->setCompletion(100);
+    if (wwfm) wwfm->writeComplete();
 }