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;
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;
1609 for(Track *track = mwindow->edl->tracks->first;
1611 track = track->next)
1613 if(track->expand_view)
1615 for(int i = 0; i < track->plugin_set.total; i++)
1617 PluginSet *pluginset = track->plugin_set.values[i];
1619 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1621 int64_t total_x, y, total_w, h;
1622 plugin_dimensions(plugin, total_x, y, total_w, h);
1624 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1625 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1626 plugin->plugin_type != PLUGIN_NONE)
1628 int x = total_x, w = total_w, left_margin = 5;
1629 int right_margin = 5;
1635 if(w + x > get_w()) w -= (w + x) - get_w();
1642 mwindow->theme->get_image("plugin_bg_data"),
1644 set_color(mwindow->theme->title_color);
1645 set_font(mwindow->theme->title_font);
1646 plugin->calculate_title(string, 0);
1648 // Truncate string to int64_test visible in background
1649 int len = strlen(string), j;
1650 for(j = len; j >= 0; j--)
1652 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1660 // Justify the text on the left boundary of the edit if it is visible.
1661 // Otherwise justify it on the left side of the screen.
1662 int64_t text_x = total_x + left_margin;
1663 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1664 text_x = MAX(left_margin, text_x);
1666 y + get_text_ascent(mwindow->theme->title_font) + 2,
1670 int64_t min_x = total_x + text_w;
1673 // Update plugin toggles
1674 int toggle_x = total_x + total_w;
1676 toggle_x = MIN(get_w() - right_margin, toggle_x);
1679 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1680 if(toggle_x > min_x)
1682 if(current_on >= plugin_on_toggles.total)
1684 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1685 add_subwindow(plugin_on);
1686 plugin_on_toggles.append(plugin_on);
1690 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1695 // Toggles for standalone plugins only
1696 if(plugin->plugin_type == PLUGIN_STANDALONE)
1699 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1700 if(toggle_x > min_x)
1702 if(current_show >= plugin_show_toggles.total)
1704 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1705 add_subwindow(plugin_show);
1706 plugin_show_toggles.append(plugin_show);
1710 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1724 // Remove unused toggles
1726 while(current_show < plugin_show_toggles.total)
1728 plugin_show_toggles.remove_object_number(current_show);
1731 while(current_on < plugin_on_toggles.total)
1733 plugin_on_toggles.remove_object_number(current_on);
1738 void TrackCanvas::refresh_plugintoggles()
1740 for(int i = 0; i < plugin_on_toggles.total; i++)
1742 PluginOn *on = plugin_on_toggles.values[i];
1743 on->reposition_window(on->get_x(), on->get_y());
1745 for(int i = 0; i < plugin_show_toggles.total; i++)
1747 PluginShow *show = plugin_show_toggles.values[i];
1748 show->reposition_window(show->get_x(), show->get_y());
1752 void TrackCanvas::draw_inout_points()
1757 void TrackCanvas::draw_drag_handle()
1759 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1760 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1762 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1763 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1764 mwindow->edl->session->sample_rate /
1765 mwindow->edl->local_session->zoom_sample -
1766 mwindow->edl->local_session->view_start[pane->number]);
1767 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1768 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1770 //printf("TrackCanvas::draw_drag_handle 3\n");
1771 draw_line(pixel1, 0, pixel1, get_h());
1773 //printf("TrackCanvas::draw_drag_handle 4\n");
1778 void TrackCanvas::draw_transitions()
1782 // if(!mwindow->edl->session->show_assets) return;
1784 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1785 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1786 if(!edit->transition) continue;
1787 edit_dimensions(edit, x, y, w, h);
1788 int strip_x = x, strip_y = y;
1789 if(mwindow->edl->session->show_titles)
1790 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1791 get_transition_coords(x, y, w, h);
1792 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1793 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1794 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1795 MWindowGUI::visible(y, y + h, 0, get_h()) )
1797 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1799 if( !server ) continue;
1800 VFrame *picon = server->get_picon();
1801 if( !picon ) continue;
1802 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1804 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1805 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1807 int x = strip_x, w = strip_w;
1813 if(w + x > get_w()) w -= (w + x) - get_w();
1815 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1816 mwindow->theme->get_image("plugin_bg_data"), 0);
1822 void TrackCanvas::draw_loop_points()
1824 //printf("TrackCanvas::draw_loop_points 1\n");
1825 if(mwindow->edl->local_session->loop_playback)
1827 //printf("TrackCanvas::draw_loop_points 2\n");
1828 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1829 mwindow->edl->session->sample_rate /
1830 mwindow->edl->local_session->zoom_sample -
1831 mwindow->edl->local_session->view_start[pane->number]);
1832 //printf("TrackCanvas::draw_loop_points 3\n");
1834 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1837 draw_line(x, 0, x, get_h());
1839 //printf("TrackCanvas::draw_loop_points 4\n");
1841 x = Units::round(mwindow->edl->local_session->loop_end *
1842 mwindow->edl->session->sample_rate /
1843 mwindow->edl->local_session->zoom_sample -
1844 mwindow->edl->local_session->view_start[pane->number]);
1845 //printf("TrackCanvas::draw_loop_points 5\n");
1847 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1850 draw_line(x, 0, x, get_h());
1852 //printf("TrackCanvas::draw_loop_points 6\n");
1854 //printf("TrackCanvas::draw_loop_points 7\n");
1857 void TrackCanvas::draw_brender_range()
1859 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1860 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1861 if( mwindow->edl->session->brender_end > 0 )
1863 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1864 mwindow->edl->session->sample_rate /
1865 mwindow->edl->local_session->zoom_sample -
1866 mwindow->edl->local_session->view_start[pane->number]);
1867 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1870 draw_line(x1, 0, x1, get_h());
1872 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1873 mwindow->edl->session->sample_rate /
1874 mwindow->edl->local_session->zoom_sample -
1875 mwindow->edl->local_session->view_start[pane->number]);
1877 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1880 draw_line(x2, 0, x2, get_h());
1885 // The operations which correspond to each automation type
1886 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1902 // The buttonpress operations, so nothing changes unless the mouse moves
1903 // a certain amount. This allows the keyframe to be used to position the
1904 // insertion point without moving itself.
1905 static int pre_auto_operations[AUTOMATION_TOTAL] =
1922 int TrackCanvas::do_keyframes(int cursor_x,
1930 // Note: button 3 (right mouse button) is not eaten to allow
1931 // track context menu to appear
1933 EDLSession *session = mwindow->edl->session;
1937 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1939 0, 0, 0, 0, 0, 0, 0, 0,
1941 modekeyframe_pixmap,
1942 maskkeyframe_pixmap,
1947 for(Track *track = mwindow->edl->tracks->first;
1949 track = track->next) {
1950 Auto *auto_keyframe = 0;
1951 Automation *automation = track->automation;
1954 // Handle keyframes in reverse drawing order if a button press
1956 int end = AUTOMATION_TOTAL;
1960 start = AUTOMATION_TOTAL - 1;
1964 for(int i = start; i != end && !result; i += step)
1966 // Event not trapped and automation visible
1967 Autos *autos = automation->autos[i];
1968 if(!result && session->auto_conf->autos[i] && autos) {
1970 case AUTOMATION_MODE:
1971 case AUTOMATION_PAN:
1972 case AUTOMATION_MASK:
1973 result = do_autos(track, automation->autos[i],
1974 cursor_x, cursor_y, draw,
1975 buttonpress, auto_pixmaps[i],
1976 auto_keyframe, rerender);
1980 switch(autos->get_type()) {
1981 case Autos::AUTOMATION_TYPE_FLOAT: {
1982 Automation automation(0, track);
1983 int grouptype = automation.autogrouptype(i, track);
1984 if(draw) // Do dropshadow
1985 result = do_float_autos(track, autos,
1986 cursor_x, cursor_y, draw,
1987 buttonpress, 1, 1, MDGREY,
1988 auto_keyframe, grouptype);
1990 result = do_float_autos(track, autos,
1991 cursor_x, cursor_y, draw, buttonpress,
1992 0, 0, GWindowGUI::auto_colors[i],
1993 auto_keyframe, grouptype);
1996 case Autos::AUTOMATION_TYPE_INT: {
1997 if(draw) // Do dropshadow
1998 result = do_int_autos(track, autos,
1999 cursor_x, cursor_y, draw,
2000 buttonpress, 1, 1, MDGREY,
2002 result = do_int_autos(track, autos,
2003 cursor_x, cursor_y, draw, buttonpress,
2004 0, 0, GWindowGUI::auto_colors[i],
2013 if(mwindow->session->current_operation == auto_operations[i])
2016 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2018 // mwindow->session->current_operation,
2019 // auto_operations[i]);
2022 if (buttonpress != 3)
2024 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2025 synchronize_autos(0,
2027 (FloatAuto*)mwindow->session->drag_auto,
2029 mwindow->session->current_operation = pre_auto_operations[i];
2030 update_drag_caption();
2033 else if( auto_keyframe )
2035 gui->keyframe_menu->update(automation,
2038 gui->keyframe_menu->activate_menu();
2039 rerender = 1; // the position changes
2043 gui->keyframe_hide->update(autos);
2044 gui->keyframe_hide->activate_menu();
2045 rerender = 1; // the position changes
2047 if(buttonpress == 1 && ctrl_down() &&
2048 AUTOMATION_TYPE_FLOAT == autos->get_type())
2049 rerender = 1; // special case: curve mode changed
2056 session->auto_conf->plugins /* &&
2057 mwindow->edl->session->show_assets */) {
2060 result = do_plugin_autos(track, cursor_x, cursor_y,
2061 draw, buttonpress, plugin, keyframe);
2062 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2065 if(result && (buttonpress == 1)) {
2066 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2067 update_drag_caption();
2070 else if (result && (buttonpress == 3)) {
2071 gui->keyframe_menu->update(plugin, keyframe);
2072 gui->keyframe_menu->activate_menu();
2073 rerender = 1; // the position changes
2078 // Final pass to trap event
2079 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2080 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2081 mwindow->session->current_operation == auto_operations[i]) {
2087 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2088 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2094 new_cursor = UPRIGHT_ARROW_CURSOR;
2101 void TrackCanvas::draw_keyframe_reticle()
2103 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2104 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2106 int current_op = mwindow->session->current_operation, dragging = 0;
2107 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2108 if( current_op == auto_operations[i] ) dragging = 1;
2110 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2111 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2112 draw_hairline(mwindow->session->drag_auto, RED);
2117 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2118 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2119 for( Track *track = mwindow->edl->tracks->first; track;
2120 track=track->next ) {
2121 Automation *automation = track->automation;
2122 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2123 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2124 // automation visible
2125 Autos *autos = automation->autos[i];
2126 if( !autos ) continue;
2127 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2128 auto_keyframe = auto_keyframe->next ) {
2129 draw_hairline(auto_keyframe, GREEN);
2133 if( dragging && mwindow->session->drag_auto ) {
2134 draw_hairline(mwindow->session->drag_auto, RED);
2140 void TrackCanvas::draw_auto(Auto *current,
2148 x1 = x - HANDLE_W / 2;
2149 x2 = x + HANDLE_W / 2;
2150 y1 = center_pixel + y - HANDLE_W / 2;
2151 y2 = center_pixel + y + HANDLE_W / 2;
2153 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2154 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2156 draw_box(x1, y1, x2 - x1, y2 - y1);
2160 // This draws lines for bezier in & out controls
2161 void TrackCanvas::draw_cropped_line(int x1,
2170 // Don't care about x since it is clipped by the window.
2171 // Put y coords in ascending order
2173 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2174 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2179 double slope = (double)(x2 - x1) / (y2 - y1);
2180 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2182 x1 = (int)(x1 + (min_y - y1) * slope);
2185 else if(y1 >= max_y) {
2186 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2191 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2194 else if(y2 < min_y) {
2195 x2 = (int)(x2 + (min_y - y2) * slope);
2200 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2201 if( y1 >= min_y && y1 < max_y &&
2202 y2 >= min_y && y2 < max_y )
2203 draw_line(x1, y1, x2, y2);
2207 void TrackCanvas::draw_floatauto(FloatAuto *current,
2218 int x1 = x - HANDLE_W / 2; // Center
2219 int x2 = x + HANDLE_W / 2;
2220 int y1 = center_pixel + y - HANDLE_H / 2;
2221 int y2 = center_pixel + y + HANDLE_H / 2;
2222 int ymin = center_pixel - zoom_track / 2;
2223 int ymax = center_pixel + zoom_track / 2;
2224 CLAMP(y1, ymin, ymax);
2225 CLAMP(y2, ymin, ymax);
2230 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2232 draw_box(x1, y1, x2 - x1, y2 - y1);
2235 // show bezier control points (only) if this
2236 // floatauto doesn't adjust it's tangents automatically
2237 if(current->curve_mode != FloatAuto::FREE &&
2238 current->curve_mode != FloatAuto::TFREE)
2242 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2244 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2247 inline int quantize(float f) { return (int)floor(f + 0.5); }
2249 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2250 int x, int y, int cp_x, int cp_y, int center_pixel,
2251 int zoom_track, int color)
2252 // draw the tangent and a handle for given bézier ctrl point
2254 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2256 float slope = (float)(cp_y - y)/(cp_x - x);
2257 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2259 cp_x = x + quantize((cp_y - y) / slope);
2262 cp_y += center_pixel;
2264 // drawing the tangent as a dashed line...
2265 int const dash = HANDLE_W;
2266 int const gap = HANDLE_W / 2;
2267 float sx = 3 * (cp_x - x) / 4.;
2270 // q is the x displacement for a unit line of slope
2271 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2273 float dist = 1/q * sx;
2279 float sy = slope * sx, ey = slope * ex;
2280 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2287 int r = HANDLE_W / 2;
2288 int cp_x1 = cp_x - r;
2289 int cp_y1 = cp_y - r;
2291 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2293 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2298 int TrackCanvas::test_auto(Auto *current,
2299 int x, int y, int center_pixel, int zoom_track,
2300 int cursor_x, int cursor_y, int buttonpress)
2305 x1 = x - HANDLE_W / 2;
2306 x2 = x + HANDLE_W / 2;
2307 y1 = center_pixel + y - HANDLE_H / 2;
2308 y2 = center_pixel + y + HANDLE_H / 2;
2309 int ymin = center_pixel - zoom_track / 2;
2310 int ymax = center_pixel + zoom_track / 2;
2311 CLAMP(y1, ymin, ymax);
2312 CLAMP(y2, ymin, ymax);
2314 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2316 if(buttonpress && buttonpress != 3)
2318 mwindow->session->drag_auto = current;
2319 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2320 // Toggle Autos don't respond to vertical zoom, they always show up
2321 // with "on" == 100% == line on top
2322 mwindow->session->drag_start_position = current->position;
2323 mwindow->session->drag_origin_x = cursor_x;
2324 mwindow->session->drag_origin_y = cursor_y;
2329 if(buttonpress && buttonpress != 3 && result)
2331 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2332 mwindow->undo->update_undo_before();
2338 // some Helpers for test_floatauto(..)
2339 // and for dragging the tangents/ctrl points
2340 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2341 float cursor_x, float cursor_y)
2343 // Control point switched off?
2344 if( x0 == ctrl_x ) return 0.0;
2345 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2346 double x = cursor_x-x0, y = cursor_y-y0;
2347 // wrong side of ctrl handle
2348 if( x*x1 < 0 ) return 0.0;
2349 // outside handle radius
2350 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2351 double xx1 = x1*x1, yy1 = y1*y1;
2352 double xx = x*x, yy = y*y;
2353 // distance squared from cursor to cursor projected to line from ctrl to handle
2354 // along a line perpendicular to line from ctrl to handle (closest approach)
2355 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2356 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2357 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2362 float levered_position(float position, float ref_pos)
2364 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2366 return ref_pos / position;
2370 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2371 // transforms automation value into current display coords,
2372 // dependant on current automation display range for the given kind of automation
2374 if(!mwindow || !mwindow->edl) return 0;
2375 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2376 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2377 float automation_range = automation_max - automation_min;
2378 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2380 return (auto_value - automation_min) / automation_range;
2385 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2386 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2387 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2391 int x1 = x - HANDLE_W / 2;
2392 int x2 = x + HANDLE_W / 2;
2393 int y1 = center_pixel + y - HANDLE_W / 2;
2394 int y2 = center_pixel + y + HANDLE_W / 2;
2395 int ymin = center_pixel - zoom_track / 2;
2396 int ymax = center_pixel + zoom_track / 2;
2397 CLAMP(y1, ymin, ymax);
2398 CLAMP(y2, ymin, ymax);
2400 int in_x1 = in_x - HANDLE_W / 2;
2401 int in_x2 = in_x + HANDLE_W / 2;
2402 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2403 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2404 CLAMP(in_y1, ymin, ymax);
2405 CLAMP(in_y2, ymin, ymax);
2407 int out_x1 = out_x - HANDLE_W / 2;
2408 int out_x2 = out_x + HANDLE_W / 2;
2409 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2410 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2411 CLAMP(out_y1, ymin, ymax);
2412 CLAMP(out_y2, ymin, ymax);
2415 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2416 // buttonpress could be the start of a drag operation
2417 #define INIT_DRAG(POS,VAL) \
2418 mwindow->session->drag_auto = current; \
2419 mwindow->session->drag_origin_x = cursor_x; \
2420 mwindow->session->drag_origin_y = cursor_y; \
2421 mwindow->session->drag_start_position = (POS); \
2422 mwindow->session->drag_start_percentage = (VAL);
2424 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2427 // without modifier we are manipulating the automation node
2428 // with ALT it's about dragging only the value of the node
2429 // with SHIFT the value snaps to the value of neighbouring nodes
2430 // CTRL indicates we are rather manipulating the tangent(s) of the node
2434 if( WITHIN(x1,x2,y1,y2))
2435 { // cursor hits node
2438 if(buttonpress && (buttonpress != 3))
2440 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2441 mwindow->session->drag_handle = 0;
2446 if( WITHIN(x1,x2,y1,y2))
2449 if(buttonpress && (buttonpress != 3))
2451 // could be ctrl-click or ctrl-drag
2452 // click would cycle through tangent modes
2453 ((FloatAuto*)current)->toggle_curve_mode();
2455 // drag will start dragging the tangent, if applicable
2456 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2457 mwindow->session->drag_handle = 0;
2461 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2464 if( in_x != x && current->position > 0 &&
2465 (FloatAuto::FREE == current->curve_mode ||
2466 FloatAuto::TFREE == current->curve_mode))
2467 // act on in control handle only if
2468 // tangent is significant and is editable (not automatically choosen)
2470 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2471 // either cursor in ctrl-point handle or cursor on tangent line
2472 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2474 if(buttonpress && (buttonpress != 3)) {
2475 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2477 mwindow->session->drag_handle = 1;
2478 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2479 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2480 value_to_percentage(new_invalue, autogrouptype))
2487 (FloatAuto::FREE == current->curve_mode ||
2488 FloatAuto::TFREE == current->curve_mode))
2489 // act on out control only if tangent is significant and is editable
2491 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2492 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2494 if(buttonpress && (buttonpress != 3)) {
2495 if(lever == 0.0) lever=1.0;
2497 mwindow->session->drag_handle = 2;
2498 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2499 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2500 value_to_percentage(new_outvalue, autogrouptype))
2504 } // end ctrl_down()
2510 // 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",
2511 // mwindow->session->drag_handle,
2516 if(buttonpress && (buttonpress != 3) && result)
2518 mwindow->undo->update_undo_before();
2525 // Get the float value & y for position x on the canvas
2526 #define X_TO_FLOATLINE(x) \
2527 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2528 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2529 /* Call by reference fails for some reason here */ \
2530 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2531 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2532 double position = unit_start + x * zoom_units; \
2534 if(position2 > position1) \
2537 (value2 - value1) * \
2538 (position - position1) / \
2539 (position2 - position1); \
2545 AUTOMATIONCLAMPS(value, autogrouptype); \
2546 int y = center_pixel + \
2547 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2550 void TrackCanvas::draw_floatline(int center_pixel,
2551 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2552 double unit_start, double zoom_units, double yscale,
2553 int x1, int y1, int x2, int y2,
2554 int color, int autogrouptype)
2556 // Solve bezier equation for either every pixel or a certain large number of
2559 // Not using slope intercept
2561 int prev_y = y1 + center_pixel;
2564 // Call by reference fails for some reason here
2565 FloatAuto *previous1 = previous, *next1 = next;
2566 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2567 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2568 float automation_range = automation_max - automation_min;
2570 for(int x = x1; x < x2; x++)
2572 // Interpolate value between frames
2576 y >= center_pixel - yscale / 2 &&
2577 y < center_pixel + yscale / 2 - 1)
2579 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2581 // (int)(center_pixel - yscale / 2),
2582 // (int)(center_pixel + yscale / 2 - 1));
2584 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2585 draw_line(x - 1, prev_y , x, y );
2595 int TrackCanvas::test_floatline(int center_pixel,
2610 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2611 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2612 float automation_range = automation_max - automation_min;
2613 FloatAuto *previous1 = 0, *next1 = 0;
2614 X_TO_FLOATLINE(cursor_x);
2616 if(cursor_x >= x1 &&
2618 cursor_y >= y - HANDLE_W / 2 &&
2619 cursor_y < y + HANDLE_W / 2 &&
2625 if(buttonpress == 3)
2633 mwindow->undo->update_undo_before();
2634 double position = autos->track->from_units(position1);
2635 position = mwindow->edl->align_to_frame(position, 0);
2636 int64_t new_position = autos->track->to_units(position,0);
2637 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2638 ((FloatAuto*)current)->set_value(value);
2639 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2640 mwindow->session->drag_start_position = current->position;
2641 mwindow->session->drag_origin_x = cursor_x;
2642 mwindow->session->drag_origin_y = cursor_y;
2643 mwindow->session->drag_handle = 0;
2652 void TrackCanvas::synchronize_autos(float change,
2653 Track *skip, FloatAuto *fauto, int fill_gangs)
2655 // Handles the special case of modifying a fadeauto
2656 // when there are ganged faders on several tracks
2657 // (skip and fauto may be NULL if fill_gangs==-1)
2659 if( fill_gangs > 0 && skip->gang ) {
2660 double position = skip->from_units(fauto->position);
2661 int autoidx = fauto->autos->autoidx;
2663 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2664 if( (current->data_type == skip->data_type || get_double_click()) &&
2665 current->gang && current->record && current != skip ) {
2666 int64_t current_position = current->to_units(position, 1);
2667 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2668 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2669 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2670 FloatAuto *previous = 0, *next = 0;
2671 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2673 // create keyframe on neighbouring track at the point in time given by fauto
2674 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2675 float new_value = init_value + change;
2676 CLAMP(new_value, auto_min, auto_max);
2677 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2678 keyframe->set_value(new_value);
2681 // keyframe exists, just change it
2682 float new_value = keyframe->get_value() + change;
2683 CLAMP(new_value, auto_min, auto_max);
2684 keyframe->adjust_to_new_coordinates(current_position, new_value);
2685 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2688 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2692 else if( !fill_gangs ) {
2693 double position = skip->from_units(fauto->position);
2695 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2696 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2697 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2698 float new_value = keyframe->get_value() + change;
2700 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2701 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2702 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2708 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2709 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2710 keyframe->autos->remove_nonsequential(
2713 mwindow->session->drag_auto_gang->remove_all();
2718 void TrackCanvas::draw_toggleline(int center_pixel,
2724 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2728 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2732 int TrackCanvas::test_toggleline(Autos *autos,
2743 if(cursor_x >= x1 && cursor_x < x2)
2745 int miny = center_pixel + y1 - HANDLE_W / 2;
2746 int maxy = center_pixel + y1 + HANDLE_W / 2;
2747 if(cursor_y >= miny && cursor_y < maxy)
2752 if(buttonpress == 3)
2760 double position = (double)(cursor_x +
2761 mwindow->edl->local_session->view_start[pane->number]) *
2762 mwindow->edl->local_session->zoom_sample /
2763 mwindow->edl->session->sample_rate;
2764 int64_t unit_position = autos->track->to_units(position, 0);
2765 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2767 mwindow->undo->update_undo_before();
2769 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2770 ((IntAuto*)current)->value = new_value;
2771 // Toggle Autos don't respond to vertical zoom, they always show up
2772 // with "on" == 100% == line on top
2773 mwindow->session->drag_start_percentage = (float)new_value;
2774 mwindow->session->drag_start_position = current->position;
2775 mwindow->session->drag_origin_x = cursor_x;
2776 mwindow->session->drag_origin_y = cursor_y;
2784 void TrackCanvas::calculate_viewport(Track *track,
2785 double &view_start, // Seconds
2787 double &view_end, // Seconds
2791 double &zoom_sample,
2794 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2795 mwindow->edl->local_session->zoom_sample /
2796 mwindow->edl->session->sample_rate;
2797 unit_start = track->to_doubleunits(view_start);
2798 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2800 mwindow->edl->local_session->zoom_sample /
2801 mwindow->edl->session->sample_rate;
2802 unit_end = track->to_doubleunits(view_end);
2803 yscale = mwindow->edl->local_session->zoom_track;
2804 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2805 center_pixel = (int)(track->y_pixel -
2806 mwindow->edl->local_session->track_start[pane->number] +
2808 (mwindow->edl->session->show_titles ?
2809 mwindow->theme->get_image("title_bg_data")->get_h() :
2811 zoom_sample = mwindow->edl->local_session->zoom_sample;
2813 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2816 float TrackCanvas::percentage_to_value(float percentage,
2824 if(percentage > 0.5)
2831 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2832 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2833 float automation_range = automation_max - automation_min;
2835 result = percentage * automation_range + automation_min;
2838 FloatAuto *ptr = (FloatAuto*)reference;
2839 result -= ptr->get_value();
2841 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2847 void TrackCanvas::calculate_auto_position(double *x, double *y,
2848 double *in_x, double *in_y, double *out_x, double *out_y,
2849 Auto *current, double unit_start, double zoom_units, double yscale,
2852 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2853 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2854 float automation_range = automation_max - automation_min;
2855 FloatAuto *ptr = (FloatAuto*)current;
2856 *x = (double)(ptr->position - unit_start) / zoom_units;
2857 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2860 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2861 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2865 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2866 automation_min) / automation_range - 0.5) * -yscale;
2870 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2871 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2875 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2876 automation_min) / automation_range - 0.5) * -yscale;
2881 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2882 int draw, int buttonpress, int x_offset, int y_offset, int color,
2883 Auto* &auto_instance, int autogrouptype)
2886 int center_pixel, draw_auto;
2887 double view_start, unit_start;
2888 double view_end, unit_end, yscale;
2889 double zoom_sample, zoom_units;
2890 double in_x2, in_y2, out_x2, out_y2;
2896 if(draw) set_color(color);
2898 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2899 yscale, center_pixel, zoom_sample, zoom_units);
2901 // Get first auto before start
2902 Auto *current = 0, *previous = 0;
2904 for( current = autos->last;
2905 current && current->position >= unit_start;
2906 current = PREVIOUS ) ;
2908 Auto *first_auto = current ? current :
2909 autos->first ? autos->first : autos->default_auto;
2911 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2913 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2914 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2919 current = autos->first;
2928 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2929 current, unit_start, zoom_units, yscale, autogrouptype);
2937 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2942 ay2 = ay + slope * (get_w() - ax);
2946 ay = ay + slope * (0 - ax);
2950 // Draw or test handle
2951 if( current && !result && current != autos->default_auto ) {
2952 if( !draw && track->record ) {
2953 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
2954 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
2955 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
2956 buttonpress, autogrouptype);
2958 auto_instance = current;
2960 if( draw && draw_auto ) {
2961 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
2962 (int)in_x2 + x_offset, (int)in_y2,
2963 (int)out_x2 + x_offset, (int)out_y2,
2964 (int)center_pixel + y_offset, (int)yscale, color);
2968 // Draw or test joining line
2969 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
2970 result = test_floatline(center_pixel,
2971 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2972 // Exclude auto coverage from the end of the line. The auto overlaps
2973 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
2974 buttonpress, autogrouptype);
2977 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
2978 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2979 (int)ax, (int)ay, (int)ax2, (int)ay2,
2980 color, autogrouptype);
2988 } while( current && current->position <= unit_end && !result );
2990 if( ax < get_w() && !result ) {
2991 ax2 = get_w(); ay2 = ay;
2992 if(!draw && track->record /* && buttonpress != 3 */ ) {
2993 result = test_floatline(center_pixel,
2994 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2995 (int)ax, (int)ax2, cursor_x, cursor_y,
2996 buttonpress, autogrouptype);
2999 draw_floatline(center_pixel,
3000 (FloatAuto*)previous, (FloatAuto*)current,
3001 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3002 (int)ax, (int)ay, (int)ax2, (int)ay2,
3003 color, autogrouptype);
3010 int TrackCanvas::do_int_autos(Track *track,
3019 Auto *&auto_instance)
3030 double ax, ay, ax2, ay2;
3034 if(draw) set_color(color);
3036 calculate_viewport(track,
3047 double high = -yscale * 0.8 / 2;
3048 double low = yscale * 0.8 / 2;
3050 // Get first auto before start
3052 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3058 ay = ((IntAuto*)current)->value > 0 ? high : low;
3063 current = autos->first ? autos->first : autos->default_auto;
3067 ay = ((IntAuto*)current)->value > 0 ? high : low;
3080 ax2 = (double)(current->position - unit_start) / zoom_units;
3081 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3089 if(ax2 > get_w()) ax2 = get_w();
3091 if(current && !result)
3093 if(current != autos->default_auto)
3099 result = test_auto(current,
3108 auto_instance = current;
3113 (int)ax2 + x_offset,
3114 (int)ay2 + y_offset,
3126 if(track->record /* && buttonpress != 3 */)
3128 result = test_toggleline(autos,
3141 draw_toggleline(center_pixel + y_offset,
3149 }while(current && current->position <= unit_end && !result);
3151 if(ax < get_w() && !result)
3157 if(track->record /* && buttonpress != 3 */)
3159 result = test_toggleline(autos,
3171 draw_toggleline(center_pixel + y_offset,
3180 int TrackCanvas::do_autos(Track *track,
3187 Auto * &auto_instance,
3201 calculate_viewport(track,
3214 for(current = autos->first; current && !result; current = NEXT)
3216 if(current->position >= unit_start && current->position < unit_end)
3219 x = (int64_t)((double)(current->position - unit_start) /
3220 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3221 y = center_pixel - pixmap->get_h() / 2;
3225 if(cursor_x >= x && cursor_y >= y &&
3226 cursor_x < x + pixmap->get_w() &&
3227 cursor_y < y + pixmap->get_h())
3230 auto_instance = current;
3232 if(buttonpress && (buttonpress != 3))
3234 mwindow->session->drag_auto = current;
3235 mwindow->session->drag_start_position = current->position;
3236 mwindow->session->drag_origin_x = cursor_x;
3237 mwindow->session->drag_origin_y = cursor_y;
3239 double position = autos->track->from_units(current->position);
3240 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3241 mwindow->edl->local_session->get_selectionend(1)) /
3246 mwindow->edl->local_session->set_selectionstart(position);
3247 mwindow->edl->local_session->set_selectionend(position);
3250 if(position < center)
3252 mwindow->edl->local_session->set_selectionstart(position);
3255 mwindow->edl->local_session->set_selectionend(position);
3262 draw_pixmap(pixmap, x, y);
3270 // so this means it is always >0 when keyframe is found
3271 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3272 int draw, int buttonpress, Plugin* &keyframe_plugin,
3273 KeyFrame* &keyframe_instance)
3286 if(!track->expand_view) return 0;
3288 calculate_viewport(track,
3300 for(int i = 0; i < track->plugin_set.total && !result; i++)
3302 PluginSet *plugin_set = track->plugin_set.values[i];
3303 int center_pixel = (int)(track->y_pixel -
3304 mwindow->edl->local_session->track_start[pane->number] +
3305 mwindow->edl->local_session->zoom_track +
3306 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3307 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3309 for(Plugin *plugin = (Plugin*)plugin_set->first;
3311 plugin = (Plugin*)plugin->next)
3313 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3314 keyframe && !result;
3315 keyframe = (KeyFrame*)keyframe->next)
3317 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3318 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3320 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3321 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3323 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3326 if(cursor_x >= x && cursor_y >= y &&
3327 cursor_x < x + keyframe_pixmap->get_w() &&
3328 cursor_y < y + keyframe_pixmap->get_h())
3331 keyframe_plugin = plugin;
3332 keyframe_instance = keyframe;
3336 mwindow->session->drag_auto = keyframe;
3337 mwindow->session->drag_start_position = keyframe->position;
3338 mwindow->session->drag_origin_x = cursor_x;
3339 mwindow->session->drag_origin_y = cursor_y;
3341 double position = track->from_units(keyframe->position);
3342 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3343 mwindow->edl->local_session->get_selectionend(1)) /
3348 mwindow->edl->local_session->set_selectionstart(position);
3349 mwindow->edl->local_session->set_selectionend(position);
3352 if(position < center)
3354 mwindow->edl->local_session->set_selectionstart(position);
3357 mwindow->edl->local_session->set_selectionend(position);
3362 draw_pixmap(keyframe_pixmap,
3372 // if(buttonpress && buttonpress != 3 && result)
3374 // mwindow->undo->update_undo_before();
3380 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3382 Track *track = auto_keyframe->autos->track;
3383 int autogrouptype = auto_keyframe->autos->get_type();
3386 double view_start, unit_start;
3387 double view_end, unit_end, yscale;
3388 double zoom_sample, zoom_units;
3390 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3391 yscale, center_pixel, zoom_sample, zoom_units);
3393 double ax = 0, ay = 0;
3394 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3395 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3398 draw_line(ax, 0, ax, get_h());
3402 void TrackCanvas::draw_overlays()
3404 int new_cursor, update_cursor, rerender;
3406 // Move background pixmap to foreground pixmap
3407 draw_pixmap(background_pixmap,
3416 draw_inout_points();
3419 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3426 draw_brender_range();
3428 // Highlighted areas
3429 draw_highlighting();
3432 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3435 if(pane->cursor) pane->cursor->restore(1);
3441 draw_playback_cursor();
3443 draw_keyframe_reticle();
3448 int TrackCanvas::activate()
3452 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3453 //BC_Signals::dump_stack();
3454 get_top_level()->deactivate();
3456 set_active_subwindow(this);
3457 pane->cursor->activate();
3458 gui->focused_pane = pane->number;
3463 int TrackCanvas::deactivate()
3468 pane->cursor->deactivate();
3474 void TrackCanvas::update_drag_handle()
3476 double new_position;
3477 int cursor_x = get_cursor_x();
3481 mwindow->edl->local_session->view_start[pane->number]) *
3482 mwindow->edl->local_session->zoom_sample /
3483 mwindow->edl->session->sample_rate;
3486 mwindow->edl->align_to_frame(new_position, 0);
3488 if( ctrl_down() && alt_down() ) {
3489 #define snapper(v) do { \
3491 if( pos < 0 ) break; \
3492 double dist = fabs(new_position - pos); \
3493 if( dist >= snap_min ) break; \
3494 snap_position = pos; snap_min = dist; \
3496 double snap_position = new_position;
3497 double snap_min = DBL_MAX;
3498 if( mwindow->edl->local_session->inpoint_valid() )
3499 snapper(mwindow->edl->local_session->get_inpoint());
3500 if( mwindow->edl->local_session->outpoint_valid() )
3501 snapper(mwindow->edl->local_session->get_outpoint());
3502 snapper(mwindow->edl->prev_edit(new_position));
3503 snapper(mwindow->edl->next_edit(new_position));
3504 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3505 if( prev_label ) snapper(prev_label->position);
3506 Label *next_label = mwindow->edl->labels->next_label(new_position);
3507 if( next_label ) snapper(next_label->position);
3508 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3509 mwindow->edl->local_session->zoom_sample -
3510 mwindow->edl->local_session->view_start[pane->number];
3511 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3513 new_position = snap_position;
3518 if(new_position != mwindow->session->drag_position)
3520 mwindow->session->drag_position = new_position;
3521 gui->mainclock->update(new_position);
3524 timebar_position = new_position;
3525 gui->update_timebar(0);
3526 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3528 // mwindow->cwindow->update(1, 0, 0);
3532 int TrackCanvas::update_drag_edit()
3541 int TrackCanvas::get_drag_values(float *percentage,
3548 //int x = cursor_x - mwindow->session->drag_origin_x;
3549 //int y = cursor_y - mwindow->session->drag_origin_y;
3553 if(!current->autos->track->record) return 1;
3563 calculate_viewport(current->autos->track,
3573 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3575 mwindow->session->drag_start_percentage;
3576 if(do_clamp) CLAMP(*percentage, 0, 1);
3578 *position = Units::to_int64(zoom_units *
3579 (cursor_x - mwindow->session->drag_origin_x) +
3580 mwindow->session->drag_start_position + 0.5);
3582 if((do_clamp) && *position < 0) *position = 0;
3587 #define UPDATE_DRAG_HEAD(do_clamp) \
3588 int result = 0, center_pixel; \
3589 if(!current->autos->track->record) return 0; \
3590 double view_start, unit_start, view_end, unit_end; \
3591 double yscale, zoom_sample, zoom_units; \
3593 calculate_viewport(current->autos->track, \
3594 view_start, unit_start, view_end, unit_end, \
3595 yscale, center_pixel, zoom_sample, zoom_units); \
3597 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3598 yscale + mwindow->session->drag_start_percentage; \
3599 if(do_clamp) CLAMP(percentage, 0, 1); \
3601 int64_t position = Units::to_int64(zoom_units * \
3602 (cursor_x - mwindow->session->drag_origin_x) + \
3603 mwindow->session->drag_start_position); \
3604 if((do_clamp) && position < 0) position = 0;
3607 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3609 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3611 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3612 int x = cursor_x - mwindow->session->drag_origin_x;
3613 int y = cursor_y - mwindow->session->drag_origin_y;
3614 float value, old_value;
3616 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3617 // not really editing the node, rather start editing the curve
3618 // tangent is editable and drag movement is significant
3619 if( (FloatAuto::FREE == current->curve_mode ||
3620 FloatAuto::TFREE==current->curve_mode) &&
3621 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3622 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3625 switch(mwindow->session->drag_handle) {
3627 // Snap to nearby values
3628 old_value = current->get_value();
3630 double value1, value2, distance1, distance2;
3632 if(current->previous) {
3633 int autogrouptype = current->previous->autos->autogrouptype;
3634 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3635 value1 = ((FloatAuto*)current->previous)->get_value();
3636 distance1 = fabs(value - value1);
3637 current->set_value(value1);
3641 int autogrouptype = current->next->autos->autogrouptype;
3642 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3643 value2 = ((FloatAuto*)current->next)->get_value();
3644 distance2 = fabs(value - value2);
3645 if(!current->previous || distance2 < distance1) {
3646 current->set_value(value2);
3650 if(!current->previous && !current->next) {
3651 current->set_value( ((FloatAutos*)current->autos)->default_);
3653 value = current->get_value();
3656 int autogrouptype = current->autos->autogrouptype;
3657 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3660 if(alt_down() && !shift_down())
3661 // ALT constrains movement: fixed position, only changing the value
3662 position = mwindow->session->drag_start_position;
3664 if(value != old_value || position != current->position) {
3666 float change = value - old_value;
3667 current->adjust_to_new_coordinates(position, value);
3668 synchronize_autos(change, current->autos->track, current, 0);
3669 show_message(current, 1,", %.2f", current->get_value());
3675 int autogrouptype = current->autos->autogrouptype;
3676 value = percentage_to_value(percentage, 0, current, autogrouptype);
3677 if(value != current->get_control_in_value())
3680 // note: (position,value) need not be at the location of the ctrl point,
3681 // but could be somewhere in between on the curve (or even outward or
3682 // on the opposit side). We set the new control point such as
3683 // to point the curve through (position,value)
3684 current->set_control_in_value(
3685 value * levered_position(position - current->position,
3686 current->get_control_in_position()));
3687 synchronize_autos(0, current->autos->track, current, 0);
3688 show_message(current, 1,", %.2f", current->get_control_in_value());
3694 int autogrouptype = current->autos->autogrouptype;
3695 value = percentage_to_value(percentage, 0, current, autogrouptype);
3696 if(value != current->get_control_out_value()) {
3698 current->set_control_out_value(
3699 value * levered_position(position - current->position,
3700 current->get_control_out_position()));
3701 synchronize_autos(0, current->autos->track, current, 0);
3702 show_message(current, 1,", %.2f", current->get_control_out_value());
3710 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3712 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3714 UPDATE_DRAG_HEAD(1);
3715 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3717 if(value != current->value || position != current->position)
3720 current->value = value;
3721 current->position = position;
3722 show_message(current, 0,", %d", current->value);
3728 // Autos which can't change value through dragging.
3730 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3732 Auto *current = (Auto*)mwindow->session->drag_auto;
3735 if(position != current->position)
3738 current->position = position;
3739 show_message(current, 0,"");
3741 double position_f = current->autos->track->from_units(current->position);
3742 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3743 mwindow->edl->local_session->get_selectionend(1)) /
3747 mwindow->edl->local_session->set_selectionstart(position_f);
3748 mwindow->edl->local_session->set_selectionend(position_f);
3751 if(position_f < center_f)
3753 mwindow->edl->local_session->set_selectionstart(position_f);
3756 mwindow->edl->local_session->set_selectionend(position_f);
3763 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3765 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3768 if(position != current->position)
3770 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3771 Track *track = current->autos->track;
3772 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3773 PluginSet *pluginset;
3775 // figure out the correct pluginset & correct plugin
3777 for(int i = 0; i < track->plugin_set.total; i++)
3779 pluginset = track->plugin_set.values[i];
3780 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3782 KeyFrames *keyframes = plugin->keyframes;
3783 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3785 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3787 if (currentkeyframe == current)
3799 mwindow->session->plugin_highlighted = plugin;
3800 mwindow->session->track_highlighted = track;
3802 current->position = position;
3803 show_message(current, 0,"");
3805 double position_f = current->autos->track->from_units(current->position);
3806 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3807 mwindow->edl->local_session->get_selectionend(1)) /
3811 mwindow->edl->local_session->set_selectionstart(position_f);
3812 mwindow->edl->local_session->set_selectionend(position_f);
3815 if(position_f < center_f)
3817 mwindow->edl->local_session->set_selectionstart(position_f);
3820 mwindow->edl->local_session->set_selectionend(position_f);
3827 void TrackCanvas::update_drag_caption()
3829 switch(mwindow->session->current_operation)
3839 int TrackCanvas::cursor_motion_event()
3844 int update_clock = 0;
3845 int update_zoom = 0;
3846 int update_scroll = 0;
3847 int update_overlay = 0;
3848 int update_cursor = 0;
3851 double position = 0.;
3852 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3855 switch(mwindow->edl->session->editing_mode)
3857 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3858 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3861 switch(mwindow->session->current_operation)
3863 case DRAG_EDITHANDLE1:
3864 // Outside threshold. Upgrade status
3867 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3869 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3875 case DRAG_EDITHANDLE2:
3878 update_drag_handle();
3883 case DRAG_PLUGINHANDLE1:
3886 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3888 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3894 case DRAG_PLUGINHANDLE2:
3897 update_drag_handle();
3902 // Rubber band curves
3910 case DRAG_PROJECTOR_X:
3911 case DRAG_PROJECTOR_Y:
3912 case DRAG_PROJECTOR_Z:
3913 if(active) rerender = update_overlay =
3914 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3918 if(active) rerender = update_overlay =
3919 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3923 if(active) rerender = update_overlay =
3924 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3927 // Keyframe icons are sticky
3931 case DRAG_PLUGINKEY_PRE:
3933 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3934 mwindow->session->current_operation++;
3937 mwindow->undo->update_undo_before();
3945 if(active) rerender = update_overlay =
3946 update_drag_auto(get_cursor_x(), get_cursor_y());
3949 case DRAG_PLUGINKEY:
3950 if(active) rerender = update_overlay =
3951 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
3956 cursor_x = get_cursor_x();
3957 cursor_y = get_cursor_y();
3958 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
3959 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
3961 position = mwindow->edl->align_to_frame(position, 0);
3962 position = MAX(position, 0);
3964 if(position < selection_midpoint) {
3965 mwindow->edl->local_session->set_selectionend(selection_midpoint);
3966 mwindow->edl->local_session->set_selectionstart(position);
3968 gui->unlock_window();
3969 mwindow->cwindow->update(1, 0, 0, 0, 1);
3970 gui->lock_window("TrackCanvas::cursor_motion_event 1");
3971 // Update the faders
3972 mwindow->update_plugin_guis();
3973 gui->update_patchbay();
3976 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
3977 mwindow->edl->local_session->set_selectionend(position);
3978 // Don't que the CWindow
3981 timebar_position = mwindow->edl->local_session->get_selectionend(1);
3983 gui->hide_cursor(0);
3984 gui->draw_cursor(1);
3985 gui->update_timebar(0);
3986 gui->flash_canvas(1);
3995 if(is_event_win() && cursor_inside()) {
3997 cursor_x = get_cursor_x();
3998 position = (double)cursor_x *
3999 (double)mwindow->edl->local_session->zoom_sample /
4000 (double)mwindow->edl->session->sample_rate +
4001 (double)mwindow->edl->local_session->view_start[pane->number] *
4002 (double)mwindow->edl->local_session->zoom_sample /
4003 (double)mwindow->edl->session->sample_rate;
4004 position = mwindow->edl->align_to_frame(position, 0);
4008 for(int i = 0; i < TOTAL_PANES; i++)
4009 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4011 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4012 gui->update_timebar(0);
4014 if(do_transitions(get_cursor_x(), get_cursor_y(),
4015 0, new_cursor, update_cursor)) break;
4016 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4017 0, 0, new_cursor, update_cursor, rerender)) break;
4018 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4019 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4020 // Plugin boundaries
4021 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4022 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4023 if(do_edits(get_cursor_x(), get_cursor_y(),
4024 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4029 //printf("TrackCanvas::cursor_motion_event 1\n");
4030 if(update_cursor && new_cursor != get_cursor())
4032 set_cursor(new_cursor, 0, 1);
4035 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
4036 if(rerender && render_timer->get_difference() > 0.25 ) {
4037 render_timer->update();
4038 mwindow->restart_brender();
4039 mwindow->sync_parameters(CHANGE_PARAMS);
4040 mwindow->update_plugin_guis();
4041 gui->unlock_window();
4042 mwindow->cwindow->update(1, 0, 0, 0, 1);
4043 gui->lock_window("TrackCanvas::cursor_motion_event 2");
4047 gui->update_patchbay();
4052 if(!mwindow->cwindow->playback_engine->is_playing_back)
4053 gui->mainclock->update(position);
4057 gui->zoombar->update();
4062 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4066 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4070 if(update_overlay) {
4071 gui->draw_overlays(1);
4074 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
4078 void TrackCanvas::start_dragscroll()
4082 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4083 //printf("TrackCanvas::start_dragscroll 1\n");
4087 void TrackCanvas::stop_dragscroll()
4091 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4092 //printf("TrackCanvas::stop_dragscroll 1\n");
4096 int TrackCanvas::repeat_event(int64_t duration)
4098 if(!drag_scroll) return 0;
4099 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4101 int sample_movement = 0;
4102 int track_movement = 0;
4103 int64_t x_distance = 0;
4104 int64_t y_distance = 0;
4105 double position = 0;
4108 switch(mwindow->session->current_operation) {
4110 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4111 if(get_cursor_x() > get_w()) {
4112 x_distance = get_cursor_x() - get_w();
4113 sample_movement = 1;
4115 else if(get_cursor_x() < 0) {
4116 x_distance = get_cursor_x();
4117 sample_movement = 1;
4120 if(get_cursor_y() > get_h()) {
4121 y_distance = get_cursor_y() - get_h();
4124 else if(get_cursor_y() < 0) {
4125 y_distance = get_cursor_y();
4132 if(sample_movement) {
4133 position = (double)(get_cursor_x() +
4134 mwindow->edl->local_session->view_start[pane->number] +
4136 mwindow->edl->local_session->zoom_sample /
4137 mwindow->edl->session->sample_rate;
4138 position = mwindow->edl->align_to_frame(position, 0);
4139 position = MAX(position, 0);
4141 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4142 switch(mwindow->session->current_operation) {
4144 if(position < selection_midpoint) {
4145 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4146 mwindow->edl->local_session->set_selectionstart(position);
4148 gui->unlock_window();
4149 mwindow->cwindow->update(1, 0, 0);
4150 gui->lock_window("TrackCanvas::repeat_event");
4151 // Update the faders
4152 mwindow->update_plugin_guis();
4153 gui->update_patchbay();
4156 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4157 mwindow->edl->local_session->set_selectionend(position);
4158 // Don't que the CWindow
4163 mwindow->samplemovement(
4164 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4168 if(track_movement) {
4169 mwindow->trackmovement(y_distance, pane->number);
4175 int TrackCanvas::button_release_event()
4177 int redraw = 0, update_overlay = 0, result = 0;
4179 // printf("TrackCanvas::button_release_event %d\n",
4180 // mwindow->session->current_operation);
4182 switch(mwindow->session->current_operation) {
4183 case DRAG_EDITHANDLE2:
4184 mwindow->session->current_operation = NO_OPERATION;
4188 end_edithandle_selection();
4191 case DRAG_EDITHANDLE1:
4192 mwindow->session->current_operation = NO_OPERATION;
4197 case DRAG_PLUGINHANDLE2:
4198 mwindow->session->current_operation = NO_OPERATION;
4202 end_pluginhandle_selection();
4205 case DRAG_PLUGINHANDLE1:
4206 mwindow->session->current_operation = NO_OPERATION;
4213 // delete the drag_auto_gang first and remove out of order keys
4214 synchronize_autos(0, 0, 0, -1);
4225 case DRAG_PROJECTOR_X:
4226 case DRAG_PROJECTOR_Y:
4227 case DRAG_PROJECTOR_Z:
4228 case DRAG_PLUGINKEY:
4229 mwindow->session->current_operation = NO_OPERATION;
4230 mwindow->session->drag_handle = 0;
4231 // Remove any out-of-order keyframe
4232 if(mwindow->session->drag_auto) {
4233 mwindow->session->drag_auto->autos->remove_nonsequential(
4234 mwindow->session->drag_auto);
4235 // mwindow->session->drag_auto->autos->optimize();
4240 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4245 case DRAG_AEFFECT_COPY:
4246 case DRAG_VEFFECT_COPY:
4247 // Trap in drag stop
4252 if(mwindow->session->current_operation) {
4253 // if(mwindow->session->current_operation == SELECT_REGION) {
4254 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4257 mwindow->session->current_operation = NO_OPERATION;
4259 // Traps button release events
4267 cursor_motion_event();
4269 if(update_overlay) {
4270 gui->draw_overlays(1);
4273 gui->draw_canvas(NORMAL_DRAW, 0);
4278 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4279 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4281 Edit *edit_result = 0;
4282 int handle_result = 0;
4285 if(!mwindow->edl->session->show_assets) return 0;
4287 for(Track *track = mwindow->edl->tracks->first;
4289 track = track->next) {
4290 for(Edit *edit = track->edits->first;
4292 edit = edit->next) {
4293 int64_t edit_x, edit_y, edit_w, edit_h;
4294 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4296 if(cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4297 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4298 if(cursor_x < edit_x + HANDLE_W) {
4303 else if(cursor_x >= edit_x + edit_w - HANDLE_W) {
4317 double position = 0;
4318 if(handle_result == 0) {
4319 position = edit_result->track->from_units(edit_result->startproject);
4320 new_cursor = LEFT_CURSOR;
4322 else if(handle_result == 1) {
4323 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4324 new_cursor = RIGHT_CURSOR;
4327 // Reposition cursor
4329 mwindow->session->drag_edit = edit_result;
4330 mwindow->session->drag_handle = handle_result;
4331 mwindow->session->drag_button = get_buttonpress() - 1;
4332 mwindow->session->drag_position = position;
4333 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4334 mwindow->session->drag_origin_x = get_cursor_x();
4335 mwindow->session->drag_origin_y = get_cursor_y();
4336 mwindow->session->drag_start = position;
4338 rerender = start_selection(position);
4346 int TrackCanvas::do_plugin_handles(int cursor_x,
4350 int &update_overlay,
4354 Plugin *plugin_result = 0;
4355 int handle_result = 0;
4358 // if(!mwindow->edl->session->show_assets) return 0;
4360 for(Track *track = mwindow->edl->tracks->first;
4362 track = track->next) {
4363 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4364 PluginSet *plugin_set = track->plugin_set.values[i];
4365 for(Plugin *plugin = (Plugin*)plugin_set->first;
4367 plugin = (Plugin*)plugin->next) {
4368 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4369 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4371 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4372 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4373 if(cursor_x < plugin_x + HANDLE_W) {
4374 plugin_result = plugin;
4378 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4379 plugin_result = plugin;
4386 if(result && shift_down())
4387 mwindow->session->trim_edits = plugin_set;
4393 double position = 0;
4394 if(handle_result == 0) {
4395 position = plugin_result->track->from_units(plugin_result->startproject);
4396 new_cursor = LEFT_CURSOR;
4398 else if(handle_result == 1) {
4399 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4400 new_cursor = RIGHT_CURSOR;
4404 mwindow->session->drag_plugin = plugin_result;
4405 mwindow->session->drag_handle = handle_result;
4406 mwindow->session->drag_button = get_buttonpress() - 1;
4407 mwindow->session->drag_position = position;
4408 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4409 mwindow->session->drag_origin_x = get_cursor_x();
4410 mwindow->session->drag_origin_y = get_cursor_y();
4411 mwindow->session->drag_start = position;
4413 rerender = start_selection(position);
4422 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4426 // if(!mwindow->edl->session->show_assets) return 0;
4428 for(Track *track = mwindow->edl->tracks->first;
4430 track = track->next) {
4431 int64_t track_x, track_y, track_w, track_h;
4432 track_dimensions(track, track_x, track_y, track_w, track_h);
4434 if(button_press && get_buttonpress() == RIGHT_BUTTON &&
4435 cursor_y >= track_y && cursor_y < track_y + track_h) {
4436 gui->edit_menu->update(track, 0);
4437 gui->edit_menu->activate_menu();
4445 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4446 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4450 if(!mwindow->edl->session->show_assets) return 0;
4452 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4454 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4455 int64_t edit_x, edit_y, edit_w, edit_h;
4456 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4458 // Cursor inside a track
4459 // Cursor inside an edit
4460 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4461 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4462 // Select duration of edit
4464 if(get_double_click() && !drag_start) {
4465 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4466 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4467 edit->track->from_units(edit->length));
4468 if(mwindow->edl->session->cursor_on_frames)
4470 mwindow->edl->local_session->set_selectionstart(
4471 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4472 mwindow->edl->local_session->set_selectionend(
4473 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4481 else if(drag_start && track->record) {
4482 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4483 // Need to create drag window
4484 mwindow->session->current_operation = DRAG_EDIT;
4485 mwindow->session->drag_edit = edit;
4486 //printf("TrackCanvas::do_edits 2\n");
4488 // Drag only one edit if ctrl is initially down
4490 mwindow->session->drag_edits->remove_all();
4491 mwindow->session->drag_edits->append(edit);
4494 // Construct list of all affected edits
4495 mwindow->edl->tracks->get_affected_edits(
4496 mwindow->session->drag_edits,
4497 edit->track->from_units(edit->startproject),
4500 mwindow->session->drag_origin_x = cursor_x;
4501 mwindow->session->drag_origin_y = cursor_y;
4502 // Where the drag started, so we know relative position inside the edit later
4503 mwindow->session->drag_position = (double)cursor_x *
4504 mwindow->edl->local_session->zoom_sample /
4505 mwindow->edl->session->sample_rate +
4506 (double)mwindow->edl->local_session->view_start[pane->number] *
4507 mwindow->edl->local_session->zoom_sample /
4508 mwindow->edl->session->sample_rate;
4511 get_abs_cursor_xy(cx, cy);
4512 cx -= mwindow->theme->get_image("clip_icon")->get_w() / 2,
4513 cy -= mwindow->theme->get_image("clip_icon")->get_h() / 2;
4514 gui->drag_popup = new BC_DragWindow(gui,
4515 mwindow->theme->get_image("clip_icon"), cx, cy);
4527 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4532 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4533 int button_press, int &redraw, int &rerender)
4542 // if(!mwindow->edl->session->show_assets) return 0;
4545 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4546 if(!track->expand_view) continue;
4548 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4549 // first check if plugins are visible at all
4550 if (!track->expand_view)
4552 PluginSet *plugin_set = track->plugin_set.values[i];
4553 for(plugin = (Plugin*)plugin_set->first;
4555 plugin = (Plugin*)plugin->next) {
4556 plugin_dimensions(plugin, x, y, w, h);
4557 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4558 MWindowGUI::visible(y, y + h, 0, get_h())) {
4559 if(cursor_x >= x && cursor_x < x + w &&
4560 cursor_y >= y && cursor_y < y + h) {
4570 // Start plugin popup
4572 if(get_buttonpress() == 3) {
4573 gui->plugin_menu->update(plugin);
4574 gui->plugin_menu->activate_menu();
4577 else if (get_double_click() && !drag_start) {
4578 // Select range of plugin on doubleclick over plugin
4579 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4580 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4581 plugin->track->from_units(plugin->length));
4582 if(mwindow->edl->session->cursor_on_frames) {
4583 mwindow->edl->local_session->set_selectionstart(
4584 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4585 mwindow->edl->local_session->set_selectionend(
4586 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4595 if(drag_start && plugin->track->record) {
4596 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4597 if(plugin->track->data_type == TRACK_AUDIO)
4598 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4599 else if(plugin->track->data_type == TRACK_VIDEO)
4600 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4602 mwindow->session->drag_plugin = plugin;
4603 mwindow->session->drag_origin_x = cursor_x;
4604 mwindow->session->drag_origin_y = cursor_y;
4605 // Where the drag started, so we know relative position inside the edit later
4606 mwindow->session->drag_position =
4607 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4608 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4610 switch(plugin->plugin_type) {
4611 case PLUGIN_STANDALONE: {
4612 PluginServer *server =
4613 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4614 if( !server ) break;
4615 VFrame *frame = server->picon;
4617 if(plugin->track->data_type == TRACK_AUDIO) {
4618 frame = mwindow->theme->get_image("aeffect_icon");
4621 frame = mwindow->theme->get_image("veffect_icon");
4625 get_abs_cursor_xy(cx, cy);
4626 cx -= frame->get_w() / 2;
4627 cy -= frame->get_h() / 2;
4628 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4631 case PLUGIN_SHAREDPLUGIN:
4632 case PLUGIN_SHAREDMODULE: {
4633 VFrame *frame = mwindow->theme->get_image("clip_icon");
4635 get_abs_cursor_xy(cx, cy);
4636 cx -= frame->get_w() / 2;
4637 cy -= frame->get_h() / 2;
4638 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4650 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4651 int button_press, int &new_cursor, int &update_cursor)
4653 Transition *transition = 0;
4657 if(/* !mwindow->edl->session->show_assets || */
4658 !mwindow->edl->session->auto_conf->transitions) return 0;
4660 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4662 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4663 if( edit->transition ) {
4664 edit_dimensions(edit, x, y, w, h);
4665 get_transition_coords(x, y, w, h);
4667 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4668 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4669 if( cursor_x >= x && cursor_x < x + w &&
4670 cursor_y >= y && cursor_y < y + h ) {
4671 transition = edit->transition;
4683 new_cursor = UPRIGHT_ARROW_CURSOR;
4685 else if(get_buttonpress() == 3) {
4686 gui->transition_menu->update(transition);
4687 gui->transition_menu->activate_menu();
4694 int TrackCanvas::button_press_event()
4697 int cursor_x, cursor_y;
4700 cursor_x = get_cursor_x();
4701 cursor_y = get_cursor_y();
4702 mwindow->session->trim_edits = 0;
4704 if(is_event_win() && cursor_inside()) {
4705 // double position = (double)cursor_x *
4706 // mwindow->edl->local_session->zoom_sample /
4707 // mwindow->edl->session->sample_rate +
4708 // (double)mwindow->edl->local_session->view_start[pane->number] *
4709 // mwindow->edl->local_session->zoom_sample /
4710 // mwindow->edl->session->sample_rate;
4717 if( get_buttonpress() == LEFT_BUTTON &&
4718 gui->mbuttons->transport->engine->command->command != STOP ) {
4719 gui->unlock_window();
4720 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4721 gui->lock_window("TrackCanvas::button_press_event");
4724 int update_overlay = 0, update_cursor = 0, rerender = 0;
4726 if(get_buttonpress() == WHEEL_UP) {
4728 mwindow->expand_sample();
4729 else if(ctrl_down())
4730 mwindow->move_left(get_w()/ 10);
4732 mwindow->move_up(get_h() / 10);
4734 else if(get_buttonpress() == WHEEL_DOWN) {
4736 mwindow->zoom_in_sample();
4737 else if(ctrl_down())
4738 mwindow->move_right(get_w() / 10);
4740 mwindow->move_down(get_h() / 10);
4742 else if(get_buttonpress() == 6) {
4744 mwindow->move_left(get_w());
4746 mwindow->move_left(get_w() / 20);
4748 mwindow->move_left(get_w() / 5);
4750 else if(get_buttonpress() == 7) {
4752 mwindow->move_right(get_w());
4754 mwindow->move_right(get_w() / 20);
4756 mwindow->move_right(get_w() / 5);
4759 switch(mwindow->edl->session->editing_mode) {
4760 // Test handles and resource boundaries and highlight a track
4761 case EDITING_ARROW: {
4762 if( do_transitions(cursor_x, cursor_y,
4763 1, new_cursor, update_cursor) ) break;
4765 if( do_keyframes(cursor_x, cursor_y,
4766 0, get_buttonpress(), new_cursor,
4767 update_cursor, rerender) ) break;
4768 // Test edit boundaries
4769 if( do_edit_handles(cursor_x, cursor_y,
4770 1, rerender, update_overlay, new_cursor,
4771 update_cursor) ) break;
4772 // Test plugin boundaries
4773 if( do_plugin_handles(cursor_x, cursor_y,
4774 1, rerender, update_overlay, new_cursor,
4775 update_cursor) ) break;
4777 if( do_edits(cursor_x, cursor_y, 1, 0,
4778 update_cursor, rerender, new_cursor,
4779 update_cursor) ) break;
4781 if( do_plugins(cursor_x, cursor_y, 0, 1,
4782 update_cursor, rerender) ) break;
4784 if( test_resources(cursor_x, cursor_y) ) break;
4786 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4791 // Test handles only and select a region
4792 case EDITING_IBEAM: {
4793 double position = (double)cursor_x *
4794 mwindow->edl->local_session->zoom_sample /
4795 mwindow->edl->session->sample_rate +
4796 (double)mwindow->edl->local_session->view_start[pane->number] *
4797 mwindow->edl->local_session->zoom_sample /
4798 mwindow->edl->session->sample_rate;
4799 //printf("TrackCanvas::button_press_event %d\n", position);
4801 if( do_transitions(cursor_x, cursor_y,
4802 1, new_cursor, update_cursor)) break;
4803 if(do_keyframes(cursor_x, cursor_y,
4804 0, get_buttonpress(), new_cursor,
4805 update_cursor, rerender)) {
4809 // Test edit boundaries
4810 if( do_edit_handles(cursor_x, cursor_y,
4811 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4812 // Test plugin boundaries
4813 if( do_plugin_handles(cursor_x, cursor_y,
4814 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4816 if( do_edits(cursor_x, cursor_y,
4817 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4819 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4821 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4822 // Highlight selection
4823 if( get_buttonpress() != LEFT_BUTTON ) break;
4824 rerender = start_selection(position);
4825 mwindow->session->current_operation = SELECT_REGION;
4832 gui->unlock_window();
4833 mwindow->cwindow->update(1, 0, 0, 0, 1);
4834 gui->lock_window("TrackCanvas::button_press_event 2");
4836 mwindow->update_plugin_guis();
4837 gui->update_patchbay();
4840 if( update_overlay ) {
4841 gui->draw_overlays(1);
4843 if( update_cursor < 0 ) {
4844 // double_click edit
4845 gui->swindow->update_selection();
4847 if( update_cursor ) {
4848 gui->update_timebar(0);
4849 gui->hide_cursor(0);
4850 gui->show_cursor(1);
4851 gui->zoombar->update();
4852 gui->flash_canvas(1);
4859 int TrackCanvas::start_selection(double position)
4862 position = mwindow->edl->align_to_frame(position, 1);
4868 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4869 mwindow->edl->local_session->get_selectionend(1)) / 2;
4871 if(position < midpoint)
4873 mwindow->edl->local_session->set_selectionstart(position);
4874 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4880 mwindow->edl->local_session->set_selectionend(position);
4881 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4882 // Don't que the CWindow for the end
4886 // Start a new selection
4888 //printf("TrackCanvas::start_selection %f\n", position);
4889 mwindow->edl->local_session->set_selectionstart(position);
4890 mwindow->edl->local_session->set_selectionend(position);
4891 selection_midpoint = position;
4899 void TrackCanvas::end_edithandle_selection()
4901 mwindow->modify_edithandles();
4904 void TrackCanvas::end_pluginhandle_selection()
4906 mwindow->modify_pluginhandles();
4910 double TrackCanvas::time_visible()
4912 return (double)get_w() *
4913 mwindow->edl->local_session->zoom_sample /
4914 mwindow->edl->session->sample_rate;
4918 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
4920 char string[BCTEXTLEN];
4921 char *cp = string, *ep = cp + sizeof(string)-1;
4922 if( show_curve_type ) {
4923 cp += snprintf(string, ep-cp, "%-8s ",
4924 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
4926 char string2[BCTEXTLEN];
4927 Units::totext(string2,
4928 current->autos->track->from_units(current->position),
4929 mwindow->edl->session->time_format,
4930 mwindow->edl->session->sample_rate,
4931 mwindow->edl->session->frame_rate,
4932 mwindow->edl->session->frames_per_foot);
4933 cp += snprintf(cp, ep-cp, "%s", string2);
4936 vsnprintf(cp, ep-cp, fmt, ap);
4938 gui->show_message(string);
4941 // Patchbay* TrackCanvas::get_patchbay()
4943 // if(pane->patchbay) return pane->patchbay;
4944 // if(gui->total_panes() == 2 &&
4945 // gui->pane[TOP_LEFT_PANE] &&
4946 // gui->pane[TOP_RIGHT_PANE])
4947 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4948 // if(gui->total_panes() == 4)
4950 // if(pane->number == TOP_RIGHT_PANE)
4951 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4953 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;