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"
30 #include "cplayback.h"
32 #include "cwindowgui.h"
34 #include "edithandles.h"
35 #include "editpopup.h"
38 #include "edlsession.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
41 #include "indexstate.h"
45 #include "keyframepopup.h"
46 #include "keyframes.h"
48 #include "localsession.h"
49 #include "mainclock.h"
50 #include "maincursor.h"
51 #include "mainsession.h"
53 #include "maskautos.h"
56 #include "mwindowgui.h"
60 #include "playbackengine.h"
61 #include "playtransport.h"
63 #include "pluginpopup.h"
64 #include "pluginserver.h"
65 #include "pluginset.h"
66 #include "plugintoggles.h"
67 #include "preferences.h"
68 #include "resourcepixmap.h"
69 #include "resourcethread.h"
72 #include "trackcanvas.h"
75 #include "transition.h"
76 #include "transitionhandles.h"
77 #include "transitionpopup.h"
78 #include "transportque.h"
80 #include "vpatchgui.inc"
85 //#define PIXMAP_AGE -5
86 #define PIXMAP_AGE -32
88 TrackCanvas::TrackCanvas(MWindow *mwindow,
99 this->mwindow = mwindow;
100 this->gui = mwindow->gui;
103 selection_midpoint = 0;
107 resource_timer = new Timer;
108 render_timer = new Timer;
109 hourglass_enabled = 0;
110 timebar_position = -1;
113 TrackCanvas::~TrackCanvas()
115 // delete transition_handles;
117 delete keyframe_pixmap;
118 delete camerakeyframe_pixmap;
119 delete modekeyframe_pixmap;
120 delete pankeyframe_pixmap;
121 delete projectorkeyframe_pixmap;
122 delete maskkeyframe_pixmap;
123 delete background_pixmap;
124 if(temp_picon) delete temp_picon;
126 delete resource_timer;
129 void TrackCanvas::create_objects()
131 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
132 // transition_handles = new TransitionHandles(mwindow, this);
133 edit_handles = new EditHandles(mwindow, this);
134 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
135 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
136 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
137 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
138 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
139 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
145 void TrackCanvas::resize_event()
147 //printf("TrackCanvas::resize_event 1\n");
150 //printf("TrackCanvas::resize_event 2\n");
153 int TrackCanvas::keypress_event()
158 int TrackCanvas::cursor_leave_event()
160 // Because drag motion calls get_cursor_over_window we can be sure that
161 // all highlights get deleted now.
162 // This ended up blocking keyboard input from the drag operations.
163 if( timebar_position >= 0 )
165 timebar_position = -1;
167 pane->timebar->update(1);
171 // return drag_motion();
174 int TrackCanvas::drag_motion_event()
176 return gui->drag_motion();
179 int TrackCanvas::drag_motion(Track **over_track,
181 PluginSet **over_pluginset,
182 Plugin **over_plugin)
184 int cursor_x = get_relative_cursor_x();
185 int cursor_y = get_relative_cursor_y();
187 if( get_cursor_over_window() &&
188 cursor_x >= 0 && cursor_y >= 0 &&
189 cursor_x < get_w() && cursor_y < get_h() )
191 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
192 // Find the edit and track the cursor is over
193 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
195 int64_t track_x, track_y, track_w, track_h;
196 track_dimensions(track, track_x, track_y, track_w, track_h);
198 if(cursor_y >= track_y &&
199 cursor_y < track_y + track_h)
202 for(Edit *edit = track->edits->first; edit; edit = edit->next)
204 int64_t edit_x, edit_y, edit_w, edit_h;
205 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
207 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
208 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
212 if( edit != track->edits->last ) continue;
213 if( edit->silence() ) continue;
214 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
215 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
216 if( cursor_x >= edit_x + edit_w &&
217 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
218 // add silence to allow drag transition past last edit
219 // will be deleted by Edits::optimize if not used
220 double length = mwindow->edl->session->default_transition_length;
221 int64_t start = edit->startproject+edit->length;
222 int64_t units = track->to_units(length, 1);
223 track->edits->create_silence(start, start+units);
227 for(int i = 0; i < track->plugin_set.total; i++)
229 PluginSet *pluginset = track->plugin_set.values[i];
230 for(Plugin *plugin = (Plugin*)pluginset->first;
232 plugin = (Plugin*)plugin->next)
234 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
235 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
237 if(cursor_y >= plugin_y &&
238 cursor_y < plugin_y + plugin_h)
240 *over_pluginset = plugin->plugin_set;
242 if(cursor_x >= plugin_x &&
243 cursor_x < plugin_x + plugin_w)
245 *over_plugin = plugin;
257 *over_track = pane->is_over_patchbay();
263 int TrackCanvas::drag_stop_event()
265 int result = gui->drag_stop();
266 if( !result && mwindow->session->current_operation ) {
267 mwindow->session->current_operation = NO_OPERATION;
273 int TrackCanvas::drag_stop(int *redraw)
278 int cursor_x = -1, cursor_y = -1;
280 if( get_cursor_over_window() ) {
281 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
282 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
285 Track *track = pane->is_over_patchbay();
286 if( track && mwindow->session->track_highlighted == track )
292 switch(mwindow->session->current_operation) {
293 case DRAG_VTRANSITION:
294 case DRAG_ATRANSITION:
295 if(mwindow->session->edit_highlighted) {
296 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
297 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
298 (mwindow->session->current_operation == DRAG_VTRANSITION &&
299 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
300 mwindow->session->current_operation = NO_OPERATION;
301 mwindow->paste_transition();
308 // Behavior for dragged plugins is limited by the fact that a shared plugin
309 // can only refer to a standalone plugin that exists in the same position in
310 // time. Dragging a plugin from one point in time to another can't produce
311 // a shared plugin to the original plugin. In this case we relocate the
312 // plugin instead of sharing it.
313 case DRAG_AEFFECT_COPY:
314 case DRAG_VEFFECT_COPY:
315 if( mwindow->session->track_highlighted &&
316 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
317 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
318 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
319 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
320 mwindow->session->current_operation = NO_OPERATION;
322 int64_t drop_position = -1;
323 Plugin *drag_plugin = mwindow->session->drag_plugin;
324 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
325 Track *hi_track = mwindow->session->track_highlighted;
327 // Insert shared plugin in source
328 // Move source to different location
329 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
330 //printf("TrackCanvas::drag_stop 6\n");
331 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
332 if( drop_position >= 0 )
333 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
336 else if( hi_track ) {
337 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
338 Edit *hi_edit = mwindow->session->edit_highlighted;
339 drop_position = hi_edit ? hi_edit->startproject : 0;
340 if( drop_position >= 0 )
341 mwindow->move_effect(drag_plugin, hi_track, drop_position);
349 if( mwindow->session->track_highlighted &&
350 ((mwindow->session->current_operation == DRAG_AEFFECT &&
351 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
352 (mwindow->session->current_operation == DRAG_VEFFECT &&
353 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
354 // Drop all the effects
355 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
356 Track *track = mwindow->session->track_highlighted;
358 double length = track->get_length();
360 if(mwindow->session->plugin_highlighted) {
361 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
362 length = track->from_units(mwindow->session->plugin_highlighted->length);
363 if(length <= 0) length = track->get_length();
365 else if(mwindow->session->pluginset_highlighted) {
366 start = track->from_units(plugin_set->length());
367 length = track->get_length() - start;
368 if(length <= 0) length = track->get_length();
370 else if(mwindow->edl->local_session->get_selectionend() >
371 mwindow->edl->local_session->get_selectionstart()) {
372 start = mwindow->edl->local_session->get_selectionstart();
373 length = mwindow->edl->local_session->get_selectionend() -
374 mwindow->edl->local_session->get_selectionstart();
376 // Move to a point between two edits
377 else if(mwindow->session->edit_highlighted) {
378 start = mwindow->session->track_highlighted->from_units(
379 mwindow->session->edit_highlighted->startproject);
380 length = mwindow->session->track_highlighted->from_units(
381 mwindow->session->edit_highlighted->length);
384 mwindow->insert_effects_canvas(start, length);
387 if( mwindow->session->track_highlighted )
388 result = 1; // we have to cleanup
392 if(mwindow->session->track_highlighted) {
393 double asset_duration = 0;
394 int64_t asset_length_units = 0;
395 int64_t position = 0;
397 if(mwindow->session->current_operation == DRAG_ASSET &&
398 mwindow->session->drag_assets->total) {
399 Indexable *indexable = mwindow->session->drag_assets->values[0];
400 // we use video if we are over video and audio if we are over audio
401 if( indexable->have_video() &&
402 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
403 // Images have length -1
404 int64_t video_length = indexable->get_video_frames();
405 if (video_length < 0) {
406 if(mwindow->edl->session->si_useduration)
407 video_length = mwindow->edl->session->si_duration;
409 video_length = 1.0 / mwindow->edl->session->frame_rate ;
411 asset_duration = video_length / indexable->get_frame_rate();
413 else if( indexable->have_audio() &&
414 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
415 int64_t audio_length = indexable->get_audio_samples();
416 asset_duration = (double)audio_length / indexable->get_sample_rate();
420 break; // Do not do anything
423 else if( mwindow->session->current_operation == DRAG_ASSET &&
424 mwindow->session->drag_clips->total ) {
425 EDL *clip = mwindow->session->drag_clips->values[0];
426 asset_duration = clip->tracks->total_length();
429 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
432 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
433 position = drop_edit_position (&insertion, NULL, asset_length_units);
434 if( position == -1 ) {
436 break; // Do not do anything
439 double position_f = mwindow->session->track_highlighted->from_units(position);
440 Track *track = mwindow->session->track_highlighted;
443 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
444 // // Unfortunately, this is _a lot_ of work to do right
445 // printf("Problematic insertion\n");
446 // mwindow->edl->tracks->clear(position_f,
447 // position_f + asset_duration, 0);
449 mwindow->paste_assets(position_f, track, !insertion);
450 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
455 mwindow->session->current_operation = NO_OPERATION;
456 if(mwindow->session->track_highlighted) {
457 if( mwindow->session->track_highlighted->data_type ==
458 mwindow->session->drag_edit->track->data_type) {
459 int64_t position = 0;
460 position = drop_edit_position(&insertion,
461 mwindow->session->drag_edit,
462 mwindow->session->drag_edit->length);
463 if (position == -1) {
465 break; // Do not do anything
468 double position_f = mwindow->session->track_highlighted->from_units(position);
469 Track *track = mwindow->session->track_highlighted;
470 mwindow->move_edits(mwindow->session->drag_edits,
471 track, position_f, !insertion);
483 int TrackCanvas::drag_start_event()
488 int new_cursor, update_cursor;
490 if(mwindow->session->current_operation != NO_OPERATION) return 0;
493 if(do_plugins(get_drag_x(), get_drag_y(),
494 1, 0, redraw, rerender)) {
497 else if(do_edits(get_drag_x(), get_drag_y(),
498 0, 1, redraw, rerender, new_cursor, update_cursor)) {
506 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
508 // get the canvas/track position
509 Track *track = mwindow->session->track_highlighted;
510 int cursor_x = get_relative_cursor_x();
511 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
512 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
513 // we use cursor position for affinity calculations
514 int64_t cursor_position = track->to_units(drop_time, 0);
515 if( cursor_position <= 0 ) {
519 if( moved_edit ) // relative cursor position depends upon drop point
520 drop_time -= mwindow->session->drag_position - moved_edit->track->from_units(moved_edit->startproject);
521 int64_t drop_position = track->to_units(drop_time, 1);
522 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
523 drop_position -= moved_edit_length / 2;
524 Edit *last_edit = track->edits->last;
525 if( !last_edit || drop_position > last_edit->startproject+last_edit->length ) {
527 return drop_position;
530 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
531 for( Edit *edit = track->edits->first; edit; ) {
532 int64_t edit_x0 = edit->startproject, edit_x1 = edit_x0 + edit->length;
533 if( Units::round(labs(edit_x0-cursor_position)*zoom_scale) < HANDLE_W ) {
534 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
535 return edit->startproject;
537 if( Units::round(labs(edit_x1-cursor_position)*zoom_scale) < HANDLE_W ) {
538 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
539 return edit->startproject + edit->length;
541 if( edit != moved_edit && !edit->silence() )
542 drop_x0 = edit_x1; // reset drop zone
543 if( (edit=edit->next) != 0 ) {
544 if( edit == moved_edit || edit->silence() ) continue;
549 //printf("drop cursor=%jd, x0=%jd, x1=%jd\n", cursor_position, drop_x0, drop_x1);
550 if( drop_position >= drop_x0 && drop_position+moved_edit_length < drop_x1 ) {
551 *is_insertion = 0; // fits in the zone
552 //printf("into %jd\n", drop_position);
553 return drop_position;
555 if( cursor_position < drop_x1 ) { // drop in the zone
556 if( (drop_x1-drop_x0) >= moved_edit_length ) {
557 *is_insertion = 0; // fits in the zone, but over the edge
558 int64_t dx0 = llabs(cursor_position-drop_x0);
559 int64_t dx1 = llabs(cursor_position-drop_x1);
560 //printf("onto %jd\n", dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length);
561 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length;
563 int edit_center = (edit_x0+edit_x1) / 2;
564 if( cursor_position < edit_center ) {
566 //printf("snap left %jd\n", drop_x0);
567 return drop_x0; // snap left
571 //printf("snap right %jd\n", drop_x1);
572 return drop_x1; // snap right
581 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
583 // get the canvas/track position
584 Track *track = plugin_set->track;
585 int cursor_x = get_relative_cursor_x();
586 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
587 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
588 // we use cursor position for affinity calculations
589 int64_t cursor_position = track->to_units(drop_time, 0);
590 if( cursor_position <= 0 ) return 0;
591 drop_time -= mwindow->session->drag_position - moved_plugin->track->from_units(moved_plugin->startproject);
592 int64_t drop_position = track->to_units(drop_time, 1);
593 Plugin *last_plugin = (Plugin *)plugin_set->last;
594 if( !last_plugin || drop_position > last_plugin->startproject+last_plugin->length ) {
595 return drop_position;
598 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
599 for( Plugin *plugin = (Plugin *)plugin_set->first; plugin; ) {
600 int64_t plugin_x0 = plugin->startproject, plugin_x1 = plugin_x0 + plugin->length;
601 if( plugin != moved_plugin && !plugin->silence() )
603 if( (plugin=(Plugin *)plugin->next) != 0 ) {
604 if( plugin == moved_plugin || plugin->silence() ) continue;
609 if( drop_position >= drop_x0 && // fits in the zone
610 drop_position+moved_plugin->length < drop_x1 ) {
611 return drop_position;
613 if( cursor_position < drop_x1 ) { // drop in the zone
614 if( (drop_x1-drop_x0) >= moved_plugin->length ) {
615 int64_t dx0 = llabs(cursor_position-drop_x0);
616 int64_t dx1 = llabs(cursor_position-drop_x1);
617 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_plugin->length;
626 void TrackCanvas::draw(int mode, int hide_cursor)
631 // Swap pixmap layers
632 if(get_w() != background_pixmap->get_w() ||
633 get_h() != background_pixmap->get_h())
635 delete background_pixmap;
636 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
639 // Cursor disappears after resize when this is called.
640 // Cursor doesn't redraw after editing when this isn't called.
641 if(pane->cursor && hide_cursor) pane->cursor->hide();
642 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
644 if(debug) PRINT_TRACE
645 draw_resources(mode);
647 if(debug) PRINT_TRACE
649 if(debug) PRINT_TRACE
652 void TrackCanvas::update_cursor(int flush)
654 switch(mwindow->edl->session->editing_mode)
656 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
657 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
662 void TrackCanvas::test_timer()
664 if(resource_timer->get_difference() > 1000 &&
668 hourglass_enabled = 1;
673 void TrackCanvas::draw_indexes(Indexable *indexable)
675 // Don't redraw raw samples
676 IndexState *index_state = 0;
677 index_state = indexable->index_state;
680 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
684 draw_resources(0, 1, indexable);
690 void TrackCanvas::draw_resources(int mode,
692 Indexable *indexable)
696 if(debug) PRINT_TRACE
698 if(!mwindow->edl->session->show_assets) return;
701 // can't stop thread here, because this is called for every pane
702 // if(mode != IGNORE_THREAD && !indexes_only)
703 // gui->resource_thread->stop_draw(!indexes_only);
705 if(mode != IGNORE_THREAD &&
707 !gui->resource_thread->interrupted)
709 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
712 BC_Signals::dump_stack();
715 if(debug) PRINT_TRACE
717 resource_timer->update();
719 // Age resource pixmaps for deletion
721 for(int i = 0; i < gui->resource_pixmaps.total; i++)
722 gui->resource_pixmaps.values[i]->visible--;
724 if(mode == FORCE_REDRAW)
725 gui->resource_pixmaps.remove_all_objects();
727 if(debug) PRINT_TRACE
730 for(Track *current = mwindow->edl->tracks->first;
734 if(debug) PRINT_TRACE
735 for(Edit *edit = current->edits->first; edit; edit = edit->next)
737 if(debug) PRINT_TRACE
738 if( current->data_type != TRACK_SUBTITLE )
739 if(!edit->asset && !edit->nested_edl) continue;
742 if(edit->track->data_type != TRACK_AUDIO) continue;
744 if(edit->nested_edl &&
745 strcmp(indexable->path, edit->nested_edl->path)) continue;
748 strcmp(indexable->path, edit->asset->path)) continue;
751 if(debug) PRINT_TRACE
753 int64_t edit_x, edit_y, edit_w, edit_h;
754 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
757 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
758 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
760 int64_t pixmap_x, pixmap_w, pixmap_h;
761 if(debug) PRINT_TRACE
763 // Search for existing pixmap containing edit
764 for(int i = 0; i < gui->resource_pixmaps.total; i++)
766 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
767 // Same pointer can be different edit if editing took place
768 if(pixmap->edit_id == edit->id &&
769 pixmap->pane_number == pane->number)
775 if(debug) PRINT_TRACE
777 // Get new size, offset of pixmap needed
778 get_pixmap_size(edit,
784 if(debug) PRINT_TRACE
787 if(pixmap_w && pixmap_h)
789 // Create pixmap if it doesn't exist
790 ResourcePixmap* pixmap = create_pixmap(edit,
795 // Resize it if it's bigger
796 if(pixmap_w > pixmap->pixmap_w ||
797 pixmap_h > pixmap->pixmap_h)
798 pixmap->resize(pixmap_w, pixmap_h);
799 pixmap->draw_data(this,
808 // Resize it if it's smaller
809 if(pixmap_w < pixmap->pixmap_w ||
810 pixmap_h < pixmap->pixmap_h)
811 pixmap->resize(pixmap_w, pixmap_h);
813 // Copy pixmap to background canvas
814 background_pixmap->draw_pixmap(pixmap,
816 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
820 if(debug) PRINT_TRACE
827 // Delete unused pixmaps
828 if(debug) PRINT_TRACE
830 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
831 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
833 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
834 delete gui->resource_pixmaps.values[i];
835 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
837 if(debug) PRINT_TRACE
839 if(hourglass_enabled)
842 hourglass_enabled = 0;
844 if(debug) PRINT_TRACE
846 // can't stop thread here, because this is called for every pane
847 // if(mode != IGNORE_THREAD && !indexes_only)
848 // gui->resource_thread->start_draw();
849 if(debug) PRINT_TRACE
854 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
860 ResourcePixmap *result = 0;
862 for(int i = 0; i < gui->resource_pixmaps.total; i++)
864 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
865 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
866 gui->resource_pixmaps.values[i]->pane_number == pane->number)
868 result = gui->resource_pixmaps.values[i];
876 result = new ResourcePixmap(mwindow,
883 gui->resource_pixmaps.append(result);
886 // result->resize(pixmap_w, pixmap_h);
890 void TrackCanvas::get_pixmap_size(Edit *edit,
898 // Align x on frame boundaries
901 // switch(edit->edits->track->data_type)
913 if(pixmap_x + pixmap_w > get_w())
915 pixmap_w = get_w() - pixmap_x;
922 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
923 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
924 // int64_t pixel_increment = MAX(picon_w, frame_w);
925 // int64_t pixmap_x1 = edit_x;
926 // int64_t pixmap_x2 = edit_x + edit_w;
930 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
935 // if(pixmap_x2 > get_w())
937 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
941 // pixmap_x = pixmap_x1;
942 // pixmap_w = pixmap_x2 - pixmap_x1;
947 pixmap_h = mwindow->edl->local_session->zoom_track;
948 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
949 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
952 void TrackCanvas::edit_dimensions(Edit *edit,
958 // w = Units::round(edit->track->from_units(edit->length) *
959 // mwindow->edl->session->sample_rate /
960 // mwindow->edl->local_session->zoom_sample);
964 x = Units::round(edit->track->from_units(edit->startproject) *
965 mwindow->edl->session->sample_rate /
966 mwindow->edl->local_session->zoom_sample -
967 mwindow->edl->local_session->view_start[pane->number]);
969 // Method for calculating w so when edits are together we never get off by one error due to rounding
970 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
971 mwindow->edl->session->sample_rate /
972 mwindow->edl->local_session->zoom_sample -
973 mwindow->edl->local_session->view_start[pane->number]);
976 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
978 if(mwindow->edl->session->show_titles)
979 h += mwindow->theme->get_image("title_bg_data")->get_h();
982 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
986 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
987 h = track->vertical_span(mwindow->theme);
991 void TrackCanvas::draw_paste_destination()
993 //int cursor_x = get_relative_cursor_x();
994 //int cursor_y = get_relative_cursor_y();
995 int current_atrack = 0;
996 int current_vtrack = 0;
997 int current_aedit = 0;
998 int current_vedit = 0;
1004 //if(pane->number == BOTTOM_RIGHT_PANE)
1005 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1007 if((mwindow->session->current_operation == DRAG_ASSET &&
1008 (mwindow->session->drag_assets->total ||
1009 mwindow->session->drag_clips->total)) ||
1010 (mwindow->session->current_operation == DRAG_EDIT &&
1011 mwindow->session->drag_edits->total)) {
1012 Indexable *indexable = 0;
1016 if(mwindow->session->current_operation == DRAG_ASSET &&
1017 mwindow->session->drag_assets->size())
1018 indexable = mwindow->session->drag_assets->get(0);
1020 if(mwindow->session->current_operation == DRAG_ASSET &&
1021 mwindow->session->drag_clips->size())
1022 clip = mwindow->session->drag_clips->get(0);
1024 int has_audio = 0, has_video = 0;
1025 double paste_audio_length = 0, paste_video_length = 0;
1026 double paste_audio_position = -1, paste_video_position = -1;
1029 has_audio = indexable->have_audio();
1030 paste_audio_length = !has_audio ? 0 :
1031 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1032 has_video = indexable->have_video();
1033 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1034 // Images have length -1
1035 if( asset && asset->video_data && asset->video_length < 0 ) {
1036 paste_video_length = mwindow->edl->session->si_useduration ?
1037 mwindow->edl->session->si_duration / asset->frame_rate :
1038 1.0 / asset->frame_rate ; // 1 frame
1041 paste_video_length = !has_video ? 0 :
1042 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1046 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1047 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1048 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1049 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1052 // 'Align cursor on frame' lengths calculations
1053 if( mwindow->edl->session->cursor_on_frames ) {
1054 double fps = mwindow->edl->session->frame_rate;
1055 double aud = floor(paste_audio_length * fps) / fps;
1056 double vid = floor(paste_video_length * fps) / fps;
1057 double length = has_video && has_audio ?
1058 aud < vid ? aud : vid :
1060 has_audio ? aud : 0;
1061 paste_video_length = paste_audio_length = length;
1064 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1066 switch( mwindow->session->track_highlighted->data_type ) {
1067 case TRACK_VIDEO: length = paste_video_length; break;
1068 case TRACK_AUDIO: length = paste_audio_length; break;
1070 int64_t asset_length = mwindow->session->track_highlighted->
1071 to_units(length, 1);
1072 paste_audio_position = mwindow->session->track_highlighted->
1073 from_units(drop_edit_position(&insertion, NULL, asset_length));
1076 int64_t asset_length = mwindow->session->track_highlighted->
1077 to_units(paste_video_length, 1);
1078 paste_video_position = mwindow->session->track_highlighted->
1079 from_units(drop_edit_position(&insertion, NULL, asset_length));
1082 // Get destination track
1083 for(Track *dest = mwindow->session->track_highlighted;
1085 dest = dest->next) {
1087 // Get source width in pixels
1089 // Use start of highlighted edit
1090 if(mwindow->session->edit_highlighted) {
1091 position = mwindow->session->track_highlighted->from_units(
1092 mwindow->session->edit_highlighted->startproject);
1095 // Use end of highlighted track, disregarding effects
1096 position = mwindow->session->track_highlighted->from_units(
1097 mwindow->session->track_highlighted->edits->length());
1100 // Get the x coordinate
1101 x = Units::to_int64(position *
1102 mwindow->edl->session->sample_rate /
1103 mwindow->edl->local_session->zoom_sample) -
1104 mwindow->edl->local_session->view_start[pane->number];
1106 double paste_position = -1.;
1107 if(dest->data_type == TRACK_AUDIO) {
1108 if(indexable && current_atrack < indexable->get_audio_channels()) {
1109 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1110 w = Units::to_int64((double)indexable->get_audio_samples() /
1111 indexable->get_sample_rate() *
1112 mwindow->edl->session->sample_rate /
1113 mwindow->edl->local_session->zoom_sample);
1114 paste_position = paste_audio_position;
1116 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1117 w = Units::to_int64((double)clip->tracks->total_length() *
1118 mwindow->edl->session->sample_rate /
1119 mwindow->edl->local_session->zoom_sample);
1120 paste_position = paste_audio_position;
1121 //printf("draw_paste_destination %d\n", x);
1123 else if(mwindow->session->current_operation == DRAG_EDIT &&
1124 current_aedit < mwindow->session->drag_edits->total) {
1126 while(current_aedit < mwindow->session->drag_edits->total &&
1127 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1130 if(current_aedit < mwindow->session->drag_edits->total) {
1131 edit = mwindow->session->drag_edits->values[current_aedit];
1132 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1133 paste_position = mwindow->session->track_highlighted->
1134 from_units(drop_edit_position(&insertion,
1135 mwindow->session->drag_edit,
1136 mwindow->session->drag_edit->length));
1139 if( paste_position >= 0 ) {
1140 position = paste_position;
1147 else if(dest->data_type == TRACK_VIDEO) {
1148 //printf("draw_paste_destination 1\n");
1149 if(indexable && current_vtrack < indexable->get_video_layers())
1151 w = Units::to_int64((double)indexable->get_video_frames() /
1152 indexable->get_frame_rate() *
1153 mwindow->edl->session->sample_rate /
1154 mwindow->edl->local_session->zoom_sample);
1155 paste_position = paste_video_position;
1157 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1158 w = Units::to_int64(clip->tracks->total_length() *
1159 mwindow->edl->session->sample_rate /
1160 mwindow->edl->local_session->zoom_sample);
1161 paste_position = paste_video_position;
1163 else if(mwindow->session->current_operation == DRAG_EDIT &&
1164 current_vedit < mwindow->session->drag_edits->total) {
1166 while(current_vedit < mwindow->session->drag_edits->total &&
1167 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1170 if(current_vedit < mwindow->session->drag_edits->total) {
1171 edit = mwindow->session->drag_edits->values[current_vedit];
1172 w = Units::to_int64(edit->track->from_units(edit->length) *
1173 mwindow->edl->session->sample_rate /
1174 mwindow->edl->local_session->zoom_sample);
1175 paste_position = mwindow->session->track_highlighted->
1176 from_units(drop_edit_position(&insertion,
1177 mwindow->session->drag_edit,
1178 mwindow->session->drag_edit->length));
1181 if( paste_position >= 0 ) {
1182 position = paste_position;
1191 // Get the x coordinate
1192 x = Units::to_int64(position *
1193 mwindow->edl->session->sample_rate /
1194 mwindow->edl->local_session->zoom_sample) -
1195 mwindow->edl->local_session->view_start[pane->number];
1196 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1197 int h = dest->vertical_span(mwindow->theme);
1199 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1201 draw_highlight_insertion(x, y, w, h);
1203 draw_highlight_rectangle(x, y, w, h);
1204 if(x < -BC_INFINITY) {
1205 w -= -BC_INFINITY - x;
1206 x += -BC_INFINITY - x;
1209 // if(pane->number == TOP_RIGHT_PANE)
1210 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1211 // __LINE__, x, y, w, h);
1212 draw_highlight_rectangle(x, y, w, h);
1219 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1221 x = Units::round(plugin->track->from_units(plugin->startproject) *
1222 mwindow->edl->session->sample_rate /
1223 mwindow->edl->local_session->zoom_sample -
1224 mwindow->edl->local_session->view_start[pane->number]);
1225 w = Units::round(plugin->track->from_units(plugin->length) *
1226 mwindow->edl->session->sample_rate /
1227 mwindow->edl->local_session->zoom_sample);
1228 y = plugin->track->y_pixel -
1229 mwindow->edl->local_session->track_start[pane->number] +
1230 mwindow->edl->local_session->zoom_track +
1231 plugin->plugin_set->get_number() *
1232 mwindow->theme->get_image("plugin_bg_data")->get_h();
1233 if(mwindow->edl->session->show_titles)
1234 y += mwindow->theme->get_image("title_bg_data")->get_h();
1235 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1238 int TrackCanvas::resource_h()
1240 return mwindow->edl->local_session->zoom_track;
1243 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1246 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1247 // just draw arrows, so user has indication that something is there
1248 // FIXME: get better colors
1252 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1257 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1261 // Fix bug in heroines & cvs version as of 22.8.2005:
1262 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1263 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1276 w = MIN(w, get_w() + 20);
1277 h = MIN(h, get_h() + 20);
1282 //draw_rectangle(x, y, w, h);
1283 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1284 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1286 draw_rectangle(x, y, w, h);
1288 //if(pane->number == TOP_RIGHT_PANE)
1289 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1292 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1295 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1296 // just draw arrows, so user has indication that something is there
1297 // FIXME: get better colors
1306 /* these don't look so good
1308 draw_line(x, y, x, y+h);
1309 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1310 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1311 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1312 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1314 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1315 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1317 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1318 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1319 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1320 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1322 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1323 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1325 // draw the box centred around x
1327 // Fix bug in heroines & cvs version as of 22.8.2005:
1328 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1329 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1340 w = MIN(w, get_w() + 20);
1341 h = MIN(h, get_h() + 20);
1344 draw_rectangle(x, y, w, h);
1345 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1347 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1350 void TrackCanvas::draw_playback_cursor()
1352 // Called before playback_cursor exists
1353 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1355 // mwindow->playback_cursor->visible = 0;
1356 // mwindow->playback_cursor->draw();
1360 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1362 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1363 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1365 edit_dimensions(edit, x, y, w, h);
1367 if(mwindow->edl->session->show_titles)
1369 y += mwindow->theme->get_image("title_bg_data")->get_h();
1376 if(side == EDIT_OUT)
1385 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1387 //printf("TrackCanvas::get_transition_coords 1\n");
1388 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1389 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1390 int transition_w = 30;
1391 int transition_h = 30;
1392 //printf("TrackCanvas::get_transition_coords 1\n");
1394 if(mwindow->edl->session->show_titles)
1395 y += mwindow->theme->get_image("title_bg_data")->get_h();
1396 //printf("TrackCanvas::get_transition_coords 2\n");
1398 y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
1399 x -= transition_w / 2;
1405 void TrackCanvas::draw_highlighting()
1410 switch(mwindow->session->current_operation)
1412 case DRAG_ATRANSITION:
1413 case DRAG_VTRANSITION:
1414 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1415 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1416 if(mwindow->session->edit_highlighted) {
1417 //printf("TrackCanvas::draw_highlighting 2\n");
1418 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1419 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1420 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1421 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1422 //printf("TrackCanvas::draw_highlighting 2\n");
1423 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1424 //printf("TrackCanvas::draw_highlighting 2\n");
1426 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1427 MWindowGUI::visible(y, y + h, 0, get_h())) {
1429 get_transition_coords(x, y, w, h);
1431 //printf("TrackCanvas::draw_highlighting 3\n");
1436 // Dragging a new effect from the Resource window
1439 if(mwindow->session->track_highlighted &&
1440 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1441 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1442 (mwindow->session->current_operation == DRAG_VEFFECT &&
1443 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1444 // Put it before another plugin
1445 if(mwindow->session->plugin_highlighted) {
1446 plugin_dimensions(mwindow->session->plugin_highlighted,
1448 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1450 // Put it after a plugin set
1451 else if( mwindow->session->pluginset_highlighted &&
1452 mwindow->session->pluginset_highlighted->last ) {
1453 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1455 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1456 int64_t track_x, track_y, track_w, track_h;
1457 track_dimensions(mwindow->session->track_highlighted,
1458 track_x, track_y, track_w, track_h);
1462 mwindow->session->track_highlighted->get_length() *
1463 mwindow->edl->session->sample_rate /
1464 mwindow->edl->local_session->zoom_sample -
1465 mwindow->edl->local_session->view_start[pane->number]) -
1467 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1468 if(w <= 0) w = track_w;
1471 track_dimensions(mwindow->session->track_highlighted,
1474 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1475 // Put it in a new plugin set determined by the selected range
1476 if(mwindow->edl->local_session->get_selectionend() >
1477 mwindow->edl->local_session->get_selectionstart()) {
1478 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1479 mwindow->edl->session->sample_rate /
1480 mwindow->edl->local_session->zoom_sample -
1481 mwindow->edl->local_session->view_start[pane->number]);
1482 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1483 mwindow->edl->local_session->get_selectionstart()) *
1484 mwindow->edl->session->sample_rate /
1485 mwindow->edl->local_session->zoom_sample);
1487 // Put it in a new plugin set determined by an edit boundary
1488 else if(mwindow->session->edit_highlighted) {
1489 int64_t temp_y, temp_h;
1490 edit_dimensions(mwindow->session->edit_highlighted,
1491 x, temp_y, w, temp_h);
1493 // Put it at the beginning of the track in a new plugin set
1496 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1497 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1498 //printf("TrackCanvas::draw_highlighting 1\n");
1505 if(mwindow->session->track_highlighted) {
1506 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1508 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1510 draw_paste_destination();
1516 if(mwindow->session->track_highlighted) {
1517 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1519 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1520 draw_paste_destination();
1525 // Dragging an effect from the timeline
1526 case DRAG_AEFFECT_COPY:
1527 case DRAG_VEFFECT_COPY:
1528 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1529 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1530 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1531 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1532 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1534 int64_t plugin_position = -1;
1535 Plugin *drag_plugin = mwindow->session->drag_plugin;
1536 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1537 Track *hi_track = mwindow->session->track_highlighted;
1538 Edit *hi_edit = mwindow->session->edit_highlighted;
1539 // Put it into a silence zone
1540 if( hi_plugin_set && hi_plugin_set->last &&
1541 hi_plugin_set->track == drag_plugin->track ) {
1542 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1543 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1544 hi_track = drag_plugin->track;
1546 else if( hi_track ) {
1547 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1548 track_dimensions(hi_track, x, y, w, h);
1549 plugin_position = hi_edit ? hi_edit->startproject : 0;
1552 if( plugin_position < 0 ) break;
1554 // Calculate length of plugin based on data type of track and units
1555 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1556 mwindow->edl->local_session->zoom_sample;
1557 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1558 mwindow->edl->local_session->view_start[pane->number];
1559 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1561 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1562 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1568 case DRAG_PLUGINKEY:
1569 if(mwindow->session->plugin_highlighted &&
1570 mwindow->session->current_operation == DRAG_PLUGINKEY)
1572 // Just highlight the plugin
1573 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1575 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1576 MWindowGUI::visible(y, y + h, 0, get_h()))
1588 draw_highlight_rectangle(x, y, w, h);
1592 void TrackCanvas::draw_plugins()
1594 char string[BCTEXTLEN];
1596 int current_show = 0;
1599 // if(!mwindow->edl->session->show_assets) goto done;
1601 for(int i = 0; i < plugin_on_toggles.total; i++)
1602 plugin_on_toggles.values[i]->in_use = 0;
1603 for(int i = 0; i < plugin_show_toggles.total; i++)
1604 plugin_show_toggles.values[i]->in_use = 0;
1607 for(Track *track = mwindow->edl->tracks->first;
1609 track = track->next)
1611 if(track->expand_view)
1613 for(int i = 0; i < track->plugin_set.total; i++)
1615 PluginSet *pluginset = track->plugin_set.values[i];
1617 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1619 int64_t total_x, y, total_w, h;
1620 plugin_dimensions(plugin, total_x, y, total_w, h);
1622 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1623 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1624 plugin->plugin_type != PLUGIN_NONE)
1626 int x = total_x, w = total_w, left_margin = 5;
1627 int right_margin = 5;
1633 if(w + x > get_w()) w -= (w + x) - get_w();
1640 mwindow->theme->get_image("plugin_bg_data"),
1642 set_color(mwindow->theme->title_color);
1643 set_font(mwindow->theme->title_font);
1644 plugin->calculate_title(string, 0);
1646 // Truncate string to int64_test visible in background
1647 int len = strlen(string), j;
1648 for(j = len; j >= 0; j--)
1650 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1658 // Justify the text on the left boundary of the edit if it is visible.
1659 // Otherwise justify it on the left side of the screen.
1660 int64_t text_x = total_x + left_margin;
1661 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1662 text_x = MAX(left_margin, text_x);
1664 y + get_text_ascent(mwindow->theme->title_font) + 2,
1668 int64_t min_x = total_x + text_w;
1671 // Update plugin toggles
1672 int toggle_x = total_x + total_w;
1674 toggle_x = MIN(get_w() - right_margin, toggle_x);
1677 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1678 if(toggle_x > min_x)
1680 if(current_on >= plugin_on_toggles.total)
1682 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1683 add_subwindow(plugin_on);
1684 plugin_on_toggles.append(plugin_on);
1688 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1693 // Toggles for standalone plugins only
1694 if(plugin->plugin_type == PLUGIN_STANDALONE)
1697 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1698 if(toggle_x > min_x)
1700 if(current_show >= plugin_show_toggles.total)
1702 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1703 add_subwindow(plugin_show);
1704 plugin_show_toggles.append(plugin_show);
1708 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1722 // Remove unused toggles
1724 while(current_show < plugin_show_toggles.total)
1726 plugin_show_toggles.remove_object_number(current_show);
1729 while(current_on < plugin_on_toggles.total)
1731 plugin_on_toggles.remove_object_number(current_on);
1736 void TrackCanvas::refresh_plugintoggles()
1738 for(int i = 0; i < plugin_on_toggles.total; i++)
1740 PluginOn *on = plugin_on_toggles.values[i];
1741 on->reposition_window(on->get_x(), on->get_y());
1743 for(int i = 0; i < plugin_show_toggles.total; i++)
1745 PluginShow *show = plugin_show_toggles.values[i];
1746 show->reposition_window(show->get_x(), show->get_y());
1750 void TrackCanvas::draw_inout_points()
1755 void TrackCanvas::draw_drag_handle()
1757 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1758 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1760 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1761 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1762 mwindow->edl->session->sample_rate /
1763 mwindow->edl->local_session->zoom_sample -
1764 mwindow->edl->local_session->view_start[pane->number]);
1765 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1768 //printf("TrackCanvas::draw_drag_handle 3\n");
1769 draw_line(pixel1, 0, pixel1, get_h());
1771 //printf("TrackCanvas::draw_drag_handle 4\n");
1776 void TrackCanvas::draw_transitions()
1780 // if(!mwindow->edl->session->show_assets) return;
1782 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1783 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1784 if(!edit->transition) continue;
1785 edit_dimensions(edit, x, y, w, h);
1786 int strip_x = x, strip_y = y;
1787 if(mwindow->edl->session->show_titles)
1788 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1789 get_transition_coords(x, y, w, h);
1790 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1791 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1792 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1793 MWindowGUI::visible(y, y + h, 0, get_h()) )
1795 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1797 if( !server ) continue;
1798 VFrame *picon = server->get_picon();
1799 if( !picon ) continue;
1800 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1802 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1803 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1805 int x = strip_x, w = strip_w;
1811 if(w + x > get_w()) w -= (w + x) - get_w();
1813 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1814 mwindow->theme->get_image("plugin_bg_data"), 0);
1820 void TrackCanvas::draw_loop_points()
1822 //printf("TrackCanvas::draw_loop_points 1\n");
1823 if(mwindow->edl->local_session->loop_playback)
1825 //printf("TrackCanvas::draw_loop_points 2\n");
1826 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1827 mwindow->edl->session->sample_rate /
1828 mwindow->edl->local_session->zoom_sample -
1829 mwindow->edl->local_session->view_start[pane->number]);
1830 //printf("TrackCanvas::draw_loop_points 3\n");
1832 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1835 draw_line(x, 0, x, get_h());
1837 //printf("TrackCanvas::draw_loop_points 4\n");
1839 x = Units::round(mwindow->edl->local_session->loop_end *
1840 mwindow->edl->session->sample_rate /
1841 mwindow->edl->local_session->zoom_sample -
1842 mwindow->edl->local_session->view_start[pane->number]);
1843 //printf("TrackCanvas::draw_loop_points 5\n");
1845 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1848 draw_line(x, 0, x, get_h());
1850 //printf("TrackCanvas::draw_loop_points 6\n");
1852 //printf("TrackCanvas::draw_loop_points 7\n");
1855 void TrackCanvas::draw_brender_start()
1857 if(mwindow->preferences->use_brender)
1859 int64_t x = Units::round(mwindow->edl->session->brender_start *
1860 mwindow->edl->session->sample_rate /
1861 mwindow->edl->local_session->zoom_sample -
1862 mwindow->edl->local_session->view_start[pane->number]);
1864 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1867 draw_line(x, 0, x, get_h());
1872 static int auto_colors[AUTOMATION_TOTAL] =
1888 // The operations which correspond to each automation type
1889 static int auto_operations[AUTOMATION_TOTAL] =
1905 // The buttonpress operations, so nothing changes unless the mouse moves
1906 // a certain amount. This allows the keyframe to be used to position the
1907 // insertion point without moving itself.
1908 static int pre_auto_operations[AUTOMATION_TOTAL] =
1925 int TrackCanvas::do_keyframes(int cursor_x,
1933 // Note: button 3 (right mouse button) is not eaten to allow
1934 // track context menu to appear
1936 EDLSession *session = mwindow->edl->session;
1940 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1942 0, 0, 0, 0, 0, 0, 0, 0,
1944 modekeyframe_pixmap,
1945 maskkeyframe_pixmap,
1950 for(Track *track = mwindow->edl->tracks->first;
1952 track = track->next) {
1953 Auto *auto_keyframe = 0;
1954 Automation *automation = track->automation;
1957 // Handle keyframes in reverse drawing order if a button press
1959 int end = AUTOMATION_TOTAL;
1963 start = AUTOMATION_TOTAL - 1;
1967 for(int i = start; i != end && !result; i += step)
1969 // Event not trapped and automation visible
1970 Autos *autos = automation->autos[i];
1971 if(!result && session->auto_conf->autos[i] && autos) {
1973 case AUTOMATION_MODE:
1974 case AUTOMATION_PAN:
1975 case AUTOMATION_MASK:
1976 result = do_autos(track, automation->autos[i],
1977 cursor_x, cursor_y, draw,
1978 buttonpress, auto_pixmaps[i],
1979 auto_keyframe, rerender);
1983 switch(autos->get_type()) {
1984 case Autos::AUTOMATION_TYPE_FLOAT: {
1985 Automation automation(0, track);
1986 int grouptype = automation.autogrouptype(i, track);
1987 if(draw) // Do dropshadow
1988 result = do_float_autos(track, autos,
1989 cursor_x, cursor_y, draw,
1990 buttonpress, 1, 1, MDGREY,
1991 auto_keyframe, grouptype);
1993 result = do_float_autos(track, autos,
1994 cursor_x, cursor_y, draw,
1995 buttonpress, 0, 0, auto_colors[i],
1996 auto_keyframe, grouptype);
1999 case Autos::AUTOMATION_TYPE_INT: {
2000 if(draw) // Do dropshadow
2001 result = do_int_autos(track, autos,
2002 cursor_x, cursor_y, draw,
2003 buttonpress, 1, 1, MDGREY,
2005 result = do_int_autos(track, autos,
2006 cursor_x, cursor_y, draw,
2007 buttonpress, 0, 0, auto_colors[i],
2016 if(mwindow->session->current_operation == auto_operations[i])
2019 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2021 // mwindow->session->current_operation,
2022 // auto_operations[i]);
2025 if (buttonpress != 3)
2027 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2028 synchronize_autos(0,
2030 (FloatAuto*)mwindow->session->drag_auto,
2032 mwindow->session->current_operation = pre_auto_operations[i];
2033 update_drag_caption();
2036 else if( auto_keyframe )
2038 gui->keyframe_menu->update(automation,
2041 gui->keyframe_menu->activate_menu();
2042 rerender = 1; // the position changes
2046 gui->keyframe_hide->update(autos);
2047 gui->keyframe_hide->activate_menu();
2048 rerender = 1; // the position changes
2050 if(buttonpress == 1 && ctrl_down() &&
2051 AUTOMATION_TYPE_FLOAT == autos->get_type())
2052 rerender = 1; // special case: curve mode changed
2059 session->auto_conf->plugins /* &&
2060 mwindow->edl->session->show_assets */) {
2063 result = do_plugin_autos(track, cursor_x, cursor_y,
2064 draw, buttonpress, plugin, keyframe);
2065 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2068 if(result && (buttonpress == 1)) {
2069 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2070 update_drag_caption();
2073 else if (result && (buttonpress == 3)) {
2074 gui->keyframe_menu->update(plugin, keyframe);
2075 gui->keyframe_menu->activate_menu();
2076 rerender = 1; // the position changes
2081 // Final pass to trap event
2082 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2083 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2084 mwindow->session->current_operation == auto_operations[i]) {
2090 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2091 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2097 new_cursor = UPRIGHT_ARROW_CURSOR;
2104 void TrackCanvas::draw_keyframe_reticle()
2106 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2107 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2109 int current_op = mwindow->session->current_operation, dragging = 0;
2110 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2111 if( current_op == auto_operations[i] ) dragging = 1;
2113 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2114 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2115 draw_hairline(mwindow->session->drag_auto, RED);
2120 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2121 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2122 for( Track *track = mwindow->edl->tracks->first; track;
2123 track=track->next ) {
2124 Automation *automation = track->automation;
2125 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2126 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2127 // automation visible
2128 Autos *autos = automation->autos[i];
2129 if( !autos ) continue;
2130 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2131 auto_keyframe = auto_keyframe->next ) {
2132 draw_hairline(auto_keyframe, GREEN);
2136 if( dragging && mwindow->session->drag_auto ) {
2137 draw_hairline(mwindow->session->drag_auto, RED);
2143 void TrackCanvas::draw_auto(Auto *current,
2151 x1 = x - HANDLE_W / 2;
2152 x2 = x + HANDLE_W / 2;
2153 y1 = center_pixel + y - HANDLE_W / 2;
2154 y2 = center_pixel + y + HANDLE_W / 2;
2156 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2157 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2159 draw_box(x1, y1, x2 - x1, y2 - y1);
2163 // This draws lines for bezier in & out controls
2164 void TrackCanvas::draw_cropped_line(int x1,
2173 // Don't care about x since it is clipped by the window.
2174 // Put y coords in ascending order
2176 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2177 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2182 double slope = (double)(x2 - x1) / (y2 - y1);
2183 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2185 x1 = (int)(x1 + (min_y - y1) * slope);
2188 else if(y1 >= max_y) {
2189 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2194 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2197 else if(y2 < min_y) {
2198 x2 = (int)(x2 + (min_y - y2) * slope);
2203 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2204 if( y1 >= min_y && y1 < max_y &&
2205 y2 >= min_y && y2 < max_y )
2206 draw_line(x1, y1, x2, y2);
2210 void TrackCanvas::draw_floatauto(FloatAuto *current,
2221 int x1 = x - HANDLE_W / 2; // Center
2222 int x2 = x + HANDLE_W / 2;
2223 int y1 = center_pixel + y - HANDLE_H / 2;
2224 int y2 = center_pixel + y + HANDLE_H / 2;
2225 int ymin = center_pixel - zoom_track / 2;
2226 int ymax = center_pixel + zoom_track / 2;
2227 CLAMP(y1, ymin, ymax);
2228 CLAMP(y2, ymin, ymax);
2233 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2235 draw_box(x1, y1, x2 - x1, y2 - y1);
2238 // show bezier control points (only) if this
2239 // floatauto doesn't adjust it's tangents automatically
2240 if(current->curve_mode != FloatAuto::FREE &&
2241 current->curve_mode != FloatAuto::TFREE)
2245 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2247 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2250 inline int quantize(float f) { return (int)floor(f + 0.5); }
2252 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2253 int x, int y, int cp_x, int cp_y, int center_pixel,
2254 int zoom_track, int color)
2255 // draw the tangent and a handle for given bézier ctrl point
2257 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2259 float slope = (float)(cp_y - y)/(cp_x - x);
2260 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2262 cp_x = x + quantize((cp_y - y) / slope);
2265 cp_y += center_pixel;
2267 // drawing the tangent as a dashed line...
2268 int const dash = HANDLE_W;
2269 int const gap = HANDLE_W / 2;
2270 float sx = 3 * (cp_x - x) / 4.;
2273 // q is the x displacement for a unit line of slope
2274 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2276 float dist = 1/q * sx;
2282 float sy = slope * sx, ey = slope * ex;
2283 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2290 int r = HANDLE_W / 2;
2291 int cp_x1 = cp_x - r;
2292 int cp_y1 = cp_y - r;
2294 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2296 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2301 int TrackCanvas::test_auto(Auto *current,
2302 int x, int y, int center_pixel, int zoom_track,
2303 int cursor_x, int cursor_y, int buttonpress)
2308 x1 = x - HANDLE_W / 2;
2309 x2 = x + HANDLE_W / 2;
2310 y1 = center_pixel + y - HANDLE_H / 2;
2311 y2 = center_pixel + y + HANDLE_H / 2;
2312 int ymin = center_pixel - zoom_track / 2;
2313 int ymax = center_pixel + zoom_track / 2;
2314 CLAMP(y1, ymin, ymax);
2315 CLAMP(y2, ymin, ymax);
2317 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2319 if(buttonpress && buttonpress != 3)
2321 mwindow->session->drag_auto = current;
2322 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2323 // Toggle Autos don't respond to vertical zoom, they always show up
2324 // with "on" == 100% == line on top
2325 mwindow->session->drag_start_position = current->position;
2326 mwindow->session->drag_origin_x = cursor_x;
2327 mwindow->session->drag_origin_y = cursor_y;
2332 if(buttonpress && buttonpress != 3 && result)
2334 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2335 mwindow->undo->update_undo_before();
2341 // some Helpers for test_floatauto(..)
2342 // and for dragging the tangents/ctrl points
2343 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2344 float cursor_x, float cursor_y)
2346 // Control point switched off?
2347 if( x0 == ctrl_x ) return 0.0;
2348 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2349 double x = cursor_x-x0, y = cursor_y-y0;
2350 // wrong side of ctrl handle
2351 if( x*x1 < 0 ) return 0.0;
2352 // outside handle radius
2353 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2354 double xx1 = x1*x1, yy1 = y1*y1;
2355 double xx = x*x, yy = y*y;
2356 // distance squared from cursor to cursor projected to line from ctrl to handle
2357 // along a line perpendicular to line from ctrl to handle (closest approach)
2358 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2359 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2360 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2365 float levered_position(float position, float ref_pos)
2367 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2369 return ref_pos / position;
2373 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2374 // transforms automation value into current display coords,
2375 // dependant on current automation display range for the given kind of automation
2377 if(!mwindow || !mwindow->edl) return 0;
2378 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2379 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2380 float automation_range = automation_max - automation_min;
2381 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2383 return (auto_value - automation_min) / automation_range;
2388 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2389 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2390 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2394 int x1 = x - HANDLE_W / 2;
2395 int x2 = x + HANDLE_W / 2;
2396 int y1 = center_pixel + y - HANDLE_W / 2;
2397 int y2 = center_pixel + y + HANDLE_W / 2;
2398 int ymin = center_pixel - zoom_track / 2;
2399 int ymax = center_pixel + zoom_track / 2;
2400 CLAMP(y1, ymin, ymax);
2401 CLAMP(y2, ymin, ymax);
2403 int in_x1 = in_x - HANDLE_W / 2;
2404 int in_x2 = in_x + HANDLE_W / 2;
2405 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2406 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2407 CLAMP(in_y1, ymin, ymax);
2408 CLAMP(in_y2, ymin, ymax);
2410 int out_x1 = out_x - HANDLE_W / 2;
2411 int out_x2 = out_x + HANDLE_W / 2;
2412 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2413 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2414 CLAMP(out_y1, ymin, ymax);
2415 CLAMP(out_y2, ymin, ymax);
2418 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2419 // buttonpress could be the start of a drag operation
2420 #define INIT_DRAG(POS,VAL) \
2421 mwindow->session->drag_auto = current; \
2422 mwindow->session->drag_origin_x = cursor_x; \
2423 mwindow->session->drag_origin_y = cursor_y; \
2424 mwindow->session->drag_start_position = (POS); \
2425 mwindow->session->drag_start_percentage = (VAL);
2427 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2430 // without modifier we are manipulating the automation node
2431 // with ALT it's about dragging only the value of the node
2432 // with SHIFT the value snaps to the value of neighbouring nodes
2433 // CTRL indicates we are rather manipulating the tangent(s) of the node
2437 if( WITHIN(x1,x2,y1,y2))
2438 { // cursor hits node
2441 if(buttonpress && (buttonpress != 3))
2443 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2444 mwindow->session->drag_handle = 0;
2449 if( WITHIN(x1,x2,y1,y2))
2452 if(buttonpress && (buttonpress != 3))
2454 // could be ctrl-click or ctrl-drag
2455 // click would cycle through tangent modes
2456 ((FloatAuto*)current)->toggle_curve_mode();
2458 // drag will start dragging the tangent, if applicable
2459 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2460 mwindow->session->drag_handle = 0;
2464 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2467 if( in_x != x && current->position > 0 &&
2468 (FloatAuto::FREE == current->curve_mode ||
2469 FloatAuto::TFREE == current->curve_mode))
2470 // act on in control handle only if
2471 // tangent is significant and is editable (not automatically choosen)
2473 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2474 // either cursor in ctrl-point handle or cursor on tangent line
2475 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2477 if(buttonpress && (buttonpress != 3)) {
2478 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2480 mwindow->session->drag_handle = 1;
2481 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2482 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2483 value_to_percentage(new_invalue, autogrouptype))
2490 (FloatAuto::FREE == current->curve_mode ||
2491 FloatAuto::TFREE == current->curve_mode))
2492 // act on out control only if tangent is significant and is editable
2494 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2495 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2497 if(buttonpress && (buttonpress != 3)) {
2498 if(lever == 0.0) lever=1.0;
2500 mwindow->session->drag_handle = 2;
2501 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2502 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2503 value_to_percentage(new_outvalue, autogrouptype))
2507 } // end ctrl_down()
2513 // 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",
2514 // mwindow->session->drag_handle,
2519 if(buttonpress && (buttonpress != 3) && result)
2521 mwindow->undo->update_undo_before();
2528 // Get the float value & y for position x on the canvas
2529 #define X_TO_FLOATLINE(x) \
2530 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2531 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2532 /* Call by reference fails for some reason here */ \
2533 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2534 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2535 double position = unit_start + x * zoom_units; \
2537 if(position2 > position1) \
2540 (value2 - value1) * \
2541 (position - position1) / \
2542 (position2 - position1); \
2548 AUTOMATIONCLAMPS(value, autogrouptype); \
2549 int y = center_pixel + \
2550 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2553 void TrackCanvas::draw_floatline(int center_pixel,
2554 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2555 double unit_start, double zoom_units, double yscale,
2556 int x1, int y1, int x2, int y2,
2557 int color, int autogrouptype)
2559 // Solve bezier equation for either every pixel or a certain large number of
2562 // Not using slope intercept
2564 int prev_y = y1 + center_pixel;
2567 // Call by reference fails for some reason here
2568 FloatAuto *previous1 = previous, *next1 = next;
2569 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2570 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2571 float automation_range = automation_max - automation_min;
2573 for(int x = x1; x < x2; x++)
2575 // Interpolate value between frames
2579 y >= center_pixel - yscale / 2 &&
2580 y < center_pixel + yscale / 2 - 1)
2582 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2584 // (int)(center_pixel - yscale / 2),
2585 // (int)(center_pixel + yscale / 2 - 1));
2587 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2588 draw_line(x - 1, prev_y , x, y );
2598 int TrackCanvas::test_floatline(int center_pixel,
2613 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2614 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2615 float automation_range = automation_max - automation_min;
2616 FloatAuto *previous1 = 0, *next1 = 0;
2617 X_TO_FLOATLINE(cursor_x);
2619 if(cursor_x >= x1 &&
2621 cursor_y >= y - HANDLE_W / 2 &&
2622 cursor_y < y + HANDLE_W / 2 &&
2628 if(buttonpress == 3)
2636 mwindow->undo->update_undo_before();
2637 current = mwindow->session->drag_auto = autos->insert_auto(position1);
2638 ((FloatAuto*)current)->set_value(value);
2639 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2640 mwindow->session->drag_start_position = current->position;
2641 mwindow->session->drag_origin_x = cursor_x;
2642 mwindow->session->drag_origin_y = cursor_y;
2643 mwindow->session->drag_handle = 0;
2652 void TrackCanvas::synchronize_autos(float change,
2653 Track *skip, FloatAuto *fauto, int fill_gangs)
2655 // Handles the special case of modifying a fadeauto
2656 // when there are ganged faders on several tracks
2657 // (skip and fauto may be NULL if fill_gangs==-1)
2659 if( fill_gangs > 0 && skip->gang ) {
2660 double position = skip->from_units(fauto->position);
2661 int autoidx = fauto->autos->autoidx;
2663 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2664 if( (current->data_type == skip->data_type || get_double_click()) &&
2665 current->gang && current->record && current != skip ) {
2666 int64_t current_position = current->to_units(position, 1);
2667 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2668 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2669 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2670 FloatAuto *previous = 0, *next = 0;
2671 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2673 // create keyframe on neighbouring track at the point in time given by fauto
2674 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2675 float new_value = init_value + change;
2676 CLAMP(new_value, auto_min, auto_max);
2677 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2678 keyframe->set_value(new_value);
2681 // keyframe exists, just change it
2682 float new_value = keyframe->get_value() + change;
2683 CLAMP(new_value, auto_min, auto_max);
2684 keyframe->adjust_to_new_coordinates(current_position, new_value);
2685 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2688 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2692 else if( !fill_gangs ) {
2693 double position = skip->from_units(fauto->position);
2695 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2696 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2697 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2698 float new_value = keyframe->get_value() + change;
2700 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2701 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2702 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2708 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2709 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2710 keyframe->autos->remove_nonsequential(
2713 mwindow->session->drag_auto_gang->remove_all();
2718 void TrackCanvas::draw_toggleline(int center_pixel,
2724 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2728 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2732 int TrackCanvas::test_toggleline(Autos *autos,
2743 if(cursor_x >= x1 && cursor_x < x2)
2745 int miny = center_pixel + y1 - HANDLE_W / 2;
2746 int maxy = center_pixel + y1 + HANDLE_W / 2;
2747 if(cursor_y >= miny && cursor_y < maxy)
2752 if(buttonpress == 3)
2760 double position = (double)(cursor_x +
2761 mwindow->edl->local_session->view_start[pane->number]) *
2762 mwindow->edl->local_session->zoom_sample /
2763 mwindow->edl->session->sample_rate;
2764 int64_t unit_position = autos->track->to_units(position, 0);
2765 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2767 mwindow->undo->update_undo_before();
2769 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2770 ((IntAuto*)current)->value = new_value;
2771 // Toggle Autos don't respond to vertical zoom, they always show up
2772 // with "on" == 100% == line on top
2773 mwindow->session->drag_start_percentage = (float)new_value;
2774 mwindow->session->drag_start_position = current->position;
2775 mwindow->session->drag_origin_x = cursor_x;
2776 mwindow->session->drag_origin_y = cursor_y;
2784 void TrackCanvas::calculate_viewport(Track *track,
2785 double &view_start, // Seconds
2787 double &view_end, // Seconds
2791 double &zoom_sample,
2794 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2795 mwindow->edl->local_session->zoom_sample /
2796 mwindow->edl->session->sample_rate;
2797 unit_start = track->to_doubleunits(view_start);
2798 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2800 mwindow->edl->local_session->zoom_sample /
2801 mwindow->edl->session->sample_rate;
2802 unit_end = track->to_doubleunits(view_end);
2803 yscale = mwindow->edl->local_session->zoom_track;
2804 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2805 center_pixel = (int)(track->y_pixel -
2806 mwindow->edl->local_session->track_start[pane->number] +
2808 (mwindow->edl->session->show_titles ?
2809 mwindow->theme->get_image("title_bg_data")->get_h() :
2811 zoom_sample = mwindow->edl->local_session->zoom_sample;
2813 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2816 float TrackCanvas::percentage_to_value(float percentage,
2824 if(percentage > 0.5)
2831 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2832 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2833 float automation_range = automation_max - automation_min;
2835 result = percentage * automation_range + automation_min;
2838 FloatAuto *ptr = (FloatAuto*)reference;
2839 result -= ptr->get_value();
2841 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2847 void TrackCanvas::calculate_auto_position(double *x, double *y,
2848 double *in_x, double *in_y, double *out_x, double *out_y,
2849 Auto *current, double unit_start, double zoom_units, double yscale,
2852 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2853 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2854 float automation_range = automation_max - automation_min;
2855 FloatAuto *ptr = (FloatAuto*)current;
2856 *x = (double)(ptr->position - unit_start) / zoom_units;
2857 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2860 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2861 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2865 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2866 automation_min) / automation_range - 0.5) * -yscale;
2870 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2871 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2875 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2876 automation_min) / automation_range - 0.5) * -yscale;
2881 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2882 int draw, int buttonpress, int x_offset, int y_offset, int color,
2883 Auto* &auto_instance, int autogrouptype)
2886 int center_pixel, draw_auto;
2887 double view_start, unit_start;
2888 double view_end, unit_end, yscale;
2889 double zoom_sample, zoom_units;
2890 double in_x2, in_y2, out_x2, out_y2;
2896 if(draw) set_color(color);
2898 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2899 yscale, center_pixel, zoom_sample, zoom_units);
2901 // Get first auto before start
2902 Auto *current = 0, *previous = 0;
2904 for( current = autos->last;
2905 current && current->position >= unit_start;
2906 current = PREVIOUS ) ;
2908 Auto *first_auto = current ? current :
2909 autos->first ? autos->first : autos->default_auto;
2911 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2913 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2914 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2919 current = autos->first;
2928 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2929 current, unit_start, zoom_units, yscale, autogrouptype);
2937 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2942 ay2 = ay + slope * (get_w() - ax);
2946 ay = ay + slope * (0 - ax);
2950 // Draw or test handle
2951 if( current && !result && current != autos->default_auto ) {
2952 if( !draw && track->record ) {
2953 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
2954 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
2955 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
2956 buttonpress, autogrouptype);
2958 auto_instance = current;
2960 if( draw && draw_auto ) {
2961 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
2962 (int)in_x2 + x_offset, (int)in_y2,
2963 (int)out_x2 + x_offset, (int)out_y2,
2964 (int)center_pixel + y_offset, (int)yscale, color);
2968 // Draw or test joining line
2969 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
2970 result = test_floatline(center_pixel,
2971 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2972 // Exclude auto coverage from the end of the line. The auto overlaps
2973 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
2974 buttonpress, autogrouptype);
2977 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
2978 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2979 (int)ax, (int)ay, (int)ax2, (int)ay2,
2980 color, autogrouptype);
2988 } while( current && current->position <= unit_end && !result );
2990 if( ax < get_w() && !result ) {
2991 ax2 = get_w(); ay2 = ay;
2992 if(!draw && track->record /* && buttonpress != 3 */ ) {
2993 result = test_floatline(center_pixel,
2994 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2995 (int)ax, (int)ax2, cursor_x, cursor_y,
2996 buttonpress, autogrouptype);
2999 draw_floatline(center_pixel,
3000 (FloatAuto*)previous, (FloatAuto*)current,
3001 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3002 (int)ax, (int)ay, (int)ax2, (int)ay2,
3003 color, autogrouptype);
3010 int TrackCanvas::do_int_autos(Track *track,
3019 Auto *&auto_instance)
3030 double ax, ay, ax2, ay2;
3034 if(draw) set_color(color);
3036 calculate_viewport(track,
3047 double high = -yscale * 0.8 / 2;
3048 double low = yscale * 0.8 / 2;
3050 // Get first auto before start
3052 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3058 ay = ((IntAuto*)current)->value > 0 ? high : low;
3063 current = autos->first ? autos->first : autos->default_auto;
3067 ay = ((IntAuto*)current)->value > 0 ? high : low;
3080 ax2 = (double)(current->position - unit_start) / zoom_units;
3081 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3089 if(ax2 > get_w()) ax2 = get_w();
3091 if(current && !result)
3093 if(current != autos->default_auto)
3099 result = test_auto(current,
3108 auto_instance = current;
3113 (int)ax2 + x_offset,
3114 (int)ay2 + y_offset,
3126 if(track->record /* && buttonpress != 3 */)
3128 result = test_toggleline(autos,
3141 draw_toggleline(center_pixel + y_offset,
3149 }while(current && current->position <= unit_end && !result);
3151 if(ax < get_w() && !result)
3157 if(track->record /* && buttonpress != 3 */)
3159 result = test_toggleline(autos,
3171 draw_toggleline(center_pixel + y_offset,
3180 int TrackCanvas::do_autos(Track *track,
3187 Auto * &auto_instance,
3201 calculate_viewport(track,
3214 for(current = autos->first; current && !result; current = NEXT)
3216 if(current->position >= unit_start && current->position < unit_end)
3219 x = (int64_t)((double)(current->position - unit_start) /
3220 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3221 y = center_pixel - pixmap->get_h() / 2;
3225 if(cursor_x >= x && cursor_y >= y &&
3226 cursor_x < x + pixmap->get_w() &&
3227 cursor_y < y + pixmap->get_h())
3230 auto_instance = current;
3232 if(buttonpress && (buttonpress != 3))
3234 mwindow->session->drag_auto = current;
3235 mwindow->session->drag_start_position = current->position;
3236 mwindow->session->drag_origin_x = cursor_x;
3237 mwindow->session->drag_origin_y = cursor_y;
3239 double position = autos->track->from_units(current->position);
3240 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3241 mwindow->edl->local_session->get_selectionend(1)) /
3246 mwindow->edl->local_session->set_selectionstart(position);
3247 mwindow->edl->local_session->set_selectionend(position);
3250 if(position < center)
3252 mwindow->edl->local_session->set_selectionstart(position);
3255 mwindow->edl->local_session->set_selectionend(position);
3262 draw_pixmap(pixmap, x, y);
3270 // so this means it is always >0 when keyframe is found
3271 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3272 int draw, int buttonpress, Plugin* &keyframe_plugin,
3273 KeyFrame* &keyframe_instance)
3286 if(!track->expand_view) return 0;
3288 calculate_viewport(track,
3300 for(int i = 0; i < track->plugin_set.total && !result; i++)
3302 PluginSet *plugin_set = track->plugin_set.values[i];
3303 int center_pixel = (int)(track->y_pixel -
3304 mwindow->edl->local_session->track_start[pane->number] +
3305 mwindow->edl->local_session->zoom_track +
3306 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3307 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3309 for(Plugin *plugin = (Plugin*)plugin_set->first;
3311 plugin = (Plugin*)plugin->next)
3313 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3314 keyframe && !result;
3315 keyframe = (KeyFrame*)keyframe->next)
3317 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3318 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3320 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3321 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3323 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3326 if(cursor_x >= x && cursor_y >= y &&
3327 cursor_x < x + keyframe_pixmap->get_w() &&
3328 cursor_y < y + keyframe_pixmap->get_h())
3331 keyframe_plugin = plugin;
3332 keyframe_instance = keyframe;
3336 mwindow->session->drag_auto = keyframe;
3337 mwindow->session->drag_start_position = keyframe->position;
3338 mwindow->session->drag_origin_x = cursor_x;
3339 mwindow->session->drag_origin_y = cursor_y;
3341 double position = track->from_units(keyframe->position);
3342 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3343 mwindow->edl->local_session->get_selectionend(1)) /
3348 mwindow->edl->local_session->set_selectionstart(position);
3349 mwindow->edl->local_session->set_selectionend(position);
3352 if(position < center)
3354 mwindow->edl->local_session->set_selectionstart(position);
3357 mwindow->edl->local_session->set_selectionend(position);
3362 draw_pixmap(keyframe_pixmap,
3372 // if(buttonpress && buttonpress != 3 && result)
3374 // mwindow->undo->update_undo_before();
3380 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3382 Track *track = auto_keyframe->autos->track;
3383 int autogrouptype = auto_keyframe->autos->get_type();
3386 double view_start, unit_start;
3387 double view_end, unit_end, yscale;
3388 double zoom_sample, zoom_units;
3390 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3391 yscale, center_pixel, zoom_sample, zoom_units);
3393 double ax = 0, ay = 0;
3394 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3395 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3398 draw_line(ax, 0, ax, get_h());
3402 void TrackCanvas::draw_overlays()
3404 int new_cursor, update_cursor, rerender;
3406 // Move background pixmap to foreground pixmap
3407 draw_pixmap(background_pixmap,
3416 draw_inout_points();
3419 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3426 draw_brender_start();
3428 // Highlighted areas
3429 draw_highlighting();
3432 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3435 if(pane->cursor) pane->cursor->restore(1);
3441 draw_playback_cursor();
3443 draw_keyframe_reticle();
3448 int TrackCanvas::activate()
3452 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3453 //BC_Signals::dump_stack();
3454 get_top_level()->deactivate();
3456 set_active_subwindow(this);
3457 pane->cursor->activate();
3458 gui->focused_pane = pane->number;
3463 int TrackCanvas::deactivate()
3468 pane->cursor->deactivate();
3474 void TrackCanvas::update_drag_handle()
3476 double new_position;
3479 (double)(get_cursor_x() +
3480 mwindow->edl->local_session->view_start[pane->number]) *
3481 mwindow->edl->local_session->zoom_sample /
3482 mwindow->edl->session->sample_rate;
3484 mwindow->edl->align_to_frame(new_position, 0);
3487 if(new_position != mwindow->session->drag_position)
3489 mwindow->session->drag_position = new_position;
3490 gui->mainclock->update(new_position);
3493 timebar_position = new_position;
3494 gui->update_timebar(0);
3495 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3497 // mwindow->cwindow->update(1, 0, 0);
3501 int TrackCanvas::update_drag_edit()
3510 int TrackCanvas::get_drag_values(float *percentage,
3517 //int x = cursor_x - mwindow->session->drag_origin_x;
3518 //int y = cursor_y - mwindow->session->drag_origin_y;
3522 if(!current->autos->track->record) return 1;
3532 calculate_viewport(current->autos->track,
3542 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3544 mwindow->session->drag_start_percentage;
3545 if(do_clamp) CLAMP(*percentage, 0, 1);
3547 *position = Units::to_int64(zoom_units *
3548 (cursor_x - mwindow->session->drag_origin_x) +
3549 mwindow->session->drag_start_position + 0.5);
3551 if((do_clamp) && *position < 0) *position = 0;
3556 #define UPDATE_DRAG_HEAD(do_clamp) \
3557 int result = 0, center_pixel; \
3558 if(!current->autos->track->record) return 0; \
3559 double view_start, unit_start, view_end, unit_end; \
3560 double yscale, zoom_sample, zoom_units; \
3562 calculate_viewport(current->autos->track, \
3563 view_start, unit_start, view_end, unit_end, \
3564 yscale, center_pixel, zoom_sample, zoom_units); \
3566 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3567 yscale + mwindow->session->drag_start_percentage; \
3568 if(do_clamp) CLAMP(percentage, 0, 1); \
3570 int64_t position = Units::to_int64(zoom_units * \
3571 (cursor_x - mwindow->session->drag_origin_x) + \
3572 mwindow->session->drag_start_position); \
3573 if((do_clamp) && position < 0) position = 0;
3576 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3578 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3580 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3581 int x = cursor_x - mwindow->session->drag_origin_x;
3582 int y = cursor_y - mwindow->session->drag_origin_y;
3583 float value, old_value;
3585 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3586 // not really editing the node, rather start editing the curve
3587 // tangent is editable and drag movement is significant
3588 if( (FloatAuto::FREE == current->curve_mode ||
3589 FloatAuto::TFREE==current->curve_mode) &&
3590 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3591 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3594 switch(mwindow->session->drag_handle) {
3596 // Snap to nearby values
3597 old_value = current->get_value();
3599 double value1, value2, distance1, distance2;
3601 if(current->previous) {
3602 int autogrouptype = current->previous->autos->autogrouptype;
3603 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3604 value1 = ((FloatAuto*)current->previous)->get_value();
3605 distance1 = fabs(value - value1);
3606 current->set_value(value1);
3610 int autogrouptype = current->next->autos->autogrouptype;
3611 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3612 value2 = ((FloatAuto*)current->next)->get_value();
3613 distance2 = fabs(value - value2);
3614 if(!current->previous || distance2 < distance1) {
3615 current->set_value(value2);
3619 if(!current->previous && !current->next) {
3620 current->set_value( ((FloatAutos*)current->autos)->default_);
3622 value = current->get_value();
3625 int autogrouptype = current->autos->autogrouptype;
3626 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3629 if(alt_down() && !shift_down())
3630 // ALT constrains movement: fixed position, only changing the value
3631 position = mwindow->session->drag_start_position;
3633 if(value != old_value || position != current->position) {
3635 float change = value - old_value;
3636 current->adjust_to_new_coordinates(position, value);
3637 synchronize_autos(change, current->autos->track, current, 0);
3638 show_message(current, 1,", %.2f", current->get_value());
3644 int autogrouptype = current->autos->autogrouptype;
3645 value = percentage_to_value(percentage, 0, current, autogrouptype);
3646 if(value != current->get_control_in_value())
3649 // note: (position,value) need not be at the location of the ctrl point,
3650 // but could be somewhere in between on the curve (or even outward or
3651 // on the opposit side). We set the new control point such as
3652 // to point the curve through (position,value)
3653 current->set_control_in_value(
3654 value * levered_position(position - current->position,
3655 current->get_control_in_position()));
3656 synchronize_autos(0, current->autos->track, current, 0);
3657 show_message(current, 1,", %.2f", current->get_control_in_value());
3663 int autogrouptype = current->autos->autogrouptype;
3664 value = percentage_to_value(percentage, 0, current, autogrouptype);
3665 if(value != current->get_control_out_value()) {
3667 current->set_control_out_value(
3668 value * levered_position(position - current->position,
3669 current->get_control_out_position()));
3670 synchronize_autos(0, current->autos->track, current, 0);
3671 show_message(current, 1,", %.2f", current->get_control_out_value());
3679 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3681 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3683 UPDATE_DRAG_HEAD(1);
3684 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3686 if(value != current->value || position != current->position)
3689 current->value = value;
3690 current->position = position;
3691 show_message(current, 0,", %d", current->value);
3697 // Autos which can't change value through dragging.
3699 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3701 Auto *current = (Auto*)mwindow->session->drag_auto;
3704 if(position != current->position)
3707 current->position = position;
3708 show_message(current, 0,"");
3710 double position_f = current->autos->track->from_units(current->position);
3711 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3712 mwindow->edl->local_session->get_selectionend(1)) /
3716 mwindow->edl->local_session->set_selectionstart(position_f);
3717 mwindow->edl->local_session->set_selectionend(position_f);
3720 if(position_f < center_f)
3722 mwindow->edl->local_session->set_selectionstart(position_f);
3725 mwindow->edl->local_session->set_selectionend(position_f);
3732 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3734 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3737 if(position != current->position)
3739 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3740 Track *track = current->autos->track;
3741 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3742 PluginSet *pluginset;
3744 // figure out the correct pluginset & correct plugin
3746 for(int i = 0; i < track->plugin_set.total; i++)
3748 pluginset = track->plugin_set.values[i];
3749 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3751 KeyFrames *keyframes = plugin->keyframes;
3752 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3754 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3756 if (currentkeyframe == current)
3768 mwindow->session->plugin_highlighted = plugin;
3769 mwindow->session->track_highlighted = track;
3771 current->position = position;
3772 show_message(current, 0,"");
3774 double position_f = current->autos->track->from_units(current->position);
3775 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3776 mwindow->edl->local_session->get_selectionend(1)) /
3780 mwindow->edl->local_session->set_selectionstart(position_f);
3781 mwindow->edl->local_session->set_selectionend(position_f);
3784 if(position_f < center_f)
3786 mwindow->edl->local_session->set_selectionstart(position_f);
3789 mwindow->edl->local_session->set_selectionend(position_f);
3796 void TrackCanvas::update_drag_caption()
3798 switch(mwindow->session->current_operation)
3808 int TrackCanvas::cursor_motion_event()
3813 int update_clock = 0;
3814 int update_zoom = 0;
3815 int update_scroll = 0;
3816 int update_overlay = 0;
3817 int update_cursor = 0;
3820 double position = 0.;
3821 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3824 switch(mwindow->edl->session->editing_mode)
3826 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3827 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3830 switch(mwindow->session->current_operation)
3832 case DRAG_EDITHANDLE1:
3833 // Outside threshold. Upgrade status
3836 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3838 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3844 case DRAG_EDITHANDLE2:
3847 update_drag_handle();
3852 case DRAG_PLUGINHANDLE1:
3855 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3857 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3863 case DRAG_PLUGINHANDLE2:
3866 update_drag_handle();
3871 // Rubber band curves
3879 case DRAG_PROJECTOR_X:
3880 case DRAG_PROJECTOR_Y:
3881 case DRAG_PROJECTOR_Z:
3882 if(active) rerender = update_overlay =
3883 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3887 if(active) rerender = update_overlay =
3888 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3892 if(active) rerender = update_overlay =
3893 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3896 // Keyframe icons are sticky
3900 case DRAG_PLUGINKEY_PRE:
3902 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3903 mwindow->session->current_operation++;
3906 mwindow->undo->update_undo_before();
3914 if(active) rerender = update_overlay =
3915 update_drag_auto(get_cursor_x(), get_cursor_y());
3918 case DRAG_PLUGINKEY:
3919 if(active) rerender = update_overlay =
3920 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
3925 cursor_x = get_cursor_x();
3926 cursor_y = get_cursor_y();
3927 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
3928 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
3930 position = mwindow->edl->align_to_frame(position, 0);
3931 position = MAX(position, 0);
3933 if(position < selection_midpoint) {
3934 mwindow->edl->local_session->set_selectionend(selection_midpoint);
3935 mwindow->edl->local_session->set_selectionstart(position);
3937 gui->unlock_window();
3938 mwindow->cwindow->update(1, 0, 0, 0, 1);
3939 gui->lock_window("TrackCanvas::cursor_motion_event 1");
3940 // Update the faders
3941 mwindow->update_plugin_guis();
3942 gui->update_patchbay();
3945 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
3946 mwindow->edl->local_session->set_selectionend(position);
3947 // Don't que the CWindow
3950 timebar_position = mwindow->edl->local_session->get_selectionend(1);
3952 gui->hide_cursor(0);
3953 gui->draw_cursor(1);
3954 gui->update_timebar(0);
3955 gui->flash_canvas(1);
3964 if(is_event_win() && cursor_inside()) {
3966 cursor_x = get_cursor_x();
3967 position = (double)cursor_x *
3968 (double)mwindow->edl->local_session->zoom_sample /
3969 (double)mwindow->edl->session->sample_rate +
3970 (double)mwindow->edl->local_session->view_start[pane->number] *
3971 (double)mwindow->edl->local_session->zoom_sample /
3972 (double)mwindow->edl->session->sample_rate;
3973 position = mwindow->edl->align_to_frame(position, 0);
3977 for(int i = 0; i < TOTAL_PANES; i++)
3978 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
3980 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
3981 gui->update_timebar(0);
3983 if(do_transitions(get_cursor_x(), get_cursor_y(),
3984 0, new_cursor, update_cursor)) break;
3985 if(do_keyframes(get_cursor_x(), get_cursor_y(),
3986 0, 0, new_cursor, update_cursor, rerender)) break;
3987 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
3988 0, rerender, update_overlay, new_cursor, update_cursor)) break;
3989 // Plugin boundaries
3990 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
3991 0, rerender, update_overlay, new_cursor, update_cursor)) break;
3992 if(do_edits(get_cursor_x(), get_cursor_y(),
3993 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
3998 //printf("TrackCanvas::cursor_motion_event 1\n");
3999 if(update_cursor && new_cursor != get_cursor())
4001 set_cursor(new_cursor, 0, 1);
4004 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
4005 if(rerender && render_timer->get_difference() > 0.25 ) {
4006 render_timer->update();
4007 mwindow->restart_brender();
4008 mwindow->sync_parameters(CHANGE_PARAMS);
4009 mwindow->update_plugin_guis();
4010 gui->unlock_window();
4011 mwindow->cwindow->update(1, 0, 0, 0, 1);
4012 gui->lock_window("TrackCanvas::cursor_motion_event 2");
4016 gui->update_patchbay();
4021 if(!mwindow->cwindow->playback_engine->is_playing_back)
4022 gui->mainclock->update(position);
4026 gui->zoombar->update();
4031 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4035 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4039 if(update_overlay) {
4040 gui->draw_overlays(1);
4043 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
4047 void TrackCanvas::start_dragscroll()
4051 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4052 //printf("TrackCanvas::start_dragscroll 1\n");
4056 void TrackCanvas::stop_dragscroll()
4060 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4061 //printf("TrackCanvas::stop_dragscroll 1\n");
4065 int TrackCanvas::repeat_event(int64_t duration)
4067 if(!drag_scroll) return 0;
4068 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4070 int sample_movement = 0;
4071 int track_movement = 0;
4072 int64_t x_distance = 0;
4073 int64_t y_distance = 0;
4074 double position = 0;
4077 switch(mwindow->session->current_operation) {
4079 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4080 if(get_cursor_x() > get_w()) {
4081 x_distance = get_cursor_x() - get_w();
4082 sample_movement = 1;
4084 else if(get_cursor_x() < 0) {
4085 x_distance = get_cursor_x();
4086 sample_movement = 1;
4089 if(get_cursor_y() > get_h()) {
4090 y_distance = get_cursor_y() - get_h();
4093 else if(get_cursor_y() < 0) {
4094 y_distance = get_cursor_y();
4101 if(sample_movement) {
4102 position = (double)(get_cursor_x() +
4103 mwindow->edl->local_session->view_start[pane->number] +
4105 mwindow->edl->local_session->zoom_sample /
4106 mwindow->edl->session->sample_rate;
4107 position = mwindow->edl->align_to_frame(position, 0);
4108 position = MAX(position, 0);
4110 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4111 switch(mwindow->session->current_operation) {
4113 if(position < selection_midpoint) {
4114 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4115 mwindow->edl->local_session->set_selectionstart(position);
4117 gui->unlock_window();
4118 mwindow->cwindow->update(1, 0, 0);
4119 gui->lock_window("TrackCanvas::repeat_event");
4120 // Update the faders
4121 mwindow->update_plugin_guis();
4122 gui->update_patchbay();
4125 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4126 mwindow->edl->local_session->set_selectionend(position);
4127 // Don't que the CWindow
4132 mwindow->samplemovement(
4133 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4137 if(track_movement) {
4138 mwindow->trackmovement(y_distance, pane->number);
4144 int TrackCanvas::button_release_event()
4146 int redraw = 0, update_overlay = 0, result = 0;
4148 // printf("TrackCanvas::button_release_event %d\n",
4149 // mwindow->session->current_operation);
4151 switch(mwindow->session->current_operation) {
4152 case DRAG_EDITHANDLE2:
4153 mwindow->session->current_operation = NO_OPERATION;
4157 end_edithandle_selection();
4160 case DRAG_EDITHANDLE1:
4161 mwindow->session->current_operation = NO_OPERATION;
4166 case DRAG_PLUGINHANDLE2:
4167 mwindow->session->current_operation = NO_OPERATION;
4171 end_pluginhandle_selection();
4174 case DRAG_PLUGINHANDLE1:
4175 mwindow->session->current_operation = NO_OPERATION;
4182 // delete the drag_auto_gang first and remove out of order keys
4183 synchronize_autos(0, 0, 0, -1);
4194 case DRAG_PROJECTOR_X:
4195 case DRAG_PROJECTOR_Y:
4196 case DRAG_PROJECTOR_Z:
4197 case DRAG_PLUGINKEY:
4198 mwindow->session->current_operation = NO_OPERATION;
4199 mwindow->session->drag_handle = 0;
4200 // Remove any out-of-order keyframe
4201 if(mwindow->session->drag_auto) {
4202 mwindow->session->drag_auto->autos->remove_nonsequential(
4203 mwindow->session->drag_auto);
4204 // mwindow->session->drag_auto->autos->optimize();
4209 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4214 case DRAG_AEFFECT_COPY:
4215 case DRAG_VEFFECT_COPY:
4216 // Trap in drag stop
4221 if(mwindow->session->current_operation) {
4222 // if(mwindow->session->current_operation == SELECT_REGION) {
4223 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4226 mwindow->session->current_operation = NO_OPERATION;
4228 // Traps button release events
4236 cursor_motion_event();
4238 if(update_overlay) {
4239 gui->draw_overlays(1);
4242 gui->draw_canvas(NORMAL_DRAW, 0);
4247 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4248 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4250 Edit *edit_result = 0;
4251 int handle_result = 0;
4254 if(!mwindow->edl->session->show_assets) return 0;
4256 for(Track *track = mwindow->edl->tracks->first;
4258 track = track->next) {
4259 for(Edit *edit = track->edits->first;
4261 edit = edit->next) {
4262 int64_t edit_x, edit_y, edit_w, edit_h;
4263 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4265 if(cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4266 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4267 if(cursor_x < edit_x + HANDLE_W) {
4272 else if(cursor_x >= edit_x + edit_w - HANDLE_W) {
4286 double position = 0;
4287 if(handle_result == 0) {
4288 position = edit_result->track->from_units(edit_result->startproject);
4289 new_cursor = LEFT_CURSOR;
4291 else if(handle_result == 1) {
4292 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4293 new_cursor = RIGHT_CURSOR;
4296 // Reposition cursor
4298 mwindow->session->drag_edit = edit_result;
4299 mwindow->session->drag_handle = handle_result;
4300 mwindow->session->drag_button = get_buttonpress() - 1;
4301 mwindow->session->drag_position = position;
4302 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4303 mwindow->session->drag_origin_x = get_cursor_x();
4304 mwindow->session->drag_origin_y = get_cursor_y();
4305 mwindow->session->drag_start = position;
4307 rerender = start_selection(position);
4315 int TrackCanvas::do_plugin_handles(int cursor_x,
4319 int &update_overlay,
4323 Plugin *plugin_result = 0;
4324 int handle_result = 0;
4327 // if(!mwindow->edl->session->show_assets) return 0;
4329 for(Track *track = mwindow->edl->tracks->first;
4331 track = track->next) {
4332 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4333 PluginSet *plugin_set = track->plugin_set.values[i];
4334 for(Plugin *plugin = (Plugin*)plugin_set->first;
4336 plugin = (Plugin*)plugin->next) {
4337 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4338 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4340 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4341 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4342 if(cursor_x < plugin_x + HANDLE_W) {
4343 plugin_result = plugin;
4347 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4348 plugin_result = plugin;
4355 if(result && shift_down())
4356 mwindow->session->trim_edits = plugin_set;
4362 double position = 0;
4363 if(handle_result == 0) {
4364 position = plugin_result->track->from_units(plugin_result->startproject);
4365 new_cursor = LEFT_CURSOR;
4367 else if(handle_result == 1) {
4368 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4369 new_cursor = RIGHT_CURSOR;
4373 mwindow->session->drag_plugin = plugin_result;
4374 mwindow->session->drag_handle = handle_result;
4375 mwindow->session->drag_button = get_buttonpress() - 1;
4376 mwindow->session->drag_position = position;
4377 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4378 mwindow->session->drag_origin_x = get_cursor_x();
4379 mwindow->session->drag_origin_y = get_cursor_y();
4380 mwindow->session->drag_start = position;
4382 rerender = start_selection(position);
4391 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4395 // if(!mwindow->edl->session->show_assets) return 0;
4397 for(Track *track = mwindow->edl->tracks->first;
4399 track = track->next) {
4400 int64_t track_x, track_y, track_w, track_h;
4401 track_dimensions(track, track_x, track_y, track_w, track_h);
4403 if(button_press && get_buttonpress() == 3 &&
4404 cursor_y >= track_y && cursor_y < track_y + track_h) {
4405 gui->edit_menu->update(track, 0);
4406 gui->edit_menu->activate_menu();
4414 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4415 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4419 if(!mwindow->edl->session->show_assets) return 0;
4421 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4423 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4424 int64_t edit_x, edit_y, edit_w, edit_h;
4425 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4427 // Cursor inside a track
4428 // Cursor inside an edit
4429 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4430 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4431 // Select duration of edit
4433 if(get_double_click() && !drag_start) {
4434 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4435 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4436 edit->track->from_units(edit->length));
4437 if(mwindow->edl->session->cursor_on_frames)
4439 mwindow->edl->local_session->set_selectionstart(
4440 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4441 mwindow->edl->local_session->set_selectionend(
4442 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4450 else if(drag_start && track->record) {
4451 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4452 // Need to create drag window
4453 mwindow->session->current_operation = DRAG_EDIT;
4454 mwindow->session->drag_edit = edit;
4455 //printf("TrackCanvas::do_edits 2\n");
4457 // Drag only one edit if ctrl is initially down
4459 mwindow->session->drag_edits->remove_all();
4460 mwindow->session->drag_edits->append(edit);
4463 // Construct list of all affected edits
4464 mwindow->edl->tracks->get_affected_edits(
4465 mwindow->session->drag_edits,
4466 edit->track->from_units(edit->startproject),
4469 mwindow->session->drag_origin_x = cursor_x;
4470 mwindow->session->drag_origin_y = cursor_y;
4471 // Where the drag started, so we know relative position inside the edit later
4472 mwindow->session->drag_position = (double)cursor_x *
4473 mwindow->edl->local_session->zoom_sample /
4474 mwindow->edl->session->sample_rate +
4475 (double)mwindow->edl->local_session->view_start[pane->number] *
4476 mwindow->edl->local_session->zoom_sample /
4477 mwindow->edl->session->sample_rate;
4479 gui->drag_popup = new BC_DragWindow(gui,
4480 mwindow->theme->get_image("clip_icon") /*,
4481 get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
4482 get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
4494 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4499 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4500 int button_press, int &redraw, int &rerender)
4509 // if(!mwindow->edl->session->show_assets) return 0;
4512 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4513 if(!track->expand_view) continue;
4515 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4516 // first check if plugins are visible at all
4517 if (!track->expand_view)
4519 PluginSet *plugin_set = track->plugin_set.values[i];
4520 for(plugin = (Plugin*)plugin_set->first;
4522 plugin = (Plugin*)plugin->next) {
4523 plugin_dimensions(plugin, x, y, w, h);
4524 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4525 MWindowGUI::visible(y, y + h, 0, get_h())) {
4526 if(cursor_x >= x && cursor_x < x + w &&
4527 cursor_y >= y && cursor_y < y + h) {
4537 // Start plugin popup
4539 if(get_buttonpress() == 3) {
4540 gui->plugin_menu->update(plugin);
4541 gui->plugin_menu->activate_menu();
4544 else if (get_double_click() && !drag_start) {
4545 // Select range of plugin on doubleclick over plugin
4546 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4547 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4548 plugin->track->from_units(plugin->length));
4549 if(mwindow->edl->session->cursor_on_frames) {
4550 mwindow->edl->local_session->set_selectionstart(
4551 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4552 mwindow->edl->local_session->set_selectionend(
4553 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4562 if(drag_start && plugin->track->record) {
4563 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4564 if(plugin->track->data_type == TRACK_AUDIO)
4565 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4566 else if(plugin->track->data_type == TRACK_VIDEO)
4567 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4569 mwindow->session->drag_plugin = plugin;
4570 mwindow->session->drag_origin_x = cursor_x;
4571 mwindow->session->drag_origin_y = cursor_y;
4572 // Where the drag started, so we know relative position inside the edit later
4573 mwindow->session->drag_position =
4574 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4575 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4577 switch(plugin->plugin_type) {
4578 case PLUGIN_STANDALONE: {
4579 PluginServer *server =
4580 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4581 if( !server ) break;
4582 VFrame *frame = server->picon;
4584 if(plugin->track->data_type == TRACK_AUDIO) {
4585 frame = mwindow->theme->get_image("aeffect_icon");
4588 frame = mwindow->theme->get_image("veffect_icon");
4592 gui->drag_popup = new BC_DragWindow(gui, frame /*,
4593 get_abs_cursor_x(0) - frame->get_w() / 2,
4594 get_abs_cursor_y(0) - frame->get_h() / 2 */);
4597 case PLUGIN_SHAREDPLUGIN:
4598 case PLUGIN_SHAREDMODULE:
4599 gui->drag_popup = new BC_DragWindow(gui,
4600 mwindow->theme->get_image("clip_icon") /*,
4601 get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
4602 get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
4614 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4615 int button_press, int &new_cursor, int &update_cursor)
4617 Transition *transition = 0;
4621 if(/* !mwindow->edl->session->show_assets || */
4622 !mwindow->edl->session->auto_conf->transitions) return 0;
4624 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4626 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4627 if( edit->transition ) {
4628 edit_dimensions(edit, x, y, w, h);
4629 get_transition_coords(x, y, w, h);
4631 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4632 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4633 if( cursor_x >= x && cursor_x < x + w &&
4634 cursor_y >= y && cursor_y < y + h ) {
4635 transition = edit->transition;
4647 new_cursor = UPRIGHT_ARROW_CURSOR;
4649 else if(get_buttonpress() == 3) {
4650 gui->transition_menu->update(transition);
4651 gui->transition_menu->activate_menu();
4658 int TrackCanvas::button_press_event()
4661 int cursor_x, cursor_y;
4664 cursor_x = get_cursor_x();
4665 cursor_y = get_cursor_y();
4666 mwindow->session->trim_edits = 0;
4668 if(is_event_win() && cursor_inside()) {
4669 // double position = (double)cursor_x *
4670 // mwindow->edl->local_session->zoom_sample /
4671 // mwindow->edl->session->sample_rate +
4672 // (double)mwindow->edl->local_session->view_start[pane->number] *
4673 // mwindow->edl->local_session->zoom_sample /
4674 // mwindow->edl->session->sample_rate;
4681 if( get_buttonpress() == LEFT_BUTTON ) {
4682 gui->unlock_window();
4683 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4684 gui->lock_window("TrackCanvas::button_press_event");
4687 int update_overlay = 0, update_cursor = 0, rerender = 0;
4689 if(get_buttonpress() == WHEEL_UP) {
4691 mwindow->expand_sample();
4692 else if(ctrl_down())
4693 mwindow->move_left(get_w()/ 10);
4695 mwindow->move_up(get_h() / 10);
4697 else if(get_buttonpress() == WHEEL_DOWN) {
4699 mwindow->zoom_in_sample();
4700 else if(ctrl_down())
4701 mwindow->move_right(get_w() / 10);
4703 mwindow->move_down(get_h() / 10);
4705 else if(get_buttonpress() == 6) {
4707 mwindow->move_left(get_w());
4709 mwindow->move_left(get_w() / 20);
4711 mwindow->move_left(get_w() / 5);
4713 else if(get_buttonpress() == 7) {
4715 mwindow->move_right(get_w());
4717 mwindow->move_right(get_w() / 20);
4719 mwindow->move_right(get_w() / 5);
4722 switch(mwindow->edl->session->editing_mode) {
4723 // Test handles and resource boundaries and highlight a track
4724 case EDITING_ARROW: {
4725 if( mwindow->edl->session->auto_conf->transitions &&
4726 do_transitions(cursor_x, cursor_y,
4727 1, new_cursor, update_cursor) ) break;
4729 if( do_keyframes(cursor_x, cursor_y,
4730 0, get_buttonpress(), new_cursor,
4731 update_cursor, rerender) ) break;
4732 // Test edit boundaries
4733 if( do_edit_handles(cursor_x, cursor_y,
4734 1, rerender, update_overlay, new_cursor,
4735 update_cursor) ) break;
4736 // Test plugin boundaries
4737 if( do_plugin_handles(cursor_x, cursor_y,
4738 1, rerender, update_overlay, new_cursor,
4739 update_cursor) ) break;
4741 if( do_edits(cursor_x, cursor_y, 1, 0,
4742 update_cursor, rerender, new_cursor,
4743 update_cursor) ) break;
4745 if( do_plugins(cursor_x, cursor_y, 0, 1,
4746 update_cursor, rerender) ) break;
4748 if( test_resources(cursor_x, cursor_y) ) break;
4750 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4755 // Test handles only and select a region
4756 case EDITING_IBEAM: {
4757 double position = (double)cursor_x *
4758 mwindow->edl->local_session->zoom_sample /
4759 mwindow->edl->session->sample_rate +
4760 (double)mwindow->edl->local_session->view_start[pane->number] *
4761 mwindow->edl->local_session->zoom_sample /
4762 mwindow->edl->session->sample_rate;
4763 //printf("TrackCanvas::button_press_event %d\n", position);
4765 if(mwindow->edl->session->auto_conf->transitions &&
4766 do_transitions(cursor_x, cursor_y,
4767 1, new_cursor, update_cursor)) break;
4768 if(do_keyframes(cursor_x, cursor_y,
4769 0, get_buttonpress(), new_cursor,
4770 update_cursor, rerender)) {
4774 // Test edit boundaries
4775 if( do_edit_handles(cursor_x, cursor_y,
4776 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4777 // Test plugin boundaries
4778 if( do_plugin_handles(cursor_x, cursor_y,
4779 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4781 if( do_edits(cursor_x, cursor_y,
4782 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4784 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4786 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4787 // Highlight selection
4788 rerender = start_selection(position);
4789 mwindow->session->current_operation = SELECT_REGION;
4796 gui->unlock_window();
4797 mwindow->cwindow->update(1, 0, 0, 0, 1);
4798 gui->lock_window("TrackCanvas::button_press_event 2");
4800 mwindow->update_plugin_guis();
4801 gui->update_patchbay();
4804 if( update_overlay ) {
4805 gui->draw_overlays(1);
4808 if( update_cursor > 0 ) {
4809 gui->update_timebar(0);
4810 gui->hide_cursor(0);
4811 gui->show_cursor(1);
4812 gui->zoombar->update();
4813 gui->flash_canvas(1);
4815 else if(update_cursor < 0) {
4816 gui->swindow->update_selection();
4822 int TrackCanvas::start_selection(double position)
4825 position = mwindow->edl->align_to_frame(position, 0);
4831 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4832 mwindow->edl->local_session->get_selectionend(1)) / 2;
4834 if(position < midpoint)
4836 mwindow->edl->local_session->set_selectionstart(position);
4837 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4843 mwindow->edl->local_session->set_selectionend(position);
4844 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4845 // Don't que the CWindow for the end
4849 // Start a new selection
4851 //printf("TrackCanvas::start_selection %f\n", position);
4852 mwindow->edl->local_session->set_selectionstart(position);
4853 mwindow->edl->local_session->set_selectionend(position);
4854 selection_midpoint = position;
4862 void TrackCanvas::end_edithandle_selection()
4864 mwindow->modify_edithandles();
4867 void TrackCanvas::end_pluginhandle_selection()
4869 mwindow->modify_pluginhandles();
4873 double TrackCanvas::time_visible()
4875 return (double)get_w() *
4876 mwindow->edl->local_session->zoom_sample /
4877 mwindow->edl->session->sample_rate;
4881 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
4883 char string[BCTEXTLEN];
4884 char *cp = string, *ep = cp + sizeof(string)-1;
4885 if( show_curve_type ) {
4886 cp += snprintf(string, ep-cp, "%-8s ",
4887 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
4889 char string2[BCTEXTLEN];
4890 Units::totext(string2,
4891 current->autos->track->from_units(current->position),
4892 mwindow->edl->session->time_format,
4893 mwindow->edl->session->sample_rate,
4894 mwindow->edl->session->frame_rate,
4895 mwindow->edl->session->frames_per_foot);
4896 cp += snprintf(cp, ep-cp, "%s", string2);
4899 vsnprintf(cp, ep-cp, fmt, ap);
4901 gui->show_message(string);
4904 // Patchbay* TrackCanvas::get_patchbay()
4906 // if(pane->patchbay) return pane->patchbay;
4907 // if(gui->total_panes() == 2 &&
4908 // gui->pane[TOP_LEFT_PANE] &&
4909 // gui->pane[TOP_RIGHT_PANE])
4910 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4911 // if(gui->total_panes() == 4)
4913 // if(pane->number == TOP_RIGHT_PANE)
4914 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4916 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;