X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Ftrackcanvas.C;h=d15f9a3774f0978adece81815e2adc412342b89e;hp=fc7283c9be31f76ba88e6dafe8a5b4178788ba07;hb=b104b77f5296719bd5e6de8472eb71542ddaedec;hpb=1529091cdf16df199a901aabe6e8fa1813a933af diff --git a/cinelerra-5.1/cinelerra/trackcanvas.C b/cinelerra-5.1/cinelerra/trackcanvas.C index fc7283c9..d15f9a37 100644 --- a/cinelerra-5.1/cinelerra/trackcanvas.C +++ b/cinelerra-5.1/cinelerra/trackcanvas.C @@ -158,10 +158,646 @@ void TrackCanvas::resize_event() //printf("TrackCanvas::resize_event 2\n"); } +// *** CONTEXT_HELP *** +// This complicated implementation (up to *** END_CONTEXT_HELP ***) +// serves solely for context dependent help int TrackCanvas::keypress_event() { + int cursor_x, cursor_y; + +// printf("TrackCanvas::keypress_event: %d\n", get_keypress()); + if (get_keypress() != 'h' || ! alt_down()) return 0; + if (! is_tooltip_event_win() || ! cursor_inside()) return 0; + + cursor_x = get_cursor_x(); + cursor_y = get_cursor_y(); + +// Provide different help depending on the kind of object under the cursor: +// transition border handles +// transition icons themselves +// autos (keyframes or lines) and plugin keyframes +// asset border handles +// plugin border handles +// plugin bars themselves + if (help_transition_handles(cursor_x, cursor_y)) return 1; + if (help_transitions(cursor_x, cursor_y)) return 1; + if (help_keyframes(cursor_x, cursor_y)) return 1; + if (help_edit_handles(cursor_x, cursor_y)) return 1; + if (help_plugin_handles(cursor_x, cursor_y)) return 1; + if (help_plugins(cursor_x, cursor_y)) return 1; + +// Show "Editing" chapter as a fallback when cursor was over anything else + context_help_show("Editing"); + return 1; +} + +int TrackCanvas::help_transitions(int cursor_x, int cursor_y) +{ + int done = 0; + int64_t x, y, w, h; + Transition *transition = 0; + + // Detect, if any, the transition under cursor + for( Track *track = mwindow->edl->tracks->first; track && !done; track = track->next ) { + if( track->is_hidden() ) continue; + if( !track->show_transitions() ) continue; + + for( Edit *edit = track->edits->first; edit; edit = edit->next ) { + if( edit->transition ) { + edit_dimensions(edit, x, y, w, h); + get_transition_coords(edit, x, y, w, h); + + if( MWindowGUI::visible(x, x + w, 0, get_w()) && + MWindowGUI::visible(y, y + h, 0, get_h()) ) { + if( cursor_x >= x && cursor_x < x + w && + cursor_y >= y && cursor_y < y + h ) { + transition = edit->transition; + done = 1; + break; + } + } + } + } + } + + // If transition found, display its context help + if(transition) { + context_help_show(transition->title); + return 1; + } + + return 0; +} + +int TrackCanvas::help_keyframes(int cursor_x, int cursor_y) +{ + int result = 0; + EDLSession *session = mwindow->edl->session; + + static BC_Pixmap *help_pixmaps[AUTOMATION_TOTAL] = + { + 0, 0, 0, 0, 0, 0, 0, 0, + pankeyframe_pixmap, + modekeyframe_pixmap, + maskkeyframe_pixmap, + 0, + }; + + for(Track *track = mwindow->edl->tracks->first; + track && !result; + track = track->next) { + if( track->is_hidden() ) continue; + Automation *automation = track->automation; + + for(int i = 0; i < AUTOMATION_TOTAL && !result; i ++) + { +// Event not trapped and automation visible + Autos *autos = automation->autos[i]; + if(!result && session->auto_conf->autos[i] && autos) { + switch(i) { + case AUTOMATION_MODE: + case AUTOMATION_PAN: + case AUTOMATION_MASK: + result = help_autos(track, automation->autos[i], + cursor_x, cursor_y, + help_pixmaps[i]); + break; + + default: { + switch(autos->get_type()) { + case Autos::AUTOMATION_TYPE_FLOAT: { + Automation automation(0, track); + int grouptype = automation.autogrouptype(i, track); + + result = help_float_autos(track, autos, + cursor_x, cursor_y, + grouptype); + + break; } + + case Autos::AUTOMATION_TYPE_INT: { + result = help_int_autos(track, autos, + cursor_x, cursor_y); + break; } + } + break; } + } + + if(result) + { + context_help_show("Using Autos"); + } + } + } + + if(!result && session->auto_conf->plugins) { + result = help_plugin_autos(track, cursor_x, cursor_y); + if(result) { + context_help_show("Edit Params"); + } + } + } + + return result; +} + +int TrackCanvas::help_plugin_autos(Track *track, int cursor_x, int cursor_y) +{ + int result = 0; + + double view_start; + double unit_start; + double view_end; + double unit_end; + double yscale; + int center_pixel; + double zoom_sample; + double zoom_units; + + if(!track->expand_view) return 0; + + calculate_viewport(track, + view_start, + unit_start, + view_end, + unit_end, + yscale, + center_pixel, + zoom_sample, + zoom_units); + + for(int i = 0; i < track->plugin_set.total && !result; i++) + { + PluginSet *plugin_set = track->plugin_set.values[i]; + int center_pixel = track->y_pixel - + mwindow->edl->local_session->track_start[pane->number]; + if( track->show_titles() ) + center_pixel += mwindow->theme->get_image("title_bg_data")->get_h(); + if( track->show_assets() ) + 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; + plugin && !result; + plugin = (Plugin*)plugin->next) + { + for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first; + keyframe && !result; + keyframe = (KeyFrame*)keyframe->next) + { + if(keyframe->position >= unit_start && keyframe->position < unit_end) + { + int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units); + int y = center_pixel - keyframe_pixmap->get_h() / 2; + + if(cursor_x >= x && cursor_y >= y && + cursor_x < x + keyframe_pixmap->get_w() && + cursor_y < y + keyframe_pixmap->get_h()) + { + result = 1; + } + } + } + } + } + + return result; +} + +int TrackCanvas::help_autos(Track *track, Autos *autos, int cursor_x, + int cursor_y, BC_Pixmap *pixmap) +{ + int result = 0; + + double view_start; + double unit_start; + double view_end; + double unit_end; + double yscale; + int center_pixel; + double zoom_sample; + double zoom_units; + + calculate_viewport(track, + view_start, + unit_start, + view_end, + unit_end, + yscale, + center_pixel, + zoom_sample, + zoom_units); + + Auto *current; + + for(current = autos->first; current && !result; current = NEXT) + { + if(current->position >= unit_start && current->position < unit_end) + { + int64_t x, y; + x = (int64_t)((double)(current->position - unit_start) / + zoom_units - (pixmap->get_w() / 2.0 + 0.5)); + y = center_pixel - pixmap->get_h() / 2; + + if(cursor_x >= x && cursor_y >= y && + cursor_x < x + pixmap->get_w() && + cursor_y < y + pixmap->get_h()) + { + result = 1; + } + } + } + + return result; +} + +int TrackCanvas::help_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y, int autogrouptype) +{ + int result = 0; + int center_pixel; + double view_start, unit_start; + double view_end, unit_end, yscale; + double zoom_sample, zoom_units; + double slope; + + calculate_viewport(track, view_start, unit_start, view_end, unit_end, + yscale, center_pixel, zoom_sample, zoom_units); + +// Get first auto before start + Auto *current = 0, *previous = 0; + + for( current = autos->last; + current && current->position >= unit_start; + current = PREVIOUS ) ; + + Auto *first_auto = current ? current : + autos->first ? autos->first : autos->default_auto; + + double ax = 0, ay = 0, ax2 = 0, ay2 = 0; + if( first_auto ) { + calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0, + first_auto, unit_start, zoom_units, yscale, autogrouptype); + } + if( current ) + current = NEXT; + else { + current = autos->first; + ax = 0; + } + + do { + if(current) { + calculate_auto_position(1, &ax2, &ay2, 0, 0, 0, 0, + current, unit_start, zoom_units, yscale, autogrouptype); + } + else { + ax2 = get_w(); + ay2 = ay; + } + + slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0; + + if(ax2 > get_w()) { + ax2 = get_w(); + ay2 = ay + slope * (get_w() - ax); + } + + if(ax < 0) { + ay = ay + slope * (0 - ax); + ax = 0; + } + +// test handle + if( current && !result && current != autos->default_auto ) { + if( track->is_armed() ) { + result = test_floatauto((FloatAuto*)current, 0, + (int)center_pixel, (int)yscale, cursor_x, cursor_y, + unit_start, zoom_units, yscale, autogrouptype); + } + } + +// test joining line + if( !result && track->is_armed() ) { + result = test_floatline(center_pixel, + (FloatAutos*)autos, unit_start, zoom_units, yscale, +// Exclude auto coverage from the end of the line. The auto overlaps + (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y, + 0, autogrouptype); + } + + 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(track->is_armed()) { + result = test_floatline(center_pixel, + (FloatAutos*)autos, unit_start, zoom_units, yscale, + (int)ax, (int)ax2, cursor_x, cursor_y, + 0, autogrouptype); + } + } + + return result; +} + +int TrackCanvas::help_int_autos(Track *track, Autos *autos, int cursor_x, int cursor_y) +{ + int result = 0; + double view_start; + double unit_start; + double view_end; + double unit_end; + double yscale; + int center_pixel; + double zoom_sample; + double zoom_units; + double ax, ay, ax2, ay2; + + calculate_viewport(track, + view_start, + unit_start, + view_end, + unit_end, + yscale, + center_pixel, + zoom_sample, + zoom_units); + + double high = -yscale * 0.8 / 2; + double low = yscale * 0.8 / 2; + +// Get first auto before start + Auto *current; + for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS) + ; + + if(current) + { + ax = 0; + ay = ((IntAuto*)current)->value > 0 ? high : low; + current = NEXT; + } + else + { + current = autos->first ? autos->first : autos->default_auto; + if(current) + { + ax = 0; + ay = ((IntAuto*)current)->value > 0 ? high : low; + } + else + { + ax = 0; + ay = yscale; + } + } + + do + { + if(current) + { + ax2 = (double)(current->position - unit_start) / zoom_units; + ay2 = ((IntAuto*)current)->value > 0 ? high : low; + } + else + { + ax2 = get_w(); + ay2 = ay; + } + + if(ax2 > get_w()) ax2 = get_w(); + + if(current && !result) + { + if(current != autos->default_auto) + { + if(track->is_armed()) + { + result = test_auto(current, + (int)ax2, + (int)ay2, + (int)center_pixel, + (int)yscale, + cursor_x, + cursor_y, + 0); + } + } + + current = NEXT; + } + + if(!result) + { + if(track->is_armed()) + { + result = test_toggleline(autos, + center_pixel, + (int)ax, + (int)ay, + (int)ax2, + (int)ay2, + cursor_x, + cursor_y, + 0); + } + } + + ax = ax2; + ay = ay2; + }while(current && current->position <= unit_end && !result); + + if(ax < get_w() && !result) + { + ax2 = get_w(); + ay2 = ay; + if(track->is_armed()) + { + result = test_toggleline(autos, + center_pixel, + (int)ax, + (int)ay, + (int)ax2, + (int)ay2, + cursor_x, + cursor_y, + 0); + } + } + return result; +} + +int TrackCanvas::help_transition_handles(int cursor_x, int cursor_y) +{ + if( !mwindow->edl->session->auto_conf->transitions ) + return 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 ) { + result = 1; + } + } + } + + if( result ) { + context_help_show("Editing Effects"); + } + + return result; +} + +int TrackCanvas::help_edit_handles(int cursor_x, int cursor_y) +{ + 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); + + if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w && + cursor_y >= edit_y && cursor_y < edit_y + edit_h && + ( cursor_x < edit_x + HANDLE_W || + cursor_x >= edit_x + edit_w - HANDLE_W )) { + result = 1; + } + } + } + + if( result ) { + context_help_show("Trimming"); + } + + return result; +} + +int TrackCanvas::help_plugin_handles(int cursor_x, int cursor_y) +{ + int result = 0; + + 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; + plugin && !result; + plugin = (Plugin*)plugin->next) { + int64_t plugin_x, plugin_y, plugin_w, plugin_h; + plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h); + + if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w && + cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h && + (cursor_x < plugin_x + HANDLE_W || + cursor_x >= plugin_x + plugin_w - HANDLE_W)) { + result = 1; + } + } + } + } + + if(result) { + context_help_show("Editing Effects"); + } + + return result; +} + +int TrackCanvas::help_plugins(int cursor_x, int cursor_y) +{ + int done = 0; + int64_t x, y, w, h; + Track *track = 0; + Plugin *plugin = 0; + char title[BCTEXTLEN]; + + // Detect, if any, the plugin under cursor + for(track = mwindow->edl->tracks->first; track && !done; track = track->next) { + if(!track->expand_view) continue; + + for(int i = 0; i < track->plugin_set.total && !done; i++) { + // first check if plugins are visible at all + if (!track->expand_view) + continue; + PluginSet *plugin_set = track->plugin_set.values[i]; + for(plugin = (Plugin*)plugin_set->first; + plugin && !done; + plugin = (Plugin*)plugin->next) { + plugin_dimensions(plugin, x, y, w, h); + if(MWindowGUI::visible(x, x + w, 0, get_w()) && + MWindowGUI::visible(y, y + h, 0, get_h())) { + if(cursor_x >= x && cursor_x < x + w && + cursor_y >= y && cursor_y < y + h) { + done = 1; + break; + } + } + } + } + } + + // If plugin found, display its context help + if(plugin) { + strcpy(title, plugin->title); + if(! strcmp(title, "Overlay")) + // "Overlay" plugin title is ambiguous + switch(plugin->track->data_type) + { + case TRACK_AUDIO: + strcat(title, " \\(Audio\\)"); + break; + case TRACK_VIDEO: + strcat(title, " \\(Video\\)"); + break; + } + if(! strncmp(title, "F_", 2)) + // FFmpeg plugins can be audio or video + switch(plugin->track->data_type) + { + case TRACK_AUDIO: + strcpy(title, "FFmpeg Audio Plugins"); + break; + case TRACK_VIDEO: + strcpy(title, "FFmpeg Video Plugins"); + break; + } + context_help_show(title); + return 1; + } + return 0; } +// *** END_CONTEXT_HELP *** int TrackCanvas::cursor_leave_event() { @@ -188,6 +824,7 @@ int TrackCanvas::drag_motion( Track **over_track, Edit **over_edit, PluginSet **over_pluginset, Plugin **over_plugin) { + int update_scroll = 0; int cursor_x = get_relative_cursor_x(); int cursor_y = get_relative_cursor_y(); if( get_cursor_over_window() ) { @@ -196,6 +833,28 @@ int TrackCanvas::drag_motion( } if( over_track && !*over_track ) *over_track = pane->over_patchbay(); + + switch( mwindow->session->current_operation ) { + case DRAG_EDIT_SELECT: { + Edit *edit = over_edit ? *over_edit : 0; + double position = mwindow->edl->get_cursor_position(cursor_x, pane->number); + mwindow->session->drag_position = mwindow->edl->align_to_frame(position, 0); + drag_edit_select(edit, 0, 1); + update_scroll = 1; + break; } + } + + if( update_scroll ) { + if( !drag_scroll && + (cursor_x >= get_w() || cursor_x < 0 || + cursor_y >= get_h() || cursor_y < 0)) + start_dragscroll(); + else if( drag_scroll && + cursor_x < get_w() && cursor_x >= 0 && + cursor_y < get_h() && cursor_y >= 0 ) + stop_dragscroll(); + } + return 0; } @@ -210,6 +869,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 +1067,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 ) @@ -499,7 +1159,7 @@ int TrackCanvas::drag_stop(int *redraw) result = 1; } break; - case DRAG_GROUP: + case DRAG_GROUP: { mwindow->session->current_operation = NO_OPERATION; EDL *drag_group = mwindow->session->drag_group; if( drag_group ) { @@ -531,10 +1191,21 @@ int TrackCanvas::drag_stop(int *redraw) } } result = 1; + break; } + case DRAG_EDIT_SELECT: + int select = ctrl_down() ? -1 : 1; + drag_edit_select(mwindow->session->edit_highlighted, select, 0); break; } } + switch( mwindow->session->current_operation ) { + case DRAG_EDIT_SELECT: + mwindow->session->current_operation = NO_OPERATION; + result = 1; + break; + } + return result; } @@ -770,23 +1441,21 @@ void TrackCanvas::draw_resources(int mode, resource_timer->update(); + if(!indexes_only) { // Age resource pixmaps for deletion - if(!indexes_only) for(int i = 0; i < gui->resource_pixmaps.total; i++) gui->resource_pixmaps.values[i]->visible--; - - if(mode == FORCE_REDRAW) - gui->resource_pixmaps.remove_all_objects(); - + } if(debug) PRINT_TRACE if(mode != IGNORE_THREAD) - gui->resource_thread->reset(pane->number); + 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) { @@ -942,12 +1611,9 @@ ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit, if(!result) { //SET_TRACE - result = new ResourcePixmap(mwindow, - gui, - edit, - pane->number, - pixmap_w, - pixmap_h); + result = new ResourcePixmap(mwindow, gui, edit, pane->number, pixmap_w, pixmap_h); + set_bg_color(BLACK); + clear_box(0,0, pixmap_w,pixmap_h, result); //SET_TRACE gui->resource_pixmaps.append(result); } @@ -1149,7 +1815,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 @@ -1655,6 +2322,9 @@ void TrackCanvas::draw_highlighting() } break; + case DRAG_SPEED: + draw_speed_highlight(); + break; } if( draw_box ) @@ -1663,6 +2333,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) { @@ -1680,7 +2377,8 @@ void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int { int dropping = 0; for( Track *track=edl->tracks->first; track; track=track->next ) { - if( !track->record && color1 < 0 ) { + if( track->is_hidden() ) continue; + if( !track->is_armed() && color1 < 0 ) { if( dropping ) dy -= track->vertical_span(mwindow->theme); continue; @@ -1697,9 +2395,9 @@ void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int int inner = color1 < 0 ? color0 : !edit->group_id ? color0 : mwindow->get_group_color(edit->group_id); int outer = color1 < 0 ? color0 : !edit->group_id ? color1 : inner; - set_color(track->record ? inner : outer); + set_color(track->is_armed() ? inner : outer); draw_selected(x, y, w, h); - set_color(track->record ? outer : inner); + 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); } @@ -1725,6 +2423,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++) @@ -1891,6 +2590,7 @@ void TrackCanvas::draw_hard_edges() 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); @@ -1931,7 +2631,8 @@ void TrackCanvas::draw_inout_points() void TrackCanvas::draw_drag_handle() { if( mwindow->session->current_operation != DRAG_EDITHANDLE2 && - mwindow->session->current_operation != DRAG_PLUGINHANDLE2 ) return; + 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 - @@ -1954,6 +2655,7 @@ void TrackCanvas::draw_drag_handle() 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 ) { @@ -1974,7 +2676,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 ) @@ -2010,8 +2715,10 @@ void TrackCanvas::draw_drag_handle() 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) { @@ -2163,8 +2870,8 @@ int TrackCanvas::do_keyframes(int cursor_x, // track context menu to appear int result = 0; EDLSession *session = mwindow->edl->session; - - + int gang = mwindow->edl->local_session->gang_tracks != GANG_NONE || + get_double_click() ? 1 : 0; static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] = { @@ -2180,6 +2887,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; @@ -2229,7 +2937,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); @@ -2271,7 +2979,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(); @@ -2365,6 +3073,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; @@ -2448,14 +3157,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); @@ -2483,13 +3198,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); } @@ -2630,16 +3354,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); @@ -2652,6 +3381,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; @@ -2709,13 +3441,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; @@ -2731,12 +3464,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)) { @@ -2764,6 +3498,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; @@ -2771,43 +3508,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); @@ -2825,6 +3550,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; } @@ -2842,6 +3573,8 @@ void TrackCanvas::draw_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; for( int x=x1; xedl->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); @@ -2914,40 +3649,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 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); } } @@ -2960,11 +3698,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()); } } @@ -3116,7 +3852,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) @@ -3124,9 +3860,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; @@ -3134,7 +3872,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; } @@ -3144,7 +3882,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; } } @@ -3159,7 +3897,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; @@ -3182,7 +3919,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 ) @@ -3197,7 +3934,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 { @@ -3221,24 +3958,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 @@ -3253,15 +3988,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, @@ -3366,7 +4102,7 @@ int TrackCanvas::do_int_autos(Track *track, { if(!draw) { - if(track->record) + if(track->is_armed()) { result = test_auto(current, (int)ax2, @@ -3395,7 +4131,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, @@ -3426,7 +4162,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, @@ -3668,7 +4404,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); @@ -3777,14 +4513,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 { \ @@ -3886,7 +4616,7 @@ int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode) !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; float ox1, oy1, ox2, oy2, cx1, cy1, cx2, cy2; @@ -3940,7 +4670,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; @@ -3976,7 +4706,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; \ \ @@ -4007,7 +4737,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; } @@ -4017,28 +4748,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(); } @@ -4228,6 +4958,53 @@ void TrackCanvas::update_drag_caption() } +void TrackCanvas::drag_edit_select(Edit *over_edit, int select, int draw) +{ + if( !over_edit ) return; + if( !mwindow->session->drag_edit ) return; + Track *drag_track = mwindow->session->drag_edit->track; + Track *over_track = over_edit->track; + if( !drag_track || !over_track ) return; + if( drag_track->number_of() > over_track->number_of() ) { + Track *trk = drag_track; + drag_track = over_track; + over_track = trk; + } + double start_pos = mwindow->session->drag_start; + double end_pos = mwindow->session->drag_position; + if( start_pos > end_pos ) { + double pos = start_pos; + start_pos = end_pos; + end_pos = pos; + } + int done = 0, do_flash = 0; + for( Track *track=drag_track; !done; track=track->next ) { + if( !track->is_armed() ) continue; + for( Edit *edit=track->edits->first; edit; edit=edit->next ) { + int64_t pos = edit->startproject; + int64_t end = pos + edit->length; + double edit_start = track->from_units(pos); + double edit_end = track->from_units(end); + if( start_pos >= edit_end ) continue; + if( edit_start > end_pos ) continue; + if( select > 0 ) + edit->is_selected = 1; + else if( select < 0 ) + edit->is_selected = 0; + if( draw ) { + int64_t edit_x, edit_y, edit_w, edit_h; + edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h); + set_color(YELLOW); + draw_rectangle(edit_x, edit_y, edit_w, edit_h); + do_flash = 1; + } + } + if( track == over_track ) done = 1; + } + if( do_flash ) + flash(); +} + int TrackCanvas::cursor_update(int in_motion) { @@ -4241,7 +5018,7 @@ int TrackCanvas::cursor_update(int in_motion) int update_cursor = 0; int rerender = 0; double position = 0.; -//printf("TrackCanvas::cursor_update %d\n", __LINE__); +//printf("TrackCanvas::cursor_update %d %d,%d\n", __LINE__, get_cursor_x(), get_cursor_y()); // Default cursor int new_cursor = @@ -4252,42 +5029,46 @@ int TrackCanvas::cursor_update(int in_motion) { 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: @@ -4303,7 +5084,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: @@ -4410,6 +5191,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 @@ -4506,6 +5289,7 @@ int TrackCanvas::repeat_event(int64_t duration) int result = 0; switch(mwindow->session->current_operation) { + case DRAG_EDIT_SELECT: case SELECT_REGION: //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start); if(get_cursor_x() > get_w()) { @@ -4609,9 +5393,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(); @@ -4689,6 +5487,10 @@ int TrackCanvas::button_release_event() drag_scroll = 0; break; } + case DRAG_EDIT_SELECT: + //result = 0; + break; + default: if( mwindow->session->current_operation ) { // if(mwindow->session->current_operation == SELECT_REGION) { @@ -4728,6 +5530,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); @@ -4824,6 +5627,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 ) { @@ -4870,6 +5674,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; @@ -4928,6 +5733,97 @@ 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) +{ + if( !mwindow->edl->session->auto_conf->transitions ) + return 0; + 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) { @@ -4972,6 +5868,7 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag 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); @@ -4983,9 +5880,7 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag if( button_press && get_buttonpress() == LEFT_BUTTON ) { if( get_double_click() ) { mwindow->edl->tracks->clear_selected_edits(); - mwindow->edl->tracks->select_affected_edits( - edit->track->from_units(edit->startproject), - edit->track, 1); + 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); @@ -5004,13 +5899,20 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag update_cursor = -1; } } - else if( drag_start && track->record ) { + 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); + double position = mwindow->edl->get_cursor_position(cursor_x, pane->number); + mwindow->session->drag_position = mwindow->edl->align_to_frame(position, 1); + if( get_buttonpress() == LEFT_BUTTON && alt_down() ) { + mwindow->session->drag_start = mwindow->session->drag_position; + drag_edit_select(edit, 0, 1); + mwindow->session->current_operation = DRAG_EDIT_SELECT; + result = 1; + continue; + } drag_start = 0; // if unselected "fast" drag if( !edit->silence() && !edit->is_selected ) { mwindow->edl->tracks->clear_selected_edits(); @@ -5021,9 +5923,7 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag edit->set_selected(1); } else - mwindow->edl->tracks->select_affected_edits( - edit->track->from_units(edit->startproject), - edit->track, 1); + edit->select_affected_edits(1, -1); drag_start = 1; } // Construct list of all affected edits @@ -5071,7 +5971,7 @@ 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 ) return -1; + 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; @@ -5191,7 +6091,7 @@ int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start, } else // Move plugin - if( drag_start && plugin->track->record && !plugin->silence() ) { + 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; @@ -5251,6 +6151,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 ) { @@ -5351,6 +6252,10 @@ int TrackCanvas::button_press_event() 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, @@ -5387,6 +6292,8 @@ int TrackCanvas::button_press_event() 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; @@ -5483,11 +6390,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; }