X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fcustomtrackview.cpp;h=38ab4d668a5551506a3cf8050834fba8b4864652;hb=f389b8c737a6a0f9450beb20328058fdce10093f;hp=44e932e02aa0fed328abc003640a310dbb936c56;hpb=c61a7e8c4518bbb3762384d5ed15ab3343682976;p=kdenlive diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 44e932e0..38ab4d66 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -130,7 +130,7 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen m_commandStack = doc->commandStack(); else m_commandStack = NULL; - + m_ct = 0; setMouseTracking(true); setAcceptDrops(true); setFrameShape(QFrame::NoFrame); @@ -142,8 +142,6 @@ CustomTrackView::CustomTrackView(KdenliveDoc *doc, CustomTrackScene* projectscen m_activeTrackBrush = KStatefulBrush(KColorScheme::View, KColorScheme::ActiveBackground, KSharedConfig::openConfig(KdenliveSettings::colortheme())); - m_pixmapCache = new KPixmapCache("kdenlive-thumbs"); - m_animationTimer = new QTimeLine(800); m_animationTimer->setFrameRange(0, 5); m_animationTimer->setUpdateInterval(100); @@ -188,7 +186,6 @@ CustomTrackView::~CustomTrackView() qDeleteAll(m_guides); m_guides.clear(); m_waitingThumbs.clear(); - delete m_pixmapCache; delete m_animationTimer; } @@ -587,7 +584,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); @@ -704,7 +708,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) { @@ -732,7 +735,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(); @@ -972,7 +974,12 @@ 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 @@ -1323,26 +1330,37 @@ void CustomTrackView::editItemDuration() 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); @@ -1583,7 +1601,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; } @@ -1614,7 +1632,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()); @@ -1635,7 +1654,7 @@ void CustomTrackView::deleteEffect(int track, GenTime pos, QDomElement effect) QString index = effect.attribute("kdenlive_ix"); if (pos < GenTime()) { // Delete track effect - if (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); @@ -1650,11 +1669,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; @@ -1695,11 +1714,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++; } @@ -1772,12 +1787,6 @@ 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); } } @@ -1864,10 +1873,6 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE 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); @@ -1888,7 +1893,8 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE 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; + 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()); @@ -1903,10 +1909,6 @@ void CustomTrackView::updateEffect(int track, GenTime pos, QDomElement insertedE } 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); @@ -2078,9 +2080,6 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo if (dup->checkKeyFrames()) slotRefreshEffects(dup); - updatePanZoom(item); - updatePanZoom(dup, cutTime - item->startPos()); - item->baseClip()->addReference(); m_document->updateClip(item->baseClip()->getId()); setDocumentModified(); @@ -2137,9 +2136,6 @@ ClipItem *CustomTrackView::cutClip(ItemInfo info, GenTime cutTime, bool cut, boo bool success = m_document->renderer()->mltResizeClipEnd(clipinfo, info.endPos - info.startPos); if (success) { item->resizeEnd((int) info.endPos.frames(m_document->fps())); - - updatePanZoom(item); - setDocumentModified(); } else { emit displayMessage(i18n("Error when resizing clip"), ErrorMessage); @@ -2726,9 +2722,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) { + if (clip->clipType() == AV || clip->clipType() == AUDIO || clip->clipType() == PLAYLIST) { Mlt::Producer *prod = clip->getProducer(clipinfo.track); - if (!m_document->renderer()->mltUpdateClipProducer((int)(m_document->tracksCount() - clipinfo.track), clipinfo.startPos.frames(m_document->fps()), prod)) { + if (prod == NULL || !m_document->renderer()->mltUpdateClipProducer((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); } } @@ -2895,9 +2891,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); @@ -2914,7 +2917,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; @@ -2946,6 +2948,38 @@ 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); @@ -3461,9 +3495,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; adjustTimelineClips(m_scene->editMode(), clip, ItemInfo(), moveGroup); - m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track), 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); } @@ -3702,9 +3737,15 @@ 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); @@ -3754,7 +3795,6 @@ void CustomTrackView::deleteSelectedClips() scene()->clearSelection(); QUndoCommand *deleteSelected = new QUndoCommand(); - bool resetGroup = false; int groupCount = 0; int clipCount = 0; int transitionCount = 0; @@ -3765,7 +3805,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)); @@ -3791,7 +3830,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); @@ -3799,7 +3837,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); } @@ -3817,6 +3854,7 @@ void CustomTrackView::deleteSelectedClips() 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); @@ -3830,7 +3868,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; @@ -3980,7 +4017,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(); @@ -4085,6 +4121,7 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i 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); @@ -4092,7 +4129,7 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i baseclip->addReference(); m_document->updateClip(baseclip->getId()); info.track = m_document->tracksCount() - info.track; - m_document->renderer()->mltInsertClip(info, xml, item->getProducer(info.track), 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); } @@ -4107,20 +4144,26 @@ void CustomTrackView::addClip(QDomElement xml, const QString &clipId, ItemInfo i void CustomTrackView::slotUpdateClip(const QString &clipId, bool reload) { QList list = scene()->items(); + QList clipList; 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() == clipId) { ItemInfo info = clip->info(); - info.track = m_document->tracksCount() - clip->track(); - if (reload && !m_document->renderer()->mltUpdateClip(info, clip->xml(), clip->baseClip()->producer(info.track))) { + Mlt::Producer *prod = NULL; + 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 (reload && !m_document->renderer()->mltUpdateClip(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, true); + else clipList.append(clip); } } } + for (int i = 0; i < clipList.count(); i++) + clipList.at(i)->refreshClip(true, true); } ClipItem *CustomTrackView::getClipItemAtEnd(GenTime pos, int track) @@ -4355,8 +4398,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; - m_document->renderer()->mltInsertClip(info, clip->xml(), clip->getProducer(info.track)); + 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); } @@ -4457,19 +4501,18 @@ void CustomTrackView::resizeClip(const ItemInfo start, const ItemInfo end, bool 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); @@ -5291,10 +5334,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; } @@ -5486,6 +5541,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(); @@ -5499,9 +5555,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); @@ -5652,8 +5708,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); @@ -5777,25 +5833,6 @@ 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) { QList list = scene()->items(); @@ -5881,7 +5918,9 @@ 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); } } } @@ -5892,7 +5931,7 @@ void CustomTrackView::splitAudio() } } -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) { @@ -5937,6 +5976,20 @@ void CustomTrackView::doSplitAudio(const GenTime &pos, int track, bool split) } 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); } } @@ -5958,9 +6011,18 @@ 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))) { emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage); } + + // 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; } } @@ -6308,10 +6370,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; } @@ -6498,6 +6565,7 @@ void CustomTrackView::slotAddTrackEffect(const QDomElement effect, int ix) 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")); @@ -6510,7 +6578,10 @@ 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); @@ -6518,7 +6589,7 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) 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); + values[j] = pos + "=" + locale.toString(val); } // kDebug() << "/ / / /SENDING KEYFR:" << values; parameters.addParam(e.attribute("name"), values.join(";")); @@ -6550,10 +6621,10 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) } else { if (e.attribute("factor", "1") != "1") { 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)); + parameters.addParam(e.attribute("name"), locale.toString(e.attribute("value").toDouble() / fact)); } else { parameters.addParam(e.attribute("name"), e.attribute("value")); } @@ -6562,23 +6633,6 @@ EffectsParameterList CustomTrackView::getEffectArgs(const QDomElement effect) return parameters; } -void CustomTrackView::updatePanZoom(ClipItem* item, GenTime cutPos) -{ - QList effects = item->updatePanZoom(m_document->width(), m_document->height(), cutPos.frames(m_document->fps())); - - for (int i = 0; i < effects.count(); ++i) { - if (!m_document->renderer()->mltEditEffect(m_document->tracksCount() - item->track(), item->startPos(), getEffectArgs(item->effectAt(effects.at(i))))) - emit displayMessage(i18n("Problem editing effect"), ErrorMessage); - - // if effect is displayed, update the effect edit widget with new clip duration - /*if (item->isSelected() && effects.at(i) == item->selectedEffectIndex()) - emit clipItemSelected(item, effects.at(i));*/ - } - // update always, otherwise there might problems when resizing groups - if (effects.count()) - emit clipItemSelected(item, item->selectedEffectIndex()); -} - void CustomTrackView::updateTrackNames(int track, bool added) { QList tracks = m_document->tracksList(); @@ -6663,8 +6717,7 @@ void CustomTrackView::slotRefreshThumbs(const QString &id, bool resetThumbs) void CustomTrackView::adjustEffects(ClipItem* item, ItemInfo oldInfo, QUndoCommand* command) { - QMap effects; - item->adjustEffectsToDuration(m_document->width(), m_document->height(), oldInfo); + QMap effects = item->adjustEffectsToDuration(m_document->width(), m_document->height(), oldInfo); if (effects.count()) { QMap::const_iterator i = effects.constBegin(); @@ -6674,3 +6727,5 @@ void CustomTrackView::adjustEffects(ClipItem* item, ItemInfo oldInfo, QUndoComma } } } + +