diff layer/TimeInstantLayer.cpp @ 76:45ba0b381c5d

* 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 bf306158803d
children 19bf27e4fb29
line wrap: on
line diff
--- a/layer/TimeInstantLayer.cpp	Thu Apr 06 12:12:41 2006 +0000
+++ b/layer/TimeInstantLayer.cpp	Fri Apr 07 17:50:33 2006 +0000
@@ -19,6 +19,7 @@
 #include "base/RealTime.h"
 #include "base/View.h"
 #include "base/Profiler.h"
+#include "base/Clipboard.h"
 
 #include "model/SparseOneDimensionalModel.h"
 
@@ -689,7 +690,46 @@
 
     command->finish();
 }
-  
+
+void
+TimeInstantLayer::copy(Selection s, Clipboard &to)
+{
+    SparseOneDimensionalModel::PointList points =
+	m_model->getPoints(s.getStartFrame(), s.getEndFrame());
+
+    for (SparseOneDimensionalModel::PointList::iterator i = points.begin();
+	 i != points.end(); ++i) {
+	if (s.contains(i->frame)) {
+            Clipboard::Point point(i->frame, i->label);
+            to.addPoint(point);
+        }
+    }
+}
+
+void
+TimeInstantLayer::paste(const Clipboard &from, int frameOffset)
+{
+    const Clipboard::PointList &points = from.getPoints();
+
+    SparseOneDimensionalModel::EditCommand *command =
+	new SparseOneDimensionalModel::EditCommand(m_model, tr("Paste"));
+
+    for (Clipboard::PointList::const_iterator i = points.begin();
+         i != points.end(); ++i) {
+        
+        if (!i->haveFrame()) continue;
+        size_t frame = 0;
+        if (frameOffset > 0 || -frameOffset < i->getFrame()) {
+            frame = i->getFrame() + frameOffset;
+        }
+        SparseOneDimensionalModel::Point newPoint(frame);
+        if (i->haveLabel()) newPoint.label = i->getLabel();
+        
+        command->addPoint(newPoint);
+    }
+
+    command->finish();
+}
 
 QString
 TimeInstantLayer::toXmlString(QString indent, QString extraAttributes) const