4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "apatchgui.inc"
25 #include "automation.h"
26 #include "bcsignals.h"
30 #include "cplayback.h"
32 #include "cwindowgui.h"
34 #include "edithandles.h"
35 #include "editpopup.h"
38 #include "edlsession.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
41 #include "indexstate.h"
45 #include "keyframepopup.h"
46 #include "keyframes.h"
48 #include "localsession.h"
49 #include "mainclock.h"
50 #include "maincursor.h"
51 #include "mainsession.h"
53 #include "maskautos.h"
56 #include "mwindowgui.h"
60 #include "playbackengine.h"
61 #include "playtransport.h"
63 #include "pluginpopup.h"
64 #include "pluginserver.h"
65 #include "pluginset.h"
66 #include "plugintoggles.h"
67 #include "preferences.h"
68 #include "resourcepixmap.h"
69 #include "resourcethread.h"
72 #include "trackcanvas.h"
75 #include "transition.h"
76 #include "transitionhandles.h"
77 #include "transitionpopup.h"
78 #include "transportque.h"
80 #include "vpatchgui.inc"
85 //#define PIXMAP_AGE -5
86 #define PIXMAP_AGE -32
88 TrackCanvas::TrackCanvas(MWindow *mwindow,
99 this->mwindow = mwindow;
100 this->gui = mwindow->gui;
103 selection_midpoint = 0;
107 resource_timer = new Timer;
108 render_timer = new Timer;
109 hourglass_enabled = 0;
110 timebar_position = -1;
113 TrackCanvas::~TrackCanvas()
115 // delete transition_handles;
117 delete keyframe_pixmap;
118 delete camerakeyframe_pixmap;
119 delete modekeyframe_pixmap;
120 delete pankeyframe_pixmap;
121 delete projectorkeyframe_pixmap;
122 delete maskkeyframe_pixmap;
123 delete background_pixmap;
124 if(temp_picon) delete temp_picon;
126 delete resource_timer;
129 void TrackCanvas::create_objects()
131 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
132 // transition_handles = new TransitionHandles(mwindow, this);
133 edit_handles = new EditHandles(mwindow, this);
134 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
135 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
136 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
137 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
138 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
139 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
145 void TrackCanvas::resize_event()
147 //printf("TrackCanvas::resize_event 1\n");
150 //printf("TrackCanvas::resize_event 2\n");
153 int TrackCanvas::keypress_event()
158 int TrackCanvas::cursor_leave_event()
160 // Because drag motion calls get_cursor_over_window we can be sure that
161 // all highlights get deleted now.
162 // This ended up blocking keyboard input from the drag operations.
163 if( timebar_position >= 0 )
165 timebar_position = -1;
167 pane->timebar->update(1);
171 // return drag_motion();
174 int TrackCanvas::drag_motion_event()
176 return gui->drag_motion();
179 int TrackCanvas::drag_motion(Track **over_track,
181 PluginSet **over_pluginset,
182 Plugin **over_plugin)
184 int cursor_x = get_relative_cursor_x();
185 int cursor_y = get_relative_cursor_y();
187 if( get_cursor_over_window() &&
188 cursor_x >= 0 && cursor_y >= 0 &&
189 cursor_x < get_w() && cursor_y < get_h() )
191 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
192 // Find the edit and track the cursor is over
193 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
195 int64_t track_x, track_y, track_w, track_h;
196 track_dimensions(track, track_x, track_y, track_w, track_h);
198 if(cursor_y >= track_y &&
199 cursor_y < track_y + track_h)
202 for(Edit *edit = track->edits->first; edit; edit = edit->next)
204 int64_t edit_x, edit_y, edit_w, edit_h;
205 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
207 if(cursor_x >= edit_x &&
208 cursor_y >= edit_y &&
209 cursor_x < edit_x + edit_w &&
210 cursor_y < edit_y + edit_h)
217 for(int i = 0; i < track->plugin_set.total; i++)
219 PluginSet *pluginset = track->plugin_set.values[i];
220 for(Plugin *plugin = (Plugin*)pluginset->first;
222 plugin = (Plugin*)plugin->next)
224 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
225 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
227 if(cursor_y >= plugin_y &&
228 cursor_y < plugin_y + plugin_h)
230 *over_pluginset = plugin->plugin_set;
232 if(cursor_x >= plugin_x &&
233 cursor_x < plugin_x + plugin_w)
235 *over_plugin = plugin;
247 *over_track = pane->is_over_patchbay();
253 int TrackCanvas::drag_stop_event()
255 int result = gui->drag_stop();
256 if( !result && mwindow->session->current_operation ) {
257 mwindow->session->current_operation = NO_OPERATION;
263 int TrackCanvas::drag_stop(int *redraw)
268 int cursor_x = -1, cursor_y = -1;
270 if( get_cursor_over_window() ) {
271 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
272 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
275 Track *track = pane->is_over_patchbay();
276 if( track && mwindow->session->track_highlighted == track )
282 switch(mwindow->session->current_operation) {
283 case DRAG_VTRANSITION:
284 case DRAG_ATRANSITION:
285 if(mwindow->session->edit_highlighted) {
286 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
287 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
288 (mwindow->session->current_operation == DRAG_VTRANSITION &&
289 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
290 mwindow->session->current_operation = NO_OPERATION;
291 mwindow->paste_transition();
298 // Behavior for dragged plugins is limited by the fact that a shared plugin
299 // can only refer to a standalone plugin that exists in the same position in
300 // time. Dragging a plugin from one point in time to another can't produce
301 // a shared plugin to the original plugin. In this case we relocate the
302 // plugin instead of sharing it.
303 case DRAG_AEFFECT_COPY:
304 case DRAG_VEFFECT_COPY:
305 if( mwindow->session->track_highlighted &&
306 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
307 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
308 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
309 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
310 mwindow->session->current_operation = NO_OPERATION;
312 int64_t drop_position = -1;
313 Plugin *drag_plugin = mwindow->session->drag_plugin;
314 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
315 Track *hi_track = mwindow->session->track_highlighted;
317 // Insert shared plugin in source
318 // Move source to different location
319 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
320 //printf("TrackCanvas::drag_stop 6\n");
321 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
322 if( drop_position >= 0 )
323 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
326 else if( hi_track ) {
327 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
328 Edit *hi_edit = mwindow->session->edit_highlighted;
329 drop_position = hi_edit ? hi_edit->startproject : 0;
330 if( drop_position >= 0 )
331 mwindow->move_effect(drag_plugin, hi_track, drop_position);
339 if( mwindow->session->track_highlighted &&
340 ((mwindow->session->current_operation == DRAG_AEFFECT &&
341 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
342 (mwindow->session->current_operation == DRAG_VEFFECT &&
343 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
344 // Drop all the effects
345 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
346 Track *track = mwindow->session->track_highlighted;
348 double length = track->get_length();
350 if(mwindow->session->plugin_highlighted) {
351 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
352 length = track->from_units(mwindow->session->plugin_highlighted->length);
353 if(length <= 0) length = track->get_length();
355 else if(mwindow->session->pluginset_highlighted) {
356 start = track->from_units(plugin_set->length());
357 length = track->get_length() - start;
358 if(length <= 0) length = track->get_length();
360 else if(mwindow->edl->local_session->get_selectionend() >
361 mwindow->edl->local_session->get_selectionstart()) {
362 start = mwindow->edl->local_session->get_selectionstart();
363 length = mwindow->edl->local_session->get_selectionend() -
364 mwindow->edl->local_session->get_selectionstart();
366 // Move to a point between two edits
367 else if(mwindow->session->edit_highlighted) {
368 start = mwindow->session->track_highlighted->from_units(
369 mwindow->session->edit_highlighted->startproject);
370 length = mwindow->session->track_highlighted->from_units(
371 mwindow->session->edit_highlighted->length);
374 mwindow->insert_effects_canvas(start, length);
377 if( mwindow->session->track_highlighted )
378 result = 1; // we have to cleanup
382 if(mwindow->session->track_highlighted) {
383 double asset_duration = 0;
384 int64_t asset_length_units = 0;
385 int64_t position = 0;
387 if(mwindow->session->current_operation == DRAG_ASSET &&
388 mwindow->session->drag_assets->total) {
389 Indexable *indexable = mwindow->session->drag_assets->values[0];
390 // we use video if we are over video and audio if we are over audio
391 if( indexable->have_video() &&
392 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
393 // Images have length -1
394 int64_t video_length = indexable->get_video_frames();
395 if (video_length < 0) {
396 if(mwindow->edl->session->si_useduration)
397 video_length = mwindow->edl->session->si_duration;
399 video_length = 1.0 / mwindow->edl->session->frame_rate ;
401 asset_duration = video_length / indexable->get_frame_rate();
403 else if( indexable->have_audio() &&
404 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
405 int64_t audio_length = indexable->get_audio_samples();
406 asset_duration = (double)audio_length / indexable->get_sample_rate();
410 break; // Do not do anything
413 else if( mwindow->session->current_operation == DRAG_ASSET &&
414 mwindow->session->drag_clips->total ) {
415 EDL *clip = mwindow->session->drag_clips->values[0];
416 asset_duration = clip->tracks->total_length();
419 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
422 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
423 position = drop_edit_position (&insertion, NULL, asset_length_units);
424 if( position == -1 ) {
426 break; // Do not do anything
429 double position_f = mwindow->session->track_highlighted->from_units(position);
430 Track *track = mwindow->session->track_highlighted;
433 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
434 // // Unfortunately, this is _a lot_ of work to do right
435 // printf("Problematic insertion\n");
436 // mwindow->edl->tracks->clear(position_f,
437 // position_f + asset_duration, 0);
439 mwindow->paste_assets(position_f, track, !insertion);
440 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
445 mwindow->session->current_operation = NO_OPERATION;
446 if(mwindow->session->track_highlighted) {
447 if( mwindow->session->track_highlighted->data_type ==
448 mwindow->session->drag_edit->track->data_type) {
449 int64_t position = 0;
450 position = drop_edit_position(&insertion,
451 mwindow->session->drag_edit,
452 mwindow->session->drag_edit->length);
453 if (position == -1) {
455 break; // Do not do anything
458 double position_f = mwindow->session->track_highlighted->from_units(position);
459 Track *track = mwindow->session->track_highlighted;
460 mwindow->move_edits(mwindow->session->drag_edits,
461 track, position_f, !insertion);
473 int TrackCanvas::drag_start_event()
478 int new_cursor, update_cursor;
480 if(mwindow->session->current_operation != NO_OPERATION) return 0;
483 if(do_plugins(get_drag_x(), get_drag_y(),
484 1, 0, redraw, rerender)) {
487 else if(do_edits(get_drag_x(), get_drag_y(),
488 0, 1, redraw, rerender, new_cursor, update_cursor)) {
496 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
498 // get the canvas/track position
499 Track *track = mwindow->session->track_highlighted;
500 int cursor_x = get_relative_cursor_x();
501 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
502 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
503 // we use cursor position for affinity calculations
504 int64_t cursor_position = track->to_units(drop_time, 0);
505 if( cursor_position <= 0 ) {
509 if( moved_edit ) // relative cursor position depends upon drop point
510 drop_time -= mwindow->session->drag_position - moved_edit->track->from_units(moved_edit->startproject);
511 int64_t drop_position = track->to_units(drop_time, 1);
512 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
513 drop_position -= moved_edit_length / 2;
514 Edit *last_edit = track->edits->last;
515 if( !last_edit || drop_position > last_edit->startproject+last_edit->length ) {
517 return drop_position;
520 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
521 for( Edit *edit = track->edits->first; edit; ) {
522 int64_t edit_x0 = edit->startproject, edit_x1 = edit_x0 + edit->length;
523 if( Units::round(labs(edit_x0-cursor_position)*zoom_scale) < HANDLE_W ) {
524 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
525 return edit->startproject;
527 if( Units::round(labs(edit_x1-cursor_position)*zoom_scale) < HANDLE_W ) {
528 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
529 return edit->startproject + edit->length;
531 if( edit != moved_edit && !edit->silence() )
532 drop_x0 = edit_x1; // reset drop zone
533 if( (edit=edit->next) != 0 ) {
534 if( edit == moved_edit || edit->silence() ) continue;
539 //printf("drop cursor=%jd, x0=%jd, x1=%jd\n", cursor_position, drop_x0, drop_x1);
540 if( drop_position >= drop_x0 && drop_position+moved_edit_length < drop_x1 ) {
541 *is_insertion = 0; // fits in the zone
542 //printf("into %jd\n", drop_position);
543 return drop_position;
545 if( cursor_position < drop_x1 ) { // drop in the zone
546 if( (drop_x1-drop_x0) >= moved_edit_length ) {
547 *is_insertion = 0; // fits in the zone, but over the edge
548 int64_t dx0 = llabs(cursor_position-drop_x0);
549 int64_t dx1 = llabs(cursor_position-drop_x1);
550 //printf("onto %jd\n", dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length);
551 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length;
553 int edit_center = (edit_x0+edit_x1) / 2;
554 if( cursor_position < edit_center ) {
556 //printf("snap left %jd\n", drop_x0);
557 return drop_x0; // snap left
561 //printf("snap right %jd\n", drop_x1);
562 return drop_x1; // snap right
571 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
573 // get the canvas/track position
574 Track *track = plugin_set->track;
575 int cursor_x = get_relative_cursor_x();
576 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
577 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
578 // we use cursor position for affinity calculations
579 int64_t cursor_position = track->to_units(drop_time, 0);
580 if( cursor_position <= 0 ) return 0;
581 drop_time -= mwindow->session->drag_position - moved_plugin->track->from_units(moved_plugin->startproject);
582 int64_t drop_position = track->to_units(drop_time, 1);
583 Plugin *last_plugin = (Plugin *)plugin_set->last;
584 if( !last_plugin || drop_position > last_plugin->startproject+last_plugin->length ) {
585 return drop_position;
588 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
589 for( Plugin *plugin = (Plugin *)plugin_set->first; plugin; ) {
590 int64_t plugin_x0 = plugin->startproject, plugin_x1 = plugin_x0 + plugin->length;
591 if( plugin != moved_plugin && !plugin->silence() )
593 if( (plugin=(Plugin *)plugin->next) != 0 ) {
594 if( plugin == moved_plugin || plugin->silence() ) continue;
599 if( drop_position >= drop_x0 && // fits in the zone
600 drop_position+moved_plugin->length < drop_x1 ) {
601 return drop_position;
603 if( cursor_position < drop_x1 ) { // drop in the zone
604 if( (drop_x1-drop_x0) >= moved_plugin->length ) {
605 int64_t dx0 = llabs(cursor_position-drop_x0);
606 int64_t dx1 = llabs(cursor_position-drop_x1);
607 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_plugin->length;
616 void TrackCanvas::draw(int mode, int hide_cursor)
621 // Swap pixmap layers
622 if(get_w() != background_pixmap->get_w() ||
623 get_h() != background_pixmap->get_h())
625 delete background_pixmap;
626 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
629 // Cursor disappears after resize when this is called.
630 // Cursor doesn't redraw after editing when this isn't called.
631 if(pane->cursor && hide_cursor) pane->cursor->hide();
632 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
634 if(debug) PRINT_TRACE
635 draw_resources(mode);
637 if(debug) PRINT_TRACE
639 if(debug) PRINT_TRACE
642 void TrackCanvas::update_cursor(int flush)
644 switch(mwindow->edl->session->editing_mode)
646 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
647 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
652 void TrackCanvas::test_timer()
654 if(resource_timer->get_difference() > 1000 &&
658 hourglass_enabled = 1;
663 void TrackCanvas::draw_indexes(Indexable *indexable)
665 // Don't redraw raw samples
666 IndexState *index_state = 0;
667 index_state = indexable->index_state;
670 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
674 draw_resources(0, 1, indexable);
680 void TrackCanvas::draw_resources(int mode,
682 Indexable *indexable)
686 if(debug) PRINT_TRACE
688 if(!mwindow->edl->session->show_assets) return;
691 // can't stop thread here, because this is called for every pane
692 // if(mode != IGNORE_THREAD && !indexes_only)
693 // gui->resource_thread->stop_draw(!indexes_only);
695 if(mode != IGNORE_THREAD &&
697 !gui->resource_thread->interrupted)
699 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
702 BC_Signals::dump_stack();
705 if(debug) PRINT_TRACE
707 resource_timer->update();
709 // Age resource pixmaps for deletion
711 for(int i = 0; i < gui->resource_pixmaps.total; i++)
712 gui->resource_pixmaps.values[i]->visible--;
714 if(mode == FORCE_REDRAW)
715 gui->resource_pixmaps.remove_all_objects();
717 if(debug) PRINT_TRACE
720 for(Track *current = mwindow->edl->tracks->first;
724 if(debug) PRINT_TRACE
725 for(Edit *edit = current->edits->first; edit; edit = edit->next)
727 if(debug) PRINT_TRACE
728 if( current->data_type != TRACK_SUBTITLE )
729 if(!edit->asset && !edit->nested_edl) continue;
732 if(edit->track->data_type != TRACK_AUDIO) continue;
734 if(edit->nested_edl &&
735 strcmp(indexable->path, edit->nested_edl->path)) continue;
738 strcmp(indexable->path, edit->asset->path)) continue;
741 if(debug) PRINT_TRACE
743 int64_t edit_x, edit_y, edit_w, edit_h;
744 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
747 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
748 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
750 int64_t pixmap_x, pixmap_w, pixmap_h;
751 if(debug) PRINT_TRACE
753 // Search for existing pixmap containing edit
754 for(int i = 0; i < gui->resource_pixmaps.total; i++)
756 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
757 // Same pointer can be different edit if editing took place
758 if(pixmap->edit_id == edit->id &&
759 pixmap->pane_number == pane->number)
765 if(debug) PRINT_TRACE
767 // Get new size, offset of pixmap needed
768 get_pixmap_size(edit,
774 if(debug) PRINT_TRACE
777 if(pixmap_w && pixmap_h)
779 // Create pixmap if it doesn't exist
780 ResourcePixmap* pixmap = create_pixmap(edit,
785 // Resize it if it's bigger
786 if(pixmap_w > pixmap->pixmap_w ||
787 pixmap_h > pixmap->pixmap_h)
788 pixmap->resize(pixmap_w, pixmap_h);
789 pixmap->draw_data(this,
798 // Resize it if it's smaller
799 if(pixmap_w < pixmap->pixmap_w ||
800 pixmap_h < pixmap->pixmap_h)
801 pixmap->resize(pixmap_w, pixmap_h);
803 // Copy pixmap to background canvas
804 background_pixmap->draw_pixmap(pixmap,
806 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
810 if(debug) PRINT_TRACE
817 // Delete unused pixmaps
818 if(debug) PRINT_TRACE
820 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
821 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
823 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
824 delete gui->resource_pixmaps.values[i];
825 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
827 if(debug) PRINT_TRACE
829 if(hourglass_enabled)
832 hourglass_enabled = 0;
834 if(debug) PRINT_TRACE
836 // can't stop thread here, because this is called for every pane
837 // if(mode != IGNORE_THREAD && !indexes_only)
838 // gui->resource_thread->start_draw();
839 if(debug) PRINT_TRACE
844 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
850 ResourcePixmap *result = 0;
852 for(int i = 0; i < gui->resource_pixmaps.total; i++)
854 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
855 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
856 gui->resource_pixmaps.values[i]->pane_number == pane->number)
858 result = gui->resource_pixmaps.values[i];
866 result = new ResourcePixmap(mwindow,
873 gui->resource_pixmaps.append(result);
876 // result->resize(pixmap_w, pixmap_h);
880 void TrackCanvas::get_pixmap_size(Edit *edit,
888 // Align x on frame boundaries
891 // switch(edit->edits->track->data_type)
903 if(pixmap_x + pixmap_w > get_w())
905 pixmap_w = get_w() - pixmap_x;
912 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
913 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
914 // int64_t pixel_increment = MAX(picon_w, frame_w);
915 // int64_t pixmap_x1 = edit_x;
916 // int64_t pixmap_x2 = edit_x + edit_w;
920 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
925 // if(pixmap_x2 > get_w())
927 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
931 // pixmap_x = pixmap_x1;
932 // pixmap_w = pixmap_x2 - pixmap_x1;
937 pixmap_h = mwindow->edl->local_session->zoom_track;
938 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
939 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
942 void TrackCanvas::edit_dimensions(Edit *edit,
948 // w = Units::round(edit->track->from_units(edit->length) *
949 // mwindow->edl->session->sample_rate /
950 // mwindow->edl->local_session->zoom_sample);
954 x = Units::round(edit->track->from_units(edit->startproject) *
955 mwindow->edl->session->sample_rate /
956 mwindow->edl->local_session->zoom_sample -
957 mwindow->edl->local_session->view_start[pane->number]);
959 // Method for calculating w so when edits are together we never get off by one error due to rounding
960 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
961 mwindow->edl->session->sample_rate /
962 mwindow->edl->local_session->zoom_sample -
963 mwindow->edl->local_session->view_start[pane->number]);
966 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
968 if(mwindow->edl->session->show_titles)
969 h += mwindow->theme->get_image("title_bg_data")->get_h();
972 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
976 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
977 h = track->vertical_span(mwindow->theme);
981 void TrackCanvas::draw_paste_destination()
983 //int cursor_x = get_relative_cursor_x();
984 //int cursor_y = get_relative_cursor_y();
985 int current_atrack = 0;
986 int current_vtrack = 0;
987 int current_aedit = 0;
988 int current_vedit = 0;
994 //if(pane->number == BOTTOM_RIGHT_PANE)
995 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
997 if((mwindow->session->current_operation == DRAG_ASSET &&
998 (mwindow->session->drag_assets->total ||
999 mwindow->session->drag_clips->total)) ||
1000 (mwindow->session->current_operation == DRAG_EDIT &&
1001 mwindow->session->drag_edits->total)) {
1002 Indexable *indexable = 0;
1006 if(mwindow->session->current_operation == DRAG_ASSET &&
1007 mwindow->session->drag_assets->size())
1008 indexable = mwindow->session->drag_assets->get(0);
1010 if(mwindow->session->current_operation == DRAG_ASSET &&
1011 mwindow->session->drag_clips->size())
1012 clip = mwindow->session->drag_clips->get(0);
1014 int has_audio = 0, has_video = 0;
1015 double paste_audio_length = 0, paste_video_length = 0;
1016 double paste_audio_position = -1, paste_video_position = -1;
1019 has_audio = indexable->have_audio();
1020 paste_audio_length = !has_audio ? 0 :
1021 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1022 has_video = indexable->have_video();
1023 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1024 // Images have length -1
1025 if( asset && asset->video_data && asset->video_length < 0 ) {
1026 paste_video_length = mwindow->edl->session->si_useduration ?
1027 mwindow->edl->session->si_duration / asset->frame_rate :
1028 1.0 / asset->frame_rate ; // 1 frame
1031 paste_video_length = !has_video ? 0 :
1032 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1036 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1037 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1038 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1039 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1042 // 'Align cursor on frame' lengths calculations
1043 if( mwindow->edl->session->cursor_on_frames ) {
1044 double fps = mwindow->edl->session->frame_rate;
1045 double aud = floor(paste_audio_length * fps) / fps;
1046 double vid = floor(paste_video_length * fps) / fps;
1047 double length = has_video && has_audio ?
1048 aud < vid ? aud : vid :
1050 has_audio ? aud : 0;
1051 paste_video_length = paste_audio_length = length;
1054 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1056 switch( mwindow->session->track_highlighted->data_type ) {
1057 case TRACK_VIDEO: length = paste_video_length; break;
1058 case TRACK_AUDIO: length = paste_audio_length; break;
1060 int64_t asset_length = mwindow->session->track_highlighted->
1061 to_units(length, 1);
1062 paste_audio_position = mwindow->session->track_highlighted->
1063 from_units(drop_edit_position(&insertion, NULL, asset_length));
1066 int64_t asset_length = mwindow->session->track_highlighted->
1067 to_units(paste_video_length, 1);
1068 paste_video_position = mwindow->session->track_highlighted->
1069 from_units(drop_edit_position(&insertion, NULL, asset_length));
1072 // Get destination track
1073 for(Track *dest = mwindow->session->track_highlighted;
1075 dest = dest->next) {
1077 // Get source width in pixels
1079 // Use start of highlighted edit
1080 if(mwindow->session->edit_highlighted) {
1081 position = mwindow->session->track_highlighted->from_units(
1082 mwindow->session->edit_highlighted->startproject);
1085 // Use end of highlighted track, disregarding effects
1086 position = mwindow->session->track_highlighted->from_units(
1087 mwindow->session->track_highlighted->edits->length());
1090 // Get the x coordinate
1091 x = Units::to_int64(position *
1092 mwindow->edl->session->sample_rate /
1093 mwindow->edl->local_session->zoom_sample) -
1094 mwindow->edl->local_session->view_start[pane->number];
1096 double paste_position = -1.;
1097 if(dest->data_type == TRACK_AUDIO) {
1098 if(indexable && current_atrack < indexable->get_audio_channels()) {
1099 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1100 w = Units::to_int64((double)indexable->get_audio_samples() /
1101 indexable->get_sample_rate() *
1102 mwindow->edl->session->sample_rate /
1103 mwindow->edl->local_session->zoom_sample);
1104 paste_position = paste_audio_position;
1106 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1107 w = Units::to_int64((double)clip->tracks->total_length() *
1108 mwindow->edl->session->sample_rate /
1109 mwindow->edl->local_session->zoom_sample);
1110 paste_position = paste_audio_position;
1111 //printf("draw_paste_destination %d\n", x);
1113 else if(mwindow->session->current_operation == DRAG_EDIT &&
1114 current_aedit < mwindow->session->drag_edits->total) {
1116 while(current_aedit < mwindow->session->drag_edits->total &&
1117 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1120 if(current_aedit < mwindow->session->drag_edits->total) {
1121 edit = mwindow->session->drag_edits->values[current_aedit];
1122 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1123 paste_position = mwindow->session->track_highlighted->
1124 from_units(drop_edit_position(&insertion,
1125 mwindow->session->drag_edit,
1126 mwindow->session->drag_edit->length));
1129 if( paste_position >= 0 ) {
1130 position = paste_position;
1137 else if(dest->data_type == TRACK_VIDEO) {
1138 //printf("draw_paste_destination 1\n");
1139 if(indexable && current_vtrack < indexable->get_video_layers())
1141 w = Units::to_int64((double)indexable->get_video_frames() /
1142 indexable->get_frame_rate() *
1143 mwindow->edl->session->sample_rate /
1144 mwindow->edl->local_session->zoom_sample);
1145 paste_position = paste_video_position;
1147 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1148 w = Units::to_int64(clip->tracks->total_length() *
1149 mwindow->edl->session->sample_rate /
1150 mwindow->edl->local_session->zoom_sample);
1151 paste_position = paste_video_position;
1153 else if(mwindow->session->current_operation == DRAG_EDIT &&
1154 current_vedit < mwindow->session->drag_edits->total) {
1156 while(current_vedit < mwindow->session->drag_edits->total &&
1157 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1160 if(current_vedit < mwindow->session->drag_edits->total) {
1161 edit = mwindow->session->drag_edits->values[current_vedit];
1162 w = Units::to_int64(edit->track->from_units(edit->length) *
1163 mwindow->edl->session->sample_rate /
1164 mwindow->edl->local_session->zoom_sample);
1165 paste_position = mwindow->session->track_highlighted->
1166 from_units(drop_edit_position(&insertion,
1167 mwindow->session->drag_edit,
1168 mwindow->session->drag_edit->length));
1171 if( paste_position >= 0 ) {
1172 position = paste_position;
1181 // Get the x coordinate
1182 x = Units::to_int64(position *
1183 mwindow->edl->session->sample_rate /
1184 mwindow->edl->local_session->zoom_sample) -
1185 mwindow->edl->local_session->view_start[pane->number];
1186 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1187 int h = dest->vertical_span(mwindow->theme);
1189 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1191 draw_highlight_insertion(x, y, w, h);
1193 draw_highlight_rectangle(x, y, w, h);
1194 if(x < -BC_INFINITY) {
1195 w -= -BC_INFINITY - x;
1196 x += -BC_INFINITY - x;
1199 // if(pane->number == TOP_RIGHT_PANE)
1200 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1201 // __LINE__, x, y, w, h);
1202 draw_highlight_rectangle(x, y, w, h);
1209 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1211 x = Units::round(plugin->track->from_units(plugin->startproject) *
1212 mwindow->edl->session->sample_rate /
1213 mwindow->edl->local_session->zoom_sample -
1214 mwindow->edl->local_session->view_start[pane->number]);
1215 w = Units::round(plugin->track->from_units(plugin->length) *
1216 mwindow->edl->session->sample_rate /
1217 mwindow->edl->local_session->zoom_sample);
1218 y = plugin->track->y_pixel -
1219 mwindow->edl->local_session->track_start[pane->number] +
1220 mwindow->edl->local_session->zoom_track +
1221 plugin->plugin_set->get_number() *
1222 mwindow->theme->get_image("plugin_bg_data")->get_h();
1223 if(mwindow->edl->session->show_titles)
1224 y += mwindow->theme->get_image("title_bg_data")->get_h();
1225 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1228 int TrackCanvas::resource_h()
1230 return mwindow->edl->local_session->zoom_track;
1233 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1236 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1237 // just draw arrows, so user has indication that something is there
1238 // FIXME: get better colors
1242 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1247 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1251 // Fix bug in heroines & cvs version as of 22.8.2005:
1252 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1253 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1266 w = MIN(w, get_w() + 20);
1267 h = MIN(h, get_h() + 20);
1272 //draw_rectangle(x, y, w, h);
1273 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1274 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1276 draw_rectangle(x, y, w, h);
1278 //if(pane->number == TOP_RIGHT_PANE)
1279 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1282 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1285 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1286 // just draw arrows, so user has indication that something is there
1287 // FIXME: get better colors
1296 /* these don't look so good
1298 draw_line(x, y, x, y+h);
1299 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1300 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1301 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1302 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1304 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1305 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1307 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1308 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1309 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1310 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1312 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1313 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1315 // draw the box centred around x
1317 // Fix bug in heroines & cvs version as of 22.8.2005:
1318 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1319 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1330 w = MIN(w, get_w() + 20);
1331 h = MIN(h, get_h() + 20);
1334 draw_rectangle(x, y, w, h);
1335 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1337 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1340 void TrackCanvas::draw_playback_cursor()
1342 // Called before playback_cursor exists
1343 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1345 // mwindow->playback_cursor->visible = 0;
1346 // mwindow->playback_cursor->draw();
1350 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1352 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1353 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1355 edit_dimensions(edit, x, y, w, h);
1357 if(mwindow->edl->session->show_titles)
1359 y += mwindow->theme->get_image("title_bg_data")->get_h();
1366 if(side == EDIT_OUT)
1375 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1377 //printf("TrackCanvas::get_transition_coords 1\n");
1378 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1379 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1380 int transition_w = 30;
1381 int transition_h = 30;
1382 //printf("TrackCanvas::get_transition_coords 1\n");
1384 if(mwindow->edl->session->show_titles)
1385 y += mwindow->theme->get_image("title_bg_data")->get_h();
1386 //printf("TrackCanvas::get_transition_coords 2\n");
1388 y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
1389 x -= transition_w / 2;
1395 void TrackCanvas::draw_highlighting()
1400 switch(mwindow->session->current_operation)
1402 case DRAG_ATRANSITION:
1403 case DRAG_VTRANSITION:
1404 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1405 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1406 if(mwindow->session->edit_highlighted) {
1407 //printf("TrackCanvas::draw_highlighting 2\n");
1408 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1409 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1410 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1411 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1412 //printf("TrackCanvas::draw_highlighting 2\n");
1413 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1414 //printf("TrackCanvas::draw_highlighting 2\n");
1416 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1417 MWindowGUI::visible(y, y + h, 0, get_h())) {
1419 get_transition_coords(x, y, w, h);
1421 //printf("TrackCanvas::draw_highlighting 3\n");
1426 // Dragging a new effect from the Resource window
1429 if(mwindow->session->track_highlighted &&
1430 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1431 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1432 (mwindow->session->current_operation == DRAG_VEFFECT &&
1433 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1434 // Put it before another plugin
1435 if(mwindow->session->plugin_highlighted) {
1436 plugin_dimensions(mwindow->session->plugin_highlighted,
1438 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1440 // Put it after a plugin set
1441 else if( mwindow->session->pluginset_highlighted &&
1442 mwindow->session->pluginset_highlighted->last ) {
1443 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1445 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1446 int64_t track_x, track_y, track_w, track_h;
1447 track_dimensions(mwindow->session->track_highlighted,
1448 track_x, track_y, track_w, track_h);
1452 mwindow->session->track_highlighted->get_length() *
1453 mwindow->edl->session->sample_rate /
1454 mwindow->edl->local_session->zoom_sample -
1455 mwindow->edl->local_session->view_start[pane->number]) -
1457 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1458 if(w <= 0) w = track_w;
1461 track_dimensions(mwindow->session->track_highlighted,
1464 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1465 // Put it in a new plugin set determined by the selected range
1466 if(mwindow->edl->local_session->get_selectionend() >
1467 mwindow->edl->local_session->get_selectionstart()) {
1468 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1469 mwindow->edl->session->sample_rate /
1470 mwindow->edl->local_session->zoom_sample -
1471 mwindow->edl->local_session->view_start[pane->number]);
1472 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1473 mwindow->edl->local_session->get_selectionstart()) *
1474 mwindow->edl->session->sample_rate /
1475 mwindow->edl->local_session->zoom_sample);
1477 // Put it in a new plugin set determined by an edit boundary
1478 else if(mwindow->session->edit_highlighted) {
1479 int64_t temp_y, temp_h;
1480 edit_dimensions(mwindow->session->edit_highlighted,
1481 x, temp_y, w, temp_h);
1483 // Put it at the beginning of the track in a new plugin set
1486 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1487 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1488 //printf("TrackCanvas::draw_highlighting 1\n");
1495 if(mwindow->session->track_highlighted) {
1496 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1498 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1500 draw_paste_destination();
1506 if(mwindow->session->track_highlighted) {
1507 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1509 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1510 draw_paste_destination();
1515 // Dragging an effect from the timeline
1516 case DRAG_AEFFECT_COPY:
1517 case DRAG_VEFFECT_COPY:
1518 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1519 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1520 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1521 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1522 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1524 int64_t plugin_position = -1;
1525 Plugin *drag_plugin = mwindow->session->drag_plugin;
1526 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1527 Track *hi_track = mwindow->session->track_highlighted;
1528 Edit *hi_edit = mwindow->session->edit_highlighted;
1529 // Put it into a silence zone
1530 if( hi_plugin_set && hi_plugin_set->last &&
1531 hi_plugin_set->track == drag_plugin->track ) {
1532 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1533 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1534 hi_track = drag_plugin->track;
1536 else if( hi_track ) {
1537 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1538 track_dimensions(hi_track, x, y, w, h);
1539 plugin_position = hi_edit ? hi_edit->startproject : 0;
1542 if( plugin_position < 0 ) break;
1544 // Calculate length of plugin based on data type of track and units
1545 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1546 mwindow->edl->local_session->zoom_sample;
1547 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1548 mwindow->edl->local_session->view_start[pane->number];
1549 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1551 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1552 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1558 case DRAG_PLUGINKEY:
1559 if(mwindow->session->plugin_highlighted &&
1560 mwindow->session->current_operation == DRAG_PLUGINKEY)
1562 // Just highlight the plugin
1563 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1565 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1566 MWindowGUI::visible(y, y + h, 0, get_h()))
1578 draw_highlight_rectangle(x, y, w, h);
1582 void TrackCanvas::draw_plugins()
1584 char string[BCTEXTLEN];
1586 int current_show = 0;
1589 // if(!mwindow->edl->session->show_assets) goto done;
1591 for(int i = 0; i < plugin_on_toggles.total; i++)
1592 plugin_on_toggles.values[i]->in_use = 0;
1593 for(int i = 0; i < plugin_show_toggles.total; i++)
1594 plugin_show_toggles.values[i]->in_use = 0;
1597 for(Track *track = mwindow->edl->tracks->first;
1599 track = track->next)
1601 if(track->expand_view)
1603 for(int i = 0; i < track->plugin_set.total; i++)
1605 PluginSet *pluginset = track->plugin_set.values[i];
1607 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1609 int64_t total_x, y, total_w, h;
1610 plugin_dimensions(plugin, total_x, y, total_w, h);
1612 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1613 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1614 plugin->plugin_type != PLUGIN_NONE)
1616 int x = total_x, w = total_w, left_margin = 5;
1617 int right_margin = 5;
1623 if(w + x > get_w()) w -= (w + x) - get_w();
1630 mwindow->theme->get_image("plugin_bg_data"),
1632 set_color(mwindow->theme->title_color);
1633 set_font(mwindow->theme->title_font);
1634 plugin->calculate_title(string, 0);
1636 // Truncate string to int64_test visible in background
1637 int len = strlen(string), j;
1638 for(j = len; j >= 0; j--)
1640 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1648 // Justify the text on the left boundary of the edit if it is visible.
1649 // Otherwise justify it on the left side of the screen.
1650 int64_t text_x = total_x + left_margin;
1651 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1652 text_x = MAX(left_margin, text_x);
1654 y + get_text_ascent(mwindow->theme->title_font) + 2,
1658 int64_t min_x = total_x + text_w;
1661 // Update plugin toggles
1662 int toggle_x = total_x + total_w;
1664 toggle_x = MIN(get_w() - right_margin, toggle_x);
1667 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1668 if(toggle_x > min_x)
1670 if(current_on >= plugin_on_toggles.total)
1672 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1673 add_subwindow(plugin_on);
1674 plugin_on_toggles.append(plugin_on);
1678 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1683 // Toggles for standalone plugins only
1684 if(plugin->plugin_type == PLUGIN_STANDALONE)
1687 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1688 if(toggle_x > min_x)
1690 if(current_show >= plugin_show_toggles.total)
1692 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1693 add_subwindow(plugin_show);
1694 plugin_show_toggles.append(plugin_show);
1698 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1712 // Remove unused toggles
1714 while(current_show < plugin_show_toggles.total)
1716 plugin_show_toggles.remove_object_number(current_show);
1719 while(current_on < plugin_on_toggles.total)
1721 plugin_on_toggles.remove_object_number(current_on);
1726 void TrackCanvas::refresh_plugintoggles()
1728 for(int i = 0; i < plugin_on_toggles.total; i++)
1730 PluginOn *on = plugin_on_toggles.values[i];
1731 on->reposition_window(on->get_x(), on->get_y());
1733 for(int i = 0; i < plugin_show_toggles.total; i++)
1735 PluginShow *show = plugin_show_toggles.values[i];
1736 show->reposition_window(show->get_x(), show->get_y());
1740 void TrackCanvas::draw_inout_points()
1745 void TrackCanvas::draw_drag_handle()
1747 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1748 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1750 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1751 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1752 mwindow->edl->session->sample_rate /
1753 mwindow->edl->local_session->zoom_sample -
1754 mwindow->edl->local_session->view_start[pane->number]);
1755 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1758 //printf("TrackCanvas::draw_drag_handle 3\n");
1759 draw_line(pixel1, 0, pixel1, get_h());
1761 //printf("TrackCanvas::draw_drag_handle 4\n");
1766 void TrackCanvas::draw_transitions()
1770 // if(!mwindow->edl->session->show_assets) return;
1772 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1773 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1774 if(!edit->transition) continue;
1775 edit_dimensions(edit, x, y, w, h);
1776 int strip_x = x, strip_y = y;
1777 if(mwindow->edl->session->show_titles)
1778 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1779 get_transition_coords(x, y, w, h);
1780 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1781 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1782 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1783 MWindowGUI::visible(y, y + h, 0, get_h()) )
1785 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1787 if( !server ) continue;
1788 VFrame *picon = server->get_picon();
1789 if( !picon ) continue;
1790 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1792 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1793 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1795 int x = strip_x, w = strip_w;
1801 if(w + x > get_w()) w -= (w + x) - get_w();
1803 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1804 mwindow->theme->get_image("plugin_bg_data"), 0);
1810 void TrackCanvas::draw_loop_points()
1812 //printf("TrackCanvas::draw_loop_points 1\n");
1813 if(mwindow->edl->local_session->loop_playback)
1815 //printf("TrackCanvas::draw_loop_points 2\n");
1816 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1817 mwindow->edl->session->sample_rate /
1818 mwindow->edl->local_session->zoom_sample -
1819 mwindow->edl->local_session->view_start[pane->number]);
1820 //printf("TrackCanvas::draw_loop_points 3\n");
1822 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1825 draw_line(x, 0, x, get_h());
1827 //printf("TrackCanvas::draw_loop_points 4\n");
1829 x = Units::round(mwindow->edl->local_session->loop_end *
1830 mwindow->edl->session->sample_rate /
1831 mwindow->edl->local_session->zoom_sample -
1832 mwindow->edl->local_session->view_start[pane->number]);
1833 //printf("TrackCanvas::draw_loop_points 5\n");
1835 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1838 draw_line(x, 0, x, get_h());
1840 //printf("TrackCanvas::draw_loop_points 6\n");
1842 //printf("TrackCanvas::draw_loop_points 7\n");
1845 void TrackCanvas::draw_brender_start()
1847 if(mwindow->preferences->use_brender)
1849 int64_t x = Units::round(mwindow->edl->session->brender_start *
1850 mwindow->edl->session->sample_rate /
1851 mwindow->edl->local_session->zoom_sample -
1852 mwindow->edl->local_session->view_start[pane->number]);
1854 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1857 draw_line(x, 0, x, get_h());
1862 static int auto_colors[AUTOMATION_TOTAL] =
1878 // The operations which correspond to each automation type
1879 static int auto_operations[AUTOMATION_TOTAL] =
1895 // The buttonpress operations, so nothing changes unless the mouse moves
1896 // a certain amount. This allows the keyframe to be used to position the
1897 // insertion point without moving itself.
1898 static int pre_auto_operations[AUTOMATION_TOTAL] =
1915 int TrackCanvas::do_keyframes(int cursor_x,
1923 // Note: button 3 (right mouse button) is not eaten to allow
1924 // track context menu to appear
1926 EDLSession *session = mwindow->edl->session;
1930 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1932 0, 0, 0, 0, 0, 0, 0, 0,
1934 modekeyframe_pixmap,
1935 maskkeyframe_pixmap,
1940 for(Track *track = mwindow->edl->tracks->first;
1942 track = track->next) {
1943 Auto *auto_keyframe = 0;
1944 Automation *automation = track->automation;
1947 // Handle keyframes in reverse drawing order if a button press
1949 int end = AUTOMATION_TOTAL;
1953 start = AUTOMATION_TOTAL - 1;
1957 for(int i = start; i != end && !result; i += step)
1959 // Event not trapped and automation visible
1960 Autos *autos = automation->autos[i];
1961 if(!result && session->auto_conf->autos[i] && autos) {
1963 case AUTOMATION_MODE:
1964 case AUTOMATION_PAN:
1965 case AUTOMATION_MASK:
1966 result = do_autos(track, automation->autos[i],
1967 cursor_x, cursor_y, draw,
1968 buttonpress, auto_pixmaps[i],
1969 auto_keyframe, rerender);
1973 switch(autos->get_type()) {
1974 case Autos::AUTOMATION_TYPE_FLOAT: {
1975 Automation automation(0, track);
1976 int grouptype = automation.autogrouptype(i, track);
1977 if(draw) // Do dropshadow
1978 result = do_float_autos(track, autos,
1979 cursor_x, cursor_y, draw,
1980 buttonpress, 1, 1, MDGREY,
1981 auto_keyframe, grouptype);
1983 result = do_float_autos(track, autos,
1984 cursor_x, cursor_y, draw,
1985 buttonpress, 0, 0, auto_colors[i],
1986 auto_keyframe, grouptype);
1989 case Autos::AUTOMATION_TYPE_INT: {
1990 if(draw) // Do dropshadow
1991 result = do_int_autos(track, autos,
1992 cursor_x, cursor_y, draw,
1993 buttonpress, 1, 1, MDGREY,
1995 result = do_int_autos(track, autos,
1996 cursor_x, cursor_y, draw,
1997 buttonpress, 0, 0, auto_colors[i],
2006 if(mwindow->session->current_operation == auto_operations[i])
2009 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2011 // mwindow->session->current_operation,
2012 // auto_operations[i]);
2015 if (buttonpress != 3)
2017 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2018 synchronize_autos(0,
2020 (FloatAuto*)mwindow->session->drag_auto,
2022 mwindow->session->current_operation = pre_auto_operations[i];
2023 update_drag_caption();
2026 else if( auto_keyframe )
2028 gui->keyframe_menu->update(automation,
2031 gui->keyframe_menu->activate_menu();
2032 rerender = 1; // the position changes
2034 if(buttonpress == 1 && ctrl_down() &&
2035 AUTOMATION_TYPE_FLOAT == autos->get_type())
2036 rerender = 1; // special case: curve mode changed
2043 session->auto_conf->plugins /* &&
2044 mwindow->edl->session->show_assets */) {
2047 result = do_plugin_autos(track, cursor_x, cursor_y,
2048 draw, buttonpress, plugin, keyframe);
2049 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2052 if(result && (buttonpress == 1)) {
2053 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2054 update_drag_caption();
2057 else if (result && (buttonpress == 3)) {
2058 gui->keyframe_menu->update(plugin, keyframe);
2059 gui->keyframe_menu->activate_menu();
2060 rerender = 1; // the position changes
2065 // Final pass to trap event
2066 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2067 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2068 mwindow->session->current_operation == auto_operations[i]) {
2074 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2075 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2081 new_cursor = UPRIGHT_ARROW_CURSOR;
2088 void TrackCanvas::draw_auto(Auto *current,
2096 x1 = x - HANDLE_W / 2;
2097 x2 = x + HANDLE_W / 2;
2098 y1 = center_pixel + y - HANDLE_W / 2;
2099 y2 = center_pixel + y + HANDLE_W / 2;
2101 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2102 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2104 draw_box(x1, y1, x2 - x1, y2 - y1);
2108 // This draws lines for bezier in & out controls
2109 void TrackCanvas::draw_cropped_line(int x1,
2118 // Don't care about x since it is clipped by the window.
2119 // Put y coords in ascending order
2121 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2122 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2127 double slope = (double)(x2 - x1) / (y2 - y1);
2128 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2130 x1 = (int)(x1 + (min_y - y1) * slope);
2133 else if(y1 >= max_y) {
2134 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2139 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2142 else if(y2 < min_y) {
2143 x2 = (int)(x2 + (min_y - y2) * slope);
2148 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2149 if( y1 >= min_y && y1 < max_y &&
2150 y2 >= min_y && y2 < max_y )
2151 draw_line(x1, y1, x2, y2);
2155 void TrackCanvas::draw_floatauto(FloatAuto *current,
2166 int x1 = x - HANDLE_W / 2; // Center
2167 int x2 = x + HANDLE_W / 2;
2168 int y1 = center_pixel + y - HANDLE_H / 2;
2169 int y2 = center_pixel + y + HANDLE_H / 2;
2170 int ymin = center_pixel - zoom_track / 2;
2171 int ymax = center_pixel + zoom_track / 2;
2172 CLAMP(y1, ymin, ymax);
2173 CLAMP(y2, ymin, ymax);
2178 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2180 draw_box(x1, y1, x2 - x1, y2 - y1);
2183 // show bezier control points (only) if this
2184 // floatauto doesn't adjust it's tangents automatically
2185 if(current->curve_mode != FloatAuto::FREE &&
2186 current->curve_mode != FloatAuto::TFREE)
2190 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2192 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2195 inline int quantize(float f) { return (int)floor(f + 0.5); }
2197 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2198 int x, int y, int cp_x, int cp_y, int center_pixel,
2199 int zoom_track, int color)
2200 // draw the tangent and a handle for given bézier ctrl point
2202 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2204 float slope = (float)(cp_y - y)/(cp_x - x);
2205 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2207 cp_x = x + quantize((cp_y - y) / slope);
2210 cp_y += center_pixel;
2212 // drawing the tangent as a dashed line...
2213 int const dash = HANDLE_W;
2214 int const gap = HANDLE_W / 2;
2215 float sx = 3 * (cp_x - x) / 4.;
2218 // q is the x displacement for a unit line of slope
2219 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2221 float dist = 1/q * sx;
2227 float sy = slope * sx, ey = slope * ex;
2228 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2235 int r = HANDLE_W / 2;
2236 int cp_x1 = cp_x - r;
2237 int cp_y1 = cp_y - r;
2239 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2241 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2246 int TrackCanvas::test_auto(Auto *current,
2247 int x, int y, int center_pixel, int zoom_track,
2248 int cursor_x, int cursor_y, int buttonpress)
2253 x1 = x - HANDLE_W / 2;
2254 x2 = x + HANDLE_W / 2;
2255 y1 = center_pixel + y - HANDLE_H / 2;
2256 y2 = center_pixel + y + HANDLE_H / 2;
2257 int ymin = center_pixel - zoom_track / 2;
2258 int ymax = center_pixel + zoom_track / 2;
2259 CLAMP(y1, ymin, ymax);
2260 CLAMP(y2, ymin, ymax);
2262 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2264 if(buttonpress && buttonpress != 3)
2266 mwindow->session->drag_auto = current;
2267 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2268 // Toggle Autos don't respond to vertical zoom, they always show up
2269 // with "on" == 100% == line on top
2270 mwindow->session->drag_start_position = current->position;
2271 mwindow->session->drag_origin_x = cursor_x;
2272 mwindow->session->drag_origin_y = cursor_y;
2277 if(buttonpress && buttonpress != 3 && result)
2279 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2280 mwindow->undo->update_undo_before();
2286 // some Helpers for test_floatauto(..)
2287 // and for dragging the tangents/ctrl points
2288 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2289 float cursor_x, float cursor_y)
2291 // Control point switched off?
2292 if( x0 == ctrl_x ) return 0.0;
2293 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2294 double x = cursor_x-x0, y = cursor_y-y0;
2295 // wrong side of ctrl handle
2296 if( x*x1 < 0 ) return 0.0;
2297 // outside handle radius
2298 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2299 double xx1 = x1*x1, yy1 = y1*y1;
2300 double xx = x*x, yy = y*y;
2301 // distance squared from cursor to cursor projected to line from ctrl to handle
2302 // along a line perpendicular to line from ctrl to handle (closest approach)
2303 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2304 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2305 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2310 float levered_position(float position, float ref_pos)
2312 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2314 return ref_pos / position;
2318 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2319 // transforms automation value into current display coords,
2320 // dependant on current automation display range for the given kind of automation
2322 if(!mwindow || !mwindow->edl) return 0;
2323 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2324 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2325 float automation_range = automation_max - automation_min;
2326 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2328 return (auto_value - automation_min) / automation_range;
2333 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2334 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2335 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2339 int x1 = x - HANDLE_W / 2;
2340 int x2 = x + HANDLE_W / 2;
2341 int y1 = center_pixel + y - HANDLE_W / 2;
2342 int y2 = center_pixel + y + HANDLE_W / 2;
2343 int ymin = center_pixel - zoom_track / 2;
2344 int ymax = center_pixel + zoom_track / 2;
2345 CLAMP(y1, ymin, ymax);
2346 CLAMP(y2, ymin, ymax);
2348 int in_x1 = in_x - HANDLE_W / 2;
2349 int in_x2 = in_x + HANDLE_W / 2;
2350 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2351 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2352 CLAMP(in_y1, ymin, ymax);
2353 CLAMP(in_y2, ymin, ymax);
2355 int out_x1 = out_x - HANDLE_W / 2;
2356 int out_x2 = out_x + HANDLE_W / 2;
2357 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2358 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2359 CLAMP(out_y1, ymin, ymax);
2360 CLAMP(out_y2, ymin, ymax);
2363 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2364 // buttonpress could be the start of a drag operation
2365 #define INIT_DRAG(POS,VAL) \
2366 mwindow->session->drag_auto = current; \
2367 mwindow->session->drag_origin_x = cursor_x; \
2368 mwindow->session->drag_origin_y = cursor_y; \
2369 mwindow->session->drag_start_position = (POS); \
2370 mwindow->session->drag_start_percentage = (VAL);
2372 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2375 // without modifier we are manipulating the automation node
2376 // with ALT it's about dragging only the value of the node
2377 // with SHIFT the value snaps to the value of neighbouring nodes
2378 // CTRL indicates we are rather manipulating the tangent(s) of the node
2382 if( WITHIN(x1,x2,y1,y2))
2383 { // cursor hits node
2386 if(buttonpress && (buttonpress != 3))
2388 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2389 mwindow->session->drag_handle = 0;
2394 if( WITHIN(x1,x2,y1,y2))
2397 if(buttonpress && (buttonpress != 3))
2399 // could be ctrl-click or ctrl-drag
2400 // click would cycle through tangent modes
2401 ((FloatAuto*)current)->toggle_curve_mode();
2403 // drag will start dragging the tangent, if applicable
2404 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2405 mwindow->session->drag_handle = 0;
2409 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2412 if( in_x != x && current->position > 0 &&
2413 (FloatAuto::FREE == current->curve_mode ||
2414 FloatAuto::TFREE == current->curve_mode))
2415 // act on in control handle only if
2416 // tangent is significant and is editable (not automatically choosen)
2418 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2419 // either cursor in ctrl-point handle or cursor on tangent line
2420 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2422 if(buttonpress && (buttonpress != 3)) {
2423 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2425 mwindow->session->drag_handle = 1;
2426 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2427 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2428 value_to_percentage(new_invalue, autogrouptype))
2435 (FloatAuto::FREE == current->curve_mode ||
2436 FloatAuto::TFREE == current->curve_mode))
2437 // act on out control only if tangent is significant and is editable
2439 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2440 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2442 if(buttonpress && (buttonpress != 3)) {
2443 if(lever == 0.0) lever=1.0;
2445 mwindow->session->drag_handle = 2;
2446 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2447 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2448 value_to_percentage(new_outvalue, autogrouptype))
2452 } // end ctrl_down()
2458 // 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",
2459 // mwindow->session->drag_handle,
2464 if(buttonpress && (buttonpress != 3) && result)
2466 mwindow->undo->update_undo_before();
2473 // Get the float value & y for position x on the canvas
2474 #define X_TO_FLOATLINE(x) \
2475 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2476 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2477 /* Call by reference fails for some reason here */ \
2478 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2479 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2480 double position = unit_start + x * zoom_units; \
2482 if(position2 > position1) \
2485 (value2 - value1) * \
2486 (position - position1) / \
2487 (position2 - position1); \
2493 AUTOMATIONCLAMPS(value, autogrouptype); \
2494 int y = center_pixel + \
2495 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2498 void TrackCanvas::draw_floatline(int center_pixel,
2499 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2500 double unit_start, double zoom_units, double yscale,
2501 int x1, int y1, int x2, int y2,
2502 int color, int autogrouptype)
2504 // Solve bezier equation for either every pixel or a certain large number of
2507 // Not using slope intercept
2512 // Call by reference fails for some reason here
2513 FloatAuto *previous1 = previous, *next1 = next;
2514 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2515 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2516 float automation_range = automation_max - automation_min;
2518 for(int x = x1; x < x2; x++)
2520 // Interpolate value between frames
2524 y >= center_pixel - yscale / 2 &&
2525 y < center_pixel + yscale / 2 - 1)
2527 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2529 // (int)(center_pixel - yscale / 2),
2530 // (int)(center_pixel + yscale / 2 - 1));
2532 draw_line(x - 1, prev_y , x, y );
2542 int TrackCanvas::test_floatline(int center_pixel,
2557 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2558 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2559 float automation_range = automation_max - automation_min;
2560 FloatAuto *previous1 = 0, *next1 = 0;
2561 X_TO_FLOATLINE(cursor_x);
2563 if(cursor_x >= x1 &&
2565 cursor_y >= y - HANDLE_W / 2 &&
2566 cursor_y < y + HANDLE_W / 2 &&
2572 if(buttonpress == 3)
2580 mwindow->undo->update_undo_before();
2581 current = mwindow->session->drag_auto = autos->insert_auto(position1);
2582 ((FloatAuto*)current)->set_value(value);
2583 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2584 mwindow->session->drag_start_position = current->position;
2585 mwindow->session->drag_origin_x = cursor_x;
2586 mwindow->session->drag_origin_y = cursor_y;
2587 mwindow->session->drag_handle = 0;
2596 void TrackCanvas::synchronize_autos(float change,
2597 Track *skip, FloatAuto *fauto, int fill_gangs)
2599 // Handles the special case of modifying a fadeauto
2600 // when there are ganged faders on several tracks
2601 // (skip and fauto may be NULL if fill_gangs==-1)
2603 if( fill_gangs > 0 && skip->gang ) {
2604 double position = skip->from_units(fauto->position);
2605 int autoidx = fauto->autos->autoidx;
2607 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2608 if( (current->data_type == skip->data_type || get_double_click()) &&
2609 current->gang && current->record && current != skip ) {
2610 int64_t current_position = current->to_units(position, 1);
2611 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2612 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2613 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2614 FloatAuto *previous = 0, *next = 0;
2615 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2617 // create keyframe on neighbouring track at the point in time given by fauto
2618 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2619 float new_value = init_value + change;
2620 CLAMP(new_value, auto_min, auto_max);
2621 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2622 keyframe->set_value(new_value);
2625 // keyframe exists, just change it
2626 float new_value = keyframe->get_value() + change;
2627 CLAMP(new_value, auto_min, auto_max);
2628 keyframe->adjust_to_new_coordinates(current_position, new_value);
2629 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2632 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2636 else if( !fill_gangs ) {
2637 double position = skip->from_units(fauto->position);
2639 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2640 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2641 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2642 float new_value = keyframe->get_value() + change;
2644 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2645 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2646 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2652 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2653 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2654 keyframe->autos->remove_nonsequential(
2657 mwindow->session->drag_auto_gang->remove_all();
2662 void TrackCanvas::draw_toggleline(int center_pixel,
2668 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2672 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2676 int TrackCanvas::test_toggleline(Autos *autos,
2687 if(cursor_x >= x1 && cursor_x < x2)
2689 int miny = center_pixel + y1 - HANDLE_W / 2;
2690 int maxy = center_pixel + y1 + HANDLE_W / 2;
2691 if(cursor_y >= miny && cursor_y < maxy)
2696 if(buttonpress == 3)
2704 double position = (double)(cursor_x +
2705 mwindow->edl->local_session->view_start[pane->number]) *
2706 mwindow->edl->local_session->zoom_sample /
2707 mwindow->edl->session->sample_rate;
2708 int64_t unit_position = autos->track->to_units(position, 0);
2709 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2711 mwindow->undo->update_undo_before();
2713 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2714 ((IntAuto*)current)->value = new_value;
2715 // Toggle Autos don't respond to vertical zoom, they always show up
2716 // with "on" == 100% == line on top
2717 mwindow->session->drag_start_percentage = (float)new_value;
2718 mwindow->session->drag_start_position = current->position;
2719 mwindow->session->drag_origin_x = cursor_x;
2720 mwindow->session->drag_origin_y = cursor_y;
2728 void TrackCanvas::calculate_viewport(Track *track,
2729 double &view_start, // Seconds
2731 double &view_end, // Seconds
2735 double &zoom_sample,
2738 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2739 mwindow->edl->local_session->zoom_sample /
2740 mwindow->edl->session->sample_rate;
2741 unit_start = track->to_doubleunits(view_start);
2742 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2744 mwindow->edl->local_session->zoom_sample /
2745 mwindow->edl->session->sample_rate;
2746 unit_end = track->to_doubleunits(view_end);
2747 yscale = mwindow->edl->local_session->zoom_track;
2748 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2749 center_pixel = (int)(track->y_pixel -
2750 mwindow->edl->local_session->track_start[pane->number] +
2752 (mwindow->edl->session->show_titles ?
2753 mwindow->theme->get_image("title_bg_data")->get_h() :
2755 zoom_sample = mwindow->edl->local_session->zoom_sample;
2757 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2760 float TrackCanvas::percentage_to_value(float percentage,
2768 if(percentage > 0.5)
2775 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2776 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2777 float automation_range = automation_max - automation_min;
2779 result = percentage * automation_range + automation_min;
2782 FloatAuto *ptr = (FloatAuto*)reference;
2783 result -= ptr->get_value();
2785 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2791 void TrackCanvas::calculate_auto_position(double *x, double *y,
2792 double *in_x, double *in_y, double *out_x, double *out_y,
2793 Auto *current, double unit_start, double zoom_units, double yscale,
2796 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2797 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2798 float automation_range = automation_max - automation_min;
2799 FloatAuto *ptr = (FloatAuto*)current;
2800 *x = (double)(ptr->position - unit_start) / zoom_units;
2801 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2804 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2805 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2809 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2810 automation_min) / automation_range - 0.5) * -yscale;
2814 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2815 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2819 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2820 automation_min) / automation_range - 0.5) * -yscale;
2825 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2826 int draw, int buttonpress, int x_offset, int y_offset, int color,
2827 Auto* &auto_instance, int autogrouptype)
2830 int center_pixel, draw_auto;
2831 double view_start, unit_start;
2832 double view_end, unit_end, yscale;
2833 double zoom_sample, zoom_units;
2834 double in_x2, in_y2, out_x2, out_y2;
2840 if(draw) set_color(color);
2842 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2843 yscale, center_pixel, zoom_sample, zoom_units);
2845 // Get first auto before start
2846 Auto *current = 0, *previous = 0;
2848 for( current = autos->last;
2849 current && current->position >= unit_start;
2850 current = PREVIOUS ) ;
2852 Auto *first_auto = current ? current :
2853 autos->first ? autos->first : autos->default_auto;
2855 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2857 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2858 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2863 current = autos->first;
2872 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2873 current, unit_start, zoom_units, yscale, autogrouptype);
2881 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2886 ay2 = ay + slope * (get_w() - ax);
2890 ay = ay + slope * (0 - ax);
2894 // Draw or test handle
2895 if( current && !result && current != autos->default_auto ) {
2896 if( !draw && track->record ) {
2897 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
2898 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
2899 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
2900 buttonpress, autogrouptype);
2902 auto_instance = current;
2904 if( draw && draw_auto ) {
2905 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
2906 (int)in_x2 + x_offset, (int)in_y2,
2907 (int)out_x2 + x_offset, (int)out_y2,
2908 (int)center_pixel + y_offset, (int)yscale, color);
2912 // Draw or test joining line
2913 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
2914 result = test_floatline(center_pixel,
2915 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2916 // Exclude auto coverage from the end of the line. The auto overlaps
2917 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
2918 buttonpress, autogrouptype);
2921 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
2922 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2923 (int)ax, (int)ay, (int)ax2, (int)ay2,
2924 color, autogrouptype);
2932 } while( current && current->position <= unit_end && !result );
2934 if( ax < get_w() && !result ) {
2935 ax2 = get_w(); ay2 = ay;
2936 if(!draw && track->record /* && buttonpress != 3 */ ) {
2937 result = test_floatline(center_pixel,
2938 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2939 (int)ax, (int)ax2, cursor_x, cursor_y,
2940 buttonpress, autogrouptype);
2943 draw_floatline(center_pixel,
2944 (FloatAuto*)previous, (FloatAuto*)current,
2945 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2946 (int)ax, (int)ay, (int)ax2, (int)ay2,
2947 color, autogrouptype);
2954 int TrackCanvas::do_int_autos(Track *track,
2963 Auto *&auto_instance)
2974 double ax, ay, ax2, ay2;
2978 if(draw) set_color(color);
2980 calculate_viewport(track,
2991 double high = -yscale * 0.8 / 2;
2992 double low = yscale * 0.8 / 2;
2994 // Get first auto before start
2996 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3002 ay = ((IntAuto*)current)->value > 0 ? high : low;
3007 current = autos->first ? autos->first : autos->default_auto;
3011 ay = ((IntAuto*)current)->value > 0 ? high : low;
3024 ax2 = (double)(current->position - unit_start) / zoom_units;
3025 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3033 if(ax2 > get_w()) ax2 = get_w();
3035 if(current && !result)
3037 if(current != autos->default_auto)
3043 result = test_auto(current,
3052 auto_instance = current;
3057 (int)ax2 + x_offset,
3058 (int)ay2 + y_offset,
3070 if(track->record /* && buttonpress != 3 */)
3072 result = test_toggleline(autos,
3085 draw_toggleline(center_pixel + y_offset,
3093 }while(current && current->position <= unit_end && !result);
3095 if(ax < get_w() && !result)
3101 if(track->record /* && buttonpress != 3 */)
3103 result = test_toggleline(autos,
3115 draw_toggleline(center_pixel + y_offset,
3124 int TrackCanvas::do_autos(Track *track,
3131 Auto * &auto_instance,
3145 calculate_viewport(track,
3158 for(current = autos->first; current && !result; current = NEXT)
3160 if(current->position >= unit_start && current->position < unit_end)
3163 x = (int64_t)((double)(current->position - unit_start) /
3164 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3165 y = center_pixel - pixmap->get_h() / 2;
3169 if(cursor_x >= x && cursor_y >= y &&
3170 cursor_x < x + pixmap->get_w() &&
3171 cursor_y < y + pixmap->get_h())
3174 auto_instance = current;
3176 if(buttonpress && (buttonpress != 3))
3178 mwindow->session->drag_auto = current;
3179 mwindow->session->drag_start_position = current->position;
3180 mwindow->session->drag_origin_x = cursor_x;
3181 mwindow->session->drag_origin_y = cursor_y;
3183 double position = autos->track->from_units(current->position);
3184 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3185 mwindow->edl->local_session->get_selectionend(1)) /
3190 mwindow->edl->local_session->set_selectionstart(position);
3191 mwindow->edl->local_session->set_selectionend(position);
3194 if(position < center)
3196 mwindow->edl->local_session->set_selectionstart(position);
3199 mwindow->edl->local_session->set_selectionend(position);
3206 draw_pixmap(pixmap, x, y);
3214 // so this means it is always >0 when keyframe is found
3215 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3216 int draw, int buttonpress, Plugin* &keyframe_plugin,
3217 KeyFrame* &keyframe_instance)
3230 if(!track->expand_view) return 0;
3232 calculate_viewport(track,
3244 for(int i = 0; i < track->plugin_set.total && !result; i++)
3246 PluginSet *plugin_set = track->plugin_set.values[i];
3247 int center_pixel = (int)(track->y_pixel -
3248 mwindow->edl->local_session->track_start[pane->number] +
3249 mwindow->edl->local_session->zoom_track +
3250 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3251 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3253 for(Plugin *plugin = (Plugin*)plugin_set->first;
3255 plugin = (Plugin*)plugin->next)
3257 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3258 keyframe && !result;
3259 keyframe = (KeyFrame*)keyframe->next)
3261 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3262 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3264 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3265 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3267 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3270 if(cursor_x >= x && cursor_y >= y &&
3271 cursor_x < x + keyframe_pixmap->get_w() &&
3272 cursor_y < y + keyframe_pixmap->get_h())
3275 keyframe_plugin = plugin;
3276 keyframe_instance = keyframe;
3280 mwindow->session->drag_auto = keyframe;
3281 mwindow->session->drag_start_position = keyframe->position;
3282 mwindow->session->drag_origin_x = cursor_x;
3283 mwindow->session->drag_origin_y = cursor_y;
3285 double position = track->from_units(keyframe->position);
3286 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3287 mwindow->edl->local_session->get_selectionend(1)) /
3292 mwindow->edl->local_session->set_selectionstart(position);
3293 mwindow->edl->local_session->set_selectionend(position);
3296 if(position < center)
3298 mwindow->edl->local_session->set_selectionstart(position);
3301 mwindow->edl->local_session->set_selectionend(position);
3306 draw_pixmap(keyframe_pixmap,
3316 // if(buttonpress && buttonpress != 3 && result)
3318 // mwindow->undo->update_undo_before();
3324 void TrackCanvas::draw_overlays()
3326 int new_cursor, update_cursor, rerender;
3328 // Move background pixmap to foreground pixmap
3329 draw_pixmap(background_pixmap,
3338 draw_inout_points();
3341 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3348 draw_brender_start();
3350 // Highlighted areas
3351 draw_highlighting();
3354 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3357 if(pane->cursor) pane->cursor->restore(1);
3363 draw_playback_cursor();
3368 int TrackCanvas::activate()
3372 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3373 //BC_Signals::dump_stack();
3374 get_top_level()->deactivate();
3376 set_active_subwindow(this);
3377 pane->cursor->activate();
3378 gui->focused_pane = pane->number;
3383 int TrackCanvas::deactivate()
3388 pane->cursor->deactivate();
3394 void TrackCanvas::update_drag_handle()
3396 double new_position;
3399 (double)(get_cursor_x() +
3400 mwindow->edl->local_session->view_start[pane->number]) *
3401 mwindow->edl->local_session->zoom_sample /
3402 mwindow->edl->session->sample_rate;
3404 mwindow->edl->align_to_frame(new_position, 0);
3407 if(new_position != mwindow->session->drag_position)
3409 mwindow->session->drag_position = new_position;
3410 gui->mainclock->update(new_position);
3413 timebar_position = new_position;
3414 gui->update_timebar(0);
3415 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3417 // mwindow->cwindow->update(1, 0, 0);
3421 int TrackCanvas::update_drag_edit()
3430 int TrackCanvas::get_drag_values(float *percentage,
3437 //int x = cursor_x - mwindow->session->drag_origin_x;
3438 //int y = cursor_y - mwindow->session->drag_origin_y;
3442 if(!current->autos->track->record) return 1;
3452 calculate_viewport(current->autos->track,
3462 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3464 mwindow->session->drag_start_percentage;
3465 if(do_clamp) CLAMP(*percentage, 0, 1);
3467 *position = Units::to_int64(zoom_units *
3468 (cursor_x - mwindow->session->drag_origin_x) +
3469 mwindow->session->drag_start_position + 0.5);
3471 if((do_clamp) && *position < 0) *position = 0;
3476 #define UPDATE_DRAG_HEAD(do_clamp) \
3477 int result = 0, center_pixel; \
3478 if(!current->autos->track->record) return 0; \
3479 double view_start, unit_start, view_end, unit_end; \
3480 double yscale, zoom_sample, zoom_units; \
3482 calculate_viewport(current->autos->track, \
3483 view_start, unit_start, view_end, unit_end, \
3484 yscale, center_pixel, zoom_sample, zoom_units); \
3486 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3487 yscale + mwindow->session->drag_start_percentage; \
3488 if(do_clamp) CLAMP(percentage, 0, 1); \
3490 int64_t position = Units::to_int64(zoom_units * \
3491 (cursor_x - mwindow->session->drag_origin_x) + \
3492 mwindow->session->drag_start_position); \
3493 if((do_clamp) && position < 0) position = 0;
3496 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3498 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3500 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3501 int x = cursor_x - mwindow->session->drag_origin_x;
3502 int y = cursor_y - mwindow->session->drag_origin_y;
3503 float value, old_value;
3505 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3506 // not really editing the node, rather start editing the curve
3507 // tangent is editable and drag movement is significant
3508 if( (FloatAuto::FREE == current->curve_mode ||
3509 FloatAuto::TFREE==current->curve_mode) &&
3510 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3511 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3514 switch(mwindow->session->drag_handle) {
3516 // Snap to nearby values
3517 old_value = current->get_value();
3519 double value1, value2, distance1, distance2;
3521 if(current->previous) {
3522 int autogrouptype = current->previous->autos->autogrouptype;
3523 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3524 value1 = ((FloatAuto*)current->previous)->get_value();
3525 distance1 = fabs(value - value1);
3526 current->set_value(value1);
3530 int autogrouptype = current->next->autos->autogrouptype;
3531 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3532 value2 = ((FloatAuto*)current->next)->get_value();
3533 distance2 = fabs(value - value2);
3534 if(!current->previous || distance2 < distance1) {
3535 current->set_value(value2);
3539 if(!current->previous && !current->next) {
3540 current->set_value( ((FloatAutos*)current->autos)->default_);
3542 value = current->get_value();
3545 int autogrouptype = current->autos->autogrouptype;
3546 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3549 if(alt_down() && !shift_down())
3550 // ALT constrains movement: fixed position, only changing the value
3551 position = mwindow->session->drag_start_position;
3553 if(value != old_value || position != current->position) {
3555 float change = value - old_value;
3556 current->adjust_to_new_coordinates(position, value);
3557 synchronize_autos(change, current->autos->track, current, 0);
3558 show_message(current, 1,", %.2f", current->get_value());
3564 int autogrouptype = current->autos->autogrouptype;
3565 value = percentage_to_value(percentage, 0, current, autogrouptype);
3566 if(value != current->get_control_in_value())
3569 // note: (position,value) need not be at the location of the ctrl point,
3570 // but could be somewhere in between on the curve (or even outward or
3571 // on the opposit side). We set the new control point such as
3572 // to point the curve through (position,value)
3573 current->set_control_in_value(
3574 value * levered_position(position - current->position,
3575 current->get_control_in_position()));
3576 synchronize_autos(0, current->autos->track, current, 0);
3577 show_message(current, 1,", %.2f", current->get_control_in_value());
3583 int autogrouptype = current->autos->autogrouptype;
3584 value = percentage_to_value(percentage, 0, current, autogrouptype);
3585 if(value != current->get_control_out_value()) {
3587 current->set_control_out_value(
3588 value * levered_position(position - current->position,
3589 current->get_control_out_position()));
3590 synchronize_autos(0, current->autos->track, current, 0);
3591 show_message(current, 1,", %.2f", current->get_control_out_value());
3599 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3601 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3603 UPDATE_DRAG_HEAD(1);
3604 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3606 if(value != current->value || position != current->position)
3609 current->value = value;
3610 current->position = position;
3611 show_message(current, 0,", %d", current->value);
3617 // Autos which can't change value through dragging.
3619 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3621 Auto *current = (Auto*)mwindow->session->drag_auto;
3624 if(position != current->position)
3627 current->position = position;
3628 show_message(current, 0,"");
3630 double position_f = current->autos->track->from_units(current->position);
3631 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3632 mwindow->edl->local_session->get_selectionend(1)) /
3636 mwindow->edl->local_session->set_selectionstart(position_f);
3637 mwindow->edl->local_session->set_selectionend(position_f);
3640 if(position_f < center_f)
3642 mwindow->edl->local_session->set_selectionstart(position_f);
3645 mwindow->edl->local_session->set_selectionend(position_f);
3652 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3654 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3657 if(position != current->position)
3659 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3660 Track *track = current->autos->track;
3661 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3662 PluginSet *pluginset;
3664 // figure out the correct pluginset & correct plugin
3666 for(int i = 0; i < track->plugin_set.total; i++)
3668 pluginset = track->plugin_set.values[i];
3669 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3671 KeyFrames *keyframes = plugin->keyframes;
3672 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3674 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3676 if (currentkeyframe == current)
3688 mwindow->session->plugin_highlighted = plugin;
3689 mwindow->session->track_highlighted = track;
3691 current->position = position;
3692 show_message(current, 0,"");
3694 double position_f = current->autos->track->from_units(current->position);
3695 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3696 mwindow->edl->local_session->get_selectionend(1)) /
3700 mwindow->edl->local_session->set_selectionstart(position_f);
3701 mwindow->edl->local_session->set_selectionend(position_f);
3704 if(position_f < center_f)
3706 mwindow->edl->local_session->set_selectionstart(position_f);
3709 mwindow->edl->local_session->set_selectionend(position_f);
3716 void TrackCanvas::update_drag_caption()
3718 switch(mwindow->session->current_operation)
3728 int TrackCanvas::cursor_motion_event()
3733 int update_clock = 0;
3734 int update_zoom = 0;
3735 int update_scroll = 0;
3736 int update_overlay = 0;
3737 int update_cursor = 0;
3740 double position = 0.;
3741 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3744 switch(mwindow->edl->session->editing_mode)
3746 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3747 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3750 switch(mwindow->session->current_operation)
3752 case DRAG_EDITHANDLE1:
3753 // Outside threshold. Upgrade status
3756 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3758 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3764 case DRAG_EDITHANDLE2:
3767 update_drag_handle();
3772 case DRAG_PLUGINHANDLE1:
3775 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3777 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3783 case DRAG_PLUGINHANDLE2:
3786 update_drag_handle();
3791 // Rubber band curves
3799 case DRAG_PROJECTOR_X:
3800 case DRAG_PROJECTOR_Y:
3801 case DRAG_PROJECTOR_Z:
3802 if(active) rerender = update_overlay =
3803 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3807 if(active) rerender = update_overlay =
3808 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3812 if(active) rerender = update_overlay =
3813 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3816 // Keyframe icons are sticky
3820 case DRAG_PLUGINKEY_PRE:
3822 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3823 mwindow->session->current_operation++;
3826 mwindow->undo->update_undo_before();
3834 if(active) rerender = update_overlay =
3835 update_drag_auto(get_cursor_x(), get_cursor_y());
3838 case DRAG_PLUGINKEY:
3839 if(active) rerender = update_overlay =
3840 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
3845 cursor_x = get_cursor_x();
3846 cursor_y = get_cursor_y();
3847 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
3848 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
3850 position = mwindow->edl->align_to_frame(position, 0);
3851 position = MAX(position, 0);
3853 if(position < selection_midpoint) {
3854 mwindow->edl->local_session->set_selectionend(selection_midpoint);
3855 mwindow->edl->local_session->set_selectionstart(position);
3857 gui->unlock_window();
3858 mwindow->cwindow->update(1, 0, 0, 0, 1);
3859 gui->lock_window("TrackCanvas::cursor_motion_event 1");
3860 // Update the faders
3861 mwindow->update_plugin_guis();
3862 gui->update_patchbay();
3865 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
3866 mwindow->edl->local_session->set_selectionend(position);
3867 // Don't que the CWindow
3870 timebar_position = mwindow->edl->local_session->get_selectionend(1);
3872 gui->hide_cursor(0);
3873 gui->draw_cursor(1);
3874 gui->update_timebar(0);
3875 gui->flash_canvas(1);
3884 if(is_event_win() && cursor_inside()) {
3886 cursor_x = get_cursor_x();
3887 position = (double)cursor_x *
3888 (double)mwindow->edl->local_session->zoom_sample /
3889 (double)mwindow->edl->session->sample_rate +
3890 (double)mwindow->edl->local_session->view_start[pane->number] *
3891 (double)mwindow->edl->local_session->zoom_sample /
3892 (double)mwindow->edl->session->sample_rate;
3893 position = mwindow->edl->align_to_frame(position, 0);
3897 for(int i = 0; i < TOTAL_PANES; i++)
3898 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
3900 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
3901 gui->update_timebar(0);
3903 if(do_transitions(get_cursor_x(), get_cursor_y(),
3904 0, new_cursor, update_cursor)) break;
3905 if(do_keyframes(get_cursor_x(), get_cursor_y(),
3906 0, 0, new_cursor, update_cursor, rerender)) break;
3907 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
3908 0, rerender, update_overlay, new_cursor, update_cursor)) break;
3909 // Plugin boundaries
3910 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
3911 0, rerender, update_overlay, new_cursor, update_cursor)) break;
3912 if(do_edits(get_cursor_x(), get_cursor_y(),
3913 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
3918 //printf("TrackCanvas::cursor_motion_event 1\n");
3919 if(update_cursor && new_cursor != get_cursor())
3921 set_cursor(new_cursor, 0, 1);
3924 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
3925 if(rerender && render_timer->get_difference() > 0.25 ) {
3926 render_timer->update();
3927 mwindow->restart_brender();
3928 mwindow->sync_parameters(CHANGE_PARAMS);
3929 mwindow->update_plugin_guis();
3930 gui->unlock_window();
3931 mwindow->cwindow->update(1, 0, 0, 0, 1);
3932 gui->lock_window("TrackCanvas::cursor_motion_event 2");
3936 gui->update_patchbay();
3941 if(!mwindow->cwindow->playback_engine->is_playing_back)
3942 gui->mainclock->update(position);
3946 gui->zoombar->update();
3951 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
3955 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
3959 if(update_overlay) {
3960 gui->draw_overlays(1);
3963 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3967 void TrackCanvas::start_dragscroll()
3971 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3972 //printf("TrackCanvas::start_dragscroll 1\n");
3976 void TrackCanvas::stop_dragscroll()
3980 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3981 //printf("TrackCanvas::stop_dragscroll 1\n");
3985 int TrackCanvas::repeat_event(int64_t duration)
3987 if(!drag_scroll) return 0;
3988 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
3990 int sample_movement = 0;
3991 int track_movement = 0;
3992 int64_t x_distance = 0;
3993 int64_t y_distance = 0;
3994 double position = 0;
3997 switch(mwindow->session->current_operation) {
3999 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4000 if(get_cursor_x() > get_w()) {
4001 x_distance = get_cursor_x() - get_w();
4002 sample_movement = 1;
4004 else if(get_cursor_x() < 0) {
4005 x_distance = get_cursor_x();
4006 sample_movement = 1;
4009 if(get_cursor_y() > get_h()) {
4010 y_distance = get_cursor_y() - get_h();
4013 else if(get_cursor_y() < 0) {
4014 y_distance = get_cursor_y();
4021 if(sample_movement) {
4022 position = (double)(get_cursor_x() +
4023 mwindow->edl->local_session->view_start[pane->number] +
4025 mwindow->edl->local_session->zoom_sample /
4026 mwindow->edl->session->sample_rate;
4027 position = mwindow->edl->align_to_frame(position, 0);
4028 position = MAX(position, 0);
4030 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4031 switch(mwindow->session->current_operation) {
4033 if(position < selection_midpoint) {
4034 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4035 mwindow->edl->local_session->set_selectionstart(position);
4037 gui->unlock_window();
4038 mwindow->cwindow->update(1, 0, 0);
4039 gui->lock_window("TrackCanvas::repeat_event");
4040 // Update the faders
4041 mwindow->update_plugin_guis();
4042 gui->update_patchbay();
4045 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4046 mwindow->edl->local_session->set_selectionend(position);
4047 // Don't que the CWindow
4052 mwindow->samplemovement(
4053 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4057 if(track_movement) {
4058 mwindow->trackmovement(y_distance, pane->number);
4064 int TrackCanvas::button_release_event()
4066 int redraw = 0, update_overlay = 0, result = 0;
4068 // printf("TrackCanvas::button_release_event %d\n",
4069 // mwindow->session->current_operation);
4071 switch(mwindow->session->current_operation) {
4072 case DRAG_EDITHANDLE2:
4073 mwindow->session->current_operation = NO_OPERATION;
4077 end_edithandle_selection();
4080 case DRAG_EDITHANDLE1:
4081 mwindow->session->current_operation = NO_OPERATION;
4086 case DRAG_PLUGINHANDLE2:
4087 mwindow->session->current_operation = NO_OPERATION;
4091 end_pluginhandle_selection();
4094 case DRAG_PLUGINHANDLE1:
4095 mwindow->session->current_operation = NO_OPERATION;
4102 // delete the drag_auto_gang first and remove out of order keys
4103 synchronize_autos(0, 0, 0, -1);
4114 case DRAG_PROJECTOR_X:
4115 case DRAG_PROJECTOR_Y:
4116 case DRAG_PROJECTOR_Z:
4117 case DRAG_PLUGINKEY:
4118 mwindow->session->current_operation = NO_OPERATION;
4119 mwindow->session->drag_handle = 0;
4120 // Remove any out-of-order keyframe
4121 if(mwindow->session->drag_auto) {
4122 mwindow->session->drag_auto->autos->remove_nonsequential(
4123 mwindow->session->drag_auto);
4124 // mwindow->session->drag_auto->autos->optimize();
4129 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4134 case DRAG_AEFFECT_COPY:
4135 case DRAG_VEFFECT_COPY:
4136 // Trap in drag stop
4141 if(mwindow->session->current_operation) {
4142 // if(mwindow->session->current_operation == SELECT_REGION) {
4143 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4146 mwindow->session->current_operation = NO_OPERATION;
4148 // Traps button release events
4156 cursor_motion_event();
4158 if(update_overlay) {
4159 gui->draw_overlays(1);
4162 gui->draw_canvas(NORMAL_DRAW, 0);
4167 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4168 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4170 Edit *edit_result = 0;
4171 int handle_result = 0;
4174 if(!mwindow->edl->session->show_assets) return 0;
4176 for(Track *track = mwindow->edl->tracks->first;
4178 track = track->next) {
4179 for(Edit *edit = track->edits->first;
4181 edit = edit->next) {
4182 int64_t edit_x, edit_y, edit_w, edit_h;
4183 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4185 if(cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4186 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4187 if(cursor_x < edit_x + HANDLE_W) {
4192 else if(cursor_x >= edit_x + edit_w - HANDLE_W) {
4206 double position = 0;
4207 if(handle_result == 0) {
4208 position = edit_result->track->from_units(edit_result->startproject);
4209 new_cursor = LEFT_CURSOR;
4211 else if(handle_result == 1) {
4212 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4213 new_cursor = RIGHT_CURSOR;
4216 // Reposition cursor
4218 mwindow->session->drag_edit = edit_result;
4219 mwindow->session->drag_handle = handle_result;
4220 mwindow->session->drag_button = get_buttonpress() - 1;
4221 mwindow->session->drag_position = position;
4222 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4223 mwindow->session->drag_origin_x = get_cursor_x();
4224 mwindow->session->drag_origin_y = get_cursor_y();
4225 mwindow->session->drag_start = position;
4227 rerender = start_selection(position);
4235 int TrackCanvas::do_plugin_handles(int cursor_x,
4239 int &update_overlay,
4243 Plugin *plugin_result = 0;
4244 int handle_result = 0;
4247 // if(!mwindow->edl->session->show_assets) return 0;
4249 for(Track *track = mwindow->edl->tracks->first;
4251 track = track->next) {
4252 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4253 PluginSet *plugin_set = track->plugin_set.values[i];
4254 for(Plugin *plugin = (Plugin*)plugin_set->first;
4256 plugin = (Plugin*)plugin->next) {
4257 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4258 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4260 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4261 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4262 if(cursor_x < plugin_x + HANDLE_W) {
4263 plugin_result = plugin;
4267 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4268 plugin_result = plugin;
4275 if(result && shift_down())
4276 mwindow->session->trim_edits = plugin_set;
4282 double position = 0;
4283 if(handle_result == 0) {
4284 position = plugin_result->track->from_units(plugin_result->startproject);
4285 new_cursor = LEFT_CURSOR;
4287 else if(handle_result == 1) {
4288 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4289 new_cursor = RIGHT_CURSOR;
4293 mwindow->session->drag_plugin = plugin_result;
4294 mwindow->session->drag_handle = handle_result;
4295 mwindow->session->drag_button = get_buttonpress() - 1;
4296 mwindow->session->drag_position = position;
4297 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4298 mwindow->session->drag_origin_x = get_cursor_x();
4299 mwindow->session->drag_origin_y = get_cursor_y();
4300 mwindow->session->drag_start = position;
4302 rerender = start_selection(position);
4311 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4315 // if(!mwindow->edl->session->show_assets) return 0;
4317 for(Track *track = mwindow->edl->tracks->first;
4319 track = track->next) {
4320 int64_t track_x, track_y, track_w, track_h;
4321 track_dimensions(track, track_x, track_y, track_w, track_h);
4323 if(button_press && get_buttonpress() == 3 &&
4324 cursor_y >= track_y && cursor_y < track_y + track_h) {
4325 gui->edit_menu->update(track, 0);
4326 gui->edit_menu->activate_menu();
4334 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4335 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4339 if(!mwindow->edl->session->show_assets) return 0;
4341 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4343 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4344 int64_t edit_x, edit_y, edit_w, edit_h;
4345 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4347 // Cursor inside a track
4348 // Cursor inside an edit
4349 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4350 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4351 // Select duration of edit
4353 if(get_double_click() && !drag_start) {
4354 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4355 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4356 edit->track->from_units(edit->length));
4357 if(mwindow->edl->session->cursor_on_frames)
4359 mwindow->edl->local_session->set_selectionstart(
4360 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4361 mwindow->edl->local_session->set_selectionend(
4362 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4370 else if(drag_start && track->record) {
4371 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4372 // Need to create drag window
4373 mwindow->session->current_operation = DRAG_EDIT;
4374 mwindow->session->drag_edit = edit;
4375 //printf("TrackCanvas::do_edits 2\n");
4377 // Drag only one edit if ctrl is initially down
4379 mwindow->session->drag_edits->remove_all();
4380 mwindow->session->drag_edits->append(edit);
4383 // Construct list of all affected edits
4384 mwindow->edl->tracks->get_affected_edits(
4385 mwindow->session->drag_edits,
4386 edit->track->from_units(edit->startproject),
4389 mwindow->session->drag_origin_x = cursor_x;
4390 mwindow->session->drag_origin_y = cursor_y;
4391 // Where the drag started, so we know relative position inside the edit later
4392 mwindow->session->drag_position = (double)cursor_x *
4393 mwindow->edl->local_session->zoom_sample /
4394 mwindow->edl->session->sample_rate +
4395 (double)mwindow->edl->local_session->view_start[pane->number] *
4396 mwindow->edl->local_session->zoom_sample /
4397 mwindow->edl->session->sample_rate;
4399 gui->drag_popup = new BC_DragWindow(gui,
4400 mwindow->theme->get_image("clip_icon") /*,
4401 get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
4402 get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
4414 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4419 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4420 int button_press, int &redraw, int &rerender)
4429 // if(!mwindow->edl->session->show_assets) return 0;
4432 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4433 if(!track->expand_view) continue;
4435 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4436 // first check if plugins are visible at all
4437 if (!track->expand_view)
4439 PluginSet *plugin_set = track->plugin_set.values[i];
4440 for(plugin = (Plugin*)plugin_set->first;
4442 plugin = (Plugin*)plugin->next) {
4443 plugin_dimensions(plugin, x, y, w, h);
4444 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4445 MWindowGUI::visible(y, y + h, 0, get_h())) {
4446 if(cursor_x >= x && cursor_x < x + w &&
4447 cursor_y >= y && cursor_y < y + h) {
4457 // Start plugin popup
4459 if(get_buttonpress() == 3) {
4460 gui->plugin_menu->update(plugin);
4461 gui->plugin_menu->activate_menu();
4464 else if (get_double_click() && !drag_start) {
4465 // Select range of plugin on doubleclick over plugin
4466 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4467 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4468 plugin->track->from_units(plugin->length));
4469 if(mwindow->edl->session->cursor_on_frames) {
4470 mwindow->edl->local_session->set_selectionstart(
4471 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4472 mwindow->edl->local_session->set_selectionend(
4473 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4482 if(drag_start && plugin->track->record) {
4483 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4484 if(plugin->track->data_type == TRACK_AUDIO)
4485 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4486 else if(plugin->track->data_type == TRACK_VIDEO)
4487 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4489 mwindow->session->drag_plugin = plugin;
4490 mwindow->session->drag_origin_x = cursor_x;
4491 mwindow->session->drag_origin_y = cursor_y;
4492 // Where the drag started, so we know relative position inside the edit later
4493 mwindow->session->drag_position =
4494 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4495 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4497 switch(plugin->plugin_type) {
4498 case PLUGIN_STANDALONE: {
4499 PluginServer *server =
4500 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4501 if( !server ) break;
4502 VFrame *frame = server->picon;
4504 if(plugin->track->data_type == TRACK_AUDIO) {
4505 frame = mwindow->theme->get_image("aeffect_icon");
4508 frame = mwindow->theme->get_image("veffect_icon");
4512 gui->drag_popup = new BC_DragWindow(gui, frame /*,
4513 get_abs_cursor_x(0) - frame->get_w() / 2,
4514 get_abs_cursor_y(0) - frame->get_h() / 2 */);
4517 case PLUGIN_SHAREDPLUGIN:
4518 case PLUGIN_SHAREDMODULE:
4519 gui->drag_popup = new BC_DragWindow(gui,
4520 mwindow->theme->get_image("clip_icon") /*,
4521 get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
4522 get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
4534 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4535 int button_press, int &new_cursor, int &update_cursor)
4537 Transition *transition = 0;
4541 if(/* !mwindow->edl->session->show_assets || */
4542 !mwindow->edl->session->auto_conf->transitions) return 0;
4544 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4546 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4547 if( edit->transition ) {
4548 edit_dimensions(edit, x, y, w, h);
4549 get_transition_coords(x, y, w, h);
4551 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4552 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4553 if( cursor_x >= x && cursor_x < x + w &&
4554 cursor_y >= y && cursor_y < y + h ) {
4555 transition = edit->transition;
4567 new_cursor = UPRIGHT_ARROW_CURSOR;
4569 else if(get_buttonpress() == 3) {
4570 gui->transition_menu->update(transition);
4571 gui->transition_menu->activate_menu();
4578 int TrackCanvas::button_press_event()
4581 int cursor_x, cursor_y;
4584 cursor_x = get_cursor_x();
4585 cursor_y = get_cursor_y();
4586 mwindow->session->trim_edits = 0;
4588 if(is_event_win() && cursor_inside()) {
4589 // double position = (double)cursor_x *
4590 // mwindow->edl->local_session->zoom_sample /
4591 // mwindow->edl->session->sample_rate +
4592 // (double)mwindow->edl->local_session->view_start[pane->number] *
4593 // mwindow->edl->local_session->zoom_sample /
4594 // mwindow->edl->session->sample_rate;
4601 if( get_buttonpress() == LEFT_BUTTON ) {
4602 gui->unlock_window();
4603 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4604 gui->lock_window("TrackCanvas::button_press_event");
4607 int update_overlay = 0, update_cursor = 0, rerender = 0;
4609 if(get_buttonpress() == WHEEL_UP) {
4611 mwindow->expand_sample();
4612 else if(ctrl_down())
4613 mwindow->move_left(get_w()/ 10);
4615 mwindow->move_up(get_h() / 10);
4617 else if(get_buttonpress() == WHEEL_DOWN) {
4619 mwindow->zoom_in_sample();
4620 else if(ctrl_down())
4621 mwindow->move_right(get_w() / 10);
4623 mwindow->move_down(get_h() / 10);
4625 else if(get_buttonpress() == 6) {
4627 mwindow->move_left(get_w());
4629 mwindow->move_left(get_w() / 20);
4631 mwindow->move_left(get_w() / 5);
4633 else if(get_buttonpress() == 7) {
4635 mwindow->move_right(get_w());
4637 mwindow->move_right(get_w() / 20);
4639 mwindow->move_right(get_w() / 5);
4642 switch(mwindow->edl->session->editing_mode) {
4643 // Test handles and resource boundaries and highlight a track
4644 case EDITING_ARROW: {
4645 if( mwindow->edl->session->auto_conf->transitions &&
4646 do_transitions(cursor_x, cursor_y,
4647 1, new_cursor, update_cursor) ) break;
4649 if( do_keyframes(cursor_x, cursor_y,
4650 0, get_buttonpress(), new_cursor,
4651 update_cursor, rerender) ) break;
4652 // Test edit boundaries
4653 if( do_edit_handles(cursor_x, cursor_y,
4654 1, rerender, update_overlay, new_cursor,
4655 update_cursor) ) break;
4656 // Test plugin boundaries
4657 if( do_plugin_handles(cursor_x, cursor_y,
4658 1, rerender, update_overlay, new_cursor,
4659 update_cursor) ) break;
4661 if( do_edits(cursor_x, cursor_y, 1, 0,
4662 update_cursor, rerender, new_cursor,
4663 update_cursor) ) break;
4665 if( do_plugins(cursor_x, cursor_y, 0, 1,
4666 update_cursor, rerender) ) break;
4668 if( test_resources(cursor_x, cursor_y) ) break;
4670 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4675 // Test handles only and select a region
4676 case EDITING_IBEAM: {
4677 double position = (double)cursor_x *
4678 mwindow->edl->local_session->zoom_sample /
4679 mwindow->edl->session->sample_rate +
4680 (double)mwindow->edl->local_session->view_start[pane->number] *
4681 mwindow->edl->local_session->zoom_sample /
4682 mwindow->edl->session->sample_rate;
4683 //printf("TrackCanvas::button_press_event %d\n", position);
4685 if(mwindow->edl->session->auto_conf->transitions &&
4686 do_transitions(cursor_x, cursor_y,
4687 1, new_cursor, update_cursor)) break;
4688 if(do_keyframes(cursor_x, cursor_y,
4689 0, get_buttonpress(), new_cursor,
4690 update_cursor, rerender)) {
4694 // Test edit boundaries
4695 if( do_edit_handles(cursor_x, cursor_y,
4696 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4697 // Test plugin boundaries
4698 if( do_plugin_handles(cursor_x, cursor_y,
4699 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4701 if( do_edits(cursor_x, cursor_y,
4702 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4704 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4706 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4707 // Highlight selection
4708 rerender = start_selection(position);
4709 mwindow->session->current_operation = SELECT_REGION;
4716 gui->unlock_window();
4717 mwindow->cwindow->update(1, 0, 0, 0, 1);
4718 gui->lock_window("TrackCanvas::button_press_event 2");
4720 mwindow->update_plugin_guis();
4721 gui->update_patchbay();
4724 if( update_overlay ) {
4725 gui->draw_overlays(1);
4728 if( update_cursor > 0 ) {
4729 gui->update_timebar(0);
4730 gui->hide_cursor(0);
4731 gui->show_cursor(1);
4732 gui->zoombar->update();
4733 gui->flash_canvas(1);
4735 else if(update_cursor < 0) {
4736 gui->swindow->update_selection();
4742 int TrackCanvas::start_selection(double position)
4745 position = mwindow->edl->align_to_frame(position, 0);
4751 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4752 mwindow->edl->local_session->get_selectionend(1)) / 2;
4754 if(position < midpoint)
4756 mwindow->edl->local_session->set_selectionstart(position);
4757 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4763 mwindow->edl->local_session->set_selectionend(position);
4764 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4765 // Don't que the CWindow for the end
4769 // Start a new selection
4771 //printf("TrackCanvas::start_selection %f\n", position);
4772 mwindow->edl->local_session->set_selectionstart(position);
4773 mwindow->edl->local_session->set_selectionend(position);
4774 selection_midpoint = position;
4782 void TrackCanvas::end_edithandle_selection()
4784 mwindow->modify_edithandles();
4787 void TrackCanvas::end_pluginhandle_selection()
4789 mwindow->modify_pluginhandles();
4793 double TrackCanvas::time_visible()
4795 return (double)get_w() *
4796 mwindow->edl->local_session->zoom_sample /
4797 mwindow->edl->session->sample_rate;
4801 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
4803 char string[BCTEXTLEN];
4804 char *cp = string, *ep = cp + sizeof(string)-1;
4805 if( show_curve_type ) {
4806 cp += snprintf(string, ep-cp, "%-8s ",
4807 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
4809 char string2[BCTEXTLEN];
4810 Units::totext(string2,
4811 current->autos->track->from_units(current->position),
4812 mwindow->edl->session->time_format,
4813 mwindow->edl->session->sample_rate,
4814 mwindow->edl->session->frame_rate,
4815 mwindow->edl->session->frames_per_foot);
4816 cp += snprintf(cp, ep-cp, "%s", string2);
4819 vsnprintf(cp, ep-cp, fmt, ap);
4821 gui->show_message(string);
4824 // Patchbay* TrackCanvas::get_patchbay()
4826 // if(pane->patchbay) return pane->patchbay;
4827 // if(gui->total_panes() == 2 &&
4828 // gui->pane[TOP_LEFT_PANE] &&
4829 // gui->pane[TOP_RIGHT_PANE])
4830 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4831 // if(gui->total_panes() == 4)
4833 // if(pane->number == TOP_RIGHT_PANE)
4834 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4836 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;