18 new shapewipe transitions from rafa, rework savefile/confirm for nested edl edits
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindowmove.C
index c55f6228d81752d65f35f8e07d82d2be42c5ccf1..dedf96e87671af9b5f7ec099d986cf4a25c58de0 100644 (file)
@@ -145,7 +145,7 @@ void MWindow::fit_selection()
 }
 
 
-void MWindow::fit_autos(int doall)
+void MWindow::fit_autos(int all)
 {
        float min = 0, max = 0;
        double start, end;
@@ -167,7 +167,7 @@ void MWindow::fit_autos(int doall)
        int forstart = edl->local_session->zoombar_showautotype;
        int forend   = edl->local_session->zoombar_showautotype + 1;
 
-       if (doall) {
+       if( all ) {
                forstart = 0;
                forend   = AUTOGROUPTYPE_COUNT;
        }
@@ -500,21 +500,10 @@ int MWindow::goto_start()
 
 int MWindow::goto_position(double position)
 {
-       TimelinePane *pane = gui->get_focused_pane();
-       int64_t old_view_start = edl->local_session->view_start[pane->number];
-       edl->local_session->set_selectionstart(position);
-       edl->local_session->set_selectionend(position);
-       find_cursor();
-       int64_t new_view_start = edl->local_session->view_start[pane->number];
-       if(new_view_start != old_view_start)
-               samplemovement(new_view_start, pane->number);
-       update_plugin_guis();
-       gui->update_patchbay();
-       gui->update_cursor();
+       position = edl->align_to_frame(position, 0);
+       if( position < 0 ) position = 0;
+       select_point(position);
        gui->activate_timeline();
-       gui->zoombar->update();
-       gui->update_timebar(1);
-       cwindow->update(1, 0, 0, 0, 1);
        return 0;
 }
 
@@ -548,8 +537,7 @@ int MWindow::move_left(int64_t distance)
 {
        TimelinePane *pane = gui->get_focused_pane();
        if(!distance)
-               distance = pane->canvas->get_w() /
-                       10;
+               distance = pane->canvas->get_w() / 10;
        edl->local_session->view_start[pane->number] -= distance;
        samplemovement(edl->local_session->view_start[pane->number],
                pane->number);
@@ -560,8 +548,7 @@ int MWindow::move_right(int64_t distance)
 {
        TimelinePane *pane = gui->get_focused_pane();
        if(!distance)
-               distance = pane->canvas->get_w() /
-                       10;
+               distance = pane->canvas->get_w() / 10;
        edl->local_session->view_start[pane->number] += distance;
        samplemovement(edl->local_session->view_start[pane->number],
                pane->number);
@@ -577,7 +564,7 @@ void MWindow::select_all()
                edl->local_session->set_selectionstart(0);
                edl->local_session->set_selectionend(edl->tracks->total_length());
        }
-       gui->update(0, 1, 1, 1, 0, 1, 0);
+       gui->update(0, NORMAL_DRAW, 1, 1, 0, 1, 0);
        gui->activate_timeline();
        cwindow->update(1, 0, 0, 0, 1);
        update_plugin_guis();
@@ -657,7 +644,8 @@ int MWindow::nearest_plugin_keyframe(int shift_down, int dir)
        KeyFrame *keyframe = 0;
        double start = edl->local_session->get_selectionstart(1);
        double end = edl->local_session->get_selectionend(1);
-       double position = dir == PLAY_FORWARD ? end : start, new_position = 0;
+       double position = dir == PLAY_FORWARD ? end : start;
+       double new_position = dir == PLAY_FORWARD ? start : end;
        for( Track *track=edl->tracks->first; track; track=track->next ) {
                if( !track->record ) continue;
                for( int i=0; i<track->plugin_set.size(); ++i ) {
@@ -689,6 +677,47 @@ int MWindow::nearest_plugin_keyframe(int shift_down, int dir)
        return find_selection(new_position);
 }
 
+int MWindow::nearest_auto_keyframe(int shift_down, int dir)
+{
+       Auto *keyframe = 0;
+       double start = edl->local_session->get_selectionstart(1);
+       double end = edl->local_session->get_selectionend(1);
+       double position = dir == PLAY_FORWARD ? end : start;
+       double new_position = dir == PLAY_FORWARD ? start : end;
+       for( Track *track=edl->tracks->first; track; track=track->next ) {
+               if( !track->record ) continue;
+               int64_t pos = track->to_units(position, 0);
+               for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
+                       Autos *autos = track->automation->autos[i];
+                       if( !autos ) continue;
+                       Auto *key = dir == PLAY_FORWARD ?
+                                autos->nearest_after(pos) :
+                                autos->nearest_before(pos);
+                       if( !key ) continue;
+                       double key_position = track->from_units(key->position);
+                       if( keyframe && (dir == PLAY_FORWARD ?
+                               key_position >= new_position :
+                               new_position >= key_position ) ) continue;
+                       keyframe = key;  new_position = key_position;
+               }
+       }
+
+       new_position = keyframe ?
+               keyframe->autos->track->from_units(keyframe->position) :
+               dir == PLAY_FORWARD ? edl->tracks->total_length() : 0;
+
+       if( !shift_down )
+               start = end = new_position;
+       else if( dir == PLAY_FORWARD )
+               end = new_position;
+       else
+               start = new_position;
+
+       edl->local_session->set_selectionstart(start);
+       edl->local_session->set_selectionend(end);
+       return find_selection(new_position);
+}
+
 int MWindow::find_selection(double position, int scroll_display)
 {
        update_plugin_guis();
@@ -716,6 +745,25 @@ int MWindow::find_selection(double position, int scroll_display)
        return 0;
 }
 
+double MWindow::get_position()
+{
+        return edl->local_session->get_selectionstart(1);
+}
+
+void MWindow::set_position(double position)
+{
+        if( position != get_position() ) {
+                if( position < 0 ) position = 0;
+                edl->local_session->set_selectionstart(position);
+                edl->local_session->set_selectionend(position);
+                gui->lock_window();
+                find_cursor();
+                gui->update(1, NORMAL_DRAW, 1, 1, 1, 1, 0);
+                gui->unlock_window();
+                cwindow->update(1, 0, 0, 0, 0);
+        }
+}
+
 
 int MWindow::expand_y()
 {