Krita Source Code Documentation
Loading...
Searching...
No Matches
KisScalarKeyframeChannel Class Reference

The KisScalarKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisScalarKeyframes. More...

#include <kis_scalar_keyframe_channel.h>

+ Inheritance diagram for KisScalarKeyframeChannel:

Classes

struct  Private
 

Public Member Functions

void addScalarKeyframe (int time, qreal value, KUndo2Command *parentUndoCmd=nullptr)
 
virtual KisTimeSpan affectedFrames (int time) const override
 Get the set of frames affected by any changes to the value or content of the active keyframe at the given time.
 
qreal currentValue ()
 
virtual KisTimeSpan identicalFrames (int time) const override
 Get a span of times for which the channel gives identical results compared to frame at a given time. NOTE: This set may be different than the set of affected frames due to interpolation.
 
virtual void insertKeyframe (int time, KisKeyframeSP keyframe, KUndo2Command *parentUndoCmd=nullptr) override
 Insert an existing keyframe into the channel at the specified time.
 
bool isCurrentTimeAffectedBy (int keyTime)
 
 KisScalarKeyframeChannel (const KisScalarKeyframeChannel &rhs)
 
 KisScalarKeyframeChannel (const KoID &id, KisDefaultBoundsBaseSP bounds)
 
QSharedPointer< ScalarKeyframeLimits > limits () const
 
virtual void removeKeyframe (int time, KUndo2Command *parentUndoCmd=nullptr) override
 Remove a keyframe from the channel at the specified time.
 
void removeLimits ()
 
void setDefaultInterpolationMode (KisScalarKeyframe::InterpolationMode mode)
 
void setDefaultValue (qreal value)
 
void setLimits (qreal low, qreal high)
 
qreal valueAt (int time) const
 Quickly get the interpolated value at the given time.
 
 ~KisScalarKeyframeChannel () override
 
- Public Member Functions inherited from KisKeyframeChannel
KisKeyframeSP activeKeyframeAt (int time) const
 
template<class KeyframeType >
QSharedPointer< KeyframeType > activeKeyframeAt (int time) const
 
int activeKeyframeTime () const
 
int activeKeyframeTime (int time) const
 Get the time of the active keyframe. Useful for snapping any time to that of the most recent keyframe.
 
void addKeyframe (int time, KUndo2Command *parentUndoCmd=nullptr)
 Add a new keyframe to the channel at the specified time.
 
QSet< int > allKeyframeTimes () const
 Get a set of all integer times that map to a keyframe.
 
int channelHash () const
 Calculates a pseudo-unique hash based on the relevant internal state of the channel.
 
void copyKeyframe (int sourceTime, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 
int firstKeyframeTime () const
 
QString id () const
 
KisKeyframeSP keyframeAt (int time) const
 Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.
 
template<class KeyframeType >
QSharedPointer< KeyframeType > keyframeAt (int time) const
 
int keyframeCount () const
 
 KisKeyframeChannel (const KisKeyframeChannel &rhs)
 
 KisKeyframeChannel (const KoID &id, KisDefaultBoundsBaseSP bounds)
 
int lastKeyframeTime () const
 
virtual void loadXML (const QDomElement &channelNode)
 
int lookupKeyframeTime (KisKeyframeSP toLookup)
 Search for the time for a given keyframe. (Reverse map lookup, so use sparingly.)
 
void moveKeyframe (int sourceTime, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 
QString name () const
 
int nextKeyframeTime (const int time) const
 
KisNodeWSP node () const
 
int previousKeyframeTime (const int time) const
 
void setDefaultBounds (KisDefaultBoundsBaseSP bounds)
 
void setNode (KisNodeWSP node)
 
void swapKeyframes (int timeA, int timeB, KUndo2Command *parentUndoCmd=nullptr)
 
virtual QDomElement toXML (QDomDocument doc, const QString &layerFilename)
 
 ~KisKeyframeChannel () override
 

Static Public Member Functions

static QPointF interpolate (QPointF point1, QPointF rightTangent, QPointF leftTangent, QPointF point2, qreal t)
 
- Static Public Member Functions inherited from KisKeyframeChannel
static KoID channelIdToKoId (const QString &id)
 
static void copyKeyframe (const KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 Copy a keyframe across channel(s) at the specified times.
 
static void moveKeyframe (KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
 Move a keyframe across channel(s) at the specified times.
 
static void swapKeyframes (KisKeyframeChannel *channelA, int timeA, KisKeyframeChannel *channelB, int timeB, KUndo2Command *parentUndoCmd=nullptr)
 Swap two keyframes across channel(s) at the specified times.
 

Private Member Functions

virtual QRect affectedRect (int time) const override
 
virtual KisKeyframeSP createKeyframe () override
 Virtual keyframe creation function. Derived classes implement this function based on the needs of their specific KisKeyframe subclasses.
 
virtual QPair< int, KisKeyframeSP > loadKeyframe (const QDomElement &keyframeNode) override
 
virtual void saveKeyframe (KisKeyframeSP keyframe, QDomElement keyframeElement, const QString &layerFilename) override
 

Static Private Member Functions

static qreal cubicBezier (qreal p0, qreal delta1, qreal delta2, qreal p3, qreal t)
 
static qreal findCubicCurveParameter (int time0, qreal delta0, qreal delta1, int time1, int time)
 
static void normalizeTangents (const QPointF point1, QPointF &rightTangent, QPointF &leftTangent, const QPointF point2)
 

Private Attributes

QScopedPointer< Private > m_d
 

Additional Inherited Members

- Signals inherited from KisKeyframeChannel
void sigAddedKeyframe (const KisKeyframeChannel *channel, int time)
 This signal is emitted just AFTER a keyframe was added to the channel.
 
void sigAnyKeyframeChange ()
 
void sigKeyframeAboutToBeRemoved (const KisKeyframeChannel *channel, int time)
 This signal is emitted just BEFORE a keyframe is removed from the channel.
 
void sigKeyframeChanged (const KisKeyframeChannel *channel, int time)
 This signal is emitted just AFTER a non-raster keyframe was changed its value.
 
void sigKeyframeHasBeenRemoved (const KisKeyframeChannel *channel, int time)
 This signal is emitted just AFTER a keyframe is removed from the channel.
 
- Static Public Attributes inherited from KisKeyframeChannel
static const KoID Opacity = KoID("opacity", ki18n("Opacity"))
 
static const KoID PositionX = KoID("transform_pos_x", ki18n("Position (X)"))
 
static const KoID PositionY = KoID("transform_pos_y", ki18n("Position (Y)"))
 
static const KoID Raster = KoID("content", ki18n("Content"))
 
static const KoID RotationX = KoID("transform_rotation_x", ki18n("Rotation (X)"))
 
static const KoID RotationY = KoID("transform_rotation_y", ki18n("Rotation (Y)"))
 
static const KoID RotationZ = KoID("transform_rotation_z", ki18n("Rotation (Z)"))
 
static const KoID ScaleX = KoID("transform_scale_x", ki18n("Scale (X)"))
 
static const KoID ScaleY = KoID("transform_scale_y", ki18n("Scale (Y)"))
 
static const KoID ShearX = KoID("transform_shear_x", ki18n("Shear (X)"))
 
static const KoID ShearY = KoID("transform_shear_y", ki18n("Shear (Y)"))
 
static const KoID TransformArguments
 
- Protected Types inherited from KisKeyframeChannel
typedef QMap< int, KisKeyframeSP > TimeKeyframeMap
 
- Protected Member Functions inherited from KisKeyframeChannel
const TimeKeyframeMap & constKeys () const
 
int currentTime () const
 
TimeKeyframeMap & keys ()
 
virtual void removeKeyframeImpl (int time, KUndo2Command *parentUndoCmd)
 
Q_DECL_DEPRECATED void workaroundBrokenFrameTimeBug (int *time)
 Between Krita 4.1 and 4.4 Krita had a bug which resulted in creating frames with negative time stamp. The bug has been fixed, but there might be some files still in the wild.
 

Detailed Description

The KisScalarKeyframeChannel is a concrete KisKeyframeChannel subclass that stores and manages KisScalarKeyframes.

This class maps units of time (in frames) to points along a curve for the animation of various interpolated scalar parameters within Krita. Each scalar channel can be provided with default values and interpolation modes, as well as an optional ScalarKeyframeLimits object that can be used to limit the range of possible values.

Generally, each scalar channel will be represented as an individual curve within Krita's KisAnimationCurvesDocker.

Definition at line 119 of file kis_scalar_keyframe_channel.h.

Constructor & Destructor Documentation

◆ KisScalarKeyframeChannel() [1/2]

KisScalarKeyframeChannel::KisScalarKeyframeChannel ( const KoID & id,
KisDefaultBoundsBaseSP bounds )

Definition at line 167 of file kis_scalar_keyframe_channel.cpp.

169 , m_d(new Private)
170{
171}
KisKeyframeChannel(const KoID &id, KisDefaultBoundsBaseSP bounds)
#define bounds(x, a, b)

◆ KisScalarKeyframeChannel() [2/2]

KisScalarKeyframeChannel::KisScalarKeyframeChannel ( const KisScalarKeyframeChannel & rhs)

Definition at line 173 of file kis_scalar_keyframe_channel.cpp.

174 : KisKeyframeChannel(rhs)
175{
176 m_d.reset(new Private(*rhs.m_d));
177
178 Q_FOREACH (int time, rhs.constKeys().keys()) {
179 KisKeyframeChannel::copyKeyframe(&rhs, time, this, time);
180 }
181}
static void copyKeyframe(const KisKeyframeChannel *sourceChannel, int sourceTime, KisKeyframeChannel *targetChannel, int targetTime, KUndo2Command *parentUndoCmd=nullptr)
Copy a keyframe across channel(s) at the specified times.
const TimeKeyframeMap & constKeys() const

References KisKeyframeChannel::constKeys(), KisKeyframeChannel::copyKeyframe(), and m_d.

◆ ~KisScalarKeyframeChannel()

KisScalarKeyframeChannel::~KisScalarKeyframeChannel ( )
override

Definition at line 183 of file kis_scalar_keyframe_channel.cpp.

184{
185}

Member Function Documentation

◆ addScalarKeyframe()

void KisScalarKeyframeChannel::addScalarKeyframe ( int time,
qreal value,
KUndo2Command * parentUndoCmd = nullptr )

Utility for adding keyframe with non-default value.

Definition at line 187 of file kis_scalar_keyframe_channel.cpp.

187 {
188 KisScalarKeyframeSP scalarKey = keyframeAt<KisScalarKeyframe>(time);
189 if (!scalarKey) {
190 addKeyframe(time, parentUndoCmd);
191 scalarKey = keyframeAt<KisScalarKeyframe>(time);
192 }
193
194 if (scalarKey) {
195 scalarKey->setValue(value, parentUndoCmd);
196 }
197}
float value(const T *src, size_t ch)
void addKeyframe(int time, KUndo2Command *parentUndoCmd=nullptr)
Add a new keyframe to the channel at the specified time.

References KisKeyframeChannel::addKeyframe(), and value().

◆ affectedFrames()

KisTimeSpan KisScalarKeyframeChannel::affectedFrames ( int time) const
overridevirtual

Get the set of frames affected by any changes to the value or content of the active keyframe at the given time.

Reimplemented from KisKeyframeChannel.

Definition at line 337 of file kis_scalar_keyframe_channel.cpp.

338{
340
341 const int activeKeyTime = activeKeyframeTime(time);
342 const int previousKeyTime = previousKeyframeTime(activeKeyTime);
343 const KisScalarKeyframeSP prevScalarKey = keyframeAt<KisScalarKeyframe>(previousKeyTime);
344
345 if(prevScalarKey) {
346 // In the case that a previous keyframe is present with a non-constant interpolation mode,
347 // the affected frames must include all the frames just after the previous keyframe.
348 if (prevScalarKey->interpolationMode() == KisScalarKeyframe::Constant) {
349 return normalSpan;
350 } else {
351 return normalSpan | KisTimeSpan::fromTimeToTime(previousKeyTime + 1, activeKeyTime);
352 }
353 } else {
354 const KisScalarKeyframeSP firstScalarKey = keyframeAt<KisScalarKeyframe>(firstKeyframeTime());
355 if (!firstScalarKey) {
356 return KisTimeSpan::infinite(0);
357 }
358 return normalSpan | KisTimeSpan::fromTimeToTime(0, activeKeyTime);
359 }
360}
int previousKeyframeTime(const int time) const
virtual KisTimeSpan affectedFrames(int time) const
Get the set of frames affected by any changes to the value or content of the active keyframe at the g...
static KisTimeSpan infinite(int start)
static KisTimeSpan fromTimeToTime(int start, int end)

References KisKeyframeChannel::activeKeyframeTime(), KisKeyframeChannel::affectedFrames(), KisScalarKeyframe::Constant, KisKeyframeChannel::firstKeyframeTime(), KisTimeSpan::fromTimeToTime(), KisTimeSpan::infinite(), and KisKeyframeChannel::previousKeyframeTime().

◆ affectedRect()

QRect KisScalarKeyframeChannel::affectedRect ( int time) const
overrideprivatevirtual

The rect that is affected by a frame at the given time

Implements KisKeyframeChannel.

Definition at line 450 of file kis_scalar_keyframe_channel.cpp.

451{
452 Q_UNUSED(time);
453
454 if (node()) {
455 return node()->exactBounds();
456 } else {
457 return QRect();
458 }
459}
virtual QRect exactBounds() const

References KisBaseNode::exactBounds(), and KisKeyframeChannel::node().

◆ createKeyframe()

KisKeyframeSP KisScalarKeyframeChannel::createKeyframe ( )
overrideprivatevirtual

Virtual keyframe creation function. Derived classes implement this function based on the needs of their specific KisKeyframe subclasses.

Implements KisKeyframeChannel.

Definition at line 443 of file kis_scalar_keyframe_channel.cpp.

444{
445 KisScalarKeyframe *keyframe = new KisScalarKeyframe(m_d->defaultValue, m_d->limits);
446 keyframe->setInterpolationMode(m_d->defaultInterpolationMode);
447 return toQShared(keyframe);
448}
The KisScalarKeyframe class is a concrete subclass of KisKeyframe that wraps a scalar value and inter...
void setInterpolationMode(InterpolationMode mode, KUndo2Command *parentUndoCmd=nullptr)
QSharedPointer< T > toQShared(T *ptr)

References m_d, KisScalarKeyframe::setInterpolationMode(), and toQShared().

◆ cubicBezier()

qreal KisScalarKeyframeChannel::cubicBezier ( qreal p0,
qreal delta1,
qreal delta2,
qreal p3,
qreal t )
staticprivate

Definition at line 417 of file kis_scalar_keyframe_channel.cpp.

417 {
418 qreal p1 = p0 + delta1;
419 qreal p2 = p3 + delta2;
420
421 qreal c = 1-t;
422 return c*c*c * p0 + 3*c*c*t * p1 + 3*c*t*t * p2 + t*t*t * p3;
423}
QPointF p0
QPointF p2
QPointF p3
QPointF p1

References p0, p1, p2, and p3.

◆ currentValue()

qreal KisScalarKeyframeChannel::currentValue ( )
inline

Definition at line 138 of file kis_scalar_keyframe_channel.h.

138{ return valueAt(currentTime()); }
qreal valueAt(int time) const
Quickly get the interpolated value at the given time.

◆ findCubicCurveParameter()

qreal KisScalarKeyframeChannel::findCubicCurveParameter ( int time0,
qreal delta0,
qreal delta1,
int time1,
int time )
staticprivate

Definition at line 394 of file kis_scalar_keyframe_channel.cpp.

395{
396 if (time == time0) return 0.0;
397 if (time == time1) return 1.0;
398
399 qreal min_t = 0.0;
400 qreal max_t = 1.0;
401
402 while (true) {
403 qreal t = (max_t + min_t) / 2;
404 qreal time_t = cubicBezier(time0, delta0, delta1, time1, t);
405
406 if (time_t < time - 0.05) {
407 min_t = t;
408 } else if (time_t > time + 0.05) {
409 max_t = t;
410 } else {
411 // Close enough
412 return t;
413 }
414 }
415}
static qreal cubicBezier(qreal p0, qreal delta1, qreal delta2, qreal p3, qreal t)

References cubicBezier().

◆ identicalFrames()

KisTimeSpan KisScalarKeyframeChannel::identicalFrames ( int time) const
overridevirtual

Get a span of times for which the channel gives identical results compared to frame at a given time. NOTE: This set may be different than the set of affected frames due to interpolation.

Reimplemented from KisKeyframeChannel.

Definition at line 362 of file kis_scalar_keyframe_channel.cpp.

363{
364 //Failsafe == no keys should mean all frames are identical!
365 if (allKeyframeTimes().count() == 0) {
366 return KisTimeSpan::infinite(0);
367 }
368
369 KisScalarKeyframeSP activeScalarKey = activeKeyframeAt<KisScalarKeyframe>(time);
370 if ( activeScalarKey &&
371 activeScalarKey->interpolationMode() != KisScalarKeyframe::Constant &&
372 activeScalarKey != keyframeAt(lastKeyframeTime()) ) {
373 //TODO: Two keyframes should be considered identical if linear with same value..
374 //TODO: Also, if bezier with same value AND tangents lie between points.
375 // (tangenty == keyframey)
376 return KisTimeSpan::fromTimeToTime(time, time);
377 }
378
379 const int nextKeyTime = nextKeyframeTime(time);
380
381 //Before the first frame => there's no active frame but a valid next frame.
382 if (!activeScalarKey && keyframeAt(nextKeyTime)) {
383 return KisTimeSpan::fromTimeToTime(0, nextKeyTime);
384 }
385
386 //No next frame, all frames after are identical.
387 if (!keyframeAt(nextKeyTime)) {
389 }
390
391 return KisTimeSpan::fromTimeToTime(activeKeyframeTime(time), nextKeyTime - 1);
392}
QSet< int > allKeyframeTimes() const
Get a set of all integer times that map to a keyframe.
KisKeyframeSP keyframeAt(int time) const
Get a keyframe at specified time. Used primarily when the value of a given keyframe is needed.
int nextKeyframeTime(const int time) const

References KisKeyframeChannel::activeKeyframeTime(), KisKeyframeChannel::allKeyframeTimes(), KisScalarKeyframe::Constant, KisTimeSpan::fromTimeToTime(), KisTimeSpan::infinite(), KisKeyframeChannel::keyframeAt(), KisKeyframeChannel::lastKeyframeTime(), and KisKeyframeChannel::nextKeyframeTime().

◆ insertKeyframe()

void KisScalarKeyframeChannel::insertKeyframe ( int time,
KisKeyframeSP keyframe,
KUndo2Command * parentUndoCmd = nullptr )
overridevirtual

Insert an existing keyframe into the channel at the specified time.

Reimplemented from KisKeyframeChannel.

Definition at line 310 of file kis_scalar_keyframe_channel.cpp.

311{
312 KisScalarKeyframeSP scalarKeyframe = keyframe.dynamicCast<KisScalarKeyframe>();
313 if (scalarKeyframe) {
314 scalarKeyframe->valueChangedChannelConnection =
315 QObject::connect(scalarKeyframe.data(),
317 this,
318 [this, time](const KisScalarKeyframe* key){
319 Q_UNUSED(key);
320 Q_EMIT sigKeyframeChanged(this, time);
321 });
322 }
323
324 KisKeyframeChannel::insertKeyframe(time, keyframe, parentUndoCmd);
325}
virtual void insertKeyframe(int time, KisKeyframeSP keyframe, KUndo2Command *parentUndoCmd=nullptr)
Insert an existing keyframe into the channel at the specified time.
void sigChanged(const KisScalarKeyframe *scalarKey)

References KisKeyframeChannel::insertKeyframe(), and KisScalarKeyframe::sigChanged().

◆ interpolate()

QPointF KisScalarKeyframeChannel::interpolate ( QPointF point1,
QPointF rightTangent,
QPointF leftTangent,
QPointF point2,
qreal t )
static

Definition at line 300 of file kis_scalar_keyframe_channel.cpp.

301{
302 normalizeTangents(point1, rightTangent, leftTangent, point2);
303
304 qreal x = cubicBezier(point1.x(), rightTangent.x(), leftTangent.x(), point2.x(), t);
305 qreal y = cubicBezier(point1.y(), rightTangent.y(), leftTangent.y(), point2.y(), t);
306
307 return QPointF(x,y);
308}
static void normalizeTangents(const QPointF point1, QPointF &rightTangent, QPointF &leftTangent, const QPointF point2)

References cubicBezier(), and normalizeTangents().

◆ isCurrentTimeAffectedBy()

bool KisScalarKeyframeChannel::isCurrentTimeAffectedBy ( int keyTime)

Definition at line 286 of file kis_scalar_keyframe_channel.cpp.

286 {
288}
virtual KisTimeSpan affectedFrames(int time) const override
Get the set of frames affected by any changes to the value or content of the active keyframe at the g...
bool contains(int time) const

References KisKeyframeChannel::activeKeyframeTime(), affectedFrames(), KisTimeSpan::contains(), and KisKeyframeChannel::currentTime().

◆ limits()

QSharedPointer< ScalarKeyframeLimits > KisScalarKeyframeChannel::limits ( ) const

Definition at line 199 of file kis_scalar_keyframe_channel.cpp.

200{
201 return m_d->limits;
202}

References m_d.

◆ loadKeyframe()

QPair< int, KisKeyframeSP > KisScalarKeyframeChannel::loadKeyframe ( const QDomElement & keyframeNode)
overrideprivatevirtual

Implements KisKeyframeChannel.

Definition at line 484 of file kis_scalar_keyframe_channel.cpp.

485{
486 int time = keyframeNode.toElement().attribute("time").toInt();
488
489 qreal value = KisDomUtils::toDouble(keyframeNode.toElement().attribute("value"));
490
491 KisScalarKeyframeSP keyframe = createKeyframe().dynamicCast<KisScalarKeyframe>();
492 keyframe->setValue(value);
493
494 KisScalarKeyframeSP scalarKey = keyframe.dynamicCast<KisScalarKeyframe>();
495
496 QString interpolationMode = keyframeNode.toElement().attribute("interpolation");
497 if (interpolationMode == "constant") {
498 scalarKey->setInterpolationMode(KisScalarKeyframe::Constant);
499 } else if (interpolationMode == "linear") {
500 scalarKey->setInterpolationMode(KisScalarKeyframe::Linear);
501 } else if (interpolationMode == "bezier") {
502 scalarKey->setInterpolationMode(KisScalarKeyframe::Bezier);
503 }
504
505 QString tangentsMode = keyframeNode.toElement().attribute("tangents");
506 if (tangentsMode == "smooth") {
507 scalarKey->setTangentsMode(KisScalarKeyframe::Smooth);
508 } else if (tangentsMode == "sharp") {
509 scalarKey->setTangentsMode(KisScalarKeyframe::Sharp);
510 }
511
512 QPointF leftTangent;
513 QPointF rightTangent;
514 KisDomUtils::loadValue(keyframeNode, "leftTangent", &leftTangent);
515 KisDomUtils::loadValue(keyframeNode, "rightTangent", &rightTangent);
516 scalarKey->setInterpolationTangents(leftTangent, rightTangent);
517
518 return QPair<int, KisKeyframeSP>(time, keyframe);
519}
Q_DECL_DEPRECATED void workaroundBrokenFrameTimeBug(int *time)
Between Krita 4.1 and 4.4 Krita had a bug which resulted in creating frames with negative time stamp....
virtual KisKeyframeSP createKeyframe() override
Virtual keyframe creation function. Derived classes implement this function based on the needs of the...
double toDouble(const QString &str, bool *ok=nullptr)
bool loadValue(const QDomElement &e, float *v)

References KisScalarKeyframe::Bezier, KisScalarKeyframe::Constant, createKeyframe(), KisScalarKeyframe::Linear, KisDomUtils::loadValue(), KisScalarKeyframe::Sharp, KisScalarKeyframe::Smooth, KisDomUtils::toDouble(), value(), and KisKeyframeChannel::workaroundBrokenFrameTimeBug().

◆ normalizeTangents()

void KisScalarKeyframeChannel::normalizeTangents ( const QPointF point1,
QPointF & rightTangent,
QPointF & leftTangent,
const QPointF point2 )
staticprivate

Definition at line 425 of file kis_scalar_keyframe_channel.cpp.

426{
427 // To ensure that the curve is monotonic wrt time,
428 // check that control points lie between the endpoints.
429 // If not, force them into range by scaling down the tangents
430
431 float interval = point2.x() - point1.x();
432 if (rightTangent.x() < 0) rightTangent *= 0;
433 if (leftTangent.x() > 0) leftTangent *= 0;
434
435 if (rightTangent.x() > interval) {
436 rightTangent *= interval / rightTangent.x();
437 }
438 if (leftTangent.x() < -interval) {
439 leftTangent *= interval / -leftTangent.x();
440 }
441}

◆ removeKeyframe()

void KisScalarKeyframeChannel::removeKeyframe ( int time,
KUndo2Command * parentUndoCmd = nullptr )
overridevirtual

Remove a keyframe from the channel at the specified time.

Reimplemented from KisKeyframeChannel.

Definition at line 327 of file kis_scalar_keyframe_channel.cpp.

328{
329 KisScalarKeyframeSP keyframe = keyframeAt<KisScalarKeyframe>(time);
330 if (keyframe) {
331 disconnect(keyframe->valueChangedChannelConnection);
332 }
333
334 KisKeyframeChannel::removeKeyframe(time, parentUndoCmd);
335}
virtual void removeKeyframe(int time, KUndo2Command *parentUndoCmd=nullptr)
Remove a keyframe from the channel at the specified time.

References KisKeyframeChannel::removeKeyframe().

◆ removeLimits()

void KisScalarKeyframeChannel::removeLimits ( )

Remove limits, allowing channel to operate within any range of values.

Definition at line 215 of file kis_scalar_keyframe_channel.cpp.

216{
217 if (m_d->limits) {
218 m_d->limits.reset();
219 }
220}

References m_d.

◆ saveKeyframe()

void KisScalarKeyframeChannel::saveKeyframe ( KisKeyframeSP keyframe,
QDomElement keyframeElement,
const QString & layerFilename )
overrideprivatevirtual

Implements KisKeyframeChannel.

Definition at line 461 of file kis_scalar_keyframe_channel.cpp.

462{
463 Q_UNUSED(layerFilename);
464 KisScalarKeyframeSP scalarKey = keyframe.dynamicCast<KisScalarKeyframe>();
466 const qreal value = scalarKey->value();
467 keyframeElement.setAttribute("value", KisDomUtils::toString(value));
468
469 QString interpolationMode;
470 if (scalarKey->interpolationMode() == KisScalarKeyframe::Constant) interpolationMode = "constant";
471 if (scalarKey->interpolationMode() == KisScalarKeyframe::Linear) interpolationMode = "linear";
472 if (scalarKey->interpolationMode() == KisScalarKeyframe::Bezier) interpolationMode = "bezier";
473
474 QString tangentsMode;
475 if (scalarKey->tangentsMode() == KisScalarKeyframe::Smooth) tangentsMode = "smooth";
476 if (scalarKey->tangentsMode() == KisScalarKeyframe::Sharp) tangentsMode = "sharp";
477
478 keyframeElement.setAttribute("interpolation", interpolationMode);
479 keyframeElement.setAttribute("tangents", tangentsMode);
480 KisDomUtils::saveValue(&keyframeElement, "leftTangent", scalarKey->leftTangent());
481 KisDomUtils::saveValue(&keyframeElement, "rightTangent", scalarKey->rightTangent());
482}
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:128
void saveValue(QDomElement *parent, const QString &tag, const QSize &size)
QString toString(const QString &value)

References KisScalarKeyframe::Bezier, KisScalarKeyframe::Constant, KIS_SAFE_ASSERT_RECOVER_RETURN, KisScalarKeyframe::Linear, KisDomUtils::saveValue(), KisScalarKeyframe::Sharp, KisScalarKeyframe::Smooth, KisDomUtils::toString(), and value().

◆ setDefaultInterpolationMode()

void KisScalarKeyframeChannel::setDefaultInterpolationMode ( KisScalarKeyframe::InterpolationMode mode)

Definition at line 295 of file kis_scalar_keyframe_channel.cpp.

296{
297 m_d->defaultInterpolationMode = mode;
298}

References m_d.

◆ setDefaultValue()

void KisScalarKeyframeChannel::setDefaultValue ( qreal value)

Definition at line 290 of file kis_scalar_keyframe_channel.cpp.

291{
292 m_d->defaultValue = value;
293}

References m_d, and value().

◆ setLimits()

void KisScalarKeyframeChannel::setLimits ( qreal low,
qreal high )

Limit channel within scalar value range.

Definition at line 204 of file kis_scalar_keyframe_channel.cpp.

205{
206 m_d->limits = toQShared(new ScalarKeyframeLimits(low, high));
207 QSet<int> keyEntries = allKeyframeTimes();
208 foreach (const int &time, keyEntries) {
209 KisScalarKeyframeSP scalarKey = keyframeAt<KisScalarKeyframe>(time);
210 scalarKey->setLimits(m_d->limits);
211 scalarKey->setValue(scalarKey->value());
212 }
213}
This structure represents an optional limited range of values that be handled by KisScalarKeyframeCha...

References KisKeyframeChannel::allKeyframeTimes(), m_d, and toQShared().

◆ valueAt()

qreal KisScalarKeyframeChannel::valueAt ( int time) const

Quickly get the interpolated value at the given time.

Definition at line 222 of file kis_scalar_keyframe_channel.cpp.

223{
224 const int activeKeyTime = activeKeyframeTime(time);
225 KisScalarKeyframeSP activeKey = keyframeAt<KisScalarKeyframe>(activeKeyTime);
226 KisScalarKeyframeSP nextKeyframe = keyframeAt<KisScalarKeyframe>(nextKeyframeTime(time));
227 qreal result = qQNaN();
228
229 if (activeKey) {
230 if (!nextKeyframe) {
231 result = activeKey->value();
232 } else {
233 switch (activeKey->interpolationMode()) {
235 result = activeKey->value();
236 break;
237 }
239 const int nextKeyTime = nextKeyframeTime(time);
240 const qreal activeKeyValue = activeKey->value();
241 const qreal nextKeyValue = keyframeAt<KisScalarKeyframe>(nextKeyTime)->value();
242 const int interpolationLength = (nextKeyTime - activeKeyTime);
243 if (interpolationLength > 0) {
244 result = activeKeyValue + (nextKeyValue - activeKeyValue) * (time - activeKeyTime) / (interpolationLength);
245 } else {
246 result = activeKeyValue;
247 }
248 break;
249 }
251 const int nextKeyTime = nextKeyframeTime(time);
252 const KisScalarKeyframeSP nextKey = keyframeAt<KisScalarKeyframe>(nextKeyTime);
253 QPointF point0 = QPointF(activeKeyTime, activeKey->value());
254 QPointF point1 = QPointF(nextKeyTime, nextKey->value());
255
256 QPointF tangent0 = activeKey->rightTangent();
257 QPointF tangent1 = nextKey->leftTangent();
258
259 normalizeTangents(point0, tangent0, tangent1, point1);
260 qreal t = KisScalarKeyframeChannel::findCubicCurveParameter(point0.x(), tangent0.x(), tangent1.x(), point1.x(), time);
261 result = KisScalarKeyframeChannel::interpolate(point0, tangent0, tangent1, point1, t).y();
262 break;
263 }
264 default: {
266 break;
267 }
268 }
269 }
270 } else {
271 if (nextKeyframe) {
272 result = nextKeyframe->value();
273 } else {
274 return qQNaN();
275 }
276 }
277
278 // Output value must be also be clamped to account for interpolation.
279 if (m_d->limits) {
280 return m_d->limits->clamp(result);
281 } else {
282 return result;
283 }
284}
static qreal findCubicCurveParameter(int time0, qreal delta0, qreal delta1, int time1, int time)
static QPointF interpolate(QPointF point1, QPointF rightTangent, QPointF leftTangent, QPointF point2, qreal t)
#define KIS_ASSERT_RECOVER_BREAK(cond)
Definition kis_assert.h:65

References KisKeyframeChannel::activeKeyframeTime(), KisScalarKeyframe::Bezier, KisScalarKeyframe::Constant, findCubicCurveParameter(), interpolate(), KIS_ASSERT_RECOVER_BREAK, KisScalarKeyframe::Linear, m_d, KisKeyframeChannel::nextKeyframeTime(), and normalizeTangents().

Member Data Documentation

◆ m_d

QScopedPointer<Private> KisScalarKeyframeChannel::m_d
private

Definition at line 163 of file kis_scalar_keyframe_channel.h.


The documentation for this class was generated from the following files: