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
26 #include "edlsession.h"
29 #include "keyframes.h"
30 #include "localsession.h"
32 #include "transportque.inc"
34 KeyFrames::KeyFrames(EDL *edl, Track *track)
37 type = Autos::AUTOMATION_TYPE_PLUGIN;
40 KeyFrames::~KeyFrames()
45 KeyFrame* KeyFrames::get_prev_keyframe(int64_t position,
48 KeyFrame *current = 0;
50 // This doesn't work because edl->selectionstart doesn't change during
51 // playback at the same rate as PluginClient::source_position.
54 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
57 // Get keyframe on or before current position
58 for(current = (KeyFrame*)last;
60 current = (KeyFrame*)PREVIOUS)
62 if(direction == PLAY_FORWARD && current->position <= position) break;
64 if(direction == PLAY_REVERSE && current->position < position) break;
67 // Nothing before current position
70 current = (KeyFrame*)first;
76 current = (KeyFrame*)default_auto;
82 KeyFrame* KeyFrames::get_keyframe()
84 // Search for keyframe on or before selection
87 track->to_units(edl->local_session->get_selectionstart(1), 0),
90 // Return nearest keyframe if not in automatic keyframe generation
91 if(!edl->session->auto_keyframes)
96 // Return new keyframe
97 if(result == (KeyFrame*)default_auto ||
98 result->position != track->to_units(edl->local_session->get_selectionstart(1), 0))
100 return (KeyFrame*)insert_auto(track->to_units(edl->local_session->get_selectionstart(1), 0));
103 // Return existing keyframe
112 void KeyFrames::update_parameter(KeyFrame *src)
115 // Create new keyframe if auto keyframes or replace entire keyframe.
116 double selection_start = edl->local_session->get_selectionstart(0);
117 double selection_end = edl->local_session->get_selectionend(0);
118 selection_start = edl->align_to_frame(selection_start, 0);
119 selection_end = edl->align_to_frame(selection_end, 0);
121 if(EQUIV(selection_start, selection_end))
123 // Search for keyframe to write to
124 KeyFrame *dst = get_keyframe();
129 // Replace changed parameter in all selected keyframes.
136 // Search all keyframes in selection but don't create a new one.
137 int64_t start = track->to_units(selection_start, 0);
138 int64_t end = track->to_units(selection_end, 0);
139 KeyFrame *current = get_prev_keyframe(
143 // The first one determines the changed parameters since it is the one displayed
145 current->get_diff(src,
151 if(debug) printf("KeyFrames::update_parameter %d params=%p position=" _LD " start=" _LD "\n",
152 __LINE__, params, current->position, track->to_units(start, 0));
156 for(int i = 0; i < params->size(); i++)
157 printf("KeyFrames::update_parameter %d changed=%s %s\n",
160 params->get_value(i));
163 // Always update the first one
164 current->update_parameter(params,
167 for(current = (KeyFrame*)NEXT ; current && current->position < end; current = (KeyFrame*)NEXT)
169 if(debug) printf("KeyFrames::update_parameter %d position=" _LD "\n",
170 __LINE__, current->position);
171 current->update_parameter(params,
182 Auto* KeyFrames::new_auto()
184 return new KeyFrame(edl, this);
188 void KeyFrames::dump(FILE *fp)
190 fprintf(fp," DEFAULT_KEYFRAME\n");
191 ((KeyFrame*)default_auto)->dump(fp);
192 fprintf(fp," KEYFRAMES total=%d\n", total());
193 for(KeyFrame *current = (KeyFrame*)first;
195 current = (KeyFrame*)NEXT)