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"
80 #include "transition.h"
81 #include "transitionhandles.h"
82 #include "transitionpopup.h"
83 #include "transportque.h"
85 #include "vpatchgui.inc"
91 //#define PIXMAP_AGE -5
92 #define PIXMAP_AGE -32
94 TrackCanvas::TrackCanvas(MWindow *mwindow,
105 this->mwindow = mwindow;
106 this->gui = mwindow->gui;
109 selection_midpoint = 0;
113 resource_timer = new Timer;
114 render_timer = new Timer;
115 hourglass_enabled = 0;
116 timebar_position = -1;
120 TrackCanvas::~TrackCanvas()
122 // delete transition_handles;
124 delete keyframe_pixmap;
125 delete camerakeyframe_pixmap;
126 delete modekeyframe_pixmap;
127 delete pankeyframe_pixmap;
128 delete projectorkeyframe_pixmap;
129 delete maskkeyframe_pixmap;
130 delete background_pixmap;
131 if(temp_picon) delete temp_picon;
133 delete resource_timer;
136 void TrackCanvas::create_objects()
138 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
139 // transition_handles = new TransitionHandles(mwindow, this);
140 edit_handles = new EditHandles(mwindow, this);
141 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
142 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
143 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
144 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
145 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
146 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
152 void TrackCanvas::resize_event()
154 //printf("TrackCanvas::resize_event 1\n");
157 //printf("TrackCanvas::resize_event 2\n");
160 int TrackCanvas::keypress_event()
165 int TrackCanvas::cursor_leave_event()
167 // Because drag motion calls get_cursor_over_window we can be sure that
168 // all highlights get deleted now.
169 // This ended up blocking keyboard input from the drag operations.
170 if( timebar_position >= 0 )
172 timebar_position = -1;
174 pane->timebar->update(1);
178 // return drag_motion();
181 int TrackCanvas::drag_motion_event()
183 return gui->drag_motion();
186 int TrackCanvas::drag_motion(Track **over_track,
188 PluginSet **over_pluginset,
189 Plugin **over_plugin)
191 int cursor_x = get_relative_cursor_x();
192 int cursor_y = get_relative_cursor_y();
194 if( get_cursor_over_window() &&
195 cursor_x >= 0 && cursor_y >= 0 &&
196 cursor_x < get_w() && cursor_y < get_h() )
198 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
199 // Find the edit and track the cursor is over
200 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
202 int64_t track_x, track_y, track_w, track_h;
203 track_dimensions(track, track_x, track_y, track_w, track_h);
205 if(cursor_y >= track_y &&
206 cursor_y < track_y + track_h)
209 for(Edit *edit = track->edits->first; edit; edit = edit->next)
211 int64_t edit_x, edit_y, edit_w, edit_h;
212 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
213 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
214 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
218 if( edit != track->edits->last ) continue;
219 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
220 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
221 if( !edit->silence() ) {
222 // add silence to allow drag transition past last edit
223 // will be deleted by Edits::optimize if not used
224 double length = mwindow->edl->session->default_transition_length;
225 int64_t start = edit->startproject+edit->length;
226 int64_t units = track->to_units(length, 1);
227 track->edits->create_silence(start, start+units);
230 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
233 for(int i = 0; i < track->plugin_set.total; i++)
235 PluginSet *pluginset = track->plugin_set.values[i];
236 for(Plugin *plugin = (Plugin*)pluginset->first;
238 plugin = (Plugin*)plugin->next)
240 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
241 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
243 if(cursor_y >= plugin_y &&
244 cursor_y < plugin_y + plugin_h)
246 *over_pluginset = plugin->plugin_set;
248 if(cursor_x >= plugin_x &&
249 cursor_x < plugin_x + plugin_w)
251 *over_plugin = plugin;
263 *over_track = pane->over_patchbay();
269 int TrackCanvas::drag_stop_event()
271 int result = gui->drag_stop();
272 if( !result && mwindow->session->current_operation ) {
273 mwindow->session->current_operation = NO_OPERATION;
279 int TrackCanvas::drag_stop(int *redraw)
284 int cursor_x = -1, cursor_y = -1;
286 if( get_cursor_over_window() ) {
287 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
288 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
291 Track *track = pane->over_patchbay();
292 if( track && mwindow->session->track_highlighted == track )
298 switch(mwindow->session->current_operation) {
299 case DRAG_VTRANSITION:
300 case DRAG_ATRANSITION:
301 if(mwindow->session->edit_highlighted) {
302 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
303 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
304 (mwindow->session->current_operation == DRAG_VTRANSITION &&
305 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
306 mwindow->session->current_operation = NO_OPERATION;
307 mwindow->paste_transition();
314 // Behavior for dragged plugins is limited by the fact that a shared plugin
315 // can only refer to a standalone plugin that exists in the same position in
316 // time. Dragging a plugin from one point in time to another can't produce
317 // a shared plugin to the original plugin. In this case we relocate the
318 // plugin instead of sharing it.
319 case DRAG_AEFFECT_COPY:
320 case DRAG_VEFFECT_COPY:
321 if( mwindow->session->track_highlighted &&
322 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
323 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
324 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
325 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
326 mwindow->session->current_operation = NO_OPERATION;
328 int64_t drop_position = -1;
329 Plugin *drag_plugin = mwindow->session->drag_plugin;
330 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
331 Track *hi_track = mwindow->session->track_highlighted;
333 // Insert shared plugin in source
334 // Move source to different location
335 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
336 //printf("TrackCanvas::drag_stop 6\n");
337 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
338 if( drop_position < 0 ) {
340 break; // Do not do anything
343 Track *track = mwindow->session->track_highlighted;
344 drop_position = track->frame_align(drop_position, 0);
345 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
348 else if( hi_track ) {
349 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
350 Edit *hi_edit = mwindow->session->edit_highlighted;
351 drop_position = hi_edit ? hi_edit->startproject : 0;
352 if( drop_position < 0 ) {
354 break; // Do not do anything
357 Track *track = mwindow->session->track_highlighted;
358 drop_position = track->frame_align(drop_position, 0);
359 mwindow->move_effect(drag_plugin, hi_track, drop_position);
367 if( mwindow->session->track_highlighted &&
368 ((mwindow->session->current_operation == DRAG_AEFFECT &&
369 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
370 (mwindow->session->current_operation == DRAG_VEFFECT &&
371 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
372 // Drop all the effects
373 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
374 Track *track = mwindow->session->track_highlighted;
376 double length = track->get_length();
378 if(mwindow->session->plugin_highlighted) {
379 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
380 length = track->from_units(mwindow->session->plugin_highlighted->length);
381 if(length <= 0) length = track->get_length();
383 else if(mwindow->session->pluginset_highlighted) {
384 start = track->from_units(plugin_set->length());
385 length = track->get_length() - start;
386 if(length <= 0) length = track->get_length();
388 else if(mwindow->edl->local_session->get_selectionend() >
389 mwindow->edl->local_session->get_selectionstart()) {
390 start = mwindow->edl->local_session->get_selectionstart();
391 length = mwindow->edl->local_session->get_selectionend() -
392 mwindow->edl->local_session->get_selectionstart();
394 // Move to a point between two edits
395 else if(mwindow->session->edit_highlighted) {
396 start = mwindow->session->track_highlighted->from_units(
397 mwindow->session->edit_highlighted->startproject);
398 length = mwindow->session->track_highlighted->from_units(
399 mwindow->session->edit_highlighted->length);
401 start = mwindow->edl->align_to_frame(start, 0);
402 mwindow->insert_effects_canvas(start, length);
405 if( mwindow->session->track_highlighted )
406 result = 1; // we have to cleanup
410 if(mwindow->session->track_highlighted) {
411 double asset_duration = 0;
412 int64_t asset_length_units = 0;
414 if(mwindow->session->current_operation == DRAG_ASSET &&
415 mwindow->session->drag_assets->total) {
416 Indexable *indexable = mwindow->session->drag_assets->values[0];
417 // we use video if we are over video and audio if we are over audio
418 if( indexable->have_video() &&
419 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
420 // Images have length -1
421 int64_t video_length = indexable->get_video_frames();
422 if (video_length < 0) {
423 if(mwindow->edl->session->si_useduration)
424 video_length = mwindow->edl->session->si_duration;
426 video_length = 1.0 / mwindow->edl->session->frame_rate ;
428 asset_duration = video_length / indexable->get_frame_rate();
430 else if( indexable->have_audio() &&
431 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
432 int64_t audio_length = indexable->get_audio_samples();
433 asset_duration = (double)audio_length / indexable->get_sample_rate();
437 break; // Do not do anything
440 else if( mwindow->session->current_operation == DRAG_ASSET &&
441 mwindow->session->drag_clips->total ) {
442 EDL *clip = mwindow->session->drag_clips->values[0];
443 asset_duration = clip->tracks->total_length();
446 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
449 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
450 int64_t drop_position = drop_edit_position (&insertion, NULL, asset_length_units);
451 if( drop_position < 0 ) {
453 break; // Do not do anything
456 Track *track = mwindow->session->track_highlighted;
457 double track_position = track->from_units(drop_position);
458 track_position = mwindow->edl->align_to_frame(track_position, 0);
461 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
462 // // Unfortunately, this is _a lot_ of work to do right
463 // printf("Problematic insertion\n");
464 // mwindow->edl->tracks->clear(track_position,
465 // track_position + asset_duration, 0);
467 mwindow->paste_assets(track_position, track, !insertion);
468 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
473 mwindow->session->current_operation = NO_OPERATION;
474 if(mwindow->session->track_highlighted) {
475 if( mwindow->session->track_highlighted->data_type ==
476 mwindow->session->drag_edit->track->data_type) {
477 int64_t drop_position = drop_edit_position(&insertion,
478 mwindow->session->drag_edit,
479 mwindow->session->drag_edit->length);
480 if( drop_position < 0 ) {
482 break; // Do not do anything
484 Track *track = mwindow->session->track_highlighted;
485 double track_position = track->from_units(drop_position);
486 track_position = mwindow->edl->align_to_frame(track_position, 0);
487 mwindow->move_edits(mwindow->session->drag_edits,
488 track, track_position, !insertion);
500 int TrackCanvas::drag_start_event()
505 int new_cursor, update_cursor;
507 if(mwindow->session->current_operation != NO_OPERATION) return 0;
510 if(do_plugins(get_drag_x(), get_drag_y(),
511 1, 0, redraw, rerender)) {
514 else if(do_edits(get_drag_x(), get_drag_y(),
515 0, 1, redraw, rerender, new_cursor, update_cursor)) {
523 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
525 // get the canvas/track position
526 Track *track = mwindow->session->track_highlighted;
527 int cursor_x = get_relative_cursor_x();
528 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
529 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
530 double position = mwindow->edl->align_to_frame(cur_pos, 1);
531 if( position <= 0 ) {
535 double cursor_position = position;
536 int64_t drop_position = track->to_units(cursor_position, 1);
537 if( moved_edit ) { // relative cursor position depends upon drop point
538 double moved_edit_start = moved_edit->track->from_units(moved_edit->startproject);
539 position -= mwindow->session->drag_position - moved_edit_start;
541 int64_t edit_position = track->to_units(position, 1);
542 int64_t grab_position = edit_position;
543 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
544 grab_position -= moved_edit_length / 2;
545 Edit *last_edit = track->edits->last;
546 if( !last_edit || edit_position >= (last_edit->startproject+last_edit->length) ) {
548 return grab_position;
551 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
552 Edit *next_edit = track->edits->first;
554 Edit *edit = next_edit; next_edit = (Edit *)edit->next;
555 int64_t edit_start = edit->startproject;
556 int64_t edit_end = edit_start + edit->length;
557 double edit_start_pos = edit->track->from_units(edit_start);
558 if( (fabs(edit_start_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
559 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
562 double edit_end_pos = edit->track->from_units(edit_end);
563 if( (fabs(edit_end_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
564 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
567 if( edit != moved_edit && !edit->silence() )
568 drop_start = edit_end; // reset drop zone
570 if( next_edit == moved_edit || next_edit->silence() ) continue;
574 drop_end = INT64_MAX;
575 if( edit_position >= drop_start &&
576 edit_position+moved_edit_length < drop_end ) {
577 *is_insertion = 0; // fits in the zone
578 return edit_position;
580 if( drop_position < drop_end ) { // drop in the zone
581 if( (drop_end - drop_start) >= moved_edit_length ) {
582 *is_insertion = 0; // fits in the zone, but over the edge
583 int64_t dx0 = llabs(drop_position - drop_start);
584 int64_t dx1 = llabs(drop_position - drop_end);
585 return dx0 < dx1 ? drop_start : drop_end - moved_edit_length;
588 int64_t edit_center = (edit_start + edit_end) / 2;
589 return position < edit_center ? drop_start : drop_end;
597 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
599 // get the canvas/track position
600 Track *track = plugin_set->track;
601 double moved_plugin_length = moved_plugin->track->from_units(moved_plugin->length);
602 int64_t track_plugin_length = track->to_units(moved_plugin_length, 0);
603 int cursor_x = get_relative_cursor_x();
604 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
605 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
606 double position = mwindow->edl->align_to_frame(cur_pos, 1);
607 if( position <= 0 ) return 0;
608 int64_t drop_position = track->to_units(position, 1);
609 Plugin *last_plugin = (Plugin *)plugin_set->last;
610 if( !last_plugin ) return drop_position;
611 double plugin_set_end = last_plugin->track->from_units(last_plugin->startproject+last_plugin->length);
612 if( position >= plugin_set_end ) return drop_position;
613 double moved_plugin_start = moved_plugin->track->from_units(moved_plugin->startproject);
614 position -= mwindow->session->drag_position - moved_plugin_start;
615 int64_t plugin_position = track->to_units(position, 1);
617 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
618 Plugin *next_plugin = (Plugin *)plugin_set->first;
619 while( next_plugin ) {
620 Plugin *plugin = next_plugin; next_plugin = (Plugin *)plugin->next;
621 int64_t plugin_start = plugin->startproject;
622 int64_t plugin_end = plugin_start + plugin->length;
623 double plugin_end_pos = plugin->track->from_units(plugin_end);
624 int64_t track_plugin_end = track->to_units(plugin_end_pos, 0);
625 if( plugin != moved_plugin && !plugin->silence() )
626 drop_start = track_plugin_end;
628 if( next_plugin == moved_plugin || next_plugin->silence() ) continue;
629 drop_end = track_plugin_end;
632 drop_end = INT64_MAX;
633 if( plugin_position >= drop_start && // fits in the zone
634 plugin_position+track_plugin_length < drop_end ) {
635 return plugin_position;
637 if( drop_position < drop_end ) { // drop in the zone
638 if( (drop_end - drop_start) >= track_plugin_length ) {
639 int64_t dx0 = llabs(drop_position - drop_start);
640 int64_t dx1 = llabs(drop_position - drop_end);
641 return dx0 < dx1 ? drop_start : drop_end - track_plugin_length;
649 void TrackCanvas::draw(int mode, int hide_cursor)
654 // Swap pixmap layers
655 if(get_w() != background_pixmap->get_w() ||
656 get_h() != background_pixmap->get_h())
658 delete background_pixmap;
659 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
662 // Cursor disappears after resize when this is called.
663 // Cursor doesn't redraw after editing when this isn't called.
664 if(pane->cursor && hide_cursor) pane->cursor->hide();
665 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
667 if(debug) PRINT_TRACE
668 draw_resources(mode);
670 if(debug) PRINT_TRACE
672 if(debug) PRINT_TRACE
675 void TrackCanvas::update_cursor(int flush)
677 switch(mwindow->edl->session->editing_mode)
679 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
680 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
685 void TrackCanvas::test_timer()
687 if(resource_timer->get_difference() > 1000 &&
691 hourglass_enabled = 1;
696 void TrackCanvas::draw_indexes(Indexable *indexable)
698 IndexState *index_state = indexable->index_state;
699 // Don't redraw raw samples
700 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
702 draw_resources(0, 1, indexable);
707 void TrackCanvas::draw_resources(int mode,
709 Indexable *indexable)
713 if(debug) PRINT_TRACE
715 // can't stop thread here, because this is called for every pane
716 // if(mode != IGNORE_THREAD && !indexes_only)
717 // gui->resource_thread->stop_draw(!indexes_only);
719 if(mode != IGNORE_THREAD &&
721 !gui->resource_thread->interrupted)
723 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
726 BC_Signals::dump_stack();
729 if(debug) PRINT_TRACE
731 resource_timer->update();
733 // Age resource pixmaps for deletion
735 for(int i = 0; i < gui->resource_pixmaps.total; i++)
736 gui->resource_pixmaps.values[i]->visible--;
738 if(mode == FORCE_REDRAW)
739 gui->resource_pixmaps.remove_all_objects();
741 if(debug) PRINT_TRACE
744 for(Track *current = mwindow->edl->tracks->first;
748 if(debug) PRINT_TRACE
749 for(Edit *edit = current->edits->first; edit; edit = edit->next)
751 if(debug) PRINT_TRACE
752 if( current->data_type != TRACK_SUBTITLE )
753 if(!edit->asset && !edit->nested_edl) continue;
756 if(edit->track->data_type != TRACK_AUDIO) continue;
758 if(edit->nested_edl &&
759 strcmp(indexable->path, edit->nested_edl->path)) continue;
762 strcmp(indexable->path, edit->asset->path)) continue;
765 if(debug) PRINT_TRACE
767 int64_t edit_x, edit_y, edit_w, edit_h;
768 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
771 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
772 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
774 int64_t pixmap_x, pixmap_w, pixmap_h;
775 if(debug) PRINT_TRACE
777 // Search for existing pixmap containing edit
778 for(int i = 0; i < gui->resource_pixmaps.total; i++)
780 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
781 // Same pointer can be different edit if editing took place
782 if(pixmap->edit_id == edit->id &&
783 pixmap->pane_number == pane->number)
789 if(debug) PRINT_TRACE
791 // Get new size, offset of pixmap needed
792 get_pixmap_size(edit,
798 if(debug) PRINT_TRACE
801 if(pixmap_w && pixmap_h)
803 // Create pixmap if it doesn't exist
804 ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
805 pixmap_x, pixmap_w, pixmap_h);
806 // Resize it if it's bigger
807 if( pixmap_w > pixmap->pixmap_w ||
808 pixmap_h > pixmap->pixmap_h)
809 pixmap->resize(pixmap_w, pixmap_h);
810 pixmap->update_settings(edit, edit_x, edit_w,
811 pixmap_x, pixmap_w, pixmap_h);
813 if( current->show_assets() )
814 pixmap->draw_data(this,
815 edit, edit_x, edit_w,
816 pixmap_x, pixmap_w, pixmap_h,
820 clear_box(0,0, pixmap_w,pixmap_h, pixmap);
823 if( current->show_titles() )
824 pixmap->draw_title(this,
825 edit, edit_x, edit_w,
827 // Resize it if it's smaller
828 if(pixmap_w < pixmap->pixmap_w ||
829 pixmap_h < pixmap->pixmap_h)
830 pixmap->resize(pixmap_w, pixmap_h);
832 // Copy pixmap to background canvas
833 background_pixmap->draw_pixmap(pixmap,
835 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
839 if(debug) PRINT_TRACE
846 // Delete unused pixmaps
847 if(debug) PRINT_TRACE
849 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
850 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
852 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
853 delete gui->resource_pixmaps.values[i];
854 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
856 if(debug) PRINT_TRACE
858 if(hourglass_enabled)
861 hourglass_enabled = 0;
863 if(debug) PRINT_TRACE
865 // can't stop thread here, because this is called for every pane
866 // if(mode != IGNORE_THREAD && !indexes_only)
867 // gui->resource_thread->start_draw();
868 if(debug) PRINT_TRACE
873 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
879 ResourcePixmap *result = 0;
881 for(int i = 0; i < gui->resource_pixmaps.total; i++)
883 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
884 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
885 gui->resource_pixmaps.values[i]->pane_number == pane->number)
887 result = gui->resource_pixmaps.values[i];
895 result = new ResourcePixmap(mwindow,
902 gui->resource_pixmaps.append(result);
905 // result->resize(pixmap_w, pixmap_h);
909 void TrackCanvas::get_pixmap_size(Edit *edit,
917 // Align x on frame boundaries
920 // switch(edit->edits->track->data_type)
932 if(pixmap_x + pixmap_w > get_w())
934 pixmap_w = get_w() - pixmap_x;
941 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
942 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
943 // int64_t pixel_increment = MAX(picon_w, frame_w);
944 // int64_t pixmap_x1 = edit_x;
945 // int64_t pixmap_x2 = edit_x + edit_w;
949 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
954 // if(pixmap_x2 > get_w())
956 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
960 // pixmap_x = pixmap_x1;
961 // pixmap_w = pixmap_x2 - pixmap_x1;
966 pixmap_h = mwindow->edl->local_session->zoom_track;
967 Track *track = edit->edits->track;
968 if( track->show_titles() )
969 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
970 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
973 void TrackCanvas::edit_dimensions(Edit *edit,
974 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
976 x = Units::round(edit->track->from_units(edit->startproject) *
977 mwindow->edl->session->sample_rate /
978 mwindow->edl->local_session->zoom_sample -
979 mwindow->edl->local_session->view_start[pane->number]);
981 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
983 // Method for calculating w so when edits are together we never get off by one error due to rounding
984 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
985 mwindow->edl->session->sample_rate /
986 mwindow->edl->local_session->zoom_sample -
987 mwindow->edl->local_session->view_start[pane->number]);
991 if( edit->track->show_titles() )
992 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
993 if( edit->track->show_assets() )
994 edit_h += resource_h();
998 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1002 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1003 h = track->vertical_span(mwindow->theme);
1007 void TrackCanvas::draw_paste_destination()
1009 //int cursor_x = get_relative_cursor_x();
1010 //int cursor_y = get_relative_cursor_y();
1011 int current_atrack = 0;
1012 int current_vtrack = 0;
1013 int current_aedit = 0;
1014 int current_vedit = 0;
1020 //if(pane->number == BOTTOM_RIGHT_PANE)
1021 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1023 if((mwindow->session->current_operation == DRAG_ASSET &&
1024 (mwindow->session->drag_assets->total ||
1025 mwindow->session->drag_clips->total)) ||
1026 (mwindow->session->current_operation == DRAG_EDIT &&
1027 mwindow->session->drag_edits->total)) {
1028 Indexable *indexable = 0;
1032 if(mwindow->session->current_operation == DRAG_ASSET &&
1033 mwindow->session->drag_assets->size())
1034 indexable = mwindow->session->drag_assets->get(0);
1036 if(mwindow->session->current_operation == DRAG_ASSET &&
1037 mwindow->session->drag_clips->size())
1038 clip = mwindow->session->drag_clips->get(0);
1040 int has_audio = 0, has_video = 0;
1041 double paste_audio_length = 0, paste_video_length = 0;
1042 double paste_audio_position = -1, paste_video_position = -1;
1045 has_audio = indexable->have_audio();
1046 paste_audio_length = !has_audio ? 0 :
1047 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1048 has_video = indexable->have_video();
1049 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1050 // Images have length -1
1051 if( asset && asset->video_data && asset->video_length < 0 ) {
1052 paste_video_length = mwindow->edl->session->si_useduration ?
1053 mwindow->edl->session->si_duration / asset->frame_rate :
1054 1.0 / asset->frame_rate ; // 1 frame
1057 paste_video_length = !has_video ? 0 :
1058 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1062 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1063 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1064 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1065 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1068 // 'Align cursor on frame' lengths calculations
1069 if( mwindow->edl->session->cursor_on_frames ) {
1070 double fps = mwindow->edl->session->frame_rate;
1071 double aud = floor(paste_audio_length * fps) / fps;
1072 double vid = floor(paste_video_length * fps) / fps;
1073 double length = has_video && has_audio ?
1074 aud < vid ? aud : vid :
1076 has_audio ? aud : 0;
1077 paste_video_length = paste_audio_length = length;
1080 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1082 switch( mwindow->session->track_highlighted->data_type ) {
1083 case TRACK_VIDEO: length = paste_video_length; break;
1084 case TRACK_AUDIO: length = paste_audio_length; break;
1086 int64_t asset_length = mwindow->session->track_highlighted->
1087 to_units(length, 1);
1088 paste_audio_position = mwindow->session->track_highlighted->
1089 from_units(drop_edit_position(&insertion, NULL, asset_length));
1092 int64_t asset_length = mwindow->session->track_highlighted->
1093 to_units(paste_video_length, 1);
1094 paste_video_position = mwindow->session->track_highlighted->
1095 from_units(drop_edit_position(&insertion, NULL, asset_length));
1098 // Get destination track
1099 for(Track *dest = mwindow->session->track_highlighted;
1101 dest = dest->next) {
1103 // Get source width in pixels
1105 // Use start of highlighted edit
1106 if(mwindow->session->edit_highlighted) {
1107 position = mwindow->session->track_highlighted->from_units(
1108 mwindow->session->edit_highlighted->startproject);
1111 // Use end of highlighted track, disregarding effects
1112 position = mwindow->session->track_highlighted->from_units(
1113 mwindow->session->track_highlighted->edits->length());
1116 // Get the x coordinate
1117 x = Units::to_int64(position *
1118 mwindow->edl->session->sample_rate /
1119 mwindow->edl->local_session->zoom_sample) -
1120 mwindow->edl->local_session->view_start[pane->number];
1122 double paste_position = -1.;
1123 if(dest->data_type == TRACK_AUDIO) {
1124 if(indexable && current_atrack < indexable->get_audio_channels()) {
1125 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1126 w = Units::to_int64((double)indexable->get_audio_samples() /
1127 indexable->get_sample_rate() *
1128 mwindow->edl->session->sample_rate /
1129 mwindow->edl->local_session->zoom_sample);
1130 paste_position = paste_audio_position;
1132 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1133 w = Units::to_int64((double)clip->tracks->total_length() *
1134 mwindow->edl->session->sample_rate /
1135 mwindow->edl->local_session->zoom_sample);
1136 paste_position = paste_audio_position;
1137 //printf("draw_paste_destination %d\n", x);
1139 else if(mwindow->session->current_operation == DRAG_EDIT &&
1140 current_aedit < mwindow->session->drag_edits->total) {
1142 while(current_aedit < mwindow->session->drag_edits->total &&
1143 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1146 if(current_aedit < mwindow->session->drag_edits->total) {
1147 edit = mwindow->session->drag_edits->values[current_aedit];
1148 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1149 paste_position = mwindow->session->track_highlighted->
1150 from_units(drop_edit_position(&insertion,
1151 mwindow->session->drag_edit,
1152 mwindow->session->drag_edit->length));
1156 if( paste_position >= 0 ) {
1157 position = paste_position;
1164 else if(dest->data_type == TRACK_VIDEO) {
1165 //printf("draw_paste_destination 1\n");
1166 if(indexable && current_vtrack < indexable->get_video_layers())
1168 w = Units::to_int64((double)indexable->get_video_frames() /
1169 indexable->get_frame_rate() *
1170 mwindow->edl->session->sample_rate /
1171 mwindow->edl->local_session->zoom_sample);
1172 paste_position = paste_video_position;
1174 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1175 w = Units::to_int64(clip->tracks->total_length() *
1176 mwindow->edl->session->sample_rate /
1177 mwindow->edl->local_session->zoom_sample);
1178 paste_position = paste_video_position;
1180 else if(mwindow->session->current_operation == DRAG_EDIT &&
1181 current_vedit < mwindow->session->drag_edits->total) {
1183 while(current_vedit < mwindow->session->drag_edits->total &&
1184 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1187 if(current_vedit < mwindow->session->drag_edits->total) {
1188 edit = mwindow->session->drag_edits->values[current_vedit];
1189 w = Units::to_int64(edit->track->from_units(edit->length) *
1190 mwindow->edl->session->sample_rate /
1191 mwindow->edl->local_session->zoom_sample);
1192 paste_position = mwindow->session->track_highlighted->
1193 from_units(drop_edit_position(&insertion,
1194 mwindow->session->drag_edit,
1195 mwindow->session->drag_edit->length));
1199 if( paste_position >= 0 ) {
1200 position = paste_position;
1209 // Get the x coordinate
1210 x = Units::to_int64(position *
1211 mwindow->edl->session->sample_rate /
1212 mwindow->edl->local_session->zoom_sample) -
1213 mwindow->edl->local_session->view_start[pane->number];
1214 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1215 int h = dest->vertical_span(mwindow->theme);
1217 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1218 if(x < -BC_INFINITY) {
1219 w -= -BC_INFINITY - x;
1220 x += -BC_INFINITY - x;
1223 // if(pane->number == TOP_RIGHT_PANE)
1224 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1225 // __LINE__, x, y, w, h);
1227 draw_highlight_insertion(x, y, w, h);
1229 draw_highlight_rectangle(x, y, w, h);
1236 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1238 x = Units::round(plugin->track->from_units(plugin->startproject) *
1239 mwindow->edl->session->sample_rate /
1240 mwindow->edl->local_session->zoom_sample -
1241 mwindow->edl->local_session->view_start[pane->number]);
1242 w = Units::round(plugin->track->from_units(plugin->length) *
1243 mwindow->edl->session->sample_rate /
1244 mwindow->edl->local_session->zoom_sample);
1245 y = plugin->track->y_pixel
1246 - mwindow->edl->local_session->track_start[pane->number];
1247 if( plugin->track->show_titles() )
1248 y += mwindow->theme->get_image("title_bg_data")->get_h();
1249 if( plugin->track->show_assets() )
1251 y += plugin->plugin_set->get_number() *
1252 mwindow->theme->get_image("plugin_bg_data")->get_h();
1253 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1256 int TrackCanvas::resource_h()
1258 return mwindow->edl->local_session->zoom_track;
1261 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1264 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1265 // just draw arrows, so user has indication that something is there
1266 // FIXME: get better colors
1270 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1275 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1279 // Fix bug in heroines & cvs version as of 22.8.2005:
1280 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1281 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1294 w = MIN(w, get_w() + 20);
1295 h = MIN(h, get_h() + 20);
1298 set_color(mwindow->preferences->highlight_inverse);
1300 //draw_rectangle(x, y, w, h);
1301 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1302 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1304 draw_rectangle(x, y, w, h);
1306 //if(pane->number == TOP_RIGHT_PANE)
1307 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1310 void TrackCanvas::draw_highlight_insertion(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
1324 /* these don't look so good
1326 draw_line(x, y, x, y+h);
1327 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1328 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1329 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1330 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1332 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1333 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1335 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1336 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1337 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1338 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1340 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1341 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1343 // draw the box centred around x
1345 // Fix bug in heroines & cvs version as of 22.8.2005:
1346 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1347 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1358 w = MIN(w, get_w() + 20);
1359 h = MIN(h, get_h() + 20);
1360 set_color(mwindow->preferences->highlight_inverse);
1362 draw_rectangle(x, y, w, h);
1363 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1365 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1368 void TrackCanvas::draw_playback_cursor()
1370 // Called before playback_cursor exists
1371 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1373 // mwindow->playback_cursor->visible = 0;
1374 // mwindow->playback_cursor->draw();
1378 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1380 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1381 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1383 edit_dimensions(edit, x, y, w, h);
1385 if( edit->track->show_titles() )
1386 y += mwindow->theme->get_image("title_bg_data")->get_h();
1388 if(side == EDIT_OUT)
1395 void TrackCanvas::get_transition_coords(Edit *edit,
1396 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1398 int transition_w = 30, transition_h = 30;
1399 int has_titles = edit->track->show_titles();
1400 int has_assets = edit->track->show_assets();
1401 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
1402 double asset_h = resource_h();
1403 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
1404 double dy = has_titles ?
1405 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) :
1406 ( has_assets ? asset_h/2 : 0) ;
1407 double title_h = mwindow->theme->title_h;
1408 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
1411 x -= transition_w / 2;
1412 y -= transition_h / 2;
1417 void TrackCanvas::draw_highlighting()
1422 switch(mwindow->session->current_operation)
1424 case DRAG_ATRANSITION:
1425 case DRAG_VTRANSITION:
1426 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1427 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1428 if(mwindow->session->edit_highlighted) {
1429 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1430 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1431 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1432 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1433 edit_dimensions(mwindow->session->edit_highlighted,
1435 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1436 MWindowGUI::visible(y, y + h, 0, get_h())) {
1438 get_transition_coords(mwindow->session->edit_highlighted,
1445 // Dragging a new effect from the Resource window
1448 if(mwindow->session->track_highlighted &&
1449 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1450 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1451 (mwindow->session->current_operation == DRAG_VEFFECT &&
1452 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1453 // Put it before another plugin
1454 if(mwindow->session->plugin_highlighted) {
1455 plugin_dimensions(mwindow->session->plugin_highlighted,
1457 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1459 // Put it after a plugin set
1460 else if( mwindow->session->pluginset_highlighted &&
1461 mwindow->session->pluginset_highlighted->last ) {
1462 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1464 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1465 int64_t track_x, track_y, track_w, track_h;
1466 track_dimensions(mwindow->session->track_highlighted,
1467 track_x, track_y, track_w, track_h);
1471 mwindow->session->track_highlighted->get_length() *
1472 mwindow->edl->session->sample_rate /
1473 mwindow->edl->local_session->zoom_sample -
1474 mwindow->edl->local_session->view_start[pane->number]) -
1476 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1477 if(w <= 0) w = track_w;
1480 track_dimensions(mwindow->session->track_highlighted,
1483 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1484 // Put it in a new plugin set determined by the selected range
1485 if(mwindow->edl->local_session->get_selectionend() >
1486 mwindow->edl->local_session->get_selectionstart()) {
1487 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1488 mwindow->edl->session->sample_rate /
1489 mwindow->edl->local_session->zoom_sample -
1490 mwindow->edl->local_session->view_start[pane->number]);
1491 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1492 mwindow->edl->local_session->get_selectionstart()) *
1493 mwindow->edl->session->sample_rate /
1494 mwindow->edl->local_session->zoom_sample);
1496 // Put it in a new plugin set determined by an edit boundary
1497 else if(mwindow->session->edit_highlighted) {
1498 int64_t temp_y, temp_h;
1499 edit_dimensions(mwindow->session->edit_highlighted,
1500 x, temp_y, w, temp_h);
1502 // Put it at the beginning of the track in a new plugin set
1505 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1506 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1507 //printf("TrackCanvas::draw_highlighting 1\n");
1514 if(mwindow->session->track_highlighted) {
1515 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1517 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1519 draw_paste_destination();
1525 if(mwindow->session->track_highlighted) {
1526 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1528 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1529 draw_paste_destination();
1534 // Dragging an effect from the timeline
1535 case DRAG_AEFFECT_COPY:
1536 case DRAG_VEFFECT_COPY:
1537 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1538 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1539 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1540 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1541 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1543 int64_t plugin_position = -1;
1544 Plugin *drag_plugin = mwindow->session->drag_plugin;
1545 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1546 Track *hi_track = mwindow->session->track_highlighted;
1547 Edit *hi_edit = mwindow->session->edit_highlighted;
1548 // Put it into a silence zone
1549 if( hi_plugin_set && hi_plugin_set->last &&
1550 hi_plugin_set->track == drag_plugin->track ) {
1551 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1552 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1553 hi_track = drag_plugin->track;
1555 else if( hi_track ) {
1556 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1557 track_dimensions(hi_track, x, y, w, h);
1558 plugin_position = hi_edit ? hi_edit->startproject : 0;
1561 if( plugin_position < 0 ) break;
1563 // Calculate length of plugin based on data type of track and units
1564 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1565 mwindow->edl->local_session->zoom_sample;
1566 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1567 mwindow->edl->local_session->view_start[pane->number];
1568 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1570 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1571 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1577 case DRAG_PLUGINKEY:
1578 if(mwindow->session->plugin_highlighted &&
1579 mwindow->session->current_operation == DRAG_PLUGINKEY)
1581 // Just highlight the plugin
1582 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1584 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1585 MWindowGUI::visible(y, y + h, 0, get_h()))
1597 draw_highlight_rectangle(x, y, w, h);
1601 void TrackCanvas::draw_plugins()
1603 char string[BCTEXTLEN];
1605 int current_show = 0;
1606 int current_preset = 0;
1608 for(int i = 0; i < plugin_on_toggles.total; i++)
1609 plugin_on_toggles.values[i]->in_use = 0;
1610 for(int i = 0; i < plugin_show_toggles.total; i++)
1611 plugin_show_toggles.values[i]->in_use = 0;
1612 for(int i = 0; i < preset_edit_buttons.total; i++)
1613 plugin_show_toggles.values[i]->in_use = 0;
1616 for(Track *track = mwindow->edl->tracks->first;
1618 track = track->next)
1620 if(track->expand_view)
1622 for(int i = 0; i < track->plugin_set.total; i++)
1624 PluginSet *pluginset = track->plugin_set.values[i];
1626 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1628 int64_t total_x, y, total_w, h;
1629 plugin_dimensions(plugin, total_x, y, total_w, h);
1631 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1632 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1633 plugin->plugin_type != PLUGIN_NONE)
1635 int x = total_x, w = total_w, left_margin = 5;
1636 int right_margin = 5;
1642 if(w + x > get_w()) w -= (w + x) - get_w();
1649 mwindow->theme->get_image("plugin_bg_data"),
1651 set_color(mwindow->theme->title_color);
1652 set_font(mwindow->theme->title_font);
1653 plugin->calculate_title(string, 0);
1655 // Truncate string to int64_test visible in background
1656 int len = strlen(string), j;
1657 for(j = len; j >= 0; j--)
1659 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1667 // Justify the text on the left boundary of the edit if it is visible.
1668 // Otherwise justify it on the left side of the screen.
1669 int64_t text_x = total_x + left_margin;
1670 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1671 text_x = MAX(left_margin, text_x);
1673 y + get_text_ascent(mwindow->theme->title_font) + 2,
1677 int64_t min_x = total_x + text_w;
1680 // Update plugin toggles
1681 int toggle_x = total_x + total_w;
1683 toggle_x = MIN(get_w() - right_margin, toggle_x);
1686 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1687 if(toggle_x > min_x)
1689 if(current_on >= plugin_on_toggles.total)
1691 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1692 add_subwindow(plugin_on);
1693 plugin_on_toggles.append(plugin_on);
1697 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1702 // Toggles for standalone plugins only
1703 if(plugin->plugin_type == PLUGIN_STANDALONE)
1706 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1707 if(toggle_x > min_x)
1709 if(current_show >= plugin_show_toggles.total)
1711 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1712 add_subwindow(plugin_show);
1713 plugin_show_toggles.append(plugin_show);
1717 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1721 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1722 if(toggle_x > min_x)
1724 if(current_preset >= preset_edit_buttons.total)
1726 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1727 add_subwindow(preset_edit);
1728 preset_edit_buttons.append(preset_edit);
1732 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1743 // Remove unused toggles
1745 while(current_preset < preset_edit_buttons.total)
1747 preset_edit_buttons.remove_object_number(current_preset);
1749 while(current_show < plugin_show_toggles.total)
1751 plugin_show_toggles.remove_object_number(current_show);
1754 while(current_on < plugin_on_toggles.total)
1756 plugin_on_toggles.remove_object_number(current_on);
1760 void TrackCanvas::refresh_plugintoggles()
1762 for(int i = 0; i < plugin_on_toggles.total; i++)
1764 PluginOn *on = plugin_on_toggles.values[i];
1765 on->reposition_window(on->get_x(), on->get_y());
1767 for(int i = 0; i < plugin_show_toggles.total; i++)
1769 PluginShow *show = plugin_show_toggles.values[i];
1770 show->reposition_window(show->get_x(), show->get_y());
1772 for(int i = 0; i < preset_edit_buttons.total; i++)
1774 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1775 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1779 void TrackCanvas::draw_hard_edges()
1783 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1784 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1785 if( !edit->hard_left && !edit->hard_right ) continue;
1786 edit_dimensions(edit, x, y, w, h);
1790 if( track->show_titles() )
1791 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
1792 if( track->show_assets() )
1795 y1 += mwindow->theme->title_h;
1796 if( edit->hard_left ) {
1797 ArrayList<int> xpt, ypt;
1798 xpt.append(x); ypt.append(y1);
1799 xpt.append(x+HANDLE_W); ypt.append(y1);
1800 xpt.append(x); ypt.append(y1-HANDLE_H);
1801 fill_polygon(&xpt, &ypt);
1803 if( edit->hard_right ) {
1804 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1805 xpt.append(x1); ypt.append(y1);
1806 xpt.append(x1-HANDLE_W); ypt.append(y1);
1807 xpt.append(x1); ypt.append(y1-HANDLE_H);
1808 fill_polygon(&xpt, &ypt);
1814 void TrackCanvas::draw_inout_points()
1819 void TrackCanvas::draw_drag_handle()
1821 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1822 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1824 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1825 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1826 mwindow->edl->session->sample_rate /
1827 mwindow->edl->local_session->zoom_sample -
1828 mwindow->edl->local_session->view_start[pane->number]);
1829 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1830 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1832 //printf("TrackCanvas::draw_drag_handle 3\n");
1833 draw_line(pixel1, 0, pixel1, get_h());
1835 //printf("TrackCanvas::draw_drag_handle 4\n");
1840 void TrackCanvas::draw_transitions()
1844 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1845 if( !track->show_transitions() ) continue;
1847 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1848 if(!edit->transition) continue;
1849 edit_dimensions(edit, x, y, w, h);
1850 int strip_x = x, edit_y = y;
1851 get_transition_coords(edit, x, y, w, h);
1852 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
1853 if( track->show_assets() && track->show_titles() )
1854 edit_y += mwindow->theme->get_image("title_bg_data")->get_h();
1855 if( strip_y < edit_y ) strip_y = edit_y;
1857 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1858 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1859 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1860 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1861 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1863 if( !server ) continue;
1864 VFrame *picon = server->get_picon();
1865 if( !picon ) continue;
1866 int picon_w = picon->get_w(), picon_h = picon->get_h();
1867 int track_h = edit->track->vertical_span(mwindow->theme);
1868 if( picon_h > track_h ) picon_h = track_h;
1869 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
1871 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1872 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
1873 int x = strip_x, w = strip_w;
1874 if( x < 0 ) { w -= -x; x = 0; }
1875 if( w + x > get_w() ) w -= (w + x) - get_w();
1877 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1878 mwindow->theme->get_image("plugin_bg_data"), 0);
1884 void TrackCanvas::draw_loop_points()
1886 //printf("TrackCanvas::draw_loop_points 1\n");
1887 if(mwindow->edl->local_session->loop_playback)
1889 //printf("TrackCanvas::draw_loop_points 2\n");
1890 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1891 mwindow->edl->session->sample_rate /
1892 mwindow->edl->local_session->zoom_sample -
1893 mwindow->edl->local_session->view_start[pane->number]);
1894 //printf("TrackCanvas::draw_loop_points 3\n");
1896 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1899 draw_line(x, 0, x, get_h());
1901 //printf("TrackCanvas::draw_loop_points 4\n");
1903 x = Units::round(mwindow->edl->local_session->loop_end *
1904 mwindow->edl->session->sample_rate /
1905 mwindow->edl->local_session->zoom_sample -
1906 mwindow->edl->local_session->view_start[pane->number]);
1907 //printf("TrackCanvas::draw_loop_points 5\n");
1909 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1912 draw_line(x, 0, x, get_h());
1914 //printf("TrackCanvas::draw_loop_points 6\n");
1916 //printf("TrackCanvas::draw_loop_points 7\n");
1919 void TrackCanvas::draw_brender_range()
1921 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1922 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1923 if( mwindow->edl->session->brender_end > 0 )
1925 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1926 mwindow->edl->session->sample_rate /
1927 mwindow->edl->local_session->zoom_sample -
1928 mwindow->edl->local_session->view_start[pane->number]);
1929 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1932 draw_line(x1, 0, x1, get_h());
1934 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1935 mwindow->edl->session->sample_rate /
1936 mwindow->edl->local_session->zoom_sample -
1937 mwindow->edl->local_session->view_start[pane->number]);
1939 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1942 draw_line(x2, 0, x2, get_h());
1947 // The operations which correspond to each automation type
1948 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1964 // The buttonpress operations, so nothing changes unless the mouse moves
1965 // a certain amount. This allows the keyframe to be used to position the
1966 // insertion point without moving itself.
1967 static int pre_auto_operations[AUTOMATION_TOTAL] =
1984 int TrackCanvas::do_keyframes(int cursor_x,
1992 // Note: button 3 (right mouse button) is not eaten to allow
1993 // track context menu to appear
1995 EDLSession *session = mwindow->edl->session;
1999 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
2001 0, 0, 0, 0, 0, 0, 0, 0,
2003 modekeyframe_pixmap,
2004 maskkeyframe_pixmap,
2009 for(Track *track = mwindow->edl->tracks->first;
2011 track = track->next) {
2012 Auto *auto_keyframe = 0;
2013 Automation *automation = track->automation;
2016 // Handle keyframes in reverse drawing order if a button press
2018 int end = AUTOMATION_TOTAL;
2022 start = AUTOMATION_TOTAL - 1;
2026 for(int i = start; i != end && !result; i += step)
2028 // Event not trapped and automation visible
2029 Autos *autos = automation->autos[i];
2030 if(!result && session->auto_conf->autos[i] && autos) {
2032 case AUTOMATION_MODE:
2033 case AUTOMATION_PAN:
2034 case AUTOMATION_MASK:
2035 result = do_autos(track, automation->autos[i],
2036 cursor_x, cursor_y, draw,
2037 buttonpress, auto_pixmaps[i],
2038 auto_keyframe, rerender);
2042 switch(autos->get_type()) {
2043 case Autos::AUTOMATION_TYPE_FLOAT: {
2044 Automation automation(0, track);
2045 int grouptype = automation.autogrouptype(i, track);
2046 if( buttonpress && i == AUTOMATION_SPEED ) {
2047 mwindow->speed_before();
2050 if(draw) // Do dropshadow
2051 result = do_float_autos(track, autos,
2052 cursor_x, cursor_y, draw,
2053 buttonpress, 1, 1, MDGREY,
2054 auto_keyframe, grouptype);
2055 result = do_float_autos(track, autos,
2056 cursor_x, cursor_y, draw, buttonpress,
2057 0, 0, GWindowGUI::auto_colors[i],
2058 auto_keyframe, grouptype);
2060 if( !result && buttonpress && i == AUTOMATION_SPEED )
2061 mwindow->speed_after(-1);
2062 int current_grouptype = mwindow->edl->local_session->zoombar_showautotype;
2063 if( result && buttonpress && grouptype != current_grouptype ) {
2064 mwindow->edl->local_session->zoombar_showautotype = grouptype;
2065 mwindow->gui->zoombar->update_autozoom();
2069 case Autos::AUTOMATION_TYPE_INT: {
2070 if(draw) // Do dropshadow
2071 result = do_int_autos(track, autos,
2072 cursor_x, cursor_y, draw,
2073 buttonpress, 1, 1, MDGREY,
2075 result = do_int_autos(track, autos,
2076 cursor_x, cursor_y, draw, buttonpress,
2077 0, 0, GWindowGUI::auto_colors[i],
2086 if(mwindow->session->current_operation == auto_operations[i])
2089 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2091 // mwindow->session->current_operation,
2092 // auto_operations[i]);
2095 if (buttonpress == 2 && auto_keyframe )
2097 double position = track->from_units(auto_keyframe->position);
2098 mwindow->edl->local_session->set_selectionstart(position);
2099 mwindow->edl->local_session->set_selectionend(position);
2101 if (buttonpress != 3)
2103 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2104 fill_ganged_autos(get_double_click(), 0, track,
2105 (FloatAuto*)mwindow->session->drag_auto);
2106 mwindow->session->current_operation = pre_auto_operations[i];
2107 update_drag_caption();
2110 else if( auto_keyframe )
2112 gui->keyframe_menu->update(automation,
2115 gui->keyframe_menu->activate_menu();
2116 rerender = 1; // the position changes
2120 gui->keyframe_hide->update(autos);
2121 gui->keyframe_hide->activate_menu();
2122 rerender = 1; // the position changes
2124 if(buttonpress == 1 && ctrl_down() &&
2125 AUTOMATION_TYPE_FLOAT == autos->get_type())
2126 rerender = 1; // special case: curve mode changed
2132 if(!result && session->auto_conf->plugins) {
2135 result = do_plugin_autos(track, cursor_x, cursor_y,
2136 draw, buttonpress, plugin, keyframe);
2137 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2140 if(result && (buttonpress == 1)) {
2141 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2142 update_drag_caption();
2145 else if (result && (buttonpress == 3)) {
2146 gui->keyframe_menu->update(plugin, keyframe);
2147 gui->keyframe_menu->activate_menu();
2148 rerender = 1; // the position changes
2153 // Final pass to trap event
2154 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2155 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2156 mwindow->session->current_operation == auto_operations[i]) {
2162 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2163 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2169 new_cursor = UPRIGHT_ARROW_CURSOR;
2176 void TrackCanvas::draw_keyframe_reticle()
2178 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2179 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2181 int current_op = mwindow->session->current_operation, dragging = 0;
2182 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2183 if( current_op == auto_operations[i] ) dragging = 1;
2184 if( dragging && !mwindow->session->drag_auto ) dragging = 0;
2186 int autoidx = dragging && keyframe_hairline != HAIRLINE_ALWAYS ?
2187 mwindow->session->drag_auto->autos->autoidx : -1;
2189 if( get_buttonpress() == 1 && dragging &&
2190 keyframe_hairline == HAIRLINE_DRAGGING ) {
2191 draw_hairline(mwindow->session->drag_auto, RED, 1);
2195 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2196 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2197 int show = dragging || keyframe_hairline == HAIRLINE_ALWAYS ? 1 : 0;
2198 for( Track *track = mwindow->edl->tracks->first; track; track=track->next ) {
2199 Automation *automation = track->automation;
2200 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2201 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2202 // automation visible
2203 Autos *autos = automation->autos[i];
2204 if( !autos ) continue;
2205 if( autoidx >= 0 && autos->autoidx != autoidx ) continue;
2206 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2207 auto_keyframe = auto_keyframe->next ) {
2208 draw_hairline(auto_keyframe, BLUE, show);
2214 draw_hairline(mwindow->session->drag_auto, RED, 1);
2218 void TrackCanvas::draw_auto(Auto *current,
2226 x1 = x - HANDLE_W / 2;
2227 x2 = x + HANDLE_W / 2;
2228 y1 = center_pixel + y - HANDLE_W / 2;
2229 y2 = center_pixel + y + HANDLE_W / 2;
2231 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2232 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2234 draw_box(x1, y1, x2 - x1, y2 - y1);
2238 // This draws lines for bezier in & out controls
2239 void TrackCanvas::draw_cropped_line(int x1,
2248 // Don't care about x since it is clipped by the window.
2249 // Put y coords in ascending order
2251 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2252 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2257 double slope = (double)(x2 - x1) / (y2 - y1);
2258 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2260 x1 = (int)(x1 + (min_y - y1) * slope);
2263 else if(y1 >= max_y) {
2264 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2269 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2272 else if(y2 < min_y) {
2273 x2 = (int)(x2 + (min_y - y2) * slope);
2278 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2279 if( y1 >= min_y && y1 < max_y &&
2280 y2 >= min_y && y2 < max_y )
2281 draw_line(x1, y1, x2, y2);
2285 void TrackCanvas::draw_floatauto(FloatAuto *current,
2296 int x1 = x - HANDLE_W / 2; // Center
2297 int x2 = x + HANDLE_W / 2;
2298 int y1 = center_pixel + y - HANDLE_H / 2;
2299 int y2 = center_pixel + y + HANDLE_H / 2;
2300 int ymin = center_pixel - zoom_track / 2;
2301 int ymax = center_pixel + zoom_track / 2;
2302 CLAMP(y1, ymin, ymax);
2303 CLAMP(y2, ymin, ymax);
2308 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2310 draw_box(x1, y1, x2 - x1, y2 - y1);
2313 // show bezier control points (only) if this
2314 // floatauto doesn't adjust it's tangents automatically
2315 if(current->curve_mode != FloatAuto::FREE &&
2316 current->curve_mode != FloatAuto::TFREE)
2320 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2322 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2325 inline int quantize(float f) { return (int)floor(f + 0.5); }
2327 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2328 int x, int y, int cp_x, int cp_y, int center_pixel,
2329 int zoom_track, int color)
2330 // draw the tangent and a handle for given bézier ctrl point
2332 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2334 float slope = (float)(cp_y - y)/(cp_x - x);
2335 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2337 cp_x = x + quantize((cp_y - y) / slope);
2340 cp_y += center_pixel;
2342 // drawing the tangent as a dashed line...
2343 int const dash = HANDLE_W;
2344 int const gap = HANDLE_W / 2;
2345 float sx = 3 * (cp_x - x) / 4.;
2348 // q is the x displacement for a unit line of slope
2349 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2351 float dist = 1/q * sx;
2357 float sy = slope * sx, ey = slope * ex;
2358 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2365 int r = HANDLE_W / 2;
2366 int cp_x1 = cp_x - r;
2367 int cp_y1 = cp_y - r;
2369 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2371 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2376 int TrackCanvas::test_auto(Auto *current,
2377 int x, int y, int center_pixel, int zoom_track,
2378 int cursor_x, int cursor_y, int buttonpress)
2383 x1 = x - HANDLE_W / 2;
2384 x2 = x + HANDLE_W / 2;
2385 y1 = center_pixel + y - HANDLE_H / 2;
2386 y2 = center_pixel + y + HANDLE_H / 2;
2387 int ymin = center_pixel - zoom_track / 2;
2388 int ymax = center_pixel + zoom_track / 2;
2389 CLAMP(y1, ymin, ymax);
2390 CLAMP(y2, ymin, ymax);
2392 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2394 if(buttonpress && buttonpress != 3)
2396 mwindow->session->drag_auto = current;
2397 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2398 // Toggle Autos don't respond to vertical zoom, they always show up
2399 // with "on" == 100% == line on top
2400 mwindow->session->drag_start_position = current->position;
2401 mwindow->session->drag_origin_x = cursor_x;
2402 mwindow->session->drag_origin_y = cursor_y;
2407 if(buttonpress && buttonpress != 3 && result)
2409 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2410 mwindow->undo->update_undo_before();
2416 // some Helpers for test_floatauto(..)
2417 // and for dragging the tangents/ctrl points
2418 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2419 float cursor_x, float cursor_y)
2421 // Control point switched off?
2422 if( x0 == ctrl_x ) return 0.0;
2423 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2424 double x = cursor_x-x0, y = cursor_y-y0;
2425 // wrong side of ctrl handle
2426 if( x*x1 < 0 ) return 0.0;
2427 // outside handle radius
2428 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2429 double xx1 = x1*x1, yy1 = y1*y1;
2430 double xx = x*x, yy = y*y;
2431 // distance squared from cursor to cursor projected to line from ctrl to handle
2432 // along a line perpendicular to line from ctrl to handle (closest approach)
2433 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2434 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2435 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2440 float levered_position(float position, float ref_pos)
2442 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2444 return ref_pos / position;
2448 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2449 // transforms automation value into current display coords,
2450 // dependant on current automation display range for the given kind of automation
2452 if(!mwindow || !mwindow->edl) return 0;
2453 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2454 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2455 float automation_range = automation_max - automation_min;
2456 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2458 return (auto_value - automation_min) / automation_range;
2463 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2464 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2465 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2469 int x1 = x - HANDLE_W / 2;
2470 int x2 = x + HANDLE_W / 2;
2471 int y1 = center_pixel + y - HANDLE_W / 2;
2472 int y2 = center_pixel + y + HANDLE_W / 2;
2473 int ymin = center_pixel - zoom_track / 2;
2474 int ymax = center_pixel + zoom_track / 2;
2475 CLAMP(y1, ymin, ymax);
2476 CLAMP(y2, ymin, ymax);
2478 int in_x1 = in_x - HANDLE_W / 2;
2479 int in_x2 = in_x + HANDLE_W / 2;
2480 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2481 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2482 CLAMP(in_y1, ymin, ymax);
2483 CLAMP(in_y2, ymin, ymax);
2485 int out_x1 = out_x - HANDLE_W / 2;
2486 int out_x2 = out_x + HANDLE_W / 2;
2487 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2488 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2489 CLAMP(out_y1, ymin, ymax);
2490 CLAMP(out_y2, ymin, ymax);
2493 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2494 // buttonpress could be the start of a drag operation
2495 #define INIT_DRAG(POS,VAL) \
2496 mwindow->session->drag_auto = current; \
2497 mwindow->session->drag_origin_x = cursor_x; \
2498 mwindow->session->drag_origin_y = cursor_y; \
2499 mwindow->session->drag_start_position = (POS); \
2500 mwindow->session->drag_start_percentage = (VAL);
2502 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2505 // without modifier we are manipulating the automation node
2506 // with ALT it's about dragging only the value of the node
2507 // with SHIFT the value snaps to the value of neighbouring nodes
2508 // CTRL indicates we are rather manipulating the tangent(s) of the node
2512 if( WITHIN(x1,x2,y1,y2))
2513 { // cursor hits node
2516 if(buttonpress && (buttonpress != 3))
2518 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2519 mwindow->session->drag_handle = 0;
2524 if( WITHIN(x1,x2,y1,y2))
2527 if(buttonpress && (buttonpress != 3))
2529 // could be ctrl-click or ctrl-drag
2530 // click would cycle through tangent modes
2531 ((FloatAuto*)current)->toggle_curve_mode();
2533 // drag will start dragging the tangent, if applicable
2534 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2535 mwindow->session->drag_handle = 0;
2539 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2542 if( in_x != x && current->position > 0 &&
2543 (FloatAuto::FREE == current->curve_mode ||
2544 FloatAuto::TFREE == current->curve_mode))
2545 // act on in control handle only if
2546 // tangent is significant and is editable (not automatically choosen)
2548 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2549 // either cursor in ctrl-point handle or cursor on tangent line
2550 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2552 if(buttonpress && (buttonpress != 3)) {
2553 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2555 mwindow->session->drag_handle = 1;
2556 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2557 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2558 value_to_percentage(new_invalue, autogrouptype))
2565 (FloatAuto::FREE == current->curve_mode ||
2566 FloatAuto::TFREE == current->curve_mode))
2567 // act on out control only if tangent is significant and is editable
2569 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2570 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2572 if(buttonpress && (buttonpress != 3)) {
2573 if(lever == 0.0) lever=1.0;
2575 mwindow->session->drag_handle = 2;
2576 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2577 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2578 value_to_percentage(new_outvalue, autogrouptype))
2582 } // end ctrl_down()
2588 // 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",
2589 // mwindow->session->drag_handle,
2594 if(buttonpress && (buttonpress != 3) && result)
2596 mwindow->undo->update_undo_before();
2603 // Get the float value & y for position x on the canvas
2604 #define X_TO_FLOATLINE(x) \
2605 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2606 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2607 /* Call by reference fails for some reason here */ \
2608 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2609 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2610 double position = unit_start + x * zoom_units; \
2612 if(position2 > position1) \
2615 (value2 - value1) * \
2616 (position - position1) / \
2617 (position2 - position1); \
2623 AUTOMATIONCLAMPS(value, autogrouptype); \
2624 int y = center_pixel + \
2625 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2628 void TrackCanvas::draw_floatline(int center_pixel,
2629 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2630 double unit_start, double zoom_units, double yscale,
2631 int x1, int y1, int x2, int y2,
2632 int color, int autogrouptype)
2634 // Solve bezier equation for either every pixel or a certain large number of
2637 // Not using slope intercept
2639 int prev_y = y1 + center_pixel;
2642 // Call by reference fails for some reason here
2643 FloatAuto *previous1 = previous, *next1 = next;
2644 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2645 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2646 float automation_range = automation_max - automation_min;
2648 for(int x = x1; x < x2; x++)
2650 // Interpolate value between frames
2654 y >= center_pixel - yscale / 2 &&
2655 y < center_pixel + yscale / 2 - 1)
2657 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2659 // (int)(center_pixel - yscale / 2),
2660 // (int)(center_pixel + yscale / 2 - 1));
2662 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2663 draw_line(x - 1, prev_y , x, y );
2673 int TrackCanvas::test_floatline(int center_pixel,
2688 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2689 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2690 float automation_range = automation_max - automation_min;
2691 FloatAuto *previous1 = 0, *next1 = 0;
2692 X_TO_FLOATLINE(cursor_x);
2694 if(cursor_x >= x1 &&
2696 cursor_y >= y - HANDLE_W / 2 &&
2697 cursor_y < y + HANDLE_W / 2 &&
2703 if(buttonpress == 3)
2711 mwindow->undo->update_undo_before();
2712 double position = autos->track->from_units(position1);
2713 position = mwindow->edl->align_to_frame(position, 0);
2714 int64_t new_position = autos->track->to_units(position,0);
2715 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2716 ((FloatAuto*)current)->set_value(value);
2717 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2718 mwindow->session->drag_start_position = current->position;
2719 mwindow->session->drag_origin_x = cursor_x;
2720 mwindow->session->drag_origin_y = cursor_y;
2721 mwindow->session->drag_handle = 0;
2730 void TrackCanvas::fill_ganged_autos(int all, float change, Track *skip, FloatAuto *fauto)
2732 if( !skip->gang ) return;
2733 // Handles the special case of modifying a fadeauto
2734 // when there are ganged faders on several tracks
2735 double position = skip->from_units(fauto->position);
2736 int autoidx = fauto->autos->autoidx;
2738 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2739 if( (all || current->data_type == skip->data_type) &&
2740 current->gang && current->record && current != skip ) {
2741 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2742 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2743 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2744 int64_t current_position = current->to_units(position, 1);
2745 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
2747 // keyframe exists, just change it
2748 float value = keyframe->get_value();
2749 float new_value = value + change;
2750 CLAMP(new_value, auto_min, auto_max);
2751 keyframe->adjust_to_new_coordinates(current_position, new_value);
2754 // create keyframe on neighbouring track at the point in time given by fauto
2755 FloatAuto *previous = 0, *next = 0;
2756 float value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2757 float new_value = value + change;
2758 CLAMP(new_value, auto_min, auto_max);
2759 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2760 keyframe->set_value(new_value);
2762 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2767 void TrackCanvas::update_ganged_autos(float change, Track *skip, FloatAuto *fauto)
2769 double position = skip->from_units(fauto->position);
2771 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2772 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2773 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2774 float new_value = keyframe->get_value() + change;
2776 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2777 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2778 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2782 void TrackCanvas::clear_ganged_autos()
2785 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2786 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2787 keyframe->autos->remove_nonsequential(keyframe);
2789 mwindow->session->drag_auto_gang->remove_all();
2793 void TrackCanvas::draw_toggleline(int center_pixel,
2799 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2803 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2807 int TrackCanvas::test_toggleline(Autos *autos,
2818 if(cursor_x >= x1 && cursor_x < x2)
2820 int miny = center_pixel + y1 - HANDLE_W / 2;
2821 int maxy = center_pixel + y1 + HANDLE_W / 2;
2822 if(cursor_y >= miny && cursor_y < maxy)
2827 if(buttonpress == 3)
2835 double position = (double)(cursor_x +
2836 mwindow->edl->local_session->view_start[pane->number]) *
2837 mwindow->edl->local_session->zoom_sample /
2838 mwindow->edl->session->sample_rate;
2839 int64_t unit_position = autos->track->to_units(position, 0);
2840 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2842 mwindow->undo->update_undo_before();
2844 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2845 ((IntAuto*)current)->value = new_value;
2846 // Toggle Autos don't respond to vertical zoom, they always show up
2847 // with "on" == 100% == line on top
2848 mwindow->session->drag_start_percentage = (float)new_value;
2849 mwindow->session->drag_start_position = current->position;
2850 mwindow->session->drag_origin_x = cursor_x;
2851 mwindow->session->drag_origin_y = cursor_y;
2859 void TrackCanvas::calculate_viewport(Track *track,
2860 double &view_start, // Seconds
2862 double &view_end, // Seconds
2866 double &zoom_sample,
2870 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2871 mwindow->edl->local_session->zoom_sample /
2872 mwindow->edl->session->sample_rate;
2873 unit_start = track->to_doubleunits(view_start);
2874 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2876 mwindow->edl->local_session->zoom_sample /
2877 mwindow->edl->session->sample_rate;
2878 unit_end = track->to_doubleunits(view_end);
2880 int y = track->y_pixel
2881 - mwindow->edl->local_session->track_start[pane->number];
2882 int has_titles = track->show_titles();
2883 int has_assets = track->show_assets();
2884 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
2885 double asset_h = resource_h();
2886 double title_h = mwindow->theme->title_h;
2887 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
2888 double dy = has_titles ?
2889 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) :
2890 ( has_assets ? asset_h/2 : 0) ;
2891 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
2893 center_pixel = y + dy;
2895 zoom_sample = mwindow->edl->local_session->zoom_sample;
2896 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2899 float TrackCanvas::percentage_to_value(float percentage,
2907 if(percentage > 0.5)
2914 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2915 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2916 float automation_range = automation_max - automation_min;
2918 result = percentage * automation_range + automation_min;
2921 FloatAuto *ptr = (FloatAuto*)reference;
2922 result -= ptr->get_value();
2924 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2930 void TrackCanvas::calculate_auto_position(double *x, double *y,
2931 double *in_x, double *in_y, double *out_x, double *out_y,
2932 Auto *current, double unit_start, double zoom_units, double yscale,
2935 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2936 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2937 float automation_range = automation_max - automation_min;
2938 FloatAuto *ptr = (FloatAuto*)current;
2939 *x = (double)(ptr->position - unit_start) / zoom_units;
2940 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2943 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2944 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2948 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2949 automation_min) / automation_range - 0.5) * -yscale;
2953 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2954 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2958 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2959 automation_min) / automation_range - 0.5) * -yscale;
2964 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2965 int draw, int buttonpress, int x_offset, int y_offset, int color,
2966 Auto* &auto_instance, int autogrouptype)
2969 int center_pixel, draw_auto;
2970 double view_start, unit_start;
2971 double view_end, unit_end, yscale;
2972 double zoom_sample, zoom_units;
2973 double in_x2, in_y2, out_x2, out_y2;
2979 if(draw) set_color(color);
2981 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2982 yscale, center_pixel, zoom_sample, zoom_units);
2984 // Get first auto before start
2985 Auto *current = 0, *previous = 0;
2987 for( current = autos->last;
2988 current && current->position >= unit_start;
2989 current = PREVIOUS ) ;
2991 Auto *first_auto = current ? current :
2992 autos->first ? autos->first : autos->default_auto;
2994 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2996 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2997 first_auto, unit_start, zoom_units, yscale, autogrouptype);
3002 current = autos->first;
3011 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
3012 current, unit_start, zoom_units, yscale, autogrouptype);
3020 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3025 ay2 = ay + slope * (get_w() - ax);
3029 ay = ay + slope * (0 - ax);
3033 // Draw or test handle
3034 if( current && !result && current != autos->default_auto ) {
3035 if( !draw && track->record ) {
3036 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3037 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3038 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3039 buttonpress, autogrouptype);
3041 auto_instance = current;
3043 if( draw && draw_auto ) {
3044 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3045 (int)in_x2 + x_offset, (int)in_y2,
3046 (int)out_x2 + x_offset, (int)out_y2,
3047 (int)center_pixel + y_offset, (int)yscale, color);
3051 // Draw or test joining line
3052 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3053 result = test_floatline(center_pixel,
3054 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3055 // Exclude auto coverage from the end of the line. The auto overlaps
3056 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3057 buttonpress, autogrouptype);
3060 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3061 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3062 (int)ax, (int)ay, (int)ax2, (int)ay2,
3063 color, autogrouptype);
3071 } while( current && current->position <= unit_end && !result );
3073 if( ax < get_w() && !result ) {
3074 ax2 = get_w(); ay2 = ay;
3075 if(!draw && track->record /* && buttonpress != 3 */ ) {
3076 result = test_floatline(center_pixel,
3077 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3078 (int)ax, (int)ax2, cursor_x, cursor_y,
3079 buttonpress, autogrouptype);
3082 draw_floatline(center_pixel,
3083 (FloatAuto*)previous, (FloatAuto*)current,
3084 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3085 (int)ax, (int)ay, (int)ax2, (int)ay2,
3086 color, autogrouptype);
3093 int TrackCanvas::do_int_autos(Track *track,
3102 Auto *&auto_instance)
3113 double ax, ay, ax2, ay2;
3117 if(draw) set_color(color);
3119 calculate_viewport(track,
3130 double high = -yscale * 0.8 / 2;
3131 double low = yscale * 0.8 / 2;
3133 // Get first auto before start
3135 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3141 ay = ((IntAuto*)current)->value > 0 ? high : low;
3146 current = autos->first ? autos->first : autos->default_auto;
3150 ay = ((IntAuto*)current)->value > 0 ? high : low;
3163 ax2 = (double)(current->position - unit_start) / zoom_units;
3164 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3172 if(ax2 > get_w()) ax2 = get_w();
3174 if(current && !result)
3176 if(current != autos->default_auto)
3182 result = test_auto(current,
3191 auto_instance = current;
3196 (int)ax2 + x_offset,
3197 (int)ay2 + y_offset,
3209 if(track->record /* && buttonpress != 3 */)
3211 result = test_toggleline(autos,
3224 draw_toggleline(center_pixel + y_offset,
3232 }while(current && current->position <= unit_end && !result);
3234 if(ax < get_w() && !result)
3240 if(track->record /* && buttonpress != 3 */)
3242 result = test_toggleline(autos,
3254 draw_toggleline(center_pixel + y_offset,
3263 int TrackCanvas::do_autos(Track *track,
3270 Auto * &auto_instance,
3284 calculate_viewport(track,
3297 for(current = autos->first; current && !result; current = NEXT)
3299 if(current->position >= unit_start && current->position < unit_end)
3302 x = (int64_t)((double)(current->position - unit_start) /
3303 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3304 y = center_pixel - pixmap->get_h() / 2;
3308 if(cursor_x >= x && cursor_y >= y &&
3309 cursor_x < x + pixmap->get_w() &&
3310 cursor_y < y + pixmap->get_h())
3313 auto_instance = current;
3315 if(buttonpress && (buttonpress != 3))
3317 mwindow->session->drag_auto = current;
3318 mwindow->session->drag_start_position = current->position;
3319 mwindow->session->drag_origin_x = cursor_x;
3320 mwindow->session->drag_origin_y = cursor_y;
3322 double position = autos->track->from_units(current->position);
3323 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3324 mwindow->edl->local_session->get_selectionend(1)) /
3329 mwindow->edl->local_session->set_selectionstart(position);
3330 mwindow->edl->local_session->set_selectionend(position);
3333 if(position < center)
3335 mwindow->edl->local_session->set_selectionstart(position);
3338 mwindow->edl->local_session->set_selectionend(position);
3345 draw_pixmap(pixmap, x, y);
3353 // so this means it is always >0 when keyframe is found
3354 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3355 int draw, int buttonpress, Plugin* &keyframe_plugin,
3356 KeyFrame* &keyframe_instance)
3369 if(!track->expand_view) return 0;
3371 calculate_viewport(track,
3383 for(int i = 0; i < track->plugin_set.total && !result; i++)
3385 PluginSet *plugin_set = track->plugin_set.values[i];
3386 int center_pixel = track->y_pixel -
3387 mwindow->edl->local_session->track_start[pane->number];
3388 if( track->show_titles() )
3389 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
3390 if( track->show_assets() )
3391 center_pixel += resource_h();
3392 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
3394 for(Plugin *plugin = (Plugin*)plugin_set->first;
3396 plugin = (Plugin*)plugin->next)
3398 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3399 keyframe && !result;
3400 keyframe = (KeyFrame*)keyframe->next)
3402 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3403 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3405 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3406 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3408 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3411 if(cursor_x >= x && cursor_y >= y &&
3412 cursor_x < x + keyframe_pixmap->get_w() &&
3413 cursor_y < y + keyframe_pixmap->get_h())
3416 keyframe_plugin = plugin;
3417 keyframe_instance = keyframe;
3421 mwindow->session->drag_auto = keyframe;
3422 mwindow->session->drag_start_position = keyframe->position;
3423 mwindow->session->drag_origin_x = cursor_x;
3424 mwindow->session->drag_origin_y = cursor_y;
3426 double position = track->from_units(keyframe->position);
3427 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3428 mwindow->edl->local_session->get_selectionend(1)) /
3433 mwindow->edl->local_session->set_selectionstart(position);
3434 mwindow->edl->local_session->set_selectionend(position);
3437 if(position < center)
3439 mwindow->edl->local_session->set_selectionstart(position);
3442 mwindow->edl->local_session->set_selectionend(position);
3447 draw_pixmap(keyframe_pixmap,
3457 // if(buttonpress && buttonpress != 3 && result)
3459 // mwindow->undo->update_undo_before();
3465 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color, int show)
3467 Track *track = auto_keyframe->autos->track;
3468 int autogrouptype = auto_keyframe->autos->autogrouptype;
3471 double view_start, unit_start;
3472 double view_end, unit_end, yscale;
3473 double zoom_sample, zoom_units;
3475 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3476 yscale, center_pixel, zoom_sample, zoom_units);
3478 double ax = 0, ay = 0;
3479 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3480 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3483 draw_line(ax, 0, ax, get_h());
3486 char text[BCSTRLEN];
3487 if( auto_keyframe->is_floatauto() ) {
3488 FloatAuto *float_auto = (FloatAuto *)auto_keyframe;
3489 sprintf(text, "%0.2f", float_auto->get_value());
3492 IntAuto *int_auto = (IntAuto *)auto_keyframe;
3493 sprintf(text, "%d", int_auto->value);
3495 int font = MEDIUMFONT;
3496 int tw = get_text_width(font, text) + TOOLTIP_MARGIN * 2;
3497 int th = get_text_height(font, text) + TOOLTIP_MARGIN * 2;
3498 set_color(get_resources()->tooltip_bg_color);
3500 ay += center_pixel + HANDLE_W/2;
3501 draw_box(ax, ay, tw, th);
3503 draw_rectangle(ax, ay, tw, th);
3505 ax += TOOLTIP_MARGIN;
3506 ay += TOOLTIP_MARGIN + get_text_ascent(font);
3507 draw_text(ax, ay, text);
3512 void TrackCanvas::draw_overlays()
3514 int new_cursor, update_cursor, rerender;
3516 // Move background pixmap to foreground pixmap
3517 draw_pixmap(background_pixmap,
3526 draw_inout_points();
3537 draw_brender_range();
3539 // Highlighted areas
3540 draw_highlighting();
3543 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3546 if(pane->cursor) pane->cursor->restore(1);
3552 draw_playback_cursor();
3554 draw_keyframe_reticle();
3559 int TrackCanvas::activate()
3563 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3564 //BC_Signals::dump_stack();
3565 get_top_level()->deactivate();
3567 set_active_subwindow(this);
3568 pane->cursor->activate();
3569 gui->focused_pane = pane->number;
3574 int TrackCanvas::deactivate()
3579 pane->cursor->deactivate();
3585 void TrackCanvas::update_drag_handle()
3587 double new_position;
3588 int cursor_x = get_cursor_x();
3592 mwindow->edl->local_session->view_start[pane->number]) *
3593 mwindow->edl->local_session->zoom_sample /
3594 mwindow->edl->session->sample_rate;
3597 mwindow->edl->align_to_frame(new_position, 0);
3599 if( ctrl_down() && alt_down() ) {
3600 #define snapper(v) do { \
3602 if( pos < 0 ) break; \
3603 double dist = fabs(new_position - pos); \
3604 if( dist >= snap_min ) break; \
3605 snap_position = pos; snap_min = dist; \
3607 double snap_position = new_position;
3608 double snap_min = DBL_MAX;
3609 if( mwindow->edl->local_session->inpoint_valid() )
3610 snapper(mwindow->edl->local_session->get_inpoint());
3611 if( mwindow->edl->local_session->outpoint_valid() )
3612 snapper(mwindow->edl->local_session->get_outpoint());
3613 snapper(mwindow->edl->prev_edit(new_position));
3614 snapper(mwindow->edl->next_edit(new_position));
3615 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3616 if( prev_label ) snapper(prev_label->position);
3617 Label *next_label = mwindow->edl->labels->next_label(new_position);
3618 if( next_label ) snapper(next_label->position);
3619 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3620 mwindow->edl->local_session->zoom_sample -
3621 mwindow->edl->local_session->view_start[pane->number];
3622 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3624 new_position = snap_position;
3629 if(new_position != mwindow->session->drag_position)
3631 mwindow->session->drag_position = new_position;
3632 gui->mainclock->update(new_position);
3633 timebar_position = new_position;
3634 gui->update_timebar(0);
3637 edl->create_objects();
3638 edl->copy_all(mwindow->edl);
3639 MainSession *session = mwindow->session;
3640 int edit_mode = mwindow->edl->session->edit_handle_mode[session->drag_button];
3641 edl->modify_edithandles(session->drag_start,
3642 session->drag_position,
3643 session->drag_handle,
3645 edl->session->labels_follow_edits,
3646 edl->session->plugins_follow_edits,
3647 edl->session->autos_follow_edits);
3648 double position = edit_mode != MOVE_NO_EDITS &&
3649 ( session->drag_handle || edit_mode == MOVE_ONE_EDIT ) ?
3650 session->drag_position : session->drag_start;
3651 Track *track = session->drag_handle_track();
3652 int64_t pos = track->to_units(position, 0);
3653 render_handle_frame(edl, pos, shift_down() ? 0 :
3654 session->drag_handle ? 1 : 2);
3659 int TrackCanvas::render_handle_frame(EDL *edl, int64_t pos, int mode)
3662 int64_t left = pos-1;
3663 if( left < 0 ) left = 0;
3666 VFrame vlt(edl->get_w(), edl->get_h(), edl->session->color_model);
3667 VFrame vrt(edl->get_w(), edl->get_h(), edl->session->color_model);
3668 TransportCommand command;
3669 command.command = CURRENT_FRAME;
3670 command.get_edl()->copy_all((EDL *)edl);
3671 command.change_type = CHANGE_ALL;
3672 command.realtime = 0;
3673 Preferences *preferences = mwindow->preferences;
3674 RenderEngine *render_engine = new RenderEngine(0, preferences, 0, 0);
3675 CICache *video_cache = new CICache(preferences);
3676 render_engine->set_vcache(video_cache);
3677 render_engine->arm_command(&command);
3678 int64_t left = pos-1;
3679 if( left < 0 ) left = 0;
3680 VRender *vrender = render_engine->vrender;
3682 !vrender->process_buffer(&vlt, left, 0) &&
3683 !vrender->process_buffer(&vrt, pos , 0) ? 0 : 1;
3684 delete render_engine;
3686 mwindow->cwindow->gui->lock_window("TrackCanvas::render_handle_frame 0");
3687 Canvas *canvas = mwindow->cwindow->gui->canvas;
3688 canvas->lock_canvas("TrackCanvas::render_handle_frame 1");
3689 int w = canvas->w, h = canvas->h, w2 = w/2, h2 = h/2;
3690 int lx = 0, ly = h2/2, rx = w2, ry = h2/2;
3691 BC_WindowBase *window = canvas->get_canvas();
3692 window->set_color(BLACK);
3693 window->clear_box(0,0, window->get_w(),window->get_h());
3694 window->draw_vframe(&vlt, lx,ly, w2,h2, 0,0,vlt.get_w(),vlt.get_h());
3695 window->draw_vframe(&vrt, rx,ry, w2,h2, 0,0,vrt.get_w(),vrt.get_h());
3697 canvas->unlock_canvas();
3698 mwindow->cwindow->gui->unlock_window();
3702 Track *track = mwindow->session->drag_handle_track();
3703 double position = track->from_units(mode == 1 ? left : pos);
3704 if( position < 0 ) position = 0;
3705 edl->local_session->set_selectionstart(position);
3706 edl->local_session->set_selectionend(position);
3707 PlaybackEngine *playback_engine = mwindow->cwindow->playback_engine;
3708 if( playback_engine->is_playing_back )
3709 playback_engine->stop_playback(1);
3710 mwindow->cwindow->playback_engine->refresh_frame(CHANGE_EDL, edl, 0);
3716 int TrackCanvas::update_drag_edit()
3725 int TrackCanvas::get_drag_values(float *percentage,
3732 //int x = cursor_x - mwindow->session->drag_origin_x;
3733 //int y = cursor_y - mwindow->session->drag_origin_y;
3737 if(!current->autos->track->record) return 1;
3747 calculate_viewport(current->autos->track,
3757 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3759 mwindow->session->drag_start_percentage;
3760 if(do_clamp) CLAMP(*percentage, 0, 1);
3762 *position = Units::to_int64(zoom_units *
3763 (cursor_x - mwindow->session->drag_origin_x) +
3764 mwindow->session->drag_start_position + 0.5);
3766 if((do_clamp) && *position < 0) *position = 0;
3771 #define UPDATE_DRAG_HEAD(do_clamp) \
3772 int result = 0, center_pixel; \
3773 if(!current->autos->track->record) return 0; \
3774 double view_start, unit_start, view_end, unit_end; \
3775 double yscale, zoom_sample, zoom_units; \
3777 calculate_viewport(current->autos->track, \
3778 view_start, unit_start, view_end, unit_end, \
3779 yscale, center_pixel, zoom_sample, zoom_units); \
3781 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3782 yscale + mwindow->session->drag_start_percentage; \
3783 if(do_clamp) CLAMP(percentage, 0, 1); \
3785 int64_t position = Units::to_int64(zoom_units * \
3786 (cursor_x - mwindow->session->drag_origin_x) + \
3787 mwindow->session->drag_start_position); \
3788 if((do_clamp) && position < 0) position = 0;
3791 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3793 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3795 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3796 int x = cursor_x - mwindow->session->drag_origin_x;
3797 int y = cursor_y - mwindow->session->drag_origin_y;
3798 float value, old_value;
3800 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3801 // not really editing the node, rather start editing the curve
3802 // tangent is editable and drag movement is significant
3803 if( (FloatAuto::FREE == current->curve_mode ||
3804 FloatAuto::TFREE==current->curve_mode) &&
3805 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3806 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3809 switch(mwindow->session->drag_handle) {
3811 // Snap to nearby values
3812 old_value = current->get_value();
3814 double value1, value2, distance1, distance2;
3816 if(current->previous) {
3817 int autogrouptype = current->previous->autos->autogrouptype;
3818 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3819 value1 = ((FloatAuto*)current->previous)->get_value();
3820 distance1 = fabs(value - value1);
3821 current->set_value(value1);
3825 int autogrouptype = current->next->autos->autogrouptype;
3826 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3827 value2 = ((FloatAuto*)current->next)->get_value();
3828 distance2 = fabs(value - value2);
3829 if(!current->previous || distance2 < distance1) {
3830 current->set_value(value2);
3834 if(!current->previous && !current->next) {
3835 current->set_value( ((FloatAutos*)current->autos)->default_);
3837 value = current->get_value();
3840 int autogrouptype = current->autos->autogrouptype;
3841 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3844 if(alt_down() && !shift_down())
3845 // ALT constrains movement: fixed position, only changing the value
3846 position = mwindow->session->drag_start_position;
3848 if(value != old_value || position != current->position) {
3850 float change = value - old_value;
3851 current->adjust_to_new_coordinates(position, value);
3852 update_ganged_autos(change, current->autos->track, current);
3853 show_message(current, 1,", %.2f", current->get_value());
3859 int autogrouptype = current->autos->autogrouptype;
3860 value = percentage_to_value(percentage, 0, current, autogrouptype);
3861 if(value != current->get_control_in_value())
3864 // note: (position,value) need not be at the location of the ctrl point,
3865 // but could be somewhere in between on the curve (or even outward or
3866 // on the opposit side). We set the new control point such as
3867 // to point the curve through (position,value)
3868 current->set_control_in_value(
3869 value * levered_position(position - current->position,
3870 current->get_control_in_position()));
3871 update_ganged_autos(0, current->autos->track, current);
3872 show_message(current, 1,", %.2f", current->get_control_in_value());
3878 int autogrouptype = current->autos->autogrouptype;
3879 value = percentage_to_value(percentage, 0, current, autogrouptype);
3880 if(value != current->get_control_out_value()) {
3882 current->set_control_out_value(
3883 value * levered_position(position - current->position,
3884 current->get_control_out_position()));
3885 update_ganged_autos(0, current->autos->track, current);
3886 show_message(current, 1,", %.2f", current->get_control_out_value());
3894 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3896 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3898 UPDATE_DRAG_HEAD(1);
3899 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3901 if(value != current->value || position != current->position)
3904 current->value = value;
3905 current->position = position;
3906 show_message(current, 0,", %d", current->value);
3912 // Autos which can't change value through dragging.
3914 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3916 Auto *current = (Auto*)mwindow->session->drag_auto;
3919 if(position != current->position)
3922 current->position = position;
3923 show_message(current, 0,"");
3925 double position_f = current->autos->track->from_units(current->position);
3926 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3927 mwindow->edl->local_session->get_selectionend(1)) /
3931 mwindow->edl->local_session->set_selectionstart(position_f);
3932 mwindow->edl->local_session->set_selectionend(position_f);
3935 if(position_f < center_f)
3937 mwindow->edl->local_session->set_selectionstart(position_f);
3940 mwindow->edl->local_session->set_selectionend(position_f);
3947 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3949 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3952 if(position != current->position)
3954 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3955 Track *track = current->autos->track;
3956 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3957 PluginSet *pluginset;
3959 // figure out the correct pluginset & correct plugin
3961 for(int i = 0; i < track->plugin_set.total; i++)
3963 pluginset = track->plugin_set.values[i];
3964 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3966 KeyFrames *keyframes = plugin->keyframes;
3967 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3969 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3971 if (currentkeyframe == current)
3983 mwindow->session->plugin_highlighted = plugin;
3984 mwindow->session->track_highlighted = track;
3986 current->position = position;
3987 show_message(current, 0,"");
3989 double position_f = current->autos->track->from_units(current->position);
3990 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3991 mwindow->edl->local_session->get_selectionend(1)) /
3995 mwindow->edl->local_session->set_selectionstart(position_f);
3996 mwindow->edl->local_session->set_selectionend(position_f);
3999 if(position_f < center_f)
4001 mwindow->edl->local_session->set_selectionstart(position_f);
4004 mwindow->edl->local_session->set_selectionend(position_f);
4011 void TrackCanvas::update_drag_caption()
4013 switch(mwindow->session->current_operation)
4023 int TrackCanvas::cursor_update(int in_motion)
4028 int update_clock = 0;
4029 int update_zoom = 0;
4030 int update_scroll = 0;
4031 int update_overlay = 0;
4032 int update_cursor = 0;
4035 double position = 0.;
4036 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4039 switch(mwindow->edl->session->editing_mode)
4041 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
4042 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
4045 switch(mwindow->session->current_operation)
4047 case DRAG_EDITHANDLE1:
4048 // Outside threshold. Upgrade status
4051 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4053 mwindow->session->current_operation = DRAG_EDITHANDLE2;
4059 case DRAG_EDITHANDLE2:
4062 update_drag_handle();
4067 case DRAG_PLUGINHANDLE1:
4070 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
4072 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
4078 case DRAG_PLUGINHANDLE2:
4081 update_drag_handle();
4086 // Rubber band curves
4094 case DRAG_PROJECTOR_X:
4095 case DRAG_PROJECTOR_Y:
4096 case DRAG_PROJECTOR_Z:
4097 if(active) rerender = update_overlay =
4098 update_drag_floatauto(get_cursor_x(), get_cursor_y());
4099 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
4100 mwindow->speed_after(!in_motion ? 1 : 0);
4104 if(active) rerender = update_overlay =
4105 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4109 if(active) rerender = update_overlay =
4110 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4113 // Keyframe icons are sticky
4117 case DRAG_PLUGINKEY_PRE:
4119 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
4120 mwindow->session->current_operation++;
4123 mwindow->undo->update_undo_before();
4131 if(active) rerender = update_overlay =
4132 update_drag_auto(get_cursor_x(), get_cursor_y());
4135 case DRAG_PLUGINKEY:
4136 if(active) rerender = update_overlay =
4137 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4142 cursor_x = get_cursor_x();
4143 cursor_y = get_cursor_y();
4144 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4145 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4147 position = mwindow->edl->align_to_frame(position, 0);
4148 position = MAX(position, 0);
4150 double start = mwindow->edl->local_session->get_selectionstart(1);
4151 double end = mwindow->edl->local_session->get_selectionend(1);
4152 if(position < selection_midpoint) {
4153 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4154 mwindow->edl->local_session->set_selectionstart(position);
4157 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4158 mwindow->edl->local_session->set_selectionend(position);
4161 gui->unlock_window();
4163 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
4164 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
4165 mwindow->cwindow->update(dir, 0, 0, 0, 1);
4166 gui->lock_window("TrackCanvas::cursor_update 1");
4167 // Update the faders
4168 mwindow->update_plugin_guis();
4169 gui->update_patchbay();
4171 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4173 gui->hide_cursor(0);
4174 gui->draw_cursor(1);
4175 gui->update_timebar(0);
4176 gui->flash_canvas(1);
4185 if(is_event_win() && cursor_inside()) {
4187 cursor_x = get_cursor_x();
4188 position = (double)cursor_x *
4189 (double)mwindow->edl->local_session->zoom_sample /
4190 (double)mwindow->edl->session->sample_rate +
4191 (double)mwindow->edl->local_session->view_start[pane->number] *
4192 (double)mwindow->edl->local_session->zoom_sample /
4193 (double)mwindow->edl->session->sample_rate;
4194 position = mwindow->edl->align_to_frame(position, 0);
4198 for(int i = 0; i < TOTAL_PANES; i++)
4199 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4201 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4202 gui->update_timebar(0);
4204 if(do_transitions(get_cursor_x(), get_cursor_y(),
4205 0, new_cursor, update_cursor)) break;
4206 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4207 0, 0, new_cursor, update_cursor, rerender)) break;
4208 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4209 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4210 // Plugin boundaries
4211 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4212 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4213 if(do_edits(get_cursor_x(), get_cursor_y(),
4214 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4219 //printf("TrackCanvas::cursor_update 1\n");
4220 if(update_cursor && new_cursor != get_cursor())
4222 set_cursor(new_cursor, 0, 1);
4225 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
4226 if(rerender && render_timer->get_difference() > 0.25 ) {
4227 render_timer->update();
4228 mwindow->restart_brender();
4229 mwindow->sync_parameters(CHANGE_PARAMS);
4230 mwindow->update_plugin_guis();
4231 gui->unlock_window();
4232 mwindow->cwindow->update(1, 0, 0, 0, 1);
4233 gui->lock_window("TrackCanvas::cursor_update 2");
4237 gui->update_patchbay();
4242 if(!mwindow->cwindow->playback_engine->is_playing_back)
4243 gui->mainclock->update(position);
4247 gui->zoombar->update();
4252 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4256 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4260 if(update_overlay) {
4261 gui->draw_overlays(1);
4264 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4268 int TrackCanvas::cursor_motion_event()
4270 return cursor_update(1);
4273 void TrackCanvas::start_dragscroll()
4277 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4278 //printf("TrackCanvas::start_dragscroll 1\n");
4282 void TrackCanvas::stop_dragscroll()
4286 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4287 //printf("TrackCanvas::stop_dragscroll 1\n");
4291 int TrackCanvas::repeat_event(int64_t duration)
4293 if(!drag_scroll) return 0;
4294 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4296 int sample_movement = 0;
4297 int track_movement = 0;
4298 int64_t x_distance = 0;
4299 int64_t y_distance = 0;
4300 double position = 0;
4303 switch(mwindow->session->current_operation) {
4305 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4306 if(get_cursor_x() > get_w()) {
4307 x_distance = get_cursor_x() - get_w();
4308 sample_movement = 1;
4310 else if(get_cursor_x() < 0) {
4311 x_distance = get_cursor_x();
4312 sample_movement = 1;
4315 if(get_cursor_y() > get_h()) {
4316 y_distance = get_cursor_y() - get_h();
4319 else if(get_cursor_y() < 0) {
4320 y_distance = get_cursor_y();
4327 if(sample_movement) {
4328 position = (double)(get_cursor_x() +
4329 mwindow->edl->local_session->view_start[pane->number] +
4331 mwindow->edl->local_session->zoom_sample /
4332 mwindow->edl->session->sample_rate;
4333 position = mwindow->edl->align_to_frame(position, 0);
4334 position = MAX(position, 0);
4336 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4337 switch(mwindow->session->current_operation) {
4339 if(position < selection_midpoint) {
4340 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4341 mwindow->edl->local_session->set_selectionstart(position);
4343 gui->unlock_window();
4344 mwindow->cwindow->update(1, 0, 0);
4345 gui->lock_window("TrackCanvas::repeat_event");
4346 // Update the faders
4347 mwindow->update_plugin_guis();
4348 gui->update_patchbay();
4351 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4352 mwindow->edl->local_session->set_selectionend(position);
4353 // Don't que the CWindow
4358 mwindow->samplemovement(
4359 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4363 if(track_movement) {
4364 mwindow->trackmovement(y_distance, pane->number);
4370 int TrackCanvas::button_release_event()
4372 int redraw = -1, update_overlay = 0;
4373 int result = 0, load_flags = 0;
4375 // printf("TrackCanvas::button_release_event %d\n",
4376 // mwindow->session->current_operation);
4378 switch(mwindow->session->current_operation) {
4379 case DRAG_EDITHANDLE2:
4380 mwindow->session->current_operation = NO_OPERATION;
4384 end_edithandle_selection();
4387 case DRAG_EDITHANDLE1:
4388 mwindow->session->current_operation = NO_OPERATION;
4393 case DRAG_PLUGINHANDLE2:
4394 mwindow->session->current_operation = NO_OPERATION;
4398 end_pluginhandle_selection();
4401 case DRAG_PLUGINHANDLE1:
4402 mwindow->session->current_operation = NO_OPERATION;
4408 redraw = FORCE_REDRAW;
4409 load_flags |= LOAD_EDITS;
4411 // delete the drag_auto_gang first and remove out of order keys
4412 clear_ganged_autos();
4423 case DRAG_PROJECTOR_X:
4424 case DRAG_PROJECTOR_Y:
4425 case DRAG_PROJECTOR_Z:
4426 case DRAG_PLUGINKEY:
4427 load_flags |= LOAD_AUTOMATION;
4428 mwindow->session->current_operation = NO_OPERATION;
4429 mwindow->session->drag_handle = 0;
4430 // Remove any out-of-order keyframe
4431 if(mwindow->session->drag_auto) {
4432 mwindow->session->drag_auto->autos->remove_nonsequential(
4433 mwindow->session->drag_auto);
4434 // mwindow->session->drag_auto->autos->optimize();
4438 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
4443 case DRAG_AEFFECT_COPY:
4444 case DRAG_VEFFECT_COPY:
4445 // Trap in drag stop
4450 if(mwindow->session->current_operation) {
4451 // if(mwindow->session->current_operation == SELECT_REGION) {
4452 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4455 mwindow->session->current_operation = NO_OPERATION;
4457 // Traps button release events
4467 if(update_overlay) {
4468 gui->draw_overlays(1);
4471 gui->draw_canvas(redraw, 0);
4472 gui->flash_canvas(1);
4477 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4478 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4480 Edit *edit_result = 0;
4481 int handle_result = -1;
4484 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4485 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4486 int64_t edit_x, edit_y, edit_w, edit_h;
4487 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4489 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4490 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4491 if( cursor_x < edit_x + HANDLE_W ) {
4494 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4495 track->show_assets() ) {
4496 new_cursor = DOWNLEFT_RESIZE;
4497 if( button_press == LEFT_BUTTON )
4503 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4506 if( cursor_y >= edit_y+edit_h - HANDLE_W &&
4507 track->show_assets() ) {
4508 new_cursor = DOWNRIGHT_RESIZE;
4509 if( button_press == LEFT_BUTTON )
4521 double position = 0;
4522 if( handle_result == 0 ) {
4523 position = edit_result->track->from_units(edit_result->startproject);
4524 new_cursor = LEFT_CURSOR;
4526 else if( handle_result == 1 ) {
4527 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4528 new_cursor = RIGHT_CURSOR;
4531 // Reposition cursor
4532 if( button_press ) {
4533 mwindow->session->drag_edit = edit_result;
4534 mwindow->session->drag_handle = handle_result;
4535 mwindow->session->drag_button = get_buttonpress() - 1;
4536 mwindow->session->drag_position = position;
4537 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4538 mwindow->session->drag_origin_x = get_cursor_x();
4539 mwindow->session->drag_origin_y = get_cursor_y();
4540 mwindow->session->drag_start = position;
4542 rerender = start_selection(position);
4546 else if( result < 0 ) {
4547 mwindow->undo->update_undo_before();
4548 if( !shift_down() ) {
4549 if( handle_result == 0 )
4550 edit_result->hard_left = !edit_result->hard_left;
4551 else if( handle_result == 1 )
4552 edit_result->hard_right = !edit_result->hard_right;
4555 int status = handle_result == 0 ? edit_result->hard_left :
4556 handle_result == 1 ? edit_result->hard_right : 0;
4557 int new_status = !status;
4558 int64_t edit_edge = edit_result->startproject;
4559 if( handle_result == 1 ) edit_edge += edit_result->length;
4560 double edge_position = edit_result->track->from_units(edit_edge);
4561 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4562 int64_t track_position = track->to_units(edge_position, 1);
4563 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4565 int64_t left_edge = left_edit->startproject;
4566 double left_position = track->from_units(left_edge);
4567 if( EQUIV(edge_position, left_position) ) {
4568 left_edit->hard_left = new_status;
4569 if( left_edit->previous )
4570 left_edit->previous->hard_right = new_status;
4573 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4575 int64_t right_edge = right_edit->startproject + right_edit->length;
4576 double right_position = track->from_units(right_edge);
4577 if( EQUIV(edge_position, right_position) ) {
4578 right_edit->hard_right = new_status;
4579 if( right_edit->next )
4580 right_edit->next->hard_left = new_status;
4585 rerender = update_overlay = 1;
4586 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4593 int TrackCanvas::do_plugin_handles(int cursor_x,
4597 int &update_overlay,
4601 Plugin *plugin_result = 0;
4602 int handle_result = 0;
4605 for(Track *track = mwindow->edl->tracks->first;
4607 track = track->next) {
4608 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4609 PluginSet *plugin_set = track->plugin_set.values[i];
4610 for(Plugin *plugin = (Plugin*)plugin_set->first;
4612 plugin = (Plugin*)plugin->next) {
4613 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4614 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4616 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4617 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4618 if(cursor_x < plugin_x + HANDLE_W) {
4619 plugin_result = plugin;
4623 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4624 plugin_result = plugin;
4631 if(result && shift_down())
4632 mwindow->session->trim_edits = plugin_set;
4638 double position = 0;
4639 if(handle_result == 0) {
4640 position = plugin_result->track->from_units(plugin_result->startproject);
4641 new_cursor = LEFT_CURSOR;
4643 else if(handle_result == 1) {
4644 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4645 new_cursor = RIGHT_CURSOR;
4649 mwindow->session->drag_plugin = plugin_result;
4650 mwindow->session->drag_handle = handle_result;
4651 mwindow->session->drag_button = get_buttonpress() - 1;
4652 mwindow->session->drag_position = position;
4653 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4654 mwindow->session->drag_origin_x = get_cursor_x();
4655 mwindow->session->drag_origin_y = get_cursor_y();
4656 mwindow->session->drag_start = position;
4658 rerender = start_selection(position);
4667 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4671 for(Track *track = mwindow->edl->tracks->first;
4673 track = track->next) {
4674 int64_t track_x, track_y, track_w, track_h;
4675 track_dimensions(track, track_x, track_y, track_w, track_h);
4677 if( button_press && get_buttonpress() == RIGHT_BUTTON &&
4678 cursor_y >= track_y && cursor_y < track_y + track_h) {
4679 double pos = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4680 int64_t position = track->to_units(pos, 0);
4681 gui->edit_menu->update(track, track->edits->editof(position, PLAY_FORWARD, 0));
4682 gui->edit_menu->activate_menu();
4690 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4691 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4695 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4696 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4697 int64_t edit_x, edit_y, edit_w, edit_h;
4698 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4700 // Cursor inside a track
4701 // Cursor inside an edit
4702 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4703 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4704 // Select duration of edit
4706 if(get_double_click() && !drag_start) {
4707 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4708 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4709 edit->track->from_units(edit->length));
4710 if(mwindow->edl->session->cursor_on_frames)
4712 mwindow->edl->local_session->set_selectionstart(
4713 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4714 mwindow->edl->local_session->set_selectionend(
4715 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4723 else if(drag_start && track->record) {
4724 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4725 // Need to create drag window
4726 mwindow->session->current_operation = DRAG_EDIT;
4727 mwindow->session->drag_edit = edit;
4728 //printf("TrackCanvas::do_edits 2\n");
4730 // Drag only one edit if ctrl is initially down
4732 mwindow->session->drag_edits->remove_all();
4733 mwindow->session->drag_edits->append(edit);
4736 // Construct list of all affected edits
4737 mwindow->edl->tracks->get_affected_edits(
4738 mwindow->session->drag_edits,
4739 edit->track->from_units(edit->startproject),
4742 mwindow->session->drag_origin_x = cursor_x;
4743 mwindow->session->drag_origin_y = cursor_y;
4744 // Where the drag started, so we know relative position inside the edit later
4745 mwindow->session->drag_position = (double)cursor_x *
4746 mwindow->edl->local_session->zoom_sample /
4747 mwindow->edl->session->sample_rate +
4748 (double)mwindow->edl->local_session->view_start[pane->number] *
4749 mwindow->edl->local_session->zoom_sample /
4750 mwindow->edl->session->sample_rate;
4753 get_abs_cursor(cx, cy);
4754 gui->drag_popup = new BC_DragWindow(gui,
4755 mwindow->theme->get_image("clip_icon"), cx, cy);
4767 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4772 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4773 int button_press, int &redraw, int &rerender)
4781 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4782 if(!track->expand_view) continue;
4784 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4785 // first check if plugins are visible at all
4786 if (!track->expand_view)
4788 PluginSet *plugin_set = track->plugin_set.values[i];
4789 for(plugin = (Plugin*)plugin_set->first;
4791 plugin = (Plugin*)plugin->next) {
4792 plugin_dimensions(plugin, x, y, w, h);
4793 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4794 MWindowGUI::visible(y, y + h, 0, get_h())) {
4795 if(cursor_x >= x && cursor_x < x + w &&
4796 cursor_y >= y && cursor_y < y + h) {
4806 // Start plugin popup
4808 if(get_buttonpress() == 3) {
4809 gui->plugin_menu->update(plugin);
4810 gui->plugin_menu->activate_menu();
4813 else if (get_double_click() && !drag_start) {
4814 // Select range of plugin on doubleclick over plugin
4815 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4816 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4817 plugin->track->from_units(plugin->length));
4818 if(mwindow->edl->session->cursor_on_frames) {
4819 mwindow->edl->local_session->set_selectionstart(
4820 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4821 mwindow->edl->local_session->set_selectionend(
4822 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4831 if(drag_start && plugin->track->record) {
4832 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4833 if(plugin->track->data_type == TRACK_AUDIO)
4834 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4835 else if(plugin->track->data_type == TRACK_VIDEO)
4836 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4838 mwindow->session->drag_plugin = plugin;
4839 mwindow->session->drag_origin_x = cursor_x;
4840 mwindow->session->drag_origin_y = cursor_y;
4841 // Where the drag started, so we know relative position inside the edit later
4842 mwindow->session->drag_position =
4843 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4844 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4846 switch(plugin->plugin_type) {
4847 case PLUGIN_STANDALONE: {
4848 PluginServer *server =
4849 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4850 if( !server ) break;
4851 VFrame *frame = server->picon;
4853 if(plugin->track->data_type == TRACK_AUDIO) {
4854 frame = mwindow->theme->get_image("aeffect_icon");
4857 frame = mwindow->theme->get_image("veffect_icon");
4861 get_abs_cursor(cx, cy);
4862 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4865 case PLUGIN_SHAREDPLUGIN:
4866 case PLUGIN_SHAREDMODULE: {
4867 VFrame *frame = mwindow->theme->get_image("clip_icon");
4869 get_abs_cursor(cx, cy);
4870 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4882 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4883 int button_press, int &new_cursor, int &update_cursor)
4885 Transition *transition = 0;
4890 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4891 if( !track->show_transitions() ) continue;
4893 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4894 if( edit->transition ) {
4895 edit_dimensions(edit, x, y, w, h);
4896 get_transition_coords(edit, x, y, w, h);
4898 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4899 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4900 if( cursor_x >= x && cursor_x < x + w &&
4901 cursor_y >= y && cursor_y < y + h ) {
4902 transition = edit->transition;
4914 new_cursor = UPRIGHT_ARROW_CURSOR;
4916 else if(get_buttonpress() == 3) {
4917 gui->transition_menu->update(transition);
4918 gui->transition_menu->activate_menu();
4925 int TrackCanvas::button_press_event()
4928 int cursor_x, cursor_y;
4931 cursor_x = get_cursor_x();
4932 cursor_y = get_cursor_y();
4933 mwindow->session->trim_edits = 0;
4935 if(is_event_win() && cursor_inside()) {
4936 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4943 if( get_buttonpress() == LEFT_BUTTON ) {
4944 gui->stop_transport("TrackCanvas::button_press_event");
4947 int update_overlay = 0, update_cursor = 0, rerender = 0;
4949 if(get_buttonpress() == WHEEL_UP) {
4951 mwindow->expand_sample();
4952 else if(ctrl_down())
4953 mwindow->move_left(get_w()/ 10);
4955 mwindow->move_up(get_h() / 10);
4957 else if(get_buttonpress() == WHEEL_DOWN) {
4959 mwindow->zoom_in_sample();
4960 else if(ctrl_down())
4961 mwindow->move_right(get_w() / 10);
4963 mwindow->move_down(get_h() / 10);
4965 else if(get_buttonpress() == 6) {
4967 mwindow->move_left(get_w());
4969 mwindow->move_left(get_w() / 20);
4971 mwindow->move_left(get_w() / 5);
4973 else if(get_buttonpress() == 7) {
4975 mwindow->move_right(get_w());
4977 mwindow->move_right(get_w() / 20);
4979 mwindow->move_right(get_w() / 5);
4982 switch(mwindow->edl->session->editing_mode) {
4983 // Test handles and resource boundaries and highlight a track
4984 case EDITING_ARROW: {
4985 if( do_transitions(cursor_x, cursor_y,
4986 1, new_cursor, update_cursor) ) break;
4988 if( do_keyframes(cursor_x, cursor_y,
4989 0, get_buttonpress(), new_cursor,
4990 update_cursor, rerender) ) break;
4991 // Test edit boundaries
4992 if( do_edit_handles(cursor_x, cursor_y,
4993 1, rerender, update_overlay, new_cursor,
4994 update_cursor) ) break;
4995 // Test plugin boundaries
4996 if( do_plugin_handles(cursor_x, cursor_y,
4997 1, rerender, update_overlay, new_cursor,
4998 update_cursor) ) break;
5000 if( do_edits(cursor_x, cursor_y, 1, 0,
5001 update_cursor, rerender, new_cursor,
5002 update_cursor) ) break;
5004 if( do_plugins(cursor_x, cursor_y, 0, 1,
5005 update_cursor, rerender) ) break;
5007 if( test_resources(cursor_x, cursor_y) ) break;
5009 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5014 // Test handles only and select a region
5015 case EDITING_IBEAM: {
5016 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
5017 //printf("TrackCanvas::button_press_event %d\n", position);
5019 if( do_transitions(cursor_x, cursor_y,
5020 1, new_cursor, update_cursor)) break;
5021 if(do_keyframes(cursor_x, cursor_y,
5022 0, get_buttonpress(), new_cursor,
5023 update_cursor, rerender)) {
5027 // Test edit boundaries
5028 if( do_edit_handles(cursor_x, cursor_y,
5029 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5030 // Test plugin boundaries
5031 if( do_plugin_handles(cursor_x, cursor_y,
5032 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
5034 if( do_edits(cursor_x, cursor_y,
5035 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
5037 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
5039 if( do_tracks(cursor_x, cursor_y, 1) ) break;
5040 // Highlight selection
5041 if( get_buttonpress() != LEFT_BUTTON ) break;
5042 rerender = start_selection(position);
5043 mwindow->session->current_operation = SELECT_REGION;
5050 gui->unlock_window();
5051 mwindow->cwindow->update(1, 0, 0, 0, 1);
5052 gui->lock_window("TrackCanvas::button_press_event 2");
5054 mwindow->update_plugin_guis();
5055 gui->update_patchbay();
5058 if( update_overlay ) {
5059 gui->draw_overlays(1);
5061 if( update_cursor < 0 ) {
5062 // double_click edit
5063 gui->swindow->update_selection();
5065 if( update_cursor ) {
5066 gui->update_timebar(0);
5067 gui->hide_cursor(0);
5068 gui->show_cursor(1);
5069 gui->zoombar->update();
5070 gui->flash_canvas(1);
5077 int TrackCanvas::start_selection(double position)
5080 position = mwindow->edl->align_to_frame(position, 1);
5086 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
5087 mwindow->edl->local_session->get_selectionend(1)) / 2;
5089 if(position < midpoint)
5091 mwindow->edl->local_session->set_selectionstart(position);
5092 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
5098 mwindow->edl->local_session->set_selectionend(position);
5099 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
5100 // Don't que the CWindow for the end
5104 // Start a new selection
5106 //printf("TrackCanvas::start_selection %f\n", position);
5107 mwindow->edl->local_session->set_selectionstart(position);
5108 mwindow->edl->local_session->set_selectionend(position);
5109 selection_midpoint = position;
5117 void TrackCanvas::end_edithandle_selection()
5119 mwindow->modify_edithandles();
5122 void TrackCanvas::end_pluginhandle_selection()
5124 mwindow->modify_pluginhandles();
5128 double TrackCanvas::time_visible()
5130 return (double)get_w() *
5131 mwindow->edl->local_session->zoom_sample /
5132 mwindow->edl->session->sample_rate;
5136 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
5138 char string[BCTEXTLEN];
5139 char *cp = string, *ep = cp + sizeof(string)-1;
5140 if( show_curve_type ) {
5141 cp += snprintf(string, ep-cp, "%-8s ",
5142 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5144 char string2[BCTEXTLEN];
5145 Units::totext(string2,
5146 current->autos->track->from_units(current->position),
5147 mwindow->edl->session->time_format,
5148 mwindow->edl->session->sample_rate,
5149 mwindow->edl->session->frame_rate,
5150 mwindow->edl->session->frames_per_foot);
5151 cp += snprintf(cp, ep-cp, "%s", string2);
5154 vsnprintf(cp, ep-cp, fmt, ap);
5156 gui->show_message(string);
5159 // Patchbay* TrackCanvas::get_patchbay()
5161 // if(pane->patchbay) return pane->patchbay;
5162 // if(gui->total_panes() == 2 &&
5163 // gui->pane[TOP_LEFT_PANE] &&
5164 // gui->pane[TOP_RIGHT_PANE])
5165 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5166 // if(gui->total_panes() == 4)
5168 // if(pane->number == TOP_RIGHT_PANE)
5169 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5171 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;