You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Added some new methods on the keyframe class, and added some unit tests for the keyframes.
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
#include "Exceptions.h"
|
||||
#include "Fraction.h"
|
||||
#include "Coordinate.h"
|
||||
#include "Point.h"
|
||||
|
||||
@@ -95,6 +96,12 @@ namespace openshot {
|
||||
/// Get the rounded INT value at a specific index
|
||||
int GetInt(int index);
|
||||
|
||||
/// Get the direction of the curve at a specific index (increasing or decreasing)
|
||||
bool IsIncreasing(int index);
|
||||
|
||||
/// Get the fraction that represents how many times this value is repeated in the curve
|
||||
Fraction GetRepeatFraction(int index);
|
||||
|
||||
/// Get a point at a specific index
|
||||
Point& GetPoint(int index) throw(OutOfBoundsPoint);
|
||||
|
||||
|
||||
17
src/Clip.cpp
17
src/Clip.cpp
@@ -208,27 +208,12 @@ void Clip::apply_time_mapped_frame(tr1::shared_ptr<Frame> frame, int frame_numbe
|
||||
resampler = new AudioResampler();
|
||||
|
||||
// Get new frame number
|
||||
int new_frame_number = time.GetValue(frame_number);
|
||||
int new_frame_number = time.GetInt(frame_number);
|
||||
|
||||
// Get previous and next values (if any)
|
||||
int previous_value = time.GetValue(frame_number - 1);
|
||||
int next_value = time.GetValue(frame_number + 1);
|
||||
|
||||
// walk the curve (for 100 X coordinates), and try and detect direction
|
||||
bool reverse = false;
|
||||
for (int index = frame_number; index < frame_number + 100; index++)
|
||||
{
|
||||
if (time.GetValue(index) > new_frame_number)
|
||||
{
|
||||
// reverse time
|
||||
reverse = true;
|
||||
break;
|
||||
}
|
||||
else if (time.GetValue(index) < new_frame_number)
|
||||
// forward time
|
||||
break;
|
||||
}
|
||||
|
||||
// difference between previous frame and current frame
|
||||
int previous_diff = abs(new_frame_number - previous_value);
|
||||
|
||||
|
||||
@@ -190,6 +190,50 @@ int Keyframe::GetInt(int index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Get the direction of the curve at a specific index (increasing or decreasing)
|
||||
bool Keyframe::IsIncreasing(int index)
|
||||
{
|
||||
// Check if it needs to be processed
|
||||
if (needs_update)
|
||||
Process();
|
||||
|
||||
// Is index a valid point?
|
||||
if (index >= 0 && index < Values.size())
|
||||
// Return value
|
||||
return int(round(Values[index].increasing));
|
||||
else if (index < 0 && Values.size() > 0)
|
||||
// Return the minimum value
|
||||
return int(round(Values[0].increasing));
|
||||
else if (index >= Values.size() && Values.size() > 0)
|
||||
// return the maximum value
|
||||
return int(round(Values[Values.size() - 1].increasing));
|
||||
else
|
||||
// return a blank coordinate (0,0)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get the fraction that represents how many times this value is repeated in the curve
|
||||
Fraction Keyframe::GetRepeatFraction(int index)
|
||||
{
|
||||
// Check if it needs to be processed
|
||||
if (needs_update)
|
||||
Process();
|
||||
|
||||
// Is index a valid point?
|
||||
if (index >= 0 && index < Values.size())
|
||||
// Return value
|
||||
return Values[index].repeated;
|
||||
else if (index < 0 && Values.size() > 0)
|
||||
// Return the minimum value
|
||||
return Values[0].repeated;
|
||||
else if (index >= Values.size() && Values.size() > 0)
|
||||
// return the maximum value
|
||||
return Values[Values.size() - 1].repeated;
|
||||
else
|
||||
// return a blank coordinate (0,0)
|
||||
return Fraction(1,1);
|
||||
}
|
||||
|
||||
// Get a point at a specific index
|
||||
Point& Keyframe::GetPoint(int index) throw(OutOfBoundsPoint) {
|
||||
// Is index a valid point?
|
||||
|
||||
@@ -162,3 +162,33 @@ TEST(Keyframe_GetValue_For_Constant_Curve_3_Points)
|
||||
// Check the expected number of values
|
||||
CHECK_EQUAL(kf.Values.size(), 51);
|
||||
}
|
||||
|
||||
TEST(Keyframe_Check_Direction_and_Repeat_Fractions)
|
||||
{
|
||||
// Create a keyframe curve with 2 points
|
||||
Keyframe kf;
|
||||
kf.AddPoint(1, 500);
|
||||
kf.AddPoint(400, 100);
|
||||
kf.AddPoint(500, 500);
|
||||
|
||||
// Spot check values from the curve
|
||||
CHECK_EQUAL(kf.GetInt(1), 500);
|
||||
CHECK_EQUAL(kf.IsIncreasing(1), false);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(1).num, 1);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(1).den, 10);
|
||||
|
||||
CHECK_EQUAL(kf.GetInt(24), 497);
|
||||
CHECK_EQUAL(kf.IsIncreasing(24), false);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(24).num, 2);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(24).den, 4);
|
||||
|
||||
CHECK_EQUAL(kf.GetInt(390), 101);
|
||||
CHECK_EQUAL(kf.IsIncreasing(390), false);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(390).num, 8);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(390).den, 8);
|
||||
|
||||
CHECK_EQUAL(kf.GetInt(391), 100);
|
||||
CHECK_EQUAL(kf.IsIncreasing(391), true);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(391).num, 1);
|
||||
CHECK_EQUAL(kf.GetRepeatFraction(391).den, 12);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user