X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=428612df4ece540b243863d1d2098c9e7564fa1b;hb=492d385f45df2bb1c67dcac7d7c541fa1b52a125;hp=db8588d948e778a44343ee0cc0a0c3290440cdd0;hpb=0dc379c5294a981179781cc45928b0e1c9f1a5d5;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index db8588d9..428612df 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -67,7 +67,6 @@ #include #include #include -#include #include #include @@ -124,49 +123,49 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen m_menuPosition(), m_blockRefresh(false), m_selectionGroup(NULL), - m_selectedTrack(0) + m_selectedTrack(0), + m_controlModifier(false) { - if (doc) m_commandStack = doc->commandStack(); - else m_commandStack = NULL; + if (doc) + m_commandStack = doc->commandStack(); + else + m_commandStack = NULL; + m_ct = 0; setMouseTracking(true); setAcceptDrops(true); setFrameShape(QFrame::NoFrame); setLineWidth(0); //setCacheMode(QGraphicsView::CacheBackground); - //setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + setAutoFillBackground(false); setViewportUpdateMode(QGraphicsView::SmartViewportUpdate); + setContentsMargins(0, 0, 0, 0); + + m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())); - pixmapCache = new KPixmapCache("kdenlive-thumbs"); - KdenliveSettings::setTrackheight(m_tracksHeight); m_animationTimer = new QTimeLine(800); m_animationTimer->setFrameRange(0, 5); m_animationTimer->setUpdateInterval(100); m_animationTimer->setLoopCount(0); + m_tipColor = QColor(0, 192, 0, 200); - QColor border = QColor(255, 255, 255, 100); - m_tipPen.setColor(border); + m_tipPen.setColor(QColor(255, 255, 255, 100)); m_tipPen.setWidth(3); - setContentsMargins(0, 0, 0, 0); + const int maxHeight = m_tracksHeight * m_document->tracksCount(); setSceneRect(0, 0, sceneRect().width(), maxHeight); verticalScrollBar()->setMaximum(maxHeight); + verticalScrollBar()->setTracking(true); + // repaint guides when using vertical scroll + connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides())); + m_cursorLine = projectscene->addLine(0, 0, 0, maxHeight); m_cursorLine->setZValue(1000); - QPen pen1 = QPen(); pen1.setWidth(1); pen1.setColor(palette().text().color()); m_cursorLine->setPen(pen1); m_cursorLine->setFlag(QGraphicsItem::ItemIgnoresTransformations, true); - KIcon razorIcon("edit-cut"); - m_razorCursor = QCursor(razorIcon.pixmap(22, 22)); - - KIcon spacerIcon("kdenlive-spacer-tool"); - m_spacerCursor = QCursor(spacerIcon.pixmap(22, 22)); - verticalScrollBar()->setTracking(true); - // Line below was supposed to scroll guides label with scrollbar, not implemented yet - //connect(verticalScrollBar(), SIGNAL(valueChanged(int)), this, SLOT(slotRefreshGuides())); connect(&m_scrollTimer, SIGNAL(timeout()), this, SLOT(slotCheckMouseScrolling())); m_scrollTimer.setInterval(100); m_scrollTimer.setSingleShot(true); @@ -174,6 +173,12 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen connect(&m_thumbsTimer, SIGNAL(timeout()), this, SLOT(slotFetchNextThumbs())); m_thumbsTimer.setInterval(500); m_thumbsTimer.setSingleShot(true); + + KIcon razorIcon("edit-cut"); + m_razorCursor = QCursor(razorIcon.pixmap(22, 22)); + + KIcon spacerIcon("kdenlive-spacer-tool"); + m_spacerCursor = QCursor(spacerIcon.pixmap(22, 22)); } CustomTrackView::~CustomTrackView() @@ -181,6 +186,7 @@ CustomTrackView::~CustomTrackView() qDeleteAll(m_guides); m_guides.clear(); m_waitingThumbs.clear(); + delete m_animationTimer; } //virtual @@ -256,14 +262,35 @@ void CustomTrackView::checkAutoScroll() return m_scene->m_tracksList; }*/ -void CustomTrackView::checkTrackHeight() + +int CustomTrackView::getFrameWidth() +{ + return (int) (m_tracksHeight * m_document->mltProfile().display_aspect_num / m_document->mltProfile().display_aspect_den + 0.5); +} + +void CustomTrackView::updateSceneFrameWidth() +{ + int frameWidth = getFrameWidth(); + QList itemList = items(); + ClipItem *item; + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == AVWIDGET) { + item = (ClipItem*) itemList.at(i); + item->resetFrameWidth(frameWidth); + item->resetThumbs(true); + } + } +} + +bool CustomTrackView::checkTrackHeight() { - if (m_tracksHeight == KdenliveSettings::trackheight()) return; + if (m_tracksHeight == KdenliveSettings::trackheight()) return false; m_tracksHeight = KdenliveSettings::trackheight(); emit trackHeightChanged(); QList itemList = items(); ClipItem *item; Transition *transitionitem; + int frameWidth = getFrameWidth(); bool snap = KdenliveSettings::snaptopoints(); KdenliveSettings::setSnaptopoints(false); for (int i = 0; i < itemList.count(); i++) { @@ -271,6 +298,7 @@ void CustomTrackView::checkTrackHeight() item = (ClipItem*) itemList.at(i); item->setRect(0, 0, item->rect().width(), m_tracksHeight - 1); item->setPos((qreal) item->startPos().frames(m_document->fps()), (qreal) item->track() * m_tracksHeight + 1); + item->resetFrameWidth(frameWidth); item->resetThumbs(true); } else if (itemList.at(i)->type() == TRANSITIONWIDGET) { transitionitem = (Transition*) itemList.at(i); @@ -279,7 +307,7 @@ void CustomTrackView::checkTrackHeight() } } double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1); for (int i = 0; i < m_guides.count(); i++) { QLineF l = m_guides.at(i)->line(); @@ -291,6 +319,7 @@ void CustomTrackView::checkTrackHeight() // verticalScrollBar()->setMaximum(m_tracksHeight * m_document->tracksCount()); KdenliveSettings::setSnaptopoints(snap); viewport()->update(); + return true; } /** Zoom or move viewport on mousewheel @@ -327,7 +356,7 @@ void CustomTrackView::slotFetchNextThumbs() { if (!m_waitingThumbs.isEmpty()) { ClipItem *item = m_waitingThumbs.takeFirst(); - while ((item == NULL) && !m_waitingThumbs.isEmpty()) { + while (item == NULL && !m_waitingThumbs.isEmpty()) { item = m_waitingThumbs.takeFirst(); } if (item) item->slotFetchThumbs(); @@ -366,6 +395,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) { int pos = event->x(); int mappedXPos = qMax((int)(mapToScene(event->pos()).x() + 0.5), 0); + double snappedPos = getSnapPointForPos(mappedXPos); emit mousePosition(mappedXPos); @@ -394,22 +424,29 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) } } else if (m_operationMode == RESIZESTART && move) { m_document->renderer()->pause(); - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) - parent->resizeStart((int)(snappedPos) - m_dragItemInfo.startPos.frames(m_document->fps())); + parent->resizeStart((int)(snappedPos - m_dragItemInfo.startPos.frames(m_document->fps()))); } else { m_dragItem->resizeStart((int)(snappedPos)); } + QString crop = m_document->timecode().getDisplayTimecode(m_dragItem->cropStart(), KdenliveSettings::frametimecode()); + QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode()); + QString offset = m_document->timecode().getDisplayTimecode(m_dragItem->cropStart() - m_dragItemInfo.cropStart, KdenliveSettings::frametimecode()); + emit displayMessage(i18n("Crop from start:") + ' ' + crop + ' ' + i18n("Duration:") + ' ' + duration + ' ' + i18n("Offset:") + ' ' + offset, InformationMessage); } else if (m_operationMode == RESIZEEND && move) { m_document->renderer()->pause(); - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) - parent->resizeEnd((int)(snappedPos) - m_dragItemInfo.endPos.frames(m_document->fps())); + parent->resizeEnd((int)(snappedPos - m_dragItemInfo.endPos.frames(m_document->fps()))); } else { m_dragItem->resizeEnd((int)(snappedPos)); } + QString duration = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration(), KdenliveSettings::frametimecode()); + QString offset = m_document->timecode().getDisplayTimecode(m_dragItem->cropDuration() - m_dragItemInfo.cropDuration, KdenliveSettings::frametimecode()); + emit displayMessage(i18n("Duration:") + ' ' + duration + ' ' + i18n("Offset:") + ' ' + offset, InformationMessage); } else if (m_operationMode == FADEIN && move) { ((ClipItem*) m_dragItem)->setFadeIn((int)(mappedXPos - m_dragItem->startPos().frames(m_document->fps()))); } else if (m_operationMode == FADEOUT && move) { @@ -421,6 +458,8 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) double maxh = 100.0 / br.height(); pos = (br.bottom() - pos) * maxh; m_dragItem->updateKeyFramePos(keyFramePos, pos); + QString position = m_document->timecode().getDisplayTimecodeFromFrames(m_dragItem->editedKeyFramePos(), KdenliveSettings::frametimecode()); + emit displayMessage(position + " : " + QString::number(m_dragItem->editedKeyFrameValue()), InformationMessage); } removeTipAnimation(); return; @@ -568,7 +607,14 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) event->accept(); return; } - opMode = clip->operationMode(mapToScene(event->pos())); + + if (m_selectionGroup && clip->parentItem() == m_selectionGroup) { + // all other modes break the selection, so the user probably wants to move it + opMode = MOVE; + } else { + opMode = clip->operationMode(mapToScene(event->pos())); + } + const double size = 5; if (opMode == m_moveOpMode) { QGraphicsView::mouseMoveEvent(event); @@ -578,11 +624,14 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) } m_moveOpMode = opMode; setTipAnimation(clip, opMode, size); + ClipItem *ci = NULL; + if (item->type() == AVWIDGET) + ci = static_cast (item); + QString message; if (opMode == MOVE) { setCursor(Qt::OpenHandCursor); - if (item->type() == AVWIDGET) { - ClipItem *ci = static_cast (item); - QString message = ci->clipName() + i18n(":"); + if (ci) { + message = ci->clipName() + i18n(":"); message.append(i18n(" Position:") + m_document->timecode().getDisplayTimecode(ci->info().startPos, KdenliveSettings::frametimecode())); message.append(i18n(" Duration:") + m_document->timecode().getDisplayTimecode(ci->cropDuration(), KdenliveSettings::frametimecode())); if (clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) { @@ -597,26 +646,40 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) message.append(i18n(" Selection duration:") + m_document->timecode().getDisplayTimecode(parent2->duration(), KdenliveSettings::frametimecode())); } } - emit displayMessage(message, InformationMessage); } } else if (opMode == RESIZESTART) { setCursor(KCursor("left_side", Qt::SizeHorCursor)); + if (ci) + message = i18n("Crop from start: ") + m_document->timecode().getDisplayTimecode(ci->cropStart(), KdenliveSettings::frametimecode()); if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup) - emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage); + message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once.")); } else if (opMode == RESIZEEND) { setCursor(KCursor("right_side", Qt::SizeHorCursor)); + if (ci) + message = i18n("Duration: ") + m_document->timecode().getDisplayTimecode(ci->cropDuration(), KdenliveSettings::frametimecode()); if (item->type() == AVWIDGET && item->parentItem() && item->parentItem() != m_selectionGroup) - emit displayMessage(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once."), InformationMessage); + message.append(i18n("Use Ctrl to resize only current item, otherwise all items in this group will be resized at once.")); } else if (opMode == FADEIN || opMode == FADEOUT) { setCursor(Qt::PointingHandCursor); - emit displayMessage(i18n("Drag to add or resize a fade effect."), InformationMessage); + if (ci && opMode == FADEIN && ci->fadeIn()) { + message = i18n("Fade in duration: "); + message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeIn(), KdenliveSettings::frametimecode())); + } else if (ci && opMode == FADEOUT && ci->fadeOut()) { + message = i18n("Fade out duration: "); + message.append(m_document->timecode().getDisplayTimecodeFromFrames(ci->fadeOut(), KdenliveSettings::frametimecode())); + } else { + message = i18n("Drag to add or resize a fade effect."); + } } else if (opMode == TRANSITIONSTART || opMode == TRANSITIONEND) { setCursor(Qt::PointingHandCursor); - emit displayMessage(i18n("Click to add a transition."), InformationMessage); + message = i18n("Click to add a transition."); } else if (opMode == KEYFRAME) { setCursor(Qt::PointingHandCursor); emit displayMessage(i18n("Move keyframe above or below clip to remove it, double click to add a new one."), InformationMessage); } + + if (!message.isEmpty()) + emit displayMessage(message, InformationMessage); } // no clip under mouse else if (m_tool == RAZORTOOL) { event->accept(); @@ -668,7 +731,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) m_blockRefresh = true; m_dragGuide = NULL; - bool collision = false; if (m_tool != RAZORTOOL) activateMonitor(); else if (m_document->renderer()->playSpeed() != 0.0) { @@ -679,7 +741,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) // check item under mouse QList collisionList = items(m_clickEvent); - if (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && collisionList.count() == 0) { // Pressing Ctrl + left mouse button in an empty area scrolls the timeline setDragMode(QGraphicsView::ScrollHandDrag); @@ -696,7 +757,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) m_dragGuide = (Guide *) collisionList.at(i); if (event->button() == Qt::LeftButton) { // move it m_dragGuide->setFlag(QGraphicsItem::ItemIsMovable, true); - collision = true; m_operationMode = MOVEGUIDE; // deselect all clips so that only the guide will move m_scene->clearSelection(); @@ -867,7 +927,8 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } else { setCursorPos((int)(mapToScene(event->x(), 0).x())); } - QGraphicsView::mousePressEvent(event); + //QGraphicsView::mousePressEvent(event); + event->ignore(); return; } @@ -909,7 +970,6 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) } else resetSelectionGroup(); dragGroup = NULL; if (m_dragItem->parentItem() && m_dragItem->parentItem()->type() == GROUPWIDGET) { - //kDebug()<<"// KLIK FOUND GRP: "<sceneBoundingRect(); dragGroup = static_cast (m_dragItem->parentItem()); } bool selected = !m_dragItem->isSelected(); @@ -937,7 +997,13 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (event->modifiers() != Qt::ControlModifier && m_operationMode == NONE) QGraphicsView::mousePressEvent(event); m_clickPoint = QPoint((int)(mapToScene(event->pos()).x() - m_dragItem->startPos().frames(m_document->fps())), (int)(event->pos().y() - m_dragItem->pos().y())); - m_operationMode = m_dragItem->operationMode(mapToScene(event->pos())); + if (m_selectionGroup && m_dragItem->parentItem() == m_selectionGroup) { + // all other modes break the selection, so the user probably wants to move it + m_operationMode = MOVE; + } else { + m_operationMode = m_dragItem->operationMode(mapToScene(event->pos())); + } + m_controlModifier = (event->modifiers() == Qt::ControlModifier); // Update snap points if (m_selectionGroup == NULL) { @@ -1101,6 +1167,7 @@ void CustomTrackView::resetSelectionGroup(bool selectItems) children.at(i)->setSelected(selectItems); } } + m_selectionGroup = NULL; KdenliveSettings::setSnaptopoints(snap); } @@ -1282,30 +1349,43 @@ void CustomTrackView::editItemDuration() clipInfo.endPos = clipInfo.startPos + d.duration(); clipInfo.track = item->track(); MoveTransitionCommand *command = new MoveTransitionCommand(this, startInfo, clipInfo, true); + updateTrackDuration(clipInfo.track, command); m_commandStack->push(command); } else { // move and resize clip + ClipItem *clip = static_cast(item); QUndoCommand *moveCommand = new QUndoCommand(); moveCommand->setText(i18n("Edit clip")); if (d.duration() < item->cropDuration() || d.cropStart() != clipInfo.cropStart) { // duration was reduced, so process it first clipInfo.endPos = clipInfo.startPos + d.duration(); clipInfo.cropStart = d.cropStart(); - new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand); + + resizeClip(startInfo, clipInfo); + new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand); + adjustEffects(clip, startInfo, moveCommand); + new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand); } + if (d.startPos() != clipInfo.startPos) { startInfo = clipInfo; clipInfo.startPos = d.startPos(); clipInfo.endPos = item->endPos() + (clipInfo.startPos - startInfo.startPos); new MoveClipCommand(this, startInfo, clipInfo, true, moveCommand); } + if (d.duration() > item->cropDuration()) { // duration was increased, so process it after move startInfo = clipInfo; clipInfo.endPos = clipInfo.startPos + d.duration(); clipInfo.cropStart = d.cropStart(); - new ResizeClipCommand(this, startInfo, clipInfo, true, false, moveCommand); + + resizeClip(startInfo, clipInfo); + new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand); + adjustEffects(clip, startInfo, moveCommand); + new ResizeClipCommand(this, startInfo, clipInfo, false, true, moveCommand); } + updateTrackDuration(clipInfo.track, moveCommand); m_commandStack->push(moveCommand); } } @@ -1314,7 +1394,7 @@ void CustomTrackView::editItemDuration() } } -void CustomTrackView::editKeyFrame(const GenTime /*pos*/, const int /*track*/, const int /*index*/, const QString /*keyframes*/) +void CustomTrackView::editKeyFrame(const GenTime & /*pos*/, const int /*track*/, const int /*index*/, const QString & /*keyframes*/) { /*ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), track); if (clip) { @@ -1390,6 +1470,7 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out) } AddTimelineClipCommand *command = new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), pasteInfo, EffectsList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, true, false); + updateTrackDuration(pasteInfo.track, command); m_commandStack->push(command); selectClip(true, false); @@ -1398,7 +1479,7 @@ void CustomTrackView::insertClipCut(DocClipBase *clip, int in, int out) splitAudio(); } -bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) +bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint &pos) { if (data->hasFormat("kdenlive/clip")) { m_clipDrag = true; @@ -1410,6 +1491,10 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << list.at(0); return false; } + if (clip->getProducer() == NULL) { + emit displayMessage(i18n("Clip not ready"), ErrorMessage); + return false; + } QPointF framePos = mapToScene(pos); ItemInfo info; info.startPos = GenTime(); @@ -1429,7 +1514,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) return true; } m_selectionGroup = new AbstractGroupItem(m_document->fps()); - ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1); + ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth()); m_selectionGroup->addToGroup(item); item->setFlag(QGraphicsItem::ItemIsMovable, false); @@ -1461,6 +1546,10 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) kDebug() << " WARNING))))))))) CLIP NOT FOUND : " << ids.at(i); return false; } + if (clip->getProducer() == NULL) { + emit displayMessage(i18n("Clip not ready"), ErrorMessage); + return false; + } ItemInfo info; info.startPos = start; info.cropDuration = clip->duration(); @@ -1483,7 +1572,7 @@ bool CustomTrackView::insertDropClips(const QMimeData *data, const QPoint pos) info.track = 0; start += info.cropDuration; offsetList.append(start); - ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, false); + ClipItem *item = new ClipItem(clip, info, m_document->fps(), 1.0, 1, getFrameWidth(), false); item->setFlag(QGraphicsItem::ItemIsMovable, false); m_selectionGroup->addToGroup(item); if (!clip->isPlaceHolder()) m_waitingThumbs.append(item); @@ -1535,7 +1624,7 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip) { int track = m_document->tracksCount() - clip->track(); GenTime pos = clip->startPos(); - if (!m_document->renderer()->mltRemoveEffect(track, pos, "-1", false, false)) { + if (!m_document->renderer()->mltRemoveEffect(track, pos, -1, false, false)) { emit displayMessage(i18n("Problem deleting effect"), ErrorMessage); return; } @@ -1551,8 +1640,15 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) { if (pos < GenTime()) { // Add track effect + if (effect.attribute("id") == "speed") { + // TODO: uncomment after 0.8.2 release + // emit displayMessage(i18n("Cannot add speed effect to track")); + return; + } + clearSelection(); m_document->addTrackEffect(track - 1, effect); m_document->renderer()->mltAddTrackEffect(track, getEffectArgs(effect)); + emit updateTrackEffectState(track - 1); emit showTrackEffects(track, m_document->trackInfoAt(track - 1)); return; } @@ -1564,7 +1660,8 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage); return; } - double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0; + QLocale locale; + double speed = locale.toDouble(EffectsList::parameter(effect, "speed")) / 100.0; int strobe = EffectsList::parameter(effect, "strobe").toInt(); if (strobe == 0) strobe = 1; doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, 1.0, strobe, clip->baseClip()->getId()); @@ -1585,8 +1682,11 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) QString index = effect.attribute("kdenlive_ix"); if (pos < GenTime()) { // Delete track effect - m_document->removeTrackEffect(track - 1, effect); - m_document->renderer()->mltRemoveTrackEffect(track, index, true); + if (m_document->renderer()->mltRemoveTrackEffect(track, index.toInt(), true)) { + m_document->removeTrackEffect(track - 1, effect); + } + else emit displayMessage(i18n("Problem deleting effect"), ErrorMessage); + emit updateTrackEffectState(track - 1); emit showTrackEffects(track, m_document->trackInfoAt(track - 1)); return; } @@ -1597,11 +1697,11 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId()); clip->deleteEffect(index); emit clipItemSelected(clip); - m_document->renderer()->mltRemoveEffect(track, pos, index, true); + m_document->renderer()->mltRemoveEffect(track, pos, index.toInt(), true); return; } } - if (!m_document->renderer()->mltRemoveEffect(track, pos, index, true)) { + if (!m_document->renderer()->mltRemoveEffect(track, pos, index.toInt(), true)) { kDebug() << "// ERROR REMOV EFFECT: " << index << ", DISABLE: " << effect.attribute("disable"); emit displayMessage(i18n("Problem deleting effect"), ErrorMessage); return; @@ -1618,8 +1718,8 @@ void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem * QList itemList = group->childItems(); QUndoCommand *effectCommand = new QUndoCommand(); QString effectName; - QDomNode namenode = effect.elementsByTagName("name").item(0); - if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data()); + QDomElement namenode = effect.firstChildElement("name"); + if (!namenode.isNull()) effectName = i18n(namenode.text().toUtf8().data()); else effectName = i18n("effect"); effectCommand->setText(i18n("Add %1", effectName)); int count = 0; @@ -1642,11 +1742,7 @@ void CustomTrackView::slotAddGroupEffect(QDomElement effect, AbstractGroupItem * continue; } item->initEffect(effect); - if (effect.attribute("tag") == "ladspa") { - QString ladpsaFile = m_document->getLadspaFile(); - initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect)); - effect.setAttribute("src", ladpsaFile); - } + new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand); count++; } @@ -1662,8 +1758,8 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) QList itemList; QUndoCommand *effectCommand = new QUndoCommand(); QString effectName; - QDomNode namenode = effect.elementsByTagName("name").item(0); - if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data()); + QDomElement namenode = effect.firstChildElement("name"); + if (!namenode.isNull()) effectName = i18n(namenode.text().toUtf8().data()); else effectName = i18n("effect"); effectCommand->setText(i18n("Add %1", effectName)); @@ -1719,18 +1815,27 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) } else { item->initEffect(effect); } - - if (effect.attribute("tag") == "ladspa") { - QString ladpsaFile = m_document->getLadspaFile(); - initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect)); - effect.setAttribute("src", ladpsaFile); - } new AddEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), effect, true, effectCommand); } } if (effectCommand->childCount() > 0) { m_commandStack->push(effectCommand); setDocumentModified(); + if (effectCommand->childCount() == 1) { + // Display newly added clip effect + for (int i = 0; i < itemList.count(); i++) { + if (itemList.at(i)->type() == AVWIDGET) { + ClipItem *clip = static_cast(itemList.at(i)); + if (!clip->isSelected()) { + clearSelection(); + clip->setSelected(true); + } + clip->setSelectedEffect(clip->effectsCount() - 1); + emit clipItemSelected(clip, clip->effectsCount() - 1); + break; + } + } + } } else delete effectCommand; } @@ -1748,8 +1853,8 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement ef QList items = m_selectionGroup->childItems(); QUndoCommand *delCommand = new QUndoCommand(); QString effectName; - QDomNode namenode = effect.elementsByTagName("name").item(0); - if (!namenode.isNull()) effectName = i18n(namenode.toElement().text().toUtf8().data()); + QDomElement namenode = effect.firstChildElement("name"); + if (!namenode.isNull()) effectName = i18n(namenode.text().toUtf8().data()); else effectName = i18n("effect"); delCommand->setText(i18n("Delete %1", effectName)); @@ -1773,8 +1878,11 @@ void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement ef } } } - if (delCommand->childCount() > 0) m_commandStack->push(delCommand); - else delete delCommand; + if (delCommand->childCount() > 0) + m_commandStack->push(delCommand); + else + delete delCommand; + setDocumentModified(); return; } AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effect, false); @@ -1789,21 +1897,20 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE return; } QDomElement effect = insertedEffect.cloneNode().toElement(); + //kDebug() << "// update effect ix: " << effect.attribute("kdenlive_ix")<<", TRACK: "<initEffect(effect); + /*if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) { + clip->initEffect(effect); effectParams = getEffectArgs(effect); - } + }*/ if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - track, pos, effectParams)) emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - m_document->setTrackEffect(track - 1, ix, effect); + m_document->setTrackEffect(m_document->tracksCount() - track - 1, ix, effect); + emit updateTrackEffectState(track); + setDocumentModified(); return; } @@ -1811,9 +1918,11 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE if (clip) { // Special case: speed effect if (effect.attribute("id") == "speed") { - if (effect.attribute("disable") == "1") doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId()); - else { - double speed = EffectsList::parameter(effect, "speed").toDouble() / 100.0; + if (effect.attribute("disable") == "1") { + doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), 1.0, clip->speed(), 1, clip->baseClip()->getId()); + } else { + QLocale locale; + double speed = locale.toDouble(EffectsList::parameter(effect, "speed")) / 100.0; int strobe = EffectsList::parameter(effect, "strobe").toInt(); if (strobe == 0) strobe = 1; doChangeClipSpeed(clip->info(), clip->speedIndependantInfo(), speed, clip->speed(), strobe, clip->baseClip()->getId()); @@ -1821,29 +1930,19 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE clip->setEffectAt(ix, effect); if (ix == clip->selectedEffectIndex()) { clip->setSelectedEffect(ix); - if (!triggeredByUser) emit clipItemSelected(clip, ix); + if (!triggeredByUser) + emit clipItemSelected(clip, ix); } return; } EffectsParameterList effectParams = getEffectArgs(effect); - if (effect.attribute("tag") == "ladspa") { - // Update the ladspa affect file - initEffects::ladspaEffectFile(effect.attribute("src"), effect.attribute("ladspaid").toInt(), getLadspaParams(effect)); - } // check if we are trying to reset a keyframe effect if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) { clip->initEffect(effect); effectParams = getEffectArgs(effect); } - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams)) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - clip->setEffectAt(ix, effect); - if (ix == clip->selectedEffectIndex()) { - clip->setSelectedEffect(ix); - if (!triggeredByUser) emit clipItemSelected(clip, ix); - } if (effect.attribute("tag") == "volume" || effect.attribute("tag") == "brightness") { // A fade effect was modified, update the clip if (effect.attribute("id") == "fadein" || effect.attribute("id") == "fade_from_black") { @@ -1855,6 +1954,16 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE clip->setFadeOut(pos); } } + + if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams)) + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + + clip->setEffectAt(ix, effect); + if (ix == clip->selectedEffectIndex()) { + clip->setSelectedEffect(ix); + if (!triggeredByUser) + emit clipItemSelected(clip, ix); + } } setDocumentModified(); } @@ -1954,8 +2063,6 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo return NULL; } - kDebug() << "///////// CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25); - if (execute) m_document->renderer()->mltCutClip(m_document->tracksCount() - info.track, cutTime); int cutPos = (int) cutTime.frames(m_document->fps()); ItemInfo newPos; @@ -1968,29 +2075,46 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo bool snap = KdenliveSettings::snaptopoints(); KdenliveSettings::setSnaptopoints(false); ClipItem *dup = item->clone(newPos); - // remove unwanted effects (fade in) from 2nd part of cutted clip + + // remove unwanted effects + // fade in from 2nd part of the clip int ix = dup->hasEffect(QString(), "fadein"); if (ix != -1) { - QDomElement oldeffect = item->effectAt(ix); + QDomElement oldeffect = dup->effectAt(ix); dup->deleteEffect(oldeffect.attribute("kdenlive_ix")); } ix = dup->hasEffect(QString(), "fade_from_black"); if (ix != -1) { - QDomElement oldeffect = item->effectAt(ix); + QDomElement oldeffect = dup->effectAt(ix); dup->deleteEffect(oldeffect.attribute("kdenlive_ix")); } + // fade out from 1st part of the clip + ix = item->hasEffect(QString(), "fadeout"); + if (ix != -1) { + QDomElement oldeffect = item->effectAt(ix); + item->deleteEffect(oldeffect.attribute("kdenlive_ix")); + } + ix = item->hasEffect(QString(), "fade_to_black"); + if (ix != -1) { + QDomElement oldeffect = item->effectAt(ix); + item->deleteEffect(oldeffect.attribute("kdenlive_ix")); + } + + item->resizeEnd(cutPos); scene()->addItem(dup); if (item->checkKeyFrames()) slotRefreshEffects(item); if (dup->checkKeyFrames()) slotRefreshEffects(dup); + item->baseClip()->addReference(); m_document->updateClip(item->baseClip()->getId()); setDocumentModified(); KdenliveSettings::setSnaptopoints(snap); + if (execute && item->isSelected()) + emit clipItemSelected(item); return dup; - //kDebug() << "///////// CUTTING CLIP RESULT: (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), DUP: (" << dup->startPos().frames(25) << "-" << dup->endPos().frames(25) << ")" << ", CUT: " << cutTime.frames(25); } else { // uncut clip @@ -2007,19 +2131,33 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo return NULL; } - /*kDebug() << "// UNCUTTING CLIPS: ITEM 1 (" << item->startPos().frames(25) << "x" << item->endPos().frames(25) << ")"; - kDebug() << "// UNCUTTING CLIPS: ITEM 2 (" << dup->startPos().frames(25) << "x" << dup->endPos().frames(25) << ")"; - kDebug() << "// UNCUTTING CLIPS, INFO (" << info.startPos.frames(25) << "x" << info.endPos.frames(25) << ") , CUT: " << cutTime.frames(25);;*/ - //deleteClip(dup->info()); - bool snap = KdenliveSettings::snaptopoints(); KdenliveSettings::setSnaptopoints(false); - if (dup->isSelected()) emit clipItemSelected(NULL); + // join fade effects again + int ix = dup->hasEffect(QString(), "fadeout"); + if (ix != -1) { + QDomElement effect = dup->effectAt(ix); + item->addEffect(effect); + } + ix = dup->hasEffect(QString(), "fade_to_black"); + if (ix != -1) { + QDomElement effect = dup->effectAt(ix); + item->addEffect(effect); + } + + m_waitingThumbs.removeAll(dup); + bool selected = item->isSelected(); + if (dup->isSelected()) { + selected = true; + item->setSelected(true); + emit clipItemSelected(NULL); + } dup->baseClip()->removeReference(); m_document->updateClip(dup->baseClip()->getId()); scene()->removeItem(dup); delete dup; + dup = NULL; ItemInfo clipinfo = item->info(); clipinfo.track = m_document->tracksCount() - clipinfo.track; @@ -2031,6 +2169,8 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); } KdenliveSettings::setSnaptopoints(snap); + if (execute && selected) + emit clipItemSelected(item); return item; } //QTimer::singleShot(3000, this, SLOT(slotEnableRefresh())); @@ -2183,6 +2323,7 @@ void CustomTrackView::slotTransitionUpdated(Transition *tr, QDomElement old) return; } EditTransitionCommand *command = new EditTransitionCommand(this, tr->track(), tr->startPos(), old, xml, false); + updateTrackDuration(tr->track(), command); m_commandStack->push(command); setDocumentModified(); } @@ -2194,8 +2335,10 @@ void CustomTrackView::updateTransition(int track, GenTime pos, QDomElement oldTr kWarning() << "Unable to find transition at pos :" << pos.frames(m_document->fps()) << ", ON track: " << track; return; } + bool force = false; - if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack")) force = true; + if (oldTransition.attribute("transition_atrack") != transition.attribute("transition_atrack") || oldTransition.attribute("transition_btrack") != transition.attribute("transition_btrack")) + force = true; m_document->renderer()->mltUpdateTransition(oldTransition.attribute("tag"), transition.attribute("tag"), transition.attribute("transition_btrack").toInt(), m_document->tracksCount() - transition.attribute("transition_atrack").toInt(), item->startPos(), item->endPos(), transition, force); //kDebug() << "ORIGINAL TRACK: "<< oldTransition.attribute("transition_btrack") << ", NEW TRACK: "<setTransitionParameters(transition); @@ -2277,7 +2420,7 @@ void CustomTrackView::dropEvent(QDropEvent * event) ItemInfo clipInfo = info; clipInfo.track = m_document->tracksCount() - item->track(); - int worked = m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->producer(item->track()), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); + int worked = m_document->renderer()->mltInsertClip(clipInfo, item->xml(), item->baseClip()->getProducer(item->track()), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); if (worked == -1) { emit displayMessage(i18n("Cannot insert clip in timeline"), ErrorMessage); brokenClips.append(item); @@ -2286,6 +2429,7 @@ void CustomTrackView::dropEvent(QDropEvent * event) adjustTimelineClips(m_scene->editMode(), item, ItemInfo(), addCommand); new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT, false, false, addCommand); + updateTrackDuration(info.track, addCommand); if (item->baseClip()->isTransparent() && getTransitionItemAtStart(info.startPos, info.track) == NULL) { // add transparency transition @@ -2323,7 +2467,12 @@ void CustomTrackView::dropEvent(QDropEvent * event) */ m_pasteEffectsAction->setEnabled(m_copiedItems.count() == 1); - if (items.count() > 1) groupSelectedItems(true); + if (items.count() > 1) { + groupSelectedItems(true); + } else if (items.count() == 1) { + m_dragItem = static_cast (items.at(0)); + emit clipItemSelected((ClipItem*)m_dragItem, -1, false); + } event->setDropAction(Qt::MoveAction); event->accept(); } else QGraphicsView::dropEvent(event); @@ -2371,6 +2520,7 @@ void CustomTrackView::adjustTimelineClips(EDITMODE mode, ClipItem *item, ItemInf } } else if (clip->endPos() <= info.endPos) { new AddTimelineClipCommand(this, clip->xml(), clip->clipProducer(), clip->info(), clip->effectList(), false, false, false, true, command); + m_waitingThumbs.removeAll(clip); scene()->removeItem(clip); delete clip; clip = NULL; @@ -2513,6 +2663,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) m_selectionGroup->translate(0, m_tracksHeight); // adjust track number + Mlt::Tractor *tractor = m_document->renderer()->lockService(); QList children = m_selectionGroup->childItems(); for (int i = 0; i < children.count(); i++) { if (children.at(i)->type() == GROUPWIDGET) { @@ -2529,11 +2680,8 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) if (clip->speed() != 1.0) continue; // We add a move clip command so that we get the correct producer for new track number if (clip->clipType() == AV || clip->clipType() == AUDIO) { - Mlt::Producer *prod; - if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track); - else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer(); - else prod = clip->baseClip()->producer(clipinfo.track); - if (m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) { + Mlt::Producer *prod = clip->getProducer(clipinfo.track); + if (m_document->renderer()->mltUpdateClipProducer(tractor, (int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod) == false) { // problem updating clip emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage); } @@ -2547,6 +2695,7 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) } } resetSelectionGroup(false); + m_document->renderer()->unlockService(tractor); } int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); @@ -2555,12 +2704,14 @@ void CustomTrackView::addTrack(TrackInfo type, int ix) l.setP2(QPointF(l.x2(), maxHeight)); m_guides.at(i)->setLine(l); } - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight); + + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1); setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); viewport()->update(); - emit tracksChanged(); //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged())); //setFixedHeight(50 * m_tracksCount); + + updateTrackNames(ix, true); } void CustomTrackView::removeTrack(int ix) @@ -2586,6 +2737,7 @@ void CustomTrackView::removeTrack(int ix) // Move graphic items qreal ydiff = 0 - (int) m_tracksHeight; m_selectionGroup->translate(0, ydiff); + Mlt::Tractor *tractor = m_document->renderer()->lockService(); // adjust track number QList children = m_selectionGroup->childItems(); @@ -2601,12 +2753,9 @@ void CustomTrackView::removeTrack(int ix) clip->updateItem(); ItemInfo clipinfo = clip->info(); // We add a move clip command so that we get the correct producer for new track number - if (clip->clipType() == AV || clip->clipType() == AUDIO) { - Mlt::Producer *prod; - if (clip->isAudioOnly()) prod = clip->baseClip()->audioProducer(clipinfo.track); - else if (clip->isVideoOnly()) prod = clip->baseClip()->videoProducer(); - else prod = clip->baseClip()->producer(clipinfo.track); - if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) { + if (clip->clipType() == AV || clip->clipType() == AUDIO || clip->clipType() == PLAYLIST) { + Mlt::Producer *prod = clip->getProducer(clipinfo.track); + if (prod == NULL || !m_document->renderer()->mltUpdateClipProducer(tractor, (int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", clipinfo.startPos.frames(m_document->fps()), clipinfo.track), ErrorMessage); } } @@ -2621,6 +2770,7 @@ void CustomTrackView::removeTrack(int ix) } } resetSelectionGroup(false); + m_document->renderer()->unlockService(tractor); int maxHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); for (int i = 0; i < m_guides.count(); i++) { @@ -2628,12 +2778,13 @@ void CustomTrackView::removeTrack(int ix) l.setP2(QPointF(l.x2(), maxHeight)); m_guides.at(i)->setLine(l); } - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), maxHeight - 1); setSceneRect(0, 0, sceneRect().width(), m_tracksHeight * m_document->tracksCount()); m_selectedTrack = qMin(m_selectedTrack, m_document->tracksCount() - 1); viewport()->update(); - emit tracksChanged(); + + updateTrackNames(ix, false); //QTimer::singleShot(500, this, SIGNAL(trackHeightChanged())); } @@ -2642,10 +2793,11 @@ void CustomTrackView::configTracks(QList < TrackInfo > trackInfos) for (int i = 0; i < trackInfos.count(); ++i) { m_document->setTrackType(i, trackInfos.at(i)); m_document->renderer()->mltChangeTrackState(i + 1, m_document->trackInfoAt(i).isMute, m_document->trackInfoAt(i).isBlind); + lockTrack(m_document->tracksCount() - i - 1, m_document->trackInfoAt(i).isLocked, false); } - QTimer::singleShot(300, this, SIGNAL(trackHeightChanged())); viewport()->update(); + emit trackHeightChanged(); } void CustomTrackView::slotSwitchTrackAudio(int ix) @@ -2667,24 +2819,71 @@ void CustomTrackView::slotSwitchTrackLock(int ix) } -void CustomTrackView::lockTrack(int ix, bool lock) +void CustomTrackView::lockTrack(int ix, bool lock, bool requestUpdate) { int tracknumber = m_document->tracksCount() - ix - 1; m_document->switchTrackLock(tracknumber, lock); - emit doTrackLock(ix, lock); + if (requestUpdate) + emit doTrackLock(ix, lock); AbstractClipItem *clip = NULL; QList selection = m_scene->items(0, ix * m_tracksHeight + m_tracksHeight / 2, sceneRect().width(), m_tracksHeight / 2 - 2); for (int i = 0; i < selection.count(); i++) { - if (selection.at(i)->type() != AVWIDGET && selection.at(i)->type() != TRANSITIONWIDGET) continue; - if (selection.at(i)->isSelected()) { - if (selection.at(i)->type() == AVWIDGET) emit clipItemSelected(NULL); - else emit transitionItemSelected(NULL); + if (selection.at(i)->type() == GROUPWIDGET && (AbstractGroupItem *)selection.at(i) != m_selectionGroup) { + if (selection.at(i)->parentItem() && m_selectionGroup) { + selection.removeAll((QGraphicsItem*)m_selectionGroup); + resetSelectionGroup(); + } + + bool changeGroupLock = true; + bool hasClipOnTrack = false; + QList children = selection.at(i)->childItems(); + for (int j = 0; j < children.count(); ++j) { + if (children.at(j)->isSelected()) { + if (children.at(j)->type() == AVWIDGET) + emit clipItemSelected(NULL); + else if (children.at(j)->type() == TRANSITIONWIDGET) + emit transitionItemSelected(NULL); + else + continue; + } + + AbstractClipItem * child = static_cast (children.at(j)); + if (child == m_dragItem) + m_dragItem = NULL; + + // only unlock group, if it is not locked by another track too + if (!lock && child->track() != ix && m_document->trackInfoAt(m_document->tracksCount() - child->track() - 1).isLocked) + changeGroupLock = false; + + // only (un-)lock if at least one clip is on the track + if (child->track() == ix) + hasClipOnTrack = true; + } + if (changeGroupLock && hasClipOnTrack) + ((AbstractGroupItem*)selection.at(i))->setItemLocked(lock); + } else if((selection.at(i)->type() == AVWIDGET || selection.at(i)->type() == TRANSITIONWIDGET)) { + if (selection.at(i)->parentItem()) { + if (selection.at(i)->parentItem() == m_selectionGroup) { + selection.removeAll((QGraphicsItem*)m_selectionGroup); + resetSelectionGroup(); + } else { + // groups are handled separately + continue; + } + } + + if (selection.at(i)->isSelected()) { + if (selection.at(i)->type() == AVWIDGET) + emit clipItemSelected(NULL); + else + emit transitionItemSelected(NULL); + } + clip = static_cast (selection.at(i)); + clip->setItemLocked(lock); + if (clip == m_dragItem) + m_dragItem = NULL; } - clip = static_cast (selection.at(i)); - clip->setItemLocked(lock); - if (clip == m_dragItem) - m_dragItem = NULL; } kDebug() << "NEXT TRK STATE: " << m_document->trackInfoAt(tracknumber).isLocked; viewport()->update(); @@ -2724,9 +2923,16 @@ void CustomTrackView::slotRemoveSpace() int track = 0; if (m_menuPosition.isNull()) { pos = GenTime(cursorPos(), m_document->fps()); - bool ok; - track = QInputDialog::getInteger(this, i18n("Remove Space"), i18n("Track"), 0, 0, m_document->tracksCount() - 1, 1, &ok); - if (!ok) return; + + TrackDialog d(m_document, parentWidget()); + d.comboTracks->setCurrentIndex(m_selectedTrack); + d.label->setText(i18n("Track")); + d.before_select->setHidden(true); + d.setWindowTitle(i18n("Remove Space")); + d.video_track->setHidden(true); + d.audio_track->setHidden(true); + if (d.exec() != QDialog::Accepted) return; + track = d.comboTracks->currentIndex(); } else { pos = GenTime((int)(mapToScene(m_menuPosition).x()), m_document->fps()); track = (int)(mapToScene(m_menuPosition).y() / m_tracksHeight); @@ -2743,7 +2949,6 @@ void CustomTrackView::slotRemoveSpace() return; } int length = m_document->renderer()->mltGetSpaceLength(pos, m_document->tracksCount() - track, true); - //kDebug() << "// GOT LENGT; " << length; if (length <= 0) { emit displayMessage(i18n("You must be in an empty space to remove space (time: %1, track: %2)", m_document->timecode().getTimecodeFromFrames(mapToScene(m_menuPosition).x()), track), ErrorMessage); return; @@ -2775,7 +2980,40 @@ void CustomTrackView::slotRemoveSpace() } } + if (!transitionsToMove.isEmpty()) { + // Make sure that by moving the items, we don't get a transition collision + // Find first transition + ItemInfo info = transitionsToMove.at(0); + for (int i = 1; i < transitionsToMove.count(); i++) + if (transitionsToMove.at(i).startPos < info.startPos) info = transitionsToMove.at(i); + + // make sure there are no transitions on the way + QRectF rect(info.startPos.frames(m_document->fps()) - length, track * m_tracksHeight + m_tracksHeight / 2, length - 1, m_tracksHeight / 2 - 2); + items = scene()->items(rect); + int transitionCorrection = -1; + for (int i = 0; i < items.count(); i++) { + if (items.at(i)->type() == TRANSITIONWIDGET) { + // There is a transition on the way + AbstractClipItem *item = static_cast (items.at(i)); + int transitionEnd = item->endPos().frames(m_document->fps()); + if (transitionEnd > transitionCorrection) transitionCorrection = transitionEnd; + } + } + + if (transitionCorrection > 0) { + // We need to fix the move length + length = info.startPos.frames(m_document->fps()) - transitionCorrection; + } + + // Make sure we don't send transition before 0 + if (info.startPos.frames(m_document->fps()) < length) { + // reduce length to maximum possible + length = info.startPos.frames(m_document->fps()); + } + } + InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, GenTime(-length, m_document->fps()), true); + updateTrackDuration(track, command); m_commandStack->push(command); } @@ -2795,7 +3033,7 @@ void CustomTrackView::slotInsertSpace() track = d.selectedTrack(); QList items; - if (track > 0) { + if (track >= 0) { if (m_document->isTrackLocked(m_document->tracksCount() - track - 1)) { emit displayMessage(i18n("Cannot insert space in a locked track"), ErrorMessage); return; @@ -2834,11 +3072,12 @@ void CustomTrackView::slotInsertSpace() if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) { InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, spaceDuration, true); + updateTrackDuration(track, command); m_commandStack->push(command); } } -void CustomTrackView::insertSpace(QList clipsToMove, QList transToMove, int track, const GenTime duration, const GenTime offset) +void CustomTrackView::insertSpace(QList clipsToMove, QList transToMove, int track, const GenTime &duration, const GenTime &offset) { int diff = duration.frames(m_document->fps()); resetSelectionGroup(); @@ -2928,8 +3167,12 @@ void CustomTrackView::deleteClip(const QString &clipId) } } deleteCommand->setText(i18np("Delete timeline clip", "Delete timeline clips", count)); - if (count == 0) delete deleteCommand; - else m_commandStack->push(deleteCommand); + if (count == 0) { + delete deleteCommand; + } else { + updateTrackDuration(-1, deleteCommand); + m_commandStack->push(deleteCommand); + } } void CustomTrackView::setCursorPos(int pos, bool seek) @@ -2937,7 +3180,7 @@ void CustomTrackView::setCursorPos(int pos, bool seek) if (pos == m_cursorPos) return; emit cursorMoved((int)(m_cursorPos), (int)(pos)); m_cursorPos = pos; - if (seek) m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps())); + if (seek) m_document->renderer()->seek(m_cursorPos); else if (m_autoScroll) checkScrolling(); m_cursorLine->setPos(m_cursorPos, 0); } @@ -2958,7 +3201,7 @@ void CustomTrackView::moveCursorPos(int delta) emit cursorMoved((int)(m_cursorPos), (int)((m_cursorPos + delta))); m_cursorPos += delta; m_cursorLine->setPos(m_cursorPos, 0); - m_document->renderer()->seek(GenTime(m_cursorPos, m_document->fps())); + m_document->renderer()->seek(m_cursorPos); } void CustomTrackView::initCursorPos(int pos) @@ -3049,6 +3292,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) { InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false); + updateTrackDuration(track, command); m_commandStack->push(command); if (track != -1) track = m_document->tracksCount() - track; kDebug() << "SPACER TRACK:" << track; @@ -3059,7 +3303,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) resetSelectionGroup(false); m_operationMode = NONE; } else if (m_operationMode == RUBBERSELECTION) { - //kDebug() << "// END RUBBER SELECT"; resetSelectionGroup(); groupSelectedItems(); m_operationMode = NONE; @@ -3078,10 +3321,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) // we are moving one clip, easy if (m_dragItem->type() == AVWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) { ClipItem *item = static_cast (m_dragItem); - Mlt::Producer *prod; - if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(info.track); - else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer(); - else prod = item->baseClip()->producer(info.track); + Mlt::Producer *prod = item->getProducer(info.track); bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - info.track), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(info.startPos.frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); if (success) { @@ -3192,6 +3432,9 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } } } + updateTrackDuration(info.track, moveCommand); + if (m_dragItemInfo.track != info.track) + updateTrackDuration(m_dragItemInfo.track, moveCommand); m_commandStack->push(moveCommand); //checkTrackSequence(m_dragItem->track()); } else { @@ -3215,6 +3458,9 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) moveCommand->setText(i18n("Move transition")); adjustTimelineTransitions(m_scene->editMode(), transition, moveCommand); new MoveTransitionCommand(this, m_dragItemInfo, info, false, moveCommand); + updateTrackDuration(info.track, moveCommand); + if (m_dragItemInfo.track != info.track) + updateTrackDuration(m_dragItemInfo.track, moveCommand); m_commandStack->push(moveCommand); setDocumentModified(); } @@ -3234,7 +3480,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) GenTime timeOffset = GenTime(m_dragItem->scenePos().x(), m_document->fps()) - m_dragItemInfo.startPos; const int trackOffset = (int)(m_dragItem->scenePos().y() / m_tracksHeight) - m_dragItemInfo.track; - //kDebug() << "// MOVED SEVERAL CLIPS" << timeOffset.frames(25); + QUndoCommand *moveGroup = new QUndoCommand(); moveGroup->setText(i18n("Move group")); if (timeOffset != GenTime() || trackOffset != 0) { @@ -3281,16 +3527,10 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (item->type() == AVWIDGET) { ClipItem *clip = static_cast (item); + int trackProducer = info.track; info.track = m_document->tracksCount() - info.track; - Mlt::Producer *prod; adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup); - if (clip->isAudioOnly()) - prod = clip->baseClip()->audioProducer(info.track); - else if (clip->isVideoOnly()) - prod = clip->baseClip()->videoProducer(); - else - prod = clip->baseClip()->producer(info.track); - m_document->renderer()->mltInsertClip(info, clip->xml(), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); + m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(trackProducer), m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); for (int i = 0; i < clip->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false); } @@ -3306,6 +3546,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } } new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false, moveGroup); + updateTrackDuration(-1, moveGroup); m_commandStack->push(moveGroup); //QPointF top = group->sceneBoundingRect().topLeft(); @@ -3331,6 +3572,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) items.at(i)->parentItem()->setSelected(true); } } + resetSelectionGroup(); groupSelectedItems(); } else { rebuildGroup((AbstractGroupItem *)group); @@ -3341,7 +3583,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) m_document->renderer()->doRefresh(); } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) { // resize start - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) { QUndoCommand *resizeCommand = new QUndoCommand(); @@ -3365,7 +3607,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) } } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) { // resize end - if (event->modifiers() != Qt::ControlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (!m_controlModifier && m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { AbstractGroupItem *parent = static_cast (m_dragItem->parentItem()); if (parent) { QUndoCommand *resizeCommand = new QUndoCommand(); @@ -3382,6 +3624,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) ++itemcount; } } + updateTrackDuration(-1, resizeCommand); m_commandStack->push(resizeCommand); } } else { @@ -3489,7 +3732,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int start = item->cropStart().frames(m_document->fps()); int end = (item->cropStart() + item->cropDuration()).frames(m_document->fps()) - 1; - if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end) { + if ((val < -50 || val > 150) && item->editedKeyFramePos() != start && item->editedKeyFramePos() != end && item->keyFrameNumber() > 1) { //delete keyframe item->movedKeyframe(item->getEffectAt(item->selectedEffectIndex()), item->selectedKeyFramePos(), -1, 0); } else { @@ -3526,11 +3769,18 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) void CustomTrackView::deleteClip(ItemInfo info, bool refresh) { ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track); - + m_ct++; + if (!item) kDebug()<<"// PROBLEM FINDING CLIP ITEM TO REMOVVE!!!!!!!!!"; + else kDebug()<<"// deleting CLIP: "<fps())<<", "<baseClip()->fileURL(); + //m_document->renderer()->saveSceneList(QString("/tmp/error%1.mlt").arg(m_ct), QDomElement()); if (!item || m_document->renderer()->mltRemoveClip(m_document->tracksCount() - info.track, info.startPos) == false) { emit displayMessage(i18n("Error removing clip at %1 on track %2", m_document->timecode().getTimecodeFromFrames(info.startPos.frames(m_document->fps())), info.track), ErrorMessage); + kDebug()<<"CANNOT REMOVE: "<fps())<<", TK: "<renderer()->saveSceneList(QString("/tmp/error%1.mlt").arg(m_ct), QDomElement()); + exit(1); return; } + m_waitingThumbs.removeAll(item); if (item->isSelected()) emit clipItemSelected(NULL); item->baseClip()->removeReference(); m_document->updateClip(item->baseClip()->getId()); @@ -3544,8 +3794,9 @@ void CustomTrackView::deleteClip(ItemInfo info, bool refresh) delete tr; } }*/ - m_waitingThumbs.removeAll(item); + if (m_dragItem == item) m_dragItem = NULL; + #if QT_VERSION >= 0x040600 // animate item deletion item->closeAnimation(); @@ -3576,7 +3827,6 @@ void CustomTrackView::deleteSelectedClips() scene()->clearSelection(); QUndoCommand *deleteSelected = new QUndoCommand(); - bool resetGroup = false; int groupCount = 0; int clipCount = 0; int transitionCount = 0; @@ -3587,7 +3837,6 @@ void CustomTrackView::deleteSelectedClips() QList children = itemList.at(i)->childItems(); QList clipInfos; QList transitionInfos; - GenTime currentPos = GenTime(m_cursorPos, m_document->fps()); for (int j = 0; j < children.count(); j++) { if (children.at(j)->type() == AVWIDGET) { AbstractClipItem *clip = static_cast (children.at(j)); @@ -3613,7 +3862,6 @@ void CustomTrackView::deleteSelectedClips() if (itemList.at(i)->type() == AVWIDGET) { clipCount++; ClipItem *item = static_cast (itemList.at(i)); - if (item->parentItem()) resetGroup = true; //kDebug()<<"// DELETE CLP AT: "<info().startPos.frames(25); new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, true, true, deleteSelected); emit clipItemSelected(NULL); @@ -3621,7 +3869,6 @@ void CustomTrackView::deleteSelectedClips() transitionCount++; Transition *item = static_cast (itemList.at(i)); //kDebug()<<"// DELETE TRANS AT: "<info().startPos.frames(25); - if (item->parentItem()) resetGroup = true; new AddTransitionCommand(this, item->info(), item->transitionEndTrack(), item->toXML(), true, true, deleteSelected); emit transitionItemSelected(NULL); } @@ -3633,11 +3880,13 @@ void CustomTrackView::deleteSelectedClips() else if (transitionCount > 0 && groupCount == 0 && clipCount == 0) deleteSelected->setText(i18np("Delete selected transition", "Delete selected transitions", transitionCount)); else deleteSelected->setText(i18n("Delete selected items")); + updateTrackDuration(-1, deleteSelected); m_commandStack->push(deleteSelected); } void CustomTrackView::changeClipSpeed() { + // TODO: remove after string freeze QList itemList = scene()->selectedItems(); if (itemList.count() == 0) { emit displayMessage(i18n("Select clip to change speed"), ErrorMessage); @@ -3651,7 +3900,6 @@ void CustomTrackView::changeClipSpeed() for (int i = 0; i < itemList.count(); i++) { if (itemList.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast (itemList.at(i)); - ItemInfo info = item->info(); if (percent == -1) percent = QInputDialog::getInteger(this, i18n("Edit Clip Speed"), i18n("New speed (percents)"), item->speed() * 100, 1, 10000, 1, &ok); if (!ok) break; double speed = (double) percent / 100.0; @@ -3667,7 +3915,9 @@ void CustomTrackView::changeClipSpeed() void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, const double speed, const double oldspeed, int strobe, const QString &id) { - DocClipBase *baseclip = m_document->clipManager()->getClipById(id); + Q_UNUSED(id) + //DocClipBase *baseclip = m_document->clipManager()->getClipById(id); + ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track); if (!item) { kDebug() << "ERROR: Cannot find clip for speed change"; @@ -3675,22 +3925,17 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant return; } info.track = m_document->tracksCount() - item->track(); - int endPos; - if (item->isVideoOnly()) - endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->videoProducer()); - else if (item->isAudioOnly()) - endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->audioProducer(item->track())); - else - endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, baseclip->producer()); + int endPos = m_document->renderer()->mltChangeClipSpeed(info, speedIndependantInfo, speed, oldspeed, strobe, item->getProducer(item->track(), false)); if (endPos >= 0) { item->setSpeed(speed, strobe); item->updateRectGeometry(); - if (item->cropDuration().frames(m_document->fps()) != endPos) { + if (item->cropDuration().frames(m_document->fps()) != endPos) item->resizeEnd((int) info.startPos.frames(m_document->fps()) + endPos - 1); - } updatePositionEffects(item, info); setDocumentModified(); - } else emit displayMessage(i18n("Invalid clip"), ErrorMessage); + } else { + emit displayMessage(i18n("Invalid clip"), ErrorMessage); + } } void CustomTrackView::cutSelectedClips() @@ -3804,7 +4049,6 @@ void CustomTrackView::groupClips(bool group) QList itemList = scene()->selectedItems(); QList clipInfos; QList transitionInfos; - GenTime currentPos = GenTime(m_cursorPos, m_document->fps()); // Expand groups int max = itemList.count(); @@ -3871,7 +4115,6 @@ void CustomTrackView::doGroupClips(QList clipInfos, QList clip->setSelected(true); } } - groupSelectedItems(false, true); setDocumentModified(); } @@ -3884,18 +4127,18 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i return; } - if (baseclip->producer() == NULL) { + if (baseclip->getProducer() == NULL) { // If the clip has no producer, we must wait until it is created... m_mutex.lock(); emit displayMessage(i18n("Waiting for clip..."), InformationMessage); emit forceClipProcessing(clipId); qApp->processEvents(); for (int i = 0; i < 3; i++) { - if (baseclip->producer() == NULL) { + if (baseclip->getProducer() == NULL) { m_producerNotReady.wait(&m_mutex, 500 + 500 * i); } else break; } - if (baseclip->producer() == NULL) { + if (baseclip->getProducer() == NULL) { emit displayMessage(i18n("Cannot insert clip..."), ErrorMessage); m_mutex.unlock(); return; @@ -3904,12 +4147,13 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i m_mutex.unlock(); } - ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt()); + ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt(), getFrameWidth()); item->setEffectList(effects); if (xml.hasAttribute("audio_only")) item->setAudioOnly(true); else if (xml.hasAttribute("video_only")) item->setVideoOnly(true); scene()->addItem(item); + int producerTrack = info.track; int tracknumber = m_document->tracksCount() - info.track - 1; bool isLocked = m_document->trackInfoAt(tracknumber).isLocked; if (isLocked) item->setItemLocked(true); @@ -3917,38 +4161,51 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i baseclip->addReference(); m_document->updateClip(baseclip->getId()); info.track = m_document->tracksCount() - info.track; - Mlt::Producer *prod; - if (item->isAudioOnly()) prod = baseclip->audioProducer(info.track); - else if (item->isVideoOnly()) prod = baseclip->videoProducer(); - else prod = baseclip->producer(info.track); - m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push); + m_document->renderer()->mltInsertClip(info, xml, item->getProducer(producerTrack), overwrite, push); for (int i = 0; i < item->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false); } setDocumentModified(); - if (refresh) m_document->renderer()->doRefresh(); - if (!baseclip->isPlaceHolder()) m_waitingThumbs.append(item); + if (refresh) + m_document->renderer()->doRefresh(); + if (!baseclip->isPlaceHolder()) + m_waitingThumbs.append(item); m_thumbsTimer.start(); } void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload) { + QMutexLocker locker(&m_mutex); QList list = scene()->items(); + QList clipList; ClipItem *clip = NULL; + DocClipBase *baseClip = NULL; + Mlt::Tractor *tractor = m_document->renderer()->lockService(); for (int i = 0; i < list.size(); ++i) { if (list.at(i)->type() == AVWIDGET) { clip = static_cast (list.at(i)); if (clip->clipProducer() == clipId) { + if (baseClip == NULL) { + baseClip = clip->baseClip(); + } ItemInfo info = clip->info(); - info.track = m_document->tracksCount() - clip->track(); - if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer())) { + Mlt::Producer *prod = NULL; + if (clip->isAudioOnly()) prod = baseClip->audioProducer(info.track); + else if (clip->isVideoOnly()) prod = baseClip->videoProducer(); + else prod = baseClip->getProducer(info.track); + if (reload && !m_document->renderer()->mltUpdateClip(tractor, info, clip->xml(), prod)) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage); } - clip->refreshClip(true); - clip->update(); + else clipList.append(clip); } } } + m_document->renderer()->unlockService(tractor); + for (int i = 0; i < clipList.count(); i++) + clipList.at(i)->refreshClip(true, true); + if (baseClip) { + baseClip->cleanupProducers(); + } } ClipItem *CustomTrackView::getClipItemAtEnd(GenTime pos, int track) @@ -4055,7 +4312,7 @@ Transition *CustomTrackView::getTransitionItemAtStart(GenTime pos, int track) return clip; } -void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool refresh) +void CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool refresh) { if (m_selectionGroup) resetSelectionGroup(false); ClipItem *item = getClipItemAt((int) start.startPos.frames(m_document->fps()), start.track); @@ -4064,10 +4321,7 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool re kDebug() << "---------------- ERROR, CANNOT find clip to move at.. "; return; } - Mlt::Producer *prod; - if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(end.track); - else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer(); - else prod = item->baseClip()->producer(end.track); + Mlt::Producer *prod = item->getProducer(end.track); bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), (int) start.startPos.frames(m_document->fps()), (int)end.startPos.frames(m_document->fps()), prod); if (success) { @@ -4099,14 +4353,11 @@ void CustomTrackView::moveClip(const ItemInfo start, const ItemInfo end, bool re emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(end.startPos.frames(m_document->fps()))), ErrorMessage); } if (refresh) m_document->renderer()->doRefresh(); - //kDebug() << " // MOVED CLIP TO: " << end.startPos.frames(25) << ", ITEM START: " << item->startPos().frames(25); } -void CustomTrackView::moveGroup(QList startClip, QList startTransition, const GenTime offset, const int trackOffset, bool reverseMove) +void CustomTrackView::moveGroup(QList startClip, QList startTransition, const GenTime &offset, const int trackOffset, bool reverseMove) { // Group Items - /*kDebug() << "//GRP MOVE, REVERS:" << reverseMove; - kDebug() << "// GROUP MOV; OFFSET: " << offset.frames(25) << ", TK OFF: " << trackOffset;*/ resetSelectionGroup(); m_scene->clearSelection(); @@ -4119,7 +4370,6 @@ void CustomTrackView::moveGroup(QList startClip, QList sta startClip[i].startPos = startClip.at(i).startPos - offset; startClip[i].track = startClip.at(i).track - trackOffset; } - //kDebug()<<"//LKING FR CLIP AT:"<setItemLocked(false); @@ -4190,15 +4440,9 @@ void CustomTrackView::moveGroup(QList startClip, QList sta if (item->type() == AVWIDGET) { ClipItem *clip = static_cast (item); + int trackProducer = info.track; info.track = m_document->tracksCount() - info.track; - Mlt::Producer *prod; - if (clip->isAudioOnly()) - prod = clip->baseClip()->audioProducer(info.track); - else if (clip->isVideoOnly()) - prod = clip->baseClip()->videoProducer(); - else - prod = clip->baseClip()->producer(info.track); - m_document->renderer()->mltInsertClip(info, clip->xml(), prod); + m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(trackProducer)); for (int i = 0; i < clip->effectsCount(); i++) { m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false); } @@ -4229,7 +4473,7 @@ void CustomTrackView::moveGroup(QList startClip, QList sta } else kDebug() << "///////// WARNING; NO GROUP TO MOVE"; } -void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, bool m_refresh) +void CustomTrackView::moveTransition(const ItemInfo &start, const ItemInfo &end, bool m_refresh) { Transition *item = getTransitionItemAt(start.startPos, start.track); if (!item) { @@ -4237,10 +4481,10 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, b kDebug() << "---------------- ERROR, CANNOT find transition to move... ";// << startPos.x() * m_scale * FRAME_SIZE + 1 << ", " << startPos.y() * m_tracksHeight + m_tracksHeight / 2; return; } - //kDebug() << "---------------- Move TRANSITION FROM: " << startPos.x() << ", END:" << endPos.x() << ",TRACKS: " << oldtrack << " TO " << newtrack; + bool snap = KdenliveSettings::snaptopoints(); KdenliveSettings::setSnaptopoints(false); - //kDebug()<<"/// RESIZE TRANS START: ("<< startPos.x()<<"x"<< startPos.y()<<") / ("<setPos((int) end.startPos.frames(m_document->fps()), (end.track) * m_tracksHeight + 1); @@ -4277,7 +4521,7 @@ void CustomTrackView::moveTransition(const ItemInfo start, const ItemInfo end, b setDocumentModified(); } -void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool dontWorry) +void CustomTrackView::resizeClip(const ItemInfo &start, const ItemInfo &end, bool dontWorry) { bool resizeClipStart = (start.startPos != end.startPos); ClipItem *item = getClipItemAtStart(start.startPos, start.track); @@ -4294,23 +4538,23 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool bool snap = KdenliveSettings::snaptopoints(); KdenliveSettings::setSnaptopoints(false); + if (resizeClipStart) { ItemInfo clipinfo = item->info(); clipinfo.track = m_document->tracksCount() - clipinfo.track; bool success = m_document->renderer()->mltResizeClipStart(clipinfo, end.startPos - clipinfo.startPos); - if (success) { - kDebug() << "RESIZE CLP STRAT TO:" << end.startPos.frames(m_document->fps()) << ", OLD ST: " << start.startPos.frames(25); + if (success) item->resizeStart((int) end.startPos.frames(m_document->fps())); - updatePositionEffects(item, clipinfo); - } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); + else + emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); } else { ItemInfo clipinfo = item->info(); clipinfo.track = m_document->tracksCount() - clipinfo.track; bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, end.endPos - clipinfo.startPos); - if (success) { + if (success) item->resizeEnd((int) end.endPos.frames(m_document->fps())); - updatePositionEffects(item, clipinfo); - } else emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); + else + emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); } if (!resizeClipStart && end.cropStart != start.cropStart) { kDebug() << "// RESIZE CROP, DIFF: " << (end.cropStart - start.cropStart).frames(25); @@ -4383,39 +4627,15 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol } ClipItem *clip = static_cast < ClipItem * >(item); - updatePositionEffects(clip, oldInfo); - - // check keyframes - QDomDocument doc; - QDomElement root = doc.createElement("list"); - doc.appendChild(root); - QList indexes; - for (int i = 0; i < clip->effectsCount(); i++) { - QDomElement effect = clip->effectAt(i); - if (EffectsList::hasKeyFrames(effect)) { - doc.appendChild(doc.importNode(effect, true)); - indexes.append(i); - } - } - - if (clip->checkEffectsKeyframesPos(oldInfo.cropStart.frames(m_document->fps()), clip->cropStart().frames(m_document->fps()), true)) { - // Keyframes were modified, updateClip - QDomNodeList effs = doc.elementsByTagName("effect"); - // Hack: - // Since we must always resize clip before updating the keyframes, we - // put a resize command before & after checking keyframes so that - // we are sure the resize is performed before whenever we do or undo the action - new ResizeClipCommand(this, oldInfo, info, false, true, command); - for (int i = 0; i < indexes.count(); i++) { - new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command); - updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i)); - } - new ResizeClipCommand(this, oldInfo, info, false, true, command); - emit clipItemSelected(clip); - } else { - new ResizeClipCommand(this, oldInfo, info, false, false, command); - } + // Hack: + // Since we must always resize clip before updating the keyframes, we + // put a resize command before & after checking keyframes so that + // we are sure the resize is performed before whenever we do or undo the action + new ResizeClipCommand(this, oldInfo, info, false, true, command); + adjustEffects(clip, oldInfo, command); + new ResizeClipCommand(this, oldInfo, info, false, true, command); + emit clipItemSelected(clip); } else { KdenliveSettings::setSnaptopoints(false); item->resizeStart((int) oldInfo.startPos.frames(m_document->fps())); @@ -4466,7 +4686,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI hasParentCommand = true; } else { command = new QUndoCommand(); - command->setText(i18n("Resize clip end")); } // do this here, too, because otherwise undo won't update the group @@ -4475,9 +4694,10 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI ItemInfo info = item->info(); if (item->type() == AVWIDGET) { + if (!hasParentCommand) command->setText(i18n("Resize clip end")); ItemInfo resizeinfo = info; resizeinfo.track = m_document->tracksCount() - resizeinfo.track; - bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos); + bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.cropDuration); if (success) { // Check if there is an automatic transition on that clip (lower track) Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track); @@ -4501,40 +4721,16 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI } - // check keyframes ClipItem *clip = static_cast < ClipItem * >(item); - QDomDocument doc; - QDomElement root = doc.createElement("list"); - doc.appendChild(root); - QList indexes; - for (int i = 0; i < clip->effectsCount(); i++) { - QDomElement effect = clip->effectAt(i); - if (EffectsList::hasKeyFrames(effect)) { - doc.appendChild(doc.importNode(effect, true)); - indexes.append(i); - } - } - - if (clip->checkEffectsKeyframesPos((oldInfo.cropStart + oldInfo.endPos - oldInfo.startPos).frames(m_document->fps()) - 1, (clip->cropStart() + clip->cropDuration()).frames(m_document->fps()) - 1, false)) { - // Keyframes were modified, updateClip - QDomNodeList effs = doc.elementsByTagName("effect"); - // Hack: - // Since we must always resize clip before updating the keyframes, we - // put a resize command before & after checking keyframes so that - // we are sure the resize is performed before whenever we do or undo the action - - new ResizeClipCommand(this, oldInfo, info, false, true, command); - for (int i = 0; i < indexes.count(); i++) { - new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), effs.at(i).cloneNode().toElement(), clip->effectAt(indexes.at(i)), indexes.at(i), false, command); - updateEffect(m_document->tracksCount() - clip->track(), clip->startPos(), clip->effectAt(indexes.at(i)), indexes.at(i)); - } - new ResizeClipCommand(this, oldInfo, info, false, true, command); - emit clipItemSelected(clip); - } else { - new ResizeClipCommand(this, oldInfo, info, false, false, command); - } - updatePositionEffects(clip, oldInfo); + // Hack: + // Since we must always resize clip before updating the keyframes, we + // put a resize command before & after checking keyframes so that + // we are sure the resize is performed before whenever we do or undo the action + new ResizeClipCommand(this, oldInfo, info, false, true, command); + adjustEffects(clip, oldInfo, command); + new ResizeClipCommand(this, oldInfo, info, false, true, command); + emit clipItemSelected(clip); } else { KdenliveSettings::setSnaptopoints(false); item->resizeEnd((int) oldInfo.endPos.frames(m_document->fps())); @@ -4542,6 +4738,7 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); } } else if (item->type() == TRANSITIONWIDGET) { + if (!hasParentCommand) command->setText(i18n("Resize transition end")); Transition *transition = static_cast (item); if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - oldInfo.track), (int)(m_document->tracksCount() - oldInfo.track), transition->transitionEndTrack(), oldInfo.startPos, oldInfo.endPos, info.startPos, info.endPos)) { // Cannot resize transition @@ -4550,26 +4747,33 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI KdenliveSettings::setSnaptopoints(true); emit displayMessage(i18n("Cannot resize transition"), ErrorMessage); } else { - MoveTransitionCommand *moveCommand = new MoveTransitionCommand(this, oldInfo, info, false, command); - if (command == NULL) - m_commandStack->push(moveCommand); + // Check transition keyframes + QDomElement old = transition->toXML(); + if (transition->updateKeyframes()) { + QDomElement xml = transition->toXML(); + m_document->renderer()->mltUpdateTransition(xml.attribute("tag"), xml.attribute("tag"), xml.attribute("transition_btrack").toInt(), m_document->tracksCount() - xml.attribute("transition_atrack").toInt(), transition->startPos(), transition->endPos(), xml); + new EditTransitionCommand(this, transition->track(), transition->startPos(), old, xml, false, command); + } + new MoveTransitionCommand(this, oldInfo, info, false, command); } } if (item->parentItem() && item->parentItem() != m_selectionGroup) new RebuildGroupCommand(this, item->info().track, item->startPos(), command); - if (!hasParentCommand) + if (!hasParentCommand) { + updateTrackDuration(oldInfo.track, command); m_commandStack->push(command); + } } -void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) +void CustomTrackView::updatePositionEffects(ClipItem* item, ItemInfo info, bool standalone) { int end = item->fadeIn(); if (end != 0) { // there is a fade in effect int effectPos = item->hasEffect("volume", "fadein"); if (effectPos != -1) { - QDomElement oldeffect = item->effectAt(effectPos); + QDomElement effect = item->getEffectAt(effectPos); int start = item->cropStart().frames(m_document->fps()); int max = item->cropDuration().frames(m_document->fps()); if (end > max) { @@ -4578,16 +4782,19 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) end = item->fadeIn(); } end += start; - EffectsList::setParameter(oldeffect, "in", QString::number(start)); - EffectsList::setParameter(oldeffect, "out", QString::number(end)); - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect))) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - // if fade effect is displayed, update the effect edit widget with new clip duration - if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos); + EffectsList::setParameter(effect, "in", QString::number(start)); + EffectsList::setParameter(effect, "out", QString::number(end)); + if (standalone) { + if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect))) + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + // if fade effect is displayed, update the effect edit widget with new clip duration + if (item->isSelected() && effectPos == item->selectedEffectIndex()) + emit clipItemSelected(item, effectPos); + } } effectPos = item->hasEffect("brightness", "fade_from_black"); if (effectPos != -1) { - QDomElement oldeffect = item->effectAt(effectPos); + QDomElement effect = item->getEffectAt(effectPos); int start = item->cropStart().frames(m_document->fps()); int max = item->cropDuration().frames(m_document->fps()); if (end > max) { @@ -4596,20 +4803,24 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) end = item->fadeIn(); } end += start; - EffectsList::setParameter(oldeffect, "in", QString::number(start)); - EffectsList::setParameter(oldeffect, "out", QString::number(end)); - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect))) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - // if fade effect is displayed, update the effect edit widget with new clip duration - if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos); + EffectsList::setParameter(effect, "in", QString::number(start)); + EffectsList::setParameter(effect, "out", QString::number(end)); + if (standalone) { + if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect))) + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + // if fade effect is displayed, update the effect edit widget with new clip duration + if (item->isSelected() && effectPos == item->selectedEffectIndex()) + emit clipItemSelected(item, effectPos); + } } } + int start = item->fadeOut(); if (start != 0) { // there is a fade out effect int effectPos = item->hasEffect("volume", "fadeout"); if (effectPos != -1) { - QDomElement oldeffect = item->effectAt(effectPos); + QDomElement effect = item->getEffectAt(effectPos); int max = item->cropDuration().frames(m_document->fps()); int end = max + item->cropStart().frames(m_document->fps()); if (start > max) { @@ -4618,16 +4829,19 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) start = item->fadeOut(); } start = end - start; - EffectsList::setParameter(oldeffect, "in", QString::number(start)); - EffectsList::setParameter(oldeffect, "out", QString::number(end)); - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect))) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - // if fade effect is displayed, update the effect edit widget with new clip duration - if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos); + EffectsList::setParameter(effect, "in", QString::number(start)); + EffectsList::setParameter(effect, "out", QString::number(end)); + if (standalone) { + if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect))) + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + // if fade effect is displayed, update the effect edit widget with new clip duration + if (item->isSelected() && effectPos == item->selectedEffectIndex()) + emit clipItemSelected(item, effectPos); + } } effectPos = item->hasEffect("brightness", "fade_to_black"); if (effectPos != -1) { - QDomElement oldeffect = item->effectAt(effectPos); + QDomElement effect = item->getEffectAt(effectPos); int max = item->cropDuration().frames(m_document->fps()); int end = max + item->cropStart().frames(m_document->fps()); if (start > max) { @@ -4636,12 +4850,15 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) start = item->fadeOut(); } start = end - start; - EffectsList::setParameter(oldeffect, "in", QString::number(start)); - EffectsList::setParameter(oldeffect, "out", QString::number(end)); - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect))) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - // if fade effect is displayed, update the effect edit widget with new clip duration - if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos); + EffectsList::setParameter(effect, "in", QString::number(start)); + EffectsList::setParameter(effect, "out", QString::number(end)); + if (standalone) { + if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(effect))) + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + // if fade effect is displayed, update the effect edit widget with new clip duration + if (item->isSelected() && effectPos == item->selectedEffectIndex()) + emit clipItemSelected(item, effectPos); + } } } @@ -4653,28 +4870,13 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) if (!eff.isNull() && diff != 0) { int freeze_pos = EffectsList::parameter(eff, "frame").toInt() + diff; EffectsList::setParameter(eff, "frame", QString::number(freeze_pos)); - if (item->isSelected() && item->selectedEffect().attribute("id") == "freeze") { - emit clipItemSelected(item, item->selectedEffectIndex()); + if (standalone) { + if (item->isSelected() && item->selectedEffect().attribute("id") == "freeze") { + emit clipItemSelected(item, item->selectedEffectIndex()); + } } } } - - effectPos = item->hasEffect("affine", "pan_zoom"); - if (effectPos != -1) { - QDomElement oldeffect = item->effectAt(effectPos); - int start = item->cropStart().frames(m_document->fps()); - int max = start + item->cropDuration().frames(m_document->fps()); - if (start < 0) { - max -= start; - start = 0; - } - oldeffect.setAttribute("in", start); - oldeffect.setAttribute("out", max); - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(oldeffect))) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - // if effect is displayed, update the effect edit widget with new clip duration - if (item->isSelected() && effectPos == item->selectedEffectIndex()) emit clipItemSelected(item, effectPos); - } } double CustomTrackView::getSnapPointForPos(double pos) @@ -4747,6 +4949,11 @@ void CustomTrackView::updateSnapPoints(AbstractClipItem *selected, QList zone(); + snaps.append(GenTime(z.x(), m_document->fps())); + snaps.append(GenTime(z.y(), m_document->fps())); + qSort(snaps); m_scene->setSnapList(snaps); //for (int i = 0; i < m_snapPoints.size(); ++i) @@ -4818,7 +5025,7 @@ void CustomTrackView::slotDeleteAllClipMarkers(const QString &id) m_commandStack->push(deleteMarkers); } -void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString comment) +void CustomTrackView::addMarker(const QString &id, const GenTime &pos, const QString &comment) { DocClipBase *base = m_document->clipManager()->getClipById(id); if (!comment.isEmpty()) base->addSnapMarker(pos, comment); @@ -4850,7 +5057,7 @@ void CustomTrackView::buildGuidesMenu(QMenu *goMenu) const goMenu->setEnabled(!m_guides.isEmpty()); } -void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const QString &comment) +void CustomTrackView::editGuide(const GenTime &oldPos, const GenTime &pos, const QString &comment) { if (oldPos > GenTime() && pos > GenTime()) { // move guide @@ -4878,7 +5085,7 @@ void CustomTrackView::editGuide(const GenTime oldPos, const GenTime pos, const Q m_document->syncGuides(m_guides); } -bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) +bool CustomTrackView::addGuide(const GenTime &pos, const QString &comment) { for (int i = 0; i < m_guides.count(); i++) { if (m_guides.at(i)->position() == pos) { @@ -4894,13 +5101,19 @@ bool CustomTrackView::addGuide(const GenTime pos, const QString &comment) return true; } -void CustomTrackView::slotAddGuide() +void CustomTrackView::slotAddGuide(bool dialog) { CommentedTime marker(GenTime(m_cursorPos, m_document->fps()), i18n("Guide")); - MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this); - if (d.exec() != QDialog::Accepted) return; - if (addGuide(d.newMarker().time(), d.newMarker().comment())) { - EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), d.newMarker().time(), d.newMarker().comment(), false); + if (dialog) { + MarkerDialog d(NULL, marker, m_document->timecode(), i18n("Add Guide"), this); + if (d.exec() != QDialog::Accepted) return; + marker = d.newMarker(); + + } else { + marker.setComment(m_document->timecode().getDisplayTimecodeFromFrames(m_cursorPos, false)); + } + if (addGuide(marker.time(), marker.comment())) { + EditGuideCommand *command = new EditGuideCommand(this, GenTime(), QString(), marker.time(), marker.comment(), false); m_commandStack->push(command); } } @@ -4989,13 +5202,12 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale) newmatrix = newmatrix.scale(scaleFactor, verticalScale); m_scene->setScale(scaleFactor, verticalScale); removeTipAnimation(); - double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y(); bool adjust = false; if (verticalScale != matrix().m22()) adjust = true; setMatrix(newmatrix); if (adjust) { double newHeight = m_tracksHeight * m_document->tracksCount() * matrix().m22(); - m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight); + m_cursorLine->setLine(m_cursorLine->line().x1(), 0, m_cursorLine->line().x1(), newHeight - 1); for (int i = 0; i < m_guides.count(); i++) { QLineF l = m_guides.at(i)->line(); l.setP2(QPointF(l.x2(), newHeight)); @@ -5011,6 +5223,7 @@ void CustomTrackView::setScale(double scaleFactor, double verticalScale) else setSceneRect(0, 0, (m_projectDuration + 300), sceneRect().height()); } + double verticalPos = mapToScene(QPoint(0, viewport()->height() / 2)).y(); centerOn(QPointF(cursorPos(), verticalPos)); } @@ -5024,35 +5237,27 @@ void CustomTrackView::slotRefreshGuides() void CustomTrackView::drawBackground(QPainter * painter, const QRectF &rect) { - //kDebug() << "// DRAW BG: " << rect.width(); painter->setClipRect(rect); - KColorScheme scheme(palette().currentColorGroup(), KColorScheme::Window); QPen pen1 = painter->pen(); - pen1.setColor(scheme.shade(KColorScheme::DarkShade)); + pen1.setColor(palette().dark().color()); painter->setPen(pen1); double min = rect.left(); double max = rect.right(); painter->drawLine(QPointF(min, 0), QPointF(max, 0)); int maxTrack = m_document->tracksCount(); - QColor lockedColor = scheme.background(KColorScheme::NegativeBackground).color(); + QColor lockedColor = palette().button().color(); QColor audioColor = palette().alternateBase().color(); - QColor base = scheme.background(KColorScheme::NormalBackground).color(); for (int i = 0; i < maxTrack; i++) { TrackInfo info = m_document->trackInfoAt(maxTrack - i - 1); if (info.isLocked || info.type == AUDIOTRACK || i == m_selectedTrack) { const QRectF track(min, m_tracksHeight * i + 1, max - min, m_tracksHeight - 1); if (i == m_selectedTrack) - painter->fillRect(track, scheme.background(KColorScheme::ActiveBackground).color()); + painter->fillRect(track, m_activeTrackBrush.brush(this)); else painter->fillRect(track, info.isLocked ? lockedColor : audioColor); } painter->drawLine(QPointF(min, m_tracksHeight *(i + 1)), QPointF(max, m_tracksHeight *(i + 1))); } - int lowerLimit = m_tracksHeight * maxTrack + 1; - if (height() > lowerLimit) { - const QRectF bg(min, lowerLimit, max - min, height() - lowerLimit); - painter->fillRect(bg, base); - } } bool CustomTrackView::findString(const QString &text) @@ -5171,10 +5376,22 @@ bool CustomTrackView::canBePastedTo(ItemInfo info, int type) const // If we are in overwrite mode, always allow the move return true; } - QRectF rect((double) info.startPos.frames(m_document->fps()), (double)(info.track * m_tracksHeight + 1), (double)(info.endPos - info.startPos).frames(m_document->fps()), (double)(m_tracksHeight - 1)); + int height = m_tracksHeight - 2; + int offset = 0; + if (type == TRANSITIONWIDGET) { + height = Transition::itemHeight(); + offset = Transition::itemOffset(); + } + else if (type == AVWIDGET) { + height = ClipItem::itemHeight(); + offset = ClipItem::itemOffset(); + } + QRectF rect((double) info.startPos.frames(m_document->fps()), (double)(info.track * m_tracksHeight + 1 + offset), (double)(info.endPos - info.startPos).frames(m_document->fps()), (double) height); QList collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect); for (int i = 0; i < collisions.count(); i++) { - if (collisions.at(i)->type() == type) return false; + if (collisions.at(i)->type() == type) { + return false; + } } return true; } @@ -5240,16 +5457,24 @@ void CustomTrackView::pasteClip() return; } QPoint position; + int track = -1; + GenTime pos = GenTime(-1); if (m_menuPosition.isNull()) { position = mapFromGlobal(QCursor::pos()); if (!contentsRect().contains(position) || mapToScene(position).y() / m_tracksHeight > m_document->tracksCount()) { - emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage); - return; + track = m_selectedTrack; + pos = GenTime(m_cursorPos, m_document->fps()); + /*emit displayMessage(i18n("Cannot paste selected clips"), ErrorMessage); + return;*/ } - } else position = m_menuPosition; + } else { + position = m_menuPosition; + } - GenTime pos = GenTime((int)(mapToScene(position).x()), m_document->fps()); - int track = (int)(mapToScene(position).y() / m_tracksHeight); + if (pos == GenTime(-1)) + pos = GenTime((int)(mapToScene(position).x()), m_document->fps()); + if (track == -1) + track = (int)(mapToScene(position).y() / m_tracksHeight); GenTime leftPos = m_copiedItems.at(0)->startPos(); int lowerTrack = m_copiedItems.at(0)->track(); @@ -5299,6 +5524,7 @@ void CustomTrackView::pasteClip() } else emit displayMessage(i18n("Cannot paste transition to selected place"), ErrorMessage); } } + updateTrackDuration(-1, pasteClips); m_commandStack->push(pasteClips); } @@ -5327,7 +5553,6 @@ void CustomTrackView::pasteClipEffects() } } - for (int i = 0; i < clips.count(); ++i) { if (clips.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast < ClipItem *>(clips.at(i)); @@ -5358,6 +5583,7 @@ void CustomTrackView::adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime // parse parameters to check if we need to adjust to the new crop start int diff = (newstart - oldstart).frames(m_document->fps()); int max = (newstart + duration).frames(m_document->fps()); + QLocale locale; QDomNodeList params = xml.elementsByTagName("parameter"); for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); @@ -5371,9 +5597,9 @@ void CustomTrackView::adjustKeyfames(GenTime oldstart, GenTime newstart, GenTime double val = str.section(':', 1, 1).toDouble(); pos += diff; if (pos > max) { - newKeyFrames.append(QString::number(max) + ':' + QString::number(val)); + newKeyFrames.append(QString::number(max) + ':' + locale.toString(val)); break; - } else newKeyFrames.append(QString::number(pos) + ':' + QString::number(val)); + } else newKeyFrames.append(QString::number(pos) + ':' + locale.toString(val)); } //kDebug()<<"ORIGIN: "<baseClip()->getClipHash() + '_'; QString endThumb = startThumb; - startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png"); - endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png"); + startThumb.append(QString::number((int) item->speedIndependantCropStart().frames(m_document->fps())) + ".png"); + endThumb.append(QString::number((int) (item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png"); if (QFile::exists(startThumb)) { QPixmap pix(startThumb); if (pix.isNull()) KIO::NetAccess::del(KUrl(startThumb), this); @@ -5498,7 +5724,7 @@ void CustomTrackView::slotUpdateAllThumbs() item->slotSetEndThumb(pix); } } - item->refreshClip(false); + item->refreshClip(false, false); } } } @@ -5524,8 +5750,8 @@ void CustomTrackView::saveThumbnails() } else { QString startThumb = thumbBase + item->baseClip()->getClipHash() + '_'; QString endThumb = startThumb; - startThumb.append(QString::number(item->speedIndependantCropStart().frames(m_document->fps())) + ".png"); - endThumb.append(QString::number((item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png"); + startThumb.append(QString::number((int) item->speedIndependantCropStart().frames(m_document->fps())) + ".png"); + endThumb.append(QString::number((int) (item->speedIndependantCropStart() + item->speedIndependantCropDuration()).frames(m_document->fps()) - 1) + ".png"); if (!QFile::exists(startThumb)) { QPixmap pix(item->startThumb()); pix.save(startThumb); @@ -5553,6 +5779,7 @@ void CustomTrackView::slotInsertTrack(int ix) if (d.before_select->currentIndex() == 1) ix++; TrackInfo info; + info.duration = 0; info.isMute = false; info.isLocked = false; if (d.video_track->isChecked()) { @@ -5617,6 +5844,7 @@ void CustomTrackView::deleteTimelineTrack(int ix, TrackInfo trackinfo) if (selection.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast (selection.at(i)); new AddTimelineClipCommand(this, item->xml(), item->clipProducer(), item->info(), item->effectList(), false, false, false, true, deleteTrack); + m_waitingThumbs.removeAll(item); m_scene->removeItem(item); delete item; item = NULL; @@ -5647,26 +5875,7 @@ void CustomTrackView::autoTransition() setDocumentModified(); } - -QStringList CustomTrackView::getLadspaParams(QDomElement effect) const -{ - QStringList result; - QDomNodeList params = effect.elementsByTagName("parameter"); - for (int i = 0; i < params.count(); i++) { - QDomElement e = params.item(i).toElement(); - if (!e.isNull() && e.attribute("type") == "constant") { - if (e.hasAttribute("factor")) { - double factor = e.attribute("factor").toDouble(); - double value = e.attribute("value").toDouble(); - value = value / factor; - result.append(QString::number(value)); - } else result.append(e.attribute("value")); - } - } - return result; -} - -void CustomTrackView::clipNameChanged(const QString id, const QString name) +void CustomTrackView::clipNameChanged(const QString &id, const QString &name) { QList list = scene()->items(); ClipItem *clip = NULL; @@ -5713,14 +5922,13 @@ void CustomTrackView::getTransitionAvailableSpace(AbstractClipItem *item, GenTim } } -void CustomTrackView::loadGroups(const QDomNodeList groups) +void CustomTrackView::loadGroups(const QDomNodeList &groups) { for (int i = 0; i < groups.count(); i++) { QDomNodeList children = groups.at(i).childNodes(); scene()->clearSelection(); for (int nodeindex = 0; nodeindex < children.count(); nodeindex++) { - QDomNode n = children.item(nodeindex); - QDomElement elem = n.toElement(); + QDomElement elem = children.item(nodeindex).toElement(); int pos = elem.attribute("position").toInt(); int track = elem.attribute("track").toInt(); if (elem.tagName() == "clipitem") { @@ -5752,16 +5960,20 @@ void CustomTrackView::splitAudio() if (clip->parentItem()) { emit displayMessage(i18n("Cannot split audio of grouped clips"), ErrorMessage); } else { - new SplitAudioCommand(this, clip->track(), clip->startPos(), splitCommand); + EffectsList effects; + effects.clone(clip->effectList()); + new SplitAudioCommand(this, clip->track(), clip->startPos(), effects, splitCommand); } } } } - if (splitCommand->childCount() > 0) + if (splitCommand->childCount()) { + updateTrackDuration(-1, splitCommand); m_commandStack->push(splitCommand); + } } -void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split) +void CustomTrackView::doSplitAudio(const GenTime &pos, int track, EffectsList effects, bool split) { ClipItem *clip = getClipItemAt(pos, track); if (clip == NULL) { @@ -5771,12 +5983,17 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split) if (split) { int start = pos.frames(m_document->fps()); int freetrack = m_document->tracksCount() - track - 1; + + // do not split audio when we are on an audio track + if (m_document->trackInfoAt(freetrack).type == AUDIOTRACK) + return; + for (; freetrack > 0; freetrack--) { - kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack); + //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack); if (m_document->trackInfoAt(freetrack - 1).type == AUDIOTRACK && !m_document->trackInfoAt(freetrack - 1).isLocked) { - kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack); + //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack); if (m_document->renderer()->mltTrackDuration(freetrack) < start || m_document->renderer()->mltGetSpaceLength(pos, freetrack, false) >= clip->cropDuration().frames(m_document->fps())) { - kDebug() << "FOUND SPACE ON TRK: " << freetrack; + //kDebug() << "FOUND SPACE ON TRK: " << freetrack; break; } } @@ -5792,15 +6009,31 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split) clip->setSelected(true); ClipItem *audioClip = getClipItemAt(start, info.track); if (audioClip) { + Mlt::Tractor *tractor = m_document->renderer()->lockService(); clip->setVideoOnly(true); - if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) { + if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage); } - if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) { + if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage); } + m_document->renderer()->unlockService(tractor); audioClip->setSelected(true); audioClip->setAudioOnly(true); + + // keep video effects, move audio effects to audio clip + int videoIx = 0; + int audioIx = 0; + for (int i = 0; i < effects.count(); ++i) { + if (effects.at(i).attribute("type") == "audio") { + deleteEffect(m_document->tracksCount() - track, pos, clip->effectAt(videoIx)); + audioIx++; + } else { + deleteEffect(freetrack, pos, audioClip->effectAt(audioIx)); + videoIx++; + } + } + groupSelectedItems(false, true); } } @@ -5822,9 +6055,19 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split) ItemInfo info = clip->info(); deleteClip(clp->info()); clip->setVideoOnly(false); - if (!m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track))) { + Mlt::Tractor *tractor = m_document->renderer()->lockService(); + if (!m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->getProducer(info.track))) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage); } + m_document->renderer()->unlockService(tractor); + + // re-add audio effects + for (int i = 0; i < effects.count(); ++i) { + if (effects.at(i).attribute("type") == "audio") { + addEffect(m_document->tracksCount() - track, pos, effects.at(i)); + } + } + break; } } @@ -5916,28 +6159,30 @@ void CustomTrackView::doChangeClipType(const GenTime &pos, int track, bool video kDebug() << "// Cannot find clip to split!!!"; return; } + Mlt::Tractor *tractor = m_document->renderer()->lockService(); if (videoOnly) { int start = pos.frames(m_document->fps()); clip->setVideoOnly(true); clip->setAudioOnly(false); - if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) { + if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage); } } else if (audioOnly) { int start = pos.frames(m_document->fps()); clip->setAudioOnly(true); clip->setVideoOnly(false); - if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) { + if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->audioProducer(track)) == false) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage); } } else { int start = pos.frames(m_document->fps()); clip->setAudioOnly(false); clip->setVideoOnly(false); - if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->producer(track)) == false) { + if (m_document->renderer()->mltUpdateClipProducer(tractor, m_document->tracksCount() - track, start, clip->baseClip()->getProducer(track)) == false) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage); } } + m_document->renderer()->unlockService(tractor); clip->update(); setDocumentModified(); } @@ -6051,6 +6296,7 @@ void CustomTrackView::updateProjectFps() m_document->clipManager()->removeGroup(grp); m_scene->addItem(grp); scene()->destroyItemGroup(grp); + scene()->clearSelection(); for (int j = 0; j < children.count(); j++) { if (children.at(j)->type() == AVWIDGET || children.at(j)->type() == TRANSITIONWIDGET) { //children.at(j)->setParentItem(0); @@ -6171,10 +6417,15 @@ QStringList CustomTrackView::extractTransitionsLumas() if (itemList.at(i)->type() == TRANSITIONWIDGET) { transitionitem = static_cast (itemList.at(i)); transitionXml = transitionitem->toXML(); + // luma files in transitions can be in "resource" or "luma" property QString luma = EffectsList::parameter(transitionXml, "luma"); - if (!luma.isEmpty()) urls << luma; + if (luma.isEmpty()) luma = EffectsList::parameter(transitionXml, "resource"); + if (!luma.isEmpty()) urls << KUrl(luma).path(); } } +#if QT_VERSION >= 0x040500 + urls.removeDuplicates(); +#endif return urls; } @@ -6219,6 +6470,7 @@ void CustomTrackView::insertZoneOverwrite(QStringList data, int in) addCommand->setText(i18n("Insert clip")); adjustTimelineClips(OVERWRITEEDIT, NULL, info, addCommand); new AddTimelineClipCommand(this, clip->toXML(), clip->getId(), info, EffectsList(), true, false, true, false, addCommand); + updateTrackDuration(info.track, addCommand); m_commandStack->push(addCommand); selectClip(true, false, m_selectedTrack, in); @@ -6237,12 +6489,14 @@ void CustomTrackView::clearSelection() void CustomTrackView::updatePalette() { + m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())); if (m_cursorLine) { QPen pen1 = QPen(); pen1.setWidth(1); pen1.setColor(palette().text().color()); m_cursorLine->setPen(pen1); } + emit tracksChanged(); } void CustomTrackView::removeTipAnimation() @@ -6347,7 +6601,7 @@ bool CustomTrackView::hasAudio(int track) const return false; } -void CustomTrackView::slotAddTrackEffect(const QDomElement effect, int ix) +void CustomTrackView::slotAddTrackEffect(const QDomElement &effect, int ix) { AddEffectCommand *command = new AddEffectCommand(this, m_document->tracksCount() - ix, GenTime(-1), effect, true); m_commandStack->push(command); @@ -6355,9 +6609,10 @@ void CustomTrackView::slotAddTrackEffect(const QDomElement effect, int ix) } -EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) +EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement &effect) { EffectsParameterList parameters; + QLocale locale; parameters.addParam("tag", effect.attribute("tag")); if (effect.hasAttribute("region")) parameters.addParam("region", effect.attribute("region")); parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix")); @@ -6370,15 +6625,19 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) QDomNodeList params = effect.elementsByTagName("parameter"); for (int i = 0; i < params.count(); i++) { QDomElement e = params.item(i).toElement(); - //kDebug() << "/ / / /SENDING EFFECT PARAM: " << e.attribute("type") << ", NAME_ " << e.attribute("tag"); + if (e.attribute("type") == "geometry" && !e.hasAttribute("fixed")) { + // effects with geometry param need in / out synced with the clip, request it... + parameters.addParam("_sync_in_out", "1"); + } if (e.attribute("type") == "simplekeyframe") { QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts); double factor = e.attribute("factor", "1").toDouble(); + double offset = e.attribute("offset", "0").toDouble(); for (int j = 0; j < values.count(); j++) { - QString pos = values.at(j).section(":", 0, 0); - double val = values.at(j).section(":", 1, 1).toDouble() / factor; - values[j] = pos + "=" + QString::number(val); + QString pos = values.at(j).section(':', 0, 0); + double val = (values.at(j).section(':', 1, 1).toDouble() - offset) / factor; + values[j] = pos + "=" + locale.toString(val); } // kDebug() << "/ / / /SENDING KEYFR:" << values; parameters.addParam(e.attribute("name"), values.join(";")); @@ -6392,6 +6651,7 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) parameters.addParam("max", e.attribute("max")); parameters.addParam("min", e.attribute("min")); parameters.addParam("factor", e.attribute("factor", "1")); + parameters.addParam("offset", e.attribute("offset", "0")); parameters.addParam("starttag", e.attribute("starttag", "start")); parameters.addParam("endtag", e.attribute("endtag", "end")); } else if (e.attribute("namedesc").contains(';')) { @@ -6408,16 +6668,116 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) } parameters.addParam("start", neu); } else { - if (e.attribute("factor", "1") != "1") { + if (e.attribute("factor", "1") != "1" || e.attribute("offset", "0") != "0") { double fact; - if (e.attribute("factor").startsWith('%')) { + if (e.attribute("factor").contains('%')) { fact = ProfilesDialog::getStringEval(m_document->mltProfile(), e.attribute("factor")); - } else fact = e.attribute("factor", "1").toDouble(); - parameters.addParam(e.attribute("name"), QString::number(e.attribute("value").toDouble() / fact)); + } else { + fact = e.attribute("factor", "1").toDouble(); + } + double offset = e.attribute("offset", "0").toDouble(); + parameters.addParam(e.attribute("name"), locale.toString((e.attribute("value").toDouble() - offset) / fact)); } else { parameters.addParam(e.attribute("name"), e.attribute("value")); } } } return parameters; -} \ No newline at end of file +} + +void CustomTrackView::updateTrackNames(int track, bool added) +{ + QList tracks = m_document->tracksList(); + int max = tracks.count(); + int docTrack = max - track - 1; + + // count number of tracks of each type + int videoTracks = 0; + int audioTracks = 0; + for (int i = max - 1; i >= 0; --i) { + TrackInfo info = tracks.at(i); + if (info.type == VIDEOTRACK) + videoTracks++; + else + audioTracks++; + + if (i <= docTrack) { + QString type = (info.type == VIDEOTRACK ? "Video " : "Audio "); + int typeNumber = (info.type == VIDEOTRACK ? videoTracks : audioTracks); + + if (added) { + if (i == docTrack || info.trackName == type + QString::number(typeNumber - 1)) { + info.trackName = type + QString::number(typeNumber); + m_document->setTrackType(i, info); + } + } else { + if (info.trackName == type + QString::number(typeNumber + 1)) { + info.trackName = type + QString::number(typeNumber); + m_document->setTrackType(i, info); + } + } + } + } + emit tracksChanged(); +} + +void CustomTrackView::updateTrackDuration(int track, QUndoCommand *command) +{ + Q_UNUSED(command) + + QList tracks; + if (track >= 0) { + tracks << m_document->tracksCount() - track - 1; + } else { + // negative track number -> update all tracks + for (int i = 0; i < m_document->tracksCount(); ++i) + tracks << i; + } + int t, duration; + for (int i = 0; i < tracks.count(); ++i) { + t = tracks.at(i); + // t + 1 because of black background track + duration = m_document->renderer()->mltTrackDuration(t + 1); + if (duration != m_document->trackDuration(t)) { + m_document->setTrackDuration(t, duration); + + // update effects + EffectsList effects = m_document->getTrackEffects(t); + for (int j = 0; j < effects.count(); ++j) { + /* TODO + * - lookout for keyframable parameters and update them so all keyframes are in the new range (0 - duration) + * - update the effectstack if necessary + */ + } + } + } +} + +void CustomTrackView::slotRefreshThumbs(const QString &id, bool resetThumbs) +{ + QList list = scene()->items(); + ClipItem *clip = NULL; + for (int i = 0; i < list.size(); ++i) { + if (list.at(i)->type() == AVWIDGET) { + clip = static_cast (list.at(i)); + if (clip->clipProducer() == id) { + clip->refreshClip(true, resetThumbs); + } + } + } +} + +void CustomTrackView::adjustEffects(ClipItem* item, ItemInfo oldInfo, QUndoCommand* command) +{ + QMap effects = item->adjustEffectsToDuration(m_document->width(), m_document->height(), oldInfo); + + if (effects.count()) { + QMap::const_iterator i = effects.constBegin(); + while (i != effects.constEnd()) { + new EditEffectCommand(this, m_document->tracksCount() - item->track(), item->startPos(), i.value(), item->effectAt(i.key()), i.key(), false, command); + ++i; + } + } +} + +