Skip to content

Commit

Permalink
add keyframes support for color parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Aug 29, 2023
1 parent 835f9e7 commit 91072db
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/models/keyframesmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,19 @@ void KeyframesModel::addKeyframe(int parameterIndex, int position)
emit keyframeAdded(name, position);
}
} else {
// Strings and color values
auto value = m_filter->get(name, position);
Mlt::Animation anim = m_filter->getAnimation(name);
if (anim.is_valid() && !anim.is_key(position)) {
mlt_keyframe_type keyframeType = m_filter->getKeyframeType(anim, position, mlt_keyframe_type(-1));
m_filter->blockSignals(true);
m_filter->set(name, value, position, keyframeType);
for (auto &key : parameter->gangedProperties()) {
value = m_filter->get(key, position);
m_filter->set(key, value, position, keyframeType);
}
m_filter->blockSignals(false);
}
emit keyframeAdded(name, position);
}
onFilterChanged(name);
Expand Down
2 changes: 1 addition & 1 deletion src/qml/modules/Shotcut/Controls/ColorPicker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import QtQuick.Layouts
import Shotcut.Controls as Shotcut

RowLayout {
property string value: "white"
property color value: "white"
property bool alpha: false
property alias eyedropper: pickerButton.visible

Expand Down
34 changes: 34 additions & 0 deletions src/qmltypes/qmlfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ QString QmlFilter::get(QString name, int position)
}
}

QColor QmlFilter::getColor(QString name, int position)
{
mlt_color color = {0, 0, 0, 0};
if (m_service.is_valid()) {
if (position < 0)
color = m_service.get_color(qUtf8Printable(name));
else
color = m_service.anim_get_color(qUtf8Printable(name), position, duration());
}
return QColor(color.r, color.g, color.b, color.a);
}

double QmlFilter::getDouble(QString name, int position)
{
if (m_service.is_valid()) {
Expand Down Expand Up @@ -175,6 +187,28 @@ void QmlFilter::set(QString name, QString value, int position)
}
}

void QmlFilter::set(QString name, QColor value, int position, mlt_keyframe_type keyframeType)
{
if (!m_service.is_valid()) return;
if (position < 0) {
auto mltColor = m_service.get_color(qUtf8Printable(name));
if (!m_service.get(qUtf8Printable(name))
|| value != QColor(mltColor.r, mltColor.g, mltColor.b, mltColor.a)) {
m_service.set(qUtf8Printable(name), Util::mltColorFromQColor(value));
emit changed(name);
}
} else {
// Only set an animation keyframe if it does not already exist with the same value.
Mlt::Animation animation(m_service.get_animation(qUtf8Printable(name)));
auto mltColor = m_service.anim_get_color(qUtf8Printable(name), position, duration());
if (!animation.is_valid() || !animation.is_key(position)
|| value != QColor(mltColor.r, mltColor.g, mltColor.b, mltColor.a)) {
m_service.anim_set(qUtf8Printable(name), Util::mltColorFromQColor(value), position, duration());
emit changed(name);
}
}
}

void QmlFilter::set(QString name, double value, int position, mlt_keyframe_type keyframeType)
{
if (!m_service.is_valid()) return;
Expand Down
4 changes: 4 additions & 0 deletions src/qmltypes/qmlfilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <QVariant>
#include <QRectF>
#include <QUuid>
#include <QColor>
#include <MltService.h>
#include <MltProducer.h>
#include <MltAnimation.h>
Expand Down Expand Up @@ -76,11 +77,14 @@ class QmlFilter : public QObject
}

Q_INVOKABLE QString get(QString name, int position = -1);
Q_INVOKABLE QColor getColor(QString name, int position = -1);
Q_INVOKABLE double getDouble(QString name, int position = -1);
Q_INVOKABLE QRectF getRect(QString name, int position = -1);
Q_INVOKABLE void removeRectPercents(QString name);
Q_INVOKABLE QStringList getGradient(QString name);
Q_INVOKABLE void set(QString name, QString value, int position = -1);
Q_INVOKABLE void set(QString name, QColor value,
int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
Q_INVOKABLE void set(QString name, double value,
int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
Q_INVOKABLE void set(QString name, int value,
Expand Down
10 changes: 10 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -823,3 +823,13 @@ QString Util::getConversionAdvice(Mlt::Producer *producer)
}
return advice;
}

mlt_color Util::mltColorFromQColor(const QColor &color)
{
return mlt_color {
static_cast<uint8_t>(color.red()),
static_cast<uint8_t>(color.green()),
static_cast<uint8_t>(color.blue()),
static_cast<uint8_t>(color.alpha())
};
}
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Util
static QString trcString(int trc);
static bool trcIsCompatible(int trc);
static QString getConversionAdvice(Mlt::Producer *producer);
static mlt_color mltColorFromQColor(const QColor &color);
};

#endif // UTIL_H

0 comments on commit 91072db

Please sign in to comment.