Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Cleanup fades

parent 531f9ec5
......@@ -41,6 +41,7 @@ std::shared_ptr<EffectItemModel> EffectItemModel::construct(const QString &effec
QDomElement xml = EffectsRepository::get()->getXml(effectId);
Mlt::Properties *effect = EffectsRepository::get()->getEffect(effectId);
effect->set("kdenlive:id", effectId.toUtf8().constData());
QList<QVariant> data;
data << EffectsRepository::get()->getName(effectId) << effectId;
......
......@@ -99,66 +99,106 @@ void EffectStackModel::appendEffect(const QString &effectId)
}
}
bool EffectStackModel::adjustEffectLength(const QString &effectName, int duration)
bool EffectStackModel::adjustFadeLength(int duration, bool fromStart, bool audioFade, bool videoFade)
{
int row = -1;
for (int i = 0; i < rootItem->childCount(); ++i) {
if (std::static_pointer_cast<AbstractEffectItem>(rootItem->child(i))->dataColumn(1) == effectName) {
row = i;
break;
if (fromStart) {
// Fade in
int audioRow = audioFade ? getEffectById(QStringLiteral("fadein")) : -1;
int videoRow = videoFade ? getEffectById(QStringLiteral("fade_from_black")) : -1;
if (audioRow == -1 && videoRow == -1) {
if (audioFade) {
appendEffect(QStringLiteral("fadein"));
audioRow = rootItem->childCount() - 1;
}
if (videoFade) {
appendEffect(QStringLiteral("fade_from_black"));
videoRow = rootItem->childCount() - 1;
}
}
QModelIndex audioIx;
QModelIndex videoIx;
if (audioFade && audioRow > -1) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(audioRow));
effect->filter().set("out", duration);
audioIx = getIndexFromItem(effect);
}
if (videoFade && videoRow > -1) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(videoRow));
effect->filter().set("out", duration);
videoIx = getIndexFromItem(effect);
}
emit dataChanged(audioIx.isValid() ? audioIx : videoIx, videoIx.isValid() ? videoIx : audioIx, QVector<int>());
} else {
// Fade out
int audioRow = audioFade ? getEffectById(QStringLiteral("fadeout")) : -1;
int videoRow = videoFade ? getEffectById(QStringLiteral("fade_to_black")) : -1;
if (audioRow == -1 && videoRow == -1) {
if (audioFade) {
appendEffect(QStringLiteral("fadeout"));
audioRow = rootItem->childCount() - 1;
}
if (videoFade) {
appendEffect(QStringLiteral("fade_to_black"));
videoRow = rootItem->childCount() - 1;
}
}
}
if (row == -1) {
appendEffect(effectName);
row = rootItem->childCount() - 1;
}
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(row));
if (effectName == QLatin1String("fadein")) {
effect->filter().set("out", duration);
QModelIndex ix = getIndexFromItem(effect);
emit dataChanged(ix, ix, QVector<int>());
}
else if (effectName == QLatin1String("fadeout")) {
int out = pCore->getItemDuration(m_ownerId);
effect->filter().set("out", out);
effect->filter().set("in", out - duration);
QModelIndex ix = getIndexFromItem(effect);
emit dataChanged(ix, ix, QVector<int>());
QModelIndex audioIx;
QModelIndex videoIx;
if (audioFade && audioRow > -1) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(audioRow));
effect->filter().set("out", out);
effect->filter().set("in", out - duration);
audioIx = getIndexFromItem(effect);
}
if (videoFade && videoRow > -1) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(videoRow));
effect->filter().set("out", out);
effect->filter().set("in", out - duration);
videoIx = getIndexFromItem(effect);
}
emit dataChanged(audioIx.isValid() ? audioIx : videoIx, videoIx.isValid() ? videoIx : audioIx, QVector<int>());
}
return true;
}
int EffectStackModel::getFadeIn()
int EffectStackModel::getFadePosition(bool fromStart)
{
for (int i = 0; i < rootItem->childCount(); ++i) {
if (std::static_pointer_cast<AbstractEffectItem>(rootItem->child(i))->dataColumn(1) == QLatin1String("fadein")) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(i));
int row = -1;
if (fromStart) {
row = getEffectById(QStringLiteral("fadein"));
if (row == -1) row = getEffectById(QStringLiteral("fade_from_black"));
if (row != -1) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(row));
return effect->filter().get_int("out");
}
}
return 0;
}
int EffectStackModel::getFadeOut()
{
for (int i = 0; i < rootItem->childCount(); ++i) {
if (std::static_pointer_cast<AbstractEffectItem>(rootItem->child(i))->dataColumn(1) == QLatin1String("fadeout")) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(i));
} else {
row = getEffectById(QStringLiteral("fadeout"));
if (row == -1) row = getEffectById(QStringLiteral("fade_to_black"));
if (row != -1) {
std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(getEffectStackRow(row));
return effect->filter().get_int("out") - effect->filter().get_int("in");
}
}
return 0;
}
bool EffectStackModel::removeEffectById(const QString &effectName)
int EffectStackModel::getEffectById(const QString &effectName)
{
int row = -1;
for (int i = 0; i < rootItem->childCount(); ++i) {
if (std::static_pointer_cast<AbstractEffectItem>(rootItem->child(i))->dataColumn(1) == effectName) {
row = i;
return i;
break;
}
}
return -1;
}
bool EffectStackModel::removeEffectById(const QString &effectName)
{
int row = getEffectById(effectName);
if (row == -1) {
return false;
}
......
......@@ -77,15 +77,14 @@ public:
/* @brief Get currently active effect row */
int getActiveEffect() const;
/* @brief Adjust an effect duration (useful for fades) */
bool adjustEffectLength(const QString &effectName, int duration);
bool adjustFadeLength(int duration, bool fromStart, bool audioFade, bool videoFade);
void slotCreateGroup(std::shared_ptr<EffectItemModel> childEffect);
/* @brief Returns the id of the owner of the stack */
ObjectId getOwnerId() const;
int getFadeIn();
int getFadeOut();
int getFadePosition(bool fromStart);
public slots:
/* @brief Delete an effect from the stack */
......@@ -103,8 +102,10 @@ protected:
ObjectId m_ownerId;
std::weak_ptr<DocUndoStack> m_undoStack;
private:
mutable QReadWriteLock m_lock;
int getEffectById(const QString &effectName);
};
#endif
......@@ -210,7 +210,9 @@ bool ClipModel::removeEffect(const QString &effectId)
bool ClipModel::adjustEffectLength(const QString &effectName, int duration)
{
READ_LOCK();
m_effectStack->adjustEffectLength(effectName, duration);
qDebug()<<"// ADJUSTING FADE: "<<hasAudio()<<", "<<!isAudioOnly();
m_effectStack->adjustFadeLength(duration, effectName == QLatin1String("fadein"), hasAudio(), !isAudioOnly());
//m_effectStack->adjustEffectLength(effectName, duration, isAudioOnly());
return true;
}
......@@ -218,7 +220,7 @@ bool ClipModel::hasAudio() const
{
READ_LOCK();
QString service = getProperty("mlt_service");
return service.contains(QStringLiteral("avformat"));
return service.contains(QStringLiteral("avformat")) && (getIntProperty(QStringLiteral("audio_index")) > -1);
}
bool ClipModel::isAudioOnly() const
......@@ -266,11 +268,11 @@ std::shared_ptr<MarkerListModel> ClipModel::getMarkerModel() const
int ClipModel::fadeIn() const
{
return m_effectStack->getFadeIn();
return m_effectStack->getFadePosition(true);
}
int ClipModel::fadeOut() const
{
return m_effectStack->getFadeOut();
return m_effectStack->getFadePosition(false);
}
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