changeset 74:47fd14e29813

* Fix long-standing off-by-1 bug in WaveFileModel that was getting us the wrong values for almost all audio data when merging channels (channel == -1) * Implement cut, copy and paste * Make draw mode work properly in time value layer * Minor fixes to CSV import
author Chris Cannam
date Fri, 07 Apr 2006 17:50:33 +0000
parents e9b8b51f6326
children 163f3428bbe0
files base/Clipboard.cpp base/Clipboard.h base/Layer.h base/View.h base/ViewManager.h transform/FeatureExtractionPluginTransform.cpp transform/RealTimePluginTransform.cpp
diffstat 7 files changed, 260 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Clipboard.cpp	Fri Apr 07 17:50:33 2006 +0000
@@ -0,0 +1,158 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#include "Clipboard.h"
+
+Clipboard::Point::Point(long frame, QString label) :
+    m_haveFrame(true),
+    m_frame(frame),
+    m_haveValue(false),
+    m_haveDuration(false),
+    m_haveLabel(true),
+    m_label(label)
+{
+}
+
+Clipboard::Point::Point(long frame, float value, QString label) :
+    m_haveFrame(true),
+    m_frame(frame),
+    m_haveValue(true),
+    m_value(value),
+    m_haveDuration(false),
+    m_haveLabel(true),
+    m_label(label)
+{
+}
+
+Clipboard::Point::Point(long frame, float value, size_t duration, 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)
+{
+}
+
+Clipboard::Point::Point(const Point &point) :
+    m_haveFrame(point.m_haveFrame),
+    m_frame(point.m_frame),
+    m_haveValue(point.m_haveValue),
+    m_value(point.m_value),
+    m_haveDuration(point.m_haveDuration),
+    m_duration(point.m_duration),
+    m_haveLabel(point.m_haveLabel),
+    m_label(point.m_label)
+{
+}
+
+Clipboard::Point &
+Clipboard::Point::operator=(const Point &point)
+{
+    if (this == &point) return *this;
+    m_haveFrame = point.m_haveFrame;
+    m_frame = point.m_frame;
+    m_haveValue = point.m_haveValue;
+    m_value = point.m_value;
+    m_haveDuration = point.m_haveDuration;
+    m_duration = point.m_duration;
+    m_haveLabel = point.m_haveLabel;
+    m_label = point.m_label;
+    return *this;
+}
+
+bool
+Clipboard::Point::haveFrame() const
+{
+    return m_haveFrame;
+}
+
+long
+Clipboard::Point::getFrame() const
+{
+    return m_frame;
+}
+
+bool
+Clipboard::Point::haveValue() const
+{
+    return m_haveValue;
+}
+
+float
+Clipboard::Point::getValue() const
+{
+    return m_value;
+}
+
+bool
+Clipboard::Point::haveDuration() const
+{
+    return m_haveDuration;
+}
+
+size_t
+Clipboard::Point::getDuration() const
+{
+    return m_duration;
+}
+
+bool
+Clipboard::Point::haveLabel() const
+{
+    return m_haveLabel;
+}
+
+QString
+Clipboard::Point::getLabel() const
+{
+    return m_label;
+}
+
+Clipboard::Clipboard() { }
+Clipboard::~Clipboard() { }
+
+void
+Clipboard::clear()
+{
+    m_points.clear();
+}
+
+bool
+Clipboard::empty() const
+{
+    return m_points.empty();
+}
+
+const Clipboard::PointList &
+Clipboard::getPoints() const
+{
+    return m_points;
+}
+
+void
+Clipboard::setPoints(const PointList &pl)
+{
+    m_points = pl;
+}
+
+void
+Clipboard::addPoint(const Point &point)
+{
+    m_points.push_back(point);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/base/Clipboard.h	Fri Apr 07 17:50:33 2006 +0000
@@ -0,0 +1,72 @@
+/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */
+
+/*
+    Sonic Visualiser
+    An audio file viewer and annotation editor.
+    Centre for Digital Music, Queen Mary, University of London.
+    This file copyright 2006 Chris Cannam.
+    
+    This program is free software; you can redistribute it and/or
+    modify it under the terms of the GNU General Public License as
+    published by the Free Software Foundation; either version 2 of the
+    License, or (at your option) any later version.  See the file
+    COPYING included with this distribution for more information.
+*/
+
+#ifndef _CLIPBOARD_H_
+#define _CLIPBOARD_H_
+
+#include <QString>
+#include <vector>
+
+class Clipboard
+{
+public:
+    class Point
+    {
+    public:
+        Point(long frame, QString label);
+        Point(long frame, float value, QString label);
+        Point(long frame, float value, size_t duration, QString label);
+        Point(const Point &point);
+        Point &operator=(const Point &point);
+
+        bool haveFrame() const;
+        long getFrame() const;
+
+        bool haveValue() const;
+        float getValue() const;
+        
+        bool haveDuration() const;
+        size_t getDuration() const;
+        
+        bool haveLabel() const;
+        QString getLabel() const;
+
+    private:
+        bool m_haveFrame;
+        long m_frame;
+        bool m_haveValue;
+        float m_value;
+        bool m_haveDuration;
+        size_t m_duration;
+        bool m_haveLabel;
+        QString m_label;
+    };
+
+    Clipboard();
+    ~Clipboard();
+
+    typedef std::vector<Point> PointList;
+
+    void clear();
+    bool empty() const;
+    const PointList &getPoints() const;
+    void setPoints(const PointList &points);
+    void addPoint(const Point &point);
+
+protected:
+    PointList m_points;
+};
+
+#endif
--- a/base/Layer.h	Thu Apr 06 17:24:13 2006 +0000
+++ b/base/Layer.h	Fri Apr 07 17:50:33 2006 +0000
@@ -32,6 +32,7 @@
 class QPainter;
 class View;
 class QMouseEvent;
+class Clipboard;
 
 /**
  * The base class for visual representations of the data found in a
@@ -139,6 +140,8 @@
     virtual void resizeSelection(Selection s, Selection newSize) { }
     virtual void deleteSelection(Selection s) { }
 
+    virtual void copy(Selection s, Clipboard &to) { }
+    virtual void paste(const Clipboard &from, int frameOffset) { }
 
     // Text mode:
     //
--- a/base/View.h	Thu Apr 06 17:24:13 2006 +0000
+++ b/base/View.h	Fri Apr 07 17:50:33 2006 +0000
@@ -223,6 +223,9 @@
     virtual QString toXmlString(QString indent = "",
 				QString extraAttributes = "") const;
 
+    size_t getModelsStartFrame() const;
+    size_t getModelsEndFrame() const;
+
 signals:
     void propertyContainerAdded(PropertyContainer *pc);
     void propertyContainerRemoved(PropertyContainer *pc);
@@ -258,8 +261,6 @@
 
     typedef std::vector<Layer *> LayerList;
 
-    size_t getModelsStartFrame() const;
-    size_t getModelsEndFrame() const;
     int getModelsSampleRate() const;
     bool areLayersScrollable() const;
     LayerList getScrollableBackLayers(bool testChanged, bool &changed) const;
--- a/base/ViewManager.h	Thu Apr 06 17:24:13 2006 +0000
+++ b/base/ViewManager.h	Fri Apr 07 17:50:33 2006 +0000
@@ -23,6 +23,7 @@
 
 #include "Selection.h"
 #include "Command.h"
+#include "Clipboard.h"
 
 class AudioPlaySource;
 class Model;
@@ -74,6 +75,8 @@
      */
     Selection getContainingSelection(size_t frame, bool defaultToFollowing) const;
 
+    Clipboard &getClipboard() { return m_clipboard; }
+
     enum ToolMode {
 	NavigateMode,
 	SelectMode,
@@ -152,6 +155,8 @@
     Selection m_inProgressSelection;
     bool m_inProgressExclusive;
 
+    Clipboard m_clipboard;
+
     ToolMode m_toolMode;
 
     bool m_playLoopMode;
--- a/transform/FeatureExtractionPluginTransform.cpp	Thu Apr 06 17:24:13 2006 +0000
+++ b/transform/FeatureExtractionPluginTransform.cpp	Fri Apr 07 17:50:33 2006 +0000
@@ -73,8 +73,10 @@
     if (m_blockSize == 0) m_blockSize = 1024; //!!! todo: ask user
     if (m_stepSize == 0) m_stepSize = m_blockSize; //!!! likewise
 
-    Vamp::Plugin::OutputList outputs =
-	m_plugin->getOutputDescriptors();
+    //!!! cope with plugins that request non-power-of-2 block sizes in
+    // the frequency domain!
+
+    Vamp::Plugin::OutputList outputs = m_plugin->getOutputDescriptors();
 
     if (outputs.empty()) {
 	std::cerr << "FeatureExtractionPluginTransform: Plugin \""
@@ -344,6 +346,15 @@
         buffer[offset + got] = 0.0;
         ++got;
     }
+
+    if (m_channel == -1 && channelCount == 1 &&
+        getInput()->getChannelCount() > 1) {
+        // use mean instead of sum, as plugin input
+        int cc = getInput()->getChannelCount();
+        for (long i = 0; i < size; ++i) {
+            buffer[i] /= cc;
+        }
+    }
 }
 
 void
--- a/transform/RealTimePluginTransform.cpp	Thu Apr 06 17:24:13 2006 +0000
+++ b/transform/RealTimePluginTransform.cpp	Fri Apr 07 17:50:33 2006 +0000
@@ -136,6 +136,12 @@
 	    while (got < blockSize) {
 		buffers[0][got++] = 0.0;
 	    }
+            if (m_channel == -1 && channelCount > 1) {
+                // use mean instead of sum, as plugin input
+                for (size_t i = 0; i < got; ++i) {
+                    buffers[0][i] /= channelCount;
+                }
+            }                
 	} else {
 	    for (size_t ch = 0; ch < channelCount; ++ch) {
 		got = input->getValues