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"
25 #include "bcwindowbase.h"
27 #include "cwindowgui.h"
30 #include "edlsession.h"
33 #include "gwindowgui.h"
35 #include "keyframepopup.h"
37 #include "localsession.h"
38 #include "maincursor.h"
41 #include "mwindowgui.h"
46 #include "vpatchgui.h"
48 KeyframePopup::KeyframePopup(MWindow *mwindow, MWindowGUI *gui)
49 : BC_PopupMenu(0, 0, 0, "", 0)
51 this->mwindow = mwindow;
60 key_mode_displayed = false;
61 key_edit_displayed = false;
64 KeyframePopup::~KeyframePopup()
66 if( !key_mode_displayed ) {
73 if( !key_edit_displayed ) {
78 void KeyframePopup::create_objects()
80 add_item(key_show = new KeyframePopupShow(mwindow, this));
81 add_item(key_delete = new KeyframePopupDelete(mwindow, this));
82 add_item(key_copy = new KeyframePopupCopy(mwindow, this));
84 key_edit = new KeyframePopupEdit(mwindow, this);
85 key_mbar = new BC_MenuItem("-");
86 key_smooth = new KeyframePopupCurveMode(mwindow, this, FloatAuto::SMOOTH);
87 key_linear = new KeyframePopupCurveMode(mwindow, this, FloatAuto::LINEAR);
88 key_free_t = new KeyframePopupCurveMode(mwindow, this, FloatAuto::TFREE );
89 key_free = new KeyframePopupCurveMode(mwindow, this, FloatAuto::FREE );
92 int KeyframePopup::update(Plugin *plugin, KeyFrame *keyframe)
94 this->keyframe_plugin = plugin;
95 this->keyframe_auto = keyframe;
96 this->keyframe_autos = 0;
97 this->keyframe_automation = 0;
98 handle_curve_mode(0, 0);
102 int KeyframePopup::update(Automation *automation, Autos *autos, Auto *auto_keyframe)
104 this->keyframe_plugin = 0;
105 this->keyframe_automation = automation;
106 this->keyframe_autos = autos;
107 this->keyframe_auto = auto_keyframe;
108 handle_curve_mode(autos, auto_keyframe);
111 double current_position = mwindow->edl->local_session->get_selectionstart(1);
112 double new_position = keyframe_automation->track->from_units(keyframe_auto->position);
113 mwindow->edl->local_session->set_selectionstart(new_position);
114 mwindow->edl->local_session->set_selectionend(new_position);
115 if (current_position != new_position)
117 mwindow->edl->local_session->set_selectionstart(new_position);
118 mwindow->edl->local_session->set_selectionend(new_position);
119 mwindow->gui->lock_window();
120 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
121 mwindow->gui->unlock_window();
126 void KeyframePopup::handle_curve_mode(Autos *autos, Auto *auto_keyframe)
127 // determines the type of automation node. if floatauto, adds
128 // menu entries showing the curve mode of the node
131 if( !key_edit_displayed && keyframe_plugin ) {
133 key_edit_displayed = true;
135 else if( key_edit_displayed && !keyframe_plugin ) {
136 remove_item(key_edit);
137 key_edit_displayed = false;
140 if(!key_mode_displayed && autos && autos->get_type() == AUTOMATION_TYPE_FLOAT)
141 { // append additional menu entries showing the curve_mode
143 add_item(key_smooth);
144 add_item(key_linear);
145 add_item(key_free_t);
147 key_mode_displayed = true;
149 else if(key_mode_displayed && (!autos || autos->get_type() != AUTOMATION_TYPE_FLOAT))
150 { // remove additional menu entries
151 remove_item(key_free);
152 remove_item(key_free_t);
153 remove_item(key_linear);
154 remove_item(key_smooth);
155 remove_item(key_mbar);
156 key_mode_displayed = false;
158 if(key_mode_displayed && auto_keyframe)
159 { // set checkmarks to display current mode
160 key_smooth->toggle_mode((FloatAuto*)auto_keyframe);
161 key_linear->toggle_mode((FloatAuto*)auto_keyframe);
162 key_free_t->toggle_mode((FloatAuto*)auto_keyframe);
163 key_free ->toggle_mode((FloatAuto*)auto_keyframe);
168 KeyframePopupDelete::KeyframePopupDelete(MWindow *mwindow, KeyframePopup *popup)
169 : BC_MenuItem(_("Delete keyframe"))
171 this->mwindow = mwindow;
175 KeyframePopupDelete::~KeyframePopupDelete()
179 int KeyframePopupDelete::handle_event()
181 mwindow->undo->update_undo_before(_("delete keyframe"), 0);
182 delete popup->keyframe_auto;
183 mwindow->undo->update_undo_after(_("delete keyframe"), LOAD_ALL);
185 mwindow->save_backup();
186 mwindow->gui->update(0, 1, // 1 for incremental drawing. 2 for full refresh
188 mwindow->update_plugin_guis();
189 mwindow->restart_brender();
190 mwindow->sync_parameters(CHANGE_EDL);
195 KeyframePopupShow::KeyframePopupShow(MWindow *mwindow, KeyframePopup *popup)
196 : BC_MenuItem(_("Show keyframe settings"))
198 this->mwindow = mwindow;
202 KeyframePopupShow::~KeyframePopupShow()
206 int KeyframePopupShow::handle_event()
208 if (popup->keyframe_plugin)
210 mwindow->update_plugin_guis();
211 mwindow->show_plugin(popup->keyframe_plugin);
213 else if( popup->keyframe_automation ) {
216 mwindow->cwindow->gui->lock_window();
218 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos ||
219 popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
222 mwindow->cwindow->gui->set_operation(CWINDOW_PROJECTOR);
224 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos ||
225 popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
228 mwindow->cwindow->gui->set_operation(CWINDOW_CAMERA);
230 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
233 // no window to be shown
235 // first find the appropriate patchgui
236 PatchBay *patchbay = mwindow->gui->patchbay;
237 PatchGUI *patchgui = 0;
238 for (int i = 0; i < patchbay->patches.total; i++)
239 if (patchbay->patches.values[i]->track == popup->keyframe_automation->track)
240 patchgui = patchbay->patches.values[i];
243 // FIXME: repositioning of the listbox needs support in guicast
244 // int cursor_x = popup->get_relative_cursor_x();
245 // int cursor_y = popup->get_relative_cursor_y();
246 // vpatchgui->mode->reposition_window(cursor_x, cursor_y);
249 // Open the popup menu
250 VPatchGUI *vpatchgui = (VPatchGUI *)patchgui;
251 vpatchgui->mode->activate_menu();
254 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
257 mwindow->cwindow->gui->set_operation(CWINDOW_MASK);
259 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
262 // no window to be shown
264 // first find the appropriate patchgui
265 PatchBay *patchbay = mwindow->gui->patchbay;
266 PatchGUI *patchgui = 0;
267 for (int i = 0; i < patchbay->patches.total; i++)
268 if (patchbay->patches.values[i]->track == popup->keyframe_automation->track)
269 patchgui = patchbay->patches.values[i];
272 // Open the popup menu at current mouse position
273 APatchGUI *apatchgui = (APatchGUI *)patchgui;
274 int cursor_x = popup->get_relative_cursor_x();
275 int cursor_y = popup->get_relative_cursor_y();
276 apatchgui->pan->activate(cursor_x, cursor_y);
281 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
284 // no window to be shown, so do nothing
285 // IDEA: open window for fading
288 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
291 // no window to be shown, so do nothing
292 // IDEA: directly switch
297 // ensure bringing to front
300 ((CPanelToolWindow *)(mwindow->cwindow->gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]))->set_shown(0);
301 ((CPanelToolWindow *)(mwindow->cwindow->gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]))->set_shown(1);
303 mwindow->cwindow->gui->unlock_window();
313 KeyframePopupCopy::KeyframePopupCopy(MWindow *mwindow, KeyframePopup *popup)
314 : BC_MenuItem(_("Copy keyframe"))
316 this->mwindow = mwindow;
320 KeyframePopupCopy::~KeyframePopupCopy()
324 int KeyframePopupCopy::handle_event()
328 we want to copy just keyframe under cursor, NOT all keyframes at this frame
329 - very hard to do, so this is good approximation for now...
333 if (popup->keyframe_automation)
336 EDL *edl = mwindow->edl;
337 Track *track = popup->keyframe_automation->track;
338 int64_t position = popup->keyframe_auto->position;
340 // first find out type of our auto
342 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos)
343 autoconf.projector = 1;
344 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
346 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos)
348 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
350 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
352 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
354 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
356 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
358 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
362 // now create a clipboard
363 file.tag.set_title("AUTO_CLIPBOARD");
364 file.tag.set_property("LENGTH", 0);
365 file.tag.set_property("FRAMERATE", edl->session->frame_rate);
366 file.tag.set_property("SAMPLERATE", edl->session->sample_rate);
368 file.append_newline();
369 file.append_newline();
371 /* track->copy_automation(position,
377 file.tag.set_title("TRACK");
379 track->save_header(&file);
381 file.append_newline();
383 track->automation->copy(position,
392 file.tag.set_title("/TRACK");
394 file.append_newline();
395 file.append_newline();
396 file.append_newline();
397 file.append_newline();
401 file.tag.set_title("/AUTO_CLIPBOARD");
403 file.append_newline();
404 file.terminate_string();
406 mwindow->gui->lock_window();
407 mwindow->gui->get_clipboard()->to_clipboard(file.string,
409 SECONDARY_SELECTION);
410 mwindow->gui->unlock_window();
414 mwindow->copy_automation();
420 KeyframePopupCurveMode::KeyframePopupCurveMode(
422 KeyframePopup *popup,
424 : BC_MenuItem( get_labeltext(curve_mode))
426 this->curve_mode = curve_mode;
427 this->mwindow = mwindow;
431 KeyframePopupCurveMode::~KeyframePopupCurveMode() { }
434 const char* KeyframePopupCurveMode::get_labeltext(int mode)
437 case FloatAuto::SMOOTH: return _("smooth curve");
438 case FloatAuto::LINEAR: return _("linear segments");
439 case FloatAuto::TFREE: return _("tangent edit");
440 case FloatAuto::FREE: return _("disjoint edit");
442 return _("misconfigured");
446 void KeyframePopupCurveMode::toggle_mode(FloatAuto *keyframe)
448 set_checked(curve_mode == keyframe->curve_mode);
452 int KeyframePopupCurveMode::handle_event()
454 if (popup->keyframe_autos &&
455 popup->keyframe_autos->get_type() == AUTOMATION_TYPE_FLOAT)
457 mwindow->undo->update_undo_before(_("change keyframe curve mode"), 0);
458 ((FloatAuto*)popup->keyframe_auto)->
459 change_curve_mode((FloatAuto::t_mode)curve_mode);
461 // if we switched to some "auto" mode, this may imply a
462 // real change to parameters, so this needs to be undoable...
463 mwindow->undo->update_undo_after(_("change keyframe curve mode"), LOAD_ALL);
464 mwindow->save_backup();
466 mwindow->gui->update(0, 1, 0,0,0,0,0); // incremental redraw for canvas
467 mwindow->cwindow->update(0,0, 1, 0,0); // redraw tool window in compositor
468 mwindow->update_plugin_guis();
469 mwindow->restart_brender();
470 mwindow->sync_parameters(CHANGE_EDL);
476 KeyframePopupEdit::KeyframePopupEdit(MWindow *mwindow, KeyframePopup *popup)
477 : BC_MenuItem(_("Edit Params..."))
479 this->mwindow = mwindow;
483 int KeyframePopupEdit::handle_event()
485 mwindow->show_keyframe_gui(popup->keyframe_plugin);
490 KeyframeHidePopup::KeyframeHidePopup(MWindow *mwindow, MWindowGUI *gui)
491 : BC_PopupMenu(0, 0, 0, "", 0)
493 this->mwindow = mwindow;
495 this->keyframe_autos = 0;
498 KeyframeHidePopup::~KeyframeHidePopup()
502 void KeyframeHidePopup::create_objects()
504 add_item(new KeyframePopupHide(mwindow, this));
507 int KeyframeHidePopup::update(Autos *autos)
509 this->keyframe_autos = autos;
513 KeyframePopupHide::KeyframePopupHide(MWindow *mwindow, KeyframeHidePopup *popup)
514 : BC_MenuItem(_("Hide keyframe type"))
516 this->mwindow = mwindow;
520 int KeyframePopupHide::handle_event()
522 // Get the array index of the curve
524 if(popup->keyframe_autos)
526 if(popup->keyframe_autos->type == Autos::AUTOMATION_TYPE_PLUGIN)
528 mwindow->edl->session->auto_conf->plugins = 0;
533 Track *track = popup->keyframe_autos->track;
536 Automation *automation = track->automation;
539 for(int i = 0; i < AUTOMATION_TOTAL; i++)
541 if(automation->autos[i] == popup->keyframe_autos)
543 mwindow->edl->session->auto_conf->autos[i] = 0;
555 mwindow->gui->update(0,
556 1, // 1 for incremental drawing. 2 for full refresh
562 mwindow->gui->mainmenu->update_toggles(1);
563 mwindow->gui->unlock_window();
564 mwindow->gwindow->gui->update_toggles(1);
565 mwindow->gui->lock_window("KeyframePopupHide::handle_event");