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);
508 int TrackCanvas::drag_start_event()
513 int new_cursor, update_cursor;
515 if(mwindow->session->current_operation != NO_OPERATION) return 0;
518 if(do_plugins(get_drag_x(), get_drag_y(),
519 1, 0, redraw, rerender)) {
522 else if(do_edits(get_drag_x(), get_drag_y(),
523 0, 1, redraw, rerender, new_cursor, update_cursor)) {
531 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
533 // get the canvas/track position
534 Track *track = mwindow->session->track_highlighted;
535 int cursor_x = get_relative_cursor_x();
536 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
537 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
538 double position = mwindow->edl->align_to_frame(cur_pos, 1);
539 if( position <= 0 ) {
543 double cursor_position = position;
544 int64_t drop_position = track->to_units(cursor_position, 1);
545 if( moved_edit ) { // relative cursor position depends upon drop point
546 double moved_edit_start = moved_edit->track->from_units(moved_edit->startproject);
547 position -= mwindow->session->drag_position - moved_edit_start;
549 int64_t edit_position = track->to_units(position, 1);
550 int64_t grab_position = edit_position;
551 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
552 grab_position -= moved_edit_length / 2;
553 Edit *last_edit = track->edits->last;
554 if( !last_edit || edit_position >= (last_edit->startproject+last_edit->length) ) {
556 return grab_position;
559 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
560 Edit *next_edit = track->edits->first;
562 Edit *edit = next_edit; next_edit = (Edit *)edit->next;
563 int64_t edit_start = edit->startproject;
564 int64_t edit_end = edit_start + edit->length;
565 double edit_start_pos = edit->track->from_units(edit_start);
566 if( (fabs(edit_start_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
567 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
570 double edit_end_pos = edit->track->from_units(edit_end);
571 if( (fabs(edit_end_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
572 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
575 if( edit != moved_edit && !edit->silence() )
576 drop_start = edit_end; // reset drop zone
578 if( next_edit == moved_edit || next_edit->silence() ) continue;
582 drop_end = INT64_MAX;
583 if( edit_position >= drop_start &&
584 edit_position+moved_edit_length < drop_end ) {
585 *is_insertion = 0; // fits in the zone
586 return edit_position;
588 if( drop_position < drop_end ) { // drop in the zone
589 if( (drop_end - drop_start) >= moved_edit_length ) {
590 *is_insertion = 0; // fits in the zone, but over the edge
591 int64_t dx0 = llabs(drop_position - drop_start);
592 int64_t dx1 = llabs(drop_position - drop_end);
593 return dx0 < dx1 ? drop_start : drop_end - moved_edit_length;
596 int64_t edit_center = (edit_start + edit_end) / 2;
597 return position < edit_center ? drop_start : drop_end;
605 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
607 // get the canvas/track position
608 Track *track = plugin_set->track;
609 double moved_plugin_length = moved_plugin->track->from_units(moved_plugin->length);
610 int64_t track_plugin_length = track->to_units(moved_plugin_length, 0);
611 int cursor_x = get_relative_cursor_x();
612 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
613 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
614 double position = mwindow->edl->align_to_frame(cur_pos, 1);
615 if( position <= 0 ) return 0;
616 int64_t drop_position = track->to_units(position, 1);
617 Plugin *last_plugin = (Plugin *)plugin_set->last;
618 if( !last_plugin ) return drop_position;
619 double plugin_set_end = last_plugin->track->from_units(last_plugin->startproject+last_plugin->length);
620 if( position >= plugin_set_end ) return drop_position;
621 double moved_plugin_start = moved_plugin->track->from_units(moved_plugin->startproject);
622 position -= mwindow->session->drag_position - moved_plugin_start;
623 int64_t plugin_position = track->to_units(position, 1);
625 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
626 Plugin *next_plugin = (Plugin *)plugin_set->first;
627 while( next_plugin ) {
628 Plugin *plugin = next_plugin; next_plugin = (Plugin *)plugin->next;
629 int64_t plugin_start = plugin->startproject;
630 int64_t plugin_end = plugin_start + plugin->length;
631 double plugin_end_pos = plugin->track->from_units(plugin_end);
632 int64_t track_plugin_end = track->to_units(plugin_end_pos, 0);
633 if( plugin != moved_plugin && !plugin->silence() )
634 drop_start = track_plugin_end;
636 if( next_plugin == moved_plugin || next_plugin->silence() ) continue;
637 drop_end = track_plugin_end;
640 drop_end = INT64_MAX;
641 if( plugin_position >= drop_start && // fits in the zone
642 plugin_position+track_plugin_length < drop_end ) {
643 return plugin_position;
645 if( drop_position < drop_end ) { // drop in the zone
646 if( (drop_end - drop_start) >= track_plugin_length ) {
647 int64_t dx0 = llabs(drop_position - drop_start);
648 int64_t dx1 = llabs(drop_position - drop_end);
649 return dx0 < dx1 ? drop_start : drop_end - track_plugin_length;
657 void TrackCanvas::draw(int mode, int hide_cursor)
661 // Swap pixmap layers
662 if(get_w() != background_pixmap->get_w() ||
663 get_h() != background_pixmap->get_h())
665 delete background_pixmap;
666 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
669 // Cursor disappears after resize when this is called.
670 // Cursor doesn't redraw after editing when this isn't called.
671 if(pane->cursor && hide_cursor) pane->cursor->hide();
672 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
674 if(debug) PRINT_TRACE
675 draw_resources(mode);
677 if(debug) PRINT_TRACE
679 if(debug) PRINT_TRACE
682 void TrackCanvas::update_cursor(int flush)
684 switch(mwindow->edl->session->editing_mode)
686 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
687 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
692 void TrackCanvas::test_timer()
694 if(resource_timer->get_difference() > 1000 &&
698 hourglass_enabled = 1;
703 void TrackCanvas::draw_indexes(Indexable *indexable)
705 IndexState *index_state = indexable->index_state;
706 // Don't redraw raw samples
707 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
709 draw_resources(NORMAL_DRAW, 1, indexable);
714 void TrackCanvas::draw_resources(int mode,
716 Indexable *indexable)
720 if(debug) PRINT_TRACE
722 // can't stop thread here, because this is called for every pane
723 // if(mode != IGNORE_THREAD && !indexes_only)
724 // gui->resource_thread->stop_draw(!indexes_only);
726 if(mode != IGNORE_THREAD &&
728 !gui->resource_thread->interrupted)
730 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
733 BC_Signals::dump_stack();
736 if(debug) PRINT_TRACE
738 resource_timer->update();
740 // Age resource pixmaps for deletion
742 for(int i = 0; i < gui->resource_pixmaps.total; i++)
743 gui->resource_pixmaps.values[i]->visible--;
745 if(mode == FORCE_REDRAW)
746 gui->resource_pixmaps.remove_all_objects();
748 if(debug) PRINT_TRACE
751 for(Track *current = mwindow->edl->tracks->first;
755 if(debug) PRINT_TRACE
756 for(Edit *edit = current->edits->first; edit; edit = edit->next)
758 if(debug) PRINT_TRACE
759 if( current->data_type != TRACK_SUBTITLE )
760 if(!edit->asset && !edit->nested_edl) continue;
763 if(edit->track->data_type != TRACK_AUDIO) continue;
765 if(edit->nested_edl &&
766 strcmp(indexable->path, edit->nested_edl->path)) continue;
769 strcmp(indexable->path, edit->asset->path)) continue;
772 if(debug) PRINT_TRACE
774 int64_t edit_x, edit_y, edit_w, edit_h;
775 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
778 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
779 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
781 int64_t pixmap_x, pixmap_w, pixmap_h;
782 if(debug) PRINT_TRACE
784 // Search for existing pixmap containing edit
785 for(int i = 0; i < gui->resource_pixmaps.total; i++)
787 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
788 // Same pointer can be different edit if editing took place
789 if(pixmap->edit_id == edit->id &&
790 pixmap->pane_number == pane->number)
796 if(debug) PRINT_TRACE
798 // Get new size, offset of pixmap needed
799 get_pixmap_size(edit,
805 if(debug) PRINT_TRACE
808 if(pixmap_w && pixmap_h)
810 // Create pixmap if it doesn't exist
811 ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
812 pixmap_x, pixmap_w, pixmap_h);
813 // Resize it if it's bigger
814 if( pixmap_w > pixmap->pixmap_w ||
815 pixmap_h > pixmap->pixmap_h)
816 pixmap->resize(pixmap_w, pixmap_h);
817 pixmap->update_settings(edit, edit_x, edit_w,
818 pixmap_x, pixmap_w, pixmap_h);
820 if( current->show_assets() )
821 pixmap->draw_data(this,
822 edit, edit_x, edit_w,
823 pixmap_x, pixmap_w, pixmap_h,
827 clear_box(0,0, pixmap_w,pixmap_h, pixmap);
830 if( current->show_titles() )
831 pixmap->draw_title(this,
832 edit, edit_x, edit_w,
834 // Resize it if it's smaller
835 if(pixmap_w < pixmap->pixmap_w ||
836 pixmap_h < pixmap->pixmap_h)
837 pixmap->resize(pixmap_w, pixmap_h);
839 // Copy pixmap to background canvas
840 background_pixmap->draw_pixmap(pixmap,
842 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
846 if(debug) PRINT_TRACE
853 // Delete unused pixmaps
854 if(debug) PRINT_TRACE
856 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
857 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
859 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
860 delete gui->resource_pixmaps.values[i];
861 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
863 if(debug) PRINT_TRACE
865 if(hourglass_enabled)
868 hourglass_enabled = 0;
870 if(debug) PRINT_TRACE
872 // can't stop thread here, because this is called for every pane
873 // if(mode != IGNORE_THREAD && !indexes_only)
874 // gui->resource_thread->start_draw();
875 if(debug) PRINT_TRACE
880 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
886 ResourcePixmap *result = 0;
888 for(int i = 0; i < gui->resource_pixmaps.total; i++)
890 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
891 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
892 gui->resource_pixmaps.values[i]->pane_number == pane->number)
894 result = gui->resource_pixmaps.values[i];
902 result = new ResourcePixmap(mwindow,
909 gui->resource_pixmaps.append(result);
912 // result->resize(pixmap_w, pixmap_h);
916 void TrackCanvas::get_pixmap_size(Edit *edit,
924 // Align x on frame boundaries
927 // switch(edit->edits->track->data_type)
939 if(pixmap_x + pixmap_w > get_w())
941 pixmap_w = get_w() - pixmap_x;
948 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
949 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
950 // int64_t pixel_increment = MAX(picon_w, frame_w);
951 // int64_t pixmap_x1 = edit_x;
952 // int64_t pixmap_x2 = edit_x + edit_w;
956 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
961 // if(pixmap_x2 > get_w())
963 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
967 // pixmap_x = pixmap_x1;
968 // pixmap_w = pixmap_x2 - pixmap_x1;
973 pixmap_h = mwindow->edl->local_session->zoom_track;
974 Track *track = edit->edits->track;
975 if( track->show_titles() )
976 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
977 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
980 void TrackCanvas::edit_dimensions(Edit *edit,
981 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
983 x = Units::round(edit->track->from_units(edit->startproject) *
984 mwindow->edl->session->sample_rate /
985 mwindow->edl->local_session->zoom_sample -
986 mwindow->edl->local_session->view_start[pane->number]);
988 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
990 // Method for calculating w so when edits are together we never get off by one error due to rounding
991 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
992 mwindow->edl->session->sample_rate /
993 mwindow->edl->local_session->zoom_sample -
994 mwindow->edl->local_session->view_start[pane->number]);
998 if( edit->track->show_titles() )
999 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
1000 if( edit->track->show_assets() )
1001 edit_h += resource_h();
1005 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1009 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1010 h = track->vertical_span(mwindow->theme);
1014 void TrackCanvas::draw_paste_destination()
1016 //int cursor_x = get_relative_cursor_x();
1017 //int cursor_y = get_relative_cursor_y();
1018 int current_atrack = 0;
1019 int current_vtrack = 0;
1020 int current_aedit = 0;
1021 int current_vedit = 0;
1027 //if(pane->number == BOTTOM_RIGHT_PANE)
1028 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1030 if((mwindow->session->current_operation == DRAG_ASSET &&
1031 (mwindow->session->drag_assets->total ||
1032 mwindow->session->drag_clips->total)) ||
1033 (mwindow->session->current_operation == DRAG_EDIT &&
1034 mwindow->session->drag_edits->total)) {
1035 Indexable *indexable = 0;
1039 if(mwindow->session->current_operation == DRAG_ASSET &&
1040 mwindow->session->drag_assets->size())
1041 indexable = mwindow->session->drag_assets->get(0);
1043 if(mwindow->session->current_operation == DRAG_ASSET &&
1044 mwindow->session->drag_clips->size())
1045 clip = mwindow->session->drag_clips->get(0);
1047 int has_audio = 0, has_video = 0;
1048 double paste_audio_length = 0, paste_video_length = 0;
1049 double paste_audio_position = -1, paste_video_position = -1;
1052 has_audio = indexable->have_audio();
1053 paste_audio_length = !has_audio ? 0 :
1054 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1055 has_video = indexable->have_video();
1056 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1057 // Images have length -1
1058 if( asset && asset->video_data && asset->video_length < 0 ) {
1059 paste_video_length = mwindow->edl->session->si_useduration ?
1060 mwindow->edl->session->si_duration / asset->frame_rate :
1061 1.0 / asset->frame_rate ; // 1 frame
1064 paste_video_length = !has_video ? 0 :
1065 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1069 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1070 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1071 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1072 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1075 // 'Align cursor on frame' lengths calculations
1076 if( mwindow->edl->session->cursor_on_frames ) {
1077 double fps = mwindow->edl->session->frame_rate;
1078 double aud = floor(paste_audio_length * fps) / fps;
1079 double vid = floor(paste_video_length * fps) / fps;
1080 double length = has_video && has_audio ?
1081 aud < vid ? aud : vid :
1083 has_audio ? aud : 0;
1084 paste_video_length = paste_audio_length = length;
1087 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1089 switch( mwindow->session->track_highlighted->data_type ) {
1090 case TRACK_VIDEO: length = paste_video_length; break;
1091 case TRACK_AUDIO: length = paste_audio_length; break;
1093 int64_t asset_length = mwindow->session->track_highlighted->
1094 to_units(length, 1);
1095 paste_audio_position = mwindow->session->track_highlighted->
1096 from_units(drop_edit_position(&insertion, NULL, asset_length));
1099 int64_t asset_length = mwindow->session->track_highlighted->
1100 to_units(paste_video_length, 1);
1101 paste_video_position = mwindow->session->track_highlighted->
1102 from_units(drop_edit_position(&insertion, NULL, asset_length));
1105 // Get destination track
1106 for(Track *dest = mwindow->session->track_highlighted;
1108 dest = dest->next) {
1110 // Get source width in pixels
1112 // Use start of highlighted edit
1113 if(mwindow->session->edit_highlighted) {
1114 position = mwindow->session->track_highlighted->from_units(
1115 mwindow->session->edit_highlighted->startproject);
1118 // Use end of highlighted track, disregarding effects
1119 position = mwindow->session->track_highlighted->from_units(
1120 mwindow->session->track_highlighted->edits->length());
1123 // Get the x coordinate
1124 x = Units::to_int64(position *
1125 mwindow->edl->session->sample_rate /
1126 mwindow->edl->local_session->zoom_sample) -
1127 mwindow->edl->local_session->view_start[pane->number];
1129 double paste_position = -1.;
1130 if(dest->data_type == TRACK_AUDIO) {
1131 if(indexable && current_atrack < indexable->get_audio_channels()) {
1132 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1133 w = Units::to_int64((double)indexable->get_audio_samples() /
1134 indexable->get_sample_rate() *
1135 mwindow->edl->session->sample_rate /
1136 mwindow->edl->local_session->zoom_sample);
1137 paste_position = paste_audio_position;
1139 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1140 w = Units::to_int64((double)clip->tracks->total_length() *
1141 mwindow->edl->session->sample_rate /
1142 mwindow->edl->local_session->zoom_sample);
1143 paste_position = paste_audio_position;
1144 //printf("draw_paste_destination %d\n", x);
1146 else if(mwindow->session->current_operation == DRAG_EDIT &&
1147 current_aedit < mwindow->session->drag_edits->total) {
1149 while(current_aedit < mwindow->session->drag_edits->total &&
1150 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1153 if(current_aedit < mwindow->session->drag_edits->total) {
1154 edit = mwindow->session->drag_edits->values[current_aedit];
1155 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1156 paste_position = mwindow->session->track_highlighted->
1157 from_units(drop_edit_position(&insertion,
1158 mwindow->session->drag_edit,
1159 mwindow->session->drag_edit->length));
1163 if( paste_position >= 0 ) {
1164 position = paste_position;
1171 else if(dest->data_type == TRACK_VIDEO) {
1172 //printf("draw_paste_destination 1\n");
1173 if(indexable && current_vtrack < indexable->get_video_layers())
1175 w = Units::to_int64((double)indexable->get_video_frames() /
1176 indexable->get_frame_rate() *
1177 mwindow->edl->session->sample_rate /
1178 mwindow->edl->local_session->zoom_sample);
1179 paste_position = paste_video_position;
1181 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1182 w = Units::to_int64(clip->tracks->total_length() *
1183 mwindow->edl->session->sample_rate /
1184 mwindow->edl->local_session->zoom_sample);
1185 paste_position = paste_video_position;
1187 else if(mwindow->session->current_operation == DRAG_EDIT &&
1188 current_vedit < mwindow->session->drag_edits->total) {
1190 while(current_vedit < mwindow->session->drag_edits->total &&
1191 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1194 if(current_vedit < mwindow->session->drag_edits->total) {
1195 edit = mwindow->session->drag_edits->values[current_vedit];
1196 w = Units::to_int64(edit->track->from_units(edit->length) *
1197 mwindow->edl->session->sample_rate /
1198 mwindow->edl->local_session->zoom_sample);
1199 paste_position = mwindow->session->track_highlighted->
1200 from_units(drop_edit_position(&insertion,
1201 mwindow->session->drag_edit,
1202 mwindow->session->drag_edit->length));
1206 if( paste_position >= 0 ) {
1207 position = paste_position;
1216 // Get the x coordinate
1217 x = Units::to_int64(position *
1218 mwindow->edl->session->sample_rate /
1219 mwindow->edl->local_session->zoom_sample) -
1220 mwindow->edl->local_session->view_start[pane->number];
1221 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1222 int h = dest->vertical_span(mwindow->theme);
1224 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1225 if(x < -BC_INFINITY) {
1226 w -= -BC_INFINITY - x;
1227 x += -BC_INFINITY - x;
1230 // if(pane->number == TOP_RIGHT_PANE)
1231 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1232 // __LINE__, x, y, w, h);
1234 draw_highlight_insertion(x, y, w, h);
1236 draw_highlight_rectangle(x, y, w, h);
1243 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1245 x = Units::round(plugin->track->from_units(plugin->startproject) *
1246 mwindow->edl->session->sample_rate /
1247 mwindow->edl->local_session->zoom_sample -
1248 mwindow->edl->local_session->view_start[pane->number]);
1249 w = Units::round(plugin->track->from_units(plugin->length) *
1250 mwindow->edl->session->sample_rate /
1251 mwindow->edl->local_session->zoom_sample);
1252 y = plugin->track->y_pixel
1253 - mwindow->edl->local_session->track_start[pane->number];
1254 if( plugin->track->show_titles() )
1255 y += mwindow->theme->get_image("title_bg_data")->get_h();
1256 if( plugin->track->show_assets() )
1258 y += plugin->plugin_set->get_number() *
1259 mwindow->theme->get_image("plugin_bg_data")->get_h();
1260 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1263 int TrackCanvas::resource_h()
1265 return mwindow->edl->local_session->zoom_track;
1268 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1271 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1272 // just draw arrows, so user has indication that something is there
1273 // FIXME: get better colors
1277 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1282 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1286 // Fix bug in heroines & cvs version as of 22.8.2005:
1287 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1288 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1301 w = MIN(w, get_w() + 20);
1302 h = MIN(h, get_h() + 20);
1305 set_color(mwindow->preferences->highlight_inverse);
1307 //draw_rectangle(x, y, w, h);
1308 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1309 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1311 draw_rectangle(x, y, w, h);
1313 //if(pane->number == TOP_RIGHT_PANE)
1314 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1317 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1320 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1321 // just draw arrows, so user has indication that something is there
1322 // FIXME: get better colors
1331 /* these don't look so good
1333 draw_line(x, y, x, y+h);
1334 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1335 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1336 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1337 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1339 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1340 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1342 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1343 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1344 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1345 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1347 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1348 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1350 // draw the box centred around x
1352 // Fix bug in heroines & cvs version as of 22.8.2005:
1353 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1354 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1365 w = MIN(w, get_w() + 20);
1366 h = MIN(h, get_h() + 20);
1367 set_color(mwindow->preferences->highlight_inverse);
1369 draw_rectangle(x, y, w, h);
1370 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1372 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1375 void TrackCanvas::draw_playback_cursor()
1377 // Called before playback_cursor exists
1378 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1380 // mwindow->playback_cursor->visible = 0;
1381 // mwindow->playback_cursor->draw();
1385 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1387 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1388 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1390 edit_dimensions(edit, x, y, w, h);
1392 if( edit->track->show_titles() )
1393 y += mwindow->theme->get_image("title_bg_data")->get_h();
1395 if(side == EDIT_OUT)
1402 void TrackCanvas::get_transition_coords(Edit *edit,
1403 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1405 int transition_w = 30, transition_h = 30;
1406 int has_titles = edit->track->show_titles();
1407 int has_assets = edit->track->show_assets();
1408 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
1409 double asset_h = resource_h();
1410 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
1411 double dy = has_titles ?
1412 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) :
1413 ( has_assets ? asset_h/2 : 0) ;
1414 double title_h = mwindow->theme->title_h;
1415 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
1418 x -= transition_w / 2;
1419 y -= transition_h / 2;
1424 void TrackCanvas::draw_highlighting()
1429 switch(mwindow->session->current_operation)
1431 case DRAG_ATRANSITION:
1432 case DRAG_VTRANSITION:
1433 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1434 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1435 if(mwindow->session->edit_highlighted) {
1436 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1437 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1438 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1439 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1440 edit_dimensions(mwindow->session->edit_highlighted,
1442 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1443 MWindowGUI::visible(y, y + h, 0, get_h())) {
1445 get_transition_coords(mwindow->session->edit_highlighted,
1452 // Dragging a new effect from the Resource window
1455 if(mwindow->session->track_highlighted &&
1456 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1457 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1458 (mwindow->session->current_operation == DRAG_VEFFECT &&
1459 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1460 // Put it before another plugin
1461 if(mwindow->session->plugin_highlighted) {
1462 plugin_dimensions(mwindow->session->plugin_highlighted,
1464 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1466 // Put it after a plugin set
1467 else if( mwindow->session->pluginset_highlighted &&
1468 mwindow->session->pluginset_highlighted->last ) {
1469 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1471 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1472 int64_t track_x, track_y, track_w, track_h;
1473 track_dimensions(mwindow->session->track_highlighted,
1474 track_x, track_y, track_w, track_h);
1478 mwindow->session->track_highlighted->get_length() *
1479 mwindow->edl->session->sample_rate /
1480 mwindow->edl->local_session->zoom_sample -
1481 mwindow->edl->local_session->view_start[pane->number]) -
1483 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1484 if(w <= 0) w = track_w;
1487 track_dimensions(mwindow->session->track_highlighted,
1490 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1491 // Put it in a new plugin set determined by the selected range
1492 if(mwindow->edl->local_session->get_selectionend() >
1493 mwindow->edl->local_session->get_selectionstart()) {
1494 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1495 mwindow->edl->session->sample_rate /
1496 mwindow->edl->local_session->zoom_sample -
1497 mwindow->edl->local_session->view_start[pane->number]);
1498 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1499 mwindow->edl->local_session->get_selectionstart()) *
1500 mwindow->edl->session->sample_rate /
1501 mwindow->edl->local_session->zoom_sample);
1503 // Put it in a new plugin set determined by an edit boundary
1504 else if(mwindow->session->edit_highlighted) {
1505 int64_t temp_y, temp_h;
1506 edit_dimensions(mwindow->session->edit_highlighted,
1507 x, temp_y, w, temp_h);
1509 // Put it at the beginning of the track in a new plugin set
1512 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1513 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1514 //printf("TrackCanvas::draw_highlighting 1\n");
1521 if(mwindow->session->track_highlighted) {
1522 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1524 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1526 draw_paste_destination();
1532 if(mwindow->session->track_highlighted) {
1533 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1535 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1536 draw_paste_destination();
1541 // Dragging an effect from the timeline
1542 case DRAG_AEFFECT_COPY:
1543 case DRAG_VEFFECT_COPY:
1544 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1545 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1546 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1547 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1548 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1550 int64_t plugin_position = -1;
1551 Plugin *drag_plugin = mwindow->session->drag_plugin;
1552 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1553 Track *hi_track = mwindow->session->track_highlighted;
1554 Edit *hi_edit = mwindow->session->edit_highlighted;
1555 // Put it into a silence zone
1556 if( hi_plugin_set && hi_plugin_set->last &&
1557 hi_plugin_set->track == drag_plugin->track ) {
1558 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1559 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1560 hi_track = drag_plugin->track;
1562 else if( hi_track ) {
1563 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1564 track_dimensions(hi_track, x, y, w, h);
1565 plugin_position = hi_edit ? hi_edit->startproject : 0;
1568 if( plugin_position < 0 ) break;
1570 // Calculate length of plugin based on data type of track and units
1571 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1572 mwindow->edl->local_session->zoom_sample;
1573 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1574 mwindow->edl->local_session->view_start[pane->number];
1575 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1577 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1578 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1584 case DRAG_PLUGINKEY:
1585 if(mwindow->session->plugin_highlighted &&
1586 mwindow->session->current_operation == DRAG_PLUGINKEY)
1588 // Just highlight the plugin
1589 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1591 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1592 MWindowGUI::visible(y, y + h, 0, get_h()))
1602 draw_highlight_rectangle(x, y, w, h);
1604 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
1605 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1606 if( !edit->is_selected ) continue;
1607 edit_dimensions(edit, x, y, w, h);
1608 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue;
1609 if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
1610 set_color(GREEN | BLUE);
1612 draw_rectangle(x, y, w, h);
1614 draw_rectangle(x-1, y-1, w+2, h+2);
1620 void TrackCanvas::draw_plugins()
1622 char string[BCTEXTLEN];
1624 int current_show = 0;
1625 int current_preset = 0;
1627 for(int i = 0; i < plugin_on_toggles.total; i++)
1628 plugin_on_toggles.values[i]->in_use = 0;
1629 for(int i = 0; i < plugin_show_toggles.total; i++)
1630 plugin_show_toggles.values[i]->in_use = 0;
1631 for(int i = 0; i < preset_edit_buttons.total; i++)
1632 plugin_show_toggles.values[i]->in_use = 0;
1635 for(Track *track = mwindow->edl->tracks->first;
1637 track = track->next)
1639 if(track->expand_view)
1641 for(int i = 0; i < track->plugin_set.total; i++)
1643 PluginSet *pluginset = track->plugin_set.values[i];
1645 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1647 int64_t total_x, y, total_w, h;
1648 plugin_dimensions(plugin, total_x, y, total_w, h);
1650 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1651 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1652 plugin->plugin_type != PLUGIN_NONE)
1654 int x = total_x, w = total_w, left_margin = 5;
1655 int right_margin = 5;
1661 if(w + x > get_w()) w -= (w + x) - get_w();
1668 mwindow->theme->get_image("plugin_bg_data"),
1670 set_color(mwindow->theme->title_color);
1671 set_font(mwindow->theme->title_font);
1672 plugin->calculate_title(string, 0);
1674 // Truncate string to int64_test visible in background
1675 int len = strlen(string), j;
1676 for(j = len; j >= 0; j--)
1678 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1686 // Justify the text on the left boundary of the edit if it is visible.
1687 // Otherwise justify it on the left side of the screen.
1688 int64_t text_x = total_x + left_margin;
1689 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1690 text_x = MAX(left_margin, text_x);
1692 y + get_text_ascent(mwindow->theme->title_font) + 2,
1696 int64_t min_x = total_x + text_w;
1699 // Update plugin toggles
1700 int toggle_x = total_x + total_w;
1702 toggle_x = MIN(get_w() - right_margin, toggle_x);
1705 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1706 if(toggle_x > min_x)
1708 if(current_on >= plugin_on_toggles.total)
1710 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1711 add_subwindow(plugin_on);
1712 plugin_on_toggles.append(plugin_on);
1716 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1721 // Toggles for standalone plugins only
1722 if(plugin->plugin_type == PLUGIN_STANDALONE)
1725 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1726 if(toggle_x > min_x)
1728 if(current_show >= plugin_show_toggles.total)
1730 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1731 add_subwindow(plugin_show);
1732 plugin_show_toggles.append(plugin_show);
1736 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1740 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1741 if(toggle_x > min_x)
1743 if(current_preset >= preset_edit_buttons.total)
1745 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1746 add_subwindow(preset_edit);
1747 preset_edit_buttons.append(preset_edit);
1751 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1762 // Remove unused toggles
1764 while(current_preset < preset_edit_buttons.total)
1766 preset_edit_buttons.remove_object_number(current_preset);
1768 while(current_show < plugin_show_toggles.total)
1770 plugin_show_toggles.remove_object_number(current_show);
1773 while(current_on < plugin_on_toggles.total)
1775 plugin_on_toggles.remove_object_number(current_on);
1779 void TrackCanvas::refresh_plugintoggles()
1781 for(int i = 0; i < plugin_on_toggles.total; i++)
1783 PluginOn *on = plugin_on_toggles.values[i];
1784 on->reposition_window(on->get_x(), on->get_y());
1786 for(int i = 0; i < plugin_show_toggles.total; i++)
1788 PluginShow *show = plugin_show_toggles.values[i];
1789 show->reposition_window(show->get_x(), show->get_y());
1791 for(int i = 0; i < preset_edit_buttons.total; i++)
1793 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1794 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1798 void TrackCanvas::draw_hard_edges()
1802 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1803 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1804 if( !edit->hard_left && !edit->hard_right ) continue;
1805 edit_dimensions(edit, x, y, w, h);
1809 if( track->show_titles() )
1810 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
1811 if( track->show_assets() )
1814 y1 += mwindow->theme->title_h;
1815 if( edit->hard_left ) {
1816 ArrayList<int> xpt, ypt;
1817 xpt.append(x); ypt.append(y1);
1818 xpt.append(x+HANDLE_W); ypt.append(y1);
1819 xpt.append(x); ypt.append(y1-HANDLE_H);
1820 fill_polygon(&xpt, &ypt);
1822 if( edit->hard_right ) {
1823 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1824 xpt.append(x1); ypt.append(y1);
1825 xpt.append(x1-HANDLE_W); ypt.append(y1);
1826 xpt.append(x1); ypt.append(y1-HANDLE_H);
1827 fill_polygon(&xpt, &ypt);
1833 void TrackCanvas::draw_inout_points()
1838 void TrackCanvas::draw_drag_handle()
1840 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1841 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1843 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1844 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1845 mwindow->edl->session->sample_rate /
1846 mwindow->edl->local_session->zoom_sample -
1847 mwindow->edl->local_session->view_start[pane->number]);
1848 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1849 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1851 //printf("TrackCanvas::draw_drag_handle 3\n");
1852 draw_line(pixel1, 0, pixel1, get_h());
1854 //printf("TrackCanvas::draw_drag_handle 4\n");
1859 void TrackCanvas::draw_transitions()
1863 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1864 if( !track->show_transitions() ) continue;
1866 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1867 if(!edit->transition) continue;
1868 edit_dimensions(edit, x, y, w, h);
1869 int strip_x = x, edit_y = y;
1870 get_transition_coords(edit, x, y, w, h);
1871 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
1872 if( track->show_assets() && track->show_titles() )
1873 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
1874 if( strip_y < edit_y ) strip_y = edit_y;
1876 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1877 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1878 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1879 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1880 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1882 if( !server ) continue;
1883 VFrame *picon = server->get_picon();
1884 if( !picon ) continue;
1885 int picon_w = picon->get_w(), picon_h = picon->get_h();
1886 int track_h = edit->track->vertical_span(mwindow->theme);
1887 if( picon_h > track_h ) picon_h = track_h;
1888 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
1890 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1891 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
1892 int x = strip_x, w = strip_w;
1893 if( x < 0 ) { w -= -x; x = 0; }
1894 if( w + x > get_w() ) w -= (w + x) - get_w();
1896 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1897 mwindow->theme->get_image("plugin_bg_data"), 0);
1903 void TrackCanvas::draw_loop_points()
1905 //printf("TrackCanvas::draw_loop_points 1\n");
1906 if(mwindow->edl->local_session->loop_playback)
1908 //printf("TrackCanvas::draw_loop_points 2\n");
1909 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1910 mwindow->edl->session->sample_rate /
1911 mwindow->edl->local_session->zoom_sample -
1912 mwindow->edl->local_session->view_start[pane->number]);
1913 //printf("TrackCanvas::draw_loop_points 3\n");
1915 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1918 draw_line(x, 0, x, get_h());
1920 //printf("TrackCanvas::draw_loop_points 4\n");
1922 x = Units::round(mwindow->edl->local_session->loop_end *
1923 mwindow->edl->session->sample_rate /
1924 mwindow->edl->local_session->zoom_sample -
1925 mwindow->edl->local_session->view_start[pane->number]);
1926 //printf("TrackCanvas::draw_loop_points 5\n");
1928 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1931 draw_line(x, 0, x, get_h());
1933 //printf("TrackCanvas::draw_loop_points 6\n");
1935 //printf("TrackCanvas::draw_loop_points 7\n");
1938 void TrackCanvas::draw_brender_range()
1940 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1941 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1942 if( mwindow->edl->session->brender_end > 0 )
1944 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1945 mwindow->edl->session->sample_rate /
1946 mwindow->edl->local_session->zoom_sample -
1947 mwindow->edl->local_session->view_start[pane->number]);
1948 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1951 draw_line(x1, 0, x1, get_h());
1953 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1954 mwindow->edl->session->sample_rate /
1955 mwindow->edl->local_session->zoom_sample -
1956 mwindow->edl->local_session->view_start[pane->number]);
1958 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1961 draw_line(x2, 0, x2, get_h());
1966 // The operations which correspond to each automation type
1967 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1983 // The buttonpress operations, so nothing changes unless the mouse moves
1984 // a certain amount. This allows the keyframe to be used to position the
1985 // insertion point without moving itself.
1986 static int pre_auto_operations[AUTOMATION_TOTAL] =
2003 int TrackCanvas::do_keyframes(int cursor_x,
2011 // Note: button 3 (right mouse button) is not eaten to allow
2012 // track context menu to appear
2014 EDLSession *session = mwindow->edl->session;
2018 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
2020 0, 0, 0, 0, 0, 0, 0, 0,
2022 modekeyframe_pixmap,
2023 maskkeyframe_pixmap,
2028 for(Track *track = mwindow->edl->tracks->first;
2030 track = track->next) {
2031 Auto *auto_keyframe = 0;
2032 Automation *automation = track->automation;
2035 // Handle keyframes in reverse drawing order if a button press
2037 int end = AUTOMATION_TOTAL;
2041 start = AUTOMATION_TOTAL - 1;
2045 for(int i = start; i != end && !result; i += step)
2047 // Event not trapped and automation visible
2048 Autos *autos = automation->autos[i];
2049 if(!result && session->auto_conf->autos[i] && autos) {
2051 case AUTOMATION_MODE:
2052 case AUTOMATION_PAN:
2053 case AUTOMATION_MASK:
2054 result = do_autos(track, automation->autos[i],
2055 cursor_x, cursor_y, draw,
2056 buttonpress, auto_pixmaps[i],
2057 auto_keyframe, rerender);
2061 switch(autos->get_type()) {
2062 case Autos::AUTOMATION_TYPE_FLOAT: {
2063 Automation automation(0, track);
2064 int grouptype = automation.autogrouptype(i, track);
2065 if( buttonpress && i == AUTOMATION_SPEED ) {
2066 mwindow->speed_before();
2069 if(draw) // Do dropshadow
2070 result = do_float_autos(track, autos,
2071 cursor_x, cursor_y, draw,
2072 buttonpress, 1, 1, MDGREY,
2073 auto_keyframe, grouptype);
2074 result = do_float_autos(track, autos,
2075 cursor_x, cursor_y, draw, buttonpress,
2076 0, 0, GWindowGUI::auto_colors[i],
2077 auto_keyframe, grouptype);
2079 if( !result && buttonpress && i == AUTOMATION_SPEED )
2080 mwindow->speed_after(-1);
2081 int current_grouptype = mwindow->edl->local_session->zoombar_showautotype;
2082 if( result && buttonpress && grouptype != current_grouptype ) {
2083 mwindow->edl->local_session->zoombar_showautotype = grouptype;
2084 mwindow->gui->zoombar->update_autozoom();
2088 case Autos::AUTOMATION_TYPE_INT: {
2089 if(draw) // Do dropshadow
2090 result = do_int_autos(track, autos,
2091 cursor_x, cursor_y, draw,
2092 buttonpress, 1, 1, MDGREY,
2094 result = do_int_autos(track, autos,
2095 cursor_x, cursor_y, draw, buttonpress,
2096 0, 0, GWindowGUI::auto_colors[i],
2105 if(mwindow->session->current_operation == auto_operations[i])
2108 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2110 // mwindow->session->current_operation,
2111 // auto_operations[i]);
2114 if (buttonpress == 2 && auto_keyframe )
2116 double position = track->from_units(auto_keyframe->position);
2117 mwindow->edl->local_session->set_selectionstart(position);
2118 mwindow->edl->local_session->set_selectionend(position);
2120 if (buttonpress != 3)
2122 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2123 fill_ganged_autos(get_double_click(), 0, track,
2124 (FloatAuto*)mwindow->session->drag_auto);
2125 mwindow->session->current_operation = pre_auto_operations[i];
2126 update_drag_caption();
2129 else if( auto_keyframe )
2131 gui->keyframe_menu->update(automation,
2134 gui->keyframe_menu->activate_menu();
2135 rerender = 1; // the position changes
2139 gui->keyframe_hide->update(autos);
2140 gui->keyframe_hide->activate_menu();
2141 rerender = 1; // the position changes
2143 if(buttonpress == 1 && ctrl_down() &&
2144 AUTOMATION_TYPE_FLOAT == autos->get_type())
2145 rerender = 1; // special case: curve mode changed
2151 if(!result && session->auto_conf->plugins) {
2154 result = do_plugin_autos(track, cursor_x, cursor_y,
2155 draw, buttonpress, plugin, keyframe);
2156 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2159 if(result && (buttonpress == 1)) {
2160 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2161 update_drag_caption();
2164 else if (result && (buttonpress == 3)) {
2165 gui->keyframe_menu->update(plugin, keyframe);
2166 gui->keyframe_menu->activate_menu();
2167 rerender = 1; // the position changes
2172 // Final pass to trap event
2173 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2174 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2175 mwindow->session->current_operation == auto_operations[i]) {
2181 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2182 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2188 new_cursor = UPRIGHT_ARROW_CURSOR;
2195 void TrackCanvas::draw_keyframe_reticle()
2197 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2198 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2200 int current_op = mwindow->session->current_operation, dragging = 0;
2201 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2202 if( current_op == auto_operations[i] ) dragging = 1;
2203 if( dragging && !mwindow->session->drag_auto ) dragging = 0;
2205 int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
2206 mwindow->session->drag_auto->autos->autoidx : -1;
2208 if( get_buttonpress() == 1 && dragging &&
2209 keyframe_hairline == HAIRLINE_DRAGGING ) {
2210 draw_hairline(mwindow->session->drag_auto, RED, 1);
2214 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2215 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2216 int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
2217 for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
2218 Automation *automation = track->automation;
2219 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2220 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2221 // automation visible
2222 Autos *autos = automation->autos[i];
2223 if( !autos ) continue;
2224 if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
2225 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2226 auto_keyframe = auto_keyframe->next ) {
2227 draw_hairline(auto_keyframe, BLUE, show);
2233 draw_hairline(mwindow->session->drag_auto, RED, 1);
2237 void TrackCanvas::draw_auto(Auto *current,
2245 x1 = x - HANDLE_W / 2;
2246 x2 = x + HANDLE_W / 2;
2247 y1 = center_pixel + y - HANDLE_W / 2;
2248 y2 = center_pixel + y + HANDLE_W / 2;
2250 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2251 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2253 draw_box(x1, y1, x2 - x1, y2 - y1);
2257 // This draws lines for bezier in & out controls
2258 void TrackCanvas::draw_cropped_line(int x1,
2267 // Don't care about x since it is clipped by the window.
2268 // Put y coords in ascending order
2270 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2271 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2276 double slope = (double)(x2 - x1) / (y2 - y1);
2277 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2279 x1 = (int)(x1 + (min_y - y1) * slope);
2282 else if(y1 >= max_y) {
2283 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2288 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2291 else if(y2 < min_y) {
2292 x2 = (int)(x2 + (min_y - y2) * slope);
2297 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2298 if( y1 >= min_y && y1 < max_y &&
2299 y2 >= min_y && y2 < max_y )
2300 draw_line(x1, y1, x2, y2);
2304 void TrackCanvas::draw_floatauto(FloatAuto *current,
2315 int x1 = x - HANDLE_W / 2; // Center
2316 int x2 = x + HANDLE_W / 2;
2317 int y1 = center_pixel + y - HANDLE_H / 2;
2318 int y2 = center_pixel + y + HANDLE_H / 2;
2319 int ymin = center_pixel - zoom_track / 2;
2320 int ymax = center_pixel + zoom_track / 2;
2321 CLAMP(y1, ymin, ymax);
2322 CLAMP(y2, ymin, ymax);
2327 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2329 draw_box(x1, y1, x2 - x1, y2 - y1);
2332 // show bezier control points (only) if this
2333 // floatauto doesn't adjust it's tangents automatically
2334 if(current->curve_mode != FloatAuto::FREE &&
2335 current->curve_mode != FloatAuto::TFREE)
2339 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2341 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2344 inline int quantize(float f) { return (int)floor(f + 0.5); }
2346 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2347 int x, int y, int cp_x, int cp_y, int center_pixel,
2348 int zoom_track, int color)
2349 // draw the tangent and a handle for given bézier ctrl point
2351 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2353 float slope = (float)(cp_y - y)/(cp_x - x);
2354 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2356 cp_x = x + quantize((cp_y - y) / slope);
2359 cp_y += center_pixel;
2361 // drawing the tangent as a dashed line...
2362 int const dash = HANDLE_W;
2363 int const gap = HANDLE_W / 2;
2364 float sx = 3 * (cp_x - x) / 4.;
2367 // q is the x displacement for a unit line of slope
2368 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2370 float dist = 1/q * sx;
2376 float sy = slope * sx, ey = slope * ex;
2377 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2384 int r = HANDLE_W / 2;
2385 int cp_x1 = cp_x - r;
2386 int cp_y1 = cp_y - r;
2388 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2390 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2395 int TrackCanvas::test_auto(Auto *current,
2396 int x, int y, int center_pixel, int zoom_track,
2397 int cursor_x, int cursor_y, int buttonpress)
2402 x1 = x - HANDLE_W / 2;
2403 x2 = x + HANDLE_W / 2;
2404 y1 = center_pixel + y - HANDLE_H / 2;
2405 y2 = center_pixel + y + HANDLE_H / 2;
2406 int ymin = center_pixel - zoom_track / 2;
2407 int ymax = center_pixel + zoom_track / 2;
2408 CLAMP(y1, ymin, ymax);
2409 CLAMP(y2, ymin, ymax);
2411 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2413 if(buttonpress && buttonpress != 3)
2415 mwindow->session->drag_auto = current;
2416 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2417 // Toggle Autos don't respond to vertical zoom, they always show up
2418 // with "on" == 100% == line on top
2419 mwindow->session->drag_start_position = current->position;
2420 mwindow->session->drag_origin_x = cursor_x;
2421 mwindow->session->drag_origin_y = cursor_y;
2426 if(buttonpress && buttonpress != 3 && result)
2428 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2429 mwindow->undo->update_undo_before();
2435 // some Helpers for test_floatauto(..)
2436 // and for dragging the tangents/ctrl points
2437 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2438 float cursor_x, float cursor_y)
2440 // Control point switched off?
2441 if( x0 == ctrl_x ) return 0.0;
2442 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2443 double x = cursor_x-x0, y = cursor_y-y0;
2444 // wrong side of ctrl handle
2445 if( x*x1 < 0 ) return 0.0;
2446 // outside handle radius
2447 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2448 double xx1 = x1*x1, yy1 = y1*y1;
2449 double xx = x*x, yy = y*y;
2450 // distance squared from cursor to cursor projected to line from ctrl to handle
2451 // along a line perpendicular to line from ctrl to handle (closest approach)
2452 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2453 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2454 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2459 float levered_position(float position, float ref_pos)
2461 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2463 return ref_pos / position;
2467 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2468 // transforms automation value into current display coords,
2469 // dependant on current automation display range for the given kind of automation
2471 if(!mwindow || !mwindow->edl) return 0;
2472 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2473 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2474 float automation_range = automation_max - automation_min;
2475 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2477 return (auto_value - automation_min) / automation_range;
2482 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2483 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2484 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2488 int x1 = x - HANDLE_W / 2;
2489 int x2 = x + HANDLE_W / 2;
2490 int y1 = center_pixel + y - HANDLE_W / 2;
2491 int y2 = center_pixel + y + HANDLE_W / 2;
2492 int ymin = center_pixel - zoom_track / 2;
2493 int ymax = center_pixel + zoom_track / 2;
2494 CLAMP(y1, ymin, ymax);
2495 CLAMP(y2, ymin, ymax);
2497 int in_x1 = in_x - HANDLE_W / 2;
2498 int in_x2 = in_x + HANDLE_W / 2;
2499 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2500 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2501 CLAMP(in_y1, ymin, ymax);
2502 CLAMP(in_y2, ymin, ymax);
2504 int out_x1 = out_x - HANDLE_W / 2;
2505 int out_x2 = out_x + HANDLE_W / 2;
2506 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2507 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2508 CLAMP(out_y1, ymin, ymax);
2509 CLAMP(out_y2, ymin, ymax);
2512 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2513 // buttonpress could be the start of a drag operation
2514 #define INIT_DRAG(POS,VAL) \
2515 mwindow->session->drag_auto = current; \
2516 mwindow->session->drag_origin_x = cursor_x; \
2517 mwindow->session->drag_origin_y = cursor_y; \
2518 mwindow->session->drag_start_position = (POS); \
2519 mwindow->session->drag_start_percentage = (VAL);
2521 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2524 // without modifier we are manipulating the automation node
2525 // with ALT it's about dragging only the value of the node
2526 // with SHIFT the value snaps to the value of neighbouring nodes
2527 // CTRL indicates we are rather manipulating the tangent(s) of the node
2531 if( WITHIN(x1,x2,y1,y2))
2532 { // cursor hits node
2535 if(buttonpress && (buttonpress != 3))
2537 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2538 mwindow->session->drag_handle = 0;
2543 if( WITHIN(x1,x2,y1,y2))
2546 if(buttonpress && (buttonpress != 3))
2548 // could be ctrl-click or ctrl-drag
2549 // click would cycle through tangent modes
2550 ((FloatAuto*)current)->toggle_curve_mode();
2552 // drag will start dragging the tangent, if applicable
2553 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2554 mwindow->session->drag_handle = 0;
2558 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2561 if( in_x != x && current->position > 0 &&
2562 (FloatAuto::FREE == current->curve_mode ||
2563 FloatAuto::TFREE == current->curve_mode))
2564 // act on in control handle only if
2565 // tangent is significant and is editable (not automatically choosen)
2567 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2568 // either cursor in ctrl-point handle or cursor on tangent line
2569 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2571 if(buttonpress && (buttonpress != 3)) {
2572 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2574 mwindow->session->drag_handle = 1;
2575 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2576 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2577 value_to_percentage(new_invalue, autogrouptype))
2584 (FloatAuto::FREE == current->curve_mode ||
2585 FloatAuto::TFREE == current->curve_mode))
2586 // act on out control only if tangent is significant and is editable
2588 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2589 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2591 if(buttonpress && (buttonpress != 3)) {
2592 if(lever == 0.0) lever=1.0;
2594 mwindow->session->drag_handle = 2;
2595 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2596 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2597 value_to_percentage(new_outvalue, autogrouptype))
2601 } // end ctrl_down()
2607 // 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",
2608 // mwindow->session->drag_handle,
2613 if(buttonpress && (buttonpress != 3) && result)
2615 mwindow->undo->update_undo_before();
2622 // Get the float value & y for position x on the canvas
2623 #define X_TO_FLOATLINE(x) \
2624 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2625 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2626 /* Call by reference fails for some reason here */ \
2627 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2628 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2629 double position = unit_start + x * zoom_units; \
2631 if(position2 > position1) \
2634 (value2 - value1) * \
2635 (position - position1) / \
2636 (position2 - position1); \
2642 AUTOMATIONCLAMPS(value, autogrouptype); \
2643 int y = center_pixel + \
2644 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2647 void TrackCanvas::draw_floatline(int center_pixel,
2648 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2649 double unit_start, double zoom_units, double yscale,
2650 int x1, int y1, int x2, int y2,
2651 int color, int autogrouptype)
2653 // Solve bezier equation for either every pixel or a certain large number of
2656 // Not using slope intercept
2658 int prev_y = y1 + center_pixel;
2661 // Call by reference fails for some reason here
2662 FloatAuto *previous1 = previous, *next1 = next;
2663 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2664 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2665 float automation_range = automation_max - automation_min;
2667 for(int x = x1; x < x2; x++)
2669 // Interpolate value between frames
2673 y >= center_pixel - yscale / 2 &&
2674 y < center_pixel + yscale / 2 - 1)
2676 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2678 // (int)(center_pixel - yscale / 2),
2679 // (int)(center_pixel + yscale / 2 - 1));
2681 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2682 draw_line(x - 1, prev_y , x, y );
2692 int TrackCanvas::test_floatline(int center_pixel,
2707 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2708 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2709 float automation_range = automation_max - automation_min;
2710 FloatAuto *previous1 = 0, *next1 = 0;
2711 X_TO_FLOATLINE(cursor_x);
2713 if(cursor_x >= x1 &&
2715 cursor_y >= y - HANDLE_W / 2 &&
2716 cursor_y < y + HANDLE_W / 2 &&
2722 if(buttonpress == 3)
2730 mwindow->undo->update_undo_before();
2731 double position = autos->track->from_units(position1);
2732 position = mwindow->edl->align_to_frame(position, 0);
2733 int64_t new_position = autos->track->to_units(position,0);
2734 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2735 ((FloatAuto*)current)->set_value(value);
2736 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2737 mwindow->session->drag_start_position = current->position;
2738 mwindow->session->drag_origin_x = cursor_x;
2739 mwindow->session->drag_origin_y = cursor_y;
2740 mwindow->session->drag_handle = 0;
2749 void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto)
2751 if( !skip->gang ) return;
2752 // Handles the special case of modifying a fadeauto
2753 // when there are ganged faders on several tracks
2754 double position = skip->from_units(fauto->position);
2755 int autoidx = fauto->autos->autoidx;
2757 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2758 if( (all || current->data_type == skip->data_type) &&
2759 current->gang && current->record && current != skip ) {
2760 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2761 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2762 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2763 int64_t current_position = current->to_units(position, 1);
2764 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
2766 // keyframe exists, just change it
2767 float value = keyframe->get_value();
2768 float new_value = value + change;
2769 CLAMP(new_value, auto_min, auto_max);
2770 keyframe->adjust_to_new_coordinates(current_position, new_value);
2773 // create keyframe on neighbouring track at the point in time given by fauto
2774 FloatAuto *previous = 0, *next = 0;
2775 float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2776 float new_value = value + change;
2777 CLAMP(new_value, auto_min, auto_max);
2778 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2779 keyframe->set_value(new_value);
2781 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2786 void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
2788 double position = skip->from_units(fauto->position);
2790 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2791 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2792 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2793 float new_value = keyframe->get_value() + change;
2795 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2796 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2797 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2801 void TrackCanvas::clear_ganged_autos()
2804 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2805 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2806 keyframe->autos->remove_nonsequential(keyframe);
2808 mwindow->session->drag_auto_gang->remove_all();
2812 void TrackCanvas::draw_toggleline(int center_pixel,
2818 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2822 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2826 int TrackCanvas::test_toggleline(Autos *autos,
2837 if(cursor_x >= x1 && cursor_x < x2)
2839 int miny = center_pixel + y1 - HANDLE_W / 2;
2840 int maxy = center_pixel + y1 + HANDLE_W / 2;
2841 if(cursor_y >= miny && cursor_y < maxy)
2846 if(buttonpress == 3)
2854 double position = (double)(cursor_x +
2855 mwindow->edl->local_session->view_start[pane->number]) *
2856 mwindow->edl->local_session->zoom_sample /
2857 mwindow->edl->session->sample_rate;
2858 int64_t unit_position = autos->track->to_units(position, 0);
2859 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2861 mwindow->undo->update_undo_before();
2863 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2864 ((IntAuto*)current)->value = new_value;
2865 // Toggle Autos don't respond to vertical zoom, they always show up
2866 // with "on" == 100% == line on top
2867 mwindow->session->drag_start_percentage = (float)new_value;
2868 mwindow->session->drag_start_position = current->position;
2869 mwindow->session->drag_origin_x = cursor_x;
2870 mwindow->session->drag_origin_y = cursor_y;
2878 void TrackCanvas::calculate_viewport(Track *track,
2879 double &view_start, // Seconds
2881 double &view_end, // Seconds
2885 double &zoom_sample,
2889 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2890 mwindow->edl->local_session->zoom_sample /
2891 mwindow->edl->session->sample_rate;
2892 unit_start = track->to_doubleunits(view_start);
2893 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2895 mwindow->edl->local_session->zoom_sample /
2896 mwindow->edl->session->sample_rate;
2897 unit_end = track->to_doubleunits(view_end);
2899 int y = track->y_pixel
2900 - mwindow->edl->local_session->track_start[pane->number];
2901 int has_titles = track->show_titles();
2902 int has_assets = track->show_assets();
2903 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
2904 double asset_h = resource_h();
2905 double title_h = mwindow->theme->title_h;
2906 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
2907 double dy = has_titles ?
2908 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) :
2909 ( has_assets ? asset_h/2 : 0) ;
2910 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
2912 center_pixel = y + dy;
2914 zoom_sample = mwindow->edl->local_session->zoom_sample;
2915 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2918 float TrackCanvas::percentage_to_value(float percentage,
2926 if(percentage > 0.5)
2933 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2934 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2935 float automation_range = automation_max - automation_min;
2937 result = percentage * automation_range + automation_min;
2940 FloatAuto *ptr = (FloatAuto*)reference;
2941 result -= ptr->get_value();
2943 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2949 void TrackCanvas::calculate_auto_position(double *x, double *y,
2950 double *in_x, double *in_y, double *out_x, double *out_y,
2951 Auto *current, double unit_start, double zoom_units, double yscale,
2954 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2955 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2956 float automation_range = automation_max - automation_min;
2957 FloatAuto *ptr = (FloatAuto*)current;
2958 *x = (double)(ptr->position - unit_start) / zoom_units;
2959 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2962 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2963 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2967 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2968 automation_min) / automation_range - 0.5) * -yscale;
2972 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2973 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2977 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2978 automation_min) / automation_range - 0.5) * -yscale;
2983 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2984 int draw, int buttonpress, int x_offset, int y_offset, int color,
2985 Auto* &auto_instance, int autogrouptype)
2988 int center_pixel, draw_auto;
2989 double view_start, unit_start;
2990 double view_end, unit_end, yscale;
2991 double zoom_sample, zoom_units;
2992 double in_x2, in_y2, out_x2, out_y2;
2998 if(draw) set_color(color);
3000 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3001 yscale, center_pixel, zoom_sample, zoom_units);
3003 // Get first auto before start
3004 Auto *current = 0, *previous = 0;
3006 for( current = autos->last;
3007 current && current->position >= unit_start;
3008 current = PREVIOUS ) ;
3010 Auto *first_auto = current ? current :
3011 autos->first ? autos->first : autos->default_auto;
3013 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
3015 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3016 first_auto, unit_start, zoom_units, yscale, autogrouptype);
3021 current = autos->first;
3030 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
3031 current, unit_start, zoom_units, yscale, autogrouptype);
3039 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3044 ay2 = ay + slope * (get_w() - ax);
3048 ay = ay + slope * (0 - ax);
3052 // Draw or test handle
3053 if( current && !result && current != autos->default_auto ) {
3054 if( !draw && track->record ) {
3055 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3056 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3057 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3058 buttonpress, autogrouptype);
3060 auto_instance = current;
3062 if( draw && draw_auto ) {
3063 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3064 (int)in_x2 + x_offset, (int)in_y2,
3065 (int)out_x2 + x_offset, (int)out_y2,
3066 (int)center_pixel + y_offset, (int)yscale, color);
3070 // Draw or test joining line
3071 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3072 result = test_floatline(center_pixel,
3073 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3074 // Exclude auto coverage from the end of the line. The auto overlaps
3075 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3076 buttonpress, autogrouptype);
3079 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3080 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3081 (int)ax, (int)ay, (int)ax2, (int)ay2,
3082 color, autogrouptype);
3090 } while( current && current->position <= unit_end && !result );
3092 if( ax < get_w() && !result ) {
3093 ax2 = get_w(); ay2 = ay;
3094 if(!draw && track->record /* && buttonpress != 3 */ ) {
3095 result = test_floatline(center_pixel,
3096 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3097 (int)ax, (int)ax2, cursor_x, cursor_y,
3098 buttonpress, autogrouptype);
3101 draw_floatline(center_pixel,
3102 (FloatAuto*)previous, (FloatAuto*)current,
3103 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3104 (int)ax, (int)ay, (int)ax2, (int)ay2,
3105 color, autogrouptype);
3112 int TrackCanvas::do_int_autos(Track *track,
3121 Auto *&auto_instance)
3132 double ax, ay, ax2, ay2;
3136 if(draw) set_color(color);
3138 calculate_viewport(track,
3149 double high = -yscale * 0.8 / 2;
3150 double low = yscale * 0.8 / 2;
3152 // Get first auto before start
3154 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3160 ay = ((IntAuto*)current)->value > 0 ? high : low;
3165 current = autos->first ? autos->first : autos->default_auto;
3169 ay = ((IntAuto*)current)->value > 0 ? high : low;
3182 ax2 = (double)(current->position - unit_start) / zoom_units;
3183 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3191 if(ax2 > get_w()) ax2 = get_w();
3193 if(current && !result)
3195 if(current != autos->default_auto)
3201 result = test_auto(current,
3210 auto_instance = current;
3215 (int)ax2 + x_offset,
3216 (int)ay2 + y_offset,
3228 if(track->record /* && buttonpress != 3 */)
3230 result = test_toggleline(autos,
3243 draw_toggleline(center_pixel + y_offset,
3251 }while(current && current->position <= unit_end && !result);
3253 if(ax < get_w() && !result)
3259 if(track->record /* && buttonpress != 3 */)
3261 result = test_toggleline(autos,
3273 draw_toggleline(center_pixel + y_offset,
3282 int TrackCanvas::do_autos(Track *track,
3289 Auto * &auto_instance,
3303 calculate_viewport(track,
3316 for(current = autos->first; current && !result; current = NEXT)
3318 if(current->position >= unit_start && current->position < unit_end)
3321 x = (int64_t)((double)(current->position - unit_start) /
3322 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3323 y = center_pixel - pixmap->get_h() / 2;
3327 if(cursor_x >= x && cursor_y >= y &&
3328 cursor_x < x + pixmap->get_w() &&
3329 cursor_y < y + pixmap->get_h())
3332 auto_instance = current;
3334 if(buttonpress && (buttonpress != 3))
3336 mwindow->session->drag_auto = current;
3337 mwindow->session->drag_start_position = current->position;
3338 mwindow->session->drag_origin_x = cursor_x;
3339 mwindow->session->drag_origin_y = cursor_y;
3341 double position = autos->track->from_units(current->position);
3342 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3343 mwindow->edl->local_session->get_selectionend(1)) /
3348 mwindow->edl->local_session->set_selectionstart(position);
3349 mwindow->edl->local_session->set_selectionend(position);
3352 if(position < center)
3354 mwindow->edl->local_session->set_selectionstart(position);
3357 mwindow->edl->local_session->set_selectionend(position);
3364 draw_pixmap(pixmap, x, y);
3372 // so this means it is always >0 when keyframe is found
3373 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3374 int draw, int buttonpress, Plugin* &keyframe_plugin,
3375 KeyFrame* &keyframe_instance)
3388 if(!track->expand_view) return 0;
3390 calculate_viewport(track,
3402 for(int i = 0; i < track->plugin_set.total && !result; i++)
3404 PluginSet *plugin_set = track->plugin_set.values[i];
3405 int center_pixel = track->y_pixel -
3406 mwindow->edl->local_session->track_start[pane->number];
3407 if( track->show_titles() )
3408 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
3409 if( track->show_assets() )
3410 center_pixel += resource_h();
3411 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
3413 for(Plugin *plugin = (Plugin*)plugin_set->first;
3415 plugin = (Plugin*)plugin->next)
3417 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3418 keyframe && !result;
3419 keyframe = (KeyFrame*)keyframe->next)
3421 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3422 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3424 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3425 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3427 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3430 if(cursor_x >= x && cursor_y >= y &&
3431 cursor_x < x + keyframe_pixmap->get_w() &&
3432 cursor_y < y + keyframe_pixmap->get_h())
3435 keyframe_plugin = plugin;
3436 keyframe_instance = keyframe;
3440 mwindow->session->drag_auto = keyframe;
3441 mwindow->session->drag_start_position = keyframe->position;
3442 mwindow->session->drag_origin_x = cursor_x;
3443 mwindow->session->drag_origin_y = cursor_y;
3445 double position = track->from_units(keyframe->position);
3446 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3447 mwindow->edl->local_session->get_selectionend(1)) /
3452 mwindow->edl->local_session->set_selectionstart(position);
3453 mwindow->edl->local_session->set_selectionend(position);
3456 if(position < center)
3458 mwindow->edl->local_session->set_selectionstart(position);
3461 mwindow->edl->local_session->set_selectionend(position);
3466 draw_pixmap(keyframe_pixmap,
3476 // if(buttonpress && buttonpress != 3 && result)
3478 // mwindow->undo->update_undo_before();
3484 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
3486 Track *track = auto_keyframe->autos->track;
3487 int autogrouptype = auto_keyframe->autos->autogrouptype;
3490 double view_start, unit_start;
3491 double view_end, unit_end, yscale;
3492 double zoom_sample, zoom_units;
3494 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3495 yscale, center_pixel, zoom_sample, zoom_units);
3497 double ax = 0, ay = 0;
3498 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3499 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3502 draw_line(ax, 0, ax, get_h());
3505 char text[BCSTRLEN];
3506 if( auto_keyframe->is_floatauto() ) {
3507 FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
3508 sprintf(text, "%0.2f", float_auto->get_value());
3511 IntAuto *int_auto = (IntAuto *)auto_keyframe;
3512 sprintf(text, "%d", int_auto->value);
3514 int font = MEDIUMFONT;
3515 int tw = get_text_width(font, text) + TOOLTIP_MARGIN * 2;
3516 int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2;
3517 set_color(get_resources()->tooltip_bg_color);
3519 ay += center_pixel + HANDLE_W/2;
3520 draw_box(ax, ay, tw, th);
3522 draw_rectangle(ax, ay, tw, th);
3524 ax += TOOLTIP_MARGIN;
3525 ay += TOOLTIP_MARGIN + get_text_ascent(font);
3526 draw_text(ax, ay, text);
3531 void TrackCanvas::draw_overlays()
3533 int new_cursor, update_cursor, rerender;
3535 // Move background pixmap to foreground pixmap
3536 draw_pixmap(background_pixmap,
3545 draw_inout_points();
3556 draw_brender_range();
3558 // Highlighted areas
3559 draw_highlighting();
3562 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3565 if(pane->cursor) pane->cursor->restore(1);
3571 draw_playback_cursor();
3573 draw_keyframe_reticle();
3578 int TrackCanvas::activate()
3582 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3583 //BC_Signals::dump_stack();
3584 get_top_level()->deactivate();
3586 set_active_subwindow(this);
3587 pane->cursor->activate();
3588 gui->focused_pane = pane->number;
3593 int TrackCanvas::deactivate()
3598 pane->cursor->deactivate();
3604 void TrackCanvas::update_drag_handle()
3606 double new_position;
3607 int cursor_x = get_cursor_x();
3611 mwindow->edl->local_session->view_start[pane->number]) *
3612 mwindow->edl->local_session->zoom_sample /
3613 mwindow->edl->session->sample_rate;
3616 mwindow->edl->align_to_frame(new_position, 0);
3618 if( ctrl_down() && alt_down() ) {
3619 #define snapper(v) do { \
3621 if( pos < 0 ) break; \
3622 double dist = fabs(new_position - pos); \
3623 if( dist >= snap_min ) break; \
3624 snap_position = pos; snap_min = dist; \
3626 double snap_position = new_position;
3627 double snap_min = DBL_MAX;
3628 if( mwindow->edl->local_session->inpoint_valid() )
3629 snapper(mwindow->edl->local_session->get_inpoint());
3630 if( mwindow->edl->local_session->outpoint_valid() )
3631 snapper(mwindow->edl->local_session->get_outpoint());
3632 snapper(mwindow->edl->prev_edit(new_position));
3633 snapper(mwindow->edl->next_edit(new_position));
3634 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3635 if( prev_label ) snapper(prev_label->position);
3636 Label *next_label = mwindow->edl->labels->next_label(new_position);
3637 if( next_label ) snapper(next_label->position);
3638 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3639 mwindow->edl->local_session->zoom_sample -
3640 mwindow->edl->local_session->view_start[pane->number];
3641 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3643 new_position = snap_position;
3648 if(new_position != mwindow->session->drag_position)
3650 mwindow->session->drag_position = new_position;
3651 gui->mainclock->update(new_position);
3652 timebar_position = new_position;
3653 gui->update_timebar(0);
3656 edl->create_objects();
3657 edl->copy_all(mwindow->edl);
3658 MainSession *session = mwindow->session;
3659 int edit_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
3660 edl->modify_edithandles(session->drag_start,
3661 session->drag_position,
3662 session->drag_handle,
3664 edl->session->labels_follow_edits,
3665 edl->session->plugins_follow_edits,
3666 edl->session->autos_follow_edits);
3667 double position = edit_mode != MOVE_NO_EDITS &&
3668 ( session->drag_handle || edit_mode == MOVE_ONE_EDIT ) ?
3669 session->drag_position : session->drag_start;
3670 Track *track = session->drag_handle_track();
3671 int64_t pos = track->to_units(position, 0);
3672 render_handle_frame(edl, pos, shift_down() ? 0 :
3673 session->drag_handle ? 1 : 2);
3678 int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
3681 int64_t left = pos-1;
3682 if( left < 0 ) left = 0;
3685 VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
3686 VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
3687 TransportCommand command;
3688 command.command = CURRENT_FRAME;
3689 command.get_edl()->copy_all((EDL *)edl);
3690 command.change_type = CHANGE_ALL;
3691 command.realtime = 0;
3692 Preferences *preferences = mwindow->preferences;
3693 RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
3694 CICache *video_cache = new CICache(preferences);
3695 render_engine->set_vcache(video_cache);
3696 render_engine->arm_command(&command);
3697 int64_t left = pos-1;
3698 if( left < 0 ) left = 0;
3699 VRender *vrender = render_engine->vrender;
3701 !vrender->process_buffer(&vlt, left, 0) &&
3702 !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1;
3703 delete render_engine;
3705 mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0");
3706 Canvas *canvas = mwindow->cwindow->gui->canvas;
3707 canvas->lock_canvas("TrackCanvas::render_handle_frame 1");
3708 int w = canvas->w, h = canvas->h, w2 = w/2, h2 = h/2;
3709 int lx = 0, ly = h2/2, rx = w2, ry = h2/2;
3710 BC_WindowBase *window = canvas->get_canvas();
3711 window->set_color(BLACK);
3712 window->clear_box(0,0, window->get_w(),window->get_h());
3713 window->draw_vframe(&vlt, lx,ly, w2,h2, 0,0,vlt.get_w(),vlt.get_h());
3714 window->draw_vframe(&vrt, rx,ry, w2,h2, 0,0,vrt.get_w(),vrt.get_h());
3716 canvas->unlock_canvas();
3717 mwindow->cwindow->gui->unlock_window();
3721 Track *track = mwindow->session->drag_handle_track();
3722 double position = track->from_units(mode == 1 ? left : pos);
3723 if( position < 0 ) position = 0;
3724 edl->local_session->set_selectionstart(position);
3725 edl->local_session->set_selectionend(position);
3726 PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine;
3727 if( playback_engine->is_playing_back )
3728 playback_engine->stop_playback(1);
3729 mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
3735 int TrackCanvas::update_drag_edit()
3744 int TrackCanvas::get_drag_values(float *percentage,
3751 //int x = cursor_x - mwindow->session->drag_origin_x;
3752 //int y = cursor_y - mwindow->session->drag_origin_y;
3756 if(!current->autos->track->record) return 1;
3766 calculate_viewport(current->autos->track,
3776 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3778 mwindow->session->drag_start_percentage;
3779 if(do_clamp) CLAMP(*percentage, 0, 1);
3781 *position = Units::to_int64(zoom_units *
3782 (cursor_x - mwindow->session->drag_origin_x) +
3783 mwindow->session->drag_start_position + 0.5);
3785 if((do_clamp) && *position < 0) *position = 0;
3790 #define UPDATE_DRAG_HEAD(do_clamp) \
3791 int result = 0, center_pixel; \
3792 if(!current->autos->track->record) return 0; \
3793 double view_start, unit_start, view_end, unit_end; \
3794 double yscale, zoom_sample, zoom_units; \
3796 calculate_viewport(current->autos->track, \
3797 view_start, unit_start, view_end, unit_end, \
3798 yscale, center_pixel, zoom_sample, zoom_units); \
3800 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3801 yscale + mwindow->session->drag_start_percentage; \
3802 if(do_clamp) CLAMP(percentage, 0, 1); \
3804 int64_t position = Units::to_int64(zoom_units * \
3805 (cursor_x - mwindow->session->drag_origin_x) + \
3806 mwindow->session->drag_start_position); \
3807 if((do_clamp) && position < 0) position = 0;
3810 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3812 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3814 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3815 int x = cursor_x - mwindow->session->drag_origin_x;
3816 int y = cursor_y - mwindow->session->drag_origin_y;
3817 float value, old_value;
3819 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3820 // not really editing the node, rather start editing the curve
3821 // tangent is editable and drag movement is significant
3822 if( (FloatAuto::FREE == current->curve_mode ||
3823 FloatAuto::TFREE==current->curve_mode) &&
3824 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3825 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3828 switch(mwindow->session->drag_handle) {
3830 // Snap to nearby values
3831 old_value = current->get_value();
3833 double value1, value2, distance1, distance2;
3835 if(current->previous) {
3836 int autogrouptype = current->previous->autos->autogrouptype;
3837 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3838 value1 = ((FloatAuto*)current->previous)->get_value();
3839 distance1 = fabs(value - value1);
3840 current->set_value(value1);
3844 int autogrouptype = current->next->autos->autogrouptype;
3845 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3846 value2 = ((FloatAuto*)current->next)->get_value();
3847 distance2 = fabs(value - value2);
3848 if(!current->previous || distance2 < distance1) {
3849 current->set_value(value2);
3853 if(!current->previous && !current->next) {
3854 current->set_value( ((FloatAutos*)current->autos)->default_);
3856 value = current->get_value();
3859 int autogrouptype = current->autos->autogrouptype;
3860 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3863 if(alt_down() && !shift_down())
3864 // ALT constrains movement: fixed position, only changing the value
3865 position = mwindow->session->drag_start_position;
3867 if(value != old_value || position != current->position) {
3869 float change = value - old_value;
3870 current->adjust_to_new_coordinates(position, value);
3871 update_ganged_autos(change, current->autos->track, current);
3872 show_message(current, 1,", %.2f", current->get_value());
3878 int autogrouptype = current->autos->autogrouptype;
3879 value = percentage_to_value(percentage, 0, current, autogrouptype);
3880 if(value != current->get_control_in_value())
3883 // note: (position,value) need not be at the location of the ctrl point,
3884 // but could be somewhere in between on the curve (or even outward or
3885 // on the opposit side). We set the new control point such as
3886 // to point the curve through (position,value)
3887 current->set_control_in_value(
3888 value * levered_position(position - current->position,
3889 current->get_control_in_position()));
3890 update_ganged_autos(0, current->autos->track, current);
3891 show_message(current, 1,", %.2f", current->get_control_in_value());
3897 int autogrouptype = current->autos->autogrouptype;
3898 value = percentage_to_value(percentage, 0, current, autogrouptype);
3899 if(value != current->get_control_out_value()) {
3901 current->set_control_out_value(
3902 value * levered_position(position - current->position,
3903 current->get_control_out_position()));
3904 update_ganged_autos(0, current->autos->track, current);
3905 show_message(current, 1,", %.2f", current->get_control_out_value());
3913 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3915 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3917 UPDATE_DRAG_HEAD(1);
3918 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3920 if(value != current->value || position != current->position)
3923 current->value = value;
3924 current->position = position;
3925 show_message(current, 0,", %d", current->value);
3931 // Autos which can't change value through dragging.
3933 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3935 Auto *current = (Auto*)mwindow->session->drag_auto;
3938 if(position != current->position)
3941 current->position = position;
3942 show_message(current, 0,"");
3944 double position_f = current->autos->track->from_units(current->position);
3945 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3946 mwindow->edl->local_session->get_selectionend(1)) /
3950 mwindow->edl->local_session->set_selectionstart(position_f);
3951 mwindow->edl->local_session->set_selectionend(position_f);
3954 if(position_f < center_f)
3956 mwindow->edl->local_session->set_selectionstart(position_f);
3959 mwindow->edl->local_session->set_selectionend(position_f);
3966 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3968 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3971 if(position != current->position)
3973 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3974 Track *track = current->autos->track;
3975 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3976 PluginSet *pluginset;
3978 // figure out the correct pluginset & correct plugin
3980 for(int i = 0; i < track->plugin_set.total; i++)
3982 pluginset = track->plugin_set.values[i];
3983 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3985 KeyFrames *keyframes = plugin->keyframes;
3986 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3988 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3990 if (currentkeyframe == current)
4002 mwindow->session->plugin_highlighted = plugin;
4003 mwindow->session->track_highlighted = track;
4005 current->position = position;
4006 show_message(current, 0,"");
4008 double position_f = current->autos->track->from_units(current->position);
4009 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4010 mwindow->edl->local_session->get_selectionend(1)) /
4014 mwindow->edl->local_session->set_selectionstart(position_f);
4015 mwindow->edl->local_session->set_selectionend(position_f);
4018 if(position_f < center_f)
4020 mwindow->edl->local_session->set_selectionstart(position_f);
4023 mwindow->edl->local_session->set_selectionend(position_f);
4030 void TrackCanvas::update_drag_caption()
4032 switch(mwindow->session->current_operation)
4042 int TrackCanvas::cursor_update(int in_motion)
4047 int update_clock = 0;
4048 int update_zoom = 0;
4049 int update_scroll = 0;
4050 int update_overlay = 0;
4051 int update_cursor = 0;
4054 double position = 0.;
4055 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4058 switch(mwindow->edl->session->editing_mode)
4060 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
4061 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
4064 switch(mwindow->session->current_operation)
4066 case DRAG_EDITHANDLE1:
4067 // Outside threshold. Upgrade status
4070 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4072 mwindow->session->current_operation = DRAG_EDITHANDLE2;
4078 case DRAG_EDITHANDLE2:
4081 update_drag_handle();
4086 case DRAG_PLUGINHANDLE1:
4089 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4091 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
4097 case DRAG_PLUGINHANDLE2:
4100 update_drag_handle();
4105 // Rubber band curves
4113 case DRAG_PROJECTOR_X:
4114 case DRAG_PROJECTOR_Y:
4115 case DRAG_PROJECTOR_Z:
4116 if(active) rerender = update_overlay =
4117 update_drag_floatauto(get_cursor_x(), get_cursor_y());
4118 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
4119 mwindow->speed_after(!in_motion ? 1 : 0);
4123 if(active) rerender = update_overlay =
4124 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4128 if(active) rerender = update_overlay =
4129 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4132 // Keyframe icons are sticky
4136 case DRAG_PLUGINKEY_PRE:
4138 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
4139 mwindow->session->current_operation++;
4142 mwindow->undo->update_undo_before();
4150 if(active) rerender = update_overlay =
4151 update_drag_auto(get_cursor_x(), get_cursor_y());
4154 case DRAG_PLUGINKEY:
4155 if(active) rerender = update_overlay =
4156 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4161 cursor_x = get_cursor_x();
4162 cursor_y = get_cursor_y();
4163 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4164 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4166 position = mwindow->edl->align_to_frame(position, 0);
4167 position = MAX(position, 0);
4169 double start = mwindow->edl->local_session->get_selectionstart(1);
4170 double end = mwindow->edl->local_session->get_selectionend(1);
4171 if(position < selection_midpoint) {
4172 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4173 mwindow->edl->local_session->set_selectionstart(position);
4176 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4177 mwindow->edl->local_session->set_selectionend(position);
4180 gui->unlock_window();
4182 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
4183 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
4184 mwindow->cwindow->update(dir, 0, 0, 0, 1);
4185 gui->lock_window("TrackCanvas::cursor_update 1");
4186 // Update the faders
4187 mwindow->update_plugin_guis();
4188 gui->update_patchbay();
4190 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4192 gui->hide_cursor(0);
4193 gui->draw_cursor(1);
4194 gui->update_timebar(0);
4195 gui->flash_canvas(1);
4203 case DROP_TARGETING:
4204 new_cursor = GRABBED_CURSOR;
4208 if(is_event_win() && cursor_inside()) {
4210 cursor_x = get_cursor_x();
4211 position = (double)cursor_x *
4212 (double)mwindow->edl->local_session->zoom_sample /
4213 (double)mwindow->edl->session->sample_rate +
4214 (double)mwindow->edl->local_session->view_start[pane->number] *
4215 (double)mwindow->edl->local_session->zoom_sample /
4216 (double)mwindow->edl->session->sample_rate;
4217 position = mwindow->edl->align_to_frame(position, 0);
4221 for(int i = 0; i < TOTAL_PANES; i++)
4222 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4224 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4225 gui->update_timebar(0);
4227 if(do_transitions(get_cursor_x(), get_cursor_y(),
4228 0, new_cursor, update_cursor)) break;
4229 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4230 0, 0, new_cursor, update_cursor, rerender)) break;
4231 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4232 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4233 // Plugin boundaries
4234 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4235 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4236 if(do_edits(get_cursor_x(), get_cursor_y(),
4237 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4242 //printf("TrackCanvas::cursor_update 1\n");
4243 if(update_cursor && new_cursor != get_cursor())
4245 set_cursor(new_cursor, 0, 1);
4248 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
4249 if(rerender && render_timer->get_difference() > 0.25 ) {
4250 render_timer->update();
4251 mwindow->restart_brender();
4252 mwindow->sync_parameters(CHANGE_PARAMS);
4253 mwindow->update_plugin_guis();
4254 gui->unlock_window();
4255 mwindow->cwindow->update(1, 0, 0, 0, 1);
4256 gui->lock_window("TrackCanvas::cursor_update 2");
4260 gui->update_patchbay();
4265 if(!mwindow->cwindow->playback_engine->is_playing_back)
4266 gui->mainclock->update(position);
4270 gui->zoombar->update();
4275 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4279 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4283 if(update_overlay) {
4284 gui->draw_overlays(1);
4287 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4291 int TrackCanvas::cursor_motion_event()
4293 return cursor_update(1);
4296 void TrackCanvas::start_dragscroll()
4300 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4301 //printf("TrackCanvas::start_dragscroll 1\n");
4305 void TrackCanvas::stop_dragscroll()
4309 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4310 //printf("TrackCanvas::stop_dragscroll 1\n");
4314 int TrackCanvas::repeat_event(int64_t duration)
4316 if(!drag_scroll) return 0;
4317 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4319 int sample_movement = 0;
4320 int track_movement = 0;
4321 int64_t x_distance = 0;
4322 int64_t y_distance = 0;
4323 double position = 0;
4326 switch(mwindow->session->current_operation) {
4328 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4329 if(get_cursor_x() > get_w()) {
4330 x_distance = get_cursor_x() - get_w();
4331 sample_movement = 1;
4333 else if(get_cursor_x() < 0) {
4334 x_distance = get_cursor_x();
4335 sample_movement = 1;
4338 if(get_cursor_y() > get_h()) {
4339 y_distance = get_cursor_y() - get_h();
4342 else if(get_cursor_y() < 0) {
4343 y_distance = get_cursor_y();
4350 if(sample_movement) {
4351 position = (double)(get_cursor_x() +
4352 mwindow->edl->local_session->view_start[pane->number] +
4354 mwindow->edl->local_session->zoom_sample /
4355 mwindow->edl->session->sample_rate;
4356 position = mwindow->edl->align_to_frame(position, 0);
4357 position = MAX(position, 0);
4359 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4360 switch(mwindow->session->current_operation) {
4362 if(position < selection_midpoint) {
4363 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4364 mwindow->edl->local_session->set_selectionstart(position);
4366 gui->unlock_window();
4367 mwindow->cwindow->update(1, 0, 0);
4368 gui->lock_window("TrackCanvas::repeat_event");
4369 // Update the faders
4370 mwindow->update_plugin_guis();
4371 gui->update_patchbay();
4374 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4375 mwindow->edl->local_session->set_selectionend(position);
4376 // Don't que the CWindow
4381 mwindow->samplemovement(
4382 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4386 if(track_movement) {
4387 mwindow->trackmovement(y_distance, pane->number);
4393 int TrackCanvas::button_release_event()
4395 int redraw = -1, update_overlay = 0;
4396 int result = 0, load_flags = 0;
4398 // printf("TrackCanvas::button_release_event %d\n",
4399 // mwindow->session->current_operation);
4401 switch(mwindow->session->current_operation) {
4402 case DRAG_EDITHANDLE2:
4403 mwindow->session->current_operation = NO_OPERATION;
4407 end_edithandle_selection();
4410 case DRAG_EDITHANDLE1:
4411 mwindow->session->current_operation = NO_OPERATION;
4416 case DRAG_PLUGINHANDLE2:
4417 mwindow->session->current_operation = NO_OPERATION;
4421 end_pluginhandle_selection();
4424 case DRAG_PLUGINHANDLE1:
4425 mwindow->session->current_operation = NO_OPERATION;
4431 redraw = FORCE_REDRAW;
4432 load_flags |= LOAD_EDITS;
4434 // delete the drag_auto_gang first and remove out of order keys
4435 clear_ganged_autos();
4446 case DRAG_PROJECTOR_X:
4447 case DRAG_PROJECTOR_Y:
4448 case DRAG_PROJECTOR_Z:
4449 case DRAG_PLUGINKEY:
4450 load_flags |= LOAD_AUTOMATION;
4451 mwindow->session->current_operation = NO_OPERATION;
4452 mwindow->session->drag_handle = 0;
4453 // Remove any out-of-order keyframe
4454 if(mwindow->session->drag_auto) {
4455 mwindow->session->drag_auto->autos->remove_nonsequential(
4456 mwindow->session->drag_auto);
4457 // mwindow->session->drag_auto->autos->optimize();
4461 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
4466 case DRAG_AEFFECT_COPY:
4467 case DRAG_VEFFECT_COPY:
4468 // Trap in drag stop
4471 case DROP_TARGETING: {
4472 int cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
4473 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4474 drag_cursor_motion(cursor_x, cursor_y,
4475 &track, &edit, &pluginset, &plugin);
4477 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4478 gui->edit_menu->activate_menu(track, edit, pluginset, plugin, position);
4479 mwindow->session->current_operation = NO_OPERATION;
4484 if(mwindow->session->current_operation) {
4485 // if(mwindow->session->current_operation == SELECT_REGION) {
4486 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4489 mwindow->session->current_operation = NO_OPERATION;
4491 // Traps button release events
4501 if(update_overlay) {
4502 gui->draw_overlays(1);
4505 gui->draw_canvas(redraw, 0);
4506 gui->flash_canvas(1);
4511 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4512 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4514 Edit *edit_result = 0;
4515 int handle_result = -1;
4518 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4519 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4520 int64_t edit_x, edit_y, edit_w, edit_h;
4521 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4523 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4524 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4525 if( cursor_x < edit_x + HANDLE_W ) {
4528 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4529 track->show_assets() ) {
4530 new_cursor = DOWNLEFT_RESIZE;
4531 if( button_press == LEFT_BUTTON )
4537 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4540 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4541 track->show_assets() ) {
4542 new_cursor = DOWNRIGHT_RESIZE;
4543 if( button_press == LEFT_BUTTON )
4555 double position = 0;
4556 if( handle_result == 0 ) {
4557 position = edit_result->track->from_units(edit_result->startproject);
4558 new_cursor = LEFT_CURSOR;
4560 else if( handle_result == 1 ) {
4561 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4562 new_cursor = RIGHT_CURSOR;
4565 // Reposition cursor
4566 if( button_press ) {
4567 mwindow->session->drag_edit = edit_result;
4568 mwindow->session->drag_handle = handle_result;
4569 mwindow->session->drag_button = get_buttonpress() - 1;
4570 mwindow->session->drag_position = position;
4571 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4572 mwindow->session->drag_origin_x = get_cursor_x();
4573 mwindow->session->drag_origin_y = get_cursor_y();
4574 mwindow->session->drag_start = position;
4576 rerender = start_selection(position);
4580 else if( result < 0 ) {
4581 mwindow->undo->update_undo_before();
4582 if( !shift_down() ) {
4583 if( handle_result == 0 )
4584 edit_result->hard_left = !edit_result->hard_left;
4585 else if( handle_result == 1 )
4586 edit_result->hard_right = !edit_result->hard_right;
4589 int status = handle_result == 0 ? edit_result->hard_left :
4590 handle_result == 1 ? edit_result->hard_right : 0;
4591 int new_status = !status;
4592 int64_t edit_edge = edit_result->startproject;
4593 if( handle_result == 1 ) edit_edge += edit_result->length;
4594 double edge_position = edit_result->track->from_units(edit_edge);
4595 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4596 int64_t track_position = track->to_units(edge_position, 1);
4597 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4599 int64_t left_edge = left_edit->startproject;
4600 double left_position = track->from_units(left_edge);
4601 if( EQUIV(edge_position, left_position) ) {
4602 left_edit->hard_left = new_status;
4603 if( left_edit->previous )
4604 left_edit->previous->hard_right = new_status;
4607 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4609 int64_t right_edge = right_edit->startproject + right_edit->length;
4610 double right_position = track->from_units(right_edge);
4611 if( EQUIV(edge_position, right_position) ) {
4612 right_edit->hard_right = new_status;
4613 if( right_edit->next )
4614 right_edit->next->hard_left = new_status;
4619 rerender = update_overlay = 1;
4620 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4627 int TrackCanvas::do_plugin_handles(int cursor_x,
4631 int &update_overlay,
4635 Plugin *plugin_result = 0;
4636 int handle_result = 0;
4639 for(Track *track = mwindow->edl->tracks->first;
4641 track = track->next) {
4642 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4643 PluginSet *plugin_set = track->plugin_set.values[i];
4644 for(Plugin *plugin = (Plugin*)plugin_set->first;
4646 plugin = (Plugin*)plugin->next) {
4647 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4648 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4650 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4651 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4652 if(cursor_x < plugin_x + HANDLE_W) {
4653 plugin_result = plugin;
4657 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4658 plugin_result = plugin;
4665 if(result && shift_down())
4666 mwindow->session->trim_edits = plugin_set;
4672 double position = 0;
4673 if(handle_result == 0) {
4674 position = plugin_result->track->from_units(plugin_result->startproject);
4675 new_cursor = LEFT_CURSOR;
4677 else if(handle_result == 1) {
4678 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4679 new_cursor = RIGHT_CURSOR;
4683 mwindow->session->drag_plugin = plugin_result;
4684 mwindow->session->drag_handle = handle_result;
4685 mwindow->session->drag_button = get_buttonpress() - 1;
4686 mwindow->session->drag_position = position;
4687 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4688 mwindow->session->drag_origin_x = get_cursor_x();
4689 mwindow->session->drag_origin_y = get_cursor_y();
4690 mwindow->session->drag_start = position;
4692 rerender = start_selection(position);
4701 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4705 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4706 drag_cursor_motion(cursor_x, cursor_y,
4707 &track, &edit, &pluginset, &plugin);
4709 if( button_press && track ) {
4710 switch( get_buttonpress() ) {
4711 case RIGHT_BUTTON: {
4713 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4714 gui->track_menu->activate_menu(track, edit, pluginset, plugin, position);
4715 mwindow->session->current_operation = NO_OPERATION;
4719 set_cursor(GRABBED_CURSOR, 0, 1);
4720 mwindow->session->current_operation = DROP_TARGETING;
4729 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4730 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4734 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4735 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4736 int64_t edit_x, edit_y, edit_w, edit_h;
4737 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4739 // Cursor inside a track
4740 // Cursor inside an edit
4741 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4742 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4743 // Select duration of edit
4745 if( !drag_start && get_double_click() ) {
4746 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4747 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4748 edit->track->from_units(edit->length));
4749 if(mwindow->edl->session->cursor_on_frames)
4751 mwindow->edl->local_session->set_selectionstart(
4752 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4753 mwindow->edl->local_session->set_selectionend(
4754 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4758 if( ctrl_down() && get_buttonpress() == 1 &&
4759 mwindow->edl->session->editing_mode == EDITING_ARROW ) {
4760 edit->is_selected = !edit->is_selected ? 1 : 0;
4769 else if( drag_start && track->record ) {
4770 if( mwindow->edl->session->editing_mode == EDITING_ARROW ) {
4771 // Need to create drag window
4772 mwindow->session->current_operation = DRAG_EDIT;
4773 mwindow->session->drag_edit = edit;
4774 // Construct list of all affected edits
4775 mwindow->edl->tracks->clear_selected_edits();
4777 edit->is_selected = 1;
4779 mwindow->edl->tracks->select_affected_edits(
4780 edit->track->from_units(edit->startproject),
4782 mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits);
4783 mwindow->session->drag_origin_x = cursor_x;
4784 mwindow->session->drag_origin_y = cursor_y;
4785 // Where the drag started, so we know relative position inside the edit later
4786 mwindow->session->drag_position = (double)cursor_x *
4787 mwindow->edl->local_session->zoom_sample /
4788 mwindow->edl->session->sample_rate +
4789 (double)mwindow->edl->local_session->view_start[pane->number] *
4790 mwindow->edl->local_session->zoom_sample /
4791 mwindow->edl->session->sample_rate;
4794 get_abs_cursor(cx, cy);
4795 gui->drag_popup = new BC_DragWindow(gui,
4796 mwindow->theme->get_image("clip_icon"), cx, cy);
4808 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4813 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4814 int button_press, int &redraw, int &rerender)
4822 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4823 if(!track->expand_view) continue;
4825 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4826 // first check if plugins are visible at all
4827 if (!track->expand_view)
4829 PluginSet *plugin_set = track->plugin_set.values[i];
4830 for(plugin = (Plugin*)plugin_set->first;
4832 plugin = (Plugin*)plugin->next) {
4833 plugin_dimensions(plugin, x, y, w, h);
4834 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4835 MWindowGUI::visible(y, y + h, 0, get_h())) {
4836 if(cursor_x >= x && cursor_x < x + w &&
4837 cursor_y >= y && cursor_y < y + h) {
4847 // Start plugin popup
4849 if(get_buttonpress() == 3) {
4850 gui->plugin_menu->update(plugin);
4851 gui->plugin_menu->activate_menu();
4854 else if (get_double_click() && !drag_start) {
4855 // Select range of plugin on doubleclick over plugin
4856 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4857 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4858 plugin->track->from_units(plugin->length));
4859 if(mwindow->edl->session->cursor_on_frames) {
4860 mwindow->edl->local_session->set_selectionstart(
4861 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4862 mwindow->edl->local_session->set_selectionend(
4863 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4872 if(drag_start && plugin->track->record) {
4873 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4874 if(plugin->track->data_type == TRACK_AUDIO)
4875 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4876 else if(plugin->track->data_type == TRACK_VIDEO)
4877 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4879 mwindow->session->drag_plugin = plugin;
4880 mwindow->session->drag_origin_x = cursor_x;
4881 mwindow->session->drag_origin_y = cursor_y;
4882 // Where the drag started, so we know relative position inside the edit later
4883 mwindow->session->drag_position =
4884 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4885 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4887 switch(plugin->plugin_type) {
4888 case PLUGIN_STANDALONE: {
4889 PluginServer *server =
4890 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4891 if( !server ) break;
4892 VFrame *frame = server->picon;
4894 if(plugin->track->data_type == TRACK_AUDIO) {
4895 frame = mwindow->theme->get_image("aeffect_icon");
4898 frame = mwindow->theme->get_image("veffect_icon");
4902 get_abs_cursor(cx, cy);
4903 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4906 case PLUGIN_SHAREDPLUGIN:
4907 case PLUGIN_SHAREDMODULE: {
4908 VFrame *frame = mwindow->theme->get_image("clip_icon");
4910 get_abs_cursor(cx, cy);
4911 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4923 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4924 int button_press, int &new_cursor, int &update_cursor)
4926 Transition *transition = 0;
4931 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4932 if( !track->show_transitions() ) continue;
4934 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4935 if( edit->transition ) {
4936 edit_dimensions(edit, x, y, w, h);
4937 get_transition_coords(edit, x, y, w, h);
4939 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4940 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4941 if( cursor_x >= x && cursor_x < x + w &&
4942 cursor_y >= y && cursor_y < y + h ) {
4943 transition = edit->transition;
4955 new_cursor = UPRIGHT_ARROW_CURSOR;
4957 else if(get_buttonpress() == 3) {
4958 gui->transition_menu->update(transition);
4959 gui->transition_menu->activate_menu();
4966 int TrackCanvas::button_press_event()
4969 int cursor_x, cursor_y;
4972 cursor_x = get_cursor_x();
4973 cursor_y = get_cursor_y();
4974 mwindow->session->trim_edits = 0;
4976 if(is_event_win() && cursor_inside()) {
4977 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4984 if( get_buttonpress() == LEFT_BUTTON ) {
4985 gui->stop_transport("TrackCanvas::button_press_event");
4988 int update_overlay = 0, update_cursor = 0, rerender = 0;
4990 if(get_buttonpress() == WHEEL_UP) {
4992 mwindow->expand_sample();
4993 else if(ctrl_down())
4994 mwindow->move_left(get_w()/ 10);
4996 mwindow->move_up(get_h() / 10);
4998 else if(get_buttonpress() == WHEEL_DOWN) {
5000 mwindow->zoom_in_sample();
5001 else if(ctrl_down())
5002 mwindow->move_right(get_w() / 10);
5004 mwindow->move_down(get_h() / 10);
5006 else if(get_buttonpress() == 6) {
5008 mwindow->move_left(get_w());
5010 mwindow->move_left(get_w() / 20);
5012 mwindow->move_left(get_w() / 5);
5014 else if(get_buttonpress() == 7) {
5016 mwindow->move_right(get_w());
5018 mwindow->move_right(get_w() / 20);
5020 mwindow->move_right(get_w() / 5);
5023 switch(mwindow->edl->session->editing_mode) {
5024 // Test handles and resource boundaries and highlight a track
5025 case EDITING_ARROW: {
5026 if( do_transitions(cursor_x, cursor_y,
5027 1, new_cursor, update_cursor) ) break;
5029 if( do_keyframes(cursor_x, cursor_y,
5030 0, get_buttonpress(), new_cursor,
5031 update_cursor, rerender) ) break;
5032 // Test edit boundaries
5033 if( do_edit_handles(cursor_x, cursor_y,
5034 1, rerender, update_overlay, new_cursor,
5035 update_cursor) ) break;
5036 // Test plugin boundaries
5037 if( do_plugin_handles(cursor_x, cursor_y,
5038 1, rerender, update_overlay, new_cursor,
5039 update_cursor) ) break;
5041 if( do_edits(cursor_x, cursor_y, 1, 0,
5042 update_overlay, rerender, new_cursor,
5043 update_cursor) ) break;
5045 if( do_plugins(cursor_x, cursor_y, 0, 1,
5046 update_cursor, rerender) ) break;
5048 if( test_resources(cursor_x, cursor_y) ) break;
5050 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5055 // Test handles only and select a region
5056 case EDITING_IBEAM: {
5057 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5058 //printf("TrackCanvas::button_press_event %d\n", position);
5060 if( do_transitions(cursor_x, cursor_y,
5061 1, new_cursor, update_cursor)) break;
5062 if(do_keyframes(cursor_x, cursor_y,
5063 0, get_buttonpress(), new_cursor,
5064 update_cursor, rerender)) {
5068 // Test edit boundaries
5069 if( do_edit_handles(cursor_x, cursor_y,
5070 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5071 // Test plugin boundaries
5072 if( do_plugin_handles(cursor_x, cursor_y,
5073 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5075 if( do_edits(cursor_x, cursor_y,
5076 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
5078 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
5080 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5081 // Highlight selection
5082 if( get_buttonpress() != LEFT_BUTTON ) break;
5083 rerender = start_selection(position);
5084 mwindow->session->current_operation = SELECT_REGION;
5091 gui->unlock_window();
5092 mwindow->cwindow->update(1, 0, 0, 0, 1);
5093 gui->lock_window("TrackCanvas::button_press_event 2");
5095 mwindow->update_plugin_guis();
5096 gui->update_patchbay();
5099 if( update_overlay ) {
5100 gui->draw_overlays(1);
5102 if( update_cursor < 0 ) {
5103 // double_click edit
5104 gui->swindow->update_selection();
5106 if( update_cursor ) {
5107 gui->update_timebar(0);
5108 gui->hide_cursor(0);
5109 gui->show_cursor(1);
5110 gui->zoombar->update();
5111 gui->flash_canvas(1);
5118 int TrackCanvas::start_selection(double position)
5121 position = mwindow->edl->align_to_frame(position, 1);
5127 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
5128 mwindow->edl->local_session->get_selectionend(1)) / 2;
5130 if(position < midpoint)
5132 mwindow->edl->local_session->set_selectionstart(position);
5133 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
5139 mwindow->edl->local_session->set_selectionend(position);
5140 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
5141 // Don't que the CWindow for the end
5145 // Start a new selection
5147 //printf("TrackCanvas::start_selection %f\n", position);
5148 mwindow->edl->local_session->set_selectionstart(position);
5149 mwindow->edl->local_session->set_selectionend(position);
5150 selection_midpoint = position;
5158 void TrackCanvas::end_edithandle_selection()
5160 mwindow->modify_edithandles();
5163 void TrackCanvas::end_pluginhandle_selection()
5165 mwindow->modify_pluginhandles();
5169 double TrackCanvas::time_visible()
5171 return (double)get_w() *
5172 mwindow->edl->local_session->zoom_sample /
5173 mwindow->edl->session->sample_rate;
5177 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
5179 char string[BCTEXTLEN];
5180 char *cp = string, *ep = cp + sizeof(string)-1;
5181 if( show_curve_type ) {
5182 cp += snprintf(string, ep-cp, "%-8s ",
5183 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5185 char string2[BCTEXTLEN];
5186 Units::totext(string2,
5187 current->autos->track->from_units(current->position),
5188 mwindow->edl->session->time_format,
5189 mwindow->edl->session->sample_rate,
5190 mwindow->edl->session->frame_rate,
5191 mwindow->edl->session->frames_per_foot);
5192 cp += snprintf(cp, ep-cp, "%s", string2);
5195 vsnprintf(cp, ep-cp, fmt, ap);
5197 gui->show_message(string);
5200 // Patchbay* TrackCanvas::get_patchbay()
5202 // if(pane->patchbay) return pane->patchbay;
5203 // if(gui->total_panes() == 2 &&
5204 // gui->pane[TOP_LEFT_PANE] &&
5205 // gui->pane[TOP_RIGHT_PANE])
5206 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5207 // if(gui->total_panes() == 4)
5209 // if(pane->number == TOP_RIGHT_PANE)
5210 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5212 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;