| 1008 | } |
| 1009 | |
| 1010 | bool EffectStackModel::adjustFadeLength(int duration, bool fromStart, bool audioFade, bool videoFade, bool logUndo) |
| 1011 | { |
| 1012 | QWriteLocker locker(&m_lock); |
| 1013 | if (fromStart) { |
| 1014 | // Fade in |
| 1015 | if (m_fadeIns.empty()) { |
| 1016 | if (audioFade) { |
| 1017 | appendEffect(QStringLiteral("fadein")); |
| 1018 | } |
| 1019 | if (videoFade) { |
| 1020 | appendEffect(QStringLiteral("fade_from_black")); |
| 1021 | } |
| 1022 | } |
| 1023 | QList<QModelIndex> indexes; |
| 1024 | auto ptr = m_masterService.lock(); |
| 1025 | int in = 0; |
| 1026 | if (ptr) { |
| 1027 | in = ptr->get_int("in"); |
| 1028 | } |
| 1029 | int oldDuration = -1; |
| 1030 | for (int i = 0; i < rootItem->childCount(); ++i) { |
| 1031 | if (m_fadeIns.count(std::static_pointer_cast<TreeItem>(rootItem->child(i))->getId()) > 0) { |
| 1032 | std::shared_ptr<EffectItemModel> effect = std::static_pointer_cast<EffectItemModel>(rootItem->child(i)); |
| 1033 | if (oldDuration == -1) { |
| 1034 | oldDuration = effect->filter().get_length(); |
| 1035 | } |
| 1036 | effect->filter().set("in", in); |
| 1037 | duration = qMin(pCore->getItemDuration(m_ownerId), duration); |
| 1038 | effect->filter().set("out", in + duration); |
| 1039 | indexes << getIndexFromItem(effect); |
| 1040 | if (effect->filter().get("alpha") == QLatin1String("1")) { |
| 1041 | // Adjust level value to match filter end |
| 1042 | const QString current = effect->filter().get("level"); |
| 1043 | const QChar mod = AssetParameterModel::getKeyframeType(current); |
| 1044 | if (!mod.isNull()) { |
| 1045 | const QString val = QStringLiteral("0%1=0;-1%1=1").arg(mod); |
| 1046 | effect->filter().set("level", val.toUtf8().constData()); |
| 1047 | } else { |
| 1048 | effect->filter().set("level", "0=0;-1=1"); |
| 1049 | } |
| 1050 | } else if (effect->filter().get("level") == QLatin1String("1")) { |
| 1051 | // Adjust level value to match filter end |
| 1052 | const QString current = effect->filter().get("alpha"); |
| 1053 | const QChar mod = AssetParameterModel::getKeyframeType(current); |
| 1054 | if (!mod.isNull()) { |
| 1055 | const QString val = QStringLiteral("0%1=0;-1%1=1").arg(mod); |
| 1056 | effect->filter().set("alpha", val.toUtf8().constData()); |
| 1057 | } else { |
| 1058 | effect->filter().set("alpha", "0=0;-1=1"); |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | if (!indexes.isEmpty()) { |
| 1064 | Q_EMIT dataChanged(indexes.first(), indexes.last(), QVector<int>()); |
| 1065 | pCore->updateItemModel(m_ownerId, QStringLiteral("fadein"), QStringLiteral("out")); |
| 1066 | if (videoFade) { |
| 1067 | int min = pCore->getItemPosition(m_ownerId); |
no test coverage detected