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;
515 if( drop_track && test_track_group(drag_group, drop_track) ) {
516 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
517 position = mwindow->edl->align_to_frame(position, 0);
518 position -= mwindow->session->drag_group_position;
519 mwindow->move_group(drag_group, drop_track, position);
521 drag_group->remove_user();
522 mwindow->session->drag_group = 0;
532 int TrackCanvas::drag_start_event()
537 int new_cursor, update_cursor;
539 if(mwindow->session->current_operation != NO_OPERATION) return 0;
542 if(do_plugins(get_drag_x(), get_drag_y(),
543 1, 0, redraw, rerender)) {
546 else if(do_edits(get_drag_x(), get_drag_y(),
547 0, 1, redraw, rerender, new_cursor, update_cursor)) {
555 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
557 // get the canvas/track position
558 Track *track = mwindow->session->track_highlighted;
559 int cursor_x = get_relative_cursor_x();
560 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
561 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
562 double position = mwindow->edl->align_to_frame(cur_pos, 1);
563 if( position <= 0 ) {
567 double cursor_position = position;
568 int64_t drop_position = track->to_units(cursor_position, 1);
569 if( moved_edit ) { // relative cursor position depends upon drop point
570 double moved_edit_start = moved_edit->track->from_units(moved_edit->startproject);
571 position -= mwindow->session->drag_position - moved_edit_start;
573 int64_t edit_position = track->to_units(position, 1);
574 int64_t grab_position = edit_position;
575 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
576 grab_position -= moved_edit_length / 2;
577 Edit *last_edit = track->edits->last;
578 if( !last_edit || edit_position >= (last_edit->startproject+last_edit->length) ) {
580 return edit_position;
583 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
584 Edit *next_edit = track->edits->first;
586 Edit *edit = next_edit; next_edit = (Edit *)edit->next;
587 int64_t edit_start = edit->startproject;
588 int64_t edit_end = edit_start + edit->length;
589 double edit_start_pos = edit->track->from_units(edit_start);
590 if( (fabs(edit_start_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
591 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
594 double edit_end_pos = edit->track->from_units(edit_end);
595 if( (fabs(edit_end_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
596 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
599 if( edit != moved_edit && !edit->silence() )
600 drop_start = edit_end; // reset drop zone
602 if( next_edit == moved_edit || next_edit->silence() ) continue;
606 drop_end = INT64_MAX;
607 if( edit_position >= drop_start &&
608 edit_position+moved_edit_length < drop_end ) {
609 *is_insertion = 0; // fits in the zone
610 return edit_position;
612 if( drop_position < drop_end ) { // drop in the zone
613 if( (drop_end - drop_start) >= moved_edit_length ) {
614 *is_insertion = 0; // fits in the zone, but over the edge
615 int64_t dx0 = llabs(drop_position - drop_start);
616 int64_t dx1 = llabs(drop_position - drop_end);
617 return dx0 < dx1 ? drop_start : drop_end - moved_edit_length;
620 int64_t edit_center = (edit_start + edit_end) / 2;
621 return position < edit_center ? drop_start : drop_end;
629 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
631 // get the canvas/track position
632 Track *track = plugin_set->track;
633 double moved_plugin_length = moved_plugin->track->from_units(moved_plugin->length);
634 int64_t track_plugin_length = track->to_units(moved_plugin_length, 0);
635 int cursor_x = get_relative_cursor_x();
636 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
637 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
638 double position = mwindow->edl->align_to_frame(cur_pos, 1);
639 if( position <= 0 ) return 0;
640 int64_t drop_position = track->to_units(position, 1);
641 Plugin *last_plugin = (Plugin *)plugin_set->last;
642 if( !last_plugin ) return drop_position;
643 double plugin_set_end = last_plugin->track->from_units(last_plugin->startproject+last_plugin->length);
644 if( position >= plugin_set_end ) return drop_position;
645 double moved_plugin_start = moved_plugin->track->from_units(moved_plugin->startproject);
646 position -= mwindow->session->drag_position - moved_plugin_start;
647 int64_t plugin_position = track->to_units(position, 1);
649 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
650 Plugin *next_plugin = (Plugin *)plugin_set->first;
651 while( next_plugin ) {
652 Plugin *plugin = next_plugin; next_plugin = (Plugin *)plugin->next;
653 int64_t plugin_start = plugin->startproject;
654 int64_t plugin_end = plugin_start + plugin->length;
655 double plugin_end_pos = plugin->track->from_units(plugin_end);
656 int64_t track_plugin_end = track->to_units(plugin_end_pos, 0);
657 if( plugin != moved_plugin && !plugin->silence() )
658 drop_start = track_plugin_end;
660 if( next_plugin == moved_plugin || next_plugin->silence() ) continue;
661 drop_end = track_plugin_end;
664 drop_end = INT64_MAX;
665 if( plugin_position >= drop_start && // fits in the zone
666 plugin_position+track_plugin_length < drop_end ) {
667 return plugin_position;
669 if( drop_position < drop_end ) { // drop in the zone
670 if( (drop_end - drop_start) >= track_plugin_length ) {
671 int64_t dx0 = llabs(drop_position - drop_start);
672 int64_t dx1 = llabs(drop_position - drop_end);
673 return dx0 < dx1 ? drop_start : drop_end - track_plugin_length;
681 void TrackCanvas::draw(int mode, int hide_cursor)
685 // Swap pixmap layers
686 if(get_w() != background_pixmap->get_w() ||
687 get_h() != background_pixmap->get_h())
689 delete background_pixmap;
690 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
693 // Cursor disappears after resize when this is called.
694 // Cursor doesn't redraw after editing when this isn't called.
695 if(pane->cursor && hide_cursor) pane->cursor->hide();
696 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
698 if(debug) PRINT_TRACE
699 draw_resources(mode);
701 if(debug) PRINT_TRACE
703 if(debug) PRINT_TRACE
706 void TrackCanvas::update_cursor(int flush)
708 switch(mwindow->edl->session->editing_mode)
710 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
711 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
716 void TrackCanvas::test_timer()
718 if(resource_timer->get_difference() > 1000 &&
722 hourglass_enabled = 1;
727 void TrackCanvas::draw_indexes(Indexable *indexable)
729 IndexState *index_state = indexable->index_state;
730 // Don't redraw raw samples
731 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
733 draw_resources(NORMAL_DRAW, 1, indexable);
738 void TrackCanvas::draw_resources(int mode,
740 Indexable *indexable)
744 if(debug) PRINT_TRACE
746 // can't stop thread here, because this is called for every pane
747 // if(mode != IGNORE_THREAD && !indexes_only)
748 // gui->resource_thread->stop_draw(!indexes_only);
750 if(mode != IGNORE_THREAD &&
752 !gui->resource_thread->interrupted)
754 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
757 BC_Signals::dump_stack();
760 if(debug) PRINT_TRACE
762 resource_timer->update();
764 // Age resource pixmaps for deletion
766 for(int i = 0; i < gui->resource_pixmaps.total; i++)
767 gui->resource_pixmaps.values[i]->visible--;
769 if(mode == FORCE_REDRAW)
770 gui->resource_pixmaps.remove_all_objects();
772 if(debug) PRINT_TRACE
775 for(Track *current = mwindow->edl->tracks->first;
779 if(debug) PRINT_TRACE
780 for(Edit *edit = current->edits->first; edit; edit = edit->next)
782 if(debug) PRINT_TRACE
783 if( current->data_type != TRACK_SUBTITLE )
784 if(!edit->asset && !edit->nested_edl) continue;
787 if(edit->track->data_type != TRACK_AUDIO) continue;
789 if(edit->nested_edl &&
790 strcmp(indexable->path, edit->nested_edl->path)) continue;
793 strcmp(indexable->path, edit->asset->path)) continue;
796 if(debug) PRINT_TRACE
798 int64_t edit_x, edit_y, edit_w, edit_h;
799 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
802 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
803 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
805 int64_t pixmap_x, pixmap_w, pixmap_h;
806 if(debug) PRINT_TRACE
808 // Search for existing pixmap containing edit
809 for(int i = 0; i < gui->resource_pixmaps.total; i++)
811 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
812 // Same pointer can be different edit if editing took place
813 if(pixmap->edit_id == edit->id &&
814 pixmap->pane_number == pane->number)
820 if(debug) PRINT_TRACE
822 // Get new size, offset of pixmap needed
823 get_pixmap_size(edit,
829 if(debug) PRINT_TRACE
832 if(pixmap_w && pixmap_h)
834 // Create pixmap if it doesn't exist
835 ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
836 pixmap_x, pixmap_w, pixmap_h);
837 // Resize it if it's bigger
838 if( pixmap_w > pixmap->pixmap_w ||
839 pixmap_h > pixmap->pixmap_h)
840 pixmap->resize(pixmap_w, pixmap_h);
841 pixmap->update_settings(edit, edit_x, edit_w,
842 pixmap_x, pixmap_w, pixmap_h);
844 if( current->show_assets() )
845 pixmap->draw_data(this,
846 edit, edit_x, edit_w,
847 pixmap_x, pixmap_w, pixmap_h,
851 clear_box(0,0, pixmap_w,pixmap_h, pixmap);
854 if( current->show_titles() )
855 pixmap->draw_title(this,
856 edit, edit_x, edit_w,
858 // Resize it if it's smaller
859 if(pixmap_w < pixmap->pixmap_w ||
860 pixmap_h < pixmap->pixmap_h)
861 pixmap->resize(pixmap_w, pixmap_h);
863 // Copy pixmap to background canvas
864 background_pixmap->draw_pixmap(pixmap,
866 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
870 if(debug) PRINT_TRACE
877 // Delete unused pixmaps
878 if(debug) PRINT_TRACE
880 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
881 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
883 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
884 delete gui->resource_pixmaps.values[i];
885 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
887 if(debug) PRINT_TRACE
889 if(hourglass_enabled)
892 hourglass_enabled = 0;
894 if(debug) PRINT_TRACE
896 // can't stop thread here, because this is called for every pane
897 // if(mode != IGNORE_THREAD && !indexes_only)
898 // gui->resource_thread->start_draw();
899 if(debug) PRINT_TRACE
904 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
910 ResourcePixmap *result = 0;
912 for(int i = 0; i < gui->resource_pixmaps.total; i++)
914 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
915 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
916 gui->resource_pixmaps.values[i]->pane_number == pane->number)
918 result = gui->resource_pixmaps.values[i];
926 result = new ResourcePixmap(mwindow,
933 gui->resource_pixmaps.append(result);
936 // result->resize(pixmap_w, pixmap_h);
940 void TrackCanvas::get_pixmap_size(Edit *edit,
948 // Align x on frame boundaries
951 // switch(edit->edits->track->data_type)
963 if(pixmap_x + pixmap_w > get_w())
965 pixmap_w = get_w() - pixmap_x;
972 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
973 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
974 // int64_t pixel_increment = MAX(picon_w, frame_w);
975 // int64_t pixmap_x1 = edit_x;
976 // int64_t pixmap_x2 = edit_x + edit_w;
980 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
985 // if(pixmap_x2 > get_w())
987 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
991 // pixmap_x = pixmap_x1;
992 // pixmap_w = pixmap_x2 - pixmap_x1;
997 pixmap_h = mwindow->edl->local_session->zoom_track;
998 Track *track = edit->edits->track;
999 if( track->show_titles() )
1000 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
1001 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
1004 void TrackCanvas::edit_dimensions(Edit *edit,
1005 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1007 x = Units::round(edit->track->from_units(edit->startproject) *
1008 mwindow->edl->session->sample_rate /
1009 mwindow->edl->local_session->zoom_sample -
1010 mwindow->edl->local_session->view_start[pane->number]);
1012 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1014 // Method for calculating w so when edits are together we never get off by one error due to rounding
1015 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
1016 mwindow->edl->session->sample_rate /
1017 mwindow->edl->local_session->zoom_sample -
1018 mwindow->edl->local_session->view_start[pane->number]);
1022 if( edit->track->show_titles() )
1023 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
1024 if( edit->track->show_assets() )
1025 edit_h += resource_h();
1029 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1033 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1034 h = track->vertical_span(mwindow->theme);
1038 void TrackCanvas::draw_paste_destination()
1040 //int cursor_x = get_relative_cursor_x();
1041 //int cursor_y = get_relative_cursor_y();
1042 int current_atrack = 0;
1043 int current_vtrack = 0;
1044 int current_aedit = 0;
1045 int current_vedit = 0;
1051 //if(pane->number == BOTTOM_RIGHT_PANE)
1052 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1054 if((mwindow->session->current_operation == DRAG_ASSET &&
1055 (mwindow->session->drag_assets->total ||
1056 mwindow->session->drag_clips->total)) ||
1057 (mwindow->session->current_operation == DRAG_EDIT &&
1058 mwindow->session->drag_edits->total)) {
1059 Indexable *indexable = 0;
1063 if(mwindow->session->current_operation == DRAG_ASSET &&
1064 mwindow->session->drag_assets->size())
1065 indexable = mwindow->session->drag_assets->get(0);
1067 if(mwindow->session->current_operation == DRAG_ASSET &&
1068 mwindow->session->drag_clips->size())
1069 clip = mwindow->session->drag_clips->get(0);
1071 int has_audio = 0, has_video = 0;
1072 double paste_audio_length = 0, paste_video_length = 0;
1073 double paste_audio_position = -1, paste_video_position = -1;
1076 has_audio = indexable->have_audio();
1077 paste_audio_length = !has_audio ? 0 :
1078 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1079 has_video = indexable->have_video();
1080 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1081 // Images have length -1
1082 if( asset && asset->video_data && asset->video_length < 0 ) {
1083 paste_video_length = mwindow->edl->session->si_useduration ?
1084 mwindow->edl->session->si_duration / asset->frame_rate :
1085 1.0 / asset->frame_rate ; // 1 frame
1088 paste_video_length = !has_video ? 0 :
1089 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1093 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1094 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1095 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1096 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1099 // 'Align cursor on frame' lengths calculations
1100 if( mwindow->edl->session->cursor_on_frames ) {
1101 double fps = mwindow->edl->session->frame_rate;
1102 double aud = floor(paste_audio_length * fps) / fps;
1103 double vid = floor(paste_video_length * fps) / fps;
1104 double length = has_video && has_audio ?
1105 aud < vid ? aud : vid :
1107 has_audio ? aud : 0;
1108 paste_video_length = paste_audio_length = length;
1111 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1113 switch( mwindow->session->track_highlighted->data_type ) {
1114 case TRACK_VIDEO: length = paste_video_length; break;
1115 case TRACK_AUDIO: length = paste_audio_length; break;
1117 int64_t asset_length = mwindow->session->track_highlighted->
1118 to_units(length, 1);
1119 paste_audio_position = mwindow->session->track_highlighted->
1120 from_units(drop_edit_position(&insertion, NULL, asset_length));
1123 int64_t asset_length = mwindow->session->track_highlighted->
1124 to_units(paste_video_length, 1);
1125 paste_video_position = mwindow->session->track_highlighted->
1126 from_units(drop_edit_position(&insertion, NULL, asset_length));
1129 // Get destination track
1130 for(Track *dest = mwindow->session->track_highlighted;
1132 dest = dest->next) {
1134 // Get source width in pixels
1136 // Use start of highlighted edit
1137 if(mwindow->session->edit_highlighted) {
1138 position = mwindow->session->track_highlighted->from_units(
1139 mwindow->session->edit_highlighted->startproject);
1142 // Use end of highlighted track, disregarding effects
1143 position = mwindow->session->track_highlighted->from_units(
1144 mwindow->session->track_highlighted->edits->length());
1147 // Get the x coordinate
1148 x = Units::to_int64(position *
1149 mwindow->edl->session->sample_rate /
1150 mwindow->edl->local_session->zoom_sample) -
1151 mwindow->edl->local_session->view_start[pane->number];
1153 double paste_position = -1.;
1154 if(dest->data_type == TRACK_AUDIO) {
1155 if(indexable && current_atrack < indexable->get_audio_channels()) {
1156 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1157 w = Units::to_int64((double)indexable->get_audio_samples() /
1158 indexable->get_sample_rate() *
1159 mwindow->edl->session->sample_rate /
1160 mwindow->edl->local_session->zoom_sample);
1161 paste_position = paste_audio_position;
1163 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1164 w = Units::to_int64((double)clip->tracks->total_length() *
1165 mwindow->edl->session->sample_rate /
1166 mwindow->edl->local_session->zoom_sample);
1167 paste_position = paste_audio_position;
1168 //printf("draw_paste_destination %d\n", x);
1170 else if(mwindow->session->current_operation == DRAG_EDIT &&
1171 current_aedit < mwindow->session->drag_edits->total) {
1173 while(current_aedit < mwindow->session->drag_edits->total &&
1174 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1177 if(current_aedit < mwindow->session->drag_edits->total) {
1178 edit = mwindow->session->drag_edits->values[current_aedit];
1179 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1180 paste_position = mwindow->session->track_highlighted->
1181 from_units(drop_edit_position(&insertion,
1182 mwindow->session->drag_edit,
1183 mwindow->session->drag_edit->length));
1187 if( paste_position >= 0 ) {
1188 position = paste_position;
1195 else if(dest->data_type == TRACK_VIDEO) {
1196 //printf("draw_paste_destination 1\n");
1197 if(indexable && current_vtrack < indexable->get_video_layers())
1199 w = Units::to_int64((double)indexable->get_video_frames() /
1200 indexable->get_frame_rate() *
1201 mwindow->edl->session->sample_rate /
1202 mwindow->edl->local_session->zoom_sample);
1203 paste_position = paste_video_position;
1205 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1206 w = Units::to_int64(clip->tracks->total_length() *
1207 mwindow->edl->session->sample_rate /
1208 mwindow->edl->local_session->zoom_sample);
1209 paste_position = paste_video_position;
1211 else if(mwindow->session->current_operation == DRAG_EDIT &&
1212 current_vedit < mwindow->session->drag_edits->total) {
1214 while(current_vedit < mwindow->session->drag_edits->total &&
1215 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1218 if(current_vedit < mwindow->session->drag_edits->total) {
1219 edit = mwindow->session->drag_edits->values[current_vedit];
1220 w = Units::to_int64(edit->track->from_units(edit->length) *
1221 mwindow->edl->session->sample_rate /
1222 mwindow->edl->local_session->zoom_sample);
1223 paste_position = mwindow->session->track_highlighted->
1224 from_units(drop_edit_position(&insertion,
1225 mwindow->session->drag_edit,
1226 mwindow->session->drag_edit->length));
1230 if( paste_position >= 0 ) {
1231 position = paste_position;
1240 // Get the x coordinate
1241 x = Units::to_int64(position *
1242 mwindow->edl->session->sample_rate /
1243 mwindow->edl->local_session->zoom_sample) -
1244 mwindow->edl->local_session->view_start[pane->number];
1245 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1246 int h = dest->vertical_span(mwindow->theme);
1248 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1249 if(x < -BC_INFINITY) {
1250 w -= -BC_INFINITY - x;
1251 x += -BC_INFINITY - x;
1254 // if(pane->number == TOP_RIGHT_PANE)
1255 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1256 // __LINE__, x, y, w, h);
1258 draw_highlight_insertion(x, y, w, h);
1260 draw_highlight_rectangle(x, y, w, h);
1267 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1269 x = Units::round(plugin->track->from_units(plugin->startproject) *
1270 mwindow->edl->session->sample_rate /
1271 mwindow->edl->local_session->zoom_sample -
1272 mwindow->edl->local_session->view_start[pane->number]);
1273 w = Units::round(plugin->track->from_units(plugin->length) *
1274 mwindow->edl->session->sample_rate /
1275 mwindow->edl->local_session->zoom_sample);
1276 y = plugin->track->y_pixel
1277 - mwindow->edl->local_session->track_start[pane->number];
1278 if( plugin->track->show_titles() )
1279 y += mwindow->theme->get_image("title_bg_data")->get_h();
1280 if( plugin->track->show_assets() )
1282 y += plugin->plugin_set->get_number() *
1283 mwindow->theme->get_image("plugin_bg_data")->get_h();
1284 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1287 int TrackCanvas::resource_h()
1289 return mwindow->edl->local_session->zoom_track;
1292 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1295 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1296 // just draw arrows, so user has indication that something is there
1297 // FIXME: get better colors
1301 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1306 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1310 // Fix bug in heroines & cvs version as of 22.8.2005:
1311 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1312 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1325 w = MIN(w, get_w() + 20);
1326 h = MIN(h, get_h() + 20);
1329 set_color(mwindow->preferences->highlight_inverse);
1331 //draw_rectangle(x, y, w, h);
1332 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1333 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1335 draw_rectangle(x, y, w, h);
1337 //if(pane->number == TOP_RIGHT_PANE)
1338 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1341 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1344 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1345 // just draw arrows, so user has indication that something is there
1346 // FIXME: get better colors
1355 /* these don't look so good
1357 draw_line(x, y, x, y+h);
1358 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1359 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1360 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1361 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1363 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1364 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1366 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1367 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1368 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1369 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1371 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1372 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1374 // draw the box centred around x
1376 // Fix bug in heroines & cvs version as of 22.8.2005:
1377 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1378 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1389 w = MIN(w, get_w() + 20);
1390 h = MIN(h, get_h() + 20);
1391 set_color(mwindow->preferences->highlight_inverse);
1393 draw_rectangle(x, y, w, h);
1394 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1396 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1399 void TrackCanvas::draw_playback_cursor()
1401 // Called before playback_cursor exists
1402 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1404 // mwindow->playback_cursor->visible = 0;
1405 // mwindow->playback_cursor->draw();
1409 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1411 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1412 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1414 edit_dimensions(edit, x, y, w, h);
1416 if( edit->track->show_titles() )
1417 y += mwindow->theme->get_image("title_bg_data")->get_h();
1419 if(side == EDIT_OUT)
1426 void TrackCanvas::get_transition_coords(Edit *edit,
1427 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1429 int transition_w = 30, transition_h = 30;
1430 int has_titles = edit->track->show_titles();
1431 int has_assets = edit->track->show_assets();
1432 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
1433 double asset_h = resource_h();
1434 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
1435 double dy = has_titles ?
1436 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) :
1437 ( has_assets ? asset_h/2 : 0) ;
1438 double title_h = mwindow->theme->title_h;
1439 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
1442 x -= transition_w / 2;
1443 y -= transition_h / 2;
1448 void TrackCanvas::draw_highlighting()
1453 switch(mwindow->session->current_operation)
1455 case DRAG_ATRANSITION:
1456 case DRAG_VTRANSITION:
1457 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1458 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1459 if(mwindow->session->edit_highlighted) {
1460 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1461 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1462 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1463 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1464 edit_dimensions(mwindow->session->edit_highlighted,
1466 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1467 MWindowGUI::visible(y, y + h, 0, get_h())) {
1469 get_transition_coords(mwindow->session->edit_highlighted,
1476 // Dragging a new effect from the Resource window
1479 if(mwindow->session->track_highlighted &&
1480 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1481 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1482 (mwindow->session->current_operation == DRAG_VEFFECT &&
1483 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1484 // Put it before another plugin
1485 if(mwindow->session->plugin_highlighted) {
1486 plugin_dimensions(mwindow->session->plugin_highlighted,
1488 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1490 // Put it after a plugin set
1491 else if( mwindow->session->pluginset_highlighted &&
1492 mwindow->session->pluginset_highlighted->last ) {
1493 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1495 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1496 int64_t track_x, track_y, track_w, track_h;
1497 track_dimensions(mwindow->session->track_highlighted,
1498 track_x, track_y, track_w, track_h);
1502 mwindow->session->track_highlighted->get_length() *
1503 mwindow->edl->session->sample_rate /
1504 mwindow->edl->local_session->zoom_sample -
1505 mwindow->edl->local_session->view_start[pane->number]) -
1507 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1508 if(w <= 0) w = track_w;
1511 track_dimensions(mwindow->session->track_highlighted,
1514 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1515 // Put it in a new plugin set determined by the selected range
1516 if(mwindow->edl->local_session->get_selectionend() >
1517 mwindow->edl->local_session->get_selectionstart()) {
1518 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1519 mwindow->edl->session->sample_rate /
1520 mwindow->edl->local_session->zoom_sample -
1521 mwindow->edl->local_session->view_start[pane->number]);
1522 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1523 mwindow->edl->local_session->get_selectionstart()) *
1524 mwindow->edl->session->sample_rate /
1525 mwindow->edl->local_session->zoom_sample);
1527 // Put it in a new plugin set determined by an edit boundary
1528 else if(mwindow->session->edit_highlighted) {
1529 int64_t temp_y, temp_h;
1530 edit_dimensions(mwindow->session->edit_highlighted,
1531 x, temp_y, w, temp_h);
1533 // Put it at the beginning of the track in a new plugin set
1536 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1537 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1538 //printf("TrackCanvas::draw_highlighting 1\n");
1545 if(mwindow->session->track_highlighted) {
1546 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1548 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1550 draw_paste_destination();
1556 if(mwindow->session->track_highlighted) {
1557 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1559 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1560 draw_paste_destination();
1565 if( mwindow->session->track_highlighted && mwindow->session->drag_group &&
1566 mwindow->session->drag_group_edit && mwindow->session->drag_group_first_track ) {
1567 Track *track = mwindow->session->track_highlighted;
1568 EDL *drag_group = mwindow->session->drag_group;
1569 Track *edit_track = mwindow->session->drag_group_edit->track;
1570 Track *drag_track = mwindow->session->drag_group_first_track;
1571 while( track && edit_track && edit_track != drag_track ) {
1572 edit_track = edit_track->previous;
1573 track = track->previous;
1575 int color = track && test_track_group(drag_group, track) ? GREEN : RED;
1576 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1577 int dx = get_cursor_x() - mwindow->session->drag_origin_x;
1578 int dy = y - mwindow->session->drag_origin_y;
1579 draw_selected_edits(mwindow->edl, dx, dy, color, -1);
1582 // Dragging an effect from the timeline
1583 case DRAG_AEFFECT_COPY:
1584 case DRAG_VEFFECT_COPY:
1585 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1586 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1587 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1588 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1589 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1591 int64_t plugin_position = -1;
1592 Plugin *drag_plugin = mwindow->session->drag_plugin;
1593 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1594 Track *hi_track = mwindow->session->track_highlighted;
1595 Edit *hi_edit = mwindow->session->edit_highlighted;
1596 // Put it into a silence zone
1597 if( hi_plugin_set && hi_plugin_set->last &&
1598 hi_plugin_set->track == drag_plugin->track ) {
1599 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1600 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1601 hi_track = drag_plugin->track;
1603 else if( hi_track ) {
1604 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1605 track_dimensions(hi_track, x, y, w, h);
1606 plugin_position = hi_edit ? hi_edit->startproject : 0;
1609 if( plugin_position < 0 ) break;
1611 // Calculate length of plugin based on data type of track and units
1612 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1613 mwindow->edl->local_session->zoom_sample;
1614 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1615 mwindow->edl->local_session->view_start[pane->number];
1616 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1618 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1619 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1625 case DRAG_PLUGINKEY:
1626 if(mwindow->session->plugin_highlighted &&
1627 mwindow->session->current_operation == DRAG_PLUGINKEY)
1629 // Just highlight the plugin
1630 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1632 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1633 MWindowGUI::visible(y, y + h, 0, get_h()))
1643 draw_highlight_rectangle(x, y, w, h);
1645 draw_selected_edits(mwindow->edl, 0, 0, GREEN+BLUE, RED);
1648 void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1)
1650 for( Track *track=edl->tracks->first; track; track=track->next ) {
1651 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1652 if( !edit->is_selected ) continue;
1654 edit_dimensions(edit, x, y, w, h);
1656 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue;
1657 if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
1659 int inner = color1 < 0 ? color0 : !edit->group_id ? color0 :
1660 mwindow->get_group_color(edit->group_id);
1662 draw_rectangle(x, y, w, h);
1663 int outer = color1 < 0 ? color0 : !edit->group_id ? color1 : inner;
1665 draw_rectangle(x-1, y-1, w+2, h+2);
1670 void TrackCanvas::draw_plugins()
1672 char string[BCTEXTLEN];
1674 int current_show = 0;
1675 int current_preset = 0;
1677 for(int i = 0; i < plugin_on_toggles.total; i++)
1678 plugin_on_toggles.values[i]->in_use = 0;
1679 for(int i = 0; i < plugin_show_toggles.total; i++)
1680 plugin_show_toggles.values[i]->in_use = 0;
1681 for(int i = 0; i < preset_edit_buttons.total; i++)
1682 plugin_show_toggles.values[i]->in_use = 0;
1685 for(Track *track = mwindow->edl->tracks->first;
1687 track = track->next)
1689 if(track->expand_view)
1691 for(int i = 0; i < track->plugin_set.total; i++)
1693 PluginSet *pluginset = track->plugin_set.values[i];
1695 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1697 int64_t total_x, y, total_w, h;
1698 plugin_dimensions(plugin, total_x, y, total_w, h);
1700 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1701 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1702 plugin->plugin_type != PLUGIN_NONE)
1704 int x = total_x, w = total_w, left_margin = 5;
1705 int right_margin = 5;
1711 if(w + x > get_w()) w -= (w + x) - get_w();
1718 mwindow->theme->get_image("plugin_bg_data"),
1720 set_color(mwindow->theme->title_color);
1721 set_font(mwindow->theme->title_font);
1722 plugin->calculate_title(string, 0);
1724 // Truncate string to int64_test visible in background
1725 int len = strlen(string), j;
1726 for(j = len; j >= 0; j--)
1728 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1736 // Justify the text on the left boundary of the edit if it is visible.
1737 // Otherwise justify it on the left side of the screen.
1738 int64_t text_x = total_x + left_margin;
1739 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1740 text_x = MAX(left_margin, text_x);
1742 y + get_text_ascent(mwindow->theme->title_font) + 2,
1746 int64_t min_x = total_x + text_w;
1749 // Update plugin toggles
1750 int toggle_x = total_x + total_w;
1752 toggle_x = MIN(get_w() - right_margin, toggle_x);
1755 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1756 if(toggle_x > min_x)
1758 if(current_on >= plugin_on_toggles.total)
1760 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1761 add_subwindow(plugin_on);
1762 plugin_on_toggles.append(plugin_on);
1766 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1771 // Toggles for standalone plugins only
1772 if(plugin->plugin_type == PLUGIN_STANDALONE)
1775 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1776 if(toggle_x > min_x)
1778 if(current_show >= plugin_show_toggles.total)
1780 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1781 add_subwindow(plugin_show);
1782 plugin_show_toggles.append(plugin_show);
1786 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1790 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1791 if(toggle_x > min_x)
1793 if(current_preset >= preset_edit_buttons.total)
1795 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1796 add_subwindow(preset_edit);
1797 preset_edit_buttons.append(preset_edit);
1801 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1812 // Remove unused toggles
1814 while(current_preset < preset_edit_buttons.total)
1816 preset_edit_buttons.remove_object_number(current_preset);
1818 while(current_show < plugin_show_toggles.total)
1820 plugin_show_toggles.remove_object_number(current_show);
1823 while(current_on < plugin_on_toggles.total)
1825 plugin_on_toggles.remove_object_number(current_on);
1829 void TrackCanvas::refresh_plugintoggles()
1831 for(int i = 0; i < plugin_on_toggles.total; i++)
1833 PluginOn *on = plugin_on_toggles.values[i];
1834 on->reposition_window(on->get_x(), on->get_y());
1836 for(int i = 0; i < plugin_show_toggles.total; i++)
1838 PluginShow *show = plugin_show_toggles.values[i];
1839 show->reposition_window(show->get_x(), show->get_y());
1841 for(int i = 0; i < preset_edit_buttons.total; i++)
1843 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1844 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1848 void TrackCanvas::draw_hard_edges()
1852 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1853 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1854 if( !edit->hard_left && !edit->hard_right ) continue;
1855 edit_dimensions(edit, x, y, w, h);
1859 if( track->show_titles() )
1860 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
1861 if( track->show_assets() )
1864 y1 += mwindow->theme->title_h;
1865 if( edit->hard_left ) {
1866 ArrayList<int> xpt, ypt;
1867 xpt.append(x); ypt.append(y1);
1868 xpt.append(x+HANDLE_W); ypt.append(y1);
1869 xpt.append(x); ypt.append(y1-HANDLE_H);
1870 fill_polygon(&xpt, &ypt);
1872 if( edit->hard_right ) {
1873 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1874 xpt.append(x1); ypt.append(y1);
1875 xpt.append(x1-HANDLE_W); ypt.append(y1);
1876 xpt.append(x1); ypt.append(y1-HANDLE_H);
1877 fill_polygon(&xpt, &ypt);
1883 void TrackCanvas::draw_inout_points()
1888 void TrackCanvas::draw_drag_handle()
1890 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1891 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1893 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1894 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1895 mwindow->edl->session->sample_rate /
1896 mwindow->edl->local_session->zoom_sample -
1897 mwindow->edl->local_session->view_start[pane->number]);
1898 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1899 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1901 //printf("TrackCanvas::draw_drag_handle 3\n");
1902 draw_line(pixel1, 0, pixel1, get_h());
1904 //printf("TrackCanvas::draw_drag_handle 4\n");
1909 void TrackCanvas::draw_transitions()
1913 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1914 if( !track->show_transitions() ) continue;
1916 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1917 if(!edit->transition) continue;
1918 edit_dimensions(edit, x, y, w, h);
1919 int strip_x = x, edit_y = y;
1920 get_transition_coords(edit, x, y, w, h);
1921 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
1922 if( track->show_assets() && track->show_titles() )
1923 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
1924 if( strip_y < edit_y ) strip_y = edit_y;
1926 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1927 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1928 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1929 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1930 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1932 if( !server ) continue;
1933 VFrame *picon = server->get_picon();
1934 if( !picon ) continue;
1935 int picon_w = picon->get_w(), picon_h = picon->get_h();
1936 int track_h = edit->track->vertical_span(mwindow->theme);
1937 if( picon_h > track_h ) picon_h = track_h;
1938 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
1940 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1941 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
1942 int x = strip_x, w = strip_w;
1943 if( x < 0 ) { w -= -x; x = 0; }
1944 if( w + x > get_w() ) w -= (w + x) - get_w();
1946 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1947 mwindow->theme->get_image("plugin_bg_data"), 0);
1953 void TrackCanvas::draw_loop_points()
1955 //printf("TrackCanvas::draw_loop_points 1\n");
1956 if(mwindow->edl->local_session->loop_playback)
1958 //printf("TrackCanvas::draw_loop_points 2\n");
1959 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1960 mwindow->edl->session->sample_rate /
1961 mwindow->edl->local_session->zoom_sample -
1962 mwindow->edl->local_session->view_start[pane->number]);
1963 //printf("TrackCanvas::draw_loop_points 3\n");
1965 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1968 draw_line(x, 0, x, get_h());
1970 //printf("TrackCanvas::draw_loop_points 4\n");
1972 x = Units::round(mwindow->edl->local_session->loop_end *
1973 mwindow->edl->session->sample_rate /
1974 mwindow->edl->local_session->zoom_sample -
1975 mwindow->edl->local_session->view_start[pane->number]);
1976 //printf("TrackCanvas::draw_loop_points 5\n");
1978 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1981 draw_line(x, 0, x, get_h());
1983 //printf("TrackCanvas::draw_loop_points 6\n");
1985 //printf("TrackCanvas::draw_loop_points 7\n");
1988 void TrackCanvas::draw_brender_range()
1990 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1991 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1992 if( mwindow->edl->session->brender_end > 0 )
1994 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1995 mwindow->edl->session->sample_rate /
1996 mwindow->edl->local_session->zoom_sample -
1997 mwindow->edl->local_session->view_start[pane->number]);
1998 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
2001 draw_line(x1, 0, x1, get_h());
2003 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
2004 mwindow->edl->session->sample_rate /
2005 mwindow->edl->local_session->zoom_sample -
2006 mwindow->edl->local_session->view_start[pane->number]);
2008 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
2011 draw_line(x2, 0, x2, get_h());
2016 // The operations which correspond to each automation type
2017 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
2033 // The buttonpress operations, so nothing changes unless the mouse moves
2034 // a certain amount. This allows the keyframe to be used to position the
2035 // insertion point without moving itself.
2036 static int pre_auto_operations[AUTOMATION_TOTAL] =
2053 int TrackCanvas::do_keyframes(int cursor_x,
2061 // Note: button 3 (right mouse button) is not eaten to allow
2062 // track context menu to appear
2064 EDLSession *session = mwindow->edl->session;
2068 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
2070 0, 0, 0, 0, 0, 0, 0, 0,
2072 modekeyframe_pixmap,
2073 maskkeyframe_pixmap,
2078 for(Track *track = mwindow->edl->tracks->first;
2080 track = track->next) {
2081 Auto *auto_keyframe = 0;
2082 Automation *automation = track->automation;
2085 // Handle keyframes in reverse drawing order if a button press
2087 int end = AUTOMATION_TOTAL;
2091 start = AUTOMATION_TOTAL - 1;
2095 for(int i = start; i != end && !result; i += step)
2097 // Event not trapped and automation visible
2098 Autos *autos = automation->autos[i];
2099 if(!result && session->auto_conf->autos[i] && autos) {
2101 case AUTOMATION_MODE:
2102 case AUTOMATION_PAN:
2103 case AUTOMATION_MASK:
2104 result = do_autos(track, automation->autos[i],
2105 cursor_x, cursor_y, draw,
2106 buttonpress, auto_pixmaps[i],
2107 auto_keyframe, rerender);
2111 switch(autos->get_type()) {
2112 case Autos::AUTOMATION_TYPE_FLOAT: {
2113 Automation automation(0, track);
2114 int grouptype = automation.autogrouptype(i, track);
2115 if( buttonpress && i == AUTOMATION_SPEED ) {
2116 mwindow->speed_before();
2119 if(draw) // Do dropshadow
2120 result = do_float_autos(track, autos,
2121 cursor_x, cursor_y, draw,
2122 buttonpress, 1, 1, MDGREY,
2123 auto_keyframe, grouptype);
2124 result = do_float_autos(track, autos,
2125 cursor_x, cursor_y, draw, buttonpress,
2126 0, 0, GWindowGUI::auto_colors[i],
2127 auto_keyframe, grouptype);
2129 if( !result && buttonpress && i == AUTOMATION_SPEED )
2130 mwindow->speed_after(-1);
2131 int current_grouptype = mwindow->edl->local_session->zoombar_showautotype;
2132 if( result && buttonpress && grouptype != current_grouptype ) {
2133 mwindow->edl->local_session->zoombar_showautotype = grouptype;
2134 mwindow->gui->zoombar->update_autozoom();
2138 case Autos::AUTOMATION_TYPE_INT: {
2139 if(draw) // Do dropshadow
2140 result = do_int_autos(track, autos,
2141 cursor_x, cursor_y, draw,
2142 buttonpress, 1, 1, MDGREY,
2144 result = do_int_autos(track, autos,
2145 cursor_x, cursor_y, draw, buttonpress,
2146 0, 0, GWindowGUI::auto_colors[i],
2155 if(mwindow->session->current_operation == auto_operations[i])
2158 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2160 // mwindow->session->current_operation,
2161 // auto_operations[i]);
2164 if (buttonpress == 2 && auto_keyframe )
2166 double position = track->from_units(auto_keyframe->position);
2167 mwindow->edl->local_session->set_selectionstart(position);
2168 mwindow->edl->local_session->set_selectionend(position);
2170 if (buttonpress != 3)
2172 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2173 fill_ganged_autos(get_double_click(), 0, track,
2174 (FloatAuto*)mwindow->session->drag_auto);
2175 mwindow->session->current_operation = pre_auto_operations[i];
2176 update_drag_caption();
2179 else if( auto_keyframe )
2181 gui->keyframe_menu->update(automation,
2184 gui->keyframe_menu->activate_menu();
2185 rerender = 1; // the position changes
2189 gui->keyframe_hide->update(autos);
2190 gui->keyframe_hide->activate_menu();
2191 rerender = 1; // the position changes
2193 if(buttonpress == 1 && ctrl_down() &&
2194 AUTOMATION_TYPE_FLOAT == autos->get_type())
2195 rerender = 1; // special case: curve mode changed
2201 if(!result && session->auto_conf->plugins) {
2204 result = do_plugin_autos(track, cursor_x, cursor_y,
2205 draw, buttonpress, plugin, keyframe);
2206 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2209 if(result && (buttonpress == 1)) {
2210 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2211 update_drag_caption();
2214 else if (result && (buttonpress == 3)) {
2215 gui->keyframe_menu->update(plugin, keyframe);
2216 gui->keyframe_menu->activate_menu();
2217 rerender = 1; // the position changes
2222 // Final pass to trap event
2223 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2224 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2225 mwindow->session->current_operation == auto_operations[i]) {
2231 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2232 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2238 new_cursor = UPRIGHT_ARROW_CURSOR;
2245 void TrackCanvas::draw_keyframe_reticle()
2247 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2248 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2250 int current_op = mwindow->session->current_operation, dragging = 0;
2251 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2252 if( current_op == auto_operations[i] ) dragging = 1;
2253 if( dragging && !mwindow->session->drag_auto ) dragging = 0;
2255 int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
2256 mwindow->session->drag_auto->autos->autoidx : -1;
2258 if( get_buttonpress() == 1 && dragging &&
2259 keyframe_hairline == HAIRLINE_DRAGGING ) {
2260 draw_hairline(mwindow->session->drag_auto, RED, 1);
2264 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2265 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2266 int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
2267 for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
2268 Automation *automation = track->automation;
2269 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2270 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2271 // automation visible
2272 Autos *autos = automation->autos[i];
2273 if( !autos ) continue;
2274 if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
2275 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2276 auto_keyframe = auto_keyframe->next ) {
2277 draw_hairline(auto_keyframe, BLUE, show);
2283 draw_hairline(mwindow->session->drag_auto, RED, 1);
2287 void TrackCanvas::draw_auto(Auto *current,
2295 x1 = x - HANDLE_W / 2;
2296 x2 = x + HANDLE_W / 2;
2297 y1 = center_pixel + y - HANDLE_W / 2;
2298 y2 = center_pixel + y + HANDLE_W / 2;
2300 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2301 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2303 draw_box(x1, y1, x2 - x1, y2 - y1);
2307 // This draws lines for bezier in & out controls
2308 void TrackCanvas::draw_cropped_line(int x1,
2317 // Don't care about x since it is clipped by the window.
2318 // Put y coords in ascending order
2320 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2321 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2326 double slope = (double)(x2 - x1) / (y2 - y1);
2327 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2329 x1 = (int)(x1 + (min_y - y1) * slope);
2332 else if(y1 >= max_y) {
2333 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2338 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2341 else if(y2 < min_y) {
2342 x2 = (int)(x2 + (min_y - y2) * slope);
2347 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2348 if( y1 >= min_y && y1 < max_y &&
2349 y2 >= min_y && y2 < max_y )
2350 draw_line(x1, y1, x2, y2);
2354 void TrackCanvas::draw_floatauto(FloatAuto *current,
2365 int x1 = x - HANDLE_W / 2; // Center
2366 int x2 = x + HANDLE_W / 2;
2367 int y1 = center_pixel + y - HANDLE_H / 2;
2368 int y2 = center_pixel + y + HANDLE_H / 2;
2369 int ymin = center_pixel - zoom_track / 2;
2370 int ymax = center_pixel + zoom_track / 2;
2371 CLAMP(y1, ymin, ymax);
2372 CLAMP(y2, ymin, ymax);
2377 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2379 draw_box(x1, y1, x2 - x1, y2 - y1);
2382 // show bezier control points (only) if this
2383 // floatauto doesn't adjust it's tangents automatically
2384 if(current->curve_mode != FloatAuto::FREE &&
2385 current->curve_mode != FloatAuto::TFREE)
2389 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2391 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2394 inline int quantize(float f) { return (int)floor(f + 0.5); }
2396 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2397 int x, int y, int cp_x, int cp_y, int center_pixel,
2398 int zoom_track, int color)
2399 // draw the tangent and a handle for given bézier ctrl point
2401 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2403 float slope = (float)(cp_y - y)/(cp_x - x);
2404 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2406 cp_x = x + quantize((cp_y - y) / slope);
2409 cp_y += center_pixel;
2411 // drawing the tangent as a dashed line...
2412 int const dash = HANDLE_W;
2413 int const gap = HANDLE_W / 2;
2414 float sx = 3 * (cp_x - x) / 4.;
2417 // q is the x displacement for a unit line of slope
2418 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2420 float dist = 1/q * sx;
2426 float sy = slope * sx, ey = slope * ex;
2427 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2434 int r = HANDLE_W / 2;
2435 int cp_x1 = cp_x - r;
2436 int cp_y1 = cp_y - r;
2438 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2440 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2445 int TrackCanvas::test_auto(Auto *current,
2446 int x, int y, int center_pixel, int zoom_track,
2447 int cursor_x, int cursor_y, int buttonpress)
2452 x1 = x - HANDLE_W / 2;
2453 x2 = x + HANDLE_W / 2;
2454 y1 = center_pixel + y - HANDLE_H / 2;
2455 y2 = center_pixel + y + HANDLE_H / 2;
2456 int ymin = center_pixel - zoom_track / 2;
2457 int ymax = center_pixel + zoom_track / 2;
2458 CLAMP(y1, ymin, ymax);
2459 CLAMP(y2, ymin, ymax);
2461 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2463 if(buttonpress && buttonpress != 3)
2465 mwindow->session->drag_auto = current;
2466 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2467 // Toggle Autos don't respond to vertical zoom, they always show up
2468 // with "on" == 100% == line on top
2469 mwindow->session->drag_start_position = current->position;
2470 mwindow->session->drag_origin_x = cursor_x;
2471 mwindow->session->drag_origin_y = cursor_y;
2476 if(buttonpress && buttonpress != 3 && result)
2478 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2479 mwindow->undo->update_undo_before();
2485 // some Helpers for test_floatauto(..)
2486 // and for dragging the tangents/ctrl points
2487 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2488 float cursor_x, float cursor_y)
2490 // Control point switched off?
2491 if( x0 == ctrl_x ) return 0.0;
2492 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2493 double x = cursor_x-x0, y = cursor_y-y0;
2494 // wrong side of ctrl handle
2495 if( x*x1 < 0 ) return 0.0;
2496 // outside handle radius
2497 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2498 double xx1 = x1*x1, yy1 = y1*y1;
2499 double xx = x*x, yy = y*y;
2500 // distance squared from cursor to cursor projected to line from ctrl to handle
2501 // along a line perpendicular to line from ctrl to handle (closest approach)
2502 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2503 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2504 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2509 float levered_position(float position, float ref_pos)
2511 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2513 return ref_pos / position;
2517 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2518 // transforms automation value into current display coords,
2519 // dependant on current automation display range for the given kind of automation
2521 if(!mwindow || !mwindow->edl) return 0;
2522 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2523 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2524 float automation_range = automation_max - automation_min;
2525 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2527 return (auto_value - automation_min) / automation_range;
2532 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2533 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2534 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2538 int x1 = x - HANDLE_W / 2;
2539 int x2 = x + HANDLE_W / 2;
2540 int y1 = center_pixel + y - HANDLE_W / 2;
2541 int y2 = center_pixel + y + HANDLE_W / 2;
2542 int ymin = center_pixel - zoom_track / 2;
2543 int ymax = center_pixel + zoom_track / 2;
2544 CLAMP(y1, ymin, ymax);
2545 CLAMP(y2, ymin, ymax);
2547 int in_x1 = in_x - HANDLE_W / 2;
2548 int in_x2 = in_x + HANDLE_W / 2;
2549 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2550 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2551 CLAMP(in_y1, ymin, ymax);
2552 CLAMP(in_y2, ymin, ymax);
2554 int out_x1 = out_x - HANDLE_W / 2;
2555 int out_x2 = out_x + HANDLE_W / 2;
2556 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2557 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2558 CLAMP(out_y1, ymin, ymax);
2559 CLAMP(out_y2, ymin, ymax);
2562 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2563 // buttonpress could be the start of a drag operation
2564 #define INIT_DRAG(POS,VAL) \
2565 mwindow->session->drag_auto = current; \
2566 mwindow->session->drag_origin_x = cursor_x; \
2567 mwindow->session->drag_origin_y = cursor_y; \
2568 mwindow->session->drag_start_position = (POS); \
2569 mwindow->session->drag_start_percentage = (VAL);
2571 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2574 // without modifier we are manipulating the automation node
2575 // with ALT it's about dragging only the value of the node
2576 // with SHIFT the value snaps to the value of neighbouring nodes
2577 // CTRL indicates we are rather manipulating the tangent(s) of the node
2581 if( WITHIN(x1,x2,y1,y2))
2582 { // cursor hits node
2585 if(buttonpress && (buttonpress != 3))
2587 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2588 mwindow->session->drag_handle = 0;
2593 if( WITHIN(x1,x2,y1,y2))
2596 if(buttonpress && (buttonpress != 3))
2598 // could be ctrl-click or ctrl-drag
2599 // click would cycle through tangent modes
2600 ((FloatAuto*)current)->toggle_curve_mode();
2602 // drag will start dragging the tangent, if applicable
2603 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2604 mwindow->session->drag_handle = 0;
2608 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2611 if( in_x != x && current->position > 0 &&
2612 (FloatAuto::FREE == current->curve_mode ||
2613 FloatAuto::TFREE == current->curve_mode))
2614 // act on in control handle only if
2615 // tangent is significant and is editable (not automatically choosen)
2617 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2618 // either cursor in ctrl-point handle or cursor on tangent line
2619 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2621 if(buttonpress && (buttonpress != 3)) {
2622 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2624 mwindow->session->drag_handle = 1;
2625 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2626 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2627 value_to_percentage(new_invalue, autogrouptype))
2634 (FloatAuto::FREE == current->curve_mode ||
2635 FloatAuto::TFREE == current->curve_mode))
2636 // act on out control only if tangent is significant and is editable
2638 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2639 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2641 if(buttonpress && (buttonpress != 3)) {
2642 if(lever == 0.0) lever=1.0;
2644 mwindow->session->drag_handle = 2;
2645 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2646 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2647 value_to_percentage(new_outvalue, autogrouptype))
2651 } // end ctrl_down()
2657 // 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",
2658 // mwindow->session->drag_handle,
2663 if(buttonpress && (buttonpress != 3) && result)
2665 mwindow->undo->update_undo_before();
2672 // Get the float value & y for position x on the canvas
2673 #define X_TO_FLOATLINE(x) \
2674 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2675 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2676 /* Call by reference fails for some reason here */ \
2677 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2678 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2679 double position = unit_start + x * zoom_units; \
2681 if(position2 > position1) \
2684 (value2 - value1) * \
2685 (position - position1) / \
2686 (position2 - position1); \
2692 AUTOMATIONCLAMPS(value, autogrouptype); \
2693 int y = center_pixel + \
2694 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2697 void TrackCanvas::draw_floatline(int center_pixel,
2698 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2699 double unit_start, double zoom_units, double yscale,
2700 int x1, int y1, int x2, int y2,
2701 int color, int autogrouptype)
2703 // Solve bezier equation for either every pixel or a certain large number of
2706 // Not using slope intercept
2708 int prev_y = y1 + center_pixel;
2711 // Call by reference fails for some reason here
2712 FloatAuto *previous1 = previous, *next1 = next;
2713 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2714 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2715 float automation_range = automation_max - automation_min;
2717 for(int x = x1; x < x2; x++)
2719 // Interpolate value between frames
2723 y >= center_pixel - yscale / 2 &&
2724 y < center_pixel + yscale / 2 - 1)
2726 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2728 // (int)(center_pixel - yscale / 2),
2729 // (int)(center_pixel + yscale / 2 - 1));
2731 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2732 draw_line(x - 1, prev_y , x, y );
2742 int TrackCanvas::test_floatline(int center_pixel,
2757 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2758 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2759 float automation_range = automation_max - automation_min;
2760 FloatAuto *previous1 = 0, *next1 = 0;
2761 X_TO_FLOATLINE(cursor_x);
2763 if(cursor_x >= x1 &&
2765 cursor_y >= y - HANDLE_W / 2 &&
2766 cursor_y < y + HANDLE_W / 2 &&
2772 if(buttonpress == 3)
2780 mwindow->undo->update_undo_before();
2781 double position = autos->track->from_units(position1);
2782 position = mwindow->edl->align_to_frame(position, 0);
2783 int64_t new_position = autos->track->to_units(position,0);
2784 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2785 ((FloatAuto*)current)->set_value(value);
2786 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2787 mwindow->session->drag_start_position = current->position;
2788 mwindow->session->drag_origin_x = cursor_x;
2789 mwindow->session->drag_origin_y = cursor_y;
2790 mwindow->session->drag_handle = 0;
2799 void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto)
2801 if( !skip->gang ) return;
2802 // Handles the special case of modifying a fadeauto
2803 // when there are ganged faders on several tracks
2804 double position = skip->from_units(fauto->position);
2805 int autoidx = fauto->autos->autoidx;
2807 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2808 if( (all || current->data_type == skip->data_type) &&
2809 current->gang && current->record && current != skip ) {
2810 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2811 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2812 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2813 int64_t current_position = current->to_units(position, 1);
2814 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
2816 // keyframe exists, just change it
2817 float value = keyframe->get_value();
2818 float new_value = value + change;
2819 CLAMP(new_value, auto_min, auto_max);
2820 keyframe->adjust_to_new_coordinates(current_position, new_value);
2823 // create keyframe on neighbouring track at the point in time given by fauto
2824 FloatAuto *previous = 0, *next = 0;
2825 float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2826 float new_value = value + change;
2827 CLAMP(new_value, auto_min, auto_max);
2828 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2829 keyframe->set_value(new_value);
2831 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2836 void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
2838 double position = skip->from_units(fauto->position);
2840 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2841 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2842 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2843 float new_value = keyframe->get_value() + change;
2845 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2846 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2847 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2851 void TrackCanvas::clear_ganged_autos()
2854 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2855 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2856 keyframe->autos->remove_nonsequential(keyframe);
2858 mwindow->session->drag_auto_gang->remove_all();
2862 void TrackCanvas::draw_toggleline(int center_pixel,
2868 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2872 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2876 int TrackCanvas::test_toggleline(Autos *autos,
2887 if(cursor_x >= x1 && cursor_x < x2)
2889 int miny = center_pixel + y1 - HANDLE_W / 2;
2890 int maxy = center_pixel + y1 + HANDLE_W / 2;
2891 if(cursor_y >= miny && cursor_y < maxy)
2896 if(buttonpress == 3)
2904 double position = (double)(cursor_x +
2905 mwindow->edl->local_session->view_start[pane->number]) *
2906 mwindow->edl->local_session->zoom_sample /
2907 mwindow->edl->session->sample_rate;
2908 int64_t unit_position = autos->track->to_units(position, 0);
2909 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2911 mwindow->undo->update_undo_before();
2913 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2914 ((IntAuto*)current)->value = new_value;
2915 // Toggle Autos don't respond to vertical zoom, they always show up
2916 // with "on" == 100% == line on top
2917 mwindow->session->drag_start_percentage = (float)new_value;
2918 mwindow->session->drag_start_position = current->position;
2919 mwindow->session->drag_origin_x = cursor_x;
2920 mwindow->session->drag_origin_y = cursor_y;
2928 void TrackCanvas::calculate_viewport(Track *track,
2929 double &view_start, // Seconds
2931 double &view_end, // Seconds
2935 double &zoom_sample,
2939 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2940 mwindow->edl->local_session->zoom_sample /
2941 mwindow->edl->session->sample_rate;
2942 unit_start = track->to_doubleunits(view_start);
2943 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2945 mwindow->edl->local_session->zoom_sample /
2946 mwindow->edl->session->sample_rate;
2947 unit_end = track->to_doubleunits(view_end);
2949 int y = track->y_pixel
2950 - mwindow->edl->local_session->track_start[pane->number];
2951 int has_titles = track->show_titles();
2952 int has_assets = track->show_assets();
2953 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
2954 double asset_h = resource_h();
2955 double title_h = mwindow->theme->title_h;
2956 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
2957 double dy = has_titles ?
2958 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) :
2959 ( has_assets ? asset_h/2 : 0) ;
2960 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
2962 center_pixel = y + dy;
2964 zoom_sample = mwindow->edl->local_session->zoom_sample;
2965 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2968 float TrackCanvas::percentage_to_value(float percentage,
2976 if(percentage > 0.5)
2983 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2984 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2985 float automation_range = automation_max - automation_min;
2987 result = percentage * automation_range + automation_min;
2990 FloatAuto *ptr = (FloatAuto*)reference;
2991 result -= ptr->get_value();
2993 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2999 void TrackCanvas::calculate_auto_position(double *x, double *y,
3000 double *in_x, double *in_y, double *out_x, double *out_y,
3001 Auto *current, double unit_start, double zoom_units, double yscale,
3004 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3005 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3006 float automation_range = automation_max - automation_min;
3007 FloatAuto *ptr = (FloatAuto*)current;
3008 *x = (double)(ptr->position - unit_start) / zoom_units;
3009 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
3012 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
3013 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
3017 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
3018 automation_min) / automation_range - 0.5) * -yscale;
3022 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
3023 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
3027 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
3028 automation_min) / automation_range - 0.5) * -yscale;
3033 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
3034 int draw, int buttonpress, int x_offset, int y_offset, int color,
3035 Auto* &auto_instance, int autogrouptype)
3038 int center_pixel, draw_auto;
3039 double view_start, unit_start;
3040 double view_end, unit_end, yscale;
3041 double zoom_sample, zoom_units;
3042 double in_x2, in_y2, out_x2, out_y2;
3048 if(draw) set_color(color);
3050 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3051 yscale, center_pixel, zoom_sample, zoom_units);
3053 // Get first auto before start
3054 Auto *current = 0, *previous = 0;
3056 for( current = autos->last;
3057 current && current->position >= unit_start;
3058 current = PREVIOUS ) ;
3060 Auto *first_auto = current ? current :
3061 autos->first ? autos->first : autos->default_auto;
3063 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
3065 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3066 first_auto, unit_start, zoom_units, yscale, autogrouptype);
3071 current = autos->first;
3080 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
3081 current, unit_start, zoom_units, yscale, autogrouptype);
3089 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3094 ay2 = ay + slope * (get_w() - ax);
3098 ay = ay + slope * (0 - ax);
3102 // Draw or test handle
3103 if( current && !result && current != autos->default_auto ) {
3104 if( !draw && track->record ) {
3105 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3106 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3107 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3108 buttonpress, autogrouptype);
3110 auto_instance = current;
3112 if( draw && draw_auto ) {
3113 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3114 (int)in_x2 + x_offset, (int)in_y2,
3115 (int)out_x2 + x_offset, (int)out_y2,
3116 (int)center_pixel + y_offset, (int)yscale, color);
3120 // Draw or test joining line
3121 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3122 result = test_floatline(center_pixel,
3123 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3124 // Exclude auto coverage from the end of the line. The auto overlaps
3125 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3126 buttonpress, autogrouptype);
3129 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3130 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3131 (int)ax, (int)ay, (int)ax2, (int)ay2,
3132 color, autogrouptype);
3140 } while( current && current->position <= unit_end && !result );
3142 if( ax < get_w() && !result ) {
3143 ax2 = get_w(); ay2 = ay;
3144 if(!draw && track->record /* && buttonpress != 3 */ ) {
3145 result = test_floatline(center_pixel,
3146 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3147 (int)ax, (int)ax2, cursor_x, cursor_y,
3148 buttonpress, autogrouptype);
3151 draw_floatline(center_pixel,
3152 (FloatAuto*)previous, (FloatAuto*)current,
3153 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3154 (int)ax, (int)ay, (int)ax2, (int)ay2,
3155 color, autogrouptype);
3162 int TrackCanvas::do_int_autos(Track *track,
3171 Auto *&auto_instance)
3182 double ax, ay, ax2, ay2;
3186 if(draw) set_color(color);
3188 calculate_viewport(track,
3199 double high = -yscale * 0.8 / 2;
3200 double low = yscale * 0.8 / 2;
3202 // Get first auto before start
3204 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3210 ay = ((IntAuto*)current)->value > 0 ? high : low;
3215 current = autos->first ? autos->first : autos->default_auto;
3219 ay = ((IntAuto*)current)->value > 0 ? high : low;
3232 ax2 = (double)(current->position - unit_start) / zoom_units;
3233 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3241 if(ax2 > get_w()) ax2 = get_w();
3243 if(current && !result)
3245 if(current != autos->default_auto)
3251 result = test_auto(current,
3260 auto_instance = current;
3265 (int)ax2 + x_offset,
3266 (int)ay2 + y_offset,
3278 if(track->record /* && buttonpress != 3 */)
3280 result = test_toggleline(autos,
3293 draw_toggleline(center_pixel + y_offset,
3301 }while(current && current->position <= unit_end && !result);
3303 if(ax < get_w() && !result)
3309 if(track->record /* && buttonpress != 3 */)
3311 result = test_toggleline(autos,
3323 draw_toggleline(center_pixel + y_offset,
3332 int TrackCanvas::do_autos(Track *track,
3339 Auto * &auto_instance,
3353 calculate_viewport(track,
3366 for(current = autos->first; current && !result; current = NEXT)
3368 if(current->position >= unit_start && current->position < unit_end)
3371 x = (int64_t)((double)(current->position - unit_start) /
3372 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3373 y = center_pixel - pixmap->get_h() / 2;
3377 if(cursor_x >= x && cursor_y >= y &&
3378 cursor_x < x + pixmap->get_w() &&
3379 cursor_y < y + pixmap->get_h())
3382 auto_instance = current;
3384 if(buttonpress && (buttonpress != 3))
3386 mwindow->session->drag_auto = current;
3387 mwindow->session->drag_start_position = current->position;
3388 mwindow->session->drag_origin_x = cursor_x;
3389 mwindow->session->drag_origin_y = cursor_y;
3391 double position = autos->track->from_units(current->position);
3392 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3393 mwindow->edl->local_session->get_selectionend(1)) /
3398 mwindow->edl->local_session->set_selectionstart(position);
3399 mwindow->edl->local_session->set_selectionend(position);
3402 if(position < center)
3404 mwindow->edl->local_session->set_selectionstart(position);
3407 mwindow->edl->local_session->set_selectionend(position);
3414 draw_pixmap(pixmap, x, y);
3422 // so this means it is always >0 when keyframe is found
3423 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3424 int draw, int buttonpress, Plugin* &keyframe_plugin,
3425 KeyFrame* &keyframe_instance)
3438 if(!track->expand_view) return 0;
3440 calculate_viewport(track,
3452 for(int i = 0; i < track->plugin_set.total && !result; i++)
3454 PluginSet *plugin_set = track->plugin_set.values[i];
3455 int center_pixel = track->y_pixel -
3456 mwindow->edl->local_session->track_start[pane->number];
3457 if( track->show_titles() )
3458 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
3459 if( track->show_assets() )
3460 center_pixel += resource_h();
3461 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
3463 for(Plugin *plugin = (Plugin*)plugin_set->first;
3465 plugin = (Plugin*)plugin->next)
3467 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3468 keyframe && !result;
3469 keyframe = (KeyFrame*)keyframe->next)
3471 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3472 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3474 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3475 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3477 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3480 if(cursor_x >= x && cursor_y >= y &&
3481 cursor_x < x + keyframe_pixmap->get_w() &&
3482 cursor_y < y + keyframe_pixmap->get_h())
3485 keyframe_plugin = plugin;
3486 keyframe_instance = keyframe;
3490 mwindow->session->drag_auto = keyframe;
3491 mwindow->session->drag_start_position = keyframe->position;
3492 mwindow->session->drag_origin_x = cursor_x;
3493 mwindow->session->drag_origin_y = cursor_y;
3495 double position = track->from_units(keyframe->position);
3496 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3497 mwindow->edl->local_session->get_selectionend(1)) /
3502 mwindow->edl->local_session->set_selectionstart(position);
3503 mwindow->edl->local_session->set_selectionend(position);
3506 if(position < center)
3508 mwindow->edl->local_session->set_selectionstart(position);
3511 mwindow->edl->local_session->set_selectionend(position);
3516 draw_pixmap(keyframe_pixmap,
3526 // if(buttonpress && buttonpress != 3 && result)
3528 // mwindow->undo->update_undo_before();
3534 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
3536 Track *track = auto_keyframe->autos->track;
3537 int autogrouptype = auto_keyframe->autos->autogrouptype;
3540 double view_start, unit_start;
3541 double view_end, unit_end, yscale;
3542 double zoom_sample, zoom_units;
3544 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3545 yscale, center_pixel, zoom_sample, zoom_units);
3547 double ax = 0, ay = 0;
3548 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3549 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3552 draw_line(ax, 0, ax, get_h());
3555 char text[BCSTRLEN];
3556 if( auto_keyframe->is_floatauto() ) {
3557 FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
3558 sprintf(text, "%0.2f", float_auto->get_value());
3561 IntAuto *int_auto = (IntAuto *)auto_keyframe;
3562 sprintf(text, "%d", int_auto->value);
3564 int font = MEDIUMFONT;
3565 int tw = get_text_width(font, text) + TOOLTIP_MARGIN * 2;
3566 int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2;
3567 set_color(get_resources()->tooltip_bg_color);
3569 ay += center_pixel + HANDLE_W/2;
3570 draw_box(ax, ay, tw, th);
3572 draw_rectangle(ax, ay, tw, th);
3574 ax += TOOLTIP_MARGIN;
3575 ay += TOOLTIP_MARGIN + get_text_ascent(font);
3576 draw_text(ax, ay, text);
3581 void TrackCanvas::draw_overlays()
3583 int new_cursor, update_cursor, rerender;
3585 // Move background pixmap to foreground pixmap
3586 draw_pixmap(background_pixmap,
3595 draw_inout_points();
3606 draw_brender_range();
3608 // Highlighted areas
3609 draw_highlighting();
3612 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3615 if(pane->cursor) pane->cursor->restore(1);
3621 draw_playback_cursor();
3623 draw_keyframe_reticle();
3628 int TrackCanvas::activate()
3632 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3633 //BC_Signals::dump_stack();
3634 get_top_level()->deactivate();
3636 set_active_subwindow(this);
3637 pane->cursor->activate();
3638 gui->focused_pane = pane->number;
3643 int TrackCanvas::deactivate()
3648 pane->cursor->deactivate();
3654 void TrackCanvas::update_drag_handle()
3656 double new_position;
3657 int cursor_x = get_cursor_x();
3661 mwindow->edl->local_session->view_start[pane->number]) *
3662 mwindow->edl->local_session->zoom_sample /
3663 mwindow->edl->session->sample_rate;
3666 mwindow->edl->align_to_frame(new_position, 0);
3668 if( ctrl_down() && alt_down() ) {
3669 #define snapper(v) do { \
3671 if( pos < 0 ) break; \
3672 double dist = fabs(new_position - pos); \
3673 if( dist >= snap_min ) break; \
3674 snap_position = pos; snap_min = dist; \
3676 double snap_position = new_position;
3677 double snap_min = DBL_MAX;
3678 if( mwindow->edl->local_session->inpoint_valid() )
3679 snapper(mwindow->edl->local_session->get_inpoint());
3680 if( mwindow->edl->local_session->outpoint_valid() )
3681 snapper(mwindow->edl->local_session->get_outpoint());
3682 snapper(mwindow->edl->prev_edit(new_position));
3683 snapper(mwindow->edl->next_edit(new_position));
3684 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3685 if( prev_label ) snapper(prev_label->position);
3686 Label *next_label = mwindow->edl->labels->next_label(new_position);
3687 if( next_label ) snapper(next_label->position);
3688 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3689 mwindow->edl->local_session->zoom_sample -
3690 mwindow->edl->local_session->view_start[pane->number];
3691 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3693 new_position = snap_position;
3698 if(new_position != mwindow->session->drag_position)
3700 mwindow->session->drag_position = new_position;
3701 gui->mainclock->update(new_position);
3702 timebar_position = new_position;
3703 gui->update_timebar(0);
3706 edl->create_objects();
3707 edl->copy_all(mwindow->edl);
3708 MainSession *session = mwindow->session;
3709 int edit_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
3710 edl->modify_edithandles(session->drag_start,
3711 session->drag_position,
3712 session->drag_handle,
3714 edl->session->labels_follow_edits,
3715 edl->session->plugins_follow_edits,
3716 edl->session->autos_follow_edits);
3717 double position = edit_mode != MOVE_NO_EDITS &&
3718 ( session->drag_handle || edit_mode == MOVE_ONE_EDIT ) ?
3719 session->drag_position : session->drag_start;
3720 Track *track = session->drag_handle_track();
3721 int64_t pos = track->to_units(position, 0);
3722 render_handle_frame(edl, pos, shift_down() ? 0 :
3723 session->drag_handle ? 1 : 2);
3728 int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
3731 int64_t left = pos-1;
3732 if( left < 0 ) left = 0;
3735 VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
3736 VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
3737 TransportCommand command;
3738 command.command = CURRENT_FRAME;
3739 command.get_edl()->copy_all((EDL *)edl);
3740 command.change_type = CHANGE_ALL;
3741 command.realtime = 0;
3742 Preferences *preferences = mwindow->preferences;
3743 RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
3744 CICache *video_cache = new CICache(preferences);
3745 render_engine->set_vcache(video_cache);
3746 render_engine->arm_command(&command);
3747 int64_t left = pos-1;
3748 if( left < 0 ) left = 0;
3749 VRender *vrender = render_engine->vrender;
3751 !vrender->process_buffer(&vlt, left, 0) &&
3752 !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1;
3753 delete render_engine;
3755 mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0");
3756 Canvas *canvas = mwindow->cwindow->gui->canvas;
3757 canvas->lock_canvas("TrackCanvas::render_handle_frame 1");
3758 int w = canvas->w, h = canvas->h, w2 = w/2, h2 = h/2;
3759 int lx = 0, ly = h2/2, rx = w2, ry = h2/2;
3760 BC_WindowBase *window = canvas->get_canvas();
3761 window->set_color(BLACK);
3762 window->clear_box(0,0, window->get_w(),window->get_h());
3763 window->draw_vframe(&vlt, lx,ly, w2,h2, 0,0,vlt.get_w(),vlt.get_h());
3764 window->draw_vframe(&vrt, rx,ry, w2,h2, 0,0,vrt.get_w(),vrt.get_h());
3766 canvas->unlock_canvas();
3767 mwindow->cwindow->gui->unlock_window();
3771 Track *track = mwindow->session->drag_handle_track();
3772 double position = track->from_units(mode == 1 ? left : pos);
3773 if( position < 0 ) position = 0;
3774 edl->local_session->set_selectionstart(position);
3775 edl->local_session->set_selectionend(position);
3776 PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine;
3777 if( playback_engine->is_playing_back )
3778 playback_engine->stop_playback(1);
3779 mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
3785 int TrackCanvas::update_drag_edit()
3794 int TrackCanvas::get_drag_values(float *percentage,
3801 //int x = cursor_x - mwindow->session->drag_origin_x;
3802 //int y = cursor_y - mwindow->session->drag_origin_y;
3806 if(!current->autos->track->record) return 1;
3816 calculate_viewport(current->autos->track,
3826 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3828 mwindow->session->drag_start_percentage;
3829 if(do_clamp) CLAMP(*percentage, 0, 1);
3831 *position = Units::to_int64(zoom_units *
3832 (cursor_x - mwindow->session->drag_origin_x) +
3833 mwindow->session->drag_start_position + 0.5);
3835 if((do_clamp) && *position < 0) *position = 0;
3840 #define UPDATE_DRAG_HEAD(do_clamp) \
3841 int result = 0, center_pixel; \
3842 if(!current->autos->track->record) return 0; \
3843 double view_start, unit_start, view_end, unit_end; \
3844 double yscale, zoom_sample, zoom_units; \
3846 calculate_viewport(current->autos->track, \
3847 view_start, unit_start, view_end, unit_end, \
3848 yscale, center_pixel, zoom_sample, zoom_units); \
3850 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3851 yscale + mwindow->session->drag_start_percentage; \
3852 if(do_clamp) CLAMP(percentage, 0, 1); \
3854 int64_t position = Units::to_int64(zoom_units * \
3855 (cursor_x - mwindow->session->drag_origin_x) + \
3856 mwindow->session->drag_start_position); \
3857 if((do_clamp) && position < 0) position = 0;
3860 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3862 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3864 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3865 int x = cursor_x - mwindow->session->drag_origin_x;
3866 int y = cursor_y - mwindow->session->drag_origin_y;
3867 float value, old_value;
3869 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3870 // not really editing the node, rather start editing the curve
3871 // tangent is editable and drag movement is significant
3872 if( (FloatAuto::FREE == current->curve_mode ||
3873 FloatAuto::TFREE==current->curve_mode) &&
3874 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3875 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3878 switch(mwindow->session->drag_handle) {
3880 // Snap to nearby values
3881 old_value = current->get_value();
3883 double value1, value2, distance1, distance2;
3885 if(current->previous) {
3886 int autogrouptype = current->previous->autos->autogrouptype;
3887 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3888 value1 = ((FloatAuto*)current->previous)->get_value();
3889 distance1 = fabs(value - value1);
3890 current->set_value(value1);
3894 int autogrouptype = current->next->autos->autogrouptype;
3895 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3896 value2 = ((FloatAuto*)current->next)->get_value();
3897 distance2 = fabs(value - value2);
3898 if(!current->previous || distance2 < distance1) {
3899 current->set_value(value2);
3903 if(!current->previous && !current->next) {
3904 current->set_value( ((FloatAutos*)current->autos)->default_);
3906 value = current->get_value();
3909 int autogrouptype = current->autos->autogrouptype;
3910 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3913 if(alt_down() && !shift_down())
3914 // ALT constrains movement: fixed position, only changing the value
3915 position = mwindow->session->drag_start_position;
3917 if(value != old_value || position != current->position) {
3919 float change = value - old_value;
3920 current->adjust_to_new_coordinates(position, value);
3921 update_ganged_autos(change, current->autos->track, current);
3922 show_message(current, 1,", %.2f", current->get_value());
3928 int autogrouptype = current->autos->autogrouptype;
3929 value = percentage_to_value(percentage, 0, current, autogrouptype);
3930 if(value != current->get_control_in_value())
3933 // note: (position,value) need not be at the location of the ctrl point,
3934 // but could be somewhere in between on the curve (or even outward or
3935 // on the opposit side). We set the new control point such as
3936 // to point the curve through (position,value)
3937 current->set_control_in_value(
3938 value * levered_position(position - current->position,
3939 current->get_control_in_position()));
3940 update_ganged_autos(0, current->autos->track, current);
3941 show_message(current, 1,", %.2f", current->get_control_in_value());
3947 int autogrouptype = current->autos->autogrouptype;
3948 value = percentage_to_value(percentage, 0, current, autogrouptype);
3949 if(value != current->get_control_out_value()) {
3951 current->set_control_out_value(
3952 value * levered_position(position - current->position,
3953 current->get_control_out_position()));
3954 update_ganged_autos(0, current->autos->track, current);
3955 show_message(current, 1,", %.2f", current->get_control_out_value());
3963 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3965 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3967 UPDATE_DRAG_HEAD(1);
3968 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3970 if(value != current->value || position != current->position)
3973 current->value = value;
3974 current->position = position;
3975 show_message(current, 0,", %d", current->value);
3981 // Autos which can't change value through dragging.
3983 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3985 Auto *current = (Auto*)mwindow->session->drag_auto;
3988 if(position != current->position)
3991 current->position = position;
3992 show_message(current, 0,"");
3994 double position_f = current->autos->track->from_units(current->position);
3995 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3996 mwindow->edl->local_session->get_selectionend(1)) /
4000 mwindow->edl->local_session->set_selectionstart(position_f);
4001 mwindow->edl->local_session->set_selectionend(position_f);
4004 if(position_f < center_f)
4006 mwindow->edl->local_session->set_selectionstart(position_f);
4009 mwindow->edl->local_session->set_selectionend(position_f);
4016 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
4018 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
4021 if(position != current->position)
4023 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
4024 Track *track = current->autos->track;
4025 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
4026 PluginSet *pluginset;
4028 // figure out the correct pluginset & correct plugin
4030 for(int i = 0; i < track->plugin_set.total; i++)
4032 pluginset = track->plugin_set.values[i];
4033 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
4035 KeyFrames *keyframes = plugin->keyframes;
4036 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
4038 currentkeyframe = (KeyFrame *) currentkeyframe->next)
4040 if (currentkeyframe == current)
4052 mwindow->session->plugin_highlighted = plugin;
4053 mwindow->session->track_highlighted = track;
4055 current->position = position;
4056 show_message(current, 0,"");
4058 double position_f = current->autos->track->from_units(current->position);
4059 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4060 mwindow->edl->local_session->get_selectionend(1)) /
4064 mwindow->edl->local_session->set_selectionstart(position_f);
4065 mwindow->edl->local_session->set_selectionend(position_f);
4068 if(position_f < center_f)
4070 mwindow->edl->local_session->set_selectionstart(position_f);
4073 mwindow->edl->local_session->set_selectionend(position_f);
4080 void TrackCanvas::update_drag_caption()
4082 switch(mwindow->session->current_operation)
4092 int TrackCanvas::cursor_update(int in_motion)
4097 int update_clock = 0;
4098 int update_zoom = 0;
4099 int update_scroll = 0;
4100 int update_overlay = 0;
4101 int update_cursor = 0;
4104 double position = 0.;
4105 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4108 switch(mwindow->edl->session->editing_mode)
4110 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
4111 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
4114 switch(mwindow->session->current_operation)
4116 case DRAG_EDITHANDLE1:
4117 // Outside threshold. Upgrade status
4120 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4122 mwindow->session->current_operation = DRAG_EDITHANDLE2;
4128 case DRAG_EDITHANDLE2:
4131 update_drag_handle();
4136 case DRAG_PLUGINHANDLE1:
4139 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4141 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
4147 case DRAG_PLUGINHANDLE2:
4150 update_drag_handle();
4155 // Rubber band curves
4163 case DRAG_PROJECTOR_X:
4164 case DRAG_PROJECTOR_Y:
4165 case DRAG_PROJECTOR_Z:
4166 if(active) rerender = update_overlay =
4167 update_drag_floatauto(get_cursor_x(), get_cursor_y());
4168 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
4169 mwindow->speed_after(!in_motion ? 1 : 0);
4173 if(active) rerender = update_overlay =
4174 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4178 if(active) rerender = update_overlay =
4179 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4182 // Keyframe icons are sticky
4186 case DRAG_PLUGINKEY_PRE:
4188 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
4189 mwindow->session->current_operation++;
4192 mwindow->undo->update_undo_before();
4200 if(active) rerender = update_overlay =
4201 update_drag_auto(get_cursor_x(), get_cursor_y());
4204 case DRAG_PLUGINKEY:
4205 if(active) rerender = update_overlay =
4206 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4211 cursor_x = get_cursor_x();
4212 cursor_y = get_cursor_y();
4213 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4214 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4216 position = mwindow->edl->align_to_frame(position, 0);
4217 position = MAX(position, 0);
4219 double start = mwindow->edl->local_session->get_selectionstart(1);
4220 double end = mwindow->edl->local_session->get_selectionend(1);
4221 if(position < selection_midpoint) {
4222 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4223 mwindow->edl->local_session->set_selectionstart(position);
4226 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4227 mwindow->edl->local_session->set_selectionend(position);
4230 gui->unlock_window();
4232 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
4233 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
4234 mwindow->cwindow->update(dir, 0, 0, 0, 1);
4235 gui->lock_window("TrackCanvas::cursor_update 1");
4236 // Update the faders
4237 mwindow->update_plugin_guis();
4238 gui->update_patchbay();
4240 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4242 gui->hide_cursor(0);
4243 gui->draw_cursor(1);
4244 gui->update_timebar(0);
4245 gui->flash_canvas(1);
4253 case DROP_TARGETING:
4254 new_cursor = GRABBED_CURSOR;
4259 if(is_event_win() && cursor_inside()) {
4261 cursor_x = get_cursor_x();
4262 position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4263 position = mwindow->edl->align_to_frame(position, 0);
4266 for(int i = 0; i < TOTAL_PANES; i++)
4267 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4269 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4270 gui->update_timebar(0);
4272 if(do_transitions(get_cursor_x(), get_cursor_y(),
4273 0, new_cursor, update_cursor)) break;
4274 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4275 0, 0, new_cursor, update_cursor, rerender)) break;
4276 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4277 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4278 // Plugin boundaries
4279 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4280 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4281 if(do_edits(get_cursor_x(), get_cursor_y(),
4282 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4287 //printf("TrackCanvas::cursor_update 1\n");
4288 if(update_cursor && new_cursor != get_cursor())
4290 set_cursor(new_cursor, 0, 1);
4293 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
4294 if(rerender && render_timer->get_difference() > 0.25 ) {
4295 render_timer->update();
4296 mwindow->restart_brender();
4297 mwindow->sync_parameters(CHANGE_PARAMS);
4298 mwindow->update_plugin_guis();
4299 gui->unlock_window();
4300 mwindow->cwindow->update(1, 0, 0, 0, 1);
4301 gui->lock_window("TrackCanvas::cursor_update 2");
4305 gui->update_patchbay();
4310 if(!mwindow->cwindow->playback_engine->is_playing_back)
4311 gui->mainclock->update(position);
4315 gui->zoombar->update();
4320 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4324 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4328 if(update_overlay) {
4329 gui->draw_overlays(1);
4332 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4336 int TrackCanvas::cursor_motion_event()
4338 return cursor_update(1);
4341 void TrackCanvas::start_dragscroll()
4345 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4346 //printf("TrackCanvas::start_dragscroll 1\n");
4350 void TrackCanvas::stop_dragscroll()
4354 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4355 //printf("TrackCanvas::stop_dragscroll 1\n");
4359 int TrackCanvas::repeat_event(int64_t duration)
4361 if(!drag_scroll) return 0;
4362 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4364 int sample_movement = 0;
4365 int track_movement = 0;
4366 int64_t x_distance = 0;
4367 int64_t y_distance = 0;
4368 double position = 0;
4371 switch(mwindow->session->current_operation) {
4373 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4374 if(get_cursor_x() > get_w()) {
4375 x_distance = get_cursor_x() - get_w();
4376 sample_movement = 1;
4378 else if(get_cursor_x() < 0) {
4379 x_distance = get_cursor_x();
4380 sample_movement = 1;
4383 if(get_cursor_y() > get_h()) {
4384 y_distance = get_cursor_y() - get_h();
4387 else if(get_cursor_y() < 0) {
4388 y_distance = get_cursor_y();
4395 if(sample_movement) {
4396 position = (double)(get_cursor_x() +
4397 mwindow->edl->local_session->view_start[pane->number] +
4399 mwindow->edl->local_session->zoom_sample /
4400 mwindow->edl->session->sample_rate;
4401 position = mwindow->edl->align_to_frame(position, 0);
4402 position = MAX(position, 0);
4404 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4405 switch(mwindow->session->current_operation) {
4407 if(position < selection_midpoint) {
4408 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4409 mwindow->edl->local_session->set_selectionstart(position);
4411 gui->unlock_window();
4412 mwindow->cwindow->update(1, 0, 0);
4413 gui->lock_window("TrackCanvas::repeat_event");
4414 // Update the faders
4415 mwindow->update_plugin_guis();
4416 gui->update_patchbay();
4419 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4420 mwindow->edl->local_session->set_selectionend(position);
4421 // Don't que the CWindow
4426 mwindow->samplemovement(
4427 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4431 if(track_movement) {
4432 mwindow->trackmovement(y_distance, pane->number);
4438 int TrackCanvas::button_release_event()
4440 int redraw = -1, update_overlay = 0;
4441 int result = 0, load_flags = 0;
4443 // printf("TrackCanvas::button_release_event %d\n",
4444 // mwindow->session->current_operation);
4446 switch(mwindow->session->current_operation) {
4447 case DRAG_EDITHANDLE2:
4448 mwindow->session->current_operation = NO_OPERATION;
4452 end_edithandle_selection();
4455 case DRAG_EDITHANDLE1:
4456 mwindow->session->current_operation = NO_OPERATION;
4461 case DRAG_PLUGINHANDLE2:
4462 mwindow->session->current_operation = NO_OPERATION;
4466 end_pluginhandle_selection();
4469 case DRAG_PLUGINHANDLE1:
4470 mwindow->session->current_operation = NO_OPERATION;
4476 redraw = FORCE_REDRAW;
4477 load_flags |= LOAD_EDITS;
4479 // delete the drag_auto_gang first and remove out of order keys
4480 clear_ganged_autos();
4491 case DRAG_PROJECTOR_X:
4492 case DRAG_PROJECTOR_Y:
4493 case DRAG_PROJECTOR_Z:
4494 case DRAG_PLUGINKEY:
4495 load_flags |= LOAD_AUTOMATION;
4496 mwindow->session->current_operation = NO_OPERATION;
4497 mwindow->session->drag_handle = 0;
4498 // Remove any out-of-order keyframe
4499 if(mwindow->session->drag_auto) {
4500 mwindow->session->drag_auto->autos->remove_nonsequential(
4501 mwindow->session->drag_auto);
4502 // mwindow->session->drag_auto->autos->optimize();
4506 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
4512 case DRAG_AEFFECT_COPY:
4513 case DRAG_VEFFECT_COPY:
4514 // Trap in drag stop
4517 case DROP_TARGETING: {
4518 int cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
4519 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4520 drag_cursor_motion(cursor_x, cursor_y,
4521 &track, &edit, &pluginset, &plugin);
4523 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4524 gui->edit_menu->activate_menu(track, edit, pluginset, plugin, position);
4525 mwindow->session->current_operation = NO_OPERATION;
4530 if(mwindow->session->current_operation) {
4531 // if(mwindow->session->current_operation == SELECT_REGION) {
4532 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4535 mwindow->session->current_operation = NO_OPERATION;
4537 // Traps button release events
4547 if(update_overlay) {
4548 gui->draw_overlays(1);
4551 gui->draw_canvas(redraw, 0);
4552 gui->flash_canvas(1);
4557 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4558 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4560 Edit *edit_result = 0;
4561 int handle_result = -1;
4564 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4565 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4566 int64_t edit_x, edit_y, edit_w, edit_h;
4567 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4569 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4570 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4571 if( cursor_x < edit_x + HANDLE_W ) {
4574 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4575 track->show_assets() ) {
4576 new_cursor = DOWNLEFT_RESIZE;
4577 if( button_press == LEFT_BUTTON )
4583 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4586 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4587 track->show_assets() ) {
4588 new_cursor = DOWNRIGHT_RESIZE;
4589 if( button_press == LEFT_BUTTON )
4601 double position = 0;
4602 if( handle_result == 0 ) {
4603 position = edit_result->track->from_units(edit_result->startproject);
4604 new_cursor = LEFT_CURSOR;
4606 else if( handle_result == 1 ) {
4607 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4608 new_cursor = RIGHT_CURSOR;
4611 // Reposition cursor
4612 if( button_press ) {
4613 mwindow->session->drag_edit = edit_result;
4614 mwindow->session->drag_handle = handle_result;
4615 mwindow->session->drag_button = get_buttonpress() - 1;
4616 mwindow->session->drag_position = position;
4617 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4618 mwindow->session->drag_origin_x = get_cursor_x();
4619 mwindow->session->drag_origin_y = get_cursor_y();
4620 mwindow->session->drag_start = position;
4622 rerender = start_selection(position);
4626 else if( result < 0 ) {
4627 mwindow->undo->update_undo_before();
4628 if( !shift_down() ) {
4629 if( handle_result == 0 )
4630 edit_result->hard_left = !edit_result->hard_left;
4631 else if( handle_result == 1 )
4632 edit_result->hard_right = !edit_result->hard_right;
4635 int status = handle_result == 0 ? edit_result->hard_left :
4636 handle_result == 1 ? edit_result->hard_right : 0;
4637 int new_status = !status;
4638 int64_t edit_edge = edit_result->startproject;
4639 if( handle_result == 1 ) edit_edge += edit_result->length;
4640 double edge_position = edit_result->track->from_units(edit_edge);
4641 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4642 int64_t track_position = track->to_units(edge_position, 1);
4643 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4645 int64_t left_edge = left_edit->startproject;
4646 double left_position = track->from_units(left_edge);
4647 if( EQUIV(edge_position, left_position) ) {
4648 left_edit->hard_left = new_status;
4649 if( left_edit->previous )
4650 left_edit->previous->hard_right = new_status;
4653 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4655 int64_t right_edge = right_edit->startproject + right_edit->length;
4656 double right_position = track->from_units(right_edge);
4657 if( EQUIV(edge_position, right_position) ) {
4658 right_edit->hard_right = new_status;
4659 if( right_edit->next )
4660 right_edit->next->hard_left = new_status;
4665 rerender = update_overlay = 1;
4666 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4673 int TrackCanvas::do_plugin_handles(int cursor_x,
4677 int &update_overlay,
4681 Plugin *plugin_result = 0;
4682 int handle_result = 0;
4685 for(Track *track = mwindow->edl->tracks->first;
4687 track = track->next) {
4688 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4689 PluginSet *plugin_set = track->plugin_set.values[i];
4690 for(Plugin *plugin = (Plugin*)plugin_set->first;
4692 plugin = (Plugin*)plugin->next) {
4693 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4694 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4696 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4697 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4698 if(cursor_x < plugin_x + HANDLE_W) {
4699 plugin_result = plugin;
4703 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4704 plugin_result = plugin;
4711 if(result && shift_down())
4712 mwindow->session->trim_edits = plugin_set;
4718 double position = 0;
4719 if(handle_result == 0) {
4720 position = plugin_result->track->from_units(plugin_result->startproject);
4721 new_cursor = LEFT_CURSOR;
4723 else if(handle_result == 1) {
4724 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4725 new_cursor = RIGHT_CURSOR;
4729 mwindow->session->drag_plugin = plugin_result;
4730 mwindow->session->drag_handle = handle_result;
4731 mwindow->session->drag_button = get_buttonpress() - 1;
4732 mwindow->session->drag_position = position;
4733 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4734 mwindow->session->drag_origin_x = get_cursor_x();
4735 mwindow->session->drag_origin_y = get_cursor_y();
4736 mwindow->session->drag_start = position;
4738 rerender = start_selection(position);
4747 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4751 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4752 drag_cursor_motion(cursor_x, cursor_y,
4753 &track, &edit, &pluginset, &plugin);
4755 if( button_press && track ) {
4756 switch( get_buttonpress() ) {
4757 case RIGHT_BUTTON: {
4759 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4760 gui->track_menu->activate_menu(track, edit, pluginset, plugin, position);
4761 mwindow->session->current_operation = NO_OPERATION;
4765 set_cursor(GRABBED_CURSOR, 0, 1);
4766 mwindow->session->current_operation = DROP_TARGETING;
4775 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4776 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4780 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4781 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4782 int64_t edit_x, edit_y, edit_w, edit_h;
4783 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4785 // Cursor inside a track
4786 // Cursor inside an edit
4787 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4788 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4789 // Select duration of edit
4791 if( get_double_click() ) {
4792 if( shift_down() ) {
4793 if( edit->group_id > 0 ) {
4794 mwindow->edl->tracks->clear_selected_edits();
4795 mwindow->edl->tracks->del_group(edit->group_id);
4798 int id = mwindow->session->group_number++;
4799 mwindow->edl->tracks->new_group(id);
4801 mwindow->session->current_operation = NO_OPERATION;
4804 else if( !drag_start ) {
4805 double start = edit->track->from_units(edit->startproject);
4806 start = mwindow->edl->align_to_frame(start, 0);
4807 mwindow->edl->local_session->set_selectionstart(start);
4808 double end = edit->track->from_units(edit->startproject+edit->length);
4809 end = mwindow->edl->align_to_frame(end, 0);
4810 mwindow->edl->local_session->set_selectionend(end);
4814 else if( ctrl_down() && get_buttonpress() == 1 &&
4815 mwindow->edl->session->editing_mode == EDITING_ARROW ) {
4816 int v = !edit->is_selected ? 1 : 0;
4817 if( !edit->group_id )
4818 edit->is_selected = v;
4820 mwindow->edl->tracks->set_group_selected(edit->group_id, v);
4829 else if( drag_start && track->record ) {
4830 if( mwindow->edl->session->editing_mode == EDITING_ARROW ) {
4831 // Need to create drag window
4832 mwindow->session->drag_edit = edit;
4833 mwindow->session->drag_origin_x = cursor_x;
4834 mwindow->session->drag_origin_y = cursor_y;
4835 // Where the drag started, so we know relative position inside the edit later
4836 mwindow->session->drag_position =
4837 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4838 // Construct list of all affected edits
4839 if( !shift_down() ) {
4840 mwindow->session->current_operation = DRAG_EDIT;
4841 mwindow->edl->tracks->clear_selected_edits();
4842 if( !ctrl_down() ) {
4843 mwindow->edl->tracks->select_affected_edits(
4844 edit->track->from_units(edit->startproject),
4848 edit->is_selected = 1;
4849 mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits);
4850 int cx, cy; get_abs_cursor(cx, cy);
4851 gui->drag_popup = new BC_DragWindow(gui,
4852 mwindow->theme->get_image("clip_icon"), cx, cy);
4855 else if( edit->is_selected ) {
4856 if( mwindow->session->drag_group )
4857 mwindow->session->drag_group->remove_user();
4858 double start_position = 0;
4859 mwindow->session->drag_group =
4860 mwindow->selected_edits_to_clip(0, &start_position,
4861 &mwindow->session->drag_group_first_track);
4862 if( mwindow->session->drag_group ) {
4863 mwindow->session->current_operation = DRAG_GROUP;
4864 mwindow->session->drag_group_position =
4865 mwindow->session->drag_position - start_position;
4866 mwindow->session->drag_group_edit = edit;
4867 mwindow->session->drag_origin_y = edit_y;
4880 int TrackCanvas::test_track_group(EDL *group, Track *first_track)
4882 Track *src = group->tracks->first;
4883 for( Track *track=first_track; track && src; track=track->next ) {
4884 if( !track->record ) continue;
4885 if( src->data_type != track->data_type ) return 0;
4888 return !src ? 1 : 0;
4891 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4896 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4897 int button_press, int &redraw, int &rerender)
4905 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4906 if(!track->expand_view) continue;
4908 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4909 // first check if plugins are visible at all
4910 if (!track->expand_view)
4912 PluginSet *plugin_set = track->plugin_set.values[i];
4913 for(plugin = (Plugin*)plugin_set->first;
4915 plugin = (Plugin*)plugin->next) {
4916 plugin_dimensions(plugin, x, y, w, h);
4917 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4918 MWindowGUI::visible(y, y + h, 0, get_h())) {
4919 if(cursor_x >= x && cursor_x < x + w &&
4920 cursor_y >= y && cursor_y < y + h) {
4930 // Start plugin popup
4932 if(get_buttonpress() == 3) {
4933 gui->plugin_menu->update(plugin);
4934 gui->plugin_menu->activate_menu();
4937 else if (get_double_click() && !drag_start) {
4938 // Select range of plugin on doubleclick over plugin
4939 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4940 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4941 plugin->track->from_units(plugin->length));
4942 if(mwindow->edl->session->cursor_on_frames) {
4943 mwindow->edl->local_session->set_selectionstart(
4944 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4945 mwindow->edl->local_session->set_selectionend(
4946 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4955 if(drag_start && plugin->track->record) {
4956 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4957 if(plugin->track->data_type == TRACK_AUDIO)
4958 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4959 else if(plugin->track->data_type == TRACK_VIDEO)
4960 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4962 mwindow->session->drag_plugin = plugin;
4963 mwindow->session->drag_origin_x = cursor_x;
4964 mwindow->session->drag_origin_y = cursor_y;
4965 // Where the drag started, so we know relative position inside the edit later
4966 mwindow->session->drag_position =
4967 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4968 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4970 switch(plugin->plugin_type) {
4971 case PLUGIN_STANDALONE: {
4972 PluginServer *server =
4973 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4974 if( !server ) break;
4975 VFrame *frame = server->picon;
4977 if(plugin->track->data_type == TRACK_AUDIO) {
4978 frame = mwindow->theme->get_image("aeffect_icon");
4981 frame = mwindow->theme->get_image("veffect_icon");
4985 get_abs_cursor(cx, cy);
4986 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4989 case PLUGIN_SHAREDPLUGIN:
4990 case PLUGIN_SHAREDMODULE: {
4991 VFrame *frame = mwindow->theme->get_image("clip_icon");
4993 get_abs_cursor(cx, cy);
4994 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
5006 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
5007 int button_press, int &new_cursor, int &update_cursor)
5009 Transition *transition = 0;
5014 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
5015 if( !track->show_transitions() ) continue;
5017 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
5018 if( edit->transition ) {
5019 edit_dimensions(edit, x, y, w, h);
5020 get_transition_coords(edit, x, y, w, h);
5022 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
5023 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
5024 if( cursor_x >= x && cursor_x < x + w &&
5025 cursor_y >= y && cursor_y < y + h ) {
5026 transition = edit->transition;
5038 new_cursor = UPRIGHT_ARROW_CURSOR;
5040 else if(get_buttonpress() == 3) {
5041 gui->transition_menu->update(transition);
5042 gui->transition_menu->activate_menu();
5049 int TrackCanvas::button_press_event()
5052 int cursor_x, cursor_y;
5055 cursor_x = get_cursor_x();
5056 cursor_y = get_cursor_y();
5057 mwindow->session->trim_edits = 0;
5059 if(is_event_win() && cursor_inside()) {
5060 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5067 if( get_buttonpress() == LEFT_BUTTON ) {
5068 gui->stop_transport("TrackCanvas::button_press_event");
5071 int update_overlay = 0, update_cursor = 0, rerender = 0;
5073 if(get_buttonpress() == WHEEL_UP) {
5075 mwindow->expand_sample();
5076 else if(ctrl_down())
5077 mwindow->move_left(get_w()/ 10);
5079 mwindow->move_up(get_h() / 10);
5081 else if(get_buttonpress() == WHEEL_DOWN) {
5083 mwindow->zoom_in_sample();
5084 else if(ctrl_down())
5085 mwindow->move_right(get_w() / 10);
5087 mwindow->move_down(get_h() / 10);
5089 else if(get_buttonpress() == 6) {
5091 mwindow->move_left(get_w());
5093 mwindow->move_left(get_w() / 20);
5095 mwindow->move_left(get_w() / 5);
5097 else if(get_buttonpress() == 7) {
5099 mwindow->move_right(get_w());
5101 mwindow->move_right(get_w() / 20);
5103 mwindow->move_right(get_w() / 5);
5106 switch(mwindow->edl->session->editing_mode) {
5107 // Test handles and resource boundaries and highlight a track
5108 case EDITING_ARROW: {
5109 if( do_transitions(cursor_x, cursor_y,
5110 1, new_cursor, update_cursor) ) break;
5112 if( do_keyframes(cursor_x, cursor_y,
5113 0, get_buttonpress(), new_cursor,
5114 update_cursor, rerender) ) break;
5115 // Test edit boundaries
5116 if( do_edit_handles(cursor_x, cursor_y,
5117 1, rerender, update_overlay, new_cursor,
5118 update_cursor) ) break;
5119 // Test plugin boundaries
5120 if( do_plugin_handles(cursor_x, cursor_y,
5121 1, rerender, update_overlay, new_cursor,
5122 update_cursor) ) break;
5124 if( do_edits(cursor_x, cursor_y, 1, 0,
5125 update_overlay, rerender, new_cursor,
5126 update_cursor) ) break;
5128 if( do_plugins(cursor_x, cursor_y, 0, 1,
5129 update_cursor, rerender) ) break;
5131 if( test_resources(cursor_x, cursor_y) ) break;
5133 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5138 // Test handles only and select a region
5139 case EDITING_IBEAM: {
5140 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5141 //printf("TrackCanvas::button_press_event %d\n", position);
5143 if( do_transitions(cursor_x, cursor_y,
5144 1, new_cursor, update_cursor)) break;
5145 if(do_keyframes(cursor_x, cursor_y,
5146 0, get_buttonpress(), new_cursor,
5147 update_cursor, rerender)) {
5151 // Test edit boundaries
5152 if( do_edit_handles(cursor_x, cursor_y,
5153 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5154 // Test plugin boundaries
5155 if( do_plugin_handles(cursor_x, cursor_y,
5156 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5158 if( do_edits(cursor_x, cursor_y,
5159 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
5161 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
5163 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5164 // Highlight selection
5165 if( get_buttonpress() != LEFT_BUTTON ) break;
5166 rerender = start_selection(position);
5167 mwindow->session->current_operation = SELECT_REGION;
5174 gui->unlock_window();
5175 mwindow->cwindow->update(1, 0, 0, 0, 1);
5176 gui->lock_window("TrackCanvas::button_press_event 2");
5178 mwindow->update_plugin_guis();
5179 gui->update_patchbay();
5182 if( update_overlay ) {
5183 gui->draw_overlays(1);
5185 if( update_cursor < 0 ) {
5186 // double_click edit
5187 gui->swindow->update_selection();
5188 gui->draw_canvas(0, 0);
5190 if( update_cursor ) {
5191 gui->update_timebar(0);
5192 gui->hide_cursor(0);
5193 gui->show_cursor(1);
5194 gui->zoombar->update();
5195 gui->flash_canvas(1);
5202 int TrackCanvas::start_selection(double position)
5205 position = mwindow->edl->align_to_frame(position, 1);
5211 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
5212 mwindow->edl->local_session->get_selectionend(1)) / 2;
5214 if(position < midpoint)
5216 mwindow->edl->local_session->set_selectionstart(position);
5217 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
5223 mwindow->edl->local_session->set_selectionend(position);
5224 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
5225 // Don't que the CWindow for the end
5229 // Start a new selection
5231 //printf("TrackCanvas::start_selection %f\n", position);
5232 mwindow->edl->local_session->set_selectionstart(position);
5233 mwindow->edl->local_session->set_selectionend(position);
5234 selection_midpoint = position;
5242 void TrackCanvas::end_edithandle_selection()
5244 mwindow->modify_edithandles();
5247 void TrackCanvas::end_pluginhandle_selection()
5249 mwindow->modify_pluginhandles();
5253 double TrackCanvas::time_visible()
5255 return (double)get_w() *
5256 mwindow->edl->local_session->zoom_sample /
5257 mwindow->edl->session->sample_rate;
5261 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
5263 char string[BCTEXTLEN];
5264 char *cp = string, *ep = cp + sizeof(string)-1;
5265 if( show_curve_type ) {
5266 cp += snprintf(string, ep-cp, "%-8s ",
5267 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5269 char string2[BCTEXTLEN];
5270 Units::totext(string2,
5271 current->autos->track->from_units(current->position),
5272 mwindow->edl->session->time_format,
5273 mwindow->edl->session->sample_rate,
5274 mwindow->edl->session->frame_rate,
5275 mwindow->edl->session->frames_per_foot);
5276 cp += snprintf(cp, ep-cp, "%s", string2);
5279 vsnprintf(cp, ep-cp, fmt, ap);
5281 gui->show_message(string);
5284 // Patchbay* TrackCanvas::get_patchbay()
5286 // if(pane->patchbay) return pane->patchbay;
5287 // if(gui->total_panes() == 2 &&
5288 // gui->pane[TOP_LEFT_PANE] &&
5289 // gui->pane[TOP_RIGHT_PANE])
5290 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5291 // if(gui->total_panes() == 4)
5293 // if(pane->number == TOP_RIGHT_PANE)
5294 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5296 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;