reload plugin btn in prefs, speed gang fader tweaks
[goodguy/history.git] / cinelerra-5.1 / cinelerra / keyframepopup.C
index 293e1852054753d3a91167d0f6e21880ec5fad8c..7624da1631574fc7a8d16471c9a4f70110ec8f5c 100644 (file)
@@ -2,21 +2,21 @@
 /*
  * CINELERRA
  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
- * 
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- * 
+ *
  */
 
 #include "apatchgui.h"
@@ -25,7 +25,7 @@
 #include "autos.h"
 #include "bcwindowbase.h"
 #include "cpanel.h"
-#include "cwindowgui.h" 
+#include "cwindowgui.h"
 #include "cwindow.h"
 #include "edl.h"
 #include "edlsession.h"
@@ -34,6 +34,7 @@
 #include "gwindow.h"
 #include "gwindowgui.h"
 #include "intauto.h"
+#include "keys.h"
 #include "keyframe.h"
 #include "keyframepopup.h"
 #include "language.h"
 #include "mwindowgui.h"
 #include "mwindow.h"
 #include "patchbay.h"
-#include "patchgui.h" 
+#include "patchgui.h"
+#include "theme.h"
 #include "timelinepane.h"
 #include "track.h"
+#include "trackcanvas.h"
 #include "vtrack.h"
 
 KeyframePopup::KeyframePopup(MWindow *mwindow, MWindowGUI *gui)
@@ -125,7 +128,7 @@ int KeyframePopup::update(Automation *automation, Autos *autos, Auto *auto_keyfr
                mwindow->edl->local_session->set_selectionstart(new_position);
                mwindow->edl->local_session->set_selectionend(new_position);
                mwindow->gui->lock_window();
-               mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);      
+               mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
                mwindow->gui->unlock_window();
        }
        return 0;
@@ -187,7 +190,9 @@ KeyframePopupDelete::~KeyframePopupDelete()
 int KeyframePopupDelete::handle_event()
 {
        mwindow->undo->update_undo_before(_("delete keyframe"), 0);
+       mwindow->speed_before();
        delete popup->keyframe_auto;
+       mwindow->speed_after(1);
        mwindow->undo->update_undo_after(_("delete keyframe"), LOAD_ALL);
 
        mwindow->save_backup();
@@ -229,22 +234,6 @@ KeyframePopupShow::~KeyframePopupShow()
 {
 }
 
-PatchGUI *KeyframePopupShow::get_patchgui(Track *track)
-{
-       PatchGUI *patchgui = 0;
-       TimelinePane **panes = mwindow->gui->pane;
-       for( int i=0; i<TOTAL_PANES && !patchgui; ++i ) {
-               if( !panes[i] ) continue;
-               PatchBay *patchbay = panes[i]->patchbay;
-               if( !patchbay ) continue;
-               for( int j=0; j<patchbay->patches.total && !patchgui; ++j ) {
-                       if( patchbay->patches.values[j]->track == track )
-                               patchgui = patchbay->patches.values[j];
-               }
-       }
-       return patchgui;
-}
-
 int KeyframePopupShow::handle_event()
 {
        MWindowGUI *mgui = mwindow->gui;
@@ -271,7 +260,7 @@ int KeyframePopupShow::handle_event()
                case AUTOMATION_PROJECTOR_X:
                case AUTOMATION_PROJECTOR_Y:
                case AUTOMATION_PROJECTOR_Z: {
-                       cgui->set_operation(CWINDOW_PROJECTOR); 
+                       cgui->set_operation(CWINDOW_PROJECTOR);
                        break; }
 
                case AUTOMATION_MASK: {
@@ -280,7 +269,7 @@ int KeyframePopupShow::handle_event()
 
                default: {
                        show_window = 0;
-                       PatchGUI *patchgui = get_patchgui(popup->keyframe_automation->track);
+                       PatchGUI *patchgui = mwindow->get_patchgui(popup->keyframe_automation->track);
                        if( !patchgui ) break;
 
                        switch( popup->keyframe_autos->autoidx ) {
@@ -438,9 +427,7 @@ int KeyframePopupCopy::handle_event()
                file.terminate_string();
 
                mwindow->gui->lock_window();
-               mwindow->gui->get_clipboard()->to_clipboard(file.string, 
-                       strlen(file.string), 
-                       SECONDARY_SELECTION);
+               mwindow->gui->to_clipboard(file.string, strlen(file.string), SECONDARY_SELECTION);
                mwindow->gui->unlock_window();
 
        } else
@@ -452,8 +439,8 @@ int KeyframePopupCopy::handle_event()
 
 
 KeyframePopupCurveMode::KeyframePopupCurveMode(
-       MWindow *mwindow, 
-       KeyframePopup *popup, 
+       MWindow *mwindow,
+       KeyframePopup *popup,
        int curve_mode)
  : BC_MenuItem( get_labeltext(curve_mode))
 {
@@ -485,18 +472,18 @@ void KeyframePopupCurveMode::toggle_mode(FloatAuto *keyframe)
 
 int KeyframePopupCurveMode::handle_event()
 {
-       if (popup->keyframe_autos && 
+       if (popup->keyframe_autos &&
            popup->keyframe_autos->get_type() == AUTOMATION_TYPE_FLOAT)
        {
                mwindow->undo->update_undo_before(_("change keyframe curve mode"), 0);
                ((FloatAuto*)popup->keyframe_auto)->
                        change_curve_mode((FloatAuto::t_mode)curve_mode);
-               
+
                // if we switched to some "auto" mode, this may imply a
                // real change to parameters, so this needs to be undoable...
                mwindow->undo->update_undo_after(_("change keyframe curve mode"), LOAD_ALL);
                mwindow->save_backup();
-               
+
                mwindow->gui->update(0, 1, 0,0,0,0,0); // incremental redraw for canvas
                mwindow->cwindow->update(0,0, 1, 0,0); // redraw tool window in compositor
                mwindow->update_plugin_guis();
@@ -587,13 +574,18 @@ KeyMuteValue::KeyMuteValue(KeyMutePatch *key_mute_patch)
 int KeyMuteValue::button_release_event()
 {
        BC_CheckBox::button_release_event();
-       return 0;
+       MWindowGUI *mgui = key_mute_patch->mwindow->gui;
+       delete mgui->keyvalue_popup;
+       mgui->keyvalue_popup = 0;
+       return 1;
 }
 
-void KeyMuteValue::update_edl()
+int KeyMuteValue::handle_event()
 {
        MWindow *mwindow = key_mute_patch->mwindow;
        PatchGUI *patch = key_mute_patch->patch;
+
+       patch->change_source = 1;
        double position = mwindow->edl->local_session->get_selectionstart(1);
        Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
        int need_undo = !mute_autos->auto_exists_for_editing(position);
@@ -601,17 +593,10 @@ void KeyMuteValue::update_edl()
        IntAuto *current = (IntAuto*)mute_autos->get_auto_for_editing(position);
        current->value = this->get_value();
        mwindow->undo->update_undo_after(_("mute"), LOAD_AUTOMATION);
-}
-
-int KeyMuteValue::handle_event()
-{
-       MWindow *mwindow = key_mute_patch->mwindow;
-       PatchGUI *patch = key_mute_patch->patch;
-       patch->change_source = 1;
-       update_edl();
        patch->change_source = 0;
+
        mwindow->sync_parameters(CHANGE_PARAMS);
-       if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE]) {
+       if( mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE] ) {
                mwindow->gui->update_patchbay();
                mwindow->gui->draw_overlays(1);
        }
@@ -627,61 +612,123 @@ KeySpeedPatch::KeySpeedPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
 
 void KeySpeedPatch::create_objects()
 {
-       key_speed_slider = new KeySpeedValue(this);
-       add_subwindow(key_speed_slider);
-       key_speed_slider->activate();
+       int x = 0, y = 0;
+       float v = mwindow->get_float_auto(patch, AUTOMATION_SPEED)->get_value();
+       add_subwindow(key_speed_text = new KeySpeedText(this, x, y, 64, v));
+       x += key_speed_text->get_w();
+       VFrame **lok_images = mwindow->theme->get_image_set("lok");
+       int w1 = get_w() - x - lok_images[0]->get_w();
+       add_subwindow(key_speed_slider = new KeySpeedSlider(this, x, y, w1, v));
+       x += key_speed_slider->get_w();
+       add_subwindow(key_speed_ok = new KeySpeedOK(this, x, y, lok_images));
+       activate();
        show_window();
 }
 
-KeySpeedValue::KeySpeedValue(KeySpeedPatch *key_speed_patch)
- : BC_FSlider(0,0, 0, key_speed_patch->get_w(), key_speed_patch->get_w(),
-       key_speed_patch->mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_SPEED],
-       key_speed_patch->mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_SPEED],
-       key_speed_patch->mwindow->get_float_auto(key_speed_patch->patch, AUTOMATION_SPEED)->get_value())
+int KeySpeedPatch::cursor_enter_event()
 {
-       this->key_speed_patch = key_speed_patch;
-       set_precision(0.01);
+       if( is_event_win() )
+               mwindow->speed_before();
+       return 1;
 }
 
-KeySpeedValue::~KeySpeedValue()
+int KeySpeedPatch::cursor_leave_event()
 {
+       if( is_event_win() ) {
+               mwindow->speed_after(1);
+               mwindow->resync_guis();
+       }
+       return 1;
 }
 
-int KeySpeedValue::button_release_event()
+void KeySpeedPatch::update(float v)
 {
-       BC_FSlider::button_release_event();
-       return 0;
+       key_speed_text->update(v);
+       key_speed_slider->update(v);
+       update_speed(v);
 }
 
-void KeySpeedValue::update_edl()
+void KeySpeedPatch::update_speed(float v)
 {
-       MWindow *mwindow = key_speed_patch->mwindow;
-       PatchGUI *patch = key_speed_patch->patch;
+       patch->change_source = 1;
        double position = mwindow->edl->local_session->get_selectionstart(1);
-       Autos *speed_autos = patch->track->automation->autos[AUTOMATION_SPEED];
+       Track *track = patch->track;
+       Autos *speed_autos = track->automation->autos[AUTOMATION_SPEED];
        int need_undo = !speed_autos->auto_exists_for_editing(position);
+
        mwindow->undo->update_undo_before(_("speed"), need_undo ? 0 : this);
        FloatAuto *current = (FloatAuto*)speed_autos->get_auto_for_editing(position);
-       current->set_value(get_value());
-       mwindow->undo->update_undo_after(_("speed"), LOAD_AUTOMATION);
+       float change = v - current->get_value();
+       current->set_value(v);
+       if( track->gang && track->record ) {
+               TrackCanvas *track_canvas = patch->patchbay->pane->canvas;
+               track_canvas->fill_ganged_autos(1, change, track, current);
+               track_canvas->update_ganged_autos(0, track, current);
+               track_canvas->clear_ganged_autos();
+       }
+       mwindow->undo->update_undo_after(_("speed"), LOAD_AUTOMATION+LOAD_EDITS);
+       patch->change_source = 0;
+
+       mwindow->sync_parameters(CHANGE_PARAMS);
+       if(mwindow->edl->session->auto_conf->autos[AUTOMATION_SPEED]) {
+               mwindow->gui->draw_overlays(1);
+       }
+}
+
+KeySpeedOK::KeySpeedOK(KeySpeedPatch *key_speed_patch, int x, int y, VFrame **images)
+ : BC_Button(x, y, images)
+{
+       this->key_speed_patch = key_speed_patch;
 }
 
-int KeySpeedValue::handle_event()
+int KeySpeedOK::handle_event()
 {
        MWindow *mwindow = key_speed_patch->mwindow;
-       PatchGUI *patch = key_speed_patch->patch;
+       mwindow->speed_after(1);
+       mwindow->resync_guis();
+       MWindowGUI *mgui = mwindow->gui;
+       delete mgui->keyvalue_popup;
+       mgui->keyvalue_popup = 0;
+       return 1;
+}
+
+KeySpeedText::KeySpeedText(KeySpeedPatch *key_speed_patch, int x, int y, int w, float v)
+ : BC_TextBox(x, y, w, 1, v, 1, MEDIUMFONT, 2)
+{
+       this->key_speed_patch = key_speed_patch;
+}
+
+int KeySpeedText::handle_event()
+{
+       float v = atof(get_text());
+       key_speed_patch->update(v);
+       return get_keypress() != RETURN ? 1 :
+               key_speed_patch->key_speed_ok->handle_event();
+}
+
+KeySpeedSlider::KeySpeedSlider(KeySpeedPatch *key_speed_patch,
+               int x, int y, int w, float v)
+ : BC_FSlider(x, y, 0, w, w,
+       key_speed_patch->mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_SPEED],
+       key_speed_patch->mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_SPEED],
+       v)
+{
+       this->key_speed_patch = key_speed_patch;
+       key_speed_patch->mwindow->speed_before();
+       set_precision(0.01);
+}
+
+KeySpeedSlider::~KeySpeedSlider()
+{
+}
+
+int KeySpeedSlider::handle_event()
+{
        if( shift_down() ) {
                update(1.0);
                set_tooltip(get_caption());
        }
-
-       patch->change_source = 1;
-       update_edl();
-       patch->change_source = 0;
-       mwindow->sync_parameters(CHANGE_PARAMS);
-       if(mwindow->edl->session->auto_conf->autos[AUTOMATION_SPEED]) {
-               mwindow->gui->draw_overlays(1);
-       }
+       key_speed_patch->update(get_value());
        return 1;
 }