comparison layer/Layer.cpp @ 373:0895517bb2d1 1.2-stable

* merge from trunk (1.2 ended up being tracked from trunk, but we may want this branch for fixes later)
author Chris Cannam
date Wed, 27 Feb 2008 10:32:45 +0000
parents 4f4f38a11cd2
children
comparison
equal deleted inserted replaced
337:813170c57b13 373:0895517bb2d1
66 { 66 {
67 return LayerFactory::getInstance()->getLayerIconName 67 return LayerFactory::getInstance()->getLayerIconName
68 (LayerFactory::getInstance()->getLayerType(this)); 68 (LayerFactory::getInstance()->getLayerType(this));
69 } 69 }
70 70
71 void
72 Layer::setPresentationName(QString name)
73 {
74 m_presentationName = name;
75 }
76
71 QString 77 QString
72 Layer::getLayerPresentationName() const 78 Layer::getLayerPresentationName() const
73 { 79 {
74 // QString layerName = objectName(); 80 if (m_presentationName != "") return m_presentationName;
75 81
76 LayerFactory *factory = LayerFactory::getInstance(); 82 LayerFactory *factory = LayerFactory::getInstance();
77 QString layerName = factory->getLayerPresentationName 83 QString layerName = factory->getLayerPresentationName
78 (factory->getLayerType(this)); 84 (factory->getLayerType(this));
79 85
155 diff = 0.f; 161 diff = 0.f;
156 return false; 162 return false;
157 } 163 }
158 diff = fabsf(v1 - v0); 164 diff = fabsf(v1 - v0);
159 return true; 165 return true;
166 }
167
168 size_t
169 Layer::alignToReference(View *v, size_t frame) const
170 {
171 const Model *m = getModel();
172 std::cerr << "Layer::alignToReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << std::endl;
173 if (m && m->getAlignmentReference()) {
174 return m->alignToReference(frame);
175 } else {
176 return v->alignToReference(frame);
177 }
178 }
179
180 size_t
181 Layer::alignFromReference(View *v, size_t frame) const
182 {
183 const Model *m = getModel();
184 std::cerr << "Layer::alignFromReference(" << frame << "): model = " << m << ", alignment reference = " << (m ? m->getAlignmentReference() : 0) << std::endl;
185 if (m && m->getAlignmentReference()) {
186 return m->alignFromReference(frame);
187 } else {
188 return v->alignFromReference(frame);
189 }
190 }
191
192 bool
193 Layer::clipboardHasDifferentAlignment(View *v, const Clipboard &clip) const
194 {
195 // Notes on pasting to an aligned layer:
196 //
197 // Each point may have a reference frame that may differ from the
198 // point's given frame (in its source model). If it has no
199 // reference frame, we have to assume the source model was not
200 // aligned or was the reference model: when cutting or copying
201 // points from a layer, we must always set their reference frame
202 // correctly if we are aligned.
203 //
204 // When pasting:
205 // - if point's reference and aligned frames differ:
206 // - if this layer is aligned:
207 // - if point's aligned frame matches this layer's aligned version
208 // of point's reference frame:
209 // - we can paste at reference frame or our frame
210 // - else
211 // - we can paste at reference frame, result of aligning reference
212 // frame in our model, or literal source frame
213 // - else
214 // - we can paste at reference (our) frame, or literal source frame
215 // - else
216 // - if this layer is aligned:
217 // - we can paste at reference (point's only available) frame,
218 // or result of aligning reference frame in our model
219 // - else
220 // - we can only paste at reference frame
221 //
222 // Which of these alternatives are useful?
223 //
224 // Example: we paste between two tracks that are aligned to the
225 // same reference, and the points are at 10s and 20s in the source
226 // track, corresponding to 5s and 10s in the reference but 20s and
227 // 30s in the target track.
228 //
229 // The obvious default is to paste at 20s and 30s; if we aren't
230 // doing that, would it be better to paste at 5s and 10s or at 10s
231 // and 20s? We probably don't ever want to do the former, do we?
232 // We either want to be literal all the way through, or aligned
233 // all the way through.
234
235 for (Clipboard::PointList::const_iterator i = clip.getPoints().begin();
236 i != clip.getPoints().end(); ++i) {
237
238 // In principle, we want to know whether the aligned version
239 // of the reference frame in our layer is the same as the
240 // source frame contained in the clipboard point. However,
241 // because of rounding during alignment, that won't
242 // necessarily be the case even if the clipboard point came
243 // from our layer! What we need to check is whether, if we
244 // aligned the clipboard point's frame back to the reference
245 // using this layer's alignment, we would obtain the same
246 // reference frame as that for the clipboard point.
247
248 // What if the clipboard point has no reference frame? Then
249 // we have to treat it as having its own frame as the
250 // reference (i.e. having been copied from the reference
251 // model).
252
253 long sourceFrame = i->getFrame();
254 long referenceFrame = sourceFrame;
255 if (i->haveReferenceFrame()) {
256 referenceFrame = i->getReferenceFrame();
257 }
258 long myMappedFrame = alignToReference(v, sourceFrame);
259
260 // std::cerr << "sourceFrame = " << sourceFrame << ", referenceFrame = " << referenceFrame << " (have = " << i->haveReferenceFrame() << "), myMappedFrame = " << myMappedFrame << std::endl;
261
262 if (myMappedFrame != referenceFrame) return true;
263 }
264
265 return false;
160 } 266 }
161 267
162 bool 268 bool
163 Layer::MeasureRect::operator<(const MeasureRect &mr) const 269 Layer::MeasureRect::operator<(const MeasureRect &mr) const
164 { 270 {
486 Layer::toXml(QTextStream &stream, 592 Layer::toXml(QTextStream &stream,
487 QString indent, QString extraAttributes) const 593 QString indent, QString extraAttributes) const
488 { 594 {
489 stream << indent; 595 stream << indent;
490 596
597 if (m_presentationName != "") {
598 extraAttributes = QString("%1 presentationName=\"%2\"")
599 .arg(extraAttributes).arg(encodeEntities(m_presentationName));
600 }
601
491 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5") 602 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5")
492 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName 603 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
493 (LayerFactory::getInstance()->getLayerType(this)))) 604 (LayerFactory::getInstance()->getLayerType(this))))
494 .arg(getObjectExportId(this)) 605 .arg(getObjectExportId(this))
495 .arg(encodeEntities(objectName())) 606 .arg(encodeEntities(objectName()))
515 Layer::toBriefXml(QTextStream &stream, 626 Layer::toBriefXml(QTextStream &stream,
516 QString indent, QString extraAttributes) const 627 QString indent, QString extraAttributes) const
517 { 628 {
518 stream << indent; 629 stream << indent;
519 630
631 if (m_presentationName != "") {
632 extraAttributes = QString("%1 presentationName=\"%2\"")
633 .arg(extraAttributes).arg(encodeEntities(m_presentationName));
634 }
635
520 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n") 636 stream << QString("<layer id=\"%2\" type=\"%1\" name=\"%3\" model=\"%4\" %5/>\n")
521 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName 637 .arg(encodeEntities(LayerFactory::getInstance()->getLayerTypeName
522 (LayerFactory::getInstance()->getLayerType(this)))) 638 (LayerFactory::getInstance()->getLayerType(this))))
523 .arg(getObjectExportId(this)) 639 .arg(getObjectExportId(this))
524 .arg(encodeEntities(objectName())) 640 .arg(encodeEntities(objectName()))