Commit 26321bd6 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Mix resizing: allow to go down to 1 frame.

Related to #796
parent 385e885a
Pipeline #95195 canceled with stage
......@@ -632,8 +632,7 @@ int Core::getItemDuration(const ObjectId &id)
return m_mainWindow->getCurrentTimeline()->controller()->duration() - 1;
case ObjectType::TimelineMix:
if (m_mainWindow->getCurrentTimeline()->controller()->getModel()->isClip(id.second)) {
std::pair<int, int> mixInOut = m_mainWindow->getCurrentTimeline()->controller()->getModel()->getMixInOut(id.second);
return (mixInOut.second - mixInOut.first);
return m_mainWindow->getCurrentTimeline()->controller()->getModel()->getMixDuration(id.second);
} else {
qWarning() << "querying non clip properties";
}
......
......@@ -5552,6 +5552,16 @@ bool TimelineModel::resizeStartMix(int cid, int duration, bool singleResize)
return false;
}
int TimelineModel::getMixDuration(int cid) const
{
Q_ASSERT(isClip(cid));
int tid = m_allClips.at(cid)->getCurrentTrackId();
if (tid > -1) {
return getTrackById_const(tid)->getMixDuration(cid);
}
return 0;
}
std::pair<int, int> TimelineModel::getMixInOut(int cid) const
{
Q_ASSERT(isClip(cid));
......@@ -5620,9 +5630,9 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align)
}
}
int updatedDuration = m_allClips.at(clipToResize)->getPosition() + updatedDurationLeft - (m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - updatedDurationRight);
if (updatedDuration < 2) {
if (updatedDuration < 1) {
//
pCore->displayMessage(i18n("Cannot resize mix to less than 2 frames"), ErrorMessage, 500);
pCore->displayMessage(i18n("Cannot resize mix to less than 1 frame"), ErrorMessage, 500);
// update mix widget
emit selectedMixChanged(cid, getTrackById_const(tid)->mixModel(cid), true);
return;
......@@ -5656,9 +5666,9 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align)
updatedDurationLeft = qMin(updatedDurationLeft, m_allClips.at(clipToResize)->getPlaytime() + leftMax);
}
int updatedDuration = m_allClips.at(clipToResize)->getPosition() + updatedDurationLeft - (m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - updatedDurationRight);
if (updatedDuration < 2) {
if (updatedDuration < 1) {
//
pCore->displayMessage(i18n("Cannot resize mix to less than 2 frames"), ErrorMessage, 500);
pCore->displayMessage(i18n("Cannot resize mix to less than 1 frame"), ErrorMessage, 500);
emit selectedMixChanged(cid, getTrackById_const(tid)->mixModel(cid), true);
return;
}
......@@ -5689,8 +5699,8 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align)
updatedDurationLeft = qMin(updatedDurationLeft, m_allClips.at(clipToResize)->getPlaytime() + leftMax);
}
int updatedDuration = m_allClips.at(clipToResize)->getPosition() + updatedDurationLeft - (m_allClips.at(cid)->getPosition() + m_allClips.at(cid)->getPlaytime() - updatedDurationRight);
if (updatedDuration < 2) {
pCore->displayMessage(i18n("Cannot resize mix to less than 2 frames"), ErrorMessage, 500);
if (updatedDuration < 1) {
pCore->displayMessage(i18n("Cannot resize mix to less than 1 frame"), ErrorMessage, 500);
emit selectedMixChanged(cid, getTrackById_const(tid)->mixModel(cid), true);
return;
}
......@@ -5729,9 +5739,9 @@ void TimelineModel::requestResizeMix(int cid, int duration, MixAlignment align)
updatedDurationLeft = qMin(updatedDurationLeft, m_allClips.at(clipToResize)->getPlaytime() + leftMax);
}
int updatedDuration = m_allClips.at(clipToResize)->getPosition() + updatedDurationLeft - m_allClips.at(cid)->getPosition();
if (updatedDuration < 2) {
if (updatedDuration < 1) {
//
pCore->displayMessage(i18n("Cannot resize mix to less than 2 frames"), ErrorMessage, 500);
pCore->displayMessage(i18n("Cannot resize mix to less than 1 frame"), ErrorMessage, 500);
emit selectedMixChanged(cid, getTrackById_const(tid)->mixModel(cid), true);
return;
}
......
......@@ -208,6 +208,7 @@ public:
int getSubtitlePosition(int subId) const;
int getCompositionPlaytime(int compoId) const;
std::pair<int, int> getMixInOut(int cid) const;
int getMixDuration(int cid) const;
/** @brief Returns an item position, item can be clip or composition */
Q_INVOKABLE int getItemPosition(int itemId) const;
......
......@@ -2249,6 +2249,13 @@ void TrackModel::setMixDuration(int cid, int mixDuration, int mixCut)
emit m_sameCompositions[cid]->dataChanged(QModelIndex(), QModelIndex(), {AssetParameterModel::ParentDurationRole});
}
int TrackModel::getMixDuration(int cid) const
{
Q_ASSERT(m_sameCompositions.count(cid) > 0);
Mlt::Transition &transition = *static_cast<Mlt::Transition*>(m_sameCompositions.at(cid)->getAsset());
return transition.get_length() - 1;
}
void TrackModel::removeMix(MixInfo info)
{
Q_ASSERT(m_sameCompositions.count(info.secondClipId) > 0);
......
......@@ -135,6 +135,7 @@ public:
bool loadMix(Mlt::Transition *t);
/** @brief Set mix duration and mix cut pos on a clip */
void setMixDuration(int cid, int mixDuration, int mixCut);
int getMixDuration(int cid) const;
/** @brief Get the assetparameter model for a mix */
const std::shared_ptr<AssetParameterModel> mixModel(int cid);
/** @brief Get a list of current effect stack zones */
......
......@@ -23,6 +23,7 @@ MixStackView::MixStackView(QWidget *parent)
{
m_durationLayout = new QHBoxLayout;
m_duration = new TimecodeDisplay(pCore->timecode(), this);
m_duration->setRange(1, -1);
m_durationLayout->addWidget(new QLabel(i18n("Duration:")));
m_durationLayout->addWidget(m_duration);
m_alignLeft = new QToolButton(this);
......@@ -68,7 +69,7 @@ void MixStackView::setModel(const std::shared_ptr<AssetParameterModel> &model, Q
if (m_model->rowCount() > 0) {
QSignalBlocker bk0(m_duration);
m_duration->setValue(m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt());
m_duration->setValue(m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt() + 1);
connect(m_model.get(), &AssetParameterModel::dataChanged, this, &MixStackView::durationChanged);
}
int mainClipId = stackOwner().second;
......@@ -103,7 +104,7 @@ void MixStackView::durationChanged(const QModelIndex &, const QModelIndex &, con
{
if (roles.contains(AssetParameterModel::ParentDurationRole)) {
QSignalBlocker bk1(m_duration);
m_duration->setValue(m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt());
m_duration->setValue(m_model->data(m_model->index(0, 0), AssetParameterModel::ParentDurationRole).toInt() + 1);
}
}
......@@ -123,7 +124,7 @@ MixAlignment MixStackView::alignment() const
void MixStackView::updateDuration()
{
pCore->resizeMix(stackOwner().second, m_duration->getValue(), alignment());
pCore->resizeMix(stackOwner().second, m_duration->getValue() - 1, alignment());
}
void MixStackView::slotAlignLeft()
......@@ -133,7 +134,7 @@ void MixStackView::slotAlignLeft()
}
m_alignRight->setChecked(false);
m_alignCenter->setChecked(false);
pCore->resizeMix(stackOwner().second, m_duration->getValue(), MixAlignment::AlignLeft);
pCore->resizeMix(stackOwner().second, m_duration->getValue() - 1, MixAlignment::AlignLeft);
}
void MixStackView::slotAlignRight()
......@@ -143,7 +144,7 @@ void MixStackView::slotAlignRight()
}
m_alignLeft->setChecked(false);
m_alignCenter->setChecked(false);
pCore->resizeMix(stackOwner().second, m_duration->getValue(), MixAlignment::AlignRight);
pCore->resizeMix(stackOwner().second, m_duration->getValue() - 1, MixAlignment::AlignRight);
}
void MixStackView::slotAlignCenter()
......@@ -153,7 +154,7 @@ void MixStackView::slotAlignCenter()
}
m_alignLeft->setChecked(false);
m_alignRight->setChecked(false);
pCore->resizeMix(stackOwner().second, m_duration->getValue(), MixAlignment::AlignCenter);
pCore->resizeMix(stackOwner().second, m_duration->getValue() - 1, MixAlignment::AlignCenter);
}
void MixStackView::unsetModel()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment