X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ftrackcanvas.C;h=098090a693c4d419f0ebfbf17b26ebd76fef2981;hp=c377a8477136fba49275e2692cc45017815d4a6f;hb=13a039ef755e81e65c9479b4b615fd89bfe3e038;hpb=7995a2d831a88199bfce4c7caa9d16b214f6781b diff --git a/cinelerra-5.1/cinelerra/trackcanvas.C b/cinelerra-5.1/cinelerra/trackcanvas.C index c377a847..098090a6 100644 --- a/cinelerra-5.1/cinelerra/trackcanvas.C +++ b/cinelerra-5.1/cinelerra/trackcanvas.C @@ -194,7 +194,7 @@ int TrackCanvas::drag_motion( drag_cursor_motion(cursor_x, cursor_y, over_track, over_edit, over_pluginset, over_plugin); } - if( over_track && !*over_track ) + if( over_track && !*over_track ) *over_track = pane->over_patchbay(); return 0; } @@ -210,6 +210,7 @@ int TrackCanvas::drag_cursor_motion(int cursor_x, int cursor_y, // Find the edit and track the cursor is over for(Track *track = mwindow->edl->tracks->first; track; track = track->next) { + if( track->is_hidden() ) continue; int64_t track_x, track_y, track_w, track_h; track_dimensions(track, track_x, track_y, track_w, track_h); @@ -407,7 +408,7 @@ int TrackCanvas::drag_stop(int *redraw) mwindow->session->edit_highlighted->length); } start = mwindow->edl->align_to_frame(start, 0); - mwindow->insert_effects_canvas(start, length); + mwindow->insert_effects_canvas(track, start, length); *redraw = 1; } if( mwindow->session->track_highlighted ) @@ -493,7 +494,7 @@ int TrackCanvas::drag_stop(int *redraw) double track_position = track->from_units(drop_position); track_position = mwindow->edl->align_to_frame(track_position, 0); mwindow->move_edits(mwindow->session->drag_edits, - track, track_position, !insertion); + track, track_position, insertion); } result = 1; @@ -520,13 +521,14 @@ int TrackCanvas::drag_stop(int *redraw) double drop_position = new_pos; int ret = test_track_group(drag_group, drop_track, new_pos); if( !ret && new_pos != drop_position ) { + drop_position = new_pos; ret = test_track_group(drag_group, drop_track, new_pos); } - if( ret ) - mwindow->move_group(drag_group, drop_track, new_pos, 1); + if( ret >= 0 ) + mwindow->move_group(drag_group, drop_track, drop_position, + ret > 0 ? !shift_down() : shift_down()); drag_group->remove_user(); mwindow->session->drag_group = 0; - mwindow->edl->tracks->clear_selected_edits(); } } result = 1; @@ -544,7 +546,7 @@ int TrackCanvas::drag_start_event() int rerender = 0; int new_cursor, update_cursor; - if( mwindow->session->current_operation == DRAG_BUTTON_DOWN ) + if( mwindow->session->current_operation == GROUP_TOGGLE ) mwindow->session->current_operation = NO_OPERATION; else if( mwindow->session->current_operation != NO_OPERATION ) return 0; @@ -716,19 +718,16 @@ void TrackCanvas::draw(int mode, int hide_cursor) void TrackCanvas::update_cursor(int flush) { - switch(mwindow->edl->session->editing_mode) - { - case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break; - case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break; - } + if( arrow_mode() ) + set_cursor(ARROW_CURSOR, 0, flush); + else if( ibeam_mode() ) + set_cursor(IBEAM_CURSOR, 0, flush); } void TrackCanvas::test_timer() { - if(resource_timer->get_difference() > 1000 && - !hourglass_enabled) - { + if( resource_timer->get_difference() > 1000 && !hourglass_enabled ) { start_hourglass(); hourglass_enabled = 1; } @@ -781,12 +780,15 @@ void TrackCanvas::draw_resources(int mode, gui->resource_pixmaps.remove_all_objects(); if(debug) PRINT_TRACE + if(mode != IGNORE_THREAD) + gui->resource_thread->reset(pane->number, indexes_only); // Search every edit for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) { + if( current->is_hidden() ) continue; if(debug) PRINT_TRACE for(Edit *edit = current->edits->first; edit; edit = edit->next) { @@ -882,6 +884,14 @@ void TrackCanvas::draw_resources(int mode, } } + int64_t track_x, track_y, track_w, track_h; + track_dimensions(current, + track_x, track_y, track_w, track_h); + set_color((~get_resources()->get_bg_color()) & 0xffffff); + set_opaque(); + int x1 = track_x, x2 = x1+track_w; + int y1 = track_y+track_h-1; + draw_line(x1,y1, x2,y1, background_pixmap); } @@ -1005,8 +1015,8 @@ void TrackCanvas::get_pixmap_size(Edit *edit, // } // } - pixmap_h = mwindow->edl->local_session->zoom_track; Track *track = edit->edits->track; + pixmap_h = track->data_h; if( track->show_titles() ) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h(); //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w); @@ -1033,7 +1043,7 @@ void TrackCanvas::edit_dimensions(Edit *edit, if( edit->track->show_titles() ) edit_h += mwindow->theme->get_image("title_bg_data")->get_h(); if( edit->track->show_assets() ) - edit_h += resource_h(); + edit_h += edit->track->data_h; h = edit_h; } @@ -1141,7 +1151,8 @@ void TrackCanvas::draw_paste_destination() for(Track *dest = mwindow->session->track_highlighted; dest; dest = dest->next) { - if(dest->record) { + if( dest->is_hidden() ) continue; + if(dest->is_armed()) { // Get source width in pixels w = -1; // Use start of highlighted edit @@ -1289,16 +1300,12 @@ void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int6 if( plugin->track->show_titles() ) y += mwindow->theme->get_image("title_bg_data")->get_h(); if( plugin->track->show_assets() ) - y += resource_h(); + y += plugin->track->data_h; y += plugin->plugin_set->get_number() * mwindow->theme->get_image("plugin_bg_data")->get_h(); h = mwindow->theme->get_image("plugin_bg_data")->get_h(); } -int TrackCanvas::resource_h() -{ - return mwindow->edl->local_session->zoom_track; -} void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h) { @@ -1309,29 +1316,22 @@ void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h) if (x + w <= 0) { - draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE); + draw_triangle_left(0, y + h /6, + h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE); return; } else if (x >= get_w()) { - draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE); + draw_triangle_right(get_w() - h * 2/3, y + h /6, + h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE); return; } // Fix bug in heroines & cvs version as of 22.8.2005: // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening if (w >= 0 && w < 3) {x -= w /2; w = 3;}; - if(x < -10) - { - w += x - -10; - x = -10; - } - - if(y < -10) - { - h += y - -10; - y = -10; - } + if(x < -10) { w += x - -10; x = -10; } + if(y < -10) { h += y - -10; y = -10; } w = MIN(w, get_w() + 20); h = MIN(h, get_h() + 20); @@ -1387,16 +1387,8 @@ void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h) // Fix bug in heroines & cvs version as of 22.8.2005: // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening if (w >= 0 && w < 3) {x -= w /2; w = 3;}; - if(x < -10) - { - w += x - -10; - x = -10; - } - if(y < -10) - { - h += y - -10; - y = -10; - } + if(x < -10) { w += x - -10; x = -10; } + if(y < -10) { h += y - -10; y = -10; } w = MIN(w, get_w() + 20); h = MIN(h, get_h() + 20); set_color(mwindow->preferences->highlight_inverse); @@ -1437,15 +1429,15 @@ void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t void TrackCanvas::get_transition_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h) { - int transition_w = 30, transition_h = 30; + int transition_w = xS(30), transition_h = yS(30); int has_titles = edit->track->show_titles(); int has_assets = edit->track->show_assets(); double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h(); - double asset_h = resource_h(); - double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0; + int data_h = edit->track->data_h; + double ys = has_assets ? data_h : has_titles ? title_bg_h : 0; double dy = has_titles ? - ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) : - ( has_assets ? asset_h/2 : 0) ; + ( has_assets ? title_bg_h + data_h/2 : title_bg_h/2 ) : + ( has_assets ? data_h/2 : 0) ; double title_h = mwindow->theme->title_h; if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; } y += dy; @@ -1591,15 +1583,17 @@ void TrackCanvas::draw_highlighting() double drop_position = new_pos; int color = GREEN; int ret = test_track_group(drag_group, track, new_pos); - if( !ret && new_pos != drop_position ) { - double pos = new_pos; - pos += mwindow->session->drag_position - cur_pos; - cx = mwindow->edl->get_position_cursorx(pos, pane->number); - ret = test_track_group(drag_group, track, new_pos); - color = ret ? YELLOW : RED; + if( ret < 0 ) + color = ORANGE; + else if( !ret ) { + if( new_pos != drop_position ) { + double pos = new_pos; + pos += mwindow->session->drag_position - cur_pos; + cx = mwindow->edl->get_position_cursorx(pos, pane->number); + ret = test_track_group(drag_group, track, new_pos); + } + color = ret > 0 ? YELLOW : shift_down() ? RED : BLUE; } - else if( !ret ) - color = RED; track_dimensions(mwindow->session->track_highlighted, x, y, w, h); int dx = cx - mwindow->session->drag_origin_x; int dy = y - mwindow->session->drag_origin_y; @@ -1664,6 +1658,9 @@ void TrackCanvas::draw_highlighting() } break; + case DRAG_SPEED: + draw_speed_highlight(); + break; } if( draw_box ) @@ -1672,11 +1669,59 @@ 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) +{ + int x1 = bmax(x, 0), x2 = bmin(x+w, get_w()); + if( x1 > x2 ) return; + int y1 = bmax(y, 0), y2 = bmin(y+h, get_h()); + if( y1 > y2 ) return; + if( x >= 0 && x < get_w() ) draw_line(x,y1, x,y2); + if( x+w >= 0 && x+w < get_w() ) draw_line(x+w,y1, x+w,y2); + if( y >= 0 && y < get_h() ) draw_line(x1,y, x2,y); + if( y+h >= 0 && y+h < get_h() ) draw_line(x1,y+h, x2,y+h); +} + void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1) { + int dropping = 0; for( Track *track=edl->tracks->first; track; track=track->next ) { + if( track->is_hidden() ) continue; + if( !track->is_armed() && color1 < 0 ) { + if( dropping ) + dy -= track->vertical_span(mwindow->theme); + continue; + } for( Edit *edit=track->edits->first; edit; edit=edit->next ) { if( !edit->is_selected ) continue; + dropping = 1; int64_t x, y, w, h; edit_dimensions(edit, x, y, w, h); x += dx; y += dy; @@ -1685,12 +1730,12 @@ void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int set_opaque(); int inner = color1 < 0 ? color0 : !edit->group_id ? color0 : mwindow->get_group_color(edit->group_id); - set_color(inner); - draw_rectangle(x, y, w, h); int outer = color1 < 0 ? color0 : !edit->group_id ? color1 : inner; - set_color(outer); - draw_rectangle(x-1, y-1, w+2, h+2); - draw_rectangle(x-2, y-2, w+1, h+1); + set_color(track->is_armed() ? inner : outer); + draw_selected(x, y, w, h); + set_color(track->is_armed() ? outer : inner); + draw_selected(x-1, y-1, w+2, h+2); + draw_selected(x-2, y-2, w+1, h+1); } } } @@ -1714,6 +1759,7 @@ void TrackCanvas::draw_plugins() track; track = track->next) { + if( track->is_hidden() ) continue; if(track->expand_view) { for(int i = 0; i < track->plugin_set.total; i++) @@ -1780,7 +1826,7 @@ void TrackCanvas::draw_plugins() toggle_x = MIN(get_w() - right_margin, toggle_x); // On toggle - toggle_x -= PluginOn::calculate_w(mwindow) + 10; + toggle_x -= PluginOn::calculate_w(mwindow) + xS(10); if(toggle_x > min_x) { if(current_on >= plugin_on_toggles.total) @@ -1800,7 +1846,7 @@ void TrackCanvas::draw_plugins() if(plugin->plugin_type == PLUGIN_STANDALONE) { // Show - toggle_x -= PluginShow::calculate_w(mwindow) + 10; + toggle_x -= PluginShow::calculate_w(mwindow) + xS(10); if(toggle_x > min_x) { if(current_show >= plugin_show_toggles.total) @@ -1815,7 +1861,7 @@ void TrackCanvas::draw_plugins() } current_show++; } - toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10; + toggle_x -= PluginPresetEdit::calculate_w(mwindow) + xS(10); if(toggle_x > min_x) { if(current_preset >= preset_edit_buttons.total) @@ -1875,19 +1921,24 @@ void TrackCanvas::refresh_plugintoggles() void TrackCanvas::draw_hard_edges() { + if( !mwindow->edl->session->auto_conf->hard_edges ) + return; int64_t x, y, w, h; for(Track *track = mwindow->edl->tracks->first; track; track = track->next) { + if( track->is_hidden() ) continue; for(Edit *edit = track->edits->first; edit; edit = edit->next) { if( !edit->hard_left && !edit->hard_right ) continue; edit_dimensions(edit, x, y, w, h); + if( !MWindowGUI::visible(x, x + w, 0, get_w()) || + !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue; set_color(GREEN); set_opaque(); int y1 = y; if( track->show_titles() ) y1 += mwindow->theme->get_image("title_bg_data")->get_h(); if( track->show_assets() ) - y1 += resource_h(); + y1 += track->data_h; if( y1 == y ) y1 += mwindow->theme->title_h; if( edit->hard_left ) { @@ -1915,30 +1966,95 @@ void TrackCanvas::draw_inout_points() void TrackCanvas::draw_drag_handle() { - if(mwindow->session->current_operation == DRAG_EDITHANDLE2 || - mwindow->session->current_operation == DRAG_PLUGINHANDLE2) - { -//printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start); - int64_t pixel1 = Units::round(mwindow->session->drag_position * - mwindow->edl->session->sample_rate / - mwindow->edl->local_session->zoom_sample - - mwindow->edl->local_session->view_start[pane->number]); -//printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1); - set_color(!snapped ? GREEN : (snapped=0, YELLOW)); - set_inverse(); -//printf("TrackCanvas::draw_drag_handle 3\n"); - draw_line(pixel1, 0, pixel1, get_h()); - set_opaque(); -//printf("TrackCanvas::draw_drag_handle 4\n"); + if( mwindow->session->current_operation != DRAG_EDITHANDLE2 && + mwindow->session->current_operation != DRAG_PLUGINHANDLE2 && + mwindow->session->current_operation != DRAG_TRANSNHANDLE2 ) return; + int64_t pixel1 = Units::round(mwindow->session->drag_position * + mwindow->edl->session->sample_rate / + mwindow->edl->local_session->zoom_sample - + mwindow->edl->local_session->view_start[pane->number]); + set_color(!snapped ? GREEN : (snapped=0, YELLOW)); + set_inverse(); + draw_line(pixel1, 0, pixel1, get_h()); + set_opaque(); + + if( mwindow->session->current_operation != DRAG_EDITHANDLE2 ) return; + if( !mwindow->session->drag_edit ) return; + int group_id = mwindow->session->drag_edit->group_id; + if( !group_id ) return; + int64_t dx, dy, dw, dh; + edit_dimensions(mwindow->session->drag_edit, dx, dy, dw, dh); + int drag_handle = mwindow->session->drag_handle; + int64_t pixel0 = !drag_handle ? dx : dx + dw; + int delta = pixel1 - pixel0; + set_color(LTPURPLE); + set_line_width(3); + + for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) { + if( track->is_hidden() ) continue; + Edit *left = 0, *right = 0; + double start = DBL_MAX, end = DBL_MIN; + for( Edit *edit=track->edits->first; edit; edit=edit->next ) { + if( edit->group_id != group_id ) continue; + double edit_start = edit->track->from_units(edit->startproject); + if( edit_start < start ) { start = edit_start; left = edit; } + double edit_end = edit->track->from_units(edit->startproject+edit->length); + if( edit_end > end ) { end = edit_end; right = edit; } + } + Edit *edit = !drag_handle ? left : right; + if( !edit ) continue; + Indexable *idxbl = edit->asset; + if( !idxbl ) idxbl = edit->nested_edl; + int can_drag = idxbl ? 1 : 0; + if( drag_handle ) { + int64_t source_len = !idxbl ? -1 : + edit->track->data_type == TRACK_AUDIO ? + idxbl->get_audio_samples() : + edit->track->data_type == TRACK_VIDEO ? + idxbl->get_video_frames() : -1; + 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 ) + can_drag = 0; + int64_t x, y, w, h; + edit_dimensions(edit, x, y, w, h); + if( y+h < 0 || y >= get_h() ) continue; + int edge_x = !drag_handle ? x : x + w; + int edge_y = y + h/2, xs10 = xS(10), ys10 = yS(10); + if( edge_x >= 0 && edge_x < get_w() ) { + if( !can_drag ) { + draw_line(edge_x-xs10,edge_y-ys10, edge_x+xs10,edge_y+ys10); + draw_line(edge_x-xs10,edge_y+ys10, edge_x+xs10,edge_y-ys10); + } + else if( !drag_handle ) { + draw_line(edge_x+xs10,edge_y-ys10, edge_x,edge_y); + draw_line(edge_x+xs10,edge_y+ys10, edge_x,edge_y); + } + else { + draw_line(edge_x,edge_y, edge_x-xs10,edge_y-ys10); + draw_line(edge_x,edge_y, edge_x-xs10,edge_y+ys10); + } + } + edge_x += delta; + if( edge_x >= 0 && edge_x < get_w() ) { + draw_line(edge_x, y, edge_x, y+h); + } } + set_line_width(1); } void TrackCanvas::draw_transitions() { int64_t x, y, w, h; + if( !mwindow->edl->session->auto_conf->transitions ) return; for(Track *track = mwindow->edl->tracks->first; track; track = track->next) { + if( track->is_hidden() ) continue; if( !track->show_transitions() ) continue; for(Edit *edit = track->edits->first; edit; edit = edit->next) { @@ -2090,8 +2206,7 @@ int TrackCanvas::do_keyframes(int cursor_x, // track context menu to appear int result = 0; EDLSession *session = mwindow->edl->session; - - + int gang = session->gang_tracks != GANG_NONE || get_double_click() ? 1 : 0; static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] = { @@ -2099,6 +2214,7 @@ int TrackCanvas::do_keyframes(int cursor_x, pankeyframe_pixmap, modekeyframe_pixmap, maskkeyframe_pixmap, + 0, }; @@ -2106,6 +2222,7 @@ int TrackCanvas::do_keyframes(int cursor_x, for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) { + if( track->is_hidden() ) continue; Auto *auto_keyframe = 0; Automation *automation = track->automation; @@ -2155,11 +2272,10 @@ int TrackCanvas::do_keyframes(int cursor_x, auto_keyframe, grouptype); if( !result && buttonpress && i == AUTOMATION_SPEED ) - mwindow->speed_after(-1); - int current_grouptype = mwindow->edl->local_session->zoombar_showautotype; - if( result && buttonpress && grouptype != current_grouptype ) { - mwindow->edl->local_session->zoombar_showautotype = grouptype; - mwindow->gui->zoombar->update_autozoom(); + mwindow->speed_after(-1, 0); + if( result && buttonpress ) { + int color = GWindowGUI::auto_colors[i]; + mwindow->gui->zoombar->update_autozoom(grouptype, color); } break; } @@ -2198,7 +2314,7 @@ int TrackCanvas::do_keyframes(int cursor_x, if (buttonpress != 3) { if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED) - fill_ganged_autos(get_double_click(), 0, track, + fill_ganged_autos(gang, 0, track, (FloatAuto*)mwindow->session->drag_auto); mwindow->session->current_operation = pre_auto_operations[i]; update_drag_caption(); @@ -2266,7 +2382,6 @@ int TrackCanvas::do_keyframes(int cursor_x, new_cursor = UPRIGHT_ARROW_CURSOR; } - return result; } @@ -2284,7 +2399,7 @@ void TrackCanvas::draw_keyframe_reticle() mwindow->session->drag_auto->autos->autoidx : -1; if( get_buttonpress() == LEFT_BUTTON && dragging && - keyframe_hairline == HAIRLINE_DRAGGING ) { + keyframe_hairline == HAIRLINE_DRAGGING ) { draw_hairline(mwindow->session->drag_auto, RED, 1); return; } @@ -2293,6 +2408,7 @@ void TrackCanvas::draw_keyframe_reticle() keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) { int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0; for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) { + if( track->is_hidden() ) continue; Automation *automation = track->automation; for( int i=0; iedl->session->auto_conf->autos[i] ) continue; @@ -2312,11 +2428,8 @@ void TrackCanvas::draw_keyframe_reticle() } } -void TrackCanvas::draw_auto(Auto *current, - int x, - int y, - int center_pixel, - int zoom_track) +void TrackCanvas::draw_auto(Auto *current, int x, int y, + int center_pixel, int data_h) { int x1, y1, x2, y2; @@ -2325,8 +2438,8 @@ void TrackCanvas::draw_auto(Auto *current, y1 = center_pixel + y - HANDLE_W / 2; y2 = center_pixel + y + HANDLE_W / 2; - if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2; - if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2; + if( y1 < center_pixel - data_h/2 ) y1 = center_pixel - data_h/2; + if( y2 > center_pixel + data_h/2 ) y2 = center_pixel + data_h/2; draw_box(x1, y1, x2 - x1, y2 - y1); } @@ -2380,56 +2493,75 @@ 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 zoom_track, - int color) + 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 ymin = center_pixel - zoom_track / 2; - int ymax = center_pixel + zoom_track / 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); CLAMP(y2, ymin, ymax); - if(y2 - 1 > y1) - { - set_color(BLACK); - draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1); - set_color(color); - draw_box(x1, y1, x2 - x1, y2 - y1); + if( y2-1 > y1 ) { + if( current->curve_mode == FloatAuto::LINEAR ) { + draw_box(x1, y1, x2 - x1, y2 - y1); + } + else { + ArrayList polygon_x; + ArrayList polygon_y; + polygon_x.append((x1 + x2) / 2 + 1); + polygon_y.append(y1 + 1); + polygon_x.append(x2 + 1); + polygon_y.append((y1 + y2) / 2 + 1); + polygon_x.append((x1 + x2) / 2 + 1); + polygon_y.append(y2 + 1); + polygon_x.append(x1 + 1); + polygon_y.append((y1 + y2) / 2 + 1); + fill_polygon(&polygon_x, &polygon_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, zoom_track, color); - if(out_x != x) - draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, 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); } inline void TrackCanvas::draw_floatauto_ctrlpoint( - int x, int y, int cp_x, int cp_y, int center_pixel, - int zoom_track, int color) + int x, int y, int cp_x, int cp_y, int center_pixel, + int data_h, int color) // draw the tangent and a handle for given bézier ctrl point { - bool handle_visible = (abs(cp_y) <= zoom_track / 2); + bool handle_visible = (abs(cp_y) <= data_h/2); float slope = (float)(cp_y - y)/(cp_x - x); - CLAMP(cp_y, -zoom_track / 2, zoom_track / 2); + CLAMP(cp_y, -data_h/2, data_h/2); if(slope != 0) cp_x = x + quantize((cp_y - y) / slope); @@ -2471,7 +2603,7 @@ inline void TrackCanvas::draw_floatauto_ctrlpoint( int TrackCanvas::test_auto(Auto *current, - int x, int y, int center_pixel, int zoom_track, + int x, int y, int center_pixel, int data_h, int cursor_x, int cursor_y, int buttonpress) { int x1, y1, x2, y2; @@ -2481,8 +2613,8 @@ int TrackCanvas::test_auto(Auto *current, x2 = x + HANDLE_W / 2; y1 = center_pixel + y - HANDLE_H / 2; y2 = center_pixel + y + HANDLE_H / 2; - int ymin = center_pixel - zoom_track / 2; - int ymax = center_pixel + zoom_track / 2; + int ymin = center_pixel - data_h/2; + int ymax = center_pixel + data_h/2; CLAMP(y1, ymin, ymax); CLAMP(y2, ymin, ymax); @@ -2557,18 +2689,23 @@ 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 zoom_track, - 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; - int ymin = center_pixel - zoom_track / 2; - int ymax = center_pixel + zoom_track / 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); CLAMP(y2, ymin, ymax); @@ -2579,6 +2716,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; @@ -2636,13 +2776,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; @@ -2658,12 +2799,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)) { @@ -2691,32 +2833,41 @@ 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; } +static int is_linear(FloatAuto *prev, FloatAuto *next) +{ + 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 = next->get_control_in_value(); + float oval = prev->get_control_out_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(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); @@ -2728,45 +2879,53 @@ void TrackCanvas::draw_floatline(int center_pixel, int x1, int y1, int x2, int y2, int color, int autogrouptype) { + int ytop = center_pixel - yscale / 2; + int ybot = center_pixel + yscale / 2 - 1; + y1 += center_pixel; y2 += 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; + } + // Solve bezier equation for either every pixel or a certain large number of // points. // Not using slope intercept x1 = MAX(0, x1); - int prev_y = y1 + center_pixel; - + draw_pixel(x1, y1); + int prev_y = y1; // Call by reference fails for some reason here FloatAuto *previous1 = previous, *next1 = next; float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype]; float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype]; float automation_range = automation_max - automation_min; - - for(int x = x1; x < x2; x++) - { + if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN ) + automation_range = SPEED_MIN; + for( int x=x1; x x1 && */ - y >= center_pixel - yscale / 2 && - y < center_pixel + yscale / 2 - 1) - { -// printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n", -// y, -// (int)(center_pixel - yscale / 2), -// (int)(center_pixel + yscale / 2 - 1)); - -//printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y); - draw_line(x - 1, prev_y , x, y ); + if( /* x > x1 && */ y >= ytop && y < ybot ) { + int x1 = x-1, y1 = prev_y, x2 = x, y2 = y; + if( abs(y2-y1) < 2 ) + draw_pixel(x2, y2); + else + draw_bline(x1, y1, x2, y2); } prev_y = y; } } - - - int TrackCanvas::test_floatline(int center_pixel, FloatAutos *autos, double unit_start, @@ -2785,6 +2944,8 @@ int TrackCanvas::test_floatline(int center_pixel, float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype]; float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype]; float automation_range = automation_max - automation_min; + if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN ) + automation_range = SPEED_MIN; FloatAuto *previous1 = 0, *next1 = 0; X_TO_FLOATLINE(cursor_x); @@ -2823,39 +2984,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->gang ) return; + 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->gang && current->record && 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 { + 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); } + else + continue; mwindow->session->drag_auto_gang->append((Auto *)keyframe); } } @@ -2868,11 +3033,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()); } } @@ -2979,12 +3142,12 @@ void TrackCanvas::calculate_viewport(Track *track, int has_titles = track->show_titles(); int has_assets = track->show_assets(); double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h(); - double asset_h = resource_h(); double title_h = mwindow->theme->title_h; - double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0; + double data_h = track->data_h; + double ys = has_assets ? data_h : has_titles ? title_bg_h : 0; double dy = has_titles ? - ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) : - ( has_assets ? asset_h/2 : 0) ; + ( has_assets ? title_bg_h + data_h/2 : title_bg_h/2) : + ( has_assets ? data_h/2 : 0) ; if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; } yscale = ys; center_pixel = y + dy; @@ -3024,7 +3187,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) @@ -3032,9 +3195,11 @@ void TrackCanvas::calculate_auto_position(double *x, double *y, float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype]; float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype]; float automation_range = automation_max - automation_min; + if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN ) + 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; @@ -3042,7 +3207,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; } @@ -3052,7 +3217,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; } } @@ -3067,7 +3232,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; @@ -3090,7 +3254,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 ) @@ -3105,7 +3269,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 { @@ -3129,24 +3293,22 @@ 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->record ) { - result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2, - (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2, + if( !draw && track->is_armed() ) { + 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); } } // Draw or test joining line - if( !draw && !result && track->record /* && buttonpress != 3 */ ) { + if( !draw && !result && track->is_armed() /* && buttonpress != 3 */ ) { result = test_floatline(center_pixel, (FloatAutos*)autos, unit_start, zoom_units, yscale, // Exclude auto coverage from the end of the line. The auto overlaps @@ -3161,15 +3323,16 @@ 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 ); if( ax < get_w() && !result ) { ax2 = get_w(); ay2 = ay; - if(!draw && track->record /* && buttonpress != 3 */ ) { + if(!draw && track->is_armed() /* && buttonpress != 3 */ ) { result = test_floatline(center_pixel, (FloatAutos*)autos, unit_start, zoom_units, yscale, (int)ax, (int)ax2, cursor_x, cursor_y, @@ -3274,7 +3437,7 @@ int TrackCanvas::do_int_autos(Track *track, { if(!draw) { - if(track->record) + if(track->is_armed()) { result = test_auto(current, (int)ax2, @@ -3303,7 +3466,7 @@ int TrackCanvas::do_int_autos(Track *track, { if(!result) { - if(track->record /* && buttonpress != 3 */) + if(track->is_armed() /* && buttonpress != 3 */) { result = test_toggleline(autos, center_pixel, @@ -3334,7 +3497,7 @@ int TrackCanvas::do_int_autos(Track *track, ay2 = ay; if(!draw) { - if(track->record /* && buttonpress != 3 */) + if(track->is_armed() /* && buttonpress != 3 */) { result = test_toggleline(autos, center_pixel, @@ -3485,7 +3648,7 @@ int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y, if( track->show_titles() ) center_pixel += mwindow->theme->get_image("title_bg_data")->get_h(); if( track->show_assets() ) - center_pixel += resource_h(); + center_pixel += track->data_h; center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h(); for(Plugin *plugin = (Plugin*)plugin_set->first; @@ -3571,27 +3734,34 @@ int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show) calculate_viewport(track, view_start, unit_start, view_end, unit_end, yscale, center_pixel, zoom_sample, zoom_units); + if( auto_keyframe->position < unit_start || + auto_keyframe->position >= unit_end ) + 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); draw_line(ax, 0, ax, get_h()); + char text[BCSTRLEN]; 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 { + else if( auto_keyframe->is_intauto() ) { IntAuto *int_auto = (IntAuto *)auto_keyframe; sprintf(text, "%d", int_auto->value); } + else + show = 0; + } + if( show ) { int font = MEDIUMFONT; - int tw = get_text_width(font, text) + TOOLTIP_MARGIN * 2; - int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2; + int tw = get_text_width(font, text) + xS(TOOLTIP_MARGIN) * 2; + int th = get_text_height(font, text) + yS(TOOLTIP_MARGIN) * 2; set_color(get_resources()->tooltip_bg_color); ax += HANDLE_W/2; ay += center_pixel + HANDLE_W/2; @@ -3599,8 +3769,8 @@ int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show) set_color(BLACK); draw_rectangle(ax, ay, tw, th); set_font(font); - ax += TOOLTIP_MARGIN; - ay += TOOLTIP_MARGIN + get_text_ascent(font); + ax += xS(TOOLTIP_MARGIN); + ay += yS(TOOLTIP_MARGIN) + get_text_ascent(font); draw_text(ax, ay, text); } return 0; @@ -3611,13 +3781,7 @@ void TrackCanvas::draw_overlays() int new_cursor, update_cursor, rerender; // Move background pixmap to foreground pixmap - draw_pixmap(background_pixmap, - 0, - 0, - get_w(), - get_h(), - 0, - 0); + draw_pixmap(background_pixmap, 0, 0, get_w(), get_h(), 0, 0); // In/Out points draw_inout_points(); @@ -3684,14 +3848,8 @@ void TrackCanvas::update_drag_handle() double new_position; int cursor_x = get_cursor_x(); - new_position = - (double)(cursor_x + - mwindow->edl->local_session->view_start[pane->number]) * - mwindow->edl->local_session->zoom_sample / - mwindow->edl->session->sample_rate; - - new_position = - mwindow->edl->align_to_frame(new_position, 0); + new_position = mwindow->edl->get_cursor_position(cursor_x, pane->number); + new_position = mwindow->edl->align_to_frame(new_position, 0); if( ctrl_down() && alt_down() ) { #define snapper(v) do { \ @@ -3734,21 +3892,37 @@ void TrackCanvas::update_drag_handle() edl->create_objects(); edl->copy_all(mwindow->edl); MainSession *session = mwindow->session; - int edit_mode = mwindow->edl->session->edit_handle_mode[session->drag_button]; + int handle_mode = mwindow->edl->session->edit_handle_mode[session->drag_button]; edl->modify_edithandles(session->drag_start, - session->drag_position, - session->drag_handle, - edit_mode, + session->drag_position, session->drag_handle, handle_mode, edl->session->labels_follow_edits, edl->session->plugins_follow_edits, - edl->session->autos_follow_edits); - double position = edit_mode != MOVE_NO_EDITS && - ( session->drag_handle || edit_mode == MOVE_ONE_EDIT ) ? + edl->session->autos_follow_edits, + !session->drag_edit ? 0 : session->drag_edit->group_id); + + double position = -1; + int show_edge = !session->drag_handle ? 1 : 2; + switch( handle_mode ) { + case MOVE_RIPPLE: + case MOVE_EDGE: + position = session->drag_handle ? session->drag_position : session->drag_start; + show_edge = 3 - show_edge; + break; + case MOVE_ROLL: + case MOVE_SLIDE: + position = session->drag_position; + break; + case MOVE_SLIP: + position = session->drag_start; + show_edge = 3 - show_edge; + break; + } + + if( position < 0 ) position = 0; Track *track = session->drag_handle_track(); int64_t pos = track->to_units(position, 0); - render_handle_frame(edl, pos, shift_down() ? 0 : - session->drag_handle ? 1 : 2); + render_handle_frame(edl, pos, shift_down() ? 0 : show_edge); edl->remove_user(); } } @@ -3772,26 +3946,26 @@ int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode) CICache *video_cache = new CICache(preferences); render_engine->set_vcache(video_cache); render_engine->arm_command(&command); - int64_t left = pos-1; - if( left < 0 ) left = 0; VRender *vrender = render_engine->vrender; result = vrender && !vrender->process_buffer(&vlt, left, 0) && !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1; delete render_engine; - delete video_cache; + video_cache->remove_user(); mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0"); Canvas *canvas = mwindow->cwindow->gui->canvas; - canvas->lock_canvas("TrackCanvas::render_handle_frame 1"); - int w = canvas->w, h = canvas->h, w2 = w/2, h2 = h/2; - int lx = 0, ly = h2/2, rx = w2, ry = h2/2; + float ox1, oy1, ox2, oy2, cx1, cy1, cx2, cy2; + canvas->get_transfers(edl, ox1, oy1, ox2, oy2, cx1, cy1, cx2, cy2); + float cw = canvas->w/2, ch = canvas->h/2; + float cdx = (cx2 - cx1)/2, cdy = (cy2 - cy1)/2; + int cx = cx1/2, cy = cy1/2 + ch/2; + int ow = ox2 - ox2, oh = oy2 - oy1; BC_WindowBase *window = canvas->get_canvas(); window->set_color(BLACK); window->clear_box(0,0, window->get_w(),window->get_h()); - window->draw_vframe(&vlt, lx,ly, w2,h2, 0,0,vlt.get_w(),vlt.get_h()); - window->draw_vframe(&vrt, rx,ry, w2,h2, 0,0,vrt.get_w(),vrt.get_h()); + window->draw_vframe(&vlt, cx,cy, cdx,cdy, ox1,oy1, ow,oh); cx += cw; + window->draw_vframe(&vrt, cx,cy, cdx,cdy, ox1,oy1, ow,oh); window->flash(1); - canvas->unlock_canvas(); mwindow->cwindow->gui->unlock_window(); break; } case 1: @@ -3799,11 +3973,11 @@ int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode) Track *track = mwindow->session->drag_handle_track(); double position = track->from_units(mode == 1 ? left : pos); if( position < 0 ) position = 0; - edl->local_session->set_selectionstart(position); - edl->local_session->set_selectionend(position); PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine; if( playback_engine->is_playing_back ) playback_engine->stop_playback(1); + edl->local_session->set_selectionstart(position); + edl->local_session->set_selectionend(position); mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0); break; } } @@ -3831,7 +4005,7 @@ int TrackCanvas::get_drag_values(float *percentage, *percentage = 0; *position = 0; - if(!current->autos->track->record) return 1; + if(!current->autos->track->is_armed()) return 1; double view_start; double unit_start; double view_end; @@ -3867,7 +4041,7 @@ int TrackCanvas::get_drag_values(float *percentage, #define UPDATE_DRAG_HEAD(do_clamp) \ int result = 0, center_pixel; \ - if(!current->autos->track->record) return 0; \ + if(!current->autos->track->is_armed()) return 0; \ double view_start, unit_start, view_end, unit_end; \ double yscale, zoom_sample, zoom_units; \ \ @@ -3898,7 +4072,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; } @@ -3908,28 +4083,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, distance2; - + 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(); } @@ -3947,7 +4121,8 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y) float change = value - old_value; current->adjust_to_new_coordinates(position, value); update_ganged_autos(change, current->autos->track, current); - show_message(current, 1,", %.2f", current->get_value()); + int color = GWindowGUI::auto_colors[current->autos->autoidx]; + show_message(current, color, ", %.2f", current->get_value()); } break; @@ -3966,7 +4141,8 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y) value * levered_position(position - current->position, current->get_control_in_position())); update_ganged_autos(0, current->autos->track, current); - show_message(current, 1,", %.2f", current->get_control_in_value()); + int color = GWindowGUI::auto_colors[current->autos->autoidx]; + show_message(current, color, ", %.2f", current->get_control_in_value()); } break; } @@ -3980,7 +4156,8 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y) value * levered_position(position - current->position, current->get_control_out_position())); update_ganged_autos(0, current->autos->track, current); - show_message(current, 1,", %.2f", current->get_control_out_value()); + int color = GWindowGUI::auto_colors[current->autos->autoidx]; + show_message(current, color, ", %.2f", current->get_control_out_value()); } break; } } @@ -4000,7 +4177,7 @@ int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y) result = 1; current->value = value; current->position = position; - show_message(current, 0,", %d", current->value); + show_message(current, -1, ", %d", current->value); } return result; @@ -4017,7 +4194,7 @@ int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y) { result = 1; current->position = position; - show_message(current, 0,""); + show_message(current, -1, ""); double position_f = current->autos->track->from_units(current->position); double center_f = (mwindow->edl->local_session->get_selectionstart(1) + @@ -4081,7 +4258,7 @@ int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y) mwindow->session->track_highlighted = track; result = 1; current->position = position; - show_message(current, 0,""); + show_message(current, -1, ""); double position_f = current->autos->track->from_units(current->position); double center_f = (mwindow->edl->local_session->get_selectionstart(1) + @@ -4127,58 +4304,59 @@ int TrackCanvas::cursor_update(int in_motion) int update_scroll = 0; int update_overlay = 0; int update_cursor = 0; - int new_cursor = 0; int rerender = 0; double position = 0.; //printf("TrackCanvas::cursor_update %d\n", __LINE__); // Default cursor - switch(mwindow->edl->session->editing_mode) - { - case EDITING_ARROW: new_cursor = ARROW_CURSOR; break; - case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break; - } + int new_cursor = + arrow_mode() ? ARROW_CURSOR : + ibeam_mode() ? IBEAM_CURSOR : 0; switch(mwindow->session->current_operation) { case DRAG_EDITHANDLE1: // Outside threshold. Upgrade status - if(active) - { - if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) - { - mwindow->session->current_operation = DRAG_EDITHANDLE2; - update_overlay = 1; - } + if( !active ) break; + if( labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W ) { + mwindow->session->current_operation = DRAG_EDITHANDLE2; + update_overlay = 1; } break; - case DRAG_EDITHANDLE2: - if(active) - { - update_drag_handle(); - update_overlay = 1; - } + if( !active ) break; + update_drag_handle(); + update_overlay = 1; break; case DRAG_PLUGINHANDLE1: - if(active) - { - if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) - { - mwindow->session->current_operation = DRAG_PLUGINHANDLE2; - update_overlay = 1; - } + if( !active ) break; + if( labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W ) { + mwindow->session->current_operation = DRAG_PLUGINHANDLE2; + update_overlay = 1; } break; - case DRAG_PLUGINHANDLE2: - if(active) - { - update_drag_handle(); + if( !active ) break; + update_drag_handle(); + update_overlay = 1; + break; + + case DRAG_TRANSNHANDLE1: + if( !active ) break; + if( labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W ) { + mwindow->session->current_operation = DRAG_TRANSNHANDLE2; update_overlay = 1; } break; + case DRAG_TRANSNHANDLE2: { + if( !active ) break; + position = mwindow->edl->get_cursor_position(get_cursor_x(), pane->number); + position = mwindow->edl->align_to_frame(position, 1); + drag_transition_handle(position); + rerender = 1; + update_overlay = 1; + break; } // Rubber band curves case DRAG_FADE: @@ -4194,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: @@ -4301,6 +4479,8 @@ int TrackCanvas::cursor_update(int in_motion) 0, new_cursor, update_cursor)) break; if(do_keyframes(get_cursor_x(), get_cursor_y(), 0, 0, new_cursor, update_cursor, rerender)) break; + if(do_transition_handles(get_cursor_x(), get_cursor_y(), + 0, rerender, update_overlay, new_cursor, update_cursor)) break; if(do_edit_handles(get_cursor_x(), get_cursor_y(), 0, rerender, update_overlay, new_cursor, update_cursor)) break; // Plugin boundaries @@ -4500,9 +4680,23 @@ int TrackCanvas::button_release_event() result = 1; break; + case DRAG_TRANSNHANDLE2: + mwindow->session->current_operation = NO_OPERATION; + drag_scroll = 0; + result = 1; + + end_transnhandle_selection(); + break; + + case DRAG_TRANSNHANDLE1: + mwindow->session->current_operation = NO_OPERATION; + drag_scroll = 0; + result = 1; + break; + 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(); @@ -4554,7 +4748,7 @@ int TrackCanvas::button_release_event() result = 1; break; } - case DRAG_BUTTON_DOWN: { + case GROUP_TOGGLE: { Edit *edit = mwindow->session->drag_edit; if( edit ) { if( shift_down() && edit->is_selected ) { @@ -4569,10 +4763,9 @@ int TrackCanvas::button_release_event() redraw = 0; } else { - if( edit->group_id ) - mwindow->edl->tracks->set_group_selected(edit->group_id, -1); - else - edit->is_selected = !edit->is_selected ? 1 : 0; + if( mwindow->preferences->ctrl_toggle && !ctrl_down() ) + mwindow->edl->tracks->clear_selected_edits(); + edit->set_selected(-1); } } mwindow->session->current_operation = NO_OPERATION; @@ -4596,6 +4789,9 @@ int TrackCanvas::button_release_event() } } + if( mwindow->edl->local_session->zoombar_showautocolor >= 0 ) + mwindow->gui->zoombar->update_autozoom(-1); + if (result) cursor_update(0); @@ -4617,6 +4813,7 @@ int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press, int result = 0; for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) { + if( track->is_hidden() ) continue; for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) { int64_t edit_x, edit_y, edit_w, edit_h; edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h); @@ -4651,6 +4848,25 @@ int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press, } } + if( result > 0 ) { + int group_id = edit_result->group_id; + if( group_id > 0 ) { + Track *track = edit_result->track; + Edit *left = 0, *right = 0; + double start = DBL_MAX, end = DBL_MIN; + for( Edit *edit=track->edits->first; edit; edit=edit->next ) { + if( edit->group_id != group_id ) continue; + double edit_start = edit->track->from_units(edit->startproject); + if( edit_start < start ) { start = edit_start; left = edit; } + double edit_end = edit->track->from_units(edit->startproject+edit->length); + if( edit_end > end ) { end = edit_end; right = edit; } + } + Edit *edit = !handle_result ? left : right; + if( edit != edit_result ) + result = 0; + } + } + update_cursor = 1; if( result > 0 ) { double position = 0; @@ -4678,7 +4894,7 @@ int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press, update_overlay = 1; } } - else if( result < 0 ) { + else if( result < 0 && !edit_result->silence() ) { mwindow->undo->update_undo_before(); if( !shift_down() ) { if( handle_result == 0 ) @@ -4694,6 +4910,7 @@ int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press, if( handle_result == 1 ) edit_edge += edit_result->length; double edge_position = edit_result->track->from_units(edit_edge); for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) { + if( track->is_hidden() ) continue; int64_t track_position = track->to_units(edge_position, 1); Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0); if( left_edit ) { @@ -4740,6 +4957,7 @@ int TrackCanvas::do_plugin_handles(int cursor_x, for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) { + if( track->is_hidden() ) continue; for(int i = 0; i < track->plugin_set.total && !result; i++) { PluginSet *plugin_set = track->plugin_set.values[i]; for(Plugin *plugin = (Plugin*)plugin_set->first; @@ -4798,6 +5016,95 @@ int TrackCanvas::do_plugin_handles(int cursor_x, return result; } +int TrackCanvas::do_transition_handles(int cursor_x, int cursor_y, int button_press, + int &rerender, int &update_overlay, int &new_cursor, int &update_cursor) +{ + Transition *trans_result = 0; + int result = 0; + + Track *track = mwindow->edl->tracks->first; + for( ; track && !result; track=track->next) { + if( track->is_hidden() ) continue; + Edit *edit = track->edits->first; + for( ; edit && !result; edit=edit->next ) { + Transition *trans = edit->transition; + if( !trans ) continue; + int64_t x, y, w, h; + edit_dimensions(edit, x, y, w, h); + int strip_x = x, edit_y = y; + get_transition_coords(edit, x, y, w, h); + VFrame *strip = mwindow->theme->get_image("plugin_bg_data"); + int strip_y = y - strip->get_h(); + if( track->show_assets() && track->show_titles() ) + edit_y += mwindow->theme->get_image("title_bg_data")->get_h(); + if( strip_y < edit_y ) strip_y = edit_y; + int strip_w = Units::round(edit->track->from_units(edit->transition->length) * + mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample); + int x1 = strip_x + strip_w - HANDLE_W/2, x2 = x1 + HANDLE_W; + int y1 = strip_y + strip->get_h()/2 - HANDLE_H/2, y2 = y1 + HANDLE_W; + if( cursor_x >= x1 && cursor_x < x2 && + cursor_y >= y1 && cursor_y < y2 ) { + trans_result = trans; + result = 1; + } + } + } + + if( result ) { + if( button_press ) { + mwindow->session->drag_transition = trans_result; + mwindow->session->drag_handle = 1; + mwindow->session->drag_button = get_buttonpress() - 1; + int64_t trans_end = trans_result->edit->startproject + trans_result->length; + double position = trans_result->edit->track->from_units(trans_end); + mwindow->session->drag_position = position; + mwindow->session->drag_start = position; + mwindow->session->current_operation = DRAG_TRANSNHANDLE1; + mwindow->session->drag_origin_x = get_cursor_x(); + mwindow->session->drag_origin_y = get_cursor_y(); + update_cursor = 1; + } + new_cursor = RIGHT_CURSOR; + update_overlay = 1; + } + + return result; +} + +int TrackCanvas::drag_transition_handle(double position) +{ + Transition *transition = mwindow->session->drag_transition; + if( !transition ) return 1; + mwindow->session->drag_position = position; + mwindow->edl->local_session->set_selectionstart(position); + mwindow->edl->local_session->set_selectionend(position); + char string[BCSTRLEN]; + int64_t length = transition->length; + Track *track = transition->edit->track; + int64_t start_pos = track->to_units(mwindow->session->drag_start, 0); + int64_t end_pos = track->to_units(mwindow->session->drag_position, 0); + length += end_pos - start_pos; + if( length < 0 ) length = 0; + double time = track->from_units(length); + Units::totext(string, time, + mwindow->edl->session->time_format, + mwindow->edl->session->sample_rate, + mwindow->edl->session->frame_rate, + mwindow->edl->session->frames_per_foot); + mwindow->gui->show_message(string); + if( mwindow->gui->transition_menu->length_thread->running() ) { + TransitionLengthDialog *dialog = (TransitionLengthDialog *) + mwindow->gui->transition_menu->length_thread->get_gui(); + if( dialog ) { + dialog->lock_window("TrackCanvas::drag_transition_handle"); + dialog->update_text(time); + dialog->thread->new_length = time; + dialog->unlock_window(); + } + } + return 0; +} + int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press) { @@ -4827,41 +5134,45 @@ int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press) return result; } +int TrackCanvas::arrow_mode() +{ + return mwindow->edl->session->editing_mode == EDITING_ARROW ? 1 : 0; +} +int TrackCanvas::ibeam_mode() +{ + return mwindow->edl->session->editing_mode == EDITING_IBEAM ? 1 : 0; +} + int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start, int &redraw, int &rerender, int &new_cursor, int &update_cursor) { int result = 0; for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) { + if( track->is_hidden() ) continue; for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) { int64_t edit_x, edit_y, edit_w, edit_h; edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h); // Cursor inside a track // Cursor inside an edit - if(cursor_x >= edit_x && cursor_x < edit_x + edit_w && - cursor_y >= edit_y && cursor_y < edit_y + edit_h) { + if( cursor_x >= edit_x && cursor_x < edit_x + edit_w && + cursor_y >= edit_y && cursor_y < edit_y + edit_h ) { if( button_press && get_buttonpress() == LEFT_BUTTON ) { - if( mwindow->edl->session->editing_mode == EDITING_IBEAM && - get_double_click() ) { -// Select duration of edit + if( get_double_click() ) { + mwindow->edl->tracks->clear_selected_edits(); + edit->select_affected_edits(1, -1); double start = edit->track->from_units(edit->startproject); start = mwindow->edl->align_to_frame(start, 0); mwindow->edl->local_session->set_selectionstart(start); double end = edit->track->from_units(edit->startproject+edit->length); end = mwindow->edl->align_to_frame(end, 0); mwindow->edl->local_session->set_selectionend(end); - mwindow->edl->tracks->clear_selected_edits(); - mwindow->edl->tracks->select_affected_edits( - edit->track->from_units(edit->startproject), - edit->track, 1); - result = 1; + result = 1; // Select edit duration or select_region } - else if( mwindow->edl->session->editing_mode == EDITING_ARROW || - (mwindow->edl->session->editing_mode == EDITING_IBEAM && - ctrl_down()) ) { + else if( arrow_mode() || (ibeam_mode() && ctrl_down()) ) { mwindow->session->drag_edit = edit; - mwindow->session->current_operation = DRAG_BUTTON_DOWN; + mwindow->session->current_operation = GROUP_TOGGLE; result = 1; } if( result ) { @@ -4869,41 +5180,57 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag update_cursor = -1; } } - else if( drag_start && track->record ) { - if( mwindow->edl->session->editing_mode == EDITING_ARROW || - ( mwindow->edl->session->editing_mode == EDITING_IBEAM && - ctrl_down() ) ) { -// Need to create drag window - mwindow->session->drag_edit = edit; - mwindow->session->drag_origin_x = cursor_x; - mwindow->session->drag_origin_y = cursor_y; - // Where the drag started, so we know relative position inside the edit later - mwindow->session->drag_position = - mwindow->edl->get_cursor_position(cursor_x, pane->number); + else if( drag_start && track->is_armed() ) { + mwindow->session->drag_edit = edit; + mwindow->session->drag_origin_x = cursor_x; + mwindow->session->drag_origin_y = cursor_y; +// Where the drag started, so we know relative position inside the edit later + mwindow->session->drag_position = + mwindow->edl->get_cursor_position(cursor_x, pane->number); + drag_start = 0; // if unselected "fast" drag + if( !edit->silence() && !edit->is_selected ) { + mwindow->edl->tracks->clear_selected_edits(); + if( ibeam_mode() ) { + double start = edit->track->from_units(edit->startproject); + mwindow->edl->local_session->set_selectionstart(start); + mwindow->edl->local_session->set_selectionend(start); + edit->set_selected(1); + } + else + edit->select_affected_edits(1, -1); + drag_start = 1; + } // Construct list of all affected edits - if( ctrl_down() ) { + if( drag_start || ibeam_mode() ) { + mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits); + if( mwindow->session->drag_edits->size() > 0 ) { mwindow->session->current_operation = DRAG_EDIT; - mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits); +// Need to create drag window int cx, cy; get_abs_cursor(cx, cy); gui->drag_popup = new BC_DragWindow(gui, mwindow->theme->get_image("clip_icon"), cx, cy); - + result = 1; } - else if( edit->is_selected ) { - if( mwindow->session->drag_group ) - mwindow->session->drag_group->remove_user(); - double start_position = 0; - mwindow->session->drag_group = - mwindow->selected_edits_to_clip(0, &start_position, - &mwindow->session->drag_group_first_track); - if( mwindow->session->drag_group ) { - mwindow->session->current_operation = DRAG_GROUP; - mwindow->session->drag_group_position = start_position; - mwindow->session->drag_group_edit = edit; - mwindow->session->drag_origin_y = edit_y; - } + else { + rerender = start_selection(mwindow->session->drag_position); + mwindow->session->current_operation = SELECT_REGION; + update_cursor = 1; + } + } + else if( edit->is_selected && arrow_mode() ) { + if( mwindow->session->drag_group ) + mwindow->session->drag_group->remove_user(); + double start_position = 0; + mwindow->session->drag_group = + mwindow->edl->selected_edits_to_clip(0, &start_position, + &mwindow->session->drag_group_first_track); + if( mwindow->session->drag_group ) { + mwindow->session->current_operation = DRAG_GROUP; + mwindow->session->drag_group_position = start_position; + mwindow->session->drag_group_edit = edit; + mwindow->session->drag_origin_y = edit_y; + result = 1; } - result = 1; } } } @@ -4912,46 +5239,63 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag return result; } - +// returns -1=doesnt fit, 1=fits, 0=fits but overwrites int TrackCanvas::test_track_group(EDL *group, Track *first_track, double &pos) { + int intersects = 0; Track *src = group->tracks->first; for( Track *track=first_track; track && src; track=track->next ) { - if( !track->record ) continue; - if( src->data_type != track->data_type ) return 0; + if( !track->is_armed() ) return -1; + if( src->data_type != track->data_type ) return -1; for( Edit *src_edit=src->edits->first; src_edit; src_edit=src_edit->next ) { if( src_edit->silence() ) continue; - if( edit_intersects(track, src_edit, pos) ) return 0; + if( !intersects && edit_intersects(track, src_edit, pos) ) + intersects = 1; } src = src->next; } - return !src ? 1 : 0; + return src ? -1 : !intersects ? 1 : 0; } int TrackCanvas::edit_intersects(Track *track, Edit *src_edit, double &pos) { if( pos < 0 ) { pos = 0; return 1; } + int pane_no = pane->number; + int cur_pix = track->edl->get_position_cursorx(pos, pane_no); int64_t src_start = src_edit->startproject; int64_t src_end = src_start + src_edit->length; double new_start = src_edit->track->from_units(src_start) + pos; double new_end = src_edit->track->from_units(src_end) + pos; - int64_t trk_start = track->to_units(new_start, 0); - int64_t trk_end = track->to_units(new_end, 0); + int64_t trk_start = track->to_units(new_start, 1); + int64_t trk_end = track->to_units(new_end, 1); for( Edit *edit=track->edits->first; edit; edit=edit->next ) { if( edit->is_selected || edit->silence() ) continue; int64_t edit_start = edit->startproject; if( edit_start >= trk_end ) continue; int64_t edit_end = edit_start + edit->length; if( trk_start >= edit_end ) continue; - int lt_dist = abs(trk_end - edit_start); - int rt_dist = abs(edit_end - trk_start); + + int64_t lt_dist = labs(trk_end - edit_start); + int64_t rt_dist = labs(edit_end - trk_start); + int64_t position; if( lt_dist < rt_dist ) { - pos = edit->track->from_units(edit_start) - - src_edit->track->from_units(src_end); + position = edit_start; + lt_dist = abs(trk_start - edit_start); + rt_dist = abs(trk_end - edit_start); + if( lt_dist > rt_dist ) + position -= src_end; } else { - pos = edit->track->from_units(edit_end); + position = edit_end; + lt_dist = abs(trk_start - edit_end); + rt_dist = abs(trk_end - edit_end); + if( lt_dist > rt_dist ) + position -= src_end; } + double new_pos = edit->track->from_units(position); + int new_pix = track->edl->get_position_cursorx(new_pos, pane_no); + if( abs(new_pix-cur_pix) < HANDLE_W ) + pos = new_pos; return 1; } return 0; @@ -5021,11 +5365,11 @@ int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start, } else // Move plugin - if(drag_start && plugin->track->record) { - if(mwindow->edl->session->editing_mode == EDITING_ARROW) { - if(plugin->track->data_type == TRACK_AUDIO) + if( drag_start && plugin->track->is_armed() && !plugin->silence() ) { + if( mwindow->edl->session->editing_mode == EDITING_ARROW ) { + if( plugin->track->data_type == TRACK_AUDIO ) mwindow->session->current_operation = DRAG_AEFFECT_COPY; - else if(plugin->track->data_type == TRACK_VIDEO) + else if( plugin->track->data_type == TRACK_VIDEO ) mwindow->session->current_operation = DRAG_VEFFECT_COPY; mwindow->session->drag_plugin = plugin; @@ -5081,6 +5425,7 @@ int TrackCanvas::do_transitions(int cursor_x, int cursor_y, for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) { + if( track->is_hidden() ) continue; if( !track->show_transitions() ) continue; for( Edit *edit = track->edits->first; edit; edit = edit->next ) { @@ -5137,7 +5482,7 @@ int TrackCanvas::button_press_event() gui->stop_transport("TrackCanvas::button_press_event"); } - int update_overlay = 0, update_cursor = 0, rerender = 0; + int update_overlay = 0, update_cursor = 0, rerender = 0, update_message = 0; if(get_buttonpress() == WHEEL_UP) { if(shift_down()) @@ -5172,15 +5517,19 @@ int TrackCanvas::button_press_event() mwindow->move_right(get_w() / 5); } else { - switch(mwindow->edl->session->editing_mode) { + if( arrow_mode() ) do { // Test handles and resource boundaries and highlight a track - case EDITING_ARROW: { if( do_transitions(cursor_x, cursor_y, 1, new_cursor, update_cursor) ) break; if( do_keyframes(cursor_x, cursor_y, 0, get_buttonpress(), new_cursor, update_cursor, rerender) ) break; + update_message = 1; + + if( do_transition_handles(cursor_x, cursor_y, + 1, rerender, update_overlay, new_cursor, + update_cursor) ) break; // Test edit boundaries if( do_edit_handles(cursor_x, cursor_y, 1, rerender, update_overlay, new_cursor, @@ -5202,10 +5551,9 @@ int TrackCanvas::button_press_event() if( do_tracks(cursor_x, cursor_y, 1) ) break; result = 0; - break; } - + } while(0); + else if( ibeam_mode() ) do { // Test handles only and select a region - case EDITING_IBEAM: { double position = mwindow->edl->get_cursor_position(cursor_x, pane->number); //printf("TrackCanvas::button_press_event %d\n", position); @@ -5217,6 +5565,9 @@ int TrackCanvas::button_press_event() update_overlay = 1; break; } + update_message = 1; + if( do_transition_handles(cursor_x, cursor_y, + 1, rerender, update_overlay, new_cursor, update_cursor) ) break; // Test edit boundaries if( do_edit_handles(cursor_x, cursor_y, 1, rerender, update_overlay, new_cursor, update_cursor) ) break; @@ -5235,8 +5586,7 @@ int TrackCanvas::button_press_event() rerender = start_selection(position); mwindow->session->current_operation = SELECT_REGION; update_cursor = 1; - break; } - } + } while(0); } if( rerender ) { @@ -5248,9 +5598,12 @@ int TrackCanvas::button_press_event() gui->update_patchbay(); } - if( update_overlay ) { + if( update_message ) + gui->default_message(); + + if( update_overlay ) gui->draw_overlays(1); - } + if( update_cursor < 0 ) { // double_click edit gui->swindow->update_selection(); @@ -5311,11 +5664,19 @@ int TrackCanvas::start_selection(double position) void TrackCanvas::end_edithandle_selection() { mwindow->modify_edithandles(); + mwindow->session->drag_edit = 0; } void TrackCanvas::end_pluginhandle_selection() { mwindow->modify_pluginhandles(); + mwindow->session->drag_plugin = 0; +} + +void TrackCanvas::end_transnhandle_selection() +{ + mwindow->modify_transnhandles(); + mwindow->session->drag_transition = 0; } @@ -5327,11 +5688,11 @@ double TrackCanvas::time_visible() } -void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...) +void TrackCanvas::show_message(Auto *current, int box_color, const char *fmt, ...) { char string[BCTEXTLEN]; char *cp = string, *ep = cp + sizeof(string)-1; - if( show_curve_type ) { + if( box_color >= 0 ) { cp += snprintf(string, ep-cp, "%-8s ", FloatAuto::curve_name(((FloatAuto*)current)->curve_mode)); } @@ -5346,8 +5707,8 @@ void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *f va_list ap; va_start(ap, fmt); vsnprintf(cp, ep-cp, fmt, ap); - va_end(ap); - gui->show_message(string); + va_end(ap); + gui->show_message(string, -1, box_color); } // Patchbay* TrackCanvas::get_patchbay()