X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=db8588d948e778a44343ee0cc0a0c3290440cdd0;hb=bd08944c74ebd91de5d41e45bf5ea15b17921002;hp=e61448e9ff598bb123cb6a851d9eef4d4620e803;hpb=35a5c83d59396a357f49d73a7c5127cc06bbb686;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index e61448e9..db8588d9 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -59,6 +59,8 @@ #include "tracksconfigdialog.h" #include "configtrackscommand.h" #include "rebuildgroupcommand.h" +#include "razorgroupcommand.h" +#include "profilesdialog.h" #include #include @@ -368,7 +370,7 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) emit mousePosition(mappedXPos); if (event->buttons() & Qt::MidButton) return; - if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL)) { + if (dragMode() == QGraphicsView::RubberBandDrag || (event->modifiers() == Qt::ControlModifier && m_tool != SPACERTOOL && m_operationMode != RESIZESTART && m_operationMode != RESIZEEND)) { event->setAccepted(true); m_moveOpMode = NONE; QGraphicsView::mouseMoveEvent(event); @@ -387,14 +389,21 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) } else if (viewport()->width() - pos < 10) { m_scrollOffset = 30; m_scrollTimer.start(); - } else if (m_scrollTimer.isActive()) m_scrollTimer.stop(); - + } else if (m_scrollTimer.isActive()) { + m_scrollTimer.stop(); + } } else if (m_operationMode == RESIZESTART && move) { m_document->renderer()->pause(); - m_dragItem->resizeStart((int)(snappedPos)); + if (event->modifiers() != Qt::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())); + } else { + m_dragItem->resizeStart((int)(snappedPos)); + } } else if (m_operationMode == RESIZEEND && move) { m_document->renderer()->pause(); - if (m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (event->modifiers() != Qt::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())); @@ -571,27 +580,33 @@ void CustomTrackView::mouseMoveEvent(QMouseEvent * event) setTipAnimation(clip, opMode, size); if (opMode == MOVE) { setCursor(Qt::OpenHandCursor); - ClipItem *ci = static_cast (item); - QString 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) { - AbstractGroupItem *parent = static_cast (clip->parentItem()); - if (clip->parentItem() == m_selectionGroup) - message.append(i18n(" Selection duration:")); - else - message.append(i18n(" Group duration:")); - message.append(m_document->timecode().getDisplayTimecode(parent->duration(), KdenliveSettings::frametimecode())); - if (parent->parentItem() && parent->parentItem()->type() == GROUPWIDGET) { - AbstractGroupItem *parent2 = static_cast (parent->parentItem()); - message.append(i18n(" Selection duration:") + m_document->timecode().getDisplayTimecode(parent2->duration(), KdenliveSettings::frametimecode())); + if (item->type() == AVWIDGET) { + ClipItem *ci = static_cast (item); + QString 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) { + AbstractGroupItem *parent = static_cast (clip->parentItem()); + if (clip->parentItem() == m_selectionGroup) + message.append(i18n(" Selection duration:")); + else + message.append(i18n(" Group duration:")); + message.append(m_document->timecode().getDisplayTimecode(parent->duration(), KdenliveSettings::frametimecode())); + if (parent->parentItem() && parent->parentItem()->type() == GROUPWIDGET) { + AbstractGroupItem *parent2 = static_cast (parent->parentItem()); + message.append(i18n(" Selection duration:") + m_document->timecode().getDisplayTimecode(parent2->duration(), KdenliveSettings::frametimecode())); + } } + emit displayMessage(message, InformationMessage); } - emit displayMessage(message, InformationMessage); } else if (opMode == RESIZESTART) { setCursor(KCursor("left_side", Qt::SizeHorCursor)); + 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); } else if (opMode == RESIZEEND) { setCursor(KCursor("right_side", Qt::SizeHorCursor)); + 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); } else if (opMode == FADEIN || opMode == FADEOUT) { setCursor(Qt::PointingHandCursor); emit displayMessage(i18n("Drag to add or resize a fade effect."), InformationMessage); @@ -858,31 +873,32 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) // Razor tool if (m_tool == RAZORTOOL && m_dragItem) { + GenTime cutPos = GenTime((int)(mapToScene(event->pos()).x()), m_document->fps()); if (m_dragItem->type() == TRANSITIONWIDGET) { emit displayMessage(i18n("Cannot cut a transition"), ErrorMessage); - event->accept(); - m_dragItem = NULL; - return; - } else if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { - emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage); - event->accept(); - m_dragItem = NULL; - return; + } else { + m_document->renderer()->pause(); + if (m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + razorGroup((AbstractGroupItem *)m_dragItem->parentItem(), cutPos); + } else { + AbstractClipItem *clip = static_cast (m_dragItem); + RazorClipCommand* command = new RazorClipCommand(this, clip->info(), cutPos); + m_commandStack->push(command); + } + setDocumentModified(); } - AbstractClipItem *clip = static_cast (m_dragItem); - RazorClipCommand* command = new RazorClipCommand(this, clip->info(), GenTime((int)(mapToScene(event->pos()).x()), m_document->fps())); - m_document->renderer()->pause(); - m_commandStack->push(command); - setDocumentModified(); m_dragItem = NULL; event->accept(); return; } bool itemSelected = false; - if (m_dragItem->isSelected()) itemSelected = true; - else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) itemSelected = true; - else if (dragGroup && dragGroup->isSelected()) itemSelected = true; + if (m_dragItem->isSelected()) + itemSelected = true; + else if (m_dragItem->parentItem() && m_dragItem->parentItem()->isSelected()) + itemSelected = true; + else if (dragGroup && dragGroup->isSelected()) + itemSelected = true; if (event->modifiers() == Qt::ControlModifier || itemSelected == false) { if (event->modifiers() != Qt::ControlModifier) { @@ -897,8 +913,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) dragGroup = static_cast (m_dragItem->parentItem()); } bool selected = !m_dragItem->isSelected(); - if (dragGroup) dragGroup->setSelected(selected); - else m_dragItem->setSelected(selected); + if (dragGroup) + dragGroup->setSelected(selected); + else + m_dragItem->setSelected(selected); groupSelectedItems(); ClipItem *clip = static_cast (m_dragItem); @@ -910,7 +928,9 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) if (m_dragItem && m_dragItem->type() == AVWIDGET && !m_dragItem->isItemLocked()) { ClipItem *selected = static_cast (m_dragItem); emit clipItemSelected(selected); - } else emit clipItemSelected(NULL); + } else { + emit clipItemSelected(NULL); + } } // If clicked item is selected, allow move @@ -921,8 +941,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) // Update snap points if (m_selectionGroup == NULL) { - if (m_operationMode == RESIZEEND || m_operationMode == RESIZESTART) updateSnapPoints(NULL); - else updateSnapPoints(m_dragItem); + if (m_operationMode == RESIZEEND || m_operationMode == RESIZESTART) + updateSnapPoints(NULL); + else + updateSnapPoints(m_dragItem); } else { QList offsetList; QList children = m_selectionGroup->childItems(); @@ -964,8 +986,10 @@ void CustomTrackView::mousePressEvent(QMouseEvent * event) info.endPos = transitionClip->endPos(); } else { GenTime transitionDuration(65, m_document->fps()); - if (m_dragItem->cropDuration() < transitionDuration) info.endPos = m_dragItem->endPos(); - else info.endPos = info.startPos + transitionDuration; + if (m_dragItem->cropDuration() < transitionDuration) + info.endPos = m_dragItem->endPos(); + else + info.endPos = info.startPos + transitionDuration; } if (info.endPos == info.startPos) info.endPos = info.startPos + GenTime(65, m_document->fps()); // Check there is no other transition at that place @@ -1039,7 +1063,15 @@ void CustomTrackView::rebuildGroup(int childTrack, GenTime childPos) break; } } + rebuildGroup(group); +} + +void CustomTrackView::rebuildGroup(AbstractGroupItem *group) +{ if (group) { + resetSelectionGroup(false); + m_scene->clearSelection(); + QList children = group->childItems(); m_document->clipManager()->removeGroup(group); scene()->destroyItemGroup(group); @@ -1509,7 +1541,7 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip) } bool success = true; for (int i = 0; i < clip->effectsCount(); i++) { - if (!m_document->renderer()->mltAddEffect(track, pos, clip->getEffectArgs(clip->effectAt(i)), false)) success = false; + if (!m_document->renderer()->mltAddEffect(track, pos, getEffectArgs(clip->effectAt(i)), false)) success = false; } if (!success) emit displayMessage(i18n("Problem adding effect to clip"), ErrorMessage); m_document->renderer()->doRefresh(); @@ -1517,6 +1549,13 @@ void CustomTrackView::slotRefreshEffects(ClipItem *clip) void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) { + if (pos < GenTime()) { + // Add track effect + m_document->addTrackEffect(track - 1, effect); + m_document->renderer()->mltAddTrackEffect(track, getEffectArgs(effect)); + emit showTrackEffects(track, m_document->trackInfoAt(track - 1)); + return; + } ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track); if (clip) { // Special case: speed effect @@ -1544,6 +1583,13 @@ void CustomTrackView::addEffect(int track, GenTime pos, QDomElement effect) 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); + emit showTrackEffects(track, m_document->trackInfoAt(track - 1)); + return; + } // Special case: speed effect if (effect.attribute("id") == "speed") { ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track); @@ -1644,13 +1690,19 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) if (effect.attribute("type") == "audio") { // Don't add audio effects on video clips if (item->isVideoOnly() || (item->clipType() != AUDIO && item->clipType() != AV && item->clipType() != PLAYLIST)) { - emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage); + /* do not show error message when item is part of a group as the user probably knows what he does then + * and the message is annoying when working with the split audio feature */ + if (!item->parentItem() || item->parentItem() == m_selectionGroup) + emit displayMessage(i18n("Cannot add an audio effect to this clip"), ErrorMessage); continue; } - } else if (effect.hasAttribute("type") == false) { + } else if (effect.attribute("type") == "video" || !effect.hasAttribute("type")) { // Don't add video effect on audio clips if (item->isAudioOnly() || item->clipType() == AUDIO) { - emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage); + /* do not show error message when item is part of a group as the user probably knows what he does then + * and the message is annoying when working with the split audio feature */ + if (!item->parentItem() || item->parentItem() == m_selectionGroup) + emit displayMessage(i18n("Cannot add a video effect to this clip"), ErrorMessage); continue; } } @@ -1661,9 +1713,13 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) if (item->isItemLocked()) { continue; } + if (effect.attribute("id") == "freeze" && m_cursorPos > item->startPos().frames(m_document->fps()) && m_cursorPos < item->endPos().frames(m_document->fps())) { item->initEffect(effect, m_cursorPos - item->startPos().frames(m_document->fps())); - } else item->initEffect(effect); + } else { + item->initEffect(effect); + } + if (effect.attribute("tag") == "ladspa") { QString ladpsaFile = m_document->getLadspaFile(); initEffects::ladspaEffectFile(ladpsaFile, effect.attribute("ladspaid").toInt(), getLadspaParams(effect)); @@ -1678,8 +1734,15 @@ void CustomTrackView::slotAddEffect(QDomElement effect, GenTime pos, int track) } else delete effectCommand; } -void CustomTrackView::slotDeleteEffect(ClipItem *clip, QDomElement effect, bool affectGroup) +void CustomTrackView::slotDeleteEffect(ClipItem *clip, int track, QDomElement effect, bool affectGroup) { + if (clip == NULL) { + // delete track effect + AddEffectCommand *command = new AddEffectCommand(this, track, GenTime(-1), effect, false); + m_commandStack->push(command); + setDocumentModified(); + return; + } if (affectGroup && clip->parentItem() && clip->parentItem() == m_selectionGroup) { //clip is in a group, also remove the effect in other clips of the group QList items = m_selectionGroup->childItems(); @@ -1725,8 +1788,26 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE emit displayMessage(i18n("Problem editing effect"), ErrorMessage); return; } - ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track); QDomElement effect = insertedEffect.cloneNode().toElement(); + if (pos < GenTime()) { + // editing a track effect + 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() - track, pos, effectParams)) + emit displayMessage(i18n("Problem editing effect"), ErrorMessage); + m_document->setTrackEffect(track - 1, ix, effect); + return; + + } + ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track); if (clip) { // Special case: speed effect if (effect.attribute("id") == "speed") { @@ -1745,7 +1826,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE return; } - EffectsParameterList effectParams = clip->getEffectArgs(effect); + 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)); @@ -1753,7 +1834,7 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE // check if we are trying to reset a keyframe effect if (effectParams.hasParam("keyframes") && effectParams.paramValue("keyframes").isEmpty()) { clip->initEffect(effect); - effectParams = clip->getEffectArgs(effect); + effectParams = getEffectArgs(effect); } if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - clip->track(), clip->startPos(), effectParams)) emit displayMessage(i18n("Problem editing effect"), ErrorMessage); @@ -1780,6 +1861,19 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos) { + if (pos < GenTime()) { + // Moving track effect + QDomElement act = m_document->getTrackEffect(m_document->tracksCount() - track - 1, newPos - 1); + QDomElement before = m_document->getTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1); + + if (!act.isNull() && !before.isNull()) { + m_document->setTrackEffect(m_document->tracksCount() - track - 1, oldPos - 1, act); + m_document->setTrackEffect(m_document->tracksCount() - track - 1, newPos - 1, before); + m_document->renderer()->mltMoveEffect(m_document->tracksCount() - track, pos, oldPos, newPos); + emit showTrackEffects(m_document->tracksCount() - track, m_document->trackInfoAt(m_document->tracksCount() - track - 1)); + } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage); + return; + } ClipItem *clip = getClipItemAt((int)pos.frames(m_document->fps()), m_document->tracksCount() - track); if (clip && !clip->effectAt(newPos - 1).isNull() && !clip->effectAt(oldPos - 1).isNull()) { QDomElement act = clip->effectAt(newPos - 1); @@ -1797,27 +1891,42 @@ void CustomTrackView::moveEffect(int track, GenTime pos, int oldPos, int newPos) } else emit displayMessage(i18n("Cannot move effect"), ErrorMessage); } -void CustomTrackView::slotChangeEffectState(ClipItem *clip, int effectPos, bool disable) +void CustomTrackView::slotChangeEffectState(ClipItem *clip, int track, int effectPos, bool disable) { - QDomElement effect = clip->effectAt(effectPos); + EditEffectCommand *command; + QDomElement effect; + if (clip == NULL) effect = m_document->getTrackEffect(track - 1, effectPos); + else effect = clip->effectAt(effectPos); QDomElement oldEffect = effect.cloneNode().toElement(); - effect.setAttribute("disable", (int) disable); - EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true); + + + if (clip == NULL) { + // editing track effect + command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldEffect, effect, effectPos, true); + } else { + command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldEffect, effect, effectPos, true); + } m_commandStack->push(command); setDocumentModified();; } -void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int currentPos, int newPos) +void CustomTrackView::slotChangeEffectPosition(ClipItem *clip, int track, int currentPos, int newPos) { - MoveEffectCommand *command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos); + MoveEffectCommand *command; + if (clip == NULL) { + // editing track effect + command = new MoveEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), currentPos, newPos); + } else command = new MoveEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), currentPos, newPos); m_commandStack->push(command); setDocumentModified(); } -void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, QDomElement oldeffect, QDomElement effect, int ix) +void CustomTrackView::slotUpdateClipEffect(ClipItem *clip, int track, QDomElement oldeffect, QDomElement effect, int ix) { - EditEffectCommand *command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true); + EditEffectCommand *command; + if (clip) command = new EditEffectCommand(this, m_document->tracksCount() - clip->track(), clip->startPos(), oldeffect, effect, ix, true); + else command = new EditEffectCommand(this, m_document->tracksCount() - track, GenTime(-1), oldeffect, effect, ix, true); m_commandStack->push(command); } @@ -1837,15 +1946,14 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo ClipItem *item = getClipItemAt((int) info.startPos.frames(m_document->fps()), info.track); if (!item || cutTime >= item->endPos() || cutTime <= item->startPos()) { emit displayMessage(i18n("Cannot find clip to cut"), ErrorMessage); - if (item) kDebug() << "///////// ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25); - else kDebug() << "/// ERROR NO CLIP at: " << info.startPos.frames(m_document->fps()) << ", track: " << info.track; + if (item) + kDebug() << "///////// ERROR CUTTING CLIP : (" << item->startPos().frames(25) << "-" << item->endPos().frames(25) << "), INFO: (" << info.startPos.frames(25) << "-" << info.endPos.frames(25) << ")" << ", CUT: " << cutTime.frames(25); + else + kDebug() << "/// ERROR NO CLIP at: " << info.startPos.frames(m_document->fps()) << ", track: " << info.track; m_blockRefresh = false; return NULL; } - if (item->parentItem()) { - // Item is part of a group, reset group - resetSelectionGroup(); - } + 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); @@ -1873,8 +1981,10 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo } item->resizeEnd(cutPos); scene()->addItem(dup); - if (item->checkKeyFrames()) slotRefreshEffects(item); - if (dup->checkKeyFrames()) slotRefreshEffects(dup); + if (item->checkKeyFrames()) + slotRefreshEffects(item); + if (dup->checkKeyFrames()) + slotRefreshEffects(dup); item->baseClip()->addReference(); m_document->updateClip(item->baseClip()->getId()); setDocumentModified(); @@ -1917,11 +2027,11 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo if (success) { item->resizeEnd((int) info.endPos.frames(m_document->fps())); setDocumentModified(); - } else + } else { emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); + } KdenliveSettings::setSnaptopoints(snap); return item; - } //QTimer::singleShot(3000, this, SLOT(slotEnableRefresh())); } @@ -2937,12 +3047,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) trackTransitionStartList[m_document->tracksCount() - info.track] = info.startPos.frames(m_document->fps()); } } - - InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false); - m_commandStack->push(command); - if (track != -1) track = m_document->tracksCount() - track; - kDebug() << "SPACER TRACK:" << track; - m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime()); + if (!clipsToMove.isEmpty() || !transitionsToMove.isEmpty()) { + InsertSpaceCommand *command = new InsertSpaceCommand(this, clipsToMove, transitionsToMove, track, timeOffset, false); + m_commandStack->push(command); + if (track != -1) track = m_document->tracksCount() - track; + kDebug() << "SPACER TRACK:" << track; + m_document->renderer()->mltInsertSpace(trackClipStartList, trackTransitionStartList, track, timeOffset, GenTime()); + setDocumentModified(); + } } resetSelectionGroup(false); m_operationMode = NONE; @@ -2967,10 +3079,10 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) 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(m_dragItemInfo.track); + if (item->isAudioOnly()) prod = item->baseClip()->audioProducer(info.track); else if (item->isVideoOnly()) prod = item->baseClip()->videoProducer(); - else prod = item->baseClip()->producer(m_dragItemInfo.track); - bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), (int) m_dragItemInfo.startPos.frames(m_document->fps()), (int)(m_dragItem->startPos().frames(m_document->fps())), prod, m_scene->editMode() == OVERWRITEEDIT, m_scene->editMode() == INSERTEDIT); + else prod = item->baseClip()->producer(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) { QUndoCommand *moveCommand = new QUndoCommand(); @@ -3091,8 +3203,7 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) emit displayMessage(i18n("Cannot move clip to position %1", m_document->timecode().getTimecodeFromFrames(m_dragItemInfo.startPos.frames(m_document->fps()))), ErrorMessage); } setDocumentModified(); - } - if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) { + } else if (m_dragItem->type() == TRANSITIONWIDGET && (m_dragItemInfo.startPos != info.startPos || m_dragItemInfo.track != info.track)) { Transition *transition = static_cast (m_dragItem); transition->updateTransitionEndTrack(getPreviousVideoTrack(m_dragItem->track())); if (!m_document->renderer()->mltMoveTransition(transition->transitionTag(), (int)(m_document->tracksCount() - m_dragItemInfo.track), (int)(m_document->tracksCount() - m_dragItem->track()), transition->transitionEndTrack(), m_dragItemInfo.startPos, m_dragItemInfo.endPos, info.startPos, info.endPos)) { @@ -3105,12 +3216,17 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) adjustTimelineTransitions(m_scene->editMode(), transition, moveCommand); new MoveTransitionCommand(this, m_dragItemInfo, info, false, moveCommand); m_commandStack->push(moveCommand); + setDocumentModified(); } } } else { // Moving several clips. We need to delete them and readd them to new position, // or they might overlap each other during the move - QGraphicsItemGroup *group = static_cast (m_dragItem->parentItem()); + QGraphicsItemGroup *group; + if (m_selectionGroup) + group = static_cast (m_selectionGroup); + else + group = static_cast (m_dragItem->parentItem()); QList items = group->childItems(); QList clipsToMove; @@ -3168,12 +3284,15 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) 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); + 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); for (int i = 0; i < clip->effectsCount(); i++) { - m_document->renderer()->mltAddEffect(info.track, info.startPos, clip->getEffectArgs(clip->effectAt(i)), false); + m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false); } } else { Transition *tr = static_cast (item); @@ -3186,7 +3305,6 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML()); } } - new MoveGroupCommand(this, clipsToMove, transitionsToMove, timeOffset, trackOffset, false, moveGroup); m_commandStack->push(moveGroup); @@ -3198,6 +3316,24 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) if (m_selectionGroup) { m_selectionGroupInfo.startPos = GenTime(m_selectionGroup->scenePos().x(), m_document->fps()); m_selectionGroupInfo.track = m_selectionGroup->track(); + + for (int i = 0; i < items.count(); ++i) { + if (items.at(i)->type() == GROUPWIDGET) { + rebuildGroup((AbstractGroupItem*)items.at(i)); + items.removeAt(i); + --i; + } + } + for (int i = 0; i < items.count(); ++i) { + if (items.at(i)) { + items.at(i)->setSelected(true); + if (items.at(i)->parentItem()) + items.at(i)->parentItem()->setSelected(true); + } + } + groupSelectedItems(); + } else { + rebuildGroup((AbstractGroupItem *)group); } setDocumentModified(); } @@ -3205,10 +3341,31 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) m_document->renderer()->doRefresh(); } else if (m_operationMode == RESIZESTART && m_dragItem->startPos() != m_dragItemInfo.startPos) { // resize start - prepareResizeClipStart(m_dragItem, m_dragItemInfo, m_dragItem->startPos().frames(m_document->fps())); + if (event->modifiers() != Qt::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(); + resizeCommand->setText(i18n("Resize group")); + QList items = parent->childItems(); + QList infos = parent->resizeInfos(); + parent->clearResizeInfos(); + int itemcount = 0; + for (int i = 0; i < items.count(); ++i) { + AbstractClipItem *item = static_cast(items.at(i)); + if (item && item->type() == AVWIDGET) { + ItemInfo info = infos.at(itemcount); + prepareResizeClipStart(item, info, item->startPos().frames(m_document->fps()), false, resizeCommand); + ++itemcount; + } + } + m_commandStack->push(resizeCommand); + } + } else { + prepareResizeClipStart(m_dragItem, m_dragItemInfo, m_dragItem->startPos().frames(m_document->fps())); + } } else if (m_operationMode == RESIZEEND && m_dragItem->endPos() != m_dragItemInfo.endPos) { // resize end - if (m_dragItem->type() == AVWIDGET && m_dragItem->parentItem() && m_dragItem->parentItem() != m_selectionGroup) { + if (event->modifiers() != Qt::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(); @@ -3240,13 +3397,13 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int start = item->cropStart().frames(m_document->fps()); int end = item->fadeIn(); if (end == 0) { - slotDeleteEffect(item, oldeffect, false); + slotDeleteEffect(item, -1, oldeffect, false); } else { end += start; QDomElement effect = oldeffect.cloneNode().toElement(); EffectsList::setParameter(oldeffect, "in", QString::number(start)); EffectsList::setParameter(oldeffect, "out", QString::number(end)); - slotUpdateClipEffect(item, effect, oldeffect, ix); + slotUpdateClipEffect(item, -1, effect, oldeffect, ix); emit clipItemSelected(item, ix); } } else if (item->fadeIn() != 0 && ix2 == -1) { @@ -3263,13 +3420,13 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int start = item->cropStart().frames(m_document->fps()); int end = item->fadeIn(); if (end == 0) { - slotDeleteEffect(item, oldeffect, false); + slotDeleteEffect(item, -1, oldeffect, false); } else { end += start; QDomElement effect = oldeffect.cloneNode().toElement(); EffectsList::setParameter(oldeffect, "in", QString::number(start)); EffectsList::setParameter(oldeffect, "out", QString::number(end)); - slotUpdateClipEffect(item, effect, oldeffect, ix2); + slotUpdateClipEffect(item, -1, effect, oldeffect, ix2); emit clipItemSelected(item, ix2); } } @@ -3283,14 +3440,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps()); int start = item->fadeOut(); if (start == 0) { - slotDeleteEffect(item, oldeffect, false); + slotDeleteEffect(item, -1, oldeffect, false); } else { start = end - start; QDomElement effect = oldeffect.cloneNode().toElement(); EffectsList::setParameter(oldeffect, "in", QString::number(start)); EffectsList::setParameter(oldeffect, "out", QString::number(end)); // kDebug()<<"EDIT FADE OUT : "<fadeOut() != 0 && ix2 == -1) { @@ -3308,14 +3465,14 @@ void CustomTrackView::mouseReleaseEvent(QMouseEvent * event) int end = (item->cropDuration() + item->cropStart()).frames(m_document->fps()); int start = item->fadeOut(); if (start == 0) { - slotDeleteEffect(item, oldeffect, false); + slotDeleteEffect(item, -1, oldeffect, false); } else { start = end - start; QDomElement effect = oldeffect.cloneNode().toElement(); EffectsList::setParameter(oldeffect, "in", QString::number(start)); EffectsList::setParameter(oldeffect, "out", QString::number(end)); // kDebug()<<"EDIT FADE OUT : "<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()); + 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()); if (endPos >= 0) { item->setSpeed(speed, strobe); item->updateRectGeometry(); @@ -3536,17 +3696,106 @@ void CustomTrackView::doChangeClipSpeed(ItemInfo info, ItemInfo speedIndependant void CustomTrackView::cutSelectedClips() { QList itemList = scene()->selectedItems(); + QList groups; GenTime currentPos = GenTime(m_cursorPos, m_document->fps()); - for (int i = 0; i < itemList.count(); i++) { + for (int i = 0; i < itemList.count(); ++i) { + if (!itemList.at(i)) + continue; if (itemList.at(i)->type() == AVWIDGET) { ClipItem *item = static_cast (itemList.at(i)); if (item->parentItem() && item->parentItem() != m_selectionGroup) { - emit displayMessage(i18n("Cannot cut a clip in a group"), ErrorMessage); - } else if (currentPos > item->startPos() && currentPos < item->endPos()) { + AbstractGroupItem *group = static_cast (item->parentItem()); + if (!groups.contains(group)) + groups << group; + } else if (currentPos > item->startPos() && currentPos < item->endPos()) { RazorClipCommand *command = new RazorClipCommand(this, item->info(), currentPos); m_commandStack->push(command); } + } else if (itemList.at(i)->type() == GROUPWIDGET && itemList.at(i) != m_selectionGroup) { + AbstractGroupItem *group = static_cast(itemList.at(i)); + if (!groups.contains(group)) + groups << group; + } + } + + for (int i = 0; i < groups.count(); ++i) + razorGroup(groups.at(i), currentPos); +} + +void CustomTrackView::razorGroup(AbstractGroupItem* group, GenTime cutPos) +{ + if (group) { + QList children = group->childItems(); + QList clips1, transitions1; + QList clipsCut, transitionsCut; + QList clips2, transitions2; + for (int i = 0; i < children.count(); ++i) { + children.at(i)->setSelected(false); + AbstractClipItem *child = static_cast (children.at(i)); + if (child->type() == AVWIDGET) { + if (cutPos > child->endPos()) + clips1 << child->info(); + else if (cutPos < child->startPos()) + clips2 << child->info(); + else + clipsCut << child->info(); + } else { + if (cutPos > child->endPos()) + transitions1 << child->info(); + else if (cutPos < child->startPos()) + transitions2 << child->info(); + else + transitionsCut << child->info(); + } + } + if (clipsCut.isEmpty() && transitionsCut.isEmpty() && ((clips1.isEmpty() && transitions1.isEmpty()) || (clips2.isEmpty() && transitions2.isEmpty()))) + return; + RazorGroupCommand *command = new RazorGroupCommand(this, clips1, transitions1, clipsCut, transitionsCut, clips2, transitions2, cutPos); + m_commandStack->push(command); + } +} + +void CustomTrackView::slotRazorGroup(QList clips1, QList transitions1, QList clipsCut, QList transitionsCut, QList clips2, QList transitions2, GenTime cutPos, bool cut) +{ + if (cut) { + for (int i = 0; i < clipsCut.count(); ++i) { + ClipItem *clip = getClipItemAt(clipsCut.at(i).startPos.frames(m_document->fps()), clipsCut.at(i).track); + if (clip) { + ClipItem *clipBehind = cutClip(clipsCut.at(i), cutPos, true); + clips1 << clip->info(); + if (clipBehind != NULL) + clips2 << clipBehind->info(); + } + } + /* TODO: cut transitionsCut + * For now just append them to group1 */ + transitions1 << transitionsCut; + doGroupClips(clips1, transitions1, true); + doGroupClips(clips2, transitions2, true); + } else { + /* we might also just use clipsCut.at(0)->parentItem(). + * Do this loop just in case something went wrong during cut */ + for (int i = 0; i < clipsCut.count(); ++i) { + ClipItem *clip = getClipItemAt(cutPos.frames(m_document->fps()), clipsCut.at(i).track); + if (clip && clip->parentItem() && clip->parentItem()->type() == GROUPWIDGET) { + AbstractGroupItem *group = static_cast (clip->parentItem()); + QList children = group->childItems(); + QList groupClips; + QList groupTrans; + for (int j = 0; j < children.count(); ++j) { + if (children.at(j)->type() == AVWIDGET) + groupClips << ((AbstractClipItem *)children.at(j))->info(); + else if (children.at(j)->type() == TRANSITIONWIDGET) + groupTrans << ((AbstractClipItem *)children.at(j))->info(); + } + doGroupClips(groupClips, groupTrans, false); + break; + } } + for (int i = 0; i < clipsCut.count(); ++i) + cutClip(clipsCut.at(i), cutPos, false); + // TODO: uncut transitonsCut + doGroupClips(QList () << clips1 << clipsCut << clips2, QList () << transitions1 << transitionsCut << transitions2, true); } } @@ -3634,6 +3883,27 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i emit displayMessage(i18n("No clip copied"), ErrorMessage); return; } + + if (baseclip->producer() == 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) { + m_producerNotReady.wait(&m_mutex, 500 + 500 * i); + } else break; + } + if (baseclip->producer() == NULL) { + emit displayMessage(i18n("Cannot insert clip..."), ErrorMessage); + m_mutex.unlock(); + return; + } + emit displayMessage(QString(), InformationMessage); + m_mutex.unlock(); + } + ClipItem *item = new ClipItem(baseclip, info, m_document->fps(), xml.attribute("speed", "1").toDouble(), xml.attribute("strobe", "1").toInt()); item->setEffectList(effects); if (xml.hasAttribute("audio_only")) item->setAudioOnly(true); @@ -3653,7 +3923,7 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i else prod = baseclip->producer(info.track); m_document->renderer()->mltInsertClip(info, xml, prod, overwrite, push); for (int i = 0; i < item->effectsCount(); i++) { - m_document->renderer()->mltAddEffect(info.track, info.startPos, item->getEffectArgs(item->effectAt(i)), false); + m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(item->effectAt(i)), false); } setDocumentModified(); if (refresh) m_document->renderer()->doRefresh(); @@ -3913,22 +4183,31 @@ void CustomTrackView::moveGroup(QList startClip, QList sta ItemInfo info = item->info(); int tracknumber = m_document->tracksCount() - info.track - 1; bool isLocked = m_document->trackInfoAt(tracknumber).isLocked; - if (isLocked) item->setItemLocked(true); - else if (item->isItemLocked()) item->setItemLocked(false); + if (isLocked) + item->setItemLocked(true); + else if (item->isItemLocked()) + item->setItemLocked(false); if (item->type() == AVWIDGET) { ClipItem *clip = static_cast (item); 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); + 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); + for (int i = 0; i < clip->effectsCount(); i++) { + m_document->renderer()->mltAddEffect(info.track, info.startPos, getEffectArgs(clip->effectAt(i)), false); + } } else if (item->type() == TRANSITIONWIDGET) { Transition *tr = static_cast (item); int newTrack; - if (!tr->forcedTrack()) newTrack = getPreviousVideoTrack(info.track); - else { + if (!tr->forcedTrack()) { + newTrack = getPreviousVideoTrack(info.track); + } else { newTrack = tr->transitionEndTrack() + trackOffset; if (newTrack < 0 || newTrack > m_document->tracksCount()) newTrack = getPreviousVideoTrack(info.track); } @@ -3936,7 +4215,15 @@ void CustomTrackView::moveGroup(QList startClip, QList sta m_document->renderer()->mltAddTransition(tr->transitionTag(), newTrack, m_document->tracksCount() - info.track, info.startPos, info.endPos, tr->toXML()); } } + resetSelectionGroup(false); + + for (int i = 0; i < children.count(); i++) { + if (children.at(i)->parentItem()) + rebuildGroup((AbstractGroupItem*)children.at(i)->parentItem()); + } + clearSelection(); + KdenliveSettings::setSnaptopoints(snap); m_document->renderer()->doRefresh(); } else kDebug() << "///////// WARNING; NO GROUP TO MOVE"; @@ -4056,20 +4343,25 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol } KdenliveSettings::setSnaptopoints(snap); } + + bool hasParentCommand = false; + if (command) { + hasParentCommand = true; + } else { + command = new QUndoCommand(); + command->setText(i18n("Resize clip start")); + } + + // do this here, too, because otherwise undo won't update the group + if (item->parentItem() && item->parentItem() != m_selectionGroup) + new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command); + ItemInfo info = item->info(); if (item->type() == AVWIDGET) { ItemInfo resizeinfo = oldInfo; resizeinfo.track = m_document->tracksCount() - resizeinfo.track; bool success = m_document->renderer()->mltResizeClipStart(resizeinfo, item->startPos() - oldInfo.startPos); if (success) { - bool hasParentCommand = false; - if (command) { - hasParentCommand = true; - } else { - command = new QUndoCommand(); - command->setText(i18n("Resize clip start")); - } - // Check if there is an automatic transition on that clip (lower track) Transition *transition = getTransitionItemAtStart(oldInfo.startPos, oldInfo.track); if (transition && transition->isAutomatic()) { @@ -4124,9 +4416,6 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol } else { new ResizeClipCommand(this, oldInfo, info, false, false, command); } - - if (!hasParentCommand) - m_commandStack->push(command); } else { KdenliveSettings::setSnaptopoints(false); item->resizeStart((int) oldInfo.startPos.frames(m_document->fps())); @@ -4149,7 +4438,10 @@ void CustomTrackView::prepareResizeClipStart(AbstractClipItem* item, ItemInfo ol } if (item->parentItem() && item->parentItem() != m_selectionGroup) - new RebuildGroupCommand(this, item->info().track, item->info().startPos, command); + new RebuildGroupCommand(this, item->info().track, item->endPos() - GenTime(1, m_document->fps()), command); + + if (!hasParentCommand) + m_commandStack->push(command); } void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldInfo, int pos, bool check, QUndoCommand *command) @@ -4168,20 +4460,25 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI } KdenliveSettings::setSnaptopoints(snap); } + + bool hasParentCommand = false; + if (command) { + hasParentCommand = true; + } else { + command = new QUndoCommand(); + command->setText(i18n("Resize clip end")); + } + + // do this here, too, because otherwise undo won't update the group + if (item->parentItem() && item->parentItem() != m_selectionGroup) + new RebuildGroupCommand(this, item->info().track, item->startPos(), command); + ItemInfo info = item->info(); if (item->type() == AVWIDGET) { ItemInfo resizeinfo = info; resizeinfo.track = m_document->tracksCount() - resizeinfo.track; bool success = m_document->renderer()->mltResizeClipEnd(resizeinfo, resizeinfo.endPos - resizeinfo.startPos); if (success) { - bool hasParentCommand = false; - if (command) { - hasParentCommand = true; - } else { - command = new QUndoCommand(); - command->setText(i18n("Resize clip end")); - } - // Check if there is an automatic transition on that clip (lower track) Transition *tr = getTransitionItemAtEnd(oldInfo.endPos, oldInfo.track); if (tr && tr->isAutomatic()) { @@ -4237,8 +4534,6 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI new ResizeClipCommand(this, oldInfo, info, false, false, command); } - if (!hasParentCommand) - m_commandStack->push(command); updatePositionEffects(clip, oldInfo); } else { KdenliveSettings::setSnaptopoints(false); @@ -4261,7 +4556,10 @@ void CustomTrackView::prepareResizeClipEnd(AbstractClipItem* item, ItemInfo oldI } } if (item->parentItem() && item->parentItem() != m_selectionGroup) - new RebuildGroupCommand(this, item->info().track, item->info().startPos, command); + new RebuildGroupCommand(this, item->info().track, item->startPos(), command); + + if (!hasParentCommand) + m_commandStack->push(command); } void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) @@ -4282,7 +4580,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) 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(), item->getEffectArgs(oldeffect))) + 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); @@ -4300,7 +4598,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) 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(), item->getEffectArgs(oldeffect))) + 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); @@ -4322,7 +4620,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) 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(), item->getEffectArgs(oldeffect))) + 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); @@ -4340,7 +4638,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) 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(), item->getEffectArgs(oldeffect))) + 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); @@ -4372,7 +4670,7 @@ void CustomTrackView::updatePositionEffects(ClipItem * item, ItemInfo info) } oldeffect.setAttribute("in", start); oldeffect.setAttribute("out", max); - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), item->getEffectArgs(oldeffect))) + 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); @@ -5175,7 +5473,7 @@ void CustomTrackView::slotUpdateAllThumbs() for (int i = 0; i < itemList.count(); i++) { if (itemList.at(i)->type() == AVWIDGET) { item = static_cast (itemList.at(i)); - if (item->clipType() != COLOR && item->clipType() != AUDIO) { + if (item && item->isEnabled() && item->clipType() != COLOR && item->clipType() != AUDIO) { // Check if we have a cached thumbnail if (item->clipType() == IMAGE || item->clipType() == TEXT) { QString thumb = thumbBase + item->baseClip()->getClipHash() + "_0.png"; @@ -5200,9 +5498,8 @@ void CustomTrackView::slotUpdateAllThumbs() item->slotSetEndThumb(pix); } } + item->refreshClip(false); } - item->refreshClip(false); - //qApp->processEvents(); } } viewport()->update(); @@ -6033,3 +6330,94 @@ void CustomTrackView::setTipAnimation(AbstractClipItem *clip, OPERATIONTYPE mode m_animationTimer->start(); } } + +bool CustomTrackView::hasAudio(int track) const +{ + QRectF rect(0, (double)(track * m_tracksHeight + 1), (double) sceneRect().width(), (double)(m_tracksHeight - 1)); + QList collisions = scene()->items(rect, Qt::IntersectsItemBoundingRect); + QGraphicsItem *item; + for (int i = 0; i < collisions.count(); i++) { + item = collisions.at(i); + if (!item->isEnabled()) continue; + if (item->type() == AVWIDGET) { + ClipItem *clip = static_cast (item); + if (!clip->isVideoOnly() && (clip->clipType() == AUDIO || clip->clipType() == AV || clip->clipType() == PLAYLIST)) return true; + } + } + return false; +} + +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); + setDocumentModified(); +} + + +EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) +{ + EffectsParameterList parameters; + parameters.addParam("tag", effect.attribute("tag")); + if (effect.hasAttribute("region")) parameters.addParam("region", effect.attribute("region")); + parameters.addParam("kdenlive_ix", effect.attribute("kdenlive_ix")); + parameters.addParam("id", effect.attribute("id")); + if (effect.hasAttribute("src")) parameters.addParam("src", effect.attribute("src")); + if (effect.hasAttribute("disable")) parameters.addParam("disable", effect.attribute("disable")); + if (effect.hasAttribute("in")) parameters.addParam("in", effect.attribute("in")); + if (effect.hasAttribute("out")) parameters.addParam("out", effect.attribute("out")); + + 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") == "simplekeyframe") { + + QStringList values = e.attribute("keyframes").split(";", QString::SkipEmptyParts); + double factor = e.attribute("factor", "1").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); + } + // kDebug() << "/ / / /SENDING KEYFR:" << values; + parameters.addParam(e.attribute("name"), values.join(";")); + /*parameters.addParam(e.attribute("name"), e.attribute("keyframes").replace(":", "=")); + parameters.addParam("max", e.attribute("max")); + parameters.addParam("min", e.attribute("min")); + parameters.addParam("factor", e.attribute("factor", "1"));*/ + } else if (e.attribute("type") == "keyframe") { + kDebug() << "/ / / /SENDING KEYFR EFFECT TYPE"; + parameters.addParam("keyframes", e.attribute("keyframes")); + parameters.addParam("max", e.attribute("max")); + parameters.addParam("min", e.attribute("min")); + parameters.addParam("factor", e.attribute("factor", "1")); + parameters.addParam("starttag", e.attribute("starttag", "start")); + parameters.addParam("endtag", e.attribute("endtag", "end")); + } else if (e.attribute("namedesc").contains(';')) { + QString format = e.attribute("format"); + QStringList separators = format.split("%d", QString::SkipEmptyParts); + QStringList values = e.attribute("value").split(QRegExp("[,:;x]")); + QString neu; + QTextStream txtNeu(&neu); + if (values.size() > 0) + txtNeu << (int)values[0].toDouble(); + for (int i = 0; i < separators.size() && i + 1 < values.size(); i++) { + txtNeu << separators[i]; + txtNeu << (int)(values[i+1].toDouble()); + } + parameters.addParam("start", neu); + } else { + if (e.attribute("factor", "1") != "1") { + double fact; + if (e.attribute("factor").startsWith('%')) { + 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 { + parameters.addParam(e.attribute("name"), e.attribute("value")); + } + } + } + return parameters; +} \ No newline at end of file