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 int TrackCanvas::keypress_event()
166 int TrackCanvas::cursor_leave_event()
168 // Because drag motion calls get_cursor_over_window we can be sure that
169 // all highlights get deleted now.
170 // This ended up blocking keyboard input from the drag operations.
171 if( timebar_position >= 0 )
173 timebar_position = -1;
175 pane->timebar->update(1);
179 // return drag_motion();
182 int TrackCanvas::drag_motion_event()
184 return gui->drag_motion();
187 int TrackCanvas::drag_motion(
188 Track **over_track, Edit **over_edit,
189 PluginSet **over_pluginset, Plugin **over_plugin)
191 int cursor_x = get_relative_cursor_x();
192 int cursor_y = get_relative_cursor_y();
193 if( get_cursor_over_window() ) {
194 drag_cursor_motion(cursor_x, cursor_y,
195 over_track, over_edit, over_pluginset, over_plugin);
197 if( over_track && !*over_track )
198 *over_track = pane->over_patchbay();
202 int TrackCanvas::drag_cursor_motion(int cursor_x, int cursor_y,
203 Track **over_track, Edit **over_edit,
204 PluginSet **over_pluginset, Plugin **over_plugin)
206 if( cursor_x >= 0 && cursor_y >= 0 &&
207 cursor_x < get_w() && cursor_y < get_h() )
209 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
210 // Find the edit and track the cursor is over
211 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
213 int64_t track_x, track_y, track_w, track_h;
214 track_dimensions(track, track_x, track_y, track_w, track_h);
216 if(cursor_y >= track_y &&
217 cursor_y < track_y + track_h)
220 for(Edit *edit = track->edits->first; edit; edit = edit->next)
222 int64_t edit_x, edit_y, edit_w, edit_h;
223 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
224 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
225 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
229 if( edit != track->edits->last ) continue;
230 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
231 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
232 if( !edit->silence() ) {
233 // add silence to allow drag transition past last edit
234 // will be deleted by Edits::optimize if not used
235 double length = mwindow->edl->session->default_transition_length;
236 int64_t start = edit->startproject+edit->length;
237 int64_t units = track->to_units(length, 1);
238 track->edits->create_silence(start, start+units);
241 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
244 for(int i = 0; i < track->plugin_set.total; i++)
246 PluginSet *pluginset = track->plugin_set.values[i];
247 for(Plugin *plugin = (Plugin*)pluginset->first;
249 plugin = (Plugin*)plugin->next)
251 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
252 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
254 if(cursor_y >= plugin_y &&
255 cursor_y < plugin_y + plugin_h)
257 *over_pluginset = plugin->plugin_set;
259 if(cursor_x >= plugin_x &&
260 cursor_x < plugin_x + plugin_w)
262 *over_plugin = plugin;
277 int TrackCanvas::drag_stop_event()
279 int result = gui->drag_stop();
280 if( !result && mwindow->session->current_operation ) {
281 mwindow->session->current_operation = NO_OPERATION;
287 int TrackCanvas::drag_stop(int *redraw)
292 int cursor_x = -1, cursor_y = -1;
294 if( get_cursor_over_window() ) {
295 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
296 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
299 Track *track = pane->over_patchbay();
300 if( track && mwindow->session->track_highlighted == track )
306 switch(mwindow->session->current_operation) {
307 case DRAG_VTRANSITION:
308 case DRAG_ATRANSITION:
309 if(mwindow->session->edit_highlighted) {
310 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
311 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
312 (mwindow->session->current_operation == DRAG_VTRANSITION &&
313 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
314 mwindow->session->current_operation = NO_OPERATION;
315 mwindow->paste_transition();
322 // Behavior for dragged plugins is limited by the fact that a shared plugin
323 // can only refer to a standalone plugin that exists in the same position in
324 // time. Dragging a plugin from one point in time to another can't produce
325 // a shared plugin to the original plugin. In this case we relocate the
326 // plugin instead of sharing it.
327 case DRAG_AEFFECT_COPY:
328 case DRAG_VEFFECT_COPY:
329 if( mwindow->session->track_highlighted &&
330 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
331 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
332 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
333 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
334 mwindow->session->current_operation = NO_OPERATION;
336 int64_t drop_position = -1;
337 Plugin *drag_plugin = mwindow->session->drag_plugin;
338 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
339 Track *hi_track = mwindow->session->track_highlighted;
341 // Insert shared plugin in source
342 // Move source to different location
343 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
344 //printf("TrackCanvas::drag_stop 6\n");
345 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
346 if( drop_position < 0 ) {
348 break; // Do not do anything
351 Track *track = mwindow->session->track_highlighted;
352 drop_position = track->frame_align(drop_position, 0);
353 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
356 else if( hi_track ) {
357 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
358 Edit *hi_edit = mwindow->session->edit_highlighted;
359 drop_position = hi_edit ? hi_edit->startproject : 0;
360 if( drop_position < 0 ) {
362 break; // Do not do anything
365 Track *track = mwindow->session->track_highlighted;
366 drop_position = track->frame_align(drop_position, 0);
367 mwindow->move_effect(drag_plugin, hi_track, drop_position);
375 if( mwindow->session->track_highlighted &&
376 ((mwindow->session->current_operation == DRAG_AEFFECT &&
377 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
378 (mwindow->session->current_operation == DRAG_VEFFECT &&
379 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
380 // Drop all the effects
381 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
382 Track *track = mwindow->session->track_highlighted;
384 double length = track->get_length();
386 if(mwindow->session->plugin_highlighted) {
387 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
388 length = track->from_units(mwindow->session->plugin_highlighted->length);
389 if(length <= 0) length = track->get_length();
391 else if(mwindow->session->pluginset_highlighted) {
392 start = track->from_units(plugin_set->length());
393 length = track->get_length() - start;
394 if(length <= 0) length = track->get_length();
396 else if(mwindow->edl->local_session->get_selectionend() >
397 mwindow->edl->local_session->get_selectionstart()) {
398 start = mwindow->edl->local_session->get_selectionstart();
399 length = mwindow->edl->local_session->get_selectionend() -
400 mwindow->edl->local_session->get_selectionstart();
402 // Move to a point between two edits
403 else if(mwindow->session->edit_highlighted) {
404 start = mwindow->session->track_highlighted->from_units(
405 mwindow->session->edit_highlighted->startproject);
406 length = mwindow->session->track_highlighted->from_units(
407 mwindow->session->edit_highlighted->length);
409 start = mwindow->edl->align_to_frame(start, 0);
410 mwindow->insert_effects_canvas(start, length);
413 if( mwindow->session->track_highlighted )
414 result = 1; // we have to cleanup
418 if(mwindow->session->track_highlighted) {
419 double asset_duration = 0;
420 int64_t asset_length_units = 0;
422 if(mwindow->session->current_operation == DRAG_ASSET &&
423 mwindow->session->drag_assets->total) {
424 Indexable *indexable = mwindow->session->drag_assets->values[0];
425 // we use video if we are over video and audio if we are over audio
426 if( indexable->have_video() &&
427 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
428 // Images have length -1
429 int64_t video_length = indexable->get_video_frames();
430 if (video_length < 0) {
431 if(mwindow->edl->session->si_useduration)
432 video_length = mwindow->edl->session->si_duration;
434 video_length = 1.0 / mwindow->edl->session->frame_rate ;
436 asset_duration = video_length / indexable->get_frame_rate();
438 else if( indexable->have_audio() &&
439 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
440 int64_t audio_length = indexable->get_audio_samples();
441 asset_duration = (double)audio_length / indexable->get_sample_rate();
445 break; // Do not do anything
448 else if( mwindow->session->current_operation == DRAG_ASSET &&
449 mwindow->session->drag_clips->total ) {
450 EDL *clip = mwindow->session->drag_clips->values[0];
451 asset_duration = clip->tracks->total_length();
454 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
457 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
458 int64_t drop_position = drop_edit_position (&insertion, NULL, asset_length_units);
459 if( drop_position < 0 ) {
461 break; // Do not do anything
464 Track *track = mwindow->session->track_highlighted;
465 double track_position = track->from_units(drop_position);
466 track_position = mwindow->edl->align_to_frame(track_position, 0);
469 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
470 // // Unfortunately, this is _a lot_ of work to do right
471 // printf("Problematic insertion\n");
472 // mwindow->edl->tracks->clear(track_position,
473 // track_position + asset_duration, 0);
475 mwindow->paste_assets(track_position, track, !insertion);
476 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
481 mwindow->session->current_operation = NO_OPERATION;
482 if(mwindow->session->track_highlighted) {
483 if( mwindow->session->track_highlighted->data_type ==
484 mwindow->session->drag_edit->track->data_type) {
485 int64_t drop_position = drop_edit_position(&insertion,
486 mwindow->session->drag_edit,
487 mwindow->session->drag_edit->length);
488 if( drop_position < 0 ) {
490 break; // Do not do anything
492 Track *track = mwindow->session->track_highlighted;
493 double track_position = track->from_units(drop_position);
494 track_position = mwindow->edl->align_to_frame(track_position, 0);
495 mwindow->move_edits(mwindow->session->drag_edits,
496 track, track_position, insertion);
503 mwindow->session->current_operation = NO_OPERATION;
504 EDL *drag_group = mwindow->session->drag_group;
506 Track *drop_track = mwindow->session->track_highlighted;
507 Track *drag_track = mwindow->session->drag_group_first_track;
508 Edit *drag_edit = mwindow->session->drag_group_edit;
509 Track *edit_track = drag_edit ? drag_edit->track : 0;
510 while( drop_track && edit_track ) {
511 if( edit_track == drag_track ) break;
512 edit_track = edit_track->previous;
513 drop_track = drop_track->previous;
516 double cur_pos = mwindow->session->drag_group_position;
517 double new_pos = mwindow->edl->get_cursor_position(cursor_x, pane->number);
518 new_pos -= mwindow->session->drag_position - cur_pos;
519 new_pos = mwindow->edl->align_to_frame(new_pos, 0);
520 double drop_position = new_pos;
521 int ret = test_track_group(drag_group, drop_track, new_pos);
522 if( !ret && new_pos != drop_position ) {
523 drop_position = new_pos;
524 ret = test_track_group(drag_group, drop_track, new_pos);
527 mwindow->move_group(drag_group, drop_track, drop_position,
528 ret > 0 ? !shift_down() : shift_down());
529 drag_group->remove_user();
530 mwindow->session->drag_group = 0;
541 int TrackCanvas::drag_start_event()
546 int new_cursor, update_cursor;
548 if( mwindow->session->current_operation == GROUP_TOGGLE )
549 mwindow->session->current_operation = NO_OPERATION;
550 else if( mwindow->session->current_operation != NO_OPERATION )
554 if(do_plugins(get_drag_x(), get_drag_y(),
555 1, 0, redraw, rerender)) {
558 else if(do_edits(get_drag_x(), get_drag_y(),
559 0, 1, redraw, rerender, new_cursor, update_cursor)) {
567 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
569 // get the canvas/track position
570 Track *track = mwindow->session->track_highlighted;
571 int cursor_x = get_relative_cursor_x();
572 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
573 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
574 double position = mwindow->edl->align_to_frame(cur_pos, 1);
575 if( position <= 0 ) {
579 double cursor_position = position;
580 int64_t drop_position = track->to_units(cursor_position, 1);
581 if( moved_edit ) { // relative cursor position depends upon drop point
582 double moved_edit_start = moved_edit->track->from_units(moved_edit->startproject);
583 position -= mwindow->session->drag_position - moved_edit_start;
585 int64_t edit_position = track->to_units(position, 1);
586 int64_t grab_position = edit_position;
587 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
588 grab_position -= moved_edit_length / 2;
589 Edit *last_edit = track->edits->last;
590 if( !last_edit || edit_position >= (last_edit->startproject+last_edit->length) ) {
592 return edit_position;
595 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
596 Edit *next_edit = track->edits->first;
598 Edit *edit = next_edit; next_edit = (Edit *)edit->next;
599 int64_t edit_start = edit->startproject;
600 int64_t edit_end = edit_start + edit->length;
601 double edit_start_pos = edit->track->from_units(edit_start);
602 if( (fabs(edit_start_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
603 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
606 double edit_end_pos = edit->track->from_units(edit_end);
607 if( (fabs(edit_end_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
608 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
611 if( edit != moved_edit && !edit->silence() )
612 drop_start = edit_end; // reset drop zone
614 if( next_edit == moved_edit || next_edit->silence() ) continue;
618 drop_end = INT64_MAX;
619 if( edit_position >= drop_start &&
620 edit_position+moved_edit_length < drop_end ) {
621 *is_insertion = 0; // fits in the zone
622 return edit_position;
624 if( drop_position < drop_end ) { // drop in the zone
625 if( (drop_end - drop_start) >= moved_edit_length ) {
626 *is_insertion = 0; // fits in the zone, but over the edge
627 int64_t dx0 = llabs(drop_position - drop_start);
628 int64_t dx1 = llabs(drop_position - drop_end);
629 return dx0 < dx1 ? drop_start : drop_end - moved_edit_length;
632 int64_t edit_center = (edit_start + edit_end) / 2;
633 return position < edit_center ? drop_start : drop_end;
641 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
643 // get the canvas/track position
644 Track *track = plugin_set->track;
645 double moved_plugin_length = moved_plugin->track->from_units(moved_plugin->length);
646 int64_t track_plugin_length = track->to_units(moved_plugin_length, 0);
647 int cursor_x = get_relative_cursor_x();
648 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
649 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
650 double position = mwindow->edl->align_to_frame(cur_pos, 1);
651 if( position <= 0 ) return 0;
652 int64_t drop_position = track->to_units(position, 1);
653 Plugin *last_plugin = (Plugin *)plugin_set->last;
654 if( !last_plugin ) return drop_position;
655 double plugin_set_end = last_plugin->track->from_units(last_plugin->startproject+last_plugin->length);
656 if( position >= plugin_set_end ) return drop_position;
657 double moved_plugin_start = moved_plugin->track->from_units(moved_plugin->startproject);
658 position -= mwindow->session->drag_position - moved_plugin_start;
659 int64_t plugin_position = track->to_units(position, 1);
661 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
662 Plugin *next_plugin = (Plugin *)plugin_set->first;
663 while( next_plugin ) {
664 Plugin *plugin = next_plugin; next_plugin = (Plugin *)plugin->next;
665 int64_t plugin_start = plugin->startproject;
666 int64_t plugin_end = plugin_start + plugin->length;
667 double plugin_end_pos = plugin->track->from_units(plugin_end);
668 int64_t track_plugin_end = track->to_units(plugin_end_pos, 0);
669 if( plugin != moved_plugin && !plugin->silence() )
670 drop_start = track_plugin_end;
672 if( next_plugin == moved_plugin || next_plugin->silence() ) continue;
673 drop_end = track_plugin_end;
676 drop_end = INT64_MAX;
677 if( plugin_position >= drop_start && // fits in the zone
678 plugin_position+track_plugin_length < drop_end ) {
679 return plugin_position;
681 if( drop_position < drop_end ) { // drop in the zone
682 if( (drop_end - drop_start) >= track_plugin_length ) {
683 int64_t dx0 = llabs(drop_position - drop_start);
684 int64_t dx1 = llabs(drop_position - drop_end);
685 return dx0 < dx1 ? drop_start : drop_end - track_plugin_length;
693 void TrackCanvas::draw(int mode, int hide_cursor)
697 // Swap pixmap layers
698 if(get_w() != background_pixmap->get_w() ||
699 get_h() != background_pixmap->get_h())
701 delete background_pixmap;
702 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
705 // Cursor disappears after resize when this is called.
706 // Cursor doesn't redraw after editing when this isn't called.
707 if(pane->cursor && hide_cursor) pane->cursor->hide();
708 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
710 if(debug) PRINT_TRACE
711 draw_resources(mode);
713 if(debug) PRINT_TRACE
715 if(debug) PRINT_TRACE
718 void TrackCanvas::update_cursor(int flush)
721 set_cursor(ARROW_CURSOR, 0, flush);
722 else if( ibeam_mode() )
723 set_cursor(IBEAM_CURSOR, 0, flush);
727 void TrackCanvas::test_timer()
729 if( resource_timer->get_difference() > 1000 && !hourglass_enabled ) {
731 hourglass_enabled = 1;
736 void TrackCanvas::draw_indexes(Indexable *indexable)
738 IndexState *index_state = indexable->index_state;
739 // Don't redraw raw samples
740 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
742 draw_resources(NORMAL_DRAW, 1, indexable);
747 void TrackCanvas::draw_resources(int mode,
749 Indexable *indexable)
753 if(debug) PRINT_TRACE
755 // can't stop thread here, because this is called for every pane
756 // if(mode != IGNORE_THREAD && !indexes_only)
757 // gui->resource_thread->stop_draw(!indexes_only);
759 if(mode != IGNORE_THREAD &&
761 !gui->resource_thread->interrupted)
763 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
766 BC_Signals::dump_stack();
769 if(debug) PRINT_TRACE
771 resource_timer->update();
773 // Age resource pixmaps for deletion
775 for(int i = 0; i < gui->resource_pixmaps.total; i++)
776 gui->resource_pixmaps.values[i]->visible--;
778 if(mode == FORCE_REDRAW)
779 gui->resource_pixmaps.remove_all_objects();
781 if(debug) PRINT_TRACE
784 for(Track *current = mwindow->edl->tracks->first;
788 if(debug) PRINT_TRACE
789 for(Edit *edit = current->edits->first; edit; edit = edit->next)
791 if(debug) PRINT_TRACE
792 if( current->data_type != TRACK_SUBTITLE )
793 if(!edit->asset && !edit->nested_edl) continue;
796 if(edit->track->data_type != TRACK_AUDIO) continue;
798 if(edit->nested_edl &&
799 strcmp(indexable->path, edit->nested_edl->path)) continue;
802 strcmp(indexable->path, edit->asset->path)) continue;
805 if(debug) PRINT_TRACE
807 int64_t edit_x, edit_y, edit_w, edit_h;
808 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
811 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
812 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
814 int64_t pixmap_x, pixmap_w, pixmap_h;
815 if(debug) PRINT_TRACE
817 // Search for existing pixmap containing edit
818 for(int i = 0; i < gui->resource_pixmaps.total; i++)
820 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
821 // Same pointer can be different edit if editing took place
822 if(pixmap->edit_id == edit->id &&
823 pixmap->pane_number == pane->number)
829 if(debug) PRINT_TRACE
831 // Get new size, offset of pixmap needed
832 get_pixmap_size(edit,
838 if(debug) PRINT_TRACE
841 if(pixmap_w && pixmap_h)
843 // Create pixmap if it doesn't exist
844 ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
845 pixmap_x, pixmap_w, pixmap_h);
846 // Resize it if it's bigger
847 if( pixmap_w > pixmap->pixmap_w ||
848 pixmap_h > pixmap->pixmap_h)
849 pixmap->resize(pixmap_w, pixmap_h);
850 pixmap->update_settings(edit, edit_x, edit_w,
851 pixmap_x, pixmap_w, pixmap_h);
853 if( current->show_assets() )
854 pixmap->draw_data(this,
855 edit, edit_x, edit_w,
856 pixmap_x, pixmap_w, pixmap_h,
860 clear_box(0,0, pixmap_w,pixmap_h, pixmap);
863 if( current->show_titles() )
864 pixmap->draw_title(this,
865 edit, edit_x, edit_w,
867 // Resize it if it's smaller
868 if(pixmap_w < pixmap->pixmap_w ||
869 pixmap_h < pixmap->pixmap_h)
870 pixmap->resize(pixmap_w, pixmap_h);
872 // Copy pixmap to background canvas
873 background_pixmap->draw_pixmap(pixmap,
875 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
879 if(debug) PRINT_TRACE
883 int64_t track_x, track_y, track_w, track_h;
884 track_dimensions(current,
885 track_x, track_y, track_w, track_h);
886 set_color((~get_resources()->get_bg_color()) & 0xffffff);
888 int x1 = track_x, x2 = x1+track_w;
889 int y1 = track_y+track_h-1;
890 draw_line(x1,y1, x2,y1, background_pixmap);
894 // Delete unused pixmaps
895 if(debug) PRINT_TRACE
897 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
898 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
900 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
901 delete gui->resource_pixmaps.values[i];
902 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
904 if(debug) PRINT_TRACE
906 if(hourglass_enabled)
909 hourglass_enabled = 0;
911 if(debug) PRINT_TRACE
913 // can't stop thread here, because this is called for every pane
914 // if(mode != IGNORE_THREAD && !indexes_only)
915 // gui->resource_thread->start_draw();
916 if(debug) PRINT_TRACE
921 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
927 ResourcePixmap *result = 0;
929 for(int i = 0; i < gui->resource_pixmaps.total; i++)
931 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
932 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
933 gui->resource_pixmaps.values[i]->pane_number == pane->number)
935 result = gui->resource_pixmaps.values[i];
943 result = new ResourcePixmap(mwindow,
950 gui->resource_pixmaps.append(result);
953 // result->resize(pixmap_w, pixmap_h);
957 void TrackCanvas::get_pixmap_size(Edit *edit,
965 // Align x on frame boundaries
968 // switch(edit->edits->track->data_type)
980 if(pixmap_x + pixmap_w > get_w())
982 pixmap_w = get_w() - pixmap_x;
989 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
990 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
991 // int64_t pixel_increment = MAX(picon_w, frame_w);
992 // int64_t pixmap_x1 = edit_x;
993 // int64_t pixmap_x2 = edit_x + edit_w;
997 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
1002 // if(pixmap_x2 > get_w())
1004 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
1005 // pixel_increment +
1008 // pixmap_x = pixmap_x1;
1009 // pixmap_w = pixmap_x2 - pixmap_x1;
1014 pixmap_h = mwindow->edl->local_session->zoom_track;
1015 Track *track = edit->edits->track;
1016 if( track->show_titles() )
1017 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
1018 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
1021 void TrackCanvas::edit_dimensions(Edit *edit,
1022 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1024 x = Units::round(edit->track->from_units(edit->startproject) *
1025 mwindow->edl->session->sample_rate /
1026 mwindow->edl->local_session->zoom_sample -
1027 mwindow->edl->local_session->view_start[pane->number]);
1029 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1031 // Method for calculating w so when edits are together we never get off by one error due to rounding
1032 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
1033 mwindow->edl->session->sample_rate /
1034 mwindow->edl->local_session->zoom_sample -
1035 mwindow->edl->local_session->view_start[pane->number]);
1039 if( edit->track->show_titles() )
1040 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
1041 if( edit->track->show_assets() )
1042 edit_h += resource_h();
1046 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1050 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1051 h = track->vertical_span(mwindow->theme);
1055 void TrackCanvas::draw_paste_destination()
1057 //int cursor_x = get_relative_cursor_x();
1058 //int cursor_y = get_relative_cursor_y();
1059 int current_atrack = 0;
1060 int current_vtrack = 0;
1061 int current_aedit = 0;
1062 int current_vedit = 0;
1068 //if(pane->number == BOTTOM_RIGHT_PANE)
1069 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1071 if((mwindow->session->current_operation == DRAG_ASSET &&
1072 (mwindow->session->drag_assets->total ||
1073 mwindow->session->drag_clips->total)) ||
1074 (mwindow->session->current_operation == DRAG_EDIT &&
1075 mwindow->session->drag_edits->total)) {
1076 Indexable *indexable = 0;
1080 if(mwindow->session->current_operation == DRAG_ASSET &&
1081 mwindow->session->drag_assets->size())
1082 indexable = mwindow->session->drag_assets->get(0);
1084 if(mwindow->session->current_operation == DRAG_ASSET &&
1085 mwindow->session->drag_clips->size())
1086 clip = mwindow->session->drag_clips->get(0);
1088 int has_audio = 0, has_video = 0;
1089 double paste_audio_length = 0, paste_video_length = 0;
1090 double paste_audio_position = -1, paste_video_position = -1;
1093 has_audio = indexable->have_audio();
1094 paste_audio_length = !has_audio ? 0 :
1095 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1096 has_video = indexable->have_video();
1097 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1098 // Images have length -1
1099 if( asset && asset->video_data && asset->video_length < 0 ) {
1100 paste_video_length = mwindow->edl->session->si_useduration ?
1101 mwindow->edl->session->si_duration / asset->frame_rate :
1102 1.0 / asset->frame_rate ; // 1 frame
1105 paste_video_length = !has_video ? 0 :
1106 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1110 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1111 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1112 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1113 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1116 // 'Align cursor on frame' lengths calculations
1117 if( mwindow->edl->session->cursor_on_frames ) {
1118 double fps = mwindow->edl->session->frame_rate;
1119 double aud = floor(paste_audio_length * fps) / fps;
1120 double vid = floor(paste_video_length * fps) / fps;
1121 double length = has_video && has_audio ?
1122 aud < vid ? aud : vid :
1124 has_audio ? aud : 0;
1125 paste_video_length = paste_audio_length = length;
1128 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1130 switch( mwindow->session->track_highlighted->data_type ) {
1131 case TRACK_VIDEO: length = paste_video_length; break;
1132 case TRACK_AUDIO: length = paste_audio_length; break;
1134 int64_t asset_length = mwindow->session->track_highlighted->
1135 to_units(length, 1);
1136 paste_audio_position = mwindow->session->track_highlighted->
1137 from_units(drop_edit_position(&insertion, NULL, asset_length));
1140 int64_t asset_length = mwindow->session->track_highlighted->
1141 to_units(paste_video_length, 1);
1142 paste_video_position = mwindow->session->track_highlighted->
1143 from_units(drop_edit_position(&insertion, NULL, asset_length));
1146 // Get destination track
1147 for(Track *dest = mwindow->session->track_highlighted;
1149 dest = dest->next) {
1151 // Get source width in pixels
1153 // Use start of highlighted edit
1154 if(mwindow->session->edit_highlighted) {
1155 position = mwindow->session->track_highlighted->from_units(
1156 mwindow->session->edit_highlighted->startproject);
1159 // Use end of highlighted track, disregarding effects
1160 position = mwindow->session->track_highlighted->from_units(
1161 mwindow->session->track_highlighted->edits->length());
1164 // Get the x coordinate
1165 x = Units::to_int64(position *
1166 mwindow->edl->session->sample_rate /
1167 mwindow->edl->local_session->zoom_sample) -
1168 mwindow->edl->local_session->view_start[pane->number];
1170 double paste_position = -1.;
1171 if(dest->data_type == TRACK_AUDIO) {
1172 if(indexable && current_atrack < indexable->get_audio_channels()) {
1173 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1174 w = Units::to_int64((double)indexable->get_audio_samples() /
1175 indexable->get_sample_rate() *
1176 mwindow->edl->session->sample_rate /
1177 mwindow->edl->local_session->zoom_sample);
1178 paste_position = paste_audio_position;
1180 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1181 w = Units::to_int64((double)clip->tracks->total_length() *
1182 mwindow->edl->session->sample_rate /
1183 mwindow->edl->local_session->zoom_sample);
1184 paste_position = paste_audio_position;
1185 //printf("draw_paste_destination %d\n", x);
1187 else if(mwindow->session->current_operation == DRAG_EDIT &&
1188 current_aedit < mwindow->session->drag_edits->total) {
1190 while(current_aedit < mwindow->session->drag_edits->total &&
1191 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1194 if(current_aedit < mwindow->session->drag_edits->total) {
1195 edit = mwindow->session->drag_edits->values[current_aedit];
1196 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1197 paste_position = mwindow->session->track_highlighted->
1198 from_units(drop_edit_position(&insertion,
1199 mwindow->session->drag_edit,
1200 mwindow->session->drag_edit->length));
1204 if( paste_position >= 0 ) {
1205 position = paste_position;
1212 else if(dest->data_type == TRACK_VIDEO) {
1213 //printf("draw_paste_destination 1\n");
1214 if(indexable && current_vtrack < indexable->get_video_layers())
1216 w = Units::to_int64((double)indexable->get_video_frames() /
1217 indexable->get_frame_rate() *
1218 mwindow->edl->session->sample_rate /
1219 mwindow->edl->local_session->zoom_sample);
1220 paste_position = paste_video_position;
1222 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1223 w = Units::to_int64(clip->tracks->total_length() *
1224 mwindow->edl->session->sample_rate /
1225 mwindow->edl->local_session->zoom_sample);
1226 paste_position = paste_video_position;
1228 else if(mwindow->session->current_operation == DRAG_EDIT &&
1229 current_vedit < mwindow->session->drag_edits->total) {
1231 while(current_vedit < mwindow->session->drag_edits->total &&
1232 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1235 if(current_vedit < mwindow->session->drag_edits->total) {
1236 edit = mwindow->session->drag_edits->values[current_vedit];
1237 w = Units::to_int64(edit->track->from_units(edit->length) *
1238 mwindow->edl->session->sample_rate /
1239 mwindow->edl->local_session->zoom_sample);
1240 paste_position = mwindow->session->track_highlighted->
1241 from_units(drop_edit_position(&insertion,
1242 mwindow->session->drag_edit,
1243 mwindow->session->drag_edit->length));
1247 if( paste_position >= 0 ) {
1248 position = paste_position;
1257 // Get the x coordinate
1258 x = Units::to_int64(position *
1259 mwindow->edl->session->sample_rate /
1260 mwindow->edl->local_session->zoom_sample) -
1261 mwindow->edl->local_session->view_start[pane->number];
1262 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1263 int h = dest->vertical_span(mwindow->theme);
1265 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1266 if(x < -BC_INFINITY) {
1267 w -= -BC_INFINITY - x;
1268 x += -BC_INFINITY - x;
1271 // if(pane->number == TOP_RIGHT_PANE)
1272 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1273 // __LINE__, x, y, w, h);
1275 draw_highlight_insertion(x, y, w, h);
1277 draw_highlight_rectangle(x, y, w, h);
1284 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1286 x = Units::round(plugin->track->from_units(plugin->startproject) *
1287 mwindow->edl->session->sample_rate /
1288 mwindow->edl->local_session->zoom_sample -
1289 mwindow->edl->local_session->view_start[pane->number]);
1290 w = Units::round(plugin->track->from_units(plugin->length) *
1291 mwindow->edl->session->sample_rate /
1292 mwindow->edl->local_session->zoom_sample);
1293 y = plugin->track->y_pixel
1294 - mwindow->edl->local_session->track_start[pane->number];
1295 if( plugin->track->show_titles() )
1296 y += mwindow->theme->get_image("title_bg_data")->get_h();
1297 if( plugin->track->show_assets() )
1299 y += plugin->plugin_set->get_number() *
1300 mwindow->theme->get_image("plugin_bg_data")->get_h();
1301 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1304 int TrackCanvas::resource_h()
1306 return mwindow->edl->local_session->zoom_track;
1309 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1312 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1313 // just draw arrows, so user has indication that something is there
1314 // FIXME: get better colors
1318 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1323 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1327 // Fix bug in heroines & cvs version as of 22.8.2005:
1328 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1329 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1342 w = MIN(w, get_w() + 20);
1343 h = MIN(h, get_h() + 20);
1346 set_color(mwindow->preferences->highlight_inverse);
1348 //draw_rectangle(x, y, w, h);
1349 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1350 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1352 draw_rectangle(x, y, w, h);
1354 //if(pane->number == TOP_RIGHT_PANE)
1355 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1358 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1361 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1362 // just draw arrows, so user has indication that something is there
1363 // FIXME: get better colors
1372 /* these don't look so good
1374 draw_line(x, y, x, y+h);
1375 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1376 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1377 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1378 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1380 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1381 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1383 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1384 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1385 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1386 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1388 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1389 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1391 // draw the box centred around x
1393 // Fix bug in heroines & cvs version as of 22.8.2005:
1394 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1395 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1406 w = MIN(w, get_w() + 20);
1407 h = MIN(h, get_h() + 20);
1408 set_color(mwindow->preferences->highlight_inverse);
1410 draw_rectangle(x, y, w, h);
1411 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1413 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1416 void TrackCanvas::draw_playback_cursor()
1418 // Called before playback_cursor exists
1419 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1421 // mwindow->playback_cursor->visible = 0;
1422 // mwindow->playback_cursor->draw();
1426 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1428 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1429 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1431 edit_dimensions(edit, x, y, w, h);
1433 if( edit->track->show_titles() )
1434 y += mwindow->theme->get_image("title_bg_data")->get_h();
1436 if(side == EDIT_OUT)
1443 void TrackCanvas::get_transition_coords(Edit *edit,
1444 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1446 int transition_w = 30, transition_h = 30;
1447 int has_titles = edit->track->show_titles();
1448 int has_assets = edit->track->show_assets();
1449 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
1450 double asset_h = resource_h();
1451 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
1452 double dy = has_titles ?
1453 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) :
1454 ( has_assets ? asset_h/2 : 0) ;
1455 double title_h = mwindow->theme->title_h;
1456 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
1459 x -= transition_w / 2;
1460 y -= transition_h / 2;
1465 void TrackCanvas::draw_highlighting()
1470 switch(mwindow->session->current_operation)
1472 case DRAG_ATRANSITION:
1473 case DRAG_VTRANSITION:
1474 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1475 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1476 if(mwindow->session->edit_highlighted) {
1477 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1478 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1479 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1480 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1481 edit_dimensions(mwindow->session->edit_highlighted,
1483 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1484 MWindowGUI::visible(y, y + h, 0, get_h())) {
1486 get_transition_coords(mwindow->session->edit_highlighted,
1493 // Dragging a new effect from the Resource window
1496 if(mwindow->session->track_highlighted &&
1497 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1498 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1499 (mwindow->session->current_operation == DRAG_VEFFECT &&
1500 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1501 // Put it before another plugin
1502 if(mwindow->session->plugin_highlighted) {
1503 plugin_dimensions(mwindow->session->plugin_highlighted,
1505 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1507 // Put it after a plugin set
1508 else if( mwindow->session->pluginset_highlighted &&
1509 mwindow->session->pluginset_highlighted->last ) {
1510 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1512 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1513 int64_t track_x, track_y, track_w, track_h;
1514 track_dimensions(mwindow->session->track_highlighted,
1515 track_x, track_y, track_w, track_h);
1519 mwindow->session->track_highlighted->get_length() *
1520 mwindow->edl->session->sample_rate /
1521 mwindow->edl->local_session->zoom_sample -
1522 mwindow->edl->local_session->view_start[pane->number]) -
1524 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1525 if(w <= 0) w = track_w;
1528 track_dimensions(mwindow->session->track_highlighted,
1531 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1532 // Put it in a new plugin set determined by the selected range
1533 if(mwindow->edl->local_session->get_selectionend() >
1534 mwindow->edl->local_session->get_selectionstart()) {
1535 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1536 mwindow->edl->session->sample_rate /
1537 mwindow->edl->local_session->zoom_sample -
1538 mwindow->edl->local_session->view_start[pane->number]);
1539 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1540 mwindow->edl->local_session->get_selectionstart()) *
1541 mwindow->edl->session->sample_rate /
1542 mwindow->edl->local_session->zoom_sample);
1544 // Put it in a new plugin set determined by an edit boundary
1545 else if(mwindow->session->edit_highlighted) {
1546 int64_t temp_y, temp_h;
1547 edit_dimensions(mwindow->session->edit_highlighted,
1548 x, temp_y, w, temp_h);
1550 // Put it at the beginning of the track in a new plugin set
1553 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1554 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1555 //printf("TrackCanvas::draw_highlighting 1\n");
1562 if(mwindow->session->track_highlighted) {
1563 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1565 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1567 draw_paste_destination();
1573 if(mwindow->session->track_highlighted) {
1574 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1576 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1577 draw_paste_destination();
1582 if( mwindow->session->track_highlighted && mwindow->session->drag_group &&
1583 mwindow->session->drag_group_edit && mwindow->session->drag_group_first_track ) {
1584 Track *track = mwindow->session->track_highlighted;
1585 EDL *drag_group = mwindow->session->drag_group;
1586 Track *edit_track = mwindow->session->drag_group_edit->track;
1587 Track *drag_track = mwindow->session->drag_group_first_track;
1588 while( track && edit_track && edit_track != drag_track ) {
1589 edit_track = edit_track->previous;
1590 track = track->previous;
1592 int cx = get_cursor_x();
1593 double cur_pos = mwindow->session->drag_group_position;
1594 double new_pos = mwindow->edl->get_cursor_position(cx, pane->number);
1595 new_pos -= mwindow->session->drag_position - cur_pos;
1596 new_pos = mwindow->edl->align_to_frame(new_pos, 0);
1597 double drop_position = new_pos;
1599 int ret = test_track_group(drag_group, track, new_pos);
1603 if( new_pos != drop_position ) {
1604 double pos = new_pos;
1605 pos += mwindow->session->drag_position - cur_pos;
1606 cx = mwindow->edl->get_position_cursorx(pos, pane->number);
1607 ret = test_track_group(drag_group, track, new_pos);
1609 color = ret > 0 ? YELLOW : shift_down() ? RED : BLUE;
1611 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1612 int dx = cx - mwindow->session->drag_origin_x;
1613 int dy = y - mwindow->session->drag_origin_y;
1614 draw_selected_edits(mwindow->edl, dx, dy, color, -1);
1617 // Dragging an effect from the timeline
1618 case DRAG_AEFFECT_COPY:
1619 case DRAG_VEFFECT_COPY:
1620 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1621 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1622 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1623 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1624 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1626 int64_t plugin_position = -1;
1627 Plugin *drag_plugin = mwindow->session->drag_plugin;
1628 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1629 Track *hi_track = mwindow->session->track_highlighted;
1630 Edit *hi_edit = mwindow->session->edit_highlighted;
1631 // Put it into a silence zone
1632 if( hi_plugin_set && hi_plugin_set->last &&
1633 hi_plugin_set->track == drag_plugin->track ) {
1634 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1635 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1636 hi_track = drag_plugin->track;
1638 else if( hi_track ) {
1639 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1640 track_dimensions(hi_track, x, y, w, h);
1641 plugin_position = hi_edit ? hi_edit->startproject : 0;
1644 if( plugin_position < 0 ) break;
1646 // Calculate length of plugin based on data type of track and units
1647 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1648 mwindow->edl->local_session->zoom_sample;
1649 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1650 mwindow->edl->local_session->view_start[pane->number];
1651 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1653 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1654 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1660 case DRAG_PLUGINKEY:
1661 if(mwindow->session->plugin_highlighted &&
1662 mwindow->session->current_operation == DRAG_PLUGINKEY)
1664 // Just highlight the plugin
1665 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1667 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1668 MWindowGUI::visible(y, y + h, 0, get_h()))
1678 draw_highlight_rectangle(x, y, w, h);
1680 draw_selected_edits(mwindow->edl, 0, 0, GREEN+BLUE, RED);
1683 // x does not reliably draw a really big rectangle
1684 void TrackCanvas::draw_selected(int x, int y, int w, int h)
1686 int x1 = bmax(x, 0), x2 = bmin(x+w, get_w());
1687 if( x1 > x2 ) return;
1688 int y1 = bmax(y, 0), y2 = bmin(y+h, get_h());
1689 if( y1 > y2 ) return;
1690 if( x >= 0 && x < get_w() ) draw_line(x,y1, x,y2);
1691 if( x+w >= 0 && x+w < get_w() ) draw_line(x+w,y1, x+w,y2);
1692 if( y >= 0 && y < get_h() ) draw_line(x1,y, x2,y);
1693 if( y+h >= 0 && y+h < get_h() ) draw_line(x1,y+h, x2,y+h);
1696 void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1)
1698 for( Track *track=edl->tracks->first; track; track=track->next ) {
1699 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1700 if( !edit->is_selected ) continue;
1702 edit_dimensions(edit, x, y, w, h);
1704 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue;
1705 if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
1707 int inner = color1 < 0 ? color0 : !edit->group_id ? color0 :
1708 mwindow->get_group_color(edit->group_id);
1710 draw_selected(x, y, w, h);
1711 int outer = color1 < 0 ? color0 : !edit->group_id ? color1 : inner;
1713 draw_selected(x-1, y-1, w+2, h+2);
1714 draw_selected(x-2, y-2, w+1, h+1);
1719 void TrackCanvas::draw_plugins()
1721 char string[BCTEXTLEN];
1723 int current_show = 0;
1724 int current_preset = 0;
1726 for(int i = 0; i < plugin_on_toggles.total; i++)
1727 plugin_on_toggles.values[i]->in_use = 0;
1728 for(int i = 0; i < plugin_show_toggles.total; i++)
1729 plugin_show_toggles.values[i]->in_use = 0;
1730 for(int i = 0; i < preset_edit_buttons.total; i++)
1731 plugin_show_toggles.values[i]->in_use = 0;
1734 for(Track *track = mwindow->edl->tracks->first;
1736 track = track->next)
1738 if(track->expand_view)
1740 for(int i = 0; i < track->plugin_set.total; i++)
1742 PluginSet *pluginset = track->plugin_set.values[i];
1744 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1746 int64_t total_x, y, total_w, h;
1747 plugin_dimensions(plugin, total_x, y, total_w, h);
1749 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1750 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1751 plugin->plugin_type != PLUGIN_NONE)
1753 int x = total_x, w = total_w, left_margin = 5;
1754 int right_margin = 5;
1760 if(w + x > get_w()) w -= (w + x) - get_w();
1767 mwindow->theme->get_image("plugin_bg_data"),
1769 set_color(mwindow->theme->title_color);
1770 set_font(mwindow->theme->title_font);
1771 plugin->calculate_title(string, 0);
1773 // Truncate string to int64_test visible in background
1774 int len = strlen(string), j;
1775 for(j = len; j >= 0; j--)
1777 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1785 // Justify the text on the left boundary of the edit if it is visible.
1786 // Otherwise justify it on the left side of the screen.
1787 int64_t text_x = total_x + left_margin;
1788 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1789 text_x = MAX(left_margin, text_x);
1791 y + get_text_ascent(mwindow->theme->title_font) + 2,
1795 int64_t min_x = total_x + text_w;
1798 // Update plugin toggles
1799 int toggle_x = total_x + total_w;
1801 toggle_x = MIN(get_w() - right_margin, toggle_x);
1804 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1805 if(toggle_x > min_x)
1807 if(current_on >= plugin_on_toggles.total)
1809 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1810 add_subwindow(plugin_on);
1811 plugin_on_toggles.append(plugin_on);
1815 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1820 // Toggles for standalone plugins only
1821 if(plugin->plugin_type == PLUGIN_STANDALONE)
1824 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1825 if(toggle_x > min_x)
1827 if(current_show >= plugin_show_toggles.total)
1829 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1830 add_subwindow(plugin_show);
1831 plugin_show_toggles.append(plugin_show);
1835 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1839 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1840 if(toggle_x > min_x)
1842 if(current_preset >= preset_edit_buttons.total)
1844 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1845 add_subwindow(preset_edit);
1846 preset_edit_buttons.append(preset_edit);
1850 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1861 // Remove unused toggles
1863 while(current_preset < preset_edit_buttons.total)
1865 preset_edit_buttons.remove_object_number(current_preset);
1867 while(current_show < plugin_show_toggles.total)
1869 plugin_show_toggles.remove_object_number(current_show);
1872 while(current_on < plugin_on_toggles.total)
1874 plugin_on_toggles.remove_object_number(current_on);
1878 void TrackCanvas::refresh_plugintoggles()
1880 for(int i = 0; i < plugin_on_toggles.total; i++)
1882 PluginOn *on = plugin_on_toggles.values[i];
1883 on->reposition_window(on->get_x(), on->get_y());
1885 for(int i = 0; i < plugin_show_toggles.total; i++)
1887 PluginShow *show = plugin_show_toggles.values[i];
1888 show->reposition_window(show->get_x(), show->get_y());
1890 for(int i = 0; i < preset_edit_buttons.total; i++)
1892 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1893 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1897 void TrackCanvas::draw_hard_edges()
1899 if( !mwindow->edl->session->auto_conf->hard_edges )
1903 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1904 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1905 if( !edit->hard_left && !edit->hard_right ) continue;
1906 edit_dimensions(edit, x, y, w, h);
1910 if( track->show_titles() )
1911 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
1912 if( track->show_assets() )
1915 y1 += mwindow->theme->title_h;
1916 if( edit->hard_left ) {
1917 ArrayList<int> xpt, ypt;
1918 xpt.append(x); ypt.append(y1);
1919 xpt.append(x+HANDLE_W); ypt.append(y1);
1920 xpt.append(x); ypt.append(y1-HANDLE_H);
1921 fill_polygon(&xpt, &ypt);
1923 if( edit->hard_right ) {
1924 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1925 xpt.append(x1); ypt.append(y1);
1926 xpt.append(x1-HANDLE_W); ypt.append(y1);
1927 xpt.append(x1); ypt.append(y1-HANDLE_H);
1928 fill_polygon(&xpt, &ypt);
1934 void TrackCanvas::draw_inout_points()
1939 void TrackCanvas::draw_drag_handle()
1941 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 &&
1942 mwindow->session->current_operation != DRAG_PLUGINHANDLE2 ) return;
1943 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1944 mwindow->edl->session->sample_rate /
1945 mwindow->edl->local_session->zoom_sample -
1946 mwindow->edl->local_session->view_start[pane->number]);
1947 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1949 draw_line(pixel1, 0, pixel1, get_h());
1952 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 ) return;
1953 if( !mwindow->session->drag_edit ) return;
1954 int group_id = mwindow->session->drag_edit->group_id;
1955 if( !group_id ) return;
1956 int64_t dx, dy, dw, dh;
1957 edit_dimensions(mwindow->session->drag_edit, dx, dy, dw, dh);
1958 int drag_handle = mwindow->session->drag_handle;
1959 int64_t pixel0 = !drag_handle ? dx : dx + dw;
1960 int delta = pixel1 - pixel0;
1961 set_color(LTPURPLE);
1964 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
1965 Edit *left = 0, *right = 0;
1966 double start = DBL_MAX, end = DBL_MIN;
1967 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1968 if( edit->group_id != group_id ) continue;
1969 double edit_start = edit->track->from_units(edit->startproject);
1970 if( edit_start < start ) { start = edit_start; left = edit; }
1971 double edit_end = edit->track->from_units(edit->startproject+edit->length);
1972 if( edit_end > end ) { end = edit_end; right = edit; }
1974 Edit *edit = !drag_handle ? left : right;
1975 if( !edit ) continue;
1976 Indexable *idxbl = edit->asset;
1977 if( !idxbl ) idxbl = edit->nested_edl;
1978 int can_drag = idxbl ? 1 : 0;
1980 int64_t source_len = !idxbl ? -1 :
1981 edit->track->data_type == TRACK_AUDIO ?
1982 idxbl->get_audio_samples() :
1983 edit->track->data_type == TRACK_VIDEO ?
1984 idxbl->get_video_frames() : -1;
1985 if( edit->startsource + edit->length >= source_len )
1988 else if( !edit->startsource )
1991 edit_dimensions(edit, x, y, w, h);
1992 if( y+h < 0 || y >= get_h() ) continue;
1993 int edge_x = !drag_handle ? x : x + w;
1994 int edge_y = y + h/2, k = 10;
1995 if( edge_x >= 0 && edge_x < get_w() ) {
1997 draw_line(edge_x-k,edge_y-k, edge_x+k,edge_y+k);
1998 draw_line(edge_x-k,edge_y+k, edge_x+k,edge_y-k);
2000 else if( !drag_handle ) {
2001 draw_line(edge_x+k,edge_y-k, edge_x,edge_y);
2002 draw_line(edge_x+k,edge_y+k, edge_x,edge_y);
2005 draw_line(edge_x,edge_y, edge_x-k,edge_y-k);
2006 draw_line(edge_x,edge_y, edge_x-k,edge_y+k);
2010 if( edge_x >= 0 && edge_x < get_w() ) {
2011 draw_line(edge_x, y, edge_x, y+h);
2018 void TrackCanvas::draw_transitions()
2022 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
2023 if( !track->show_transitions() ) continue;
2025 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
2026 if(!edit->transition) continue;
2027 edit_dimensions(edit, x, y, w, h);
2028 int strip_x = x, edit_y = y;
2029 get_transition_coords(edit, x, y, w, h);
2030 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
2031 if( track->show_assets() && track->show_titles() )
2032 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
2033 if( strip_y < edit_y ) strip_y = edit_y;
2035 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
2036 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
2037 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
2038 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
2039 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
2041 if( !server ) continue;
2042 VFrame *picon = server->get_picon();
2043 if( !picon ) continue;
2044 int picon_w = picon->get_w(), picon_h = picon->get_h();
2045 int track_h = edit->track->vertical_span(mwindow->theme);
2046 if( picon_h > track_h ) picon_h = track_h;
2047 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
2049 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
2050 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
2051 int x = strip_x, w = strip_w;
2052 if( x < 0 ) { w -= -x; x = 0; }
2053 if( w + x > get_w() ) w -= (w + x) - get_w();
2055 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
2056 mwindow->theme->get_image("plugin_bg_data"), 0);
2062 void TrackCanvas::draw_loop_points()
2064 //printf("TrackCanvas::draw_loop_points 1\n");
2065 if(mwindow->edl->local_session->loop_playback)
2067 //printf("TrackCanvas::draw_loop_points 2\n");
2068 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
2069 mwindow->edl->session->sample_rate /
2070 mwindow->edl->local_session->zoom_sample -
2071 mwindow->edl->local_session->view_start[pane->number]);
2072 //printf("TrackCanvas::draw_loop_points 3\n");
2074 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2077 draw_line(x, 0, x, get_h());
2079 //printf("TrackCanvas::draw_loop_points 4\n");
2081 x = Units::round(mwindow->edl->local_session->loop_end *
2082 mwindow->edl->session->sample_rate /
2083 mwindow->edl->local_session->zoom_sample -
2084 mwindow->edl->local_session->view_start[pane->number]);
2085 //printf("TrackCanvas::draw_loop_points 5\n");
2087 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2090 draw_line(x, 0, x, get_h());
2092 //printf("TrackCanvas::draw_loop_points 6\n");
2094 //printf("TrackCanvas::draw_loop_points 7\n");
2097 void TrackCanvas::draw_brender_range()
2099 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
2100 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
2101 if( mwindow->edl->session->brender_end > 0 )
2103 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
2104 mwindow->edl->session->sample_rate /
2105 mwindow->edl->local_session->zoom_sample -
2106 mwindow->edl->local_session->view_start[pane->number]);
2107 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
2110 draw_line(x1, 0, x1, get_h());
2112 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
2113 mwindow->edl->session->sample_rate /
2114 mwindow->edl->local_session->zoom_sample -
2115 mwindow->edl->local_session->view_start[pane->number]);
2117 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
2120 draw_line(x2, 0, x2, get_h());
2125 // The operations which correspond to each automation type
2126 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
2142 // The buttonpress operations, so nothing changes unless the mouse moves
2143 // a certain amount. This allows the keyframe to be used to position the
2144 // insertion point without moving itself.
2145 static int pre_auto_operations[AUTOMATION_TOTAL] =
2162 int TrackCanvas::do_keyframes(int cursor_x,
2170 // Note: button 3 (right mouse button) is not eaten to allow
2171 // track context menu to appear
2173 EDLSession *session = mwindow->edl->session;
2177 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
2179 0, 0, 0, 0, 0, 0, 0, 0,
2181 modekeyframe_pixmap,
2182 maskkeyframe_pixmap,
2188 for(Track *track = mwindow->edl->tracks->first;
2190 track = track->next) {
2191 Auto *auto_keyframe = 0;
2192 Automation *automation = track->automation;
2195 // Handle keyframes in reverse drawing order if a button press
2197 int end = AUTOMATION_TOTAL;
2201 start = AUTOMATION_TOTAL - 1;
2205 for(int i = start; i != end && !result; i += step)
2207 // Event not trapped and automation visible
2208 Autos *autos = automation->autos[i];
2209 if(!result && session->auto_conf->autos[i] && autos) {
2211 case AUTOMATION_MODE:
2212 case AUTOMATION_PAN:
2213 case AUTOMATION_MASK:
2214 result = do_autos(track, automation->autos[i],
2215 cursor_x, cursor_y, draw,
2216 buttonpress, auto_pixmaps[i],
2217 auto_keyframe, rerender);
2221 switch(autos->get_type()) {
2222 case Autos::AUTOMATION_TYPE_FLOAT: {
2223 Automation automation(0, track);
2224 int grouptype = automation.autogrouptype(i, track);
2225 if( buttonpress && i == AUTOMATION_SPEED ) {
2226 mwindow->speed_before();
2229 if(draw) // Do dropshadow
2230 result = do_float_autos(track, autos,
2231 cursor_x, cursor_y, draw,
2232 buttonpress, 1, 1, MDGREY,
2233 auto_keyframe, grouptype);
2234 result = do_float_autos(track, autos,
2235 cursor_x, cursor_y, draw, buttonpress,
2236 0, 0, GWindowGUI::auto_colors[i],
2237 auto_keyframe, grouptype);
2239 if( !result && buttonpress && i == AUTOMATION_SPEED )
2240 mwindow->speed_after(-1);
2241 if( result && buttonpress ) {
2242 int color = GWindowGUI::auto_colors[i];
2243 mwindow->gui->zoombar->update_autozoom(grouptype, color);
2247 case Autos::AUTOMATION_TYPE_INT: {
2248 if(draw) // Do dropshadow
2249 result = do_int_autos(track, autos,
2250 cursor_x, cursor_y, draw,
2251 buttonpress, 1, 1, MDGREY,
2253 result = do_int_autos(track, autos,
2254 cursor_x, cursor_y, draw, buttonpress,
2255 0, 0, GWindowGUI::auto_colors[i],
2264 if(mwindow->session->current_operation == auto_operations[i])
2267 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2269 // mwindow->session->current_operation,
2270 // auto_operations[i]);
2273 if (buttonpress == 2 && auto_keyframe )
2275 double position = track->from_units(auto_keyframe->position);
2276 mwindow->edl->local_session->set_selectionstart(position);
2277 mwindow->edl->local_session->set_selectionend(position);
2279 if (buttonpress != 3)
2281 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2282 fill_ganged_autos(get_double_click(), 0, track,
2283 (FloatAuto*)mwindow->session->drag_auto);
2284 mwindow->session->current_operation = pre_auto_operations[i];
2285 update_drag_caption();
2288 else if( auto_keyframe )
2290 gui->keyframe_menu->update(automation,
2293 gui->keyframe_menu->activate_menu();
2294 rerender = 1; // the position changes
2298 gui->keyframe_hide->update(autos);
2299 gui->keyframe_hide->activate_menu();
2300 rerender = 1; // the position changes
2302 if(buttonpress == 1 && ctrl_down() &&
2303 AUTOMATION_TYPE_FLOAT == autos->get_type())
2304 rerender = 1; // special case: curve mode changed
2310 if(!result && session->auto_conf->plugins) {
2313 result = do_plugin_autos(track, cursor_x, cursor_y,
2314 draw, buttonpress, plugin, keyframe);
2315 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2318 if(result && (buttonpress == 1)) {
2319 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2320 update_drag_caption();
2323 else if (result && (buttonpress == 3)) {
2324 gui->keyframe_menu->update(plugin, keyframe);
2325 gui->keyframe_menu->activate_menu();
2326 rerender = 1; // the position changes
2331 // Final pass to trap event
2332 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2333 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2334 mwindow->session->current_operation == auto_operations[i]) {
2340 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2341 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2347 new_cursor = UPRIGHT_ARROW_CURSOR;
2353 void TrackCanvas::draw_keyframe_reticle()
2355 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2356 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2358 int current_op = mwindow->session->current_operation, dragging = 0;
2359 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2360 if( current_op == auto_operations[i] ) dragging = 1;
2361 if( dragging && !mwindow->session->drag_auto ) dragging = 0;
2363 int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
2364 mwindow->session->drag_auto->autos->autoidx : -1;
2366 if( get_buttonpress() == LEFT_BUTTON && dragging &&
2367 keyframe_hairline == HAIRLINE_DRAGGING ) {
2368 draw_hairline(mwindow->session->drag_auto, RED, 1);
2372 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == MIDDLE_BUTTON &&
2373 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2374 int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
2375 for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
2376 Automation *automation = track->automation;
2377 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2378 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2379 // automation visible
2380 Autos *autos = automation->autos[i];
2381 if( !autos ) continue;
2382 if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
2383 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2384 auto_keyframe = auto_keyframe->next ) {
2385 draw_hairline(auto_keyframe, BLUE, show);
2391 draw_hairline(mwindow->session->drag_auto, RED, 1);
2395 void TrackCanvas::draw_auto(Auto *current,
2403 x1 = x - HANDLE_W / 2;
2404 x2 = x + HANDLE_W / 2;
2405 y1 = center_pixel + y - HANDLE_W / 2;
2406 y2 = center_pixel + y + HANDLE_W / 2;
2408 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2409 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2411 draw_box(x1, y1, x2 - x1, y2 - y1);
2415 // This draws lines for bezier in & out controls
2416 void TrackCanvas::draw_cropped_line(int x1,
2425 // Don't care about x since it is clipped by the window.
2426 // Put y coords in ascending order
2428 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2429 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2434 double slope = (double)(x2 - x1) / (y2 - y1);
2435 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2437 x1 = (int)(x1 + (min_y - y1) * slope);
2440 else if(y1 >= max_y) {
2441 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2446 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2449 else if(y2 < min_y) {
2450 x2 = (int)(x2 + (min_y - y2) * slope);
2455 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2456 if( y1 >= min_y && y1 < max_y &&
2457 y2 >= min_y && y2 < max_y )
2458 draw_line(x1, y1, x2, y2);
2462 void TrackCanvas::draw_floatauto(FloatAuto *current,
2473 int x1 = x - HANDLE_W / 2; // Center
2474 int x2 = x + HANDLE_W / 2;
2475 int y1 = center_pixel + y - HANDLE_H / 2;
2476 int y2 = center_pixel + y + HANDLE_H / 2;
2477 int ymin = center_pixel - zoom_track / 2;
2478 int ymax = center_pixel + zoom_track / 2;
2479 CLAMP(y1, ymin, ymax);
2480 CLAMP(y2, ymin, ymax);
2483 if( current->curve_mode == FloatAuto::LINEAR ) {
2484 draw_box(x1, y1, x2 - x1, y2 - y1);
2487 ArrayList<int> polygon_x;
2488 ArrayList<int> polygon_y;
2489 polygon_x.append((x1 + x2) / 2 + 1);
2490 polygon_y.append(y1 + 1);
2491 polygon_x.append(x2 + 1);
2492 polygon_y.append((y1 + y2) / 2 + 1);
2493 polygon_x.append((x1 + x2) / 2 + 1);
2494 polygon_y.append(y2 + 1);
2495 polygon_x.append(x1 + 1);
2496 polygon_y.append((y1 + y2) / 2 + 1);
2497 fill_polygon(&polygon_x, &polygon_y);
2501 // show bezier control points (only) if this
2502 // floatauto doesn't adjust it's tangents automatically
2503 if(current->curve_mode != FloatAuto::FREE &&
2504 current->curve_mode != FloatAuto::TFREE)
2508 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2510 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2513 inline int quantize(float f) { return (int)floor(f + 0.5); }
2515 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2516 int x, int y, int cp_x, int cp_y, int center_pixel,
2517 int zoom_track, int color)
2518 // draw the tangent and a handle for given bézier ctrl point
2520 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2522 float slope = (float)(cp_y - y)/(cp_x - x);
2523 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2525 cp_x = x + quantize((cp_y - y) / slope);
2528 cp_y += center_pixel;
2530 // drawing the tangent as a dashed line...
2531 int const dash = HANDLE_W;
2532 int const gap = HANDLE_W / 2;
2533 float sx = 3 * (cp_x - x) / 4.;
2536 // q is the x displacement for a unit line of slope
2537 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2539 float dist = 1/q * sx;
2545 float sy = slope * sx, ey = slope * ex;
2546 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2553 int r = HANDLE_W / 2;
2554 int cp_x1 = cp_x - r;
2555 int cp_y1 = cp_y - r;
2557 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2559 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2564 int TrackCanvas::test_auto(Auto *current,
2565 int x, int y, int center_pixel, int zoom_track,
2566 int cursor_x, int cursor_y, int buttonpress)
2571 x1 = x - HANDLE_W / 2;
2572 x2 = x + HANDLE_W / 2;
2573 y1 = center_pixel + y - HANDLE_H / 2;
2574 y2 = center_pixel + y + HANDLE_H / 2;
2575 int ymin = center_pixel - zoom_track / 2;
2576 int ymax = center_pixel + zoom_track / 2;
2577 CLAMP(y1, ymin, ymax);
2578 CLAMP(y2, ymin, ymax);
2580 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2582 if(buttonpress && buttonpress != 3)
2584 mwindow->session->drag_auto = current;
2585 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2586 // Toggle Autos don't respond to vertical zoom, they always show up
2587 // with "on" == 100% == line on top
2588 mwindow->session->drag_start_position = current->position;
2589 mwindow->session->drag_origin_x = cursor_x;
2590 mwindow->session->drag_origin_y = cursor_y;
2595 if(buttonpress && buttonpress != 3 && result)
2597 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2598 mwindow->undo->update_undo_before();
2604 // some Helpers for test_floatauto(..)
2605 // and for dragging the tangents/ctrl points
2606 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2607 float cursor_x, float cursor_y)
2609 // Control point switched off?
2610 if( x0 == ctrl_x ) return 0.0;
2611 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2612 double x = cursor_x-x0, y = cursor_y-y0;
2613 // wrong side of ctrl handle
2614 if( x*x1 < 0 ) return 0.0;
2615 // outside handle radius
2616 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2617 double xx1 = x1*x1, yy1 = y1*y1;
2618 double xx = x*x, yy = y*y;
2619 // distance squared from cursor to cursor projected to line from ctrl to handle
2620 // along a line perpendicular to line from ctrl to handle (closest approach)
2621 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2622 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2623 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2628 float levered_position(float position, float ref_pos)
2630 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2632 return ref_pos / position;
2636 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2637 // transforms automation value into current display coords,
2638 // dependant on current automation display range for the given kind of automation
2640 if(!mwindow || !mwindow->edl) return 0;
2641 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2642 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2643 float automation_range = automation_max - automation_min;
2644 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2646 return (auto_value - automation_min) / automation_range;
2651 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2652 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2653 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2657 int x1 = x - HANDLE_W / 2;
2658 int x2 = x + HANDLE_W / 2;
2659 int y1 = center_pixel + y - HANDLE_W / 2;
2660 int y2 = center_pixel + y + HANDLE_W / 2;
2661 int ymin = center_pixel - zoom_track / 2;
2662 int ymax = center_pixel + zoom_track / 2;
2663 CLAMP(y1, ymin, ymax);
2664 CLAMP(y2, ymin, ymax);
2666 int in_x1 = in_x - HANDLE_W / 2;
2667 int in_x2 = in_x + HANDLE_W / 2;
2668 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2669 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2670 CLAMP(in_y1, ymin, ymax);
2671 CLAMP(in_y2, ymin, ymax);
2673 int out_x1 = out_x - HANDLE_W / 2;
2674 int out_x2 = out_x + HANDLE_W / 2;
2675 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2676 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2677 CLAMP(out_y1, ymin, ymax);
2678 CLAMP(out_y2, ymin, ymax);
2681 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2682 // buttonpress could be the start of a drag operation
2683 #define INIT_DRAG(POS,VAL) \
2684 mwindow->session->drag_auto = current; \
2685 mwindow->session->drag_origin_x = cursor_x; \
2686 mwindow->session->drag_origin_y = cursor_y; \
2687 mwindow->session->drag_start_position = (POS); \
2688 mwindow->session->drag_start_percentage = (VAL);
2690 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2693 // without modifier we are manipulating the automation node
2694 // with ALT it's about dragging only the value of the node
2695 // with SHIFT the value snaps to the value of neighbouring nodes
2696 // CTRL indicates we are rather manipulating the tangent(s) of the node
2700 if( WITHIN(x1,x2,y1,y2))
2701 { // cursor hits node
2704 if(buttonpress && (buttonpress != 3))
2706 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2707 mwindow->session->drag_handle = 0;
2712 if( WITHIN(x1,x2,y1,y2))
2715 if(buttonpress && (buttonpress != 3))
2717 // could be ctrl-click or ctrl-drag
2718 // click would cycle through tangent modes
2719 ((FloatAuto*)current)->toggle_curve_mode();
2721 // drag will start dragging the tangent, if applicable
2722 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2723 mwindow->session->drag_handle = 0;
2727 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2730 if( in_x != x && current->position > 0 &&
2731 (FloatAuto::FREE == current->curve_mode ||
2732 FloatAuto::TFREE == current->curve_mode))
2733 // act on in control handle only if
2734 // tangent is significant and is editable (not automatically choosen)
2736 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2737 // either cursor in ctrl-point handle or cursor on tangent line
2738 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2740 if(buttonpress && (buttonpress != 3)) {
2741 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2743 mwindow->session->drag_handle = 1;
2744 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2745 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2746 value_to_percentage(new_invalue, autogrouptype))
2753 (FloatAuto::FREE == current->curve_mode ||
2754 FloatAuto::TFREE == current->curve_mode))
2755 // act on out control only if tangent is significant and is editable
2757 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2758 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2760 if(buttonpress && (buttonpress != 3)) {
2761 if(lever == 0.0) lever=1.0;
2763 mwindow->session->drag_handle = 2;
2764 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2765 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2766 value_to_percentage(new_outvalue, autogrouptype))
2770 } // end ctrl_down()
2776 // 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",
2777 // mwindow->session->drag_handle,
2782 if(buttonpress && (buttonpress != 3) && result)
2784 mwindow->undo->update_undo_before();
2791 // Get the float value & y for position x on the canvas
2792 #define X_TO_FLOATLINE(x) \
2793 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2794 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2795 /* Call by reference fails for some reason here */ \
2796 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2797 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2798 double position = unit_start + x * zoom_units; \
2800 if(position2 > position1) \
2803 (value2 - value1) * \
2804 (position - position1) / \
2805 (position2 - position1); \
2811 AUTOMATIONCLAMPS(value, autogrouptype); \
2812 int y = center_pixel + \
2813 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2816 void TrackCanvas::draw_floatline(int center_pixel,
2817 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2818 double unit_start, double zoom_units, double yscale,
2819 int x1, int y1, int x2, int y2,
2820 int color, int autogrouptype)
2822 // Solve bezier equation for either every pixel or a certain large number of
2825 // Not using slope intercept
2827 int prev_y = y1 + center_pixel;
2830 // Call by reference fails for some reason here
2831 FloatAuto *previous1 = previous, *next1 = next;
2832 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2833 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2834 float automation_range = automation_max - automation_min;
2836 for(int x = x1; x < x2; x++)
2838 // Interpolate value between frames
2842 y >= center_pixel - yscale / 2 &&
2843 y < center_pixel + yscale / 2 - 1)
2845 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2847 // (int)(center_pixel - yscale / 2),
2848 // (int)(center_pixel + yscale / 2 - 1));
2850 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2851 draw_line(x - 1, prev_y , x, y );
2861 int TrackCanvas::test_floatline(int center_pixel,
2876 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2877 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2878 float automation_range = automation_max - automation_min;
2879 FloatAuto *previous1 = 0, *next1 = 0;
2880 X_TO_FLOATLINE(cursor_x);
2882 if(cursor_x >= x1 &&
2884 cursor_y >= y - HANDLE_W / 2 &&
2885 cursor_y < y + HANDLE_W / 2 &&
2891 if(buttonpress == 3)
2899 mwindow->undo->update_undo_before();
2900 double position = autos->track->from_units(position1);
2901 position = mwindow->edl->align_to_frame(position, 0);
2902 int64_t new_position = autos->track->to_units(position,0);
2903 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2904 ((FloatAuto*)current)->set_value(value);
2905 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2906 mwindow->session->drag_start_position = current->position;
2907 mwindow->session->drag_origin_x = cursor_x;
2908 mwindow->session->drag_origin_y = cursor_y;
2909 mwindow->session->drag_handle = 0;
2918 void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto)
2920 if( !skip->gang ) return;
2921 // Handles the special case of modifying a fadeauto
2922 // when there are ganged faders on several tracks
2923 double position = skip->from_units(fauto->position);
2924 int autoidx = fauto->autos->autoidx;
2926 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2927 if( (all || current->data_type == skip->data_type) &&
2928 current->gang && current->record && current != skip ) {
2929 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2930 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2931 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2932 int64_t current_position = current->to_units(position, 1);
2933 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
2935 // keyframe exists, just change it
2936 float value = keyframe->get_value();
2937 float new_value = value + change;
2938 CLAMP(new_value, auto_min, auto_max);
2939 keyframe->adjust_to_new_coordinates(current_position, new_value);
2942 // create keyframe on neighbouring track at the point in time given by fauto
2943 FloatAuto *previous = 0, *next = 0;
2944 float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2945 float new_value = value + change;
2946 CLAMP(new_value, auto_min, auto_max);
2947 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2948 keyframe->set_value(new_value);
2950 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2955 void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
2957 double position = skip->from_units(fauto->position);
2959 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2960 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2961 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2962 float new_value = keyframe->get_value() + change;
2964 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2965 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2966 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2970 void TrackCanvas::clear_ganged_autos()
2973 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2974 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2975 keyframe->autos->remove_nonsequential(keyframe);
2977 mwindow->session->drag_auto_gang->remove_all();
2981 void TrackCanvas::draw_toggleline(int center_pixel,
2987 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2991 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2995 int TrackCanvas::test_toggleline(Autos *autos,
3006 if(cursor_x >= x1 && cursor_x < x2)
3008 int miny = center_pixel + y1 - HANDLE_W / 2;
3009 int maxy = center_pixel + y1 + HANDLE_W / 2;
3010 if(cursor_y >= miny && cursor_y < maxy)
3015 if(buttonpress == 3)
3023 double position = (double)(cursor_x +
3024 mwindow->edl->local_session->view_start[pane->number]) *
3025 mwindow->edl->local_session->zoom_sample /
3026 mwindow->edl->session->sample_rate;
3027 int64_t unit_position = autos->track->to_units(position, 0);
3028 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
3030 mwindow->undo->update_undo_before();
3032 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
3033 ((IntAuto*)current)->value = new_value;
3034 // Toggle Autos don't respond to vertical zoom, they always show up
3035 // with "on" == 100% == line on top
3036 mwindow->session->drag_start_percentage = (float)new_value;
3037 mwindow->session->drag_start_position = current->position;
3038 mwindow->session->drag_origin_x = cursor_x;
3039 mwindow->session->drag_origin_y = cursor_y;
3047 void TrackCanvas::calculate_viewport(Track *track,
3048 double &view_start, // Seconds
3050 double &view_end, // Seconds
3054 double &zoom_sample,
3058 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
3059 mwindow->edl->local_session->zoom_sample /
3060 mwindow->edl->session->sample_rate;
3061 unit_start = track->to_doubleunits(view_start);
3062 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
3064 mwindow->edl->local_session->zoom_sample /
3065 mwindow->edl->session->sample_rate;
3066 unit_end = track->to_doubleunits(view_end);
3068 int y = track->y_pixel
3069 - mwindow->edl->local_session->track_start[pane->number];
3070 int has_titles = track->show_titles();
3071 int has_assets = track->show_assets();
3072 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
3073 double asset_h = resource_h();
3074 double title_h = mwindow->theme->title_h;
3075 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
3076 double dy = has_titles ?
3077 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) :
3078 ( has_assets ? asset_h/2 : 0) ;
3079 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
3081 center_pixel = y + dy;
3083 zoom_sample = mwindow->edl->local_session->zoom_sample;
3084 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
3087 float TrackCanvas::percentage_to_value(float percentage,
3095 if(percentage > 0.5)
3102 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3103 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3104 float automation_range = automation_max - automation_min;
3106 result = percentage * automation_range + automation_min;
3109 FloatAuto *ptr = (FloatAuto*)reference;
3110 result -= ptr->get_value();
3112 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
3118 void TrackCanvas::calculate_auto_position(double *x, double *y,
3119 double *in_x, double *in_y, double *out_x, double *out_y,
3120 Auto *current, double unit_start, double zoom_units, double yscale,
3123 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3124 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3125 float automation_range = automation_max - automation_min;
3126 FloatAuto *ptr = (FloatAuto*)current;
3127 *x = (double)(ptr->position - unit_start) / zoom_units;
3128 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
3131 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
3132 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
3136 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
3137 automation_min) / automation_range - 0.5) * -yscale;
3141 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
3142 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
3146 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
3147 automation_min) / automation_range - 0.5) * -yscale;
3152 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
3153 int draw, int buttonpress, int x_offset, int y_offset, int color,
3154 Auto* &auto_instance, int autogrouptype)
3157 int center_pixel, draw_auto;
3158 double view_start, unit_start;
3159 double view_end, unit_end, yscale;
3160 double zoom_sample, zoom_units;
3161 double in_x2, in_y2, out_x2, out_y2;
3167 if(draw) set_color(color);
3169 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3170 yscale, center_pixel, zoom_sample, zoom_units);
3172 // Get first auto before start
3173 Auto *current = 0, *previous = 0;
3175 for( current = autos->last;
3176 current && current->position >= unit_start;
3177 current = PREVIOUS ) ;
3179 Auto *first_auto = current ? current :
3180 autos->first ? autos->first : autos->default_auto;
3182 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
3184 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3185 first_auto, unit_start, zoom_units, yscale, autogrouptype);
3190 current = autos->first;
3199 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
3200 current, unit_start, zoom_units, yscale, autogrouptype);
3208 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3213 ay2 = ay + slope * (get_w() - ax);
3217 ay = ay + slope * (0 - ax);
3221 // Draw or test handle
3222 if( current && !result && current != autos->default_auto ) {
3223 if( !draw && track->record ) {
3224 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3225 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3226 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3227 buttonpress, autogrouptype);
3229 auto_instance = current;
3231 if( draw && draw_auto ) {
3232 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3233 (int)in_x2 + x_offset, (int)in_y2,
3234 (int)out_x2 + x_offset, (int)out_y2,
3235 (int)center_pixel + y_offset, (int)yscale, color);
3239 // Draw or test joining line
3240 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3241 result = test_floatline(center_pixel,
3242 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3243 // Exclude auto coverage from the end of the line. The auto overlaps
3244 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3245 buttonpress, autogrouptype);
3248 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3249 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3250 (int)ax, (int)ay, (int)ax2, (int)ay2,
3251 color, autogrouptype);
3259 } while( current && current->position <= unit_end && !result );
3261 if( ax < get_w() && !result ) {
3262 ax2 = get_w(); ay2 = ay;
3263 if(!draw && track->record /* && buttonpress != 3 */ ) {
3264 result = test_floatline(center_pixel,
3265 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3266 (int)ax, (int)ax2, cursor_x, cursor_y,
3267 buttonpress, autogrouptype);
3270 draw_floatline(center_pixel,
3271 (FloatAuto*)previous, (FloatAuto*)current,
3272 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3273 (int)ax, (int)ay, (int)ax2, (int)ay2,
3274 color, autogrouptype);
3281 int TrackCanvas::do_int_autos(Track *track,
3290 Auto *&auto_instance)
3301 double ax, ay, ax2, ay2;
3305 if(draw) set_color(color);
3307 calculate_viewport(track,
3318 double high = -yscale * 0.8 / 2;
3319 double low = yscale * 0.8 / 2;
3321 // Get first auto before start
3323 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3329 ay = ((IntAuto*)current)->value > 0 ? high : low;
3334 current = autos->first ? autos->first : autos->default_auto;
3338 ay = ((IntAuto*)current)->value > 0 ? high : low;
3351 ax2 = (double)(current->position - unit_start) / zoom_units;
3352 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3360 if(ax2 > get_w()) ax2 = get_w();
3362 if(current && !result)
3364 if(current != autos->default_auto)
3370 result = test_auto(current,
3379 auto_instance = current;
3384 (int)ax2 + x_offset,
3385 (int)ay2 + y_offset,
3397 if(track->record /* && buttonpress != 3 */)
3399 result = test_toggleline(autos,
3412 draw_toggleline(center_pixel + y_offset,
3420 }while(current && current->position <= unit_end && !result);
3422 if(ax < get_w() && !result)
3428 if(track->record /* && buttonpress != 3 */)
3430 result = test_toggleline(autos,
3442 draw_toggleline(center_pixel + y_offset,
3451 int TrackCanvas::do_autos(Track *track,
3458 Auto * &auto_instance,
3472 calculate_viewport(track,
3485 for(current = autos->first; current && !result; current = NEXT)
3487 if(current->position >= unit_start && current->position < unit_end)
3490 x = (int64_t)((double)(current->position - unit_start) /
3491 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3492 y = center_pixel - pixmap->get_h() / 2;
3496 if(cursor_x >= x && cursor_y >= y &&
3497 cursor_x < x + pixmap->get_w() &&
3498 cursor_y < y + pixmap->get_h())
3501 auto_instance = current;
3503 if(buttonpress && (buttonpress != 3))
3505 mwindow->session->drag_auto = current;
3506 mwindow->session->drag_start_position = current->position;
3507 mwindow->session->drag_origin_x = cursor_x;
3508 mwindow->session->drag_origin_y = cursor_y;
3510 double position = autos->track->from_units(current->position);
3511 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3512 mwindow->edl->local_session->get_selectionend(1)) /
3517 mwindow->edl->local_session->set_selectionstart(position);
3518 mwindow->edl->local_session->set_selectionend(position);
3521 if(position < center)
3523 mwindow->edl->local_session->set_selectionstart(position);
3526 mwindow->edl->local_session->set_selectionend(position);
3533 draw_pixmap(pixmap, x, y);
3541 // so this means it is always >0 when keyframe is found
3542 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3543 int draw, int buttonpress, Plugin* &keyframe_plugin,
3544 KeyFrame* &keyframe_instance)
3557 if(!track->expand_view) return 0;
3559 calculate_viewport(track,
3571 for(int i = 0; i < track->plugin_set.total && !result; i++)
3573 PluginSet *plugin_set = track->plugin_set.values[i];
3574 int center_pixel = track->y_pixel -
3575 mwindow->edl->local_session->track_start[pane->number];
3576 if( track->show_titles() )
3577 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
3578 if( track->show_assets() )
3579 center_pixel += resource_h();
3580 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
3582 for(Plugin *plugin = (Plugin*)plugin_set->first;
3584 plugin = (Plugin*)plugin->next)
3586 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3587 keyframe && !result;
3588 keyframe = (KeyFrame*)keyframe->next)
3590 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3591 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3593 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3594 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3596 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3599 if(cursor_x >= x && cursor_y >= y &&
3600 cursor_x < x + keyframe_pixmap->get_w() &&
3601 cursor_y < y + keyframe_pixmap->get_h())
3604 keyframe_plugin = plugin;
3605 keyframe_instance = keyframe;
3609 mwindow->session->drag_auto = keyframe;
3610 mwindow->session->drag_start_position = keyframe->position;
3611 mwindow->session->drag_origin_x = cursor_x;
3612 mwindow->session->drag_origin_y = cursor_y;
3614 double position = track->from_units(keyframe->position);
3615 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3616 mwindow->edl->local_session->get_selectionend(1)) /
3621 mwindow->edl->local_session->set_selectionstart(position);
3622 mwindow->edl->local_session->set_selectionend(position);
3625 if(position < center)
3627 mwindow->edl->local_session->set_selectionstart(position);
3630 mwindow->edl->local_session->set_selectionend(position);
3635 draw_pixmap(keyframe_pixmap,
3645 // if(buttonpress && buttonpress != 3 && result)
3647 // mwindow->undo->update_undo_before();
3653 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
3655 Track *track = auto_keyframe->autos->track;
3656 int autogrouptype = auto_keyframe->autos->autogrouptype;
3659 double view_start, unit_start;
3660 double view_end, unit_end, yscale;
3661 double zoom_sample, zoom_units;
3663 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3664 yscale, center_pixel, zoom_sample, zoom_units);
3665 if( auto_keyframe->position < unit_start ||
3666 auto_keyframe->position >= unit_end )
3669 double ax = 0, ay = 0;
3670 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3671 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3674 draw_line(ax, 0, ax, get_h());
3676 char text[BCSTRLEN];
3678 if( auto_keyframe->is_floatauto() ) {
3679 FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
3680 sprintf(text, "%0.2f", float_auto->get_value());
3682 else if( auto_keyframe->is_intauto() ) {
3683 IntAuto *int_auto = (IntAuto *)auto_keyframe;
3684 sprintf(text, "%d", int_auto->value);
3690 int font = MEDIUMFONT;
3691 int tw = get_text_width(font, text) + TOOLTIP_MARGIN * 2;
3692 int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2;
3693 set_color(get_resources()->tooltip_bg_color);
3695 ay += center_pixel + HANDLE_W/2;
3696 draw_box(ax, ay, tw, th);
3698 draw_rectangle(ax, ay, tw, th);
3700 ax += TOOLTIP_MARGIN;
3701 ay += TOOLTIP_MARGIN + get_text_ascent(font);
3702 draw_text(ax, ay, text);
3707 void TrackCanvas::draw_overlays()
3709 int new_cursor, update_cursor, rerender;
3711 // Move background pixmap to foreground pixmap
3712 draw_pixmap(background_pixmap,
3721 draw_inout_points();
3732 draw_brender_range();
3734 // Highlighted areas
3735 draw_highlighting();
3738 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3741 if(pane->cursor) pane->cursor->restore(1);
3747 draw_playback_cursor();
3749 draw_keyframe_reticle();
3754 int TrackCanvas::activate()
3758 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3759 //BC_Signals::dump_stack();
3760 get_top_level()->deactivate();
3762 set_active_subwindow(this);
3763 pane->cursor->activate();
3764 gui->focused_pane = pane->number;
3769 int TrackCanvas::deactivate()
3774 pane->cursor->deactivate();
3780 void TrackCanvas::update_drag_handle()
3782 double new_position;
3783 int cursor_x = get_cursor_x();
3787 mwindow->edl->local_session->view_start[pane->number]) *
3788 mwindow->edl->local_session->zoom_sample /
3789 mwindow->edl->session->sample_rate;
3792 mwindow->edl->align_to_frame(new_position, 0);
3794 if( ctrl_down() && alt_down() ) {
3795 #define snapper(v) do { \
3797 if( pos < 0 ) break; \
3798 double dist = fabs(new_position - pos); \
3799 if( dist >= snap_min ) break; \
3800 snap_position = pos; snap_min = dist; \
3802 double snap_position = new_position;
3803 double snap_min = DBL_MAX;
3804 if( mwindow->edl->local_session->inpoint_valid() )
3805 snapper(mwindow->edl->local_session->get_inpoint());
3806 if( mwindow->edl->local_session->outpoint_valid() )
3807 snapper(mwindow->edl->local_session->get_outpoint());
3808 snapper(mwindow->edl->prev_edit(new_position));
3809 snapper(mwindow->edl->next_edit(new_position));
3810 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3811 if( prev_label ) snapper(prev_label->position);
3812 Label *next_label = mwindow->edl->labels->next_label(new_position);
3813 if( next_label ) snapper(next_label->position);
3814 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3815 mwindow->edl->local_session->zoom_sample -
3816 mwindow->edl->local_session->view_start[pane->number];
3817 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3819 new_position = snap_position;
3824 if(new_position != mwindow->session->drag_position)
3826 mwindow->session->drag_position = new_position;
3827 gui->mainclock->update(new_position);
3828 timebar_position = new_position;
3829 gui->update_timebar(0);
3832 edl->create_objects();
3833 edl->copy_all(mwindow->edl);
3834 MainSession *session = mwindow->session;
3835 int handle_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
3836 edl->modify_edithandles(session->drag_start,
3837 session->drag_position, session->drag_handle, handle_mode,
3838 edl->session->labels_follow_edits,
3839 edl->session->plugins_follow_edits,
3840 edl->session->autos_follow_edits,
3841 !session->drag_edit ? 0 : session->drag_edit->group_id);
3843 double position = -1;
3844 int show_edge = !session->drag_handle ? 1 : 2;
3845 switch( handle_mode ) {
3848 position = session->drag_handle ?
3849 session->drag_position : session->drag_start;
3850 show_edge = 3 - show_edge;
3854 position = session->drag_position;
3857 position = session->drag_start;
3858 show_edge = 3 - show_edge;
3862 if( position < 0 ) position = 0;
3863 Track *track = session->drag_handle_track();
3864 int64_t pos = track->to_units(position, 0);
3865 render_handle_frame(edl, pos, shift_down() ? 0 : show_edge);
3870 int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
3873 int64_t left = pos-1;
3874 if( left < 0 ) left = 0;
3877 VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
3878 VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
3879 TransportCommand command;
3880 command.command = CURRENT_FRAME;
3881 command.get_edl()->copy_all((EDL *)edl);
3882 command.change_type = CHANGE_ALL;
3883 command.realtime = 0;
3884 Preferences *preferences = mwindow->preferences;
3885 RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
3886 CICache *video_cache = new CICache(preferences);
3887 render_engine->set_vcache(video_cache);
3888 render_engine->arm_command(&command);
3889 VRender *vrender = render_engine->vrender;
3891 !vrender->process_buffer(&vlt, left, 0) &&
3892 !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1;
3893 delete render_engine;
3895 mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0");
3896 Canvas *canvas = mwindow->cwindow->gui->canvas;
3897 int w = canvas->w, h = canvas->h, w2 = w/2, h2 = h/2;
3898 int lx = 0, ly = h2/2, rx = w2, ry = h2/2;
3899 BC_WindowBase *window = canvas->get_canvas();
3900 window->set_color(BLACK);
3901 window->clear_box(0,0, window->get_w(),window->get_h());
3902 window->draw_vframe(&vlt, lx,ly, w2,h2, 0,0,vlt.get_w(),vlt.get_h());
3903 window->draw_vframe(&vrt, rx,ry, w2,h2, 0,0,vrt.get_w(),vrt.get_h());
3905 mwindow->cwindow->gui->unlock_window();
3909 Track *track = mwindow->session->drag_handle_track();
3910 double position = track->from_units(mode == 1 ? left : pos);
3911 if( position < 0 ) position = 0;
3912 PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine;
3913 if( playback_engine->is_playing_back )
3914 playback_engine->stop_playback(1);
3915 edl->local_session->set_selectionstart(position);
3916 edl->local_session->set_selectionend(position);
3917 mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
3923 int TrackCanvas::update_drag_edit()
3932 int TrackCanvas::get_drag_values(float *percentage,
3939 //int x = cursor_x - mwindow->session->drag_origin_x;
3940 //int y = cursor_y - mwindow->session->drag_origin_y;
3944 if(!current->autos->track->record) return 1;
3954 calculate_viewport(current->autos->track,
3964 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3966 mwindow->session->drag_start_percentage;
3967 if(do_clamp) CLAMP(*percentage, 0, 1);
3969 *position = Units::to_int64(zoom_units *
3970 (cursor_x - mwindow->session->drag_origin_x) +
3971 mwindow->session->drag_start_position + 0.5);
3973 if((do_clamp) && *position < 0) *position = 0;
3978 #define UPDATE_DRAG_HEAD(do_clamp) \
3979 int result = 0, center_pixel; \
3980 if(!current->autos->track->record) return 0; \
3981 double view_start, unit_start, view_end, unit_end; \
3982 double yscale, zoom_sample, zoom_units; \
3984 calculate_viewport(current->autos->track, \
3985 view_start, unit_start, view_end, unit_end, \
3986 yscale, center_pixel, zoom_sample, zoom_units); \
3988 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3989 yscale + mwindow->session->drag_start_percentage; \
3990 if(do_clamp) CLAMP(percentage, 0, 1); \
3992 int64_t position = Units::to_int64(zoom_units * \
3993 (cursor_x - mwindow->session->drag_origin_x) + \
3994 mwindow->session->drag_start_position); \
3995 if((do_clamp) && position < 0) position = 0;
3998 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
4000 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
4002 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
4003 int x = cursor_x - mwindow->session->drag_origin_x;
4004 int y = cursor_y - mwindow->session->drag_origin_y;
4005 float value, old_value;
4007 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
4008 // not really editing the node, rather start editing the curve
4009 // tangent is editable and drag movement is significant
4010 if( (FloatAuto::FREE == current->curve_mode ||
4011 FloatAuto::TFREE==current->curve_mode) &&
4012 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
4013 mwindow->session->drag_handle = x < 0 ? 1 : 2;
4016 switch(mwindow->session->drag_handle) {
4018 // Snap to nearby values
4019 old_value = current->get_value();
4021 double value1, value2, distance1=-1, distance2=-1;
4023 if(current->previous) {
4024 int autogrouptype = current->previous->autos->autogrouptype;
4025 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4026 value1 = ((FloatAuto*)current->previous)->get_value();
4027 distance1 = fabs(value - value1);
4028 current->set_value(value1);
4032 int autogrouptype = current->next->autos->autogrouptype;
4033 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4034 value2 = ((FloatAuto*)current->next)->get_value();
4035 distance2 = fabs(value - value2);
4036 if(!current->previous || distance2 < distance1) {
4037 current->set_value(value2);
4041 if(!current->previous && !current->next) {
4042 current->set_value( ((FloatAutos*)current->autos)->default_);
4044 value = current->get_value();
4047 int autogrouptype = current->autos->autogrouptype;
4048 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4051 if(alt_down() && !shift_down())
4052 // ALT constrains movement: fixed position, only changing the value
4053 position = mwindow->session->drag_start_position;
4055 if(value != old_value || position != current->position) {
4057 float change = value - old_value;
4058 current->adjust_to_new_coordinates(position, value);
4059 update_ganged_autos(change, current->autos->track, current);
4060 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4061 show_message(current, color, ", %.2f", current->get_value());
4067 int autogrouptype = current->autos->autogrouptype;
4068 value = percentage_to_value(percentage, 0, current, autogrouptype);
4069 if(value != current->get_control_in_value())
4072 // note: (position,value) need not be at the location of the ctrl point,
4073 // but could be somewhere in between on the curve (or even outward or
4074 // on the opposit side). We set the new control point such as
4075 // to point the curve through (position,value)
4076 current->set_control_in_value(
4077 value * levered_position(position - current->position,
4078 current->get_control_in_position()));
4079 update_ganged_autos(0, current->autos->track, current);
4080 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4081 show_message(current, color, ", %.2f", current->get_control_in_value());
4087 int autogrouptype = current->autos->autogrouptype;
4088 value = percentage_to_value(percentage, 0, current, autogrouptype);
4089 if(value != current->get_control_out_value()) {
4091 current->set_control_out_value(
4092 value * levered_position(position - current->position,
4093 current->get_control_out_position()));
4094 update_ganged_autos(0, current->autos->track, current);
4095 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4096 show_message(current, color, ", %.2f", current->get_control_out_value());
4104 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
4106 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
4108 UPDATE_DRAG_HEAD(1);
4109 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
4111 if(value != current->value || position != current->position)
4114 current->value = value;
4115 current->position = position;
4116 show_message(current, -1, ", %d", current->value);
4122 // Autos which can't change value through dragging.
4124 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
4126 Auto *current = (Auto*)mwindow->session->drag_auto;
4129 if(position != current->position)
4132 current->position = position;
4133 show_message(current, -1, "");
4135 double position_f = current->autos->track->from_units(current->position);
4136 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4137 mwindow->edl->local_session->get_selectionend(1)) /
4141 mwindow->edl->local_session->set_selectionstart(position_f);
4142 mwindow->edl->local_session->set_selectionend(position_f);
4145 if(position_f < center_f)
4147 mwindow->edl->local_session->set_selectionstart(position_f);
4150 mwindow->edl->local_session->set_selectionend(position_f);
4157 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
4159 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
4162 if(position != current->position)
4164 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
4165 Track *track = current->autos->track;
4166 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
4167 PluginSet *pluginset;
4169 // figure out the correct pluginset & correct plugin
4171 for(int i = 0; i < track->plugin_set.total; i++)
4173 pluginset = track->plugin_set.values[i];
4174 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
4176 KeyFrames *keyframes = plugin->keyframes;
4177 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
4179 currentkeyframe = (KeyFrame *) currentkeyframe->next)
4181 if (currentkeyframe == current)
4193 mwindow->session->plugin_highlighted = plugin;
4194 mwindow->session->track_highlighted = track;
4196 current->position = position;
4197 show_message(current, -1, "");
4199 double position_f = current->autos->track->from_units(current->position);
4200 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4201 mwindow->edl->local_session->get_selectionend(1)) /
4205 mwindow->edl->local_session->set_selectionstart(position_f);
4206 mwindow->edl->local_session->set_selectionend(position_f);
4209 if(position_f < center_f)
4211 mwindow->edl->local_session->set_selectionstart(position_f);
4214 mwindow->edl->local_session->set_selectionend(position_f);
4221 void TrackCanvas::update_drag_caption()
4223 switch(mwindow->session->current_operation)
4233 int TrackCanvas::cursor_update(int in_motion)
4238 int update_clock = 0;
4239 int update_zoom = 0;
4240 int update_scroll = 0;
4241 int update_overlay = 0;
4242 int update_cursor = 0;
4244 double position = 0.;
4245 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4249 arrow_mode() ? ARROW_CURSOR :
4250 ibeam_mode() ? IBEAM_CURSOR : 0;
4252 switch(mwindow->session->current_operation)
4254 case DRAG_EDITHANDLE1:
4255 // Outside threshold. Upgrade status
4258 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4260 mwindow->session->current_operation = DRAG_EDITHANDLE2;
4266 case DRAG_EDITHANDLE2:
4269 update_drag_handle();
4274 case DRAG_PLUGINHANDLE1:
4277 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4279 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
4285 case DRAG_PLUGINHANDLE2:
4288 update_drag_handle();
4293 // Rubber band curves
4301 case DRAG_PROJECTOR_X:
4302 case DRAG_PROJECTOR_Y:
4303 case DRAG_PROJECTOR_Z:
4304 if(active) rerender = update_overlay =
4305 update_drag_floatauto(get_cursor_x(), get_cursor_y());
4306 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
4307 mwindow->speed_after(!in_motion ? 1 : 0);
4311 if(active) rerender = update_overlay =
4312 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4316 if(active) rerender = update_overlay =
4317 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4320 // Keyframe icons are sticky
4324 case DRAG_PLUGINKEY_PRE:
4326 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
4327 mwindow->session->current_operation++;
4330 mwindow->undo->update_undo_before();
4338 if(active) rerender = update_overlay =
4339 update_drag_auto(get_cursor_x(), get_cursor_y());
4342 case DRAG_PLUGINKEY:
4343 if(active) rerender = update_overlay =
4344 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4349 cursor_x = get_cursor_x();
4350 cursor_y = get_cursor_y();
4351 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4352 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4354 position = mwindow->edl->align_to_frame(position, 0);
4355 position = MAX(position, 0);
4357 double start = mwindow->edl->local_session->get_selectionstart(1);
4358 double end = mwindow->edl->local_session->get_selectionend(1);
4359 if(position < selection_midpoint) {
4360 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4361 mwindow->edl->local_session->set_selectionstart(position);
4364 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4365 mwindow->edl->local_session->set_selectionend(position);
4368 gui->unlock_window();
4370 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
4371 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
4372 mwindow->cwindow->update(dir, 0, 0, 0, 1);
4373 gui->lock_window("TrackCanvas::cursor_update 1");
4374 // Update the faders
4375 mwindow->update_plugin_guis();
4376 gui->update_patchbay();
4378 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4380 gui->hide_cursor(0);
4381 gui->draw_cursor(1);
4382 gui->update_timebar(0);
4383 gui->flash_canvas(1);
4391 case DROP_TARGETING:
4392 new_cursor = GRABBED_CURSOR;
4397 if(is_event_win() && cursor_inside()) {
4399 cursor_x = get_cursor_x();
4400 position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4401 position = mwindow->edl->align_to_frame(position, 0);
4404 for(int i = 0; i < TOTAL_PANES; i++)
4405 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4407 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4408 gui->update_timebar(0);
4410 if(do_transitions(get_cursor_x(), get_cursor_y(),
4411 0, new_cursor, update_cursor)) break;
4412 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4413 0, 0, new_cursor, update_cursor, rerender)) break;
4414 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4415 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4416 // Plugin boundaries
4417 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4418 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4419 if(do_edits(get_cursor_x(), get_cursor_y(),
4420 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4425 //printf("TrackCanvas::cursor_update 1\n");
4426 if(update_cursor && new_cursor != get_cursor())
4428 set_cursor(new_cursor, 0, 1);
4431 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
4432 if(rerender && render_timer->get_difference() > 0.25 ) {
4433 render_timer->update();
4434 mwindow->restart_brender();
4435 mwindow->sync_parameters(CHANGE_PARAMS);
4436 mwindow->update_plugin_guis();
4437 gui->unlock_window();
4438 mwindow->cwindow->update(1, 0, 0, 0, 1);
4439 gui->lock_window("TrackCanvas::cursor_update 2");
4443 gui->update_patchbay();
4448 if(!mwindow->cwindow->playback_engine->is_playing_back)
4449 gui->mainclock->update(position);
4453 gui->zoombar->update();
4458 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4462 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4466 if(update_overlay) {
4467 gui->draw_overlays(1);
4470 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4474 int TrackCanvas::cursor_motion_event()
4476 return cursor_update(1);
4479 void TrackCanvas::start_dragscroll()
4483 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4484 //printf("TrackCanvas::start_dragscroll 1\n");
4488 void TrackCanvas::stop_dragscroll()
4492 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4493 //printf("TrackCanvas::stop_dragscroll 1\n");
4497 int TrackCanvas::repeat_event(int64_t duration)
4499 if(!drag_scroll) return 0;
4500 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4502 int sample_movement = 0;
4503 int track_movement = 0;
4504 int64_t x_distance = 0;
4505 int64_t y_distance = 0;
4506 double position = 0;
4509 switch(mwindow->session->current_operation) {
4511 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4512 if(get_cursor_x() > get_w()) {
4513 x_distance = get_cursor_x() - get_w();
4514 sample_movement = 1;
4516 else if(get_cursor_x() < 0) {
4517 x_distance = get_cursor_x();
4518 sample_movement = 1;
4521 if(get_cursor_y() > get_h()) {
4522 y_distance = get_cursor_y() - get_h();
4525 else if(get_cursor_y() < 0) {
4526 y_distance = get_cursor_y();
4533 if(sample_movement) {
4534 position = (double)(get_cursor_x() +
4535 mwindow->edl->local_session->view_start[pane->number] +
4537 mwindow->edl->local_session->zoom_sample /
4538 mwindow->edl->session->sample_rate;
4539 position = mwindow->edl->align_to_frame(position, 0);
4540 position = MAX(position, 0);
4542 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4543 switch(mwindow->session->current_operation) {
4545 if(position < selection_midpoint) {
4546 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4547 mwindow->edl->local_session->set_selectionstart(position);
4549 gui->unlock_window();
4550 mwindow->cwindow->update(1, 0, 0);
4551 gui->lock_window("TrackCanvas::repeat_event");
4552 // Update the faders
4553 mwindow->update_plugin_guis();
4554 gui->update_patchbay();
4557 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4558 mwindow->edl->local_session->set_selectionend(position);
4559 // Don't que the CWindow
4564 mwindow->samplemovement(
4565 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4569 if(track_movement) {
4570 mwindow->trackmovement(y_distance, pane->number);
4576 int TrackCanvas::button_release_event()
4578 int redraw = -1, update_overlay = 0;
4579 int result = 0, load_flags = 0;
4581 // printf("TrackCanvas::button_release_event %d\n",
4582 // mwindow->session->current_operation);
4584 switch(mwindow->session->current_operation) {
4585 case DRAG_EDITHANDLE2:
4586 mwindow->session->current_operation = NO_OPERATION;
4590 end_edithandle_selection();
4593 case DRAG_EDITHANDLE1:
4594 mwindow->session->current_operation = NO_OPERATION;
4599 case DRAG_PLUGINHANDLE2:
4600 mwindow->session->current_operation = NO_OPERATION;
4604 end_pluginhandle_selection();
4607 case DRAG_PLUGINHANDLE1:
4608 mwindow->session->current_operation = NO_OPERATION;
4614 redraw = FORCE_REDRAW;
4615 load_flags |= LOAD_EDITS;
4617 // delete the drag_auto_gang first and remove out of order keys
4618 clear_ganged_autos();
4629 case DRAG_PROJECTOR_X:
4630 case DRAG_PROJECTOR_Y:
4631 case DRAG_PROJECTOR_Z:
4632 case DRAG_PLUGINKEY:
4633 load_flags |= LOAD_AUTOMATION;
4634 mwindow->session->current_operation = NO_OPERATION;
4635 mwindow->session->drag_handle = 0;
4636 // Remove any out-of-order keyframe
4637 if(mwindow->session->drag_auto) {
4638 mwindow->session->drag_auto->autos->remove_nonsequential(
4639 mwindow->session->drag_auto);
4640 // mwindow->session->drag_auto->autos->optimize();
4644 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
4650 case DRAG_AEFFECT_COPY:
4651 case DRAG_VEFFECT_COPY:
4652 // Trap in drag stop
4655 case DROP_TARGETING: {
4656 int cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
4657 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4658 drag_cursor_motion(cursor_x, cursor_y,
4659 &track, &edit, &pluginset, &plugin);
4661 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4662 gui->edit_menu->activate_menu(track, edit, pluginset, plugin, position);
4663 mwindow->session->current_operation = NO_OPERATION;
4667 case GROUP_TOGGLE: {
4668 Edit *edit = mwindow->session->drag_edit;
4670 if( shift_down() && edit->is_selected ) {
4671 if( edit->group_id > 0 ) {
4672 mwindow->edl->tracks->clear_selected_edits();
4673 mwindow->edl->tracks->del_group(edit->group_id);
4676 int id = mwindow->session->group_number++;
4677 mwindow->edl->tracks->new_group(id);
4682 if( mwindow->preferences->ctrl_toggle && !ctrl_down() )
4683 mwindow->edl->tracks->clear_selected_edits();
4684 edit->set_selected(-1);
4687 mwindow->session->current_operation = NO_OPERATION;
4694 if( mwindow->session->current_operation ) {
4695 // if(mwindow->session->current_operation == SELECT_REGION) {
4696 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4699 mwindow->session->current_operation = NO_OPERATION;
4708 if( mwindow->edl->local_session->zoombar_showautocolor >= 0 )
4709 mwindow->gui->zoombar->update_autozoom(-1);
4714 if(update_overlay) {
4715 gui->draw_overlays(1);
4718 gui->draw_canvas(redraw, 0);
4719 gui->flash_canvas(1);
4724 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4725 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4727 Edit *edit_result = 0;
4728 int handle_result = -1;
4731 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4732 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4733 int64_t edit_x, edit_y, edit_w, edit_h;
4734 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4736 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4737 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4738 if( cursor_x < edit_x + HANDLE_W ) {
4741 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4742 track->show_assets() ) {
4743 new_cursor = DOWNLEFT_RESIZE;
4744 if( button_press == LEFT_BUTTON )
4750 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4753 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4754 track->show_assets() ) {
4755 new_cursor = DOWNRIGHT_RESIZE;
4756 if( button_press == LEFT_BUTTON )
4767 int group_id = edit_result->group_id;
4768 if( group_id > 0 ) {
4769 Track *track = edit_result->track;
4770 Edit *left = 0, *right = 0;
4771 double start = DBL_MAX, end = DBL_MIN;
4772 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
4773 if( edit->group_id != group_id ) continue;
4774 double edit_start = edit->track->from_units(edit->startproject);
4775 if( edit_start < start ) { start = edit_start; left = edit; }
4776 double edit_end = edit->track->from_units(edit->startproject+edit->length);
4777 if( edit_end > end ) { end = edit_end; right = edit; }
4779 Edit *edit = !handle_result ? left : right;
4780 if( edit != edit_result )
4787 double position = 0;
4788 if( handle_result == 0 ) {
4789 position = edit_result->track->from_units(edit_result->startproject);
4790 new_cursor = LEFT_CURSOR;
4792 else if( handle_result == 1 ) {
4793 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4794 new_cursor = RIGHT_CURSOR;
4797 // Reposition cursor
4798 if( button_press ) {
4799 mwindow->session->drag_edit = edit_result;
4800 mwindow->session->drag_handle = handle_result;
4801 mwindow->session->drag_button = get_buttonpress() - 1;
4802 mwindow->session->drag_position = position;
4803 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4804 mwindow->session->drag_origin_x = get_cursor_x();
4805 mwindow->session->drag_origin_y = get_cursor_y();
4806 mwindow->session->drag_start = position;
4808 rerender = start_selection(position);
4812 else if( result < 0 && !edit_result->silence() ) {
4813 mwindow->undo->update_undo_before();
4814 if( !shift_down() ) {
4815 if( handle_result == 0 )
4816 edit_result->hard_left = !edit_result->hard_left;
4817 else if( handle_result == 1 )
4818 edit_result->hard_right = !edit_result->hard_right;
4821 int status = handle_result == 0 ? edit_result->hard_left :
4822 handle_result == 1 ? edit_result->hard_right : 0;
4823 int new_status = !status;
4824 int64_t edit_edge = edit_result->startproject;
4825 if( handle_result == 1 ) edit_edge += edit_result->length;
4826 double edge_position = edit_result->track->from_units(edit_edge);
4827 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4828 int64_t track_position = track->to_units(edge_position, 1);
4829 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4831 int64_t left_edge = left_edit->startproject;
4832 double left_position = track->from_units(left_edge);
4833 if( EQUIV(edge_position, left_position) ) {
4834 left_edit->hard_left = new_status;
4835 if( left_edit->previous )
4836 left_edit->previous->hard_right = new_status;
4839 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4841 int64_t right_edge = right_edit->startproject + right_edit->length;
4842 double right_position = track->from_units(right_edge);
4843 if( EQUIV(edge_position, right_position) ) {
4844 right_edit->hard_right = new_status;
4845 if( right_edit->next )
4846 right_edit->next->hard_left = new_status;
4851 rerender = update_overlay = 1;
4852 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4859 int TrackCanvas::do_plugin_handles(int cursor_x,
4863 int &update_overlay,
4867 Plugin *plugin_result = 0;
4868 int handle_result = 0;
4871 for(Track *track = mwindow->edl->tracks->first;
4873 track = track->next) {
4874 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4875 PluginSet *plugin_set = track->plugin_set.values[i];
4876 for(Plugin *plugin = (Plugin*)plugin_set->first;
4878 plugin = (Plugin*)plugin->next) {
4879 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4880 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4882 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4883 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4884 if(cursor_x < plugin_x + HANDLE_W) {
4885 plugin_result = plugin;
4889 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4890 plugin_result = plugin;
4897 if(result && shift_down())
4898 mwindow->session->trim_edits = plugin_set;
4904 double position = 0;
4905 if(handle_result == 0) {
4906 position = plugin_result->track->from_units(plugin_result->startproject);
4907 new_cursor = LEFT_CURSOR;
4909 else if(handle_result == 1) {
4910 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4911 new_cursor = RIGHT_CURSOR;
4915 mwindow->session->drag_plugin = plugin_result;
4916 mwindow->session->drag_handle = handle_result;
4917 mwindow->session->drag_button = get_buttonpress() - 1;
4918 mwindow->session->drag_position = position;
4919 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4920 mwindow->session->drag_origin_x = get_cursor_x();
4921 mwindow->session->drag_origin_y = get_cursor_y();
4922 mwindow->session->drag_start = position;
4924 rerender = start_selection(position);
4933 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4937 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4938 drag_cursor_motion(cursor_x, cursor_y,
4939 &track, &edit, &pluginset, &plugin);
4941 if( button_press && track ) {
4942 switch( get_buttonpress() ) {
4943 case RIGHT_BUTTON: {
4945 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4946 gui->track_menu->activate_menu(track, edit, pluginset, plugin, position);
4947 mwindow->session->current_operation = NO_OPERATION;
4951 set_cursor(GRABBED_CURSOR, 0, 1);
4952 mwindow->session->current_operation = DROP_TARGETING;
4961 int TrackCanvas::arrow_mode()
4963 return mwindow->edl->session->editing_mode == EDITING_ARROW ? 1 : 0;
4965 int TrackCanvas::ibeam_mode()
4967 return mwindow->edl->session->editing_mode == EDITING_IBEAM ? 1 : 0;
4970 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4971 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4975 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4976 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4977 int64_t edit_x, edit_y, edit_w, edit_h;
4978 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4980 // Cursor inside a track
4981 // Cursor inside an edit
4982 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4983 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4984 if( button_press && get_buttonpress() == LEFT_BUTTON ) {
4985 if( get_double_click() ) {
4986 mwindow->edl->tracks->clear_selected_edits();
4987 mwindow->edl->tracks->select_affected_edits(
4988 edit->track->from_units(edit->startproject),
4990 double start = edit->track->from_units(edit->startproject);
4991 start = mwindow->edl->align_to_frame(start, 0);
4992 mwindow->edl->local_session->set_selectionstart(start);
4993 double end = edit->track->from_units(edit->startproject+edit->length);
4994 end = mwindow->edl->align_to_frame(end, 0);
4995 mwindow->edl->local_session->set_selectionend(end);
4996 result = 1; // Select edit duration or select_region
4998 else if( arrow_mode() || (ibeam_mode() && ctrl_down()) ) {
4999 mwindow->session->drag_edit = edit;
5000 mwindow->session->current_operation = GROUP_TOGGLE;
5008 else if( drag_start && track->record ) {
5009 mwindow->session->drag_edit = edit;
5010 mwindow->session->drag_origin_x = cursor_x;
5011 mwindow->session->drag_origin_y = cursor_y;
5012 // Where the drag started, so we know relative position inside the edit later
5013 mwindow->session->drag_position =
5014 mwindow->edl->get_cursor_position(cursor_x, pane->number);
5015 drag_start = 0; // if unselected "fast" drag
5016 if( !edit->silence() && !edit->is_selected ) {
5017 mwindow->edl->tracks->clear_selected_edits();
5018 if( ibeam_mode() ) {
5019 double start = edit->track->from_units(edit->startproject);
5020 mwindow->edl->local_session->set_selectionstart(start);
5021 mwindow->edl->local_session->set_selectionend(start);
5022 edit->set_selected(1);
5025 mwindow->edl->tracks->select_affected_edits(
5026 edit->track->from_units(edit->startproject),
5030 // Construct list of all affected edits
5031 if( drag_start || ibeam_mode() ) {
5032 mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits);
5033 if( mwindow->session->drag_edits->size() > 0 ) {
5034 mwindow->session->current_operation = DRAG_EDIT;
5035 // Need to create drag window
5036 int cx, cy; get_abs_cursor(cx, cy);
5037 gui->drag_popup = new BC_DragWindow(gui,
5038 mwindow->theme->get_image("clip_icon"), cx, cy);
5042 rerender = start_selection(mwindow->session->drag_position);
5043 mwindow->session->current_operation = SELECT_REGION;
5047 else if( edit->is_selected && arrow_mode() ) {
5048 if( mwindow->session->drag_group )
5049 mwindow->session->drag_group->remove_user();
5050 double start_position = 0;
5051 mwindow->session->drag_group =
5052 mwindow->edl->selected_edits_to_clip(0, &start_position,
5053 &mwindow->session->drag_group_first_track);
5054 if( mwindow->session->drag_group ) {
5055 mwindow->session->current_operation = DRAG_GROUP;
5056 mwindow->session->drag_group_position = start_position;
5057 mwindow->session->drag_group_edit = edit;
5058 mwindow->session->drag_origin_y = edit_y;
5070 int TrackCanvas::test_track_group(EDL *group, Track *first_track, double &pos)
5072 Track *src = group->tracks->first;
5073 for( Track *track=first_track; track && src; track=track->next ) {
5074 if( !track->record ) continue;
5075 if( src->data_type != track->data_type ) return -1;
5076 for( Edit *src_edit=src->edits->first; src_edit; src_edit=src_edit->next ) {
5077 if( src_edit->silence() ) continue;
5078 if( edit_intersects(track, src_edit, pos) ) return 0;
5082 return !src ? 1 : 0;
5085 int TrackCanvas::edit_intersects(Track *track, Edit *src_edit, double &pos)
5087 if( pos < 0 ) { pos = 0; return 1; }
5088 int64_t src_start = src_edit->startproject;
5089 int64_t src_end = src_start + src_edit->length;
5090 double new_start = src_edit->track->from_units(src_start) + pos;
5091 double new_end = src_edit->track->from_units(src_end) + pos;
5092 int64_t trk_start = track->to_units(new_start, 1);
5093 int64_t trk_end = track->to_units(new_end, 1);
5094 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
5095 if( edit->is_selected || edit->silence() ) continue;
5096 int64_t edit_start = edit->startproject;
5097 if( edit_start >= trk_end ) continue;
5098 int64_t edit_end = edit_start + edit->length;
5099 if( trk_start >= edit_end ) continue;
5100 int64_t lt_dist = labs(trk_end - edit_start);
5101 int64_t rt_dist = labs(edit_end - trk_start);
5103 if( lt_dist < rt_dist ) {
5104 position = edit_start;
5105 lt_dist = abs(trk_start - edit_start);
5106 rt_dist = abs(trk_end - edit_start);
5107 if( lt_dist > rt_dist )
5108 position -= src_end;
5111 position = edit_end;
5112 lt_dist = abs(trk_start - edit_end);
5113 rt_dist = abs(trk_end - edit_end);
5114 if( lt_dist > rt_dist )
5115 position -= src_end;
5117 pos = edit->track->from_units(position);
5123 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
5128 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
5129 int button_press, int &redraw, int &rerender)
5137 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
5138 if(!track->expand_view) continue;
5140 for(int i = 0; i < track->plugin_set.total && !done; i++) {
5141 // first check if plugins are visible at all
5142 if (!track->expand_view)
5144 PluginSet *plugin_set = track->plugin_set.values[i];
5145 for(plugin = (Plugin*)plugin_set->first;
5147 plugin = (Plugin*)plugin->next) {
5148 plugin_dimensions(plugin, x, y, w, h);
5149 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
5150 MWindowGUI::visible(y, y + h, 0, get_h())) {
5151 if(cursor_x >= x && cursor_x < x + w &&
5152 cursor_y >= y && cursor_y < y + h) {
5162 // Start plugin popup
5164 if(get_buttonpress() == RIGHT_BUTTON ) {
5165 gui->plugin_menu->update(plugin);
5166 gui->plugin_menu->activate_menu();
5169 else if (get_double_click() && !drag_start) {
5170 // Select range of plugin on doubleclick over plugin
5171 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
5172 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
5173 plugin->track->from_units(plugin->length));
5174 if(mwindow->edl->session->cursor_on_frames) {
5175 mwindow->edl->local_session->set_selectionstart(
5176 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
5177 mwindow->edl->local_session->set_selectionend(
5178 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
5187 if( drag_start && plugin->track->record && !plugin->silence() ) {
5188 if( mwindow->edl->session->editing_mode == EDITING_ARROW ) {
5189 if( plugin->track->data_type == TRACK_AUDIO )
5190 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
5191 else if( plugin->track->data_type == TRACK_VIDEO )
5192 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
5194 mwindow->session->drag_plugin = plugin;
5195 mwindow->session->drag_origin_x = cursor_x;
5196 mwindow->session->drag_origin_y = cursor_y;
5197 // Where the drag started, so we know relative position inside the edit later
5198 mwindow->session->drag_position =
5199 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
5200 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
5202 switch(plugin->plugin_type) {
5203 case PLUGIN_STANDALONE: {
5204 PluginServer *server =
5205 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
5206 if( !server ) break;
5207 VFrame *frame = server->picon;
5209 if(plugin->track->data_type == TRACK_AUDIO) {
5210 frame = mwindow->theme->get_image("aeffect_icon");
5213 frame = mwindow->theme->get_image("veffect_icon");
5217 get_abs_cursor(cx, cy);
5218 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
5221 case PLUGIN_SHAREDPLUGIN:
5222 case PLUGIN_SHAREDMODULE: {
5223 VFrame *frame = mwindow->theme->get_image("clip_icon");
5225 get_abs_cursor(cx, cy);
5226 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
5238 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
5239 int button_press, int &new_cursor, int &update_cursor)
5241 Transition *transition = 0;
5246 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
5247 if( !track->show_transitions() ) continue;
5249 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
5250 if( edit->transition ) {
5251 edit_dimensions(edit, x, y, w, h);
5252 get_transition_coords(edit, x, y, w, h);
5254 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
5255 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
5256 if( cursor_x >= x && cursor_x < x + w &&
5257 cursor_y >= y && cursor_y < y + h ) {
5258 transition = edit->transition;
5270 new_cursor = UPRIGHT_ARROW_CURSOR;
5272 else if(get_buttonpress() == RIGHT_BUTTON ) {
5273 gui->transition_menu->update(transition);
5274 gui->transition_menu->activate_menu();
5281 int TrackCanvas::button_press_event()
5284 int cursor_x, cursor_y;
5287 cursor_x = get_cursor_x();
5288 cursor_y = get_cursor_y();
5289 mwindow->session->trim_edits = 0;
5291 if(is_event_win() && cursor_inside()) {
5292 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5299 if( get_buttonpress() == LEFT_BUTTON ) {
5300 gui->stop_transport("TrackCanvas::button_press_event");
5303 int update_overlay = 0, update_cursor = 0, rerender = 0, update_message = 0;
5305 if(get_buttonpress() == WHEEL_UP) {
5307 mwindow->expand_sample();
5308 else if(ctrl_down())
5309 mwindow->move_left(get_w()/ 10);
5311 mwindow->move_up(get_h() / 10);
5313 else if(get_buttonpress() == WHEEL_DOWN) {
5315 mwindow->zoom_in_sample();
5316 else if(ctrl_down())
5317 mwindow->move_right(get_w() / 10);
5319 mwindow->move_down(get_h() / 10);
5321 else if(get_buttonpress() == 6) {
5323 mwindow->move_left(get_w());
5325 mwindow->move_left(get_w() / 20);
5327 mwindow->move_left(get_w() / 5);
5329 else if(get_buttonpress() == 7) {
5331 mwindow->move_right(get_w());
5333 mwindow->move_right(get_w() / 20);
5335 mwindow->move_right(get_w() / 5);
5338 if( arrow_mode() ) do {
5339 // Test handles and resource boundaries and highlight a track
5340 if( do_transitions(cursor_x, cursor_y,
5341 1, new_cursor, update_cursor) ) break;
5343 if( do_keyframes(cursor_x, cursor_y,
5344 0, get_buttonpress(), new_cursor,
5345 update_cursor, rerender) ) break;
5347 // Test edit boundaries
5348 if( do_edit_handles(cursor_x, cursor_y,
5349 1, rerender, update_overlay, new_cursor,
5350 update_cursor) ) break;
5351 // Test plugin boundaries
5352 if( do_plugin_handles(cursor_x, cursor_y,
5353 1, rerender, update_overlay, new_cursor,
5354 update_cursor) ) break;
5356 if( do_edits(cursor_x, cursor_y, 1, 0,
5357 update_overlay, rerender, new_cursor,
5358 update_cursor) ) break;
5360 if( do_plugins(cursor_x, cursor_y, 0, 1,
5361 update_cursor, rerender) ) break;
5363 if( test_resources(cursor_x, cursor_y) ) break;
5365 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5369 else if( ibeam_mode() ) do {
5370 // Test handles only and select a region
5371 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5372 //printf("TrackCanvas::button_press_event %d\n", position);
5374 if( do_transitions(cursor_x, cursor_y,
5375 1, new_cursor, update_cursor)) break;
5376 if(do_keyframes(cursor_x, cursor_y,
5377 0, get_buttonpress(), new_cursor,
5378 update_cursor, rerender)) {
5383 // Test edit boundaries
5384 if( do_edit_handles(cursor_x, cursor_y,
5385 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5386 // Test plugin boundaries
5387 if( do_plugin_handles(cursor_x, cursor_y,
5388 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5390 if( do_edits(cursor_x, cursor_y,
5391 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
5393 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
5395 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5396 // Highlight selection
5397 if( get_buttonpress() != LEFT_BUTTON ) break;
5398 rerender = start_selection(position);
5399 mwindow->session->current_operation = SELECT_REGION;
5405 gui->unlock_window();
5406 mwindow->cwindow->update(1, 0, 0, 0, 1);
5407 gui->lock_window("TrackCanvas::button_press_event 2");
5409 mwindow->update_plugin_guis();
5410 gui->update_patchbay();
5413 if( update_message )
5414 gui->default_message();
5416 if( update_overlay )
5417 gui->draw_overlays(1);
5419 if( update_cursor < 0 ) {
5420 // double_click edit
5421 gui->swindow->update_selection();
5422 gui->draw_canvas(0, 0);
5424 if( update_cursor ) {
5425 gui->update_timebar(0);
5426 gui->hide_cursor(0);
5427 gui->show_cursor(1);
5428 gui->zoombar->update();
5429 gui->flash_canvas(1);
5436 int TrackCanvas::start_selection(double position)
5439 position = mwindow->edl->align_to_frame(position, 1);
5445 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
5446 mwindow->edl->local_session->get_selectionend(1)) / 2;
5448 if(position < midpoint)
5450 mwindow->edl->local_session->set_selectionstart(position);
5451 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
5457 mwindow->edl->local_session->set_selectionend(position);
5458 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
5459 // Don't que the CWindow for the end
5463 // Start a new selection
5465 //printf("TrackCanvas::start_selection %f\n", position);
5466 mwindow->edl->local_session->set_selectionstart(position);
5467 mwindow->edl->local_session->set_selectionend(position);
5468 selection_midpoint = position;
5476 void TrackCanvas::end_edithandle_selection()
5478 mwindow->modify_edithandles();
5481 void TrackCanvas::end_pluginhandle_selection()
5483 mwindow->modify_pluginhandles();
5487 double TrackCanvas::time_visible()
5489 return (double)get_w() *
5490 mwindow->edl->local_session->zoom_sample /
5491 mwindow->edl->session->sample_rate;
5495 void TrackCanvas::show_message(Auto *current, int box_color, const char *fmt, ...)
5497 char string[BCTEXTLEN];
5498 char *cp = string, *ep = cp + sizeof(string)-1;
5499 if( box_color >= 0 ) {
5500 cp += snprintf(string, ep-cp, "%-8s ",
5501 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5503 char string2[BCTEXTLEN];
5504 Units::totext(string2,
5505 current->autos->track->from_units(current->position),
5506 mwindow->edl->session->time_format,
5507 mwindow->edl->session->sample_rate,
5508 mwindow->edl->session->frame_rate,
5509 mwindow->edl->session->frames_per_foot);
5510 cp += snprintf(cp, ep-cp, "%s", string2);
5513 vsnprintf(cp, ep-cp, fmt, ap);
5515 gui->show_message(string, -1, box_color);
5518 // Patchbay* TrackCanvas::get_patchbay()
5520 // if(pane->patchbay) return pane->patchbay;
5521 // if(gui->total_panes() == 2 &&
5522 // gui->pane[TOP_LEFT_PANE] &&
5523 // gui->pane[TOP_RIGHT_PANE])
5524 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5525 // if(gui->total_panes() == 4)
5527 // if(pane->number == TOP_RIGHT_PANE)
5528 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5530 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;