changeset 340:516819f2b97b

* Add Erase tool and mode * Add icons for Normalize buttons in property boxes, and for Show Peaks * Add support for velocity in notes -- not yet reflected in display or editable in the note edit dialog, but they are imported from MIDI, played, and exported * Begin work on making pastes align pasted times (subtler than I thought)
author Chris Cannam
date Fri, 23 Nov 2007 16:48:23 +0000
parents ba30f4a3e3be
children db8fcd280234
files base/Clipboard.cpp base/Clipboard.h base/PropertyContainer.cpp base/PropertyContainer.h data/fileio/MIDIFileReader.cpp data/fileio/MIDIFileWriter.cpp data/model/Model.cpp data/model/NoteModel.h plugin/transform/FeatureExtractionModelTransformer.cpp
diffstat 9 files changed, 127 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/base/Clipboard.cpp	Thu Nov 22 14:17:19 2007 +0000
+++ b/base/Clipboard.cpp	Fri Nov 23 16:48:23 2007 +0000
@@ -21,7 +21,11 @@
     m_haveValue(false),
     m_haveDuration(false),
     m_haveLabel(true),
-    m_label(label)
+    m_label(label),
+    m_haveLevel(false),
+    m_level(0.f),
+    m_haveReferenceFrame(false),
+    m_referenceFrame(frame)
 {
 }
 
@@ -32,7 +36,11 @@
     m_value(value),
     m_haveDuration(false),
     m_haveLabel(true),
-    m_label(label)
+    m_label(label),
+    m_haveLevel(false),
+    m_level(0.f),
+    m_haveReferenceFrame(false),
+    m_referenceFrame(frame)
 {
 }
 
@@ -44,7 +52,27 @@
     m_haveDuration(true),
     m_duration(duration),
     m_haveLabel(true),
-    m_label(label)
+    m_label(label),
+    m_haveLevel(false),
+    m_level(0.f),
+    m_haveReferenceFrame(false),
+    m_referenceFrame(frame)
+{
+}
+
+Clipboard::Point::Point(long frame, float value, size_t duration, float level, QString label) :
+    m_haveFrame(true),
+    m_frame(frame),
+    m_haveValue(true),
+    m_value(value),
+    m_haveDuration(true),
+    m_duration(duration),
+    m_haveLabel(true),
+    m_label(label),
+    m_haveLevel(true),
+    m_level(level),
+    m_haveReferenceFrame(false),
+    m_referenceFrame(frame)
 {
 }
 
@@ -56,7 +84,11 @@
     m_haveDuration(point.m_haveDuration),
     m_duration(point.m_duration),
     m_haveLabel(point.m_haveLabel),
-    m_label(point.m_label)
+    m_label(point.m_label),
+    m_haveLevel(point.m_haveLevel),
+    m_level(point.m_level),
+    m_haveReferenceFrame(point.m_haveReferenceFrame),
+    m_referenceFrame(point.m_referenceFrame)
 {
 }
 
@@ -72,6 +104,10 @@
     m_duration = point.m_duration;
     m_haveLabel = point.m_haveLabel;
     m_label = point.m_label;
+    m_haveLevel = point.m_haveLevel;
+    m_level = point.m_level;
+    m_haveReferenceFrame = point.m_haveReferenceFrame;
+    m_referenceFrame = point.m_referenceFrame;
     return *this;
 }
 
@@ -123,6 +159,37 @@
     return m_label;
 }
 
+bool
+Clipboard::Point::haveLevel() const
+{
+    return m_haveLevel;
+}
+
+float
+Clipboard::Point::getLevel() const
+{
+    return m_level;
+}
+
+bool
+Clipboard::Point::haveReferenceFrame() const
+{
+    return m_haveReferenceFrame;
+}
+
+long
+Clipboard::Point::getReferenceFrame() const
+{
+    return m_referenceFrame;
+}
+
+void
+Clipboard::Point::setReferenceFrame(long f) 
+{
+    if (f != m_frame) m_haveReferenceFrame = true;
+    m_referenceFrame = f;
+}
+
 Clipboard::Clipboard() { }
 Clipboard::~Clipboard() { }
 
@@ -156,3 +223,13 @@
     m_points.push_back(point);
 }
 
+bool
+Clipboard::haveReferenceFrames() const
+{
+    for (PointList::const_iterator i = m_points.begin();
+         i != m_points.end(); ++i) {
+        if (i->haveReferenceFrame()) return true;
+    } 
+    return false;
+}
+
--- a/base/Clipboard.h	Thu Nov 22 14:17:19 2007 +0000
+++ b/base/Clipboard.h	Fri Nov 23 16:48:23 2007 +0000
@@ -28,6 +28,7 @@
         Point(long frame, QString label);
         Point(long frame, float value, QString label);
         Point(long frame, float value, size_t duration, QString label);
+        Point(long frame, float value, size_t duration, float level, QString label);
         Point(const Point &point);
         Point &operator=(const Point &point);
 
@@ -43,6 +44,13 @@
         bool haveLabel() const;
         QString getLabel() const;
 
+        bool haveLevel() const;
+        float getLevel() const;
+
+        bool haveReferenceFrame() const;
+        long getReferenceFrame() const;
+        void setReferenceFrame(long);
+
     private:
         bool m_haveFrame;
         long m_frame;
@@ -52,6 +60,10 @@
         size_t m_duration;
         bool m_haveLabel;
         QString m_label;
+        bool m_haveLevel;
+        float m_level;
+        bool m_haveReferenceFrame;
+        long m_referenceFrame;
     };
 
     Clipboard();
@@ -65,6 +77,8 @@
     void setPoints(const PointList &points);
     void addPoint(const Point &point);
 
+    bool haveReferenceFrames() const;
+
 protected:
     PointList m_points;
 };
--- a/base/PropertyContainer.cpp	Thu Nov 22 14:17:19 2007 +0000
+++ b/base/PropertyContainer.cpp	Fri Nov 23 16:48:23 2007 +0000
@@ -29,12 +29,6 @@
     return PropertyList();
 }
 
-//QString
-//PropertyContainer::getPropertyLabel(const PropertyName &) const
-//{
-//    return "";
-//}
-
 PropertyContainer::PropertyType
 PropertyContainer::getPropertyType(const PropertyName &) const
 {
@@ -42,6 +36,12 @@
 }
 
 QString
+PropertyContainer::getPropertyIconName(const PropertyName &) const
+{
+    return QString();
+}
+
+QString
 PropertyContainer::getPropertyGroupName(const PropertyName &) const
 {
     return QString();
--- a/base/PropertyContainer.h	Thu Nov 22 14:17:19 2007 +0000
+++ b/base/PropertyContainer.h	Fri Nov 23 16:48:23 2007 +0000
@@ -62,6 +62,11 @@
     virtual PropertyType getPropertyType(const PropertyName &) const;
 
     /**
+     * Return an icon for the property, if any.
+     */
+    virtual QString getPropertyIconName(const PropertyName &) const;
+
+    /**
      * If this property has something in common with other properties
      * on this container, return a name that can be used to group them
      * (in order to save screen space, for example).  e.g. "Window
--- a/data/fileio/MIDIFileReader.cpp	Thu Nov 22 14:17:19 2007 +0000
+++ b/data/fileio/MIDIFileReader.cpp	Fri Nov 23 16:48:23 2007 +0000
@@ -1021,8 +1021,10 @@
 		    QString noteLabel = tr("%1 - vel %2")
 			.arg(pitchLabel).arg(int((*i)->getVelocity()));
 
+                    float level = float((*i)->getVelocity()) / 128.f;
+
 		    Note note(startFrame, (*i)->getPitch(),
-			      endFrame - startFrame, noteLabel);
+			      endFrame - startFrame, level, noteLabel);
 
 //		    std::cerr << "Adding note " << startFrame << "," << (endFrame-startFrame) << " : " << int((*i)->getPitch()) << std::endl;
 
--- a/data/fileio/MIDIFileWriter.cpp	Thu Nov 22 14:17:19 2007 +0000
+++ b/data/fileio/MIDIFileWriter.cpp	Fri Nov 23 16:48:23 2007 +0000
@@ -369,8 +369,10 @@
         double quarters = (seconds * m_tempo) / 60.0;
         unsigned long midiTime = lrint(quarters * m_timingDivision);
 
-        // We don't support velocity in note models yet
         int velocity = 100;
+        if (i->level > 0.f && i->level <= 1.f) {
+            velocity = lrintf(i->level * 127.f);
+        }
 
         // Get the sounding time for the matching NOTE_OFF
         seconds = double(frame + duration) / double(m_model->getSampleRate());
--- a/data/model/Model.cpp	Thu Nov 22 14:17:19 2007 +0000
+++ b/data/model/Model.cpp	Fri Nov 23 16:48:23 2007 +0000
@@ -113,9 +113,8 @@
         else return frame;
     }
     size_t refFrame = m_alignment->toReference(frame);
-    //!!! this should be totally wrong, but because alignToReference and
-    // alignFromReference are the wrong way around, it's right... *sigh*
-    if (refFrame > getEndFrame()) refFrame = getEndFrame();
+    const Model *m = m_alignment->getReferenceModel();
+    if (m && refFrame > m->getEndFrame()) refFrame = m->getEndFrame();
     return refFrame;
 }
 
@@ -127,6 +126,7 @@
         else return refFrame;
     }
     size_t frame = m_alignment->fromReference(refFrame);
+    if (frame > getEndFrame()) frame = getEndFrame();
     return frame;
 }
 
--- a/data/model/NoteModel.h	Thu Nov 22 14:17:19 2007 +0000
+++ b/data/model/NoteModel.h	Fri Nov 23 16:48:23 2007 +0000
@@ -32,15 +32,16 @@
 struct Note
 {
 public:
-    Note(long _frame) : frame(_frame), value(0.0f), duration(0) { }
-    Note(long _frame, float _value, size_t _duration, QString _label) :
-	frame(_frame), value(_value), duration(_duration), label(_label) { }
+    Note(long _frame) : frame(_frame), value(0.0f), duration(0), level(1.f) { }
+    Note(long _frame, float _value, size_t _duration, float _level, QString _label) :
+	frame(_frame), value(_value), duration(_duration), level(_level), label(_label) { }
 
     int getDimensions() const { return 3; }
 
     long frame;
     float value;
     size_t duration;
+    float level;
     QString label;
 
     QString getLabel() const { return label; }
@@ -50,8 +51,8 @@
                QString extraAttributes = "") const
     {
 	stream <<
-            QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" label=\"%5\" %6/>\n")
-	    .arg(indent).arg(frame).arg(value).arg(duration).arg(label).arg(extraAttributes);
+            QString("%1<point frame=\"%2\" value=\"%3\" duration=\"%4\" level=\"%5\" label=\"%6\" %7/>\n")
+	    .arg(indent).arg(frame).arg(value).arg(duration).arg(level).arg(label).arg(extraAttributes);
     }
 
     QString toDelimitedDataString(QString delimiter, size_t sampleRate) const
@@ -59,7 +60,8 @@
         QStringList list;
         list << RealTime::frame2RealTime(frame, sampleRate).toString().c_str();
         list << QString("%1").arg(value);
-        list << QString("%1").arg(duration);
+        list << RealTime::frame2RealTime(duration, sampleRate).toString().c_str();
+        list << QString("%1").arg(level);
         if (label != "") list << label;
         return list.join(delimiter);
     }
@@ -70,6 +72,7 @@
 	    if (p1.frame != p2.frame) return p1.frame < p2.frame;
 	    if (p1.value != p2.value) return p1.value < p2.value;
 	    if (p1.duration != p2.duration) return p1.duration < p2.duration;
+            if (p1.level != p2.level) return p1.level < p2.level;
 	    return p1.label < p2.label;
 	}
     };
--- a/plugin/transform/FeatureExtractionModelTransformer.cpp	Thu Nov 22 14:17:19 2007 +0000
+++ b/plugin/transform/FeatureExtractionModelTransformer.cpp	Fri Nov 23 16:48:23 2007 +0000
@@ -495,12 +495,15 @@
         
         float velocity = 100;
         if (feature.values.size() > 2) velocity = feature.values[2];
+        if (velocity < 0) velocity = 127;
+        if (velocity > 127) velocity = 127;
 
         NoteModel *model = getOutput<NoteModel>();
         if (!model) return;
 
         model->addPoint(NoteModel::Point(frame, pitch,
                                          lrintf(duration),
+                                         velocity / 127.f,
                                          feature.label.c_str()));
 	
     } else {