X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ftrackcanvas.C;h=f37b1cd63c4d307873a64fdda3c71b2cd5cfc3c5;hb=22c6251d37911a11e322bf7518e6a992ea0bb6c7;hp=c0f8f995d3453504ef4fc830c5cf9d55c7189e8a;hpb=f5725c7e12def18fec49a295dad688652edaa4b3;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/cinelerra/trackcanvas.C b/cinelerra-5.1/cinelerra/trackcanvas.C index c0f8f995..f37b1cd6 100644 --- a/cinelerra-5.1/cinelerra/trackcanvas.C +++ b/cinelerra-5.1/cinelerra/trackcanvas.C @@ -1658,6 +1658,9 @@ void TrackCanvas::draw_highlighting() } break; + case DRAG_SPEED: + draw_speed_highlight(); + break; } if( draw_box ) @@ -1666,6 +1669,33 @@ void TrackCanvas::draw_highlighting() draw_selected_edits(mwindow->edl, 0, 0, GREEN+BLUE, RED); } +void TrackCanvas::draw_speed_highlight() +{ + FloatAuto *drag_speed = (FloatAuto*)mwindow->session->drag_auto; + if( !drag_speed ) return; + draw_speed_track(drag_speed->autos->track); + ArrayList &speed_gang = *mwindow->session->drag_auto_gang; + for( int i=0, sz=speed_gang.size(); iautos->track; + if( track->is_hidden() ) continue; + draw_speed_track(track); + } +} + +void TrackCanvas::draw_speed_track(Track *track) +{ + for( Edit *edit=track->edits->first; edit; edit=edit->next ) { + int64_t x, y, w, h; + edit_dimensions(edit, x, y, w, h); + if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue; + if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue; + int color = 0xc00cc0; + set_color(color); + set_opaque(); + draw_selected(x, y, w, h); + } +} + // x does not reliably draw a really big rectangle void TrackCanvas::draw_selected(int x, int y, int w, int h) { @@ -1981,7 +2011,10 @@ void TrackCanvas::draw_drag_handle() idxbl->get_audio_samples() : edit->track->data_type == TRACK_VIDEO ? idxbl->get_video_frames() : -1; - if( edit->startsource + edit->length >= source_len ) + int64_t speed_start = edit->startproject; + int64_t speed_end = speed_start + edit->length; + int64_t speed_length = track->speed_length(speed_start, speed_end); + if( edit->startsource + speed_length >= source_len ) can_drag = 0; } else if( !edit->startsource ) @@ -2237,7 +2270,7 @@ int TrackCanvas::do_keyframes(int cursor_x, auto_keyframe, grouptype); if( !result && buttonpress && i == AUTOMATION_SPEED ) - mwindow->speed_after(-1); + mwindow->speed_after(-1, 0); if( result && buttonpress ) { int color = GWindowGUI::auto_colors[i]; mwindow->gui->zoombar->update_autozoom(grouptype, color); @@ -2457,14 +2490,20 @@ void TrackCanvas::draw_cropped_line(int x1, } -void TrackCanvas::draw_floatauto(FloatAuto *current, int x, int y, - int in_x, int in_y, int out_x, int out_y, - int center_pixel, int data_h, int color) +void TrackCanvas::draw_floatauto(FloatAuto *current, + int x_offset, int center_pixel, int data_h, int color, + double unit_start, double zoom_units, double yscale, + int autogrouptype) { + double xx, yy; + calculate_auto_position(1, &xx, &yy, 0, 0, 0, 0, + current, unit_start, zoom_units, yscale, autogrouptype); + int x = (int)xx + x_offset; int x1 = x - HANDLE_W / 2; // Center int x2 = x + HANDLE_W / 2; - int y1 = center_pixel + y - HANDLE_H / 2; - int y2 = center_pixel + y + HANDLE_H / 2; + int y = (int)yy + center_pixel; + int y1 = y - HANDLE_H / 2; + int y2 = y + HANDLE_H / 2; int ymin = center_pixel - data_h / 2; int ymax = center_pixel + data_h / 2; CLAMP(y1, ymin, ymax); @@ -2492,13 +2531,22 @@ void TrackCanvas::draw_floatauto(FloatAuto *current, int x, int y, // show bezier control points (only) if this // floatauto doesn't adjust it's tangents automatically if(current->curve_mode != FloatAuto::FREE && - current->curve_mode != FloatAuto::TFREE) + current->curve_mode != FloatAuto::TFREE && + current->curve_mode != FloatAuto::BUMP) return; - - if(in_x != x) - draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, data_h, color); - if(out_x != x) - draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, data_h, color); + double in_xx, in_yy, out_xx, out_yy; + calculate_auto_position(1, &xx, &yy, &in_xx, &in_yy, 0, 0, + current, unit_start, zoom_units, yscale, autogrouptype); + int ix = xx, iy = yy, in_x = in_xx, in_y = in_yy; + if( in_x != ix ) + draw_floatauto_ctrlpoint(ix, iy, in_x, in_y, center_pixel, data_h, color); + calculate_auto_position(0, &xx, &yy, 0, 0, &out_xx, &out_yy, + current, unit_start, zoom_units, yscale, autogrouptype); + int ox = xx, oy = yy, out_x = out_xx, out_y = out_yy; + if( out_x != ox ) + draw_floatauto_ctrlpoint(ox, oy, out_x, out_y, center_pixel, data_h, color); + if( current->curve_mode == FloatAuto::BUMP && iy != oy ) + draw_bline(ix, iy+center_pixel, ox, oy+center_pixel); } inline int quantize(float f) { return (int)floor(f + 0.5); } @@ -2639,16 +2687,21 @@ float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype) -int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x, - int in_y, int out_x, int out_y, int center_pixel, int data_h, - int cursor_x, int cursor_y, int buttonpress, int autogrouptype) +int TrackCanvas::test_floatauto(FloatAuto *current, int buttonpress, + int center_pixel, int data_h, int cursor_x, int cursor_y, + double unit_start, double zoom_units, double yscale, + int autogrouptype) { int result = 0; - - int x1 = x - HANDLE_W / 2; - int x2 = x + HANDLE_W / 2; - int y1 = center_pixel + y - HANDLE_W / 2; - int y2 = center_pixel + y + HANDLE_W / 2; + double xx, yy, in_xx, in_yy, out_xx, out_yy; + calculate_auto_position(1, &xx, &yy, &in_xx, &in_yy, 0, 0, + current, unit_start, zoom_units, yscale, autogrouptype); + int ix = xx, iy = yy, in_x = in_xx, in_y = in_yy; + + int x1 = ix - HANDLE_W / 2; + int x2 = ix + HANDLE_W / 2; + int y1 = center_pixel + iy - HANDLE_W / 2; + int y2 = center_pixel + iy + HANDLE_W / 2; int ymin = center_pixel - data_h/2; int ymax = center_pixel + data_h/2; CLAMP(y1, ymin, ymax); @@ -2661,6 +2714,9 @@ int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x, CLAMP(in_y1, ymin, ymax); CLAMP(in_y2, ymin, ymax); + calculate_auto_position(0, &xx, &yy, 0, 0, &out_xx, &out_yy, + current, unit_start, zoom_units, yscale, autogrouptype); + int ox = xx, oy = yy, out_x = out_xx, out_y = out_yy; int out_x1 = out_x - HANDLE_W / 2; int out_x2 = out_x + HANDLE_W / 2; int out_y1 = center_pixel + out_y - HANDLE_W / 2; @@ -2718,13 +2774,14 @@ int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x, float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point // Test in control - if( in_x != x && current->position > 0 && + if( in_x != ix && current->position > 0 && (FloatAuto::FREE == current->curve_mode || - FloatAuto::TFREE == current->curve_mode)) + FloatAuto::TFREE == current->curve_mode || + FloatAuto::BUMP == current->curve_mode)) // act on in control handle only if // tangent is significant and is editable (not automatically choosen) { - lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel); + lever = test_curve_line(ix, iy, in_x, in_y, cursor_x, cursor_y-center_pixel); // either cursor in ctrl-point handle or cursor on tangent line if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) { result = 1; @@ -2740,12 +2797,13 @@ int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x, } // Test out control - if(out_x != x && + if(out_x != ox && (FloatAuto::FREE == current->curve_mode || - FloatAuto::TFREE == current->curve_mode)) + FloatAuto::TFREE == current->curve_mode || + FloatAuto::BUMP == current->curve_mode)) // act on out control only if tangent is significant and is editable { - lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel); + lever = test_curve_line(ox, oy, out_x, out_y, cursor_x, cursor_y-center_pixel); if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) { result = 1; if(buttonpress && (buttonpress != 3)) { @@ -2773,6 +2831,9 @@ int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x, if(buttonpress && (buttonpress != 3) && result) { mwindow->undo->update_undo_before(); + double position = current->autos->track->from_units(current->position); + mwindow->edl->local_session->set_selectionstart(position); + mwindow->edl->local_session->set_selectionend(position); } return result; @@ -2780,43 +2841,31 @@ int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x, static int is_linear(FloatAuto *prev, FloatAuto *next) { - if( !prev || !next ) return 1; + if( !prev || !next ) return 0; if( prev->curve_mode == FloatAuto::LINEAR ) return 1; int64_t ipos = prev->get_control_in_position(); int64_t opos = prev->get_control_out_position(); if( !ipos && !opos ) return 1; if( !ipos || !opos ) return 0; - float ival = prev->get_control_in_value(); + float ival = next->get_control_in_value(); float oval = prev->get_control_out_value(); - float cval = prev->get_value(), nval = next->get_value(); + float cval = prev->get_value(0), nval = next->get_value(1); if( !ival && !oval && EQUIV(cval, nval) ) return 1; float ig = ival / ipos, og = oval / opos; int64_t cpos = prev->position, npos = next->position; float g = (nval - cval) / (npos - cpos); - if( EQUIV(ig, g) && EQUIV(og, g) ) return 1; + if( !EQUIV(g, 0) && EQUIV(ig, g) && EQUIV(og, g) ) return 1; return 0; } // Get the float value & y for position x on the canvas #define X_TO_FLOATLINE(x) \ - int64_t position1 = (int64_t)(unit_start + x * zoom_units); \ - int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \ + double position = unit_start + x * zoom_units; \ + int64_t position1 = (int64_t)position, position2 = position1 + 1; \ /* Call by reference fails for some reason here */ \ float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \ float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \ - double position = unit_start + x * zoom_units; \ - double value = 0; \ - if(position2 > position1) \ - { \ - value = value1 + \ - (value2 - value1) * \ - (position - position1) / \ - (position2 - position1); \ - } \ - else \ - { \ - value = value1; \ - } \ + double value = value1 + (value2 - value1) * (position - position1); \ AUTOMATIONCLAMPS(value, autogrouptype); \ int y = center_pixel + \ (int)(((value - automation_min) / automation_range - 0.5) * -yscale); @@ -2834,6 +2883,12 @@ void TrackCanvas::draw_floatline(int center_pixel, if( (y1 < ytop && y1 >= ybot) && (y2 < ytop || y2 >= ybot) ) return; // check for line draw if( is_linear(previous, next) ) { + if( previous && previous->curve_mode == FloatAuto::BUMP ) { + double ax, ay; + calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0, previous, + unit_start, zoom_units, yscale, autogrouptype); + x1 = ax; y1 = ay; y1 += center_pixel; + } draw_line(x1, y1, x2, y2); return; } @@ -2927,41 +2982,43 @@ int TrackCanvas::test_floatline(int center_pixel, return result; } - -void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto) +// gang=-1 for keyframepopup update, all tracks where fautos exist +// gang=0 for trackcanvas drag update, all gang matching tracks, create new fautos if needed +// gang=1 for trackcanvas drag update, all gang tracks, create new fautos if needed +void TrackCanvas::fill_ganged_autos(int gang, float change, Track *skip, FloatAuto *fauto) { if( !skip->is_ganged() ) return; // Handles the special case of modifying a fadeauto // when there are ganged faders on several tracks double position = skip->from_units(fauto->position); int autoidx = fauto->autos->autoidx; - + PatchGUI *patch = gang < 0 ? pane->patchbay->get_patch_of(skip) : 0; + int edge = patch ? patch->edge : 0; + int span = patch ? patch->span : 0; for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) { - if( (all || current->data_type == skip->data_type) && - current->armed_gang(skip) && current->is_armed() && - current != skip ) { + if( current == skip || !current->is_armed() ) continue; + if( !gang && current->data_type != skip->data_type ) continue; + if( skip->armed_gang(current) || get_double_click() ) { 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); + int64_t current_position = current->to_units(position, 1); if( keyframe ) { // keyframe exists, just change it - 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); + keyframe->bump_update(current_position, change, edge, span); } - else if( all >= 0 ) { + else if( gang >= 0 ) { // 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); + float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype]; + float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype]; + bclamp(new_value, auto_min, auto_max); keyframe = (FloatAuto*)fade_autos->insert_auto(current_position); - keyframe->set_value(new_value); + keyframe->set_value(new_value, edge); } - if( !keyframe ) continue; + else + continue; mwindow->session->drag_auto_gang->append((Auto *)keyframe); } } @@ -2974,11 +3031,9 @@ void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *faut 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); + keyframe->bump_update(keyframe_position, change, 0, 0); + keyframe->set_control_in_value(fauto->get_control_in_value()); + keyframe->set_control_out_value(fauto->get_control_out_value()); } } @@ -3130,7 +3185,7 @@ float TrackCanvas::percentage_to_value(float percentage, } -void TrackCanvas::calculate_auto_position(double *x, double *y, +void TrackCanvas::calculate_auto_position(int edge, double *x, double *y, double *in_x, double *in_y, double *out_x, double *out_y, Auto *current, double unit_start, double zoom_units, double yscale, int autogrouptype) @@ -3142,7 +3197,7 @@ void TrackCanvas::calculate_auto_position(double *x, double *y, automation_range = SPEED_MIN; FloatAuto *ptr = (FloatAuto*)current; *x = (double)(ptr->position - unit_start) / zoom_units; - *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale; + *y = ((ptr->get_value(edge) - automation_min) / automation_range - 0.5) * -yscale; if(in_x) { // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels; @@ -3150,7 +3205,7 @@ void TrackCanvas::calculate_auto_position(double *x, double *y, } if(in_y) { - *in_y = (((ptr->get_value() + ptr->get_control_in_value()) - + *in_y = (((ptr->get_value(edge) + ptr->get_control_in_value()) - automation_min) / automation_range - 0.5) * -yscale; } @@ -3160,7 +3215,7 @@ void TrackCanvas::calculate_auto_position(double *x, double *y, } if(out_y) { - *out_y = (((ptr->get_value() + ptr->get_control_out_value()) - + *out_y = (((ptr->get_value(edge) + ptr->get_control_out_value()) - automation_min) / automation_range - 0.5) * -yscale; } } @@ -3175,7 +3230,6 @@ int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cu double view_start, unit_start; double view_end, unit_end, yscale; double zoom_sample, zoom_units; - double in_x2, in_y2, out_x2, out_y2; double slope; //int skip = 0; @@ -3198,7 +3252,7 @@ int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cu double ax = 0, ay = 0, ax2 = 0, ay2 = 0; if( first_auto ) { - calculate_auto_position(&ax, &ay, 0, 0, 0, 0, + calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0, first_auto, unit_start, zoom_units, yscale, autogrouptype); } if( current ) @@ -3213,7 +3267,7 @@ int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cu draw_auto = 1; if(current) { - calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2, + calculate_auto_position(1, &ax2, &ay2, 0, 0, 0, 0, current, unit_start, zoom_units, yscale, autogrouptype); } else { @@ -3238,18 +3292,16 @@ int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cu // Draw or test handle if( current && !result && current != autos->default_auto ) { if( !draw && track->is_armed() ) { - result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2, - (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2, + result = test_floatauto((FloatAuto*)current, buttonpress, (int)center_pixel, (int)yscale, cursor_x, cursor_y, - buttonpress, autogrouptype); + unit_start, zoom_units, yscale, autogrouptype); if( result ) auto_instance = current; } if( draw && draw_auto ) { - draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2, - (int)in_x2 + x_offset, (int)in_y2, - (int)out_x2 + x_offset, (int)out_y2, - (int)center_pixel + y_offset, (int)yscale, color); + draw_floatauto((FloatAuto*)current, x_offset, + (int)center_pixel + y_offset, (int)yscale, color, + unit_start, zoom_units, yscale, autogrouptype); } } @@ -3269,9 +3321,10 @@ int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cu if( current ) { previous = current; + calculate_auto_position(0, &ax2, &ay2, 0, 0, 0, 0, previous, + unit_start, zoom_units, yscale, autogrouptype); current = NEXT; } - ax = ax2; ay = ay2; } while( current && current->position <= unit_end && !result ); @@ -3684,7 +3737,7 @@ int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show) return 0; double ax = 0, ay = 0; - calculate_auto_position(&ax, &ay, 0, 0, 0, 0, + calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0, auto_keyframe, unit_start, zoom_units, yscale, autogrouptype); set_color(color); @@ -4023,7 +4076,8 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y) // not really editing the node, rather start editing the curve // tangent is editable and drag movement is significant if( (FloatAuto::FREE == current->curve_mode || - FloatAuto::TFREE==current->curve_mode) && + FloatAuto::TFREE==current->curve_mode || + FloatAuto::BUMP==current->curve_mode) && (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2)) mwindow->session->drag_handle = x < 0 ? 1 : 2; } @@ -4033,28 +4087,27 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y) // Snap to nearby values old_value = current->get_value(); if(shift_down()) { - double value1, value2, distance1=-1, distance2=-1; - + double distance1=-1, distance2=-1; if(current->previous) { int autogrouptype = current->previous->autos->autogrouptype; value = percentage_to_value(percentage, 0, 0, autogrouptype); - value1 = ((FloatAuto*)current->previous)->get_value(); + double value1 = ((FloatAuto*)current->previous)->get_value(0); distance1 = fabs(value - value1); - current->set_value(value1); + current->set_value(value1, 1); } if(current->next) { int autogrouptype = current->next->autos->autogrouptype; value = percentage_to_value(percentage, 0, 0, autogrouptype); - value2 = ((FloatAuto*)current->next)->get_value(); + double value2 = ((FloatAuto*)current->next)->get_value(1); distance2 = fabs(value - value2); if(!current->previous || distance2 < distance1) { - current->set_value(value2); + current->set_value(value2, 0); } } if(!current->previous && !current->next) { - current->set_value( ((FloatAutos*)current->autos)->default_); + current->set_value(((FloatAutos*)current->autos)->default_, 0); } value = current->get_value(); } @@ -4319,7 +4372,7 @@ int TrackCanvas::cursor_update(int in_motion) if(active) rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y()); if( rerender && mwindow->session->current_operation == DRAG_SPEED ) - mwindow->speed_after(!in_motion ? 1 : 0); + mwindow->speed_after(!in_motion ? 1 : 0, 0); break; case DRAG_PLAY: @@ -4627,7 +4680,7 @@ int TrackCanvas::button_release_event() case DRAG_SPEED: redraw = FORCE_REDRAW; - load_flags |= LOAD_EDITS; + load_flags |= LOAD_EDITS | LOAD_TIMEBAR; case DRAG_FADE: // delete the drag_auto_gang first and remove out of order keys clear_ganged_autos();