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
22 #include "apatchgui.h"
24 #include "automation.h"
26 #include "bcwindowbase.h"
28 #include "cwindowgui.h"
31 #include "edlsession.h"
34 #include "gwindowgui.h"
36 #include "keyframegui.h"
37 #include "keyframepopup.h"
39 #include "localsession.h"
40 #include "maincursor.h"
43 #include "mwindowgui.h"
48 #include "vpatchgui.h"
50 KeyframePopup::KeyframePopup(MWindow *mwindow, MWindowGUI *gui)
57 this->mwindow = mwindow;
67 KeyframePopup::~KeyframePopup()
71 void KeyframePopup::create_objects()
73 add_item(key_hide = new KeyframePopupHide(mwindow, this));
76 int KeyframePopup::update(Plugin *plugin, KeyFrame *keyframe)
78 this->keyframe_plugin = plugin;
79 this->keyframe_auto = keyframe;
80 this->keyframe_autos = keyframe->autos;
81 this->keyframe_automation = 0;
83 // Suspect this routine is only used for plugins so this is never reached
84 if(keyframe->autos->type == Autos::AUTOMATION_TYPE_FLOAT)
86 if(!key_linear) add_item(key_linear = new KeyframePopupLinear(mwindow, this));
87 if(!key_bezier) add_item(key_bezier = new KeyframePopupBezier(mwindow, this));
91 if(key_linear) delete key_linear;
92 if(key_bezier) delete key_bezier;
99 if(!edit) add_item(edit = new KeyframePopupEdit(mwindow, this));
109 int KeyframePopup::update(Automation *automation,
113 this->keyframe_plugin = 0;
114 this->keyframe_automation = automation;
115 this->keyframe_autos = autos;
116 this->keyframe_auto = auto_keyframe;
118 if(auto_keyframe && autos->type == Autos::AUTOMATION_TYPE_FLOAT)
120 if(!key_linear) add_item(key_linear = new KeyframePopupLinear(mwindow, this));
121 if(!key_bezier) add_item(key_bezier = new KeyframePopupBezier(mwindow, this));
125 if(key_linear) delete key_linear;
126 if(key_bezier) delete key_bezier;
133 if(!key_delete) add_item(key_delete = new KeyframePopupDelete(mwindow, this));
134 if(!key_copy) add_item(key_copy = new KeyframePopupCopy(mwindow, this));
138 if(key_delete) delete key_delete;
139 if(key_copy) delete key_copy;
153 double current_position = mwindow->edl->local_session->get_selectionstart(1);
154 double new_position = keyframe_automation->track->from_units(keyframe_auto->position);
155 mwindow->edl->local_session->set_selectionstart(new_position);
156 mwindow->edl->local_session->set_selectionend(new_position);
158 if (current_position != new_position)
160 mwindow->edl->local_session->set_selectionstart(new_position);
161 mwindow->edl->local_session->set_selectionend(new_position);
162 mwindow->gui->lock_window();
163 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
164 mwindow->gui->unlock_window();
175 KeyframePopupDelete::KeyframePopupDelete(MWindow *mwindow, KeyframePopup *popup)
176 : BC_MenuItem(_("Delete keyframe"))
178 this->mwindow = mwindow;
182 KeyframePopupDelete::~KeyframePopupDelete()
186 int KeyframePopupDelete::handle_event()
188 mwindow->undo->update_undo_before(_("delete keyframe"), 0);
189 delete popup->keyframe_auto;
190 popup->keyframe_auto = 0;
191 mwindow->save_backup();
192 mwindow->undo->update_undo_after(_("delete keyframe"), LOAD_ALL);
194 mwindow->gui->update(0,
195 1, // 1 for incremental drawing. 2 for full refresh
201 mwindow->update_plugin_guis();
202 mwindow->restart_brender();
203 mwindow->sync_parameters(CHANGE_EDL);
212 KeyframePopupLinear::KeyframePopupLinear(MWindow *mwindow, KeyframePopup *popup)
213 : BC_MenuItem(_("Make linear"))
215 this->mwindow = mwindow;
219 KeyframePopupLinear::~KeyframePopupLinear()
223 int KeyframePopupLinear::handle_event()
225 mwindow->undo->update_undo_before();
226 popup->keyframe_auto->mode = Auto::LINEAR;
227 mwindow->save_backup();
228 mwindow->undo->update_undo_after(_("make linear curve"), LOAD_ALL);
230 mwindow->gui->update(0,
231 1, // 1 for incremental drawing. 2 for full refresh
237 mwindow->update_plugin_guis();
238 mwindow->restart_brender();
239 mwindow->sync_parameters(CHANGE_EDL);
248 KeyframePopupBezier::KeyframePopupBezier(MWindow *mwindow, KeyframePopup *popup)
249 : BC_MenuItem(_("Make bezier"))
251 this->mwindow = mwindow;
255 KeyframePopupBezier::~KeyframePopupBezier()
259 int KeyframePopupBezier::handle_event()
261 mwindow->undo->update_undo_before();
262 popup->keyframe_auto->mode = Auto::BEZIER;
263 mwindow->save_backup();
264 mwindow->undo->update_undo_after(_("make bezier curve"), LOAD_ALL);
266 mwindow->gui->update(0,
267 1, // 1 for incremental drawing. 2 for full refresh
273 mwindow->update_plugin_guis();
274 mwindow->restart_brender();
275 mwindow->sync_parameters(CHANGE_EDL);
284 KeyframePopupHide::KeyframePopupHide(MWindow *mwindow, KeyframePopup *popup)
285 : BC_MenuItem(_("Hide keyframe type"))
287 this->mwindow = mwindow;
291 int KeyframePopupHide::handle_event()
293 // Get the array index of the curve
295 if(popup->keyframe_autos)
297 if(popup->keyframe_autos->type == Autos::AUTOMATION_TYPE_PLUGIN)
299 mwindow->edl->session->auto_conf->plugins = 0;
304 Track *track = popup->keyframe_autos->track;
307 Automation *automation = track->automation;
310 for(int i = 0; i < AUTOMATION_TOTAL; i++)
312 if(automation->autos[i] == popup->keyframe_autos)
314 mwindow->edl->session->auto_conf->autos[i] = 0;
326 mwindow->gui->update(0,
327 1, // 1 for incremental drawing. 2 for full refresh
333 mwindow->gui->mainmenu->update_toggles(1);
334 mwindow->gui->unlock_window();
335 mwindow->gwindow->gui->update_toggles(1);
336 mwindow->gui->lock_window("KeyframePopupHide::handle_event");
344 KeyframePopupCopy::KeyframePopupCopy(MWindow *mwindow, KeyframePopup *popup)
345 : BC_MenuItem(_("Copy"))
347 this->mwindow = mwindow;
351 int KeyframePopupCopy::handle_event()
355 we want to copy just keyframe under cursor, NOT all keyframes at this frame
356 - very hard to do, so this is good approximation for now...
359 // if (popup->keyframe_automation)
362 // EDL *edl = mwindow->edl;
363 // Track *track = popup->keyframe_automation->track;
364 // int64_t position = popup->keyframe_auto->position;
365 // AutoConf autoconf;
366 // // first find out type of our auto
367 // autoconf.set_all(0);
368 // if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos)
369 // autoconf.projector = 1;
370 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
371 // autoconf.pzoom = 1;
372 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos)
373 // autoconf.camera = 1;
374 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
375 // autoconf.czoom = 1;
376 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
377 // autoconf.mode = 1;
378 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
379 // autoconf.mask = 1;
380 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
382 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
383 // autoconf.fade = 1;
384 // else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
385 // autoconf.mute = 1;
388 // // now create a clipboard
389 // file.tag.set_title("AUTO_CLIPBOARD");
390 // file.tag.set_property("LENGTH", 0);
391 // file.tag.set_property("FRAMERATE", edl->session->frame_rate);
392 // file.tag.set_property("SAMPLERATE", edl->session->sample_rate);
393 // file.append_tag();
394 // file.append_newline();
395 // file.append_newline();
397 // /* track->copy_automation(position,
403 // file.tag.set_title("TRACK");
405 // track->save_header(&file);
406 // file.append_tag();
407 // file.append_newline();
409 // track->automation->copy(position,
418 // file.tag.set_title("/TRACK");
419 // file.append_tag();
420 // file.append_newline();
421 // file.append_newline();
422 // file.append_newline();
423 // file.append_newline();
427 // file.tag.set_title("/AUTO_CLIPBOARD");
428 // file.append_tag();
429 // file.append_newline();
430 // file.terminate_string();
432 // mwindow->gui->lock_window();
433 // mwindow->gui->get_clipboard()->to_clipboard(file.string,
434 // strlen(file.string),
435 // SECONDARY_SELECTION);
436 // mwindow->gui->unlock_window();
440 mwindow->copy_automation();
445 KeyframePopupEdit::KeyframePopupEdit(MWindow *mwindow, KeyframePopup *popup)
446 : BC_MenuItem(_("Presets..."))
448 this->mwindow = mwindow;
452 int KeyframePopupEdit::handle_event()
454 mwindow->show_keyframe_gui(popup->keyframe_plugin);