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"
26 #include "bcwindowbase.h"
28 #include "cwindowgui.h"
31 #include "edlsession.h"
33 #include "floatauto.h"
35 #include "gwindowgui.h"
38 #include "keyframepopup.h"
40 #include "localsession.h"
41 #include "maincursor.h"
44 #include "mwindowgui.h"
48 #include "timelinepane.h"
52 KeyframePopup::KeyframePopup(MWindow *mwindow, MWindowGUI *gui)
53 : BC_PopupMenu(0, 0, 0, "", 0)
55 this->mwindow = mwindow;
65 key_mode_displayed = false;
66 key_edit_displayed = false;
69 KeyframePopup::~KeyframePopup()
71 if( !key_mode_displayed ) {
78 if( !key_edit_displayed ) {
83 void KeyframePopup::create_objects()
85 add_item(key_show = new KeyframePopupShow(mwindow, this));
86 add_item(key_hide = new KeyframePopupHide(mwindow, this));
87 add_item(key_delete = new KeyframePopupDelete(mwindow, this));
88 add_item(key_copy = new KeyframePopupCopy(mwindow, this));
90 key_edit = new KeyframePopupEdit(mwindow, this);
91 key_mbar = new BC_MenuItem("-");
92 key_smooth = new KeyframePopupCurveMode(mwindow, this, FloatAuto::SMOOTH);
93 key_linear = new KeyframePopupCurveMode(mwindow, this, FloatAuto::LINEAR);
94 key_free_t = new KeyframePopupCurveMode(mwindow, this, FloatAuto::TFREE );
95 key_free = new KeyframePopupCurveMode(mwindow, this, FloatAuto::FREE );
98 int KeyframePopup::update(Plugin *plugin, KeyFrame *keyframe)
100 key_show->set_text(_("Show Plugin Settings"));
101 this->keyframe_plugin = plugin;
102 this->keyframe_auto = keyframe;
103 this->keyframe_autos = 0;
104 this->keyframe_automation = 0;
105 handle_curve_mode(0, 0);
109 int KeyframePopup::update(Automation *automation, Autos *autos, Auto *auto_keyframe)
111 key_show->set_text(_(GWindowGUI::auto_text[autos->autoidx]));
112 this->keyframe_plugin = 0;
113 this->keyframe_automation = automation;
114 this->keyframe_autos = autos;
115 this->keyframe_auto = auto_keyframe;
116 handle_curve_mode(autos, auto_keyframe);
119 double current_position = mwindow->edl->local_session->get_selectionstart(1);
120 double new_position = keyframe_automation->track->from_units(keyframe_auto->position);
121 mwindow->edl->local_session->set_selectionstart(new_position);
122 mwindow->edl->local_session->set_selectionend(new_position);
123 if (current_position != new_position)
125 mwindow->edl->local_session->set_selectionstart(new_position);
126 mwindow->edl->local_session->set_selectionend(new_position);
127 mwindow->gui->lock_window();
128 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
129 mwindow->gui->unlock_window();
134 void KeyframePopup::handle_curve_mode(Autos *autos, Auto *auto_keyframe)
135 // determines the type of automation node. if floatauto, adds
136 // menu entries showing the curve mode of the node
139 if( !key_edit_displayed && keyframe_plugin ) {
141 key_edit_displayed = true;
143 else if( key_edit_displayed && !keyframe_plugin ) {
144 remove_item(key_edit);
145 key_edit_displayed = false;
148 if(!key_mode_displayed && autos && autos->get_type() == AUTOMATION_TYPE_FLOAT)
149 { // append additional menu entries showing the curve_mode
151 add_item(key_smooth);
152 add_item(key_linear);
153 add_item(key_free_t);
155 key_mode_displayed = true;
157 else if(key_mode_displayed && (!autos || autos->get_type() != AUTOMATION_TYPE_FLOAT))
158 { // remove additional menu entries
159 remove_item(key_free);
160 remove_item(key_free_t);
161 remove_item(key_linear);
162 remove_item(key_smooth);
163 remove_item(key_mbar);
164 key_mode_displayed = false;
166 if(key_mode_displayed && auto_keyframe)
167 { // set checkmarks to display current mode
168 key_smooth->toggle_mode((FloatAuto*)auto_keyframe);
169 key_linear->toggle_mode((FloatAuto*)auto_keyframe);
170 key_free_t->toggle_mode((FloatAuto*)auto_keyframe);
171 key_free ->toggle_mode((FloatAuto*)auto_keyframe);
176 KeyframePopupDelete::KeyframePopupDelete(MWindow *mwindow, KeyframePopup *popup)
177 : BC_MenuItem(_("Delete keyframe"))
179 this->mwindow = mwindow;
183 KeyframePopupDelete::~KeyframePopupDelete()
187 int KeyframePopupDelete::handle_event()
189 mwindow->undo->update_undo_before(_("delete keyframe"), 0);
190 mwindow->speed_before();
191 delete popup->keyframe_auto;
192 mwindow->speed_after(1);
193 mwindow->undo->update_undo_after(_("delete keyframe"), LOAD_ALL);
195 mwindow->save_backup();
196 mwindow->gui->update(0, 1, // 1 for incremental drawing. 2 for full refresh
198 mwindow->update_plugin_guis();
199 mwindow->restart_brender();
200 mwindow->sync_parameters(CHANGE_EDL);
205 KeyframePopupHide::KeyframePopupHide(MWindow *mwindow, KeyframePopup *popup)
206 : BC_MenuItem(_("Hide keyframe type"))
208 this->mwindow = mwindow;
212 KeyframePopupHide::~KeyframePopupHide()
216 int KeyframePopupHide::handle_event()
218 if( popup->keyframe_autos )
219 mwindow->set_auto_visibility(popup->keyframe_autos, 0);
223 KeyframePopupShow::KeyframePopupShow(MWindow *mwindow, KeyframePopup *popup)
224 : BC_MenuItem(_("Show keyframe settings"))
226 this->mwindow = mwindow;
230 KeyframePopupShow::~KeyframePopupShow()
234 int KeyframePopupShow::handle_event()
236 MWindowGUI *mgui = mwindow->gui;
237 CWindowGUI *cgui = mwindow->cwindow->gui;
238 int cx = mgui->get_relative_cursor_x()+15, cy = mgui->get_relative_cursor_y()-15;
239 delete mgui->keyvalue_popup;
240 mgui->keyvalue_popup = 0;
242 if( popup->keyframe_plugin ) {
243 mwindow->update_plugin_guis();
244 mwindow->show_plugin(popup->keyframe_plugin);
246 else if( popup->keyframe_automation ) {
250 switch( popup->keyframe_autos->autoidx ) {
251 case AUTOMATION_CAMERA_X:
252 case AUTOMATION_CAMERA_Y:
253 case AUTOMATION_CAMERA_Z: {
254 cgui->set_operation(CWINDOW_CAMERA);
257 case AUTOMATION_PROJECTOR_X:
258 case AUTOMATION_PROJECTOR_Y:
259 case AUTOMATION_PROJECTOR_Z: {
260 cgui->set_operation(CWINDOW_PROJECTOR);
263 case AUTOMATION_MASK: {
264 cgui->set_operation(CWINDOW_MASK);
269 PatchGUI *patchgui = mwindow->get_patchgui(popup->keyframe_automation->track);
270 if( !patchgui ) break;
272 switch( popup->keyframe_autos->autoidx ) {
273 case AUTOMATION_MODE: {
274 VKeyModePatch *mode = new VKeyModePatch(mwindow, (VPatchGUI *)patchgui);
275 mgui->add_subwindow(mode);
276 mode->create_objects();
277 mode->activate_menu();
278 mgui->keyvalue_popup = mode;
281 case AUTOMATION_PAN: {
282 AKeyPanPatch *pan = new AKeyPanPatch(mwindow, (APatchGUI *)patchgui);
283 mgui->add_subwindow(pan);
284 pan->create_objects();
285 pan->activate(cx, cy);
286 mgui->keyvalue_popup = pan;
289 case AUTOMATION_FADE: {
290 switch( patchgui->data_type ) {
292 AKeyFadePatch *fade = new AKeyFadePatch(mwindow, (APatchGUI *)patchgui, cx, cy);
293 mgui->add_subwindow(fade);
294 fade->create_objects();
295 mgui->keyvalue_popup = fade;
298 VKeyFadePatch *fade = new VKeyFadePatch(mwindow, (VPatchGUI *)patchgui, cx, cy);
299 mgui->add_subwindow(fade);
300 fade->create_objects();
301 mgui->keyvalue_popup = fade;
306 case AUTOMATION_SPEED: {
307 KeySpeedPatch *speed = new KeySpeedPatch(mwindow, patchgui, cx, cy);
308 mgui->add_subwindow(speed);
309 speed->create_objects();
310 mgui->keyvalue_popup = speed;
313 case AUTOMATION_MUTE: {
314 KeyMutePatch *mute = new KeyMutePatch(mwindow, (APatchGUI *)patchgui, cx, cy);
315 mgui->add_subwindow(mute);
316 mute->create_objects();
317 mgui->keyvalue_popup = mute;
323 // ensure bringing to front
325 mwindow->show_cwindow();
326 CPanelToolWindow *panel_tool_window =
327 (CPanelToolWindow *)cgui->composite_panel->operation[CWINDOW_TOOL_WINDOW];
328 panel_tool_window->set_shown(0);
329 panel_tool_window->set_shown(1);
331 cgui->unlock_window();
338 KeyframePopupCopy::KeyframePopupCopy(MWindow *mwindow, KeyframePopup *popup)
339 : BC_MenuItem(_("Copy keyframe"))
341 this->mwindow = mwindow;
345 KeyframePopupCopy::~KeyframePopupCopy()
349 int KeyframePopupCopy::handle_event()
353 we want to copy just keyframe under cursor, NOT all keyframes at this frame
354 - very hard to do, so this is good approximation for now...
358 if (popup->keyframe_automation)
361 EDL *edl = mwindow->edl;
362 Track *track = popup->keyframe_automation->track;
363 int64_t position = popup->keyframe_auto->position;
365 // first find out type of our auto
367 if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->projector_autos)
368 autoconf.projector = 1;
369 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pzoom_autos)
371 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->camera_autos)
373 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->czoom_autos)
375 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mode_autos)
377 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mask_autos)
379 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->pan_autos)
381 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->fade_autos)
383 else if (popup->keyframe_autos == (Autos *)popup->keyframe_automation->mute_autos)
387 // now create a clipboard
388 file.tag.set_title("AUTO_CLIPBOARD");
389 file.tag.set_property("LENGTH", 0);
390 file.tag.set_property("FRAMERATE", edl->session->frame_rate);
391 file.tag.set_property("SAMPLERATE", edl->session->sample_rate);
393 file.append_newline();
394 file.append_newline();
396 /* track->copy_automation(position,
402 file.tag.set_title("TRACK");
404 track->save_header(&file);
406 file.append_newline();
408 track->automation->copy(position,
414 file.tag.set_title("/TRACK");
416 file.append_newline();
417 file.append_newline();
418 file.append_newline();
419 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->to_clipboard(file.string, strlen(file.string), SECONDARY_SELECTION);
428 mwindow->gui->unlock_window();
432 mwindow->copy_automation();
438 KeyframePopupCurveMode::KeyframePopupCurveMode(
440 KeyframePopup *popup,
442 : BC_MenuItem( get_labeltext(curve_mode))
444 this->curve_mode = curve_mode;
445 this->mwindow = mwindow;
449 KeyframePopupCurveMode::~KeyframePopupCurveMode() { }
452 const char* KeyframePopupCurveMode::get_labeltext(int mode)
455 case FloatAuto::SMOOTH: return _("smooth curve");
456 case FloatAuto::LINEAR: return _("linear segments");
457 case FloatAuto::TFREE: return _("tangent edit");
458 case FloatAuto::FREE: return _("disjoint edit");
460 return _("misconfigured");
464 void KeyframePopupCurveMode::toggle_mode(FloatAuto *keyframe)
466 set_checked(curve_mode == keyframe->curve_mode);
470 int KeyframePopupCurveMode::handle_event()
472 if (popup->keyframe_autos &&
473 popup->keyframe_autos->get_type() == AUTOMATION_TYPE_FLOAT)
475 mwindow->undo->update_undo_before(_("change keyframe curve mode"), 0);
476 ((FloatAuto*)popup->keyframe_auto)->
477 change_curve_mode((FloatAuto::t_mode)curve_mode);
479 // if we switched to some "auto" mode, this may imply a
480 // real change to parameters, so this needs to be undoable...
481 mwindow->undo->update_undo_after(_("change keyframe curve mode"), LOAD_ALL);
482 mwindow->save_backup();
484 mwindow->gui->update(0, 1, 0,0,0,0,0); // incremental redraw for canvas
485 mwindow->cwindow->update(0,0, 1, 0,0); // redraw tool window in compositor
486 mwindow->update_plugin_guis();
487 mwindow->restart_brender();
488 mwindow->sync_parameters(CHANGE_EDL);
494 KeyframePopupEdit::KeyframePopupEdit(MWindow *mwindow, KeyframePopup *popup)
495 : BC_MenuItem(_("Edit Params..."))
497 this->mwindow = mwindow;
501 int KeyframePopupEdit::handle_event()
503 mwindow->show_keyframe_gui(popup->keyframe_plugin);
508 KeyframeHidePopup::KeyframeHidePopup(MWindow *mwindow, MWindowGUI *gui)
509 : BC_PopupMenu(0, 0, 0, "", 0)
511 this->mwindow = mwindow;
513 this->keyframe_autos = 0;
516 KeyframeHidePopup::~KeyframeHidePopup()
520 void KeyframeHidePopup::create_objects()
522 add_item(new KeyframeHideItem(mwindow, this));
525 int KeyframeHidePopup::update(Autos *autos)
527 this->keyframe_autos = autos;
531 KeyframeHideItem::KeyframeHideItem(MWindow *mwindow, KeyframeHidePopup *popup)
532 : BC_MenuItem(_("Hide keyframe type"))
534 this->mwindow = mwindow;
539 int KeyframeHideItem::handle_event()
541 if( popup->keyframe_autos )
542 mwindow->set_auto_visibility(popup->keyframe_autos, 0);
548 KeyMutePatch::KeyMutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
549 : BC_SubWindow(x, y, 100, 20, GWindowGUI::auto_colors[AUTOMATION_MUTE])
551 this->mwindow = mwindow;
555 void KeyMutePatch::create_objects()
557 key_mute_checkbox = new KeyMuteValue(this);
558 add_subwindow(key_mute_checkbox);
559 key_mute_checkbox->activate();
563 KeyMuteValue::KeyMuteValue(KeyMutePatch *key_mute_patch)
564 : BC_CheckBox(0,0, key_mute_patch->mwindow->
565 get_int_auto(key_mute_patch->patch, AUTOMATION_MUTE)->value,
566 _("Mute"), MEDIUMFONT, RED)
568 this->key_mute_patch = key_mute_patch;
571 int KeyMuteValue::button_release_event()
573 BC_CheckBox::button_release_event();
577 void KeyMuteValue::update_edl()
579 MWindow *mwindow = key_mute_patch->mwindow;
580 PatchGUI *patch = key_mute_patch->patch;
581 double position = mwindow->edl->local_session->get_selectionstart(1);
582 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
583 int need_undo = !mute_autos->auto_exists_for_editing(position);
584 mwindow->undo->update_undo_before(_("mute"), need_undo ? 0 : this);
585 IntAuto *current = (IntAuto*)mute_autos->get_auto_for_editing(position);
586 current->value = this->get_value();
587 mwindow->undo->update_undo_after(_("mute"), LOAD_AUTOMATION);
590 int KeyMuteValue::handle_event()
592 MWindow *mwindow = key_mute_patch->mwindow;
593 PatchGUI *patch = key_mute_patch->patch;
594 patch->change_source = 1;
596 patch->change_source = 0;
597 mwindow->sync_parameters(CHANGE_PARAMS);
598 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE]) {
599 mwindow->gui->update_patchbay();
600 mwindow->gui->draw_overlays(1);
605 KeySpeedPatch::KeySpeedPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
606 : BC_SubWindow(x,y, 200,20, GWindowGUI::auto_colors[AUTOMATION_SPEED])
608 this->mwindow = mwindow;
612 void KeySpeedPatch::create_objects()
614 key_speed_slider = new KeySpeedValue(this);
615 add_subwindow(key_speed_slider);
616 key_speed_slider->activate();
620 KeySpeedValue::KeySpeedValue(KeySpeedPatch *key_speed_patch)
621 : BC_FSlider(0,0, 0, key_speed_patch->get_w(), key_speed_patch->get_w(),
622 key_speed_patch->mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_SPEED],
623 key_speed_patch->mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_SPEED],
624 key_speed_patch->mwindow->get_float_auto(key_speed_patch->patch, AUTOMATION_SPEED)->get_value())
626 this->key_speed_patch = key_speed_patch;
627 key_speed_patch->mwindow->speed_before();
631 KeySpeedValue::~KeySpeedValue()
635 int KeySpeedValue::button_release_event()
637 BC_FSlider::button_release_event();
638 key_speed_patch->mwindow->speed_after(1);
639 key_speed_patch->mwindow->resync_guis();
643 void KeySpeedValue::update_edl()
645 MWindow *mwindow = key_speed_patch->mwindow;
646 PatchGUI *patch = key_speed_patch->patch;
647 double position = mwindow->edl->local_session->get_selectionstart(1);
648 Autos *speed_autos = patch->track->automation->autos[AUTOMATION_SPEED];
649 int need_undo = !speed_autos->auto_exists_for_editing(position);
650 mwindow->undo->update_undo_before(_("speed"), need_undo ? 0 : this);
651 FloatAuto *current = (FloatAuto*)speed_autos->get_auto_for_editing(position);
652 current->set_value(get_value());
653 mwindow->undo->update_undo_after(_("speed"), LOAD_AUTOMATION+LOAD_EDITS);
656 int KeySpeedValue::handle_event()
658 MWindow *mwindow = key_speed_patch->mwindow;
659 PatchGUI *patch = key_speed_patch->patch;
662 set_tooltip(get_caption());
665 patch->change_source = 1;
667 patch->change_source = 0;
668 mwindow->sync_parameters(CHANGE_PARAMS);
669 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_SPEED]) {
670 mwindow->gui->draw_overlays(1);