4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
25 #include "edlsession.h"
28 #include "keyframes.h"
29 #include "localsession.h"
32 #include "transportque.inc"
34 KeyFrames::KeyFrames(EDL *edl, Plugin *plugin)
35 : Autos(edl, plugin->track)
37 type = Autos::AUTOMATION_TYPE_PLUGIN;
41 KeyFrames::~KeyFrames()
46 KeyFrame* KeyFrames::get_prev_keyframe(int64_t position,
49 KeyFrame *current = 0;
51 // This doesn't work because edl->selectionstart doesn't change during
52 // playback at the same rate as PluginClient::source_position.
55 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
58 // Get keyframe on or before current position
59 for(current = (KeyFrame*)last;
61 current = (KeyFrame*)PREVIOUS)
63 if(direction == PLAY_FORWARD && current->position <= position) break;
65 if(direction == PLAY_REVERSE && current->position < position) break;
68 // Nothing before current position
71 current = (KeyFrame*)first;
77 current = (KeyFrame*)default_auto;
83 KeyFrame* KeyFrames::get_keyframe()
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);
97 Auto* KeyFrames::new_auto()
99 return new KeyFrame(edl, this);
103 void KeyFrames::dump(FILE *fp)
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;
110 current = (KeyFrame*)NEXT)