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 ) {
336 break; // Do not do anything
339 Track *track = mwindow->session->track_highlighted;
340 drop_position = track->frame_align(drop_position, 0);
341 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
344 else if( hi_track ) {
345 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
346 Edit *hi_edit = mwindow->session->edit_highlighted;
347 drop_position = hi_edit ? hi_edit->startproject : 0;
348 if( drop_position < 0 ) {
350 break; // Do not do anything
353 Track *track = mwindow->session->track_highlighted;
354 drop_position = track->frame_align(drop_position, 0);
355 mwindow->move_effect(drag_plugin, hi_track, drop_position);
363 if( mwindow->session->track_highlighted &&
364 ((mwindow->session->current_operation == DRAG_AEFFECT &&
365 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
366 (mwindow->session->current_operation == DRAG_VEFFECT &&
367 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
368 // Drop all the effects
369 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
370 Track *track = mwindow->session->track_highlighted;
372 double length = track->get_length();
374 if(mwindow->session->plugin_highlighted) {
375 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
376 length = track->from_units(mwindow->session->plugin_highlighted->length);
377 if(length <= 0) length = track->get_length();
379 else if(mwindow->session->pluginset_highlighted) {
380 start = track->from_units(plugin_set->length());
381 length = track->get_length() - start;
382 if(length <= 0) length = track->get_length();
384 else if(mwindow->edl->local_session->get_selectionend() >
385 mwindow->edl->local_session->get_selectionstart()) {
386 start = mwindow->edl->local_session->get_selectionstart();
387 length = mwindow->edl->local_session->get_selectionend() -
388 mwindow->edl->local_session->get_selectionstart();
390 // Move to a point between two edits
391 else if(mwindow->session->edit_highlighted) {
392 start = mwindow->session->track_highlighted->from_units(
393 mwindow->session->edit_highlighted->startproject);
394 length = mwindow->session->track_highlighted->from_units(
395 mwindow->session->edit_highlighted->length);
397 start = mwindow->edl->align_to_frame(start, 0);
398 mwindow->insert_effects_canvas(start, length);
401 if( mwindow->session->track_highlighted )
402 result = 1; // we have to cleanup
406 if(mwindow->session->track_highlighted) {
407 double asset_duration = 0;
408 int64_t asset_length_units = 0;
410 if(mwindow->session->current_operation == DRAG_ASSET &&
411 mwindow->session->drag_assets->total) {
412 Indexable *indexable = mwindow->session->drag_assets->values[0];
413 // we use video if we are over video and audio if we are over audio
414 if( indexable->have_video() &&
415 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
416 // Images have length -1
417 int64_t video_length = indexable->get_video_frames();
418 if (video_length < 0) {
419 if(mwindow->edl->session->si_useduration)
420 video_length = mwindow->edl->session->si_duration;
422 video_length = 1.0 / mwindow->edl->session->frame_rate ;
424 asset_duration = video_length / indexable->get_frame_rate();
426 else if( indexable->have_audio() &&
427 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
428 int64_t audio_length = indexable->get_audio_samples();
429 asset_duration = (double)audio_length / indexable->get_sample_rate();
433 break; // Do not do anything
436 else if( mwindow->session->current_operation == DRAG_ASSET &&
437 mwindow->session->drag_clips->total ) {
438 EDL *clip = mwindow->session->drag_clips->values[0];
439 asset_duration = clip->tracks->total_length();
442 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
445 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
446 int64_t drop_position = drop_edit_position (&insertion, NULL, asset_length_units);
447 if( drop_position < 0 ) {
449 break; // Do not do anything
452 Track *track = mwindow->session->track_highlighted;
453 double track_position = track->from_units(drop_position);
454 track_position = mwindow->edl->align_to_frame(track_position, 0);
457 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
458 // // Unfortunately, this is _a lot_ of work to do right
459 // printf("Problematic insertion\n");
460 // mwindow->edl->tracks->clear(track_position,
461 // track_position + asset_duration, 0);
463 mwindow->paste_assets(track_position, track, !insertion);
464 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
469 mwindow->session->current_operation = NO_OPERATION;
470 if(mwindow->session->track_highlighted) {
471 if( mwindow->session->track_highlighted->data_type ==
472 mwindow->session->drag_edit->track->data_type) {
473 int64_t drop_position = drop_edit_position(&insertion,
474 mwindow->session->drag_edit,
475 mwindow->session->drag_edit->length);
476 if( drop_position < 0 ) {
478 break; // Do not do anything
480 Track *track = mwindow->session->track_highlighted;
481 double track_position = track->from_units(drop_position);
482 track_position = mwindow->edl->align_to_frame(track_position, 0);
483 mwindow->move_edits(mwindow->session->drag_edits,
484 track, track_position, !insertion);
496 int TrackCanvas::drag_start_event()
501 int new_cursor, update_cursor;
503 if(mwindow->session->current_operation != NO_OPERATION) return 0;
506 if(do_plugins(get_drag_x(), get_drag_y(),
507 1, 0, redraw, rerender)) {
510 else if(do_edits(get_drag_x(), get_drag_y(),
511 0, 1, redraw, rerender, new_cursor, update_cursor)) {
519 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
521 // get the canvas/track position
522 Track *track = mwindow->session->track_highlighted;
523 int cursor_x = get_relative_cursor_x();
524 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
525 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
526 double position = mwindow->edl->align_to_frame(cur_pos, 1);
527 if( position <= 0 ) {
531 double cursor_position = position;
532 int64_t drop_position = track->to_units(cursor_position, 1);
533 if( moved_edit ) { // relative cursor position depends upon drop point
534 double moved_edit_start = moved_edit->track->from_units(moved_edit->startproject);
535 position -= mwindow->session->drag_position - moved_edit_start;
537 int64_t edit_position = track->to_units(position, 1);
538 int64_t grab_position = edit_position;
539 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
540 grab_position -= moved_edit_length / 2;
541 Edit *last_edit = track->edits->last;
542 if( !last_edit || edit_position >= (last_edit->startproject+last_edit->length) ) {
544 return grab_position;
547 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
548 Edit *next_edit = track->edits->first;
550 Edit *edit = next_edit; next_edit = (Edit *)edit->next;
551 int64_t edit_start = edit->startproject;
552 int64_t edit_end = edit_start + edit->length;
553 double edit_start_pos = edit->track->from_units(edit_start);
554 if( (fabs(edit_start_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
555 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
558 double edit_end_pos = edit->track->from_units(edit_end);
559 if( (fabs(edit_end_pos-cursor_position)*zoom_scale) < HANDLE_W ) {
560 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
563 if( edit != moved_edit && !edit->silence() )
564 drop_start = edit_end; // reset drop zone
566 if( next_edit == moved_edit || next_edit->silence() ) continue;
570 drop_end = INT64_MAX;
571 if( edit_position >= drop_start &&
572 edit_position+moved_edit_length < drop_end ) {
573 *is_insertion = 0; // fits in the zone
574 return edit_position;
576 if( drop_position < drop_end ) { // drop in the zone
577 if( (drop_end - drop_start) >= moved_edit_length ) {
578 *is_insertion = 0; // fits in the zone, but over the edge
579 int64_t dx0 = llabs(drop_position - drop_start);
580 int64_t dx1 = llabs(drop_position - drop_end);
581 return dx0 < dx1 ? drop_start : drop_end - moved_edit_length;
584 int64_t edit_center = (edit_start + edit_end) / 2;
585 return position < edit_center ? drop_start : drop_end;
593 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
595 // get the canvas/track position
596 Track *track = plugin_set->track;
597 double moved_plugin_length = moved_plugin->track->from_units(moved_plugin->length);
598 int64_t track_plugin_length = track->to_units(moved_plugin_length, 0);
599 int cursor_x = get_relative_cursor_x();
600 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
601 double cur_pos = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
602 double position = mwindow->edl->align_to_frame(cur_pos, 1);
603 if( position <= 0 ) return 0;
604 int64_t drop_position = track->to_units(position, 1);
605 Plugin *last_plugin = (Plugin *)plugin_set->last;
606 if( !last_plugin ) return drop_position;
607 double plugin_set_end = last_plugin->track->from_units(last_plugin->startproject+last_plugin->length);
608 if( position >= plugin_set_end ) return drop_position;
609 double moved_plugin_start = moved_plugin->track->from_units(moved_plugin->startproject);
610 position -= mwindow->session->drag_position - moved_plugin_start;
611 int64_t plugin_position = track->to_units(position, 1);
613 int64_t drop_start = 0, drop_end = 0; // drop zone boundries
614 Plugin *next_plugin = (Plugin *)plugin_set->first;
615 while( next_plugin ) {
616 Plugin *plugin = next_plugin; next_plugin = (Plugin *)plugin->next;
617 int64_t plugin_start = plugin->startproject;
618 int64_t plugin_end = plugin_start + plugin->length;
619 double plugin_end_pos = plugin->track->from_units(plugin_end);
620 int64_t track_plugin_end = track->to_units(plugin_end_pos, 0);
621 if( plugin != moved_plugin && !plugin->silence() )
622 drop_start = track_plugin_end;
624 if( next_plugin == moved_plugin || next_plugin->silence() ) continue;
625 drop_end = track_plugin_end;
628 drop_end = INT64_MAX;
629 if( plugin_position >= drop_start && // fits in the zone
630 plugin_position+track_plugin_length < drop_end ) {
631 return plugin_position;
633 if( drop_position < drop_end ) { // drop in the zone
634 if( (drop_end - drop_start) >= track_plugin_length ) {
635 int64_t dx0 = llabs(drop_position - drop_start);
636 int64_t dx1 = llabs(drop_position - drop_end);
637 return dx0 < dx1 ? drop_start : drop_end - track_plugin_length;
645 void TrackCanvas::draw(int mode, int hide_cursor)
650 // Swap pixmap layers
651 if(get_w() != background_pixmap->get_w() ||
652 get_h() != background_pixmap->get_h())
654 delete background_pixmap;
655 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
658 // Cursor disappears after resize when this is called.
659 // Cursor doesn't redraw after editing when this isn't called.
660 if(pane->cursor && hide_cursor) pane->cursor->hide();
661 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
663 if(debug) PRINT_TRACE
664 draw_resources(mode);
666 if(debug) PRINT_TRACE
668 if(debug) PRINT_TRACE
671 void TrackCanvas::update_cursor(int flush)
673 switch(mwindow->edl->session->editing_mode)
675 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
676 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
681 void TrackCanvas::test_timer()
683 if(resource_timer->get_difference() > 1000 &&
687 hourglass_enabled = 1;
692 void TrackCanvas::draw_indexes(Indexable *indexable)
694 IndexState *index_state = indexable->index_state;
695 // Don't redraw raw samples
696 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
698 draw_resources(0, 1, indexable);
703 void TrackCanvas::draw_resources(int mode,
705 Indexable *indexable)
709 if(debug) PRINT_TRACE
711 // can't stop thread here, because this is called for every pane
712 // if(mode != IGNORE_THREAD && !indexes_only)
713 // gui->resource_thread->stop_draw(!indexes_only);
715 if(mode != IGNORE_THREAD &&
717 !gui->resource_thread->interrupted)
719 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
722 BC_Signals::dump_stack();
725 if(debug) PRINT_TRACE
727 resource_timer->update();
729 // Age resource pixmaps for deletion
731 for(int i = 0; i < gui->resource_pixmaps.total; i++)
732 gui->resource_pixmaps.values[i]->visible--;
734 if(mode == FORCE_REDRAW)
735 gui->resource_pixmaps.remove_all_objects();
737 if(debug) PRINT_TRACE
740 for(Track *current = mwindow->edl->tracks->first;
744 if(debug) PRINT_TRACE
745 for(Edit *edit = current->edits->first; edit; edit = edit->next)
747 if(debug) PRINT_TRACE
748 if( current->data_type != TRACK_SUBTITLE )
749 if(!edit->asset && !edit->nested_edl) continue;
752 if(edit->track->data_type != TRACK_AUDIO) continue;
754 if(edit->nested_edl &&
755 strcmp(indexable->path, edit->nested_edl->path)) continue;
758 strcmp(indexable->path, edit->asset->path)) continue;
761 if(debug) PRINT_TRACE
763 int64_t edit_x, edit_y, edit_w, edit_h;
764 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
767 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
768 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
770 int64_t pixmap_x, pixmap_w, pixmap_h;
771 if(debug) PRINT_TRACE
773 // Search for existing pixmap containing edit
774 for(int i = 0; i < gui->resource_pixmaps.total; i++)
776 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
777 // Same pointer can be different edit if editing took place
778 if(pixmap->edit_id == edit->id &&
779 pixmap->pane_number == pane->number)
785 if(debug) PRINT_TRACE
787 // Get new size, offset of pixmap needed
788 get_pixmap_size(edit,
794 if(debug) PRINT_TRACE
797 if(pixmap_w && pixmap_h)
799 // Create pixmap if it doesn't exist
800 ResourcePixmap* pixmap = create_pixmap(edit, edit_x,
801 pixmap_x, pixmap_w, pixmap_h);
802 // Resize it if it's bigger
803 if( pixmap_w > pixmap->pixmap_w ||
804 pixmap_h > pixmap->pixmap_h)
805 pixmap->resize(pixmap_w, pixmap_h);
806 pixmap->update_settings(edit, edit_x, edit_w,
807 pixmap_x, pixmap_w, pixmap_h);
809 if( current->show_assets() )
810 pixmap->draw_data(this,
811 edit, edit_x, edit_w,
812 pixmap_x, pixmap_w, pixmap_h,
816 clear_box(0,0, pixmap_w,pixmap_h, pixmap);
819 if( current->show_titles() )
820 pixmap->draw_title(this,
821 edit, edit_x, edit_w,
823 // Resize it if it's smaller
824 if(pixmap_w < pixmap->pixmap_w ||
825 pixmap_h < pixmap->pixmap_h)
826 pixmap->resize(pixmap_w, pixmap_h);
828 // Copy pixmap to background canvas
829 background_pixmap->draw_pixmap(pixmap,
831 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
835 if(debug) PRINT_TRACE
842 // Delete unused pixmaps
843 if(debug) PRINT_TRACE
845 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
846 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
848 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
849 delete gui->resource_pixmaps.values[i];
850 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
852 if(debug) PRINT_TRACE
854 if(hourglass_enabled)
857 hourglass_enabled = 0;
859 if(debug) PRINT_TRACE
861 // can't stop thread here, because this is called for every pane
862 // if(mode != IGNORE_THREAD && !indexes_only)
863 // gui->resource_thread->start_draw();
864 if(debug) PRINT_TRACE
869 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
875 ResourcePixmap *result = 0;
877 for(int i = 0; i < gui->resource_pixmaps.total; i++)
879 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
880 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
881 gui->resource_pixmaps.values[i]->pane_number == pane->number)
883 result = gui->resource_pixmaps.values[i];
891 result = new ResourcePixmap(mwindow,
898 gui->resource_pixmaps.append(result);
901 // result->resize(pixmap_w, pixmap_h);
905 void TrackCanvas::get_pixmap_size(Edit *edit,
913 // Align x on frame boundaries
916 // switch(edit->edits->track->data_type)
928 if(pixmap_x + pixmap_w > get_w())
930 pixmap_w = get_w() - pixmap_x;
937 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
938 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
939 // int64_t pixel_increment = MAX(picon_w, frame_w);
940 // int64_t pixmap_x1 = edit_x;
941 // int64_t pixmap_x2 = edit_x + edit_w;
945 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
950 // if(pixmap_x2 > get_w())
952 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
956 // pixmap_x = pixmap_x1;
957 // pixmap_w = pixmap_x2 - pixmap_x1;
962 pixmap_h = mwindow->edl->local_session->zoom_track;
963 Track *track = edit->edits->track;
964 if( track->show_titles() )
965 pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
966 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
969 void TrackCanvas::edit_dimensions(Edit *edit,
970 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
972 x = Units::round(edit->track->from_units(edit->startproject) *
973 mwindow->edl->session->sample_rate /
974 mwindow->edl->local_session->zoom_sample -
975 mwindow->edl->local_session->view_start[pane->number]);
977 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
979 // Method for calculating w so when edits are together we never get off by one error due to rounding
980 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
981 mwindow->edl->session->sample_rate /
982 mwindow->edl->local_session->zoom_sample -
983 mwindow->edl->local_session->view_start[pane->number]);
987 if( edit->track->show_titles() )
988 edit_h += mwindow->theme->get_image("title_bg_data")->get_h();
989 if( edit->track->show_assets() )
990 edit_h += resource_h();
994 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
998 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
999 h = track->vertical_span(mwindow->theme);
1003 void TrackCanvas::draw_paste_destination()
1005 //int cursor_x = get_relative_cursor_x();
1006 //int cursor_y = get_relative_cursor_y();
1007 int current_atrack = 0;
1008 int current_vtrack = 0;
1009 int current_aedit = 0;
1010 int current_vedit = 0;
1016 //if(pane->number == BOTTOM_RIGHT_PANE)
1017 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1019 if((mwindow->session->current_operation == DRAG_ASSET &&
1020 (mwindow->session->drag_assets->total ||
1021 mwindow->session->drag_clips->total)) ||
1022 (mwindow->session->current_operation == DRAG_EDIT &&
1023 mwindow->session->drag_edits->total)) {
1024 Indexable *indexable = 0;
1028 if(mwindow->session->current_operation == DRAG_ASSET &&
1029 mwindow->session->drag_assets->size())
1030 indexable = mwindow->session->drag_assets->get(0);
1032 if(mwindow->session->current_operation == DRAG_ASSET &&
1033 mwindow->session->drag_clips->size())
1034 clip = mwindow->session->drag_clips->get(0);
1036 int has_audio = 0, has_video = 0;
1037 double paste_audio_length = 0, paste_video_length = 0;
1038 double paste_audio_position = -1, paste_video_position = -1;
1041 has_audio = indexable->have_audio();
1042 paste_audio_length = !has_audio ? 0 :
1043 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1044 has_video = indexable->have_video();
1045 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1046 // Images have length -1
1047 if( asset && asset->video_data && asset->video_length < 0 ) {
1048 paste_video_length = mwindow->edl->session->si_useduration ?
1049 mwindow->edl->session->si_duration / asset->frame_rate :
1050 1.0 / asset->frame_rate ; // 1 frame
1053 paste_video_length = !has_video ? 0 :
1054 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1058 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1059 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1060 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1061 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1064 // 'Align cursor on frame' lengths calculations
1065 if( mwindow->edl->session->cursor_on_frames ) {
1066 double fps = mwindow->edl->session->frame_rate;
1067 double aud = floor(paste_audio_length * fps) / fps;
1068 double vid = floor(paste_video_length * fps) / fps;
1069 double length = has_video && has_audio ?
1070 aud < vid ? aud : vid :
1072 has_audio ? aud : 0;
1073 paste_video_length = paste_audio_length = length;
1076 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1078 switch( mwindow->session->track_highlighted->data_type ) {
1079 case TRACK_VIDEO: length = paste_video_length; break;
1080 case TRACK_AUDIO: length = paste_audio_length; break;
1082 int64_t asset_length = mwindow->session->track_highlighted->
1083 to_units(length, 1);
1084 paste_audio_position = mwindow->session->track_highlighted->
1085 from_units(drop_edit_position(&insertion, NULL, asset_length));
1088 int64_t asset_length = mwindow->session->track_highlighted->
1089 to_units(paste_video_length, 1);
1090 paste_video_position = mwindow->session->track_highlighted->
1091 from_units(drop_edit_position(&insertion, NULL, asset_length));
1094 // Get destination track
1095 for(Track *dest = mwindow->session->track_highlighted;
1097 dest = dest->next) {
1099 // Get source width in pixels
1101 // Use start of highlighted edit
1102 if(mwindow->session->edit_highlighted) {
1103 position = mwindow->session->track_highlighted->from_units(
1104 mwindow->session->edit_highlighted->startproject);
1107 // Use end of highlighted track, disregarding effects
1108 position = mwindow->session->track_highlighted->from_units(
1109 mwindow->session->track_highlighted->edits->length());
1112 // Get the x coordinate
1113 x = Units::to_int64(position *
1114 mwindow->edl->session->sample_rate /
1115 mwindow->edl->local_session->zoom_sample) -
1116 mwindow->edl->local_session->view_start[pane->number];
1118 double paste_position = -1.;
1119 if(dest->data_type == TRACK_AUDIO) {
1120 if(indexable && current_atrack < indexable->get_audio_channels()) {
1121 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1122 w = Units::to_int64((double)indexable->get_audio_samples() /
1123 indexable->get_sample_rate() *
1124 mwindow->edl->session->sample_rate /
1125 mwindow->edl->local_session->zoom_sample);
1126 paste_position = paste_audio_position;
1128 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1129 w = Units::to_int64((double)clip->tracks->total_length() *
1130 mwindow->edl->session->sample_rate /
1131 mwindow->edl->local_session->zoom_sample);
1132 paste_position = paste_audio_position;
1133 //printf("draw_paste_destination %d\n", x);
1135 else if(mwindow->session->current_operation == DRAG_EDIT &&
1136 current_aedit < mwindow->session->drag_edits->total) {
1138 while(current_aedit < mwindow->session->drag_edits->total &&
1139 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1142 if(current_aedit < mwindow->session->drag_edits->total) {
1143 edit = mwindow->session->drag_edits->values[current_aedit];
1144 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1145 paste_position = mwindow->session->track_highlighted->
1146 from_units(drop_edit_position(&insertion,
1147 mwindow->session->drag_edit,
1148 mwindow->session->drag_edit->length));
1152 if( paste_position >= 0 ) {
1153 position = paste_position;
1160 else if(dest->data_type == TRACK_VIDEO) {
1161 //printf("draw_paste_destination 1\n");
1162 if(indexable && current_vtrack < indexable->get_video_layers())
1164 w = Units::to_int64((double)indexable->get_video_frames() /
1165 indexable->get_frame_rate() *
1166 mwindow->edl->session->sample_rate /
1167 mwindow->edl->local_session->zoom_sample);
1168 paste_position = paste_video_position;
1170 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1171 w = Units::to_int64(clip->tracks->total_length() *
1172 mwindow->edl->session->sample_rate /
1173 mwindow->edl->local_session->zoom_sample);
1174 paste_position = paste_video_position;
1176 else if(mwindow->session->current_operation == DRAG_EDIT &&
1177 current_vedit < mwindow->session->drag_edits->total) {
1179 while(current_vedit < mwindow->session->drag_edits->total &&
1180 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1183 if(current_vedit < mwindow->session->drag_edits->total) {
1184 edit = mwindow->session->drag_edits->values[current_vedit];
1185 w = Units::to_int64(edit->track->from_units(edit->length) *
1186 mwindow->edl->session->sample_rate /
1187 mwindow->edl->local_session->zoom_sample);
1188 paste_position = mwindow->session->track_highlighted->
1189 from_units(drop_edit_position(&insertion,
1190 mwindow->session->drag_edit,
1191 mwindow->session->drag_edit->length));
1195 if( paste_position >= 0 ) {
1196 position = paste_position;
1205 // Get the x coordinate
1206 x = Units::to_int64(position *
1207 mwindow->edl->session->sample_rate /
1208 mwindow->edl->local_session->zoom_sample) -
1209 mwindow->edl->local_session->view_start[pane->number];
1210 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1211 int h = dest->vertical_span(mwindow->theme);
1213 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1214 if(x < -BC_INFINITY) {
1215 w -= -BC_INFINITY - x;
1216 x += -BC_INFINITY - x;
1219 // if(pane->number == TOP_RIGHT_PANE)
1220 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1221 // __LINE__, x, y, w, h);
1223 draw_highlight_insertion(x, y, w, h);
1225 draw_highlight_rectangle(x, y, w, h);
1232 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1234 x = Units::round(plugin->track->from_units(plugin->startproject) *
1235 mwindow->edl->session->sample_rate /
1236 mwindow->edl->local_session->zoom_sample -
1237 mwindow->edl->local_session->view_start[pane->number]);
1238 w = Units::round(plugin->track->from_units(plugin->length) *
1239 mwindow->edl->session->sample_rate /
1240 mwindow->edl->local_session->zoom_sample);
1241 y = plugin->track->y_pixel
1242 - mwindow->edl->local_session->track_start[pane->number];
1243 if( plugin->track->show_titles() )
1244 y += mwindow->theme->get_image("title_bg_data")->get_h();
1245 if( plugin->track->show_assets() )
1247 y += plugin->plugin_set->get_number() *
1248 mwindow->theme->get_image("plugin_bg_data")->get_h();
1249 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1252 int TrackCanvas::resource_h()
1254 return mwindow->edl->local_session->zoom_track;
1257 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1260 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1261 // just draw arrows, so user has indication that something is there
1262 // FIXME: get better colors
1266 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1271 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1275 // Fix bug in heroines & cvs version as of 22.8.2005:
1276 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1277 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1290 w = MIN(w, get_w() + 20);
1291 h = MIN(h, get_h() + 20);
1294 set_color(mwindow->preferences->highlight_inverse);
1296 //draw_rectangle(x, y, w, h);
1297 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1298 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1300 draw_rectangle(x, y, w, h);
1302 //if(pane->number == TOP_RIGHT_PANE)
1303 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1306 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1309 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1310 // just draw arrows, so user has indication that something is there
1311 // FIXME: get better colors
1320 /* these don't look so good
1322 draw_line(x, y, x, y+h);
1323 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1324 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1325 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1326 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1328 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1329 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1331 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1332 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1333 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1334 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1336 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1337 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1339 // draw the box centred around x
1341 // Fix bug in heroines & cvs version as of 22.8.2005:
1342 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1343 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1354 w = MIN(w, get_w() + 20);
1355 h = MIN(h, get_h() + 20);
1356 set_color(mwindow->preferences->highlight_inverse);
1358 draw_rectangle(x, y, w, h);
1359 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1361 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1364 void TrackCanvas::draw_playback_cursor()
1366 // Called before playback_cursor exists
1367 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1369 // mwindow->playback_cursor->visible = 0;
1370 // mwindow->playback_cursor->draw();
1374 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1376 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1377 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1379 edit_dimensions(edit, x, y, w, h);
1381 if( edit->track->show_titles() )
1382 y += mwindow->theme->get_image("title_bg_data")->get_h();
1384 if(side == EDIT_OUT)
1391 void TrackCanvas::get_transition_coords(Edit *edit,
1392 int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1394 int transition_w = 30, transition_h = 30;
1395 int has_titles = edit->track->show_titles();
1396 int has_assets = edit->track->show_assets();
1397 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
1398 double asset_h = resource_h();
1399 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
1400 double dy = has_titles ?
1401 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2 ) :
1402 ( has_assets ? asset_h/2 : 0) ;
1403 double title_h = mwindow->theme->title_h;
1404 if( dy < title_h / 2 ) { ys = title_h; dy = ys / 2; }
1407 x -= transition_w / 2;
1408 y -= transition_h / 2;
1413 void TrackCanvas::draw_highlighting()
1418 switch(mwindow->session->current_operation)
1420 case DRAG_ATRANSITION:
1421 case DRAG_VTRANSITION:
1422 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1423 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1424 if(mwindow->session->edit_highlighted) {
1425 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1426 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1427 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1428 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1429 edit_dimensions(mwindow->session->edit_highlighted,
1431 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1432 MWindowGUI::visible(y, y + h, 0, get_h())) {
1434 get_transition_coords(mwindow->session->edit_highlighted,
1441 // Dragging a new effect from the Resource window
1444 if(mwindow->session->track_highlighted &&
1445 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1446 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1447 (mwindow->session->current_operation == DRAG_VEFFECT &&
1448 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1449 // Put it before another plugin
1450 if(mwindow->session->plugin_highlighted) {
1451 plugin_dimensions(mwindow->session->plugin_highlighted,
1453 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1455 // Put it after a plugin set
1456 else if( mwindow->session->pluginset_highlighted &&
1457 mwindow->session->pluginset_highlighted->last ) {
1458 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1460 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1461 int64_t track_x, track_y, track_w, track_h;
1462 track_dimensions(mwindow->session->track_highlighted,
1463 track_x, track_y, track_w, track_h);
1467 mwindow->session->track_highlighted->get_length() *
1468 mwindow->edl->session->sample_rate /
1469 mwindow->edl->local_session->zoom_sample -
1470 mwindow->edl->local_session->view_start[pane->number]) -
1472 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1473 if(w <= 0) w = track_w;
1476 track_dimensions(mwindow->session->track_highlighted,
1479 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1480 // Put it in a new plugin set determined by the selected range
1481 if(mwindow->edl->local_session->get_selectionend() >
1482 mwindow->edl->local_session->get_selectionstart()) {
1483 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1484 mwindow->edl->session->sample_rate /
1485 mwindow->edl->local_session->zoom_sample -
1486 mwindow->edl->local_session->view_start[pane->number]);
1487 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1488 mwindow->edl->local_session->get_selectionstart()) *
1489 mwindow->edl->session->sample_rate /
1490 mwindow->edl->local_session->zoom_sample);
1492 // Put it in a new plugin set determined by an edit boundary
1493 else if(mwindow->session->edit_highlighted) {
1494 int64_t temp_y, temp_h;
1495 edit_dimensions(mwindow->session->edit_highlighted,
1496 x, temp_y, w, temp_h);
1498 // Put it at the beginning of the track in a new plugin set
1501 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1502 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1503 //printf("TrackCanvas::draw_highlighting 1\n");
1510 if(mwindow->session->track_highlighted) {
1511 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1513 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1515 draw_paste_destination();
1521 if(mwindow->session->track_highlighted) {
1522 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1524 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1525 draw_paste_destination();
1530 // Dragging an effect from the timeline
1531 case DRAG_AEFFECT_COPY:
1532 case DRAG_VEFFECT_COPY:
1533 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1534 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1535 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1536 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1537 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1539 int64_t plugin_position = -1;
1540 Plugin *drag_plugin = mwindow->session->drag_plugin;
1541 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1542 Track *hi_track = mwindow->session->track_highlighted;
1543 Edit *hi_edit = mwindow->session->edit_highlighted;
1544 // Put it into a silence zone
1545 if( hi_plugin_set && hi_plugin_set->last &&
1546 hi_plugin_set->track == drag_plugin->track ) {
1547 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1548 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1549 hi_track = drag_plugin->track;
1551 else if( hi_track ) {
1552 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1553 track_dimensions(hi_track, x, y, w, h);
1554 plugin_position = hi_edit ? hi_edit->startproject : 0;
1557 if( plugin_position < 0 ) break;
1559 // Calculate length of plugin based on data type of track and units
1560 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1561 mwindow->edl->local_session->zoom_sample;
1562 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1563 mwindow->edl->local_session->view_start[pane->number];
1564 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1566 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1567 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1573 case DRAG_PLUGINKEY:
1574 if(mwindow->session->plugin_highlighted &&
1575 mwindow->session->current_operation == DRAG_PLUGINKEY)
1577 // Just highlight the plugin
1578 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1580 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1581 MWindowGUI::visible(y, y + h, 0, get_h()))
1593 draw_highlight_rectangle(x, y, w, h);
1597 void TrackCanvas::draw_plugins()
1599 char string[BCTEXTLEN];
1601 int current_show = 0;
1602 int current_preset = 0;
1604 for(int i = 0; i < plugin_on_toggles.total; i++)
1605 plugin_on_toggles.values[i]->in_use = 0;
1606 for(int i = 0; i < plugin_show_toggles.total; i++)
1607 plugin_show_toggles.values[i]->in_use = 0;
1608 for(int i = 0; i < preset_edit_buttons.total; i++)
1609 plugin_show_toggles.values[i]->in_use = 0;
1612 for(Track *track = mwindow->edl->tracks->first;
1614 track = track->next)
1616 if(track->expand_view)
1618 for(int i = 0; i < track->plugin_set.total; i++)
1620 PluginSet *pluginset = track->plugin_set.values[i];
1622 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1624 int64_t total_x, y, total_w, h;
1625 plugin_dimensions(plugin, total_x, y, total_w, h);
1627 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1628 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1629 plugin->plugin_type != PLUGIN_NONE)
1631 int x = total_x, w = total_w, left_margin = 5;
1632 int right_margin = 5;
1638 if(w + x > get_w()) w -= (w + x) - get_w();
1645 mwindow->theme->get_image("plugin_bg_data"),
1647 set_color(mwindow->theme->title_color);
1648 set_font(mwindow->theme->title_font);
1649 plugin->calculate_title(string, 0);
1651 // Truncate string to int64_test visible in background
1652 int len = strlen(string), j;
1653 for(j = len; j >= 0; j--)
1655 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1663 // Justify the text on the left boundary of the edit if it is visible.
1664 // Otherwise justify it on the left side of the screen.
1665 int64_t text_x = total_x + left_margin;
1666 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1667 text_x = MAX(left_margin, text_x);
1669 y + get_text_ascent(mwindow->theme->title_font) + 2,
1673 int64_t min_x = total_x + text_w;
1676 // Update plugin toggles
1677 int toggle_x = total_x + total_w;
1679 toggle_x = MIN(get_w() - right_margin, toggle_x);
1682 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1683 if(toggle_x > min_x)
1685 if(current_on >= plugin_on_toggles.total)
1687 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1688 add_subwindow(plugin_on);
1689 plugin_on_toggles.append(plugin_on);
1693 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1698 // Toggles for standalone plugins only
1699 if(plugin->plugin_type == PLUGIN_STANDALONE)
1702 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1703 if(toggle_x > min_x)
1705 if(current_show >= plugin_show_toggles.total)
1707 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1708 add_subwindow(plugin_show);
1709 plugin_show_toggles.append(plugin_show);
1713 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1717 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1718 if(toggle_x > min_x)
1720 if(current_preset >= preset_edit_buttons.total)
1722 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1723 add_subwindow(preset_edit);
1724 preset_edit_buttons.append(preset_edit);
1728 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1739 // Remove unused toggles
1741 while(current_preset < preset_edit_buttons.total)
1743 preset_edit_buttons.remove_object_number(current_preset);
1745 while(current_show < plugin_show_toggles.total)
1747 plugin_show_toggles.remove_object_number(current_show);
1750 while(current_on < plugin_on_toggles.total)
1752 plugin_on_toggles.remove_object_number(current_on);
1756 void TrackCanvas::refresh_plugintoggles()
1758 for(int i = 0; i < plugin_on_toggles.total; i++)
1760 PluginOn *on = plugin_on_toggles.values[i];
1761 on->reposition_window(on->get_x(), on->get_y());
1763 for(int i = 0; i < plugin_show_toggles.total; i++)
1765 PluginShow *show = plugin_show_toggles.values[i];
1766 show->reposition_window(show->get_x(), show->get_y());
1768 for(int i = 0; i < preset_edit_buttons.total; i++)
1770 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1771 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1775 void TrackCanvas::draw_hard_edges()
1779 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1780 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1781 if( !edit->hard_left && !edit->hard_right ) continue;
1782 edit_dimensions(edit, x, y, w, h);
1786 if( track->show_titles() )
1787 y1 += mwindow->theme->get_image("title_bg_data")->get_h();
1788 if( track->show_assets() )
1791 y1 += mwindow->theme->title_h;
1792 if( edit->hard_left ) {
1793 ArrayList<int> xpt, ypt;
1794 xpt.append(x); ypt.append(y1);
1795 xpt.append(x+HANDLE_W); ypt.append(y1);
1796 xpt.append(x); ypt.append(y1-HANDLE_H);
1797 fill_polygon(&xpt, &ypt);
1799 if( edit->hard_right ) {
1800 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1801 xpt.append(x1); ypt.append(y1);
1802 xpt.append(x1-HANDLE_W); ypt.append(y1);
1803 xpt.append(x1); ypt.append(y1-HANDLE_H);
1804 fill_polygon(&xpt, &ypt);
1810 void TrackCanvas::draw_inout_points()
1815 void TrackCanvas::draw_drag_handle()
1817 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1818 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1820 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1821 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1822 mwindow->edl->session->sample_rate /
1823 mwindow->edl->local_session->zoom_sample -
1824 mwindow->edl->local_session->view_start[pane->number]);
1825 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1826 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1828 //printf("TrackCanvas::draw_drag_handle 3\n");
1829 draw_line(pixel1, 0, pixel1, get_h());
1831 //printf("TrackCanvas::draw_drag_handle 4\n");
1836 void TrackCanvas::draw_transitions()
1840 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1841 if( !track->show_transitions() ) continue;
1843 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1844 if(!edit->transition) continue;
1845 edit_dimensions(edit, x, y, w, h);
1846 int strip_x = x, edit_y = y;
1847 get_transition_coords(edit, x, y, w, h);
1848 int strip_y = y - mwindow->theme->get_image("plugin_bg_data")->get_h();
1849 if( strip_y < edit_y ) strip_y = edit_y;
1851 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1852 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1853 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1854 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1855 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1857 if( !server ) continue;
1858 VFrame *picon = server->get_picon();
1859 if( !picon ) continue;
1860 int picon_w = picon->get_w(), picon_h = picon->get_h();
1861 int track_h = edit->track->vertical_span(mwindow->theme);
1862 if( picon_h > track_h ) picon_h = track_h;
1863 draw_vframe(picon, x, y, w, h, 0, 0, picon_w, picon_h);
1865 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1866 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h())) {
1867 int x = strip_x, w = strip_w;
1868 if( x < 0 ) { w -= -x; x = 0; }
1869 if( w + x > get_w() ) w -= (w + x) - get_w();
1871 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1872 mwindow->theme->get_image("plugin_bg_data"), 0);
1878 void TrackCanvas::draw_loop_points()
1880 //printf("TrackCanvas::draw_loop_points 1\n");
1881 if(mwindow->edl->local_session->loop_playback)
1883 //printf("TrackCanvas::draw_loop_points 2\n");
1884 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1885 mwindow->edl->session->sample_rate /
1886 mwindow->edl->local_session->zoom_sample -
1887 mwindow->edl->local_session->view_start[pane->number]);
1888 //printf("TrackCanvas::draw_loop_points 3\n");
1890 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1893 draw_line(x, 0, x, get_h());
1895 //printf("TrackCanvas::draw_loop_points 4\n");
1897 x = Units::round(mwindow->edl->local_session->loop_end *
1898 mwindow->edl->session->sample_rate /
1899 mwindow->edl->local_session->zoom_sample -
1900 mwindow->edl->local_session->view_start[pane->number]);
1901 //printf("TrackCanvas::draw_loop_points 5\n");
1903 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1906 draw_line(x, 0, x, get_h());
1908 //printf("TrackCanvas::draw_loop_points 6\n");
1910 //printf("TrackCanvas::draw_loop_points 7\n");
1913 void TrackCanvas::draw_brender_range()
1915 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1916 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1917 if( mwindow->edl->session->brender_end > 0 )
1919 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1920 mwindow->edl->session->sample_rate /
1921 mwindow->edl->local_session->zoom_sample -
1922 mwindow->edl->local_session->view_start[pane->number]);
1923 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1926 draw_line(x1, 0, x1, get_h());
1928 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1929 mwindow->edl->session->sample_rate /
1930 mwindow->edl->local_session->zoom_sample -
1931 mwindow->edl->local_session->view_start[pane->number]);
1933 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1936 draw_line(x2, 0, x2, get_h());
1941 // The operations which correspond to each automation type
1942 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1958 // The buttonpress operations, so nothing changes unless the mouse moves
1959 // a certain amount. This allows the keyframe to be used to position the
1960 // insertion point without moving itself.
1961 static int pre_auto_operations[AUTOMATION_TOTAL] =
1978 int TrackCanvas::do_keyframes(int cursor_x,
1986 // Note: button 3 (right mouse button) is not eaten to allow
1987 // track context menu to appear
1989 EDLSession *session = mwindow->edl->session;
1993 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1995 0, 0, 0, 0, 0, 0, 0, 0,
1997 modekeyframe_pixmap,
1998 maskkeyframe_pixmap,
2003 for(Track *track = mwindow->edl->tracks->first;
2005 track = track->next) {
2006 Auto *auto_keyframe = 0;
2007 Automation *automation = track->automation;
2010 // Handle keyframes in reverse drawing order if a button press
2012 int end = AUTOMATION_TOTAL;
2016 start = AUTOMATION_TOTAL - 1;
2020 for(int i = start; i != end && !result; i += step)
2022 // Event not trapped and automation visible
2023 Autos *autos = automation->autos[i];
2024 if(!result && session->auto_conf->autos[i] && autos) {
2026 case AUTOMATION_MODE:
2027 case AUTOMATION_PAN:
2028 case AUTOMATION_MASK:
2029 result = do_autos(track, automation->autos[i],
2030 cursor_x, cursor_y, draw,
2031 buttonpress, auto_pixmaps[i],
2032 auto_keyframe, rerender);
2036 switch(autos->get_type()) {
2037 case Autos::AUTOMATION_TYPE_FLOAT: {
2038 Automation automation(0, track);
2039 int grouptype = automation.autogrouptype(i, track);
2040 if( buttonpress && i == AUTOMATION_SPEED ) {
2041 mwindow->speed_before();
2044 if(draw) // Do dropshadow
2045 result = do_float_autos(track, autos,
2046 cursor_x, cursor_y, draw,
2047 buttonpress, 1, 1, MDGREY,
2048 auto_keyframe, grouptype);
2049 result = do_float_autos(track, autos,
2050 cursor_x, cursor_y, draw, buttonpress,
2051 0, 0, GWindowGUI::auto_colors[i],
2052 auto_keyframe, grouptype);
2054 if( !result && buttonpress && i == AUTOMATION_SPEED )
2055 mwindow->speed_after(-1);
2056 int current_grouptype = mwindow->edl->local_session->zoombar_showautotype;
2057 if( result && buttonpress && grouptype != current_grouptype ) {
2058 mwindow->edl->local_session->zoombar_showautotype = grouptype;
2059 mwindow->gui->zoombar->update_autozoom();
2063 case Autos::AUTOMATION_TYPE_INT: {
2064 if(draw) // Do dropshadow
2065 result = do_int_autos(track, autos,
2066 cursor_x, cursor_y, draw,
2067 buttonpress, 1, 1, MDGREY,
2069 result = do_int_autos(track, autos,
2070 cursor_x, cursor_y, draw, buttonpress,
2071 0, 0, GWindowGUI::auto_colors[i],
2080 if(mwindow->session->current_operation == auto_operations[i])
2083 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2085 // mwindow->session->current_operation,
2086 // auto_operations[i]);
2089 if (buttonpress != 3)
2091 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2092 synchronize_autos(0,
2094 (FloatAuto*)mwindow->session->drag_auto,
2096 mwindow->session->current_operation = pre_auto_operations[i];
2097 update_drag_caption();
2100 else if( auto_keyframe )
2102 gui->keyframe_menu->update(automation,
2105 gui->keyframe_menu->activate_menu();
2106 rerender = 1; // the position changes
2110 gui->keyframe_hide->update(autos);
2111 gui->keyframe_hide->activate_menu();
2112 rerender = 1; // the position changes
2114 if(buttonpress == 1 && ctrl_down() &&
2115 AUTOMATION_TYPE_FLOAT == autos->get_type())
2116 rerender = 1; // special case: curve mode changed
2122 if(!result && session->auto_conf->plugins) {
2125 result = do_plugin_autos(track, cursor_x, cursor_y,
2126 draw, buttonpress, plugin, keyframe);
2127 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2130 if(result && (buttonpress == 1)) {
2131 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2132 update_drag_caption();
2135 else if (result && (buttonpress == 3)) {
2136 gui->keyframe_menu->update(plugin, keyframe);
2137 gui->keyframe_menu->activate_menu();
2138 rerender = 1; // the position changes
2143 // Final pass to trap event
2144 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2145 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2146 mwindow->session->current_operation == auto_operations[i]) {
2152 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2153 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2159 new_cursor = UPRIGHT_ARROW_CURSOR;
2166 void TrackCanvas::draw_keyframe_reticle()
2168 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2169 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2171 int current_op = mwindow->session->current_operation, dragging = 0;
2172 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2173 if( current_op == auto_operations[i] ) dragging = 1;
2175 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2176 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2177 draw_hairline(mwindow->session->drag_auto, RED);
2182 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2183 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2184 for( Track *track = mwindow->edl->tracks->first; track;
2185 track=track->next ) {
2186 Automation *automation = track->automation;
2187 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2188 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2189 // automation visible
2190 Autos *autos = automation->autos[i];
2191 if( !autos ) continue;
2192 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2193 auto_keyframe = auto_keyframe->next ) {
2194 draw_hairline(auto_keyframe, BLUE);
2198 if( dragging && mwindow->session->drag_auto ) {
2199 draw_hairline(mwindow->session->drag_auto, RED);
2205 void TrackCanvas::draw_auto(Auto *current,
2213 x1 = x - HANDLE_W / 2;
2214 x2 = x + HANDLE_W / 2;
2215 y1 = center_pixel + y - HANDLE_W / 2;
2216 y2 = center_pixel + y + HANDLE_W / 2;
2218 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2219 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2221 draw_box(x1, y1, x2 - x1, y2 - y1);
2225 // This draws lines for bezier in & out controls
2226 void TrackCanvas::draw_cropped_line(int x1,
2235 // Don't care about x since it is clipped by the window.
2236 // Put y coords in ascending order
2238 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2239 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2244 double slope = (double)(x2 - x1) / (y2 - y1);
2245 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2247 x1 = (int)(x1 + (min_y - y1) * slope);
2250 else if(y1 >= max_y) {
2251 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2256 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2259 else if(y2 < min_y) {
2260 x2 = (int)(x2 + (min_y - y2) * slope);
2265 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2266 if( y1 >= min_y && y1 < max_y &&
2267 y2 >= min_y && y2 < max_y )
2268 draw_line(x1, y1, x2, y2);
2272 void TrackCanvas::draw_floatauto(FloatAuto *current,
2283 int x1 = x - HANDLE_W / 2; // Center
2284 int x2 = x + HANDLE_W / 2;
2285 int y1 = center_pixel + y - HANDLE_H / 2;
2286 int y2 = center_pixel + y + HANDLE_H / 2;
2287 int ymin = center_pixel - zoom_track / 2;
2288 int ymax = center_pixel + zoom_track / 2;
2289 CLAMP(y1, ymin, ymax);
2290 CLAMP(y2, ymin, ymax);
2295 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2297 draw_box(x1, y1, x2 - x1, y2 - y1);
2300 // show bezier control points (only) if this
2301 // floatauto doesn't adjust it's tangents automatically
2302 if(current->curve_mode != FloatAuto::FREE &&
2303 current->curve_mode != FloatAuto::TFREE)
2307 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2309 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2312 inline int quantize(float f) { return (int)floor(f + 0.5); }
2314 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2315 int x, int y, int cp_x, int cp_y, int center_pixel,
2316 int zoom_track, int color)
2317 // draw the tangent and a handle for given bézier ctrl point
2319 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2321 float slope = (float)(cp_y - y)/(cp_x - x);
2322 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2324 cp_x = x + quantize((cp_y - y) / slope);
2327 cp_y += center_pixel;
2329 // drawing the tangent as a dashed line...
2330 int const dash = HANDLE_W;
2331 int const gap = HANDLE_W / 2;
2332 float sx = 3 * (cp_x - x) / 4.;
2335 // q is the x displacement for a unit line of slope
2336 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2338 float dist = 1/q * sx;
2344 float sy = slope * sx, ey = slope * ex;
2345 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2352 int r = HANDLE_W / 2;
2353 int cp_x1 = cp_x - r;
2354 int cp_y1 = cp_y - r;
2356 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2358 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2363 int TrackCanvas::test_auto(Auto *current,
2364 int x, int y, int center_pixel, int zoom_track,
2365 int cursor_x, int cursor_y, int buttonpress)
2370 x1 = x - HANDLE_W / 2;
2371 x2 = x + HANDLE_W / 2;
2372 y1 = center_pixel + y - HANDLE_H / 2;
2373 y2 = center_pixel + y + HANDLE_H / 2;
2374 int ymin = center_pixel - zoom_track / 2;
2375 int ymax = center_pixel + zoom_track / 2;
2376 CLAMP(y1, ymin, ymax);
2377 CLAMP(y2, ymin, ymax);
2379 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2381 if(buttonpress && buttonpress != 3)
2383 mwindow->session->drag_auto = current;
2384 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2385 // Toggle Autos don't respond to vertical zoom, they always show up
2386 // with "on" == 100% == line on top
2387 mwindow->session->drag_start_position = current->position;
2388 mwindow->session->drag_origin_x = cursor_x;
2389 mwindow->session->drag_origin_y = cursor_y;
2394 if(buttonpress && buttonpress != 3 && result)
2396 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2397 mwindow->undo->update_undo_before();
2403 // some Helpers for test_floatauto(..)
2404 // and for dragging the tangents/ctrl points
2405 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2406 float cursor_x, float cursor_y)
2408 // Control point switched off?
2409 if( x0 == ctrl_x ) return 0.0;
2410 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2411 double x = cursor_x-x0, y = cursor_y-y0;
2412 // wrong side of ctrl handle
2413 if( x*x1 < 0 ) return 0.0;
2414 // outside handle radius
2415 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2416 double xx1 = x1*x1, yy1 = y1*y1;
2417 double xx = x*x, yy = y*y;
2418 // distance squared from cursor to cursor projected to line from ctrl to handle
2419 // along a line perpendicular to line from ctrl to handle (closest approach)
2420 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2421 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2422 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2427 float levered_position(float position, float ref_pos)
2429 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2431 return ref_pos / position;
2435 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2436 // transforms automation value into current display coords,
2437 // dependant on current automation display range for the given kind of automation
2439 if(!mwindow || !mwindow->edl) return 0;
2440 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2441 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2442 float automation_range = automation_max - automation_min;
2443 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2445 return (auto_value - automation_min) / automation_range;
2450 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2451 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2452 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2456 int x1 = x - HANDLE_W / 2;
2457 int x2 = x + HANDLE_W / 2;
2458 int y1 = center_pixel + y - HANDLE_W / 2;
2459 int y2 = center_pixel + y + HANDLE_W / 2;
2460 int ymin = center_pixel - zoom_track / 2;
2461 int ymax = center_pixel + zoom_track / 2;
2462 CLAMP(y1, ymin, ymax);
2463 CLAMP(y2, ymin, ymax);
2465 int in_x1 = in_x - HANDLE_W / 2;
2466 int in_x2 = in_x + HANDLE_W / 2;
2467 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2468 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2469 CLAMP(in_y1, ymin, ymax);
2470 CLAMP(in_y2, ymin, ymax);
2472 int out_x1 = out_x - HANDLE_W / 2;
2473 int out_x2 = out_x + HANDLE_W / 2;
2474 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2475 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2476 CLAMP(out_y1, ymin, ymax);
2477 CLAMP(out_y2, ymin, ymax);
2480 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2481 // buttonpress could be the start of a drag operation
2482 #define INIT_DRAG(POS,VAL) \
2483 mwindow->session->drag_auto = current; \
2484 mwindow->session->drag_origin_x = cursor_x; \
2485 mwindow->session->drag_origin_y = cursor_y; \
2486 mwindow->session->drag_start_position = (POS); \
2487 mwindow->session->drag_start_percentage = (VAL);
2489 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2492 // without modifier we are manipulating the automation node
2493 // with ALT it's about dragging only the value of the node
2494 // with SHIFT the value snaps to the value of neighbouring nodes
2495 // CTRL indicates we are rather manipulating the tangent(s) of the node
2499 if( WITHIN(x1,x2,y1,y2))
2500 { // cursor hits node
2503 if(buttonpress && (buttonpress != 3))
2505 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2506 mwindow->session->drag_handle = 0;
2511 if( WITHIN(x1,x2,y1,y2))
2514 if(buttonpress && (buttonpress != 3))
2516 // could be ctrl-click or ctrl-drag
2517 // click would cycle through tangent modes
2518 ((FloatAuto*)current)->toggle_curve_mode();
2520 // drag will start dragging the tangent, if applicable
2521 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2522 mwindow->session->drag_handle = 0;
2526 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2529 if( in_x != x && current->position > 0 &&
2530 (FloatAuto::FREE == current->curve_mode ||
2531 FloatAuto::TFREE == current->curve_mode))
2532 // act on in control handle only if
2533 // tangent is significant and is editable (not automatically choosen)
2535 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2536 // either cursor in ctrl-point handle or cursor on tangent line
2537 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2539 if(buttonpress && (buttonpress != 3)) {
2540 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2542 mwindow->session->drag_handle = 1;
2543 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2544 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2545 value_to_percentage(new_invalue, autogrouptype))
2552 (FloatAuto::FREE == current->curve_mode ||
2553 FloatAuto::TFREE == current->curve_mode))
2554 // act on out control only if tangent is significant and is editable
2556 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2557 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2559 if(buttonpress && (buttonpress != 3)) {
2560 if(lever == 0.0) lever=1.0;
2562 mwindow->session->drag_handle = 2;
2563 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2564 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2565 value_to_percentage(new_outvalue, autogrouptype))
2569 } // end ctrl_down()
2575 // 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",
2576 // mwindow->session->drag_handle,
2581 if(buttonpress && (buttonpress != 3) && result)
2583 mwindow->undo->update_undo_before();
2590 // Get the float value & y for position x on the canvas
2591 #define X_TO_FLOATLINE(x) \
2592 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2593 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2594 /* Call by reference fails for some reason here */ \
2595 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2596 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2597 double position = unit_start + x * zoom_units; \
2599 if(position2 > position1) \
2602 (value2 - value1) * \
2603 (position - position1) / \
2604 (position2 - position1); \
2610 AUTOMATIONCLAMPS(value, autogrouptype); \
2611 int y = center_pixel + \
2612 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2615 void TrackCanvas::draw_floatline(int center_pixel,
2616 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2617 double unit_start, double zoom_units, double yscale,
2618 int x1, int y1, int x2, int y2,
2619 int color, int autogrouptype)
2621 // Solve bezier equation for either every pixel or a certain large number of
2624 // Not using slope intercept
2626 int prev_y = y1 + center_pixel;
2629 // Call by reference fails for some reason here
2630 FloatAuto *previous1 = previous, *next1 = next;
2631 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2632 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2633 float automation_range = automation_max - automation_min;
2635 for(int x = x1; x < x2; x++)
2637 // Interpolate value between frames
2641 y >= center_pixel - yscale / 2 &&
2642 y < center_pixel + yscale / 2 - 1)
2644 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2646 // (int)(center_pixel - yscale / 2),
2647 // (int)(center_pixel + yscale / 2 - 1));
2649 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2650 draw_line(x - 1, prev_y , x, y );
2660 int TrackCanvas::test_floatline(int center_pixel,
2675 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2676 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2677 float automation_range = automation_max - automation_min;
2678 FloatAuto *previous1 = 0, *next1 = 0;
2679 X_TO_FLOATLINE(cursor_x);
2681 if(cursor_x >= x1 &&
2683 cursor_y >= y - HANDLE_W / 2 &&
2684 cursor_y < y + HANDLE_W / 2 &&
2690 if(buttonpress == 3)
2698 mwindow->undo->update_undo_before();
2699 double position = autos->track->from_units(position1);
2700 position = mwindow->edl->align_to_frame(position, 0);
2701 int64_t new_position = autos->track->to_units(position,0);
2702 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2703 ((FloatAuto*)current)->set_value(value);
2704 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2705 mwindow->session->drag_start_position = current->position;
2706 mwindow->session->drag_origin_x = cursor_x;
2707 mwindow->session->drag_origin_y = cursor_y;
2708 mwindow->session->drag_handle = 0;
2717 void TrackCanvas::synchronize_autos(float change,
2718 Track *skip, FloatAuto *fauto, int fill_gangs)
2720 // Handles the special case of modifying a fadeauto
2721 // when there are ganged faders on several tracks
2722 // (skip and fauto may be NULL if fill_gangs==-1)
2724 if( fill_gangs > 0 && skip->gang ) {
2725 double position = skip->from_units(fauto->position);
2726 int autoidx = fauto->autos->autoidx;
2728 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2729 if( (current->data_type == skip->data_type || get_double_click()) &&
2730 current->gang && current->record && current != skip ) {
2731 int64_t current_position = current->to_units(position, 1);
2732 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2733 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2734 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2735 FloatAuto *previous = 0, *next = 0;
2736 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2738 // create keyframe on neighbouring track at the point in time given by fauto
2739 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2740 float new_value = init_value + change;
2741 CLAMP(new_value, auto_min, auto_max);
2742 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2743 keyframe->set_value(new_value);
2746 // keyframe exists, just change it
2747 float new_value = keyframe->get_value() + change;
2748 CLAMP(new_value, auto_min, auto_max);
2749 keyframe->adjust_to_new_coordinates(current_position, new_value);
2750 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2753 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2757 else if( !fill_gangs ) {
2758 double position = skip->from_units(fauto->position);
2760 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2761 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2762 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2763 float new_value = keyframe->get_value() + change;
2765 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2766 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2767 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2773 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2774 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2775 keyframe->autos->remove_nonsequential(
2778 mwindow->session->drag_auto_gang->remove_all();
2783 void TrackCanvas::draw_toggleline(int center_pixel,
2789 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2793 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2797 int TrackCanvas::test_toggleline(Autos *autos,
2808 if(cursor_x >= x1 && cursor_x < x2)
2810 int miny = center_pixel + y1 - HANDLE_W / 2;
2811 int maxy = center_pixel + y1 + HANDLE_W / 2;
2812 if(cursor_y >= miny && cursor_y < maxy)
2817 if(buttonpress == 3)
2825 double position = (double)(cursor_x +
2826 mwindow->edl->local_session->view_start[pane->number]) *
2827 mwindow->edl->local_session->zoom_sample /
2828 mwindow->edl->session->sample_rate;
2829 int64_t unit_position = autos->track->to_units(position, 0);
2830 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2832 mwindow->undo->update_undo_before();
2834 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2835 ((IntAuto*)current)->value = new_value;
2836 // Toggle Autos don't respond to vertical zoom, they always show up
2837 // with "on" == 100% == line on top
2838 mwindow->session->drag_start_percentage = (float)new_value;
2839 mwindow->session->drag_start_position = current->position;
2840 mwindow->session->drag_origin_x = cursor_x;
2841 mwindow->session->drag_origin_y = cursor_y;
2849 void TrackCanvas::calculate_viewport(Track *track,
2850 double &view_start, // Seconds
2852 double &view_end, // Seconds
2856 double &zoom_sample,
2860 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2861 mwindow->edl->local_session->zoom_sample /
2862 mwindow->edl->session->sample_rate;
2863 unit_start = track->to_doubleunits(view_start);
2864 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2866 mwindow->edl->local_session->zoom_sample /
2867 mwindow->edl->session->sample_rate;
2868 unit_end = track->to_doubleunits(view_end);
2870 int y = track->y_pixel
2871 - mwindow->edl->local_session->track_start[pane->number];
2872 int has_titles = track->show_titles();
2873 int has_assets = track->show_assets();
2874 double title_bg_h = mwindow->theme->get_image("title_bg_data")->get_h();
2875 double asset_h = resource_h();
2876 double title_h = mwindow->theme->title_h;
2877 double ys = has_assets ? asset_h : has_titles ? title_bg_h : 0;
2878 double dy = has_titles ?
2879 ( has_assets ? title_bg_h + asset_h/2 : title_bg_h/2) :
2880 ( has_assets ? asset_h/2 : 0) ;
2881 if( dy < title_h/2 ) { ys = title_h; dy = ys / 2; }
2883 center_pixel = y + dy;
2885 zoom_sample = mwindow->edl->local_session->zoom_sample;
2886 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2889 float TrackCanvas::percentage_to_value(float percentage,
2897 if(percentage > 0.5)
2904 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2905 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2906 float automation_range = automation_max - automation_min;
2908 result = percentage * automation_range + automation_min;
2911 FloatAuto *ptr = (FloatAuto*)reference;
2912 result -= ptr->get_value();
2914 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2920 void TrackCanvas::calculate_auto_position(double *x, double *y,
2921 double *in_x, double *in_y, double *out_x, double *out_y,
2922 Auto *current, double unit_start, double zoom_units, double yscale,
2925 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2926 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2927 float automation_range = automation_max - automation_min;
2928 FloatAuto *ptr = (FloatAuto*)current;
2929 *x = (double)(ptr->position - unit_start) / zoom_units;
2930 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2933 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2934 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2938 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2939 automation_min) / automation_range - 0.5) * -yscale;
2943 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2944 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2948 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2949 automation_min) / automation_range - 0.5) * -yscale;
2954 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2955 int draw, int buttonpress, int x_offset, int y_offset, int color,
2956 Auto* &auto_instance, int autogrouptype)
2959 int center_pixel, draw_auto;
2960 double view_start, unit_start;
2961 double view_end, unit_end, yscale;
2962 double zoom_sample, zoom_units;
2963 double in_x2, in_y2, out_x2, out_y2;
2969 if(draw) set_color(color);
2971 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2972 yscale, center_pixel, zoom_sample, zoom_units);
2974 // Get first auto before start
2975 Auto *current = 0, *previous = 0;
2977 for( current = autos->last;
2978 current && current->position >= unit_start;
2979 current = PREVIOUS ) ;
2981 Auto *first_auto = current ? current :
2982 autos->first ? autos->first : autos->default_auto;
2984 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2986 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2987 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2992 current = autos->first;
3001 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
3002 current, unit_start, zoom_units, yscale, autogrouptype);
3010 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
3015 ay2 = ay + slope * (get_w() - ax);
3019 ay = ay + slope * (0 - ax);
3023 // Draw or test handle
3024 if( current && !result && current != autos->default_auto ) {
3025 if( !draw && track->record ) {
3026 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3027 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3028 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3029 buttonpress, autogrouptype);
3031 auto_instance = current;
3033 if( draw && draw_auto ) {
3034 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3035 (int)in_x2 + x_offset, (int)in_y2,
3036 (int)out_x2 + x_offset, (int)out_y2,
3037 (int)center_pixel + y_offset, (int)yscale, color);
3041 // Draw or test joining line
3042 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3043 result = test_floatline(center_pixel,
3044 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3045 // Exclude auto coverage from the end of the line. The auto overlaps
3046 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3047 buttonpress, autogrouptype);
3050 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3051 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3052 (int)ax, (int)ay, (int)ax2, (int)ay2,
3053 color, autogrouptype);
3061 } while( current && current->position <= unit_end && !result );
3063 if( ax < get_w() && !result ) {
3064 ax2 = get_w(); ay2 = ay;
3065 if(!draw && track->record /* && buttonpress != 3 */ ) {
3066 result = test_floatline(center_pixel,
3067 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3068 (int)ax, (int)ax2, cursor_x, cursor_y,
3069 buttonpress, autogrouptype);
3072 draw_floatline(center_pixel,
3073 (FloatAuto*)previous, (FloatAuto*)current,
3074 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3075 (int)ax, (int)ay, (int)ax2, (int)ay2,
3076 color, autogrouptype);
3083 int TrackCanvas::do_int_autos(Track *track,
3092 Auto *&auto_instance)
3103 double ax, ay, ax2, ay2;
3107 if(draw) set_color(color);
3109 calculate_viewport(track,
3120 double high = -yscale * 0.8 / 2;
3121 double low = yscale * 0.8 / 2;
3123 // Get first auto before start
3125 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3131 ay = ((IntAuto*)current)->value > 0 ? high : low;
3136 current = autos->first ? autos->first : autos->default_auto;
3140 ay = ((IntAuto*)current)->value > 0 ? high : low;
3153 ax2 = (double)(current->position - unit_start) / zoom_units;
3154 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3162 if(ax2 > get_w()) ax2 = get_w();
3164 if(current && !result)
3166 if(current != autos->default_auto)
3172 result = test_auto(current,
3181 auto_instance = current;
3186 (int)ax2 + x_offset,
3187 (int)ay2 + y_offset,
3199 if(track->record /* && buttonpress != 3 */)
3201 result = test_toggleline(autos,
3214 draw_toggleline(center_pixel + y_offset,
3222 }while(current && current->position <= unit_end && !result);
3224 if(ax < get_w() && !result)
3230 if(track->record /* && buttonpress != 3 */)
3232 result = test_toggleline(autos,
3244 draw_toggleline(center_pixel + y_offset,
3253 int TrackCanvas::do_autos(Track *track,
3260 Auto * &auto_instance,
3274 calculate_viewport(track,
3287 for(current = autos->first; current && !result; current = NEXT)
3289 if(current->position >= unit_start && current->position < unit_end)
3292 x = (int64_t)((double)(current->position - unit_start) /
3293 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3294 y = center_pixel - pixmap->get_h() / 2;
3298 if(cursor_x >= x && cursor_y >= y &&
3299 cursor_x < x + pixmap->get_w() &&
3300 cursor_y < y + pixmap->get_h())
3303 auto_instance = current;
3305 if(buttonpress && (buttonpress != 3))
3307 mwindow->session->drag_auto = current;
3308 mwindow->session->drag_start_position = current->position;
3309 mwindow->session->drag_origin_x = cursor_x;
3310 mwindow->session->drag_origin_y = cursor_y;
3312 double position = autos->track->from_units(current->position);
3313 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3314 mwindow->edl->local_session->get_selectionend(1)) /
3319 mwindow->edl->local_session->set_selectionstart(position);
3320 mwindow->edl->local_session->set_selectionend(position);
3323 if(position < center)
3325 mwindow->edl->local_session->set_selectionstart(position);
3328 mwindow->edl->local_session->set_selectionend(position);
3335 draw_pixmap(pixmap, x, y);
3343 // so this means it is always >0 when keyframe is found
3344 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3345 int draw, int buttonpress, Plugin* &keyframe_plugin,
3346 KeyFrame* &keyframe_instance)
3359 if(!track->expand_view) return 0;
3361 calculate_viewport(track,
3373 for(int i = 0; i < track->plugin_set.total && !result; i++)
3375 PluginSet *plugin_set = track->plugin_set.values[i];
3376 int center_pixel = track->y_pixel -
3377 mwindow->edl->local_session->track_start[pane->number];
3378 if( track->show_titles() )
3379 center_pixel += mwindow->theme->get_image("title_bg_data")->get_h();
3380 if( track->show_assets() )
3381 center_pixel += resource_h();
3382 center_pixel += (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h();
3384 for(Plugin *plugin = (Plugin*)plugin_set->first;
3386 plugin = (Plugin*)plugin->next)
3388 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3389 keyframe && !result;
3390 keyframe = (KeyFrame*)keyframe->next)
3392 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3393 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3395 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3396 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3398 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3401 if(cursor_x >= x && cursor_y >= y &&
3402 cursor_x < x + keyframe_pixmap->get_w() &&
3403 cursor_y < y + keyframe_pixmap->get_h())
3406 keyframe_plugin = plugin;
3407 keyframe_instance = keyframe;
3411 mwindow->session->drag_auto = keyframe;
3412 mwindow->session->drag_start_position = keyframe->position;
3413 mwindow->session->drag_origin_x = cursor_x;
3414 mwindow->session->drag_origin_y = cursor_y;
3416 double position = track->from_units(keyframe->position);
3417 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3418 mwindow->edl->local_session->get_selectionend(1)) /
3423 mwindow->edl->local_session->set_selectionstart(position);
3424 mwindow->edl->local_session->set_selectionend(position);
3427 if(position < center)
3429 mwindow->edl->local_session->set_selectionstart(position);
3432 mwindow->edl->local_session->set_selectionend(position);
3437 draw_pixmap(keyframe_pixmap,
3447 // if(buttonpress && buttonpress != 3 && result)
3449 // mwindow->undo->update_undo_before();
3455 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3457 Track *track = auto_keyframe->autos->track;
3458 int autogrouptype = auto_keyframe->autos->get_type();
3461 double view_start, unit_start;
3462 double view_end, unit_end, yscale;
3463 double zoom_sample, zoom_units;
3465 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3466 yscale, center_pixel, zoom_sample, zoom_units);
3468 double ax = 0, ay = 0;
3469 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3470 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3473 draw_line(ax, 0, ax, get_h());
3477 void TrackCanvas::draw_overlays()
3479 int new_cursor, update_cursor, rerender;
3481 // Move background pixmap to foreground pixmap
3482 draw_pixmap(background_pixmap,
3491 draw_inout_points();
3502 draw_brender_range();
3504 // Highlighted areas
3505 draw_highlighting();
3508 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3511 if(pane->cursor) pane->cursor->restore(1);
3517 draw_playback_cursor();
3519 draw_keyframe_reticle();
3524 int TrackCanvas::activate()
3528 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3529 //BC_Signals::dump_stack();
3530 get_top_level()->deactivate();
3532 set_active_subwindow(this);
3533 pane->cursor->activate();
3534 gui->focused_pane = pane->number;
3539 int TrackCanvas::deactivate()
3544 pane->cursor->deactivate();
3550 void TrackCanvas::update_drag_handle()
3552 double new_position;
3553 int cursor_x = get_cursor_x();
3557 mwindow->edl->local_session->view_start[pane->number]) *
3558 mwindow->edl->local_session->zoom_sample /
3559 mwindow->edl->session->sample_rate;
3562 mwindow->edl->align_to_frame(new_position, 0);
3564 if( ctrl_down() && alt_down() ) {
3565 #define snapper(v) do { \
3567 if( pos < 0 ) break; \
3568 double dist = fabs(new_position - pos); \
3569 if( dist >= snap_min ) break; \
3570 snap_position = pos; snap_min = dist; \
3572 double snap_position = new_position;
3573 double snap_min = DBL_MAX;
3574 if( mwindow->edl->local_session->inpoint_valid() )
3575 snapper(mwindow->edl->local_session->get_inpoint());
3576 if( mwindow->edl->local_session->outpoint_valid() )
3577 snapper(mwindow->edl->local_session->get_outpoint());
3578 snapper(mwindow->edl->prev_edit(new_position));
3579 snapper(mwindow->edl->next_edit(new_position));
3580 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3581 if( prev_label ) snapper(prev_label->position);
3582 Label *next_label = mwindow->edl->labels->next_label(new_position);
3583 if( next_label ) snapper(next_label->position);
3584 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3585 mwindow->edl->local_session->zoom_sample -
3586 mwindow->edl->local_session->view_start[pane->number];
3587 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3589 new_position = snap_position;
3594 if(new_position != mwindow->session->drag_position)
3596 mwindow->session->drag_position = new_position;
3597 gui->mainclock->update(new_position);
3600 timebar_position = new_position;
3601 gui->update_timebar(0);
3602 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3604 // mwindow->cwindow->update(1, 0, 0);
3608 int TrackCanvas::update_drag_edit()
3617 int TrackCanvas::get_drag_values(float *percentage,
3624 //int x = cursor_x - mwindow->session->drag_origin_x;
3625 //int y = cursor_y - mwindow->session->drag_origin_y;
3629 if(!current->autos->track->record) return 1;
3639 calculate_viewport(current->autos->track,
3649 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3651 mwindow->session->drag_start_percentage;
3652 if(do_clamp) CLAMP(*percentage, 0, 1);
3654 *position = Units::to_int64(zoom_units *
3655 (cursor_x - mwindow->session->drag_origin_x) +
3656 mwindow->session->drag_start_position + 0.5);
3658 if((do_clamp) && *position < 0) *position = 0;
3663 #define UPDATE_DRAG_HEAD(do_clamp) \
3664 int result = 0, center_pixel; \
3665 if(!current->autos->track->record) return 0; \
3666 double view_start, unit_start, view_end, unit_end; \
3667 double yscale, zoom_sample, zoom_units; \
3669 calculate_viewport(current->autos->track, \
3670 view_start, unit_start, view_end, unit_end, \
3671 yscale, center_pixel, zoom_sample, zoom_units); \
3673 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3674 yscale + mwindow->session->drag_start_percentage; \
3675 if(do_clamp) CLAMP(percentage, 0, 1); \
3677 int64_t position = Units::to_int64(zoom_units * \
3678 (cursor_x - mwindow->session->drag_origin_x) + \
3679 mwindow->session->drag_start_position); \
3680 if((do_clamp) && position < 0) position = 0;
3683 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3685 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3687 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3688 int x = cursor_x - mwindow->session->drag_origin_x;
3689 int y = cursor_y - mwindow->session->drag_origin_y;
3690 float value, old_value;
3692 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3693 // not really editing the node, rather start editing the curve
3694 // tangent is editable and drag movement is significant
3695 if( (FloatAuto::FREE == current->curve_mode ||
3696 FloatAuto::TFREE==current->curve_mode) &&
3697 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3698 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3701 switch(mwindow->session->drag_handle) {
3703 // Snap to nearby values
3704 old_value = current->get_value();
3706 double value1, value2, distance1, distance2;
3708 if(current->previous) {
3709 int autogrouptype = current->previous->autos->autogrouptype;
3710 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3711 value1 = ((FloatAuto*)current->previous)->get_value();
3712 distance1 = fabs(value - value1);
3713 current->set_value(value1);
3717 int autogrouptype = current->next->autos->autogrouptype;
3718 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3719 value2 = ((FloatAuto*)current->next)->get_value();
3720 distance2 = fabs(value - value2);
3721 if(!current->previous || distance2 < distance1) {
3722 current->set_value(value2);
3726 if(!current->previous && !current->next) {
3727 current->set_value( ((FloatAutos*)current->autos)->default_);
3729 value = current->get_value();
3732 int autogrouptype = current->autos->autogrouptype;
3733 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3736 if(alt_down() && !shift_down())
3737 // ALT constrains movement: fixed position, only changing the value
3738 position = mwindow->session->drag_start_position;
3740 if(value != old_value || position != current->position) {
3742 float change = value - old_value;
3743 current->adjust_to_new_coordinates(position, value);
3744 synchronize_autos(change, current->autos->track, current, 0);
3745 show_message(current, 1,", %.2f", current->get_value());
3751 int autogrouptype = current->autos->autogrouptype;
3752 value = percentage_to_value(percentage, 0, current, autogrouptype);
3753 if(value != current->get_control_in_value())
3756 // note: (position,value) need not be at the location of the ctrl point,
3757 // but could be somewhere in between on the curve (or even outward or
3758 // on the opposit side). We set the new control point such as
3759 // to point the curve through (position,value)
3760 current->set_control_in_value(
3761 value * levered_position(position - current->position,
3762 current->get_control_in_position()));
3763 synchronize_autos(0, current->autos->track, current, 0);
3764 show_message(current, 1,", %.2f", current->get_control_in_value());
3770 int autogrouptype = current->autos->autogrouptype;
3771 value = percentage_to_value(percentage, 0, current, autogrouptype);
3772 if(value != current->get_control_out_value()) {
3774 current->set_control_out_value(
3775 value * levered_position(position - current->position,
3776 current->get_control_out_position()));
3777 synchronize_autos(0, current->autos->track, current, 0);
3778 show_message(current, 1,", %.2f", current->get_control_out_value());
3786 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3788 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3790 UPDATE_DRAG_HEAD(1);
3791 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3793 if(value != current->value || position != current->position)
3796 current->value = value;
3797 current->position = position;
3798 show_message(current, 0,", %d", current->value);
3804 // Autos which can't change value through dragging.
3806 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3808 Auto *current = (Auto*)mwindow->session->drag_auto;
3811 if(position != current->position)
3814 current->position = position;
3815 show_message(current, 0,"");
3817 double position_f = current->autos->track->from_units(current->position);
3818 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3819 mwindow->edl->local_session->get_selectionend(1)) /
3823 mwindow->edl->local_session->set_selectionstart(position_f);
3824 mwindow->edl->local_session->set_selectionend(position_f);
3827 if(position_f < center_f)
3829 mwindow->edl->local_session->set_selectionstart(position_f);
3832 mwindow->edl->local_session->set_selectionend(position_f);
3839 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3841 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3844 if(position != current->position)
3846 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3847 Track *track = current->autos->track;
3848 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3849 PluginSet *pluginset;
3851 // figure out the correct pluginset & correct plugin
3853 for(int i = 0; i < track->plugin_set.total; i++)
3855 pluginset = track->plugin_set.values[i];
3856 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3858 KeyFrames *keyframes = plugin->keyframes;
3859 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3861 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3863 if (currentkeyframe == current)
3875 mwindow->session->plugin_highlighted = plugin;
3876 mwindow->session->track_highlighted = track;
3878 current->position = position;
3879 show_message(current, 0,"");
3881 double position_f = current->autos->track->from_units(current->position);
3882 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3883 mwindow->edl->local_session->get_selectionend(1)) /
3887 mwindow->edl->local_session->set_selectionstart(position_f);
3888 mwindow->edl->local_session->set_selectionend(position_f);
3891 if(position_f < center_f)
3893 mwindow->edl->local_session->set_selectionstart(position_f);
3896 mwindow->edl->local_session->set_selectionend(position_f);
3903 void TrackCanvas::update_drag_caption()
3905 switch(mwindow->session->current_operation)
3915 int TrackCanvas::cursor_update(int in_motion)
3920 int update_clock = 0;
3921 int update_zoom = 0;
3922 int update_scroll = 0;
3923 int update_overlay = 0;
3924 int update_cursor = 0;
3927 double position = 0.;
3928 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
3931 switch(mwindow->edl->session->editing_mode)
3933 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3934 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3937 switch(mwindow->session->current_operation)
3939 case DRAG_EDITHANDLE1:
3940 // Outside threshold. Upgrade status
3943 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3945 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3951 case DRAG_EDITHANDLE2:
3954 update_drag_handle();
3959 case DRAG_PLUGINHANDLE1:
3962 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3964 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3970 case DRAG_PLUGINHANDLE2:
3973 update_drag_handle();
3978 // Rubber band curves
3986 case DRAG_PROJECTOR_X:
3987 case DRAG_PROJECTOR_Y:
3988 case DRAG_PROJECTOR_Z:
3989 if(active) rerender = update_overlay =
3990 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3991 if( rerender && mwindow->session->current_operation == DRAG_SPEED )
3992 mwindow->speed_after(!in_motion ? 1 : 0);
3996 if(active) rerender = update_overlay =
3997 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4001 if(active) rerender = update_overlay =
4002 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
4005 // Keyframe icons are sticky
4009 case DRAG_PLUGINKEY_PRE:
4011 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
4012 mwindow->session->current_operation++;
4015 mwindow->undo->update_undo_before();
4023 if(active) rerender = update_overlay =
4024 update_drag_auto(get_cursor_x(), get_cursor_y());
4027 case DRAG_PLUGINKEY:
4028 if(active) rerender = update_overlay =
4029 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4034 cursor_x = get_cursor_x();
4035 cursor_y = get_cursor_y();
4036 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4037 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4039 position = mwindow->edl->align_to_frame(position, 0);
4040 position = MAX(position, 0);
4042 double start = mwindow->edl->local_session->get_selectionstart(1);
4043 double end = mwindow->edl->local_session->get_selectionend(1);
4044 if(position < selection_midpoint) {
4045 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4046 mwindow->edl->local_session->set_selectionstart(position);
4049 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4050 mwindow->edl->local_session->set_selectionend(position);
4053 gui->unlock_window();
4055 start != mwindow->edl->local_session->get_selectionstart(1) ? 1 :
4056 end != mwindow->edl->local_session->get_selectionend(1) ? -1 : 0;
4057 mwindow->cwindow->update(dir, 0, 0, 0, 1);
4058 gui->lock_window("TrackCanvas::cursor_update 1");
4059 // Update the faders
4060 mwindow->update_plugin_guis();
4061 gui->update_patchbay();
4063 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4065 gui->hide_cursor(0);
4066 gui->draw_cursor(1);
4067 gui->update_timebar(0);
4068 gui->flash_canvas(1);
4077 if(is_event_win() && cursor_inside()) {
4079 cursor_x = get_cursor_x();
4080 position = (double)cursor_x *
4081 (double)mwindow->edl->local_session->zoom_sample /
4082 (double)mwindow->edl->session->sample_rate +
4083 (double)mwindow->edl->local_session->view_start[pane->number] *
4084 (double)mwindow->edl->local_session->zoom_sample /
4085 (double)mwindow->edl->session->sample_rate;
4086 position = mwindow->edl->align_to_frame(position, 0);
4090 for(int i = 0; i < TOTAL_PANES; i++)
4091 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4093 //printf("TrackCanvas::cursor_update %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4094 gui->update_timebar(0);
4096 if(do_transitions(get_cursor_x(), get_cursor_y(),
4097 0, new_cursor, update_cursor)) break;
4098 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4099 0, 0, new_cursor, update_cursor, rerender)) break;
4100 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4101 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4102 // Plugin boundaries
4103 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4104 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4105 if(do_edits(get_cursor_x(), get_cursor_y(),
4106 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4111 //printf("TrackCanvas::cursor_update 1\n");
4112 if(update_cursor && new_cursor != get_cursor())
4114 set_cursor(new_cursor, 0, 1);
4117 //printf("TrackCanvas::cursor_update 1 %d\n", rerender);
4118 if(rerender && render_timer->get_difference() > 0.25 ) {
4119 render_timer->update();
4120 mwindow->restart_brender();
4121 mwindow->sync_parameters(CHANGE_PARAMS);
4122 mwindow->update_plugin_guis();
4123 gui->unlock_window();
4124 mwindow->cwindow->update(1, 0, 0, 0, 1);
4125 gui->lock_window("TrackCanvas::cursor_update 2");
4129 gui->update_patchbay();
4134 if(!mwindow->cwindow->playback_engine->is_playing_back)
4135 gui->mainclock->update(position);
4139 gui->zoombar->update();
4144 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4148 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4152 if(update_overlay) {
4153 gui->draw_overlays(1);
4156 //printf("TrackCanvas::cursor_update %d\n", __LINE__);
4160 int TrackCanvas::cursor_motion_event()
4162 return cursor_update(1);
4165 void TrackCanvas::start_dragscroll()
4169 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4170 //printf("TrackCanvas::start_dragscroll 1\n");
4174 void TrackCanvas::stop_dragscroll()
4178 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4179 //printf("TrackCanvas::stop_dragscroll 1\n");
4183 int TrackCanvas::repeat_event(int64_t duration)
4185 if(!drag_scroll) return 0;
4186 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4188 int sample_movement = 0;
4189 int track_movement = 0;
4190 int64_t x_distance = 0;
4191 int64_t y_distance = 0;
4192 double position = 0;
4195 switch(mwindow->session->current_operation) {
4197 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4198 if(get_cursor_x() > get_w()) {
4199 x_distance = get_cursor_x() - get_w();
4200 sample_movement = 1;
4202 else if(get_cursor_x() < 0) {
4203 x_distance = get_cursor_x();
4204 sample_movement = 1;
4207 if(get_cursor_y() > get_h()) {
4208 y_distance = get_cursor_y() - get_h();
4211 else if(get_cursor_y() < 0) {
4212 y_distance = get_cursor_y();
4219 if(sample_movement) {
4220 position = (double)(get_cursor_x() +
4221 mwindow->edl->local_session->view_start[pane->number] +
4223 mwindow->edl->local_session->zoom_sample /
4224 mwindow->edl->session->sample_rate;
4225 position = mwindow->edl->align_to_frame(position, 0);
4226 position = MAX(position, 0);
4228 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4229 switch(mwindow->session->current_operation) {
4231 if(position < selection_midpoint) {
4232 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4233 mwindow->edl->local_session->set_selectionstart(position);
4235 gui->unlock_window();
4236 mwindow->cwindow->update(1, 0, 0);
4237 gui->lock_window("TrackCanvas::repeat_event");
4238 // Update the faders
4239 mwindow->update_plugin_guis();
4240 gui->update_patchbay();
4243 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4244 mwindow->edl->local_session->set_selectionend(position);
4245 // Don't que the CWindow
4250 mwindow->samplemovement(
4251 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4255 if(track_movement) {
4256 mwindow->trackmovement(y_distance, pane->number);
4262 int TrackCanvas::button_release_event()
4264 int redraw = -1, update_overlay = 0;
4265 int result = 0, load_flags = 0;
4267 // printf("TrackCanvas::button_release_event %d\n",
4268 // mwindow->session->current_operation);
4270 switch(mwindow->session->current_operation) {
4271 case DRAG_EDITHANDLE2:
4272 mwindow->session->current_operation = NO_OPERATION;
4276 end_edithandle_selection();
4279 case DRAG_EDITHANDLE1:
4280 mwindow->session->current_operation = NO_OPERATION;
4285 case DRAG_PLUGINHANDLE2:
4286 mwindow->session->current_operation = NO_OPERATION;
4290 end_pluginhandle_selection();
4293 case DRAG_PLUGINHANDLE1:
4294 mwindow->session->current_operation = NO_OPERATION;
4300 redraw = FORCE_REDRAW;
4301 load_flags |= LOAD_EDITS;
4303 // delete the drag_auto_gang first and remove out of order keys
4304 synchronize_autos(0, 0, 0, -1);
4315 case DRAG_PROJECTOR_X:
4316 case DRAG_PROJECTOR_Y:
4317 case DRAG_PROJECTOR_Z:
4318 case DRAG_PLUGINKEY:
4319 load_flags |= LOAD_AUTOMATION;
4320 mwindow->session->current_operation = NO_OPERATION;
4321 mwindow->session->drag_handle = 0;
4322 // Remove any out-of-order keyframe
4323 if(mwindow->session->drag_auto) {
4324 mwindow->session->drag_auto->autos->remove_nonsequential(
4325 mwindow->session->drag_auto);
4326 // mwindow->session->drag_auto->autos->optimize();
4330 mwindow->undo->update_undo_after(_("keyframe"), load_flags);
4335 case DRAG_AEFFECT_COPY:
4336 case DRAG_VEFFECT_COPY:
4337 // Trap in drag stop
4342 if(mwindow->session->current_operation) {
4343 // if(mwindow->session->current_operation == SELECT_REGION) {
4344 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4347 mwindow->session->current_operation = NO_OPERATION;
4349 // Traps button release events
4359 if(update_overlay) {
4360 gui->draw_overlays(1);
4363 gui->draw_canvas(redraw, 0);
4364 gui->flash_canvas(1);
4369 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4370 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4372 Edit *edit_result = 0;
4373 int handle_result = -1;
4376 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4377 if( !track->show_assets() ) continue;
4379 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4380 int64_t edit_x, edit_y, edit_w, edit_h;
4381 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4383 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4384 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4385 if( cursor_x < edit_x + HANDLE_W ) {
4388 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4389 new_cursor = DOWNLEFT_RESIZE;
4390 if( button_press == LEFT_BUTTON )
4396 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4399 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4400 new_cursor = DOWNRIGHT_RESIZE;
4401 if( button_press == LEFT_BUTTON )
4413 double position = 0;
4414 if( handle_result == 0 ) {
4415 position = edit_result->track->from_units(edit_result->startproject);
4416 new_cursor = LEFT_CURSOR;
4418 else if( handle_result == 1 ) {
4419 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4420 new_cursor = RIGHT_CURSOR;
4423 // Reposition cursor
4424 if( button_press ) {
4425 mwindow->session->drag_edit = edit_result;
4426 mwindow->session->drag_handle = handle_result;
4427 mwindow->session->drag_button = get_buttonpress() - 1;
4428 mwindow->session->drag_position = position;
4429 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4430 mwindow->session->drag_origin_x = get_cursor_x();
4431 mwindow->session->drag_origin_y = get_cursor_y();
4432 mwindow->session->drag_start = position;
4434 rerender = start_selection(position);
4438 else if( result < 0) {
4439 mwindow->undo->update_undo_before();
4440 if( !shift_down() ) {
4441 if( handle_result == 0 )
4442 edit_result->hard_left = !edit_result->hard_left;
4443 else if( handle_result == 1 )
4444 edit_result->hard_right = !edit_result->hard_right;
4447 int status = handle_result == 0 ? edit_result->hard_left :
4448 handle_result == 1 ? edit_result->hard_right : 0;
4449 int new_status = !status;
4450 int64_t edit_edge = edit_result->startproject;
4451 if( handle_result == 1 ) edit_edge += edit_result->length;
4452 double edge_position = edit_result->track->from_units(edit_edge);
4453 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4454 int64_t track_position = track->to_units(edge_position, 1);
4455 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4457 int64_t left_edge = left_edit->startproject;
4458 double left_position = track->from_units(left_edge);
4459 if( EQUIV(edge_position, left_position) ) {
4460 left_edit->hard_left = new_status;
4461 if( left_edit->previous )
4462 left_edit->previous->hard_right = new_status;
4465 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4467 int64_t right_edge = right_edit->startproject + right_edit->length;
4468 double right_position = track->from_units(right_edge);
4469 if( EQUIV(edge_position, right_position) ) {
4470 right_edit->hard_right = new_status;
4471 if( right_edit->next )
4472 right_edit->next->hard_left = new_status;
4477 rerender = update_overlay = 1;
4478 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4485 int TrackCanvas::do_plugin_handles(int cursor_x,
4489 int &update_overlay,
4493 Plugin *plugin_result = 0;
4494 int handle_result = 0;
4497 for(Track *track = mwindow->edl->tracks->first;
4499 track = track->next) {
4500 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4501 PluginSet *plugin_set = track->plugin_set.values[i];
4502 for(Plugin *plugin = (Plugin*)plugin_set->first;
4504 plugin = (Plugin*)plugin->next) {
4505 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4506 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4508 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4509 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4510 if(cursor_x < plugin_x + HANDLE_W) {
4511 plugin_result = plugin;
4515 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4516 plugin_result = plugin;
4523 if(result && shift_down())
4524 mwindow->session->trim_edits = plugin_set;
4530 double position = 0;
4531 if(handle_result == 0) {
4532 position = plugin_result->track->from_units(plugin_result->startproject);
4533 new_cursor = LEFT_CURSOR;
4535 else if(handle_result == 1) {
4536 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4537 new_cursor = RIGHT_CURSOR;
4541 mwindow->session->drag_plugin = plugin_result;
4542 mwindow->session->drag_handle = handle_result;
4543 mwindow->session->drag_button = get_buttonpress() - 1;
4544 mwindow->session->drag_position = position;
4545 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4546 mwindow->session->drag_origin_x = get_cursor_x();
4547 mwindow->session->drag_origin_y = get_cursor_y();
4548 mwindow->session->drag_start = position;
4550 rerender = start_selection(position);
4559 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4563 for(Track *track = mwindow->edl->tracks->first;
4565 track = track->next) {
4566 int64_t track_x, track_y, track_w, track_h;
4567 track_dimensions(track, track_x, track_y, track_w, track_h);
4569 if( button_press && get_buttonpress() == RIGHT_BUTTON &&
4570 cursor_y >= track_y && cursor_y < track_y + track_h) {
4571 double pos = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4572 int64_t position = track->to_units(pos, 0);
4573 gui->edit_menu->update(track, track->edits->editof(position, PLAY_FORWARD, 0));
4574 gui->edit_menu->activate_menu();
4582 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4583 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4587 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4588 if( !track->show_assets() ) continue;
4590 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4591 int64_t edit_x, edit_y, edit_w, edit_h;
4592 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4594 // Cursor inside a track
4595 // Cursor inside an edit
4596 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4597 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4598 // Select duration of edit
4600 if(get_double_click() && !drag_start) {
4601 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4602 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4603 edit->track->from_units(edit->length));
4604 if(mwindow->edl->session->cursor_on_frames)
4606 mwindow->edl->local_session->set_selectionstart(
4607 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4608 mwindow->edl->local_session->set_selectionend(
4609 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4617 else if(drag_start && track->record) {
4618 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4619 // Need to create drag window
4620 mwindow->session->current_operation = DRAG_EDIT;
4621 mwindow->session->drag_edit = edit;
4622 //printf("TrackCanvas::do_edits 2\n");
4624 // Drag only one edit if ctrl is initially down
4626 mwindow->session->drag_edits->remove_all();
4627 mwindow->session->drag_edits->append(edit);
4630 // Construct list of all affected edits
4631 mwindow->edl->tracks->get_affected_edits(
4632 mwindow->session->drag_edits,
4633 edit->track->from_units(edit->startproject),
4636 mwindow->session->drag_origin_x = cursor_x;
4637 mwindow->session->drag_origin_y = cursor_y;
4638 // Where the drag started, so we know relative position inside the edit later
4639 mwindow->session->drag_position = (double)cursor_x *
4640 mwindow->edl->local_session->zoom_sample /
4641 mwindow->edl->session->sample_rate +
4642 (double)mwindow->edl->local_session->view_start[pane->number] *
4643 mwindow->edl->local_session->zoom_sample /
4644 mwindow->edl->session->sample_rate;
4647 get_abs_cursor(cx, cy);
4648 gui->drag_popup = new BC_DragWindow(gui,
4649 mwindow->theme->get_image("clip_icon"), cx, cy);
4661 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4666 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4667 int button_press, int &redraw, int &rerender)
4675 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4676 if(!track->expand_view) continue;
4678 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4679 // first check if plugins are visible at all
4680 if (!track->expand_view)
4682 PluginSet *plugin_set = track->plugin_set.values[i];
4683 for(plugin = (Plugin*)plugin_set->first;
4685 plugin = (Plugin*)plugin->next) {
4686 plugin_dimensions(plugin, x, y, w, h);
4687 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4688 MWindowGUI::visible(y, y + h, 0, get_h())) {
4689 if(cursor_x >= x && cursor_x < x + w &&
4690 cursor_y >= y && cursor_y < y + h) {
4700 // Start plugin popup
4702 if(get_buttonpress() == 3) {
4703 gui->plugin_menu->update(plugin);
4704 gui->plugin_menu->activate_menu();
4707 else if (get_double_click() && !drag_start) {
4708 // Select range of plugin on doubleclick over plugin
4709 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4710 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4711 plugin->track->from_units(plugin->length));
4712 if(mwindow->edl->session->cursor_on_frames) {
4713 mwindow->edl->local_session->set_selectionstart(
4714 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4715 mwindow->edl->local_session->set_selectionend(
4716 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4725 if(drag_start && plugin->track->record) {
4726 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4727 if(plugin->track->data_type == TRACK_AUDIO)
4728 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4729 else if(plugin->track->data_type == TRACK_VIDEO)
4730 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4732 mwindow->session->drag_plugin = plugin;
4733 mwindow->session->drag_origin_x = cursor_x;
4734 mwindow->session->drag_origin_y = cursor_y;
4735 // Where the drag started, so we know relative position inside the edit later
4736 mwindow->session->drag_position =
4737 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4738 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4740 switch(plugin->plugin_type) {
4741 case PLUGIN_STANDALONE: {
4742 PluginServer *server =
4743 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4744 if( !server ) break;
4745 VFrame *frame = server->picon;
4747 if(plugin->track->data_type == TRACK_AUDIO) {
4748 frame = mwindow->theme->get_image("aeffect_icon");
4751 frame = mwindow->theme->get_image("veffect_icon");
4755 get_abs_cursor(cx, cy);
4756 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4759 case PLUGIN_SHAREDPLUGIN:
4760 case PLUGIN_SHAREDMODULE: {
4761 VFrame *frame = mwindow->theme->get_image("clip_icon");
4763 get_abs_cursor(cx, cy);
4764 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4776 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4777 int button_press, int &new_cursor, int &update_cursor)
4779 Transition *transition = 0;
4784 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4785 if( !track->show_transitions() ) continue;
4787 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4788 if( edit->transition ) {
4789 edit_dimensions(edit, x, y, w, h);
4790 get_transition_coords(edit, x, y, w, h);
4792 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4793 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4794 if( cursor_x >= x && cursor_x < x + w &&
4795 cursor_y >= y && cursor_y < y + h ) {
4796 transition = edit->transition;
4808 new_cursor = UPRIGHT_ARROW_CURSOR;
4810 else if(get_buttonpress() == 3) {
4811 gui->transition_menu->update(transition);
4812 gui->transition_menu->activate_menu();
4819 int TrackCanvas::button_press_event()
4822 int cursor_x, cursor_y;
4825 cursor_x = get_cursor_x();
4826 cursor_y = get_cursor_y();
4827 mwindow->session->trim_edits = 0;
4829 if(is_event_win() && cursor_inside()) {
4830 // double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4837 if( get_buttonpress() == LEFT_BUTTON ) {
4838 gui->stop_transport("TrackCanvas::button_press_event");
4841 int update_overlay = 0, update_cursor = 0, rerender = 0;
4843 if(get_buttonpress() == WHEEL_UP) {
4845 mwindow->expand_sample();
4846 else if(ctrl_down())
4847 mwindow->move_left(get_w()/ 10);
4849 mwindow->move_up(get_h() / 10);
4851 else if(get_buttonpress() == WHEEL_DOWN) {
4853 mwindow->zoom_in_sample();
4854 else if(ctrl_down())
4855 mwindow->move_right(get_w() / 10);
4857 mwindow->move_down(get_h() / 10);
4859 else if(get_buttonpress() == 6) {
4861 mwindow->move_left(get_w());
4863 mwindow->move_left(get_w() / 20);
4865 mwindow->move_left(get_w() / 5);
4867 else if(get_buttonpress() == 7) {
4869 mwindow->move_right(get_w());
4871 mwindow->move_right(get_w() / 20);
4873 mwindow->move_right(get_w() / 5);
4876 switch(mwindow->edl->session->editing_mode) {
4877 // Test handles and resource boundaries and highlight a track
4878 case EDITING_ARROW: {
4879 if( do_transitions(cursor_x, cursor_y,
4880 1, new_cursor, update_cursor) ) break;
4882 if( do_keyframes(cursor_x, cursor_y,
4883 0, get_buttonpress(), new_cursor,
4884 update_cursor, rerender) ) break;
4885 // Test edit boundaries
4886 if( do_edit_handles(cursor_x, cursor_y,
4887 1, rerender, update_overlay, new_cursor,
4888 update_cursor) ) break;
4889 // Test plugin boundaries
4890 if( do_plugin_handles(cursor_x, cursor_y,
4891 1, rerender, update_overlay, new_cursor,
4892 update_cursor) ) break;
4894 if( do_edits(cursor_x, cursor_y, 1, 0,
4895 update_cursor, rerender, new_cursor,
4896 update_cursor) ) break;
4898 if( do_plugins(cursor_x, cursor_y, 0, 1,
4899 update_cursor, rerender) ) break;
4901 if( test_resources(cursor_x, cursor_y) ) break;
4903 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4908 // Test handles only and select a region
4909 case EDITING_IBEAM: {
4910 double position = mwindow->edl->get_cursor_position(cursor_x, pane->number);
4911 //printf("TrackCanvas::button_press_event %d\n", position);
4913 if( do_transitions(cursor_x, cursor_y,
4914 1, new_cursor, update_cursor)) break;
4915 if(do_keyframes(cursor_x, cursor_y,
4916 0, get_buttonpress(), new_cursor,
4917 update_cursor, rerender)) {
4921 // Test edit boundaries
4922 if( do_edit_handles(cursor_x, cursor_y,
4923 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4924 // Test plugin boundaries
4925 if( do_plugin_handles(cursor_x, cursor_y,
4926 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4928 if( do_edits(cursor_x, cursor_y,
4929 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4931 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4933 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4934 // Highlight selection
4935 if( get_buttonpress() != LEFT_BUTTON ) break;
4936 rerender = start_selection(position);
4937 mwindow->session->current_operation = SELECT_REGION;
4944 gui->unlock_window();
4945 mwindow->cwindow->update(1, 0, 0, 0, 1);
4946 gui->lock_window("TrackCanvas::button_press_event 2");
4948 mwindow->update_plugin_guis();
4949 gui->update_patchbay();
4952 if( update_overlay ) {
4953 gui->draw_overlays(1);
4955 if( update_cursor < 0 ) {
4956 // double_click edit
4957 gui->swindow->update_selection();
4959 if( update_cursor ) {
4960 gui->update_timebar(0);
4961 gui->hide_cursor(0);
4962 gui->show_cursor(1);
4963 gui->zoombar->update();
4964 gui->flash_canvas(1);
4971 int TrackCanvas::start_selection(double position)
4974 position = mwindow->edl->align_to_frame(position, 1);
4980 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4981 mwindow->edl->local_session->get_selectionend(1)) / 2;
4983 if(position < midpoint)
4985 mwindow->edl->local_session->set_selectionstart(position);
4986 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4992 mwindow->edl->local_session->set_selectionend(position);
4993 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4994 // Don't que the CWindow for the end
4998 // Start a new selection
5000 //printf("TrackCanvas::start_selection %f\n", position);
5001 mwindow->edl->local_session->set_selectionstart(position);
5002 mwindow->edl->local_session->set_selectionend(position);
5003 selection_midpoint = position;
5011 void TrackCanvas::end_edithandle_selection()
5013 mwindow->modify_edithandles();
5016 void TrackCanvas::end_pluginhandle_selection()
5018 mwindow->modify_pluginhandles();
5022 double TrackCanvas::time_visible()
5024 return (double)get_w() *
5025 mwindow->edl->local_session->zoom_sample /
5026 mwindow->edl->session->sample_rate;
5030 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
5032 char string[BCTEXTLEN];
5033 char *cp = string, *ep = cp + sizeof(string)-1;
5034 if( show_curve_type ) {
5035 cp += snprintf(string, ep-cp, "%-8s ",
5036 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5038 char string2[BCTEXTLEN];
5039 Units::totext(string2,
5040 current->autos->track->from_units(current->position),
5041 mwindow->edl->session->time_format,
5042 mwindow->edl->session->sample_rate,
5043 mwindow->edl->session->frame_rate,
5044 mwindow->edl->session->frames_per_foot);
5045 cp += snprintf(cp, ep-cp, "%s", string2);
5048 vsnprintf(cp, ep-cp, fmt, ap);
5050 gui->show_message(string);
5053 // Patchbay* TrackCanvas::get_patchbay()
5055 // if(pane->patchbay) return pane->patchbay;
5056 // if(gui->total_panes() == 2 &&
5057 // gui->pane[TOP_LEFT_PANE] &&
5058 // gui->pane[TOP_RIGHT_PANE])
5059 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5060 // if(gui->total_panes() == 4)
5062 // if(pane->number == TOP_RIGHT_PANE)
5063 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5065 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;