splashgui text clr, faders/speed keyframe popup slider rework, reticle rework
[goodguy/history.git] / cinelerra-5.1 / cinelerra / trackcanvas.C
index 6a34b7f1d33deff5abd4f5b01ff533358765f743..5b283ff6eca69caabc5cc83683b183663c1efef3 100644 (file)
@@ -27,6 +27,8 @@
 #include "bctimer.h"
 #include "clip.h"
 #include "bccolors.h"
+#include "cache.h"
+#include "canvas.h"
 #include "cplayback.h"
 #include "cursors.h"
 #include "cwindowgui.h"
@@ -67,6 +69,7 @@
 #include "pluginset.h"
 #include "plugintoggles.h"
 #include "preferences.h"
+#include "renderengine.h"
 #include "resourcepixmap.h"
 #include "resourcethread.h"
 #include "swindow.h"
@@ -80,6 +83,7 @@
 #include "transportque.h"
 #include "vframe.h"
 #include "vpatchgui.inc"
+#include "vrender.h"
 #include "zoombar.h"
 
 #include <string.h>
@@ -642,7 +646,6 @@ int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_p
        return -1;
 }
 
-
 void TrackCanvas::draw(int mode, int hide_cursor)
 {
        const int debug = 0;
@@ -709,9 +712,6 @@ void TrackCanvas::draw_resources(int mode,
 
        if(debug) PRINT_TRACE
 
-       if(!mwindow->edl->session->show_assets) return;
-
-
 // can't stop thread here, because this is called for every pane
 //     if(mode != IGNORE_THREAD && !indexes_only)
 //             gui->resource_thread->stop_draw(!indexes_only);
@@ -801,24 +801,29 @@ void TrackCanvas::draw_resources(int mode,
                                if(pixmap_w && pixmap_h)
                                {
 // Create pixmap if it doesn't exist
-                                       ResourcePixmap* pixmap = create_pixmap(edit,
-                                               edit_x,
-                                               pixmap_x,
-                                               pixmap_w,
-                                               pixmap_h);
+                                       ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
+                                               pixmap_x, pixmap_w, pixmap_h);
 // Resize it if it's bigger
-                                       if(pixmap_w > pixmap->pixmap_w ||
-                                               pixmap_h > pixmap->pixmap_h)
+                                       if( pixmap_w > pixmap->pixmap_w ||
+                                           pixmap_h > pixmap->pixmap_h)
                                                pixmap->resize(pixmap_w, pixmap_h);
-                                       pixmap->draw_data(this,
-                                               edit,
-                                               edit_x,
-                                               edit_w,
-                                               pixmap_x,
-                                               pixmap_w,
-                                               pixmap_h,
-                                               mode,
-                                               indexes_only);
+                                       pixmap->update_settings(edit, edit_x, edit_w,
+                                               pixmap_x, pixmap_w, pixmap_h);
+// Draw data
+                                       if( current->show_assets() )
+                                               pixmap->draw_data(this,
+                                                       edit, edit_x, edit_w,
+                                                       pixmap_x, pixmap_w, pixmap_h,
+                                                       mode, indexes_only);
+                                       else {
+                                               set_bg_color(BLACK);
+                                               clear_box(0,0, pixmap_w,pixmap_h, pixmap);
+                                       }
+// Draw title
+                                       if( current->show_titles() )
+                                               pixmap->draw_title(this,
+                                                       edit, edit_x, edit_w,
+                                                       pixmap_x, pixmap_w);
 // Resize it if it's smaller
                                        if(pixmap_w < pixmap->pixmap_w ||
                                                pixmap_h < pixmap->pixmap_h)
@@ -959,27 +964,22 @@ void TrackCanvas::get_pixmap_size(Edit *edit,
 //     }
 
        pixmap_h = mwindow->edl->local_session->zoom_track;
-       if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
+       Track *track = edit->edits->track;
+       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);
 }
 
 void TrackCanvas::edit_dimensions(Edit *edit,
-       int64_t &x,
-       int64_t &y,
-       int64_t &w,
-       int64_t &h)
+       int64_t &x, int64_t &y, int64_t &w, int64_t &h)
 {
-//     w = Units::round(edit->track->from_units(edit->length) *
-//             mwindow->edl->session->sample_rate /
-//             mwindow->edl->local_session->zoom_sample);
-
-       h = resource_h();
-
        x = Units::round(edit->track->from_units(edit->startproject) *
                        mwindow->edl->session->sample_rate /
                        mwindow->edl->local_session->zoom_sample -
                        mwindow->edl->local_session->view_start[pane->number]);
 
+       y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
+
 // Method for calculating w so when edits are together we never get off by one error due to rounding
        int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
                        mwindow->edl->session->sample_rate /
@@ -987,10 +987,12 @@ void TrackCanvas::edit_dimensions(Edit *edit,
                        mwindow->edl->local_session->view_start[pane->number]);
        w = x_next - x;
 
-       y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
-
-       if(mwindow->edl->session->show_titles)
-               h += mwindow->theme->get_image("title_bg_data")->get_h();
+       int edit_h = 0;
+       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();
+       h = edit_h;
 }
 
 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
@@ -1240,13 +1242,14 @@ void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int6
        w = Units::round(plugin->track->from_units(plugin->length) *
                mwindow->edl->session->sample_rate /
                mwindow->edl->local_session->zoom_sample);
-       y = plugin->track->y_pixel -
-               mwindow->edl->local_session->track_start[pane->number] +
-               mwindow->edl->local_session->zoom_track +
-               plugin->plugin_set->get_number() *
-               mwindow->theme->get_image("plugin_bg_data")->get_h();
-       if(mwindow->edl->session->show_titles)
+       y = plugin->track->y_pixel
+               - mwindow->edl->local_session->track_start[pane->number];
+       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->plugin_set->get_number() *
+                       mwindow->theme->get_image("plugin_bg_data")->get_h();
        h = mwindow->theme->get_image("plugin_bg_data")->get_h();
 }
 
@@ -1379,42 +1382,36 @@ void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t
 
        edit_dimensions(edit, x, y, w, h);
 
-       if(mwindow->edl->session->show_titles)
-       {
+       if( edit->track->show_titles() )
                y += mwindow->theme->get_image("title_bg_data")->get_h();
-       }
-       else
-       {
-               y = 0;
-       }
 
        if(side == EDIT_OUT)
-       {
                x += w - handle_w;
-       }
 
        h = handle_h;
        w = handle_w;
 }
 
-void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
+void TrackCanvas::get_transition_coords(Edit *edit,
+               int64_t &x, int64_t &y, int64_t &w, int64_t &h)
 {
-//printf("TrackCanvas::get_transition_coords 1\n");
-//     int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
-//     int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
-       int transition_w = 30;
-       int transition_h = 30;
-//printf("TrackCanvas::get_transition_coords 1\n");
-
-       if(mwindow->edl->session->show_titles)
-               y += mwindow->theme->get_image("title_bg_data")->get_h();
-//printf("TrackCanvas::get_transition_coords 2\n");
+       int transition_w = 30, transition_h = 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;
+       double dy = has_titles ?
+               ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) :
+               ( has_assets ? asset_h/2 : 0) ;
+       double title_h = mwindow->theme->title_h;
+       if( dy < title_h / 2 ) { ys = title_h;  dy = ys / 2; }
+       y += dy;
 
-       y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
        x -= transition_w / 2;
-
-       h = transition_h;
+       y -= transition_h / 2;
        w = transition_w;
+       h = transition_h;
 }
 
 void TrackCanvas::draw_highlighting()
@@ -1429,21 +1426,18 @@ void TrackCanvas::draw_highlighting()
 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
 //     mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
                        if(mwindow->session->edit_highlighted) {
-//printf("TrackCanvas::draw_highlighting 2\n");
                                if((mwindow->session->current_operation == DRAG_ATRANSITION &&
                                        mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
                                        (mwindow->session->current_operation == DRAG_VTRANSITION &&
                                        mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
-//printf("TrackCanvas::draw_highlighting 2\n");
-                                       edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
-//printf("TrackCanvas::draw_highlighting 2\n");
-
+                                       edit_dimensions(mwindow->session->edit_highlighted,
+                                               x, y, w, h);
                                        if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
                                                MWindowGUI::visible(y, y + h, 0, get_h())) {
                                                draw_box = 1;
-                                               get_transition_coords(x, y, w, h);
+                                               get_transition_coords(mwindow->session->edit_highlighted,
+                                                       x, y, w, h);
                                        }
-//printf("TrackCanvas::draw_highlighting 3\n");
                                }
                        }
                        break;
@@ -1611,8 +1605,6 @@ void TrackCanvas::draw_plugins()
        int current_show = 0;
        int current_preset = 0;
 
-//     if(!mwindow->edl->session->show_assets) goto done;
-
        for(int i = 0; i < plugin_on_toggles.total; i++)
                plugin_on_toggles.values[i]->in_use = 0;
        for(int i = 0; i < plugin_show_toggles.total; i++)
@@ -1788,14 +1780,19 @@ void TrackCanvas::draw_hard_edges()
 {
        int64_t x, y, w, h;
 
-//     if(!mwindow->edl->session->show_assets) return;
-
        for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
                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);
                        set_color(GREEN);
-                       set_opaque();    int y1 = y+h-1;
+                       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();
+                       if( y1 == y )
+                               y1 += mwindow->theme->title_h;
                        if( edit->hard_left ) {
                                ArrayList<int> xpt, ypt;
                                xpt.append(x);              ypt.append(y1);
@@ -1844,38 +1841,38 @@ void TrackCanvas::draw_transitions()
 {
        int64_t x, y, w, h;
 
-//     if(!mwindow->edl->session->show_assets) return;
-
        for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
+               if( !track->show_transitions() ) continue;
+
                for(Edit *edit = track->edits->first; edit; edit = edit->next) {
                        if(!edit->transition) continue;
                        edit_dimensions(edit, x, y, w, h);
-                       int strip_x = x, strip_y = y;
-                       if(mwindow->edl->session->show_titles)
-                               strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
-                       get_transition_coords(x, y, w, h);
+                       int strip_x = x, edit_y = y;
+                       get_transition_coords(edit, x, y, w, h);
+                       int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->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);
                        if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
-                               MWindowGUI::visible(y, y + h, 0, get_h()) )
-                       {
+                           MWindowGUI::visible(y, y + h, 0, get_h()) ) {
                                PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
                                                track->data_type);
                                if( !server ) continue;
                                VFrame *picon = server->get_picon();
                                if( !picon ) continue;
-                               draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
+                               int picon_w = picon->get_w(), picon_h = picon->get_h();
+                               int track_h = edit->track->vertical_span(mwindow->theme);
+                               if( picon_h > track_h ) picon_h = track_h;
+                               draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
                        }
                        if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
-                               MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
-                       {
+                               MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
                                int x = strip_x, w = strip_w;
-                               if(x < 0)
-                               {
-                                       w -= -x;
-                                       x = 0;
-                               }
-                               if(w + x > get_w()) w -= (w + x) - get_w();
+                               if( x < 0 ) {  w -= -x;  x = 0; }
+                               if( w + x > get_w() ) w -= (w + x) - get_w();
 
                                draw_3segmenth( x, strip_y, w, strip_x, strip_w,
                                        mwindow->theme->get_image("plugin_bg_data"), 0);
@@ -2046,16 +2043,27 @@ int TrackCanvas::do_keyframes(int cursor_x,
                                        case Autos::AUTOMATION_TYPE_FLOAT: {
                                                Automation automation(0, track);
                                                int grouptype = automation.autogrouptype(i, track);
+                                               if( buttonpress && i == AUTOMATION_SPEED ) {
+                                                       mwindow->speed_before();
+                                               }
+
                                                if(draw) // Do dropshadow
                                                        result = do_float_autos(track, autos,
                                                                cursor_x, cursor_y, draw,
                                                                buttonpress, 1, 1, MDGREY,
                                                                auto_keyframe, grouptype);
-
                                                result = do_float_autos(track, autos,
                                                        cursor_x, cursor_y, draw, buttonpress,
                                                        0, 0, GWindowGUI::auto_colors[i],
                                                        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();
+                                               }
                                                break; }
 
                                        case Autos::AUTOMATION_TYPE_INT: {
@@ -2117,9 +2125,7 @@ int TrackCanvas::do_keyframes(int cursor_x,
                        }
                }
 
-               if(!result &&
-                       session->auto_conf->plugins /* &&
-                       mwindow->edl->session->show_assets */) {
+               if(!result && session->auto_conf->plugins) {
                        Plugin *plugin;
                        KeyFrame *keyframe;
                        result = do_plugin_autos(track, cursor_x, cursor_y,
@@ -2171,34 +2177,37 @@ void TrackCanvas::draw_keyframe_reticle()
        int current_op = mwindow->session->current_operation, dragging = 0;
        for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
                if( current_op == auto_operations[i] ) dragging = 1;
+       if( dragging && !mwindow->session->drag_auto ) dragging = 0;
 
-       if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
-               if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
-                       draw_hairline(mwindow->session->drag_auto, RED);
-                       return;
-               }
+       int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
+               mwindow->session->drag_auto->autos->autoidx : -1;
+
+       if( get_buttonpress() == 1 && dragging &&
+            keyframe_hairline == HAIRLINE_DRAGGING ) {
+               draw_hairline(mwindow->session->drag_auto, RED, 1);
+               return;
        }
 
        if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
            keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
-               for( Track *track = mwindow->edl->tracks->first; track;
-                    track=track->next ) {
+               int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
+               for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
                        Automation *automation = track->automation;
                        for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
                                if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
                                // automation visible
                                Autos *autos = automation->autos[i];
                                if( !autos ) continue;
+                               if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
                                for( Auto *auto_keyframe=autos->first; auto_keyframe;
                                     auto_keyframe = auto_keyframe->next ) {
-                                       draw_hairline(auto_keyframe, BLUE);
+                                       draw_hairline(auto_keyframe, BLUE, show);
                                }
                        }
-
-                       if( dragging && mwindow->session->drag_auto ) {
-                               draw_hairline(mwindow->session->drag_auto, RED);
-                       }
                }
+
+               if( dragging )
+                       draw_hairline(mwindow->session->drag_auto, RED, 1);
        }
 }
 
@@ -2856,6 +2865,7 @@ void TrackCanvas::calculate_viewport(Track *track,
        double &zoom_sample,
        double &zoom_units)
 {
+
        view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
                mwindow->edl->local_session->zoom_sample /
                mwindow->edl->session->sample_rate;
@@ -2865,16 +2875,23 @@ void TrackCanvas::calculate_viewport(Track *track,
                mwindow->edl->local_session->zoom_sample /
                mwindow->edl->session->sample_rate;
        unit_end = track->to_doubleunits(view_end);
-       yscale = mwindow->edl->local_session->zoom_track;
-//printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
-       center_pixel = (int)(track->y_pixel -
-                       mwindow->edl->local_session->track_start[pane->number] +
-                       yscale / 2) +
-               (mwindow->edl->session->show_titles ?
-                       mwindow->theme->get_image("title_bg_data")->get_h() :
-                       0);
-       zoom_sample = mwindow->edl->local_session->zoom_sample;
 
+       int y = track->y_pixel
+                       - mwindow->edl->local_session->track_start[pane->number];
+       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 dy = has_titles ?
+               ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) :
+               ( has_assets ? asset_h/2 : 0) ;
+       if( dy < title_h/2 ) { ys = title_h;  dy = ys / 2; }
+       yscale = ys;
+       center_pixel = y + dy;
+
+       zoom_sample = mwindow->edl->local_session->zoom_sample;
        zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
 }
 
@@ -3365,11 +3382,13 @@ int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
        for(int i = 0; i < track->plugin_set.total && !result; i++)
        {
                PluginSet *plugin_set = track->plugin_set.values[i];
-               int center_pixel = (int)(track->y_pixel -
-                       mwindow->edl->local_session->track_start[pane->number] +
-                       mwindow->edl->local_session->zoom_track +
-                       (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
-                       (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
+               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 += resource_h();
+               center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
 
                for(Plugin *plugin = (Plugin*)plugin_set->first;
                        plugin && !result;
@@ -3442,10 +3461,10 @@ int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
        return result;
 }
 
-int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
+int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
 {
        Track *track = auto_keyframe->autos->track;
-       int autogrouptype = auto_keyframe->autos->get_type();
+       int autogrouptype = auto_keyframe->autos->autogrouptype;
 
        int center_pixel;
        double view_start, unit_start;
@@ -3461,6 +3480,31 @@ int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
 
        set_color(color);
        draw_line(ax, 0, ax, get_h());
+
+       if( show ) {
+               char text[BCSTRLEN];
+               if( auto_keyframe->is_floatauto() ) {
+                       FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
+                       sprintf(text, "%0.2f", float_auto->get_value());
+               }
+               else {
+                       IntAuto *int_auto = (IntAuto *)auto_keyframe;
+                       sprintf(text, "%d", int_auto->value);
+               }
+               int font = MEDIUMFONT;
+               int tw = get_text_width(font, text)  + TOOLTIP_MARGIN * 2;
+               int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2;
+               set_color(get_resources()->tooltip_bg_color);
+               ax += HANDLE_W/2;
+               ay += center_pixel + HANDLE_W/2;
+               draw_box(ax, ay, tw, th);
+               set_color(BLACK);
+               draw_rectangle(ax, ay, tw, th);
+               set_font(font);
+               ax += TOOLTIP_MARGIN;
+               ay += TOOLTIP_MARGIN + get_text_ascent(font);
+               draw_text(ax, ay, text);
+       }
        return 0;
 }
 
@@ -3481,7 +3525,7 @@ void TrackCanvas::draw_overlays()
        draw_inout_points();
 
 // Transitions
-       if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
+       draw_transitions();
 
 // Plugins
        draw_plugins();
@@ -3585,16 +3629,89 @@ void TrackCanvas::update_drag_handle()
        {
                mwindow->session->drag_position = new_position;
                gui->mainclock->update(new_position);
-
-
                timebar_position = new_position;
                gui->update_timebar(0);
-// Que the CWindow.  Doesn't do anything if selectionstart and selection end
-// aren't changed.
-//             mwindow->cwindow->update(1, 0, 0);
+
+               EDL *edl = new EDL;
+               edl->create_objects();
+               edl->copy_all(mwindow->edl);
+               MainSession *session = mwindow->session;
+               int edit_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
+               edl->modify_edithandles(session->drag_start,
+                       session->drag_position,
+                       session->drag_handle,
+                       edit_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 ) ?
+                               session->drag_position : session->drag_start;
+               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);
+               edl->remove_user();
        }
 }
 
+int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
+{
+       int result = 0;
+       int64_t left = pos-1;
+       if( left < 0 ) left = 0;
+       switch( mode ) {
+       case 0: {
+               VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
+               VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
+               TransportCommand command;
+               command.command = CURRENT_FRAME;
+               command.get_edl()->copy_all((EDL *)edl);
+               command.change_type = CHANGE_ALL;
+               command.realtime = 0;
+               Preferences *preferences = mwindow->preferences;
+               RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
+               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;
+               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;
+               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->flash(1);
+               canvas->unlock_canvas();
+               mwindow->cwindow->gui->unlock_window();
+               break; }
+       case 1:
+       case 2: {
+               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);
+               mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
+               break; }
+       }
+       return result;
+}
+
 int TrackCanvas::update_drag_edit()
 {
        int result = 0;
@@ -3902,7 +4019,7 @@ void TrackCanvas::update_drag_caption()
 
 
 
-int TrackCanvas::cursor_motion_event()
+int TrackCanvas::cursor_update(int in_motion)
 {
        int result = 0;
        int cursor_x = 0;
@@ -3915,7 +4032,7 @@ int TrackCanvas::cursor_motion_event()
        int new_cursor = 0;
        int rerender = 0;
        double position = 0.;
-//printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
+//printf("TrackCanvas::cursor_update %d\n", __LINE__);
 
 // Default cursor
        switch(mwindow->edl->session->editing_mode)
@@ -3978,6 +4095,8 @@ int TrackCanvas::cursor_motion_event()
                case DRAG_PROJECTOR_Z:
                        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);
                        break;
 
                case DRAG_PLAY:
@@ -4043,7 +4162,7 @@ int TrackCanvas::cursor_motion_event()
                                        start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
                                        end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
                                mwindow->cwindow->update(dir, 0, 0, 0, 1);
-                               gui->lock_window("TrackCanvas::cursor_motion_event 1");
+                               gui->lock_window("TrackCanvas::cursor_update 1");
        // Update the faders
                                mwindow->update_plugin_guis();
                                gui->update_patchbay();
@@ -4078,7 +4197,7 @@ int TrackCanvas::cursor_motion_event()
                                for(int i = 0; i < TOTAL_PANES; i++)
                                        if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
 
-//printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
+//printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
                                gui->update_timebar(0);
 // Update cursor
                                if(do_transitions(get_cursor_x(), get_cursor_y(),
@@ -4096,13 +4215,13 @@ int TrackCanvas::cursor_motion_event()
                        break;
        }
 
-//printf("TrackCanvas::cursor_motion_event 1\n");
+//printf("TrackCanvas::cursor_update 1\n");
        if(update_cursor && new_cursor != get_cursor())
        {
                set_cursor(new_cursor, 0, 1);
        }
 
-//printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
+//printf("TrackCanvas::cursor_update 1 %d\n", rerender);
        if(rerender && render_timer->get_difference() > 0.25 ) {
                render_timer->update();
                mwindow->restart_brender();
@@ -4110,7 +4229,7 @@ int TrackCanvas::cursor_motion_event()
                mwindow->update_plugin_guis();
                gui->unlock_window();
                mwindow->cwindow->update(1, 0, 0, 0, 1);
-               gui->lock_window("TrackCanvas::cursor_motion_event 2");
+               gui->lock_window("TrackCanvas::cursor_update 2");
        }
        if(rerender) {
 // Update faders
@@ -4141,10 +4260,15 @@ int TrackCanvas::cursor_motion_event()
                gui->draw_overlays(1);
        }
 
-//printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
+//printf("TrackCanvas::cursor_update %d\n", __LINE__);
        return result;
 }
 
+int TrackCanvas::cursor_motion_event()
+{
+       return cursor_update(1);
+}
+
 void TrackCanvas::start_dragscroll()
 {
        if(!drag_scroll) {
@@ -4244,7 +4368,8 @@ int TrackCanvas::repeat_event(int64_t duration)
 
 int TrackCanvas::button_release_event()
 {
-       int redraw = 0, update_overlay = 0, result = 0;
+       int redraw = -1, update_overlay = 0;
+       int result = 0, load_flags = 0;
 
 // printf("TrackCanvas::button_release_event %d\n",
 // mwindow->session->current_operation);
@@ -4278,8 +4403,10 @@ int TrackCanvas::button_release_event()
                        result = 1;
                        break;
 
-               case DRAG_FADE:
                case DRAG_SPEED:
+                       redraw = FORCE_REDRAW;
+                       load_flags |= LOAD_EDITS;
+               case DRAG_FADE:
 // delete the drag_auto_gang first and remove out of order keys
                        synchronize_autos(0, 0, 0, -1);
                case DRAG_CZOOM:
@@ -4296,6 +4423,7 @@ int TrackCanvas::button_release_event()
                case DRAG_PROJECTOR_Y:
                case DRAG_PROJECTOR_Z:
                case DRAG_PLUGINKEY:
+                       load_flags |= LOAD_AUTOMATION;
                        mwindow->session->current_operation = NO_OPERATION;
                        mwindow->session->drag_handle = 0;
 // Remove any out-of-order keyframe
@@ -4306,8 +4434,7 @@ int TrackCanvas::button_release_event()
                                update_overlay = 1;
                        }
 
-
-                       mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
+                       mwindow->undo->update_undo_after(_("keyframe"), load_flags);
                        result = 1;
                        break;
 
@@ -4334,13 +4461,14 @@ int TrackCanvas::button_release_event()
        }
 
        if (result)
-               cursor_motion_event();
+               cursor_update(0);
 
        if(update_overlay) {
                gui->draw_overlays(1);
        }
-       if(redraw) {
-               gui->draw_canvas(NORMAL_DRAW, 0);
+       if(redraw >= 0) {
+               gui->draw_canvas(redraw, 0);
+               gui->flash_canvas(1);
        }
        return result;
 }
@@ -4352,8 +4480,6 @@ int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
        int handle_result = -1;
        int result = 0;
 
-       if( !mwindow->edl->session->show_assets ) return 0;
-
        for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
                for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
                        int64_t edit_x, edit_y, edit_w, edit_h;
@@ -4364,7 +4490,8 @@ int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
                                if( cursor_x < edit_x + HANDLE_W ) {
                                        edit_result = edit;
                                        handle_result = 0;
-                                       if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
+                                       if( cursor_y >= edit_y+edit_h - HANDLE_W &&
+                                           track->show_assets() ) {
                                                new_cursor = DOWNLEFT_RESIZE;
                                                if( button_press == LEFT_BUTTON )
                                                        result = -1;
@@ -4375,7 +4502,8 @@ int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
                                else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
                                        edit_result = edit;
                                        handle_result = 1;
-                                       if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
+                                       if( cursor_y >= edit_y+edit_h - HANDLE_W &&
+                                           track->show_assets() ) {
                                                new_cursor = DOWNRIGHT_RESIZE;
                                                if( button_press == LEFT_BUTTON )
                                                        result = -1;
@@ -4414,7 +4542,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 < ) {
                mwindow->undo->update_undo_before();
                if( !shift_down() ) {
                        if( handle_result == 0 )
@@ -4473,8 +4601,6 @@ int TrackCanvas::do_plugin_handles(int cursor_x,
        int handle_result = 0;
        int result = 0;
 
-//     if(!mwindow->edl->session->show_assets) return 0;
-
        for(Track *track = mwindow->edl->tracks->first;
                track && !result;
                track = track->next) {
@@ -4541,17 +4667,17 @@ int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
 {
        int result = 0;
 
-//     if(!mwindow->edl->session->show_assets) return 0;
-
        for(Track *track = mwindow->edl->tracks->first;
                track && !result;
                track = track->next) {
                int64_t track_x, track_y, track_w, track_h;
                track_dimensions(track, track_x, track_y, track_w, track_h);
 
-               if(button_press && get_buttonpress() == RIGHT_BUTTON &&
-                       cursor_y >= track_y && cursor_y < track_y + track_h) {
-                       gui->edit_menu->update(track, 0);
+               if( button_press && get_buttonpress() == RIGHT_BUTTON &&
+                   cursor_y >= track_y && cursor_y < track_y + track_h) {
+                       double pos = mwindow->edl->get_cursor_position(cursor_x, pane->number);
+                       int64_t position = track->to_units(pos, 0);
+                       gui->edit_menu->update(track, track->edits->editof(position, PLAY_FORWARD, 0));
                        gui->edit_menu->activate_menu();
                        result = 1;
                }
@@ -4565,10 +4691,7 @@ int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag
 {
        int result = 0;
 
-       if(!mwindow->edl->session->show_assets) return 0;
-
        for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
-
                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);
@@ -4654,10 +4777,6 @@ int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
        int64_t x, y, w, h;
        Track *track = 0;
 
-
-//     if(!mwindow->edl->session->show_assets) return 0;
-
-
        for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
                if(!track->expand_view) continue;
 
@@ -4766,15 +4885,14 @@ int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
        int result = 0;
        int64_t x, y, w, h;
 
-       if(/* !mwindow->edl->session->show_assets || */
-               !mwindow->edl->session->auto_conf->transitions) return 0;
 
        for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
+               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(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()) ) {
@@ -4814,12 +4932,7 @@ int TrackCanvas::button_press_event()
        mwindow->session->trim_edits = 0;
 
        if(is_event_win() && cursor_inside()) {
-//             double position = (double)cursor_x *
-//                     mwindow->edl->local_session->zoom_sample /
-//                     mwindow->edl->session->sample_rate +
-//                     (double)mwindow->edl->local_session->view_start[pane->number] *
-//                     mwindow->edl->local_session->zoom_sample /
-//                     mwindow->edl->session->sample_rate;
+//             double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
 
                result = 1;
                if(!active) {
@@ -4899,12 +5012,7 @@ int TrackCanvas::button_press_event()
 
 // Test handles only and select a region
                        case EDITING_IBEAM: {
-                               double position = (double)cursor_x *
-                                       mwindow->edl->local_session->zoom_sample /
-                                       mwindow->edl->session->sample_rate +
-                                       (double)mwindow->edl->local_session->view_start[pane->number] *
-                                       mwindow->edl->local_session->zoom_sample /
-                                       mwindow->edl->session->sample_rate;
+                               double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
 //printf("TrackCanvas::button_press_event %d\n", position);
 
                                if( do_transitions(cursor_x, cursor_y,