3 #include "automation.h"
5 #include "bezierauto.h"
6 #include "bezierautos.h"
12 #include "cwindowgui.h"
13 #include "edithandles.h"
14 #include "editpopup.h"
17 #include "edlsession.h"
18 #include "floatauto.h"
19 #include "floatautos.h"
22 #include "keyframes.h"
24 #include "localsession.h"
25 #include "mainclock.h"
27 #include "maskautos.h"
31 #include "mwindowgui.h"
35 #include "playbackengine.h"
36 #include "playtransport.h"
38 #include "pluginpopup.h"
39 #include "pluginset.h"
40 #include "pluginserver.h"
41 #include "preferences.h"
42 #include "resourcepixmap.h"
43 #include "mainsession.h"
44 #include "transitionhandles.h"
45 #include "transitionpopup.h"
46 #include "transportque.h"
50 #include "trackcanvas.h"
52 #include "transition.h"
57 TrackCanvas::TrackCanvas(MWindow *mwindow, MWindowGUI *gui)
58 : BC_SubWindow(mwindow->theme->mcanvas_x,
59 mwindow->theme->mcanvas_y,
63 this->mwindow = mwindow;
66 selection_midpoint1 = selection_midpoint2 = 0;
71 translate_selected = 0;
80 TrackCanvas::~TrackCanvas()
82 for(int i = 0; i < resource_pixmaps.total; i++)
83 delete resource_pixmaps.values[i];
84 // delete transition_handles;
86 delete keyframe_pixmap;
87 delete camerakeyframe_pixmap;
88 delete modekeyframe_pixmap;
89 delete pankeyframe_pixmap;
90 delete projectorkeyframe_pixmap;
91 delete maskkeyframe_pixmap;
92 delete background_pixmap;
95 int TrackCanvas::create_objects()
97 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
98 // transition_handles = new TransitionHandles(mwindow, this);
99 edit_handles = new EditHandles(mwindow, this);
100 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
101 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
102 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
103 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
104 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
105 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
112 void TrackCanvas::resize_event()
114 //printf("TrackCanvas::resize_event 1\n");
117 //printf("TrackCanvas::resize_event 2\n");
120 int TrackCanvas::keypress_event()
124 switch(get_keypress())
129 mwindow->move_left();
136 mwindow->move_right();
144 mwindow->expand_sample();
157 mwindow->zoom_in_sample();
162 mwindow->zoom_in_y();
183 mwindow->move_down();
188 mwindow->zoom_in_t();
197 int TrackCanvas::drag_motion()
200 int cursor_x = get_relative_cursor_x();
201 int cursor_y = get_relative_cursor_y();
202 Track *over_track = 0;
204 PluginSet *over_pluginset = 0;
205 Plugin *over_plugin = 0;
211 drag_popup->cursor_motion_event();
217 if(get_cursor_over_window() &&
220 cursor_x < get_w() &&
223 // Find the edit and track the cursor is over
224 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
226 int64_t track_x, track_y, track_w, track_h;
227 track_dimensions(track, track_x, track_y, track_w, track_h);
229 if(cursor_y >= track_y &&
230 cursor_y < track_y + track_h)
233 for(Edit *edit = track->edits->first; edit; edit = edit->next)
235 int64_t edit_x, edit_y, edit_w, edit_h;
236 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
238 if(cursor_x >= edit_x &&
239 cursor_y >= edit_y &&
240 cursor_x < edit_x + edit_w &&
241 cursor_y < edit_y + edit_h)
248 for(int i = 0; i < track->plugin_set.total; i++)
250 PluginSet *pluginset = track->plugin_set.values[i];
254 for(Plugin *plugin = (Plugin*)pluginset->first;
256 plugin = (Plugin*)plugin->next)
258 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
259 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
261 if(cursor_y >= plugin_y &&
262 cursor_y < plugin_y + plugin_h)
264 over_pluginset = plugin->plugin_set;
266 if(cursor_x >= plugin_x &&
267 cursor_x < plugin_x + plugin_w)
269 over_plugin = plugin;
280 if(mwindow->session->track_highlighted != over_track)
282 mwindow->session->track_highlighted = over_track;
286 if(mwindow->session->edit_highlighted != over_edit)
288 mwindow->session->edit_highlighted = over_edit;
292 if(mwindow->session->pluginset_highlighted != over_pluginset)
294 mwindow->session->pluginset_highlighted = over_pluginset;
298 if(mwindow->session->plugin_highlighted != over_plugin)
300 mwindow->session->plugin_highlighted = over_plugin;
304 //printf("TrackCanvas::drag_motion 2 %p\n", mwindow->session->track_highlighted);
316 int TrackCanvas::drag_start_event()
321 int new_cursor, update_cursor;
323 if(mwindow->session->current_operation != NO_OPERATION) return 0;
327 if(test_plugins(get_drag_x(),
335 if(test_edits(get_drag_x(),
351 int TrackCanvas::drag_motion_event()
353 return drag_motion();
356 int TrackCanvas::drag_stop_event()
358 int result = drag_stop();
362 //printf("TrackCanvas::drag_stop_event 1 %p\n", drag_popup);
372 int TrackCanvas::drag_stop()
374 // In most cases the editing routine redraws and not the drag_stop
375 int result = 0, redraw = 0;
377 switch(mwindow->session->current_operation)
379 case DRAG_VTRANSITION:
380 case DRAG_ATRANSITION:
381 if(mwindow->session->edit_highlighted)
383 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
384 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
385 (mwindow->session->current_operation == DRAG_VTRANSITION &&
386 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))
388 mwindow->session->current_operation = NO_OPERATION;
389 mwindow->paste_transition();
399 // Behavior for dragged plugins is limited by the fact that a shared plugin
400 // can only refer to a standalone plugin that exists in the same position in
401 // time. Dragging a plugin from one point in time to another can't produce
402 // a shared plugin to the original plugin. In this case we relocate the
403 // plugin instead of sharing it.
404 case DRAG_AEFFECT_COPY:
405 case DRAG_VEFFECT_COPY:
406 if(mwindow->session->track_highlighted &&
407 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
408 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
409 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
410 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
412 mwindow->session->current_operation = NO_OPERATION;
414 // Insert shared plugin in source
415 if(mwindow->session->track_highlighted != mwindow->session->drag_plugin->track &&
416 !mwindow->session->plugin_highlighted &&
417 !mwindow->session->pluginset_highlighted)
419 // Move plugin if different startproject
420 mwindow->move_effect(mwindow->session->drag_plugin,
422 mwindow->session->track_highlighted,
427 // Move source to different location
428 if(mwindow->session->pluginset_highlighted)
430 //printf("TrackCanvas::drag_stop 6\n");
431 if(mwindow->session->plugin_highlighted)
433 mwindow->move_effect(mwindow->session->drag_plugin,
434 mwindow->session->plugin_highlighted->plugin_set,
436 mwindow->session->plugin_highlighted->startproject);
441 mwindow->move_effect(mwindow->session->drag_plugin,
442 mwindow->session->pluginset_highlighted,
444 mwindow->session->pluginset_highlighted->length());
449 // Move to a new plugin set between two edits
450 if(mwindow->session->edit_highlighted)
452 mwindow->move_effect(mwindow->session->drag_plugin,
454 mwindow->session->track_highlighted,
455 mwindow->session->edit_highlighted->startproject);
459 // Move to a new plugin set
460 if(mwindow->session->track_highlighted)
462 mwindow->move_effect(mwindow->session->drag_plugin,
464 mwindow->session->track_highlighted,
473 if(mwindow->session->track_highlighted &&
474 ((mwindow->session->current_operation == DRAG_AEFFECT &&
475 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
476 (mwindow->session->current_operation == DRAG_VEFFECT &&
477 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
479 // Drop all the effects
480 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
481 Track *track = mwindow->session->track_highlighted;
483 double length = track->get_length();
485 if(mwindow->session->plugin_highlighted)
487 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
488 length = track->from_units(mwindow->session->plugin_highlighted->length);
489 if(length <= 0) length = track->get_length();
492 if(mwindow->session->pluginset_highlighted)
494 start = track->from_units(plugin_set->length());
495 length = track->get_length() - start;
496 if(length <= 0) length = track->get_length();
499 if(mwindow->edl->local_session->get_selectionend() >
500 mwindow->edl->local_session->get_selectionstart())
502 start = mwindow->edl->local_session->get_selectionstart();
503 length = mwindow->edl->local_session->get_selectionend() -
504 mwindow->edl->local_session->get_selectionstart();
506 // Move to a point between two edits
508 // if(mwindow->session->edit_highlighted)
510 // start = mwindow->session->track_highlighted->from_units(
511 // mwindow->session->edit_highlighted->startproject);
512 // length = mwindow->session->track_highlighted->from_units(
513 // mwindow->session->edit_highlighted->length);
516 mwindow->insert_effects_canvas(start, length);
523 if(mwindow->session->track_highlighted)
525 int64_t position = mwindow->session->edit_highlighted ?
526 mwindow->session->edit_highlighted->startproject :
527 mwindow->session->track_highlighted->edits->length();
528 double position_f = mwindow->session->track_highlighted->from_units(position);
529 Track *track = mwindow->session->track_highlighted;
530 mwindow->session->track_highlighted = 0;
531 result = mwindow->paste_assets(position_f, track);
536 mwindow->session->current_operation = NO_OPERATION;
537 if(mwindow->session->track_highlighted)
539 if(mwindow->session->track_highlighted->data_type == mwindow->session->drag_edit->track->data_type)
541 int64_t position = mwindow->session->edit_highlighted ?
542 mwindow->session->edit_highlighted->startproject :
543 mwindow->session->track_highlighted->edits->length();
544 double position_f = mwindow->session->track_highlighted->from_units(position);
545 Track *track = mwindow->session->track_highlighted;
546 mwindow->session->track_highlighted = 0;
547 mwindow->move_edits(mwindow->session->drag_edits,
559 mwindow->session->track_highlighted = 0;
560 mwindow->session->edit_highlighted = 0;
561 mwindow->session->plugin_highlighted = 0;
562 mwindow->session->current_operation = NO_OPERATION;
566 //printf("TrackCanvas::drag_stop %d %d\n", redraw, mwindow->session->current_operation);
569 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
570 gui->get_scrollbars();
572 gui->patchbay->update();
573 gui->cursor->update();
582 void TrackCanvas::draw(int force, int hide_cursor)
584 // Swap pixmap layers
585 TRON("TrackCanvas::draw")
586 if(get_w() != background_pixmap->get_w() ||
587 get_h() != background_pixmap->get_h())
589 delete background_pixmap;
590 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
593 //printf("TrackCanvas::draw 2\n");
594 // Cursor disappears after resize when this is called.
595 // Cursor doesn't redraw after editing when this isn't called.
596 if(gui->cursor && hide_cursor) gui->cursor->hide();
597 //printf("TrackCanvas::draw 3\n");
598 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
599 //printf("TrackCanvas::draw 4\n");
600 draw_resources(force);
601 //printf("TrackCanvas::draw 5\n");
603 TROFF("TrackCanvas::draw")
606 void TrackCanvas::update_cursor()
608 switch(mwindow->edl->session->editing_mode)
610 case EDITING_ARROW: set_cursor(ARROW_CURSOR); break;
611 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR); break;
616 void TrackCanvas::draw_indexes(Asset *asset)
618 // Don't redraw raw samples
619 if(asset->index_zoom > mwindow->edl->local_session->zoom_sample)
622 draw_resources(0, 1, asset);
630 void TrackCanvas::draw_resources(int force,
634 // Age resource pixmaps for deletion
636 for(int i = 0; i < resource_pixmaps.total; i++)
637 resource_pixmaps.values[i]->visible--;
640 resource_pixmaps.remove_all_objects();
642 //printf("TrackCanvas::draw_resources 1 %d %d\n", force, indexes_only);
645 for(Track *current = mwindow->edl->tracks->first;
649 //printf("TrackCanvas::draw_resources 2\n");
650 for(Edit *edit = current->edits->first; edit; edit = edit->next)
652 //printf("TrackCanvas::draw_resources 3\n");
653 if(!edit->asset) continue;
654 //printf("TrackCanvas::draw_resources 4\n");
657 if(edit->track->data_type != TRACK_AUDIO) continue;
658 if(!edit->asset->test_path(index_asset->path)) continue;
661 int64_t edit_x, edit_y, edit_w, edit_h;
662 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
663 //printf("TrackCanvas::draw_resources 10\n");
666 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
667 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
669 int64_t pixmap_x, pixmap_w, pixmap_h;
671 //printf("TrackCanvas::draw_resources 20\n");
672 // Search for existing pixmap containing edit
673 for(int i = 0; i < resource_pixmaps.total; i++)
675 ResourcePixmap* pixmap = resource_pixmaps.values[i];
676 //printf("TrackCanvas::draw_resources 30\n");
677 // Same pointer can be different edit if editing took place
678 if(pixmap->edit_id == edit->id)
680 //printf("TrackCanvas::draw_resources 40\n");
684 //printf("TrackCanvas::draw_resources 50\n");
687 // Get new size, offset of pixmap needed
688 get_pixmap_size(edit,
694 //printf("TrackCanvas::draw_resources 60\n");
697 if(pixmap_w && pixmap_h)
699 // Create pixmap if it doesn't exist
700 ResourcePixmap* pixmap = create_pixmap(edit,
705 //printf("TrackCanvas::draw_resources 70\n");
706 // Resize it if it's bigger
707 if(pixmap_w > pixmap->pixmap_w ||
708 pixmap_h > pixmap->pixmap_h)
709 pixmap->resize(pixmap_w, pixmap_h);
710 //printf("TrackCanvas::draw_resources 80\n");
711 pixmap->draw_data(edit,
719 //printf("TrackCanvas::draw_resources 90\n");
720 // Resize it if it's smaller
721 if(pixmap_w < pixmap->pixmap_w ||
722 pixmap_h < pixmap->pixmap_h)
723 pixmap->resize(pixmap_w, pixmap_h);
724 //printf("TrackCanvas::draw_resources 100\n");
725 // Copy pixmap to background canvas
726 background_pixmap->draw_pixmap(pixmap,
731 //printf("TrackCanvas::draw_resources 110\n");
736 //printf("TrackCanvas::draw_resources 200\n");
738 // Delete unused pixmaps
740 for(int i = resource_pixmaps.total - 1; i >= 0; i--)
741 if(resource_pixmaps.values[i]->visible < -5)
743 delete resource_pixmaps.values[i];
744 resource_pixmaps.remove(resource_pixmaps.values[i]);
748 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
754 ResourcePixmap *result = 0;
756 for(int i = 0; i < resource_pixmaps.total; i++)
758 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
759 if(resource_pixmaps.values[i]->edit_id == edit->id)
761 result = resource_pixmaps.values[i];
768 //printf("TrackCanvas::create_pixmap 2\n");
769 result = new ResourcePixmap(mwindow,
774 resource_pixmaps.append(result);
777 // result->resize(pixmap_w, pixmap_h);
781 void TrackCanvas::get_pixmap_size(Edit *edit,
789 // Align x on frame boundaries
792 // switch(edit->edits->track->data_type)
804 if(pixmap_x + pixmap_w > get_w())
806 pixmap_w = get_w() - pixmap_x;
813 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
814 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
815 // int64_t pixel_increment = MAX(picon_w, frame_w);
816 // int64_t pixmap_x1 = edit_x;
817 // int64_t pixmap_x2 = edit_x + edit_w;
821 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
826 // if(pixmap_x2 > get_w())
828 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
832 // pixmap_x = pixmap_x1;
833 // pixmap_w = pixmap_x2 - pixmap_x1;
838 pixmap_h = mwindow->edl->local_session->zoom_track;
839 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->title_bg_data->get_h();
840 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
843 void TrackCanvas::edit_dimensions(Edit *edit,
849 //printf("TrackCanvas::edit_dimensions 1 %p\n", edit->track);
850 w = Units::round(edit->track->from_units(edit->length) *
851 mwindow->edl->session->sample_rate /
852 mwindow->edl->local_session->zoom_sample);
853 //printf("TrackCanvas::edit_dimensions 1\n");
857 //printf("TrackCanvas::edit_dimensions 1\n");
858 x = Units::round(edit->track->from_units(edit->startproject) *
859 mwindow->edl->session->sample_rate /
860 mwindow->edl->local_session->zoom_sample -
861 mwindow->edl->local_session->view_start);
863 //printf("TrackCanvas::edit_dimensions 1\n");
864 y = edit->edits->track->y_pixel;
865 //printf("TrackCanvas::edit_dimensions 1\n");
867 if(mwindow->edl->session->show_titles)
868 h += mwindow->theme->title_bg_data->get_h();
869 //printf("TrackCanvas::edit_dimensions 2\n");
872 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
877 h = track->vertical_span(mwindow->theme);
881 void TrackCanvas::draw_paste_destination()
883 int cursor_x = get_cursor_x();
884 int cursor_y = get_cursor_y();
885 int current_atrack = 0;
886 int current_vtrack = 0;
887 int current_aedit = 0;
888 int current_vedit = 0;
893 //printf("TrackCanvas::draw_paste_destination 1\n");
894 if((mwindow->session->current_operation == DRAG_ASSET &&
895 (mwindow->session->drag_assets->total ||
896 mwindow->session->drag_clips->total)) ||
897 (mwindow->session->current_operation == DRAG_EDIT &&
898 mwindow->session->drag_edits->total))
900 //printf("TrackCanvas::draw_paste_destination 1\n");
905 if(mwindow->session->current_operation == DRAG_ASSET &&
906 mwindow->session->drag_assets->total)
907 asset = mwindow->session->drag_assets->values[0];
909 if(mwindow->session->current_operation == DRAG_ASSET &&
910 mwindow->session->drag_clips->total)
911 clip = mwindow->session->drag_clips->values[0];
913 // Get destination track
914 for(Track *dest = mwindow->session->track_highlighted;
920 // Get source width in pixels
924 // Use start of highlighted edit
925 if(mwindow->session->edit_highlighted)
926 position = mwindow->session->track_highlighted->from_units(
927 mwindow->session->edit_highlighted->startproject);
929 // Use end of highlighted track, disregarding effects
930 position = mwindow->session->track_highlighted->from_units(
931 mwindow->session->track_highlighted->edits->length());
933 // Get the x coordinate
934 x = Units::to_int64(position *
935 mwindow->edl->session->sample_rate /
936 mwindow->edl->local_session->zoom_sample) -
937 mwindow->edl->local_session->view_start;
939 if(dest->data_type == TRACK_AUDIO)
941 if(asset && current_atrack < asset->channels)
943 w = Units::to_int64((double)asset->audio_length /
945 mwindow->edl->session->sample_rate /
946 mwindow->edl->local_session->zoom_sample);
951 if(clip && current_atrack < clip->tracks->total_audio_tracks())
953 w = Units::to_int64((double)clip->tracks->total_length() *
954 mwindow->edl->session->sample_rate /
955 mwindow->edl->local_session->zoom_sample);
956 //printf("draw_paste_destination %d\n", x);
961 if(mwindow->session->current_operation == DRAG_EDIT &&
962 current_aedit < mwindow->session->drag_edits->total)
965 while(current_aedit < mwindow->session->drag_edits->total &&
966 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
969 if(current_aedit < mwindow->session->drag_edits->total)
971 edit = mwindow->session->drag_edits->values[current_aedit];
972 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
980 if(dest->data_type == TRACK_VIDEO)
982 //printf("draw_paste_destination 1\n");
983 if(asset && current_vtrack < asset->layers)
985 w = Units::to_int64((double)asset->video_length /
987 mwindow->edl->session->sample_rate /
988 mwindow->edl->local_session->zoom_sample);
993 if(clip && current_vtrack < clip->tracks->total_video_tracks())
995 w = Units::to_int64(clip->tracks->total_length() *
996 mwindow->edl->session->sample_rate /
997 mwindow->edl->local_session->zoom_sample);
1002 if(mwindow->session->current_operation == DRAG_EDIT &&
1003 current_vedit < mwindow->session->drag_edits->total)
1005 //printf("draw_paste_destination 2\n");
1007 while(current_vedit < mwindow->session->drag_edits->total &&
1008 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1011 if(current_vedit < mwindow->session->drag_edits->total)
1013 //printf("draw_paste_destination 3\n");
1014 edit = mwindow->session->drag_edits->values[current_vedit];
1015 w = Units::to_int64(edit->track->from_units(edit->length) *
1016 mwindow->edl->session->sample_rate /
1017 mwindow->edl->local_session->zoom_sample);
1027 int y = dest->y_pixel;
1028 int h = dest->vertical_span(mwindow->theme);
1031 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1032 if(x < -BC_INFINITY)
1034 w -= -BC_INFINITY - x;
1035 x += -BC_INFINITY - x;
1038 draw_highlight_rectangle(x, y, w, h);
1045 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1047 x = Units::round(plugin->track->from_units(plugin->startproject) *
1048 mwindow->edl->session->sample_rate /
1049 mwindow->edl->local_session->zoom_sample -
1050 mwindow->edl->local_session->view_start);
1051 w = Units::round(plugin->track->from_units(plugin->length) *
1052 mwindow->edl->session->sample_rate /
1053 mwindow->edl->local_session->zoom_sample);
1054 y = plugin->track->y_pixel +
1055 mwindow->edl->local_session->zoom_track +
1056 plugin->plugin_set->get_number() *
1057 mwindow->theme->plugin_bg_data->get_h();
1058 if(mwindow->edl->session->show_titles)
1059 y += mwindow->theme->title_bg_data->get_h();
1060 h = mwindow->theme->plugin_bg_data->get_h();
1063 int TrackCanvas::resource_h()
1065 return mwindow->edl->local_session->zoom_track;
1068 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1080 w = MIN(w, get_w() + 20);
1081 h = MIN(h, get_h() + 20);
1084 draw_rectangle(x, y, w, h);
1085 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1087 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d\n", x, y, w, h);
1090 void TrackCanvas::draw_playback_cursor()
1092 // Called before playback_cursor exists
1093 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1095 // mwindow->playback_cursor->visible = 0;
1096 // mwindow->playback_cursor->draw();
1100 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1102 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1103 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1105 edit_dimensions(edit, x, y, w, h);
1107 if(mwindow->edl->session->show_titles)
1109 y += mwindow->theme->title_bg_data->get_h();
1116 if(side == EDIT_OUT)
1125 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1127 //printf("TrackCanvas::get_transition_coords 1\n");
1128 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1129 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1130 int transition_w = 30;
1131 int transition_h = 30;
1132 //printf("TrackCanvas::get_transition_coords 1\n");
1134 if(mwindow->edl->session->show_titles)
1135 y += mwindow->theme->title_bg_data->get_h();
1136 //printf("TrackCanvas::get_transition_coords 2\n");
1138 y += (h - mwindow->theme->title_bg_data->get_h()) / 2 - transition_h / 2;
1139 x -= transition_w / 2;
1145 void TrackCanvas::draw_highlighting()
1149 //printf("TrackCanvas::draw_highlighting 1 %p %d\n", mwindow->session->track_highlighted, mwindow->session->current_operation);
1153 switch(mwindow->session->current_operation)
1155 case DRAG_ATRANSITION:
1156 case DRAG_VTRANSITION:
1157 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1158 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1159 if(mwindow->session->edit_highlighted)
1161 //printf("TrackCanvas::draw_highlighting 2\n");
1162 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1163 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1164 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1165 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))
1167 //printf("TrackCanvas::draw_highlighting 2\n");
1168 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1169 //printf("TrackCanvas::draw_highlighting 2\n");
1171 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1172 MWindowGUI::visible(y, y + h, 0, get_h()))
1175 get_transition_coords(x, y, w, h);
1177 //printf("TrackCanvas::draw_highlighting 3\n");
1184 // Dragging a new effect from the Resource window
1187 if(mwindow->session->track_highlighted &&
1188 ((mwindow->session->current_operation == DRAG_AEFFECT && mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1189 (mwindow->session->current_operation == DRAG_VEFFECT && mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
1191 // Put it before another plugin
1192 if(mwindow->session->plugin_highlighted)
1194 plugin_dimensions(mwindow->session->plugin_highlighted,
1199 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1202 // Put it after a plugin set
1203 if(mwindow->session->pluginset_highlighted &&
1204 mwindow->session->pluginset_highlighted->last)
1206 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1211 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1212 int64_t track_x, track_y, track_w, track_h;
1213 track_dimensions(mwindow->session->track_highlighted,
1221 mwindow->session->track_highlighted->get_length() *
1222 mwindow->edl->session->sample_rate /
1223 mwindow->edl->local_session->zoom_sample -
1224 mwindow->edl->local_session->view_start) -
1226 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1227 if(w <= 0) w = track_w;
1231 track_dimensions(mwindow->session->track_highlighted,
1237 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1238 // Put it in a new plugin set determined by the selected range
1239 if(mwindow->edl->local_session->get_selectionend() >
1240 mwindow->edl->local_session->get_selectionstart())
1242 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1243 mwindow->edl->session->sample_rate /
1244 mwindow->edl->local_session->zoom_sample -
1245 mwindow->edl->local_session->view_start);
1246 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1247 mwindow->edl->local_session->get_selectionstart()) *
1248 mwindow->edl->session->sample_rate /
1249 mwindow->edl->local_session->zoom_sample);
1251 // Put it in a new plugin set determined by an edit boundary
1253 // if(mwindow->session->edit_highlighted)
1255 // int64_t temp_y, temp_h;
1256 // edit_dimensions(mwindow->session->edit_highlighted,
1262 // Put it at the beginning of the track in a new plugin set
1265 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1266 MWindowGUI::visible(y, y + h, 0, get_h()))
1268 //printf("TrackCanvas::draw_highlighting 1\n");
1275 if(mwindow->session->track_highlighted)
1277 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1279 if(MWindowGUI::visible(y, y + h, 0, get_h()))
1281 draw_paste_destination();
1286 // Dragging an effect from the timeline
1287 case DRAG_AEFFECT_COPY:
1288 case DRAG_VEFFECT_COPY:
1289 if((mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1290 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY && mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1291 (mwindow->session->current_operation == DRAG_VEFFECT_COPY && mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
1293 // Put it before another plugin
1294 if(mwindow->session->plugin_highlighted)
1295 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1297 // Put it after a plugin set
1298 if(mwindow->session->pluginset_highlighted &&
1299 mwindow->session->pluginset_highlighted->last)
1301 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last, x, y, w, h);
1305 if(mwindow->session->track_highlighted)
1307 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1309 // Put it in a new plugin set determined by an edit boundary
1310 if(mwindow->session->edit_highlighted)
1312 int64_t temp_y, temp_h;
1313 edit_dimensions(mwindow->session->edit_highlighted,
1319 // Put it in a new plugin set at the start of the track
1322 // Calculate length of plugin based on data type of track and units
1323 if(mwindow->session->track_highlighted->data_type == TRACK_VIDEO)
1325 w = (int64_t)((double)mwindow->session->drag_plugin->length /
1326 mwindow->edl->session->frame_rate *
1327 mwindow->edl->session->sample_rate /
1328 mwindow->edl->local_session->zoom_sample);
1332 w = (int64_t)mwindow->session->drag_plugin->length /
1333 mwindow->edl->local_session->zoom_sample;
1336 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1337 MWindowGUI::visible(y, y + h, 0, get_h()))
1346 //printf("TrackCanvas::draw_highlighting 1\n");
1347 if(mwindow->session->track_highlighted)
1349 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1351 if(MWindowGUI::visible(y, y + h, 0, get_h()))
1353 draw_paste_destination();
1364 draw_highlight_rectangle(x, y, w, h);
1368 void TrackCanvas::draw_plugins()
1370 char string[BCTEXTLEN];
1372 for(Track *track = mwindow->edl->tracks->first;
1374 track = track->next)
1376 if(track->expand_view)
1378 for(int i = 0; i < track->plugin_set.total; i++)
1380 PluginSet *pluginset = track->plugin_set.values[i];
1382 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1384 int64_t total_x, y, total_w, h;
1385 plugin_dimensions(plugin, total_x, y, total_w, h);
1387 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1388 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1389 plugin->plugin_type != PLUGIN_NONE)
1391 int x = total_x, w = total_w, left_margin = 5;
1397 if(w + x > get_w()) w -= (w + x) - get_w();
1404 mwindow->theme->plugin_bg_data,
1407 set_font(MEDIUMFONT_3D);
1408 plugin->calculate_title(string);
1410 // Truncate string to int64_test visible in background
1411 int len = strlen(string), j;
1412 for(j = len; j >= 0; j--)
1414 if(left_margin + get_text_width(MEDIUMFONT_3D, string) > w)
1422 // Justify the text on the left boundary of the edit if it is visible.
1423 // Otherwise justify it on the left side of the screen.
1424 int text_x = total_x + left_margin;
1425 text_x = MAX(left_margin, text_x);
1427 y + get_text_ascent(MEDIUMFONT_3D) + 2,
1439 void TrackCanvas::draw_inout_points()
1444 void TrackCanvas::draw_drag_handle()
1446 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1447 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1449 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1450 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1451 mwindow->edl->session->sample_rate /
1452 mwindow->edl->local_session->zoom_sample -
1453 mwindow->edl->local_session->view_start);
1454 //printf("TrackCanvas::draw_drag_handle 2 %d\n", pixel1);
1457 //printf("TrackCanvas::draw_drag_handle 3\n");
1458 draw_line(pixel1, 0, pixel1, get_h());
1460 //printf("TrackCanvas::draw_drag_handle 4\n");
1465 void TrackCanvas::draw_transitions()
1469 for(Track *track = mwindow->edl->tracks->first;
1471 track = track->next)
1473 for(Edit *edit = track->edits->first;
1477 if(edit->transition)
1479 edit_dimensions(edit, x, y, w, h);
1480 get_transition_coords(x, y, w, h);
1482 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1483 MWindowGUI::visible(y, y + h, 0, get_h()))
1485 PluginServer *server = mwindow->scan_plugindb(edit->transition->title);
1486 draw_vframe(server->picon,
1493 server->picon->get_w(),
1494 server->picon->get_h());
1501 void TrackCanvas::draw_loop_points()
1503 //printf("TrackCanvas::draw_loop_points 1\n");
1504 if(mwindow->edl->local_session->loop_playback)
1506 //printf("TrackCanvas::draw_loop_points 2\n");
1507 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1508 mwindow->edl->session->sample_rate /
1509 mwindow->edl->local_session->zoom_sample -
1510 mwindow->edl->local_session->view_start);
1511 //printf("TrackCanvas::draw_loop_points 3\n");
1513 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1516 draw_line(x, 0, x, get_h());
1518 //printf("TrackCanvas::draw_loop_points 4\n");
1520 x = Units::round(mwindow->edl->local_session->loop_end *
1521 mwindow->edl->session->sample_rate /
1522 mwindow->edl->local_session->zoom_sample -
1523 mwindow->edl->local_session->view_start);
1524 //printf("TrackCanvas::draw_loop_points 5\n");
1526 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1529 draw_line(x, 0, x, get_h());
1531 //printf("TrackCanvas::draw_loop_points 6\n");
1533 //printf("TrackCanvas::draw_loop_points 7\n");
1536 void TrackCanvas::draw_brender_start()
1538 if(mwindow->preferences->use_brender)
1540 int64_t x = Units::round(mwindow->edl->session->brender_start *
1541 mwindow->edl->session->sample_rate /
1542 mwindow->edl->local_session->zoom_sample -
1543 mwindow->edl->local_session->view_start);
1545 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1548 draw_line(x, 0, x, get_h());
1553 int TrackCanvas::do_keyframes(int cursor_x,
1561 int current_tool = 0;
1563 EDLSession *session = mwindow->edl->session;
1565 for(Track *track = mwindow->edl->tracks->first;
1567 track = track->next)
1569 Automation *automation = track->automation;
1571 //printf("TrackCanvas::draw_keyframes 1\n");
1572 if(!result && session->auto_conf->fade)
1574 result = do_float_autos(track,
1575 automation->fade_autos,
1581 if(result && mwindow->session->current_operation == DRAG_FADE)
1585 if(result && buttonpress)
1587 mwindow->session->current_operation = DRAG_FADE;
1588 update_drag_caption();
1592 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1594 if(!result && session->auto_conf->czoom && automation->czoom_autos)
1596 result = do_float_autos(track,
1597 automation->czoom_autos,
1603 if(result && mwindow->session->current_operation == DRAG_CZOOM)
1607 if(result && buttonpress)
1609 mwindow->session->current_operation = DRAG_CZOOM;
1610 update_drag_caption();
1614 //printf("TrackCanvas::draw_keyframes 2 %d\n", result);
1615 if(!result && session->auto_conf->pzoom && automation->pzoom_autos)
1617 result = do_float_autos(track,
1618 automation->pzoom_autos,
1624 if(result && mwindow->session->current_operation == DRAG_PZOOM)
1628 if(result && buttonpress)
1630 mwindow->session->current_operation = DRAG_PZOOM;
1631 update_drag_caption();
1635 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1636 if(!result && session->auto_conf->mute)
1638 result = do_toggle_autos(track,
1639 automation->mute_autos,
1645 if(result && mwindow->session->current_operation == DRAG_MUTE)
1649 if(result && buttonpress)
1651 mwindow->session->current_operation = DRAG_MUTE;
1652 update_drag_caption();
1656 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1657 if(!result && session->auto_conf->camera && automation->camera_autos)
1659 result = do_autos(track,
1660 automation->camera_autos,
1665 camerakeyframe_pixmap);
1666 if(result && mwindow->session->current_operation == DRAG_CAMERA)
1670 if(result && buttonpress)
1672 mwindow->session->current_operation = DRAG_CAMERA_PRE;
1673 update_drag_caption();
1678 if(!result && session->auto_conf->mode && automation->mode_autos)
1680 result = do_autos(track,
1681 automation->mode_autos,
1686 modekeyframe_pixmap);
1687 if(result && mwindow->session->current_operation == DRAG_MODE)
1691 if(result && buttonpress)
1693 mwindow->session->current_operation = DRAG_MODE_PRE;
1694 update_drag_caption();
1699 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1700 if(!result && session->auto_conf->projector && automation->projector_autos)
1702 result = do_autos(track,
1703 automation->projector_autos,
1708 projectorkeyframe_pixmap);
1709 if(result && mwindow->session->current_operation == DRAG_PROJECTOR)
1713 if(result && buttonpress)
1715 mwindow->session->current_operation = DRAG_PROJECTOR_PRE;
1716 update_drag_caption();
1721 if(!result && session->auto_conf->mask && automation->mask_autos)
1723 result = do_autos(track,
1724 automation->mask_autos,
1729 maskkeyframe_pixmap);
1730 if(result && mwindow->session->current_operation == DRAG_MASK)
1734 if(result && buttonpress)
1736 mwindow->session->current_operation = DRAG_MASK_PRE;
1737 update_drag_caption();
1742 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1743 if(!result && session->auto_conf->pan && automation->pan_autos)
1745 result = do_autos(track,
1746 automation->pan_autos,
1751 pankeyframe_pixmap);
1752 if(result && mwindow->session->current_operation == DRAG_PAN)
1756 if(result && buttonpress)
1758 mwindow->session->current_operation = DRAG_PAN_PRE;
1759 update_drag_caption();
1764 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1765 if(!result && session->auto_conf->plugins)
1767 result = do_plugin_autos(track,
1772 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY)
1776 if(result && buttonpress)
1778 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
1779 update_drag_caption();
1783 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1786 if(mwindow->session->current_operation == DRAG_FADE ||
1787 mwindow->session->current_operation == DRAG_CZOOM ||
1788 mwindow->session->current_operation == DRAG_PZOOM ||
1789 mwindow->session->current_operation == DRAG_PLAY ||
1790 mwindow->session->current_operation == DRAG_MUTE ||
1791 mwindow->session->current_operation == DRAG_CAMERA ||
1792 mwindow->session->current_operation == DRAG_CAMERA_PRE ||
1793 mwindow->session->current_operation == DRAG_MASK ||
1794 mwindow->session->current_operation == DRAG_MASK_PRE ||
1795 mwindow->session->current_operation == DRAG_MODE ||
1796 mwindow->session->current_operation == DRAG_MODE_PRE ||
1797 mwindow->session->current_operation == DRAG_PAN ||
1798 mwindow->session->current_operation == DRAG_PAN_PRE ||
1799 mwindow->session->current_operation == DRAG_PLUGINKEY ||
1800 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE ||
1801 mwindow->session->current_operation == DRAG_PROJECTOR ||
1802 mwindow->session->current_operation == DRAG_PROJECTOR_PRE)
1807 //printf("TrackCanvas::draw_keyframes 2 %d\n", result);
1811 new_cursor = UPRIGHT_ARROW_CURSOR;
1815 //printf("TrackCanvas::do_keyframes 3 %d\n", result);
1819 void TrackCanvas::draw_auto(Auto *current,
1827 char string[BCTEXTLEN];
1829 x1 = x - HANDLE_W / 2;
1830 x2 = x + HANDLE_W / 2;
1831 y1 = center_pixel + y - HANDLE_W / 2;
1832 y2 = center_pixel + y + HANDLE_W / 2;
1834 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
1835 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
1838 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
1840 draw_box(x1, y1, x2 - x1, y2 - y1);
1843 void TrackCanvas::draw_floatauto(Auto *current,
1855 int in_x1, in_y1, in_x2, in_y2;
1856 int out_x1, out_y1, out_x2, out_y2;
1857 char string[BCTEXTLEN];
1860 x1 = x - HANDLE_W / 2;
1861 x2 = x + HANDLE_W / 2;
1862 y1 = center_pixel + y - HANDLE_W / 2;
1863 y2 = center_pixel + y + HANDLE_W / 2;
1865 CLAMP(y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1866 CLAMP(y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1869 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
1871 draw_box(x1, y1, x2 - x1, y2 - y1);
1874 in_x1 = in_x - HANDLE_W / 2;
1875 in_x2 = in_x + HANDLE_W / 2;
1876 in_y1 = center_pixel + in_y - HANDLE_W / 2;
1877 in_y2 = center_pixel + in_y + HANDLE_W / 2;
1879 CLAMP(in_y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1880 CLAMP(in_y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1881 CLAMP(in_y, -zoom_track / 2, zoom_track / 2);
1884 draw_line(x + 1, center_pixel + y + 1, in_x + 1, center_pixel + in_y + 1);
1885 draw_box(in_x1 + 1, in_y1 + 1, in_x2 - in_x1, in_y2 - in_y1);
1887 draw_line(x, center_pixel + y, in_x, center_pixel + in_y);
1888 draw_box(in_x1, in_y1, in_x2 - in_x1, in_y2 - in_y1);
1893 out_x1 = out_x - HANDLE_W / 2;
1894 out_x2 = out_x + HANDLE_W / 2;
1895 out_y1 = center_pixel + out_y - HANDLE_W / 2;
1896 out_y2 = center_pixel + out_y + HANDLE_W / 2;
1898 CLAMP(out_y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1899 CLAMP(out_y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1900 CLAMP(out_y, -zoom_track / 2, zoom_track / 2);
1904 draw_line(x + 1, center_pixel + y + 1, out_x + 1, center_pixel + out_y + 1);
1905 draw_box(out_x1 + 1, out_y1 + 1, out_x2 - out_x1, out_y2 - out_y1);
1907 draw_line(x, center_pixel + y, out_x, center_pixel + out_y);
1908 draw_box(out_x1, out_y1, out_x2 - out_x1, out_y2 - out_y1);
1912 int TrackCanvas::test_auto(Auto *current,
1922 char string[BCTEXTLEN];
1925 x1 = x - HANDLE_W / 2;
1926 x2 = x + HANDLE_W / 2;
1927 y1 = center_pixel + y - HANDLE_W / 2;
1928 y2 = center_pixel + y + HANDLE_W / 2;
1930 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
1931 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
1932 //printf("test_auto 1 %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
1934 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
1936 //printf("test_auto 2 %d\n", buttonpress);
1939 //printf("test_auto 3\n");
1940 mwindow->session->drag_auto = current;
1941 mwindow->session->drag_start_percentage = current->value_to_percentage();
1942 mwindow->session->drag_start_position = current->position;
1943 mwindow->session->drag_origin_x = cursor_x;
1944 mwindow->session->drag_origin_y = cursor_y;
1952 int TrackCanvas::test_floatauto(Auto *current,
1966 int in_x1, in_y1, in_x2, in_y2;
1967 int out_x1, out_y1, out_x2, out_y2;
1968 char string[BCTEXTLEN];
1971 x1 = x - HANDLE_W / 2;
1972 x2 = x + HANDLE_W / 2;
1973 y1 = center_pixel + y - HANDLE_W / 2;
1974 y2 = center_pixel + y + HANDLE_W / 2;
1976 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
1977 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
1979 in_x1 = in_x - HANDLE_W / 2;
1980 in_x2 = in_x + HANDLE_W / 2;
1981 in_y1 = center_pixel + in_y - HANDLE_W / 2;
1982 in_y2 = center_pixel + in_y + HANDLE_W / 2;
1984 if(in_y1 < center_pixel + -zoom_track / 2) in_y1 = center_pixel + -zoom_track / 2;
1985 if(in_y2 > center_pixel + zoom_track / 2) in_y2 = center_pixel + zoom_track / 2;
1987 out_x1 = out_x - HANDLE_W / 2;
1988 out_x2 = out_x + HANDLE_W / 2;
1989 out_y1 = center_pixel + out_y - HANDLE_W / 2;
1990 out_y2 = center_pixel + out_y + HANDLE_W / 2;
1992 if(out_y1 < center_pixel + -zoom_track / 2) out_y1 = center_pixel + -zoom_track / 2;
1993 if(out_y2 > center_pixel + zoom_track / 2) out_y2 = center_pixel + zoom_track / 2;
1997 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2007 mwindow->session->drag_auto = current;
2008 mwindow->session->drag_start_percentage = current->value_to_percentage();
2009 mwindow->session->drag_start_position = current->position;
2010 mwindow->session->drag_origin_x = cursor_x;
2011 mwindow->session->drag_origin_y = cursor_y;
2012 mwindow->session->drag_handle = 0;
2019 cursor_x >= in_x1 &&
2021 cursor_y >= in_y1 &&
2023 current->position > 0)
2027 mwindow->session->drag_auto = current;
2028 mwindow->session->drag_start_percentage =
2029 current->invalue_to_percentage();
2030 mwindow->session->drag_start_position =
2031 ((FloatAuto*)current)->control_in_position;
2032 mwindow->session->drag_origin_x = cursor_x;
2033 mwindow->session->drag_origin_y = cursor_y;
2034 mwindow->session->drag_handle = 1;
2041 cursor_x >= out_x1 &&
2042 cursor_x < out_x2 &&
2043 cursor_y >= out_y1 &&
2048 mwindow->session->drag_auto = current;
2049 mwindow->session->drag_start_percentage =
2050 current->outvalue_to_percentage();
2051 mwindow->session->drag_start_position =
2052 ((FloatAuto*)current)->control_out_position;
2053 mwindow->session->drag_origin_x = cursor_x;
2054 mwindow->session->drag_origin_y = cursor_y;
2055 mwindow->session->drag_handle = 2;
2061 // 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",
2062 // mwindow->session->drag_handle,
2071 void TrackCanvas::draw_floatline(int center_pixel,
2072 FloatAuto *previous,
2084 // Solve bezier equation for either every pixel or a certain large number of
2089 // Not using slope intercept
2096 // Call by reference fails for some reason here
2097 FloatAuto *previous1 = previous, *next1 = next;
2098 for(int x = x1; x < x2; x++)
2100 int64_t position = (int64_t)(unit_start + x * zoom_units);
2101 float value = autos->get_value(position, PLAY_FORWARD, previous1, next1);
2103 int y = (int)(center_pixel +
2104 (autos->value_to_percentage(value) - 0.5) * -yscale);
2109 draw_line(x - 1, prev_y + 1, x, y + 1);
2111 draw_line(x - 1, prev_y, x, y);
2118 // set_color(BLACK);
2119 // draw_line(x1, center_pixel + y1 + 1, x2, center_pixel + y2 + 1);
2120 // set_color(WHITE);
2121 // draw_line(x1, center_pixel + y1, x2, center_pixel + y2);
2129 int TrackCanvas::test_floatline(int center_pixel,
2143 int64_t position = (int64_t)(unit_start + cursor_x * zoom_units);
2144 // Call by reference fails for some reason here
2145 FloatAuto *previous = 0, *next = 0;
2146 float value = autos->get_value(position, PLAY_FORWARD, previous, next);
2147 int y = (int)(center_pixel +
2148 (autos->value_to_percentage(value) - 0.5) * -yscale);
2150 if(cursor_x >= x1 &&
2152 cursor_y >= y - HANDLE_W / 2 &&
2153 cursor_y < y + HANDLE_W / 2 &&
2161 mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
2165 current = mwindow->session->drag_auto = autos->insert_auto(position);
2166 ((FloatAuto*)current)->value = value;
2167 mwindow->session->drag_start_percentage = current->value_to_percentage();
2168 mwindow->session->drag_start_position = current->position;
2169 mwindow->session->drag_origin_x = cursor_x;
2170 mwindow->session->drag_origin_y = cursor_y;
2171 mwindow->session->drag_handle = 0;
2180 void TrackCanvas::draw_toggleline(int center_pixel,
2188 draw_line(x1, center_pixel + y1 + 1, x2, center_pixel + y1 + 1);
2190 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2195 draw_line(x2 + 1, center_pixel + y1, x2 + 1, center_pixel + y2);
2197 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2201 int TrackCanvas::test_toggleline(Autos *autos,
2212 if(cursor_x >= x1 && cursor_x < x2)
2214 int miny = center_pixel + y1 - HANDLE_W / 2;
2215 int maxy = center_pixel + y1 + HANDLE_W / 2;
2216 if(cursor_y >= miny && cursor_y < maxy)
2222 mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
2226 double position = (double)(cursor_x +
2227 mwindow->edl->local_session->view_start) *
2228 mwindow->edl->local_session->zoom_sample /
2229 mwindow->edl->session->sample_rate;
2230 int64_t unit_position = autos->track->to_units(position, 0);
2231 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2233 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2234 ((IntAuto*)current)->value = new_value;
2235 mwindow->session->drag_start_percentage = current->value_to_percentage();
2236 mwindow->session->drag_start_position = current->position;
2237 mwindow->session->drag_origin_x = cursor_x;
2238 mwindow->session->drag_origin_y = cursor_y;
2246 void TrackCanvas::calculate_viewport(Track *track,
2247 double &view_start, // Seconds
2248 int64_t &unit_start,
2249 double &view_end, // Seconds
2253 double &zoom_sample,
2256 view_start = (double)mwindow->edl->local_session->view_start *
2257 mwindow->edl->local_session->zoom_sample /
2258 mwindow->edl->session->sample_rate;
2259 unit_start = track->to_units(view_start, 0);
2260 view_end = (double)(mwindow->edl->local_session->view_start +
2262 mwindow->edl->local_session->zoom_sample /
2263 mwindow->edl->session->sample_rate;
2264 unit_end = (int64_t)(track->to_units(view_end, 1));
2265 yscale = mwindow->edl->local_session->zoom_track;
2266 center_pixel = (int)(track->y_pixel + yscale / 2) +
2267 (mwindow->edl->session->show_titles ?
2268 mwindow->theme->title_bg_data->get_h() :
2270 zoom_sample = mwindow->edl->local_session->zoom_sample;
2272 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2275 int TrackCanvas::do_float_autos(Track *track,
2293 double ax, ay, ax2, ay2;
2294 double in_x2, in_y2, out_x2, out_y2;
2299 calculate_viewport(track,
2311 // Get first auto before start
2314 for(current = autos->last;
2315 current && current->position >= unit_start;
2321 ax = (double)(current->position - unit_start) / zoom_units;
2322 ay = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2327 current = autos->first ? autos->first : autos->default_auto;
2331 ay = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2341 //printf("TrackCanvas::do_float_autos 1\n");
2352 ax2 = (double)(current->position - unit_start) / zoom_units;
2353 ay2 = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2354 in_x2 = (double)(current->position +
2355 ((FloatAuto*)current)->control_in_position -
2358 in_y2 = (((FloatAuto*)current)->invalue_to_percentage() - 0.5) * -yscale;
2359 out_x2 = (double)(current->position +
2360 ((FloatAuto*)current)->control_out_position -
2363 out_y2 = (((FloatAuto*)current)->outvalue_to_percentage() - 0.5) * -yscale;
2372 slope = (ay2 - ay) / (ax2 - ax);
2378 ay2 = ay + slope * (get_w() - ax);
2383 ay = ay + slope * (0 - ax);
2401 if(current && !result)
2403 if(current != autos->default_auto)
2408 result = test_floatauto(current,
2423 draw_floatauto(current,
2440 // Draw joining line
2447 result = test_floatline(center_pixel,
2453 // Exclude auto coverage from the end of the line. The auto overlaps
2454 (int)ax2 - HANDLE_W / 2,
2462 draw_floatline(center_pixel,
2463 (FloatAuto*)previous,
2464 (FloatAuto*)current,
2492 current->position <= unit_end &&
2495 //printf("TrackCanvas::do_float_autos 100\n");
2504 if(ax < get_w() && !result)
2512 result = test_floatline(center_pixel,
2525 draw_floatline(center_pixel,
2526 (FloatAuto*)previous,
2527 (FloatAuto*)current,
2550 int TrackCanvas::do_toggle_autos(Track *track,
2567 double ax, ay, ax2, ay2;
2569 calculate_viewport(track,
2580 double high = -yscale * 0.8 / 2;
2581 double low = yscale * 0.8 / 2;
2583 // Get first auto before start
2585 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
2591 ay = ((IntAuto*)current)->value > 0 ? high : low;
2596 current = autos->first ? autos->first : autos->default_auto;
2600 ay = ((IntAuto*)current)->value > 0 ? high : low;
2613 ax2 = (double)(current->position - unit_start) / zoom_units;
2614 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
2622 if(ax2 > get_w()) ax2 = get_w();
2624 if(current && !result)
2626 if(current != autos->default_auto)
2632 result = test_auto(current,
2660 result = test_toggleline(autos,
2673 draw_toggleline(center_pixel,
2682 }while(current && current->position <= unit_end && !result);
2684 if(ax < get_w() && !result)
2692 result = test_toggleline(autos,
2704 draw_toggleline(center_pixel,
2714 int TrackCanvas::do_autos(Track *track,
2733 calculate_viewport(track,
2745 for(current = autos->first; current && !result; current = NEXT)
2747 if(current->position >= unit_start && current->position < unit_end)
2750 x = (int64_t)((double)(current->position - unit_start) /
2751 zoom_units - (pixmap->get_w() / 2 + 0.5));
2752 y = center_pixel - pixmap->get_h() / 2;
2756 if(cursor_x >= x && cursor_y >= y &&
2757 cursor_x < x + pixmap->get_w() &&
2758 cursor_y < y + pixmap->get_h())
2764 mwindow->session->drag_auto = current;
2765 mwindow->session->drag_start_position = current->position;
2766 mwindow->session->drag_origin_x = cursor_x;
2767 mwindow->session->drag_origin_y = cursor_y;
2769 double position = autos->track->from_units(current->position);
2770 double center = (mwindow->edl->local_session->selectionstart +
2771 mwindow->edl->local_session->selectionend) /
2776 mwindow->edl->local_session->selectionstart = position;
2777 mwindow->edl->local_session->selectionend = position;
2780 if(position < center)
2782 mwindow->edl->local_session->selectionstart = position;
2785 mwindow->edl->local_session->selectionend = position;
2790 draw_pixmap(pixmap, x, y);
2796 int TrackCanvas::do_plugin_autos(Track *track,
2813 calculate_viewport(track,
2823 //printf("TrackCanvas::draw_plugin_autos 1 %d\n", track->plugin_set.total);
2824 for(int i = 0; i < track->plugin_set.total && !result; i++)
2826 PluginSet *plugin_set = track->plugin_set.values[i];
2827 int center_pixel = (int)(track->y_pixel +
2828 mwindow->edl->local_session->zoom_track +
2829 (i + 0.5) * mwindow->theme->plugin_bg_data->get_h() +
2830 (mwindow->edl->session->show_titles ? mwindow->theme->title_bg_data->get_h() : 0));
2832 //printf("TrackCanvas::draw_plugin_autos 2\n");
2833 for(Plugin *plugin = (Plugin*)plugin_set->first;
2835 plugin = (Plugin*)plugin->next)
2837 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
2838 keyframe && !result;
2839 keyframe = (KeyFrame*)keyframe->next)
2841 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
2842 if(keyframe->position >= unit_start && keyframe->position < unit_end)
2844 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
2845 int y = center_pixel - keyframe_pixmap->get_h() / 2;
2847 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
2850 if(cursor_x >= x && cursor_y >= y &&
2851 cursor_x < x + keyframe_pixmap->get_w() &&
2852 cursor_y < y + keyframe_pixmap->get_h())
2858 mwindow->session->drag_auto = keyframe;
2859 mwindow->session->drag_start_position = keyframe->position;
2860 mwindow->session->drag_origin_x = cursor_x;
2861 mwindow->session->drag_origin_y = cursor_y;
2863 double position = track->from_units(keyframe->position);
2864 double center = (mwindow->edl->local_session->selectionstart +
2865 mwindow->edl->local_session->selectionend) /
2870 mwindow->edl->local_session->selectionstart = position;
2871 mwindow->edl->local_session->selectionend = position;
2874 if(position < center)
2876 mwindow->edl->local_session->selectionstart = position;
2879 mwindow->edl->local_session->selectionend = position;
2884 draw_pixmap(keyframe_pixmap,
2891 //printf("TrackCanvas::draw_plugin_autos 5\n");
2895 void TrackCanvas::draw_overlays()
2897 int new_cursor, update_cursor, rerender;
2898 TRON("TrackCanvas::draw_overlays")
2900 // Move background pixmap to foreground pixmap
2901 draw_pixmap(background_pixmap,
2908 TROFF("TrackCanvas::draw_overlays")
2910 //printf("TrackCanvas::draw_overlays 4\n");
2912 draw_inout_points();
2914 //printf("TrackCanvas::draw_overlays 5\n");
2916 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
2918 //printf("TrackCanvas::draw_overlays 6\n");
2922 //printf("TrackCanvas::draw_overlays 2\n");
2925 draw_brender_start();
2927 //printf("TrackCanvas::draw_overlays 7\n");
2928 // Highlighted areas
2929 draw_highlighting();
2931 //printf("TrackCanvas::draw_overlays 8\n");
2941 //printf("TrackCanvas::draw_overlays 9\n");
2943 if(gui->cursor) gui->cursor->restore();
2945 //printf("TrackCanvas::draw_overlays 10\n");
2949 //printf("TrackCanvas::draw_overlays 11\n");
2951 draw_playback_cursor();
2955 int TrackCanvas::activate()
2959 get_top_level()->deactivate();
2961 set_active_subwindow(this);
2962 gui->cursor->activate();
2967 int TrackCanvas::deactivate()
2972 gui->cursor->deactivate();
2978 void TrackCanvas::update_drag_handle()
2980 double new_position;
2983 (double)(get_cursor_x() + mwindow->edl->local_session->view_start) *
2984 mwindow->edl->local_session->zoom_sample /
2985 mwindow->edl->session->sample_rate;
2987 mwindow->edl->align_to_frame(new_position, 0);
2990 if(new_position != mwindow->session->drag_position)
2992 mwindow->session->drag_position = new_position;
2993 gui->mainclock->update(new_position);
2994 // Que the CWindow. Doesn't do anything if selectionstart and selection end
2996 // mwindow->cwindow->update(1, 0, 0);
3000 int TrackCanvas::update_drag_edit()
3009 #define UPDATE_DRAG_HEAD(do_clamp) \
3011 int x = cursor_x - mwindow->session->drag_origin_x; \
3012 int y = cursor_y - mwindow->session->drag_origin_y; \
3014 if(!current->autos->track->record) return 0; \
3015 double view_start; \
3016 int64_t unit_start; \
3021 double zoom_sample; \
3022 double zoom_units; \
3024 mwindow->undo->update_undo_before(_("tweek"), LOAD_AUTOMATION); \
3025 calculate_viewport(current->autos->track, \
3035 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3036 MAX(128, yscale) + \
3037 mwindow->session->drag_start_percentage; \
3038 if(do_clamp) CLAMP(percentage, 0, 1); \
3040 int64_t position = Units::to_int64(zoom_units * \
3041 (cursor_x - mwindow->session->drag_origin_x) + \
3042 mwindow->session->drag_start_position); \
3044 if((do_clamp) && position < 0) position = 0;
3054 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3056 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3058 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3061 //printf("TrackCanvas::update_drag_floatauto %ld %d\n",
3063 //mwindow->session->drag_handle);
3065 switch(mwindow->session->drag_handle)
3069 // Snap to nearby values
3072 if(current->previous)
3073 value = ((FloatAuto*)current->previous)->value;
3076 value = ((FloatAuto*)current->next)->value;
3078 value = ((FloatAutos*)current->autos)->default_;
3081 value = ((FloatAuto*)current)->percentage_to_value(percentage);
3083 //printf("TrackCanvas::update_drag_floatauto 1 %f\n", value);
3084 if(value != current->value || position != current->position)
3087 current->value = value;
3088 current->position = position;
3090 char string[BCTEXTLEN], string2[BCTEXTLEN];
3091 Units::totext(string2,
3092 current->autos->track->from_units(current->position),
3093 mwindow->edl->session->time_format,
3094 mwindow->edl->session->sample_rate,
3095 mwindow->edl->session->frame_rate,
3096 mwindow->edl->session->frames_per_foot);
3097 sprintf(string, "%s, %.2f", string2, current->value);
3098 gui->show_message(string);
3104 value = ((FloatAuto*)current)->percentage_to_invalue(percentage);
3105 position = MIN(0, position);
3106 if(value != current->control_in_value ||
3107 position != current->control_in_position)
3110 current->control_in_value = value;
3111 current->control_in_position = position;
3113 char string[BCTEXTLEN], string2[BCTEXTLEN];
3114 Units::totext(string2,
3115 current->autos->track->from_units(current->control_in_position),
3116 mwindow->edl->session->time_format,
3117 mwindow->edl->session->sample_rate,
3118 mwindow->edl->session->frame_rate,
3119 mwindow->edl->session->frames_per_foot);
3120 sprintf(string, "%s, %.2f", string2, current->control_in_value);
3121 gui->show_message(string);
3127 value = ((FloatAuto*)current)->percentage_to_outvalue(percentage);
3128 position = MAX(0, position);
3129 if(value != current->control_out_value ||
3130 position != current->control_out_position)
3133 ((FloatAuto*)current)->control_out_value = value;
3134 ((FloatAuto*)current)->control_out_position = position;
3136 char string[BCTEXTLEN], string2[BCTEXTLEN];
3137 Units::totext(string2,
3138 current->autos->track->from_units(
3139 ((FloatAuto*)current)->control_out_position),
3140 mwindow->edl->session->time_format,
3141 mwindow->edl->session->sample_rate,
3142 mwindow->edl->session->frame_rate,
3143 mwindow->edl->session->frames_per_foot);
3144 sprintf(string, "%s, %.2f",
3146 ((FloatAuto*)current)->control_out_value);
3147 gui->show_message(string);
3155 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3157 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3159 UPDATE_DRAG_HEAD(1);
3161 int value = ((IntAuto*)current)->percentage_to_value(percentage);
3163 if(value != current->value || position != current->position)
3166 current->value = value;
3167 current->position = position;
3169 char string[BCTEXTLEN], string2[BCTEXTLEN];
3170 Units::totext(string2,
3171 current->autos->track->from_units(current->position),
3172 mwindow->edl->session->time_format,
3173 mwindow->edl->session->sample_rate,
3174 mwindow->edl->session->frame_rate,
3175 mwindow->edl->session->frames_per_foot);
3176 sprintf(string, "%s, %d", string2, current->value);
3177 gui->show_message(string);
3183 // Autos which can't change value through dragging.
3185 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3187 Auto *current = (Auto*)mwindow->session->drag_auto;
3191 if(position != current->position)
3194 current->position = position;
3196 char string[BCTEXTLEN];
3197 Units::totext(string,
3198 current->autos->track->from_units(current->position),
3199 mwindow->edl->session->time_format,
3200 mwindow->edl->session->sample_rate,
3201 mwindow->edl->session->frame_rate,
3202 mwindow->edl->session->frames_per_foot);
3203 gui->show_message(string);
3205 double position_f = current->autos->track->from_units(current->position);
3206 double center_f = (mwindow->edl->local_session->selectionstart +
3207 mwindow->edl->local_session->selectionend) /
3211 mwindow->edl->local_session->selectionstart = position_f;
3212 mwindow->edl->local_session->selectionend = position_f;
3215 if(position_f < center_f)
3217 mwindow->edl->local_session->selectionstart = position_f;
3220 mwindow->edl->local_session->selectionend = position_f;
3227 void TrackCanvas::update_drag_caption()
3229 switch(mwindow->session->current_operation)
3239 int TrackCanvas::cursor_motion_event()
3241 int result, cursor_x, cursor_y;
3242 int update_clock = 0;
3243 int update_zoom = 0;
3244 int update_scroll = 0;
3245 int update_overlay = 0;
3246 int update_cursor = 0;
3249 double position = 0;
3250 //printf("TrackCanvas::cursor_motion_event 1 %f\n", mwindow->edl->local_session->selectionstart);
3254 switch(mwindow->edl->session->editing_mode)
3256 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3257 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3260 switch(mwindow->session->current_operation)
3262 case DRAG_EDITHANDLE1:
3263 // Outside threshold. Upgrade status
3264 //printf("TrackCanvas::cursor_motion_event 1\n");
3265 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3267 //printf("TrackCanvas::cursor_motion_event 2\n");
3268 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3273 case DRAG_EDITHANDLE2:
3274 update_drag_handle();
3278 case DRAG_PLUGINHANDLE1:
3279 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3281 //printf("TrackCanvas::cursor_motion_event 2\n");
3282 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3287 case DRAG_PLUGINHANDLE2:
3288 update_drag_handle();
3292 // Rubber band curves
3294 rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3298 rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3302 rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3306 rerender = update_overlay = update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3310 rerender = update_overlay = update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3313 // Keyframe icons are sticky
3315 case DRAG_CAMERA_PRE:
3318 case DRAG_PROJECTOR_PRE:
3319 case DRAG_PLUGINKEY_PRE:
3320 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3322 //printf("TrackCanvas::cursor_motion_event 2\n");
3323 mwindow->session->current_operation++;
3332 case DRAG_PROJECTOR:
3333 case DRAG_PLUGINKEY:
3334 rerender = update_overlay =
3335 update_drag_auto(get_cursor_x(), get_cursor_y());
3340 cursor_x = get_cursor_x();
3341 cursor_y = get_cursor_y();
3342 position = (double)(cursor_x + mwindow->edl->local_session->view_start) *
3343 mwindow->edl->local_session->zoom_sample /
3344 mwindow->edl->session->sample_rate;
3346 position = mwindow->edl->align_to_frame(position, 0);
3347 position = MAX(position, 0);
3349 if(position < selection_midpoint1)
3351 mwindow->edl->local_session->selectionend = selection_midpoint1;
3352 mwindow->edl->local_session->selectionstart = position;
3354 mwindow->cwindow->update(1, 0, 0, 0, 1);
3355 // Update the faders
3356 mwindow->update_plugin_guis();
3357 gui->patchbay->update();
3361 mwindow->edl->local_session->selectionstart = selection_midpoint1;
3362 mwindow->edl->local_session->selectionend = position;
3363 // Don't que the CWindow
3365 //printf("TrackCanvas::cursor_motion_event 1 %f %f %f\n", position, mwindow->edl->local_session->selectionstart, mwindow->edl->local_session->selectionend);
3367 gui->cursor->hide();
3368 gui->cursor->draw();
3378 if(is_event_win() && cursor_inside())
3381 cursor_x = get_cursor_x();
3382 position = (double)cursor_x *
3383 (double)mwindow->edl->local_session->zoom_sample /
3384 (double)mwindow->edl->session->sample_rate +
3385 (double)mwindow->edl->local_session->view_start *
3386 (double)mwindow->edl->local_session->zoom_sample /
3387 (double)mwindow->edl->session->sample_rate;
3388 position = mwindow->edl->align_to_frame(position, 0);
3392 if(mwindow->edl->session->auto_conf->transitions &&
3393 test_transitions(get_cursor_x(),
3403 if(do_keyframes(get_cursor_x(),
3415 if(test_edit_handles(get_cursor_x(),
3424 // Plugin boundaries
3425 if(test_plugin_handles(get_cursor_x(),
3434 if(test_edits(get_cursor_x(),
3449 //printf("TrackCanvas::cursor_motion_event 1\n");
3450 if(update_cursor && new_cursor != get_cursor())
3452 set_cursor(new_cursor);
3455 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
3458 mwindow->restart_brender();
3459 mwindow->sync_parameters(CHANGE_PARAMS);
3460 mwindow->update_plugin_guis();
3461 mwindow->cwindow->update(1, 0, 0, 0, 1);
3463 gui->patchbay->update();
3469 if(!mwindow->cwindow->playback_engine->is_playing_back)
3470 gui->mainclock->update(position);
3475 gui->zoombar->update();
3481 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
3485 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
3494 //printf("TrackCanvas::cursor_motion_event 100 %f\n", mwindow->edl->local_session->selectionstart);
3498 void TrackCanvas::start_dragscroll()
3503 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3504 //printf("TrackCanvas::start_dragscroll 1\n");
3508 void TrackCanvas::stop_dragscroll()
3513 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3514 //printf("TrackCanvas::stop_dragscroll 1\n");
3518 int TrackCanvas::repeat_event(int64_t duration)
3520 if(!drag_scroll) return 0;
3521 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
3523 int sample_movement = 0;
3524 int track_movement = 0;
3525 int64_t x_distance = 0;
3526 int64_t y_distance = 0;
3527 double position = 0;
3530 switch(mwindow->session->current_operation)
3533 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
3534 if(get_cursor_x() > get_w())
3536 x_distance = get_cursor_x() - get_w();
3537 sample_movement = 1;
3540 if(get_cursor_x() < 0)
3542 x_distance = get_cursor_x();
3543 sample_movement = 1;
3546 if(get_cursor_y() > get_h())
3548 y_distance = get_cursor_y() - get_h();
3552 if(get_cursor_y() < 0)
3554 y_distance = get_cursor_y();
3564 position = (double)(get_cursor_x() +
3565 mwindow->edl->local_session->view_start +
3567 mwindow->edl->local_session->zoom_sample /
3568 mwindow->edl->session->sample_rate;
3569 position = mwindow->edl->align_to_frame(position, 0);
3570 position = MAX(position, 0);
3572 //printf("TrackCanvas::repeat_event 1 %f\n", position);
3573 switch(mwindow->session->current_operation)
3576 if(position < selection_midpoint1)
3578 mwindow->edl->local_session->selectionend = selection_midpoint1;
3579 mwindow->edl->local_session->selectionstart = position;
3581 mwindow->cwindow->update(1, 0, 0);
3582 // Update the faders
3583 mwindow->update_plugin_guis();
3584 gui->patchbay->update();
3588 mwindow->edl->local_session->selectionstart = selection_midpoint1;
3589 mwindow->edl->local_session->selectionend = position;
3590 // Don't que the CWindow
3595 mwindow->samplemovement(mwindow->edl->local_session->view_start +
3601 mwindow->trackmovement(mwindow->edl->local_session->track_start +
3608 int TrackCanvas::button_release_event()
3610 int redraw = 0, update_overlay = 0, result = 0;
3612 switch(mwindow->session->current_operation)
3614 case DRAG_EDITHANDLE2:
3615 mwindow->session->current_operation = NO_OPERATION;
3619 end_edithandle_selection();
3622 case DRAG_EDITHANDLE1:
3623 mwindow->session->current_operation = NO_OPERATION;
3628 case DRAG_PLUGINHANDLE2:
3629 mwindow->session->current_operation = NO_OPERATION;
3633 end_pluginhandle_selection();
3636 case DRAG_PLUGINHANDLE1:
3637 mwindow->session->current_operation = NO_OPERATION;
3651 case DRAG_PROJECTOR:
3652 case DRAG_PLUGINKEY:
3653 mwindow->session->current_operation = NO_OPERATION;
3654 mwindow->session->drag_handle = 0;
3655 // Remove any out-of-order keyframe
3656 if(mwindow->session->drag_auto)
3658 mwindow->session->drag_auto->autos->remove_nonsequential(
3659 mwindow->session->drag_auto);
3660 // mwindow->session->drag_auto->autos->optimize();
3663 mwindow->undo->update_undo_after();
3668 case DRAG_AEFFECT_COPY:
3669 case DRAG_VEFFECT_COPY:
3670 // Trap in drag stop
3676 if(mwindow->session->current_operation)
3678 mwindow->session->current_operation = NO_OPERATION;
3680 // Traps button release events
3699 int TrackCanvas::test_edit_handles(int cursor_x,
3705 Edit *edit_result = 0;
3706 int handle_result = 0;
3709 for(Track *track = mwindow->edl->tracks->first;
3711 track = track->next)
3713 for(Edit *edit = track->edits->first;
3717 int64_t edit_x, edit_y, edit_w, edit_h;
3718 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
3720 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
3721 cursor_y >= edit_y && cursor_y < edit_y + edit_h)
3723 if(cursor_x < edit_x + HANDLE_W)
3730 if(cursor_x >= edit_x + edit_w - HANDLE_W)
3748 if(handle_result == 0)
3750 position = edit_result->track->from_units(edit_result->startproject);
3751 new_cursor = LEFT_CURSOR;
3754 if(handle_result == 1)
3756 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
3757 new_cursor = RIGHT_CURSOR;
3760 // Reposition cursor
3763 mwindow->session->drag_edit = edit_result;
3764 mwindow->session->drag_handle = handle_result;
3765 mwindow->session->drag_button = get_buttonpress() - 1;
3766 mwindow->session->drag_position = position;
3767 mwindow->session->current_operation = DRAG_EDITHANDLE1;
3768 mwindow->session->drag_origin_x = get_cursor_x();
3769 mwindow->session->drag_origin_y = get_cursor_y();
3770 mwindow->session->drag_start = position;
3772 int rerender = start_selection(position);
3774 mwindow->cwindow->update(1, 0, 0);
3775 gui->timebar->update_highlights();
3776 gui->zoombar->update();
3777 gui->cursor->hide();
3778 gui->cursor->draw();
3788 int TrackCanvas::test_plugin_handles(int cursor_x,
3794 Plugin *plugin_result = 0;
3795 int handle_result = 0;
3798 for(Track *track = mwindow->edl->tracks->first;
3800 track = track->next)
3802 for(int i = 0; i < track->plugin_set.total && !result; i++)
3804 PluginSet *plugin_set = track->plugin_set.values[i];
3805 for(Plugin *plugin = (Plugin*)plugin_set->first;
3807 plugin = (Plugin*)plugin->next)
3809 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
3810 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
3812 if(cursor_x >= plugin_x && cursor_x < plugin_x + plugin_w &&
3813 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h)
3815 if(cursor_x < plugin_x + HANDLE_W)
3817 plugin_result = plugin;
3822 if(cursor_x >= plugin_x + plugin_w - HANDLE_W)
3824 plugin_result = plugin;
3833 //printf("TrackCanvas::test_plugin_handles %d %d %d\n", button_press, handle_result, result);
3838 if(handle_result == 0)
3840 position = plugin_result->track->from_units(plugin_result->startproject);
3841 new_cursor = LEFT_CURSOR;
3844 if(handle_result == 1)
3846 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
3847 new_cursor = RIGHT_CURSOR;
3852 mwindow->session->drag_plugin = plugin_result;
3853 mwindow->session->drag_handle = handle_result;
3854 mwindow->session->drag_button = get_buttonpress() - 1;
3855 mwindow->session->drag_position = position;
3856 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
3857 mwindow->session->drag_origin_x = get_cursor_x();
3858 mwindow->session->drag_origin_y = get_cursor_y();
3859 mwindow->session->drag_start = position;
3861 int rerender = start_selection(position);
3862 if(rerender) mwindow->cwindow->update(1, 0, 0);
3863 gui->timebar->update_highlights();
3864 gui->zoombar->update();
3865 gui->cursor->hide();
3866 gui->cursor->draw();
3877 int TrackCanvas::test_tracks(int cursor_x,
3882 for(Track *track = mwindow->edl->tracks->first;
3884 track = track->next)
3886 int64_t track_x, track_y, track_w, track_h;
3887 track_dimensions(track, track_x, track_y, track_w, track_h);
3890 get_buttonpress() == 3 &&
3891 cursor_y >= track_y &&
3892 cursor_y < track_y + track_h)
3894 gui->edit_menu->update(track, 0);
3895 gui->edit_menu->activate_menu();
3902 int TrackCanvas::test_edits(int cursor_x,
3912 int over_edit_handle = 0;
3914 //printf("TrackCanvas::test_edits 1\n");
3915 for(Track *track = mwindow->edl->tracks->first;
3917 track = track->next)
3919 for(Edit *edit = track->edits->first;
3923 int64_t edit_x, edit_y, edit_w, edit_h;
3924 //printf("TrackCanvas::test_edits 1\n");
3925 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
3927 // Cursor inside a track
3928 // Cursor inside an edit
3929 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
3930 cursor_y >= edit_y && cursor_y < edit_y + edit_h)
3932 // Select duration of edit
3933 //printf("TrackCanvas::test_edits 2\n");
3936 if(get_double_click() && !drag_start)
3938 //printf("TrackCanvas::test_edits 3\n");
3939 mwindow->edl->local_session->selectionstart =
3940 edit->track->from_units(edit->startproject);
3941 mwindow->edl->local_session->selectionend =
3942 edit->track->from_units(edit->startproject) +
3943 edit->track->from_units(edit->length);
3944 if(mwindow->edl->session->cursor_on_frames)
3946 mwindow->edl->local_session->selectionstart =
3947 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionstart, 0);
3948 mwindow->edl->local_session->selectionend =
3949 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionend, 1);
3959 if(mwindow->edl->session->editing_mode == EDITING_ARROW)
3961 // Need to create drag window
3962 mwindow->session->current_operation = DRAG_EDIT;
3963 mwindow->session->drag_edit = edit;
3964 //printf("TrackCanvas::test_edits 2\n");
3966 // Drag only one edit
3969 mwindow->session->drag_edits->remove_all();
3970 mwindow->session->drag_edits->append(edit);
3973 // Construct list of all affected edits
3975 mwindow->edl->tracks->get_affected_edits(
3976 mwindow->session->drag_edits,
3977 edit->track->from_units(edit->startproject),
3980 mwindow->session->drag_origin_x = cursor_x;
3981 mwindow->session->drag_origin_y = cursor_y;
3983 drag_pixmap = new BC_Pixmap(gui,
3984 mwindow->theme->clip_icon,
3986 drag_popup = new BC_DragWindow(gui,
3988 get_abs_cursor_x() - drag_pixmap->get_w() / 2,
3989 get_abs_cursor_y() - drag_pixmap->get_h() / 2);
3990 //printf("TrackCanvas::test_edits 3 %p\n", drag_popup);
4002 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4007 int TrackCanvas::test_plugins(int cursor_x,
4017 //printf("TrackCanvas::test_plugins 1\n");
4018 for(Track *track = mwindow->edl->tracks->first;
4020 track = track->next)
4022 for(int i = 0; i < track->plugin_set.total && !done; i++)
4024 PluginSet *plugin_set = track->plugin_set.values[i];
4025 for(plugin = (Plugin*)plugin_set->first;
4027 plugin = (Plugin*)plugin->next)
4029 plugin_dimensions(plugin, x, y, w, h);
4030 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4031 MWindowGUI::visible(y, y + h, 0, get_h()))
4033 if(cursor_x >= x && cursor_x < x + w &&
4034 cursor_y >= y && cursor_y < y + h)
4044 //printf("TrackCanvas::test_plugins 1\n");
4047 // Start plugin popup
4050 //printf("TrackCanvas::test_plugins 2\n");
4051 if(get_buttonpress() == 3)
4053 gui->plugin_menu->update(plugin);
4054 gui->plugin_menu->activate_menu();
4057 //printf("TrackCanvas::test_plugins 3\n");
4063 //printf("TrackCanvas::test_plugins 4\n");
4064 if(mwindow->edl->session->editing_mode == EDITING_ARROW)
4066 //printf("TrackCanvas::test_plugins 5\n");
4067 if(plugin->track->data_type == TRACK_AUDIO)
4068 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4070 if(plugin->track->data_type == TRACK_VIDEO)
4071 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4073 mwindow->session->drag_plugin = plugin;
4074 //printf("TrackCanvas::test_plugins 6\n");
4081 switch(plugin->plugin_type)
4083 case PLUGIN_STANDALONE:
4085 PluginServer *server = mwindow->scan_plugindb(plugin->title);
4086 VFrame *frame = server->picon;
4087 //printf("TrackCanvas::test_plugins 7\n");
4088 if(frame->get_color_model() == BC_RGB888)
4090 drag_pixmap = new BC_Pixmap(gui, frame->get_w(), frame->get_h());
4091 drag_pixmap->draw_vframe(frame,
4101 drag_pixmap = new BC_Pixmap(gui,
4105 //printf("TrackCanvas::test_plugins 8\n");
4109 case PLUGIN_SHAREDPLUGIN:
4110 drag_pixmap = new BC_Pixmap(gui,
4111 mwindow->theme->clip_icon,
4115 case PLUGIN_SHAREDMODULE:
4116 drag_pixmap = new BC_Pixmap(gui,
4117 mwindow->theme->clip_icon,
4120 //printf("test plugins %d %p\n", mwindow->edl->session->editing_mode, mwindow->session->drag_plugin);
4123 //printf("TrackCanvas::test_plugins 9 %p\n");
4124 drag_popup = new BC_DragWindow(gui,
4126 get_abs_cursor_x() - drag_pixmap->get_w() / 2,
4127 get_abs_cursor_y() - drag_pixmap->get_h() / 2);
4128 //printf("TrackCanvas::test_plugins 10\n");
4134 //printf("TrackCanvas::test_plugins 11\n");
4138 int TrackCanvas::test_transitions(int cursor_x,
4144 Transition *transition = 0;
4148 for(Track *track = mwindow->edl->tracks->first;
4150 track = track->next)
4152 for(Edit *edit = track->edits->first;
4156 if(edit->transition)
4158 edit_dimensions(edit, x, y, w, h);
4159 get_transition_coords(x, y, w, h);
4161 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4162 MWindowGUI::visible(y, y + h, 0, get_h()))
4164 if(cursor_x >= x && cursor_x < x + w &&
4165 cursor_y >= y && cursor_y < y + h)
4167 transition = edit->transition;
4181 new_cursor = UPRIGHT_ARROW_CURSOR;
4184 if(get_buttonpress() == 3)
4186 gui->transition_menu->update(transition);
4187 gui->transition_menu->activate_menu();
4194 int TrackCanvas::button_press_event()
4197 int cursor_x, cursor_y;
4198 int new_cursor, update_cursor;
4200 //printf("TrackCanvas::button_press_event 1\n");
4201 cursor_x = get_cursor_x();
4202 cursor_y = get_cursor_y();
4204 if(is_event_win() && cursor_inside())
4211 if(get_buttonpress() == 1)
4213 gui->unlock_window();
4214 gui->mbuttons->transport->handle_transport(STOP, 1);
4218 int update_overlay = 0, update_cursor = 0, rerender = 0;
4220 if(get_buttonpress() == 4)
4222 //printf("TrackCanvas::button_press_event 1\n");
4223 mwindow->move_up(get_h() / 10);
4227 if(get_buttonpress() == 5)
4229 //printf("TrackCanvas::button_press_event 2\n");
4230 mwindow->move_down(get_h() / 10);
4234 switch(mwindow->edl->session->editing_mode)
4236 // Test handles and resource boundaries and highlight a track
4241 if(mwindow->edl->session->auto_conf->transitions &&
4242 test_transitions(cursor_x,
4251 if(do_keyframes(cursor_x,
4262 // Test edit boundaries
4263 if(test_edit_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4268 // Test plugin boundaries
4269 if(test_plugin_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4274 if(test_edits(cursor_x, cursor_y, 1, 0, update_cursor, rerender, new_cursor, update_cursor))
4279 if(test_plugins(cursor_x, cursor_y, 0, 1))
4284 if(test_resources(cursor_x, cursor_y))
4289 if(test_tracks(cursor_x, cursor_y, 1))
4296 // Test handles only and select a region
4299 double position = (double)cursor_x *
4300 mwindow->edl->local_session->zoom_sample /
4301 mwindow->edl->session->sample_rate +
4302 (double)mwindow->edl->local_session->view_start *
4303 mwindow->edl->local_session->zoom_sample /
4304 mwindow->edl->session->sample_rate;
4305 //printf("TrackCanvas::button_press_event %d\n", position);
4307 if(mwindow->edl->session->auto_conf->transitions &&
4308 test_transitions(cursor_x,
4317 if(do_keyframes(cursor_x,
4329 // Test edit boundaries
4330 if(test_edit_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4335 // Test plugin boundaries
4336 if(test_plugin_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4341 if(test_edits(cursor_x, cursor_y, 1, 0, update_cursor, rerender, new_cursor, update_cursor))
4346 if(test_plugins(cursor_x, cursor_y, 0, 1))
4351 if(test_tracks(cursor_x, cursor_y, 1))
4355 // Highlight selection
4358 rerender = start_selection(position);
4359 mwindow->session->current_operation = SELECT_REGION;
4370 mwindow->cwindow->update(1, 0, 0, 0, 1);
4372 mwindow->update_plugin_guis();
4373 gui->patchbay->update();
4384 gui->timebar->update_highlights();
4385 gui->cursor->hide();
4386 gui->cursor->show();
4387 gui->zoombar->update();
4398 int TrackCanvas::start_selection(double position)
4401 position = mwindow->edl->align_to_frame(position, 0);
4406 double midpoint = (mwindow->edl->local_session->selectionstart +
4407 mwindow->edl->local_session->selectionend) / 2;
4409 if(position < midpoint)
4411 mwindow->edl->local_session->selectionstart = position;
4412 selection_midpoint1 = mwindow->edl->local_session->selectionend;
4418 mwindow->edl->local_session->selectionend = position;
4419 selection_midpoint1 = mwindow->edl->local_session->selectionstart;
4420 // Don't que the CWindow for the end
4424 // Start a new selection
4426 //printf("TrackCanvas::start_selection %f\n", position);
4427 mwindow->edl->local_session->selectionstart =
4428 mwindow->edl->local_session->selectionend =
4430 selection_midpoint1 = position;
4438 void TrackCanvas::end_edithandle_selection()
4440 mwindow->modify_edithandles();
4443 void TrackCanvas::end_pluginhandle_selection()
4445 mwindow->modify_pluginhandles();
4449 double TrackCanvas::time_visible()
4451 return (double)get_w() *
4452 mwindow->edl->local_session->zoom_sample /
4453 mwindow->edl->session->sample_rate;
4496 void TrackCanvas::draw_automation()
4501 int TrackCanvas::set_index_file(int flash, Asset *asset)
4507 int TrackCanvas::button_release()
4513 int TrackCanvas::auto_reposition(int &cursor_x, int &cursor_y, int64_t cursor_position)
4519 int TrackCanvas::draw_floating_handle(int flash)
4524 int TrackCanvas::draw_loop_point(int64_t position, int flash)
4529 int TrackCanvas::draw_playback_cursor(int pixel, int flash)
4535 int TrackCanvas::update_handle_selection(int64_t cursor_position)
4540 int TrackCanvas::end_translation()