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"
31 #include "transportque.inc"
33 KeyFrames::KeyFrames(EDL *edl, Track *track)
36 type = Autos::AUTOMATION_TYPE_PLUGIN;
39 KeyFrames::~KeyFrames()
44 KeyFrame* KeyFrames::get_prev_keyframe(int64_t position,
47 KeyFrame *current = 0;
49 // This doesn't work because edl->selectionstart doesn't change during
50 // playback at the same rate as PluginClient::source_position.
53 position = track->to_units(edl->local_session->get_selectionstart(1), 0);
56 // Get keyframe on or before current position
57 for(current = (KeyFrame*)last;
59 current = (KeyFrame*)PREVIOUS)
61 if(direction == PLAY_FORWARD && current->position <= position) break;
63 if(direction == PLAY_REVERSE && current->position < position) break;
66 // Nothing before current position
69 current = (KeyFrame*)first;
75 current = (KeyFrame*)default_auto;
81 KeyFrame* KeyFrames::get_keyframe()
83 // Search for keyframe on or before selection
86 track->to_units(edl->local_session->get_selectionstart(1), 0),
89 // Return nearest keyframe if not in automatic keyframe generation
90 if(!edl->session->auto_keyframes)
95 // Return new keyframe
96 if(result == (KeyFrame*)default_auto ||
97 result->position != track->to_units(edl->local_session->get_selectionstart(1), 0))
99 return (KeyFrame*)insert_auto(track->to_units(edl->local_session->get_selectionstart(1), 0));
102 // Return existing keyframe
111 void KeyFrames::update_parameter(KeyFrame *src)
114 // Create new keyframe if auto keyframes or replace entire keyframe.
115 double selection_start = edl->local_session->get_selectionstart(0);
116 double selection_end = edl->local_session->get_selectionend(0);
117 selection_start = edl->align_to_frame(selection_start, 0);
118 selection_end = edl->align_to_frame(selection_end, 0);
120 if(EQUIV(selection_start, selection_end))
122 // Search for keyframe to write to
123 KeyFrame *dst = get_keyframe();
128 // Replace changed parameter in all selected keyframes.
135 // Search all keyframes in selection but don't create a new one.
136 int64_t start = track->to_units(selection_start, 0);
137 int64_t end = track->to_units(selection_end, 0);
138 KeyFrame *current = get_prev_keyframe(
142 // The first one determines the changed parameters since it is the one displayed
144 current->get_diff(src,
150 if(debug) printf("KeyFrames::update_parameter %d params=%p position=%jd start=%jd\n",
151 __LINE__, params, current->position, track->to_units(start, 0));
155 for(int i = 0; i < params->size(); i++)
156 printf("KeyFrames::update_parameter %d changed=%s %s\n",
159 params->get_value(i));
162 // Always update the first one
163 current->update_parameter(params,
166 for(current = (KeyFrame*)NEXT ; current && current->position < end; current = (KeyFrame*)NEXT)
168 if(debug) printf("KeyFrames::update_parameter %d position=%jd\n",
169 __LINE__, current->position);
170 current->update_parameter(params,
181 Auto* KeyFrames::new_auto()
183 return new KeyFrame(edl, this);
187 void KeyFrames::dump(FILE *fp)
189 fprintf(fp," DEFAULT_KEYFRAME\n");
190 ((KeyFrame*)default_auto)->dump(fp);
191 fprintf(fp," KEYFRAMES total=%d\n", total());
192 for(KeyFrame *current = (KeyFrame*)first;
194 current = (KeyFrame*)NEXT)