reload plugin btn in prefs, speed gang fader tweaks
[goodguy/history.git] / cinelerra-5.1 / cinelerra / trackcanvas.C
index 8ff10d201436032da96830af9e896bf38e342c76..fdd3112bb6b2fb62f315fc7c2f3fb70de94bf9ba 100644 (file)
@@ -2095,10 +2095,8 @@ int TrackCanvas::do_keyframes(int cursor_x,
                                                if (buttonpress != 3)
                                                {
                                                        if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
-                                                               synchronize_autos(0,
-                                                                       track,
-                                                                       (FloatAuto*)mwindow->session->drag_auto,
-                                                                       1);
+                                                               fill_ganged_autos(get_double_click(), 0, track,
+                                                                       (FloatAuto*)mwindow->session->drag_auto);
                                                        mwindow->session->current_operation = pre_auto_operations[i];
                                                        update_drag_caption();
                                                        rerender = 1;
@@ -2177,34 +2175,37 @@ void TrackCanvas::draw_keyframe_reticle()
        int current_op = mwindow->session->current_operation, dragging = 0;
        for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
                if( current_op == auto_operations[i] ) dragging = 1;
+       if( dragging && !mwindow->session->drag_auto ) dragging = 0;
 
-       if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
-               if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
-                       draw_hairline(mwindow->session->drag_auto, RED);
-                       return;
-               }
+       int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
+               mwindow->session->drag_auto->autos->autoidx : -1;
+
+       if( get_buttonpress() == 1 && dragging &&
+            keyframe_hairline == HAIRLINE_DRAGGING ) {
+               draw_hairline(mwindow->session->drag_auto, RED, 1);
+               return;
        }
 
        if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
            keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
-               for( Track *track = mwindow->edl->tracks->first; track;
-                    track=track->next ) {
+               int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
+               for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
                        Automation *automation = track->automation;
                        for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
                                if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
                                // automation visible
                                Autos *autos = automation->autos[i];
                                if( !autos ) continue;
+                               if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
                                for( Auto *auto_keyframe=autos->first; auto_keyframe;
                                     auto_keyframe = auto_keyframe->next ) {
-                                       draw_hairline(auto_keyframe, BLUE);
+                                       draw_hairline(auto_keyframe, BLUE, show);
                                }
                        }
-
-                       if( dragging && mwindow->session->drag_auto ) {
-                               draw_hairline(mwindow->session->drag_auto, RED);
-                       }
                }
+
+               if( dragging )
+                       draw_hairline(mwindow->session->drag_auto, RED, 1);
        }
 }
 
@@ -2720,69 +2721,68 @@ int TrackCanvas::test_floatline(int center_pixel,
 }
 
 
-void TrackCanvas::synchronize_autos(float change,
-               Track *skip, FloatAuto *fauto, int fill_gangs)
+void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto)
 {
+       if( !skip->gang ) return;
 // Handles the special case of modifying a fadeauto
 // when there are ganged faders on several tracks
-// (skip and fauto may be NULL if fill_gangs==-1)
-
-       if( fill_gangs > 0 && skip->gang ) {
-               double position = skip->from_units(fauto->position);
-               int autoidx = fauto->autos->autoidx;
-
-               for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
-                       if( (current->data_type == skip->data_type || get_double_click()) &&
-                           current->gang && current->record && current != skip ) {
-                               int64_t current_position = current->to_units(position, 1);
-                               FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
-                               float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
-                               float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
-                               FloatAuto *previous = 0, *next = 0;
-                               FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
-                               if( !keyframe ) {
-// create keyframe on neighbouring track at the point in time given by fauto
-                                       float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
-                                       float new_value = init_value + change;
-                                       CLAMP(new_value, auto_min, auto_max);
-                                       keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
-                                       keyframe->set_value(new_value);
-                               }
-                               else {
+       double position = skip->from_units(fauto->position);
+       int autoidx = fauto->autos->autoidx;
+
+       for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
+               if( (all || current->data_type == skip->data_type) &&
+                   current->gang && current->record && current != skip ) {
+                       FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
+                       float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
+                       float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
+                       int64_t current_position = current->to_units(position, 1);
+                       FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
+                       if( keyframe ) {
 // keyframe exists, just change it
-                                       float new_value = keyframe->get_value() + change;
-                                       CLAMP(new_value, auto_min, auto_max);
-                                       keyframe->adjust_to_new_coordinates(current_position, new_value);
-// need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
-                               }
-
-                               mwindow->session->drag_auto_gang->append((Auto *)keyframe);
+                               float value = keyframe->get_value();
+                               float new_value = value + change;
+                               CLAMP(new_value, auto_min, auto_max);
+                               keyframe->adjust_to_new_coordinates(current_position, new_value);
+                       }
+                       else if( mwindow->edl->session->auto_keyframes ) {
+// create keyframe on neighbouring track at the point in time given by fauto
+                               FloatAuto *previous = 0, *next = 0;
+                               float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
+                               float new_value = value + change;
+                               CLAMP(new_value, auto_min, auto_max);
+                               keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
+                               keyframe->set_value(new_value);
                        }
+                       else
+                               continue;
+                       mwindow->session->drag_auto_gang->append((Auto *)keyframe);
                }
        }
-       else if( !fill_gangs ) {
-               double position = skip->from_units(fauto->position);
-// Move the gangs
-               for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
-                       FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
-                       int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
-                       float new_value = keyframe->get_value() + change;
-                       CLAMP(new_value,
-                             mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
-                             mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
-                       keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
-               }
+}
 
+void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
+{
+       double position = skip->from_units(fauto->position);
+// Move the gangs
+       for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
+               FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
+               int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
+               float new_value = keyframe->get_value() + change;
+               CLAMP(new_value,
+                     mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
+                     mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
+               keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
        }
-       else {
+}
+
+void TrackCanvas::clear_ganged_autos()
+{
 // remove the gangs
-               for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
-                       FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
-                       keyframe->autos->remove_nonsequential(
-                                       keyframe);
-               }
-               mwindow->session->drag_auto_gang->remove_all();
+       for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
+               FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
+               keyframe->autos->remove_nonsequential(keyframe);
        }
+       mwindow->session->drag_auto_gang->remove_all();
 }
 
 
@@ -3458,10 +3458,10 @@ int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
        return result;
 }
 
-int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
+int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
 {
        Track *track = auto_keyframe->autos->track;
-       int autogrouptype = auto_keyframe->autos->get_type();
+       int autogrouptype = auto_keyframe->autos->autogrouptype;
 
        int center_pixel;
        double view_start, unit_start;
@@ -3477,6 +3477,31 @@ int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
 
        set_color(color);
        draw_line(ax, 0, ax, get_h());
+
+       if( show ) {
+               char text[BCSTRLEN];
+               if( auto_keyframe->is_floatauto() ) {
+                       FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
+                       sprintf(text, "%0.2f", float_auto->get_value());
+               }
+               else {
+                       IntAuto *int_auto = (IntAuto *)auto_keyframe;
+                       sprintf(text, "%d", int_auto->value);
+               }
+               int font = MEDIUMFONT;
+               int tw = get_text_width(font, text)  + TOOLTIP_MARGIN * 2;
+               int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2;
+               set_color(get_resources()->tooltip_bg_color);
+               ax += HANDLE_W/2;
+               ay += center_pixel + HANDLE_W/2;
+               draw_box(ax, ay, tw, th);
+               set_color(BLACK);
+               draw_rectangle(ax, ay, tw, th);
+               set_font(font);
+               ax += TOOLTIP_MARGIN;
+               ay += TOOLTIP_MARGIN + get_text_ascent(font);
+               draw_text(ax, ay, text);
+       }
        return 0;
 }
 
@@ -3820,7 +3845,7 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
                        result = 1;
                        float change = value - old_value;
                        current->adjust_to_new_coordinates(position, value);
-                       synchronize_autos(change, current->autos->track, current, 0);
+                       update_ganged_autos(change, current->autos->track, current);
                        show_message(current, 1,", %.2f", current->get_value());
                }
                break;
@@ -3839,7 +3864,7 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
                        current->set_control_in_value(
                                value * levered_position(position - current->position,
                                                         current->get_control_in_position()));
-                       synchronize_autos(0, current->autos->track, current, 0);
+                       update_ganged_autos(0, current->autos->track, current);
                        show_message(current, 1,", %.2f", current->get_control_in_value());
                }
                break; }
@@ -3853,7 +3878,7 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
                        current->set_control_out_value(
                                value * levered_position(position - current->position,
                                                         current->get_control_out_position()));
-                       synchronize_autos(0, current->autos->track, current, 0);
+                       update_ganged_autos(0, current->autos->track, current);
                        show_message(current, 1,", %.2f", current->get_control_out_value());
                }
                break; }
@@ -4380,7 +4405,7 @@ int TrackCanvas::button_release_event()
                        load_flags |= LOAD_EDITS;
                case DRAG_FADE:
 // delete the drag_auto_gang first and remove out of order keys
-                       synchronize_autos(0, 0, 0, -1);
+                       clear_ganged_autos();
                case DRAG_CZOOM:
                case DRAG_PZOOM:
                case DRAG_PLAY: