no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / keyframes.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "bchash.h"
23 #include "clip.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "filexml.h"
27 #include "keyframe.h"
28 #include "keyframes.h"
29 #include "localsession.h"
30 #include "plugin.h"
31 #include "track.h"
32 #include "transportque.inc"
33
34 KeyFrames::KeyFrames(EDL *edl, Plugin *plugin)
35  : Autos(edl, plugin->track)
36 {
37         type = Autos::AUTOMATION_TYPE_PLUGIN;
38         plugin = plugin;
39 }
40
41 KeyFrames::~KeyFrames()
42 {
43 }
44
45
46 KeyFrame* KeyFrames::get_prev_keyframe(int64_t position,
47         int direction)
48 {
49         KeyFrame *current = 0;
50
51 // This doesn't work because edl->selectionstart doesn't change during
52 // playback at the same rate as PluginClient::source_position.
53         if(position < 0)
54         {
55                 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
56         }
57
58 // Get keyframe on or before current position
59         for(current = (KeyFrame*)last;
60                 current;
61                 current = (KeyFrame*)PREVIOUS)
62         {
63                 if(direction == PLAY_FORWARD && current->position <= position) break;
64                 else
65                 if(direction == PLAY_REVERSE && current->position < position) break;
66         }
67
68 // Nothing before current position
69         if(!current && first)
70         {
71                 current = (KeyFrame*)first;
72         }
73         else
74 // No keyframes
75         if(!current)
76         {
77                 current = (KeyFrame*)default_auto;
78         }
79
80         return current;
81 }
82
83 KeyFrame* KeyFrames::get_keyframe()
84 {
85         int64_t pos = track->to_units(edl->local_session->get_selectionstart(1), 0);
86 // Search for keyframe on or before selection
87         KeyFrame *result = get_prev_keyframe(pos, PLAY_FORWARD);
88         if( edl->session->auto_keyframes ) {
89                 if( !result || result->position != pos ||
90                     result == (KeyFrame*)default_auto )
91 // generate keyframes while tweeking, and no keyframe found at pos
92                         result = (KeyFrame*)insert_auto(pos);
93         }
94         return result;
95 }
96
97 Auto* KeyFrames::new_auto()
98 {
99         return new KeyFrame(edl, this);
100 }
101
102
103 void KeyFrames::dump(FILE *fp)
104 {
105         fprintf(fp,"    DEFAULT_KEYFRAME\n");
106         ((KeyFrame*)default_auto)->dump(fp);
107         fprintf(fp,"    KEYFRAMES total=%d\n", total());
108         for(KeyFrame *current = (KeyFrame*)first;
109                 current;
110                 current = (KeyFrame*)NEXT)
111         {
112                 current->dump(fp);
113         }
114 }
115