You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Sort effects as they are added to the timeline.
This commit is contained in:
@@ -60,9 +60,12 @@ namespace openshot
|
||||
* The only requirements for an 'effect', is to derive from this base class, implement the Apply()
|
||||
* method, and call the InitEffectInfo() method.
|
||||
*/
|
||||
class EffectBase : ClipBase
|
||||
class EffectBase : public ClipBase
|
||||
{
|
||||
private:
|
||||
int order; ///< The order to evaluate this effect. Effects are processed in this order (when more than one overlap).
|
||||
public:
|
||||
|
||||
/// Information about the current effect
|
||||
EffectInfo info;
|
||||
|
||||
@@ -83,6 +86,12 @@ namespace openshot
|
||||
/// Initialize the values of the EffectInfo struct. It is important for derived classes to call
|
||||
/// this method, or the EffectInfo struct values will not be initialized.
|
||||
void InitEffectInfo();
|
||||
|
||||
/// Get the order that this effect should be executed.
|
||||
int Order() { return order; }
|
||||
|
||||
/// Set the order that this effect should be executed.
|
||||
void Order(int new_order) { order = new_order; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -57,8 +57,14 @@ namespace openshot {
|
||||
|
||||
/// Comparison method for sorting clip pointers (by Position and Layer)
|
||||
struct CompareClips{
|
||||
bool operator()( ClipBase* lhs, ClipBase* rhs){
|
||||
return lhs->Position() <= rhs->Position() && lhs->Layer() < rhs->Layer();
|
||||
bool operator()( Clip* lhs, Clip* rhs){
|
||||
return lhs->Position() < rhs->Position() && lhs->Layer() < rhs->Layer();
|
||||
}};
|
||||
|
||||
/// Comparison method for sorting effect pointers (by Position, Layer, and Order)
|
||||
struct CompareEffects{
|
||||
bool operator()( EffectBase* lhs, EffectBase* rhs){
|
||||
return lhs->Position() < rhs->Position() && lhs->Layer() < rhs->Layer() && lhs->Order() < rhs->Order();
|
||||
}};
|
||||
|
||||
/**
|
||||
@@ -171,7 +177,7 @@ namespace openshot {
|
||||
|
||||
/// @brief Add an openshot::Clip to the timeline
|
||||
/// @param clip Add an openshot::Clip to the timeline. A clip can contain any type of Reader.
|
||||
void AddClip(Clip* clip);
|
||||
void AddClip(Clip* clip) throw(ReaderClosed);
|
||||
|
||||
/// @brief Add an effect to the timeline
|
||||
/// @param effect Add an effect to the timeline. An effect can modify the audio or video of an openshot::Frame.
|
||||
@@ -228,6 +234,9 @@ namespace openshot {
|
||||
/// Sort clips by position on the timeline
|
||||
void SortClips();
|
||||
|
||||
/// Sort effects by position on the timeline
|
||||
void SortEffects();
|
||||
|
||||
/// Get the width of canvas and viewport
|
||||
int Width() { return width; }
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ void EffectBase::InitEffectInfo()
|
||||
Layer(0);
|
||||
Start(0.0);
|
||||
End(0.0);
|
||||
Order(0);
|
||||
|
||||
info.has_video = false;
|
||||
info.has_audio = false;
|
||||
|
||||
@@ -58,7 +58,7 @@ Timeline::Timeline(int width, int height, Framerate fps, int sample_rate, int ch
|
||||
}
|
||||
|
||||
// Add an openshot::Clip to the timeline
|
||||
void Timeline::AddClip(Clip* clip)
|
||||
void Timeline::AddClip(Clip* clip) throw(ReaderClosed)
|
||||
{
|
||||
// All clips must be converted to the frame rate of this timeline,
|
||||
// so assign the same frame rate to each clip.
|
||||
@@ -76,6 +76,9 @@ void Timeline::AddEffect(EffectBase* effect)
|
||||
{
|
||||
// Add effect to list
|
||||
effects.push_back(effect);
|
||||
|
||||
// Sort effects
|
||||
SortEffects();
|
||||
}
|
||||
|
||||
// Remove an effect from the timeline
|
||||
@@ -343,6 +346,13 @@ void Timeline::SortClips()
|
||||
clips.sort(CompareClips());
|
||||
}
|
||||
|
||||
// Sort effects by position on the timeline
|
||||
void Timeline::SortEffects()
|
||||
{
|
||||
// sort clips
|
||||
effects.sort(CompareEffects());
|
||||
}
|
||||
|
||||
// Close the reader (and any resources it was consuming)
|
||||
void Timeline::Close()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user