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 if( track->is_hidden() ) continue;
214 int64_t track_x, track_y, track_w, track_h;
215 track_dimensions(track, track_x, track_y, track_w, track_h);
217 if(cursor_y >= track_y &&
218 cursor_y < track_y + track_h)
221 for(Edit *edit = track->edits->first; edit; edit = edit->next)
223 int64_t edit_x, edit_y, edit_w, edit_h;
224 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
225 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
226 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
230 if( edit != track->edits->last ) continue;
231 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
232 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
233 if( !edit->silence() ) {
234 // add silence to allow drag transition past last edit
235 // will be deleted by Edits::optimize if not used
236 double length = mwindow->edl->session->default_transition_length;
237 int64_t start = edit->startproject+edit->length;
238 int64_t units = track->to_units(length, 1);
239 track->edits->create_silence(start, start+units);
242 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
245 for(int i = 0; i < track->plugin_set.total; i++)
247 PluginSet *pluginset = track->plugin_set.values[i];
248 for(Plugin *plugin = (Plugin*)pluginset->first;
250 plugin = (Plugin*)plugin->next)
252 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
253 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
255 if(cursor_y >= plugin_y &&
256 cursor_y < plugin_y + plugin_h)
258 *over_pluginset = plugin->plugin_set;
260 if(cursor_x >= plugin_x &&
261 cursor_x < plugin_x + plugin_w)
263 *over_plugin = plugin;
278 int TrackCanvas::drag_stop_event()
280 int result = gui->drag_stop();
281 if( !result && mwindow->session->current_operation ) {
282 mwindow->session->current_operation = NO_OPERATION;
288 int TrackCanvas::drag_stop(int *redraw)
293 int cursor_x = -1, cursor_y = -1;
295 if( get_cursor_over_window() ) {
296 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
297 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
300 Track *track = pane->over_patchbay();
301 if( track && mwindow->session->track_highlighted == track )
307 switch(mwindow->session->current_operation) {
308 case DRAG_VTRANSITION:
309 case DRAG_ATRANSITION:
310 if(mwindow->session->edit_highlighted) {
311 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
312 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
313 (mwindow->session->current_operation == DRAG_VTRANSITION &&
314 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
315 mwindow->session->current_operation = NO_OPERATION;
316 mwindow->paste_transition();
323 // Behavior for dragged plugins is limited by the fact that a shared plugin
324 // can only refer to a standalone plugin that exists in the same position in
325 // time. Dragging a plugin from one point in time to another can't produce
326 // a shared plugin to the original plugin. In this case we relocate the
327 // plugin instead of sharing it.
328 case DRAG_AEFFECT_COPY:
329 case DRAG_VEFFECT_COPY:
330 if( mwindow->session->track_highlighted &&
331 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
332 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
333 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
334 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
335 mwindow->session->current_operation = NO_OPERATION;
337 int64_t drop_position = -1;
338 Plugin *drag_plugin = mwindow->session->drag_plugin;
339 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
340 Track *hi_track = mwindow->session->track_highlighted;
342 // Insert shared plugin in source
343 // Move source to different location
344 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
345 //printf("TrackCanvas::drag_stop 6\n");
346 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
347 if( drop_position < 0 ) {
349 break; // Do not do anything
352 Track *track = mwindow->session->track_highlighted;
353 drop_position = track->frame_align(drop_position, 0);
354 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
357 else if( hi_track ) {
358 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
359 Edit *hi_edit = mwindow->session->edit_highlighted;
360 drop_position = hi_edit ? hi_edit->startproject : 0;
361 if( drop_position < 0 ) {
363 break; // Do not do anything
366 Track *track = mwindow->session->track_highlighted;
367 drop_position = track->frame_align(drop_position, 0);
368 mwindow->move_effect(drag_plugin, hi_track, drop_position);
376 if( mwindow->session->track_highlighted &&
377 ((mwindow->session->current_operation == DRAG_AEFFECT &&
378 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
379 (mwindow->session->current_operation == DRAG_VEFFECT &&
380 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
381 // Drop all the effects
382 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
383 Track *track = mwindow->session->track_highlighted;
385 double length = track->get_length();
387 if(mwindow->session->plugin_highlighted) {
388 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
389 length = track->from_units(mwindow->session->plugin_highlighted->length);
390 if(length <= 0) length = track->get_length();
392 else if(mwindow->session->pluginset_highlighted) {
393 start = track->from_units(plugin_set->length());
394 length = track->get_length() - start;
395 if(length <= 0) length = track->get_length();
397 else if(mwindow->edl->local_session->get_selectionend() >
398 mwindow->edl->local_session->get_selectionstart()) {
399 start = mwindow->edl->local_session->get_selectionstart();
400 length = mwindow->edl->local_session->get_selectionend() -
401 mwindow->edl->local_session->get_selectionstart();
403 // Move to a point between two edits
404 else if(mwindow->session->edit_highlighted) {
405 start = mwindow->session->track_highlighted->from_units(
406 mwindow->session->edit_highlighted->startproject);
407 length = mwindow->session->track_highlighted->from_units(
408 mwindow->session->edit_highlighted->length);
410 start = mwindow->edl->align_to_frame(start, 0);
411 mwindow->insert_effects_canvas(track, start, length);
414 if( mwindow->session->track_highlighted )
415 result = 1; // we have to cleanup
419 if(mwindow->session->track_highlighted) {
420 double asset_duration = 0;
421 int64_t asset_length_units = 0;
423 if(mwindow->session->current_operation == DRAG_ASSET &&
424 mwindow->session->drag_assets->total) {
425 Indexable *indexable = mwindow->session->drag_assets->values[0];
426 // we use video if we are over video and audio if we are over audio
427 if( indexable->have_video() &&
428 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
429 // Images have length -1
430 int64_t video_length = indexable->get_video_frames();
431 if (video_length < 0) {
432 if(mwindow->edl->session->si_useduration)
433 video_length = mwindow->edl->session->si_duration;
435 video_length = 1.0 / mwindow->edl->session->frame_rate ;
437 asset_duration = video_length / indexable->get_frame_rate();
439 else if( indexable->have_audio() &&
440 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
441 int64_t audio_length = indexable->get_audio_samples();
442 asset_duration = (double)audio_length / indexable->get_sample_rate();
446 break; // Do not do anything
449 else if( mwindow->session->current_operation == DRAG_ASSET &&
450 mwindow->session->drag_clips->total ) {
451 EDL *clip = mwindow->session->drag_clips->values[0];
452 asset_duration = clip->tracks->total_length();
455 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
458 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
459 int64_t drop_position = drop_edit_position (&insertion, NULL, asset_length_units);
460 if( drop_position < 0 ) {
462 break; // Do not do anything
465 Track *track = mwindow->session->track_highlighted;
466 double track_position = track->from_units(drop_position);
467 track_position = mwindow->edl->align_to_frame(track_position, 0);
470 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
471 // // Unfortunately, this is _a lot_ of work to do right
472 // printf("Problematic insertion\n");
473 // mwindow->edl->tracks->clear(track_position,
474 // track_position + asset_duration, 0);
476 mwindow->paste_assets(track_position, track, !insertion);
477 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
482 mwindow->session->current_operation = NO_OPERATION;
483 if(mwindow->session->track_highlighted) {
484 if( mwindow->session->track_highlighted->data_type ==
485 mwindow->session->drag_edit->track->data_type) {
486 int64_t drop_position = drop_edit_position(&insertion,
487 mwindow->session->drag_edit,
488 mwindow->session->drag_edit->length);
489 if( drop_position < 0 ) {
491 break; // Do not do anything
493 Track *track = mwindow->session->track_highlighted;
494 double track_position = track->from_units(drop_position);
495 track_position = mwindow->edl->align_to_frame(track_position, 0);
496 mwindow->move_edits(mwindow->session->drag_edits,
497 track, track_position, insertion);
504 mwindow->session->current_operation = NO_OPERATION;
505 EDL *drag_group = mwindow->session->drag_group;
507 Track *drop_track = mwindow->session->track_highlighted;
508 Track *drag_track = mwindow->session->drag_group_first_track;
509 Edit *drag_edit = mwindow->session->drag_group_edit;
510 Track *edit_track = drag_edit ? drag_edit->track : 0;
511 while( drop_track && edit_track ) {
512 if( edit_track == drag_track ) break;
513 edit_track = edit_track->previous;
514 drop_track = drop_track->previous;
517 double cur_pos = mwindow->session->drag_group_position;
518 double new_pos = mwindow->edl->get_cursor_position(cursor_x, pane->number);
519 new_pos -= mwindow->session->drag_position - cur_pos;
520 new_pos = mwindow->edl->align_to_frame(new_pos, 0);
521 double drop_position = new_pos;
522 int ret = test_track_group(drag_group, drop_track, new_pos);
523 if( !ret && new_pos != drop_position ) {
524 drop_position = new_pos;
525 ret = test_track_group(drag_group, drop_track, new_pos);
528 mwindow->move_group(drag_group, drop_track, drop_position,
529 ret > 0 ? !shift_down() : shift_down());
530 drag_group->remove_user();
531 mwindow->session->drag_group = 0;
542 int TrackCanvas::drag_start_event()
547 int new_cursor, update_cursor;
549 if( mwindow->session->current_operation == GROUP_TOGGLE )
550 mwindow->session->current_operation = NO_OPERATION;
551 else if( mwindow->session->current_operation != NO_OPERATION )
555 if(do_plugins(get_drag_x(), get_drag_y(),
556 1, 0, redraw, rerender)) {
559 else if(do_edits(get_drag_x(), get_drag_y(),
560 0, 1, redraw, rerender, new_cursor, update_cursor)) {
568 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
570 // get the canvas/track position
571 Track *track = mwindow->session->track_highlighted;
572 int cursor_x = get_relative_cursor_x();
573 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
574 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
575 double position = mwindow->edl->align_to_frame(cur_pos, 1);
576 if( position <= 0 ) {
580 double cursor_position = position;
581 int64_t drop_position = track->to_units(cursor_position, 1);
582 if( moved_edit ) { // relative cursor position depends upon drop point
583 double moved_edit_start = moved_edit->track->from_units(moved_edit->startproject);
584 position -= mwindow->session->drag_position - moved_edit_start;
586 int64_t edit_position = track->to_units(position, 1);
587 int64_t grab_position = edit_position;
588 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
589 grab_position -= moved_edit_length / 2;
590 Edit *last_edit = track->edits->last;
591 if( !last_edit || edit_position >= (last_edit->startproject+last_edit->length) ) {
593 return edit_position;
596 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
597 Edit *next_edit = track->edits->first;
599 Edit *edit = next_edit; next_edit = (Edit *)edit->next;
600 int64_t edit_start = edit->startproject;
601 int64_t edit_end = edit_start + edit->length;
602 double edit_start_pos = edit->track->from_units(edit_start);
603 if( (fabs(edit_start_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
604 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
607 double edit_end_pos = edit->track->from_units(edit_end);
608 if( (fabs(edit_end_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
609 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
612 if( edit != moved_edit && !edit->silence() )
613 drop_start = edit_end; // reset drop zone
615 if( next_edit == moved_edit || next_edit->silence() ) continue;
619 drop_end = INT64_MAX;
620 if( edit_position >= drop_start &&
621 edit_position+moved_edit_length < drop_end ) {
622 *is_insertion = 0; // fits in the zone
623 return edit_position;
625 if( drop_position < drop_end ) { // drop in the zone
626 if( (drop_end - drop_start) >= moved_edit_length ) {
627 *is_insertion = 0; // fits in the zone, but over the edge
628 int64_t dx0 = llabs(drop_position - drop_start);
629 int64_t dx1 = llabs(drop_position - drop_end);
630 return dx0 < dx1 ? drop_start : drop_end - moved_edit_length;
633 int64_t edit_center = (edit_start + edit_end) / 2;
634 return position < edit_center ? drop_start : drop_end;
642 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
644 // get the canvas/track position
645 Track *track = plugin_set->track;
646 double moved_plugin_length = moved_plugin->track->from_units(moved_plugin->length);
647 int64_t track_plugin_length = track->to_units(moved_plugin_length, 0);
648 int cursor_x = get_relative_cursor_x();
649 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
650 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
651 double position = mwindow->edl->align_to_frame(cur_pos, 1);
652 if( position <= 0 ) return 0;
653 int64_t drop_position = track->to_units(position, 1);
654 Plugin *last_plugin = (Plugin *)plugin_set->last;
655 if( !last_plugin ) return drop_position;
656 double plugin_set_end = last_plugin->track->from_units(last_plugin->startproject+last_plugin->length);
657 if( position >= plugin_set_end ) return drop_position;
658 double moved_plugin_start = moved_plugin->track->from_units(moved_plugin->startproject);
659 position -= mwindow->session->drag_position - moved_plugin_start;
660 int64_t plugin_position = track->to_units(position, 1);
662 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
663 Plugin *next_plugin = (Plugin *)plugin_set->first;
664 while( next_plugin ) {
665 Plugin *plugin = next_plugin; next_plugin = (Plugin *)plugin->next;
666 int64_t plugin_start = plugin->startproject;
667 int64_t plugin_end = plugin_start + plugin->length;
668 double plugin_end_pos = plugin->track->from_units(plugin_end);
669 int64_t track_plugin_end = track->to_units(plugin_end_pos, 0);
670 if( plugin != moved_plugin && !plugin->silence() )
671 drop_start = track_plugin_end;
673 if( next_plugin == moved_plugin || next_plugin->silence() ) continue;
674 drop_end = track_plugin_end;
677 drop_end = INT64_MAX;
678 if( plugin_position >= drop_start && // fits in the zone
679 plugin_position+track_plugin_length < drop_end ) {
680 return plugin_position;
682 if( drop_position < drop_end ) { // drop in the zone
683 if( (drop_end - drop_start) >= track_plugin_length ) {
684 int64_t dx0 = llabs(drop_position - drop_start);
685 int64_t dx1 = llabs(drop_position - drop_end);
686 return dx0 < dx1 ? drop_start : drop_end - track_plugin_length;
694 void TrackCanvas::draw(int mode, int hide_cursor)
698 // Swap pixmap layers
699 if(get_w() != background_pixmap->get_w() ||
700 get_h() != background_pixmap->get_h())
702 delete background_pixmap;
703 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
706 // Cursor disappears after resize when this is called.
707 // Cursor doesn't redraw after editing when this isn't called.
708 if(pane->cursor && hide_cursor) pane->cursor->hide();
709 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
711 if(debug) PRINT_TRACE
712 draw_resources(mode);
714 if(debug) PRINT_TRACE
716 if(debug) PRINT_TRACE
719 void TrackCanvas::update_cursor(int flush)
722 set_cursor(ARROW_CURSOR, 0, flush);
723 else if( ibeam_mode() )
724 set_cursor(IBEAM_CURSOR, 0, flush);
728 void TrackCanvas::test_timer()
730 if( resource_timer->get_difference() > 1000 && !hourglass_enabled ) {
732 hourglass_enabled = 1;
737 void TrackCanvas::draw_indexes(Indexable *indexable)
739 IndexState *index_state = indexable->index_state;
740 // Don't redraw raw samples
741 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
743 draw_resources(NORMAL_DRAW, 1, indexable);
748 void TrackCanvas::draw_resources(int mode,
750 Indexable *indexable)
754 if(debug) PRINT_TRACE
756 // can't stop thread here, because this is called for every pane
757 // if(mode != IGNORE_THREAD && !indexes_only)
758 // gui->resource_thread->stop_draw(!indexes_only);
760 if(mode != IGNORE_THREAD &&
762 !gui->resource_thread->interrupted)
764 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
767 BC_Signals::dump_stack();
770 if(debug) PRINT_TRACE
772 resource_timer->update();
774 // Age resource pixmaps for deletion
776 for(int i = 0; i < gui->resource_pixmaps.total; i++)
777 gui->resource_pixmaps.values[i]->visible--;
779 if(mode == FORCE_REDRAW)
780 gui->resource_pixmaps.remove_all_objects();
782 if(debug) PRINT_TRACE
783 if(mode != IGNORE_THREAD)
784 gui->resource_thread->reset(pane->number);
787 for(Track *current = mwindow->edl->tracks->first;
791 if( current->is_hidden() ) continue;
792 if(debug) PRINT_TRACE
793 for(Edit *edit = current->edits->first; edit; edit = edit->next)
795 if(debug) PRINT_TRACE
796 if( current->data_type != TRACK_SUBTITLE )
797 if(!edit->asset && !edit->nested_edl) continue;
800 if(edit->track->data_type != TRACK_AUDIO) continue;
802 if(edit->nested_edl &&
803 strcmp(indexable->path, edit->nested_edl->path)) continue;
806 strcmp(indexable->path, edit->asset->path)) continue;
809 if(debug) PRINT_TRACE
811 int64_t edit_x, edit_y, edit_w, edit_h;
812 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
815 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
816 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
818 int64_t pixmap_x, pixmap_w, pixmap_h;
819 if(debug) PRINT_TRACE
821 // Search for existing pixmap containing edit
822 for(int i = 0; i < gui->resource_pixmaps.total; i++)
824 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
825 // Same pointer can be different edit if editing took place
826 if(pixmap->edit_id == edit->id &&
827 pixmap->pane_number == pane->number)
833 if(debug) PRINT_TRACE
835 // Get new size, offset of pixmap needed
836 get_pixmap_size(edit,
842 if(debug) PRINT_TRACE
845 if(pixmap_w && pixmap_h)
847 // Create pixmap if it doesn't exist
848 ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
849 pixmap_x, pixmap_w, pixmap_h);
850 // Resize it if it's bigger
851 if( pixmap_w > pixmap->pixmap_w ||
852 pixmap_h > pixmap->pixmap_h)
853 pixmap->resize(pixmap_w, pixmap_h);
854 pixmap->update_settings(edit, edit_x, edit_w,
855 pixmap_x, pixmap_w, pixmap_h);
857 if( current->show_assets() )
858 pixmap->draw_data(this,
859 edit, edit_x, edit_w,
860 pixmap_x, pixmap_w, pixmap_h,
864 clear_box(0,0, pixmap_w,pixmap_h, pixmap);
867 if( current->show_titles() )
868 pixmap->draw_title(this,
869 edit, edit_x, edit_w,
871 // Resize it if it's smaller
872 if(pixmap_w < pixmap->pixmap_w ||
873 pixmap_h < pixmap->pixmap_h)
874 pixmap->resize(pixmap_w, pixmap_h);
876 // Copy pixmap to background canvas
877 background_pixmap->draw_pixmap(pixmap,
879 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
883 if(debug) PRINT_TRACE
887 int64_t track_x, track_y, track_w, track_h;
888 track_dimensions(current,
889 track_x, track_y, track_w, track_h);
890 set_color((~get_resources()->get_bg_color()) & 0xffffff);
892 int x1 = track_x, x2 = x1+track_w;
893 int y1 = track_y+track_h-1;
894 draw_line(x1,y1, x2,y1, background_pixmap);
898 // Delete unused pixmaps
899 if(debug) PRINT_TRACE
901 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
902 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
904 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
905 delete gui->resource_pixmaps.values[i];
906 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
908 if(debug) PRINT_TRACE
910 if(hourglass_enabled)
913 hourglass_enabled = 0;
915 if(debug) PRINT_TRACE
917 // can't stop thread here, because this is called for every pane
918 // if(mode != IGNORE_THREAD && !indexes_only)
919 // gui->resource_thread->start_draw();
920 if(debug) PRINT_TRACE
925 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
931 ResourcePixmap *result = 0;
933 for(int i = 0; i < gui->resource_pixmaps.total; i++)
935 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
936 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
937 gui->resource_pixmaps.values[i]->pane_number == pane->number)
939 result = gui->resource_pixmaps.values[i];
947 result = new ResourcePixmap(mwindow,
954 gui->resource_pixmaps.append(result);
957 // result->resize(pixmap_w, pixmap_h);
961 void TrackCanvas::get_pixmap_size(Edit *edit,
969 // Align x on frame boundaries
972 // switch(edit->edits->track->data_type)
984 if(pixmap_x + pixmap_w > get_w())
986 pixmap_w = get_w() - pixmap_x;
993 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
994 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
995 // int64_t pixel_increment = MAX(picon_w, frame_w);
996 // int64_t pixmap_x1 = edit_x;
997 // int64_t pixmap_x2 = edit_x + edit_w;
1001 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
1002 // pixel_increment +
1006 // if(pixmap_x2 > get_w())
1008 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
1009 // pixel_increment +
1012 // pixmap_x = pixmap_x1;
1013 // pixmap_w = pixmap_x2 - pixmap_x1;
1018 Track *track = edit->edits->track;
1019 pixmap_h = track->data_h;
1020 if( track->show_titles() )
1021 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
1022 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
1025 void TrackCanvas::edit_dimensions(Edit *edit,
1026 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1028 x = Units::round(edit->track->from_units(edit->startproject) *
1029 mwindow->edl->session->sample_rate /
1030 mwindow->edl->local_session->zoom_sample -
1031 mwindow->edl->local_session->view_start[pane->number]);
1033 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1035 // Method for calculating w so when edits are together we never get off by one error due to rounding
1036 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
1037 mwindow->edl->session->sample_rate /
1038 mwindow->edl->local_session->zoom_sample -
1039 mwindow->edl->local_session->view_start[pane->number]);
1043 if( edit->track->show_titles() )
1044 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
1045 if( edit->track->show_assets() )
1046 edit_h += edit->track->data_h;
1050 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1054 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1055 h = track->vertical_span(mwindow->theme);
1059 void TrackCanvas::draw_paste_destination()
1061 //int cursor_x = get_relative_cursor_x();
1062 //int cursor_y = get_relative_cursor_y();
1063 int current_atrack = 0;
1064 int current_vtrack = 0;
1065 int current_aedit = 0;
1066 int current_vedit = 0;
1072 //if(pane->number == BOTTOM_RIGHT_PANE)
1073 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1075 if((mwindow->session->current_operation == DRAG_ASSET &&
1076 (mwindow->session->drag_assets->total ||
1077 mwindow->session->drag_clips->total)) ||
1078 (mwindow->session->current_operation == DRAG_EDIT &&
1079 mwindow->session->drag_edits->total)) {
1080 Indexable *indexable = 0;
1084 if(mwindow->session->current_operation == DRAG_ASSET &&
1085 mwindow->session->drag_assets->size())
1086 indexable = mwindow->session->drag_assets->get(0);
1088 if(mwindow->session->current_operation == DRAG_ASSET &&
1089 mwindow->session->drag_clips->size())
1090 clip = mwindow->session->drag_clips->get(0);
1092 int has_audio = 0, has_video = 0;
1093 double paste_audio_length = 0, paste_video_length = 0;
1094 double paste_audio_position = -1, paste_video_position = -1;
1097 has_audio = indexable->have_audio();
1098 paste_audio_length = !has_audio ? 0 :
1099 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1100 has_video = indexable->have_video();
1101 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1102 // Images have length -1
1103 if( asset && asset->video_data && asset->video_length < 0 ) {
1104 paste_video_length = mwindow->edl->session->si_useduration ?
1105 mwindow->edl->session->si_duration / asset->frame_rate :
1106 1.0 / asset->frame_rate ; // 1 frame
1109 paste_video_length = !has_video ? 0 :
1110 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1114 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1115 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1116 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1117 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1120 // 'Align cursor on frame' lengths calculations
1121 if( mwindow->edl->session->cursor_on_frames ) {
1122 double fps = mwindow->edl->session->frame_rate;
1123 double aud = floor(paste_audio_length * fps) / fps;
1124 double vid = floor(paste_video_length * fps) / fps;
1125 double length = has_video && has_audio ?
1126 aud < vid ? aud : vid :
1128 has_audio ? aud : 0;
1129 paste_video_length = paste_audio_length = length;
1132 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1134 switch( mwindow->session->track_highlighted->data_type ) {
1135 case TRACK_VIDEO: length = paste_video_length; break;
1136 case TRACK_AUDIO: length = paste_audio_length; break;
1138 int64_t asset_length = mwindow->session->track_highlighted->
1139 to_units(length, 1);
1140 paste_audio_position = mwindow->session->track_highlighted->
1141 from_units(drop_edit_position(&insertion, NULL, asset_length));
1144 int64_t asset_length = mwindow->session->track_highlighted->
1145 to_units(paste_video_length, 1);
1146 paste_video_position = mwindow->session->track_highlighted->
1147 from_units(drop_edit_position(&insertion, NULL, asset_length));
1150 // Get destination track
1151 for(Track *dest = mwindow->session->track_highlighted;
1153 dest = dest->next) {
1154 if( dest->is_hidden() ) continue;
1155 if(dest->is_armed()) {
1156 // Get source width in pixels
1158 // Use start of highlighted edit
1159 if(mwindow->session->edit_highlighted) {
1160 position = mwindow->session->track_highlighted->from_units(
1161 mwindow->session->edit_highlighted->startproject);
1164 // Use end of highlighted track, disregarding effects
1165 position = mwindow->session->track_highlighted->from_units(
1166 mwindow->session->track_highlighted->edits->length());
1169 // Get the x coordinate
1170 x = Units::to_int64(position *
1171 mwindow->edl->session->sample_rate /
1172 mwindow->edl->local_session->zoom_sample) -
1173 mwindow->edl->local_session->view_start[pane->number];
1175 double paste_position = -1.;
1176 if(dest->data_type == TRACK_AUDIO) {
1177 if(indexable && current_atrack < indexable->get_audio_channels()) {
1178 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1179 w = Units::to_int64((double)indexable->get_audio_samples() /
1180 indexable->get_sample_rate() *
1181 mwindow->edl->session->sample_rate /
1182 mwindow->edl->local_session->zoom_sample);
1183 paste_position = paste_audio_position;
1185 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1186 w = Units::to_int64((double)clip->tracks->total_length() *
1187 mwindow->edl->session->sample_rate /
1188 mwindow->edl->local_session->zoom_sample);
1189 paste_position = paste_audio_position;
1190 //printf("draw_paste_destination %d\n", x);
1192 else if(mwindow->session->current_operation == DRAG_EDIT &&
1193 current_aedit < mwindow->session->drag_edits->total) {
1195 while(current_aedit < mwindow->session->drag_edits->total &&
1196 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1199 if(current_aedit < mwindow->session->drag_edits->total) {
1200 edit = mwindow->session->drag_edits->values[current_aedit];
1201 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1202 paste_position = mwindow->session->track_highlighted->
1203 from_units(drop_edit_position(&insertion,
1204 mwindow->session->drag_edit,
1205 mwindow->session->drag_edit->length));
1209 if( paste_position >= 0 ) {
1210 position = paste_position;
1217 else if(dest->data_type == TRACK_VIDEO) {
1218 //printf("draw_paste_destination 1\n");
1219 if(indexable && current_vtrack < indexable->get_video_layers())
1221 w = Units::to_int64((double)indexable->get_video_frames() /
1222 indexable->get_frame_rate() *
1223 mwindow->edl->session->sample_rate /
1224 mwindow->edl->local_session->zoom_sample);
1225 paste_position = paste_video_position;
1227 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1228 w = Units::to_int64(clip->tracks->total_length() *
1229 mwindow->edl->session->sample_rate /
1230 mwindow->edl->local_session->zoom_sample);
1231 paste_position = paste_video_position;
1233 else if(mwindow->session->current_operation == DRAG_EDIT &&
1234 current_vedit < mwindow->session->drag_edits->total) {
1236 while(current_vedit < mwindow->session->drag_edits->total &&
1237 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1240 if(current_vedit < mwindow->session->drag_edits->total) {
1241 edit = mwindow->session->drag_edits->values[current_vedit];
1242 w = Units::to_int64(edit->track->from_units(edit->length) *
1243 mwindow->edl->session->sample_rate /
1244 mwindow->edl->local_session->zoom_sample);
1245 paste_position = mwindow->session->track_highlighted->
1246 from_units(drop_edit_position(&insertion,
1247 mwindow->session->drag_edit,
1248 mwindow->session->drag_edit->length));
1252 if( paste_position >= 0 ) {
1253 position = paste_position;
1262 // Get the x coordinate
1263 x = Units::to_int64(position *
1264 mwindow->edl->session->sample_rate /
1265 mwindow->edl->local_session->zoom_sample) -
1266 mwindow->edl->local_session->view_start[pane->number];
1267 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1268 int h = dest->vertical_span(mwindow->theme);
1270 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1271 if(x < -BC_INFINITY) {
1272 w -= -BC_INFINITY - x;
1273 x += -BC_INFINITY - x;
1276 // if(pane->number == TOP_RIGHT_PANE)
1277 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1278 // __LINE__, x, y, w, h);
1280 draw_highlight_insertion(x, y, w, h);
1282 draw_highlight_rectangle(x, y, w, h);
1289 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1291 x = Units::round(plugin->track->from_units(plugin->startproject) *
1292 mwindow->edl->session->sample_rate /
1293 mwindow->edl->local_session->zoom_sample -
1294 mwindow->edl->local_session->view_start[pane->number]);
1295 w = Units::round(plugin->track->from_units(plugin->length) *
1296 mwindow->edl->session->sample_rate /
1297 mwindow->edl->local_session->zoom_sample);
1298 y = plugin->track->y_pixel
1299 - mwindow->edl->local_session->track_start[pane->number];
1300 if( plugin->track->show_titles() )
1301 y += mwindow->theme->get_image("title_bg_data")->get_h();
1302 if( plugin->track->show_assets() )
1303 y += plugin->track->data_h;
1304 y += plugin->plugin_set->get_number() *
1305 mwindow->theme->get_image("plugin_bg_data")->get_h();
1306 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1310 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1313 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1314 // just draw arrows, so user has indication that something is there
1315 // FIXME: get better colors
1319 draw_triangle_left(0, y + h /6,
1320 h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1325 draw_triangle_right(get_w() - h * 2/3, y + h /6,
1326 h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1330 // Fix bug in heroines & cvs version as of 22.8.2005:
1331 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1332 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1333 if(x < -10) { w += x - -10; x = -10; }
1334 if(y < -10) { h += y - -10; y = -10; }
1336 w = MIN(w, get_w() + 20);
1337 h = MIN(h, get_h() + 20);
1340 set_color(mwindow->preferences->highlight_inverse);
1342 //draw_rectangle(x, y, w, h);
1343 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1344 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1346 draw_rectangle(x, y, w, h);
1348 //if(pane->number == TOP_RIGHT_PANE)
1349 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1352 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1355 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1356 // just draw arrows, so user has indication that something is there
1357 // FIXME: get better colors
1366 /* these don't look so good
1368 draw_line(x, y, x, y+h);
1369 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1370 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1371 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1372 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1374 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1375 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1377 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1378 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1379 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1380 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1382 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1383 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1385 // draw the box centred around x
1387 // Fix bug in heroines & cvs version as of 22.8.2005:
1388 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1389 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1390 if(x < -10) { w += x - -10; x = -10; }
1391 if(y < -10) { h += y - -10; y = -10; }
1392 w = MIN(w, get_w() + 20);
1393 h = MIN(h, get_h() + 20);
1394 set_color(mwindow->preferences->highlight_inverse);
1396 draw_rectangle(x, y, w, h);
1397 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1399 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1402 void TrackCanvas::draw_playback_cursor()
1404 // Called before playback_cursor exists
1405 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1407 // mwindow->playback_cursor->visible = 0;
1408 // mwindow->playback_cursor->draw();
1412 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1414 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1415 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1417 edit_dimensions(edit, x, y, w, h);
1419 if( edit->track->show_titles() )
1420 y += mwindow->theme->get_image("title_bg_data")->get_h();
1422 if(side == EDIT_OUT)
1429 void TrackCanvas::get_transition_coords(Edit *edit,
1430 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1432 int transition_w = xS(30), transition_h = yS(30);
1433 int has_titles = edit->track->show_titles();
1434 int has_assets = edit->track->show_assets();
1435 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
1436 int data_h = edit->track->data_h;
1437 double ys = has_assets ? data_h : has_titles ? title_bg_h : 0;
1438 double dy = has_titles ?
1439 ( has_assets ? title_bg_h + data_h/2 : title_bg_h/2 ) :
1440 ( has_assets ? data_h/2 : 0) ;
1441 double title_h = mwindow->theme->title_h;
1442 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
1445 x -= transition_w / 2;
1446 y -= transition_h / 2;
1451 void TrackCanvas::draw_highlighting()
1456 switch(mwindow->session->current_operation)
1458 case DRAG_ATRANSITION:
1459 case DRAG_VTRANSITION:
1460 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1461 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1462 if(mwindow->session->edit_highlighted) {
1463 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1464 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1465 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1466 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1467 edit_dimensions(mwindow->session->edit_highlighted,
1469 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1470 MWindowGUI::visible(y, y + h, 0, get_h())) {
1472 get_transition_coords(mwindow->session->edit_highlighted,
1479 // Dragging a new effect from the Resource window
1482 if(mwindow->session->track_highlighted &&
1483 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1484 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1485 (mwindow->session->current_operation == DRAG_VEFFECT &&
1486 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1487 // Put it before another plugin
1488 if(mwindow->session->plugin_highlighted) {
1489 plugin_dimensions(mwindow->session->plugin_highlighted,
1491 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1493 // Put it after a plugin set
1494 else if( mwindow->session->pluginset_highlighted &&
1495 mwindow->session->pluginset_highlighted->last ) {
1496 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1498 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1499 int64_t track_x, track_y, track_w, track_h;
1500 track_dimensions(mwindow->session->track_highlighted,
1501 track_x, track_y, track_w, track_h);
1505 mwindow->session->track_highlighted->get_length() *
1506 mwindow->edl->session->sample_rate /
1507 mwindow->edl->local_session->zoom_sample -
1508 mwindow->edl->local_session->view_start[pane->number]) -
1510 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1511 if(w <= 0) w = track_w;
1514 track_dimensions(mwindow->session->track_highlighted,
1517 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1518 // Put it in a new plugin set determined by the selected range
1519 if(mwindow->edl->local_session->get_selectionend() >
1520 mwindow->edl->local_session->get_selectionstart()) {
1521 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1522 mwindow->edl->session->sample_rate /
1523 mwindow->edl->local_session->zoom_sample -
1524 mwindow->edl->local_session->view_start[pane->number]);
1525 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1526 mwindow->edl->local_session->get_selectionstart()) *
1527 mwindow->edl->session->sample_rate /
1528 mwindow->edl->local_session->zoom_sample);
1530 // Put it in a new plugin set determined by an edit boundary
1531 else if(mwindow->session->edit_highlighted) {
1532 int64_t temp_y, temp_h;
1533 edit_dimensions(mwindow->session->edit_highlighted,
1534 x, temp_y, w, temp_h);
1536 // Put it at the beginning of the track in a new plugin set
1539 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1540 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1541 //printf("TrackCanvas::draw_highlighting 1\n");
1548 if(mwindow->session->track_highlighted) {
1549 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1551 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1553 draw_paste_destination();
1559 if(mwindow->session->track_highlighted) {
1560 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1562 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1563 draw_paste_destination();
1568 if( mwindow->session->track_highlighted && mwindow->session->drag_group &&
1569 mwindow->session->drag_group_edit && mwindow->session->drag_group_first_track ) {
1570 Track *track = mwindow->session->track_highlighted;
1571 EDL *drag_group = mwindow->session->drag_group;
1572 Track *edit_track = mwindow->session->drag_group_edit->track;
1573 Track *drag_track = mwindow->session->drag_group_first_track;
1574 while( track && edit_track && edit_track != drag_track ) {
1575 edit_track = edit_track->previous;
1576 track = track->previous;
1578 int cx = get_cursor_x();
1579 double cur_pos = mwindow->session->drag_group_position;
1580 double new_pos = mwindow->edl->get_cursor_position(cx, pane->number);
1581 new_pos -= mwindow->session->drag_position - cur_pos;
1582 new_pos = mwindow->edl->align_to_frame(new_pos, 0);
1583 double drop_position = new_pos;
1585 int ret = test_track_group(drag_group, track, new_pos);
1589 if( new_pos != drop_position ) {
1590 double pos = new_pos;
1591 pos += mwindow->session->drag_position - cur_pos;
1592 cx = mwindow->edl->get_position_cursorx(pos, pane->number);
1593 ret = test_track_group(drag_group, track, new_pos);
1595 color = ret > 0 ? YELLOW : shift_down() ? RED : BLUE;
1597 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1598 int dx = cx - mwindow->session->drag_origin_x;
1599 int dy = y - mwindow->session->drag_origin_y;
1600 draw_selected_edits(mwindow->edl, dx, dy, color, -1);
1603 // Dragging an effect from the timeline
1604 case DRAG_AEFFECT_COPY:
1605 case DRAG_VEFFECT_COPY:
1606 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1607 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1608 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1609 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1610 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1612 int64_t plugin_position = -1;
1613 Plugin *drag_plugin = mwindow->session->drag_plugin;
1614 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1615 Track *hi_track = mwindow->session->track_highlighted;
1616 Edit *hi_edit = mwindow->session->edit_highlighted;
1617 // Put it into a silence zone
1618 if( hi_plugin_set && hi_plugin_set->last &&
1619 hi_plugin_set->track == drag_plugin->track ) {
1620 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1621 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1622 hi_track = drag_plugin->track;
1624 else if( hi_track ) {
1625 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1626 track_dimensions(hi_track, x, y, w, h);
1627 plugin_position = hi_edit ? hi_edit->startproject : 0;
1630 if( plugin_position < 0 ) break;
1632 // Calculate length of plugin based on data type of track and units
1633 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1634 mwindow->edl->local_session->zoom_sample;
1635 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1636 mwindow->edl->local_session->view_start[pane->number];
1637 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1639 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1640 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1646 case DRAG_PLUGINKEY:
1647 if(mwindow->session->plugin_highlighted &&
1648 mwindow->session->current_operation == DRAG_PLUGINKEY)
1650 // Just highlight the plugin
1651 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1653 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1654 MWindowGUI::visible(y, y + h, 0, get_h()))
1664 draw_highlight_rectangle(x, y, w, h);
1666 draw_selected_edits(mwindow->edl, 0, 0, GREEN+BLUE, RED);
1669 // x does not reliably draw a really big rectangle
1670 void TrackCanvas::draw_selected(int x, int y, int w, int h)
1672 int x1 = bmax(x, 0), x2 = bmin(x+w, get_w());
1673 if( x1 > x2 ) return;
1674 int y1 = bmax(y, 0), y2 = bmin(y+h, get_h());
1675 if( y1 > y2 ) return;
1676 if( x >= 0 && x < get_w() ) draw_line(x,y1, x,y2);
1677 if( x+w >= 0 && x+w < get_w() ) draw_line(x+w,y1, x+w,y2);
1678 if( y >= 0 && y < get_h() ) draw_line(x1,y, x2,y);
1679 if( y+h >= 0 && y+h < get_h() ) draw_line(x1,y+h, x2,y+h);
1682 void TrackCanvas::draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1)
1685 for( Track *track=edl->tracks->first; track; track=track->next ) {
1686 if( track->is_hidden() ) continue;
1687 if( !track->is_armed() && color1 < 0 ) {
1689 dy -= track->vertical_span(mwindow->theme);
1692 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1693 if( !edit->is_selected ) continue;
1696 edit_dimensions(edit, x, y, w, h);
1698 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ) continue;
1699 if( !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
1701 int inner = color1 < 0 ? color0 : !edit->group_id ? color0 :
1702 mwindow->get_group_color(edit->group_id);
1703 int outer = color1 < 0 ? color0 : !edit->group_id ? color1 : inner;
1704 set_color(track->is_armed() ? inner : outer);
1705 draw_selected(x, y, w, h);
1706 set_color(track->is_armed() ? outer : inner);
1707 draw_selected(x-1, y-1, w+2, h+2);
1708 draw_selected(x-2, y-2, w+1, h+1);
1713 void TrackCanvas::draw_plugins()
1715 char string[BCTEXTLEN];
1717 int current_show = 0;
1718 int current_preset = 0;
1720 for(int i = 0; i < plugin_on_toggles.total; i++)
1721 plugin_on_toggles.values[i]->in_use = 0;
1722 for(int i = 0; i < plugin_show_toggles.total; i++)
1723 plugin_show_toggles.values[i]->in_use = 0;
1724 for(int i = 0; i < preset_edit_buttons.total; i++)
1725 plugin_show_toggles.values[i]->in_use = 0;
1728 for(Track *track = mwindow->edl->tracks->first;
1730 track = track->next)
1732 if( track->is_hidden() ) continue;
1733 if(track->expand_view)
1735 for(int i = 0; i < track->plugin_set.total; i++)
1737 PluginSet *pluginset = track->plugin_set.values[i];
1739 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1741 int64_t total_x, y, total_w, h;
1742 plugin_dimensions(plugin, total_x, y, total_w, h);
1744 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1745 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1746 plugin->plugin_type != PLUGIN_NONE)
1748 int x = total_x, w = total_w, left_margin = 5;
1749 int right_margin = 5;
1755 if(w + x > get_w()) w -= (w + x) - get_w();
1762 mwindow->theme->get_image("plugin_bg_data"),
1764 set_color(mwindow->theme->title_color);
1765 set_font(mwindow->theme->title_font);
1766 plugin->calculate_title(string, 0);
1768 // Truncate string to int64_test visible in background
1769 int len = strlen(string), j;
1770 for(j = len; j >= 0; j--)
1772 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1780 // Justify the text on the left boundary of the edit if it is visible.
1781 // Otherwise justify it on the left side of the screen.
1782 int64_t text_x = total_x + left_margin;
1783 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1784 text_x = MAX(left_margin, text_x);
1786 y + get_text_ascent(mwindow->theme->title_font) + 2,
1790 int64_t min_x = total_x + text_w;
1793 // Update plugin toggles
1794 int toggle_x = total_x + total_w;
1796 toggle_x = MIN(get_w() - right_margin, toggle_x);
1799 toggle_x -= PluginOn::calculate_w(mwindow) + xS(10);
1800 if(toggle_x > min_x)
1802 if(current_on >= plugin_on_toggles.total)
1804 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1805 add_subwindow(plugin_on);
1806 plugin_on_toggles.append(plugin_on);
1810 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1815 // Toggles for standalone plugins only
1816 if(plugin->plugin_type == PLUGIN_STANDALONE)
1819 toggle_x -= PluginShow::calculate_w(mwindow) + xS(10);
1820 if(toggle_x > min_x)
1822 if(current_show >= plugin_show_toggles.total)
1824 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1825 add_subwindow(plugin_show);
1826 plugin_show_toggles.append(plugin_show);
1830 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1834 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + xS(10);
1835 if(toggle_x > min_x)
1837 if(current_preset >= preset_edit_buttons.total)
1839 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1840 add_subwindow(preset_edit);
1841 preset_edit_buttons.append(preset_edit);
1845 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1856 // Remove unused toggles
1858 while(current_preset < preset_edit_buttons.total)
1860 preset_edit_buttons.remove_object_number(current_preset);
1862 while(current_show < plugin_show_toggles.total)
1864 plugin_show_toggles.remove_object_number(current_show);
1867 while(current_on < plugin_on_toggles.total)
1869 plugin_on_toggles.remove_object_number(current_on);
1873 void TrackCanvas::refresh_plugintoggles()
1875 for(int i = 0; i < plugin_on_toggles.total; i++)
1877 PluginOn *on = plugin_on_toggles.values[i];
1878 on->reposition_window(on->get_x(), on->get_y());
1880 for(int i = 0; i < plugin_show_toggles.total; i++)
1882 PluginShow *show = plugin_show_toggles.values[i];
1883 show->reposition_window(show->get_x(), show->get_y());
1885 for(int i = 0; i < preset_edit_buttons.total; i++)
1887 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1888 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1892 void TrackCanvas::draw_hard_edges()
1894 if( !mwindow->edl->session->auto_conf->hard_edges )
1898 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1899 if( track->is_hidden() ) continue;
1900 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1901 if( !edit->hard_left && !edit->hard_right ) continue;
1902 edit_dimensions(edit, x, y, w, h);
1903 if( !MWindowGUI::visible(x, x + w, 0, get_w()) ||
1904 !MWindowGUI::visible(y, y + h, 0, get_h()) ) continue;
1908 if( track->show_titles() )
1909 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
1910 if( track->show_assets() )
1911 y1 += track->data_h;
1913 y1 += mwindow->theme->title_h;
1914 if( edit->hard_left ) {
1915 ArrayList<int> xpt, ypt;
1916 xpt.append(x); ypt.append(y1);
1917 xpt.append(x+HANDLE_W); ypt.append(y1);
1918 xpt.append(x); ypt.append(y1-HANDLE_H);
1919 fill_polygon(&xpt, &ypt);
1921 if( edit->hard_right ) {
1922 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1923 xpt.append(x1); ypt.append(y1);
1924 xpt.append(x1-HANDLE_W); ypt.append(y1);
1925 xpt.append(x1); ypt.append(y1-HANDLE_H);
1926 fill_polygon(&xpt, &ypt);
1932 void TrackCanvas::draw_inout_points()
1937 void TrackCanvas::draw_drag_handle()
1939 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 &&
1940 mwindow->session->current_operation != DRAG_PLUGINHANDLE2 ) return;
1941 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1942 mwindow->edl->session->sample_rate /
1943 mwindow->edl->local_session->zoom_sample -
1944 mwindow->edl->local_session->view_start[pane->number]);
1945 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1947 draw_line(pixel1, 0, pixel1, get_h());
1950 if( mwindow->session->current_operation != DRAG_EDITHANDLE2 ) return;
1951 if( !mwindow->session->drag_edit ) return;
1952 int group_id = mwindow->session->drag_edit->group_id;
1953 if( !group_id ) return;
1954 int64_t dx, dy, dw, dh;
1955 edit_dimensions(mwindow->session->drag_edit, dx, dy, dw, dh);
1956 int drag_handle = mwindow->session->drag_handle;
1957 int64_t pixel0 = !drag_handle ? dx : dx + dw;
1958 int delta = pixel1 - pixel0;
1959 set_color(LTPURPLE);
1962 for( Track *track=mwindow->edl->tracks->first; track; track=track->next ) {
1963 if( track->is_hidden() ) continue;
1964 Edit *left = 0, *right = 0;
1965 double start = DBL_MAX, end = DBL_MIN;
1966 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
1967 if( edit->group_id != group_id ) continue;
1968 double edit_start = edit->track->from_units(edit->startproject);
1969 if( edit_start < start ) { start = edit_start; left = edit; }
1970 double edit_end = edit->track->from_units(edit->startproject+edit->length);
1971 if( edit_end > end ) { end = edit_end; right = edit; }
1973 Edit *edit = !drag_handle ? left : right;
1974 if( !edit ) continue;
1975 Indexable *idxbl = edit->asset;
1976 if( !idxbl ) idxbl = edit->nested_edl;
1977 int can_drag = idxbl ? 1 : 0;
1979 int64_t source_len = !idxbl ? -1 :
1980 edit->track->data_type == TRACK_AUDIO ?
1981 idxbl->get_audio_samples() :
1982 edit->track->data_type == TRACK_VIDEO ?
1983 idxbl->get_video_frames() : -1;
1984 if( edit->startsource + edit->length >= source_len )
1987 else if( !edit->startsource )
1990 edit_dimensions(edit, x, y, w, h);
1991 if( y+h < 0 || y >= get_h() ) continue;
1992 int edge_x = !drag_handle ? x : x + w;
1993 int edge_y = y + h/2, xs10 = xS(10), ys10 = yS(10);
1994 if( edge_x >= 0 && edge_x < get_w() ) {
1996 draw_line(edge_x-xs10,edge_y-ys10, edge_x+xs10,edge_y+ys10);
1997 draw_line(edge_x-xs10,edge_y+ys10, edge_x+xs10,edge_y-ys10);
1999 else if( !drag_handle ) {
2000 draw_line(edge_x+xs10,edge_y-ys10, edge_x,edge_y);
2001 draw_line(edge_x+xs10,edge_y+ys10, edge_x,edge_y);
2004 draw_line(edge_x,edge_y, edge_x-xs10,edge_y-ys10);
2005 draw_line(edge_x,edge_y, edge_x-xs10,edge_y+ys10);
2009 if( edge_x >= 0 && edge_x < get_w() ) {
2010 draw_line(edge_x, y, edge_x, y+h);
2017 void TrackCanvas::draw_transitions()
2021 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
2022 if( track->is_hidden() ) continue;
2023 if( !track->show_transitions() ) continue;
2025 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
2026 if(!edit->transition) continue;
2027 edit_dimensions(edit, x, y, w, h);
2028 int strip_x = x, edit_y = y;
2029 get_transition_coords(edit, x, y, w, h);
2030 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
2031 if( track->show_assets() && track->show_titles() )
2032 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
2033 if( strip_y < edit_y ) strip_y = edit_y;
2035 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
2036 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
2037 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
2038 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
2039 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
2041 if( !server ) continue;
2042 VFrame *picon = server->get_picon();
2043 if( !picon ) continue;
2044 int picon_w = picon->get_w(), picon_h = picon->get_h();
2045 int track_h = edit->track->vertical_span(mwindow->theme);
2046 if( picon_h > track_h ) picon_h = track_h;
2047 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
2049 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
2050 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
2051 int x = strip_x, w = strip_w;
2052 if( x < 0 ) { w -= -x; x = 0; }
2053 if( w + x > get_w() ) w -= (w + x) - get_w();
2055 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
2056 mwindow->theme->get_image("plugin_bg_data"), 0);
2062 void TrackCanvas::draw_loop_points()
2064 //printf("TrackCanvas::draw_loop_points 1\n");
2065 if(mwindow->edl->local_session->loop_playback)
2067 //printf("TrackCanvas::draw_loop_points 2\n");
2068 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
2069 mwindow->edl->session->sample_rate /
2070 mwindow->edl->local_session->zoom_sample -
2071 mwindow->edl->local_session->view_start[pane->number]);
2072 //printf("TrackCanvas::draw_loop_points 3\n");
2074 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2077 draw_line(x, 0, x, get_h());
2079 //printf("TrackCanvas::draw_loop_points 4\n");
2081 x = Units::round(mwindow->edl->local_session->loop_end *
2082 mwindow->edl->session->sample_rate /
2083 mwindow->edl->local_session->zoom_sample -
2084 mwindow->edl->local_session->view_start[pane->number]);
2085 //printf("TrackCanvas::draw_loop_points 5\n");
2087 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
2090 draw_line(x, 0, x, get_h());
2092 //printf("TrackCanvas::draw_loop_points 6\n");
2094 //printf("TrackCanvas::draw_loop_points 7\n");
2097 void TrackCanvas::draw_brender_range()
2099 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
2100 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
2101 if( mwindow->edl->session->brender_end > 0 )
2103 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
2104 mwindow->edl->session->sample_rate /
2105 mwindow->edl->local_session->zoom_sample -
2106 mwindow->edl->local_session->view_start[pane->number]);
2107 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
2110 draw_line(x1, 0, x1, get_h());
2112 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
2113 mwindow->edl->session->sample_rate /
2114 mwindow->edl->local_session->zoom_sample -
2115 mwindow->edl->local_session->view_start[pane->number]);
2117 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
2120 draw_line(x2, 0, x2, get_h());
2125 // The operations which correspond to each automation type
2126 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
2142 // The buttonpress operations, so nothing changes unless the mouse moves
2143 // a certain amount. This allows the keyframe to be used to position the
2144 // insertion point without moving itself.
2145 static int pre_auto_operations[AUTOMATION_TOTAL] =
2162 int TrackCanvas::do_keyframes(int cursor_x,
2170 // Note: button 3 (right mouse button) is not eaten to allow
2171 // track context menu to appear
2173 EDLSession *session = mwindow->edl->session;
2174 int gang = session->gang_tracks != GANG_NONE || get_double_click() ? 1 : 0;
2176 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
2178 0, 0, 0, 0, 0, 0, 0, 0,
2180 modekeyframe_pixmap,
2181 maskkeyframe_pixmap,
2187 for(Track *track = mwindow->edl->tracks->first;
2189 track = track->next) {
2190 if( track->is_hidden() ) continue;
2191 Auto *auto_keyframe = 0;
2192 Automation *automation = track->automation;
2195 // Handle keyframes in reverse drawing order if a button press
2197 int end = AUTOMATION_TOTAL;
2201 start = AUTOMATION_TOTAL - 1;
2205 for(int i = start; i != end && !result; i += step)
2207 // Event not trapped and automation visible
2208 Autos *autos = automation->autos[i];
2209 if(!result && session->auto_conf->autos[i] && autos) {
2211 case AUTOMATION_MODE:
2212 case AUTOMATION_PAN:
2213 case AUTOMATION_MASK:
2214 result = do_autos(track, automation->autos[i],
2215 cursor_x, cursor_y, draw,
2216 buttonpress, auto_pixmaps[i],
2217 auto_keyframe, rerender);
2221 switch(autos->get_type()) {
2222 case Autos::AUTOMATION_TYPE_FLOAT: {
2223 Automation automation(0, track);
2224 int grouptype = automation.autogrouptype(i, track);
2225 if( buttonpress && i == AUTOMATION_SPEED ) {
2226 mwindow->speed_before();
2229 if(draw) // Do dropshadow
2230 result = do_float_autos(track, autos,
2231 cursor_x, cursor_y, draw,
2232 buttonpress, 1, 1, MDGREY,
2233 auto_keyframe, grouptype);
2234 result = do_float_autos(track, autos,
2235 cursor_x, cursor_y, draw, buttonpress,
2236 0, 0, GWindowGUI::auto_colors[i],
2237 auto_keyframe, grouptype);
2239 if( !result && buttonpress && i == AUTOMATION_SPEED )
2240 mwindow->speed_after(-1);
2241 if( result && buttonpress ) {
2242 int color = GWindowGUI::auto_colors[i];
2243 mwindow->gui->zoombar->update_autozoom(grouptype, color);
2247 case Autos::AUTOMATION_TYPE_INT: {
2248 if(draw) // Do dropshadow
2249 result = do_int_autos(track, autos,
2250 cursor_x, cursor_y, draw,
2251 buttonpress, 1, 1, MDGREY,
2253 result = do_int_autos(track, autos,
2254 cursor_x, cursor_y, draw, buttonpress,
2255 0, 0, GWindowGUI::auto_colors[i],
2264 if(mwindow->session->current_operation == auto_operations[i])
2267 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2269 // mwindow->session->current_operation,
2270 // auto_operations[i]);
2273 if (buttonpress == 2 && auto_keyframe )
2275 double position = track->from_units(auto_keyframe->position);
2276 mwindow->edl->local_session->set_selectionstart(position);
2277 mwindow->edl->local_session->set_selectionend(position);
2279 if (buttonpress != 3)
2281 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2282 fill_ganged_autos(gang, 0, track,
2283 (FloatAuto*)mwindow->session->drag_auto);
2284 mwindow->session->current_operation = pre_auto_operations[i];
2285 update_drag_caption();
2288 else if( auto_keyframe )
2290 gui->keyframe_menu->update(automation,
2293 gui->keyframe_menu->activate_menu();
2294 rerender = 1; // the position changes
2298 gui->keyframe_hide->update(autos);
2299 gui->keyframe_hide->activate_menu();
2300 rerender = 1; // the position changes
2302 if(buttonpress == 1 && ctrl_down() &&
2303 AUTOMATION_TYPE_FLOAT == autos->get_type())
2304 rerender = 1; // special case: curve mode changed
2310 if(!result && session->auto_conf->plugins) {
2313 result = do_plugin_autos(track, cursor_x, cursor_y,
2314 draw, buttonpress, plugin, keyframe);
2315 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2318 if(result && (buttonpress == 1)) {
2319 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2320 update_drag_caption();
2323 else if (result && (buttonpress == 3)) {
2324 gui->keyframe_menu->update(plugin, keyframe);
2325 gui->keyframe_menu->activate_menu();
2326 rerender = 1; // the position changes
2331 // Final pass to trap event
2332 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2333 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2334 mwindow->session->current_operation == auto_operations[i]) {
2340 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2341 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2347 new_cursor = UPRIGHT_ARROW_CURSOR;
2353 void TrackCanvas::draw_keyframe_reticle()
2355 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2356 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2358 int current_op = mwindow->session->current_operation, dragging = 0;
2359 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2360 if( current_op == auto_operations[i] ) dragging = 1;
2361 if( dragging && !mwindow->session->drag_auto ) dragging = 0;
2363 int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
2364 mwindow->session->drag_auto->autos->autoidx : -1;
2366 if( get_buttonpress() == LEFT_BUTTON && dragging &&
2367 keyframe_hairline == HAIRLINE_DRAGGING ) {
2368 draw_hairline(mwindow->session->drag_auto, RED, 1);
2372 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == MIDDLE_BUTTON &&
2373 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2374 int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
2375 for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
2376 if( track->is_hidden() ) continue;
2377 Automation *automation = track->automation;
2378 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2379 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2380 // automation visible
2381 Autos *autos = automation->autos[i];
2382 if( !autos ) continue;
2383 if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
2384 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2385 auto_keyframe = auto_keyframe->next ) {
2386 draw_hairline(auto_keyframe, BLUE, show);
2392 draw_hairline(mwindow->session->drag_auto, RED, 1);
2396 void TrackCanvas::draw_auto(Auto *current, int x, int y,
2397 int center_pixel, int data_h)
2401 x1 = x - HANDLE_W / 2;
2402 x2 = x + HANDLE_W / 2;
2403 y1 = center_pixel + y - HANDLE_W / 2;
2404 y2 = center_pixel + y + HANDLE_W / 2;
2406 if( y1 < center_pixel - data_h/2 ) y1 = center_pixel - data_h/2;
2407 if( y2 > center_pixel + data_h/2 ) y2 = center_pixel + data_h/2;
2409 draw_box(x1, y1, x2 - x1, y2 - y1);
2413 // This draws lines for bezier in & out controls
2414 void TrackCanvas::draw_cropped_line(int x1,
2423 // Don't care about x since it is clipped by the window.
2424 // Put y coords in ascending order
2426 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2427 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2432 double slope = (double)(x2 - x1) / (y2 - y1);
2433 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2435 x1 = (int)(x1 + (min_y - y1) * slope);
2438 else if(y1 >= max_y) {
2439 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2444 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2447 else if(y2 < min_y) {
2448 x2 = (int)(x2 + (min_y - y2) * slope);
2453 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2454 if( y1 >= min_y && y1 < max_y &&
2455 y2 >= min_y && y2 < max_y )
2456 draw_line(x1, y1, x2, y2);
2460 void TrackCanvas::draw_floatauto(FloatAuto *current, int x, int y,
2461 int in_x, int in_y, int out_x, int out_y,
2462 int center_pixel, int data_h, int color)
2464 int x1 = x - HANDLE_W / 2; // Center
2465 int x2 = x + HANDLE_W / 2;
2466 int y1 = center_pixel + y - HANDLE_H / 2;
2467 int y2 = center_pixel + y + HANDLE_H / 2;
2468 int ymin = center_pixel - data_h / 2;
2469 int ymax = center_pixel + data_h / 2;
2470 CLAMP(y1, ymin, ymax);
2471 CLAMP(y2, ymin, ymax);
2474 if( current->curve_mode == FloatAuto::LINEAR ) {
2475 draw_box(x1, y1, x2 - x1, y2 - y1);
2478 ArrayList<int> polygon_x;
2479 ArrayList<int> polygon_y;
2480 polygon_x.append((x1 + x2) / 2 + 1);
2481 polygon_y.append(y1 + 1);
2482 polygon_x.append(x2 + 1);
2483 polygon_y.append((y1 + y2) / 2 + 1);
2484 polygon_x.append((x1 + x2) / 2 + 1);
2485 polygon_y.append(y2 + 1);
2486 polygon_x.append(x1 + 1);
2487 polygon_y.append((y1 + y2) / 2 + 1);
2488 fill_polygon(&polygon_x, &polygon_y);
2492 // show bezier control points (only) if this
2493 // floatauto doesn't adjust it's tangents automatically
2494 if(current->curve_mode != FloatAuto::FREE &&
2495 current->curve_mode != FloatAuto::TFREE)
2499 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, data_h, color);
2501 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, data_h, color);
2504 inline int quantize(float f) { return (int)floor(f + 0.5); }
2506 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2507 int x, int y, int cp_x, int cp_y, int center_pixel,
2508 int data_h, int color)
2509 // draw the tangent and a handle for given bézier ctrl point
2511 bool handle_visible = (abs(cp_y) <= data_h/2);
2513 float slope = (float)(cp_y - y)/(cp_x - x);
2514 CLAMP(cp_y, -data_h/2, data_h/2);
2516 cp_x = x + quantize((cp_y - y) / slope);
2519 cp_y += center_pixel;
2521 // drawing the tangent as a dashed line...
2522 int const dash = HANDLE_W;
2523 int const gap = HANDLE_W / 2;
2524 float sx = 3 * (cp_x - x) / 4.;
2527 // q is the x displacement for a unit line of slope
2528 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2530 float dist = 1/q * sx;
2536 float sy = slope * sx, ey = slope * ex;
2537 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2544 int r = HANDLE_W / 2;
2545 int cp_x1 = cp_x - r;
2546 int cp_y1 = cp_y - r;
2548 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2550 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2555 int TrackCanvas::test_auto(Auto *current,
2556 int x, int y, int center_pixel, int data_h,
2557 int cursor_x, int cursor_y, int buttonpress)
2562 x1 = x - HANDLE_W / 2;
2563 x2 = x + HANDLE_W / 2;
2564 y1 = center_pixel + y - HANDLE_H / 2;
2565 y2 = center_pixel + y + HANDLE_H / 2;
2566 int ymin = center_pixel - data_h/2;
2567 int ymax = center_pixel + data_h/2;
2568 CLAMP(y1, ymin, ymax);
2569 CLAMP(y2, ymin, ymax);
2571 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2573 if(buttonpress && buttonpress != 3)
2575 mwindow->session->drag_auto = current;
2576 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2577 // Toggle Autos don't respond to vertical zoom, they always show up
2578 // with "on" == 100% == line on top
2579 mwindow->session->drag_start_position = current->position;
2580 mwindow->session->drag_origin_x = cursor_x;
2581 mwindow->session->drag_origin_y = cursor_y;
2586 if(buttonpress && buttonpress != 3 && result)
2588 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2589 mwindow->undo->update_undo_before();
2595 // some Helpers for test_floatauto(..)
2596 // and for dragging the tangents/ctrl points
2597 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2598 float cursor_x, float cursor_y)
2600 // Control point switched off?
2601 if( x0 == ctrl_x ) return 0.0;
2602 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2603 double x = cursor_x-x0, y = cursor_y-y0;
2604 // wrong side of ctrl handle
2605 if( x*x1 < 0 ) return 0.0;
2606 // outside handle radius
2607 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2608 double xx1 = x1*x1, yy1 = y1*y1;
2609 double xx = x*x, yy = y*y;
2610 // distance squared from cursor to cursor projected to line from ctrl to handle
2611 // along a line perpendicular to line from ctrl to handle (closest approach)
2612 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2613 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2614 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2619 float levered_position(float position, float ref_pos)
2621 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2623 return ref_pos / position;
2627 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2628 // transforms automation value into current display coords,
2629 // dependant on current automation display range for the given kind of automation
2631 if(!mwindow || !mwindow->edl) return 0;
2632 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2633 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2634 float automation_range = automation_max - automation_min;
2635 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2637 return (auto_value - automation_min) / automation_range;
2642 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2643 int in_y, int out_x, int out_y, int center_pixel, int data_h,
2644 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2648 int x1 = x - HANDLE_W / 2;
2649 int x2 = x + HANDLE_W / 2;
2650 int y1 = center_pixel + y - HANDLE_W / 2;
2651 int y2 = center_pixel + y + HANDLE_W / 2;
2652 int ymin = center_pixel - data_h/2;
2653 int ymax = center_pixel + data_h/2;
2654 CLAMP(y1, ymin, ymax);
2655 CLAMP(y2, ymin, ymax);
2657 int in_x1 = in_x - HANDLE_W / 2;
2658 int in_x2 = in_x + HANDLE_W / 2;
2659 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2660 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2661 CLAMP(in_y1, ymin, ymax);
2662 CLAMP(in_y2, ymin, ymax);
2664 int out_x1 = out_x - HANDLE_W / 2;
2665 int out_x2 = out_x + HANDLE_W / 2;
2666 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2667 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2668 CLAMP(out_y1, ymin, ymax);
2669 CLAMP(out_y2, ymin, ymax);
2672 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2673 // buttonpress could be the start of a drag operation
2674 #define INIT_DRAG(POS,VAL) \
2675 mwindow->session->drag_auto = current; \
2676 mwindow->session->drag_origin_x = cursor_x; \
2677 mwindow->session->drag_origin_y = cursor_y; \
2678 mwindow->session->drag_start_position = (POS); \
2679 mwindow->session->drag_start_percentage = (VAL);
2681 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2684 // without modifier we are manipulating the automation node
2685 // with ALT it's about dragging only the value of the node
2686 // with SHIFT the value snaps to the value of neighbouring nodes
2687 // CTRL indicates we are rather manipulating the tangent(s) of the node
2691 if( WITHIN(x1,x2,y1,y2))
2692 { // cursor hits node
2695 if(buttonpress && (buttonpress != 3))
2697 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2698 mwindow->session->drag_handle = 0;
2703 if( WITHIN(x1,x2,y1,y2))
2706 if(buttonpress && (buttonpress != 3))
2708 // could be ctrl-click or ctrl-drag
2709 // click would cycle through tangent modes
2710 ((FloatAuto*)current)->toggle_curve_mode();
2712 // drag will start dragging the tangent, if applicable
2713 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2714 mwindow->session->drag_handle = 0;
2718 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2721 if( in_x != x && current->position > 0 &&
2722 (FloatAuto::FREE == current->curve_mode ||
2723 FloatAuto::TFREE == current->curve_mode))
2724 // act on in control handle only if
2725 // tangent is significant and is editable (not automatically choosen)
2727 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2728 // either cursor in ctrl-point handle or cursor on tangent line
2729 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2731 if(buttonpress && (buttonpress != 3)) {
2732 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2734 mwindow->session->drag_handle = 1;
2735 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2736 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2737 value_to_percentage(new_invalue, autogrouptype))
2744 (FloatAuto::FREE == current->curve_mode ||
2745 FloatAuto::TFREE == current->curve_mode))
2746 // act on out control only if tangent is significant and is editable
2748 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2749 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2751 if(buttonpress && (buttonpress != 3)) {
2752 if(lever == 0.0) lever=1.0;
2754 mwindow->session->drag_handle = 2;
2755 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2756 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2757 value_to_percentage(new_outvalue, autogrouptype))
2761 } // end ctrl_down()
2767 // 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",
2768 // mwindow->session->drag_handle,
2773 if(buttonpress && (buttonpress != 3) && result)
2775 mwindow->undo->update_undo_before();
2781 static int is_linear(FloatAuto *prev, FloatAuto *next)
2783 if( !prev || !next ) return 1;
2784 if( prev->curve_mode == FloatAuto::LINEAR ) return 1;
2785 int64_t ipos = prev->get_control_in_position();
2786 int64_t opos = prev->get_control_out_position();
2787 if( !ipos && !opos ) return 1;
2788 if( !ipos || !opos ) return 0;
2789 float ival = prev->get_control_in_value();
2790 float oval = prev->get_control_out_value();
2791 float cval = prev->get_value(), nval = next->get_value();
2792 if( !ival && !oval && EQUIV(cval, nval) ) return 1;
2793 float ig = ival / ipos, og = oval / opos;
2794 int64_t cpos = prev->position, npos = next->position;
2795 float g = (nval - cval) / (npos - cpos);
2796 if( EQUIV(ig, g) && EQUIV(og, g) ) return 1;
2800 // Get the float value & y for position x on the canvas
2801 #define X_TO_FLOATLINE(x) \
2802 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2803 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2804 /* Call by reference fails for some reason here */ \
2805 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2806 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2807 double position = unit_start + x * zoom_units; \
2809 if(position2 > position1) \
2812 (value2 - value1) * \
2813 (position - position1) / \
2814 (position2 - position1); \
2820 AUTOMATIONCLAMPS(value, autogrouptype); \
2821 int y = center_pixel + \
2822 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2825 void TrackCanvas::draw_floatline(int center_pixel,
2826 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2827 double unit_start, double zoom_units, double yscale,
2828 int x1, int y1, int x2, int y2,
2829 int color, int autogrouptype)
2831 int ytop = center_pixel - yscale / 2;
2832 int ybot = center_pixel + yscale / 2 - 1;
2833 y1 += center_pixel; y2 += center_pixel;
2834 if( (y1 < ytop && y1 >= ybot) && (y2 < ytop || y2 >= ybot) ) return;
2835 // check for line draw
2836 if( is_linear(previous, next) ) {
2837 draw_line(x1, y1, x2, y2);
2841 // Solve bezier equation for either every pixel or a certain large number of
2844 // Not using slope intercept
2849 // Call by reference fails for some reason here
2850 FloatAuto *previous1 = previous, *next1 = next;
2851 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2852 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2853 float automation_range = automation_max - automation_min;
2854 if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN )
2855 automation_range = SPEED_MIN;
2856 for( int x=x1; x<x2; ++x ) {
2857 // Interpolate value between frames
2860 if( /* x > x1 && */ y >= ytop && y < ybot ) {
2861 int x1 = x-1, y1 = prev_y, x2 = x, y2 = y;
2862 if( abs(y2-y1) < 2 )
2865 draw_bline(x1, y1, x2, y2);
2872 int TrackCanvas::test_floatline(int center_pixel,
2887 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2888 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2889 float automation_range = automation_max - automation_min;
2890 if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN )
2891 automation_range = SPEED_MIN;
2892 FloatAuto *previous1 = 0, *next1 = 0;
2893 X_TO_FLOATLINE(cursor_x);
2895 if(cursor_x >= x1 &&
2897 cursor_y >= y - HANDLE_W / 2 &&
2898 cursor_y < y + HANDLE_W / 2 &&
2904 if(buttonpress == 3)
2912 mwindow->undo->update_undo_before();
2913 double position = autos->track->from_units(position1);
2914 position = mwindow->edl->align_to_frame(position, 0);
2915 int64_t new_position = autos->track->to_units(position,0);
2916 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2917 ((FloatAuto*)current)->set_value(value);
2918 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2919 mwindow->session->drag_start_position = current->position;
2920 mwindow->session->drag_origin_x = cursor_x;
2921 mwindow->session->drag_origin_y = cursor_y;
2922 mwindow->session->drag_handle = 0;
2931 void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto)
2933 if( !skip->is_ganged() ) return;
2934 // Handles the special case of modifying a fadeauto
2935 // when there are ganged faders on several tracks
2936 double position = skip->from_units(fauto->position);
2937 int autoidx = fauto->autos->autoidx;
2939 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2940 if( (all || current->data_type == skip->data_type) &&
2941 current->armed_gang(skip) && current->is_armed() &&
2943 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2944 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2945 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2946 int64_t current_position = current->to_units(position, 1);
2947 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
2949 // keyframe exists, just change it
2950 float value = keyframe->get_value();
2951 float new_value = value + change;
2952 CLAMP(new_value, auto_min, auto_max);
2953 keyframe->adjust_to_new_coordinates(current_position, new_value);
2955 else if( all >= 0 ) {
2956 // create keyframe on neighbouring track at the point in time given by fauto
2957 FloatAuto *previous = 0, *next = 0;
2958 float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2959 float new_value = value + change;
2960 CLAMP(new_value, auto_min, auto_max);
2961 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2962 keyframe->set_value(new_value);
2964 if( !keyframe ) continue;
2965 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2970 void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
2972 double position = skip->from_units(fauto->position);
2974 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2975 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2976 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2977 float new_value = keyframe->get_value() + change;
2979 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2980 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2981 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2985 void TrackCanvas::clear_ganged_autos()
2988 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2989 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2990 keyframe->autos->remove_nonsequential(keyframe);
2992 mwindow->session->drag_auto_gang->remove_all();
2996 void TrackCanvas::draw_toggleline(int center_pixel,
3002 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
3006 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
3010 int TrackCanvas::test_toggleline(Autos *autos,
3021 if(cursor_x >= x1 && cursor_x < x2)
3023 int miny = center_pixel + y1 - HANDLE_W / 2;
3024 int maxy = center_pixel + y1 + HANDLE_W / 2;
3025 if(cursor_y >= miny && cursor_y < maxy)
3030 if(buttonpress == 3)
3038 double position = (double)(cursor_x +
3039 mwindow->edl->local_session->view_start[pane->number]) *
3040 mwindow->edl->local_session->zoom_sample /
3041 mwindow->edl->session->sample_rate;
3042 int64_t unit_position = autos->track->to_units(position, 0);
3043 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
3045 mwindow->undo->update_undo_before();
3047 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
3048 ((IntAuto*)current)->value = new_value;
3049 // Toggle Autos don't respond to vertical zoom, they always show up
3050 // with "on" == 100% == line on top
3051 mwindow->session->drag_start_percentage = (float)new_value;
3052 mwindow->session->drag_start_position = current->position;
3053 mwindow->session->drag_origin_x = cursor_x;
3054 mwindow->session->drag_origin_y = cursor_y;
3062 void TrackCanvas::calculate_viewport(Track *track,
3063 double &view_start, // Seconds
3065 double &view_end, // Seconds
3069 double &zoom_sample,
3073 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
3074 mwindow->edl->local_session->zoom_sample /
3075 mwindow->edl->session->sample_rate;
3076 unit_start = track->to_doubleunits(view_start);
3077 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
3079 mwindow->edl->local_session->zoom_sample /
3080 mwindow->edl->session->sample_rate;
3081 unit_end = track->to_doubleunits(view_end);
3083 int y = track->y_pixel
3084 - mwindow->edl->local_session->track_start[pane->number];
3085 int has_titles = track->show_titles();
3086 int has_assets = track->show_assets();
3087 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
3088 double title_h = mwindow->theme->title_h;
3089 double data_h = track->data_h;
3090 double ys = has_assets ? data_h : has_titles ? title_bg_h : 0;
3091 double dy = has_titles ?
3092 ( has_assets ? title_bg_h + data_h/2 : title_bg_h/2) :
3093 ( has_assets ? data_h/2 : 0) ;
3094 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
3096 center_pixel = y + dy;
3098 zoom_sample = mwindow->edl->local_session->zoom_sample;
3099 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
3102 float TrackCanvas::percentage_to_value(float percentage,
3110 if(percentage > 0.5)
3117 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3118 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3119 float automation_range = automation_max - automation_min;
3121 result = percentage * automation_range + automation_min;
3124 FloatAuto *ptr = (FloatAuto*)reference;
3125 result -= ptr->get_value();
3127 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
3133 void TrackCanvas::calculate_auto_position(double *x, double *y,
3134 double *in_x, double *in_y, double *out_x, double *out_y,
3135 Auto *current, double unit_start, double zoom_units, double yscale,
3138 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
3139 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
3140 float automation_range = automation_max - automation_min;
3141 if( autogrouptype == AUTOGROUPTYPE_SPEED && automation_range < SPEED_MIN )
3142 automation_range = SPEED_MIN;
3143 FloatAuto *ptr = (FloatAuto*)current;
3144 *x = (double)(ptr->position - unit_start) / zoom_units;
3145 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
3148 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
3149 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
3153 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
3154 automation_min) / automation_range - 0.5) * -yscale;
3158 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
3159 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
3163 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
3164 automation_min) / automation_range - 0.5) * -yscale;
3169 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
3170 int draw, int buttonpress, int x_offset, int y_offset, int color,
3171 Auto* &auto_instance, int autogrouptype)
3174 int center_pixel, draw_auto;
3175 double view_start, unit_start;
3176 double view_end, unit_end, yscale;
3177 double zoom_sample, zoom_units;
3178 double in_x2, in_y2, out_x2, out_y2;
3184 if(draw) set_color(color);
3186 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3187 yscale, center_pixel, zoom_sample, zoom_units);
3189 // Get first auto before start
3190 Auto *current = 0, *previous = 0;
3192 for( current = autos->last;
3193 current && current->position >= unit_start;
3194 current = PREVIOUS ) ;
3196 Auto *first_auto = current ? current :
3197 autos->first ? autos->first : autos->default_auto;
3199 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
3201 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3202 first_auto, unit_start, zoom_units, yscale, autogrouptype);
3207 current = autos->first;
3216 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
3217 current, unit_start, zoom_units, yscale, autogrouptype);
3225 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3230 ay2 = ay + slope * (get_w() - ax);
3234 ay = ay + slope * (0 - ax);
3238 // Draw or test handle
3239 if( current && !result && current != autos->default_auto ) {
3240 if( !draw && track->is_armed() ) {
3241 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3242 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3243 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3244 buttonpress, autogrouptype);
3246 auto_instance = current;
3248 if( draw && draw_auto ) {
3249 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3250 (int)in_x2 + x_offset, (int)in_y2,
3251 (int)out_x2 + x_offset, (int)out_y2,
3252 (int)center_pixel + y_offset, (int)yscale, color);
3256 // Draw or test joining line
3257 if( !draw && !result && track->is_armed() /* && buttonpress != 3 */ ) {
3258 result = test_floatline(center_pixel,
3259 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3260 // Exclude auto coverage from the end of the line. The auto overlaps
3261 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3262 buttonpress, autogrouptype);
3265 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3266 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3267 (int)ax, (int)ay, (int)ax2, (int)ay2,
3268 color, autogrouptype);
3276 } while( current && current->position <= unit_end && !result );
3278 if( ax < get_w() && !result ) {
3279 ax2 = get_w(); ay2 = ay;
3280 if(!draw && track->is_armed() /* && buttonpress != 3 */ ) {
3281 result = test_floatline(center_pixel,
3282 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3283 (int)ax, (int)ax2, cursor_x, cursor_y,
3284 buttonpress, autogrouptype);
3287 draw_floatline(center_pixel,
3288 (FloatAuto*)previous, (FloatAuto*)current,
3289 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3290 (int)ax, (int)ay, (int)ax2, (int)ay2,
3291 color, autogrouptype);
3298 int TrackCanvas::do_int_autos(Track *track,
3307 Auto *&auto_instance)
3318 double ax, ay, ax2, ay2;
3322 if(draw) set_color(color);
3324 calculate_viewport(track,
3335 double high = -yscale * 0.8 / 2;
3336 double low = yscale * 0.8 / 2;
3338 // Get first auto before start
3340 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3346 ay = ((IntAuto*)current)->value > 0 ? high : low;
3351 current = autos->first ? autos->first : autos->default_auto;
3355 ay = ((IntAuto*)current)->value > 0 ? high : low;
3368 ax2 = (double)(current->position - unit_start) / zoom_units;
3369 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3377 if(ax2 > get_w()) ax2 = get_w();
3379 if(current && !result)
3381 if(current != autos->default_auto)
3385 if(track->is_armed())
3387 result = test_auto(current,
3396 auto_instance = current;
3401 (int)ax2 + x_offset,
3402 (int)ay2 + y_offset,
3414 if(track->is_armed() /* && buttonpress != 3 */)
3416 result = test_toggleline(autos,
3429 draw_toggleline(center_pixel + y_offset,
3437 }while(current && current->position <= unit_end && !result);
3439 if(ax < get_w() && !result)
3445 if(track->is_armed() /* && buttonpress != 3 */)
3447 result = test_toggleline(autos,
3459 draw_toggleline(center_pixel + y_offset,
3468 int TrackCanvas::do_autos(Track *track,
3475 Auto * &auto_instance,
3489 calculate_viewport(track,
3502 for(current = autos->first; current && !result; current = NEXT)
3504 if(current->position >= unit_start && current->position < unit_end)
3507 x = (int64_t)((double)(current->position - unit_start) /
3508 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3509 y = center_pixel - pixmap->get_h() / 2;
3513 if(cursor_x >= x && cursor_y >= y &&
3514 cursor_x < x + pixmap->get_w() &&
3515 cursor_y < y + pixmap->get_h())
3518 auto_instance = current;
3520 if(buttonpress && (buttonpress != 3))
3522 mwindow->session->drag_auto = current;
3523 mwindow->session->drag_start_position = current->position;
3524 mwindow->session->drag_origin_x = cursor_x;
3525 mwindow->session->drag_origin_y = cursor_y;
3527 double position = autos->track->from_units(current->position);
3528 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3529 mwindow->edl->local_session->get_selectionend(1)) /
3534 mwindow->edl->local_session->set_selectionstart(position);
3535 mwindow->edl->local_session->set_selectionend(position);
3538 if(position < center)
3540 mwindow->edl->local_session->set_selectionstart(position);
3543 mwindow->edl->local_session->set_selectionend(position);
3550 draw_pixmap(pixmap, x, y);
3558 // so this means it is always >0 when keyframe is found
3559 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3560 int draw, int buttonpress, Plugin* &keyframe_plugin,
3561 KeyFrame* &keyframe_instance)
3574 if(!track->expand_view) return 0;
3576 calculate_viewport(track,
3588 for(int i = 0; i < track->plugin_set.total && !result; i++)
3590 PluginSet *plugin_set = track->plugin_set.values[i];
3591 int center_pixel = track->y_pixel -
3592 mwindow->edl->local_session->track_start[pane->number];
3593 if( track->show_titles() )
3594 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
3595 if( track->show_assets() )
3596 center_pixel += track->data_h;
3597 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
3599 for(Plugin *plugin = (Plugin*)plugin_set->first;
3601 plugin = (Plugin*)plugin->next)
3603 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3604 keyframe && !result;
3605 keyframe = (KeyFrame*)keyframe->next)
3607 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3608 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3610 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3611 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3613 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3616 if(cursor_x >= x && cursor_y >= y &&
3617 cursor_x < x + keyframe_pixmap->get_w() &&
3618 cursor_y < y + keyframe_pixmap->get_h())
3621 keyframe_plugin = plugin;
3622 keyframe_instance = keyframe;
3626 mwindow->session->drag_auto = keyframe;
3627 mwindow->session->drag_start_position = keyframe->position;
3628 mwindow->session->drag_origin_x = cursor_x;
3629 mwindow->session->drag_origin_y = cursor_y;
3631 double position = track->from_units(keyframe->position);
3632 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3633 mwindow->edl->local_session->get_selectionend(1)) /
3638 mwindow->edl->local_session->set_selectionstart(position);
3639 mwindow->edl->local_session->set_selectionend(position);
3642 if(position < center)
3644 mwindow->edl->local_session->set_selectionstart(position);
3647 mwindow->edl->local_session->set_selectionend(position);
3652 draw_pixmap(keyframe_pixmap,
3662 // if(buttonpress && buttonpress != 3 && result)
3664 // mwindow->undo->update_undo_before();
3670 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
3672 Track *track = auto_keyframe->autos->track;
3673 int autogrouptype = auto_keyframe->autos->autogrouptype;
3676 double view_start, unit_start;
3677 double view_end, unit_end, yscale;
3678 double zoom_sample, zoom_units;
3680 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3681 yscale, center_pixel, zoom_sample, zoom_units);
3682 if( auto_keyframe->position < unit_start ||
3683 auto_keyframe->position >= unit_end )
3686 double ax = 0, ay = 0;
3687 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3688 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3691 draw_line(ax, 0, ax, get_h());
3693 char text[BCSTRLEN];
3695 if( auto_keyframe->is_floatauto() ) {
3696 FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
3697 sprintf(text, "%0.2f", float_auto->get_value());
3699 else if( auto_keyframe->is_intauto() ) {
3700 IntAuto *int_auto = (IntAuto *)auto_keyframe;
3701 sprintf(text, "%d", int_auto->value);
3707 int font = MEDIUMFONT;
3708 int tw = get_text_width(font, text) + xS(TOOLTIP_MARGIN) * 2;
3709 int th = get_text_height(font, text) + yS(TOOLTIP_MARGIN) * 2;
3710 set_color(get_resources()->tooltip_bg_color);
3712 ay += center_pixel + HANDLE_W/2;
3713 draw_box(ax, ay, tw, th);
3715 draw_rectangle(ax, ay, tw, th);
3717 ax += xS(TOOLTIP_MARGIN);
3718 ay += yS(TOOLTIP_MARGIN) + get_text_ascent(font);
3719 draw_text(ax, ay, text);
3724 void TrackCanvas::draw_overlays()
3726 int new_cursor, update_cursor, rerender;
3728 // Move background pixmap to foreground pixmap
3729 draw_pixmap(background_pixmap, 0, 0, get_w(), get_h(), 0, 0);
3732 draw_inout_points();
3743 draw_brender_range();
3745 // Highlighted areas
3746 draw_highlighting();
3749 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3752 if(pane->cursor) pane->cursor->restore(1);
3758 draw_playback_cursor();
3760 draw_keyframe_reticle();
3765 int TrackCanvas::activate()
3769 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3770 //BC_Signals::dump_stack();
3771 get_top_level()->deactivate();
3773 set_active_subwindow(this);
3774 pane->cursor->activate();
3775 gui->focused_pane = pane->number;
3780 int TrackCanvas::deactivate()
3785 pane->cursor->deactivate();
3791 void TrackCanvas::update_drag_handle()
3793 double new_position;
3794 int cursor_x = get_cursor_x();
3798 mwindow->edl->local_session->view_start[pane->number]) *
3799 mwindow->edl->local_session->zoom_sample /
3800 mwindow->edl->session->sample_rate;
3803 mwindow->edl->align_to_frame(new_position, 0);
3805 if( ctrl_down() && alt_down() ) {
3806 #define snapper(v) do { \
3808 if( pos < 0 ) break; \
3809 double dist = fabs(new_position - pos); \
3810 if( dist >= snap_min ) break; \
3811 snap_position = pos; snap_min = dist; \
3813 double snap_position = new_position;
3814 double snap_min = DBL_MAX;
3815 if( mwindow->edl->local_session->inpoint_valid() )
3816 snapper(mwindow->edl->local_session->get_inpoint());
3817 if( mwindow->edl->local_session->outpoint_valid() )
3818 snapper(mwindow->edl->local_session->get_outpoint());
3819 snapper(mwindow->edl->prev_edit(new_position));
3820 snapper(mwindow->edl->next_edit(new_position));
3821 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3822 if( prev_label ) snapper(prev_label->position);
3823 Label *next_label = mwindow->edl->labels->next_label(new_position);
3824 if( next_label ) snapper(next_label->position);
3825 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3826 mwindow->edl->local_session->zoom_sample -
3827 mwindow->edl->local_session->view_start[pane->number];
3828 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3830 new_position = snap_position;
3835 if(new_position != mwindow->session->drag_position)
3837 mwindow->session->drag_position = new_position;
3838 gui->mainclock->update(new_position);
3839 timebar_position = new_position;
3840 gui->update_timebar(0);
3843 edl->create_objects();
3844 edl->copy_all(mwindow->edl);
3845 MainSession *session = mwindow->session;
3846 int handle_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
3847 edl->modify_edithandles(session->drag_start,
3848 session->drag_position, session->drag_handle, handle_mode,
3849 edl->session->labels_follow_edits,
3850 edl->session->plugins_follow_edits,
3851 edl->session->autos_follow_edits,
3852 !session->drag_edit ? 0 : session->drag_edit->group_id);
3854 double position = -1;
3855 int show_edge = !session->drag_handle ? 1 : 2;
3856 switch( handle_mode ) {
3859 position = session->drag_handle ?
3860 session->drag_position : session->drag_start;
3861 show_edge = 3 - show_edge;
3865 position = session->drag_position;
3868 position = session->drag_start;
3869 show_edge = 3 - show_edge;
3873 if( position < 0 ) position = 0;
3874 Track *track = session->drag_handle_track();
3875 int64_t pos = track->to_units(position, 0);
3876 render_handle_frame(edl, pos, shift_down() ? 0 : show_edge);
3881 int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
3884 int64_t left = pos-1;
3885 if( left < 0 ) left = 0;
3888 VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
3889 VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
3890 TransportCommand command;
3891 command.command = CURRENT_FRAME;
3892 command.get_edl()->copy_all((EDL *)edl);
3893 command.change_type = CHANGE_ALL;
3894 command.realtime = 0;
3895 Preferences *preferences = mwindow->preferences;
3896 RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
3897 CICache *video_cache = new CICache(preferences);
3898 render_engine->set_vcache(video_cache);
3899 render_engine->arm_command(&command);
3900 VRender *vrender = render_engine->vrender;
3902 !vrender->process_buffer(&vlt, left, 0) &&
3903 !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1;
3904 delete render_engine;
3906 mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0");
3907 Canvas *canvas = mwindow->cwindow->gui->canvas;
3908 float ox1, oy1, ox2, oy2, cx1, cy1, cx2, cy2;
3909 canvas->get_transfers(edl, ox1, oy1, ox2, oy2, cx1, cy1, cx2, cy2);
3910 float cw = canvas->w/2, ch = canvas->h/2;
3911 float cdx = (cx2 - cx1)/2, cdy = (cy2 - cy1)/2;
3912 int cx = cx1/2, cy = cy1/2 + ch/2;
3913 int ow = ox2 - ox2, oh = oy2 - oy1;
3914 BC_WindowBase *window = canvas->get_canvas();
3915 window->set_color(BLACK);
3916 window->clear_box(0,0, window->get_w(),window->get_h());
3917 window->draw_vframe(&vlt, cx,cy, cdx,cdy, ox1,oy1, ow,oh); cx += cw;
3918 window->draw_vframe(&vrt, cx,cy, cdx,cdy, ox1,oy1, ow,oh);
3920 mwindow->cwindow->gui->unlock_window();
3924 Track *track = mwindow->session->drag_handle_track();
3925 double position = track->from_units(mode == 1 ? left : pos);
3926 if( position < 0 ) position = 0;
3927 PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine;
3928 if( playback_engine->is_playing_back )
3929 playback_engine->stop_playback(1);
3930 edl->local_session->set_selectionstart(position);
3931 edl->local_session->set_selectionend(position);
3932 mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
3938 int TrackCanvas::update_drag_edit()
3947 int TrackCanvas::get_drag_values(float *percentage,
3954 //int x = cursor_x - mwindow->session->drag_origin_x;
3955 //int y = cursor_y - mwindow->session->drag_origin_y;
3959 if(!current->autos->track->is_armed()) return 1;
3969 calculate_viewport(current->autos->track,
3979 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3981 mwindow->session->drag_start_percentage;
3982 if(do_clamp) CLAMP(*percentage, 0, 1);
3984 *position = Units::to_int64(zoom_units *
3985 (cursor_x - mwindow->session->drag_origin_x) +
3986 mwindow->session->drag_start_position + 0.5);
3988 if((do_clamp) && *position < 0) *position = 0;
3993 #define UPDATE_DRAG_HEAD(do_clamp) \
3994 int result = 0, center_pixel; \
3995 if(!current->autos->track->is_armed()) return 0; \
3996 double view_start, unit_start, view_end, unit_end; \
3997 double yscale, zoom_sample, zoom_units; \
3999 calculate_viewport(current->autos->track, \
4000 view_start, unit_start, view_end, unit_end, \
4001 yscale, center_pixel, zoom_sample, zoom_units); \
4003 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
4004 yscale + mwindow->session->drag_start_percentage; \
4005 if(do_clamp) CLAMP(percentage, 0, 1); \
4007 int64_t position = Units::to_int64(zoom_units * \
4008 (cursor_x - mwindow->session->drag_origin_x) + \
4009 mwindow->session->drag_start_position); \
4010 if((do_clamp) && position < 0) position = 0;
4013 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
4015 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
4017 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
4018 int x = cursor_x - mwindow->session->drag_origin_x;
4019 int y = cursor_y - mwindow->session->drag_origin_y;
4020 float value, old_value;
4022 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
4023 // not really editing the node, rather start editing the curve
4024 // tangent is editable and drag movement is significant
4025 if( (FloatAuto::FREE == current->curve_mode ||
4026 FloatAuto::TFREE==current->curve_mode) &&
4027 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
4028 mwindow->session->drag_handle = x < 0 ? 1 : 2;
4031 switch(mwindow->session->drag_handle) {
4033 // Snap to nearby values
4034 old_value = current->get_value();
4036 double value1, value2, distance1=-1, distance2=-1;
4038 if(current->previous) {
4039 int autogrouptype = current->previous->autos->autogrouptype;
4040 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4041 value1 = ((FloatAuto*)current->previous)->get_value();
4042 distance1 = fabs(value - value1);
4043 current->set_value(value1);
4047 int autogrouptype = current->next->autos->autogrouptype;
4048 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4049 value2 = ((FloatAuto*)current->next)->get_value();
4050 distance2 = fabs(value - value2);
4051 if(!current->previous || distance2 < distance1) {
4052 current->set_value(value2);
4056 if(!current->previous && !current->next) {
4057 current->set_value( ((FloatAutos*)current->autos)->default_);
4059 value = current->get_value();
4062 int autogrouptype = current->autos->autogrouptype;
4063 value = percentage_to_value(percentage, 0, 0, autogrouptype);
4066 if(alt_down() && !shift_down())
4067 // ALT constrains movement: fixed position, only changing the value
4068 position = mwindow->session->drag_start_position;
4070 if(value != old_value || position != current->position) {
4072 float change = value - old_value;
4073 current->adjust_to_new_coordinates(position, value);
4074 update_ganged_autos(change, current->autos->track, current);
4075 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4076 show_message(current, color, ", %.2f", current->get_value());
4082 int autogrouptype = current->autos->autogrouptype;
4083 value = percentage_to_value(percentage, 0, current, autogrouptype);
4084 if(value != current->get_control_in_value())
4087 // note: (position,value) need not be at the location of the ctrl point,
4088 // but could be somewhere in between on the curve (or even outward or
4089 // on the opposit side). We set the new control point such as
4090 // to point the curve through (position,value)
4091 current->set_control_in_value(
4092 value * levered_position(position - current->position,
4093 current->get_control_in_position()));
4094 update_ganged_autos(0, current->autos->track, current);
4095 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4096 show_message(current, color, ", %.2f", current->get_control_in_value());
4102 int autogrouptype = current->autos->autogrouptype;
4103 value = percentage_to_value(percentage, 0, current, autogrouptype);
4104 if(value != current->get_control_out_value()) {
4106 current->set_control_out_value(
4107 value * levered_position(position - current->position,
4108 current->get_control_out_position()));
4109 update_ganged_autos(0, current->autos->track, current);
4110 int color = GWindowGUI::auto_colors[current->autos->autoidx];
4111 show_message(current, color, ", %.2f", current->get_control_out_value());
4119 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
4121 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
4123 UPDATE_DRAG_HEAD(1);
4124 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
4126 if(value != current->value || position != current->position)
4129 current->value = value;
4130 current->position = position;
4131 show_message(current, -1, ", %d", current->value);
4137 // Autos which can't change value through dragging.
4139 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
4141 Auto *current = (Auto*)mwindow->session->drag_auto;
4144 if(position != current->position)
4147 current->position = position;
4148 show_message(current, -1, "");
4150 double position_f = current->autos->track->from_units(current->position);
4151 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4152 mwindow->edl->local_session->get_selectionend(1)) /
4156 mwindow->edl->local_session->set_selectionstart(position_f);
4157 mwindow->edl->local_session->set_selectionend(position_f);
4160 if(position_f < center_f)
4162 mwindow->edl->local_session->set_selectionstart(position_f);
4165 mwindow->edl->local_session->set_selectionend(position_f);
4172 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
4174 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
4177 if(position != current->position)
4179 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
4180 Track *track = current->autos->track;
4181 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
4182 PluginSet *pluginset;
4184 // figure out the correct pluginset & correct plugin
4186 for(int i = 0; i < track->plugin_set.total; i++)
4188 pluginset = track->plugin_set.values[i];
4189 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
4191 KeyFrames *keyframes = plugin->keyframes;
4192 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
4194 currentkeyframe = (KeyFrame *) currentkeyframe->next)
4196 if (currentkeyframe == current)
4208 mwindow->session->plugin_highlighted = plugin;
4209 mwindow->session->track_highlighted = track;
4211 current->position = position;
4212 show_message(current, -1, "");
4214 double position_f = current->autos->track->from_units(current->position);
4215 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
4216 mwindow->edl->local_session->get_selectionend(1)) /
4220 mwindow->edl->local_session->set_selectionstart(position_f);
4221 mwindow->edl->local_session->set_selectionend(position_f);
4224 if(position_f < center_f)
4226 mwindow->edl->local_session->set_selectionstart(position_f);
4229 mwindow->edl->local_session->set_selectionend(position_f);
4236 void TrackCanvas::update_drag_caption()
4238 switch(mwindow->session->current_operation)
4248 int TrackCanvas::cursor_update(int in_motion)
4253 int update_clock = 0;
4254 int update_zoom = 0;
4255 int update_scroll = 0;
4256 int update_overlay = 0;
4257 int update_cursor = 0;
4259 double position = 0.;
4260 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4264 arrow_mode() ? ARROW_CURSOR :
4265 ibeam_mode() ? IBEAM_CURSOR : 0;
4267 switch(mwindow->session->current_operation)
4269 case DRAG_EDITHANDLE1:
4270 // Outside threshold. Upgrade status
4273 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4275 mwindow->session->current_operation = DRAG_EDITHANDLE2;
4281 case DRAG_EDITHANDLE2:
4284 update_drag_handle();
4289 case DRAG_PLUGINHANDLE1:
4292 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4294 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
4300 case DRAG_PLUGINHANDLE2:
4303 update_drag_handle();
4308 // Rubber band curves
4316 case DRAG_PROJECTOR_X:
4317 case DRAG_PROJECTOR_Y:
4318 case DRAG_PROJECTOR_Z:
4319 if(active) rerender = update_overlay =
4320 update_drag_floatauto(get_cursor_x(), get_cursor_y());
4321 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
4322 mwindow->speed_after(!in_motion ? 1 : 0);
4326 if(active) rerender = update_overlay =
4327 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4331 if(active) rerender = update_overlay =
4332 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4335 // Keyframe icons are sticky
4339 case DRAG_PLUGINKEY_PRE:
4341 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
4342 mwindow->session->current_operation++;
4345 mwindow->undo->update_undo_before();
4353 if(active) rerender = update_overlay =
4354 update_drag_auto(get_cursor_x(), get_cursor_y());
4357 case DRAG_PLUGINKEY:
4358 if(active) rerender = update_overlay =
4359 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4364 cursor_x = get_cursor_x();
4365 cursor_y = get_cursor_y();
4366 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4367 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4369 position = mwindow->edl->align_to_frame(position, 0);
4370 position = MAX(position, 0);
4372 double start = mwindow->edl->local_session->get_selectionstart(1);
4373 double end = mwindow->edl->local_session->get_selectionend(1);
4374 if(position < selection_midpoint) {
4375 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4376 mwindow->edl->local_session->set_selectionstart(position);
4379 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4380 mwindow->edl->local_session->set_selectionend(position);
4383 gui->unlock_window();
4385 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
4386 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
4387 mwindow->cwindow->update(dir, 0, 0, 0, 1);
4388 gui->lock_window("TrackCanvas::cursor_update 1");
4389 // Update the faders
4390 mwindow->update_plugin_guis();
4391 gui->update_patchbay();
4393 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4395 gui->hide_cursor(0);
4396 gui->draw_cursor(1);
4397 gui->update_timebar(0);
4398 gui->flash_canvas(1);
4406 case DROP_TARGETING:
4407 new_cursor = GRABBED_CURSOR;
4412 if(is_event_win() && cursor_inside()) {
4414 cursor_x = get_cursor_x();
4415 position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4416 position = mwindow->edl->align_to_frame(position, 0);
4419 for(int i = 0; i < TOTAL_PANES; i++)
4420 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4422 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4423 gui->update_timebar(0);
4425 if(do_transitions(get_cursor_x(), get_cursor_y(),
4426 0, new_cursor, update_cursor)) break;
4427 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4428 0, 0, new_cursor, update_cursor, rerender)) break;
4429 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4430 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4431 // Plugin boundaries
4432 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4433 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4434 if(do_edits(get_cursor_x(), get_cursor_y(),
4435 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4440 //printf("TrackCanvas::cursor_update 1\n");
4441 if(update_cursor && new_cursor != get_cursor())
4443 set_cursor(new_cursor, 0, 1);
4446 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
4447 if(rerender && render_timer->get_difference() > 0.25 ) {
4448 render_timer->update();
4449 mwindow->restart_brender();
4450 mwindow->sync_parameters(CHANGE_PARAMS);
4451 mwindow->update_plugin_guis();
4452 gui->unlock_window();
4453 mwindow->cwindow->update(1, 0, 0, 0, 1);
4454 gui->lock_window("TrackCanvas::cursor_update 2");
4458 gui->update_patchbay();
4463 if(!mwindow->cwindow->playback_engine->is_playing_back)
4464 gui->mainclock->update(position);
4468 gui->zoombar->update();
4473 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4477 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4481 if(update_overlay) {
4482 gui->draw_overlays(1);
4485 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4489 int TrackCanvas::cursor_motion_event()
4491 return cursor_update(1);
4494 void TrackCanvas::start_dragscroll()
4498 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4499 //printf("TrackCanvas::start_dragscroll 1\n");
4503 void TrackCanvas::stop_dragscroll()
4507 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4508 //printf("TrackCanvas::stop_dragscroll 1\n");
4512 int TrackCanvas::repeat_event(int64_t duration)
4514 if(!drag_scroll) return 0;
4515 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4517 int sample_movement = 0;
4518 int track_movement = 0;
4519 int64_t x_distance = 0;
4520 int64_t y_distance = 0;
4521 double position = 0;
4524 switch(mwindow->session->current_operation) {
4526 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4527 if(get_cursor_x() > get_w()) {
4528 x_distance = get_cursor_x() - get_w();
4529 sample_movement = 1;
4531 else if(get_cursor_x() < 0) {
4532 x_distance = get_cursor_x();
4533 sample_movement = 1;
4536 if(get_cursor_y() > get_h()) {
4537 y_distance = get_cursor_y() - get_h();
4540 else if(get_cursor_y() < 0) {
4541 y_distance = get_cursor_y();
4548 if(sample_movement) {
4549 position = (double)(get_cursor_x() +
4550 mwindow->edl->local_session->view_start[pane->number] +
4552 mwindow->edl->local_session->zoom_sample /
4553 mwindow->edl->session->sample_rate;
4554 position = mwindow->edl->align_to_frame(position, 0);
4555 position = MAX(position, 0);
4557 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4558 switch(mwindow->session->current_operation) {
4560 if(position < selection_midpoint) {
4561 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4562 mwindow->edl->local_session->set_selectionstart(position);
4564 gui->unlock_window();
4565 mwindow->cwindow->update(1, 0, 0);
4566 gui->lock_window("TrackCanvas::repeat_event");
4567 // Update the faders
4568 mwindow->update_plugin_guis();
4569 gui->update_patchbay();
4572 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4573 mwindow->edl->local_session->set_selectionend(position);
4574 // Don't que the CWindow
4579 mwindow->samplemovement(
4580 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4584 if(track_movement) {
4585 mwindow->trackmovement(y_distance, pane->number);
4591 int TrackCanvas::button_release_event()
4593 int redraw = -1, update_overlay = 0;
4594 int result = 0, load_flags = 0;
4596 // printf("TrackCanvas::button_release_event %d\n",
4597 // mwindow->session->current_operation);
4599 switch(mwindow->session->current_operation) {
4600 case DRAG_EDITHANDLE2:
4601 mwindow->session->current_operation = NO_OPERATION;
4605 end_edithandle_selection();
4608 case DRAG_EDITHANDLE1:
4609 mwindow->session->current_operation = NO_OPERATION;
4614 case DRAG_PLUGINHANDLE2:
4615 mwindow->session->current_operation = NO_OPERATION;
4619 end_pluginhandle_selection();
4622 case DRAG_PLUGINHANDLE1:
4623 mwindow->session->current_operation = NO_OPERATION;
4629 redraw = FORCE_REDRAW;
4630 load_flags |= LOAD_EDITS;
4632 // delete the drag_auto_gang first and remove out of order keys
4633 clear_ganged_autos();
4644 case DRAG_PROJECTOR_X:
4645 case DRAG_PROJECTOR_Y:
4646 case DRAG_PROJECTOR_Z:
4647 case DRAG_PLUGINKEY:
4648 load_flags |= LOAD_AUTOMATION;
4649 mwindow->session->current_operation = NO_OPERATION;
4650 mwindow->session->drag_handle = 0;
4651 // Remove any out-of-order keyframe
4652 if(mwindow->session->drag_auto) {
4653 mwindow->session->drag_auto->autos->remove_nonsequential(
4654 mwindow->session->drag_auto);
4655 // mwindow->session->drag_auto->autos->optimize();
4659 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
4665 case DRAG_AEFFECT_COPY:
4666 case DRAG_VEFFECT_COPY:
4667 // Trap in drag stop
4670 case DROP_TARGETING: {
4671 int cursor_x = get_cursor_x(), cursor_y = get_cursor_y();
4672 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4673 drag_cursor_motion(cursor_x, cursor_y,
4674 &track, &edit, &pluginset, &plugin);
4676 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4677 gui->edit_menu->activate_menu(track, edit, pluginset, plugin, position);
4678 mwindow->session->current_operation = NO_OPERATION;
4682 case GROUP_TOGGLE: {
4683 Edit *edit = mwindow->session->drag_edit;
4685 if( shift_down() && edit->is_selected ) {
4686 if( edit->group_id > 0 ) {
4687 mwindow->edl->tracks->clear_selected_edits();
4688 mwindow->edl->tracks->del_group(edit->group_id);
4691 int id = mwindow->session->group_number++;
4692 mwindow->edl->tracks->new_group(id);
4697 if( mwindow->preferences->ctrl_toggle && !ctrl_down() )
4698 mwindow->edl->tracks->clear_selected_edits();
4699 edit->set_selected(-1);
4702 mwindow->session->current_operation = NO_OPERATION;
4709 if( mwindow->session->current_operation ) {
4710 // if(mwindow->session->current_operation == SELECT_REGION) {
4711 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4714 mwindow->session->current_operation = NO_OPERATION;
4723 if( mwindow->edl->local_session->zoombar_showautocolor >= 0 )
4724 mwindow->gui->zoombar->update_autozoom(-1);
4729 if(update_overlay) {
4730 gui->draw_overlays(1);
4733 gui->draw_canvas(redraw, 0);
4734 gui->flash_canvas(1);
4739 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4740 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4742 Edit *edit_result = 0;
4743 int handle_result = -1;
4746 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4747 if( track->is_hidden() ) continue;
4748 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4749 int64_t edit_x, edit_y, edit_w, edit_h;
4750 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4752 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4753 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4754 if( cursor_x < edit_x + HANDLE_W ) {
4757 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4758 track->show_assets() ) {
4759 new_cursor = DOWNLEFT_RESIZE;
4760 if( button_press == LEFT_BUTTON )
4766 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4769 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4770 track->show_assets() ) {
4771 new_cursor = DOWNRIGHT_RESIZE;
4772 if( button_press == LEFT_BUTTON )
4783 int group_id = edit_result->group_id;
4784 if( group_id > 0 ) {
4785 Track *track = edit_result->track;
4786 Edit *left = 0, *right = 0;
4787 double start = DBL_MAX, end = DBL_MIN;
4788 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
4789 if( edit->group_id != group_id ) continue;
4790 double edit_start = edit->track->from_units(edit->startproject);
4791 if( edit_start < start ) { start = edit_start; left = edit; }
4792 double edit_end = edit->track->from_units(edit->startproject+edit->length);
4793 if( edit_end > end ) { end = edit_end; right = edit; }
4795 Edit *edit = !handle_result ? left : right;
4796 if( edit != edit_result )
4803 double position = 0;
4804 if( handle_result == 0 ) {
4805 position = edit_result->track->from_units(edit_result->startproject);
4806 new_cursor = LEFT_CURSOR;
4808 else if( handle_result == 1 ) {
4809 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4810 new_cursor = RIGHT_CURSOR;
4813 // Reposition cursor
4814 if( button_press ) {
4815 mwindow->session->drag_edit = edit_result;
4816 mwindow->session->drag_handle = handle_result;
4817 mwindow->session->drag_button = get_buttonpress() - 1;
4818 mwindow->session->drag_position = position;
4819 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4820 mwindow->session->drag_origin_x = get_cursor_x();
4821 mwindow->session->drag_origin_y = get_cursor_y();
4822 mwindow->session->drag_start = position;
4824 rerender = start_selection(position);
4828 else if( result < 0 && !edit_result->silence() ) {
4829 mwindow->undo->update_undo_before();
4830 if( !shift_down() ) {
4831 if( handle_result == 0 )
4832 edit_result->hard_left = !edit_result->hard_left;
4833 else if( handle_result == 1 )
4834 edit_result->hard_right = !edit_result->hard_right;
4837 int status = handle_result == 0 ? edit_result->hard_left :
4838 handle_result == 1 ? edit_result->hard_right : 0;
4839 int new_status = !status;
4840 int64_t edit_edge = edit_result->startproject;
4841 if( handle_result == 1 ) edit_edge += edit_result->length;
4842 double edge_position = edit_result->track->from_units(edit_edge);
4843 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4844 if( track->is_hidden() ) continue;
4845 int64_t track_position = track->to_units(edge_position, 1);
4846 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4848 int64_t left_edge = left_edit->startproject;
4849 double left_position = track->from_units(left_edge);
4850 if( EQUIV(edge_position, left_position) ) {
4851 left_edit->hard_left = new_status;
4852 if( left_edit->previous )
4853 left_edit->previous->hard_right = new_status;
4856 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4858 int64_t right_edge = right_edit->startproject + right_edit->length;
4859 double right_position = track->from_units(right_edge);
4860 if( EQUIV(edge_position, right_position) ) {
4861 right_edit->hard_right = new_status;
4862 if( right_edit->next )
4863 right_edit->next->hard_left = new_status;
4868 rerender = update_overlay = 1;
4869 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4876 int TrackCanvas::do_plugin_handles(int cursor_x,
4880 int &update_overlay,
4884 Plugin *plugin_result = 0;
4885 int handle_result = 0;
4888 for(Track *track = mwindow->edl->tracks->first;
4890 track = track->next) {
4891 if( track->is_hidden() ) continue;
4892 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4893 PluginSet *plugin_set = track->plugin_set.values[i];
4894 for(Plugin *plugin = (Plugin*)plugin_set->first;
4896 plugin = (Plugin*)plugin->next) {
4897 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4898 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4900 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4901 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4902 if(cursor_x < plugin_x + HANDLE_W) {
4903 plugin_result = plugin;
4907 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4908 plugin_result = plugin;
4915 if(result && shift_down())
4916 mwindow->session->trim_edits = plugin_set;
4922 double position = 0;
4923 if(handle_result == 0) {
4924 position = plugin_result->track->from_units(plugin_result->startproject);
4925 new_cursor = LEFT_CURSOR;
4927 else if(handle_result == 1) {
4928 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4929 new_cursor = RIGHT_CURSOR;
4933 mwindow->session->drag_plugin = plugin_result;
4934 mwindow->session->drag_handle = handle_result;
4935 mwindow->session->drag_button = get_buttonpress() - 1;
4936 mwindow->session->drag_position = position;
4937 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4938 mwindow->session->drag_origin_x = get_cursor_x();
4939 mwindow->session->drag_origin_y = get_cursor_y();
4940 mwindow->session->drag_start = position;
4942 rerender = start_selection(position);
4951 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4955 Track *track=0; Edit *edit=0; PluginSet *pluginset=0; Plugin *plugin=0;
4956 drag_cursor_motion(cursor_x, cursor_y,
4957 &track, &edit, &pluginset, &plugin);
4959 if( button_press && track ) {
4960 switch( get_buttonpress() ) {
4961 case RIGHT_BUTTON: {
4963 mwindow->edl->get_cursor_position(cursor_x, pane->number);
4964 gui->track_menu->activate_menu(track, edit, pluginset, plugin, position);
4965 mwindow->session->current_operation = NO_OPERATION;
4969 set_cursor(GRABBED_CURSOR, 0, 1);
4970 mwindow->session->current_operation = DROP_TARGETING;
4979 int TrackCanvas::arrow_mode()
4981 return mwindow->edl->session->editing_mode == EDITING_ARROW ? 1 : 0;
4983 int TrackCanvas::ibeam_mode()
4985 return mwindow->edl->session->editing_mode == EDITING_IBEAM ? 1 : 0;
4988 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4989 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4993 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4994 if( track->is_hidden() ) continue;
4995 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4996 int64_t edit_x, edit_y, edit_w, edit_h;
4997 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4999 // Cursor inside a track
5000 // Cursor inside an edit
5001 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
5002 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
5003 if( button_press && get_buttonpress() == LEFT_BUTTON ) {
5004 if( get_double_click() ) {
5005 mwindow->edl->tracks->clear_selected_edits();
5006 edit->select_affected_edits(1, -1);
5007 double start = edit->track->from_units(edit->startproject);
5008 start = mwindow->edl->align_to_frame(start, 0);
5009 mwindow->edl->local_session->set_selectionstart(start);
5010 double end = edit->track->from_units(edit->startproject+edit->length);
5011 end = mwindow->edl->align_to_frame(end, 0);
5012 mwindow->edl->local_session->set_selectionend(end);
5013 result = 1; // Select edit duration or select_region
5015 else if( arrow_mode() || (ibeam_mode() && ctrl_down()) ) {
5016 mwindow->session->drag_edit = edit;
5017 mwindow->session->current_operation = GROUP_TOGGLE;
5025 else if( drag_start && track->is_armed() ) {
5026 mwindow->session->drag_edit = edit;
5027 mwindow->session->drag_origin_x = cursor_x;
5028 mwindow->session->drag_origin_y = cursor_y;
5029 // Where the drag started, so we know relative position inside the edit later
5030 mwindow->session->drag_position =
5031 mwindow->edl->get_cursor_position(cursor_x, pane->number);
5032 drag_start = 0; // if unselected "fast" drag
5033 if( !edit->silence() && !edit->is_selected ) {
5034 mwindow->edl->tracks->clear_selected_edits();
5035 if( ibeam_mode() ) {
5036 double start = edit->track->from_units(edit->startproject);
5037 mwindow->edl->local_session->set_selectionstart(start);
5038 mwindow->edl->local_session->set_selectionend(start);
5039 edit->set_selected(1);
5042 edit->select_affected_edits(1, -1);
5045 // Construct list of all affected edits
5046 if( drag_start || ibeam_mode() ) {
5047 mwindow->edl->tracks->get_selected_edits(mwindow->session->drag_edits);
5048 if( mwindow->session->drag_edits->size() > 0 ) {
5049 mwindow->session->current_operation = DRAG_EDIT;
5050 // Need to create drag window
5051 int cx, cy; get_abs_cursor(cx, cy);
5052 gui->drag_popup = new BC_DragWindow(gui,
5053 mwindow->theme->get_image("clip_icon"), cx, cy);
5057 rerender = start_selection(mwindow->session->drag_position);
5058 mwindow->session->current_operation = SELECT_REGION;
5062 else if( edit->is_selected && arrow_mode() ) {
5063 if( mwindow->session->drag_group )
5064 mwindow->session->drag_group->remove_user();
5065 double start_position = 0;
5066 mwindow->session->drag_group =
5067 mwindow->edl->selected_edits_to_clip(0, &start_position,
5068 &mwindow->session->drag_group_first_track);
5069 if( mwindow->session->drag_group ) {
5070 mwindow->session->current_operation = DRAG_GROUP;
5071 mwindow->session->drag_group_position = start_position;
5072 mwindow->session->drag_group_edit = edit;
5073 mwindow->session->drag_origin_y = edit_y;
5084 // returns -1=doesnt fit, 1=fits, 0=fits but overwrites
5085 int TrackCanvas::test_track_group(EDL *group, Track *first_track, double &pos)
5088 Track *src = group->tracks->first;
5089 for( Track *track=first_track; track && src; track=track->next ) {
5090 if( !track->is_armed() ) return -1;
5091 if( src->data_type != track->data_type ) return -1;
5092 for( Edit *src_edit=src->edits->first; src_edit; src_edit=src_edit->next ) {
5093 if( src_edit->silence() ) continue;
5094 if( !intersects && edit_intersects(track, src_edit, pos) )
5099 return src ? -1 : !intersects ? 1 : 0;
5102 int TrackCanvas::edit_intersects(Track *track, Edit *src_edit, double &pos)
5104 if( pos < 0 ) { pos = 0; return 1; }
5105 int pane_no = pane->number;
5106 int cur_pix = track->edl->get_position_cursorx(pos, pane_no);
5107 int64_t src_start = src_edit->startproject;
5108 int64_t src_end = src_start + src_edit->length;
5109 double new_start = src_edit->track->from_units(src_start) + pos;
5110 double new_end = src_edit->track->from_units(src_end) + pos;
5111 int64_t trk_start = track->to_units(new_start, 1);
5112 int64_t trk_end = track->to_units(new_end, 1);
5113 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
5114 if( edit->is_selected || edit->silence() ) continue;
5115 int64_t edit_start = edit->startproject;
5116 if( edit_start >= trk_end ) continue;
5117 int64_t edit_end = edit_start + edit->length;
5118 if( trk_start >= edit_end ) continue;
5120 int64_t lt_dist = labs(trk_end - edit_start);
5121 int64_t rt_dist = labs(edit_end - trk_start);
5123 if( lt_dist < rt_dist ) {
5124 position = edit_start;
5125 lt_dist = abs(trk_start - edit_start);
5126 rt_dist = abs(trk_end - edit_start);
5127 if( lt_dist > rt_dist )
5128 position -= src_end;
5131 position = edit_end;
5132 lt_dist = abs(trk_start - edit_end);
5133 rt_dist = abs(trk_end - edit_end);
5134 if( lt_dist > rt_dist )
5135 position -= src_end;
5137 double new_pos = edit->track->from_units(position);
5138 int new_pix = track->edl->get_position_cursorx(new_pos, pane_no);
5139 if( abs(new_pix-cur_pix) < HANDLE_W )
5146 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
5151 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
5152 int button_press, int &redraw, int &rerender)
5160 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
5161 if(!track->expand_view) continue;
5163 for(int i = 0; i < track->plugin_set.total && !done; i++) {
5164 // first check if plugins are visible at all
5165 if (!track->expand_view)
5167 PluginSet *plugin_set = track->plugin_set.values[i];
5168 for(plugin = (Plugin*)plugin_set->first;
5170 plugin = (Plugin*)plugin->next) {
5171 plugin_dimensions(plugin, x, y, w, h);
5172 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
5173 MWindowGUI::visible(y, y + h, 0, get_h())) {
5174 if(cursor_x >= x && cursor_x < x + w &&
5175 cursor_y >= y && cursor_y < y + h) {
5185 // Start plugin popup
5187 if(get_buttonpress() == RIGHT_BUTTON ) {
5188 gui->plugin_menu->update(plugin);
5189 gui->plugin_menu->activate_menu();
5192 else if (get_double_click() && !drag_start) {
5193 // Select range of plugin on doubleclick over plugin
5194 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
5195 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
5196 plugin->track->from_units(plugin->length));
5197 if(mwindow->edl->session->cursor_on_frames) {
5198 mwindow->edl->local_session->set_selectionstart(
5199 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
5200 mwindow->edl->local_session->set_selectionend(
5201 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
5210 if( drag_start && plugin->track->is_armed() && !plugin->silence() ) {
5211 if( mwindow->edl->session->editing_mode == EDITING_ARROW ) {
5212 if( plugin->track->data_type == TRACK_AUDIO )
5213 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
5214 else if( plugin->track->data_type == TRACK_VIDEO )
5215 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
5217 mwindow->session->drag_plugin = plugin;
5218 mwindow->session->drag_origin_x = cursor_x;
5219 mwindow->session->drag_origin_y = cursor_y;
5220 // Where the drag started, so we know relative position inside the edit later
5221 mwindow->session->drag_position =
5222 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
5223 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
5225 switch(plugin->plugin_type) {
5226 case PLUGIN_STANDALONE: {
5227 PluginServer *server =
5228 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
5229 if( !server ) break;
5230 VFrame *frame = server->picon;
5232 if(plugin->track->data_type == TRACK_AUDIO) {
5233 frame = mwindow->theme->get_image("aeffect_icon");
5236 frame = mwindow->theme->get_image("veffect_icon");
5240 get_abs_cursor(cx, cy);
5241 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
5244 case PLUGIN_SHAREDPLUGIN:
5245 case PLUGIN_SHAREDMODULE: {
5246 VFrame *frame = mwindow->theme->get_image("clip_icon");
5248 get_abs_cursor(cx, cy);
5249 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
5261 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
5262 int button_press, int &new_cursor, int &update_cursor)
5264 Transition *transition = 0;
5269 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
5270 if( track->is_hidden() ) continue;
5271 if( !track->show_transitions() ) continue;
5273 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
5274 if( edit->transition ) {
5275 edit_dimensions(edit, x, y, w, h);
5276 get_transition_coords(edit, x, y, w, h);
5278 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
5279 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
5280 if( cursor_x >= x && cursor_x < x + w &&
5281 cursor_y >= y && cursor_y < y + h ) {
5282 transition = edit->transition;
5294 new_cursor = UPRIGHT_ARROW_CURSOR;
5296 else if(get_buttonpress() == RIGHT_BUTTON ) {
5297 gui->transition_menu->update(transition);
5298 gui->transition_menu->activate_menu();
5305 int TrackCanvas::button_press_event()
5308 int cursor_x, cursor_y;
5311 cursor_x = get_cursor_x();
5312 cursor_y = get_cursor_y();
5313 mwindow->session->trim_edits = 0;
5315 if(is_event_win() && cursor_inside()) {
5316 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5323 if( get_buttonpress() == LEFT_BUTTON ) {
5324 gui->stop_transport("TrackCanvas::button_press_event");
5327 int update_overlay = 0, update_cursor = 0, rerender = 0, update_message = 0;
5329 if(get_buttonpress() == WHEEL_UP) {
5331 mwindow->expand_sample();
5332 else if(ctrl_down())
5333 mwindow->move_left(get_w()/ 10);
5335 mwindow->move_up(get_h() / 10);
5337 else if(get_buttonpress() == WHEEL_DOWN) {
5339 mwindow->zoom_in_sample();
5340 else if(ctrl_down())
5341 mwindow->move_right(get_w() / 10);
5343 mwindow->move_down(get_h() / 10);
5345 else if(get_buttonpress() == 6) {
5347 mwindow->move_left(get_w());
5349 mwindow->move_left(get_w() / 20);
5351 mwindow->move_left(get_w() / 5);
5353 else if(get_buttonpress() == 7) {
5355 mwindow->move_right(get_w());
5357 mwindow->move_right(get_w() / 20);
5359 mwindow->move_right(get_w() / 5);
5362 if( arrow_mode() ) do {
5363 // Test handles and resource boundaries and highlight a track
5364 if( do_transitions(cursor_x, cursor_y,
5365 1, new_cursor, update_cursor) ) break;
5367 if( do_keyframes(cursor_x, cursor_y,
5368 0, get_buttonpress(), new_cursor,
5369 update_cursor, rerender) ) break;
5371 // Test edit boundaries
5372 if( do_edit_handles(cursor_x, cursor_y,
5373 1, rerender, update_overlay, new_cursor,
5374 update_cursor) ) break;
5375 // Test plugin boundaries
5376 if( do_plugin_handles(cursor_x, cursor_y,
5377 1, rerender, update_overlay, new_cursor,
5378 update_cursor) ) break;
5380 if( do_edits(cursor_x, cursor_y, 1, 0,
5381 update_overlay, rerender, new_cursor,
5382 update_cursor) ) break;
5384 if( do_plugins(cursor_x, cursor_y, 0, 1,
5385 update_cursor, rerender) ) break;
5387 if( test_resources(cursor_x, cursor_y) ) break;
5389 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5393 else if( ibeam_mode() ) do {
5394 // Test handles only and select a region
5395 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5396 //printf("TrackCanvas::button_press_event %d\n", position);
5398 if( do_transitions(cursor_x, cursor_y,
5399 1, new_cursor, update_cursor)) break;
5400 if(do_keyframes(cursor_x, cursor_y,
5401 0, get_buttonpress(), new_cursor,
5402 update_cursor, rerender)) {
5407 // Test edit boundaries
5408 if( do_edit_handles(cursor_x, cursor_y,
5409 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5410 // Test plugin boundaries
5411 if( do_plugin_handles(cursor_x, cursor_y,
5412 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5414 if( do_edits(cursor_x, cursor_y,
5415 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
5417 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
5419 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5420 // Highlight selection
5421 if( get_buttonpress() != LEFT_BUTTON ) break;
5422 rerender = start_selection(position);
5423 mwindow->session->current_operation = SELECT_REGION;
5429 gui->unlock_window();
5430 mwindow->cwindow->update(1, 0, 0, 0, 1);
5431 gui->lock_window("TrackCanvas::button_press_event 2");
5433 mwindow->update_plugin_guis();
5434 gui->update_patchbay();
5437 if( update_message )
5438 gui->default_message();
5440 if( update_overlay )
5441 gui->draw_overlays(1);
5443 if( update_cursor < 0 ) {
5444 // double_click edit
5445 gui->swindow->update_selection();
5446 gui->draw_canvas(0, 0);
5448 if( update_cursor ) {
5449 gui->update_timebar(0);
5450 gui->hide_cursor(0);
5451 gui->show_cursor(1);
5452 gui->zoombar->update();
5453 gui->flash_canvas(1);
5460 int TrackCanvas::start_selection(double position)
5463 position = mwindow->edl->align_to_frame(position, 1);
5469 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
5470 mwindow->edl->local_session->get_selectionend(1)) / 2;
5472 if(position < midpoint)
5474 mwindow->edl->local_session->set_selectionstart(position);
5475 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
5481 mwindow->edl->local_session->set_selectionend(position);
5482 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
5483 // Don't que the CWindow for the end
5487 // Start a new selection
5489 //printf("TrackCanvas::start_selection %f\n", position);
5490 mwindow->edl->local_session->set_selectionstart(position);
5491 mwindow->edl->local_session->set_selectionend(position);
5492 selection_midpoint = position;
5500 void TrackCanvas::end_edithandle_selection()
5502 mwindow->modify_edithandles();
5505 void TrackCanvas::end_pluginhandle_selection()
5507 mwindow->modify_pluginhandles();
5511 double TrackCanvas::time_visible()
5513 return (double)get_w() *
5514 mwindow->edl->local_session->zoom_sample /
5515 mwindow->edl->session->sample_rate;
5519 void TrackCanvas::show_message(Auto *current, int box_color, const char *fmt, ...)
5521 char string[BCTEXTLEN];
5522 char *cp = string, *ep = cp + sizeof(string)-1;
5523 if( box_color >= 0 ) {
5524 cp += snprintf(string, ep-cp, "%-8s ",
5525 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5527 char string2[BCTEXTLEN];
5528 Units::totext(string2,
5529 current->autos->track->from_units(current->position),
5530 mwindow->edl->session->time_format,
5531 mwindow->edl->session->sample_rate,
5532 mwindow->edl->session->frame_rate,
5533 mwindow->edl->session->frames_per_foot);
5534 cp += snprintf(cp, ep-cp, "%s", string2);
5537 vsnprintf(cp, ep-cp, fmt, ap);
5539 gui->show_message(string, -1, box_color);
5542 // Patchbay* TrackCanvas::get_patchbay()
5544 // if(pane->patchbay) return pane->patchbay;
5545 // if(gui->total_panes() == 2 &&
5546 // gui->pane[TOP_LEFT_PANE] &&
5547 // gui->pane[TOP_RIGHT_PANE])
5548 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5549 // if(gui->total_panes() == 4)
5551 // if(pane->number == TOP_RIGHT_PANE)
5552 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5554 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;