1 /**
2 * MltAnimation.cpp - MLT Wrapper
3 * Copyright (C) 2015-2018 Meltytech, LLC
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include <stdlib.h>
21 #include "MltAnimation.h"
22 using namespace Mlt;
23
24
Animation()25 Animation::Animation()
26 : instance( 0 )
27 {
28 }
29
Animation(mlt_animation animation)30 Animation::Animation( mlt_animation animation )
31 : instance( animation )
32 {
33 }
34
Animation(const Animation & animation)35 Animation::Animation( const Animation &animation )
36 : instance( animation.instance )
37 {
38 }
39
~Animation()40 Animation::~Animation()
41 {
42 // Do not call mlt_animation_close() because mlt_animation is not reference-
43 // counted, and typically a mlt_properties owns it.
44 instance = 0;
45 }
46
is_valid() const47 bool Animation::is_valid() const
48 {
49 return instance != 0;
50 }
51
get_animation() const52 mlt_animation Animation::get_animation() const
53 {
54 return instance;
55 }
56
operator =(const Animation & animation)57 Animation &Animation::operator=( const Animation &animation )
58 {
59 if ( this != &animation )
60 {
61 instance = animation.instance;
62 }
63 return *this;
64 }
65
length()66 int Animation::length()
67 {
68 return mlt_animation_get_length( instance );
69 }
70
get_item(int position,bool & is_key,mlt_keyframe_type & type)71 int Animation::get_item( int position, bool& is_key, mlt_keyframe_type& type )
72 {
73 struct mlt_animation_item_s item;
74 item.property = NULL;
75 int error = mlt_animation_get_item( instance, &item, position );
76 if ( !error )
77 {
78 is_key = item.is_key;
79 type = item.keyframe_type;
80 }
81 return error;
82 }
83
is_key(int position)84 bool Animation::is_key( int position )
85 {
86 struct mlt_animation_item_s item;
87 item.is_key = 0;
88 item.property = NULL;
89 mlt_animation_get_item( instance, &item, position );
90 return item.is_key;
91 }
92
keyframe_type(int position)93 mlt_keyframe_type Animation::keyframe_type( int position )
94 {
95 struct mlt_animation_item_s item;
96 item.property = NULL;
97 int error = mlt_animation_get_item( instance, &item, position );
98 if ( !error )
99 return item.keyframe_type;
100 else
101 return (mlt_keyframe_type) -1;
102 }
103
next_key(int position)104 int Animation::next_key( int position )
105 {
106 struct mlt_animation_item_s item;
107 item.property = NULL;
108 int error = mlt_animation_next_key( instance, &item, position );
109 if ( !error )
110 return item.frame;
111 else
112 return error;
113 }
114
previous_key(int position)115 int Animation::previous_key( int position )
116 {
117 struct mlt_animation_item_s item;
118 item.property = NULL;
119 int error = mlt_animation_prev_key( instance, &item, position );
120 if ( !error )
121 return item.frame;
122 else
123 return error;
124 }
125
key_count()126 int Animation::key_count()
127 {
128 return mlt_animation_key_count( instance );
129 }
130
key_get(int index,int & frame,mlt_keyframe_type & type)131 int Animation::key_get( int index, int& frame, mlt_keyframe_type& type )
132 {
133 struct mlt_animation_item_s item;
134 item.property = NULL;
135 int error = mlt_animation_key_get( instance, &item, index );
136 if ( !error )
137 {
138 frame = item.frame;
139 type = item.keyframe_type;
140 }
141 return error;
142 }
143
key_get_frame(int index)144 int Animation::key_get_frame( int index )
145 {
146 struct mlt_animation_item_s item;
147 item.is_key = 0;
148 item.property = NULL;
149 int error = mlt_animation_key_get( instance, &item, index );
150 if ( !error )
151 return item.frame;
152 else
153 return -1;
154 }
155
key_get_type(int index)156 mlt_keyframe_type Animation::key_get_type( int index )
157 {
158 struct mlt_animation_item_s item;
159 item.property = NULL;
160 int error = mlt_animation_key_get( instance, &item, index );
161 if ( !error )
162 return item.keyframe_type;
163 else
164 return (mlt_keyframe_type) -1;
165 }
166
key_set_type(int index,mlt_keyframe_type type)167 int Animation::key_set_type(int index, mlt_keyframe_type type)
168 {
169 return mlt_animation_key_set_type(instance, index, type);
170 }
171
key_set_frame(int index,int frame)172 int Animation::key_set_frame(int index, int frame)
173 {
174 return mlt_animation_key_set_frame(instance, index, frame);
175 }
176
shift_frames(int shift)177 void Animation::shift_frames( int shift )
178 {
179 return mlt_animation_shift_frames(instance, shift);
180 }
181
set_length(int length)182 void Animation::set_length( int length )
183 {
184 return mlt_animation_set_length( instance, length );
185 }
186
remove(int position)187 int Animation::remove( int position )
188 {
189 return mlt_animation_remove( instance, position );
190 }
191
interpolate()192 void Animation::interpolate()
193 {
194 mlt_animation_interpolate( instance );
195 }
196
serialize_cut(int in,int out)197 char *Animation::serialize_cut( int in, int out )
198 {
199 return mlt_animation_serialize_cut( instance, in, out );
200 }
201
serialize_cut(mlt_time_format format,int in,int out)202 char *Animation::serialize_cut( mlt_time_format format , int in, int out )
203 {
204 return mlt_animation_serialize_cut_tf( instance, in, out, format );
205 }
206