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 "gwindowgui.h"
42 #include "indexstate.h"
46 #include "keyframepopup.h"
47 #include "keyframes.h"
50 #include "localsession.h"
51 #include "mainclock.h"
52 #include "maincursor.h"
53 #include "mainsession.h"
55 #include "maskautos.h"
58 #include "mwindowgui.h"
62 #include "playbackengine.h"
63 #include "playtransport.h"
65 #include "pluginpopup.h"
66 #include "pluginserver.h"
67 #include "pluginset.h"
68 #include "plugintoggles.h"
69 #include "preferences.h"
70 #include "resourcepixmap.h"
71 #include "resourcethread.h"
74 #include "trackcanvas.h"
77 #include "transition.h"
78 #include "transitionhandles.h"
79 #include "transitionpopup.h"
80 #include "transportque.h"
82 #include "vpatchgui.inc"
87 //#define PIXMAP_AGE -5
88 #define PIXMAP_AGE -32
90 TrackCanvas::TrackCanvas(MWindow *mwindow,
101 this->mwindow = mwindow;
102 this->gui = mwindow->gui;
105 selection_midpoint = 0;
109 resource_timer = new Timer;
110 render_timer = new Timer;
111 hourglass_enabled = 0;
112 timebar_position = -1;
116 TrackCanvas::~TrackCanvas()
118 // delete transition_handles;
120 delete keyframe_pixmap;
121 delete camerakeyframe_pixmap;
122 delete modekeyframe_pixmap;
123 delete pankeyframe_pixmap;
124 delete projectorkeyframe_pixmap;
125 delete maskkeyframe_pixmap;
126 delete background_pixmap;
127 if(temp_picon) delete temp_picon;
129 delete resource_timer;
132 void TrackCanvas::create_objects()
134 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
135 // transition_handles = new TransitionHandles(mwindow, this);
136 edit_handles = new EditHandles(mwindow, this);
137 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
138 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
139 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
140 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
141 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
142 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
148 void TrackCanvas::resize_event()
150 //printf("TrackCanvas::resize_event 1\n");
153 //printf("TrackCanvas::resize_event 2\n");
156 int TrackCanvas::keypress_event()
161 int TrackCanvas::cursor_leave_event()
163 // Because drag motion calls get_cursor_over_window we can be sure that
164 // all highlights get deleted now.
165 // This ended up blocking keyboard input from the drag operations.
166 if( timebar_position >= 0 )
168 timebar_position = -1;
170 pane->timebar->update(1);
174 // return drag_motion();
177 int TrackCanvas::drag_motion_event()
179 return gui->drag_motion();
182 int TrackCanvas::drag_motion(Track **over_track,
184 PluginSet **over_pluginset,
185 Plugin **over_plugin)
187 int cursor_x = get_relative_cursor_x();
188 int cursor_y = get_relative_cursor_y();
190 if( get_cursor_over_window() &&
191 cursor_x >= 0 && cursor_y >= 0 &&
192 cursor_x < get_w() && cursor_y < get_h() )
194 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
195 // Find the edit and track the cursor is over
196 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
198 int64_t track_x, track_y, track_w, track_h;
199 track_dimensions(track, track_x, track_y, track_w, track_h);
201 if(cursor_y >= track_y &&
202 cursor_y < track_y + track_h)
205 for(Edit *edit = track->edits->first; edit; edit = edit->next)
207 int64_t edit_x, edit_y, edit_w, edit_h;
208 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
209 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
210 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
214 if( edit != track->edits->last ) continue;
215 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
216 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
217 if( !edit->silence() ) {
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);
226 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
229 for(int i = 0; i < track->plugin_set.total; i++)
231 PluginSet *pluginset = track->plugin_set.values[i];
232 for(Plugin *plugin = (Plugin*)pluginset->first;
234 plugin = (Plugin*)plugin->next)
236 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
237 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
239 if(cursor_y >= plugin_y &&
240 cursor_y < plugin_y + plugin_h)
242 *over_pluginset = plugin->plugin_set;
244 if(cursor_x >= plugin_x &&
245 cursor_x < plugin_x + plugin_w)
247 *over_plugin = plugin;
259 *over_track = pane->over_patchbay();
265 int TrackCanvas::drag_stop_event()
267 int result = gui->drag_stop();
268 if( !result && mwindow->session->current_operation ) {
269 mwindow->session->current_operation = NO_OPERATION;
275 int TrackCanvas::drag_stop(int *redraw)
280 int cursor_x = -1, cursor_y = -1;
282 if( get_cursor_over_window() ) {
283 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
284 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
287 Track *track = pane->over_patchbay();
288 if( track && mwindow->session->track_highlighted == track )
294 switch(mwindow->session->current_operation) {
295 case DRAG_VTRANSITION:
296 case DRAG_ATRANSITION:
297 if(mwindow->session->edit_highlighted) {
298 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
299 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
300 (mwindow->session->current_operation == DRAG_VTRANSITION &&
301 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
302 mwindow->session->current_operation = NO_OPERATION;
303 mwindow->paste_transition();
310 // Behavior for dragged plugins is limited by the fact that a shared plugin
311 // can only refer to a standalone plugin that exists in the same position in
312 // time. Dragging a plugin from one point in time to another can't produce
313 // a shared plugin to the original plugin. In this case we relocate the
314 // plugin instead of sharing it.
315 case DRAG_AEFFECT_COPY:
316 case DRAG_VEFFECT_COPY:
317 if( mwindow->session->track_highlighted &&
318 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
319 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
320 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
321 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
322 mwindow->session->current_operation = NO_OPERATION;
324 int64_t drop_position = -1;
325 Plugin *drag_plugin = mwindow->session->drag_plugin;
326 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
327 Track *hi_track = mwindow->session->track_highlighted;
329 // Insert shared plugin in source
330 // Move source to different location
331 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
332 //printf("TrackCanvas::drag_stop 6\n");
333 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
334 if( drop_position >= 0 )
335 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
338 else if( hi_track ) {
339 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
340 Edit *hi_edit = mwindow->session->edit_highlighted;
341 drop_position = hi_edit ? hi_edit->startproject : 0;
342 if( drop_position >= 0 )
343 mwindow->move_effect(drag_plugin, hi_track, drop_position);
351 if( mwindow->session->track_highlighted &&
352 ((mwindow->session->current_operation == DRAG_AEFFECT &&
353 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
354 (mwindow->session->current_operation == DRAG_VEFFECT &&
355 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
356 // Drop all the effects
357 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
358 Track *track = mwindow->session->track_highlighted;
360 double length = track->get_length();
362 if(mwindow->session->plugin_highlighted) {
363 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
364 length = track->from_units(mwindow->session->plugin_highlighted->length);
365 if(length <= 0) length = track->get_length();
367 else if(mwindow->session->pluginset_highlighted) {
368 start = track->from_units(plugin_set->length());
369 length = track->get_length() - start;
370 if(length <= 0) length = track->get_length();
372 else if(mwindow->edl->local_session->get_selectionend() >
373 mwindow->edl->local_session->get_selectionstart()) {
374 start = mwindow->edl->local_session->get_selectionstart();
375 length = mwindow->edl->local_session->get_selectionend() -
376 mwindow->edl->local_session->get_selectionstart();
378 // Move to a point between two edits
379 else if(mwindow->session->edit_highlighted) {
380 start = mwindow->session->track_highlighted->from_units(
381 mwindow->session->edit_highlighted->startproject);
382 length = mwindow->session->track_highlighted->from_units(
383 mwindow->session->edit_highlighted->length);
386 mwindow->insert_effects_canvas(start, length);
389 if( mwindow->session->track_highlighted )
390 result = 1; // we have to cleanup
394 if(mwindow->session->track_highlighted) {
395 double asset_duration = 0;
396 int64_t asset_length_units = 0;
397 int64_t position = 0;
399 if(mwindow->session->current_operation == DRAG_ASSET &&
400 mwindow->session->drag_assets->total) {
401 Indexable *indexable = mwindow->session->drag_assets->values[0];
402 // we use video if we are over video and audio if we are over audio
403 if( indexable->have_video() &&
404 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
405 // Images have length -1
406 int64_t video_length = indexable->get_video_frames();
407 if (video_length < 0) {
408 if(mwindow->edl->session->si_useduration)
409 video_length = mwindow->edl->session->si_duration;
411 video_length = 1.0 / mwindow->edl->session->frame_rate ;
413 asset_duration = video_length / indexable->get_frame_rate();
415 else if( indexable->have_audio() &&
416 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
417 int64_t audio_length = indexable->get_audio_samples();
418 asset_duration = (double)audio_length / indexable->get_sample_rate();
422 break; // Do not do anything
425 else if( mwindow->session->current_operation == DRAG_ASSET &&
426 mwindow->session->drag_clips->total ) {
427 EDL *clip = mwindow->session->drag_clips->values[0];
428 asset_duration = clip->tracks->total_length();
431 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
434 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
435 position = drop_edit_position (&insertion, NULL, asset_length_units);
436 if( position == -1 ) {
438 break; // Do not do anything
441 double position_f = mwindow->session->track_highlighted->from_units(position);
442 Track *track = mwindow->session->track_highlighted;
445 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
446 // // Unfortunately, this is _a lot_ of work to do right
447 // printf("Problematic insertion\n");
448 // mwindow->edl->tracks->clear(position_f,
449 // position_f + asset_duration, 0);
451 mwindow->paste_assets(position_f, track, !insertion);
452 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
457 mwindow->session->current_operation = NO_OPERATION;
458 if(mwindow->session->track_highlighted) {
459 if( mwindow->session->track_highlighted->data_type ==
460 mwindow->session->drag_edit->track->data_type) {
461 int64_t position = 0;
462 position = drop_edit_position(&insertion,
463 mwindow->session->drag_edit,
464 mwindow->session->drag_edit->length);
465 if (position == -1) {
467 break; // Do not do anything
470 double position_f = mwindow->session->track_highlighted->from_units(position);
471 Track *track = mwindow->session->track_highlighted;
472 mwindow->move_edits(mwindow->session->drag_edits,
473 track, position_f, !insertion);
485 int TrackCanvas::drag_start_event()
490 int new_cursor, update_cursor;
492 if(mwindow->session->current_operation != NO_OPERATION) return 0;
495 if(do_plugins(get_drag_x(), get_drag_y(),
496 1, 0, redraw, rerender)) {
499 else if(do_edits(get_drag_x(), get_drag_y(),
500 0, 1, redraw, rerender, new_cursor, update_cursor)) {
508 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
510 // get the canvas/track position
511 Track *track = mwindow->session->track_highlighted;
512 int cursor_x = get_relative_cursor_x();
513 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
514 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
515 // we use cursor position for affinity calculations
516 int64_t cursor_position = track->to_units(drop_time, 0);
517 if( cursor_position <= 0 ) {
521 if( moved_edit ) // relative cursor position depends upon drop point
522 drop_time -= mwindow->session->drag_position - moved_edit->track->from_units(moved_edit->startproject);
523 int64_t drop_position = track->to_units(drop_time, 1);
524 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
525 drop_position -= moved_edit_length / 2;
526 Edit *last_edit = track->edits->last;
527 if( !last_edit || drop_position > last_edit->startproject+last_edit->length ) {
529 return drop_position;
532 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
533 for( Edit *edit = track->edits->first; edit; ) {
534 int64_t edit_x0 = edit->startproject, edit_x1 = edit_x0 + edit->length;
535 if( Units::round(labs(edit_x0-cursor_position)*zoom_scale) < HANDLE_W ) {
536 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
537 return edit->startproject;
539 if( Units::round(labs(edit_x1-cursor_position)*zoom_scale) < HANDLE_W ) {
540 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
541 return edit->startproject + edit->length;
543 if( edit != moved_edit && !edit->silence() )
544 drop_x0 = edit_x1; // reset drop zone
545 if( (edit=edit->next) != 0 ) {
546 if( edit == moved_edit || edit->silence() ) continue;
551 //printf("drop cursor=%jd, x0=%jd, x1=%jd\n", cursor_position, drop_x0, drop_x1);
552 if( drop_position >= drop_x0 && drop_position+moved_edit_length < drop_x1 ) {
553 *is_insertion = 0; // fits in the zone
554 //printf("into %jd\n", drop_position);
555 return drop_position;
557 if( cursor_position < drop_x1 ) { // drop in the zone
558 if( (drop_x1-drop_x0) >= moved_edit_length ) {
559 *is_insertion = 0; // fits in the zone, but over the edge
560 int64_t dx0 = llabs(cursor_position-drop_x0);
561 int64_t dx1 = llabs(cursor_position-drop_x1);
562 //printf("onto %jd\n", dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length);
563 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length;
565 int edit_center = (edit_x0+edit_x1) / 2;
566 if( cursor_position < edit_center ) {
568 //printf("snap left %jd\n", drop_x0);
569 return drop_x0; // snap left
573 //printf("snap right %jd\n", drop_x1);
574 return drop_x1; // snap right
583 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
585 // get the canvas/track position
586 Track *track = plugin_set->track;
587 int cursor_x = get_relative_cursor_x();
588 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
589 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
590 // we use cursor position for affinity calculations
591 int64_t cursor_position = track->to_units(drop_time, 0);
592 if( cursor_position <= 0 ) return 0;
593 drop_time -= mwindow->session->drag_position - moved_plugin->track->from_units(moved_plugin->startproject);
594 int64_t drop_position = track->to_units(drop_time, 1);
595 Plugin *last_plugin = (Plugin *)plugin_set->last;
596 if( !last_plugin || drop_position > last_plugin->startproject+last_plugin->length ) {
597 return drop_position;
600 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
601 for( Plugin *plugin = (Plugin *)plugin_set->first; plugin; ) {
602 int64_t plugin_x0 = plugin->startproject, plugin_x1 = plugin_x0 + plugin->length;
603 if( plugin != moved_plugin && !plugin->silence() )
605 if( (plugin=(Plugin *)plugin->next) != 0 ) {
606 if( plugin == moved_plugin || plugin->silence() ) continue;
611 if( drop_position >= drop_x0 && // fits in the zone
612 drop_position+moved_plugin->length < drop_x1 ) {
613 return drop_position;
615 if( cursor_position < drop_x1 ) { // drop in the zone
616 if( (drop_x1-drop_x0) >= moved_plugin->length ) {
617 int64_t dx0 = llabs(cursor_position-drop_x0);
618 int64_t dx1 = llabs(cursor_position-drop_x1);
619 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_plugin->length;
628 void TrackCanvas::draw(int mode, int hide_cursor)
633 // Swap pixmap layers
634 if(get_w() != background_pixmap->get_w() ||
635 get_h() != background_pixmap->get_h())
637 delete background_pixmap;
638 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
641 // Cursor disappears after resize when this is called.
642 // Cursor doesn't redraw after editing when this isn't called.
643 if(pane->cursor && hide_cursor) pane->cursor->hide();
644 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
646 if(debug) PRINT_TRACE
647 draw_resources(mode);
649 if(debug) PRINT_TRACE
651 if(debug) PRINT_TRACE
654 void TrackCanvas::update_cursor(int flush)
656 switch(mwindow->edl->session->editing_mode)
658 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
659 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
664 void TrackCanvas::test_timer()
666 if(resource_timer->get_difference() > 1000 &&
670 hourglass_enabled = 1;
675 void TrackCanvas::draw_indexes(Indexable *indexable)
677 // Don't redraw raw samples
678 IndexState *index_state = 0;
679 index_state = indexable->index_state;
682 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
686 draw_resources(0, 1, indexable);
692 void TrackCanvas::draw_resources(int mode,
694 Indexable *indexable)
698 if(debug) PRINT_TRACE
700 if(!mwindow->edl->session->show_assets) return;
703 // can't stop thread here, because this is called for every pane
704 // if(mode != IGNORE_THREAD && !indexes_only)
705 // gui->resource_thread->stop_draw(!indexes_only);
707 if(mode != IGNORE_THREAD &&
709 !gui->resource_thread->interrupted)
711 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
714 BC_Signals::dump_stack();
717 if(debug) PRINT_TRACE
719 resource_timer->update();
721 // Age resource pixmaps for deletion
723 for(int i = 0; i < gui->resource_pixmaps.total; i++)
724 gui->resource_pixmaps.values[i]->visible--;
726 if(mode == FORCE_REDRAW)
727 gui->resource_pixmaps.remove_all_objects();
729 if(debug) PRINT_TRACE
732 for(Track *current = mwindow->edl->tracks->first;
736 if(debug) PRINT_TRACE
737 for(Edit *edit = current->edits->first; edit; edit = edit->next)
739 if(debug) PRINT_TRACE
740 if( current->data_type != TRACK_SUBTITLE )
741 if(!edit->asset && !edit->nested_edl) continue;
744 if(edit->track->data_type != TRACK_AUDIO) continue;
746 if(edit->nested_edl &&
747 strcmp(indexable->path, edit->nested_edl->path)) continue;
750 strcmp(indexable->path, edit->asset->path)) continue;
753 if(debug) PRINT_TRACE
755 int64_t edit_x, edit_y, edit_w, edit_h;
756 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
759 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
760 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
762 int64_t pixmap_x, pixmap_w, pixmap_h;
763 if(debug) PRINT_TRACE
765 // Search for existing pixmap containing edit
766 for(int i = 0; i < gui->resource_pixmaps.total; i++)
768 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
769 // Same pointer can be different edit if editing took place
770 if(pixmap->edit_id == edit->id &&
771 pixmap->pane_number == pane->number)
777 if(debug) PRINT_TRACE
779 // Get new size, offset of pixmap needed
780 get_pixmap_size(edit,
786 if(debug) PRINT_TRACE
789 if(pixmap_w && pixmap_h)
791 // Create pixmap if it doesn't exist
792 ResourcePixmap* pixmap = create_pixmap(edit,
797 // Resize it if it's bigger
798 if(pixmap_w > pixmap->pixmap_w ||
799 pixmap_h > pixmap->pixmap_h)
800 pixmap->resize(pixmap_w, pixmap_h);
801 pixmap->draw_data(this,
810 // Resize it if it's smaller
811 if(pixmap_w < pixmap->pixmap_w ||
812 pixmap_h < pixmap->pixmap_h)
813 pixmap->resize(pixmap_w, pixmap_h);
815 // Copy pixmap to background canvas
816 background_pixmap->draw_pixmap(pixmap,
818 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
822 if(debug) PRINT_TRACE
829 // Delete unused pixmaps
830 if(debug) PRINT_TRACE
832 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
833 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
835 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
836 delete gui->resource_pixmaps.values[i];
837 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
839 if(debug) PRINT_TRACE
841 if(hourglass_enabled)
844 hourglass_enabled = 0;
846 if(debug) PRINT_TRACE
848 // can't stop thread here, because this is called for every pane
849 // if(mode != IGNORE_THREAD && !indexes_only)
850 // gui->resource_thread->start_draw();
851 if(debug) PRINT_TRACE
856 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
862 ResourcePixmap *result = 0;
864 for(int i = 0; i < gui->resource_pixmaps.total; i++)
866 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
867 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
868 gui->resource_pixmaps.values[i]->pane_number == pane->number)
870 result = gui->resource_pixmaps.values[i];
878 result = new ResourcePixmap(mwindow,
885 gui->resource_pixmaps.append(result);
888 // result->resize(pixmap_w, pixmap_h);
892 void TrackCanvas::get_pixmap_size(Edit *edit,
900 // Align x on frame boundaries
903 // switch(edit->edits->track->data_type)
915 if(pixmap_x + pixmap_w > get_w())
917 pixmap_w = get_w() - pixmap_x;
924 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
925 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
926 // int64_t pixel_increment = MAX(picon_w, frame_w);
927 // int64_t pixmap_x1 = edit_x;
928 // int64_t pixmap_x2 = edit_x + edit_w;
932 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
937 // if(pixmap_x2 > get_w())
939 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
943 // pixmap_x = pixmap_x1;
944 // pixmap_w = pixmap_x2 - pixmap_x1;
949 pixmap_h = mwindow->edl->local_session->zoom_track;
950 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
951 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
954 void TrackCanvas::edit_dimensions(Edit *edit,
960 // w = Units::round(edit->track->from_units(edit->length) *
961 // mwindow->edl->session->sample_rate /
962 // mwindow->edl->local_session->zoom_sample);
966 x = Units::round(edit->track->from_units(edit->startproject) *
967 mwindow->edl->session->sample_rate /
968 mwindow->edl->local_session->zoom_sample -
969 mwindow->edl->local_session->view_start[pane->number]);
971 // Method for calculating w so when edits are together we never get off by one error due to rounding
972 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
973 mwindow->edl->session->sample_rate /
974 mwindow->edl->local_session->zoom_sample -
975 mwindow->edl->local_session->view_start[pane->number]);
978 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
980 if(mwindow->edl->session->show_titles)
981 h += mwindow->theme->get_image("title_bg_data")->get_h();
984 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
988 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
989 h = track->vertical_span(mwindow->theme);
993 void TrackCanvas::draw_paste_destination()
995 //int cursor_x = get_relative_cursor_x();
996 //int cursor_y = get_relative_cursor_y();
997 int current_atrack = 0;
998 int current_vtrack = 0;
999 int current_aedit = 0;
1000 int current_vedit = 0;
1006 //if(pane->number == BOTTOM_RIGHT_PANE)
1007 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1009 if((mwindow->session->current_operation == DRAG_ASSET &&
1010 (mwindow->session->drag_assets->total ||
1011 mwindow->session->drag_clips->total)) ||
1012 (mwindow->session->current_operation == DRAG_EDIT &&
1013 mwindow->session->drag_edits->total)) {
1014 Indexable *indexable = 0;
1018 if(mwindow->session->current_operation == DRAG_ASSET &&
1019 mwindow->session->drag_assets->size())
1020 indexable = mwindow->session->drag_assets->get(0);
1022 if(mwindow->session->current_operation == DRAG_ASSET &&
1023 mwindow->session->drag_clips->size())
1024 clip = mwindow->session->drag_clips->get(0);
1026 int has_audio = 0, has_video = 0;
1027 double paste_audio_length = 0, paste_video_length = 0;
1028 double paste_audio_position = -1, paste_video_position = -1;
1031 has_audio = indexable->have_audio();
1032 paste_audio_length = !has_audio ? 0 :
1033 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1034 has_video = indexable->have_video();
1035 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1036 // Images have length -1
1037 if( asset && asset->video_data && asset->video_length < 0 ) {
1038 paste_video_length = mwindow->edl->session->si_useduration ?
1039 mwindow->edl->session->si_duration / asset->frame_rate :
1040 1.0 / asset->frame_rate ; // 1 frame
1043 paste_video_length = !has_video ? 0 :
1044 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1048 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1049 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1050 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1051 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1054 // 'Align cursor on frame' lengths calculations
1055 if( mwindow->edl->session->cursor_on_frames ) {
1056 double fps = mwindow->edl->session->frame_rate;
1057 double aud = floor(paste_audio_length * fps) / fps;
1058 double vid = floor(paste_video_length * fps) / fps;
1059 double length = has_video && has_audio ?
1060 aud < vid ? aud : vid :
1062 has_audio ? aud : 0;
1063 paste_video_length = paste_audio_length = length;
1066 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1068 switch( mwindow->session->track_highlighted->data_type ) {
1069 case TRACK_VIDEO: length = paste_video_length; break;
1070 case TRACK_AUDIO: length = paste_audio_length; break;
1072 int64_t asset_length = mwindow->session->track_highlighted->
1073 to_units(length, 1);
1074 paste_audio_position = mwindow->session->track_highlighted->
1075 from_units(drop_edit_position(&insertion, NULL, asset_length));
1078 int64_t asset_length = mwindow->session->track_highlighted->
1079 to_units(paste_video_length, 1);
1080 paste_video_position = mwindow->session->track_highlighted->
1081 from_units(drop_edit_position(&insertion, NULL, asset_length));
1084 // Get destination track
1085 for(Track *dest = mwindow->session->track_highlighted;
1087 dest = dest->next) {
1089 // Get source width in pixels
1091 // Use start of highlighted edit
1092 if(mwindow->session->edit_highlighted) {
1093 position = mwindow->session->track_highlighted->from_units(
1094 mwindow->session->edit_highlighted->startproject);
1097 // Use end of highlighted track, disregarding effects
1098 position = mwindow->session->track_highlighted->from_units(
1099 mwindow->session->track_highlighted->edits->length());
1102 // Get the x coordinate
1103 x = Units::to_int64(position *
1104 mwindow->edl->session->sample_rate /
1105 mwindow->edl->local_session->zoom_sample) -
1106 mwindow->edl->local_session->view_start[pane->number];
1108 double paste_position = -1.;
1109 if(dest->data_type == TRACK_AUDIO) {
1110 if(indexable && current_atrack < indexable->get_audio_channels()) {
1111 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1112 w = Units::to_int64((double)indexable->get_audio_samples() /
1113 indexable->get_sample_rate() *
1114 mwindow->edl->session->sample_rate /
1115 mwindow->edl->local_session->zoom_sample);
1116 paste_position = paste_audio_position;
1118 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1119 w = Units::to_int64((double)clip->tracks->total_length() *
1120 mwindow->edl->session->sample_rate /
1121 mwindow->edl->local_session->zoom_sample);
1122 paste_position = paste_audio_position;
1123 //printf("draw_paste_destination %d\n", x);
1125 else if(mwindow->session->current_operation == DRAG_EDIT &&
1126 current_aedit < mwindow->session->drag_edits->total) {
1128 while(current_aedit < mwindow->session->drag_edits->total &&
1129 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1132 if(current_aedit < mwindow->session->drag_edits->total) {
1133 edit = mwindow->session->drag_edits->values[current_aedit];
1134 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1135 paste_position = mwindow->session->track_highlighted->
1136 from_units(drop_edit_position(&insertion,
1137 mwindow->session->drag_edit,
1138 mwindow->session->drag_edit->length));
1141 if( paste_position >= 0 ) {
1142 position = paste_position;
1149 else if(dest->data_type == TRACK_VIDEO) {
1150 //printf("draw_paste_destination 1\n");
1151 if(indexable && current_vtrack < indexable->get_video_layers())
1153 w = Units::to_int64((double)indexable->get_video_frames() /
1154 indexable->get_frame_rate() *
1155 mwindow->edl->session->sample_rate /
1156 mwindow->edl->local_session->zoom_sample);
1157 paste_position = paste_video_position;
1159 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1160 w = Units::to_int64(clip->tracks->total_length() *
1161 mwindow->edl->session->sample_rate /
1162 mwindow->edl->local_session->zoom_sample);
1163 paste_position = paste_video_position;
1165 else if(mwindow->session->current_operation == DRAG_EDIT &&
1166 current_vedit < mwindow->session->drag_edits->total) {
1168 while(current_vedit < mwindow->session->drag_edits->total &&
1169 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1172 if(current_vedit < mwindow->session->drag_edits->total) {
1173 edit = mwindow->session->drag_edits->values[current_vedit];
1174 w = Units::to_int64(edit->track->from_units(edit->length) *
1175 mwindow->edl->session->sample_rate /
1176 mwindow->edl->local_session->zoom_sample);
1177 paste_position = mwindow->session->track_highlighted->
1178 from_units(drop_edit_position(&insertion,
1179 mwindow->session->drag_edit,
1180 mwindow->session->drag_edit->length));
1183 if( paste_position >= 0 ) {
1184 position = paste_position;
1193 // Get the x coordinate
1194 x = Units::to_int64(position *
1195 mwindow->edl->session->sample_rate /
1196 mwindow->edl->local_session->zoom_sample) -
1197 mwindow->edl->local_session->view_start[pane->number];
1198 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1199 int h = dest->vertical_span(mwindow->theme);
1201 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1203 draw_highlight_insertion(x, y, w, h);
1205 draw_highlight_rectangle(x, y, w, h);
1206 if(x < -BC_INFINITY) {
1207 w -= -BC_INFINITY - x;
1208 x += -BC_INFINITY - x;
1211 // if(pane->number == TOP_RIGHT_PANE)
1212 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1213 // __LINE__, x, y, w, h);
1214 draw_highlight_rectangle(x, y, w, h);
1221 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1223 x = Units::round(plugin->track->from_units(plugin->startproject) *
1224 mwindow->edl->session->sample_rate /
1225 mwindow->edl->local_session->zoom_sample -
1226 mwindow->edl->local_session->view_start[pane->number]);
1227 w = Units::round(plugin->track->from_units(plugin->length) *
1228 mwindow->edl->session->sample_rate /
1229 mwindow->edl->local_session->zoom_sample);
1230 y = plugin->track->y_pixel -
1231 mwindow->edl->local_session->track_start[pane->number] +
1232 mwindow->edl->local_session->zoom_track +
1233 plugin->plugin_set->get_number() *
1234 mwindow->theme->get_image("plugin_bg_data")->get_h();
1235 if(mwindow->edl->session->show_titles)
1236 y += mwindow->theme->get_image("title_bg_data")->get_h();
1237 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1240 int TrackCanvas::resource_h()
1242 return mwindow->edl->local_session->zoom_track;
1245 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1248 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1249 // just draw arrows, so user has indication that something is there
1250 // FIXME: get better colors
1254 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1259 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1263 // Fix bug in heroines & cvs version as of 22.8.2005:
1264 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1265 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1278 w = MIN(w, get_w() + 20);
1279 h = MIN(h, get_h() + 20);
1282 set_color(mwindow->preferences->highlight_inverse);
1284 //draw_rectangle(x, y, w, h);
1285 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1286 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1288 draw_rectangle(x, y, w, h);
1290 //if(pane->number == TOP_RIGHT_PANE)
1291 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1294 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1297 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1298 // just draw arrows, so user has indication that something is there
1299 // FIXME: get better colors
1308 /* these don't look so good
1310 draw_line(x, y, x, y+h);
1311 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1312 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1313 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1314 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1316 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1317 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1319 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1320 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1321 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1322 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1324 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1325 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1327 // draw the box centred around x
1329 // Fix bug in heroines & cvs version as of 22.8.2005:
1330 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1331 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1342 w = MIN(w, get_w() + 20);
1343 h = MIN(h, get_h() + 20);
1344 set_color(mwindow->preferences->highlight_inverse);
1346 draw_rectangle(x, y, w, h);
1347 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1349 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1352 void TrackCanvas::draw_playback_cursor()
1354 // Called before playback_cursor exists
1355 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1357 // mwindow->playback_cursor->visible = 0;
1358 // mwindow->playback_cursor->draw();
1362 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1364 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1365 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1367 edit_dimensions(edit, x, y, w, h);
1369 if(mwindow->edl->session->show_titles)
1371 y += mwindow->theme->get_image("title_bg_data")->get_h();
1378 if(side == EDIT_OUT)
1387 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1389 //printf("TrackCanvas::get_transition_coords 1\n");
1390 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1391 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1392 int transition_w = 30;
1393 int transition_h = 30;
1394 //printf("TrackCanvas::get_transition_coords 1\n");
1396 if(mwindow->edl->session->show_titles)
1397 y += mwindow->theme->get_image("title_bg_data")->get_h();
1398 //printf("TrackCanvas::get_transition_coords 2\n");
1400 y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
1401 x -= transition_w / 2;
1407 void TrackCanvas::draw_highlighting()
1412 switch(mwindow->session->current_operation)
1414 case DRAG_ATRANSITION:
1415 case DRAG_VTRANSITION:
1416 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1417 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1418 if(mwindow->session->edit_highlighted) {
1419 //printf("TrackCanvas::draw_highlighting 2\n");
1420 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1421 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1422 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1423 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1424 //printf("TrackCanvas::draw_highlighting 2\n");
1425 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1426 //printf("TrackCanvas::draw_highlighting 2\n");
1428 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1429 MWindowGUI::visible(y, y + h, 0, get_h())) {
1431 get_transition_coords(x, y, w, h);
1433 //printf("TrackCanvas::draw_highlighting 3\n");
1438 // Dragging a new effect from the Resource window
1441 if(mwindow->session->track_highlighted &&
1442 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1443 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1444 (mwindow->session->current_operation == DRAG_VEFFECT &&
1445 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1446 // Put it before another plugin
1447 if(mwindow->session->plugin_highlighted) {
1448 plugin_dimensions(mwindow->session->plugin_highlighted,
1450 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1452 // Put it after a plugin set
1453 else if( mwindow->session->pluginset_highlighted &&
1454 mwindow->session->pluginset_highlighted->last ) {
1455 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1457 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1458 int64_t track_x, track_y, track_w, track_h;
1459 track_dimensions(mwindow->session->track_highlighted,
1460 track_x, track_y, track_w, track_h);
1464 mwindow->session->track_highlighted->get_length() *
1465 mwindow->edl->session->sample_rate /
1466 mwindow->edl->local_session->zoom_sample -
1467 mwindow->edl->local_session->view_start[pane->number]) -
1469 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1470 if(w <= 0) w = track_w;
1473 track_dimensions(mwindow->session->track_highlighted,
1476 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1477 // Put it in a new plugin set determined by the selected range
1478 if(mwindow->edl->local_session->get_selectionend() >
1479 mwindow->edl->local_session->get_selectionstart()) {
1480 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1481 mwindow->edl->session->sample_rate /
1482 mwindow->edl->local_session->zoom_sample -
1483 mwindow->edl->local_session->view_start[pane->number]);
1484 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1485 mwindow->edl->local_session->get_selectionstart()) *
1486 mwindow->edl->session->sample_rate /
1487 mwindow->edl->local_session->zoom_sample);
1489 // Put it in a new plugin set determined by an edit boundary
1490 else if(mwindow->session->edit_highlighted) {
1491 int64_t temp_y, temp_h;
1492 edit_dimensions(mwindow->session->edit_highlighted,
1493 x, temp_y, w, temp_h);
1495 // Put it at the beginning of the track in a new plugin set
1498 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1499 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1500 //printf("TrackCanvas::draw_highlighting 1\n");
1507 if(mwindow->session->track_highlighted) {
1508 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1510 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1512 draw_paste_destination();
1518 if(mwindow->session->track_highlighted) {
1519 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1521 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1522 draw_paste_destination();
1527 // Dragging an effect from the timeline
1528 case DRAG_AEFFECT_COPY:
1529 case DRAG_VEFFECT_COPY:
1530 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1531 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1532 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1533 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1534 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1536 int64_t plugin_position = -1;
1537 Plugin *drag_plugin = mwindow->session->drag_plugin;
1538 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1539 Track *hi_track = mwindow->session->track_highlighted;
1540 Edit *hi_edit = mwindow->session->edit_highlighted;
1541 // Put it into a silence zone
1542 if( hi_plugin_set && hi_plugin_set->last &&
1543 hi_plugin_set->track == drag_plugin->track ) {
1544 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1545 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1546 hi_track = drag_plugin->track;
1548 else if( hi_track ) {
1549 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1550 track_dimensions(hi_track, x, y, w, h);
1551 plugin_position = hi_edit ? hi_edit->startproject : 0;
1554 if( plugin_position < 0 ) break;
1556 // Calculate length of plugin based on data type of track and units
1557 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1558 mwindow->edl->local_session->zoom_sample;
1559 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1560 mwindow->edl->local_session->view_start[pane->number];
1561 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1563 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1564 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1570 case DRAG_PLUGINKEY:
1571 if(mwindow->session->plugin_highlighted &&
1572 mwindow->session->current_operation == DRAG_PLUGINKEY)
1574 // Just highlight the plugin
1575 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1577 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1578 MWindowGUI::visible(y, y + h, 0, get_h()))
1590 draw_highlight_rectangle(x, y, w, h);
1594 void TrackCanvas::draw_plugins()
1596 char string[BCTEXTLEN];
1598 int current_show = 0;
1599 int current_preset = 0;
1601 // if(!mwindow->edl->session->show_assets) goto done;
1603 for(int i = 0; i < plugin_on_toggles.total; i++)
1604 plugin_on_toggles.values[i]->in_use = 0;
1605 for(int i = 0; i < plugin_show_toggles.total; i++)
1606 plugin_show_toggles.values[i]->in_use = 0;
1607 for(int i = 0; i < preset_edit_buttons.total; i++)
1608 plugin_show_toggles.values[i]->in_use = 0;
1611 for(Track *track = mwindow->edl->tracks->first;
1613 track = track->next)
1615 if(track->expand_view)
1617 for(int i = 0; i < track->plugin_set.total; i++)
1619 PluginSet *pluginset = track->plugin_set.values[i];
1621 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1623 int64_t total_x, y, total_w, h;
1624 plugin_dimensions(plugin, total_x, y, total_w, h);
1626 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1627 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1628 plugin->plugin_type != PLUGIN_NONE)
1630 int x = total_x, w = total_w, left_margin = 5;
1631 int right_margin = 5;
1637 if(w + x > get_w()) w -= (w + x) - get_w();
1644 mwindow->theme->get_image("plugin_bg_data"),
1646 set_color(mwindow->theme->title_color);
1647 set_font(mwindow->theme->title_font);
1648 plugin->calculate_title(string, 0);
1650 // Truncate string to int64_test visible in background
1651 int len = strlen(string), j;
1652 for(j = len; j >= 0; j--)
1654 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1662 // Justify the text on the left boundary of the edit if it is visible.
1663 // Otherwise justify it on the left side of the screen.
1664 int64_t text_x = total_x + left_margin;
1665 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1666 text_x = MAX(left_margin, text_x);
1668 y + get_text_ascent(mwindow->theme->title_font) + 2,
1672 int64_t min_x = total_x + text_w;
1675 // Update plugin toggles
1676 int toggle_x = total_x + total_w;
1678 toggle_x = MIN(get_w() - right_margin, toggle_x);
1681 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1682 if(toggle_x > min_x)
1684 if(current_on >= plugin_on_toggles.total)
1686 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1687 add_subwindow(plugin_on);
1688 plugin_on_toggles.append(plugin_on);
1692 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1697 // Toggles for standalone plugins only
1698 if(plugin->plugin_type == PLUGIN_STANDALONE)
1701 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1702 if(toggle_x > min_x)
1704 if(current_show >= plugin_show_toggles.total)
1706 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1707 add_subwindow(plugin_show);
1708 plugin_show_toggles.append(plugin_show);
1712 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1716 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1717 if(toggle_x > min_x)
1719 if(current_preset >= preset_edit_buttons.total)
1721 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1722 add_subwindow(preset_edit);
1723 preset_edit_buttons.append(preset_edit);
1727 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1738 // Remove unused toggles
1740 while(current_preset < preset_edit_buttons.total)
1742 preset_edit_buttons.remove_object_number(current_preset);
1744 while(current_show < plugin_show_toggles.total)
1746 plugin_show_toggles.remove_object_number(current_show);
1749 while(current_on < plugin_on_toggles.total)
1751 plugin_on_toggles.remove_object_number(current_on);
1755 void TrackCanvas::refresh_plugintoggles()
1757 for(int i = 0; i < plugin_on_toggles.total; i++)
1759 PluginOn *on = plugin_on_toggles.values[i];
1760 on->reposition_window(on->get_x(), on->get_y());
1762 for(int i = 0; i < plugin_show_toggles.total; i++)
1764 PluginShow *show = plugin_show_toggles.values[i];
1765 show->reposition_window(show->get_x(), show->get_y());
1767 for(int i = 0; i < preset_edit_buttons.total; i++)
1769 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1770 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1774 void TrackCanvas::draw_inout_points()
1779 void TrackCanvas::draw_drag_handle()
1781 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1782 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1784 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1785 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1786 mwindow->edl->session->sample_rate /
1787 mwindow->edl->local_session->zoom_sample -
1788 mwindow->edl->local_session->view_start[pane->number]);
1789 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1790 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1792 //printf("TrackCanvas::draw_drag_handle 3\n");
1793 draw_line(pixel1, 0, pixel1, get_h());
1795 //printf("TrackCanvas::draw_drag_handle 4\n");
1800 void TrackCanvas::draw_transitions()
1804 // if(!mwindow->edl->session->show_assets) return;
1806 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1807 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1808 if(!edit->transition) continue;
1809 edit_dimensions(edit, x, y, w, h);
1810 int strip_x = x, strip_y = y;
1811 if(mwindow->edl->session->show_titles)
1812 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1813 get_transition_coords(x, y, w, h);
1814 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1815 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1816 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1817 MWindowGUI::visible(y, y + h, 0, get_h()) )
1819 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1821 if( !server ) continue;
1822 VFrame *picon = server->get_picon();
1823 if( !picon ) continue;
1824 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1826 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1827 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1829 int x = strip_x, w = strip_w;
1835 if(w + x > get_w()) w -= (w + x) - get_w();
1837 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1838 mwindow->theme->get_image("plugin_bg_data"), 0);
1844 void TrackCanvas::draw_loop_points()
1846 //printf("TrackCanvas::draw_loop_points 1\n");
1847 if(mwindow->edl->local_session->loop_playback)
1849 //printf("TrackCanvas::draw_loop_points 2\n");
1850 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1851 mwindow->edl->session->sample_rate /
1852 mwindow->edl->local_session->zoom_sample -
1853 mwindow->edl->local_session->view_start[pane->number]);
1854 //printf("TrackCanvas::draw_loop_points 3\n");
1856 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1859 draw_line(x, 0, x, get_h());
1861 //printf("TrackCanvas::draw_loop_points 4\n");
1863 x = Units::round(mwindow->edl->local_session->loop_end *
1864 mwindow->edl->session->sample_rate /
1865 mwindow->edl->local_session->zoom_sample -
1866 mwindow->edl->local_session->view_start[pane->number]);
1867 //printf("TrackCanvas::draw_loop_points 5\n");
1869 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1872 draw_line(x, 0, x, get_h());
1874 //printf("TrackCanvas::draw_loop_points 6\n");
1876 //printf("TrackCanvas::draw_loop_points 7\n");
1879 void TrackCanvas::draw_brender_range()
1881 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1882 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1883 if( mwindow->edl->session->brender_end > 0 )
1885 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1886 mwindow->edl->session->sample_rate /
1887 mwindow->edl->local_session->zoom_sample -
1888 mwindow->edl->local_session->view_start[pane->number]);
1889 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1892 draw_line(x1, 0, x1, get_h());
1894 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1895 mwindow->edl->session->sample_rate /
1896 mwindow->edl->local_session->zoom_sample -
1897 mwindow->edl->local_session->view_start[pane->number]);
1899 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1902 draw_line(x2, 0, x2, get_h());
1907 // The operations which correspond to each automation type
1908 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1924 // The buttonpress operations, so nothing changes unless the mouse moves
1925 // a certain amount. This allows the keyframe to be used to position the
1926 // insertion point without moving itself.
1927 static int pre_auto_operations[AUTOMATION_TOTAL] =
1944 int TrackCanvas::do_keyframes(int cursor_x,
1952 // Note: button 3 (right mouse button) is not eaten to allow
1953 // track context menu to appear
1955 EDLSession *session = mwindow->edl->session;
1959 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1961 0, 0, 0, 0, 0, 0, 0, 0,
1963 modekeyframe_pixmap,
1964 maskkeyframe_pixmap,
1969 for(Track *track = mwindow->edl->tracks->first;
1971 track = track->next) {
1972 Auto *auto_keyframe = 0;
1973 Automation *automation = track->automation;
1976 // Handle keyframes in reverse drawing order if a button press
1978 int end = AUTOMATION_TOTAL;
1982 start = AUTOMATION_TOTAL - 1;
1986 for(int i = start; i != end && !result; i += step)
1988 // Event not trapped and automation visible
1989 Autos *autos = automation->autos[i];
1990 if(!result && session->auto_conf->autos[i] && autos) {
1992 case AUTOMATION_MODE:
1993 case AUTOMATION_PAN:
1994 case AUTOMATION_MASK:
1995 result = do_autos(track, automation->autos[i],
1996 cursor_x, cursor_y, draw,
1997 buttonpress, auto_pixmaps[i],
1998 auto_keyframe, rerender);
2002 switch(autos->get_type()) {
2003 case Autos::AUTOMATION_TYPE_FLOAT: {
2004 Automation automation(0, track);
2005 int grouptype = automation.autogrouptype(i, track);
2006 if(draw) // Do dropshadow
2007 result = do_float_autos(track, autos,
2008 cursor_x, cursor_y, draw,
2009 buttonpress, 1, 1, MDGREY,
2010 auto_keyframe, grouptype);
2012 result = do_float_autos(track, autos,
2013 cursor_x, cursor_y, draw, buttonpress,
2014 0, 0, GWindowGUI::auto_colors[i],
2015 auto_keyframe, grouptype);
2018 case Autos::AUTOMATION_TYPE_INT: {
2019 if(draw) // Do dropshadow
2020 result = do_int_autos(track, autos,
2021 cursor_x, cursor_y, draw,
2022 buttonpress, 1, 1, MDGREY,
2024 result = do_int_autos(track, autos,
2025 cursor_x, cursor_y, draw, buttonpress,
2026 0, 0, GWindowGUI::auto_colors[i],
2035 if(mwindow->session->current_operation == auto_operations[i])
2038 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2040 // mwindow->session->current_operation,
2041 // auto_operations[i]);
2044 if (buttonpress != 3)
2046 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2047 synchronize_autos(0,
2049 (FloatAuto*)mwindow->session->drag_auto,
2051 mwindow->session->current_operation = pre_auto_operations[i];
2052 update_drag_caption();
2055 else if( auto_keyframe )
2057 gui->keyframe_menu->update(automation,
2060 gui->keyframe_menu->activate_menu();
2061 rerender = 1; // the position changes
2065 gui->keyframe_hide->update(autos);
2066 gui->keyframe_hide->activate_menu();
2067 rerender = 1; // the position changes
2069 if(buttonpress == 1 && ctrl_down() &&
2070 AUTOMATION_TYPE_FLOAT == autos->get_type())
2071 rerender = 1; // special case: curve mode changed
2078 session->auto_conf->plugins /* &&
2079 mwindow->edl->session->show_assets */) {
2082 result = do_plugin_autos(track, cursor_x, cursor_y,
2083 draw, buttonpress, plugin, keyframe);
2084 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2087 if(result && (buttonpress == 1)) {
2088 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2089 update_drag_caption();
2092 else if (result && (buttonpress == 3)) {
2093 gui->keyframe_menu->update(plugin, keyframe);
2094 gui->keyframe_menu->activate_menu();
2095 rerender = 1; // the position changes
2100 // Final pass to trap event
2101 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2102 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2103 mwindow->session->current_operation == auto_operations[i]) {
2109 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2110 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2116 new_cursor = UPRIGHT_ARROW_CURSOR;
2123 void TrackCanvas::draw_keyframe_reticle()
2125 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2126 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2128 int current_op = mwindow->session->current_operation, dragging = 0;
2129 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2130 if( current_op == auto_operations[i] ) dragging = 1;
2132 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2133 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2134 draw_hairline(mwindow->session->drag_auto, RED);
2139 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2140 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2141 for( Track *track = mwindow->edl->tracks->first; track;
2142 track=track->next ) {
2143 Automation *automation = track->automation;
2144 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2145 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2146 // automation visible
2147 Autos *autos = automation->autos[i];
2148 if( !autos ) continue;
2149 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2150 auto_keyframe = auto_keyframe->next ) {
2151 draw_hairline(auto_keyframe, GREEN);
2155 if( dragging && mwindow->session->drag_auto ) {
2156 draw_hairline(mwindow->session->drag_auto, RED);
2162 void TrackCanvas::draw_auto(Auto *current,
2170 x1 = x - HANDLE_W / 2;
2171 x2 = x + HANDLE_W / 2;
2172 y1 = center_pixel + y - HANDLE_W / 2;
2173 y2 = center_pixel + y + HANDLE_W / 2;
2175 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2176 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2178 draw_box(x1, y1, x2 - x1, y2 - y1);
2182 // This draws lines for bezier in & out controls
2183 void TrackCanvas::draw_cropped_line(int x1,
2192 // Don't care about x since it is clipped by the window.
2193 // Put y coords in ascending order
2195 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2196 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2201 double slope = (double)(x2 - x1) / (y2 - y1);
2202 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2204 x1 = (int)(x1 + (min_y - y1) * slope);
2207 else if(y1 >= max_y) {
2208 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2213 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2216 else if(y2 < min_y) {
2217 x2 = (int)(x2 + (min_y - y2) * slope);
2222 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2223 if( y1 >= min_y && y1 < max_y &&
2224 y2 >= min_y && y2 < max_y )
2225 draw_line(x1, y1, x2, y2);
2229 void TrackCanvas::draw_floatauto(FloatAuto *current,
2240 int x1 = x - HANDLE_W / 2; // Center
2241 int x2 = x + HANDLE_W / 2;
2242 int y1 = center_pixel + y - HANDLE_H / 2;
2243 int y2 = center_pixel + y + HANDLE_H / 2;
2244 int ymin = center_pixel - zoom_track / 2;
2245 int ymax = center_pixel + zoom_track / 2;
2246 CLAMP(y1, ymin, ymax);
2247 CLAMP(y2, ymin, ymax);
2252 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2254 draw_box(x1, y1, x2 - x1, y2 - y1);
2257 // show bezier control points (only) if this
2258 // floatauto doesn't adjust it's tangents automatically
2259 if(current->curve_mode != FloatAuto::FREE &&
2260 current->curve_mode != FloatAuto::TFREE)
2264 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2266 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2269 inline int quantize(float f) { return (int)floor(f + 0.5); }
2271 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2272 int x, int y, int cp_x, int cp_y, int center_pixel,
2273 int zoom_track, int color)
2274 // draw the tangent and a handle for given bézier ctrl point
2276 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2278 float slope = (float)(cp_y - y)/(cp_x - x);
2279 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2281 cp_x = x + quantize((cp_y - y) / slope);
2284 cp_y += center_pixel;
2286 // drawing the tangent as a dashed line...
2287 int const dash = HANDLE_W;
2288 int const gap = HANDLE_W / 2;
2289 float sx = 3 * (cp_x - x) / 4.;
2292 // q is the x displacement for a unit line of slope
2293 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2295 float dist = 1/q * sx;
2301 float sy = slope * sx, ey = slope * ex;
2302 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2309 int r = HANDLE_W / 2;
2310 int cp_x1 = cp_x - r;
2311 int cp_y1 = cp_y - r;
2313 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2315 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2320 int TrackCanvas::test_auto(Auto *current,
2321 int x, int y, int center_pixel, int zoom_track,
2322 int cursor_x, int cursor_y, int buttonpress)
2327 x1 = x - HANDLE_W / 2;
2328 x2 = x + HANDLE_W / 2;
2329 y1 = center_pixel + y - HANDLE_H / 2;
2330 y2 = center_pixel + y + HANDLE_H / 2;
2331 int ymin = center_pixel - zoom_track / 2;
2332 int ymax = center_pixel + zoom_track / 2;
2333 CLAMP(y1, ymin, ymax);
2334 CLAMP(y2, ymin, ymax);
2336 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2338 if(buttonpress && buttonpress != 3)
2340 mwindow->session->drag_auto = current;
2341 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2342 // Toggle Autos don't respond to vertical zoom, they always show up
2343 // with "on" == 100% == line on top
2344 mwindow->session->drag_start_position = current->position;
2345 mwindow->session->drag_origin_x = cursor_x;
2346 mwindow->session->drag_origin_y = cursor_y;
2351 if(buttonpress && buttonpress != 3 && result)
2353 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2354 mwindow->undo->update_undo_before();
2360 // some Helpers for test_floatauto(..)
2361 // and for dragging the tangents/ctrl points
2362 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2363 float cursor_x, float cursor_y)
2365 // Control point switched off?
2366 if( x0 == ctrl_x ) return 0.0;
2367 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2368 double x = cursor_x-x0, y = cursor_y-y0;
2369 // wrong side of ctrl handle
2370 if( x*x1 < 0 ) return 0.0;
2371 // outside handle radius
2372 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2373 double xx1 = x1*x1, yy1 = y1*y1;
2374 double xx = x*x, yy = y*y;
2375 // distance squared from cursor to cursor projected to line from ctrl to handle
2376 // along a line perpendicular to line from ctrl to handle (closest approach)
2377 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2378 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2379 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2384 float levered_position(float position, float ref_pos)
2386 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2388 return ref_pos / position;
2392 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2393 // transforms automation value into current display coords,
2394 // dependant on current automation display range for the given kind of automation
2396 if(!mwindow || !mwindow->edl) return 0;
2397 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2398 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2399 float automation_range = automation_max - automation_min;
2400 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2402 return (auto_value - automation_min) / automation_range;
2407 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2408 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2409 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2413 int x1 = x - HANDLE_W / 2;
2414 int x2 = x + HANDLE_W / 2;
2415 int y1 = center_pixel + y - HANDLE_W / 2;
2416 int y2 = center_pixel + y + HANDLE_W / 2;
2417 int ymin = center_pixel - zoom_track / 2;
2418 int ymax = center_pixel + zoom_track / 2;
2419 CLAMP(y1, ymin, ymax);
2420 CLAMP(y2, ymin, ymax);
2422 int in_x1 = in_x - HANDLE_W / 2;
2423 int in_x2 = in_x + HANDLE_W / 2;
2424 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2425 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2426 CLAMP(in_y1, ymin, ymax);
2427 CLAMP(in_y2, ymin, ymax);
2429 int out_x1 = out_x - HANDLE_W / 2;
2430 int out_x2 = out_x + HANDLE_W / 2;
2431 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2432 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2433 CLAMP(out_y1, ymin, ymax);
2434 CLAMP(out_y2, ymin, ymax);
2437 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2438 // buttonpress could be the start of a drag operation
2439 #define INIT_DRAG(POS,VAL) \
2440 mwindow->session->drag_auto = current; \
2441 mwindow->session->drag_origin_x = cursor_x; \
2442 mwindow->session->drag_origin_y = cursor_y; \
2443 mwindow->session->drag_start_position = (POS); \
2444 mwindow->session->drag_start_percentage = (VAL);
2446 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2449 // without modifier we are manipulating the automation node
2450 // with ALT it's about dragging only the value of the node
2451 // with SHIFT the value snaps to the value of neighbouring nodes
2452 // CTRL indicates we are rather manipulating the tangent(s) of the node
2456 if( WITHIN(x1,x2,y1,y2))
2457 { // cursor hits node
2460 if(buttonpress && (buttonpress != 3))
2462 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2463 mwindow->session->drag_handle = 0;
2468 if( WITHIN(x1,x2,y1,y2))
2471 if(buttonpress && (buttonpress != 3))
2473 // could be ctrl-click or ctrl-drag
2474 // click would cycle through tangent modes
2475 ((FloatAuto*)current)->toggle_curve_mode();
2477 // drag will start dragging the tangent, if applicable
2478 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2479 mwindow->session->drag_handle = 0;
2483 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2486 if( in_x != x && current->position > 0 &&
2487 (FloatAuto::FREE == current->curve_mode ||
2488 FloatAuto::TFREE == current->curve_mode))
2489 // act on in control handle only if
2490 // tangent is significant and is editable (not automatically choosen)
2492 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2493 // either cursor in ctrl-point handle or cursor on tangent line
2494 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2496 if(buttonpress && (buttonpress != 3)) {
2497 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2499 mwindow->session->drag_handle = 1;
2500 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2501 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2502 value_to_percentage(new_invalue, autogrouptype))
2509 (FloatAuto::FREE == current->curve_mode ||
2510 FloatAuto::TFREE == current->curve_mode))
2511 // act on out control only if tangent is significant and is editable
2513 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2514 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2516 if(buttonpress && (buttonpress != 3)) {
2517 if(lever == 0.0) lever=1.0;
2519 mwindow->session->drag_handle = 2;
2520 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2521 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2522 value_to_percentage(new_outvalue, autogrouptype))
2526 } // end ctrl_down()
2532 // 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",
2533 // mwindow->session->drag_handle,
2538 if(buttonpress && (buttonpress != 3) && result)
2540 mwindow->undo->update_undo_before();
2547 // Get the float value & y for position x on the canvas
2548 #define X_TO_FLOATLINE(x) \
2549 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2550 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2551 /* Call by reference fails for some reason here */ \
2552 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2553 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2554 double position = unit_start + x * zoom_units; \
2556 if(position2 > position1) \
2559 (value2 - value1) * \
2560 (position - position1) / \
2561 (position2 - position1); \
2567 AUTOMATIONCLAMPS(value, autogrouptype); \
2568 int y = center_pixel + \
2569 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2572 void TrackCanvas::draw_floatline(int center_pixel,
2573 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2574 double unit_start, double zoom_units, double yscale,
2575 int x1, int y1, int x2, int y2,
2576 int color, int autogrouptype)
2578 // Solve bezier equation for either every pixel or a certain large number of
2581 // Not using slope intercept
2583 int prev_y = y1 + center_pixel;
2586 // Call by reference fails for some reason here
2587 FloatAuto *previous1 = previous, *next1 = next;
2588 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2589 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2590 float automation_range = automation_max - automation_min;
2592 for(int x = x1; x < x2; x++)
2594 // Interpolate value between frames
2598 y >= center_pixel - yscale / 2 &&
2599 y < center_pixel + yscale / 2 - 1)
2601 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2603 // (int)(center_pixel - yscale / 2),
2604 // (int)(center_pixel + yscale / 2 - 1));
2606 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2607 draw_line(x - 1, prev_y , x, y );
2617 int TrackCanvas::test_floatline(int center_pixel,
2632 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2633 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2634 float automation_range = automation_max - automation_min;
2635 FloatAuto *previous1 = 0, *next1 = 0;
2636 X_TO_FLOATLINE(cursor_x);
2638 if(cursor_x >= x1 &&
2640 cursor_y >= y - HANDLE_W / 2 &&
2641 cursor_y < y + HANDLE_W / 2 &&
2647 if(buttonpress == 3)
2655 mwindow->undo->update_undo_before();
2656 double position = autos->track->from_units(position1);
2657 position = mwindow->edl->align_to_frame(position, 0);
2658 int64_t new_position = autos->track->to_units(position,0);
2659 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2660 ((FloatAuto*)current)->set_value(value);
2661 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2662 mwindow->session->drag_start_position = current->position;
2663 mwindow->session->drag_origin_x = cursor_x;
2664 mwindow->session->drag_origin_y = cursor_y;
2665 mwindow->session->drag_handle = 0;
2674 void TrackCanvas::synchronize_autos(float change,
2675 Track *skip, FloatAuto *fauto, int fill_gangs)
2677 // Handles the special case of modifying a fadeauto
2678 // when there are ganged faders on several tracks
2679 // (skip and fauto may be NULL if fill_gangs==-1)
2681 if( fill_gangs > 0 && skip->gang ) {
2682 double position = skip->from_units(fauto->position);
2683 int autoidx = fauto->autos->autoidx;
2685 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2686 if( (current->data_type == skip->data_type || get_double_click()) &&
2687 current->gang && current->record && current != skip ) {
2688 int64_t current_position = current->to_units(position, 1);
2689 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2690 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2691 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2692 FloatAuto *previous = 0, *next = 0;
2693 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2695 // create keyframe on neighbouring track at the point in time given by fauto
2696 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2697 float new_value = init_value + change;
2698 CLAMP(new_value, auto_min, auto_max);
2699 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2700 keyframe->set_value(new_value);
2703 // keyframe exists, just change it
2704 float new_value = keyframe->get_value() + change;
2705 CLAMP(new_value, auto_min, auto_max);
2706 keyframe->adjust_to_new_coordinates(current_position, new_value);
2707 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2710 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2714 else if( !fill_gangs ) {
2715 double position = skip->from_units(fauto->position);
2717 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2718 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2719 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2720 float new_value = keyframe->get_value() + change;
2722 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2723 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2724 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2730 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2731 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2732 keyframe->autos->remove_nonsequential(
2735 mwindow->session->drag_auto_gang->remove_all();
2740 void TrackCanvas::draw_toggleline(int center_pixel,
2746 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2750 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2754 int TrackCanvas::test_toggleline(Autos *autos,
2765 if(cursor_x >= x1 && cursor_x < x2)
2767 int miny = center_pixel + y1 - HANDLE_W / 2;
2768 int maxy = center_pixel + y1 + HANDLE_W / 2;
2769 if(cursor_y >= miny && cursor_y < maxy)
2774 if(buttonpress == 3)
2782 double position = (double)(cursor_x +
2783 mwindow->edl->local_session->view_start[pane->number]) *
2784 mwindow->edl->local_session->zoom_sample /
2785 mwindow->edl->session->sample_rate;
2786 int64_t unit_position = autos->track->to_units(position, 0);
2787 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2789 mwindow->undo->update_undo_before();
2791 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2792 ((IntAuto*)current)->value = new_value;
2793 // Toggle Autos don't respond to vertical zoom, they always show up
2794 // with "on" == 100% == line on top
2795 mwindow->session->drag_start_percentage = (float)new_value;
2796 mwindow->session->drag_start_position = current->position;
2797 mwindow->session->drag_origin_x = cursor_x;
2798 mwindow->session->drag_origin_y = cursor_y;
2806 void TrackCanvas::calculate_viewport(Track *track,
2807 double &view_start, // Seconds
2809 double &view_end, // Seconds
2813 double &zoom_sample,
2816 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2817 mwindow->edl->local_session->zoom_sample /
2818 mwindow->edl->session->sample_rate;
2819 unit_start = track->to_doubleunits(view_start);
2820 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2822 mwindow->edl->local_session->zoom_sample /
2823 mwindow->edl->session->sample_rate;
2824 unit_end = track->to_doubleunits(view_end);
2825 yscale = mwindow->edl->local_session->zoom_track;
2826 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2827 center_pixel = (int)(track->y_pixel -
2828 mwindow->edl->local_session->track_start[pane->number] +
2830 (mwindow->edl->session->show_titles ?
2831 mwindow->theme->get_image("title_bg_data")->get_h() :
2833 zoom_sample = mwindow->edl->local_session->zoom_sample;
2835 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2838 float TrackCanvas::percentage_to_value(float percentage,
2846 if(percentage > 0.5)
2853 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2854 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2855 float automation_range = automation_max - automation_min;
2857 result = percentage * automation_range + automation_min;
2860 FloatAuto *ptr = (FloatAuto*)reference;
2861 result -= ptr->get_value();
2863 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2869 void TrackCanvas::calculate_auto_position(double *x, double *y,
2870 double *in_x, double *in_y, double *out_x, double *out_y,
2871 Auto *current, double unit_start, double zoom_units, double yscale,
2874 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2875 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2876 float automation_range = automation_max - automation_min;
2877 FloatAuto *ptr = (FloatAuto*)current;
2878 *x = (double)(ptr->position - unit_start) / zoom_units;
2879 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2882 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2883 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2887 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2888 automation_min) / automation_range - 0.5) * -yscale;
2892 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2893 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2897 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2898 automation_min) / automation_range - 0.5) * -yscale;
2903 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2904 int draw, int buttonpress, int x_offset, int y_offset, int color,
2905 Auto* &auto_instance, int autogrouptype)
2908 int center_pixel, draw_auto;
2909 double view_start, unit_start;
2910 double view_end, unit_end, yscale;
2911 double zoom_sample, zoom_units;
2912 double in_x2, in_y2, out_x2, out_y2;
2918 if(draw) set_color(color);
2920 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2921 yscale, center_pixel, zoom_sample, zoom_units);
2923 // Get first auto before start
2924 Auto *current = 0, *previous = 0;
2926 for( current = autos->last;
2927 current && current->position >= unit_start;
2928 current = PREVIOUS ) ;
2930 Auto *first_auto = current ? current :
2931 autos->first ? autos->first : autos->default_auto;
2933 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2935 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2936 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2941 current = autos->first;
2950 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2951 current, unit_start, zoom_units, yscale, autogrouptype);
2959 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2964 ay2 = ay + slope * (get_w() - ax);
2968 ay = ay + slope * (0 - ax);
2972 // Draw or test handle
2973 if( current && !result && current != autos->default_auto ) {
2974 if( !draw && track->record ) {
2975 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
2976 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
2977 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
2978 buttonpress, autogrouptype);
2980 auto_instance = current;
2982 if( draw && draw_auto ) {
2983 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
2984 (int)in_x2 + x_offset, (int)in_y2,
2985 (int)out_x2 + x_offset, (int)out_y2,
2986 (int)center_pixel + y_offset, (int)yscale, color);
2990 // Draw or test joining line
2991 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
2992 result = test_floatline(center_pixel,
2993 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2994 // Exclude auto coverage from the end of the line. The auto overlaps
2995 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
2996 buttonpress, autogrouptype);
2999 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3000 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3001 (int)ax, (int)ay, (int)ax2, (int)ay2,
3002 color, autogrouptype);
3010 } while( current && current->position <= unit_end && !result );
3012 if( ax < get_w() && !result ) {
3013 ax2 = get_w(); ay2 = ay;
3014 if(!draw && track->record /* && buttonpress != 3 */ ) {
3015 result = test_floatline(center_pixel,
3016 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3017 (int)ax, (int)ax2, cursor_x, cursor_y,
3018 buttonpress, autogrouptype);
3021 draw_floatline(center_pixel,
3022 (FloatAuto*)previous, (FloatAuto*)current,
3023 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3024 (int)ax, (int)ay, (int)ax2, (int)ay2,
3025 color, autogrouptype);
3032 int TrackCanvas::do_int_autos(Track *track,
3041 Auto *&auto_instance)
3052 double ax, ay, ax2, ay2;
3056 if(draw) set_color(color);
3058 calculate_viewport(track,
3069 double high = -yscale * 0.8 / 2;
3070 double low = yscale * 0.8 / 2;
3072 // Get first auto before start
3074 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3080 ay = ((IntAuto*)current)->value > 0 ? high : low;
3085 current = autos->first ? autos->first : autos->default_auto;
3089 ay = ((IntAuto*)current)->value > 0 ? high : low;
3102 ax2 = (double)(current->position - unit_start) / zoom_units;
3103 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3111 if(ax2 > get_w()) ax2 = get_w();
3113 if(current && !result)
3115 if(current != autos->default_auto)
3121 result = test_auto(current,
3130 auto_instance = current;
3135 (int)ax2 + x_offset,
3136 (int)ay2 + y_offset,
3148 if(track->record /* && buttonpress != 3 */)
3150 result = test_toggleline(autos,
3163 draw_toggleline(center_pixel + y_offset,
3171 }while(current && current->position <= unit_end && !result);
3173 if(ax < get_w() && !result)
3179 if(track->record /* && buttonpress != 3 */)
3181 result = test_toggleline(autos,
3193 draw_toggleline(center_pixel + y_offset,
3202 int TrackCanvas::do_autos(Track *track,
3209 Auto * &auto_instance,
3223 calculate_viewport(track,
3236 for(current = autos->first; current && !result; current = NEXT)
3238 if(current->position >= unit_start && current->position < unit_end)
3241 x = (int64_t)((double)(current->position - unit_start) /
3242 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3243 y = center_pixel - pixmap->get_h() / 2;
3247 if(cursor_x >= x && cursor_y >= y &&
3248 cursor_x < x + pixmap->get_w() &&
3249 cursor_y < y + pixmap->get_h())
3252 auto_instance = current;
3254 if(buttonpress && (buttonpress != 3))
3256 mwindow->session->drag_auto = current;
3257 mwindow->session->drag_start_position = current->position;
3258 mwindow->session->drag_origin_x = cursor_x;
3259 mwindow->session->drag_origin_y = cursor_y;
3261 double position = autos->track->from_units(current->position);
3262 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3263 mwindow->edl->local_session->get_selectionend(1)) /
3268 mwindow->edl->local_session->set_selectionstart(position);
3269 mwindow->edl->local_session->set_selectionend(position);
3272 if(position < center)
3274 mwindow->edl->local_session->set_selectionstart(position);
3277 mwindow->edl->local_session->set_selectionend(position);
3284 draw_pixmap(pixmap, x, y);
3292 // so this means it is always >0 when keyframe is found
3293 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3294 int draw, int buttonpress, Plugin* &keyframe_plugin,
3295 KeyFrame* &keyframe_instance)
3308 if(!track->expand_view) return 0;
3310 calculate_viewport(track,
3322 for(int i = 0; i < track->plugin_set.total && !result; i++)
3324 PluginSet *plugin_set = track->plugin_set.values[i];
3325 int center_pixel = (int)(track->y_pixel -
3326 mwindow->edl->local_session->track_start[pane->number] +
3327 mwindow->edl->local_session->zoom_track +
3328 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3329 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3331 for(Plugin *plugin = (Plugin*)plugin_set->first;
3333 plugin = (Plugin*)plugin->next)
3335 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3336 keyframe && !result;
3337 keyframe = (KeyFrame*)keyframe->next)
3339 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3340 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3342 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3343 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3345 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3348 if(cursor_x >= x && cursor_y >= y &&
3349 cursor_x < x + keyframe_pixmap->get_w() &&
3350 cursor_y < y + keyframe_pixmap->get_h())
3353 keyframe_plugin = plugin;
3354 keyframe_instance = keyframe;
3358 mwindow->session->drag_auto = keyframe;
3359 mwindow->session->drag_start_position = keyframe->position;
3360 mwindow->session->drag_origin_x = cursor_x;
3361 mwindow->session->drag_origin_y = cursor_y;
3363 double position = track->from_units(keyframe->position);
3364 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3365 mwindow->edl->local_session->get_selectionend(1)) /
3370 mwindow->edl->local_session->set_selectionstart(position);
3371 mwindow->edl->local_session->set_selectionend(position);
3374 if(position < center)
3376 mwindow->edl->local_session->set_selectionstart(position);
3379 mwindow->edl->local_session->set_selectionend(position);
3384 draw_pixmap(keyframe_pixmap,
3394 // if(buttonpress && buttonpress != 3 && result)
3396 // mwindow->undo->update_undo_before();
3402 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3404 Track *track = auto_keyframe->autos->track;
3405 int autogrouptype = auto_keyframe->autos->get_type();
3408 double view_start, unit_start;
3409 double view_end, unit_end, yscale;
3410 double zoom_sample, zoom_units;
3412 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3413 yscale, center_pixel, zoom_sample, zoom_units);
3415 double ax = 0, ay = 0;
3416 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3417 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3420 draw_line(ax, 0, ax, get_h());
3424 void TrackCanvas::draw_overlays()
3426 int new_cursor, update_cursor, rerender;
3428 // Move background pixmap to foreground pixmap
3429 draw_pixmap(background_pixmap,
3438 draw_inout_points();
3441 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3448 draw_brender_range();
3450 // Highlighted areas
3451 draw_highlighting();
3454 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3457 if(pane->cursor) pane->cursor->restore(1);
3463 draw_playback_cursor();
3465 draw_keyframe_reticle();
3470 int TrackCanvas::activate()
3474 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3475 //BC_Signals::dump_stack();
3476 get_top_level()->deactivate();
3478 set_active_subwindow(this);
3479 pane->cursor->activate();
3480 gui->focused_pane = pane->number;
3485 int TrackCanvas::deactivate()
3490 pane->cursor->deactivate();
3496 void TrackCanvas::update_drag_handle()
3498 double new_position;
3499 int cursor_x = get_cursor_x();
3503 mwindow->edl->local_session->view_start[pane->number]) *
3504 mwindow->edl->local_session->zoom_sample /
3505 mwindow->edl->session->sample_rate;
3508 mwindow->edl->align_to_frame(new_position, 0);
3510 if( ctrl_down() && alt_down() ) {
3511 #define snapper(v) do { \
3513 if( pos < 0 ) break; \
3514 double dist = fabs(new_position - pos); \
3515 if( dist >= snap_min ) break; \
3516 snap_position = pos; snap_min = dist; \
3518 double snap_position = new_position;
3519 double snap_min = DBL_MAX;
3520 if( mwindow->edl->local_session->inpoint_valid() )
3521 snapper(mwindow->edl->local_session->get_inpoint());
3522 if( mwindow->edl->local_session->outpoint_valid() )
3523 snapper(mwindow->edl->local_session->get_outpoint());
3524 snapper(mwindow->edl->prev_edit(new_position));
3525 snapper(mwindow->edl->next_edit(new_position));
3526 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3527 if( prev_label ) snapper(prev_label->position);
3528 Label *next_label = mwindow->edl->labels->next_label(new_position);
3529 if( next_label ) snapper(next_label->position);
3530 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3531 mwindow->edl->local_session->zoom_sample -
3532 mwindow->edl->local_session->view_start[pane->number];
3533 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3535 new_position = snap_position;
3540 if(new_position != mwindow->session->drag_position)
3542 mwindow->session->drag_position = new_position;
3543 gui->mainclock->update(new_position);
3546 timebar_position = new_position;
3547 gui->update_timebar(0);
3548 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3550 // mwindow->cwindow->update(1, 0, 0);
3554 int TrackCanvas::update_drag_edit()
3563 int TrackCanvas::get_drag_values(float *percentage,
3570 //int x = cursor_x - mwindow->session->drag_origin_x;
3571 //int y = cursor_y - mwindow->session->drag_origin_y;
3575 if(!current->autos->track->record) return 1;
3585 calculate_viewport(current->autos->track,
3595 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3597 mwindow->session->drag_start_percentage;
3598 if(do_clamp) CLAMP(*percentage, 0, 1);
3600 *position = Units::to_int64(zoom_units *
3601 (cursor_x - mwindow->session->drag_origin_x) +
3602 mwindow->session->drag_start_position + 0.5);
3604 if((do_clamp) && *position < 0) *position = 0;
3609 #define UPDATE_DRAG_HEAD(do_clamp) \
3610 int result = 0, center_pixel; \
3611 if(!current->autos->track->record) return 0; \
3612 double view_start, unit_start, view_end, unit_end; \
3613 double yscale, zoom_sample, zoom_units; \
3615 calculate_viewport(current->autos->track, \
3616 view_start, unit_start, view_end, unit_end, \
3617 yscale, center_pixel, zoom_sample, zoom_units); \
3619 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3620 yscale + mwindow->session->drag_start_percentage; \
3621 if(do_clamp) CLAMP(percentage, 0, 1); \
3623 int64_t position = Units::to_int64(zoom_units * \
3624 (cursor_x - mwindow->session->drag_origin_x) + \
3625 mwindow->session->drag_start_position); \
3626 if((do_clamp) && position < 0) position = 0;
3629 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3631 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3633 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3634 int x = cursor_x - mwindow->session->drag_origin_x;
3635 int y = cursor_y - mwindow->session->drag_origin_y;
3636 float value, old_value;
3638 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3639 // not really editing the node, rather start editing the curve
3640 // tangent is editable and drag movement is significant
3641 if( (FloatAuto::FREE == current->curve_mode ||
3642 FloatAuto::TFREE==current->curve_mode) &&
3643 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3644 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3647 switch(mwindow->session->drag_handle) {
3649 // Snap to nearby values
3650 old_value = current->get_value();
3652 double value1, value2, distance1, distance2;
3654 if(current->previous) {
3655 int autogrouptype = current->previous->autos->autogrouptype;
3656 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3657 value1 = ((FloatAuto*)current->previous)->get_value();
3658 distance1 = fabs(value - value1);
3659 current->set_value(value1);
3663 int autogrouptype = current->next->autos->autogrouptype;
3664 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3665 value2 = ((FloatAuto*)current->next)->get_value();
3666 distance2 = fabs(value - value2);
3667 if(!current->previous || distance2 < distance1) {
3668 current->set_value(value2);
3672 if(!current->previous && !current->next) {
3673 current->set_value( ((FloatAutos*)current->autos)->default_);
3675 value = current->get_value();
3678 int autogrouptype = current->autos->autogrouptype;
3679 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3682 if(alt_down() && !shift_down())
3683 // ALT constrains movement: fixed position, only changing the value
3684 position = mwindow->session->drag_start_position;
3686 if(value != old_value || position != current->position) {
3688 float change = value - old_value;
3689 current->adjust_to_new_coordinates(position, value);
3690 synchronize_autos(change, current->autos->track, current, 0);
3691 show_message(current, 1,", %.2f", current->get_value());
3697 int autogrouptype = current->autos->autogrouptype;
3698 value = percentage_to_value(percentage, 0, current, autogrouptype);
3699 if(value != current->get_control_in_value())
3702 // note: (position,value) need not be at the location of the ctrl point,
3703 // but could be somewhere in between on the curve (or even outward or
3704 // on the opposit side). We set the new control point such as
3705 // to point the curve through (position,value)
3706 current->set_control_in_value(
3707 value * levered_position(position - current->position,
3708 current->get_control_in_position()));
3709 synchronize_autos(0, current->autos->track, current, 0);
3710 show_message(current, 1,", %.2f", current->get_control_in_value());
3716 int autogrouptype = current->autos->autogrouptype;
3717 value = percentage_to_value(percentage, 0, current, autogrouptype);
3718 if(value != current->get_control_out_value()) {
3720 current->set_control_out_value(
3721 value * levered_position(position - current->position,
3722 current->get_control_out_position()));
3723 synchronize_autos(0, current->autos->track, current, 0);
3724 show_message(current, 1,", %.2f", current->get_control_out_value());
3732 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3734 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3736 UPDATE_DRAG_HEAD(1);
3737 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3739 if(value != current->value || position != current->position)
3742 current->value = value;
3743 current->position = position;
3744 show_message(current, 0,", %d", current->value);
3750 // Autos which can't change value through dragging.
3752 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3754 Auto *current = (Auto*)mwindow->session->drag_auto;
3757 if(position != current->position)
3760 current->position = position;
3761 show_message(current, 0,"");
3763 double position_f = current->autos->track->from_units(current->position);
3764 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3765 mwindow->edl->local_session->get_selectionend(1)) /
3769 mwindow->edl->local_session->set_selectionstart(position_f);
3770 mwindow->edl->local_session->set_selectionend(position_f);
3773 if(position_f < center_f)
3775 mwindow->edl->local_session->set_selectionstart(position_f);
3778 mwindow->edl->local_session->set_selectionend(position_f);
3785 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3787 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3790 if(position != current->position)
3792 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3793 Track *track = current->autos->track;
3794 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3795 PluginSet *pluginset;
3797 // figure out the correct pluginset & correct plugin
3799 for(int i = 0; i < track->plugin_set.total; i++)
3801 pluginset = track->plugin_set.values[i];
3802 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3804 KeyFrames *keyframes = plugin->keyframes;
3805 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3807 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3809 if (currentkeyframe == current)
3821 mwindow->session->plugin_highlighted = plugin;
3822 mwindow->session->track_highlighted = track;
3824 current->position = position;
3825 show_message(current, 0,"");
3827 double position_f = current->autos->track->from_units(current->position);
3828 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3829 mwindow->edl->local_session->get_selectionend(1)) /
3833 mwindow->edl->local_session->set_selectionstart(position_f);
3834 mwindow->edl->local_session->set_selectionend(position_f);
3837 if(position_f < center_f)
3839 mwindow->edl->local_session->set_selectionstart(position_f);
3842 mwindow->edl->local_session->set_selectionend(position_f);
3849 void TrackCanvas::update_drag_caption()
3851 switch(mwindow->session->current_operation)
3861 int TrackCanvas::cursor_motion_event()
3866 int update_clock = 0;
3867 int update_zoom = 0;
3868 int update_scroll = 0;
3869 int update_overlay = 0;
3870 int update_cursor = 0;
3873 double position = 0.;
3874 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3877 switch(mwindow->edl->session->editing_mode)
3879 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3880 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3883 switch(mwindow->session->current_operation)
3885 case DRAG_EDITHANDLE1:
3886 // Outside threshold. Upgrade status
3889 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3891 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3897 case DRAG_EDITHANDLE2:
3900 update_drag_handle();
3905 case DRAG_PLUGINHANDLE1:
3908 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3910 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3916 case DRAG_PLUGINHANDLE2:
3919 update_drag_handle();
3924 // Rubber band curves
3932 case DRAG_PROJECTOR_X:
3933 case DRAG_PROJECTOR_Y:
3934 case DRAG_PROJECTOR_Z:
3935 if(active) rerender = update_overlay =
3936 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3940 if(active) rerender = update_overlay =
3941 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3945 if(active) rerender = update_overlay =
3946 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3949 // Keyframe icons are sticky
3953 case DRAG_PLUGINKEY_PRE:
3955 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3956 mwindow->session->current_operation++;
3959 mwindow->undo->update_undo_before();
3967 if(active) rerender = update_overlay =
3968 update_drag_auto(get_cursor_x(), get_cursor_y());
3971 case DRAG_PLUGINKEY:
3972 if(active) rerender = update_overlay =
3973 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
3978 cursor_x = get_cursor_x();
3979 cursor_y = get_cursor_y();
3980 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
3981 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
3983 position = mwindow->edl->align_to_frame(position, 0);
3984 position = MAX(position, 0);
3986 if(position < selection_midpoint) {
3987 mwindow->edl->local_session->set_selectionend(selection_midpoint);
3988 mwindow->edl->local_session->set_selectionstart(position);
3990 gui->unlock_window();
3991 mwindow->cwindow->update(1, 0, 0, 0, 1);
3992 gui->lock_window("TrackCanvas::cursor_motion_event 1");
3993 // Update the faders
3994 mwindow->update_plugin_guis();
3995 gui->update_patchbay();
3998 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
3999 mwindow->edl->local_session->set_selectionend(position);
4000 // Don't que the CWindow
4003 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4005 gui->hide_cursor(0);
4006 gui->draw_cursor(1);
4007 gui->update_timebar(0);
4008 gui->flash_canvas(1);
4017 if(is_event_win() && cursor_inside()) {
4019 cursor_x = get_cursor_x();
4020 position = (double)cursor_x *
4021 (double)mwindow->edl->local_session->zoom_sample /
4022 (double)mwindow->edl->session->sample_rate +
4023 (double)mwindow->edl->local_session->view_start[pane->number] *
4024 (double)mwindow->edl->local_session->zoom_sample /
4025 (double)mwindow->edl->session->sample_rate;
4026 position = mwindow->edl->align_to_frame(position, 0);
4030 for(int i = 0; i < TOTAL_PANES; i++)
4031 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4033 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4034 gui->update_timebar(0);
4036 if(do_transitions(get_cursor_x(), get_cursor_y(),
4037 0, new_cursor, update_cursor)) break;
4038 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4039 0, 0, new_cursor, update_cursor, rerender)) break;
4040 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4041 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4042 // Plugin boundaries
4043 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4044 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4045 if(do_edits(get_cursor_x(), get_cursor_y(),
4046 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4051 //printf("TrackCanvas::cursor_motion_event 1\n");
4052 if(update_cursor && new_cursor != get_cursor())
4054 set_cursor(new_cursor, 0, 1);
4057 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
4058 if(rerender && render_timer->get_difference() > 0.25 ) {
4059 render_timer->update();
4060 mwindow->restart_brender();
4061 mwindow->sync_parameters(CHANGE_PARAMS);
4062 mwindow->update_plugin_guis();
4063 gui->unlock_window();
4064 mwindow->cwindow->update(1, 0, 0, 0, 1);
4065 gui->lock_window("TrackCanvas::cursor_motion_event 2");
4069 gui->update_patchbay();
4074 if(!mwindow->cwindow->playback_engine->is_playing_back)
4075 gui->mainclock->update(position);
4079 gui->zoombar->update();
4084 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4088 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4092 if(update_overlay) {
4093 gui->draw_overlays(1);
4096 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
4100 void TrackCanvas::start_dragscroll()
4104 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4105 //printf("TrackCanvas::start_dragscroll 1\n");
4109 void TrackCanvas::stop_dragscroll()
4113 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4114 //printf("TrackCanvas::stop_dragscroll 1\n");
4118 int TrackCanvas::repeat_event(int64_t duration)
4120 if(!drag_scroll) return 0;
4121 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4123 int sample_movement = 0;
4124 int track_movement = 0;
4125 int64_t x_distance = 0;
4126 int64_t y_distance = 0;
4127 double position = 0;
4130 switch(mwindow->session->current_operation) {
4132 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4133 if(get_cursor_x() > get_w()) {
4134 x_distance = get_cursor_x() - get_w();
4135 sample_movement = 1;
4137 else if(get_cursor_x() < 0) {
4138 x_distance = get_cursor_x();
4139 sample_movement = 1;
4142 if(get_cursor_y() > get_h()) {
4143 y_distance = get_cursor_y() - get_h();
4146 else if(get_cursor_y() < 0) {
4147 y_distance = get_cursor_y();
4154 if(sample_movement) {
4155 position = (double)(get_cursor_x() +
4156 mwindow->edl->local_session->view_start[pane->number] +
4158 mwindow->edl->local_session->zoom_sample /
4159 mwindow->edl->session->sample_rate;
4160 position = mwindow->edl->align_to_frame(position, 0);
4161 position = MAX(position, 0);
4163 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4164 switch(mwindow->session->current_operation) {
4166 if(position < selection_midpoint) {
4167 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4168 mwindow->edl->local_session->set_selectionstart(position);
4170 gui->unlock_window();
4171 mwindow->cwindow->update(1, 0, 0);
4172 gui->lock_window("TrackCanvas::repeat_event");
4173 // Update the faders
4174 mwindow->update_plugin_guis();
4175 gui->update_patchbay();
4178 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4179 mwindow->edl->local_session->set_selectionend(position);
4180 // Don't que the CWindow
4185 mwindow->samplemovement(
4186 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4190 if(track_movement) {
4191 mwindow->trackmovement(y_distance, pane->number);
4197 int TrackCanvas::button_release_event()
4199 int redraw = 0, update_overlay = 0, result = 0;
4201 // printf("TrackCanvas::button_release_event %d\n",
4202 // mwindow->session->current_operation);
4204 switch(mwindow->session->current_operation) {
4205 case DRAG_EDITHANDLE2:
4206 mwindow->session->current_operation = NO_OPERATION;
4210 end_edithandle_selection();
4213 case DRAG_EDITHANDLE1:
4214 mwindow->session->current_operation = NO_OPERATION;
4219 case DRAG_PLUGINHANDLE2:
4220 mwindow->session->current_operation = NO_OPERATION;
4224 end_pluginhandle_selection();
4227 case DRAG_PLUGINHANDLE1:
4228 mwindow->session->current_operation = NO_OPERATION;
4235 // delete the drag_auto_gang first and remove out of order keys
4236 synchronize_autos(0, 0, 0, -1);
4247 case DRAG_PROJECTOR_X:
4248 case DRAG_PROJECTOR_Y:
4249 case DRAG_PROJECTOR_Z:
4250 case DRAG_PLUGINKEY:
4251 mwindow->session->current_operation = NO_OPERATION;
4252 mwindow->session->drag_handle = 0;
4253 // Remove any out-of-order keyframe
4254 if(mwindow->session->drag_auto) {
4255 mwindow->session->drag_auto->autos->remove_nonsequential(
4256 mwindow->session->drag_auto);
4257 // mwindow->session->drag_auto->autos->optimize();
4262 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4267 case DRAG_AEFFECT_COPY:
4268 case DRAG_VEFFECT_COPY:
4269 // Trap in drag stop
4274 if(mwindow->session->current_operation) {
4275 // if(mwindow->session->current_operation == SELECT_REGION) {
4276 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4279 mwindow->session->current_operation = NO_OPERATION;
4281 // Traps button release events
4289 cursor_motion_event();
4291 if(update_overlay) {
4292 gui->draw_overlays(1);
4295 gui->draw_canvas(NORMAL_DRAW, 0);
4300 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4301 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4303 Edit *edit_result = 0;
4304 int handle_result = 0;
4307 if(!mwindow->edl->session->show_assets) return 0;
4309 for(Track *track = mwindow->edl->tracks->first;
4311 track = track->next) {
4312 for(Edit *edit = track->edits->first;
4314 edit = edit->next) {
4315 int64_t edit_x, edit_y, edit_w, edit_h;
4316 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4318 if(cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4319 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4320 if(cursor_x < edit_x + HANDLE_W) {
4325 else if(cursor_x >= edit_x + edit_w - HANDLE_W) {
4339 double position = 0;
4340 if(handle_result == 0) {
4341 position = edit_result->track->from_units(edit_result->startproject);
4342 new_cursor = LEFT_CURSOR;
4344 else if(handle_result == 1) {
4345 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4346 new_cursor = RIGHT_CURSOR;
4349 // Reposition cursor
4351 mwindow->session->drag_edit = edit_result;
4352 mwindow->session->drag_handle = handle_result;
4353 mwindow->session->drag_button = get_buttonpress() - 1;
4354 mwindow->session->drag_position = position;
4355 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4356 mwindow->session->drag_origin_x = get_cursor_x();
4357 mwindow->session->drag_origin_y = get_cursor_y();
4358 mwindow->session->drag_start = position;
4360 rerender = start_selection(position);
4368 int TrackCanvas::do_plugin_handles(int cursor_x,
4372 int &update_overlay,
4376 Plugin *plugin_result = 0;
4377 int handle_result = 0;
4380 // if(!mwindow->edl->session->show_assets) return 0;
4382 for(Track *track = mwindow->edl->tracks->first;
4384 track = track->next) {
4385 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4386 PluginSet *plugin_set = track->plugin_set.values[i];
4387 for(Plugin *plugin = (Plugin*)plugin_set->first;
4389 plugin = (Plugin*)plugin->next) {
4390 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4391 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4393 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4394 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4395 if(cursor_x < plugin_x + HANDLE_W) {
4396 plugin_result = plugin;
4400 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4401 plugin_result = plugin;
4408 if(result && shift_down())
4409 mwindow->session->trim_edits = plugin_set;
4415 double position = 0;
4416 if(handle_result == 0) {
4417 position = plugin_result->track->from_units(plugin_result->startproject);
4418 new_cursor = LEFT_CURSOR;
4420 else if(handle_result == 1) {
4421 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4422 new_cursor = RIGHT_CURSOR;
4426 mwindow->session->drag_plugin = plugin_result;
4427 mwindow->session->drag_handle = handle_result;
4428 mwindow->session->drag_button = get_buttonpress() - 1;
4429 mwindow->session->drag_position = position;
4430 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4431 mwindow->session->drag_origin_x = get_cursor_x();
4432 mwindow->session->drag_origin_y = get_cursor_y();
4433 mwindow->session->drag_start = position;
4435 rerender = start_selection(position);
4444 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4448 // if(!mwindow->edl->session->show_assets) return 0;
4450 for(Track *track = mwindow->edl->tracks->first;
4452 track = track->next) {
4453 int64_t track_x, track_y, track_w, track_h;
4454 track_dimensions(track, track_x, track_y, track_w, track_h);
4456 if(button_press && get_buttonpress() == RIGHT_BUTTON &&
4457 cursor_y >= track_y && cursor_y < track_y + track_h) {
4458 gui->edit_menu->update(track, 0);
4459 gui->edit_menu->activate_menu();
4467 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4468 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4472 if(!mwindow->edl->session->show_assets) return 0;
4474 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4476 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4477 int64_t edit_x, edit_y, edit_w, edit_h;
4478 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4480 // Cursor inside a track
4481 // Cursor inside an edit
4482 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4483 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4484 // Select duration of edit
4486 if(get_double_click() && !drag_start) {
4487 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4488 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4489 edit->track->from_units(edit->length));
4490 if(mwindow->edl->session->cursor_on_frames)
4492 mwindow->edl->local_session->set_selectionstart(
4493 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4494 mwindow->edl->local_session->set_selectionend(
4495 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4503 else if(drag_start && track->record) {
4504 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4505 // Need to create drag window
4506 mwindow->session->current_operation = DRAG_EDIT;
4507 mwindow->session->drag_edit = edit;
4508 //printf("TrackCanvas::do_edits 2\n");
4510 // Drag only one edit if ctrl is initially down
4512 mwindow->session->drag_edits->remove_all();
4513 mwindow->session->drag_edits->append(edit);
4516 // Construct list of all affected edits
4517 mwindow->edl->tracks->get_affected_edits(
4518 mwindow->session->drag_edits,
4519 edit->track->from_units(edit->startproject),
4522 mwindow->session->drag_origin_x = cursor_x;
4523 mwindow->session->drag_origin_y = cursor_y;
4524 // Where the drag started, so we know relative position inside the edit later
4525 mwindow->session->drag_position = (double)cursor_x *
4526 mwindow->edl->local_session->zoom_sample /
4527 mwindow->edl->session->sample_rate +
4528 (double)mwindow->edl->local_session->view_start[pane->number] *
4529 mwindow->edl->local_session->zoom_sample /
4530 mwindow->edl->session->sample_rate;
4533 get_abs_cursor(cx, cy);
4534 gui->drag_popup = new BC_DragWindow(gui,
4535 mwindow->theme->get_image("clip_icon"), cx, cy);
4547 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4552 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4553 int button_press, int &redraw, int &rerender)
4562 // if(!mwindow->edl->session->show_assets) return 0;
4565 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4566 if(!track->expand_view) continue;
4568 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4569 // first check if plugins are visible at all
4570 if (!track->expand_view)
4572 PluginSet *plugin_set = track->plugin_set.values[i];
4573 for(plugin = (Plugin*)plugin_set->first;
4575 plugin = (Plugin*)plugin->next) {
4576 plugin_dimensions(plugin, x, y, w, h);
4577 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4578 MWindowGUI::visible(y, y + h, 0, get_h())) {
4579 if(cursor_x >= x && cursor_x < x + w &&
4580 cursor_y >= y && cursor_y < y + h) {
4590 // Start plugin popup
4592 if(get_buttonpress() == 3) {
4593 gui->plugin_menu->update(plugin);
4594 gui->plugin_menu->activate_menu();
4597 else if (get_double_click() && !drag_start) {
4598 // Select range of plugin on doubleclick over plugin
4599 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4600 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4601 plugin->track->from_units(plugin->length));
4602 if(mwindow->edl->session->cursor_on_frames) {
4603 mwindow->edl->local_session->set_selectionstart(
4604 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4605 mwindow->edl->local_session->set_selectionend(
4606 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4615 if(drag_start && plugin->track->record) {
4616 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4617 if(plugin->track->data_type == TRACK_AUDIO)
4618 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4619 else if(plugin->track->data_type == TRACK_VIDEO)
4620 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4622 mwindow->session->drag_plugin = plugin;
4623 mwindow->session->drag_origin_x = cursor_x;
4624 mwindow->session->drag_origin_y = cursor_y;
4625 // Where the drag started, so we know relative position inside the edit later
4626 mwindow->session->drag_position =
4627 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4628 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4630 switch(plugin->plugin_type) {
4631 case PLUGIN_STANDALONE: {
4632 PluginServer *server =
4633 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4634 if( !server ) break;
4635 VFrame *frame = server->picon;
4637 if(plugin->track->data_type == TRACK_AUDIO) {
4638 frame = mwindow->theme->get_image("aeffect_icon");
4641 frame = mwindow->theme->get_image("veffect_icon");
4645 get_abs_cursor(cx, cy);
4646 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4649 case PLUGIN_SHAREDPLUGIN:
4650 case PLUGIN_SHAREDMODULE: {
4651 VFrame *frame = mwindow->theme->get_image("clip_icon");
4653 get_abs_cursor(cx, cy);
4654 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4666 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4667 int button_press, int &new_cursor, int &update_cursor)
4669 Transition *transition = 0;
4673 if(/* !mwindow->edl->session->show_assets || */
4674 !mwindow->edl->session->auto_conf->transitions) return 0;
4676 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4678 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4679 if( edit->transition ) {
4680 edit_dimensions(edit, x, y, w, h);
4681 get_transition_coords(x, y, w, h);
4683 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4684 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4685 if( cursor_x >= x && cursor_x < x + w &&
4686 cursor_y >= y && cursor_y < y + h ) {
4687 transition = edit->transition;
4699 new_cursor = UPRIGHT_ARROW_CURSOR;
4701 else if(get_buttonpress() == 3) {
4702 gui->transition_menu->update(transition);
4703 gui->transition_menu->activate_menu();
4710 int TrackCanvas::button_press_event()
4713 int cursor_x, cursor_y;
4716 cursor_x = get_cursor_x();
4717 cursor_y = get_cursor_y();
4718 mwindow->session->trim_edits = 0;
4720 if(is_event_win() && cursor_inside()) {
4721 // double position = (double)cursor_x *
4722 // mwindow->edl->local_session->zoom_sample /
4723 // mwindow->edl->session->sample_rate +
4724 // (double)mwindow->edl->local_session->view_start[pane->number] *
4725 // mwindow->edl->local_session->zoom_sample /
4726 // mwindow->edl->session->sample_rate;
4733 if( get_buttonpress() == LEFT_BUTTON &&
4734 gui->mbuttons->transport->engine->command->command != STOP ) {
4735 gui->unlock_window();
4736 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4737 gui->lock_window("TrackCanvas::button_press_event");
4740 int update_overlay = 0, update_cursor = 0, rerender = 0;
4742 if(get_buttonpress() == WHEEL_UP) {
4744 mwindow->expand_sample();
4745 else if(ctrl_down())
4746 mwindow->move_left(get_w()/ 10);
4748 mwindow->move_up(get_h() / 10);
4750 else if(get_buttonpress() == WHEEL_DOWN) {
4752 mwindow->zoom_in_sample();
4753 else if(ctrl_down())
4754 mwindow->move_right(get_w() / 10);
4756 mwindow->move_down(get_h() / 10);
4758 else if(get_buttonpress() == 6) {
4760 mwindow->move_left(get_w());
4762 mwindow->move_left(get_w() / 20);
4764 mwindow->move_left(get_w() / 5);
4766 else if(get_buttonpress() == 7) {
4768 mwindow->move_right(get_w());
4770 mwindow->move_right(get_w() / 20);
4772 mwindow->move_right(get_w() / 5);
4775 switch(mwindow->edl->session->editing_mode) {
4776 // Test handles and resource boundaries and highlight a track
4777 case EDITING_ARROW: {
4778 if( do_transitions(cursor_x, cursor_y,
4779 1, new_cursor, update_cursor) ) break;
4781 if( do_keyframes(cursor_x, cursor_y,
4782 0, get_buttonpress(), new_cursor,
4783 update_cursor, rerender) ) break;
4784 // Test edit boundaries
4785 if( do_edit_handles(cursor_x, cursor_y,
4786 1, rerender, update_overlay, new_cursor,
4787 update_cursor) ) break;
4788 // Test plugin boundaries
4789 if( do_plugin_handles(cursor_x, cursor_y,
4790 1, rerender, update_overlay, new_cursor,
4791 update_cursor) ) break;
4793 if( do_edits(cursor_x, cursor_y, 1, 0,
4794 update_cursor, rerender, new_cursor,
4795 update_cursor) ) break;
4797 if( do_plugins(cursor_x, cursor_y, 0, 1,
4798 update_cursor, rerender) ) break;
4800 if( test_resources(cursor_x, cursor_y) ) break;
4802 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4807 // Test handles only and select a region
4808 case EDITING_IBEAM: {
4809 double position = (double)cursor_x *
4810 mwindow->edl->local_session->zoom_sample /
4811 mwindow->edl->session->sample_rate +
4812 (double)mwindow->edl->local_session->view_start[pane->number] *
4813 mwindow->edl->local_session->zoom_sample /
4814 mwindow->edl->session->sample_rate;
4815 //printf("TrackCanvas::button_press_event %d\n", position);
4817 if( do_transitions(cursor_x, cursor_y,
4818 1, new_cursor, update_cursor)) break;
4819 if(do_keyframes(cursor_x, cursor_y,
4820 0, get_buttonpress(), new_cursor,
4821 update_cursor, rerender)) {
4825 // Test edit boundaries
4826 if( do_edit_handles(cursor_x, cursor_y,
4827 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4828 // Test plugin boundaries
4829 if( do_plugin_handles(cursor_x, cursor_y,
4830 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4832 if( do_edits(cursor_x, cursor_y,
4833 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4835 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4837 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4838 // Highlight selection
4839 if( get_buttonpress() != LEFT_BUTTON ) break;
4840 rerender = start_selection(position);
4841 mwindow->session->current_operation = SELECT_REGION;
4848 gui->unlock_window();
4849 mwindow->cwindow->update(1, 0, 0, 0, 1);
4850 gui->lock_window("TrackCanvas::button_press_event 2");
4852 mwindow->update_plugin_guis();
4853 gui->update_patchbay();
4856 if( update_overlay ) {
4857 gui->draw_overlays(1);
4859 if( update_cursor < 0 ) {
4860 // double_click edit
4861 gui->swindow->update_selection();
4863 if( update_cursor ) {
4864 gui->update_timebar(0);
4865 gui->hide_cursor(0);
4866 gui->show_cursor(1);
4867 gui->zoombar->update();
4868 gui->flash_canvas(1);
4875 int TrackCanvas::start_selection(double position)
4878 position = mwindow->edl->align_to_frame(position, 1);
4884 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4885 mwindow->edl->local_session->get_selectionend(1)) / 2;
4887 if(position < midpoint)
4889 mwindow->edl->local_session->set_selectionstart(position);
4890 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4896 mwindow->edl->local_session->set_selectionend(position);
4897 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4898 // Don't que the CWindow for the end
4902 // Start a new selection
4904 //printf("TrackCanvas::start_selection %f\n", position);
4905 mwindow->edl->local_session->set_selectionstart(position);
4906 mwindow->edl->local_session->set_selectionend(position);
4907 selection_midpoint = position;
4915 void TrackCanvas::end_edithandle_selection()
4917 mwindow->modify_edithandles();
4920 void TrackCanvas::end_pluginhandle_selection()
4922 mwindow->modify_pluginhandles();
4926 double TrackCanvas::time_visible()
4928 return (double)get_w() *
4929 mwindow->edl->local_session->zoom_sample /
4930 mwindow->edl->session->sample_rate;
4934 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
4936 char string[BCTEXTLEN];
4937 char *cp = string, *ep = cp + sizeof(string)-1;
4938 if( show_curve_type ) {
4939 cp += snprintf(string, ep-cp, "%-8s ",
4940 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
4942 char string2[BCTEXTLEN];
4943 Units::totext(string2,
4944 current->autos->track->from_units(current->position),
4945 mwindow->edl->session->time_format,
4946 mwindow->edl->session->sample_rate,
4947 mwindow->edl->session->frame_rate,
4948 mwindow->edl->session->frames_per_foot);
4949 cp += snprintf(cp, ep-cp, "%s", string2);
4952 vsnprintf(cp, ep-cp, fmt, ap);
4954 gui->show_message(string);
4957 // Patchbay* TrackCanvas::get_patchbay()
4959 // if(pane->patchbay) return pane->patchbay;
4960 // if(gui->total_panes() == 2 &&
4961 // gui->pane[TOP_LEFT_PANE] &&
4962 // gui->pane[TOP_RIGHT_PANE])
4963 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4964 // if(gui->total_panes() == 4)
4966 // if(pane->number == TOP_RIGHT_PANE)
4967 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4969 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;