m_monitor(monitor),
m_showScene(true),
m_in(in),
- m_out(out),
- m_pos(0)
+ m_out(out)
{
QVBoxLayout *l = new QVBoxLayout(this);
- m_keyframeWidget = new SimpleKeyframeWidget(t, in, out, this);
+ m_keyframeWidget = new SimpleKeyframeWidget(t, m_out - m_in - 1, this);
l->addWidget(m_keyframeWidget);
MonitorEditWidget *edit = monitor->getEffectEdit();
if (m_data.canConvert(QVariant::Map)) {
+ /*
+ * pass keyframe data to keyframe timeline
+ */
QList <int> keyframes;
QMap <QString, QVariant> map = m_data.toMap();
QMap <QString, QVariant>::const_iterator i = map.constBegin();
while (i != map.constEnd()) {
- keyframes.append(i.key().toInt());
+ keyframes.append(i.key().toInt() - m_in);
++i;
}
m_keyframeWidget->setKeyframes(keyframes);
for (int j = 0; j < keyframes.count(); ++j) {
// key might already be justified
- if (map.contains(QString::number(keyframes.at(j)))) {
- QVariant value = map.take(QString::number(keyframes.at(j)));
- map[QString::number(keyframes.at(j)).rightJustified(qRound(log10((double)m_out)), '0')] = value;
+ if (map.contains(QString::number(keyframes.at(j) + m_in))) {
+ QVariant value = map.take(QString::number(keyframes.at(j) + m_in));
+ map[QString::number(keyframes.at(j) + m_in).rightJustified(qRound(log10((double)m_out)), '0')] = value;
}
}
m_data = QVariant(map);
} else {
+ // static (only one keyframe)
m_keyframeWidget->setKeyframes(QList <int>() << 0);
}
connect(m_keyframeWidget, SIGNAL(positionChanged(int)), this, SLOT(slotPositionChanged(int)));
connect(m_keyframeWidget, SIGNAL(keyframeAdded(int)), this, SLOT(slotAddKeyframe(int)));
connect(m_keyframeWidget, SIGNAL(keyframeRemoved(int)), this, SLOT(slotRemoveKeyframe(int)));
+ connect(m_keyframeWidget, SIGNAL(keyframeMoved(int,int)), this, SLOT(slotMoveKeyframe(int,int)));
connect(m_scene, SIGNAL(addKeyframe()), this, SLOT(slotAddKeyframe()));
slotPositionChanged(0, false);
int width = m_monitor->render->frameRenderWidth();
int height = m_monitor->render->renderHeight();
+ /*
+ * use the position of the on-monitor points to create a storable list
+ */
QList <BPoint> spline = m_item->getPoints();
QList <QVariant> vlist;
foreach (const BPoint &point, spline) {
if (m_data.canConvert(QVariant::Map)) {
QMap <QString, QVariant> map = m_data.toMap();
- map[QString::number(pos < 0 ? m_keyframeWidget->getPosition() : pos).rightJustified(qRound(log10((double)m_out)), '0')] = QVariant(vlist);
+ // replace or insert at position
+ // we have to fill with 0s to maintain the correct order
+ map[QString::number((pos < 0 ? m_keyframeWidget->getPosition() : pos) + m_in).rightJustified(qRound(log10((double)m_out)), '0')] = QVariant(vlist);
m_data = QVariant(map);
} else {
m_data = QVariant(vlist);
void RotoWidget::slotPositionChanged(int pos, bool seek)
{
+ // do not update while the spline is being edited (points are being dragged)
if (m_item->editing())
return;
m_keyframeWidget->slotSetPosition(pos, false);
+ pos += m_in;
+
+ QList <BPoint> p;
+
if (m_data.canConvert(QVariant::Map)) {
QMap <QString, QVariant> map = m_data.toMap();
QMap <QString, QVariant>::const_iterator i = map.constBegin();
int keyframe1, keyframe2;
keyframe1 = keyframe2 = i.key().toInt();
+ // find keyframes next to pos
while (i.key().toInt() < pos && ++i != map.constEnd()) {
keyframe1 = keyframe2;
keyframe2 = i.key().toInt();
}
if (keyframe1 != keyframe2 && pos < keyframe2) {
+ /*
+ * in between two keyframes
+ * -> interpolate
+ */
QList <BPoint> p1 = getPoints(keyframe1);
QList <BPoint> p2 = getPoints(keyframe2);
- QList <BPoint> p;
qreal relPos = (pos - keyframe1) / (qreal)(keyframe2 - keyframe1 + 1);
- for (int i = 0; i < p1.count(); ++i) {
+ // additionaly points are ignored (same behavior as MLT filter)
+ int count = qMin(p1.count(), p2.count());
+ for (int i = 0; i < count; ++i) {
BPoint bp;
for (int j = 0; j < 3; ++j) {
if (p1.at(i)[j] != p2.at(i)[j])
m_item->setEnabled(false);
m_scene->setEnabled(false);
} else {
- m_item->setPoints(getPoints(keyframe2));
+ p = getPoints(keyframe2);
+ // only update if necessary to preserve the current point selection
+ if (p != m_item->getPoints())
+ m_item->setPoints(p);
m_item->setEnabled(pos == keyframe2);
m_scene->setEnabled(pos == keyframe2);
}
} else {
- m_item->setPoints(getPoints(-1));
+ p = getPoints(-1);
+ // only update if necessary to preserve the current point selection
+ if (p != m_item->getPoints())
+ m_item->setPoints(p);
m_item->setEnabled(true);
m_scene->setEnabled(true);
}
if (seek)
- emit seekToPos(pos);
+ emit seekToPos(pos - m_in);
}
QList <BPoint> RotoWidget::getPoints(int keyframe)
if (!m_data.canConvert(QVariant::Map) || m_data.toMap().count() < 2)
return;
- m_data.toMap().remove(QString::number(pos).rightJustified(qRound(log10((double)m_out)), '0'));
+ QMap<QString, QVariant> map = m_data.toMap();
+ map.remove(QString::number(pos + m_in).rightJustified(qRound(log10((double)m_out)), '0'));
+ m_data = QVariant(map);
- if (m_data.toMap().count() == 1)
+ if (m_data.toMap().count() == 1) {
+ // only one keyframe -> switch from map to list again
m_data = m_data.toMap().begin().value();
+ }
slotPositionChanged(m_keyframeWidget->getPosition(), false);
+ emit valueChanged();
+}
+
+void RotoWidget::slotMoveKeyframe(int oldPos, int newPos)
+{
+ if (m_data.canConvert(QVariant::Map)) {
+ QMap<QString, QVariant> map = m_data.toMap();
+ map[QString::number(newPos + m_in).rightJustified(qRound(log10((double)m_out)), '0')] = map.take(QString::number(oldPos + m_in).rightJustified(qRound(log10((double)m_out)), '0'));
+ m_data = QVariant(map);
+ }
+
+ slotPositionChanged(m_keyframeWidget->getPosition(), false);
+ emit valueChanged();
+}
+
+void RotoWidget::updateTimecodeFormat()
+{
+ m_keyframeWidget->updateTimecodeFormat();
}
#include "rotowidget.moc"