4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "apatchgui.inc"
25 #include "automation.h"
26 #include "bcsignals.h"
32 #include "cplayback.h"
34 #include "cwindowgui.h"
36 #include "edithandles.h"
37 #include "editpopup.h"
40 #include "edlsession.h"
41 #include "floatauto.h"
42 #include "floatautos.h"
43 #include "gwindowgui.h"
44 #include "indexstate.h"
48 #include "keyframepopup.h"
49 #include "keyframes.h"
52 #include "localsession.h"
53 #include "mainclock.h"
54 #include "maincursor.h"
55 #include "mainsession.h"
57 #include "maskautos.h"
60 #include "mwindowgui.h"
64 #include "playbackengine.h"
65 #include "playtransport.h"
67 #include "pluginpopup.h"
68 #include "pluginserver.h"
69 #include "pluginset.h"
70 #include "plugintoggles.h"
71 #include "preferences.h"
72 #include "renderengine.h"
73 #include "resourcepixmap.h"
74 #include "resourcethread.h"
77 #include "trackcanvas.h"
79 #include "trackpopup.h"
81 #include "transition.h"
82 #include "transitionhandles.h"
83 #include "transitionpopup.h"
84 #include "transportque.h"
86 #include "vpatchgui.inc"
92 //#define PIXMAP_AGE -5
93 #define PIXMAP_AGE -32
95 TrackCanvas::TrackCanvas(MWindow *mwindow,
106 this->mwindow = mwindow;
107 this->gui = mwindow->gui;
110 selection_midpoint = 0;
114 resource_timer = new Timer;
115 render_timer = new Timer;
116 hourglass_enabled = 0;
117 timebar_position = -1;
121 TrackCanvas::~TrackCanvas()
123 // delete transition_handles;
125 delete keyframe_pixmap;
126 delete camerakeyframe_pixmap;
127 delete modekeyframe_pixmap;
128 delete pankeyframe_pixmap;
129 delete projectorkeyframe_pixmap;
130 delete maskkeyframe_pixmap;
131 delete background_pixmap;
132 if(temp_picon) delete temp_picon;
134 delete resource_timer;
137 void TrackCanvas::create_objects()
139 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
140 // transition_handles = new TransitionHandles(mwindow, this);
141 edit_handles = new EditHandles(mwindow, this);
142 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
143 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
144 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
145 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
146 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
147 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
148 draw(NORMAL_DRAW, 1);
153 void TrackCanvas::resize_event()
155 //printf("TrackCanvas::resize_event 1\n");
156 draw(NORMAL_DRAW, 0);
158 //printf("TrackCanvas::resize_event 2\n");
161 // *** CONTEXT_HELP ***
162 // This complicated implementation (up to *** END_CONTEXT_HELP ***)
163 // serves solely for context dependent help
164 int TrackCanvas::keypress_event()
166 int cursor_x, cursor_y;
168 // printf("TrackCanvas::keypress_event: %d\n", get_keypress());
169 if (get_keypress() != 'h' || ! alt_down()) return 0;
170 if (! is_tooltip_event_win() || ! cursor_inside()) return 0;
172 cursor_x = get_cursor_x();
173 cursor_y = get_cursor_y();
175 // Provide different help depending on the kind of object under the cursor:
176 // transition border handles
177 // transition icons themselves
178 // autos (keyframes or lines) and plugin keyframes
179 // asset border handles
180 // plugin border handles
181 // plugin bars themselves
182 if (help_transition_handles(cursor_x, cursor_y)) return 1;
183 if (help_transitions(cursor_x, cursor_y)) return 1;
184 if (help_keyframes(cursor_x, cursor_y)) return 1;
185 if (help_edit_handles(cursor_x, cursor_y)) return 1;
186 if (help_plugin_handles(cursor_x, cursor_y)) return 1;
187 if (help_plugins(cursor_x, cursor_y)) return 1;
189 // Show "Editing" chapter as a fallback when cursor was over anything else
190 context_help_show("Editing");
194 int TrackCanvas::help_transitions(int cursor_x, int cursor_y)
198 Transition *transition = 0;
200 // Detect, if any, the transition under cursor
201 for( Track *track = mwindow->edl->tracks->first; track && !done; track = track->next ) {
202 if( track->is_hidden() ) continue;
203 if( !track->show_transitions() ) continue;
205 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
206 if( edit->transition ) {
207 edit_dimensions(edit, x, y, w, h);
208 get_transition_coords(edit, x, y, w, h);
210 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
211 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
212 if( cursor_x >= x && cursor_x < x + w &&
213 cursor_y >= y && cursor_y < y + h ) {
214 transition = edit->transition;
223 // If transition found, display its context help
225 context_help_show(transition->title);
232 int TrackCanvas::help_keyframes(int cursor_x, int cursor_y)
235 EDLSession *session = mwindow->edl->session;
237 static BC_Pixmap *help_pixmaps[AUTOMATION_TOTAL] =
239 0, 0, 0, 0, 0, 0, 0, 0,
246 for(Track *track = mwindow->edl->tracks->first;
248 track = track->next) {
249 if( track->is_hidden() ) continue;
250 Automation *automation = track->automation;
252 for(int i = 0; i < AUTOMATION_TOTAL && !result; i ++)
254 // Event not trapped and automation visible
255 Autos *autos = automation->autos[i];
256 if(!result && session->auto_conf->autos[i] && autos) {
258 case AUTOMATION_MODE:
260 case AUTOMATION_MASK:
261 result = help_autos(track, automation->autos[i],
267 switch(autos->get_type()) {
268 case Autos::AUTOMATION_TYPE_FLOAT: {
269 Automation automation(0, track);
270 int grouptype = automation.autogrouptype(i, track);
272 result = help_float_autos(track, autos,
278 case Autos::AUTOMATION_TYPE_INT: {
279 result = help_int_autos(track, autos,
288 context_help_show("Using Autos");
293 if(!result && session->auto_conf->plugins) {
294 result = help_plugin_autos(track, cursor_x, cursor_y);
296 context_help_show("Edit Params");
304 int TrackCanvas::help_plugin_autos(Track *track, int cursor_x, int cursor_y)
317 if(!track->expand_view) return 0;
319 calculate_viewport(track,
329 for(int i = 0; i < track->plugin_set.total && !result; i++)
331 PluginSet *plugin_set = track->plugin_set.values[i];
332 int center_pixel = track->y_pixel -
333 mwindow->edl->local_session->track_start[pane->number];
334 if( track->show_titles() )
335 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
336 if( track->show_assets() )
337 center_pixel += track->data_h;
338 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
340 for(Plugin *plugin = (Plugin*)plugin_set->first;
342 plugin = (Plugin*)plugin->next)
344 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
346 keyframe = (KeyFrame*)keyframe->next)
348 if(keyframe->position >= unit_start && keyframe->position < unit_end)
350 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
351 int y = center_pixel - keyframe_pixmap->get_h() / 2;
353 if(cursor_x >= x && cursor_y >= y &&
354 cursor_x < x + keyframe_pixmap->get_w() &&
355 cursor_y < y + keyframe_pixmap->get_h())
367 int TrackCanvas::help_autos(Track *track, Autos *autos, int cursor_x,
368 int cursor_y, BC_Pixmap *pixmap)
381 calculate_viewport(track,
393 for(current = autos->first; current && !result; current = NEXT)
395 if(current->position >= unit_start && current->position < unit_end)
398 x = (int64_t)((double)(current->position - unit_start) /
399 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
400 y = center_pixel - pixmap->get_h() / 2;
402 if(cursor_x >= x && cursor_y >= y &&
403 cursor_x < x + pixmap->get_w() &&
404 cursor_y < y + pixmap->get_h())
414 int TrackCanvas::help_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y, int autogrouptype)
418 double view_start, unit_start;
419 double view_end, unit_end, yscale;
420 double zoom_sample, zoom_units;
423 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
424 yscale, center_pixel, zoom_sample, zoom_units);
426 // Get first auto before start
427 Auto *current = 0, *previous = 0;
429 for( current = autos->last;
430 current && current->position >= unit_start;
431 current = PREVIOUS ) ;
433 Auto *first_auto = current ? current :
434 autos->first ? autos->first : autos->default_auto;
436 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
438 calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0,
439 first_auto, unit_start, zoom_units, yscale, autogrouptype);
444 current = autos->first;
450 calculate_auto_position(1, &ax2, &ay2, 0, 0, 0, 0,
451 current, unit_start, zoom_units, yscale, autogrouptype);
458 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
462 ay2 = ay + slope * (get_w() - ax);
466 ay = ay + slope * (0 - ax);
471 if( current && !result && current != autos->default_auto ) {
472 if( track->is_armed() ) {
473 result = test_floatauto((FloatAuto*)current, 0,
474 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
475 unit_start, zoom_units, yscale, autogrouptype);
480 if( !result && track->is_armed() ) {
481 result = test_floatline(center_pixel,
482 (FloatAutos*)autos, unit_start, zoom_units, yscale,
483 // Exclude auto coverage from the end of the line. The auto overlaps
484 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
490 calculate_auto_position(0, &ax2, &ay2, 0, 0, 0, 0, previous,
491 unit_start, zoom_units, yscale, autogrouptype);
495 } while( current && current->position <= unit_end && !result );
497 if( ax < get_w() && !result ) {
498 ax2 = get_w(); ay2 = ay;
499 if(track->is_armed()) {
500 result = test_floatline(center_pixel,
501 (FloatAutos*)autos, unit_start, zoom_units, yscale,
502 (int)ax, (int)ax2, cursor_x, cursor_y,
510 int TrackCanvas::help_int_autos(Track *track, Autos *autos, int cursor_x, int cursor_y)
521 double ax, ay, ax2, ay2;
523 calculate_viewport(track,
533 double high = -yscale * 0.8 / 2;
534 double low = yscale * 0.8 / 2;
536 // Get first auto before start
538 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
544 ay = ((IntAuto*)current)->value > 0 ? high : low;
549 current = autos->first ? autos->first : autos->default_auto;
553 ay = ((IntAuto*)current)->value > 0 ? high : low;
566 ax2 = (double)(current->position - unit_start) / zoom_units;
567 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
575 if(ax2 > get_w()) ax2 = get_w();
577 if(current && !result)
579 if(current != autos->default_auto)
581 if(track->is_armed())
583 result = test_auto(current,
599 if(track->is_armed())
601 result = test_toggleline(autos,
615 }while(current && current->position <= unit_end && !result);
617 if(ax < get_w() && !result)
621 if(track->is_armed())
623 result = test_toggleline(autos,
637 int TrackCanvas::help_transition_handles(int cursor_x, int cursor_y)
639 if( !mwindow->edl->session->auto_conf->transitions )
643 Track *track = mwindow->edl->tracks->first;
644 for( ; track && !result; track=track->next) {
645 if( track->is_hidden() ) continue;
646 Edit *edit = track->edits->first;
647 for( ; edit && !result; edit=edit->next ) {
648 Transition *trans = edit->transition;
649 if( !trans ) continue;
651 edit_dimensions(edit, x, y, w, h);
652 int strip_x = x, edit_y = y;
653 get_transition_coords(edit, x, y, w, h);
654 VFrame *strip = mwindow->theme->get_image("plugin_bg_data");
655 int strip_y = y - strip->get_h();
656 if( track->show_assets() && track->show_titles() )
657 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
658 if( strip_y < edit_y ) strip_y = edit_y;
659 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
660 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
661 int x1 = strip_x + strip_w - HANDLE_W/2, x2 = x1 + HANDLE_W;
662 int y1 = strip_y + strip->get_h()/2 - HANDLE_H/2, y2 = y1 + HANDLE_W;
663 if( cursor_x >= x1 && cursor_x < x2 &&
664 cursor_y >= y1 && cursor_y < y2 ) {
671 context_help_show("Editing Effects");
677 int TrackCanvas::help_edit_handles(int cursor_x, int cursor_y)
681 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
682 if( track->is_hidden() ) continue;
683 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
684 int64_t edit_x, edit_y, edit_w, edit_h;
685 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
687 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
688 cursor_y >= edit_y && cursor_y < edit_y + edit_h &&
689 ( cursor_x < edit_x + HANDLE_W ||
690 cursor_x >= edit_x + edit_w - HANDLE_W )) {
697 context_help_show("Trimming");
703 int TrackCanvas::help_plugin_handles(int cursor_x, int cursor_y)
707 for(Track *track = mwindow->edl->tracks->first;
709 track = track->next) {
710 if( track->is_hidden() ) continue;
711 for(int i = 0; i < track->plugin_set.total && !result; i++) {
712 PluginSet *plugin_set = track->plugin_set.values[i];
713 for(Plugin *plugin = (Plugin*)plugin_set->first;
715 plugin = (Plugin*)plugin->next) {
716 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
717 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
719 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
720 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h &&
721 (cursor_x < plugin_x + HANDLE_W ||
722 cursor_x >= plugin_x + plugin_w - HANDLE_W)) {
730 context_help_show("Editing Effects");
736 int TrackCanvas::help_plugins(int cursor_x, int cursor_y)
742 char title[BCTEXTLEN];
744 // Detect, if any, the plugin under cursor
745 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
746 if(!track->expand_view) continue;
748 for(int i = 0; i < track->plugin_set.total && !done; i++) {
749 // first check if plugins are visible at all
750 if (!track->expand_view)
752 PluginSet *plugin_set = track->plugin_set.values[i];
753 for(plugin = (Plugin*)plugin_set->first;
755 plugin = (Plugin*)plugin->next) {
756 plugin_dimensions(plugin, x, y, w, h);
757 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
758 MWindowGUI::visible(y, y + h, 0, get_h())) {
759 if(cursor_x >= x && cursor_x < x + w &&
760 cursor_y >= y && cursor_y < y + h) {
769 // If plugin found, display its context help
771 strcpy(title, plugin->title);
772 if(! strcmp(title, "Overlay"))
773 // "Overlay" plugin title is ambiguous
774 switch(plugin->track->data_type)
777 strcat(title, " \\(Audio\\)");
780 strcat(title, " \\(Video\\)");
783 if(! strncmp(title, "F_", 2))
784 // FFmpeg plugins can be audio or video
785 switch(plugin->track->data_type)
788 strcpy(title, "FFmpeg Audio Plugins");
791 strcpy(title, "FFmpeg Video Plugins");
794 context_help_show(title);
800 // *** END_CONTEXT_HELP ***
802 int TrackCanvas::cursor_leave_event()
804 // Because drag motion calls get_cursor_over_window we can be sure that
805 // all highlights get deleted now.
806 // This ended up blocking keyboard input from the drag operations.
807 if( timebar_position >= 0 )
809 timebar_position = -1;
811 pane->timebar->update(1);
815 // return drag_motion();
818 int TrackCanvas::drag_motion_event()
820 return gui->drag_motion();
823 int TrackCanvas::drag_motion(
824 Track **over_track, Edit **over_edit,
825 PluginSet **over_pluginset, Plugin **over_plugin)
827 int update_scroll = 0;
828 int cursor_x = get_relative_cursor_x();
829 int cursor_y = get_relative_cursor_y();
830 if( get_cursor_over_window() ) {
831 drag_cursor_motion(cursor_x, cursor_y,
832 over_track, over_edit, over_pluginset, over_plugin);
834 if( over_track && !*over_track )
835 *over_track = pane->over_patchbay();
837 switch( mwindow->session->current_operation ) {
838 case DRAG_EDIT_SELECT: {
839 Edit *edit = over_edit ? *over_edit : 0;
840 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
841 mwindow->session->drag_position = mwindow->edl->align_to_frame(position, 0);
842 drag_edit_select(edit, 0, 1);
847 if( update_scroll ) {
849 (cursor_x >= get_w() || cursor_x < 0 ||
850 cursor_y >= get_h() || cursor_y < 0))
852 else if( drag_scroll &&
853 cursor_x < get_w() && cursor_x >= 0 &&
854 cursor_y < get_h() && cursor_y >= 0 )
861 int TrackCanvas::drag_cursor_motion(int cursor_x, int cursor_y,
862 Track **over_track, Edit **over_edit,
863 PluginSet **over_pluginset, Plugin **over_plugin)
865 if( cursor_x >= 0 && cursor_y >= 0 &&
866 cursor_x < get_w() && cursor_y < get_h() )
868 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
869 // Find the edit and track the cursor is over
870 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
872 if( track->is_hidden() ) continue;
873 int64_t track_x, track_y, track_w, track_h;
874 track_dimensions(track, track_x, track_y, track_w, track_h);
876 if(cursor_y >= track_y &&
877 cursor_y < track_y + track_h)
880 for(Edit *edit = track->edits->first; edit; edit = edit->next)
882 int64_t edit_x, edit_y, edit_w, edit_h;
883 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
884 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
885 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
889 if( edit != track->edits->last ) continue;
890 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
891 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
892 if( !edit->silence() ) {
893 // add silence to allow drag transition past last edit
894 // will be deleted by Edits::optimize if not used
895 double length = mwindow->edl->session->default_transition_length;
896 int64_t start = edit->startproject+edit->length;
897 int64_t units = track->to_units(length, 1);
898 track->edits->create_silence(start, start+units);
901 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
904 for(int i = 0; i < track->plugin_set.total; i++)
906 PluginSet *pluginset = track->plugin_set.values[i];
907 for(Plugin *plugin = (Plugin*)pluginset->first;
909 plugin = (Plugin*)plugin->next)
911 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
912 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
914 if(cursor_y >= plugin_y &&
915 cursor_y < plugin_y + plugin_h)
917 *over_pluginset = plugin->plugin_set;
919 if(cursor_x >= plugin_x &&
920 cursor_x < plugin_x + plugin_w)
922 *over_plugin = plugin;
937 int TrackCanvas::drag_stop_event()
939 int result = gui->drag_stop();
940 if( !result && mwindow->session->current_operation ) {
941 mwindow->session->current_operation = NO_OPERATION;
947 int TrackCanvas::drag_stop(int *redraw)
952 int cursor_x = -1, cursor_y = -1;
954 if( get_cursor_over_window() ) {
955 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
956 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
959 Track *track = pane->over_patchbay();
960 if( track && mwindow->session->track_highlighted == track )
966 switch(mwindow->session->current_operation) {
967 case DRAG_VTRANSITION:
968 case DRAG_ATRANSITION:
969 if(mwindow->session->edit_highlighted) {
970 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
971 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
972 (mwindow->session->current_operation == DRAG_VTRANSITION &&
973 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
974 mwindow->session->current_operation = NO_OPERATION;
975 mwindow->paste_transition();
982 // Behavior for dragged plugins is limited by the fact that a shared plugin
983 // can only refer to a standalone plugin that exists in the same position in
984 // time. Dragging a plugin from one point in time to another can't produce
985 // a shared plugin to the original plugin. In this case we relocate the
986 // plugin instead of sharing it.
987 case DRAG_AEFFECT_COPY:
988 case DRAG_VEFFECT_COPY:
989 if( mwindow->session->track_highlighted &&
990 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
991 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
992 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
993 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
994 mwindow->session->current_operation = NO_OPERATION;
996 int64_t drop_position = -1;
997 Plugin *drag_plugin = mwindow->session->drag_plugin;
998 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
999 Track *hi_track = mwindow->session->track_highlighted;
1001 // Insert shared plugin in source
1002 // Move source to different location
1003 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
1004 //printf("TrackCanvas::drag_stop 6\n");
1005 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1006 if( drop_position < 0 ) {
1008 break; // Do not do anything
1011 Track *track = mwindow->session->track_highlighted;
1012 drop_position = track->frame_align(drop_position, 0);
1013 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
1016 else if( hi_track ) {
1017 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1018 Edit *hi_edit = mwindow->session->edit_highlighted;
1019 drop_position = hi_edit ? hi_edit->startproject : 0;
1020 if( drop_position < 0 ) {
1022 break; // Do not do anything
1025 Track *track = mwindow->session->track_highlighted;
1026 drop_position = track->frame_align(drop_position, 0);
1027 mwindow->move_effect(drag_plugin, hi_track, drop_position);
1035 if( mwindow->session->track_highlighted &&
1036 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1037 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1038 (mwindow->session->current_operation == DRAG_VEFFECT &&
1039 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
1040 // Drop all the effects
1041 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
1042 Track *track = mwindow->session->track_highlighted;
1044 double length = track->get_length();
1046 if(mwindow->session->plugin_highlighted) {
1047 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
1048 length = track->from_units(mwindow->session->plugin_highlighted->length);
1049 if(length <= 0) length = track->get_length();
1051 else if(mwindow->session->pluginset_highlighted) {
1052 start = track->from_units(plugin_set->length());
1053 length = track->get_length() - start;
1054 if(length <= 0) length = track->get_length();
1056 else if(mwindow->edl->local_session->get_selectionend() >
1057 mwindow->edl->local_session->get_selectionstart()) {
1058 start = mwindow->edl->local_session->get_selectionstart();
1059 length = mwindow->edl->local_session->get_selectionend() -
1060 mwindow->edl->local_session->get_selectionstart();
1062 // Move to a point between two edits
1063 else if(mwindow->session->edit_highlighted) {
1064 start = mwindow->session->track_highlighted->from_units(
1065 mwindow->session->edit_highlighted->startproject);
1066 length = mwindow->session->track_highlighted->from_units(
1067 mwindow->session->edit_highlighted->length);
1069 start = mwindow->edl->align_to_frame(start, 0);
1070 mwindow->insert_effects_canvas(track, start, length);
1073 if( mwindow->session->track_highlighted )
1074 result = 1; // we have to cleanup
1078 if(mwindow->session->track_highlighted) {
1079 double asset_duration = 0;
1080 int64_t asset_length_units = 0;
1082 if(mwindow->session->current_operation == DRAG_ASSET &&
1083 mwindow->session->drag_assets->total) {
1084 Indexable *indexable = mwindow->session->drag_assets->values[0];
1085 // we use video if we are over video and audio if we are over audio
1086 if( indexable->have_video() &&
1087 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
1088 // Images have length -1
1089 int64_t video_length = indexable->get_video_frames();
1090 if (video_length < 0) {
1091 if(mwindow->edl->session->si_useduration)
1092 video_length = mwindow->edl->session->si_duration;
1094 video_length = 1.0 / mwindow->edl->session->frame_rate ;
1096 asset_duration = video_length / indexable->get_frame_rate();
1098 else if( indexable->have_audio() &&
1099 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
1100 int64_t audio_length = indexable->get_audio_samples();
1101 asset_duration = (double)audio_length / indexable->get_sample_rate();
1105 break; // Do not do anything
1108 else if( mwindow->session->current_operation == DRAG_ASSET &&
1109 mwindow->session->drag_clips->total ) {
1110 EDL *clip = mwindow->session->drag_clips->values[0];
1111 asset_duration = clip->tracks->total_length();
1114 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
1117 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
1118 int64_t drop_position = drop_edit_position (&insertion, NULL, asset_length_units);
1119 if( drop_position < 0 ) {
1121 break; // Do not do anything
1124 Track *track = mwindow->session->track_highlighted;
1125 double track_position = track->from_units(drop_position);
1126 track_position = mwindow->edl->align_to_frame(track_position, 0);
1128 // if (!insertion) {
1129 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
1130 // // Unfortunately, this is _a lot_ of work to do right
1131 // printf("Problematic insertion\n");
1132 // mwindow->edl->tracks->clear(track_position,
1133 // track_position + asset_duration, 0);
1135 mwindow->paste_assets(track_position, track, !insertion);
1136 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
1141 mwindow->session->current_operation = NO_OPERATION;
1142 if(mwindow->session->track_highlighted) {
1143 if( mwindow->session->track_highlighted->data_type ==
1144 mwindow->session->drag_edit->track->data_type) {
1145 int64_t drop_position = drop_edit_position(&insertion,
1146 mwindow->session->drag_edit,
1147 mwindow->session->drag_edit->length);
1148 if( drop_position < 0 ) {
1150 break; // Do not do anything
1152 Track *track = mwindow->session->track_highlighted;
1153 double track_position = track->from_units(drop_position);
1154 track_position = mwindow->edl->align_to_frame(track_position, 0);
1155 mwindow->move_edits(mwindow->session->drag_edits,
1156 track, track_position, insertion);
1163 mwindow->session->current_operation = NO_OPERATION;
1164 EDL *drag_group = mwindow->session->drag_group;
1166 Track *drop_track = mwindow->session->track_highlighted;
1167 Track *drag_track = mwindow->session->drag_group_first_track;
1168 Edit *drag_edit = mwindow->session->drag_group_edit;
1169 Track *edit_track = drag_edit ? drag_edit->track : 0;
1170 while( drop_track && edit_track ) {
1171 if( edit_track == drag_track ) break;
1172 edit_track = edit_track->previous;
1173 drop_track = drop_track->previous;
1176 double cur_pos = mwindow->session->drag_group_position;
1177 double new_pos = mwindow->edl->get_cursor_position(cursor_x, pane->number);
1178 new_pos -= mwindow->session->drag_position - cur_pos;
1179 new_pos = mwindow->edl->align_to_frame(new_pos, 0);
1180 double drop_position = new_pos;
1181 int ret = test_track_group(drag_group, drop_track, new_pos);
1182 if( !ret && new_pos != drop_position ) {
1183 drop_position = new_pos;
1184 ret = test_track_group(drag_group, drop_track, new_pos);
1187 mwindow->move_group(drag_group, drop_track, drop_position,
1188 ret > 0 ? !shift_down() : shift_down());
1189 drag_group->remove_user();
1190 mwindow->session->drag_group = 0;
1195 case DRAG_EDIT_SELECT:
1196 int select = ctrl_down() ? -1 : 1;
1197 drag_edit_select(mwindow->session->edit_highlighted, select, 0);
1202 switch( mwindow->session->current_operation ) {
1203 case DRAG_EDIT_SELECT:
1204 mwindow->session->current_operation = NO_OPERATION;
1212 int TrackCanvas::drag_start_event()
1217 int new_cursor, update_cursor;
1219 if( mwindow->session->current_operation == GROUP_TOGGLE )
1220 mwindow->session->current_operation = NO_OPERATION;
1221 else if( mwindow->session->current_operation != NO_OPERATION )
1224 if(is_event_win()) {
1225 if(do_plugins(get_drag_x(), get_drag_y(),
1226 1, 0, redraw, rerender)) {
1229 else if(do_edits(get_drag_x(), get_drag_y(),
1230 0, 1, redraw, rerender, new_cursor, update_cursor)) {
1238 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
1240 // get the canvas/track position
1241 Track *track = mwindow->session->track_highlighted;
1242 int cursor_x = get_relative_cursor_x();
1243 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
1244 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
1245 double position = mwindow->edl->align_to_frame(cur_pos, 1);
1246 if( position <= 0 ) {
1250 double cursor_position = position;
1251 int64_t drop_position = track->to_units(cursor_position, 1);
1252 if( moved_edit ) { // relative cursor position depends upon drop point
1253 double moved_edit_start = moved_edit->track->from_units(moved_edit->startproject);
1254 position -= mwindow->session->drag_position - moved_edit_start;
1256 int64_t edit_position = track->to_units(position, 1);
1257 int64_t grab_position = edit_position;
1258 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
1259 grab_position -= moved_edit_length / 2;
1260 Edit *last_edit = track->edits->last;
1261 if( !last_edit || edit_position >= (last_edit->startproject+last_edit->length) ) {
1263 return edit_position;
1266 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
1267 Edit *next_edit = track->edits->first;
1268 while( next_edit ) {
1269 Edit *edit = next_edit; next_edit = (Edit *)edit->next;
1270 int64_t edit_start = edit->startproject;
1271 int64_t edit_end = edit_start + edit->length;
1272 double edit_start_pos = edit->track->from_units(edit_start);
1273 if( (fabs(edit_start_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
1274 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
1277 double edit_end_pos = edit->track->from_units(edit_end);
1278 if( (fabs(edit_end_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
1279 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
1282 if( edit != moved_edit && !edit->silence() )
1283 drop_start = edit_end; // reset drop zone
1285 if( next_edit == moved_edit || next_edit->silence() ) continue;
1286 drop_end = edit_end;
1289 drop_end = INT64_MAX;
1290 if( edit_position >= drop_start &&
1291 edit_position+moved_edit_length < drop_end ) {
1292 *is_insertion = 0; // fits in the zone
1293 return edit_position;
1295 if( drop_position < drop_end ) { // drop in the zone
1296 if( (drop_end - drop_start) >= moved_edit_length ) {
1297 *is_insertion = 0; // fits in the zone, but over the edge
1298 int64_t dx0 = llabs(drop_position - drop_start);
1299 int64_t dx1 = llabs(drop_position - drop_end);
1300 return dx0 < dx1 ? drop_start : drop_end - moved_edit_length;
1303 int64_t edit_center = (edit_start + edit_end) / 2;
1304 return position < edit_center ? drop_start : drop_end;
1312 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
1314 // get the canvas/track position
1315 Track *track = plugin_set->track;
1316 double moved_plugin_length = moved_plugin->track->from_units(moved_plugin->length);
1317 int64_t track_plugin_length = track->to_units(moved_plugin_length, 0);
1318 int cursor_x = get_relative_cursor_x();
1319 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
1320 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
1321 double position = mwindow->edl->align_to_frame(cur_pos, 1);
1322 if( position <= 0 ) return 0;
1323 int64_t drop_position = track->to_units(position, 1);
1324 Plugin *last_plugin = (Plugin *)plugin_set->last;
1325 if( !last_plugin ) return drop_position;
1326 double plugin_set_end = last_plugin->track->from_units(last_plugin->startproject+last_plugin->length);
1327 if( position >= plugin_set_end ) return drop_position;
1328 double moved_plugin_start = moved_plugin->track->from_units(moved_plugin->startproject);
1329 position -= mwindow->session->drag_position - moved_plugin_start;
1330 int64_t plugin_position = track->to_units(position, 1);
1332 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
1333 Plugin *next_plugin = (Plugin *)plugin_set->first;
1334 while( next_plugin ) {
1335 Plugin *plugin = next_plugin; next_plugin = (Plugin *)plugin->next;
1336 int64_t plugin_start = plugin->startproject;
1337 int64_t plugin_end = plugin_start + plugin->length;
1338 double plugin_end_pos = plugin->track->from_units(plugin_end);
1339 int64_t track_plugin_end = track->to_units(plugin_end_pos, 0);
1340 if( plugin != moved_plugin && !plugin->silence() )
1341 drop_start = track_plugin_end;
1343 if( next_plugin == moved_plugin || next_plugin->silence() ) continue;
1344 drop_end = track_plugin_end;
1347 drop_end = INT64_MAX;
1348 if( plugin_position >= drop_start && // fits in the zone
1349 plugin_position+track_plugin_length < drop_end ) {
1350 return plugin_position;
1352 if( drop_position < drop_end ) { // drop in the zone
1353 if( (drop_end - drop_start) >= track_plugin_length ) {
1354 int64_t dx0 = llabs(drop_position - drop_start);
1355 int64_t dx1 = llabs(drop_position - drop_end);
1356 return dx0 < dx1 ? drop_start : drop_end - track_plugin_length;
1364 void TrackCanvas::draw(int mode, int hide_cursor)
1366 const int debug = 0;
1368 // Swap pixmap layers
1369 if(get_w() != background_pixmap->get_w() ||
1370 get_h() != background_pixmap->get_h())
1372 delete background_pixmap;
1373 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
1376 // Cursor disappears after resize when this is called.
1377 // Cursor doesn't redraw after editing when this isn't called.
1378 if(pane->cursor && hide_cursor) pane->cursor->hide();
1379 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
1381 if(debug) PRINT_TRACE
1382 draw_resources(mode);
1384 if(debug) PRINT_TRACE
1386 if(debug) PRINT_TRACE
1389 void TrackCanvas::update_cursor(int flush)
1392 set_cursor(ARROW_CURSOR, 0, flush);
1393 else if( ibeam_mode() )
1394 set_cursor(IBEAM_CURSOR, 0, flush);
1398 void TrackCanvas::test_timer()
1400 if( resource_timer->get_difference() > 1000 && !hourglass_enabled ) {
1402 hourglass_enabled = 1;
1407 void TrackCanvas::draw_indexes(Indexable *indexable)
1409 IndexState *index_state = indexable->index_state;
1410 // Don't redraw raw samples
1411 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
1413 draw_resources(NORMAL_DRAW, 1, indexable);
1418 void TrackCanvas::draw_resources(int mode,
1420 Indexable *indexable)
1422 const int debug = 0;
1424 if(debug) PRINT_TRACE
1426 // can't stop thread here, because this is called for every pane
1427 // if(mode != IGNORE_THREAD && !indexes_only)
1428 // gui->resource_thread->stop_draw(!indexes_only);
1430 if(mode != IGNORE_THREAD &&
1432 !gui->resource_thread->interrupted)
1434 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
1437 BC_Signals::dump_stack();
1440 if(debug) PRINT_TRACE
1442 resource_timer->update();
1445 // Age resource pixmaps for deletion
1446 for(int i = 0; i < gui->resource_pixmaps.total; i++)
1447 gui->resource_pixmaps.values[i]->visible--;
1449 if(debug) PRINT_TRACE
1450 if(mode != IGNORE_THREAD)
1451 gui->resource_thread->reset(pane->number, indexes_only);
1453 // Search every edit
1454 for(Track *current = mwindow->edl->tracks->first;
1458 if( current->is_hidden() ) continue;
1459 if(debug) PRINT_TRACE
1460 for(Edit *edit = current->edits->first; edit; edit = edit->next)
1462 if(debug) PRINT_TRACE
1463 if( current->data_type != TRACK_SUBTITLE )
1464 if(!edit->asset && !edit->nested_edl) continue;
1467 if(edit->track->data_type != TRACK_AUDIO) continue;
1469 if(edit->nested_edl &&
1470 strcmp(indexable->path, edit->nested_edl->path)) continue;
1473 strcmp(indexable->path, edit->asset->path)) continue;
1476 if(debug) PRINT_TRACE
1478 int64_t edit_x, edit_y, edit_w, edit_h;
1479 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
1482 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
1483 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
1488 if(debug) PRINT_TRACE
1490 // Search for existing pixmap containing edit
1491 for(int i = 0; i < gui->resource_pixmaps.total; i++)
1493 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
1494 // Same pointer can be different edit if editing took place
1495 if(pixmap->edit_id == edit->id &&
1496 pixmap->pane_number == pane->number)
1498 pixmap->visible = 1;
1502 if(debug) PRINT_TRACE
1504 // Get new size, offset of pixmap needed
1505 get_pixmap_size(edit,
1511 if(debug) PRINT_TRACE
1514 if(pixmap_w && pixmap_h)
1516 // Create pixmap if it doesn't exist
1517 ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
1518 pixmap_x, pixmap_w, pixmap_h);
1519 // Resize it if it's bigger
1520 if( pixmap_w > pixmap->pixmap_w ||
1521 pixmap_h > pixmap->pixmap_h)
1522 pixmap->resize(pixmap_w, pixmap_h);
1523 pixmap->update_settings(edit, edit_x, edit_w,
1524 pixmap_x, pixmap_w, pixmap_h);
1526 if( current->show_assets() )
1527 pixmap->draw_data(this,
1528 edit, edit_x, edit_w,
1529 pixmap_x, pixmap_w, pixmap_h,
1530 mode, indexes_only);
1532 set_bg_color(BLACK);
1533 clear_box(0,0, pixmap_w,pixmap_h, pixmap);
1536 if( current->show_titles() )
1537 pixmap->draw_title(this,
1538 edit, edit_x, edit_w,
1539 pixmap_x, pixmap_w);
1540 // Resize it if it's smaller
1541 if(pixmap_w < pixmap->pixmap_w ||
1542 pixmap_h < pixmap->pixmap_h)
1543 pixmap->resize(pixmap_w, pixmap_h);
1545 // Copy pixmap to background canvas
1546 background_pixmap->draw_pixmap(pixmap,
1548 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
1552 if(debug) PRINT_TRACE
1556 int64_t track_x, track_y, track_w, track_h;
1557 track_dimensions(current,
1558 track_x, track_y, track_w, track_h);
1559 set_color((~get_resources()->get_bg_color()) & 0xffffff);
1561 int x1 = track_x, x2 = x1+track_w;
1562 int y1 = track_y+track_h-1;
1563 draw_line(x1,y1, x2,y1, background_pixmap);
1567 // Delete unused pixmaps
1568 if(debug) PRINT_TRACE
1570 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
1571 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
1573 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
1574 delete gui->resource_pixmaps.values[i];
1575 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
1577 if(debug) PRINT_TRACE
1579 if(hourglass_enabled)
1582 hourglass_enabled = 0;
1584 if(debug) PRINT_TRACE
1586 // can't stop thread here, because this is called for every pane
1587 // if(mode != IGNORE_THREAD && !indexes_only)
1588 // gui->resource_thread->start_draw();
1589 if(debug) PRINT_TRACE
1594 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
1600 ResourcePixmap *result = 0;
1602 for(int i = 0; i < gui->resource_pixmaps.total; i++)
1604 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
1605 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
1606 gui->resource_pixmaps.values[i]->pane_number == pane->number)
1608 result = gui->resource_pixmaps.values[i];
1616 result = new ResourcePixmap(mwindow, gui, edit, pane->number, pixmap_w, pixmap_h);
1617 set_bg_color(BLACK);
1618 clear_box(0,0, pixmap_w,pixmap_h, result);
1620 gui->resource_pixmaps.append(result);
1623 // result->resize(pixmap_w, pixmap_h);
1627 void TrackCanvas::get_pixmap_size(Edit *edit,
1635 // Align x on frame boundaries
1638 // switch(edit->edits->track->data_type)
1640 // case TRACK_AUDIO:
1646 pixmap_w -= -edit_x;
1650 if(pixmap_x + pixmap_w > get_w())
1652 pixmap_w = get_w() - pixmap_x;
1657 // case TRACK_VIDEO:
1659 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
1660 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
1661 // int64_t pixel_increment = MAX(picon_w, frame_w);
1662 // int64_t pixmap_x1 = edit_x;
1663 // int64_t pixmap_x2 = edit_x + edit_w;
1665 // if(pixmap_x1 < 0)
1667 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
1668 // pixel_increment +
1672 // if(pixmap_x2 > get_w())
1674 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
1675 // pixel_increment +
1678 // pixmap_x = pixmap_x1;
1679 // pixmap_w = pixmap_x2 - pixmap_x1;
1684 Track *track = edit->edits->track;
1685 pixmap_h = track->data_h;
1686 if( track->show_titles() )
1687 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
1688 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
1691 void TrackCanvas::edit_dimensions(Edit *edit,
1692 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1694 x = Units::round(edit->track->from_units(edit->startproject) *
1695 mwindow->edl->session->sample_rate /
1696 mwindow->edl->local_session->zoom_sample -
1697 mwindow->edl->local_session->view_start[pane->number]);
1699 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1701 // Method for calculating w so when edits are together we never get off by one error due to rounding
1702 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
1703 mwindow->edl->session->sample_rate /
1704 mwindow->edl->local_session->zoom_sample -
1705 mwindow->edl->local_session->view_start[pane->number]);
1709 if( edit->track->show_titles() )
1710 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
1711 if( edit->track->show_assets() )
1712 edit_h += edit->track->data_h;
1716 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1720 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1721 h = track->vertical_span(mwindow->theme);
1725 void TrackCanvas::draw_paste_destination()
1727 //int cursor_x = get_relative_cursor_x();
1728 //int cursor_y = get_relative_cursor_y();
1729 int current_atrack = 0;
1730 int current_vtrack = 0;
1731 int current_aedit = 0;
1732 int current_vedit = 0;
1738 //if(pane->number == BOTTOM_RIGHT_PANE)
1739 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1741 if((mwindow->session->current_operation == DRAG_ASSET &&
1742 (mwindow->session->drag_assets->total ||
1743 mwindow->session->drag_clips->total)) ||
1744 (mwindow->session->current_operation == DRAG_EDIT &&
1745 mwindow->session->drag_edits->total)) {
1746 Indexable *indexable = 0;
1750 if(mwindow->session->current_operation == DRAG_ASSET &&
1751 mwindow->session->drag_assets->size())
1752 indexable = mwindow->session->drag_assets->get(0);
1754 if(mwindow->session->current_operation == DRAG_ASSET &&
1755 mwindow->session->drag_clips->size())
1756 clip = mwindow->session->drag_clips->get(0);
1758 int has_audio = 0, has_video = 0;
1759 double paste_audio_length = 0, paste_video_length = 0;
1760 double paste_audio_position = -1, paste_video_position = -1;
1763 has_audio = indexable->have_audio();
1764 paste_audio_length = !has_audio ? 0 :
1765 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1766 has_video = indexable->have_video();
1767 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1768 // Images have length -1
1769 if( asset && asset->video_data && asset->video_length < 0 ) {
1770 paste_video_length = mwindow->edl->session->si_useduration ?
1771 mwindow->edl->session->si_duration / asset->frame_rate :
1772 1.0 / asset->frame_rate ; // 1 frame
1775 paste_video_length = !has_video ? 0 :
1776 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1780 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1781 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1782 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1783 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1786 // 'Align cursor on frame' lengths calculations
1787 if( mwindow->edl->session->cursor_on_frames ) {
1788 double fps = mwindow->edl->session->frame_rate;
1789 double aud = floor(paste_audio_length * fps) / fps;
1790 double vid = floor(paste_video_length * fps) / fps;
1791 double length = has_video && has_audio ?
1792 aud < vid ? aud : vid :
1794 has_audio ? aud : 0;
1795 paste_video_length = paste_audio_length = length;
1798 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1800 switch( mwindow->session->track_highlighted->data_type ) {
1801 case TRACK_VIDEO: length = paste_video_length; break;
1802 case TRACK_AUDIO: length = paste_audio_length; break;
1804 int64_t asset_length = mwindow->session->track_highlighted->
1805 to_units(length, 1);
1806 paste_audio_position = mwindow->session->track_highlighted->
1807 from_units(drop_edit_position(&insertion, NULL, asset_length));
1810 int64_t asset_length = mwindow->session->track_highlighted->
1811 to_units(paste_video_length, 1);
1812 paste_video_position = mwindow->session->track_highlighted->
1813 from_units(drop_edit_position(&insertion, NULL, asset_length));
1816 // Get destination track
1817 for(Track *dest = mwindow->session->track_highlighted;
1819 dest = dest->next) {
1820 if( dest->is_hidden() ) continue;
1821 if(dest->is_armed()) {
1822 // Get source width in pixels
1824 // Use start of highlighted edit
1825 if(mwindow->session->edit_highlighted) {
1826 position = mwindow->session->track_highlighted->from_units(
1827 mwindow->session->edit_highlighted->startproject);
1830 // Use end of highlighted track, disregarding effects
1831 position = mwindow->session->track_highlighted->from_units(
1832 mwindow->session->track_highlighted->edits->length());
1835 // Get the x coordinate
1836 x = Units::to_int64(position *
1837 mwindow->edl->session->sample_rate /
1838 mwindow->edl->local_session->zoom_sample) -
1839 mwindow->edl->local_session->view_start[pane->number];
1841 double paste_position = -1.;
1842 if(dest->data_type == TRACK_AUDIO) {
1843 if(indexable && current_atrack < indexable->get_audio_channels()) {
1844 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1845 w = Units::to_int64((double)indexable->get_audio_samples() /
1846 indexable->get_sample_rate() *
1847 mwindow->edl->session->sample_rate /
1848 mwindow->edl->local_session->zoom_sample);
1849 paste_position = paste_audio_position;
1851 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1852 w = Units::to_int64((double)clip->tracks->total_length() *
1853 mwindow->edl->session->sample_rate /
1854 mwindow->edl->local_session->zoom_sample);
1855 paste_position = paste_audio_position;
1856 //printf("draw_paste_destination %d\n", x);
1858 else if(mwindow->session->current_operation == DRAG_EDIT &&
1859 current_aedit < mwindow->session->drag_edits->total) {
1861 while(current_aedit < mwindow->session->drag_edits->total &&
1862 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1865 if(current_aedit < mwindow->session->drag_edits->total) {
1866 edit = mwindow->session->drag_edits->values[current_aedit];
1867 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1868 paste_position = mwindow->session->track_highlighted->
1869 from_units(drop_edit_position(&insertion,
1870 mwindow->session->drag_edit,
1871 mwindow->session->drag_edit->length));
1875 if( paste_position >= 0 ) {
1876 position = paste_position;
1883 else if(dest->data_type == TRACK_VIDEO) {
1884 //printf("draw_paste_destination 1\n");
1885 if(indexable && current_vtrack < indexable->get_video_layers())
1887 w = Units::to_int64((double)indexable->get_video_frames() /
1888 indexable->get_frame_rate() *
1889 mwindow->edl->session->sample_rate /
1890 mwindow->edl->local_session->zoom_sample);
1891 paste_position = paste_video_position;
1893 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1894 w = Units::to_int64(clip->tracks->total_length() *
1895 mwindow->edl->session->sample_rate /
1896 mwindow->edl->local_session->zoom_sample);
1897 paste_position = paste_video_position;
1899 else if(mwindow->session->current_operation == DRAG_EDIT &&
1900 current_vedit < mwindow->session->drag_edits->total) {
1902 while(current_vedit < mwindow->session->drag_edits->total &&
1903 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1906 if(current_vedit < mwindow->session->drag_edits->total) {
1907 edit = mwindow->session->drag_edits->values[current_vedit];
1908 w = Units::to_int64(edit->track->from_units(edit->length) *
1909 mwindow->edl->session->sample_rate /
1910 mwindow->edl->local_session->zoom_sample);
1911 paste_position = mwindow->session->track_highlighted->
1912 from_units(drop_edit_position(&insertion,
1913 mwindow->session->drag_edit,
1914 mwindow->session->drag_edit->length));
1918 if( paste_position >= 0 ) {
1919 position = paste_position;
1928 // Get the x coordinate
1929 x = Units::to_int64(position *
1930 mwindow->edl->session->sample_rate /
1931 mwindow->edl->local_session->zoom_sample) -
1932 mwindow->edl->local_session->view_start[pane->number];
1933 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1934 int h = dest->vertical_span(mwindow->theme);
1936 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1937 if(x < -BC_INFINITY) {
1938 w -= -BC_INFINITY - x;
1939 x += -BC_INFINITY - x;
1942 // if(pane->number == TOP_RIGHT_PANE)
1943 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1944 // __LINE__, x, y, w, h);
1946 draw_highlight_insertion(x, y, w, h);
1948 draw_highlight_rectangle(x, y, w, h);
1955 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1957 x = Units::round(plugin->track->from_units(plugin->startproject) *
1958 mwindow->edl->session->sample_rate /
1959 mwindow->edl->local_session->zoom_sample -
1960 mwindow->edl->local_session->view_start[pane->number]);
1961 w = Units::round(plugin->track->from_units(plugin->length) *
1962 mwindow->edl->session->sample_rate /
1963 mwindow->edl->local_session->zoom_sample);
1964 y = plugin->track->y_pixel
1965 - mwindow->edl->local_session->track_start[pane->number];
1966 if( plugin->track->show_titles() )
1967 y += mwindow->theme->get_image("title_bg_data")->get_h();
1968 if( plugin->track->show_assets() )
1969 y += plugin->track->data_h;
1970 y += plugin->plugin_set->get_number() *
1971 mwindow->theme->get_image("plugin_bg_data")->get_h();
1972 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1976 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1979 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1980 // just draw arrows, so user has indication that something is there
1981 // FIXME: get better colors
1985 draw_triangle_left(0, y + h /6,
1986 h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1991 draw_triangle_right(get_w() - h * 2/3, y + h /6,
1992 h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1996 // Fix bug in heroines & cvs version as of 22.8.2005:
1997 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1998 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1999 if(x < -10) { w += x - -10; x = -10; }
2000 if(y < -10) { h += y - -10; y = -10; }
2002 w = MIN(w, get_w() + 20);
2003 h = MIN(h, get_h() + 20);
2006 set_color(mwindow->preferences->highlight_inverse);
2008 //draw_rectangle(x, y, w, h);
2009 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
2010 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
2012 draw_rectangle(x, y, w, h);
2014 //if(pane->number == TOP_RIGHT_PANE)
2015 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
2018 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
2021 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
2022 // just draw arrows, so user has indication that something is there
2023 // FIXME: get better colors
2032 /* these don't look so good
2034 draw_line(x, y, x, y+h);
2035 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
2036 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
2037 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
2038 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
2040 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
2041 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
2043 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
2044 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
2045 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
2046 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
2048 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
2049 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
2051 // draw the box centred around x
2053 // Fix bug in heroines & cvs version as of 22.8.2005:
2054 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
2055 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
2056 if(x < -10) { w += x - -10; x = -10; }
2057 if(y < -10) { h += y - -10; y = -10; }
2058 w = MIN(w, get_w() + 20);
2059 h = MIN(h, get_h() + 20);
2060 set_color(mwindow->preferences->highlight_inverse);
2062 draw_rectangle(x, y, w, h);
2063 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
2065 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
2068 void TrackCanvas::draw_playback_cursor()
2070 // Called before playback_cursor exists
2071 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
2073 // mwindow->playback_cursor->visible = 0;
2074 // mwindow->playback_cursor->draw();
2078 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
2080 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
2081 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
2083 edit_dimensions(edit, x, y, w, h);
2085 if( edit->track->show_titles() )
2086 y += mwindow->theme->get_image("title_bg_data")->get_h();
2088 if(side == EDIT_OUT)
2095 void TrackCanvas::get_transition_coords(Edit *edit,
2096 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
2098 int transition_w = xS(30), transition_h = yS(30);
2099 int has_titles = edit->track->show_titles();
2100 int has_assets = edit->track->show_assets();
2101 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
2102 int data_h = edit->track->data_h;
2103 double ys = has_assets ? data_h : has_titles ? title_bg_h : 0;
2104 double dy = has_titles ?
2105 ( has_assets ? title_bg_h + data_h/2 : title_bg_h/2 ) :
2106 ( has_assets ? data_h/2 : 0) ;
2107 double title_h = mwindow->theme->title_h;
2108 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
2111 x -= transition_w / 2;
2112 y -= transition_h / 2;
2117 void TrackCanvas::draw_highlighting()
2122 switch(mwindow->session->current_operation)
2124 case DRAG_ATRANSITION:
2125 case DRAG_VTRANSITION:
2126 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
2127 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
2128 if(mwindow->session->edit_highlighted) {
2129 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
2130 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
2131 (mwindow->session->current_operation == DRAG_VTRANSITION &&
2132 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
2133 edit_dimensions(mwindow->session->edit_highlighted,
2135 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
2136 MWindowGUI::visible(y, y + h, 0, get_h())) {
2138 get_transition_coords(mwindow->session->edit_highlighted,
2145 // Dragging a new effect from the Resource window
2148 if(mwindow->session->track_highlighted &&
2149 ((mwindow->session->current_operation == DRAG_AEFFECT &&
2150 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
2151 (mwindow->session->current_operation == DRAG_VEFFECT &&
2152 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
2153 // Put it before another plugin
2154 if(mwindow->session->plugin_highlighted) {
2155 plugin_dimensions(mwindow->session->plugin_highlighted,
2157 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
2159 // Put it after a plugin set
2160 else if( mwindow->session->pluginset_highlighted &&
2161 mwindow->session->pluginset_highlighted->last ) {
2162 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
2164 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
2165 int64_t track_x, track_y, track_w, track_h;
2166 track_dimensions(mwindow->session->track_highlighted,
2167 track_x, track_y, track_w, track_h);
2171 mwindow->session->track_highlighted->get_length() *
2172 mwindow->edl->session->sample_rate /
2173 mwindow->edl->local_session->zoom_sample -
2174 mwindow->edl->local_session->view_start[pane->number]) -
2176 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
2177 if(w <= 0) w = track_w;
2180 track_dimensions(mwindow->session->track_highlighted,
2183 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
2184 // Put it in a new plugin set determined by the selected range
2185 if(mwindow->edl->local_session->get_selectionend() >
2186 mwindow->edl->local_session->get_selectionstart()) {
2187 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
2188 mwindow->edl->session->sample_rate /
2189 mwindow->edl->local_session->zoom_sample -
2190 mwindow->edl->local_session->view_start[pane->number]);
2191 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
2192 mwindow->edl->local_session->get_selectionstart()) *
2193 mwindow->edl->session->sample_rate /
2194 mwindow->edl->local_session->zoom_sample);
2196 // Put it in a new plugin set determined by an edit boundary
2197 else if(mwindow->session->edit_highlighted) {
2198 int64_t temp_y, temp_h;
2199 edit_dimensions(mwindow->session->edit_highlighted,
2200 x, temp_y, w, temp_h);
2202 // Put it at the beginning of the track in a new plugin set
2205 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
2206 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
2207 //printf("TrackCanvas::draw_highlighting 1\n");
2214 if(mwindow->session->track_highlighted) {
2215 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
2217 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
2219 draw_paste_destination();
2225 if(mwindow->session->track_highlighted) {
2226 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
2228 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
2229 draw_paste_destination();
2234 if( mwindow->session->track_highlighted && mwindow->session->drag_group &&
2235 mwindow->session->drag_group_edit && mwindow->session->drag_group_first_track ) {
2236 Track *track = mwindow->session->track_highlighted;
2237 EDL *drag_group = mwindow->session->drag_group;
2238 Track *edit_track = mwindow->session->drag_group_edit->track;
2239 Track *drag_track = mwindow->session->drag_group_first_track;
2240 while( track && edit_track && edit_track != drag_track ) {
2241 edit_track = edit_track->previous;
2242 track = track->previous;
2244 int cx = get_cursor_x();
2245 double cur_pos = mwindow->session->drag_group_position;
2246 double new_pos = mwindow->edl->get_cursor_position(cx, pane->number);
2247 new_pos -= mwindow->session->drag_position - cur_pos;
2248 new_pos = mwindow->edl->align_to_frame(new_pos, 0);
2249 double drop_position = new_pos;
2251 int ret = test_track_group(drag_group, track, new_pos);
2255 if( new_pos != drop_position ) {
2256 double pos = new_pos;
2257 pos += mwindow->session->drag_position - cur_pos;
2258 cx = mwindow->edl->get_position_cursorx(pos, pane->number);
2259 ret = test_track_group(drag_group, track, new_pos);
2261 color = ret > 0 ? YELLOW : shift_down() ? RED : BLUE;
2263 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
2264 int dx = cx - mwindow->session->drag_origin_x;
2265 int dy = y - mwindow->session->drag_origin_y;
2266 draw_selected_edits(mwindow->edl, dx, dy, color, -1);
2269 // Dragging an effect from the timeline
2270 case DRAG_AEFFECT_COPY:
2271 case DRAG_VEFFECT_COPY:
2272 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
2273 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
2274 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
2275 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
2276 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
2278 int64_t plugin_position = -1;
2279 Plugin *drag_plugin = mwindow->session->drag_plugin;
2280 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
2281 Track *hi_track = mwindow->session->track_highlighted;
2282 Edit *hi_edit = mwindow->session->edit_highlighted;
2283 // Put it into a silence zone
2284 if( hi_plugin_set && hi_plugin_set->last &&
2285 hi_plugin_set->track == drag_plugin->track ) {
2286 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
2287 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
2288 hi_track = drag_plugin->track;
2290 else if( hi_track ) {
2291 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
2292 track_dimensions(hi_track, x, y, w, h);
2293 plugin_position = hi_edit ? hi_edit->startproject : 0;
2296 if( plugin_position < 0 ) break;
2298 // Calculate length of plugin based on data type of track and units
2299 double zoom_scale = (double)mwindow->edl->session->sample_rate /
2300 mwindow->edl->local_session->zoom_sample;
2301 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
2302 mwindow->edl->local_session->view_start[pane->number];
2303 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
2305 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
2306 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
2312 case DRAG_PLUGINKEY:
2313 if(mwindow->session->plugin_highlighted &&
2314 mwindow->session->current_operation == DRAG_PLUGINKEY)
2316 // Just highlight the plugin
2317 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
2319 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
2320 MWindowGUI::visible(y, y + h, 0, get_h()))
2328 draw_speed_highlight();
2333 draw_highlight_rectangle(x, y, w, h);
2335 draw_selected_edits(mwindow->edl, 0, 0, GREEN+BLUE, RED);
2338 void TrackCanvas::draw_speed_highlight()
2340 FloatAuto *drag_speed = (FloatAuto*)mwindow->session->drag_auto;
2341 if( !drag_speed ) return;
2342 draw_speed_track(drag_speed->autos->track);
2343 ArrayList<Auto*> &speed_gang = *mwindow->session->drag_auto_gang;
2344 for( int i=0, sz=speed_gang.size(); i<sz; ++i ) {
2345 Track *track = speed_gang[i]->autos->track;
2346 if( track->is_hidden() ) continue;
2347 draw_speed_track(track);
2351 void TrackCanvas::draw_speed_track(Track *track)
2353 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2355 edit_dimensions(edit, x, y, w, h);
2356 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue;
2357 if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
2358 int color = 0xc00cc0;
2361 draw_selected(x, y, w, h);
2365 // x does not reliably draw a really big rectangle
2366 void TrackCanvas::draw_selected(int x, int y, int w, int h)
2368 int x1 = bmax(x, 0), x2 = bmin(x+w, get_w());
2369 if( x1 > x2 ) return;
2370 int y1 = bmax(y, 0), y2 = bmin(y+h, get_h());
2371 if( y1 > y2 ) return;
2372 if( x >= 0 && x < get_w() ) draw_line(x,y1, x,y2);
2373 if( x+w >= 0 && x+w < get_w() ) draw_line(x+w,y1, x+w,y2);
2374 if( y >= 0 && y < get_h() ) draw_line(x1,y, x2,y);
2375 if( y+h >= 0 && y+h < get_h() ) draw_line(x1,y+h, x2,y+h);
2378 void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1)
2381 for( Track *track=edl->tracks->first; track; track=track->next ) {
2382 if( track->is_hidden() ) continue;
2383 if( !track->is_armed() && color1 < 0 ) {
2385 dy -= track->vertical_span(mwindow->theme);
2388 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2389 if( !edit->is_selected ) continue;
2392 edit_dimensions(edit, x, y, w, h);
2394 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue;
2395 if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
2397 int inner = color1 < 0 ? color0 : !edit->group_id ? color0 :
2398 mwindow->get_group_color(edit->group_id);
2399 int outer = color1 < 0 ? color0 : !edit->group_id ? color1 : inner;
2400 set_color(track->is_armed() ? inner : outer);
2401 draw_selected(x, y, w, h);
2402 set_color(track->is_armed() ? outer : inner);
2403 draw_selected(x-1, y-1, w+2, h+2);
2404 draw_selected(x-2, y-2, w+1, h+1);
2409 void TrackCanvas::draw_plugins()
2411 char string[BCTEXTLEN];
2413 int current_show = 0;
2414 int current_preset = 0;
2416 for(int i = 0; i < plugin_on_toggles.total; i++)
2417 plugin_on_toggles.values[i]->in_use = 0;
2418 for(int i = 0; i < plugin_show_toggles.total; i++)
2419 plugin_show_toggles.values[i]->in_use = 0;
2420 for(int i = 0; i < preset_edit_buttons.total; i++)
2421 plugin_show_toggles.values[i]->in_use = 0;
2424 for(Track *track = mwindow->edl->tracks->first;
2426 track = track->next)
2428 if( track->is_hidden() ) continue;
2429 if(track->expand_view)
2431 for(int i = 0; i < track->plugin_set.total; i++)
2433 PluginSet *pluginset = track->plugin_set.values[i];
2435 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
2437 int64_t total_x, y, total_w, h;
2438 plugin_dimensions(plugin, total_x, y, total_w, h);
2440 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
2441 MWindowGUI::visible(y, y + h, 0, get_h()) &&
2442 plugin->plugin_type != PLUGIN_NONE)
2444 int x = total_x, w = total_w, left_margin = 5;
2445 int right_margin = 5;
2451 if(w + x > get_w()) w -= (w + x) - get_w();
2458 mwindow->theme->get_image("plugin_bg_data"),
2460 set_color(mwindow->theme->title_color);
2461 set_font(mwindow->theme->title_font);
2462 plugin->calculate_title(string, 0);
2464 // Truncate string to int64_test visible in background
2465 int len = strlen(string), j;
2466 for(j = len; j >= 0; j--)
2468 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
2476 // Justify the text on the left boundary of the edit if it is visible.
2477 // Otherwise justify it on the left side of the screen.
2478 int64_t text_x = total_x + left_margin;
2479 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
2480 text_x = MAX(left_margin, text_x);
2482 y + get_text_ascent(mwindow->theme->title_font) + 2,
2486 int64_t min_x = total_x + text_w;
2489 // Update plugin toggles
2490 int toggle_x = total_x + total_w;
2492 toggle_x = MIN(get_w() - right_margin, toggle_x);
2495 toggle_x -= PluginOn::calculate_w(mwindow) + xS(10);
2496 if(toggle_x > min_x)
2498 if(current_on >= plugin_on_toggles.total)
2500 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
2501 add_subwindow(plugin_on);
2502 plugin_on_toggles.append(plugin_on);
2506 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
2511 // Toggles for standalone plugins only
2512 if(plugin->plugin_type == PLUGIN_STANDALONE)
2515 toggle_x -= PluginShow::calculate_w(mwindow) + xS(10);
2516 if(toggle_x > min_x)
2518 if(current_show >= plugin_show_toggles.total)
2520 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
2521 add_subwindow(plugin_show);
2522 plugin_show_toggles.append(plugin_show);
2526 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
2530 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + xS(10);
2531 if(toggle_x > min_x)
2533 if(current_preset >= preset_edit_buttons.total)
2535 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
2536 add_subwindow(preset_edit);
2537 preset_edit_buttons.append(preset_edit);
2541 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
2552 // Remove unused toggles
2554 while(current_preset < preset_edit_buttons.total)
2556 preset_edit_buttons.remove_object_number(current_preset);
2558 while(current_show < plugin_show_toggles.total)
2560 plugin_show_toggles.remove_object_number(current_show);
2563 while(current_on < plugin_on_toggles.total)
2565 plugin_on_toggles.remove_object_number(current_on);
2569 void TrackCanvas::refresh_plugintoggles()
2571 for(int i = 0; i < plugin_on_toggles.total; i++)
2573 PluginOn *on = plugin_on_toggles.values[i];
2574 on->reposition_window(on->get_x(), on->get_y());
2576 for(int i = 0; i < plugin_show_toggles.total; i++)
2578 PluginShow *show = plugin_show_toggles.values[i];
2579 show->reposition_window(show->get_x(), show->get_y());
2581 for(int i = 0; i < preset_edit_buttons.total; i++)
2583 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
2584 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
2588 void TrackCanvas::draw_hard_edges()
2590 if( !mwindow->edl->session->auto_conf->hard_edges )
2594 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
2595 if( track->is_hidden() ) continue;
2596 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
2597 if( !edit->hard_left && !edit->hard_right ) continue;
2598 edit_dimensions(edit, x, y, w, h);
2599 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ||
2600 !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
2604 if( track->show_titles() )
2605 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
2606 if( track->show_assets() )
2607 y1 += track->data_h;
2609 y1 += mwindow->theme->title_h;
2610 if( edit->hard_left ) {
2611 ArrayList<int> xpt, ypt;
2612 xpt.append(x); ypt.append(y1);
2613 xpt.append(x+HANDLE_W); ypt.append(y1);
2614 xpt.append(x); ypt.append(y1-HANDLE_H);
2615 fill_polygon(&xpt, &ypt);
2617 if( edit->hard_right ) {
2618 ArrayList<int> xpt, ypt; int x1 = x+w-1;
2619 xpt.append(x1); ypt.append(y1);
2620 xpt.append(x1-HANDLE_W); ypt.append(y1);
2621 xpt.append(x1); ypt.append(y1-HANDLE_H);
2622 fill_polygon(&xpt, &ypt);
2628 void TrackCanvas::draw_inout_points()
2633 void TrackCanvas::draw_drag_handle()
2635 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 &&
2636 mwindow->session->current_operation != DRAG_PLUGINHANDLE2 &&
2637 mwindow->session->current_operation != DRAG_TRANSNHANDLE2 ) return;
2638 int64_t pixel1 = Units::round(mwindow->session->drag_position *
2639 mwindow->edl->session->sample_rate /
2640 mwindow->edl->local_session->zoom_sample -
2641 mwindow->edl->local_session->view_start[pane->number]);
2642 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
2644 draw_line(pixel1, 0, pixel1, get_h());
2647 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 ) return;
2648 if( !mwindow->session->drag_edit ) return;
2649 int group_id = mwindow->session->drag_edit->group_id;
2650 if( !group_id ) return;
2651 int64_t dx, dy, dw, dh;
2652 edit_dimensions(mwindow->session->drag_edit, dx, dy, dw, dh);
2653 int drag_handle = mwindow->session->drag_handle;
2654 int64_t pixel0 = !drag_handle ? dx : dx + dw;
2655 int delta = pixel1 - pixel0;
2656 set_color(LTPURPLE);
2659 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
2660 if( track->is_hidden() ) continue;
2661 Edit *left = 0, *right = 0;
2662 double start = DBL_MAX, end = DBL_MIN;
2663 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
2664 if( edit->group_id != group_id ) continue;
2665 double edit_start = edit->track->from_units(edit->startproject);
2666 if( edit_start < start ) { start = edit_start; left = edit; }
2667 double edit_end = edit->track->from_units(edit->startproject+edit->length);
2668 if( edit_end > end ) { end = edit_end; right = edit; }
2670 Edit *edit = !drag_handle ? left : right;
2671 if( !edit ) continue;
2672 Indexable *idxbl = edit->asset;
2673 if( !idxbl ) idxbl = edit->nested_edl;
2674 int can_drag = idxbl ? 1 : 0;
2676 int64_t source_len = !idxbl ? -1 :
2677 edit->track->data_type == TRACK_AUDIO ?
2678 idxbl->get_audio_samples() :
2679 edit->track->data_type == TRACK_VIDEO ?
2680 idxbl->get_video_frames() : -1;
2681 int64_t speed_start = edit->startproject;
2682 int64_t speed_end = speed_start + edit->length;
2683 int64_t speed_length = track->speed_length(speed_start, speed_end);
2684 if( edit->startsource + speed_length >= source_len )
2687 else if( !edit->startsource )
2690 edit_dimensions(edit, x, y, w, h);
2691 if( y+h < 0 || y >= get_h() ) continue;
2692 int edge_x = !drag_handle ? x : x + w;
2693 int edge_y = y + h/2, xs10 = xS(10), ys10 = yS(10);
2694 if( edge_x >= 0 && edge_x < get_w() ) {
2696 draw_line(edge_x-xs10,edge_y-ys10, edge_x+xs10,edge_y+ys10);
2697 draw_line(edge_x-xs10,edge_y+ys10, edge_x+xs10,edge_y-ys10);
2699 else if( !drag_handle ) {
2700 draw_line(edge_x+xs10,edge_y-ys10, edge_x,edge_y);
2701 draw_line(edge_x+xs10,edge_y+ys10, edge_x,edge_y);
2704 draw_line(edge_x,edge_y, edge_x-xs10,edge_y-ys10);
2705 draw_line(edge_x,edge_y, edge_x-xs10,edge_y+ys10);
2709 if( edge_x >= 0 && edge_x < get_w() ) {
2710 draw_line(edge_x, y, edge_x, y+h);
2717 void TrackCanvas::draw_transitions()
2720 if( !mwindow->edl->session->auto_conf->transitions ) return;
2722 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
2723 if( track->is_hidden() ) continue;
2724 if( !track->show_transitions() ) continue;
2726 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
2727 if(!edit->transition) continue;
2728 edit_dimensions(edit, x, y, w, h);
2729 int strip_x = x, edit_y = y;
2730 get_transition_coords(edit, x, y, w, h);
2731 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
2732 if( track->show_assets() && track->show_titles() )
2733 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
2734 if( strip_y < edit_y ) strip_y = edit_y;
2736 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
2737 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
2738 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
2739 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
2740 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
2742 if( !server ) continue;
2743 VFrame *picon = server->get_picon();
2744 if( !picon ) continue;
2745 int picon_w = picon->get_w(), picon_h = picon->get_h();
2746 int track_h = edit->track->vertical_span(mwindow->theme);
2747 if( picon_h > track_h ) picon_h = track_h;
2748 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
2750 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
2751 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
2752 int x = strip_x, w = strip_w;
2753 if( x < 0 ) { w -= -x; x = 0; }
2754 if( w + x > get_w() ) w -= (w + x) - get_w();
2756 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
2757 mwindow->theme->get_image("plugin_bg_data"), 0);
2763 void TrackCanvas::draw_loop_points()
2765 //printf("TrackCanvas::draw_loop_points 1\n");
2766 if(mwindow->edl->local_session->loop_playback)
2768 //printf("TrackCanvas::draw_loop_points 2\n");
2769 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
2770 mwindow->edl->session->sample_rate /
2771 mwindow->edl->local_session->zoom_sample -
2772 mwindow->edl->local_session->view_start[pane->number]);
2773 //printf("TrackCanvas::draw_loop_points 3\n");
2775 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2778 draw_line(x, 0, x, get_h());
2780 //printf("TrackCanvas::draw_loop_points 4\n");
2782 x = Units::round(mwindow->edl->local_session->loop_end *
2783 mwindow->edl->session->sample_rate /
2784 mwindow->edl->local_session->zoom_sample -
2785 mwindow->edl->local_session->view_start[pane->number]);
2786 //printf("TrackCanvas::draw_loop_points 5\n");
2788 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2791 draw_line(x, 0, x, get_h());
2793 //printf("TrackCanvas::draw_loop_points 6\n");
2795 //printf("TrackCanvas::draw_loop_points 7\n");
2798 void TrackCanvas::draw_brender_range()
2800 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
2801 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
2802 if( mwindow->edl->session->brender_end > 0 )
2804 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
2805 mwindow->edl->session->sample_rate /
2806 mwindow->edl->local_session->zoom_sample -
2807 mwindow->edl->local_session->view_start[pane->number]);
2808 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
2811 draw_line(x1, 0, x1, get_h());
2813 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
2814 mwindow->edl->session->sample_rate /
2815 mwindow->edl->local_session->zoom_sample -
2816 mwindow->edl->local_session->view_start[pane->number]);
2818 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
2821 draw_line(x2, 0, x2, get_h());
2826 // The operations which correspond to each automation type
2827 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
2843 // The buttonpress operations, so nothing changes unless the mouse moves
2844 // a certain amount. This allows the keyframe to be used to position the
2845 // insertion point without moving itself.
2846 static int pre_auto_operations[AUTOMATION_TOTAL] =
2863 int TrackCanvas::do_keyframes(int cursor_x,
2871 // Note: button 3 (right mouse button) is not eaten to allow
2872 // track context menu to appear
2874 EDLSession *session = mwindow->edl->session;
2875 int gang = mwindow->edl->local_session->gang_tracks != GANG_NONE ||
2876 get_double_click() ? 1 : 0;
2878 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
2880 0, 0, 0, 0, 0, 0, 0, 0,
2882 modekeyframe_pixmap,
2883 maskkeyframe_pixmap,
2889 for(Track *track = mwindow->edl->tracks->first;
2891 track = track->next) {
2892 if( track->is_hidden() ) continue;
2893 Auto *auto_keyframe = 0;
2894 Automation *automation = track->automation;
2897 // Handle keyframes in reverse drawing order if a button press
2899 int end = AUTOMATION_TOTAL;
2903 start = AUTOMATION_TOTAL - 1;
2907 for(int i = start; i != end && !result; i += step)
2909 // Event not trapped and automation visible
2910 Autos *autos = automation->autos[i];
2911 if(!result && session->auto_conf->autos[i] && autos) {
2913 case AUTOMATION_MODE:
2914 case AUTOMATION_PAN:
2915 case AUTOMATION_MASK:
2916 result = do_autos(track, automation->autos[i],
2917 cursor_x, cursor_y, draw,
2918 buttonpress, auto_pixmaps[i],
2919 auto_keyframe, rerender);
2923 switch(autos->get_type()) {
2924 case Autos::AUTOMATION_TYPE_FLOAT: {
2925 Automation automation(0, track);
2926 int grouptype = automation.autogrouptype(i, track);
2927 if( buttonpress && i == AUTOMATION_SPEED ) {
2928 mwindow->speed_before();
2931 if(draw) // Do dropshadow
2932 result = do_float_autos(track, autos,
2933 cursor_x, cursor_y, draw,
2934 buttonpress, 1, 1, MDGREY,
2935 auto_keyframe, grouptype);
2936 result = do_float_autos(track, autos,
2937 cursor_x, cursor_y, draw, buttonpress,
2938 0, 0, GWindowGUI::auto_colors[i],
2939 auto_keyframe, grouptype);
2941 if( !result && buttonpress && i == AUTOMATION_SPEED )
2942 mwindow->speed_after(-1, 0);
2943 if( result && buttonpress ) {
2944 int color = GWindowGUI::auto_colors[i];
2945 mwindow->gui->zoombar->update_autozoom(grouptype, color);
2949 case Autos::AUTOMATION_TYPE_INT: {
2950 if(draw) // Do dropshadow
2951 result = do_int_autos(track, autos,
2952 cursor_x, cursor_y, draw,
2953 buttonpress, 1, 1, MDGREY,
2955 result = do_int_autos(track, autos,
2956 cursor_x, cursor_y, draw, buttonpress,
2957 0, 0, GWindowGUI::auto_colors[i],
2966 if(mwindow->session->current_operation == auto_operations[i])
2969 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2971 // mwindow->session->current_operation,
2972 // auto_operations[i]);
2975 if (buttonpress == 2 && auto_keyframe )
2977 double position = track->from_units(auto_keyframe->position);
2978 mwindow->edl->local_session->set_selectionstart(position);
2979 mwindow->edl->local_session->set_selectionend(position);
2981 if (buttonpress != 3)
2983 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2984 fill_ganged_autos(gang, 0, track,
2985 (FloatAuto*)mwindow->session->drag_auto);
2986 mwindow->session->current_operation = pre_auto_operations[i];
2987 update_drag_caption();
2990 else if( auto_keyframe )
2992 gui->keyframe_menu->update(automation,
2995 gui->keyframe_menu->activate_menu();
2996 rerender = 1; // the position changes
3000 gui->keyframe_hide->update(autos);
3001 gui->keyframe_hide->activate_menu();
3002 rerender = 1; // the position changes
3004 if(buttonpress == 1 && ctrl_down() &&
3005 AUTOMATION_TYPE_FLOAT == autos->get_type())
3006 rerender = 1; // special case: curve mode changed
3012 if(!result && session->auto_conf->plugins) {
3015 result = do_plugin_autos(track, cursor_x, cursor_y,
3016 draw, buttonpress, plugin, keyframe);
3017 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
3020 if(result && (buttonpress == 1)) {
3021 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
3022 update_drag_caption();
3025 else if (result && (buttonpress == 3)) {
3026 gui->keyframe_menu->update(plugin, keyframe);
3027 gui->keyframe_menu->activate_menu();
3028 rerender = 1; // the position changes
3033 // Final pass to trap event
3034 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
3035 if(mwindow->session->current_operation == pre_auto_operations[i] ||
3036 mwindow->session->current_operation == auto_operations[i]) {
3042 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
3043 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
3049 new_cursor = UPRIGHT_ARROW_CURSOR;
3055 void TrackCanvas::draw_keyframe_reticle()
3057 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
3058 if( keyframe_hairline == HAIRLINE_NEVER ) return;
3060 int current_op = mwindow->session->current_operation, dragging = 0;
3061 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
3062 if( current_op == auto_operations[i] ) dragging = 1;
3063 if( dragging && !mwindow->session->drag_auto ) dragging = 0;
3065 int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
3066 mwindow->session->drag_auto->autos->autoidx : -1;
3068 if( get_buttonpress() == LEFT_BUTTON && dragging &&
3069 keyframe_hairline == HAIRLINE_DRAGGING ) {
3070 draw_hairline(mwindow->session->drag_auto, RED, 1);
3074 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == MIDDLE_BUTTON &&
3075 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
3076 int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
3077 for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
3078 if( track->is_hidden() ) continue;
3079 Automation *automation = track->automation;
3080 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
3081 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
3082 // automation visible
3083 Autos *autos = automation->autos[i];
3084 if( !autos ) continue;
3085 if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
3086 for( Auto *auto_keyframe=autos->first; auto_keyframe;
3087 auto_keyframe = auto_keyframe->next ) {
3088 draw_hairline(auto_keyframe, BLUE, show);
3094 draw_hairline(mwindow->session->drag_auto, RED, 1);
3098 void TrackCanvas::draw_auto(Auto *current, int x, int y,
3099 int center_pixel, int data_h)
3103 x1 = x - HANDLE_W / 2;
3104 x2 = x + HANDLE_W / 2;
3105 y1 = center_pixel + y - HANDLE_W / 2;
3106 y2 = center_pixel + y + HANDLE_W / 2;
3108 if( y1 < center_pixel - data_h/2 ) y1 = center_pixel - data_h/2;
3109 if( y2 > center_pixel + data_h/2 ) y2 = center_pixel + data_h/2;
3111 draw_box(x1, y1, x2 - x1, y2 - y1);
3115 // This draws lines for bezier in & out controls
3116 void TrackCanvas::draw_cropped_line(int x1,
3125 // Don't care about x since it is clipped by the window.
3126 // Put y coords in ascending order
3128 y2 ^= y1; y1 ^= y2; y2 ^= y1;
3129 x2 ^= x1; x1 ^= x2; x2 ^= x1;
3134 double slope = (double)(x2 - x1) / (y2 - y1);
3135 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
3137 x1 = (int)(x1 + (min_y - y1) * slope);
3140 else if(y1 >= max_y) {
3141 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
3146 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
3149 else if(y2 < min_y) {
3150 x2 = (int)(x2 + (min_y - y2) * slope);
3155 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
3156 if( y1 >= min_y && y1 < max_y &&
3157 y2 >= min_y && y2 < max_y )
3158 draw_line(x1, y1, x2, y2);
3162 void TrackCanvas::draw_floatauto(FloatAuto *current,
3163 int x_offset, int center_pixel, int data_h, int color,
3164 double unit_start, double zoom_units, double yscale,
3168 calculate_auto_position(1, &xx, &yy, 0, 0, 0, 0,
3169 current, unit_start, zoom_units, yscale, autogrouptype);
3170 int x = (int)xx + x_offset;
3171 int x1 = x - HANDLE_W / 2; // Center
3172 int x2 = x + HANDLE_W / 2;
3173 int y = (int)yy + center_pixel;
3174 int y1 = y - HANDLE_H / 2;
3175 int y2 = y + HANDLE_H / 2;
3176 int ymin = center_pixel - data_h / 2;
3177 int ymax = center_pixel + data_h / 2;
3178 CLAMP(y1, ymin, ymax);
3179 CLAMP(y2, ymin, ymax);
3182 if( current->curve_mode == FloatAuto::LINEAR ) {
3183 draw_box(x1, y1, x2 - x1, y2 - y1);
3186 ArrayList<int> polygon_x;
3187 ArrayList<int> polygon_y;
3188 polygon_x.append((x1 + x2) / 2 + 1);
3189 polygon_y.append(y1 + 1);
3190 polygon_x.append(x2 + 1);
3191 polygon_y.append((y1 + y2) / 2 + 1);
3192 polygon_x.append((x1 + x2) / 2 + 1);
3193 polygon_y.append(y2 + 1);
3194 polygon_x.append(x1 + 1);
3195 polygon_y.append((y1 + y2) / 2 + 1);
3196 fill_polygon(&polygon_x, &polygon_y);
3200 // show bezier control points (only) if this
3201 // floatauto doesn't adjust it's tangents automatically
3202 if(current->curve_mode != FloatAuto::FREE &&
3203 current->curve_mode != FloatAuto::TFREE &&
3204 current->curve_mode != FloatAuto::BUMP)
3206 double in_xx, in_yy, out_xx, out_yy;
3207 calculate_auto_position(1, &xx, &yy, &in_xx, &in_yy, 0, 0,
3208 current, unit_start, zoom_units, yscale, autogrouptype);
3209 int ix = xx, iy = yy, in_x = in_xx, in_y = in_yy;
3211 draw_floatauto_ctrlpoint(ix, iy, in_x, in_y, center_pixel, data_h, color);
3212 calculate_auto_position(0, &xx, &yy, 0, 0, &out_xx, &out_yy,
3213 current, unit_start, zoom_units, yscale, autogrouptype);
3214 int ox = xx, oy = yy, out_x = out_xx, out_y = out_yy;
3216 draw_floatauto_ctrlpoint(ox, oy, out_x, out_y, center_pixel, data_h, color);
3217 if( current->curve_mode == FloatAuto::BUMP && iy != oy )
3218 draw_bline(ix, iy+center_pixel, ox, oy+center_pixel);
3221 inline int quantize(float f) { return (int)floor(f + 0.5); }
3223 inline void TrackCanvas::draw_floatauto_ctrlpoint(
3224 int x, int y, int cp_x, int cp_y, int center_pixel,
3225 int data_h, int color)
3226 // draw the tangent and a handle for given bézier ctrl point
3228 bool handle_visible = (abs(cp_y) <= data_h/2);
3230 float slope = (float)(cp_y - y)/(cp_x - x);
3231 CLAMP(cp_y, -data_h/2, data_h/2);
3233 cp_x = x + quantize((cp_y - y) / slope);
3236 cp_y += center_pixel;
3238 // drawing the tangent as a dashed line...
3239 int const dash = HANDLE_W;
3240 int const gap = HANDLE_W / 2;
3241 float sx = 3 * (cp_x - x) / 4.;
3244 // q is the x displacement for a unit line of slope
3245 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
3247 float dist = 1/q * sx;
3253 float sy = slope * sx, ey = slope * ex;
3254 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
3261 int r = HANDLE_W / 2;
3262 int cp_x1 = cp_x - r;
3263 int cp_y1 = cp_y - r;
3265 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
3267 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
3272 int TrackCanvas::test_auto(Auto *current,
3273 int x, int y, int center_pixel, int data_h,
3274 int cursor_x, int cursor_y, int buttonpress)
3279 x1 = x - HANDLE_W / 2;
3280 x2 = x + HANDLE_W / 2;
3281 y1 = center_pixel + y - HANDLE_H / 2;
3282 y2 = center_pixel + y + HANDLE_H / 2;
3283 int ymin = center_pixel - data_h/2;
3284 int ymax = center_pixel + data_h/2;
3285 CLAMP(y1, ymin, ymax);
3286 CLAMP(y2, ymin, ymax);
3288 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
3290 if(buttonpress && buttonpress != 3)
3292 mwindow->session->drag_auto = current;
3293 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
3294 // Toggle Autos don't respond to vertical zoom, they always show up
3295 // with "on" == 100% == line on top
3296 mwindow->session->drag_start_position = current->position;
3297 mwindow->session->drag_origin_x = cursor_x;
3298 mwindow->session->drag_origin_y = cursor_y;
3303 if(buttonpress && buttonpress != 3 && result)
3305 //printf("TrackCanvas::test_auto %d\n", __LINE__);
3306 mwindow->undo->update_undo_before();
3312 // some Helpers for test_floatauto(..)
3313 // and for dragging the tangents/ctrl points
3314 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
3315 float cursor_x, float cursor_y)
3317 // Control point switched off?
3318 if( x0 == ctrl_x ) return 0.0;
3319 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
3320 double x = cursor_x-x0, y = cursor_y-y0;
3321 // wrong side of ctrl handle
3322 if( x*x1 < 0 ) return 0.0;
3323 // outside handle radius
3324 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
3325 double xx1 = x1*x1, yy1 = y1*y1;
3326 double xx = x*x, yy = y*y;
3327 // distance squared from cursor to cursor projected to line from ctrl to handle
3328 // along a line perpendicular to line from ctrl to handle (closest approach)
3329 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
3330 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
3331 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
3336 float levered_position(float position, float ref_pos)
3338 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
3340 return ref_pos / position;
3344 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
3345 // transforms automation value into current display coords,
3346 // dependant on current automation display range for the given kind of automation
3348 if(!mwindow || !mwindow->edl) return 0;
3349 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3350 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3351 float automation_range = automation_max - automation_min;
3352 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
3354 return (auto_value - automation_min) / automation_range;
3359 int TrackCanvas::test_floatauto(FloatAuto *current, int buttonpress,
3360 int center_pixel, int data_h, int cursor_x, int cursor_y,
3361 double unit_start, double zoom_units, double yscale,
3365 double xx, yy, in_xx, in_yy, out_xx, out_yy;
3366 calculate_auto_position(1, &xx, &yy, &in_xx, &in_yy, 0, 0,
3367 current, unit_start, zoom_units, yscale, autogrouptype);
3368 int ix = xx, iy = yy, in_x = in_xx, in_y = in_yy;
3370 int x1 = ix - HANDLE_W / 2;
3371 int x2 = ix + HANDLE_W / 2;
3372 int y1 = center_pixel + iy - HANDLE_W / 2;
3373 int y2 = center_pixel + iy + HANDLE_W / 2;
3374 int ymin = center_pixel - data_h/2;
3375 int ymax = center_pixel + data_h/2;
3376 CLAMP(y1, ymin, ymax);
3377 CLAMP(y2, ymin, ymax);
3379 int in_x1 = in_x - HANDLE_W / 2;
3380 int in_x2 = in_x + HANDLE_W / 2;
3381 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
3382 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
3383 CLAMP(in_y1, ymin, ymax);
3384 CLAMP(in_y2, ymin, ymax);
3386 calculate_auto_position(0, &xx, &yy, 0, 0, &out_xx, &out_yy,
3387 current, unit_start, zoom_units, yscale, autogrouptype);
3388 int ox = xx, oy = yy, out_x = out_xx, out_y = out_yy;
3389 int out_x1 = out_x - HANDLE_W / 2;
3390 int out_x2 = out_x + HANDLE_W / 2;
3391 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
3392 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
3393 CLAMP(out_y1, ymin, ymax);
3394 CLAMP(out_y2, ymin, ymax);
3397 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
3398 // buttonpress could be the start of a drag operation
3399 #define INIT_DRAG(POS,VAL) \
3400 mwindow->session->drag_auto = current; \
3401 mwindow->session->drag_origin_x = cursor_x; \
3402 mwindow->session->drag_origin_y = cursor_y; \
3403 mwindow->session->drag_start_position = (POS); \
3404 mwindow->session->drag_start_percentage = (VAL);
3406 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
3409 // without modifier we are manipulating the automation node
3410 // with ALT it's about dragging only the value of the node
3411 // with SHIFT the value snaps to the value of neighbouring nodes
3412 // CTRL indicates we are rather manipulating the tangent(s) of the node
3416 if( WITHIN(x1,x2,y1,y2))
3417 { // cursor hits node
3420 if(buttonpress && (buttonpress != 3))
3422 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
3423 mwindow->session->drag_handle = 0;
3428 if( WITHIN(x1,x2,y1,y2))
3431 if(buttonpress && (buttonpress != 3))
3433 // could be ctrl-click or ctrl-drag
3434 // click would cycle through tangent modes
3435 ((FloatAuto*)current)->toggle_curve_mode();
3437 // drag will start dragging the tangent, if applicable
3438 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
3439 mwindow->session->drag_handle = 0;
3443 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
3446 if( in_x != ix && current->position > 0 &&
3447 (FloatAuto::FREE == current->curve_mode ||
3448 FloatAuto::TFREE == current->curve_mode ||
3449 FloatAuto::BUMP == current->curve_mode))
3450 // act on in control handle only if
3451 // tangent is significant and is editable (not automatically choosen)
3453 lever = test_curve_line(ix, iy, in_x, in_y, cursor_x, cursor_y-center_pixel);
3454 // either cursor in ctrl-point handle or cursor on tangent line
3455 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
3457 if(buttonpress && (buttonpress != 3)) {
3458 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
3460 mwindow->session->drag_handle = 1;
3461 float new_invalue = current->get_value() + lever * current->get_control_in_value();
3462 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
3463 value_to_percentage(new_invalue, autogrouptype))
3470 (FloatAuto::FREE == current->curve_mode ||
3471 FloatAuto::TFREE == current->curve_mode ||
3472 FloatAuto::BUMP == current->curve_mode))
3473 // act on out control only if tangent is significant and is editable
3475 lever = test_curve_line(ox, oy, out_x, out_y, cursor_x, cursor_y-center_pixel);
3476 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
3478 if(buttonpress && (buttonpress != 3)) {
3479 if(lever == 0.0) lever=1.0;
3481 mwindow->session->drag_handle = 2;
3482 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
3483 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
3484 value_to_percentage(new_outvalue, autogrouptype))
3488 } // end ctrl_down()
3494 // printf("TrackCanvas::test_floatauto 2 drag_handle=%d ctrl_down=%d cursor_x=%d cursor_y=%d x1=%d x2=%d y1=%d y2=%d\n",
3495 // mwindow->session->drag_handle,
3500 if(buttonpress && (buttonpress != 3) && result)
3502 mwindow->undo->update_undo_before();
3503 double position = current->autos->track->from_units(current->position);
3504 mwindow->edl->local_session->set_selectionstart(position);
3505 mwindow->edl->local_session->set_selectionend(position);
3511 static int is_linear(FloatAuto *prev, FloatAuto *next)
3513 if( !prev || !next ) return 0;
3514 if( prev->curve_mode == FloatAuto::LINEAR ) return 1;
3515 int64_t ipos = prev->get_control_in_position();
3516 int64_t opos = prev->get_control_out_position();
3517 if( !ipos && !opos ) return 1;
3518 if( !ipos || !opos ) return 0;
3519 float ival = next->get_control_in_value();
3520 float oval = prev->get_control_out_value();
3521 float cval = prev->get_value(0), nval = next->get_value(1);
3522 if( !ival && !oval && EQUIV(cval, nval) ) return 1;
3523 float ig = ival / ipos, og = oval / opos;
3524 int64_t cpos = prev->position, npos = next->position;
3525 float g = (nval - cval) / (npos - cpos);
3526 if( !EQUIV(g, 0) && EQUIV(ig, g) && EQUIV(og, g) ) return 1;
3530 // Get the float value & y for position x on the canvas
3531 #define X_TO_FLOATLINE(x) \
3532 double position = unit_start + x * zoom_units; \
3533 int64_t position1 = (int64_t)position, position2 = position1 + 1; \
3534 /* Call by reference fails for some reason here */ \
3535 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
3536 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
3537 double value = value1 + (value2 - value1) * (position - position1); \
3538 AUTOMATIONCLAMPS(value, autogrouptype); \
3539 int y = center_pixel + \
3540 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
3543 void TrackCanvas::draw_floatline(int center_pixel,
3544 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
3545 double unit_start, double zoom_units, double yscale,
3546 int x1, int y1, int x2, int y2,
3547 int color, int autogrouptype)
3549 int ytop = center_pixel - yscale / 2;
3550 int ybot = center_pixel + yscale / 2 - 1;
3551 y1 += center_pixel; y2 += center_pixel;
3552 if( (y1 < ytop && y1 >= ybot) && (y2 < ytop || y2 >= ybot) ) return;
3553 // check for line draw
3554 if( is_linear(previous, next) ) {
3555 if( previous && previous->curve_mode == FloatAuto::BUMP ) {
3557 calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0, previous,
3558 unit_start, zoom_units, yscale, autogrouptype);
3559 x1 = ax; y1 = ay; y1 += center_pixel;
3561 draw_line(x1, y1, x2, y2);
3565 // Solve bezier equation for either every pixel or a certain large number of
3568 // Not using slope intercept
3573 // Call by reference fails for some reason here
3574 FloatAuto *previous1 = previous, *next1 = next;
3575 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3576 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3577 float automation_range = automation_max - automation_min;
3578 if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN )
3579 automation_range = SPEED_MIN;
3580 for( int x=x1; x<x2; ++x ) {
3581 // Interpolate value between frames
3584 if( /* x > x1 && */ y >= ytop && y < ybot ) {
3585 int x1 = x-1, y1 = prev_y, x2 = x, y2 = y;
3586 if( abs(y2-y1) < 2 )
3589 draw_bline(x1, y1, x2, y2);
3596 int TrackCanvas::test_floatline(int center_pixel,
3611 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3612 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3613 float automation_range = automation_max - automation_min;
3614 if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN )
3615 automation_range = SPEED_MIN;
3616 FloatAuto *previous1 = 0, *next1 = 0;
3617 X_TO_FLOATLINE(cursor_x);
3619 if(cursor_x >= x1 &&
3621 cursor_y >= y - HANDLE_W / 2 &&
3622 cursor_y < y + HANDLE_W / 2 &&
3628 if(buttonpress == 3)
3636 mwindow->undo->update_undo_before();
3637 double position = autos->track->from_units(position1);
3638 position = mwindow->edl->align_to_frame(position, 0);
3639 int64_t new_position = autos->track->to_units(position,0);
3640 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
3641 ((FloatAuto*)current)->set_value(value);
3642 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
3643 mwindow->session->drag_start_position = current->position;
3644 mwindow->session->drag_origin_x = cursor_x;
3645 mwindow->session->drag_origin_y = cursor_y;
3646 mwindow->session->drag_handle = 0;
3654 // gang=-1 for keyframepopup update, all tracks where fautos exist
3655 // gang=0 for trackcanvas drag update, all gang matching tracks, create new fautos if needed
3656 // gang=1 for trackcanvas drag update, all gang tracks, create new fautos if needed
3657 void TrackCanvas::fill_ganged_autos(int gang, float change, Track *skip, FloatAuto *fauto)
3659 if( !skip->is_ganged() ) return;
3660 // Handles the special case of modifying a fadeauto
3661 // when there are ganged faders on several tracks
3662 double position = skip->from_units(fauto->position);
3663 int autoidx = fauto->autos->autoidx;
3664 PatchGUI *patch = gang < 0 ? pane->patchbay->get_patch_of(skip) : 0;
3665 int edge = patch ? patch->edge : 0;
3666 int span = patch ? patch->span : 0;
3667 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
3668 if( current == skip || !current->is_armed() ) continue;
3669 if( !gang && current->data_type != skip->data_type ) continue;
3670 if( skip->armed_gang(current) || get_double_click() ) {
3671 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
3672 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
3673 int64_t current_position = current->to_units(position, 1);
3675 // keyframe exists, just change it
3676 keyframe->bump_update(current_position, change, edge, span);
3678 else if( gang >= 0 ) {
3679 // create keyframe on neighbouring track at the point in time given by fauto
3680 FloatAuto *previous = 0, *next = 0;
3681 float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
3682 float new_value = value + change;
3683 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
3684 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
3685 bclamp(new_value, auto_min, auto_max);
3686 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
3687 keyframe->set_value(new_value, edge);
3691 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
3696 void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
3698 double position = skip->from_units(fauto->position);
3700 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
3701 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
3702 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
3703 keyframe->bump_update(keyframe_position, change, 0, 0);
3704 keyframe->set_control_in_value(fauto->get_control_in_value());
3705 keyframe->set_control_out_value(fauto->get_control_out_value());
3709 void TrackCanvas::clear_ganged_autos()
3712 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
3713 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
3714 keyframe->autos->remove_nonsequential(keyframe);
3716 mwindow->session->drag_auto_gang->remove_all();
3720 void TrackCanvas::draw_toggleline(int center_pixel,
3726 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
3730 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
3734 int TrackCanvas::test_toggleline(Autos *autos,
3745 if(cursor_x >= x1 && cursor_x < x2)
3747 int miny = center_pixel + y1 - HANDLE_W / 2;
3748 int maxy = center_pixel + y1 + HANDLE_W / 2;
3749 if(cursor_y >= miny && cursor_y < maxy)
3754 if(buttonpress == 3)
3762 double position = (double)(cursor_x +
3763 mwindow->edl->local_session->view_start[pane->number]) *
3764 mwindow->edl->local_session->zoom_sample /
3765 mwindow->edl->session->sample_rate;
3766 int64_t unit_position = autos->track->to_units(position, 0);
3767 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
3769 mwindow->undo->update_undo_before();
3771 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
3772 ((IntAuto*)current)->value = new_value;
3773 // Toggle Autos don't respond to vertical zoom, they always show up
3774 // with "on" == 100% == line on top
3775 mwindow->session->drag_start_percentage = (float)new_value;
3776 mwindow->session->drag_start_position = current->position;
3777 mwindow->session->drag_origin_x = cursor_x;
3778 mwindow->session->drag_origin_y = cursor_y;
3786 void TrackCanvas::calculate_viewport(Track *track,
3787 double &view_start, // Seconds
3789 double &view_end, // Seconds
3793 double &zoom_sample,
3797 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
3798 mwindow->edl->local_session->zoom_sample /
3799 mwindow->edl->session->sample_rate;
3800 unit_start = track->to_doubleunits(view_start);
3801 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
3803 mwindow->edl->local_session->zoom_sample /
3804 mwindow->edl->session->sample_rate;
3805 unit_end = track->to_doubleunits(view_end);
3807 int y = track->y_pixel
3808 - mwindow->edl->local_session->track_start[pane->number];
3809 int has_titles = track->show_titles();
3810 int has_assets = track->show_assets();
3811 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
3812 double title_h = mwindow->theme->title_h;
3813 double data_h = track->data_h;
3814 double ys = has_assets ? data_h : has_titles ? title_bg_h : 0;
3815 double dy = has_titles ?
3816 ( has_assets ? title_bg_h + data_h/2 : title_bg_h/2) :
3817 ( has_assets ? data_h/2 : 0) ;
3818 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
3820 center_pixel = y + dy;
3822 zoom_sample = mwindow->edl->local_session->zoom_sample;
3823 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
3826 float TrackCanvas::percentage_to_value(float percentage,
3834 if(percentage > 0.5)
3841 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3842 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3843 float automation_range = automation_max - automation_min;
3845 result = percentage * automation_range + automation_min;
3848 FloatAuto *ptr = (FloatAuto*)reference;
3849 result -= ptr->get_value();
3851 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
3857 void TrackCanvas::calculate_auto_position(int edge, double *x, double *y,
3858 double *in_x, double *in_y, double *out_x, double *out_y,
3859 Auto *current, double unit_start, double zoom_units, double yscale,
3862 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3863 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3864 float automation_range = automation_max - automation_min;
3865 if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN )
3866 automation_range = SPEED_MIN;
3867 FloatAuto *ptr = (FloatAuto*)current;
3868 *x = (double)(ptr->position - unit_start) / zoom_units;
3869 *y = ((ptr->get_value(edge) - automation_min) / automation_range - 0.5) * -yscale;
3872 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
3873 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
3877 *in_y = (((ptr->get_value(edge) + ptr->get_control_in_value()) -
3878 automation_min) / automation_range - 0.5) * -yscale;
3882 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
3883 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
3887 *out_y = (((ptr->get_value(edge) + ptr->get_control_out_value()) -
3888 automation_min) / automation_range - 0.5) * -yscale;
3893 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
3894 int draw, int buttonpress, int x_offset, int y_offset, int color,
3895 Auto* &auto_instance, int autogrouptype)
3898 int center_pixel, draw_auto;
3899 double view_start, unit_start;
3900 double view_end, unit_end, yscale;
3901 double zoom_sample, zoom_units;
3907 if(draw) set_color(color);
3909 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3910 yscale, center_pixel, zoom_sample, zoom_units);
3912 // Get first auto before start
3913 Auto *current = 0, *previous = 0;
3915 for( current = autos->last;
3916 current && current->position >= unit_start;
3917 current = PREVIOUS ) ;
3919 Auto *first_auto = current ? current :
3920 autos->first ? autos->first : autos->default_auto;
3922 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
3924 calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0,
3925 first_auto, unit_start, zoom_units, yscale, autogrouptype);
3930 current = autos->first;
3939 calculate_auto_position(1, &ax2, &ay2, 0, 0, 0, 0,
3940 current, unit_start, zoom_units, yscale, autogrouptype);
3948 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3953 ay2 = ay + slope * (get_w() - ax);
3957 ay = ay + slope * (0 - ax);
3961 // Draw or test handle
3962 if( current && !result && current != autos->default_auto ) {
3963 if( !draw && track->is_armed() ) {
3964 result = test_floatauto((FloatAuto*)current, buttonpress,
3965 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3966 unit_start, zoom_units, yscale, autogrouptype);
3968 auto_instance = current;
3970 if( draw && draw_auto ) {
3971 draw_floatauto((FloatAuto*)current, x_offset,
3972 (int)center_pixel + y_offset, (int)yscale, color,
3973 unit_start, zoom_units, yscale, autogrouptype);
3977 // Draw or test joining line
3978 if( !draw && !result && track->is_armed() /* && buttonpress != 3 */ ) {
3979 result = test_floatline(center_pixel,
3980 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3981 // Exclude auto coverage from the end of the line. The auto overlaps
3982 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3983 buttonpress, autogrouptype);
3986 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3987 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3988 (int)ax, (int)ay, (int)ax2, (int)ay2,
3989 color, autogrouptype);
3993 calculate_auto_position(0, &ax2, &ay2, 0, 0, 0, 0, previous,
3994 unit_start, zoom_units, yscale, autogrouptype);
3998 } while( current && current->position <= unit_end && !result );
4000 if( ax < get_w() && !result ) {
4001 ax2 = get_w(); ay2 = ay;
4002 if(!draw && track->is_armed() /* && buttonpress != 3 */ ) {
4003 result = test_floatline(center_pixel,
4004 (FloatAutos*)autos, unit_start, zoom_units, yscale,
4005 (int)ax, (int)ax2, cursor_x, cursor_y,
4006 buttonpress, autogrouptype);
4009 draw_floatline(center_pixel,
4010 (FloatAuto*)previous, (FloatAuto*)current,
4011 (FloatAutos*)autos, unit_start, zoom_units, yscale,
4012 (int)ax, (int)ay, (int)ax2, (int)ay2,
4013 color, autogrouptype);
4020 int TrackCanvas::do_int_autos(Track *track,
4029 Auto *&auto_instance)
4040 double ax, ay, ax2, ay2;
4044 if(draw) set_color(color);
4046 calculate_viewport(track,
4057 double high = -yscale * 0.8 / 2;
4058 double low = yscale * 0.8 / 2;
4060 // Get first auto before start
4062 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
4068 ay = ((IntAuto*)current)->value > 0 ? high : low;
4073 current = autos->first ? autos->first : autos->default_auto;
4077 ay = ((IntAuto*)current)->value > 0 ? high : low;
4090 ax2 = (double)(current->position - unit_start) / zoom_units;
4091 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
4099 if(ax2 > get_w()) ax2 = get_w();
4101 if(current && !result)
4103 if(current != autos->default_auto)
4107 if(track->is_armed())
4109 result = test_auto(current,
4118 auto_instance = current;
4123 (int)ax2 + x_offset,
4124 (int)ay2 + y_offset,
4136 if(track->is_armed() /* && buttonpress != 3 */)
4138 result = test_toggleline(autos,
4151 draw_toggleline(center_pixel + y_offset,
4159 }while(current && current->position <= unit_end && !result);
4161 if(ax < get_w() && !result)
4167 if(track->is_armed() /* && buttonpress != 3 */)
4169 result = test_toggleline(autos,
4181 draw_toggleline(center_pixel + y_offset,
4190 int TrackCanvas::do_autos(Track *track,
4197 Auto * &auto_instance,
4211 calculate_viewport(track,
4224 for(current = autos->first; current && !result; current = NEXT)
4226 if(current->position >= unit_start && current->position < unit_end)
4229 x = (int64_t)((double)(current->position - unit_start) /
4230 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
4231 y = center_pixel - pixmap->get_h() / 2;
4235 if(cursor_x >= x && cursor_y >= y &&
4236 cursor_x < x + pixmap->get_w() &&
4237 cursor_y < y + pixmap->get_h())
4240 auto_instance = current;
4242 if(buttonpress && (buttonpress != 3))
4244 mwindow->session->drag_auto = current;
4245 mwindow->session->drag_start_position = current->position;
4246 mwindow->session->drag_origin_x = cursor_x;
4247 mwindow->session->drag_origin_y = cursor_y;
4249 double position = autos->track->from_units(current->position);
4250 double center = (mwindow->edl->local_session->get_selectionstart(1) +
4251 mwindow->edl->local_session->get_selectionend(1)) /
4256 mwindow->edl->local_session->set_selectionstart(position);
4257 mwindow->edl->local_session->set_selectionend(position);
4260 if(position < center)
4262 mwindow->edl->local_session->set_selectionstart(position);
4265 mwindow->edl->local_session->set_selectionend(position);
4272 draw_pixmap(pixmap, x, y);
4280 // so this means it is always >0 when keyframe is found
4281 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
4282 int draw, int buttonpress, Plugin* &keyframe_plugin,
4283 KeyFrame* &keyframe_instance)
4296 if(!track->expand_view) return 0;
4298 calculate_viewport(track,
4310 for(int i = 0; i < track->plugin_set.total && !result; i++)
4312 PluginSet *plugin_set = track->plugin_set.values[i];
4313 int center_pixel = track->y_pixel -
4314 mwindow->edl->local_session->track_start[pane->number];
4315 if( track->show_titles() )
4316 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
4317 if( track->show_assets() )
4318 center_pixel += track->data_h;
4319 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
4321 for(Plugin *plugin = (Plugin*)plugin_set->first;
4323 plugin = (Plugin*)plugin->next)
4325 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
4326 keyframe && !result;
4327 keyframe = (KeyFrame*)keyframe->next)
4329 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
4330 if(keyframe->position >= unit_start && keyframe->position < unit_end)
4332 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
4333 int y = center_pixel - keyframe_pixmap->get_h() / 2;
4335 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
4338 if(cursor_x >= x && cursor_y >= y &&
4339 cursor_x < x + keyframe_pixmap->get_w() &&
4340 cursor_y < y + keyframe_pixmap->get_h())
4343 keyframe_plugin = plugin;
4344 keyframe_instance = keyframe;
4348 mwindow->session->drag_auto = keyframe;
4349 mwindow->session->drag_start_position = keyframe->position;
4350 mwindow->session->drag_origin_x = cursor_x;
4351 mwindow->session->drag_origin_y = cursor_y;
4353 double position = track->from_units(keyframe->position);
4354 double center = (mwindow->edl->local_session->get_selectionstart(1) +
4355 mwindow->edl->local_session->get_selectionend(1)) /
4360 mwindow->edl->local_session->set_selectionstart(position);
4361 mwindow->edl->local_session->set_selectionend(position);
4364 if(position < center)
4366 mwindow->edl->local_session->set_selectionstart(position);
4369 mwindow->edl->local_session->set_selectionend(position);
4374 draw_pixmap(keyframe_pixmap,
4384 // if(buttonpress && buttonpress != 3 && result)
4386 // mwindow->undo->update_undo_before();
4392 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
4394 Track *track = auto_keyframe->autos->track;
4395 int autogrouptype = auto_keyframe->autos->autogrouptype;
4398 double view_start, unit_start;
4399 double view_end, unit_end, yscale;
4400 double zoom_sample, zoom_units;
4402 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
4403 yscale, center_pixel, zoom_sample, zoom_units);
4404 if( auto_keyframe->position < unit_start ||
4405 auto_keyframe->position >= unit_end )
4408 double ax = 0, ay = 0;
4409 calculate_auto_position(0, &ax, &ay, 0, 0, 0, 0,
4410 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
4413 draw_line(ax, 0, ax, get_h());
4415 char text[BCSTRLEN];
4417 if( auto_keyframe->is_floatauto() ) {
4418 FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
4419 sprintf(text, "%0.2f", float_auto->get_value());
4421 else if( auto_keyframe->is_intauto() ) {
4422 IntAuto *int_auto = (IntAuto *)auto_keyframe;
4423 sprintf(text, "%d", int_auto->value);
4429 int font = MEDIUMFONT;
4430 int tw = get_text_width(font, text) + xS(TOOLTIP_MARGIN) * 2;
4431 int th = get_text_height(font, text) + yS(TOOLTIP_MARGIN) * 2;
4432 set_color(get_resources()->tooltip_bg_color);
4434 ay += center_pixel + HANDLE_W/2;
4435 draw_box(ax, ay, tw, th);
4437 draw_rectangle(ax, ay, tw, th);
4439 ax += xS(TOOLTIP_MARGIN);
4440 ay += yS(TOOLTIP_MARGIN) + get_text_ascent(font);
4441 draw_text(ax, ay, text);
4446 void TrackCanvas::draw_overlays()
4448 int new_cursor, update_cursor, rerender;
4450 // Move background pixmap to foreground pixmap
4451 draw_pixmap(background_pixmap, 0, 0, get_w(), get_h(), 0, 0);
4454 draw_inout_points();
4465 draw_brender_range();
4467 // Highlighted areas
4468 draw_highlighting();
4471 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
4474 if(pane->cursor) pane->cursor->restore(1);
4480 draw_playback_cursor();
4482 draw_keyframe_reticle();
4487 int TrackCanvas::activate()
4491 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
4492 //BC_Signals::dump_stack();
4493 get_top_level()->deactivate();
4495 set_active_subwindow(this);
4496 pane->cursor->activate();
4497 gui->focused_pane = pane->number;
4502 int TrackCanvas::deactivate()
4507 pane->cursor->deactivate();
4513 void TrackCanvas::update_drag_handle()
4515 double new_position;
4516 int cursor_x = get_cursor_x();
4518 new_position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4519 new_position = mwindow->edl->align_to_frame(new_position, 0);
4521 if( ctrl_down() && alt_down() ) {
4522 #define snapper(v) do { \
4524 if( pos < 0 ) break; \
4525 double dist = fabs(new_position - pos); \
4526 if( dist >= snap_min ) break; \
4527 snap_position = pos; snap_min = dist; \
4529 double snap_position = new_position;
4530 double snap_min = DBL_MAX;
4531 if( mwindow->edl->local_session->inpoint_valid() )
4532 snapper(mwindow->edl->local_session->get_inpoint());
4533 if( mwindow->edl->local_session->outpoint_valid() )
4534 snapper(mwindow->edl->local_session->get_outpoint());
4535 snapper(mwindow->edl->prev_edit(new_position));
4536 snapper(mwindow->edl->next_edit(new_position));
4537 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
4538 if( prev_label ) snapper(prev_label->position);
4539 Label *next_label = mwindow->edl->labels->next_label(new_position);
4540 if( next_label ) snapper(next_label->position);
4541 int snap_x = snap_position * mwindow->edl->session->sample_rate /
4542 mwindow->edl->local_session->zoom_sample -
4543 mwindow->edl->local_session->view_start[pane->number];
4544 if( abs(snap_x - cursor_x) < HANDLE_W ) {
4546 new_position = snap_position;
4551 if(new_position != mwindow->session->drag_position)
4553 mwindow->session->drag_position = new_position;
4554 gui->mainclock->update(new_position);
4555 timebar_position = new_position;
4556 gui->update_timebar(0);
4559 edl->create_objects();
4560 edl->copy_all(mwindow->edl);
4561 MainSession *session = mwindow->session;
4562 int handle_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
4563 edl->modify_edithandles(session->drag_start,
4564 session->drag_position, session->drag_handle, handle_mode,
4565 edl->session->labels_follow_edits,
4566 edl->session->plugins_follow_edits,
4567 edl->session->autos_follow_edits,
4568 !session->drag_edit ? 0 : session->drag_edit->group_id);
4570 double position = -1;
4571 int show_edge = !session->drag_handle ? 1 : 2;
4572 switch( handle_mode ) {
4575 position = session->drag_handle ?
4576 session->drag_position : session->drag_start;
4577 show_edge = 3 - show_edge;
4581 position = session->drag_position;
4584 position = session->drag_start;
4585 show_edge = 3 - show_edge;
4589 if( position < 0 ) position = 0;
4590 Track *track = session->drag_handle_track();
4591 int64_t pos = track->to_units(position, 0);
4592 render_handle_frame(edl, pos, shift_down() ? 0 : show_edge);
4597 int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
4600 int64_t left = pos-1;
4601 if( left < 0 ) left = 0;
4604 VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
4605 VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
4606 TransportCommand command(mwindow->preferences);
4607 command.command = CURRENT_FRAME;
4608 command.get_edl()->copy_all((EDL *)edl);
4609 command.change_type = CHANGE_ALL;
4610 command.realtime = 0;
4611 Preferences *preferences = mwindow->preferences;
4612 RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
4613 CICache *video_cache = new CICache(preferences);
4614 render_engine->set_vcache(video_cache);
4615 render_engine->arm_command(&command);
4616 VRender *vrender = render_engine->vrender;
4618 !vrender->process_buffer(&vlt, left, 0) &&
4619 !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1;
4620 delete render_engine;
4621 video_cache->remove_user();
4622 mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0");
4623 Canvas *canvas = mwindow->cwindow->gui->canvas;
4624 float ox1, oy1, ox2, oy2, cx1, cy1, cx2, cy2;
4625 canvas->get_transfers(edl, ox1, oy1, ox2, oy2, cx1, cy1, cx2, cy2);
4626 float cw = canvas->w/2, ch = canvas->h/2;
4627 float cdx = (cx2 - cx1)/2, cdy = (cy2 - cy1)/2;
4628 int cx = cx1/2, cy = cy1/2 + ch/2;
4629 int ow = ox2 - ox2, oh = oy2 - oy1;
4630 BC_WindowBase *window = canvas->get_canvas();
4631 window->set_color(BLACK);
4632 window->clear_box(0,0, window->get_w(),window->get_h());
4633 window->draw_vframe(&vlt, cx,cy, cdx,cdy, ox1,oy1, ow,oh); cx += cw;
4634 window->draw_vframe(&vrt, cx,cy, cdx,cdy, ox1,oy1, ow,oh);
4636 mwindow->cwindow->gui->unlock_window();
4640 Track *track = mwindow->session->drag_handle_track();
4641 double position = track->from_units(mode == 1 ? left : pos);
4642 if( position < 0 ) position = 0;
4643 PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine;
4644 if( playback_engine->is_playing_back )
4645 playback_engine->stop_playback(1);
4646 edl->local_session->set_selectionstart(position);
4647 edl->local_session->set_selectionend(position);
4648 mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
4654 int TrackCanvas::update_drag_edit()
4663 int TrackCanvas::get_drag_values(float *percentage,
4670 //int x = cursor_x - mwindow->session->drag_origin_x;
4671 //int y = cursor_y - mwindow->session->drag_origin_y;
4675 if(!current->autos->track->is_armed()) return 1;
4685 calculate_viewport(current->autos->track,
4695 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
4697 mwindow->session->drag_start_percentage;
4698 if(do_clamp) CLAMP(*percentage, 0, 1);
4700 *position = Units::to_int64(zoom_units *
4701 (cursor_x - mwindow->session->drag_origin_x) +
4702 mwindow->session->drag_start_position + 0.5);
4704 if((do_clamp) && *position < 0) *position = 0;
4709 #define UPDATE_DRAG_HEAD(do_clamp) \
4710 int result = 0, center_pixel; \
4711 if(!current->autos->track->is_armed()) return 0; \
4712 double view_start, unit_start, view_end, unit_end; \
4713 double yscale, zoom_sample, zoom_units; \
4715 calculate_viewport(current->autos->track, \
4716 view_start, unit_start, view_end, unit_end, \
4717 yscale, center_pixel, zoom_sample, zoom_units); \
4719 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
4720 yscale + mwindow->session->drag_start_percentage; \
4721 if(do_clamp) CLAMP(percentage, 0, 1); \
4723 int64_t position = Units::to_int64(zoom_units * \
4724 (cursor_x - mwindow->session->drag_origin_x) + \
4725 mwindow->session->drag_start_position); \
4726 if((do_clamp) && position < 0) position = 0;
4729 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
4731 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
4733 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
4734 int x = cursor_x - mwindow->session->drag_origin_x;
4735 int y = cursor_y - mwindow->session->drag_origin_y;
4736 float value, old_value;
4738 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
4739 // not really editing the node, rather start editing the curve
4740 // tangent is editable and drag movement is significant
4741 if( (FloatAuto::FREE == current->curve_mode ||
4742 FloatAuto::TFREE==current->curve_mode ||
4743 FloatAuto::BUMP==current->curve_mode) &&
4744 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
4745 mwindow->session->drag_handle = x < 0 ? 1 : 2;
4748 switch(mwindow->session->drag_handle) {
4750 // Snap to nearby values
4751 old_value = current->get_value();
4753 double distance1=-1, distance2=-1;
4754 if(current->previous) {
4755 int autogrouptype = current->previous->autos->autogrouptype;
4756 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4757 double value1 = ((FloatAuto*)current->previous)->get_value(0);
4758 distance1 = fabs(value - value1);
4759 current->set_value(value1, 1);
4763 int autogrouptype = current->next->autos->autogrouptype;
4764 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4765 double value2 = ((FloatAuto*)current->next)->get_value(1);
4766 distance2 = fabs(value - value2);
4767 if(!current->previous || distance2 < distance1) {
4768 current->set_value(value2, 0);
4772 if(!current->previous && !current->next) {
4773 current->set_value(((FloatAutos*)current->autos)->default_, 0);
4775 value = current->get_value();
4778 int autogrouptype = current->autos->autogrouptype;
4779 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4782 if(alt_down() && !shift_down())
4783 // ALT constrains movement: fixed position, only changing the value
4784 position = mwindow->session->drag_start_position;
4786 if(value != old_value || position != current->position) {
4788 float change = value - old_value;
4789 current->adjust_to_new_coordinates(position, value);
4790 update_ganged_autos(change, current->autos->track, current);
4791 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4792 show_message(current, color, ", %.2f", current->get_value());
4798 int autogrouptype = current->autos->autogrouptype;
4799 value = percentage_to_value(percentage, 0, current, autogrouptype);
4800 if(value != current->get_control_in_value())
4803 // note: (position,value) need not be at the location of the ctrl point,
4804 // but could be somewhere in between on the curve (or even outward or
4805 // on the opposit side). We set the new control point such as
4806 // to point the curve through (position,value)
4807 current->set_control_in_value(
4808 value * levered_position(position - current->position,
4809 current->get_control_in_position()));
4810 update_ganged_autos(0, current->autos->track, current);
4811 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4812 show_message(current, color, ", %.2f", current->get_control_in_value());
4818 int autogrouptype = current->autos->autogrouptype;
4819 value = percentage_to_value(percentage, 0, current, autogrouptype);
4820 if(value != current->get_control_out_value()) {
4822 current->set_control_out_value(
4823 value * levered_position(position - current->position,
4824 current->get_control_out_position()));
4825 update_ganged_autos(0, current->autos->track, current);
4826 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4827 show_message(current, color, ", %.2f", current->get_control_out_value());
4835 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
4837 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
4839 UPDATE_DRAG_HEAD(1);
4840 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
4842 if(value != current->value || position != current->position)
4845 current->value = value;
4846 current->position = position;
4847 show_message(current, -1, ", %d", current->value);
4853 // Autos which can't change value through dragging.
4855 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
4857 Auto *current = (Auto*)mwindow->session->drag_auto;
4860 if(position != current->position)
4863 current->position = position;
4864 show_message(current, -1, "");
4866 double position_f = current->autos->track->from_units(current->position);
4867 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4868 mwindow->edl->local_session->get_selectionend(1)) /
4872 mwindow->edl->local_session->set_selectionstart(position_f);
4873 mwindow->edl->local_session->set_selectionend(position_f);
4876 if(position_f < center_f)
4878 mwindow->edl->local_session->set_selectionstart(position_f);
4881 mwindow->edl->local_session->set_selectionend(position_f);
4888 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
4890 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
4893 if(position != current->position)
4895 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
4896 Track *track = current->autos->track;
4897 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
4898 PluginSet *pluginset;
4900 // figure out the correct pluginset & correct plugin
4902 for(int i = 0; i < track->plugin_set.total; i++)
4904 pluginset = track->plugin_set.values[i];
4905 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
4907 KeyFrames *keyframes = plugin->keyframes;
4908 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
4910 currentkeyframe = (KeyFrame *) currentkeyframe->next)
4912 if (currentkeyframe == current)
4924 mwindow->session->plugin_highlighted = plugin;
4925 mwindow->session->track_highlighted = track;
4927 current->position = position;
4928 show_message(current, -1, "");
4930 double position_f = current->autos->track->from_units(current->position);
4931 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4932 mwindow->edl->local_session->get_selectionend(1)) /
4936 mwindow->edl->local_session->set_selectionstart(position_f);
4937 mwindow->edl->local_session->set_selectionend(position_f);
4940 if(position_f < center_f)
4942 mwindow->edl->local_session->set_selectionstart(position_f);
4945 mwindow->edl->local_session->set_selectionend(position_f);
4952 void TrackCanvas::update_drag_caption()
4954 switch(mwindow->session->current_operation)
4963 void TrackCanvas::drag_edit_select(Edit *over_edit, int select, int draw)
4965 if( !over_edit ) return;
4966 if( !mwindow->session->drag_edit ) return;
4967 Track *drag_track = mwindow->session->drag_edit->track;
4968 Track *over_track = over_edit->track;
4969 if( !drag_track || !over_track ) return;
4970 if( drag_track->number_of() > over_track->number_of() ) {
4971 Track *trk = drag_track;
4972 drag_track = over_track;
4975 double start_pos = mwindow->session->drag_start;
4976 double end_pos = mwindow->session->drag_position;
4977 if( start_pos > end_pos ) {
4978 double pos = start_pos;
4979 start_pos = end_pos;
4982 int done = 0, do_flash = 0;
4983 for( Track *track=drag_track; !done; track=track->next ) {
4984 if( !track->is_armed() ) continue;
4985 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
4986 int64_t pos = edit->startproject;
4987 int64_t end = pos + edit->length;
4988 double edit_start = track->from_units(pos);
4989 double edit_end = track->from_units(end);
4990 if( start_pos >= edit_end ) continue;
4991 if( edit_start > end_pos ) continue;
4993 edit->is_selected = 1;
4994 else if( select < 0 )
4995 edit->is_selected = 0;
4997 int64_t edit_x, edit_y, edit_w, edit_h;
4998 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
5000 draw_rectangle(edit_x, edit_y, edit_w, edit_h);
5004 if( track == over_track ) done = 1;
5011 int TrackCanvas::cursor_update(int in_motion)
5016 int update_clock = 0;
5017 int update_zoom = 0;
5018 int update_scroll = 0;
5019 int update_overlay = 0;
5020 int update_cursor = 0;
5022 double position = 0.;
5023 //printf("TrackCanvas::cursor_update %d %d,%d\n", __LINE__, get_cursor_x(), get_cursor_y());
5027 arrow_mode() ? ARROW_CURSOR :
5028 ibeam_mode() ? IBEAM_CURSOR : 0;
5030 switch(mwindow->session->current_operation)
5032 case DRAG_EDITHANDLE1:
5033 // Outside threshold. Upgrade status
5034 if( !active ) break;
5035 if( labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W ) {
5036 mwindow->session->current_operation = DRAG_EDITHANDLE2;
5040 case DRAG_EDITHANDLE2:
5041 if( !active ) break;
5042 update_drag_handle();
5046 case DRAG_PLUGINHANDLE1:
5047 if( !active ) break;
5048 if( labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W ) {
5049 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
5053 case DRAG_PLUGINHANDLE2:
5054 if( !active ) break;
5055 update_drag_handle();
5059 case DRAG_TRANSNHANDLE1:
5060 if( !active ) break;
5061 if( labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W ) {
5062 mwindow->session->current_operation = DRAG_TRANSNHANDLE2;
5066 case DRAG_TRANSNHANDLE2: {
5067 if( !active ) break;
5068 position = mwindow->edl->get_cursor_position(get_cursor_x(), pane->number);
5069 position = mwindow->edl->align_to_frame(position, 1);
5070 drag_transition_handle(position);
5075 // Rubber band curves
5083 case DRAG_PROJECTOR_X:
5084 case DRAG_PROJECTOR_Y:
5085 case DRAG_PROJECTOR_Z:
5086 if(active) rerender = update_overlay =
5087 update_drag_floatauto(get_cursor_x(), get_cursor_y());
5088 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
5089 mwindow->speed_after(!in_motion ? 1 : 0, 0);
5093 if(active) rerender = update_overlay =
5094 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
5098 if(active) rerender = update_overlay =
5099 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
5102 // Keyframe icons are sticky
5106 case DRAG_PLUGINKEY_PRE:
5108 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
5109 mwindow->session->current_operation++;
5112 mwindow->undo->update_undo_before();
5120 if(active) rerender = update_overlay =
5121 update_drag_auto(get_cursor_x(), get_cursor_y());
5124 case DRAG_PLUGINKEY:
5125 if(active) rerender = update_overlay =
5126 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
5131 cursor_x = get_cursor_x();
5132 cursor_y = get_cursor_y();
5133 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
5134 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
5136 position = mwindow->edl->align_to_frame(position, 0);
5137 position = MAX(position, 0);
5139 double start = mwindow->edl->local_session->get_selectionstart(1);
5140 double end = mwindow->edl->local_session->get_selectionend(1);
5141 if(position < selection_midpoint) {
5142 mwindow->edl->local_session->set_selectionend(selection_midpoint);
5143 mwindow->edl->local_session->set_selectionstart(position);
5146 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
5147 mwindow->edl->local_session->set_selectionend(position);
5150 gui->unlock_window();
5152 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
5153 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
5154 mwindow->cwindow->update(dir, 0, 0, 0, 1);
5155 gui->lock_window("TrackCanvas::cursor_update 1");
5156 // Update the faders
5157 mwindow->update_plugin_guis();
5158 gui->update_patchbay();
5160 timebar_position = mwindow->edl->local_session->get_selectionend(1);
5162 gui->hide_cursor(0);
5163 gui->draw_cursor(1);
5164 gui->update_timebar(0);
5165 gui->flash_canvas(1);
5173 case DROP_TARGETING:
5174 new_cursor = GRABBED_CURSOR;
5179 if(is_event_win() && cursor_inside()) {
5181 cursor_x = get_cursor_x();
5182 position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5183 position = mwindow->edl->align_to_frame(position, 0);
5186 for(int i = 0; i < TOTAL_PANES; i++)
5187 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
5189 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
5190 gui->update_timebar(0);
5192 if(do_transitions(get_cursor_x(), get_cursor_y(),
5193 0, new_cursor, update_cursor)) break;
5194 if(do_keyframes(get_cursor_x(), get_cursor_y(),
5195 0, 0, new_cursor, update_cursor, rerender)) break;
5196 if(do_transition_handles(get_cursor_x(), get_cursor_y(),
5197 0, rerender, update_overlay, new_cursor, update_cursor)) break;
5198 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
5199 0, rerender, update_overlay, new_cursor, update_cursor)) break;
5200 // Plugin boundaries
5201 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
5202 0, rerender, update_overlay, new_cursor, update_cursor)) break;
5203 if(do_edits(get_cursor_x(), get_cursor_y(),
5204 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
5209 //printf("TrackCanvas::cursor_update 1\n");
5210 if(update_cursor && new_cursor != get_cursor())
5212 set_cursor(new_cursor, 0, 1);
5215 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
5216 if(rerender && render_timer->get_difference() > 0.25 ) {
5217 render_timer->update();
5218 mwindow->restart_brender();
5219 mwindow->sync_parameters(CHANGE_PARAMS);
5220 mwindow->update_plugin_guis();
5221 gui->unlock_window();
5222 mwindow->cwindow->update(1, 0, 0, 0, 1);
5223 gui->lock_window("TrackCanvas::cursor_update 2");
5227 gui->update_patchbay();
5232 if(!mwindow->cwindow->playback_engine->is_playing_back)
5233 gui->mainclock->update(position);
5237 gui->zoombar->update();
5242 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
5246 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
5250 if(update_overlay) {
5251 gui->draw_overlays(1);
5254 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
5258 int TrackCanvas::cursor_motion_event()
5260 return cursor_update(1);
5263 void TrackCanvas::start_dragscroll()
5267 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
5268 //printf("TrackCanvas::start_dragscroll 1\n");
5272 void TrackCanvas::stop_dragscroll()
5276 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
5277 //printf("TrackCanvas::stop_dragscroll 1\n");
5281 int TrackCanvas::repeat_event(int64_t duration)
5283 if(!drag_scroll) return 0;
5284 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
5286 int sample_movement = 0;
5287 int track_movement = 0;
5288 int64_t x_distance = 0;
5289 int64_t y_distance = 0;
5290 double position = 0;
5293 switch(mwindow->session->current_operation) {
5294 case DRAG_EDIT_SELECT:
5296 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
5297 if(get_cursor_x() > get_w()) {
5298 x_distance = get_cursor_x() - get_w();
5299 sample_movement = 1;
5301 else if(get_cursor_x() < 0) {
5302 x_distance = get_cursor_x();
5303 sample_movement = 1;
5306 if(get_cursor_y() > get_h()) {
5307 y_distance = get_cursor_y() - get_h();
5310 else if(get_cursor_y() < 0) {
5311 y_distance = get_cursor_y();
5318 if(sample_movement) {
5319 position = (double)(get_cursor_x() +
5320 mwindow->edl->local_session->view_start[pane->number] +
5322 mwindow->edl->local_session->zoom_sample /
5323 mwindow->edl->session->sample_rate;
5324 position = mwindow->edl->align_to_frame(position, 0);
5325 position = MAX(position, 0);
5327 //printf("TrackCanvas::repeat_event 1 %f\n", position);
5328 switch(mwindow->session->current_operation) {
5330 if(position < selection_midpoint) {
5331 mwindow->edl->local_session->set_selectionend(selection_midpoint);
5332 mwindow->edl->local_session->set_selectionstart(position);
5334 gui->unlock_window();
5335 mwindow->cwindow->update(1, 0, 0);
5336 gui->lock_window("TrackCanvas::repeat_event");
5337 // Update the faders
5338 mwindow->update_plugin_guis();
5339 gui->update_patchbay();
5342 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
5343 mwindow->edl->local_session->set_selectionend(position);
5344 // Don't que the CWindow
5349 mwindow->samplemovement(
5350 mwindow->edl->local_session->view_start[pane->number] + x_distance,
5354 if(track_movement) {
5355 mwindow->trackmovement(y_distance, pane->number);
5361 int TrackCanvas::button_release_event()
5363 int redraw = -1, update_overlay = 0;
5364 int result = 0, load_flags = 0;
5366 // printf("TrackCanvas::button_release_event %d\n",
5367 // mwindow->session->current_operation);
5369 switch(mwindow->session->current_operation) {
5370 case DRAG_EDITHANDLE2:
5371 mwindow->session->current_operation = NO_OPERATION;
5375 end_edithandle_selection();
5378 case DRAG_EDITHANDLE1:
5379 mwindow->session->current_operation = NO_OPERATION;
5384 case DRAG_PLUGINHANDLE2:
5385 mwindow->session->current_operation = NO_OPERATION;
5389 end_pluginhandle_selection();
5392 case DRAG_PLUGINHANDLE1:
5393 mwindow->session->current_operation = NO_OPERATION;
5398 case DRAG_TRANSNHANDLE2:
5399 mwindow->session->current_operation = NO_OPERATION;
5403 end_transnhandle_selection();
5406 case DRAG_TRANSNHANDLE1:
5407 mwindow->session->current_operation = NO_OPERATION;
5413 redraw = FORCE_REDRAW;
5414 load_flags |= LOAD_EDITS | LOAD_TIMEBAR;
5416 // delete the drag_auto_gang first and remove out of order keys
5417 clear_ganged_autos();
5428 case DRAG_PROJECTOR_X:
5429 case DRAG_PROJECTOR_Y:
5430 case DRAG_PROJECTOR_Z:
5431 case DRAG_PLUGINKEY:
5432 load_flags |= LOAD_AUTOMATION;
5433 mwindow->session->current_operation = NO_OPERATION;
5434 mwindow->session->drag_handle = 0;
5435 // Remove any out-of-order keyframe
5436 if(mwindow->session->drag_auto) {
5437 mwindow->session->drag_auto->autos->remove_nonsequential(
5438 mwindow->session->drag_auto);
5439 // mwindow->session->drag_auto->autos->optimize();
5443 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
5449 case DRAG_AEFFECT_COPY:
5450 case DRAG_VEFFECT_COPY:
5451 // Trap in drag stop
5454 case DROP_TARGETING: {
5455 int cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
5456 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
5457 drag_cursor_motion(cursor_x, cursor_y,
5458 &track, &edit, &pluginset, &plugin);
5460 mwindow->edl->get_cursor_position(cursor_x, pane->number);
5461 gui->edit_menu->activate_menu(track, edit, pluginset, plugin, position);
5462 mwindow->session->current_operation = NO_OPERATION;
5466 case GROUP_TOGGLE: {
5467 Edit *edit = mwindow->session->drag_edit;
5469 if( shift_down() && edit->is_selected ) {
5470 if( edit->group_id > 0 ) {
5471 mwindow->edl->tracks->clear_selected_edits();
5472 mwindow->edl->tracks->del_group(edit->group_id);
5475 int id = mwindow->session->group_number++;
5476 mwindow->edl->tracks->new_group(id);
5481 if( mwindow->preferences->ctrl_toggle && !ctrl_down() )
5482 mwindow->edl->tracks->clear_selected_edits();
5483 edit->set_selected(-1);
5486 mwindow->session->current_operation = NO_OPERATION;
5492 case DRAG_EDIT_SELECT:
5497 if( mwindow->session->current_operation ) {
5498 // if(mwindow->session->current_operation == SELECT_REGION) {
5499 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
5502 mwindow->session->current_operation = NO_OPERATION;
5511 if( mwindow->edl->local_session->zoombar_showautocolor >= 0 )
5512 mwindow->gui->zoombar->update_autozoom(-1);
5517 if(update_overlay) {
5518 gui->draw_overlays(1);
5521 gui->draw_canvas(redraw, 0);
5522 gui->flash_canvas(1);
5527 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
5528 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
5530 Edit *edit_result = 0;
5531 int handle_result = -1;
5534 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
5535 if( track->is_hidden() ) continue;
5536 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
5537 int64_t edit_x, edit_y, edit_w, edit_h;
5538 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
5540 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
5541 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
5542 if( cursor_x < edit_x + HANDLE_W ) {
5545 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
5546 track->show_assets() ) {
5547 new_cursor = DOWNLEFT_RESIZE;
5548 if( button_press == LEFT_BUTTON )
5554 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
5557 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
5558 track->show_assets() ) {
5559 new_cursor = DOWNRIGHT_RESIZE;
5560 if( button_press == LEFT_BUTTON )
5571 int group_id = edit_result->group_id;
5572 if( group_id > 0 ) {
5573 Track *track = edit_result->track;
5574 Edit *left = 0, *right = 0;
5575 double start = DBL_MAX, end = DBL_MIN;
5576 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
5577 if( edit->group_id != group_id ) continue;
5578 double edit_start = edit->track->from_units(edit->startproject);
5579 if( edit_start < start ) { start = edit_start; left = edit; }
5580 double edit_end = edit->track->from_units(edit->startproject+edit->length);
5581 if( edit_end > end ) { end = edit_end; right = edit; }
5583 Edit *edit = !handle_result ? left : right;
5584 if( edit != edit_result )
5591 double position = 0;
5592 if( handle_result == 0 ) {
5593 position = edit_result->track->from_units(edit_result->startproject);
5594 new_cursor = LEFT_CURSOR;
5596 else if( handle_result == 1 ) {
5597 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
5598 new_cursor = RIGHT_CURSOR;
5601 // Reposition cursor
5602 if( button_press ) {
5603 mwindow->session->drag_edit = edit_result;
5604 mwindow->session->drag_handle = handle_result;
5605 mwindow->session->drag_button = get_buttonpress() - 1;
5606 mwindow->session->drag_position = position;
5607 mwindow->session->current_operation = DRAG_EDITHANDLE1;
5608 mwindow->session->drag_origin_x = get_cursor_x();
5609 mwindow->session->drag_origin_y = get_cursor_y();
5610 mwindow->session->drag_start = position;
5612 rerender = start_selection(position);
5616 else if( result < 0 && !edit_result->silence() ) {
5617 mwindow->undo->update_undo_before();
5618 if( !shift_down() ) {
5619 if( handle_result == 0 )
5620 edit_result->hard_left = !edit_result->hard_left;
5621 else if( handle_result == 1 )
5622 edit_result->hard_right = !edit_result->hard_right;
5625 int status = handle_result == 0 ? edit_result->hard_left :
5626 handle_result == 1 ? edit_result->hard_right : 0;
5627 int new_status = !status;
5628 int64_t edit_edge = edit_result->startproject;
5629 if( handle_result == 1 ) edit_edge += edit_result->length;
5630 double edge_position = edit_result->track->from_units(edit_edge);
5631 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
5632 if( track->is_hidden() ) continue;
5633 int64_t track_position = track->to_units(edge_position, 1);
5634 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
5636 int64_t left_edge = left_edit->startproject;
5637 double left_position = track->from_units(left_edge);
5638 if( EQUIV(edge_position, left_position) ) {
5639 left_edit->hard_left = new_status;
5640 if( left_edit->previous )
5641 left_edit->previous->hard_right = new_status;
5644 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
5646 int64_t right_edge = right_edit->startproject + right_edit->length;
5647 double right_position = track->from_units(right_edge);
5648 if( EQUIV(edge_position, right_position) ) {
5649 right_edit->hard_right = new_status;
5650 if( right_edit->next )
5651 right_edit->next->hard_left = new_status;
5656 rerender = update_overlay = 1;
5657 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
5664 int TrackCanvas::do_plugin_handles(int cursor_x,
5668 int &update_overlay,
5672 Plugin *plugin_result = 0;
5673 int handle_result = 0;
5676 for(Track *track = mwindow->edl->tracks->first;
5678 track = track->next) {
5679 if( track->is_hidden() ) continue;
5680 for(int i = 0; i < track->plugin_set.total && !result; i++) {
5681 PluginSet *plugin_set = track->plugin_set.values[i];
5682 for(Plugin *plugin = (Plugin*)plugin_set->first;
5684 plugin = (Plugin*)plugin->next) {
5685 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
5686 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
5688 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
5689 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
5690 if(cursor_x < plugin_x + HANDLE_W) {
5691 plugin_result = plugin;
5695 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
5696 plugin_result = plugin;
5703 if(result && shift_down())
5704 mwindow->session->trim_edits = plugin_set;
5710 double position = 0;
5711 if(handle_result == 0) {
5712 position = plugin_result->track->from_units(plugin_result->startproject);
5713 new_cursor = LEFT_CURSOR;
5715 else if(handle_result == 1) {
5716 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
5717 new_cursor = RIGHT_CURSOR;
5721 mwindow->session->drag_plugin = plugin_result;
5722 mwindow->session->drag_handle = handle_result;
5723 mwindow->session->drag_button = get_buttonpress() - 1;
5724 mwindow->session->drag_position = position;
5725 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
5726 mwindow->session->drag_origin_x = get_cursor_x();
5727 mwindow->session->drag_origin_y = get_cursor_y();
5728 mwindow->session->drag_start = position;
5730 rerender = start_selection(position);
5738 int TrackCanvas::do_transition_handles(int cursor_x, int cursor_y, int button_press,
5739 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
5741 if( !mwindow->edl->session->auto_conf->transitions )
5743 Transition *trans_result = 0;
5746 Track *track = mwindow->edl->tracks->first;
5747 for( ; track && !result; track=track->next) {
5748 if( track->is_hidden() ) continue;
5749 Edit *edit = track->edits->first;
5750 for( ; edit && !result; edit=edit->next ) {
5751 Transition *trans = edit->transition;
5752 if( !trans ) continue;
5754 edit_dimensions(edit, x, y, w, h);
5755 int strip_x = x, edit_y = y;
5756 get_transition_coords(edit, x, y, w, h);
5757 VFrame *strip = mwindow->theme->get_image("plugin_bg_data");
5758 int strip_y = y - strip->get_h();
5759 if( track->show_assets() && track->show_titles() )
5760 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
5761 if( strip_y < edit_y ) strip_y = edit_y;
5762 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
5763 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
5764 int x1 = strip_x + strip_w - HANDLE_W/2, x2 = x1 + HANDLE_W;
5765 int y1 = strip_y + strip->get_h()/2 - HANDLE_H/2, y2 = y1 + HANDLE_W;
5766 if( cursor_x >= x1 && cursor_x < x2 &&
5767 cursor_y >= y1 && cursor_y < y2 ) {
5768 trans_result = trans;
5775 if( button_press ) {
5776 mwindow->session->drag_transition = trans_result;
5777 mwindow->session->drag_handle = 1;
5778 mwindow->session->drag_button = get_buttonpress() - 1;
5779 int64_t trans_end = trans_result->edit->startproject + trans_result->length;
5780 double position = trans_result->edit->track->from_units(trans_end);
5781 mwindow->session->drag_position = position;
5782 mwindow->session->drag_start = position;
5783 mwindow->session->current_operation = DRAG_TRANSNHANDLE1;
5784 mwindow->session->drag_origin_x = get_cursor_x();
5785 mwindow->session->drag_origin_y = get_cursor_y();
5788 new_cursor = RIGHT_CURSOR;
5795 int TrackCanvas::drag_transition_handle(double position)
5797 Transition *transition = mwindow->session->drag_transition;
5798 if( !transition ) return 1;
5799 mwindow->session->drag_position = position;
5800 mwindow->edl->local_session->set_selectionstart(position);
5801 mwindow->edl->local_session->set_selectionend(position);
5802 char string[BCSTRLEN];
5803 int64_t length = transition->length;
5804 Track *track = transition->edit->track;
5805 int64_t start_pos = track->to_units(mwindow->session->drag_start, 0);
5806 int64_t end_pos = track->to_units(mwindow->session->drag_position, 0);
5807 length += end_pos - start_pos;
5808 if( length < 0 ) length = 0;
5809 double time = track->from_units(length);
5810 Units::totext(string, time,
5811 mwindow->edl->session->time_format,
5812 mwindow->edl->session->sample_rate,
5813 mwindow->edl->session->frame_rate,
5814 mwindow->edl->session->frames_per_foot);
5815 mwindow->gui->show_message(string);
5816 if( mwindow->gui->transition_menu->length_thread->running() ) {
5817 TransitionLengthDialog *dialog = (TransitionLengthDialog *)
5818 mwindow->gui->transition_menu->length_thread->get_gui();
5820 dialog->lock_window("TrackCanvas::drag_transition_handle");
5821 dialog->update_text(time);
5822 dialog->thread->new_length = time;
5823 dialog->unlock_window();
5830 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
5834 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
5835 drag_cursor_motion(cursor_x, cursor_y,
5836 &track, &edit, &pluginset, &plugin);
5838 if( button_press && track ) {
5839 switch( get_buttonpress() ) {
5840 case RIGHT_BUTTON: {
5842 mwindow->edl->get_cursor_position(cursor_x, pane->number);
5843 gui->track_menu->activate_menu(track, edit, pluginset, plugin, position);
5844 mwindow->session->current_operation = NO_OPERATION;
5848 set_cursor(GRABBED_CURSOR, 0, 1);
5849 mwindow->session->current_operation = DROP_TARGETING;
5858 int TrackCanvas::arrow_mode()
5860 return mwindow->edl->session->editing_mode == EDITING_ARROW ? 1 : 0;
5862 int TrackCanvas::ibeam_mode()
5864 return mwindow->edl->session->editing_mode == EDITING_IBEAM ? 1 : 0;
5867 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
5868 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
5872 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
5873 if( track->is_hidden() ) continue;
5874 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
5875 int64_t edit_x, edit_y, edit_w, edit_h;
5876 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
5878 // Cursor inside a track
5879 // Cursor inside an edit
5880 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
5881 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
5882 if( button_press && get_buttonpress() == LEFT_BUTTON ) {
5883 if( get_double_click() ) {
5884 mwindow->edl->tracks->clear_selected_edits();
5885 edit->select_affected_edits(1, -1);
5886 double start = edit->track->from_units(edit->startproject);
5887 start = mwindow->edl->align_to_frame(start, 0);
5888 mwindow->edl->local_session->set_selectionstart(start);
5889 double end = edit->track->from_units(edit->startproject+edit->length);
5890 end = mwindow->edl->align_to_frame(end, 0);
5891 mwindow->edl->local_session->set_selectionend(end);
5892 result = 1; // Select edit duration or select_region
5894 else if( arrow_mode() || (ibeam_mode() && ctrl_down()) ) {
5895 mwindow->session->drag_edit = edit;
5896 mwindow->session->current_operation = GROUP_TOGGLE;
5904 else if( drag_start && track->is_armed() ) {
5905 mwindow->session->drag_edit = edit;
5906 mwindow->session->drag_origin_x = cursor_x;
5907 mwindow->session->drag_origin_y = cursor_y;
5908 // Where the drag started, so we know relative position inside the edit later
5909 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5910 mwindow->session->drag_position = mwindow->edl->align_to_frame(position, 1);
5911 if( get_buttonpress() == LEFT_BUTTON && alt_down() ) {
5912 mwindow->session->drag_start = mwindow->session->drag_position;
5913 drag_edit_select(edit, 0, 1);
5914 mwindow->session->current_operation = DRAG_EDIT_SELECT;
5918 drag_start = 0; // if unselected "fast" drag
5919 if( !edit->silence() && !edit->is_selected ) {
5920 mwindow->edl->tracks->clear_selected_edits();
5921 if( ibeam_mode() ) {
5922 double start = edit->track->from_units(edit->startproject);
5923 mwindow->edl->local_session->set_selectionstart(start);
5924 mwindow->edl->local_session->set_selectionend(start);
5925 edit->set_selected(1);
5928 edit->select_affected_edits(1, -1);
5931 // Construct list of all affected edits
5932 if( drag_start || ibeam_mode() ) {
5933 mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits);
5934 if( mwindow->session->drag_edits->size() > 0 ) {
5935 mwindow->session->current_operation = DRAG_EDIT;
5936 // Need to create drag window
5937 int cx, cy; get_abs_cursor(cx, cy);
5938 gui->drag_popup = new BC_DragWindow(gui,
5939 mwindow->theme->get_image("clip_icon"), cx, cy);
5943 rerender = start_selection(mwindow->session->drag_position);
5944 mwindow->session->current_operation = SELECT_REGION;
5948 else if( edit->is_selected && arrow_mode() ) {
5949 if( mwindow->session->drag_group )
5950 mwindow->session->drag_group->remove_user();
5951 double start_position = 0;
5952 mwindow->session->drag_group =
5953 mwindow->edl->selected_edits_to_clip(0, &start_position,
5954 &mwindow->session->drag_group_first_track);
5955 if( mwindow->session->drag_group ) {
5956 mwindow->session->current_operation = DRAG_GROUP;
5957 mwindow->session->drag_group_position = start_position;
5958 mwindow->session->drag_group_edit = edit;
5959 mwindow->session->drag_origin_y = edit_y;
5970 // returns -1=doesnt fit, 1=fits, 0=fits but overwrites
5971 int TrackCanvas::test_track_group(EDL *group, Track *first_track, double &pos)
5974 Track *src = group->tracks->first;
5975 for( Track *track=first_track; track && src; track=track->next ) {
5976 if( !track->is_armed() ) return -1;
5977 if( src->data_type != track->data_type ) return -1;
5978 for( Edit *src_edit=src->edits->first; src_edit; src_edit=src_edit->next ) {
5979 if( src_edit->silence() ) continue;
5980 if( !intersects && edit_intersects(track, src_edit, pos) )
5985 return src ? -1 : !intersects ? 1 : 0;
5988 int TrackCanvas::edit_intersects(Track *track, Edit *src_edit, double &pos)
5990 if( pos < 0 ) { pos = 0; return 1; }
5991 int pane_no = pane->number;
5992 int cur_pix = track->edl->get_position_cursorx(pos, pane_no);
5993 int64_t src_start = src_edit->startproject;
5994 int64_t src_end = src_start + src_edit->length;
5995 double new_start = src_edit->track->from_units(src_start) + pos;
5996 double new_end = src_edit->track->from_units(src_end) + pos;
5997 int64_t trk_start = track->to_units(new_start, 1);
5998 int64_t trk_end = track->to_units(new_end, 1);
5999 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
6000 if( edit->is_selected || edit->silence() ) continue;
6001 int64_t edit_start = edit->startproject;
6002 if( edit_start >= trk_end ) continue;
6003 int64_t edit_end = edit_start + edit->length;
6004 if( trk_start >= edit_end ) continue;
6006 int64_t lt_dist = labs(trk_end - edit_start);
6007 int64_t rt_dist = labs(edit_end - trk_start);
6009 if( lt_dist < rt_dist ) {
6010 position = edit_start;
6011 lt_dist = abs(trk_start - edit_start);
6012 rt_dist = abs(trk_end - edit_start);
6013 if( lt_dist > rt_dist )
6014 position -= src_end;
6017 position = edit_end;
6018 lt_dist = abs(trk_start - edit_end);
6019 rt_dist = abs(trk_end - edit_end);
6020 if( lt_dist > rt_dist )
6021 position -= src_end;
6023 double new_pos = edit->track->from_units(position);
6024 int new_pix = track->edl->get_position_cursorx(new_pos, pane_no);
6025 if( abs(new_pix-cur_pix) < HANDLE_W )
6032 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
6037 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
6038 int button_press, int &redraw, int &rerender)
6046 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
6047 if(!track->expand_view) continue;
6049 for(int i = 0; i < track->plugin_set.total && !done; i++) {
6050 // first check if plugins are visible at all
6051 if (!track->expand_view)
6053 PluginSet *plugin_set = track->plugin_set.values[i];
6054 for(plugin = (Plugin*)plugin_set->first;
6056 plugin = (Plugin*)plugin->next) {
6057 plugin_dimensions(plugin, x, y, w, h);
6058 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
6059 MWindowGUI::visible(y, y + h, 0, get_h())) {
6060 if(cursor_x >= x && cursor_x < x + w &&
6061 cursor_y >= y && cursor_y < y + h) {
6071 // Start plugin popup
6073 if(get_buttonpress() == RIGHT_BUTTON ) {
6074 gui->plugin_menu->update(plugin);
6075 gui->plugin_menu->activate_menu();
6078 else if (get_double_click() && !drag_start) {
6079 // Select range of plugin on doubleclick over plugin
6080 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
6081 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
6082 plugin->track->from_units(plugin->length));
6083 if(mwindow->edl->session->cursor_on_frames) {
6084 mwindow->edl->local_session->set_selectionstart(
6085 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
6086 mwindow->edl->local_session->set_selectionend(
6087 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
6096 if( drag_start && plugin->track->is_armed() && !plugin->silence() ) {
6097 if( mwindow->edl->session->editing_mode == EDITING_ARROW ) {
6098 if( plugin->track->data_type == TRACK_AUDIO )
6099 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
6100 else if( plugin->track->data_type == TRACK_VIDEO )
6101 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
6103 mwindow->session->drag_plugin = plugin;
6104 mwindow->session->drag_origin_x = cursor_x;
6105 mwindow->session->drag_origin_y = cursor_y;
6106 // Where the drag started, so we know relative position inside the edit later
6107 mwindow->session->drag_position =
6108 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
6109 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
6111 switch(plugin->plugin_type) {
6112 case PLUGIN_STANDALONE: {
6113 PluginServer *server =
6114 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
6115 if( !server ) break;
6116 VFrame *frame = server->picon;
6118 if(plugin->track->data_type == TRACK_AUDIO) {
6119 frame = mwindow->theme->get_image("aeffect_icon");
6122 frame = mwindow->theme->get_image("veffect_icon");
6126 get_abs_cursor(cx, cy);
6127 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
6130 case PLUGIN_SHAREDPLUGIN:
6131 case PLUGIN_SHAREDMODULE: {
6132 VFrame *frame = mwindow->theme->get_image("clip_icon");
6134 get_abs_cursor(cx, cy);
6135 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
6147 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
6148 int button_press, int &new_cursor, int &update_cursor)
6150 Transition *transition = 0;
6155 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
6156 if( track->is_hidden() ) continue;
6157 if( !track->show_transitions() ) continue;
6159 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
6160 if( edit->transition ) {
6161 edit_dimensions(edit, x, y, w, h);
6162 get_transition_coords(edit, x, y, w, h);
6164 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
6165 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
6166 if( cursor_x >= x && cursor_x < x + w &&
6167 cursor_y >= y && cursor_y < y + h ) {
6168 transition = edit->transition;
6180 new_cursor = UPRIGHT_ARROW_CURSOR;
6182 else if(get_buttonpress() == RIGHT_BUTTON ) {
6183 gui->transition_menu->update(transition);
6184 gui->transition_menu->activate_menu();
6191 int TrackCanvas::button_press_event()
6194 int cursor_x, cursor_y;
6197 cursor_x = get_cursor_x();
6198 cursor_y = get_cursor_y();
6199 mwindow->session->trim_edits = 0;
6201 if(is_event_win() && cursor_inside()) {
6202 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
6209 if( get_buttonpress() == LEFT_BUTTON ) {
6210 gui->stop_transport("TrackCanvas::button_press_event");
6213 int update_overlay = 0, update_cursor = 0, rerender = 0, update_message = 0;
6215 if(get_buttonpress() == WHEEL_UP) {
6217 mwindow->expand_sample();
6218 else if(ctrl_down())
6219 mwindow->move_left(get_w()/ 10);
6221 mwindow->move_up(get_h() / 10);
6223 else if(get_buttonpress() == WHEEL_DOWN) {
6225 mwindow->zoom_in_sample();
6226 else if(ctrl_down())
6227 mwindow->move_right(get_w() / 10);
6229 mwindow->move_down(get_h() / 10);
6231 else if(get_buttonpress() == 6) {
6233 mwindow->move_left(get_w());
6235 mwindow->move_left(get_w() / 20);
6237 mwindow->move_left(get_w() / 5);
6239 else if(get_buttonpress() == 7) {
6241 mwindow->move_right(get_w());
6243 mwindow->move_right(get_w() / 20);
6245 mwindow->move_right(get_w() / 5);
6248 if( arrow_mode() ) do {
6249 // Test handles and resource boundaries and highlight a track
6250 if( do_transitions(cursor_x, cursor_y,
6251 1, new_cursor, update_cursor) ) break;
6253 if( do_keyframes(cursor_x, cursor_y,
6254 0, get_buttonpress(), new_cursor,
6255 update_cursor, rerender) ) break;
6258 if( do_transition_handles(cursor_x, cursor_y,
6259 1, rerender, update_overlay, new_cursor,
6260 update_cursor) ) break;
6261 // Test edit boundaries
6262 if( do_edit_handles(cursor_x, cursor_y,
6263 1, rerender, update_overlay, new_cursor,
6264 update_cursor) ) break;
6265 // Test plugin boundaries
6266 if( do_plugin_handles(cursor_x, cursor_y,
6267 1, rerender, update_overlay, new_cursor,
6268 update_cursor) ) break;
6270 if( do_edits(cursor_x, cursor_y, 1, 0,
6271 update_overlay, rerender, new_cursor,
6272 update_cursor) ) break;
6274 if( do_plugins(cursor_x, cursor_y, 0, 1,
6275 update_cursor, rerender) ) break;
6277 if( test_resources(cursor_x, cursor_y) ) break;
6279 if( do_tracks(cursor_x, cursor_y, 1) ) break;
6283 else if( ibeam_mode() ) do {
6284 // Test handles only and select a region
6285 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
6286 //printf("TrackCanvas::button_press_event %d\n", position);
6288 if( do_transitions(cursor_x, cursor_y,
6289 1, new_cursor, update_cursor)) break;
6290 if(do_keyframes(cursor_x, cursor_y,
6291 0, get_buttonpress(), new_cursor,
6292 update_cursor, rerender)) {
6297 if( do_transition_handles(cursor_x, cursor_y,
6298 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
6299 // Test edit boundaries
6300 if( do_edit_handles(cursor_x, cursor_y,
6301 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
6302 // Test plugin boundaries
6303 if( do_plugin_handles(cursor_x, cursor_y,
6304 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
6306 if( do_edits(cursor_x, cursor_y,
6307 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
6309 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
6311 if( do_tracks(cursor_x, cursor_y, 1) ) break;
6312 // Highlight selection
6313 if( get_buttonpress() != LEFT_BUTTON ) break;
6314 rerender = start_selection(position);
6315 mwindow->session->current_operation = SELECT_REGION;
6321 gui->unlock_window();
6322 mwindow->cwindow->update(1, 0, 0, 0, 1);
6323 gui->lock_window("TrackCanvas::button_press_event 2");
6325 mwindow->update_plugin_guis();
6326 gui->update_patchbay();
6329 if( update_message )
6330 gui->default_message();
6332 if( update_overlay )
6333 gui->draw_overlays(1);
6335 if( update_cursor < 0 ) {
6336 // double_click edit
6337 gui->swindow->update_selection();
6338 gui->draw_canvas(0, 0);
6340 if( update_cursor ) {
6341 gui->update_timebar(0);
6342 gui->hide_cursor(0);
6343 gui->show_cursor(1);
6344 gui->zoombar->update();
6345 gui->flash_canvas(1);
6352 int TrackCanvas::start_selection(double position)
6355 position = mwindow->edl->align_to_frame(position, 1);
6361 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
6362 mwindow->edl->local_session->get_selectionend(1)) / 2;
6364 if(position < midpoint)
6366 mwindow->edl->local_session->set_selectionstart(position);
6367 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
6373 mwindow->edl->local_session->set_selectionend(position);
6374 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
6375 // Don't que the CWindow for the end
6379 // Start a new selection
6381 //printf("TrackCanvas::start_selection %f\n", position);
6382 mwindow->edl->local_session->set_selectionstart(position);
6383 mwindow->edl->local_session->set_selectionend(position);
6384 selection_midpoint = position;
6392 void TrackCanvas::end_edithandle_selection()
6394 mwindow->modify_edithandles();
6395 mwindow->session->drag_edit = 0;
6398 void TrackCanvas::end_pluginhandle_selection()
6400 mwindow->modify_pluginhandles();
6401 mwindow->session->drag_plugin = 0;
6404 void TrackCanvas::end_transnhandle_selection()
6406 mwindow->modify_transnhandles();
6407 mwindow->session->drag_transition = 0;
6411 double TrackCanvas::time_visible()
6413 return (double)get_w() *
6414 mwindow->edl->local_session->zoom_sample /
6415 mwindow->edl->session->sample_rate;
6419 void TrackCanvas::show_message(Auto *current, int box_color, const char *fmt, ...)
6421 char string[BCTEXTLEN];
6422 char *cp = string, *ep = cp + sizeof(string)-1;
6423 if( box_color >= 0 ) {
6424 cp += snprintf(string, ep-cp, "%-8s ",
6425 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
6427 char string2[BCTEXTLEN];
6428 Units::totext(string2,
6429 current->autos->track->from_units(current->position),
6430 mwindow->edl->session->time_format,
6431 mwindow->edl->session->sample_rate,
6432 mwindow->edl->session->frame_rate,
6433 mwindow->edl->session->frames_per_foot);
6434 cp += snprintf(cp, ep-cp, "%s", string2);
6437 vsnprintf(cp, ep-cp, fmt, ap);
6439 gui->show_message(string, -1, box_color);
6442 // Patchbay* TrackCanvas::get_patchbay()
6444 // if(pane->patchbay) return pane->patchbay;
6445 // if(gui->total_panes() == 2 &&
6446 // gui->pane[TOP_LEFT_PANE] &&
6447 // gui->pane[TOP_RIGHT_PANE])
6448 // return gui->pane[TOP_LEFT_PANE]->patchbay;
6449 // if(gui->total_panes() == 4)
6451 // if(pane->number == TOP_RIGHT_PANE)
6452 // return gui->pane[TOP_LEFT_PANE]->patchbay;
6454 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;