diff layer/TimeInstantLayer.cpp @ 360:d58701996fae

* Update remaining editable layers to support proper realignment on copy/paste * Permit pasting when no suitable layer is current: create a new layer on paste * Add preference for showing the splash screen or not * Rename spectrogram smoothing prefs (partly following Craig's suggestions)
author Chris Cannam
date Wed, 06 Feb 2008 14:15:09 +0000
parents 020c485aa7e0
children e1a9e478b7f2
line wrap: on
line diff
--- a/layer/TimeInstantLayer.cpp	Wed Feb 06 12:49:49 2008 +0000
+++ b/layer/TimeInstantLayer.cpp	Wed Feb 06 14:15:09 2008 +0000
@@ -30,6 +30,7 @@
 #include <QPainter>
 #include <QMouseEvent>
 #include <QTextStream>
+#include <QMessageBox>
 
 #include <iostream>
 #include <cmath>
@@ -723,148 +724,36 @@
 	 i != points.end(); ++i) {
 	if (s.contains(i->frame)) {
             Clipboard::Point point(i->frame, i->label);
-
-    //!!! This fails, because simply being "on the same pane as" a
-    // particular model is not enough to give this layer the same
-    // alignment as it.  If it was generated by deriving from another
-    // layer's model, that would be... but it wasn't necessarily
-
             point.setReferenceFrame(alignToReference(v, i->frame));
-
-            std::cerr << "TimeInstantLayer::copy: frame = " << i->frame << ", reference frame = " << point.getReferenceFrame() << std::endl;
-
             to.addPoint(point);
         }
     }
 }
 
 bool
-TimeInstantLayer::clipboardAlignmentDiffers(View *v, const Clipboard &clip) const
-{
-    //!!! hoist -- all pastable layers will need this
-
-    //!!! This fails, because simply being "on the same pane as" a
-    // particular model is not enough to give this layer the same
-    // alignment as it.  If it was generated by deriving from another
-    // layer's model, that would be... but it wasn't necessarily
-
-    if (!m_model) return false;
-
-    std::cerr << "TimeInstantLayer::clipboardAlignmentDiffers" << std::endl;
-
-    for (Clipboard::PointList::const_iterator i = clip.getPoints().begin();
-         i != clip.getPoints().end(); ++i) {
-
-        // In principle, we want to know whether the aligned version
-        // of the reference frame in our model is the same as the
-        // source frame contained in the clipboard point.  However,
-        // because of rounding during alignment, that won't
-        // necessarily be the case even if the clipboard point came
-        // from our model!  What we need to check is whether, if we
-        // aligned the clipboard point's frame back to the reference
-        // using this model's alignment, we would obtain the same
-        // reference frame as that for the clipboard point.
-
-        // What if the clipboard point has no reference frame?  Then
-        // we have to treat it as having its own frame as the
-        // reference (i.e. having been copied from the reference
-        // model).
-        
-        long sourceFrame = i->getFrame();
-        long referenceFrame = sourceFrame;
-        if (i->haveReferenceFrame()) {
-            referenceFrame = i->getReferenceFrame();
-        }
-        long myMappedFrame = alignToReference(v, sourceFrame);
-
-        std::cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << std::endl;
-
-        if (myMappedFrame != referenceFrame) return true;
-    }
-
-    return false;
-}
-
-bool
 TimeInstantLayer::paste(View *v, const Clipboard &from, int frameOffset, bool)
 {
     if (!m_model) return false;
 
     const Clipboard::PointList &points = from.getPoints();
 
-    //!!!
-    
-    // Clipboard::haveReferenceFrames() will return true if any of the
-    // items in the clipboard came from an aligned, non-reference model.
-    
-    // We need to know whether these points came from our model or not
-    // -- if they did, we don't want to align them.
-
-    // If they didn't come from our model, and if reference frames are
-    // available, then we want to offer to align them.  If reference
-    // frames are unavailable but they came from the reference model,
-    // we want to offer to align them too.
-
-
-    //!!!
-
-    // Each point may have a reference frame that may differ from the
-    // point's given frame (in its source model).  If it has no
-    // reference frame, we have to assume the source model was not
-    // aligned or was the reference model: when cutting or copying
-    // points from a layer, we must always set their reference frame
-    // correctly if we are aligned.
-    // 
-    // When pasting:
-    // - if point's reference and aligned frames differ:
-    //   - if this layer is aligned:
-    //     - if point's aligned frame matches this layer's aligned version
-    //       of point's reference frame:
-    //       - we can paste at reference frame or our frame
-    //     - else
-    //       - we can paste at reference frame, result of aligning reference
-    //         frame in our model, or literal source frame
-    //   - else
-    //     - we can paste at reference (our) frame, or literal source frame
-    // - else
-    //   - if this layer is aligned:
-    //     - we can paste at reference (point's only available) frame,
-    //       or result of aligning reference frame in our model
-    //   - else
-    //     - we can only paste at reference frame
-    // 
-    // Which of these alternatives are useful?
-    //
-    // Example: we paste between two tracks that are aligned to the
-    // same reference, and the points are at 10s and 20s in the source
-    // track, corresponding to 5s and 10s in the reference but 20s and
-    // 30s in the target track.
-    // 
-    // The obvious default is to paste at 20s and 30s; if we aren't
-    // doing that, would it be better to paste at 5s and 10s or at 10s
-    // and 20s?  We probably don't ever want to do the former, do we?
-    // We either want to be literal all the way through, or aligned
-    // all the way through.
-
     bool realign = false;
 
-    if (clipboardAlignmentDiffers(v, from)) {
+    if (clipboardHasDifferentAlignment(v, from)) {
 
-        std::cerr << "Offer alignment option..." << std::endl;
+        QMessageBox::StandardButton button =
+            QMessageBox::question(v, tr("Re-align pasted instants?"),
+                                  tr("The instants you are pasting came from a layer with different source material from this one.  Do you want to re-align them in time, to match the source material for this layer?"),
+                                  QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,
+                                  QMessageBox::Yes);
 
-        QStringList options;
-        options << "Use times unchanged from the original layer";
-        options << "Re-align times to match the same points in the reference layer";
+        if (button == QMessageBox::Cancel) {
+            return false;
+        }
 
-        bool ok = false;
-
-        QString selected = ListInputDialog::getItem
-            (0, tr("Choose alignment"),
-             tr("The points you are pasting originated in a layer with different alignment from the current layer.  Would you like to re-align them when pasting?"),
-             options, 0, &ok);
-        if (!ok) return false;
-
-        if (selected == options[1]) realign = true;
+        if (button == QMessageBox::Yes) {
+            realign = true;
+        }
     }
 
     SparseOneDimensionalModel::EditCommand *command =