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;
61 key_mode_displayed = false;
62 key_edit_displayed = false;
65 KeyframePopup::~KeyframePopup()
67 if( !key_mode_displayed ) {
74 if( !key_edit_displayed ) {
79 void KeyframePopup::create_objects()
81 add_item(key_hide = new KeyframePopupHide(mwindow, this));
82 add_item(key_show = new KeyframePopupShow(mwindow, this));
83 add_item(key_delete = new KeyframePopupDelete(mwindow, this));
84 add_item(key_copy = new KeyframePopupCopy(mwindow, this));
86 key_edit = new KeyframePopupEdit(mwindow, this);
87 key_mbar = new BC_MenuItem("-");
88 key_smooth = new KeyframePopupCurveMode(mwindow, this, FloatAuto::SMOOTH);
89 key_linear = new KeyframePopupCurveMode(mwindow, this, FloatAuto::LINEAR);
90 key_free_t = new KeyframePopupCurveMode(mwindow, this, FloatAuto::TFREE );
91 key_free = new KeyframePopupCurveMode(mwindow, this, FloatAuto::FREE );
94 int KeyframePopup::update(Plugin *plugin, KeyFrame *keyframe)
96 this->keyframe_plugin = plugin;
97 this->keyframe_auto = keyframe;
98 this->keyframe_autos = 0;
99 this->keyframe_automation = 0;
100 handle_curve_mode(0, 0);
104 int KeyframePopup::update(Automation *automation, Autos *autos, Auto *auto_keyframe)
106 this->keyframe_plugin = 0;
107 this->keyframe_automation = automation;
108 this->keyframe_autos = autos;
109 this->keyframe_auto = auto_keyframe;
110 handle_curve_mode(autos, auto_keyframe);
113 double current_position = mwindow->edl->local_session->get_selectionstart(1);
114 double new_position = keyframe_automation->track->from_units(keyframe_auto->position);
115 mwindow->edl->local_session->set_selectionstart(new_position);
116 mwindow->edl->local_session->set_selectionend(new_position);
117 if (current_position != new_position)
119 mwindow->edl->local_session->set_selectionstart(new_position);
120 mwindow->edl->local_session->set_selectionend(new_position);
121 mwindow->gui->lock_window();
122 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
123 mwindow->gui->unlock_window();
128 void KeyframePopup::handle_curve_mode(Autos *autos, Auto *auto_keyframe)
129 // determines the type of automation node. if floatauto, adds
130 // menu entries showing the curve mode of the node
133 if( !key_edit_displayed && keyframe_plugin ) {
135 key_edit_displayed = true;
137 else if( key_edit_displayed && !keyframe_plugin ) {
138 remove_item(key_edit);
139 key_edit_displayed = false;
142 if(!key_mode_displayed && autos && autos->get_type() == AUTOMATION_TYPE_FLOAT)
143 { // append additional menu entries showing the curve_mode
145 add_item(key_smooth);
146 add_item(key_linear);
147 add_item(key_free_t);
149 key_mode_displayed = true;
151 else if(key_mode_displayed && (!autos || autos->get_type() != AUTOMATION_TYPE_FLOAT))
152 { // remove additional menu entries
153 remove_item(key_free);
154 remove_item(key_free_t);
155 remove_item(key_linear);
156 remove_item(key_smooth);
157 remove_item(key_mbar);
158 key_mode_displayed = false;
160 if(key_mode_displayed && auto_keyframe)
161 { // set checkmarks to display current mode
162 key_smooth->toggle_mode((FloatAuto*)auto_keyframe);
163 key_linear->toggle_mode((FloatAuto*)auto_keyframe);
164 key_free_t->toggle_mode((FloatAuto*)auto_keyframe);
165 key_free ->toggle_mode((FloatAuto*)auto_keyframe);
170 KeyframePopupDelete::KeyframePopupDelete(MWindow *mwindow, KeyframePopup *popup)
171 : BC_MenuItem(_("Delete keyframe"))
173 this->mwindow = mwindow;
177 KeyframePopupDelete::~KeyframePopupDelete()
181 int KeyframePopupDelete::handle_event()
183 mwindow->undo->update_undo_before(_("delete keyframe"), 0);
184 delete popup->keyframe_auto;
185 mwindow->undo->update_undo_after(_("delete keyframe"), LOAD_ALL);
187 mwindow->save_backup();
188 mwindow->gui->update(0, 1, // 1 for incremental drawing. 2 for full refresh
190 mwindow->update_plugin_guis();
191 mwindow->restart_brender();
192 mwindow->sync_parameters(CHANGE_EDL);
197 KeyframePopupHide::KeyframePopupHide(MWindow *mwindow, KeyframePopup *popup)
198 : BC_MenuItem(_("Hide keyframe type"))
200 this->mwindow = mwindow;
204 KeyframePopupHide::~KeyframePopupHide()
208 int KeyframePopupHide::handle_event()
210 if( popup->keyframe_autos )
211 mwindow->set_auto_visibility(popup->keyframe_autos, 0);
215 KeyframePopupShow::KeyframePopupShow(MWindow *mwindow, KeyframePopup *popup)
216 : BC_MenuItem(_("Show keyframe settings"))
218 this->mwindow = mwindow;
222 KeyframePopupShow::~KeyframePopupShow()
226 int KeyframePopupShow::handle_event()
228 if (popup->keyframe_plugin)
230 mwindow->update_plugin_guis();
231 mwindow->show_plugin(popup->keyframe_plugin);
233 else if( popup->keyframe_automation ) {
236 mwindow->cwindow->gui->lock_window();
238 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos ||
239 popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
242 mwindow->cwindow->gui->set_operation(CWINDOW_PROJECTOR);
244 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos ||
245 popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
248 mwindow->cwindow->gui->set_operation(CWINDOW_CAMERA);
250 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
253 // no window to be shown
255 // first find the appropriate patchgui
256 PatchBay *patchbay = mwindow->gui->patchbay;
257 PatchGUI *patchgui = 0;
258 for (int i = 0; i < patchbay->patches.total; i++)
259 if (patchbay->patches.values[i]->track == popup->keyframe_automation->track)
260 patchgui = patchbay->patches.values[i];
263 // FIXME: repositioning of the listbox needs support in guicast
264 // int cursor_x = popup->get_relative_cursor_x();
265 // int cursor_y = popup->get_relative_cursor_y();
266 // vpatchgui->mode->reposition_window(cursor_x, cursor_y);
269 // Open the popup menu
270 VPatchGUI *vpatchgui = (VPatchGUI *)patchgui;
271 vpatchgui->mode->activate_menu();
274 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
277 mwindow->cwindow->gui->set_operation(CWINDOW_MASK);
279 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
282 // no window to be shown
284 // first find the appropriate patchgui
285 PatchBay *patchbay = mwindow->gui->patchbay;
286 PatchGUI *patchgui = 0;
287 for (int i = 0; i < patchbay->patches.total; i++)
288 if (patchbay->patches.values[i]->track == popup->keyframe_automation->track)
289 patchgui = patchbay->patches.values[i];
292 // Open the popup menu at current mouse position
293 APatchGUI *apatchgui = (APatchGUI *)patchgui;
294 int cursor_x = popup->get_relative_cursor_x();
295 int cursor_y = popup->get_relative_cursor_y();
296 apatchgui->pan->activate(cursor_x, cursor_y);
301 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
304 // no window to be shown, so do nothing
305 // IDEA: open window for fading
308 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
311 // no window to be shown, so do nothing
312 // IDEA: directly switch
317 // ensure bringing to front
320 ((CPanelToolWindow *)(mwindow->cwindow->gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]))->set_shown(0);
321 ((CPanelToolWindow *)(mwindow->cwindow->gui->composite_panel->operation[CWINDOW_TOOL_WINDOW]))->set_shown(1);
323 mwindow->cwindow->gui->unlock_window();
333 KeyframePopupCopy::KeyframePopupCopy(MWindow *mwindow, KeyframePopup *popup)
334 : BC_MenuItem(_("Copy keyframe"))
336 this->mwindow = mwindow;
340 KeyframePopupCopy::~KeyframePopupCopy()
344 int KeyframePopupCopy::handle_event()
348 we want to copy just keyframe under cursor, NOT all keyframes at this frame
349 - very hard to do, so this is good approximation for now...
353 if (popup->keyframe_automation)
356 EDL *edl = mwindow->edl;
357 Track *track = popup->keyframe_automation->track;
358 int64_t position = popup->keyframe_auto->position;
360 // first find out type of our auto
362 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos)
363 autoconf.projector = 1;
364 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
366 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos)
368 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
370 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
372 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
374 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
376 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
378 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
382 // now create a clipboard
383 file.tag.set_title("AUTO_CLIPBOARD");
384 file.tag.set_property("LENGTH", 0);
385 file.tag.set_property("FRAMERATE", edl->session->frame_rate);
386 file.tag.set_property("SAMPLERATE", edl->session->sample_rate);
388 file.append_newline();
389 file.append_newline();
391 /* track->copy_automation(position,
397 file.tag.set_title("TRACK");
399 track->save_header(&file);
401 file.append_newline();
403 track->automation->copy(position,
412 file.tag.set_title("/TRACK");
414 file.append_newline();
415 file.append_newline();
416 file.append_newline();
417 file.append_newline();
421 file.tag.set_title("/AUTO_CLIPBOARD");
423 file.append_newline();
424 file.terminate_string();
426 mwindow->gui->lock_window();
427 mwindow->gui->get_clipboard()->to_clipboard(file.string,
429 SECONDARY_SELECTION);
430 mwindow->gui->unlock_window();
434 mwindow->copy_automation();
440 KeyframePopupCurveMode::KeyframePopupCurveMode(
442 KeyframePopup *popup,
444 : BC_MenuItem( get_labeltext(curve_mode))
446 this->curve_mode = curve_mode;
447 this->mwindow = mwindow;
451 KeyframePopupCurveMode::~KeyframePopupCurveMode() { }
454 const char* KeyframePopupCurveMode::get_labeltext(int mode)
457 case FloatAuto::SMOOTH: return _("smooth curve");
458 case FloatAuto::LINEAR: return _("linear segments");
459 case FloatAuto::TFREE: return _("tangent edit");
460 case FloatAuto::FREE: return _("disjoint edit");
462 return _("misconfigured");
466 void KeyframePopupCurveMode::toggle_mode(FloatAuto *keyframe)
468 set_checked(curve_mode == keyframe->curve_mode);
472 int KeyframePopupCurveMode::handle_event()
474 if (popup->keyframe_autos &&
475 popup->keyframe_autos->get_type() == AUTOMATION_TYPE_FLOAT)
477 mwindow->undo->update_undo_before(_("change keyframe curve mode"), 0);
478 ((FloatAuto*)popup->keyframe_auto)->
479 change_curve_mode((FloatAuto::t_mode)curve_mode);
481 // if we switched to some "auto" mode, this may imply a
482 // real change to parameters, so this needs to be undoable...
483 mwindow->undo->update_undo_after(_("change keyframe curve mode"), LOAD_ALL);
484 mwindow->save_backup();
486 mwindow->gui->update(0, 1, 0,0,0,0,0); // incremental redraw for canvas
487 mwindow->cwindow->update(0,0, 1, 0,0); // redraw tool window in compositor
488 mwindow->update_plugin_guis();
489 mwindow->restart_brender();
490 mwindow->sync_parameters(CHANGE_EDL);
496 KeyframePopupEdit::KeyframePopupEdit(MWindow *mwindow, KeyframePopup *popup)
497 : BC_MenuItem(_("Edit Params..."))
499 this->mwindow = mwindow;
503 int KeyframePopupEdit::handle_event()
505 mwindow->show_keyframe_gui(popup->keyframe_plugin);
510 KeyframeHidePopup::KeyframeHidePopup(MWindow *mwindow, MWindowGUI *gui)
511 : BC_PopupMenu(0, 0, 0, "", 0)
513 this->mwindow = mwindow;
515 this->keyframe_autos = 0;
518 KeyframeHidePopup::~KeyframeHidePopup()
522 void KeyframeHidePopup::create_objects()
524 add_item(new KeyframeHideItem(mwindow, this));
527 int KeyframeHidePopup::update(Autos *autos)
529 this->keyframe_autos = autos;
533 KeyframeHideItem::KeyframeHideItem(MWindow *mwindow, KeyframeHidePopup *popup)
534 : BC_MenuItem(_("Hide keyframe type"))
536 this->mwindow = mwindow;
541 int KeyframeHideItem::handle_event()
543 if( popup->keyframe_autos )
544 mwindow->set_auto_visibility(popup->keyframe_autos, 0);