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
886 // Delete unused pixmaps
887 if(debug) PRINT_TRACE
889 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
890 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
892 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
893 delete gui->resource_pixmaps.values[i];
894 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
896 if(debug) PRINT_TRACE
898 if(hourglass_enabled)
901 hourglass_enabled = 0;
903 if(debug) PRINT_TRACE
905 // can't stop thread here, because this is called for every pane
906 // if(mode != IGNORE_THREAD && !indexes_only)
907 // gui->resource_thread->start_draw();
908 if(debug) PRINT_TRACE
913 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
919 ResourcePixmap *result = 0;
921 for(int i = 0; i < gui->resource_pixmaps.total; i++)
923 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
924 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
925 gui->resource_pixmaps.values[i]->pane_number == pane->number)
927 result = gui->resource_pixmaps.values[i];
935 result = new ResourcePixmap(mwindow,
942 gui->resource_pixmaps.append(result);
945 // result->resize(pixmap_w, pixmap_h);
949 void TrackCanvas::get_pixmap_size(Edit *edit,
957 // Align x on frame boundaries
960 // switch(edit->edits->track->data_type)
972 if(pixmap_x + pixmap_w > get_w())
974 pixmap_w = get_w() - pixmap_x;
981 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
982 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
983 // int64_t pixel_increment = MAX(picon_w, frame_w);
984 // int64_t pixmap_x1 = edit_x;
985 // int64_t pixmap_x2 = edit_x + edit_w;
989 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
994 // if(pixmap_x2 > get_w())
996 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
1000 // pixmap_x = pixmap_x1;
1001 // pixmap_w = pixmap_x2 - pixmap_x1;
1006 pixmap_h = mwindow->edl->local_session->zoom_track;
1007 Track *track = edit->edits->track;
1008 if( track->show_titles() )
1009 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
1010 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
1013 void TrackCanvas::edit_dimensions(Edit *edit,
1014 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1016 x = Units::round(edit->track->from_units(edit->startproject) *
1017 mwindow->edl->session->sample_rate /
1018 mwindow->edl->local_session->zoom_sample -
1019 mwindow->edl->local_session->view_start[pane->number]);
1021 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1023 // Method for calculating w so when edits are together we never get off by one error due to rounding
1024 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
1025 mwindow->edl->session->sample_rate /
1026 mwindow->edl->local_session->zoom_sample -
1027 mwindow->edl->local_session->view_start[pane->number]);
1031 if( edit->track->show_titles() )
1032 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
1033 if( edit->track->show_assets() )
1034 edit_h += resource_h();
1038 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1042 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1043 h = track->vertical_span(mwindow->theme);
1047 void TrackCanvas::draw_paste_destination()
1049 //int cursor_x = get_relative_cursor_x();
1050 //int cursor_y = get_relative_cursor_y();
1051 int current_atrack = 0;
1052 int current_vtrack = 0;
1053 int current_aedit = 0;
1054 int current_vedit = 0;
1060 //if(pane->number == BOTTOM_RIGHT_PANE)
1061 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1063 if((mwindow->session->current_operation == DRAG_ASSET &&
1064 (mwindow->session->drag_assets->total ||
1065 mwindow->session->drag_clips->total)) ||
1066 (mwindow->session->current_operation == DRAG_EDIT &&
1067 mwindow->session->drag_edits->total)) {
1068 Indexable *indexable = 0;
1072 if(mwindow->session->current_operation == DRAG_ASSET &&
1073 mwindow->session->drag_assets->size())
1074 indexable = mwindow->session->drag_assets->get(0);
1076 if(mwindow->session->current_operation == DRAG_ASSET &&
1077 mwindow->session->drag_clips->size())
1078 clip = mwindow->session->drag_clips->get(0);
1080 int has_audio = 0, has_video = 0;
1081 double paste_audio_length = 0, paste_video_length = 0;
1082 double paste_audio_position = -1, paste_video_position = -1;
1085 has_audio = indexable->have_audio();
1086 paste_audio_length = !has_audio ? 0 :
1087 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1088 has_video = indexable->have_video();
1089 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1090 // Images have length -1
1091 if( asset && asset->video_data && asset->video_length < 0 ) {
1092 paste_video_length = mwindow->edl->session->si_useduration ?
1093 mwindow->edl->session->si_duration / asset->frame_rate :
1094 1.0 / asset->frame_rate ; // 1 frame
1097 paste_video_length = !has_video ? 0 :
1098 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1102 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1103 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1104 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1105 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1108 // 'Align cursor on frame' lengths calculations
1109 if( mwindow->edl->session->cursor_on_frames ) {
1110 double fps = mwindow->edl->session->frame_rate;
1111 double aud = floor(paste_audio_length * fps) / fps;
1112 double vid = floor(paste_video_length * fps) / fps;
1113 double length = has_video && has_audio ?
1114 aud < vid ? aud : vid :
1116 has_audio ? aud : 0;
1117 paste_video_length = paste_audio_length = length;
1120 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1122 switch( mwindow->session->track_highlighted->data_type ) {
1123 case TRACK_VIDEO: length = paste_video_length; break;
1124 case TRACK_AUDIO: length = paste_audio_length; break;
1126 int64_t asset_length = mwindow->session->track_highlighted->
1127 to_units(length, 1);
1128 paste_audio_position = mwindow->session->track_highlighted->
1129 from_units(drop_edit_position(&insertion, NULL, asset_length));
1132 int64_t asset_length = mwindow->session->track_highlighted->
1133 to_units(paste_video_length, 1);
1134 paste_video_position = mwindow->session->track_highlighted->
1135 from_units(drop_edit_position(&insertion, NULL, asset_length));
1138 // Get destination track
1139 for(Track *dest = mwindow->session->track_highlighted;
1141 dest = dest->next) {
1143 // Get source width in pixels
1145 // Use start of highlighted edit
1146 if(mwindow->session->edit_highlighted) {
1147 position = mwindow->session->track_highlighted->from_units(
1148 mwindow->session->edit_highlighted->startproject);
1151 // Use end of highlighted track, disregarding effects
1152 position = mwindow->session->track_highlighted->from_units(
1153 mwindow->session->track_highlighted->edits->length());
1156 // Get the x coordinate
1157 x = Units::to_int64(position *
1158 mwindow->edl->session->sample_rate /
1159 mwindow->edl->local_session->zoom_sample) -
1160 mwindow->edl->local_session->view_start[pane->number];
1162 double paste_position = -1.;
1163 if(dest->data_type == TRACK_AUDIO) {
1164 if(indexable && current_atrack < indexable->get_audio_channels()) {
1165 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1166 w = Units::to_int64((double)indexable->get_audio_samples() /
1167 indexable->get_sample_rate() *
1168 mwindow->edl->session->sample_rate /
1169 mwindow->edl->local_session->zoom_sample);
1170 paste_position = paste_audio_position;
1172 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1173 w = Units::to_int64((double)clip->tracks->total_length() *
1174 mwindow->edl->session->sample_rate /
1175 mwindow->edl->local_session->zoom_sample);
1176 paste_position = paste_audio_position;
1177 //printf("draw_paste_destination %d\n", x);
1179 else if(mwindow->session->current_operation == DRAG_EDIT &&
1180 current_aedit < mwindow->session->drag_edits->total) {
1182 while(current_aedit < mwindow->session->drag_edits->total &&
1183 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1186 if(current_aedit < mwindow->session->drag_edits->total) {
1187 edit = mwindow->session->drag_edits->values[current_aedit];
1188 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1189 paste_position = mwindow->session->track_highlighted->
1190 from_units(drop_edit_position(&insertion,
1191 mwindow->session->drag_edit,
1192 mwindow->session->drag_edit->length));
1196 if( paste_position >= 0 ) {
1197 position = paste_position;
1204 else if(dest->data_type == TRACK_VIDEO) {
1205 //printf("draw_paste_destination 1\n");
1206 if(indexable && current_vtrack < indexable->get_video_layers())
1208 w = Units::to_int64((double)indexable->get_video_frames() /
1209 indexable->get_frame_rate() *
1210 mwindow->edl->session->sample_rate /
1211 mwindow->edl->local_session->zoom_sample);
1212 paste_position = paste_video_position;
1214 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1215 w = Units::to_int64(clip->tracks->total_length() *
1216 mwindow->edl->session->sample_rate /
1217 mwindow->edl->local_session->zoom_sample);
1218 paste_position = paste_video_position;
1220 else if(mwindow->session->current_operation == DRAG_EDIT &&
1221 current_vedit < mwindow->session->drag_edits->total) {
1223 while(current_vedit < mwindow->session->drag_edits->total &&
1224 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1227 if(current_vedit < mwindow->session->drag_edits->total) {
1228 edit = mwindow->session->drag_edits->values[current_vedit];
1229 w = Units::to_int64(edit->track->from_units(edit->length) *
1230 mwindow->edl->session->sample_rate /
1231 mwindow->edl->local_session->zoom_sample);
1232 paste_position = mwindow->session->track_highlighted->
1233 from_units(drop_edit_position(&insertion,
1234 mwindow->session->drag_edit,
1235 mwindow->session->drag_edit->length));
1239 if( paste_position >= 0 ) {
1240 position = paste_position;
1249 // Get the x coordinate
1250 x = Units::to_int64(position *
1251 mwindow->edl->session->sample_rate /
1252 mwindow->edl->local_session->zoom_sample) -
1253 mwindow->edl->local_session->view_start[pane->number];
1254 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1255 int h = dest->vertical_span(mwindow->theme);
1257 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1258 if(x < -BC_INFINITY) {
1259 w -= -BC_INFINITY - x;
1260 x += -BC_INFINITY - x;
1263 // if(pane->number == TOP_RIGHT_PANE)
1264 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1265 // __LINE__, x, y, w, h);
1267 draw_highlight_insertion(x, y, w, h);
1269 draw_highlight_rectangle(x, y, w, h);
1276 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1278 x = Units::round(plugin->track->from_units(plugin->startproject) *
1279 mwindow->edl->session->sample_rate /
1280 mwindow->edl->local_session->zoom_sample -
1281 mwindow->edl->local_session->view_start[pane->number]);
1282 w = Units::round(plugin->track->from_units(plugin->length) *
1283 mwindow->edl->session->sample_rate /
1284 mwindow->edl->local_session->zoom_sample);
1285 y = plugin->track->y_pixel
1286 - mwindow->edl->local_session->track_start[pane->number];
1287 if( plugin->track->show_titles() )
1288 y += mwindow->theme->get_image("title_bg_data")->get_h();
1289 if( plugin->track->show_assets() )
1291 y += plugin->plugin_set->get_number() *
1292 mwindow->theme->get_image("plugin_bg_data")->get_h();
1293 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1296 int TrackCanvas::resource_h()
1298 return mwindow->edl->local_session->zoom_track;
1301 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1304 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1305 // just draw arrows, so user has indication that something is there
1306 // FIXME: get better colors
1310 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1315 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1319 // Fix bug in heroines & cvs version as of 22.8.2005:
1320 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1321 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1334 w = MIN(w, get_w() + 20);
1335 h = MIN(h, get_h() + 20);
1338 set_color(mwindow->preferences->highlight_inverse);
1340 //draw_rectangle(x, y, w, h);
1341 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1342 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1344 draw_rectangle(x, y, w, h);
1346 //if(pane->number == TOP_RIGHT_PANE)
1347 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1350 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1353 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1354 // just draw arrows, so user has indication that something is there
1355 // FIXME: get better colors
1364 /* these don't look so good
1366 draw_line(x, y, x, y+h);
1367 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1368 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1369 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1370 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1372 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1373 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
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_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1381 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1383 // draw the box centred around x
1385 // Fix bug in heroines & cvs version as of 22.8.2005:
1386 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1387 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1398 w = MIN(w, get_w() + 20);
1399 h = MIN(h, get_h() + 20);
1400 set_color(mwindow->preferences->highlight_inverse);
1402 draw_rectangle(x, y, w, h);
1403 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1405 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1408 void TrackCanvas::draw_playback_cursor()
1410 // Called before playback_cursor exists
1411 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1413 // mwindow->playback_cursor->visible = 0;
1414 // mwindow->playback_cursor->draw();
1418 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1420 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1421 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1423 edit_dimensions(edit, x, y, w, h);
1425 if( edit->track->show_titles() )
1426 y += mwindow->theme->get_image("title_bg_data")->get_h();
1428 if(side == EDIT_OUT)
1435 void TrackCanvas::get_transition_coords(Edit *edit,
1436 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1438 int transition_w = 30, transition_h = 30;
1439 int has_titles = edit->track->show_titles();
1440 int has_assets = edit->track->show_assets();
1441 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
1442 double asset_h = resource_h();
1443 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
1444 double dy = has_titles ?
1445 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) :
1446 ( has_assets ? asset_h/2 : 0) ;
1447 double title_h = mwindow->theme->title_h;
1448 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
1451 x -= transition_w / 2;
1452 y -= transition_h / 2;
1457 void TrackCanvas::draw_highlighting()
1462 switch(mwindow->session->current_operation)
1464 case DRAG_ATRANSITION:
1465 case DRAG_VTRANSITION:
1466 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1467 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1468 if(mwindow->session->edit_highlighted) {
1469 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1470 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1471 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1472 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1473 edit_dimensions(mwindow->session->edit_highlighted,
1475 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1476 MWindowGUI::visible(y, y + h, 0, get_h())) {
1478 get_transition_coords(mwindow->session->edit_highlighted,
1485 // Dragging a new effect from the Resource window
1488 if(mwindow->session->track_highlighted &&
1489 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1490 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1491 (mwindow->session->current_operation == DRAG_VEFFECT &&
1492 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1493 // Put it before another plugin
1494 if(mwindow->session->plugin_highlighted) {
1495 plugin_dimensions(mwindow->session->plugin_highlighted,
1497 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1499 // Put it after a plugin set
1500 else if( mwindow->session->pluginset_highlighted &&
1501 mwindow->session->pluginset_highlighted->last ) {
1502 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1504 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1505 int64_t track_x, track_y, track_w, track_h;
1506 track_dimensions(mwindow->session->track_highlighted,
1507 track_x, track_y, track_w, track_h);
1511 mwindow->session->track_highlighted->get_length() *
1512 mwindow->edl->session->sample_rate /
1513 mwindow->edl->local_session->zoom_sample -
1514 mwindow->edl->local_session->view_start[pane->number]) -
1516 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1517 if(w <= 0) w = track_w;
1520 track_dimensions(mwindow->session->track_highlighted,
1523 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1524 // Put it in a new plugin set determined by the selected range
1525 if(mwindow->edl->local_session->get_selectionend() >
1526 mwindow->edl->local_session->get_selectionstart()) {
1527 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1528 mwindow->edl->session->sample_rate /
1529 mwindow->edl->local_session->zoom_sample -
1530 mwindow->edl->local_session->view_start[pane->number]);
1531 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1532 mwindow->edl->local_session->get_selectionstart()) *
1533 mwindow->edl->session->sample_rate /
1534 mwindow->edl->local_session->zoom_sample);
1536 // Put it in a new plugin set determined by an edit boundary
1537 else if(mwindow->session->edit_highlighted) {
1538 int64_t temp_y, temp_h;
1539 edit_dimensions(mwindow->session->edit_highlighted,
1540 x, temp_y, w, temp_h);
1542 // Put it at the beginning of the track in a new plugin set
1545 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1546 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1547 //printf("TrackCanvas::draw_highlighting 1\n");
1554 if(mwindow->session->track_highlighted) {
1555 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1557 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1559 draw_paste_destination();
1565 if(mwindow->session->track_highlighted) {
1566 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1568 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1569 draw_paste_destination();
1574 if( mwindow->session->track_highlighted && mwindow->session->drag_group &&
1575 mwindow->session->drag_group_edit && mwindow->session->drag_group_first_track ) {
1576 Track *track = mwindow->session->track_highlighted;
1577 EDL *drag_group = mwindow->session->drag_group;
1578 Track *edit_track = mwindow->session->drag_group_edit->track;
1579 Track *drag_track = mwindow->session->drag_group_first_track;
1580 while( track && edit_track && edit_track != drag_track ) {
1581 edit_track = edit_track->previous;
1582 track = track->previous;
1584 int cx = get_cursor_x();
1585 double cur_pos = mwindow->session->drag_group_position;
1586 double new_pos = mwindow->edl->get_cursor_position(cx, pane->number);
1587 new_pos -= mwindow->session->drag_position - cur_pos;
1588 new_pos = mwindow->edl->align_to_frame(new_pos, 0);
1589 double drop_position = new_pos;
1591 int ret = test_track_group(drag_group, track, new_pos);
1595 if( new_pos != drop_position ) {
1596 double pos = new_pos;
1597 pos += mwindow->session->drag_position - cur_pos;
1598 cx = mwindow->edl->get_position_cursorx(pos, pane->number);
1599 ret = test_track_group(drag_group, track, new_pos);
1601 color = ret > 0 ? YELLOW : shift_down() ? RED : BLUE;
1603 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1604 int dx = cx - mwindow->session->drag_origin_x;
1605 int dy = y - mwindow->session->drag_origin_y;
1606 draw_selected_edits(mwindow->edl, dx, dy, color, -1);
1609 // Dragging an effect from the timeline
1610 case DRAG_AEFFECT_COPY:
1611 case DRAG_VEFFECT_COPY:
1612 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1613 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1614 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1615 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1616 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1618 int64_t plugin_position = -1;
1619 Plugin *drag_plugin = mwindow->session->drag_plugin;
1620 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1621 Track *hi_track = mwindow->session->track_highlighted;
1622 Edit *hi_edit = mwindow->session->edit_highlighted;
1623 // Put it into a silence zone
1624 if( hi_plugin_set && hi_plugin_set->last &&
1625 hi_plugin_set->track == drag_plugin->track ) {
1626 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1627 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1628 hi_track = drag_plugin->track;
1630 else if( hi_track ) {
1631 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1632 track_dimensions(hi_track, x, y, w, h);
1633 plugin_position = hi_edit ? hi_edit->startproject : 0;
1636 if( plugin_position < 0 ) break;
1638 // Calculate length of plugin based on data type of track and units
1639 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1640 mwindow->edl->local_session->zoom_sample;
1641 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1642 mwindow->edl->local_session->view_start[pane->number];
1643 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1645 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1646 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1652 case DRAG_PLUGINKEY:
1653 if(mwindow->session->plugin_highlighted &&
1654 mwindow->session->current_operation == DRAG_PLUGINKEY)
1656 // Just highlight the plugin
1657 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1659 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1660 MWindowGUI::visible(y, y + h, 0, get_h()))
1670 draw_highlight_rectangle(x, y, w, h);
1672 draw_selected_edits(mwindow->edl, 0, 0, GREEN+BLUE, RED);
1675 // x does not reliably draw a really big rectangle
1676 void TrackCanvas::draw_selected(int x, int y, int w, int h)
1678 int x1 = bmax(x, 0), x2 = bmin(x+w, get_w());
1679 if( x1 > x2 ) return;
1680 int y1 = bmax(y, 0), y2 = bmin(y+h, get_h());
1681 if( y1 > y2 ) return;
1682 if( x >= 0 && x < get_w() ) draw_line(x,y1, x,y2);
1683 if( x+w >= 0 && x+w < get_w() ) draw_line(x+w,y1, x+w,y2);
1684 if( y >= 0 && y < get_h() ) draw_line(x1,y, x2,y);
1685 if( y+h >= 0 && y+h < get_h() ) draw_line(x1,y+h, x2,y+h);
1688 void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1)
1690 for( Track *track=edl->tracks->first; track; track=track->next ) {
1691 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1692 if( !edit->is_selected ) continue;
1694 edit_dimensions(edit, x, y, w, h);
1696 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue;
1697 if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
1699 int inner = color1 < 0 ? color0 : !edit->group_id ? color0 :
1700 mwindow->get_group_color(edit->group_id);
1702 draw_selected(x, y, w, h);
1703 int outer = color1 < 0 ? color0 : !edit->group_id ? color1 : inner;
1705 draw_selected(x-1, y-1, w+2, h+2);
1706 draw_selected(x-2, y-2, w+1, h+1);
1711 void TrackCanvas::draw_plugins()
1713 char string[BCTEXTLEN];
1715 int current_show = 0;
1716 int current_preset = 0;
1718 for(int i = 0; i < plugin_on_toggles.total; i++)
1719 plugin_on_toggles.values[i]->in_use = 0;
1720 for(int i = 0; i < plugin_show_toggles.total; i++)
1721 plugin_show_toggles.values[i]->in_use = 0;
1722 for(int i = 0; i < preset_edit_buttons.total; i++)
1723 plugin_show_toggles.values[i]->in_use = 0;
1726 for(Track *track = mwindow->edl->tracks->first;
1728 track = track->next)
1730 if(track->expand_view)
1732 for(int i = 0; i < track->plugin_set.total; i++)
1734 PluginSet *pluginset = track->plugin_set.values[i];
1736 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1738 int64_t total_x, y, total_w, h;
1739 plugin_dimensions(plugin, total_x, y, total_w, h);
1741 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1742 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1743 plugin->plugin_type != PLUGIN_NONE)
1745 int x = total_x, w = total_w, left_margin = 5;
1746 int right_margin = 5;
1752 if(w + x > get_w()) w -= (w + x) - get_w();
1759 mwindow->theme->get_image("plugin_bg_data"),
1761 set_color(mwindow->theme->title_color);
1762 set_font(mwindow->theme->title_font);
1763 plugin->calculate_title(string, 0);
1765 // Truncate string to int64_test visible in background
1766 int len = strlen(string), j;
1767 for(j = len; j >= 0; j--)
1769 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1777 // Justify the text on the left boundary of the edit if it is visible.
1778 // Otherwise justify it on the left side of the screen.
1779 int64_t text_x = total_x + left_margin;
1780 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1781 text_x = MAX(left_margin, text_x);
1783 y + get_text_ascent(mwindow->theme->title_font) + 2,
1787 int64_t min_x = total_x + text_w;
1790 // Update plugin toggles
1791 int toggle_x = total_x + total_w;
1793 toggle_x = MIN(get_w() - right_margin, toggle_x);
1796 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1797 if(toggle_x > min_x)
1799 if(current_on >= plugin_on_toggles.total)
1801 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1802 add_subwindow(plugin_on);
1803 plugin_on_toggles.append(plugin_on);
1807 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1812 // Toggles for standalone plugins only
1813 if(plugin->plugin_type == PLUGIN_STANDALONE)
1816 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1817 if(toggle_x > min_x)
1819 if(current_show >= plugin_show_toggles.total)
1821 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1822 add_subwindow(plugin_show);
1823 plugin_show_toggles.append(plugin_show);
1827 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1831 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1832 if(toggle_x > min_x)
1834 if(current_preset >= preset_edit_buttons.total)
1836 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1837 add_subwindow(preset_edit);
1838 preset_edit_buttons.append(preset_edit);
1842 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1853 // Remove unused toggles
1855 while(current_preset < preset_edit_buttons.total)
1857 preset_edit_buttons.remove_object_number(current_preset);
1859 while(current_show < plugin_show_toggles.total)
1861 plugin_show_toggles.remove_object_number(current_show);
1864 while(current_on < plugin_on_toggles.total)
1866 plugin_on_toggles.remove_object_number(current_on);
1870 void TrackCanvas::refresh_plugintoggles()
1872 for(int i = 0; i < plugin_on_toggles.total; i++)
1874 PluginOn *on = plugin_on_toggles.values[i];
1875 on->reposition_window(on->get_x(), on->get_y());
1877 for(int i = 0; i < plugin_show_toggles.total; i++)
1879 PluginShow *show = plugin_show_toggles.values[i];
1880 show->reposition_window(show->get_x(), show->get_y());
1882 for(int i = 0; i < preset_edit_buttons.total; i++)
1884 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1885 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1889 void TrackCanvas::draw_hard_edges()
1893 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1894 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1895 if( !edit->hard_left && !edit->hard_right ) continue;
1896 edit_dimensions(edit, x, y, w, h);
1900 if( track->show_titles() )
1901 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
1902 if( track->show_assets() )
1905 y1 += mwindow->theme->title_h;
1906 if( edit->hard_left ) {
1907 ArrayList<int> xpt, ypt;
1908 xpt.append(x); ypt.append(y1);
1909 xpt.append(x+HANDLE_W); ypt.append(y1);
1910 xpt.append(x); ypt.append(y1-HANDLE_H);
1911 fill_polygon(&xpt, &ypt);
1913 if( edit->hard_right ) {
1914 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1915 xpt.append(x1); ypt.append(y1);
1916 xpt.append(x1-HANDLE_W); ypt.append(y1);
1917 xpt.append(x1); ypt.append(y1-HANDLE_H);
1918 fill_polygon(&xpt, &ypt);
1924 void TrackCanvas::draw_inout_points()
1929 void TrackCanvas::draw_drag_handle()
1931 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 &&
1932 mwindow->session->current_operation != DRAG_PLUGINHANDLE2 ) return;
1933 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1934 mwindow->edl->session->sample_rate /
1935 mwindow->edl->local_session->zoom_sample -
1936 mwindow->edl->local_session->view_start[pane->number]);
1937 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1939 draw_line(pixel1, 0, pixel1, get_h());
1942 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 ) return;
1943 if( !mwindow->session->drag_edit ) return;
1944 int group_id = mwindow->session->drag_edit->group_id;
1945 if( !group_id ) return;
1946 int64_t dx, dy, dw, dh;
1947 edit_dimensions(mwindow->session->drag_edit, dx, dy, dw, dh);
1948 int drag_handle = mwindow->session->drag_handle;
1949 int64_t pixel0 = !drag_handle ? dx : dx + dw;
1950 int delta = pixel1 - pixel0;
1951 set_color(LTPURPLE);
1954 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
1955 Edit *left = 0, *right = 0;
1956 double start = DBL_MAX, end = DBL_MIN;
1957 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1958 if( edit->group_id != group_id ) continue;
1959 double edit_start = edit->track->from_units(edit->startproject);
1960 if( edit_start < start ) { start = edit_start; left = edit; }
1961 double edit_end = edit->track->from_units(edit->startproject+edit->length);
1962 if( edit_end > end ) { end = edit_end; right = edit; }
1964 Edit *edit = !drag_handle ? left : right;
1965 if( !edit ) continue;
1966 Indexable *idxbl = edit->asset;
1967 if( !idxbl ) idxbl = edit->nested_edl;
1968 int can_drag = idxbl ? 1 : 0;
1970 int64_t source_len = !idxbl ? -1 :
1971 edit->track->data_type == TRACK_AUDIO ?
1972 idxbl->get_audio_samples() :
1973 edit->track->data_type == TRACK_VIDEO ?
1974 idxbl->get_video_frames() : -1;
1975 if( edit->startsource + edit->length >= source_len )
1978 else if( !edit->startsource )
1981 edit_dimensions(edit, x, y, w, h);
1982 if( y+h < 0 || y >= get_h() ) continue;
1983 int edge_x = !drag_handle ? x : x + w;
1984 int edge_y = y + h/2, k = 10;
1985 if( edge_x >= 0 && edge_x < get_w() ) {
1987 draw_line(edge_x-k,edge_y-k, edge_x+k,edge_y+k);
1988 draw_line(edge_x-k,edge_y+k, edge_x+k,edge_y-k);
1990 else if( !drag_handle ) {
1991 draw_line(edge_x+k,edge_y-k, edge_x,edge_y);
1992 draw_line(edge_x+k,edge_y+k, edge_x,edge_y);
1995 draw_line(edge_x,edge_y, edge_x-k,edge_y-k);
1996 draw_line(edge_x,edge_y, edge_x-k,edge_y+k);
2000 if( edge_x >= 0 && edge_x < get_w() ) {
2001 draw_line(edge_x, y, edge_x, y+h);
2008 void TrackCanvas::draw_transitions()
2012 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
2013 if( !track->show_transitions() ) continue;
2015 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
2016 if(!edit->transition) continue;
2017 edit_dimensions(edit, x, y, w, h);
2018 int strip_x = x, edit_y = y;
2019 get_transition_coords(edit, x, y, w, h);
2020 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
2021 if( track->show_assets() && track->show_titles() )
2022 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
2023 if( strip_y < edit_y ) strip_y = edit_y;
2025 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
2026 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
2027 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
2028 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
2029 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
2031 if( !server ) continue;
2032 VFrame *picon = server->get_picon();
2033 if( !picon ) continue;
2034 int picon_w = picon->get_w(), picon_h = picon->get_h();
2035 int track_h = edit->track->vertical_span(mwindow->theme);
2036 if( picon_h > track_h ) picon_h = track_h;
2037 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
2039 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
2040 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
2041 int x = strip_x, w = strip_w;
2042 if( x < 0 ) { w -= -x; x = 0; }
2043 if( w + x > get_w() ) w -= (w + x) - get_w();
2045 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
2046 mwindow->theme->get_image("plugin_bg_data"), 0);
2052 void TrackCanvas::draw_loop_points()
2054 //printf("TrackCanvas::draw_loop_points 1\n");
2055 if(mwindow->edl->local_session->loop_playback)
2057 //printf("TrackCanvas::draw_loop_points 2\n");
2058 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
2059 mwindow->edl->session->sample_rate /
2060 mwindow->edl->local_session->zoom_sample -
2061 mwindow->edl->local_session->view_start[pane->number]);
2062 //printf("TrackCanvas::draw_loop_points 3\n");
2064 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2067 draw_line(x, 0, x, get_h());
2069 //printf("TrackCanvas::draw_loop_points 4\n");
2071 x = Units::round(mwindow->edl->local_session->loop_end *
2072 mwindow->edl->session->sample_rate /
2073 mwindow->edl->local_session->zoom_sample -
2074 mwindow->edl->local_session->view_start[pane->number]);
2075 //printf("TrackCanvas::draw_loop_points 5\n");
2077 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2080 draw_line(x, 0, x, get_h());
2082 //printf("TrackCanvas::draw_loop_points 6\n");
2084 //printf("TrackCanvas::draw_loop_points 7\n");
2087 void TrackCanvas::draw_brender_range()
2089 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
2090 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
2091 if( mwindow->edl->session->brender_end > 0 )
2093 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
2094 mwindow->edl->session->sample_rate /
2095 mwindow->edl->local_session->zoom_sample -
2096 mwindow->edl->local_session->view_start[pane->number]);
2097 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
2100 draw_line(x1, 0, x1, get_h());
2102 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
2103 mwindow->edl->session->sample_rate /
2104 mwindow->edl->local_session->zoom_sample -
2105 mwindow->edl->local_session->view_start[pane->number]);
2107 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
2110 draw_line(x2, 0, x2, get_h());
2115 // The operations which correspond to each automation type
2116 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
2132 // The buttonpress operations, so nothing changes unless the mouse moves
2133 // a certain amount. This allows the keyframe to be used to position the
2134 // insertion point without moving itself.
2135 static int pre_auto_operations[AUTOMATION_TOTAL] =
2152 int TrackCanvas::do_keyframes(int cursor_x,
2160 // Note: button 3 (right mouse button) is not eaten to allow
2161 // track context menu to appear
2163 EDLSession *session = mwindow->edl->session;
2167 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
2169 0, 0, 0, 0, 0, 0, 0, 0,
2171 modekeyframe_pixmap,
2172 maskkeyframe_pixmap,
2177 for(Track *track = mwindow->edl->tracks->first;
2179 track = track->next) {
2180 Auto *auto_keyframe = 0;
2181 Automation *automation = track->automation;
2184 // Handle keyframes in reverse drawing order if a button press
2186 int end = AUTOMATION_TOTAL;
2190 start = AUTOMATION_TOTAL - 1;
2194 for(int i = start; i != end && !result; i += step)
2196 // Event not trapped and automation visible
2197 Autos *autos = automation->autos[i];
2198 if(!result && session->auto_conf->autos[i] && autos) {
2200 case AUTOMATION_MODE:
2201 case AUTOMATION_PAN:
2202 case AUTOMATION_MASK:
2203 result = do_autos(track, automation->autos[i],
2204 cursor_x, cursor_y, draw,
2205 buttonpress, auto_pixmaps[i],
2206 auto_keyframe, rerender);
2210 switch(autos->get_type()) {
2211 case Autos::AUTOMATION_TYPE_FLOAT: {
2212 Automation automation(0, track);
2213 int grouptype = automation.autogrouptype(i, track);
2214 if( buttonpress && i == AUTOMATION_SPEED ) {
2215 mwindow->speed_before();
2218 if(draw) // Do dropshadow
2219 result = do_float_autos(track, autos,
2220 cursor_x, cursor_y, draw,
2221 buttonpress, 1, 1, MDGREY,
2222 auto_keyframe, grouptype);
2223 result = do_float_autos(track, autos,
2224 cursor_x, cursor_y, draw, buttonpress,
2225 0, 0, GWindowGUI::auto_colors[i],
2226 auto_keyframe, grouptype);
2228 if( !result && buttonpress && i == AUTOMATION_SPEED )
2229 mwindow->speed_after(-1);
2230 if( result && buttonpress ) {
2231 int color = GWindowGUI::auto_colors[i];
2232 mwindow->gui->zoombar->update_autozoom(grouptype, color);
2236 case Autos::AUTOMATION_TYPE_INT: {
2237 if(draw) // Do dropshadow
2238 result = do_int_autos(track, autos,
2239 cursor_x, cursor_y, draw,
2240 buttonpress, 1, 1, MDGREY,
2242 result = do_int_autos(track, autos,
2243 cursor_x, cursor_y, draw, buttonpress,
2244 0, 0, GWindowGUI::auto_colors[i],
2253 if(mwindow->session->current_operation == auto_operations[i])
2256 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2258 // mwindow->session->current_operation,
2259 // auto_operations[i]);
2262 if (buttonpress == 2 && auto_keyframe )
2264 double position = track->from_units(auto_keyframe->position);
2265 mwindow->edl->local_session->set_selectionstart(position);
2266 mwindow->edl->local_session->set_selectionend(position);
2268 if (buttonpress != 3)
2270 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2271 fill_ganged_autos(get_double_click(), 0, track,
2272 (FloatAuto*)mwindow->session->drag_auto);
2273 mwindow->session->current_operation = pre_auto_operations[i];
2274 update_drag_caption();
2277 else if( auto_keyframe )
2279 gui->keyframe_menu->update(automation,
2282 gui->keyframe_menu->activate_menu();
2283 rerender = 1; // the position changes
2287 gui->keyframe_hide->update(autos);
2288 gui->keyframe_hide->activate_menu();
2289 rerender = 1; // the position changes
2291 if(buttonpress == 1 && ctrl_down() &&
2292 AUTOMATION_TYPE_FLOAT == autos->get_type())
2293 rerender = 1; // special case: curve mode changed
2299 if(!result && session->auto_conf->plugins) {
2302 result = do_plugin_autos(track, cursor_x, cursor_y,
2303 draw, buttonpress, plugin, keyframe);
2304 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2307 if(result && (buttonpress == 1)) {
2308 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2309 update_drag_caption();
2312 else if (result && (buttonpress == 3)) {
2313 gui->keyframe_menu->update(plugin, keyframe);
2314 gui->keyframe_menu->activate_menu();
2315 rerender = 1; // the position changes
2320 // Final pass to trap event
2321 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2322 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2323 mwindow->session->current_operation == auto_operations[i]) {
2329 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2330 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2336 new_cursor = UPRIGHT_ARROW_CURSOR;
2342 void TrackCanvas::draw_keyframe_reticle()
2344 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2345 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2347 int current_op = mwindow->session->current_operation, dragging = 0;
2348 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2349 if( current_op == auto_operations[i] ) dragging = 1;
2350 if( dragging && !mwindow->session->drag_auto ) dragging = 0;
2352 int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
2353 mwindow->session->drag_auto->autos->autoidx : -1;
2355 if( get_buttonpress() == LEFT_BUTTON && dragging &&
2356 keyframe_hairline == HAIRLINE_DRAGGING ) {
2357 draw_hairline(mwindow->session->drag_auto, RED, 1);
2361 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == MIDDLE_BUTTON &&
2362 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2363 int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
2364 for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
2365 Automation *automation = track->automation;
2366 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2367 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2368 // automation visible
2369 Autos *autos = automation->autos[i];
2370 if( !autos ) continue;
2371 if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
2372 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2373 auto_keyframe = auto_keyframe->next ) {
2374 draw_hairline(auto_keyframe, BLUE, show);
2380 draw_hairline(mwindow->session->drag_auto, RED, 1);
2384 void TrackCanvas::draw_auto(Auto *current,
2392 x1 = x - HANDLE_W / 2;
2393 x2 = x + HANDLE_W / 2;
2394 y1 = center_pixel + y - HANDLE_W / 2;
2395 y2 = center_pixel + y + HANDLE_W / 2;
2397 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2398 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2400 draw_box(x1, y1, x2 - x1, y2 - y1);
2404 // This draws lines for bezier in & out controls
2405 void TrackCanvas::draw_cropped_line(int x1,
2414 // Don't care about x since it is clipped by the window.
2415 // Put y coords in ascending order
2417 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2418 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2423 double slope = (double)(x2 - x1) / (y2 - y1);
2424 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2426 x1 = (int)(x1 + (min_y - y1) * slope);
2429 else if(y1 >= max_y) {
2430 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2435 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2438 else if(y2 < min_y) {
2439 x2 = (int)(x2 + (min_y - y2) * slope);
2444 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2445 if( y1 >= min_y && y1 < max_y &&
2446 y2 >= min_y && y2 < max_y )
2447 draw_line(x1, y1, x2, y2);
2451 void TrackCanvas::draw_floatauto(FloatAuto *current,
2462 int x1 = x - HANDLE_W / 2; // Center
2463 int x2 = x + HANDLE_W / 2;
2464 int y1 = center_pixel + y - HANDLE_H / 2;
2465 int y2 = center_pixel + y + HANDLE_H / 2;
2466 int ymin = center_pixel - zoom_track / 2;
2467 int ymax = center_pixel + zoom_track / 2;
2468 CLAMP(y1, ymin, ymax);
2469 CLAMP(y2, ymin, ymax);
2474 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2476 draw_box(x1, y1, x2 - x1, y2 - y1);
2479 // show bezier control points (only) if this
2480 // floatauto doesn't adjust it's tangents automatically
2481 if(current->curve_mode != FloatAuto::FREE &&
2482 current->curve_mode != FloatAuto::TFREE)
2486 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2488 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2491 inline int quantize(float f) { return (int)floor(f + 0.5); }
2493 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2494 int x, int y, int cp_x, int cp_y, int center_pixel,
2495 int zoom_track, int color)
2496 // draw the tangent and a handle for given bézier ctrl point
2498 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2500 float slope = (float)(cp_y - y)/(cp_x - x);
2501 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2503 cp_x = x + quantize((cp_y - y) / slope);
2506 cp_y += center_pixel;
2508 // drawing the tangent as a dashed line...
2509 int const dash = HANDLE_W;
2510 int const gap = HANDLE_W / 2;
2511 float sx = 3 * (cp_x - x) / 4.;
2514 // q is the x displacement for a unit line of slope
2515 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2517 float dist = 1/q * sx;
2523 float sy = slope * sx, ey = slope * ex;
2524 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2531 int r = HANDLE_W / 2;
2532 int cp_x1 = cp_x - r;
2533 int cp_y1 = cp_y - r;
2535 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2537 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2542 int TrackCanvas::test_auto(Auto *current,
2543 int x, int y, int center_pixel, int zoom_track,
2544 int cursor_x, int cursor_y, int buttonpress)
2549 x1 = x - HANDLE_W / 2;
2550 x2 = x + HANDLE_W / 2;
2551 y1 = center_pixel + y - HANDLE_H / 2;
2552 y2 = center_pixel + y + HANDLE_H / 2;
2553 int ymin = center_pixel - zoom_track / 2;
2554 int ymax = center_pixel + zoom_track / 2;
2555 CLAMP(y1, ymin, ymax);
2556 CLAMP(y2, ymin, ymax);
2558 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2560 if(buttonpress && buttonpress != 3)
2562 mwindow->session->drag_auto = current;
2563 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2564 // Toggle Autos don't respond to vertical zoom, they always show up
2565 // with "on" == 100% == line on top
2566 mwindow->session->drag_start_position = current->position;
2567 mwindow->session->drag_origin_x = cursor_x;
2568 mwindow->session->drag_origin_y = cursor_y;
2573 if(buttonpress && buttonpress != 3 && result)
2575 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2576 mwindow->undo->update_undo_before();
2582 // some Helpers for test_floatauto(..)
2583 // and for dragging the tangents/ctrl points
2584 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2585 float cursor_x, float cursor_y)
2587 // Control point switched off?
2588 if( x0 == ctrl_x ) return 0.0;
2589 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2590 double x = cursor_x-x0, y = cursor_y-y0;
2591 // wrong side of ctrl handle
2592 if( x*x1 < 0 ) return 0.0;
2593 // outside handle radius
2594 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2595 double xx1 = x1*x1, yy1 = y1*y1;
2596 double xx = x*x, yy = y*y;
2597 // distance squared from cursor to cursor projected to line from ctrl to handle
2598 // along a line perpendicular to line from ctrl to handle (closest approach)
2599 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2600 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2601 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2606 float levered_position(float position, float ref_pos)
2608 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2610 return ref_pos / position;
2614 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2615 // transforms automation value into current display coords,
2616 // dependant on current automation display range for the given kind of automation
2618 if(!mwindow || !mwindow->edl) return 0;
2619 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2620 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2621 float automation_range = automation_max - automation_min;
2622 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2624 return (auto_value - automation_min) / automation_range;
2629 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2630 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2631 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2635 int x1 = x - HANDLE_W / 2;
2636 int x2 = x + HANDLE_W / 2;
2637 int y1 = center_pixel + y - HANDLE_W / 2;
2638 int y2 = center_pixel + y + HANDLE_W / 2;
2639 int ymin = center_pixel - zoom_track / 2;
2640 int ymax = center_pixel + zoom_track / 2;
2641 CLAMP(y1, ymin, ymax);
2642 CLAMP(y2, ymin, ymax);
2644 int in_x1 = in_x - HANDLE_W / 2;
2645 int in_x2 = in_x + HANDLE_W / 2;
2646 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2647 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2648 CLAMP(in_y1, ymin, ymax);
2649 CLAMP(in_y2, ymin, ymax);
2651 int out_x1 = out_x - HANDLE_W / 2;
2652 int out_x2 = out_x + HANDLE_W / 2;
2653 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2654 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2655 CLAMP(out_y1, ymin, ymax);
2656 CLAMP(out_y2, ymin, ymax);
2659 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2660 // buttonpress could be the start of a drag operation
2661 #define INIT_DRAG(POS,VAL) \
2662 mwindow->session->drag_auto = current; \
2663 mwindow->session->drag_origin_x = cursor_x; \
2664 mwindow->session->drag_origin_y = cursor_y; \
2665 mwindow->session->drag_start_position = (POS); \
2666 mwindow->session->drag_start_percentage = (VAL);
2668 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2671 // without modifier we are manipulating the automation node
2672 // with ALT it's about dragging only the value of the node
2673 // with SHIFT the value snaps to the value of neighbouring nodes
2674 // CTRL indicates we are rather manipulating the tangent(s) of the node
2678 if( WITHIN(x1,x2,y1,y2))
2679 { // cursor hits node
2682 if(buttonpress && (buttonpress != 3))
2684 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2685 mwindow->session->drag_handle = 0;
2690 if( WITHIN(x1,x2,y1,y2))
2693 if(buttonpress && (buttonpress != 3))
2695 // could be ctrl-click or ctrl-drag
2696 // click would cycle through tangent modes
2697 ((FloatAuto*)current)->toggle_curve_mode();
2699 // drag will start dragging the tangent, if applicable
2700 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2701 mwindow->session->drag_handle = 0;
2705 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2708 if( in_x != x && current->position > 0 &&
2709 (FloatAuto::FREE == current->curve_mode ||
2710 FloatAuto::TFREE == current->curve_mode))
2711 // act on in control handle only if
2712 // tangent is significant and is editable (not automatically choosen)
2714 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2715 // either cursor in ctrl-point handle or cursor on tangent line
2716 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2718 if(buttonpress && (buttonpress != 3)) {
2719 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2721 mwindow->session->drag_handle = 1;
2722 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2723 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2724 value_to_percentage(new_invalue, autogrouptype))
2731 (FloatAuto::FREE == current->curve_mode ||
2732 FloatAuto::TFREE == current->curve_mode))
2733 // act on out control only if tangent is significant and is editable
2735 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2736 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2738 if(buttonpress && (buttonpress != 3)) {
2739 if(lever == 0.0) lever=1.0;
2741 mwindow->session->drag_handle = 2;
2742 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2743 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2744 value_to_percentage(new_outvalue, autogrouptype))
2748 } // end ctrl_down()
2754 // 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",
2755 // mwindow->session->drag_handle,
2760 if(buttonpress && (buttonpress != 3) && result)
2762 mwindow->undo->update_undo_before();
2769 // Get the float value & y for position x on the canvas
2770 #define X_TO_FLOATLINE(x) \
2771 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2772 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2773 /* Call by reference fails for some reason here */ \
2774 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2775 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2776 double position = unit_start + x * zoom_units; \
2778 if(position2 > position1) \
2781 (value2 - value1) * \
2782 (position - position1) / \
2783 (position2 - position1); \
2789 AUTOMATIONCLAMPS(value, autogrouptype); \
2790 int y = center_pixel + \
2791 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2794 void TrackCanvas::draw_floatline(int center_pixel,
2795 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2796 double unit_start, double zoom_units, double yscale,
2797 int x1, int y1, int x2, int y2,
2798 int color, int autogrouptype)
2800 // Solve bezier equation for either every pixel or a certain large number of
2803 // Not using slope intercept
2805 int prev_y = y1 + center_pixel;
2808 // Call by reference fails for some reason here
2809 FloatAuto *previous1 = previous, *next1 = next;
2810 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2811 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2812 float automation_range = automation_max - automation_min;
2814 for(int x = x1; x < x2; x++)
2816 // Interpolate value between frames
2820 y >= center_pixel - yscale / 2 &&
2821 y < center_pixel + yscale / 2 - 1)
2823 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2825 // (int)(center_pixel - yscale / 2),
2826 // (int)(center_pixel + yscale / 2 - 1));
2828 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2829 draw_line(x - 1, prev_y , x, y );
2839 int TrackCanvas::test_floatline(int center_pixel,
2854 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2855 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2856 float automation_range = automation_max - automation_min;
2857 FloatAuto *previous1 = 0, *next1 = 0;
2858 X_TO_FLOATLINE(cursor_x);
2860 if(cursor_x >= x1 &&
2862 cursor_y >= y - HANDLE_W / 2 &&
2863 cursor_y < y + HANDLE_W / 2 &&
2869 if(buttonpress == 3)
2877 mwindow->undo->update_undo_before();
2878 double position = autos->track->from_units(position1);
2879 position = mwindow->edl->align_to_frame(position, 0);
2880 int64_t new_position = autos->track->to_units(position,0);
2881 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2882 ((FloatAuto*)current)->set_value(value);
2883 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2884 mwindow->session->drag_start_position = current->position;
2885 mwindow->session->drag_origin_x = cursor_x;
2886 mwindow->session->drag_origin_y = cursor_y;
2887 mwindow->session->drag_handle = 0;
2896 void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto)
2898 if( !skip->gang ) return;
2899 // Handles the special case of modifying a fadeauto
2900 // when there are ganged faders on several tracks
2901 double position = skip->from_units(fauto->position);
2902 int autoidx = fauto->autos->autoidx;
2904 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2905 if( (all || current->data_type == skip->data_type) &&
2906 current->gang && current->record && current != skip ) {
2907 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2908 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2909 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2910 int64_t current_position = current->to_units(position, 1);
2911 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
2913 // keyframe exists, just change it
2914 float value = keyframe->get_value();
2915 float new_value = value + change;
2916 CLAMP(new_value, auto_min, auto_max);
2917 keyframe->adjust_to_new_coordinates(current_position, new_value);
2920 // create keyframe on neighbouring track at the point in time given by fauto
2921 FloatAuto *previous = 0, *next = 0;
2922 float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2923 float new_value = value + change;
2924 CLAMP(new_value, auto_min, auto_max);
2925 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2926 keyframe->set_value(new_value);
2928 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2933 void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
2935 double position = skip->from_units(fauto->position);
2937 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2938 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2939 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2940 float new_value = keyframe->get_value() + change;
2942 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2943 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2944 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2948 void TrackCanvas::clear_ganged_autos()
2951 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2952 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2953 keyframe->autos->remove_nonsequential(keyframe);
2955 mwindow->session->drag_auto_gang->remove_all();
2959 void TrackCanvas::draw_toggleline(int center_pixel,
2965 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2969 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2973 int TrackCanvas::test_toggleline(Autos *autos,
2984 if(cursor_x >= x1 && cursor_x < x2)
2986 int miny = center_pixel + y1 - HANDLE_W / 2;
2987 int maxy = center_pixel + y1 + HANDLE_W / 2;
2988 if(cursor_y >= miny && cursor_y < maxy)
2993 if(buttonpress == 3)
3001 double position = (double)(cursor_x +
3002 mwindow->edl->local_session->view_start[pane->number]) *
3003 mwindow->edl->local_session->zoom_sample /
3004 mwindow->edl->session->sample_rate;
3005 int64_t unit_position = autos->track->to_units(position, 0);
3006 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
3008 mwindow->undo->update_undo_before();
3010 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
3011 ((IntAuto*)current)->value = new_value;
3012 // Toggle Autos don't respond to vertical zoom, they always show up
3013 // with "on" == 100% == line on top
3014 mwindow->session->drag_start_percentage = (float)new_value;
3015 mwindow->session->drag_start_position = current->position;
3016 mwindow->session->drag_origin_x = cursor_x;
3017 mwindow->session->drag_origin_y = cursor_y;
3025 void TrackCanvas::calculate_viewport(Track *track,
3026 double &view_start, // Seconds
3028 double &view_end, // Seconds
3032 double &zoom_sample,
3036 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
3037 mwindow->edl->local_session->zoom_sample /
3038 mwindow->edl->session->sample_rate;
3039 unit_start = track->to_doubleunits(view_start);
3040 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
3042 mwindow->edl->local_session->zoom_sample /
3043 mwindow->edl->session->sample_rate;
3044 unit_end = track->to_doubleunits(view_end);
3046 int y = track->y_pixel
3047 - mwindow->edl->local_session->track_start[pane->number];
3048 int has_titles = track->show_titles();
3049 int has_assets = track->show_assets();
3050 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
3051 double asset_h = resource_h();
3052 double title_h = mwindow->theme->title_h;
3053 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
3054 double dy = has_titles ?
3055 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) :
3056 ( has_assets ? asset_h/2 : 0) ;
3057 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
3059 center_pixel = y + dy;
3061 zoom_sample = mwindow->edl->local_session->zoom_sample;
3062 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
3065 float TrackCanvas::percentage_to_value(float percentage,
3073 if(percentage > 0.5)
3080 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3081 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3082 float automation_range = automation_max - automation_min;
3084 result = percentage * automation_range + automation_min;
3087 FloatAuto *ptr = (FloatAuto*)reference;
3088 result -= ptr->get_value();
3090 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
3096 void TrackCanvas::calculate_auto_position(double *x, double *y,
3097 double *in_x, double *in_y, double *out_x, double *out_y,
3098 Auto *current, double unit_start, double zoom_units, double yscale,
3101 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3102 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3103 float automation_range = automation_max - automation_min;
3104 FloatAuto *ptr = (FloatAuto*)current;
3105 *x = (double)(ptr->position - unit_start) / zoom_units;
3106 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
3109 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
3110 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
3114 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
3115 automation_min) / automation_range - 0.5) * -yscale;
3119 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
3120 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
3124 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
3125 automation_min) / automation_range - 0.5) * -yscale;
3130 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
3131 int draw, int buttonpress, int x_offset, int y_offset, int color,
3132 Auto* &auto_instance, int autogrouptype)
3135 int center_pixel, draw_auto;
3136 double view_start, unit_start;
3137 double view_end, unit_end, yscale;
3138 double zoom_sample, zoom_units;
3139 double in_x2, in_y2, out_x2, out_y2;
3145 if(draw) set_color(color);
3147 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3148 yscale, center_pixel, zoom_sample, zoom_units);
3150 // Get first auto before start
3151 Auto *current = 0, *previous = 0;
3153 for( current = autos->last;
3154 current && current->position >= unit_start;
3155 current = PREVIOUS ) ;
3157 Auto *first_auto = current ? current :
3158 autos->first ? autos->first : autos->default_auto;
3160 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
3162 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3163 first_auto, unit_start, zoom_units, yscale, autogrouptype);
3168 current = autos->first;
3177 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
3178 current, unit_start, zoom_units, yscale, autogrouptype);
3186 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3191 ay2 = ay + slope * (get_w() - ax);
3195 ay = ay + slope * (0 - ax);
3199 // Draw or test handle
3200 if( current && !result && current != autos->default_auto ) {
3201 if( !draw && track->record ) {
3202 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3203 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3204 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3205 buttonpress, autogrouptype);
3207 auto_instance = current;
3209 if( draw && draw_auto ) {
3210 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3211 (int)in_x2 + x_offset, (int)in_y2,
3212 (int)out_x2 + x_offset, (int)out_y2,
3213 (int)center_pixel + y_offset, (int)yscale, color);
3217 // Draw or test joining line
3218 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3219 result = test_floatline(center_pixel,
3220 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3221 // Exclude auto coverage from the end of the line. The auto overlaps
3222 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3223 buttonpress, autogrouptype);
3226 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3227 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3228 (int)ax, (int)ay, (int)ax2, (int)ay2,
3229 color, autogrouptype);
3237 } while( current && current->position <= unit_end && !result );
3239 if( ax < get_w() && !result ) {
3240 ax2 = get_w(); ay2 = ay;
3241 if(!draw && track->record /* && buttonpress != 3 */ ) {
3242 result = test_floatline(center_pixel,
3243 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3244 (int)ax, (int)ax2, cursor_x, cursor_y,
3245 buttonpress, autogrouptype);
3248 draw_floatline(center_pixel,
3249 (FloatAuto*)previous, (FloatAuto*)current,
3250 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3251 (int)ax, (int)ay, (int)ax2, (int)ay2,
3252 color, autogrouptype);
3259 int TrackCanvas::do_int_autos(Track *track,
3268 Auto *&auto_instance)
3279 double ax, ay, ax2, ay2;
3283 if(draw) set_color(color);
3285 calculate_viewport(track,
3296 double high = -yscale * 0.8 / 2;
3297 double low = yscale * 0.8 / 2;
3299 // Get first auto before start
3301 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3307 ay = ((IntAuto*)current)->value > 0 ? high : low;
3312 current = autos->first ? autos->first : autos->default_auto;
3316 ay = ((IntAuto*)current)->value > 0 ? high : low;
3329 ax2 = (double)(current->position - unit_start) / zoom_units;
3330 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3338 if(ax2 > get_w()) ax2 = get_w();
3340 if(current && !result)
3342 if(current != autos->default_auto)
3348 result = test_auto(current,
3357 auto_instance = current;
3362 (int)ax2 + x_offset,
3363 (int)ay2 + y_offset,
3375 if(track->record /* && buttonpress != 3 */)
3377 result = test_toggleline(autos,
3390 draw_toggleline(center_pixel + y_offset,
3398 }while(current && current->position <= unit_end && !result);
3400 if(ax < get_w() && !result)
3406 if(track->record /* && buttonpress != 3 */)
3408 result = test_toggleline(autos,
3420 draw_toggleline(center_pixel + y_offset,
3429 int TrackCanvas::do_autos(Track *track,
3436 Auto * &auto_instance,
3450 calculate_viewport(track,
3463 for(current = autos->first; current && !result; current = NEXT)
3465 if(current->position >= unit_start && current->position < unit_end)
3468 x = (int64_t)((double)(current->position - unit_start) /
3469 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3470 y = center_pixel - pixmap->get_h() / 2;
3474 if(cursor_x >= x && cursor_y >= y &&
3475 cursor_x < x + pixmap->get_w() &&
3476 cursor_y < y + pixmap->get_h())
3479 auto_instance = current;
3481 if(buttonpress && (buttonpress != 3))
3483 mwindow->session->drag_auto = current;
3484 mwindow->session->drag_start_position = current->position;
3485 mwindow->session->drag_origin_x = cursor_x;
3486 mwindow->session->drag_origin_y = cursor_y;
3488 double position = autos->track->from_units(current->position);
3489 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3490 mwindow->edl->local_session->get_selectionend(1)) /
3495 mwindow->edl->local_session->set_selectionstart(position);
3496 mwindow->edl->local_session->set_selectionend(position);
3499 if(position < center)
3501 mwindow->edl->local_session->set_selectionstart(position);
3504 mwindow->edl->local_session->set_selectionend(position);
3511 draw_pixmap(pixmap, x, y);
3519 // so this means it is always >0 when keyframe is found
3520 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3521 int draw, int buttonpress, Plugin* &keyframe_plugin,
3522 KeyFrame* &keyframe_instance)
3535 if(!track->expand_view) return 0;
3537 calculate_viewport(track,
3549 for(int i = 0; i < track->plugin_set.total && !result; i++)
3551 PluginSet *plugin_set = track->plugin_set.values[i];
3552 int center_pixel = track->y_pixel -
3553 mwindow->edl->local_session->track_start[pane->number];
3554 if( track->show_titles() )
3555 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
3556 if( track->show_assets() )
3557 center_pixel += resource_h();
3558 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
3560 for(Plugin *plugin = (Plugin*)plugin_set->first;
3562 plugin = (Plugin*)plugin->next)
3564 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3565 keyframe && !result;
3566 keyframe = (KeyFrame*)keyframe->next)
3568 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3569 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3571 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3572 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3574 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3577 if(cursor_x >= x && cursor_y >= y &&
3578 cursor_x < x + keyframe_pixmap->get_w() &&
3579 cursor_y < y + keyframe_pixmap->get_h())
3582 keyframe_plugin = plugin;
3583 keyframe_instance = keyframe;
3587 mwindow->session->drag_auto = keyframe;
3588 mwindow->session->drag_start_position = keyframe->position;
3589 mwindow->session->drag_origin_x = cursor_x;
3590 mwindow->session->drag_origin_y = cursor_y;
3592 double position = track->from_units(keyframe->position);
3593 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3594 mwindow->edl->local_session->get_selectionend(1)) /
3599 mwindow->edl->local_session->set_selectionstart(position);
3600 mwindow->edl->local_session->set_selectionend(position);
3603 if(position < center)
3605 mwindow->edl->local_session->set_selectionstart(position);
3608 mwindow->edl->local_session->set_selectionend(position);
3613 draw_pixmap(keyframe_pixmap,
3623 // if(buttonpress && buttonpress != 3 && result)
3625 // mwindow->undo->update_undo_before();
3631 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
3633 Track *track = auto_keyframe->autos->track;
3634 int autogrouptype = auto_keyframe->autos->autogrouptype;
3637 double view_start, unit_start;
3638 double view_end, unit_end, yscale;
3639 double zoom_sample, zoom_units;
3641 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3642 yscale, center_pixel, zoom_sample, zoom_units);
3643 if( auto_keyframe->position < unit_start ||
3644 auto_keyframe->position >= unit_end )
3647 double ax = 0, ay = 0;
3648 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3649 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3652 draw_line(ax, 0, ax, get_h());
3655 char text[BCSTRLEN];
3656 if( auto_keyframe->is_floatauto() ) {
3657 FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
3658 sprintf(text, "%0.2f", float_auto->get_value());
3661 IntAuto *int_auto = (IntAuto *)auto_keyframe;
3662 sprintf(text, "%d", int_auto->value);
3664 int font = MEDIUMFONT;
3665 int tw = get_text_width(font, text) + TOOLTIP_MARGIN * 2;
3666 int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2;
3667 set_color(get_resources()->tooltip_bg_color);
3669 ay += center_pixel + HANDLE_W/2;
3670 draw_box(ax, ay, tw, th);
3672 draw_rectangle(ax, ay, tw, th);
3674 ax += TOOLTIP_MARGIN;
3675 ay += TOOLTIP_MARGIN + get_text_ascent(font);
3676 draw_text(ax, ay, text);
3681 void TrackCanvas::draw_overlays()
3683 int new_cursor, update_cursor, rerender;
3685 // Move background pixmap to foreground pixmap
3686 draw_pixmap(background_pixmap,
3695 draw_inout_points();
3706 draw_brender_range();
3708 // Highlighted areas
3709 draw_highlighting();
3712 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3715 if(pane->cursor) pane->cursor->restore(1);
3721 draw_playback_cursor();
3723 draw_keyframe_reticle();
3728 int TrackCanvas::activate()
3732 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3733 //BC_Signals::dump_stack();
3734 get_top_level()->deactivate();
3736 set_active_subwindow(this);
3737 pane->cursor->activate();
3738 gui->focused_pane = pane->number;
3743 int TrackCanvas::deactivate()
3748 pane->cursor->deactivate();
3754 void TrackCanvas::update_drag_handle()
3756 double new_position;
3757 int cursor_x = get_cursor_x();
3761 mwindow->edl->local_session->view_start[pane->number]) *
3762 mwindow->edl->local_session->zoom_sample /
3763 mwindow->edl->session->sample_rate;
3766 mwindow->edl->align_to_frame(new_position, 0);
3768 if( ctrl_down() && alt_down() ) {
3769 #define snapper(v) do { \
3771 if( pos < 0 ) break; \
3772 double dist = fabs(new_position - pos); \
3773 if( dist >= snap_min ) break; \
3774 snap_position = pos; snap_min = dist; \
3776 double snap_position = new_position;
3777 double snap_min = DBL_MAX;
3778 if( mwindow->edl->local_session->inpoint_valid() )
3779 snapper(mwindow->edl->local_session->get_inpoint());
3780 if( mwindow->edl->local_session->outpoint_valid() )
3781 snapper(mwindow->edl->local_session->get_outpoint());
3782 snapper(mwindow->edl->prev_edit(new_position));
3783 snapper(mwindow->edl->next_edit(new_position));
3784 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3785 if( prev_label ) snapper(prev_label->position);
3786 Label *next_label = mwindow->edl->labels->next_label(new_position);
3787 if( next_label ) snapper(next_label->position);
3788 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3789 mwindow->edl->local_session->zoom_sample -
3790 mwindow->edl->local_session->view_start[pane->number];
3791 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3793 new_position = snap_position;
3798 if(new_position != mwindow->session->drag_position)
3800 mwindow->session->drag_position = new_position;
3801 gui->mainclock->update(new_position);
3802 timebar_position = new_position;
3803 gui->update_timebar(0);
3806 edl->create_objects();
3807 edl->copy_all(mwindow->edl);
3808 MainSession *session = mwindow->session;
3809 int handle_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
3810 edl->modify_edithandles(session->drag_start,
3811 session->drag_position, session->drag_handle, handle_mode,
3812 edl->session->labels_follow_edits,
3813 edl->session->plugins_follow_edits,
3814 edl->session->autos_follow_edits,
3815 !session->drag_edit ? 0 : session->drag_edit->group_id);
3817 double position = -1;
3818 int show_edge = !session->drag_handle ? 1 : 2;
3819 switch( handle_mode ) {
3822 position = session->drag_handle ?
3823 session->drag_position : session->drag_start;
3824 show_edge = 3 - show_edge;
3828 position = session->drag_position;
3831 position = session->drag_start;
3832 show_edge = 3 - show_edge;
3836 if( position < 0 ) position = 0;
3837 Track *track = session->drag_handle_track();
3838 int64_t pos = track->to_units(position, 0);
3839 render_handle_frame(edl, pos, shift_down() ? 0 : show_edge);
3844 int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
3847 int64_t left = pos-1;
3848 if( left < 0 ) left = 0;
3851 VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
3852 VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
3853 TransportCommand command;
3854 command.command = CURRENT_FRAME;
3855 command.get_edl()->copy_all((EDL *)edl);
3856 command.change_type = CHANGE_ALL;
3857 command.realtime = 0;
3858 Preferences *preferences = mwindow->preferences;
3859 RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
3860 CICache *video_cache = new CICache(preferences);
3861 render_engine->set_vcache(video_cache);
3862 render_engine->arm_command(&command);
3863 VRender *vrender = render_engine->vrender;
3865 !vrender->process_buffer(&vlt, left, 0) &&
3866 !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1;
3867 delete render_engine;
3869 mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0");
3870 Canvas *canvas = mwindow->cwindow->gui->canvas;
3871 canvas->lock_canvas("TrackCanvas::render_handle_frame 1");
3872 int w = canvas->w, h = canvas->h, w2 = w/2, h2 = h/2;
3873 int lx = 0, ly = h2/2, rx = w2, ry = h2/2;
3874 BC_WindowBase *window = canvas->get_canvas();
3875 window->set_color(BLACK);
3876 window->clear_box(0,0, window->get_w(),window->get_h());
3877 window->draw_vframe(&vlt, lx,ly, w2,h2, 0,0,vlt.get_w(),vlt.get_h());
3878 window->draw_vframe(&vrt, rx,ry, w2,h2, 0,0,vrt.get_w(),vrt.get_h());
3880 canvas->unlock_canvas();
3881 mwindow->cwindow->gui->unlock_window();
3885 Track *track = mwindow->session->drag_handle_track();
3886 double position = track->from_units(mode == 1 ? left : pos);
3887 if( position < 0 ) position = 0;
3888 PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine;
3889 if( playback_engine->is_playing_back )
3890 playback_engine->stop_playback(1);
3891 edl->local_session->set_selectionstart(position);
3892 edl->local_session->set_selectionend(position);
3893 mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
3899 int TrackCanvas::update_drag_edit()
3908 int TrackCanvas::get_drag_values(float *percentage,
3915 //int x = cursor_x - mwindow->session->drag_origin_x;
3916 //int y = cursor_y - mwindow->session->drag_origin_y;
3920 if(!current->autos->track->record) return 1;
3930 calculate_viewport(current->autos->track,
3940 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3942 mwindow->session->drag_start_percentage;
3943 if(do_clamp) CLAMP(*percentage, 0, 1);
3945 *position = Units::to_int64(zoom_units *
3946 (cursor_x - mwindow->session->drag_origin_x) +
3947 mwindow->session->drag_start_position + 0.5);
3949 if((do_clamp) && *position < 0) *position = 0;
3954 #define UPDATE_DRAG_HEAD(do_clamp) \
3955 int result = 0, center_pixel; \
3956 if(!current->autos->track->record) return 0; \
3957 double view_start, unit_start, view_end, unit_end; \
3958 double yscale, zoom_sample, zoom_units; \
3960 calculate_viewport(current->autos->track, \
3961 view_start, unit_start, view_end, unit_end, \
3962 yscale, center_pixel, zoom_sample, zoom_units); \
3964 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3965 yscale + mwindow->session->drag_start_percentage; \
3966 if(do_clamp) CLAMP(percentage, 0, 1); \
3968 int64_t position = Units::to_int64(zoom_units * \
3969 (cursor_x - mwindow->session->drag_origin_x) + \
3970 mwindow->session->drag_start_position); \
3971 if((do_clamp) && position < 0) position = 0;
3974 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3976 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3978 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3979 int x = cursor_x - mwindow->session->drag_origin_x;
3980 int y = cursor_y - mwindow->session->drag_origin_y;
3981 float value, old_value;
3983 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3984 // not really editing the node, rather start editing the curve
3985 // tangent is editable and drag movement is significant
3986 if( (FloatAuto::FREE == current->curve_mode ||
3987 FloatAuto::TFREE==current->curve_mode) &&
3988 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3989 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3992 switch(mwindow->session->drag_handle) {
3994 // Snap to nearby values
3995 old_value = current->get_value();
3997 double value1, value2, distance1=-1, distance2=-1;
3999 if(current->previous) {
4000 int autogrouptype = current->previous->autos->autogrouptype;
4001 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4002 value1 = ((FloatAuto*)current->previous)->get_value();
4003 distance1 = fabs(value - value1);
4004 current->set_value(value1);
4008 int autogrouptype = current->next->autos->autogrouptype;
4009 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4010 value2 = ((FloatAuto*)current->next)->get_value();
4011 distance2 = fabs(value - value2);
4012 if(!current->previous || distance2 < distance1) {
4013 current->set_value(value2);
4017 if(!current->previous && !current->next) {
4018 current->set_value( ((FloatAutos*)current->autos)->default_);
4020 value = current->get_value();
4023 int autogrouptype = current->autos->autogrouptype;
4024 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4027 if(alt_down() && !shift_down())
4028 // ALT constrains movement: fixed position, only changing the value
4029 position = mwindow->session->drag_start_position;
4031 if(value != old_value || position != current->position) {
4033 float change = value - old_value;
4034 current->adjust_to_new_coordinates(position, value);
4035 update_ganged_autos(change, current->autos->track, current);
4036 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4037 show_message(current, color, ", %.2f", current->get_value());
4043 int autogrouptype = current->autos->autogrouptype;
4044 value = percentage_to_value(percentage, 0, current, autogrouptype);
4045 if(value != current->get_control_in_value())
4048 // note: (position,value) need not be at the location of the ctrl point,
4049 // but could be somewhere in between on the curve (or even outward or
4050 // on the opposit side). We set the new control point such as
4051 // to point the curve through (position,value)
4052 current->set_control_in_value(
4053 value * levered_position(position - current->position,
4054 current->get_control_in_position()));
4055 update_ganged_autos(0, current->autos->track, current);
4056 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4057 show_message(current, color, ", %.2f", current->get_control_in_value());
4063 int autogrouptype = current->autos->autogrouptype;
4064 value = percentage_to_value(percentage, 0, current, autogrouptype);
4065 if(value != current->get_control_out_value()) {
4067 current->set_control_out_value(
4068 value * levered_position(position - current->position,
4069 current->get_control_out_position()));
4070 update_ganged_autos(0, current->autos->track, current);
4071 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4072 show_message(current, color, ", %.2f", current->get_control_out_value());
4080 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
4082 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
4084 UPDATE_DRAG_HEAD(1);
4085 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
4087 if(value != current->value || position != current->position)
4090 current->value = value;
4091 current->position = position;
4092 show_message(current, -1, ", %d", current->value);
4098 // Autos which can't change value through dragging.
4100 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
4102 Auto *current = (Auto*)mwindow->session->drag_auto;
4105 if(position != current->position)
4108 current->position = position;
4109 show_message(current, -1, "");
4111 double position_f = current->autos->track->from_units(current->position);
4112 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4113 mwindow->edl->local_session->get_selectionend(1)) /
4117 mwindow->edl->local_session->set_selectionstart(position_f);
4118 mwindow->edl->local_session->set_selectionend(position_f);
4121 if(position_f < center_f)
4123 mwindow->edl->local_session->set_selectionstart(position_f);
4126 mwindow->edl->local_session->set_selectionend(position_f);
4133 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
4135 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
4138 if(position != current->position)
4140 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
4141 Track *track = current->autos->track;
4142 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
4143 PluginSet *pluginset;
4145 // figure out the correct pluginset & correct plugin
4147 for(int i = 0; i < track->plugin_set.total; i++)
4149 pluginset = track->plugin_set.values[i];
4150 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
4152 KeyFrames *keyframes = plugin->keyframes;
4153 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
4155 currentkeyframe = (KeyFrame *) currentkeyframe->next)
4157 if (currentkeyframe == current)
4169 mwindow->session->plugin_highlighted = plugin;
4170 mwindow->session->track_highlighted = track;
4172 current->position = position;
4173 show_message(current, -1, "");
4175 double position_f = current->autos->track->from_units(current->position);
4176 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4177 mwindow->edl->local_session->get_selectionend(1)) /
4181 mwindow->edl->local_session->set_selectionstart(position_f);
4182 mwindow->edl->local_session->set_selectionend(position_f);
4185 if(position_f < center_f)
4187 mwindow->edl->local_session->set_selectionstart(position_f);
4190 mwindow->edl->local_session->set_selectionend(position_f);
4197 void TrackCanvas::update_drag_caption()
4199 switch(mwindow->session->current_operation)
4209 int TrackCanvas::cursor_update(int in_motion)
4214 int update_clock = 0;
4215 int update_zoom = 0;
4216 int update_scroll = 0;
4217 int update_overlay = 0;
4218 int update_cursor = 0;
4220 double position = 0.;
4221 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4225 arrow_mode() ? ARROW_CURSOR :
4226 ibeam_mode() ? IBEAM_CURSOR : 0;
4228 switch(mwindow->session->current_operation)
4230 case DRAG_EDITHANDLE1:
4231 // Outside threshold. Upgrade status
4234 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4236 mwindow->session->current_operation = DRAG_EDITHANDLE2;
4242 case DRAG_EDITHANDLE2:
4245 update_drag_handle();
4250 case DRAG_PLUGINHANDLE1:
4253 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4255 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
4261 case DRAG_PLUGINHANDLE2:
4264 update_drag_handle();
4269 // Rubber band curves
4277 case DRAG_PROJECTOR_X:
4278 case DRAG_PROJECTOR_Y:
4279 case DRAG_PROJECTOR_Z:
4280 if(active) rerender = update_overlay =
4281 update_drag_floatauto(get_cursor_x(), get_cursor_y());
4282 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
4283 mwindow->speed_after(!in_motion ? 1 : 0);
4287 if(active) rerender = update_overlay =
4288 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4292 if(active) rerender = update_overlay =
4293 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4296 // Keyframe icons are sticky
4300 case DRAG_PLUGINKEY_PRE:
4302 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
4303 mwindow->session->current_operation++;
4306 mwindow->undo->update_undo_before();
4314 if(active) rerender = update_overlay =
4315 update_drag_auto(get_cursor_x(), get_cursor_y());
4318 case DRAG_PLUGINKEY:
4319 if(active) rerender = update_overlay =
4320 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4325 cursor_x = get_cursor_x();
4326 cursor_y = get_cursor_y();
4327 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4328 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4330 position = mwindow->edl->align_to_frame(position, 0);
4331 position = MAX(position, 0);
4333 double start = mwindow->edl->local_session->get_selectionstart(1);
4334 double end = mwindow->edl->local_session->get_selectionend(1);
4335 if(position < selection_midpoint) {
4336 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4337 mwindow->edl->local_session->set_selectionstart(position);
4340 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4341 mwindow->edl->local_session->set_selectionend(position);
4344 gui->unlock_window();
4346 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
4347 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
4348 mwindow->cwindow->update(dir, 0, 0, 0, 1);
4349 gui->lock_window("TrackCanvas::cursor_update 1");
4350 // Update the faders
4351 mwindow->update_plugin_guis();
4352 gui->update_patchbay();
4354 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4356 gui->hide_cursor(0);
4357 gui->draw_cursor(1);
4358 gui->update_timebar(0);
4359 gui->flash_canvas(1);
4367 case DROP_TARGETING:
4368 new_cursor = GRABBED_CURSOR;
4373 if(is_event_win() && cursor_inside()) {
4375 cursor_x = get_cursor_x();
4376 position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4377 position = mwindow->edl->align_to_frame(position, 0);
4380 for(int i = 0; i < TOTAL_PANES; i++)
4381 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4383 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4384 gui->update_timebar(0);
4386 if(do_transitions(get_cursor_x(), get_cursor_y(),
4387 0, new_cursor, update_cursor)) break;
4388 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4389 0, 0, new_cursor, update_cursor, rerender)) break;
4390 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4391 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4392 // Plugin boundaries
4393 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4394 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4395 if(do_edits(get_cursor_x(), get_cursor_y(),
4396 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4401 //printf("TrackCanvas::cursor_update 1\n");
4402 if(update_cursor && new_cursor != get_cursor())
4404 set_cursor(new_cursor, 0, 1);
4407 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
4408 if(rerender && render_timer->get_difference() > 0.25 ) {
4409 render_timer->update();
4410 mwindow->restart_brender();
4411 mwindow->sync_parameters(CHANGE_PARAMS);
4412 mwindow->update_plugin_guis();
4413 gui->unlock_window();
4414 mwindow->cwindow->update(1, 0, 0, 0, 1);
4415 gui->lock_window("TrackCanvas::cursor_update 2");
4419 gui->update_patchbay();
4424 if(!mwindow->cwindow->playback_engine->is_playing_back)
4425 gui->mainclock->update(position);
4429 gui->zoombar->update();
4434 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4438 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4442 if(update_overlay) {
4443 gui->draw_overlays(1);
4446 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4450 int TrackCanvas::cursor_motion_event()
4452 return cursor_update(1);
4455 void TrackCanvas::start_dragscroll()
4459 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4460 //printf("TrackCanvas::start_dragscroll 1\n");
4464 void TrackCanvas::stop_dragscroll()
4468 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4469 //printf("TrackCanvas::stop_dragscroll 1\n");
4473 int TrackCanvas::repeat_event(int64_t duration)
4475 if(!drag_scroll) return 0;
4476 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4478 int sample_movement = 0;
4479 int track_movement = 0;
4480 int64_t x_distance = 0;
4481 int64_t y_distance = 0;
4482 double position = 0;
4485 switch(mwindow->session->current_operation) {
4487 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4488 if(get_cursor_x() > get_w()) {
4489 x_distance = get_cursor_x() - get_w();
4490 sample_movement = 1;
4492 else if(get_cursor_x() < 0) {
4493 x_distance = get_cursor_x();
4494 sample_movement = 1;
4497 if(get_cursor_y() > get_h()) {
4498 y_distance = get_cursor_y() - get_h();
4501 else if(get_cursor_y() < 0) {
4502 y_distance = get_cursor_y();
4509 if(sample_movement) {
4510 position = (double)(get_cursor_x() +
4511 mwindow->edl->local_session->view_start[pane->number] +
4513 mwindow->edl->local_session->zoom_sample /
4514 mwindow->edl->session->sample_rate;
4515 position = mwindow->edl->align_to_frame(position, 0);
4516 position = MAX(position, 0);
4518 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4519 switch(mwindow->session->current_operation) {
4521 if(position < selection_midpoint) {
4522 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4523 mwindow->edl->local_session->set_selectionstart(position);
4525 gui->unlock_window();
4526 mwindow->cwindow->update(1, 0, 0);
4527 gui->lock_window("TrackCanvas::repeat_event");
4528 // Update the faders
4529 mwindow->update_plugin_guis();
4530 gui->update_patchbay();
4533 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4534 mwindow->edl->local_session->set_selectionend(position);
4535 // Don't que the CWindow
4540 mwindow->samplemovement(
4541 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4545 if(track_movement) {
4546 mwindow->trackmovement(y_distance, pane->number);
4552 int TrackCanvas::button_release_event()
4554 int redraw = -1, update_overlay = 0;
4555 int result = 0, load_flags = 0;
4557 // printf("TrackCanvas::button_release_event %d\n",
4558 // mwindow->session->current_operation);
4560 switch(mwindow->session->current_operation) {
4561 case DRAG_EDITHANDLE2:
4562 mwindow->session->current_operation = NO_OPERATION;
4566 end_edithandle_selection();
4569 case DRAG_EDITHANDLE1:
4570 mwindow->session->current_operation = NO_OPERATION;
4575 case DRAG_PLUGINHANDLE2:
4576 mwindow->session->current_operation = NO_OPERATION;
4580 end_pluginhandle_selection();
4583 case DRAG_PLUGINHANDLE1:
4584 mwindow->session->current_operation = NO_OPERATION;
4590 redraw = FORCE_REDRAW;
4591 load_flags |= LOAD_EDITS;
4593 // delete the drag_auto_gang first and remove out of order keys
4594 clear_ganged_autos();
4605 case DRAG_PROJECTOR_X:
4606 case DRAG_PROJECTOR_Y:
4607 case DRAG_PROJECTOR_Z:
4608 case DRAG_PLUGINKEY:
4609 load_flags |= LOAD_AUTOMATION;
4610 mwindow->session->current_operation = NO_OPERATION;
4611 mwindow->session->drag_handle = 0;
4612 // Remove any out-of-order keyframe
4613 if(mwindow->session->drag_auto) {
4614 mwindow->session->drag_auto->autos->remove_nonsequential(
4615 mwindow->session->drag_auto);
4616 // mwindow->session->drag_auto->autos->optimize();
4620 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
4626 case DRAG_AEFFECT_COPY:
4627 case DRAG_VEFFECT_COPY:
4628 // Trap in drag stop
4631 case DROP_TARGETING: {
4632 int cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
4633 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4634 drag_cursor_motion(cursor_x, cursor_y,
4635 &track, &edit, &pluginset, &plugin);
4637 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4638 gui->edit_menu->activate_menu(track, edit, pluginset, plugin, position);
4639 mwindow->session->current_operation = NO_OPERATION;
4643 case GROUP_TOGGLE: {
4644 Edit *edit = mwindow->session->drag_edit;
4646 if( shift_down() && edit->is_selected ) {
4647 if( edit->group_id > 0 ) {
4648 mwindow->edl->tracks->clear_selected_edits();
4649 mwindow->edl->tracks->del_group(edit->group_id);
4652 int id = mwindow->session->group_number++;
4653 mwindow->edl->tracks->new_group(id);
4658 if( mwindow->preferences->ctrl_toggle && !ctrl_down() )
4659 mwindow->edl->tracks->clear_selected_edits();
4660 edit->set_selected(-1);
4663 mwindow->session->current_operation = NO_OPERATION;
4670 if( mwindow->session->current_operation ) {
4671 // if(mwindow->session->current_operation == SELECT_REGION) {
4672 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4675 mwindow->session->current_operation = NO_OPERATION;
4684 if( mwindow->edl->local_session->zoombar_showautocolor >= 0 )
4685 mwindow->gui->zoombar->update_autozoom(-1);
4690 if(update_overlay) {
4691 gui->draw_overlays(1);
4694 gui->draw_canvas(redraw, 0);
4695 gui->flash_canvas(1);
4700 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4701 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4703 Edit *edit_result = 0;
4704 int handle_result = -1;
4707 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4708 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4709 int64_t edit_x, edit_y, edit_w, edit_h;
4710 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4712 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4713 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4714 if( cursor_x < edit_x + HANDLE_W ) {
4717 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4718 track->show_assets() ) {
4719 new_cursor = DOWNLEFT_RESIZE;
4720 if( button_press == LEFT_BUTTON )
4726 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4729 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4730 track->show_assets() ) {
4731 new_cursor = DOWNRIGHT_RESIZE;
4732 if( button_press == LEFT_BUTTON )
4743 int group_id = edit_result->group_id;
4744 if( group_id > 0 ) {
4745 Track *track = edit_result->track;
4746 Edit *left = 0, *right = 0;
4747 double start = DBL_MAX, end = DBL_MIN;
4748 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
4749 if( edit->group_id != group_id ) continue;
4750 double edit_start = edit->track->from_units(edit->startproject);
4751 if( edit_start < start ) { start = edit_start; left = edit; }
4752 double edit_end = edit->track->from_units(edit->startproject+edit->length);
4753 if( edit_end > end ) { end = edit_end; right = edit; }
4755 Edit *edit = !handle_result ? left : right;
4756 if( edit != edit_result )
4763 double position = 0;
4764 if( handle_result == 0 ) {
4765 position = edit_result->track->from_units(edit_result->startproject);
4766 new_cursor = LEFT_CURSOR;
4768 else if( handle_result == 1 ) {
4769 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4770 new_cursor = RIGHT_CURSOR;
4773 // Reposition cursor
4774 if( button_press ) {
4775 mwindow->session->drag_edit = edit_result;
4776 mwindow->session->drag_handle = handle_result;
4777 mwindow->session->drag_button = get_buttonpress() - 1;
4778 mwindow->session->drag_position = position;
4779 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4780 mwindow->session->drag_origin_x = get_cursor_x();
4781 mwindow->session->drag_origin_y = get_cursor_y();
4782 mwindow->session->drag_start = position;
4784 rerender = start_selection(position);
4788 else if( result < 0 ) {
4789 mwindow->undo->update_undo_before();
4790 if( !shift_down() ) {
4791 if( handle_result == 0 )
4792 edit_result->hard_left = !edit_result->hard_left;
4793 else if( handle_result == 1 )
4794 edit_result->hard_right = !edit_result->hard_right;
4797 int status = handle_result == 0 ? edit_result->hard_left :
4798 handle_result == 1 ? edit_result->hard_right : 0;
4799 int new_status = !status;
4800 int64_t edit_edge = edit_result->startproject;
4801 if( handle_result == 1 ) edit_edge += edit_result->length;
4802 double edge_position = edit_result->track->from_units(edit_edge);
4803 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4804 int64_t track_position = track->to_units(edge_position, 1);
4805 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4807 int64_t left_edge = left_edit->startproject;
4808 double left_position = track->from_units(left_edge);
4809 if( EQUIV(edge_position, left_position) ) {
4810 left_edit->hard_left = new_status;
4811 if( left_edit->previous )
4812 left_edit->previous->hard_right = new_status;
4815 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4817 int64_t right_edge = right_edit->startproject + right_edit->length;
4818 double right_position = track->from_units(right_edge);
4819 if( EQUIV(edge_position, right_position) ) {
4820 right_edit->hard_right = new_status;
4821 if( right_edit->next )
4822 right_edit->next->hard_left = new_status;
4827 rerender = update_overlay = 1;
4828 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4835 int TrackCanvas::do_plugin_handles(int cursor_x,
4839 int &update_overlay,
4843 Plugin *plugin_result = 0;
4844 int handle_result = 0;
4847 for(Track *track = mwindow->edl->tracks->first;
4849 track = track->next) {
4850 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4851 PluginSet *plugin_set = track->plugin_set.values[i];
4852 for(Plugin *plugin = (Plugin*)plugin_set->first;
4854 plugin = (Plugin*)plugin->next) {
4855 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4856 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4858 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4859 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4860 if(cursor_x < plugin_x + HANDLE_W) {
4861 plugin_result = plugin;
4865 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4866 plugin_result = plugin;
4873 if(result && shift_down())
4874 mwindow->session->trim_edits = plugin_set;
4880 double position = 0;
4881 if(handle_result == 0) {
4882 position = plugin_result->track->from_units(plugin_result->startproject);
4883 new_cursor = LEFT_CURSOR;
4885 else if(handle_result == 1) {
4886 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4887 new_cursor = RIGHT_CURSOR;
4891 mwindow->session->drag_plugin = plugin_result;
4892 mwindow->session->drag_handle = handle_result;
4893 mwindow->session->drag_button = get_buttonpress() - 1;
4894 mwindow->session->drag_position = position;
4895 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4896 mwindow->session->drag_origin_x = get_cursor_x();
4897 mwindow->session->drag_origin_y = get_cursor_y();
4898 mwindow->session->drag_start = position;
4900 rerender = start_selection(position);
4909 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4913 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4914 drag_cursor_motion(cursor_x, cursor_y,
4915 &track, &edit, &pluginset, &plugin);
4917 if( button_press && track ) {
4918 switch( get_buttonpress() ) {
4919 case RIGHT_BUTTON: {
4921 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4922 gui->track_menu->activate_menu(track, edit, pluginset, plugin, position);
4923 mwindow->session->current_operation = NO_OPERATION;
4927 set_cursor(GRABBED_CURSOR, 0, 1);
4928 mwindow->session->current_operation = DROP_TARGETING;
4937 int TrackCanvas::arrow_mode()
4939 return mwindow->edl->session->editing_mode == EDITING_ARROW ? 1 : 0;
4941 int TrackCanvas::ibeam_mode()
4943 return mwindow->edl->session->editing_mode == EDITING_IBEAM ? 1 : 0;
4946 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4947 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4951 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4952 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4953 int64_t edit_x, edit_y, edit_w, edit_h;
4954 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4956 // Cursor inside a track
4957 // Cursor inside an edit
4958 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4959 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4960 if( button_press && get_buttonpress() == LEFT_BUTTON ) {
4961 if( get_double_click() ) {
4962 mwindow->edl->tracks->clear_selected_edits();
4963 mwindow->edl->tracks->select_affected_edits(
4964 edit->track->from_units(edit->startproject),
4966 double start = edit->track->from_units(edit->startproject);
4967 start = mwindow->edl->align_to_frame(start, 0);
4968 mwindow->edl->local_session->set_selectionstart(start);
4969 double end = edit->track->from_units(edit->startproject+edit->length);
4970 end = mwindow->edl->align_to_frame(end, 0);
4971 mwindow->edl->local_session->set_selectionend(end);
4972 result = 1; // Select edit duration or select_region
4974 else if( arrow_mode() || (ibeam_mode() && ctrl_down()) ) {
4975 mwindow->session->drag_edit = edit;
4976 mwindow->session->current_operation = GROUP_TOGGLE;
4984 else if( drag_start && track->record ) {
4985 mwindow->session->drag_edit = edit;
4986 mwindow->session->drag_origin_x = cursor_x;
4987 mwindow->session->drag_origin_y = cursor_y;
4988 // Where the drag started, so we know relative position inside the edit later
4989 mwindow->session->drag_position =
4990 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4991 drag_start = 0; // if unselected "fast" drag
4992 if( !edit->silence() && !edit->is_selected ) {
4993 mwindow->edl->tracks->clear_selected_edits();
4994 if( ibeam_mode() ) {
4995 double start = edit->track->from_units(edit->startproject);
4996 mwindow->edl->local_session->set_selectionstart(start);
4997 mwindow->edl->local_session->set_selectionend(start);
4998 edit->set_selected(1);
5001 mwindow->edl->tracks->select_affected_edits(
5002 edit->track->from_units(edit->startproject),
5006 // Construct list of all affected edits
5007 if( drag_start || ibeam_mode() ) {
5008 mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits);
5009 if( mwindow->session->drag_edits->size() > 0 ) {
5010 mwindow->session->current_operation = DRAG_EDIT;
5011 // Need to create drag window
5012 int cx, cy; get_abs_cursor(cx, cy);
5013 gui->drag_popup = new BC_DragWindow(gui,
5014 mwindow->theme->get_image("clip_icon"), cx, cy);
5018 rerender = start_selection(mwindow->session->drag_position);
5019 mwindow->session->current_operation = SELECT_REGION;
5023 else if( edit->is_selected && arrow_mode() ) {
5024 if( mwindow->session->drag_group )
5025 mwindow->session->drag_group->remove_user();
5026 double start_position = 0;
5027 mwindow->session->drag_group =
5028 mwindow->selected_edits_to_clip(0, &start_position,
5029 &mwindow->session->drag_group_first_track,
5030 mwindow->edl->session->labels_follow_edits,
5031 mwindow->edl->session->autos_follow_edits,
5032 mwindow->edl->session->plugins_follow_edits);
5033 if( mwindow->session->drag_group ) {
5034 mwindow->session->current_operation = DRAG_GROUP;
5035 mwindow->session->drag_group_position = start_position;
5036 mwindow->session->drag_group_edit = edit;
5037 mwindow->session->drag_origin_y = edit_y;
5049 int TrackCanvas::test_track_group(EDL *group, Track *first_track, double &pos)
5051 Track *src = group->tracks->first;
5052 for( Track *track=first_track; track && src; track=track->next ) {
5053 if( !track->record ) continue;
5054 if( src->data_type != track->data_type ) return -1;
5055 for( Edit *src_edit=src->edits->first; src_edit; src_edit=src_edit->next ) {
5056 if( src_edit->silence() ) continue;
5057 if( edit_intersects(track, src_edit, pos) ) return 0;
5061 return !src ? 1 : 0;
5064 int TrackCanvas::edit_intersects(Track *track, Edit *src_edit, double &pos)
5066 if( pos < 0 ) { pos = 0; return 1; }
5067 int64_t src_start = src_edit->startproject;
5068 int64_t src_end = src_start + src_edit->length;
5069 double new_start = src_edit->track->from_units(src_start) + pos;
5070 double new_end = src_edit->track->from_units(src_end) + pos;
5071 int64_t trk_start = track->to_units(new_start, 1);
5072 int64_t trk_end = track->to_units(new_end, 1);
5073 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
5074 if( edit->is_selected || edit->silence() ) continue;
5075 int64_t edit_start = edit->startproject;
5076 if( edit_start >= trk_end ) continue;
5077 int64_t edit_end = edit_start + edit->length;
5078 if( trk_start >= edit_end ) continue;
5079 int64_t lt_dist = labs(trk_end - edit_start);
5080 int64_t rt_dist = labs(edit_end - trk_start);
5082 if( lt_dist < rt_dist ) {
5083 position = edit_start;
5084 lt_dist = abs(trk_start - edit_start);
5085 rt_dist = abs(trk_end - edit_start);
5086 if( lt_dist > rt_dist )
5087 position -= src_end;
5090 position = edit_end;
5091 lt_dist = abs(trk_start - edit_end);
5092 rt_dist = abs(trk_end - edit_end);
5093 if( lt_dist > rt_dist )
5094 position -= src_end;
5096 pos = edit->track->from_units(position);
5102 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
5107 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
5108 int button_press, int &redraw, int &rerender)
5116 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
5117 if(!track->expand_view) continue;
5119 for(int i = 0; i < track->plugin_set.total && !done; i++) {
5120 // first check if plugins are visible at all
5121 if (!track->expand_view)
5123 PluginSet *plugin_set = track->plugin_set.values[i];
5124 for(plugin = (Plugin*)plugin_set->first;
5126 plugin = (Plugin*)plugin->next) {
5127 plugin_dimensions(plugin, x, y, w, h);
5128 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
5129 MWindowGUI::visible(y, y + h, 0, get_h())) {
5130 if(cursor_x >= x && cursor_x < x + w &&
5131 cursor_y >= y && cursor_y < y + h) {
5141 // Start plugin popup
5143 if(get_buttonpress() == RIGHT_BUTTON ) {
5144 gui->plugin_menu->update(plugin);
5145 gui->plugin_menu->activate_menu();
5148 else if (get_double_click() && !drag_start) {
5149 // Select range of plugin on doubleclick over plugin
5150 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
5151 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
5152 plugin->track->from_units(plugin->length));
5153 if(mwindow->edl->session->cursor_on_frames) {
5154 mwindow->edl->local_session->set_selectionstart(
5155 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
5156 mwindow->edl->local_session->set_selectionend(
5157 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
5166 if( drag_start && plugin->track->record && !plugin->silence() ) {
5167 if( mwindow->edl->session->editing_mode == EDITING_ARROW ) {
5168 if( plugin->track->data_type == TRACK_AUDIO )
5169 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
5170 else if( plugin->track->data_type == TRACK_VIDEO )
5171 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
5173 mwindow->session->drag_plugin = plugin;
5174 mwindow->session->drag_origin_x = cursor_x;
5175 mwindow->session->drag_origin_y = cursor_y;
5176 // Where the drag started, so we know relative position inside the edit later
5177 mwindow->session->drag_position =
5178 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
5179 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
5181 switch(plugin->plugin_type) {
5182 case PLUGIN_STANDALONE: {
5183 PluginServer *server =
5184 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
5185 if( !server ) break;
5186 VFrame *frame = server->picon;
5188 if(plugin->track->data_type == TRACK_AUDIO) {
5189 frame = mwindow->theme->get_image("aeffect_icon");
5192 frame = mwindow->theme->get_image("veffect_icon");
5196 get_abs_cursor(cx, cy);
5197 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
5200 case PLUGIN_SHAREDPLUGIN:
5201 case PLUGIN_SHAREDMODULE: {
5202 VFrame *frame = mwindow->theme->get_image("clip_icon");
5204 get_abs_cursor(cx, cy);
5205 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
5217 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
5218 int button_press, int &new_cursor, int &update_cursor)
5220 Transition *transition = 0;
5225 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
5226 if( !track->show_transitions() ) continue;
5228 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
5229 if( edit->transition ) {
5230 edit_dimensions(edit, x, y, w, h);
5231 get_transition_coords(edit, x, y, w, h);
5233 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
5234 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
5235 if( cursor_x >= x && cursor_x < x + w &&
5236 cursor_y >= y && cursor_y < y + h ) {
5237 transition = edit->transition;
5249 new_cursor = UPRIGHT_ARROW_CURSOR;
5251 else if(get_buttonpress() == RIGHT_BUTTON ) {
5252 gui->transition_menu->update(transition);
5253 gui->transition_menu->activate_menu();
5260 int TrackCanvas::button_press_event()
5263 int cursor_x, cursor_y;
5266 cursor_x = get_cursor_x();
5267 cursor_y = get_cursor_y();
5268 mwindow->session->trim_edits = 0;
5270 if(is_event_win() && cursor_inside()) {
5271 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5278 if( get_buttonpress() == LEFT_BUTTON ) {
5279 gui->stop_transport("TrackCanvas::button_press_event");
5282 int update_overlay = 0, update_cursor = 0, rerender = 0, update_message = 0;
5284 if(get_buttonpress() == WHEEL_UP) {
5286 mwindow->expand_sample();
5287 else if(ctrl_down())
5288 mwindow->move_left(get_w()/ 10);
5290 mwindow->move_up(get_h() / 10);
5292 else if(get_buttonpress() == WHEEL_DOWN) {
5294 mwindow->zoom_in_sample();
5295 else if(ctrl_down())
5296 mwindow->move_right(get_w() / 10);
5298 mwindow->move_down(get_h() / 10);
5300 else if(get_buttonpress() == 6) {
5302 mwindow->move_left(get_w());
5304 mwindow->move_left(get_w() / 20);
5306 mwindow->move_left(get_w() / 5);
5308 else if(get_buttonpress() == 7) {
5310 mwindow->move_right(get_w());
5312 mwindow->move_right(get_w() / 20);
5314 mwindow->move_right(get_w() / 5);
5317 if( arrow_mode() ) do {
5318 // Test handles and resource boundaries and highlight a track
5319 if( do_transitions(cursor_x, cursor_y,
5320 1, new_cursor, update_cursor) ) break;
5322 if( do_keyframes(cursor_x, cursor_y,
5323 0, get_buttonpress(), new_cursor,
5324 update_cursor, rerender) ) break;
5325 // Test edit boundaries
5326 if( do_edit_handles(cursor_x, cursor_y,
5327 1, rerender, update_overlay, new_cursor,
5328 update_cursor) ) break;
5329 // Test plugin boundaries
5330 if( do_plugin_handles(cursor_x, cursor_y,
5331 1, rerender, update_overlay, new_cursor,
5332 update_cursor) ) break;
5334 if( do_edits(cursor_x, cursor_y, 1, 0,
5335 update_overlay, rerender, new_cursor,
5336 update_cursor) ) break;
5338 if( do_plugins(cursor_x, cursor_y, 0, 1,
5339 update_cursor, rerender) ) break;
5341 if( test_resources(cursor_x, cursor_y) ) break;
5343 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5348 else if( ibeam_mode() ) do {
5349 // Test handles only and select a region
5350 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5351 //printf("TrackCanvas::button_press_event %d\n", position);
5353 if( do_transitions(cursor_x, cursor_y,
5354 1, new_cursor, update_cursor)) break;
5355 if(do_keyframes(cursor_x, cursor_y,
5356 0, get_buttonpress(), new_cursor,
5357 update_cursor, rerender)) {
5361 // Test edit boundaries
5362 if( do_edit_handles(cursor_x, cursor_y,
5363 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5364 // Test plugin boundaries
5365 if( do_plugin_handles(cursor_x, cursor_y,
5366 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5368 if( do_edits(cursor_x, cursor_y,
5369 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
5371 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
5373 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5374 // Highlight selection
5375 if( get_buttonpress() != LEFT_BUTTON ) break;
5376 rerender = start_selection(position);
5377 mwindow->session->current_operation = SELECT_REGION;
5384 gui->unlock_window();
5385 mwindow->cwindow->update(1, 0, 0, 0, 1);
5386 gui->lock_window("TrackCanvas::button_press_event 2");
5388 mwindow->update_plugin_guis();
5389 gui->update_patchbay();
5392 if( update_message )
5393 gui->default_message();
5395 if( update_overlay )
5396 gui->draw_overlays(1);
5398 if( update_cursor < 0 ) {
5399 // double_click edit
5400 gui->swindow->update_selection();
5401 gui->draw_canvas(0, 0);
5403 if( update_cursor ) {
5404 gui->update_timebar(0);
5405 gui->hide_cursor(0);
5406 gui->show_cursor(1);
5407 gui->zoombar->update();
5408 gui->flash_canvas(1);
5415 int TrackCanvas::start_selection(double position)
5418 position = mwindow->edl->align_to_frame(position, 1);
5424 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
5425 mwindow->edl->local_session->get_selectionend(1)) / 2;
5427 if(position < midpoint)
5429 mwindow->edl->local_session->set_selectionstart(position);
5430 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
5436 mwindow->edl->local_session->set_selectionend(position);
5437 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
5438 // Don't que the CWindow for the end
5442 // Start a new selection
5444 //printf("TrackCanvas::start_selection %f\n", position);
5445 mwindow->edl->local_session->set_selectionstart(position);
5446 mwindow->edl->local_session->set_selectionend(position);
5447 selection_midpoint = position;
5455 void TrackCanvas::end_edithandle_selection()
5457 mwindow->modify_edithandles();
5460 void TrackCanvas::end_pluginhandle_selection()
5462 mwindow->modify_pluginhandles();
5466 double TrackCanvas::time_visible()
5468 return (double)get_w() *
5469 mwindow->edl->local_session->zoom_sample /
5470 mwindow->edl->session->sample_rate;
5474 void TrackCanvas::show_message(Auto *current, int color, const char *fmt, ...)
5476 char string[BCTEXTLEN];
5477 char *cp = string, *ep = cp + sizeof(string)-1;
5479 cp += snprintf(string, ep-cp, "%-8s ",
5480 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5482 char string2[BCTEXTLEN];
5483 Units::totext(string2,
5484 current->autos->track->from_units(current->position),
5485 mwindow->edl->session->time_format,
5486 mwindow->edl->session->sample_rate,
5487 mwindow->edl->session->frame_rate,
5488 mwindow->edl->session->frames_per_foot);
5489 cp += snprintf(cp, ep-cp, "%s", string2);
5492 vsnprintf(cp, ep-cp, fmt, ap);
5494 gui->show_message(string, color);
5497 // Patchbay* TrackCanvas::get_patchbay()
5499 // if(pane->patchbay) return pane->patchbay;
5500 // if(gui->total_panes() == 2 &&
5501 // gui->pane[TOP_LEFT_PANE] &&
5502 // gui->pane[TOP_RIGHT_PANE])
5503 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5504 // if(gui->total_panes() == 4)
5506 // if(pane->number == TOP_RIGHT_PANE)
5507 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5509 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;