4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "apatchgui.inc"
25 #include "automation.h"
26 #include "bcsignals.h"
30 #include "cplayback.h"
32 #include "cwindowgui.h"
34 #include "edithandles.h"
35 #include "editpopup.h"
38 #include "edlsession.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
41 #include "gwindowgui.h"
42 #include "indexstate.h"
46 #include "keyframepopup.h"
47 #include "keyframes.h"
50 #include "localsession.h"
51 #include "mainclock.h"
52 #include "maincursor.h"
53 #include "mainsession.h"
55 #include "maskautos.h"
58 #include "mwindowgui.h"
62 #include "playbackengine.h"
63 #include "playtransport.h"
65 #include "pluginpopup.h"
66 #include "pluginserver.h"
67 #include "pluginset.h"
68 #include "plugintoggles.h"
69 #include "preferences.h"
70 #include "resourcepixmap.h"
71 #include "resourcethread.h"
74 #include "trackcanvas.h"
77 #include "transition.h"
78 #include "transitionhandles.h"
79 #include "transitionpopup.h"
80 #include "transportque.h"
82 #include "vpatchgui.inc"
87 //#define PIXMAP_AGE -5
88 #define PIXMAP_AGE -32
90 TrackCanvas::TrackCanvas(MWindow *mwindow,
101 this->mwindow = mwindow;
102 this->gui = mwindow->gui;
105 selection_midpoint = 0;
109 resource_timer = new Timer;
110 render_timer = new Timer;
111 hourglass_enabled = 0;
112 timebar_position = -1;
116 TrackCanvas::~TrackCanvas()
118 // delete transition_handles;
120 delete keyframe_pixmap;
121 delete camerakeyframe_pixmap;
122 delete modekeyframe_pixmap;
123 delete pankeyframe_pixmap;
124 delete projectorkeyframe_pixmap;
125 delete maskkeyframe_pixmap;
126 delete background_pixmap;
127 if(temp_picon) delete temp_picon;
129 delete resource_timer;
132 void TrackCanvas::create_objects()
134 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
135 // transition_handles = new TransitionHandles(mwindow, this);
136 edit_handles = new EditHandles(mwindow, this);
137 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
138 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
139 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
140 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
141 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
142 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
148 void TrackCanvas::resize_event()
150 //printf("TrackCanvas::resize_event 1\n");
153 //printf("TrackCanvas::resize_event 2\n");
156 int TrackCanvas::keypress_event()
161 int TrackCanvas::cursor_leave_event()
163 // Because drag motion calls get_cursor_over_window we can be sure that
164 // all highlights get deleted now.
165 // This ended up blocking keyboard input from the drag operations.
166 if( timebar_position >= 0 )
168 timebar_position = -1;
170 pane->timebar->update(1);
174 // return drag_motion();
177 int TrackCanvas::drag_motion_event()
179 return gui->drag_motion();
182 int TrackCanvas::drag_motion(Track **over_track,
184 PluginSet **over_pluginset,
185 Plugin **over_plugin)
187 int cursor_x = get_relative_cursor_x();
188 int cursor_y = get_relative_cursor_y();
190 if( get_cursor_over_window() &&
191 cursor_x >= 0 && cursor_y >= 0 &&
192 cursor_x < get_w() && cursor_y < get_h() )
194 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
195 // Find the edit and track the cursor is over
196 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
198 int64_t track_x, track_y, track_w, track_h;
199 track_dimensions(track, track_x, track_y, track_w, track_h);
201 if(cursor_y >= track_y &&
202 cursor_y < track_y + track_h)
205 for(Edit *edit = track->edits->first; edit; edit = edit->next)
207 int64_t edit_x, edit_y, edit_w, edit_h;
208 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
209 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
210 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
214 if( edit != track->edits->last ) continue;
215 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
216 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
217 if( !edit->silence() ) {
218 // add silence to allow drag transition past last edit
219 // will be deleted by Edits::optimize if not used
220 double length = mwindow->edl->session->default_transition_length;
221 int64_t start = edit->startproject+edit->length;
222 int64_t units = track->to_units(length, 1);
223 track->edits->create_silence(start, start+units);
226 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
229 for(int i = 0; i < track->plugin_set.total; i++)
231 PluginSet *pluginset = track->plugin_set.values[i];
232 for(Plugin *plugin = (Plugin*)pluginset->first;
234 plugin = (Plugin*)plugin->next)
236 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
237 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
239 if(cursor_y >= plugin_y &&
240 cursor_y < plugin_y + plugin_h)
242 *over_pluginset = plugin->plugin_set;
244 if(cursor_x >= plugin_x &&
245 cursor_x < plugin_x + plugin_w)
247 *over_plugin = plugin;
259 *over_track = pane->over_patchbay();
265 int TrackCanvas::drag_stop_event()
267 int result = gui->drag_stop();
268 if( !result && mwindow->session->current_operation ) {
269 mwindow->session->current_operation = NO_OPERATION;
275 int TrackCanvas::drag_stop(int *redraw)
280 int cursor_x = -1, cursor_y = -1;
282 if( get_cursor_over_window() ) {
283 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
284 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
287 Track *track = pane->over_patchbay();
288 if( track && mwindow->session->track_highlighted == track )
294 switch(mwindow->session->current_operation) {
295 case DRAG_VTRANSITION:
296 case DRAG_ATRANSITION:
297 if(mwindow->session->edit_highlighted) {
298 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
299 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
300 (mwindow->session->current_operation == DRAG_VTRANSITION &&
301 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
302 mwindow->session->current_operation = NO_OPERATION;
303 mwindow->paste_transition();
310 // Behavior for dragged plugins is limited by the fact that a shared plugin
311 // can only refer to a standalone plugin that exists in the same position in
312 // time. Dragging a plugin from one point in time to another can't produce
313 // a shared plugin to the original plugin. In this case we relocate the
314 // plugin instead of sharing it.
315 case DRAG_AEFFECT_COPY:
316 case DRAG_VEFFECT_COPY:
317 if( mwindow->session->track_highlighted &&
318 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
319 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
320 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
321 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
322 mwindow->session->current_operation = NO_OPERATION;
324 int64_t drop_position = -1;
325 Plugin *drag_plugin = mwindow->session->drag_plugin;
326 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
327 Track *hi_track = mwindow->session->track_highlighted;
329 // Insert shared plugin in source
330 // Move source to different location
331 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
332 //printf("TrackCanvas::drag_stop 6\n");
333 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
334 if( drop_position >= 0 )
335 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
338 else if( hi_track ) {
339 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
340 Edit *hi_edit = mwindow->session->edit_highlighted;
341 drop_position = hi_edit ? hi_edit->startproject : 0;
342 if( drop_position >= 0 )
343 mwindow->move_effect(drag_plugin, hi_track, drop_position);
351 if( mwindow->session->track_highlighted &&
352 ((mwindow->session->current_operation == DRAG_AEFFECT &&
353 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
354 (mwindow->session->current_operation == DRAG_VEFFECT &&
355 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
356 // Drop all the effects
357 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
358 Track *track = mwindow->session->track_highlighted;
360 double length = track->get_length();
362 if(mwindow->session->plugin_highlighted) {
363 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
364 length = track->from_units(mwindow->session->plugin_highlighted->length);
365 if(length <= 0) length = track->get_length();
367 else if(mwindow->session->pluginset_highlighted) {
368 start = track->from_units(plugin_set->length());
369 length = track->get_length() - start;
370 if(length <= 0) length = track->get_length();
372 else if(mwindow->edl->local_session->get_selectionend() >
373 mwindow->edl->local_session->get_selectionstart()) {
374 start = mwindow->edl->local_session->get_selectionstart();
375 length = mwindow->edl->local_session->get_selectionend() -
376 mwindow->edl->local_session->get_selectionstart();
378 // Move to a point between two edits
379 else if(mwindow->session->edit_highlighted) {
380 start = mwindow->session->track_highlighted->from_units(
381 mwindow->session->edit_highlighted->startproject);
382 length = mwindow->session->track_highlighted->from_units(
383 mwindow->session->edit_highlighted->length);
386 mwindow->insert_effects_canvas(start, length);
389 if( mwindow->session->track_highlighted )
390 result = 1; // we have to cleanup
394 if(mwindow->session->track_highlighted) {
395 double asset_duration = 0;
396 int64_t asset_length_units = 0;
397 int64_t position = 0;
399 if(mwindow->session->current_operation == DRAG_ASSET &&
400 mwindow->session->drag_assets->total) {
401 Indexable *indexable = mwindow->session->drag_assets->values[0];
402 // we use video if we are over video and audio if we are over audio
403 if( indexable->have_video() &&
404 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
405 // Images have length -1
406 int64_t video_length = indexable->get_video_frames();
407 if (video_length < 0) {
408 if(mwindow->edl->session->si_useduration)
409 video_length = mwindow->edl->session->si_duration;
411 video_length = 1.0 / mwindow->edl->session->frame_rate ;
413 asset_duration = video_length / indexable->get_frame_rate();
415 else if( indexable->have_audio() &&
416 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
417 int64_t audio_length = indexable->get_audio_samples();
418 asset_duration = (double)audio_length / indexable->get_sample_rate();
422 break; // Do not do anything
425 else if( mwindow->session->current_operation == DRAG_ASSET &&
426 mwindow->session->drag_clips->total ) {
427 EDL *clip = mwindow->session->drag_clips->values[0];
428 asset_duration = clip->tracks->total_length();
431 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
434 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
435 position = drop_edit_position (&insertion, NULL, asset_length_units);
436 if( position == -1 ) {
438 break; // Do not do anything
441 double position_f = mwindow->session->track_highlighted->from_units(position);
442 Track *track = mwindow->session->track_highlighted;
445 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
446 // // Unfortunately, this is _a lot_ of work to do right
447 // printf("Problematic insertion\n");
448 // mwindow->edl->tracks->clear(position_f,
449 // position_f + asset_duration, 0);
451 mwindow->paste_assets(position_f, track, !insertion);
452 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
457 mwindow->session->current_operation = NO_OPERATION;
458 if(mwindow->session->track_highlighted) {
459 if( mwindow->session->track_highlighted->data_type ==
460 mwindow->session->drag_edit->track->data_type) {
461 int64_t position = 0;
462 position = drop_edit_position(&insertion,
463 mwindow->session->drag_edit,
464 mwindow->session->drag_edit->length);
465 if (position == -1) {
467 break; // Do not do anything
470 double position_f = mwindow->session->track_highlighted->from_units(position);
471 Track *track = mwindow->session->track_highlighted;
472 mwindow->move_edits(mwindow->session->drag_edits,
473 track, position_f, !insertion);
485 int TrackCanvas::drag_start_event()
490 int new_cursor, update_cursor;
492 if(mwindow->session->current_operation != NO_OPERATION) return 0;
495 if(do_plugins(get_drag_x(), get_drag_y(),
496 1, 0, redraw, rerender)) {
499 else if(do_edits(get_drag_x(), get_drag_y(),
500 0, 1, redraw, rerender, new_cursor, update_cursor)) {
508 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
510 // get the canvas/track position
511 Track *track = mwindow->session->track_highlighted;
512 int cursor_x = get_relative_cursor_x();
513 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
514 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
515 // we use cursor position for affinity calculations
516 int64_t cursor_position = track->to_units(drop_time, 0);
517 if( cursor_position <= 0 ) {
521 if( moved_edit ) // relative cursor position depends upon drop point
522 drop_time -= mwindow->session->drag_position - moved_edit->track->from_units(moved_edit->startproject);
523 int64_t drop_position = track->to_units(drop_time, 1);
524 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
525 drop_position -= moved_edit_length / 2;
526 Edit *last_edit = track->edits->last;
527 if( !last_edit || drop_position > last_edit->startproject+last_edit->length ) {
529 return drop_position;
532 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
533 for( Edit *edit = track->edits->first; edit; ) {
534 int64_t edit_x0 = edit->startproject, edit_x1 = edit_x0 + edit->length;
535 if( Units::round(labs(edit_x0-cursor_position)*zoom_scale) < HANDLE_W ) {
536 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
537 return edit->startproject;
539 if( Units::round(labs(edit_x1-cursor_position)*zoom_scale) < HANDLE_W ) {
540 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
541 return edit->startproject + edit->length;
543 if( edit != moved_edit && !edit->silence() )
544 drop_x0 = edit_x1; // reset drop zone
545 if( (edit=edit->next) != 0 ) {
546 if( edit == moved_edit || edit->silence() ) continue;
551 //printf("drop cursor=%jd, x0=%jd, x1=%jd\n", cursor_position, drop_x0, drop_x1);
552 if( drop_position >= drop_x0 && drop_position+moved_edit_length < drop_x1 ) {
553 *is_insertion = 0; // fits in the zone
554 //printf("into %jd\n", drop_position);
555 return drop_position;
557 if( cursor_position < drop_x1 ) { // drop in the zone
558 if( (drop_x1-drop_x0) >= moved_edit_length ) {
559 *is_insertion = 0; // fits in the zone, but over the edge
560 int64_t dx0 = llabs(cursor_position-drop_x0);
561 int64_t dx1 = llabs(cursor_position-drop_x1);
562 //printf("onto %jd\n", dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length);
563 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length;
565 int edit_center = (edit_x0+edit_x1) / 2;
566 if( cursor_position < edit_center ) {
568 //printf("snap left %jd\n", drop_x0);
569 return drop_x0; // snap left
573 //printf("snap right %jd\n", drop_x1);
574 return drop_x1; // snap right
583 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
585 // get the canvas/track position
586 Track *track = plugin_set->track;
587 int cursor_x = get_relative_cursor_x();
588 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
589 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
590 // we use cursor position for affinity calculations
591 int64_t cursor_position = track->to_units(drop_time, 0);
592 if( cursor_position <= 0 ) return 0;
593 drop_time -= mwindow->session->drag_position - moved_plugin->track->from_units(moved_plugin->startproject);
594 int64_t drop_position = track->to_units(drop_time, 1);
595 Plugin *last_plugin = (Plugin *)plugin_set->last;
596 if( !last_plugin || drop_position > last_plugin->startproject+last_plugin->length ) {
597 return drop_position;
600 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
601 for( Plugin *plugin = (Plugin *)plugin_set->first; plugin; ) {
602 int64_t plugin_x0 = plugin->startproject, plugin_x1 = plugin_x0 + plugin->length;
603 if( plugin != moved_plugin && !plugin->silence() )
605 if( (plugin=(Plugin *)plugin->next) != 0 ) {
606 if( plugin == moved_plugin || plugin->silence() ) continue;
611 if( drop_position >= drop_x0 && // fits in the zone
612 drop_position+moved_plugin->length < drop_x1 ) {
613 return drop_position;
615 if( cursor_position < drop_x1 ) { // drop in the zone
616 if( (drop_x1-drop_x0) >= moved_plugin->length ) {
617 int64_t dx0 = llabs(cursor_position-drop_x0);
618 int64_t dx1 = llabs(cursor_position-drop_x1);
619 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_plugin->length;
628 void TrackCanvas::draw(int mode, int hide_cursor)
633 // Swap pixmap layers
634 if(get_w() != background_pixmap->get_w() ||
635 get_h() != background_pixmap->get_h())
637 delete background_pixmap;
638 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
641 // Cursor disappears after resize when this is called.
642 // Cursor doesn't redraw after editing when this isn't called.
643 if(pane->cursor && hide_cursor) pane->cursor->hide();
644 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
646 if(debug) PRINT_TRACE
647 draw_resources(mode);
649 if(debug) PRINT_TRACE
651 if(debug) PRINT_TRACE
654 void TrackCanvas::update_cursor(int flush)
656 switch(mwindow->edl->session->editing_mode)
658 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
659 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
664 void TrackCanvas::test_timer()
666 if(resource_timer->get_difference() > 1000 &&
670 hourglass_enabled = 1;
675 void TrackCanvas::draw_indexes(Indexable *indexable)
677 // Don't redraw raw samples
678 IndexState *index_state = 0;
679 index_state = indexable->index_state;
682 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
686 draw_resources(0, 1, indexable);
692 void TrackCanvas::draw_resources(int mode,
694 Indexable *indexable)
698 if(debug) PRINT_TRACE
700 if(!mwindow->edl->session->show_assets) return;
703 // can't stop thread here, because this is called for every pane
704 // if(mode != IGNORE_THREAD && !indexes_only)
705 // gui->resource_thread->stop_draw(!indexes_only);
707 if(mode != IGNORE_THREAD &&
709 !gui->resource_thread->interrupted)
711 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
714 BC_Signals::dump_stack();
717 if(debug) PRINT_TRACE
719 resource_timer->update();
721 // Age resource pixmaps for deletion
723 for(int i = 0; i < gui->resource_pixmaps.total; i++)
724 gui->resource_pixmaps.values[i]->visible--;
726 if(mode == FORCE_REDRAW)
727 gui->resource_pixmaps.remove_all_objects();
729 if(debug) PRINT_TRACE
732 for(Track *current = mwindow->edl->tracks->first;
736 if(debug) PRINT_TRACE
737 for(Edit *edit = current->edits->first; edit; edit = edit->next)
739 if(debug) PRINT_TRACE
740 if( current->data_type != TRACK_SUBTITLE )
741 if(!edit->asset && !edit->nested_edl) continue;
744 if(edit->track->data_type != TRACK_AUDIO) continue;
746 if(edit->nested_edl &&
747 strcmp(indexable->path, edit->nested_edl->path)) continue;
750 strcmp(indexable->path, edit->asset->path)) continue;
753 if(debug) PRINT_TRACE
755 int64_t edit_x, edit_y, edit_w, edit_h;
756 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
759 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
760 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
762 int64_t pixmap_x, pixmap_w, pixmap_h;
763 if(debug) PRINT_TRACE
765 // Search for existing pixmap containing edit
766 for(int i = 0; i < gui->resource_pixmaps.total; i++)
768 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
769 // Same pointer can be different edit if editing took place
770 if(pixmap->edit_id == edit->id &&
771 pixmap->pane_number == pane->number)
777 if(debug) PRINT_TRACE
779 // Get new size, offset of pixmap needed
780 get_pixmap_size(edit,
786 if(debug) PRINT_TRACE
789 if(pixmap_w && pixmap_h)
791 // Create pixmap if it doesn't exist
792 ResourcePixmap* pixmap = create_pixmap(edit,
797 // Resize it if it's bigger
798 if(pixmap_w > pixmap->pixmap_w ||
799 pixmap_h > pixmap->pixmap_h)
800 pixmap->resize(pixmap_w, pixmap_h);
801 pixmap->draw_data(this,
810 // Resize it if it's smaller
811 if(pixmap_w < pixmap->pixmap_w ||
812 pixmap_h < pixmap->pixmap_h)
813 pixmap->resize(pixmap_w, pixmap_h);
815 // Copy pixmap to background canvas
816 background_pixmap->draw_pixmap(pixmap,
818 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
822 if(debug) PRINT_TRACE
829 // Delete unused pixmaps
830 if(debug) PRINT_TRACE
832 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
833 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
835 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
836 delete gui->resource_pixmaps.values[i];
837 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
839 if(debug) PRINT_TRACE
841 if(hourglass_enabled)
844 hourglass_enabled = 0;
846 if(debug) PRINT_TRACE
848 // can't stop thread here, because this is called for every pane
849 // if(mode != IGNORE_THREAD && !indexes_only)
850 // gui->resource_thread->start_draw();
851 if(debug) PRINT_TRACE
856 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
862 ResourcePixmap *result = 0;
864 for(int i = 0; i < gui->resource_pixmaps.total; i++)
866 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
867 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
868 gui->resource_pixmaps.values[i]->pane_number == pane->number)
870 result = gui->resource_pixmaps.values[i];
878 result = new ResourcePixmap(mwindow,
885 gui->resource_pixmaps.append(result);
888 // result->resize(pixmap_w, pixmap_h);
892 void TrackCanvas::get_pixmap_size(Edit *edit,
900 // Align x on frame boundaries
903 // switch(edit->edits->track->data_type)
915 if(pixmap_x + pixmap_w > get_w())
917 pixmap_w = get_w() - pixmap_x;
924 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
925 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
926 // int64_t pixel_increment = MAX(picon_w, frame_w);
927 // int64_t pixmap_x1 = edit_x;
928 // int64_t pixmap_x2 = edit_x + edit_w;
932 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
937 // if(pixmap_x2 > get_w())
939 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
943 // pixmap_x = pixmap_x1;
944 // pixmap_w = pixmap_x2 - pixmap_x1;
949 pixmap_h = mwindow->edl->local_session->zoom_track;
950 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
951 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
954 void TrackCanvas::edit_dimensions(Edit *edit,
960 // w = Units::round(edit->track->from_units(edit->length) *
961 // mwindow->edl->session->sample_rate /
962 // mwindow->edl->local_session->zoom_sample);
966 x = Units::round(edit->track->from_units(edit->startproject) *
967 mwindow->edl->session->sample_rate /
968 mwindow->edl->local_session->zoom_sample -
969 mwindow->edl->local_session->view_start[pane->number]);
971 // Method for calculating w so when edits are together we never get off by one error due to rounding
972 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
973 mwindow->edl->session->sample_rate /
974 mwindow->edl->local_session->zoom_sample -
975 mwindow->edl->local_session->view_start[pane->number]);
978 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
980 if(mwindow->edl->session->show_titles)
981 h += mwindow->theme->get_image("title_bg_data")->get_h();
984 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
988 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
989 h = track->vertical_span(mwindow->theme);
993 void TrackCanvas::draw_paste_destination()
995 //int cursor_x = get_relative_cursor_x();
996 //int cursor_y = get_relative_cursor_y();
997 int current_atrack = 0;
998 int current_vtrack = 0;
999 int current_aedit = 0;
1000 int current_vedit = 0;
1006 //if(pane->number == BOTTOM_RIGHT_PANE)
1007 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1009 if((mwindow->session->current_operation == DRAG_ASSET &&
1010 (mwindow->session->drag_assets->total ||
1011 mwindow->session->drag_clips->total)) ||
1012 (mwindow->session->current_operation == DRAG_EDIT &&
1013 mwindow->session->drag_edits->total)) {
1014 Indexable *indexable = 0;
1018 if(mwindow->session->current_operation == DRAG_ASSET &&
1019 mwindow->session->drag_assets->size())
1020 indexable = mwindow->session->drag_assets->get(0);
1022 if(mwindow->session->current_operation == DRAG_ASSET &&
1023 mwindow->session->drag_clips->size())
1024 clip = mwindow->session->drag_clips->get(0);
1026 int has_audio = 0, has_video = 0;
1027 double paste_audio_length = 0, paste_video_length = 0;
1028 double paste_audio_position = -1, paste_video_position = -1;
1031 has_audio = indexable->have_audio();
1032 paste_audio_length = !has_audio ? 0 :
1033 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1034 has_video = indexable->have_video();
1035 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1036 // Images have length -1
1037 if( asset && asset->video_data && asset->video_length < 0 ) {
1038 paste_video_length = mwindow->edl->session->si_useduration ?
1039 mwindow->edl->session->si_duration / asset->frame_rate :
1040 1.0 / asset->frame_rate ; // 1 frame
1043 paste_video_length = !has_video ? 0 :
1044 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1048 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1049 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1050 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1051 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1054 // 'Align cursor on frame' lengths calculations
1055 if( mwindow->edl->session->cursor_on_frames ) {
1056 double fps = mwindow->edl->session->frame_rate;
1057 double aud = floor(paste_audio_length * fps) / fps;
1058 double vid = floor(paste_video_length * fps) / fps;
1059 double length = has_video && has_audio ?
1060 aud < vid ? aud : vid :
1062 has_audio ? aud : 0;
1063 paste_video_length = paste_audio_length = length;
1066 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1068 switch( mwindow->session->track_highlighted->data_type ) {
1069 case TRACK_VIDEO: length = paste_video_length; break;
1070 case TRACK_AUDIO: length = paste_audio_length; break;
1072 int64_t asset_length = mwindow->session->track_highlighted->
1073 to_units(length, 1);
1074 paste_audio_position = mwindow->session->track_highlighted->
1075 from_units(drop_edit_position(&insertion, NULL, asset_length));
1078 int64_t asset_length = mwindow->session->track_highlighted->
1079 to_units(paste_video_length, 1);
1080 paste_video_position = mwindow->session->track_highlighted->
1081 from_units(drop_edit_position(&insertion, NULL, asset_length));
1084 // Get destination track
1085 for(Track *dest = mwindow->session->track_highlighted;
1087 dest = dest->next) {
1089 // Get source width in pixels
1091 // Use start of highlighted edit
1092 if(mwindow->session->edit_highlighted) {
1093 position = mwindow->session->track_highlighted->from_units(
1094 mwindow->session->edit_highlighted->startproject);
1097 // Use end of highlighted track, disregarding effects
1098 position = mwindow->session->track_highlighted->from_units(
1099 mwindow->session->track_highlighted->edits->length());
1102 // Get the x coordinate
1103 x = Units::to_int64(position *
1104 mwindow->edl->session->sample_rate /
1105 mwindow->edl->local_session->zoom_sample) -
1106 mwindow->edl->local_session->view_start[pane->number];
1108 double paste_position = -1.;
1109 if(dest->data_type == TRACK_AUDIO) {
1110 if(indexable && current_atrack < indexable->get_audio_channels()) {
1111 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1112 w = Units::to_int64((double)indexable->get_audio_samples() /
1113 indexable->get_sample_rate() *
1114 mwindow->edl->session->sample_rate /
1115 mwindow->edl->local_session->zoom_sample);
1116 paste_position = paste_audio_position;
1118 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1119 w = Units::to_int64((double)clip->tracks->total_length() *
1120 mwindow->edl->session->sample_rate /
1121 mwindow->edl->local_session->zoom_sample);
1122 paste_position = paste_audio_position;
1123 //printf("draw_paste_destination %d\n", x);
1125 else if(mwindow->session->current_operation == DRAG_EDIT &&
1126 current_aedit < mwindow->session->drag_edits->total) {
1128 while(current_aedit < mwindow->session->drag_edits->total &&
1129 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1132 if(current_aedit < mwindow->session->drag_edits->total) {
1133 edit = mwindow->session->drag_edits->values[current_aedit];
1134 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1135 paste_position = mwindow->session->track_highlighted->
1136 from_units(drop_edit_position(&insertion,
1137 mwindow->session->drag_edit,
1138 mwindow->session->drag_edit->length));
1141 if( paste_position >= 0 ) {
1142 position = paste_position;
1149 else if(dest->data_type == TRACK_VIDEO) {
1150 //printf("draw_paste_destination 1\n");
1151 if(indexable && current_vtrack < indexable->get_video_layers())
1153 w = Units::to_int64((double)indexable->get_video_frames() /
1154 indexable->get_frame_rate() *
1155 mwindow->edl->session->sample_rate /
1156 mwindow->edl->local_session->zoom_sample);
1157 paste_position = paste_video_position;
1159 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1160 w = Units::to_int64(clip->tracks->total_length() *
1161 mwindow->edl->session->sample_rate /
1162 mwindow->edl->local_session->zoom_sample);
1163 paste_position = paste_video_position;
1165 else if(mwindow->session->current_operation == DRAG_EDIT &&
1166 current_vedit < mwindow->session->drag_edits->total) {
1168 while(current_vedit < mwindow->session->drag_edits->total &&
1169 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1172 if(current_vedit < mwindow->session->drag_edits->total) {
1173 edit = mwindow->session->drag_edits->values[current_vedit];
1174 w = Units::to_int64(edit->track->from_units(edit->length) *
1175 mwindow->edl->session->sample_rate /
1176 mwindow->edl->local_session->zoom_sample);
1177 paste_position = mwindow->session->track_highlighted->
1178 from_units(drop_edit_position(&insertion,
1179 mwindow->session->drag_edit,
1180 mwindow->session->drag_edit->length));
1183 if( paste_position >= 0 ) {
1184 position = paste_position;
1193 // Get the x coordinate
1194 x = Units::to_int64(position *
1195 mwindow->edl->session->sample_rate /
1196 mwindow->edl->local_session->zoom_sample) -
1197 mwindow->edl->local_session->view_start[pane->number];
1198 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1199 int h = dest->vertical_span(mwindow->theme);
1201 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1203 draw_highlight_insertion(x, y, w, h);
1205 draw_highlight_rectangle(x, y, w, h);
1206 if(x < -BC_INFINITY) {
1207 w -= -BC_INFINITY - x;
1208 x += -BC_INFINITY - x;
1211 // if(pane->number == TOP_RIGHT_PANE)
1212 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1213 // __LINE__, x, y, w, h);
1214 draw_highlight_rectangle(x, y, w, h);
1221 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1223 x = Units::round(plugin->track->from_units(plugin->startproject) *
1224 mwindow->edl->session->sample_rate /
1225 mwindow->edl->local_session->zoom_sample -
1226 mwindow->edl->local_session->view_start[pane->number]);
1227 w = Units::round(plugin->track->from_units(plugin->length) *
1228 mwindow->edl->session->sample_rate /
1229 mwindow->edl->local_session->zoom_sample);
1230 y = plugin->track->y_pixel -
1231 mwindow->edl->local_session->track_start[pane->number] +
1232 mwindow->edl->local_session->zoom_track +
1233 plugin->plugin_set->get_number() *
1234 mwindow->theme->get_image("plugin_bg_data")->get_h();
1235 if(mwindow->edl->session->show_titles)
1236 y += mwindow->theme->get_image("title_bg_data")->get_h();
1237 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1240 int TrackCanvas::resource_h()
1242 return mwindow->edl->local_session->zoom_track;
1245 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1248 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1249 // just draw arrows, so user has indication that something is there
1250 // FIXME: get better colors
1254 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1259 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1263 // Fix bug in heroines & cvs version as of 22.8.2005:
1264 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1265 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1278 w = MIN(w, get_w() + 20);
1279 h = MIN(h, get_h() + 20);
1282 set_color(mwindow->preferences->highlight_inverse);
1284 //draw_rectangle(x, y, w, h);
1285 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1286 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1288 draw_rectangle(x, y, w, h);
1290 //if(pane->number == TOP_RIGHT_PANE)
1291 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1294 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1297 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1298 // just draw arrows, so user has indication that something is there
1299 // FIXME: get better colors
1308 /* these don't look so good
1310 draw_line(x, y, x, y+h);
1311 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1312 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1313 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1314 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1316 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1317 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1319 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1320 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1321 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1322 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1324 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1325 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1327 // draw the box centred around x
1329 // Fix bug in heroines & cvs version as of 22.8.2005:
1330 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1331 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1342 w = MIN(w, get_w() + 20);
1343 h = MIN(h, get_h() + 20);
1344 set_color(mwindow->preferences->highlight_inverse);
1346 draw_rectangle(x, y, w, h);
1347 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1349 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1352 void TrackCanvas::draw_playback_cursor()
1354 // Called before playback_cursor exists
1355 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1357 // mwindow->playback_cursor->visible = 0;
1358 // mwindow->playback_cursor->draw();
1362 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1364 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1365 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1367 edit_dimensions(edit, x, y, w, h);
1369 if(mwindow->edl->session->show_titles)
1371 y += mwindow->theme->get_image("title_bg_data")->get_h();
1378 if(side == EDIT_OUT)
1387 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1389 //printf("TrackCanvas::get_transition_coords 1\n");
1390 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1391 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1392 int transition_w = 30;
1393 int transition_h = 30;
1394 //printf("TrackCanvas::get_transition_coords 1\n");
1396 if(mwindow->edl->session->show_titles)
1397 y += mwindow->theme->get_image("title_bg_data")->get_h();
1398 //printf("TrackCanvas::get_transition_coords 2\n");
1400 y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
1401 x -= transition_w / 2;
1407 void TrackCanvas::draw_highlighting()
1412 switch(mwindow->session->current_operation)
1414 case DRAG_ATRANSITION:
1415 case DRAG_VTRANSITION:
1416 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1417 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1418 if(mwindow->session->edit_highlighted) {
1419 //printf("TrackCanvas::draw_highlighting 2\n");
1420 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1421 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1422 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1423 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1424 //printf("TrackCanvas::draw_highlighting 2\n");
1425 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1426 //printf("TrackCanvas::draw_highlighting 2\n");
1428 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1429 MWindowGUI::visible(y, y + h, 0, get_h())) {
1431 get_transition_coords(x, y, w, h);
1433 //printf("TrackCanvas::draw_highlighting 3\n");
1438 // Dragging a new effect from the Resource window
1441 if(mwindow->session->track_highlighted &&
1442 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1443 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1444 (mwindow->session->current_operation == DRAG_VEFFECT &&
1445 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1446 // Put it before another plugin
1447 if(mwindow->session->plugin_highlighted) {
1448 plugin_dimensions(mwindow->session->plugin_highlighted,
1450 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1452 // Put it after a plugin set
1453 else if( mwindow->session->pluginset_highlighted &&
1454 mwindow->session->pluginset_highlighted->last ) {
1455 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1457 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1458 int64_t track_x, track_y, track_w, track_h;
1459 track_dimensions(mwindow->session->track_highlighted,
1460 track_x, track_y, track_w, track_h);
1464 mwindow->session->track_highlighted->get_length() *
1465 mwindow->edl->session->sample_rate /
1466 mwindow->edl->local_session->zoom_sample -
1467 mwindow->edl->local_session->view_start[pane->number]) -
1469 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1470 if(w <= 0) w = track_w;
1473 track_dimensions(mwindow->session->track_highlighted,
1476 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1477 // Put it in a new plugin set determined by the selected range
1478 if(mwindow->edl->local_session->get_selectionend() >
1479 mwindow->edl->local_session->get_selectionstart()) {
1480 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1481 mwindow->edl->session->sample_rate /
1482 mwindow->edl->local_session->zoom_sample -
1483 mwindow->edl->local_session->view_start[pane->number]);
1484 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1485 mwindow->edl->local_session->get_selectionstart()) *
1486 mwindow->edl->session->sample_rate /
1487 mwindow->edl->local_session->zoom_sample);
1489 // Put it in a new plugin set determined by an edit boundary
1490 else if(mwindow->session->edit_highlighted) {
1491 int64_t temp_y, temp_h;
1492 edit_dimensions(mwindow->session->edit_highlighted,
1493 x, temp_y, w, temp_h);
1495 // Put it at the beginning of the track in a new plugin set
1498 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1499 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1500 //printf("TrackCanvas::draw_highlighting 1\n");
1507 if(mwindow->session->track_highlighted) {
1508 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1510 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1512 draw_paste_destination();
1518 if(mwindow->session->track_highlighted) {
1519 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1521 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1522 draw_paste_destination();
1527 // Dragging an effect from the timeline
1528 case DRAG_AEFFECT_COPY:
1529 case DRAG_VEFFECT_COPY:
1530 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1531 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1532 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1533 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1534 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1536 int64_t plugin_position = -1;
1537 Plugin *drag_plugin = mwindow->session->drag_plugin;
1538 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1539 Track *hi_track = mwindow->session->track_highlighted;
1540 Edit *hi_edit = mwindow->session->edit_highlighted;
1541 // Put it into a silence zone
1542 if( hi_plugin_set && hi_plugin_set->last &&
1543 hi_plugin_set->track == drag_plugin->track ) {
1544 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1545 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1546 hi_track = drag_plugin->track;
1548 else if( hi_track ) {
1549 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1550 track_dimensions(hi_track, x, y, w, h);
1551 plugin_position = hi_edit ? hi_edit->startproject : 0;
1554 if( plugin_position < 0 ) break;
1556 // Calculate length of plugin based on data type of track and units
1557 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1558 mwindow->edl->local_session->zoom_sample;
1559 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1560 mwindow->edl->local_session->view_start[pane->number];
1561 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1563 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1564 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1570 case DRAG_PLUGINKEY:
1571 if(mwindow->session->plugin_highlighted &&
1572 mwindow->session->current_operation == DRAG_PLUGINKEY)
1574 // Just highlight the plugin
1575 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1577 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1578 MWindowGUI::visible(y, y + h, 0, get_h()))
1590 draw_highlight_rectangle(x, y, w, h);
1594 void TrackCanvas::draw_plugins()
1596 char string[BCTEXTLEN];
1598 int current_show = 0;
1599 int current_preset = 0;
1601 // if(!mwindow->edl->session->show_assets) goto done;
1603 for(int i = 0; i < plugin_on_toggles.total; i++)
1604 plugin_on_toggles.values[i]->in_use = 0;
1605 for(int i = 0; i < plugin_show_toggles.total; i++)
1606 plugin_show_toggles.values[i]->in_use = 0;
1607 for(int i = 0; i < preset_edit_buttons.total; i++)
1608 plugin_show_toggles.values[i]->in_use = 0;
1611 for(Track *track = mwindow->edl->tracks->first;
1613 track = track->next)
1615 if(track->expand_view)
1617 for(int i = 0; i < track->plugin_set.total; i++)
1619 PluginSet *pluginset = track->plugin_set.values[i];
1621 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1623 int64_t total_x, y, total_w, h;
1624 plugin_dimensions(plugin, total_x, y, total_w, h);
1626 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1627 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1628 plugin->plugin_type != PLUGIN_NONE)
1630 int x = total_x, w = total_w, left_margin = 5;
1631 int right_margin = 5;
1637 if(w + x > get_w()) w -= (w + x) - get_w();
1644 mwindow->theme->get_image("plugin_bg_data"),
1646 set_color(mwindow->theme->title_color);
1647 set_font(mwindow->theme->title_font);
1648 plugin->calculate_title(string, 0);
1650 // Truncate string to int64_test visible in background
1651 int len = strlen(string), j;
1652 for(j = len; j >= 0; j--)
1654 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1662 // Justify the text on the left boundary of the edit if it is visible.
1663 // Otherwise justify it on the left side of the screen.
1664 int64_t text_x = total_x + left_margin;
1665 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1666 text_x = MAX(left_margin, text_x);
1668 y + get_text_ascent(mwindow->theme->title_font) + 2,
1672 int64_t min_x = total_x + text_w;
1675 // Update plugin toggles
1676 int toggle_x = total_x + total_w;
1678 toggle_x = MIN(get_w() - right_margin, toggle_x);
1681 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1682 if(toggle_x > min_x)
1684 if(current_on >= plugin_on_toggles.total)
1686 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1687 add_subwindow(plugin_on);
1688 plugin_on_toggles.append(plugin_on);
1692 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1697 // Toggles for standalone plugins only
1698 if(plugin->plugin_type == PLUGIN_STANDALONE)
1701 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1702 if(toggle_x > min_x)
1704 if(current_show >= plugin_show_toggles.total)
1706 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1707 add_subwindow(plugin_show);
1708 plugin_show_toggles.append(plugin_show);
1712 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1716 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1717 if(toggle_x > min_x)
1719 if(current_preset >= preset_edit_buttons.total)
1721 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1722 add_subwindow(preset_edit);
1723 preset_edit_buttons.append(preset_edit);
1727 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1738 // Remove unused toggles
1740 while(current_preset < preset_edit_buttons.total)
1742 preset_edit_buttons.remove_object_number(current_preset);
1744 while(current_show < plugin_show_toggles.total)
1746 plugin_show_toggles.remove_object_number(current_show);
1749 while(current_on < plugin_on_toggles.total)
1751 plugin_on_toggles.remove_object_number(current_on);
1755 void TrackCanvas::refresh_plugintoggles()
1757 for(int i = 0; i < plugin_on_toggles.total; i++)
1759 PluginOn *on = plugin_on_toggles.values[i];
1760 on->reposition_window(on->get_x(), on->get_y());
1762 for(int i = 0; i < plugin_show_toggles.total; i++)
1764 PluginShow *show = plugin_show_toggles.values[i];
1765 show->reposition_window(show->get_x(), show->get_y());
1767 for(int i = 0; i < preset_edit_buttons.total; i++)
1769 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1770 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1774 void TrackCanvas::draw_hard_edges()
1778 // if(!mwindow->edl->session->show_assets) return;
1780 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1781 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1782 if( !edit->hard_left && !edit->hard_right ) continue;
1783 edit_dimensions(edit, x, y, w, h);
1785 set_opaque(); int y1 = y+h-1;
1786 if( edit->hard_left ) {
1787 ArrayList<int> xpt, ypt;
1788 xpt.append(x); ypt.append(y1);
1789 xpt.append(x+HANDLE_W); ypt.append(y1);
1790 xpt.append(x); ypt.append(y1-HANDLE_H);
1791 fill_polygon(&xpt, &ypt);
1793 if( edit->hard_right ) {
1794 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1795 xpt.append(x1); ypt.append(y1);
1796 xpt.append(x1-HANDLE_W); ypt.append(y1);
1797 xpt.append(x1); ypt.append(y1-HANDLE_H);
1798 fill_polygon(&xpt, &ypt);
1804 void TrackCanvas::draw_inout_points()
1809 void TrackCanvas::draw_drag_handle()
1811 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1812 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1814 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1815 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1816 mwindow->edl->session->sample_rate /
1817 mwindow->edl->local_session->zoom_sample -
1818 mwindow->edl->local_session->view_start[pane->number]);
1819 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1820 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1822 //printf("TrackCanvas::draw_drag_handle 3\n");
1823 draw_line(pixel1, 0, pixel1, get_h());
1825 //printf("TrackCanvas::draw_drag_handle 4\n");
1830 void TrackCanvas::draw_transitions()
1834 // if(!mwindow->edl->session->show_assets) return;
1836 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1837 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1838 if(!edit->transition) continue;
1839 edit_dimensions(edit, x, y, w, h);
1840 int strip_x = x, strip_y = y;
1841 if(mwindow->edl->session->show_titles)
1842 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1843 get_transition_coords(x, y, w, h);
1844 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1845 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1846 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1847 MWindowGUI::visible(y, y + h, 0, get_h()) )
1849 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1851 if( !server ) continue;
1852 VFrame *picon = server->get_picon();
1853 if( !picon ) continue;
1854 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1856 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1857 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1859 int x = strip_x, w = strip_w;
1865 if(w + x > get_w()) w -= (w + x) - get_w();
1867 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1868 mwindow->theme->get_image("plugin_bg_data"), 0);
1874 void TrackCanvas::draw_loop_points()
1876 //printf("TrackCanvas::draw_loop_points 1\n");
1877 if(mwindow->edl->local_session->loop_playback)
1879 //printf("TrackCanvas::draw_loop_points 2\n");
1880 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1881 mwindow->edl->session->sample_rate /
1882 mwindow->edl->local_session->zoom_sample -
1883 mwindow->edl->local_session->view_start[pane->number]);
1884 //printf("TrackCanvas::draw_loop_points 3\n");
1886 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1889 draw_line(x, 0, x, get_h());
1891 //printf("TrackCanvas::draw_loop_points 4\n");
1893 x = Units::round(mwindow->edl->local_session->loop_end *
1894 mwindow->edl->session->sample_rate /
1895 mwindow->edl->local_session->zoom_sample -
1896 mwindow->edl->local_session->view_start[pane->number]);
1897 //printf("TrackCanvas::draw_loop_points 5\n");
1899 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1902 draw_line(x, 0, x, get_h());
1904 //printf("TrackCanvas::draw_loop_points 6\n");
1906 //printf("TrackCanvas::draw_loop_points 7\n");
1909 void TrackCanvas::draw_brender_range()
1911 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1912 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1913 if( mwindow->edl->session->brender_end > 0 )
1915 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1916 mwindow->edl->session->sample_rate /
1917 mwindow->edl->local_session->zoom_sample -
1918 mwindow->edl->local_session->view_start[pane->number]);
1919 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1922 draw_line(x1, 0, x1, get_h());
1924 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1925 mwindow->edl->session->sample_rate /
1926 mwindow->edl->local_session->zoom_sample -
1927 mwindow->edl->local_session->view_start[pane->number]);
1929 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1932 draw_line(x2, 0, x2, get_h());
1937 // The operations which correspond to each automation type
1938 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1954 // The buttonpress operations, so nothing changes unless the mouse moves
1955 // a certain amount. This allows the keyframe to be used to position the
1956 // insertion point without moving itself.
1957 static int pre_auto_operations[AUTOMATION_TOTAL] =
1974 int TrackCanvas::do_keyframes(int cursor_x,
1982 // Note: button 3 (right mouse button) is not eaten to allow
1983 // track context menu to appear
1985 EDLSession *session = mwindow->edl->session;
1989 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1991 0, 0, 0, 0, 0, 0, 0, 0,
1993 modekeyframe_pixmap,
1994 maskkeyframe_pixmap,
1999 for(Track *track = mwindow->edl->tracks->first;
2001 track = track->next) {
2002 Auto *auto_keyframe = 0;
2003 Automation *automation = track->automation;
2006 // Handle keyframes in reverse drawing order if a button press
2008 int end = AUTOMATION_TOTAL;
2012 start = AUTOMATION_TOTAL - 1;
2016 for(int i = start; i != end && !result; i += step)
2018 // Event not trapped and automation visible
2019 Autos *autos = automation->autos[i];
2020 if(!result && session->auto_conf->autos[i] && autos) {
2022 case AUTOMATION_MODE:
2023 case AUTOMATION_PAN:
2024 case AUTOMATION_MASK:
2025 result = do_autos(track, automation->autos[i],
2026 cursor_x, cursor_y, draw,
2027 buttonpress, auto_pixmaps[i],
2028 auto_keyframe, rerender);
2032 switch(autos->get_type()) {
2033 case Autos::AUTOMATION_TYPE_FLOAT: {
2034 Automation automation(0, track);
2035 int grouptype = automation.autogrouptype(i, track);
2036 if(draw) // Do dropshadow
2037 result = do_float_autos(track, autos,
2038 cursor_x, cursor_y, draw,
2039 buttonpress, 1, 1, MDGREY,
2040 auto_keyframe, grouptype);
2042 result = do_float_autos(track, autos,
2043 cursor_x, cursor_y, draw, buttonpress,
2044 0, 0, GWindowGUI::auto_colors[i],
2045 auto_keyframe, grouptype);
2048 case Autos::AUTOMATION_TYPE_INT: {
2049 if(draw) // Do dropshadow
2050 result = do_int_autos(track, autos,
2051 cursor_x, cursor_y, draw,
2052 buttonpress, 1, 1, MDGREY,
2054 result = do_int_autos(track, autos,
2055 cursor_x, cursor_y, draw, buttonpress,
2056 0, 0, GWindowGUI::auto_colors[i],
2065 if(mwindow->session->current_operation == auto_operations[i])
2068 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2070 // mwindow->session->current_operation,
2071 // auto_operations[i]);
2074 if (buttonpress != 3)
2076 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2077 synchronize_autos(0,
2079 (FloatAuto*)mwindow->session->drag_auto,
2081 mwindow->session->current_operation = pre_auto_operations[i];
2082 update_drag_caption();
2085 else if( auto_keyframe )
2087 gui->keyframe_menu->update(automation,
2090 gui->keyframe_menu->activate_menu();
2091 rerender = 1; // the position changes
2095 gui->keyframe_hide->update(autos);
2096 gui->keyframe_hide->activate_menu();
2097 rerender = 1; // the position changes
2099 if(buttonpress == 1 && ctrl_down() &&
2100 AUTOMATION_TYPE_FLOAT == autos->get_type())
2101 rerender = 1; // special case: curve mode changed
2108 session->auto_conf->plugins /* &&
2109 mwindow->edl->session->show_assets */) {
2112 result = do_plugin_autos(track, cursor_x, cursor_y,
2113 draw, buttonpress, plugin, keyframe);
2114 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2117 if(result && (buttonpress == 1)) {
2118 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2119 update_drag_caption();
2122 else if (result && (buttonpress == 3)) {
2123 gui->keyframe_menu->update(plugin, keyframe);
2124 gui->keyframe_menu->activate_menu();
2125 rerender = 1; // the position changes
2130 // Final pass to trap event
2131 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2132 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2133 mwindow->session->current_operation == auto_operations[i]) {
2139 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2140 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2146 new_cursor = UPRIGHT_ARROW_CURSOR;
2153 void TrackCanvas::draw_keyframe_reticle()
2155 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2156 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2158 int current_op = mwindow->session->current_operation, dragging = 0;
2159 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2160 if( current_op == auto_operations[i] ) dragging = 1;
2162 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2163 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2164 draw_hairline(mwindow->session->drag_auto, RED);
2169 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2170 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2171 for( Track *track = mwindow->edl->tracks->first; track;
2172 track=track->next ) {
2173 Automation *automation = track->automation;
2174 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2175 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2176 // automation visible
2177 Autos *autos = automation->autos[i];
2178 if( !autos ) continue;
2179 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2180 auto_keyframe = auto_keyframe->next ) {
2181 draw_hairline(auto_keyframe, GREEN);
2185 if( dragging && mwindow->session->drag_auto ) {
2186 draw_hairline(mwindow->session->drag_auto, RED);
2192 void TrackCanvas::draw_auto(Auto *current,
2200 x1 = x - HANDLE_W / 2;
2201 x2 = x + HANDLE_W / 2;
2202 y1 = center_pixel + y - HANDLE_W / 2;
2203 y2 = center_pixel + y + HANDLE_W / 2;
2205 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2206 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2208 draw_box(x1, y1, x2 - x1, y2 - y1);
2212 // This draws lines for bezier in & out controls
2213 void TrackCanvas::draw_cropped_line(int x1,
2222 // Don't care about x since it is clipped by the window.
2223 // Put y coords in ascending order
2225 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2226 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2231 double slope = (double)(x2 - x1) / (y2 - y1);
2232 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2234 x1 = (int)(x1 + (min_y - y1) * slope);
2237 else if(y1 >= max_y) {
2238 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2243 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2246 else if(y2 < min_y) {
2247 x2 = (int)(x2 + (min_y - y2) * slope);
2252 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2253 if( y1 >= min_y && y1 < max_y &&
2254 y2 >= min_y && y2 < max_y )
2255 draw_line(x1, y1, x2, y2);
2259 void TrackCanvas::draw_floatauto(FloatAuto *current,
2270 int x1 = x - HANDLE_W / 2; // Center
2271 int x2 = x + HANDLE_W / 2;
2272 int y1 = center_pixel + y - HANDLE_H / 2;
2273 int y2 = center_pixel + y + HANDLE_H / 2;
2274 int ymin = center_pixel - zoom_track / 2;
2275 int ymax = center_pixel + zoom_track / 2;
2276 CLAMP(y1, ymin, ymax);
2277 CLAMP(y2, ymin, ymax);
2282 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2284 draw_box(x1, y1, x2 - x1, y2 - y1);
2287 // show bezier control points (only) if this
2288 // floatauto doesn't adjust it's tangents automatically
2289 if(current->curve_mode != FloatAuto::FREE &&
2290 current->curve_mode != FloatAuto::TFREE)
2294 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2296 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2299 inline int quantize(float f) { return (int)floor(f + 0.5); }
2301 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2302 int x, int y, int cp_x, int cp_y, int center_pixel,
2303 int zoom_track, int color)
2304 // draw the tangent and a handle for given bézier ctrl point
2306 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2308 float slope = (float)(cp_y - y)/(cp_x - x);
2309 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2311 cp_x = x + quantize((cp_y - y) / slope);
2314 cp_y += center_pixel;
2316 // drawing the tangent as a dashed line...
2317 int const dash = HANDLE_W;
2318 int const gap = HANDLE_W / 2;
2319 float sx = 3 * (cp_x - x) / 4.;
2322 // q is the x displacement for a unit line of slope
2323 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2325 float dist = 1/q * sx;
2331 float sy = slope * sx, ey = slope * ex;
2332 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2339 int r = HANDLE_W / 2;
2340 int cp_x1 = cp_x - r;
2341 int cp_y1 = cp_y - r;
2343 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2345 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2350 int TrackCanvas::test_auto(Auto *current,
2351 int x, int y, int center_pixel, int zoom_track,
2352 int cursor_x, int cursor_y, int buttonpress)
2357 x1 = x - HANDLE_W / 2;
2358 x2 = x + HANDLE_W / 2;
2359 y1 = center_pixel + y - HANDLE_H / 2;
2360 y2 = center_pixel + y + HANDLE_H / 2;
2361 int ymin = center_pixel - zoom_track / 2;
2362 int ymax = center_pixel + zoom_track / 2;
2363 CLAMP(y1, ymin, ymax);
2364 CLAMP(y2, ymin, ymax);
2366 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2368 if(buttonpress && buttonpress != 3)
2370 mwindow->session->drag_auto = current;
2371 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2372 // Toggle Autos don't respond to vertical zoom, they always show up
2373 // with "on" == 100% == line on top
2374 mwindow->session->drag_start_position = current->position;
2375 mwindow->session->drag_origin_x = cursor_x;
2376 mwindow->session->drag_origin_y = cursor_y;
2381 if(buttonpress && buttonpress != 3 && result)
2383 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2384 mwindow->undo->update_undo_before();
2390 // some Helpers for test_floatauto(..)
2391 // and for dragging the tangents/ctrl points
2392 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2393 float cursor_x, float cursor_y)
2395 // Control point switched off?
2396 if( x0 == ctrl_x ) return 0.0;
2397 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2398 double x = cursor_x-x0, y = cursor_y-y0;
2399 // wrong side of ctrl handle
2400 if( x*x1 < 0 ) return 0.0;
2401 // outside handle radius
2402 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2403 double xx1 = x1*x1, yy1 = y1*y1;
2404 double xx = x*x, yy = y*y;
2405 // distance squared from cursor to cursor projected to line from ctrl to handle
2406 // along a line perpendicular to line from ctrl to handle (closest approach)
2407 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2408 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2409 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2414 float levered_position(float position, float ref_pos)
2416 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2418 return ref_pos / position;
2422 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2423 // transforms automation value into current display coords,
2424 // dependant on current automation display range for the given kind of automation
2426 if(!mwindow || !mwindow->edl) return 0;
2427 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2428 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2429 float automation_range = automation_max - automation_min;
2430 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2432 return (auto_value - automation_min) / automation_range;
2437 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2438 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2439 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2443 int x1 = x - HANDLE_W / 2;
2444 int x2 = x + HANDLE_W / 2;
2445 int y1 = center_pixel + y - HANDLE_W / 2;
2446 int y2 = center_pixel + y + HANDLE_W / 2;
2447 int ymin = center_pixel - zoom_track / 2;
2448 int ymax = center_pixel + zoom_track / 2;
2449 CLAMP(y1, ymin, ymax);
2450 CLAMP(y2, ymin, ymax);
2452 int in_x1 = in_x - HANDLE_W / 2;
2453 int in_x2 = in_x + HANDLE_W / 2;
2454 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2455 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2456 CLAMP(in_y1, ymin, ymax);
2457 CLAMP(in_y2, ymin, ymax);
2459 int out_x1 = out_x - HANDLE_W / 2;
2460 int out_x2 = out_x + HANDLE_W / 2;
2461 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2462 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2463 CLAMP(out_y1, ymin, ymax);
2464 CLAMP(out_y2, ymin, ymax);
2467 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2468 // buttonpress could be the start of a drag operation
2469 #define INIT_DRAG(POS,VAL) \
2470 mwindow->session->drag_auto = current; \
2471 mwindow->session->drag_origin_x = cursor_x; \
2472 mwindow->session->drag_origin_y = cursor_y; \
2473 mwindow->session->drag_start_position = (POS); \
2474 mwindow->session->drag_start_percentage = (VAL);
2476 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2479 // without modifier we are manipulating the automation node
2480 // with ALT it's about dragging only the value of the node
2481 // with SHIFT the value snaps to the value of neighbouring nodes
2482 // CTRL indicates we are rather manipulating the tangent(s) of the node
2486 if( WITHIN(x1,x2,y1,y2))
2487 { // cursor hits node
2490 if(buttonpress && (buttonpress != 3))
2492 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2493 mwindow->session->drag_handle = 0;
2498 if( WITHIN(x1,x2,y1,y2))
2501 if(buttonpress && (buttonpress != 3))
2503 // could be ctrl-click or ctrl-drag
2504 // click would cycle through tangent modes
2505 ((FloatAuto*)current)->toggle_curve_mode();
2507 // drag will start dragging the tangent, if applicable
2508 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2509 mwindow->session->drag_handle = 0;
2513 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2516 if( in_x != x && current->position > 0 &&
2517 (FloatAuto::FREE == current->curve_mode ||
2518 FloatAuto::TFREE == current->curve_mode))
2519 // act on in control handle only if
2520 // tangent is significant and is editable (not automatically choosen)
2522 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2523 // either cursor in ctrl-point handle or cursor on tangent line
2524 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2526 if(buttonpress && (buttonpress != 3)) {
2527 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2529 mwindow->session->drag_handle = 1;
2530 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2531 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2532 value_to_percentage(new_invalue, autogrouptype))
2539 (FloatAuto::FREE == current->curve_mode ||
2540 FloatAuto::TFREE == current->curve_mode))
2541 // act on out control only if tangent is significant and is editable
2543 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2544 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2546 if(buttonpress && (buttonpress != 3)) {
2547 if(lever == 0.0) lever=1.0;
2549 mwindow->session->drag_handle = 2;
2550 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2551 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2552 value_to_percentage(new_outvalue, autogrouptype))
2556 } // end ctrl_down()
2562 // 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",
2563 // mwindow->session->drag_handle,
2568 if(buttonpress && (buttonpress != 3) && result)
2570 mwindow->undo->update_undo_before();
2577 // Get the float value & y for position x on the canvas
2578 #define X_TO_FLOATLINE(x) \
2579 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2580 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2581 /* Call by reference fails for some reason here */ \
2582 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2583 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2584 double position = unit_start + x * zoom_units; \
2586 if(position2 > position1) \
2589 (value2 - value1) * \
2590 (position - position1) / \
2591 (position2 - position1); \
2597 AUTOMATIONCLAMPS(value, autogrouptype); \
2598 int y = center_pixel + \
2599 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2602 void TrackCanvas::draw_floatline(int center_pixel,
2603 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2604 double unit_start, double zoom_units, double yscale,
2605 int x1, int y1, int x2, int y2,
2606 int color, int autogrouptype)
2608 // Solve bezier equation for either every pixel or a certain large number of
2611 // Not using slope intercept
2613 int prev_y = y1 + center_pixel;
2616 // Call by reference fails for some reason here
2617 FloatAuto *previous1 = previous, *next1 = next;
2618 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2619 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2620 float automation_range = automation_max - automation_min;
2622 for(int x = x1; x < x2; x++)
2624 // Interpolate value between frames
2628 y >= center_pixel - yscale / 2 &&
2629 y < center_pixel + yscale / 2 - 1)
2631 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2633 // (int)(center_pixel - yscale / 2),
2634 // (int)(center_pixel + yscale / 2 - 1));
2636 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2637 draw_line(x - 1, prev_y , x, y );
2647 int TrackCanvas::test_floatline(int center_pixel,
2662 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2663 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2664 float automation_range = automation_max - automation_min;
2665 FloatAuto *previous1 = 0, *next1 = 0;
2666 X_TO_FLOATLINE(cursor_x);
2668 if(cursor_x >= x1 &&
2670 cursor_y >= y - HANDLE_W / 2 &&
2671 cursor_y < y + HANDLE_W / 2 &&
2677 if(buttonpress == 3)
2685 mwindow->undo->update_undo_before();
2686 double position = autos->track->from_units(position1);
2687 position = mwindow->edl->align_to_frame(position, 0);
2688 int64_t new_position = autos->track->to_units(position,0);
2689 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2690 ((FloatAuto*)current)->set_value(value);
2691 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2692 mwindow->session->drag_start_position = current->position;
2693 mwindow->session->drag_origin_x = cursor_x;
2694 mwindow->session->drag_origin_y = cursor_y;
2695 mwindow->session->drag_handle = 0;
2704 void TrackCanvas::synchronize_autos(float change,
2705 Track *skip, FloatAuto *fauto, int fill_gangs)
2707 // Handles the special case of modifying a fadeauto
2708 // when there are ganged faders on several tracks
2709 // (skip and fauto may be NULL if fill_gangs==-1)
2711 if( fill_gangs > 0 && skip->gang ) {
2712 double position = skip->from_units(fauto->position);
2713 int autoidx = fauto->autos->autoidx;
2715 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2716 if( (current->data_type == skip->data_type || get_double_click()) &&
2717 current->gang && current->record && current != skip ) {
2718 int64_t current_position = current->to_units(position, 1);
2719 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2720 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2721 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2722 FloatAuto *previous = 0, *next = 0;
2723 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2725 // create keyframe on neighbouring track at the point in time given by fauto
2726 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2727 float new_value = init_value + change;
2728 CLAMP(new_value, auto_min, auto_max);
2729 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2730 keyframe->set_value(new_value);
2733 // keyframe exists, just change it
2734 float new_value = keyframe->get_value() + change;
2735 CLAMP(new_value, auto_min, auto_max);
2736 keyframe->adjust_to_new_coordinates(current_position, new_value);
2737 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2740 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2744 else if( !fill_gangs ) {
2745 double position = skip->from_units(fauto->position);
2747 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2748 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2749 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2750 float new_value = keyframe->get_value() + change;
2752 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2753 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2754 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2760 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2761 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2762 keyframe->autos->remove_nonsequential(
2765 mwindow->session->drag_auto_gang->remove_all();
2770 void TrackCanvas::draw_toggleline(int center_pixel,
2776 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2780 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2784 int TrackCanvas::test_toggleline(Autos *autos,
2795 if(cursor_x >= x1 && cursor_x < x2)
2797 int miny = center_pixel + y1 - HANDLE_W / 2;
2798 int maxy = center_pixel + y1 + HANDLE_W / 2;
2799 if(cursor_y >= miny && cursor_y < maxy)
2804 if(buttonpress == 3)
2812 double position = (double)(cursor_x +
2813 mwindow->edl->local_session->view_start[pane->number]) *
2814 mwindow->edl->local_session->zoom_sample /
2815 mwindow->edl->session->sample_rate;
2816 int64_t unit_position = autos->track->to_units(position, 0);
2817 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2819 mwindow->undo->update_undo_before();
2821 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2822 ((IntAuto*)current)->value = new_value;
2823 // Toggle Autos don't respond to vertical zoom, they always show up
2824 // with "on" == 100% == line on top
2825 mwindow->session->drag_start_percentage = (float)new_value;
2826 mwindow->session->drag_start_position = current->position;
2827 mwindow->session->drag_origin_x = cursor_x;
2828 mwindow->session->drag_origin_y = cursor_y;
2836 void TrackCanvas::calculate_viewport(Track *track,
2837 double &view_start, // Seconds
2839 double &view_end, // Seconds
2843 double &zoom_sample,
2846 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2847 mwindow->edl->local_session->zoom_sample /
2848 mwindow->edl->session->sample_rate;
2849 unit_start = track->to_doubleunits(view_start);
2850 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2852 mwindow->edl->local_session->zoom_sample /
2853 mwindow->edl->session->sample_rate;
2854 unit_end = track->to_doubleunits(view_end);
2855 yscale = mwindow->edl->local_session->zoom_track;
2856 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2857 center_pixel = (int)(track->y_pixel -
2858 mwindow->edl->local_session->track_start[pane->number] +
2860 (mwindow->edl->session->show_titles ?
2861 mwindow->theme->get_image("title_bg_data")->get_h() :
2863 zoom_sample = mwindow->edl->local_session->zoom_sample;
2865 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2868 float TrackCanvas::percentage_to_value(float percentage,
2876 if(percentage > 0.5)
2883 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2884 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2885 float automation_range = automation_max - automation_min;
2887 result = percentage * automation_range + automation_min;
2890 FloatAuto *ptr = (FloatAuto*)reference;
2891 result -= ptr->get_value();
2893 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2899 void TrackCanvas::calculate_auto_position(double *x, double *y,
2900 double *in_x, double *in_y, double *out_x, double *out_y,
2901 Auto *current, double unit_start, double zoom_units, double yscale,
2904 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2905 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2906 float automation_range = automation_max - automation_min;
2907 FloatAuto *ptr = (FloatAuto*)current;
2908 *x = (double)(ptr->position - unit_start) / zoom_units;
2909 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2912 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2913 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2917 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2918 automation_min) / automation_range - 0.5) * -yscale;
2922 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2923 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2927 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2928 automation_min) / automation_range - 0.5) * -yscale;
2933 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2934 int draw, int buttonpress, int x_offset, int y_offset, int color,
2935 Auto* &auto_instance, int autogrouptype)
2938 int center_pixel, draw_auto;
2939 double view_start, unit_start;
2940 double view_end, unit_end, yscale;
2941 double zoom_sample, zoom_units;
2942 double in_x2, in_y2, out_x2, out_y2;
2948 if(draw) set_color(color);
2950 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2951 yscale, center_pixel, zoom_sample, zoom_units);
2953 // Get first auto before start
2954 Auto *current = 0, *previous = 0;
2956 for( current = autos->last;
2957 current && current->position >= unit_start;
2958 current = PREVIOUS ) ;
2960 Auto *first_auto = current ? current :
2961 autos->first ? autos->first : autos->default_auto;
2963 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2965 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2966 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2971 current = autos->first;
2980 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2981 current, unit_start, zoom_units, yscale, autogrouptype);
2989 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2994 ay2 = ay + slope * (get_w() - ax);
2998 ay = ay + slope * (0 - ax);
3002 // Draw or test handle
3003 if( current && !result && current != autos->default_auto ) {
3004 if( !draw && track->record ) {
3005 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3006 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3007 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3008 buttonpress, autogrouptype);
3010 auto_instance = current;
3012 if( draw && draw_auto ) {
3013 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3014 (int)in_x2 + x_offset, (int)in_y2,
3015 (int)out_x2 + x_offset, (int)out_y2,
3016 (int)center_pixel + y_offset, (int)yscale, color);
3020 // Draw or test joining line
3021 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3022 result = test_floatline(center_pixel,
3023 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3024 // Exclude auto coverage from the end of the line. The auto overlaps
3025 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3026 buttonpress, autogrouptype);
3029 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3030 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3031 (int)ax, (int)ay, (int)ax2, (int)ay2,
3032 color, autogrouptype);
3040 } while( current && current->position <= unit_end && !result );
3042 if( ax < get_w() && !result ) {
3043 ax2 = get_w(); ay2 = ay;
3044 if(!draw && track->record /* && buttonpress != 3 */ ) {
3045 result = test_floatline(center_pixel,
3046 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3047 (int)ax, (int)ax2, cursor_x, cursor_y,
3048 buttonpress, autogrouptype);
3051 draw_floatline(center_pixel,
3052 (FloatAuto*)previous, (FloatAuto*)current,
3053 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3054 (int)ax, (int)ay, (int)ax2, (int)ay2,
3055 color, autogrouptype);
3062 int TrackCanvas::do_int_autos(Track *track,
3071 Auto *&auto_instance)
3082 double ax, ay, ax2, ay2;
3086 if(draw) set_color(color);
3088 calculate_viewport(track,
3099 double high = -yscale * 0.8 / 2;
3100 double low = yscale * 0.8 / 2;
3102 // Get first auto before start
3104 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3110 ay = ((IntAuto*)current)->value > 0 ? high : low;
3115 current = autos->first ? autos->first : autos->default_auto;
3119 ay = ((IntAuto*)current)->value > 0 ? high : low;
3132 ax2 = (double)(current->position - unit_start) / zoom_units;
3133 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3141 if(ax2 > get_w()) ax2 = get_w();
3143 if(current && !result)
3145 if(current != autos->default_auto)
3151 result = test_auto(current,
3160 auto_instance = current;
3165 (int)ax2 + x_offset,
3166 (int)ay2 + y_offset,
3178 if(track->record /* && buttonpress != 3 */)
3180 result = test_toggleline(autos,
3193 draw_toggleline(center_pixel + y_offset,
3201 }while(current && current->position <= unit_end && !result);
3203 if(ax < get_w() && !result)
3209 if(track->record /* && buttonpress != 3 */)
3211 result = test_toggleline(autos,
3223 draw_toggleline(center_pixel + y_offset,
3232 int TrackCanvas::do_autos(Track *track,
3239 Auto * &auto_instance,
3253 calculate_viewport(track,
3266 for(current = autos->first; current && !result; current = NEXT)
3268 if(current->position >= unit_start && current->position < unit_end)
3271 x = (int64_t)((double)(current->position - unit_start) /
3272 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3273 y = center_pixel - pixmap->get_h() / 2;
3277 if(cursor_x >= x && cursor_y >= y &&
3278 cursor_x < x + pixmap->get_w() &&
3279 cursor_y < y + pixmap->get_h())
3282 auto_instance = current;
3284 if(buttonpress && (buttonpress != 3))
3286 mwindow->session->drag_auto = current;
3287 mwindow->session->drag_start_position = current->position;
3288 mwindow->session->drag_origin_x = cursor_x;
3289 mwindow->session->drag_origin_y = cursor_y;
3291 double position = autos->track->from_units(current->position);
3292 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3293 mwindow->edl->local_session->get_selectionend(1)) /
3298 mwindow->edl->local_session->set_selectionstart(position);
3299 mwindow->edl->local_session->set_selectionend(position);
3302 if(position < center)
3304 mwindow->edl->local_session->set_selectionstart(position);
3307 mwindow->edl->local_session->set_selectionend(position);
3314 draw_pixmap(pixmap, x, y);
3322 // so this means it is always >0 when keyframe is found
3323 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3324 int draw, int buttonpress, Plugin* &keyframe_plugin,
3325 KeyFrame* &keyframe_instance)
3338 if(!track->expand_view) return 0;
3340 calculate_viewport(track,
3352 for(int i = 0; i < track->plugin_set.total && !result; i++)
3354 PluginSet *plugin_set = track->plugin_set.values[i];
3355 int center_pixel = (int)(track->y_pixel -
3356 mwindow->edl->local_session->track_start[pane->number] +
3357 mwindow->edl->local_session->zoom_track +
3358 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3359 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3361 for(Plugin *plugin = (Plugin*)plugin_set->first;
3363 plugin = (Plugin*)plugin->next)
3365 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3366 keyframe && !result;
3367 keyframe = (KeyFrame*)keyframe->next)
3369 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3370 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3372 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3373 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3375 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3378 if(cursor_x >= x && cursor_y >= y &&
3379 cursor_x < x + keyframe_pixmap->get_w() &&
3380 cursor_y < y + keyframe_pixmap->get_h())
3383 keyframe_plugin = plugin;
3384 keyframe_instance = keyframe;
3388 mwindow->session->drag_auto = keyframe;
3389 mwindow->session->drag_start_position = keyframe->position;
3390 mwindow->session->drag_origin_x = cursor_x;
3391 mwindow->session->drag_origin_y = cursor_y;
3393 double position = track->from_units(keyframe->position);
3394 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3395 mwindow->edl->local_session->get_selectionend(1)) /
3400 mwindow->edl->local_session->set_selectionstart(position);
3401 mwindow->edl->local_session->set_selectionend(position);
3404 if(position < center)
3406 mwindow->edl->local_session->set_selectionstart(position);
3409 mwindow->edl->local_session->set_selectionend(position);
3414 draw_pixmap(keyframe_pixmap,
3424 // if(buttonpress && buttonpress != 3 && result)
3426 // mwindow->undo->update_undo_before();
3432 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3434 Track *track = auto_keyframe->autos->track;
3435 int autogrouptype = auto_keyframe->autos->get_type();
3438 double view_start, unit_start;
3439 double view_end, unit_end, yscale;
3440 double zoom_sample, zoom_units;
3442 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3443 yscale, center_pixel, zoom_sample, zoom_units);
3445 double ax = 0, ay = 0;
3446 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3447 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3450 draw_line(ax, 0, ax, get_h());
3454 void TrackCanvas::draw_overlays()
3456 int new_cursor, update_cursor, rerender;
3458 // Move background pixmap to foreground pixmap
3459 draw_pixmap(background_pixmap,
3468 draw_inout_points();
3471 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3479 draw_brender_range();
3481 // Highlighted areas
3482 draw_highlighting();
3485 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3488 if(pane->cursor) pane->cursor->restore(1);
3494 draw_playback_cursor();
3496 draw_keyframe_reticle();
3501 int TrackCanvas::activate()
3505 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3506 //BC_Signals::dump_stack();
3507 get_top_level()->deactivate();
3509 set_active_subwindow(this);
3510 pane->cursor->activate();
3511 gui->focused_pane = pane->number;
3516 int TrackCanvas::deactivate()
3521 pane->cursor->deactivate();
3527 void TrackCanvas::update_drag_handle()
3529 double new_position;
3530 int cursor_x = get_cursor_x();
3534 mwindow->edl->local_session->view_start[pane->number]) *
3535 mwindow->edl->local_session->zoom_sample /
3536 mwindow->edl->session->sample_rate;
3539 mwindow->edl->align_to_frame(new_position, 0);
3541 if( ctrl_down() && alt_down() ) {
3542 #define snapper(v) do { \
3544 if( pos < 0 ) break; \
3545 double dist = fabs(new_position - pos); \
3546 if( dist >= snap_min ) break; \
3547 snap_position = pos; snap_min = dist; \
3549 double snap_position = new_position;
3550 double snap_min = DBL_MAX;
3551 if( mwindow->edl->local_session->inpoint_valid() )
3552 snapper(mwindow->edl->local_session->get_inpoint());
3553 if( mwindow->edl->local_session->outpoint_valid() )
3554 snapper(mwindow->edl->local_session->get_outpoint());
3555 snapper(mwindow->edl->prev_edit(new_position));
3556 snapper(mwindow->edl->next_edit(new_position));
3557 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3558 if( prev_label ) snapper(prev_label->position);
3559 Label *next_label = mwindow->edl->labels->next_label(new_position);
3560 if( next_label ) snapper(next_label->position);
3561 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3562 mwindow->edl->local_session->zoom_sample -
3563 mwindow->edl->local_session->view_start[pane->number];
3564 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3566 new_position = snap_position;
3571 if(new_position != mwindow->session->drag_position)
3573 mwindow->session->drag_position = new_position;
3574 gui->mainclock->update(new_position);
3577 timebar_position = new_position;
3578 gui->update_timebar(0);
3579 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3581 // mwindow->cwindow->update(1, 0, 0);
3585 int TrackCanvas::update_drag_edit()
3594 int TrackCanvas::get_drag_values(float *percentage,
3601 //int x = cursor_x - mwindow->session->drag_origin_x;
3602 //int y = cursor_y - mwindow->session->drag_origin_y;
3606 if(!current->autos->track->record) return 1;
3616 calculate_viewport(current->autos->track,
3626 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3628 mwindow->session->drag_start_percentage;
3629 if(do_clamp) CLAMP(*percentage, 0, 1);
3631 *position = Units::to_int64(zoom_units *
3632 (cursor_x - mwindow->session->drag_origin_x) +
3633 mwindow->session->drag_start_position + 0.5);
3635 if((do_clamp) && *position < 0) *position = 0;
3640 #define UPDATE_DRAG_HEAD(do_clamp) \
3641 int result = 0, center_pixel; \
3642 if(!current->autos->track->record) return 0; \
3643 double view_start, unit_start, view_end, unit_end; \
3644 double yscale, zoom_sample, zoom_units; \
3646 calculate_viewport(current->autos->track, \
3647 view_start, unit_start, view_end, unit_end, \
3648 yscale, center_pixel, zoom_sample, zoom_units); \
3650 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3651 yscale + mwindow->session->drag_start_percentage; \
3652 if(do_clamp) CLAMP(percentage, 0, 1); \
3654 int64_t position = Units::to_int64(zoom_units * \
3655 (cursor_x - mwindow->session->drag_origin_x) + \
3656 mwindow->session->drag_start_position); \
3657 if((do_clamp) && position < 0) position = 0;
3660 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3662 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3664 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3665 int x = cursor_x - mwindow->session->drag_origin_x;
3666 int y = cursor_y - mwindow->session->drag_origin_y;
3667 float value, old_value;
3669 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3670 // not really editing the node, rather start editing the curve
3671 // tangent is editable and drag movement is significant
3672 if( (FloatAuto::FREE == current->curve_mode ||
3673 FloatAuto::TFREE==current->curve_mode) &&
3674 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3675 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3678 switch(mwindow->session->drag_handle) {
3680 // Snap to nearby values
3681 old_value = current->get_value();
3683 double value1, value2, distance1, distance2;
3685 if(current->previous) {
3686 int autogrouptype = current->previous->autos->autogrouptype;
3687 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3688 value1 = ((FloatAuto*)current->previous)->get_value();
3689 distance1 = fabs(value - value1);
3690 current->set_value(value1);
3694 int autogrouptype = current->next->autos->autogrouptype;
3695 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3696 value2 = ((FloatAuto*)current->next)->get_value();
3697 distance2 = fabs(value - value2);
3698 if(!current->previous || distance2 < distance1) {
3699 current->set_value(value2);
3703 if(!current->previous && !current->next) {
3704 current->set_value( ((FloatAutos*)current->autos)->default_);
3706 value = current->get_value();
3709 int autogrouptype = current->autos->autogrouptype;
3710 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3713 if(alt_down() && !shift_down())
3714 // ALT constrains movement: fixed position, only changing the value
3715 position = mwindow->session->drag_start_position;
3717 if(value != old_value || position != current->position) {
3719 float change = value - old_value;
3720 current->adjust_to_new_coordinates(position, value);
3721 synchronize_autos(change, current->autos->track, current, 0);
3722 show_message(current, 1,", %.2f", current->get_value());
3728 int autogrouptype = current->autos->autogrouptype;
3729 value = percentage_to_value(percentage, 0, current, autogrouptype);
3730 if(value != current->get_control_in_value())
3733 // note: (position,value) need not be at the location of the ctrl point,
3734 // but could be somewhere in between on the curve (or even outward or
3735 // on the opposit side). We set the new control point such as
3736 // to point the curve through (position,value)
3737 current->set_control_in_value(
3738 value * levered_position(position - current->position,
3739 current->get_control_in_position()));
3740 synchronize_autos(0, current->autos->track, current, 0);
3741 show_message(current, 1,", %.2f", current->get_control_in_value());
3747 int autogrouptype = current->autos->autogrouptype;
3748 value = percentage_to_value(percentage, 0, current, autogrouptype);
3749 if(value != current->get_control_out_value()) {
3751 current->set_control_out_value(
3752 value * levered_position(position - current->position,
3753 current->get_control_out_position()));
3754 synchronize_autos(0, current->autos->track, current, 0);
3755 show_message(current, 1,", %.2f", current->get_control_out_value());
3763 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3765 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3767 UPDATE_DRAG_HEAD(1);
3768 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3770 if(value != current->value || position != current->position)
3773 current->value = value;
3774 current->position = position;
3775 show_message(current, 0,", %d", current->value);
3781 // Autos which can't change value through dragging.
3783 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3785 Auto *current = (Auto*)mwindow->session->drag_auto;
3788 if(position != current->position)
3791 current->position = position;
3792 show_message(current, 0,"");
3794 double position_f = current->autos->track->from_units(current->position);
3795 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3796 mwindow->edl->local_session->get_selectionend(1)) /
3800 mwindow->edl->local_session->set_selectionstart(position_f);
3801 mwindow->edl->local_session->set_selectionend(position_f);
3804 if(position_f < center_f)
3806 mwindow->edl->local_session->set_selectionstart(position_f);
3809 mwindow->edl->local_session->set_selectionend(position_f);
3816 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3818 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3821 if(position != current->position)
3823 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3824 Track *track = current->autos->track;
3825 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3826 PluginSet *pluginset;
3828 // figure out the correct pluginset & correct plugin
3830 for(int i = 0; i < track->plugin_set.total; i++)
3832 pluginset = track->plugin_set.values[i];
3833 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3835 KeyFrames *keyframes = plugin->keyframes;
3836 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3838 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3840 if (currentkeyframe == current)
3852 mwindow->session->plugin_highlighted = plugin;
3853 mwindow->session->track_highlighted = track;
3855 current->position = position;
3856 show_message(current, 0,"");
3858 double position_f = current->autos->track->from_units(current->position);
3859 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3860 mwindow->edl->local_session->get_selectionend(1)) /
3864 mwindow->edl->local_session->set_selectionstart(position_f);
3865 mwindow->edl->local_session->set_selectionend(position_f);
3868 if(position_f < center_f)
3870 mwindow->edl->local_session->set_selectionstart(position_f);
3873 mwindow->edl->local_session->set_selectionend(position_f);
3880 void TrackCanvas::update_drag_caption()
3882 switch(mwindow->session->current_operation)
3892 int TrackCanvas::cursor_motion_event()
3897 int update_clock = 0;
3898 int update_zoom = 0;
3899 int update_scroll = 0;
3900 int update_overlay = 0;
3901 int update_cursor = 0;
3904 double position = 0.;
3905 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3908 switch(mwindow->edl->session->editing_mode)
3910 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3911 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3914 switch(mwindow->session->current_operation)
3916 case DRAG_EDITHANDLE1:
3917 // Outside threshold. Upgrade status
3920 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3922 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3928 case DRAG_EDITHANDLE2:
3931 update_drag_handle();
3936 case DRAG_PLUGINHANDLE1:
3939 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3941 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3947 case DRAG_PLUGINHANDLE2:
3950 update_drag_handle();
3955 // Rubber band curves
3963 case DRAG_PROJECTOR_X:
3964 case DRAG_PROJECTOR_Y:
3965 case DRAG_PROJECTOR_Z:
3966 if(active) rerender = update_overlay =
3967 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3971 if(active) rerender = update_overlay =
3972 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3976 if(active) rerender = update_overlay =
3977 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3980 // Keyframe icons are sticky
3984 case DRAG_PLUGINKEY_PRE:
3986 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3987 mwindow->session->current_operation++;
3990 mwindow->undo->update_undo_before();
3998 if(active) rerender = update_overlay =
3999 update_drag_auto(get_cursor_x(), get_cursor_y());
4002 case DRAG_PLUGINKEY:
4003 if(active) rerender = update_overlay =
4004 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4009 cursor_x = get_cursor_x();
4010 cursor_y = get_cursor_y();
4011 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4012 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4014 position = mwindow->edl->align_to_frame(position, 0);
4015 position = MAX(position, 0);
4017 if(position < selection_midpoint) {
4018 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4019 mwindow->edl->local_session->set_selectionstart(position);
4021 gui->unlock_window();
4022 mwindow->cwindow->update(1, 0, 0, 0, 1);
4023 gui->lock_window("TrackCanvas::cursor_motion_event 1");
4024 // Update the faders
4025 mwindow->update_plugin_guis();
4026 gui->update_patchbay();
4029 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4030 mwindow->edl->local_session->set_selectionend(position);
4031 // Don't que the CWindow
4034 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4036 gui->hide_cursor(0);
4037 gui->draw_cursor(1);
4038 gui->update_timebar(0);
4039 gui->flash_canvas(1);
4048 if(is_event_win() && cursor_inside()) {
4050 cursor_x = get_cursor_x();
4051 position = (double)cursor_x *
4052 (double)mwindow->edl->local_session->zoom_sample /
4053 (double)mwindow->edl->session->sample_rate +
4054 (double)mwindow->edl->local_session->view_start[pane->number] *
4055 (double)mwindow->edl->local_session->zoom_sample /
4056 (double)mwindow->edl->session->sample_rate;
4057 position = mwindow->edl->align_to_frame(position, 0);
4061 for(int i = 0; i < TOTAL_PANES; i++)
4062 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4064 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4065 gui->update_timebar(0);
4067 if(do_transitions(get_cursor_x(), get_cursor_y(),
4068 0, new_cursor, update_cursor)) break;
4069 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4070 0, 0, new_cursor, update_cursor, rerender)) break;
4071 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4072 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4073 // Plugin boundaries
4074 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4075 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4076 if(do_edits(get_cursor_x(), get_cursor_y(),
4077 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4082 //printf("TrackCanvas::cursor_motion_event 1\n");
4083 if(update_cursor && new_cursor != get_cursor())
4085 set_cursor(new_cursor, 0, 1);
4088 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
4089 if(rerender && render_timer->get_difference() > 0.25 ) {
4090 render_timer->update();
4091 mwindow->restart_brender();
4092 mwindow->sync_parameters(CHANGE_PARAMS);
4093 mwindow->update_plugin_guis();
4094 gui->unlock_window();
4095 mwindow->cwindow->update(1, 0, 0, 0, 1);
4096 gui->lock_window("TrackCanvas::cursor_motion_event 2");
4100 gui->update_patchbay();
4105 if(!mwindow->cwindow->playback_engine->is_playing_back)
4106 gui->mainclock->update(position);
4110 gui->zoombar->update();
4115 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4119 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4123 if(update_overlay) {
4124 gui->draw_overlays(1);
4127 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
4131 void TrackCanvas::start_dragscroll()
4135 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4136 //printf("TrackCanvas::start_dragscroll 1\n");
4140 void TrackCanvas::stop_dragscroll()
4144 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4145 //printf("TrackCanvas::stop_dragscroll 1\n");
4149 int TrackCanvas::repeat_event(int64_t duration)
4151 if(!drag_scroll) return 0;
4152 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4154 int sample_movement = 0;
4155 int track_movement = 0;
4156 int64_t x_distance = 0;
4157 int64_t y_distance = 0;
4158 double position = 0;
4161 switch(mwindow->session->current_operation) {
4163 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4164 if(get_cursor_x() > get_w()) {
4165 x_distance = get_cursor_x() - get_w();
4166 sample_movement = 1;
4168 else if(get_cursor_x() < 0) {
4169 x_distance = get_cursor_x();
4170 sample_movement = 1;
4173 if(get_cursor_y() > get_h()) {
4174 y_distance = get_cursor_y() - get_h();
4177 else if(get_cursor_y() < 0) {
4178 y_distance = get_cursor_y();
4185 if(sample_movement) {
4186 position = (double)(get_cursor_x() +
4187 mwindow->edl->local_session->view_start[pane->number] +
4189 mwindow->edl->local_session->zoom_sample /
4190 mwindow->edl->session->sample_rate;
4191 position = mwindow->edl->align_to_frame(position, 0);
4192 position = MAX(position, 0);
4194 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4195 switch(mwindow->session->current_operation) {
4197 if(position < selection_midpoint) {
4198 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4199 mwindow->edl->local_session->set_selectionstart(position);
4201 gui->unlock_window();
4202 mwindow->cwindow->update(1, 0, 0);
4203 gui->lock_window("TrackCanvas::repeat_event");
4204 // Update the faders
4205 mwindow->update_plugin_guis();
4206 gui->update_patchbay();
4209 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4210 mwindow->edl->local_session->set_selectionend(position);
4211 // Don't que the CWindow
4216 mwindow->samplemovement(
4217 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4221 if(track_movement) {
4222 mwindow->trackmovement(y_distance, pane->number);
4228 int TrackCanvas::button_release_event()
4230 int redraw = 0, update_overlay = 0, result = 0;
4232 // printf("TrackCanvas::button_release_event %d\n",
4233 // mwindow->session->current_operation);
4235 switch(mwindow->session->current_operation) {
4236 case DRAG_EDITHANDLE2:
4237 mwindow->session->current_operation = NO_OPERATION;
4241 end_edithandle_selection();
4244 case DRAG_EDITHANDLE1:
4245 mwindow->session->current_operation = NO_OPERATION;
4250 case DRAG_PLUGINHANDLE2:
4251 mwindow->session->current_operation = NO_OPERATION;
4255 end_pluginhandle_selection();
4258 case DRAG_PLUGINHANDLE1:
4259 mwindow->session->current_operation = NO_OPERATION;
4266 // delete the drag_auto_gang first and remove out of order keys
4267 synchronize_autos(0, 0, 0, -1);
4278 case DRAG_PROJECTOR_X:
4279 case DRAG_PROJECTOR_Y:
4280 case DRAG_PROJECTOR_Z:
4281 case DRAG_PLUGINKEY:
4282 mwindow->session->current_operation = NO_OPERATION;
4283 mwindow->session->drag_handle = 0;
4284 // Remove any out-of-order keyframe
4285 if(mwindow->session->drag_auto) {
4286 mwindow->session->drag_auto->autos->remove_nonsequential(
4287 mwindow->session->drag_auto);
4288 // mwindow->session->drag_auto->autos->optimize();
4293 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4298 case DRAG_AEFFECT_COPY:
4299 case DRAG_VEFFECT_COPY:
4300 // Trap in drag stop
4305 if(mwindow->session->current_operation) {
4306 // if(mwindow->session->current_operation == SELECT_REGION) {
4307 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4310 mwindow->session->current_operation = NO_OPERATION;
4312 // Traps button release events
4320 cursor_motion_event();
4322 if(update_overlay) {
4323 gui->draw_overlays(1);
4326 gui->draw_canvas(NORMAL_DRAW, 0);
4331 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4332 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4334 Edit *edit_result = 0;
4335 int handle_result = -1;
4338 if( !mwindow->edl->session->show_assets ) return 0;
4340 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4341 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4342 int64_t edit_x, edit_y, edit_w, edit_h;
4343 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4345 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4346 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4347 if( cursor_x < edit_x + HANDLE_W ) {
4350 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4351 new_cursor = DOWNLEFT_RESIZE;
4352 if( button_press == LEFT_BUTTON )
4358 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4361 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4362 new_cursor = DOWNRIGHT_RESIZE;
4363 if( button_press == LEFT_BUTTON )
4375 double position = 0;
4376 if( handle_result == 0 ) {
4377 position = edit_result->track->from_units(edit_result->startproject);
4378 new_cursor = LEFT_CURSOR;
4380 else if( handle_result == 1 ) {
4381 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4382 new_cursor = RIGHT_CURSOR;
4385 // Reposition cursor
4386 if( button_press ) {
4387 mwindow->session->drag_edit = edit_result;
4388 mwindow->session->drag_handle = handle_result;
4389 mwindow->session->drag_button = get_buttonpress() - 1;
4390 mwindow->session->drag_position = position;
4391 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4392 mwindow->session->drag_origin_x = get_cursor_x();
4393 mwindow->session->drag_origin_y = get_cursor_y();
4394 mwindow->session->drag_start = position;
4396 rerender = start_selection(position);
4400 else if( result < 0) {
4401 mwindow->undo->update_undo_before();
4402 if( !shift_down() ) {
4403 if( handle_result == 0 )
4404 edit_result->hard_left = !edit_result->hard_left;
4405 else if( handle_result == 1 )
4406 edit_result->hard_right = !edit_result->hard_right;
4409 int status = handle_result == 0 ? edit_result->hard_left :
4410 handle_result == 1 ? edit_result->hard_right : 0;
4411 int new_status = !status;
4412 int64_t edit_edge = edit_result->startproject;
4413 if( handle_result == 1 ) edit_edge += edit_result->length;
4414 double edge_position = edit_result->track->from_units(edit_edge);
4415 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4416 int64_t track_position = track->to_units(edge_position, 1);
4417 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4419 int64_t left_edge = left_edit->startproject;
4420 double left_position = track->from_units(left_edge);
4421 if( EQUIV(edge_position, left_position) )
4422 left_edit->hard_left = new_status;
4424 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4426 int64_t right_edge = right_edit->startproject + right_edit->length;
4427 double right_position = track->from_units(right_edge);
4428 if( EQUIV(edge_position, right_position) )
4429 right_edit->hard_right = new_status;
4433 rerender = update_overlay = 1;
4434 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4441 int TrackCanvas::do_plugin_handles(int cursor_x,
4445 int &update_overlay,
4449 Plugin *plugin_result = 0;
4450 int handle_result = 0;
4453 // if(!mwindow->edl->session->show_assets) return 0;
4455 for(Track *track = mwindow->edl->tracks->first;
4457 track = track->next) {
4458 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4459 PluginSet *plugin_set = track->plugin_set.values[i];
4460 for(Plugin *plugin = (Plugin*)plugin_set->first;
4462 plugin = (Plugin*)plugin->next) {
4463 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4464 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4466 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4467 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4468 if(cursor_x < plugin_x + HANDLE_W) {
4469 plugin_result = plugin;
4473 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4474 plugin_result = plugin;
4481 if(result && shift_down())
4482 mwindow->session->trim_edits = plugin_set;
4488 double position = 0;
4489 if(handle_result == 0) {
4490 position = plugin_result->track->from_units(plugin_result->startproject);
4491 new_cursor = LEFT_CURSOR;
4493 else if(handle_result == 1) {
4494 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4495 new_cursor = RIGHT_CURSOR;
4499 mwindow->session->drag_plugin = plugin_result;
4500 mwindow->session->drag_handle = handle_result;
4501 mwindow->session->drag_button = get_buttonpress() - 1;
4502 mwindow->session->drag_position = position;
4503 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4504 mwindow->session->drag_origin_x = get_cursor_x();
4505 mwindow->session->drag_origin_y = get_cursor_y();
4506 mwindow->session->drag_start = position;
4508 rerender = start_selection(position);
4517 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4521 // if(!mwindow->edl->session->show_assets) return 0;
4523 for(Track *track = mwindow->edl->tracks->first;
4525 track = track->next) {
4526 int64_t track_x, track_y, track_w, track_h;
4527 track_dimensions(track, track_x, track_y, track_w, track_h);
4529 if(button_press && get_buttonpress() == RIGHT_BUTTON &&
4530 cursor_y >= track_y && cursor_y < track_y + track_h) {
4531 gui->edit_menu->update(track, 0);
4532 gui->edit_menu->activate_menu();
4540 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4541 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4545 if(!mwindow->edl->session->show_assets) return 0;
4547 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4549 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4550 int64_t edit_x, edit_y, edit_w, edit_h;
4551 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4553 // Cursor inside a track
4554 // Cursor inside an edit
4555 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4556 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4557 // Select duration of edit
4559 if(get_double_click() && !drag_start) {
4560 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4561 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4562 edit->track->from_units(edit->length));
4563 if(mwindow->edl->session->cursor_on_frames)
4565 mwindow->edl->local_session->set_selectionstart(
4566 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4567 mwindow->edl->local_session->set_selectionend(
4568 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4576 else if(drag_start && track->record) {
4577 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4578 // Need to create drag window
4579 mwindow->session->current_operation = DRAG_EDIT;
4580 mwindow->session->drag_edit = edit;
4581 //printf("TrackCanvas::do_edits 2\n");
4583 // Drag only one edit if ctrl is initially down
4585 mwindow->session->drag_edits->remove_all();
4586 mwindow->session->drag_edits->append(edit);
4589 // Construct list of all affected edits
4590 mwindow->edl->tracks->get_affected_edits(
4591 mwindow->session->drag_edits,
4592 edit->track->from_units(edit->startproject),
4595 mwindow->session->drag_origin_x = cursor_x;
4596 mwindow->session->drag_origin_y = cursor_y;
4597 // Where the drag started, so we know relative position inside the edit later
4598 mwindow->session->drag_position = (double)cursor_x *
4599 mwindow->edl->local_session->zoom_sample /
4600 mwindow->edl->session->sample_rate +
4601 (double)mwindow->edl->local_session->view_start[pane->number] *
4602 mwindow->edl->local_session->zoom_sample /
4603 mwindow->edl->session->sample_rate;
4606 get_abs_cursor(cx, cy);
4607 gui->drag_popup = new BC_DragWindow(gui,
4608 mwindow->theme->get_image("clip_icon"), cx, cy);
4620 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4625 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4626 int button_press, int &redraw, int &rerender)
4635 // if(!mwindow->edl->session->show_assets) return 0;
4638 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4639 if(!track->expand_view) continue;
4641 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4642 // first check if plugins are visible at all
4643 if (!track->expand_view)
4645 PluginSet *plugin_set = track->plugin_set.values[i];
4646 for(plugin = (Plugin*)plugin_set->first;
4648 plugin = (Plugin*)plugin->next) {
4649 plugin_dimensions(plugin, x, y, w, h);
4650 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4651 MWindowGUI::visible(y, y + h, 0, get_h())) {
4652 if(cursor_x >= x && cursor_x < x + w &&
4653 cursor_y >= y && cursor_y < y + h) {
4663 // Start plugin popup
4665 if(get_buttonpress() == 3) {
4666 gui->plugin_menu->update(plugin);
4667 gui->plugin_menu->activate_menu();
4670 else if (get_double_click() && !drag_start) {
4671 // Select range of plugin on doubleclick over plugin
4672 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4673 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4674 plugin->track->from_units(plugin->length));
4675 if(mwindow->edl->session->cursor_on_frames) {
4676 mwindow->edl->local_session->set_selectionstart(
4677 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4678 mwindow->edl->local_session->set_selectionend(
4679 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4688 if(drag_start && plugin->track->record) {
4689 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4690 if(plugin->track->data_type == TRACK_AUDIO)
4691 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4692 else if(plugin->track->data_type == TRACK_VIDEO)
4693 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4695 mwindow->session->drag_plugin = plugin;
4696 mwindow->session->drag_origin_x = cursor_x;
4697 mwindow->session->drag_origin_y = cursor_y;
4698 // Where the drag started, so we know relative position inside the edit later
4699 mwindow->session->drag_position =
4700 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4701 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4703 switch(plugin->plugin_type) {
4704 case PLUGIN_STANDALONE: {
4705 PluginServer *server =
4706 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4707 if( !server ) break;
4708 VFrame *frame = server->picon;
4710 if(plugin->track->data_type == TRACK_AUDIO) {
4711 frame = mwindow->theme->get_image("aeffect_icon");
4714 frame = mwindow->theme->get_image("veffect_icon");
4718 get_abs_cursor(cx, cy);
4719 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4722 case PLUGIN_SHAREDPLUGIN:
4723 case PLUGIN_SHAREDMODULE: {
4724 VFrame *frame = mwindow->theme->get_image("clip_icon");
4726 get_abs_cursor(cx, cy);
4727 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4739 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4740 int button_press, int &new_cursor, int &update_cursor)
4742 Transition *transition = 0;
4746 if(/* !mwindow->edl->session->show_assets || */
4747 !mwindow->edl->session->auto_conf->transitions) return 0;
4749 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4751 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4752 if( edit->transition ) {
4753 edit_dimensions(edit, x, y, w, h);
4754 get_transition_coords(x, y, w, h);
4756 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4757 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4758 if( cursor_x >= x && cursor_x < x + w &&
4759 cursor_y >= y && cursor_y < y + h ) {
4760 transition = edit->transition;
4772 new_cursor = UPRIGHT_ARROW_CURSOR;
4774 else if(get_buttonpress() == 3) {
4775 gui->transition_menu->update(transition);
4776 gui->transition_menu->activate_menu();
4783 int TrackCanvas::button_press_event()
4786 int cursor_x, cursor_y;
4789 cursor_x = get_cursor_x();
4790 cursor_y = get_cursor_y();
4791 mwindow->session->trim_edits = 0;
4793 if(is_event_win() && cursor_inside()) {
4794 // double position = (double)cursor_x *
4795 // mwindow->edl->local_session->zoom_sample /
4796 // mwindow->edl->session->sample_rate +
4797 // (double)mwindow->edl->local_session->view_start[pane->number] *
4798 // mwindow->edl->local_session->zoom_sample /
4799 // mwindow->edl->session->sample_rate;
4806 if( get_buttonpress() == LEFT_BUTTON &&
4807 gui->mbuttons->transport->engine->command->command != STOP ) {
4808 gui->unlock_window();
4809 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4810 gui->lock_window("TrackCanvas::button_press_event");
4813 int update_overlay = 0, update_cursor = 0, rerender = 0;
4815 if(get_buttonpress() == WHEEL_UP) {
4817 mwindow->expand_sample();
4818 else if(ctrl_down())
4819 mwindow->move_left(get_w()/ 10);
4821 mwindow->move_up(get_h() / 10);
4823 else if(get_buttonpress() == WHEEL_DOWN) {
4825 mwindow->zoom_in_sample();
4826 else if(ctrl_down())
4827 mwindow->move_right(get_w() / 10);
4829 mwindow->move_down(get_h() / 10);
4831 else if(get_buttonpress() == 6) {
4833 mwindow->move_left(get_w());
4835 mwindow->move_left(get_w() / 20);
4837 mwindow->move_left(get_w() / 5);
4839 else if(get_buttonpress() == 7) {
4841 mwindow->move_right(get_w());
4843 mwindow->move_right(get_w() / 20);
4845 mwindow->move_right(get_w() / 5);
4848 switch(mwindow->edl->session->editing_mode) {
4849 // Test handles and resource boundaries and highlight a track
4850 case EDITING_ARROW: {
4851 if( do_transitions(cursor_x, cursor_y,
4852 1, new_cursor, update_cursor) ) break;
4854 if( do_keyframes(cursor_x, cursor_y,
4855 0, get_buttonpress(), new_cursor,
4856 update_cursor, rerender) ) break;
4857 // Test edit boundaries
4858 if( do_edit_handles(cursor_x, cursor_y,
4859 1, rerender, update_overlay, new_cursor,
4860 update_cursor) ) break;
4861 // Test plugin boundaries
4862 if( do_plugin_handles(cursor_x, cursor_y,
4863 1, rerender, update_overlay, new_cursor,
4864 update_cursor) ) break;
4866 if( do_edits(cursor_x, cursor_y, 1, 0,
4867 update_cursor, rerender, new_cursor,
4868 update_cursor) ) break;
4870 if( do_plugins(cursor_x, cursor_y, 0, 1,
4871 update_cursor, rerender) ) break;
4873 if( test_resources(cursor_x, cursor_y) ) break;
4875 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4880 // Test handles only and select a region
4881 case EDITING_IBEAM: {
4882 double position = (double)cursor_x *
4883 mwindow->edl->local_session->zoom_sample /
4884 mwindow->edl->session->sample_rate +
4885 (double)mwindow->edl->local_session->view_start[pane->number] *
4886 mwindow->edl->local_session->zoom_sample /
4887 mwindow->edl->session->sample_rate;
4888 //printf("TrackCanvas::button_press_event %d\n", position);
4890 if( do_transitions(cursor_x, cursor_y,
4891 1, new_cursor, update_cursor)) break;
4892 if(do_keyframes(cursor_x, cursor_y,
4893 0, get_buttonpress(), new_cursor,
4894 update_cursor, rerender)) {
4898 // Test edit boundaries
4899 if( do_edit_handles(cursor_x, cursor_y,
4900 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4901 // Test plugin boundaries
4902 if( do_plugin_handles(cursor_x, cursor_y,
4903 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4905 if( do_edits(cursor_x, cursor_y,
4906 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4908 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4910 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4911 // Highlight selection
4912 if( get_buttonpress() != LEFT_BUTTON ) break;
4913 rerender = start_selection(position);
4914 mwindow->session->current_operation = SELECT_REGION;
4921 gui->unlock_window();
4922 mwindow->cwindow->update(1, 0, 0, 0, 1);
4923 gui->lock_window("TrackCanvas::button_press_event 2");
4925 mwindow->update_plugin_guis();
4926 gui->update_patchbay();
4929 if( update_overlay ) {
4930 gui->draw_overlays(1);
4932 if( update_cursor < 0 ) {
4933 // double_click edit
4934 gui->swindow->update_selection();
4936 if( update_cursor ) {
4937 gui->update_timebar(0);
4938 gui->hide_cursor(0);
4939 gui->show_cursor(1);
4940 gui->zoombar->update();
4941 gui->flash_canvas(1);
4948 int TrackCanvas::start_selection(double position)
4951 position = mwindow->edl->align_to_frame(position, 1);
4957 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4958 mwindow->edl->local_session->get_selectionend(1)) / 2;
4960 if(position < midpoint)
4962 mwindow->edl->local_session->set_selectionstart(position);
4963 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4969 mwindow->edl->local_session->set_selectionend(position);
4970 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4971 // Don't que the CWindow for the end
4975 // Start a new selection
4977 //printf("TrackCanvas::start_selection %f\n", position);
4978 mwindow->edl->local_session->set_selectionstart(position);
4979 mwindow->edl->local_session->set_selectionend(position);
4980 selection_midpoint = position;
4988 void TrackCanvas::end_edithandle_selection()
4990 mwindow->modify_edithandles();
4993 void TrackCanvas::end_pluginhandle_selection()
4995 mwindow->modify_pluginhandles();
4999 double TrackCanvas::time_visible()
5001 return (double)get_w() *
5002 mwindow->edl->local_session->zoom_sample /
5003 mwindow->edl->session->sample_rate;
5007 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
5009 char string[BCTEXTLEN];
5010 char *cp = string, *ep = cp + sizeof(string)-1;
5011 if( show_curve_type ) {
5012 cp += snprintf(string, ep-cp, "%-8s ",
5013 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5015 char string2[BCTEXTLEN];
5016 Units::totext(string2,
5017 current->autos->track->from_units(current->position),
5018 mwindow->edl->session->time_format,
5019 mwindow->edl->session->sample_rate,
5020 mwindow->edl->session->frame_rate,
5021 mwindow->edl->session->frames_per_foot);
5022 cp += snprintf(cp, ep-cp, "%s", string2);
5025 vsnprintf(cp, ep-cp, fmt, ap);
5027 gui->show_message(string);
5030 // Patchbay* TrackCanvas::get_patchbay()
5032 // if(pane->patchbay) return pane->patchbay;
5033 // if(gui->total_panes() == 2 &&
5034 // gui->pane[TOP_LEFT_PANE] &&
5035 // gui->pane[TOP_RIGHT_PANE])
5036 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5037 // if(gui->total_panes() == 4)
5039 // if(pane->number == TOP_RIGHT_PANE)
5040 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5042 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;