4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "apatchgui.inc"
25 #include "automation.h"
26 #include "bcsignals.h"
30 #include "cplayback.h"
32 #include "cwindowgui.h"
34 #include "edithandles.h"
35 #include "editpopup.h"
38 #include "edlsession.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
41 #include "indexstate.h"
45 #include "keyframepopup.h"
46 #include "keyframes.h"
48 #include "localsession.h"
49 #include "mainclock.h"
50 #include "maincursor.h"
51 #include "mainsession.h"
53 #include "maskautos.h"
56 #include "mwindowgui.h"
60 #include "playbackengine.h"
61 #include "playtransport.h"
63 #include "pluginpopup.h"
64 #include "pluginserver.h"
65 #include "pluginset.h"
66 #include "plugintoggles.h"
67 #include "preferences.h"
68 #include "resourcepixmap.h"
69 #include "resourcethread.h"
72 #include "trackcanvas.h"
75 #include "transition.h"
76 #include "transitionhandles.h"
77 #include "transitionpopup.h"
78 #include "transportque.h"
80 #include "vpatchgui.inc"
85 //#define PIXMAP_AGE -5
86 #define PIXMAP_AGE -32
88 TrackCanvas::TrackCanvas(MWindow *mwindow,
99 this->mwindow = mwindow;
100 this->gui = mwindow->gui;
103 selection_midpoint = 0;
107 resource_timer = new Timer;
108 render_timer = new Timer;
109 hourglass_enabled = 0;
110 timebar_position = -1;
113 TrackCanvas::~TrackCanvas()
115 // delete transition_handles;
117 delete keyframe_pixmap;
118 delete camerakeyframe_pixmap;
119 delete modekeyframe_pixmap;
120 delete pankeyframe_pixmap;
121 delete projectorkeyframe_pixmap;
122 delete maskkeyframe_pixmap;
123 delete background_pixmap;
124 if(temp_picon) delete temp_picon;
126 delete resource_timer;
129 void TrackCanvas::create_objects()
131 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
132 // transition_handles = new TransitionHandles(mwindow, this);
133 edit_handles = new EditHandles(mwindow, this);
134 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
135 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
136 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
137 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
138 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
139 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
145 void TrackCanvas::resize_event()
147 //printf("TrackCanvas::resize_event 1\n");
150 //printf("TrackCanvas::resize_event 2\n");
153 int TrackCanvas::keypress_event()
158 int TrackCanvas::cursor_leave_event()
160 // Because drag motion calls get_cursor_over_window we can be sure that
161 // all highlights get deleted now.
162 // This ended up blocking keyboard input from the drag operations.
163 if( timebar_position >= 0 )
165 timebar_position = -1;
167 pane->timebar->update(1);
171 // return drag_motion();
174 int TrackCanvas::drag_motion_event()
176 return gui->drag_motion();
179 int TrackCanvas::drag_motion(Track **over_track,
181 PluginSet **over_pluginset,
182 Plugin **over_plugin)
184 int cursor_x = get_relative_cursor_x();
185 int cursor_y = get_relative_cursor_y();
187 if( get_cursor_over_window() &&
188 cursor_x >= 0 && cursor_y >= 0 &&
189 cursor_x < get_w() && cursor_y < get_h() )
191 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
192 // Find the edit and track the cursor is over
193 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
195 int64_t track_x, track_y, track_w, track_h;
196 track_dimensions(track, track_x, track_y, track_w, track_h);
198 if(cursor_y >= track_y &&
199 cursor_y < track_y + track_h)
202 for(Edit *edit = track->edits->first; edit; edit = edit->next)
204 int64_t edit_x, edit_y, edit_w, edit_h;
205 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
206 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
207 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
211 if( edit != track->edits->last ) continue;
212 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
213 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
214 if( !edit->silence() ) {
215 // add silence to allow drag transition past last edit
216 // will be deleted by Edits::optimize if not used
217 double length = mwindow->edl->session->default_transition_length;
218 int64_t start = edit->startproject+edit->length;
219 int64_t units = track->to_units(length, 1);
220 track->edits->create_silence(start, start+units);
223 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
226 for(int i = 0; i < track->plugin_set.total; i++)
228 PluginSet *pluginset = track->plugin_set.values[i];
229 for(Plugin *plugin = (Plugin*)pluginset->first;
231 plugin = (Plugin*)plugin->next)
233 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
234 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
236 if(cursor_y >= plugin_y &&
237 cursor_y < plugin_y + plugin_h)
239 *over_pluginset = plugin->plugin_set;
241 if(cursor_x >= plugin_x &&
242 cursor_x < plugin_x + plugin_w)
244 *over_plugin = plugin;
256 *over_track = pane->over_patchbay();
262 int TrackCanvas::drag_stop_event()
264 int result = gui->drag_stop();
265 if( !result && mwindow->session->current_operation ) {
266 mwindow->session->current_operation = NO_OPERATION;
272 int TrackCanvas::drag_stop(int *redraw)
277 int cursor_x = -1, cursor_y = -1;
279 if( get_cursor_over_window() ) {
280 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
281 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
284 Track *track = pane->over_patchbay();
285 if( track && mwindow->session->track_highlighted == track )
291 switch(mwindow->session->current_operation) {
292 case DRAG_VTRANSITION:
293 case DRAG_ATRANSITION:
294 if(mwindow->session->edit_highlighted) {
295 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
296 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
297 (mwindow->session->current_operation == DRAG_VTRANSITION &&
298 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
299 mwindow->session->current_operation = NO_OPERATION;
300 mwindow->paste_transition();
307 // Behavior for dragged plugins is limited by the fact that a shared plugin
308 // can only refer to a standalone plugin that exists in the same position in
309 // time. Dragging a plugin from one point in time to another can't produce
310 // a shared plugin to the original plugin. In this case we relocate the
311 // plugin instead of sharing it.
312 case DRAG_AEFFECT_COPY:
313 case DRAG_VEFFECT_COPY:
314 if( mwindow->session->track_highlighted &&
315 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
316 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
317 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
318 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
319 mwindow->session->current_operation = NO_OPERATION;
321 int64_t drop_position = -1;
322 Plugin *drag_plugin = mwindow->session->drag_plugin;
323 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
324 Track *hi_track = mwindow->session->track_highlighted;
326 // Insert shared plugin in source
327 // Move source to different location
328 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
329 //printf("TrackCanvas::drag_stop 6\n");
330 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
331 if( drop_position >= 0 )
332 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
335 else if( hi_track ) {
336 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
337 Edit *hi_edit = mwindow->session->edit_highlighted;
338 drop_position = hi_edit ? hi_edit->startproject : 0;
339 if( drop_position >= 0 )
340 mwindow->move_effect(drag_plugin, hi_track, drop_position);
348 if( mwindow->session->track_highlighted &&
349 ((mwindow->session->current_operation == DRAG_AEFFECT &&
350 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
351 (mwindow->session->current_operation == DRAG_VEFFECT &&
352 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
353 // Drop all the effects
354 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
355 Track *track = mwindow->session->track_highlighted;
357 double length = track->get_length();
359 if(mwindow->session->plugin_highlighted) {
360 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
361 length = track->from_units(mwindow->session->plugin_highlighted->length);
362 if(length <= 0) length = track->get_length();
364 else if(mwindow->session->pluginset_highlighted) {
365 start = track->from_units(plugin_set->length());
366 length = track->get_length() - start;
367 if(length <= 0) length = track->get_length();
369 else if(mwindow->edl->local_session->get_selectionend() >
370 mwindow->edl->local_session->get_selectionstart()) {
371 start = mwindow->edl->local_session->get_selectionstart();
372 length = mwindow->edl->local_session->get_selectionend() -
373 mwindow->edl->local_session->get_selectionstart();
375 // Move to a point between two edits
376 else if(mwindow->session->edit_highlighted) {
377 start = mwindow->session->track_highlighted->from_units(
378 mwindow->session->edit_highlighted->startproject);
379 length = mwindow->session->track_highlighted->from_units(
380 mwindow->session->edit_highlighted->length);
383 mwindow->insert_effects_canvas(start, length);
386 if( mwindow->session->track_highlighted )
387 result = 1; // we have to cleanup
391 if(mwindow->session->track_highlighted) {
392 double asset_duration = 0;
393 int64_t asset_length_units = 0;
394 int64_t position = 0;
396 if(mwindow->session->current_operation == DRAG_ASSET &&
397 mwindow->session->drag_assets->total) {
398 Indexable *indexable = mwindow->session->drag_assets->values[0];
399 // we use video if we are over video and audio if we are over audio
400 if( indexable->have_video() &&
401 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
402 // Images have length -1
403 int64_t video_length = indexable->get_video_frames();
404 if (video_length < 0) {
405 if(mwindow->edl->session->si_useduration)
406 video_length = mwindow->edl->session->si_duration;
408 video_length = 1.0 / mwindow->edl->session->frame_rate ;
410 asset_duration = video_length / indexable->get_frame_rate();
412 else if( indexable->have_audio() &&
413 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
414 int64_t audio_length = indexable->get_audio_samples();
415 asset_duration = (double)audio_length / indexable->get_sample_rate();
419 break; // Do not do anything
422 else if( mwindow->session->current_operation == DRAG_ASSET &&
423 mwindow->session->drag_clips->total ) {
424 EDL *clip = mwindow->session->drag_clips->values[0];
425 asset_duration = clip->tracks->total_length();
428 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
431 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
432 position = drop_edit_position (&insertion, NULL, asset_length_units);
433 if( position == -1 ) {
435 break; // Do not do anything
438 double position_f = mwindow->session->track_highlighted->from_units(position);
439 Track *track = mwindow->session->track_highlighted;
442 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
443 // // Unfortunately, this is _a lot_ of work to do right
444 // printf("Problematic insertion\n");
445 // mwindow->edl->tracks->clear(position_f,
446 // position_f + asset_duration, 0);
448 mwindow->paste_assets(position_f, track, !insertion);
449 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
454 mwindow->session->current_operation = NO_OPERATION;
455 if(mwindow->session->track_highlighted) {
456 if( mwindow->session->track_highlighted->data_type ==
457 mwindow->session->drag_edit->track->data_type) {
458 int64_t position = 0;
459 position = drop_edit_position(&insertion,
460 mwindow->session->drag_edit,
461 mwindow->session->drag_edit->length);
462 if (position == -1) {
464 break; // Do not do anything
467 double position_f = mwindow->session->track_highlighted->from_units(position);
468 Track *track = mwindow->session->track_highlighted;
469 mwindow->move_edits(mwindow->session->drag_edits,
470 track, position_f, !insertion);
482 int TrackCanvas::drag_start_event()
487 int new_cursor, update_cursor;
489 if(mwindow->session->current_operation != NO_OPERATION) return 0;
492 if(do_plugins(get_drag_x(), get_drag_y(),
493 1, 0, redraw, rerender)) {
496 else if(do_edits(get_drag_x(), get_drag_y(),
497 0, 1, redraw, rerender, new_cursor, update_cursor)) {
505 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
507 // get the canvas/track position
508 Track *track = mwindow->session->track_highlighted;
509 int cursor_x = get_relative_cursor_x();
510 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
511 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
512 // we use cursor position for affinity calculations
513 int64_t cursor_position = track->to_units(drop_time, 0);
514 if( cursor_position <= 0 ) {
518 if( moved_edit ) // relative cursor position depends upon drop point
519 drop_time -= mwindow->session->drag_position - moved_edit->track->from_units(moved_edit->startproject);
520 int64_t drop_position = track->to_units(drop_time, 1);
521 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
522 drop_position -= moved_edit_length / 2;
523 Edit *last_edit = track->edits->last;
524 if( !last_edit || drop_position > last_edit->startproject+last_edit->length ) {
526 return drop_position;
529 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
530 for( Edit *edit = track->edits->first; edit; ) {
531 int64_t edit_x0 = edit->startproject, edit_x1 = edit_x0 + edit->length;
532 if( Units::round(labs(edit_x0-cursor_position)*zoom_scale) < HANDLE_W ) {
533 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
534 return edit->startproject;
536 if( Units::round(labs(edit_x1-cursor_position)*zoom_scale) < HANDLE_W ) {
537 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
538 return edit->startproject + edit->length;
540 if( edit != moved_edit && !edit->silence() )
541 drop_x0 = edit_x1; // reset drop zone
542 if( (edit=edit->next) != 0 ) {
543 if( edit == moved_edit || edit->silence() ) continue;
548 //printf("drop cursor=%jd, x0=%jd, x1=%jd\n", cursor_position, drop_x0, drop_x1);
549 if( drop_position >= drop_x0 && drop_position+moved_edit_length < drop_x1 ) {
550 *is_insertion = 0; // fits in the zone
551 //printf("into %jd\n", drop_position);
552 return drop_position;
554 if( cursor_position < drop_x1 ) { // drop in the zone
555 if( (drop_x1-drop_x0) >= moved_edit_length ) {
556 *is_insertion = 0; // fits in the zone, but over the edge
557 int64_t dx0 = llabs(cursor_position-drop_x0);
558 int64_t dx1 = llabs(cursor_position-drop_x1);
559 //printf("onto %jd\n", dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length);
560 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length;
562 int edit_center = (edit_x0+edit_x1) / 2;
563 if( cursor_position < edit_center ) {
565 //printf("snap left %jd\n", drop_x0);
566 return drop_x0; // snap left
570 //printf("snap right %jd\n", drop_x1);
571 return drop_x1; // snap right
580 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
582 // get the canvas/track position
583 Track *track = plugin_set->track;
584 int cursor_x = get_relative_cursor_x();
585 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
586 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
587 // we use cursor position for affinity calculations
588 int64_t cursor_position = track->to_units(drop_time, 0);
589 if( cursor_position <= 0 ) return 0;
590 drop_time -= mwindow->session->drag_position - moved_plugin->track->from_units(moved_plugin->startproject);
591 int64_t drop_position = track->to_units(drop_time, 1);
592 Plugin *last_plugin = (Plugin *)plugin_set->last;
593 if( !last_plugin || drop_position > last_plugin->startproject+last_plugin->length ) {
594 return drop_position;
597 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
598 for( Plugin *plugin = (Plugin *)plugin_set->first; plugin; ) {
599 int64_t plugin_x0 = plugin->startproject, plugin_x1 = plugin_x0 + plugin->length;
600 if( plugin != moved_plugin && !plugin->silence() )
602 if( (plugin=(Plugin *)plugin->next) != 0 ) {
603 if( plugin == moved_plugin || plugin->silence() ) continue;
608 if( drop_position >= drop_x0 && // fits in the zone
609 drop_position+moved_plugin->length < drop_x1 ) {
610 return drop_position;
612 if( cursor_position < drop_x1 ) { // drop in the zone
613 if( (drop_x1-drop_x0) >= moved_plugin->length ) {
614 int64_t dx0 = llabs(cursor_position-drop_x0);
615 int64_t dx1 = llabs(cursor_position-drop_x1);
616 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_plugin->length;
625 void TrackCanvas::draw(int mode, int hide_cursor)
630 // Swap pixmap layers
631 if(get_w() != background_pixmap->get_w() ||
632 get_h() != background_pixmap->get_h())
634 delete background_pixmap;
635 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
638 // Cursor disappears after resize when this is called.
639 // Cursor doesn't redraw after editing when this isn't called.
640 if(pane->cursor && hide_cursor) pane->cursor->hide();
641 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
643 if(debug) PRINT_TRACE
644 draw_resources(mode);
646 if(debug) PRINT_TRACE
648 if(debug) PRINT_TRACE
651 void TrackCanvas::update_cursor(int flush)
653 switch(mwindow->edl->session->editing_mode)
655 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
656 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
661 void TrackCanvas::test_timer()
663 if(resource_timer->get_difference() > 1000 &&
667 hourglass_enabled = 1;
672 void TrackCanvas::draw_indexes(Indexable *indexable)
674 // Don't redraw raw samples
675 IndexState *index_state = 0;
676 index_state = indexable->index_state;
679 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
683 draw_resources(0, 1, indexable);
689 void TrackCanvas::draw_resources(int mode,
691 Indexable *indexable)
695 if(debug) PRINT_TRACE
697 if(!mwindow->edl->session->show_assets) return;
700 // can't stop thread here, because this is called for every pane
701 // if(mode != IGNORE_THREAD && !indexes_only)
702 // gui->resource_thread->stop_draw(!indexes_only);
704 if(mode != IGNORE_THREAD &&
706 !gui->resource_thread->interrupted)
708 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
711 BC_Signals::dump_stack();
714 if(debug) PRINT_TRACE
716 resource_timer->update();
718 // Age resource pixmaps for deletion
720 for(int i = 0; i < gui->resource_pixmaps.total; i++)
721 gui->resource_pixmaps.values[i]->visible--;
723 if(mode == FORCE_REDRAW)
724 gui->resource_pixmaps.remove_all_objects();
726 if(debug) PRINT_TRACE
729 for(Track *current = mwindow->edl->tracks->first;
733 if(debug) PRINT_TRACE
734 for(Edit *edit = current->edits->first; edit; edit = edit->next)
736 if(debug) PRINT_TRACE
737 if( current->data_type != TRACK_SUBTITLE )
738 if(!edit->asset && !edit->nested_edl) continue;
741 if(edit->track->data_type != TRACK_AUDIO) continue;
743 if(edit->nested_edl &&
744 strcmp(indexable->path, edit->nested_edl->path)) continue;
747 strcmp(indexable->path, edit->asset->path)) continue;
750 if(debug) PRINT_TRACE
752 int64_t edit_x, edit_y, edit_w, edit_h;
753 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
756 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
757 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
759 int64_t pixmap_x, pixmap_w, pixmap_h;
760 if(debug) PRINT_TRACE
762 // Search for existing pixmap containing edit
763 for(int i = 0; i < gui->resource_pixmaps.total; i++)
765 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
766 // Same pointer can be different edit if editing took place
767 if(pixmap->edit_id == edit->id &&
768 pixmap->pane_number == pane->number)
774 if(debug) PRINT_TRACE
776 // Get new size, offset of pixmap needed
777 get_pixmap_size(edit,
783 if(debug) PRINT_TRACE
786 if(pixmap_w && pixmap_h)
788 // Create pixmap if it doesn't exist
789 ResourcePixmap* pixmap = create_pixmap(edit,
794 // Resize it if it's bigger
795 if(pixmap_w > pixmap->pixmap_w ||
796 pixmap_h > pixmap->pixmap_h)
797 pixmap->resize(pixmap_w, pixmap_h);
798 pixmap->draw_data(this,
807 // Resize it if it's smaller
808 if(pixmap_w < pixmap->pixmap_w ||
809 pixmap_h < pixmap->pixmap_h)
810 pixmap->resize(pixmap_w, pixmap_h);
812 // Copy pixmap to background canvas
813 background_pixmap->draw_pixmap(pixmap,
815 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
819 if(debug) PRINT_TRACE
826 // Delete unused pixmaps
827 if(debug) PRINT_TRACE
829 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
830 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
832 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
833 delete gui->resource_pixmaps.values[i];
834 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
836 if(debug) PRINT_TRACE
838 if(hourglass_enabled)
841 hourglass_enabled = 0;
843 if(debug) PRINT_TRACE
845 // can't stop thread here, because this is called for every pane
846 // if(mode != IGNORE_THREAD && !indexes_only)
847 // gui->resource_thread->start_draw();
848 if(debug) PRINT_TRACE
853 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
859 ResourcePixmap *result = 0;
861 for(int i = 0; i < gui->resource_pixmaps.total; i++)
863 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
864 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
865 gui->resource_pixmaps.values[i]->pane_number == pane->number)
867 result = gui->resource_pixmaps.values[i];
875 result = new ResourcePixmap(mwindow,
882 gui->resource_pixmaps.append(result);
885 // result->resize(pixmap_w, pixmap_h);
889 void TrackCanvas::get_pixmap_size(Edit *edit,
897 // Align x on frame boundaries
900 // switch(edit->edits->track->data_type)
912 if(pixmap_x + pixmap_w > get_w())
914 pixmap_w = get_w() - pixmap_x;
921 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
922 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
923 // int64_t pixel_increment = MAX(picon_w, frame_w);
924 // int64_t pixmap_x1 = edit_x;
925 // int64_t pixmap_x2 = edit_x + edit_w;
929 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
934 // if(pixmap_x2 > get_w())
936 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
940 // pixmap_x = pixmap_x1;
941 // pixmap_w = pixmap_x2 - pixmap_x1;
946 pixmap_h = mwindow->edl->local_session->zoom_track;
947 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
948 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
951 void TrackCanvas::edit_dimensions(Edit *edit,
957 // w = Units::round(edit->track->from_units(edit->length) *
958 // mwindow->edl->session->sample_rate /
959 // mwindow->edl->local_session->zoom_sample);
963 x = Units::round(edit->track->from_units(edit->startproject) *
964 mwindow->edl->session->sample_rate /
965 mwindow->edl->local_session->zoom_sample -
966 mwindow->edl->local_session->view_start[pane->number]);
968 // Method for calculating w so when edits are together we never get off by one error due to rounding
969 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
970 mwindow->edl->session->sample_rate /
971 mwindow->edl->local_session->zoom_sample -
972 mwindow->edl->local_session->view_start[pane->number]);
975 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
977 if(mwindow->edl->session->show_titles)
978 h += mwindow->theme->get_image("title_bg_data")->get_h();
981 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
985 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
986 h = track->vertical_span(mwindow->theme);
990 void TrackCanvas::draw_paste_destination()
992 //int cursor_x = get_relative_cursor_x();
993 //int cursor_y = get_relative_cursor_y();
994 int current_atrack = 0;
995 int current_vtrack = 0;
996 int current_aedit = 0;
997 int current_vedit = 0;
1003 //if(pane->number == BOTTOM_RIGHT_PANE)
1004 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1006 if((mwindow->session->current_operation == DRAG_ASSET &&
1007 (mwindow->session->drag_assets->total ||
1008 mwindow->session->drag_clips->total)) ||
1009 (mwindow->session->current_operation == DRAG_EDIT &&
1010 mwindow->session->drag_edits->total)) {
1011 Indexable *indexable = 0;
1015 if(mwindow->session->current_operation == DRAG_ASSET &&
1016 mwindow->session->drag_assets->size())
1017 indexable = mwindow->session->drag_assets->get(0);
1019 if(mwindow->session->current_operation == DRAG_ASSET &&
1020 mwindow->session->drag_clips->size())
1021 clip = mwindow->session->drag_clips->get(0);
1023 int has_audio = 0, has_video = 0;
1024 double paste_audio_length = 0, paste_video_length = 0;
1025 double paste_audio_position = -1, paste_video_position = -1;
1028 has_audio = indexable->have_audio();
1029 paste_audio_length = !has_audio ? 0 :
1030 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1031 has_video = indexable->have_video();
1032 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1033 // Images have length -1
1034 if( asset && asset->video_data && asset->video_length < 0 ) {
1035 paste_video_length = mwindow->edl->session->si_useduration ?
1036 mwindow->edl->session->si_duration / asset->frame_rate :
1037 1.0 / asset->frame_rate ; // 1 frame
1040 paste_video_length = !has_video ? 0 :
1041 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1045 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1046 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1047 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1048 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1051 // 'Align cursor on frame' lengths calculations
1052 if( mwindow->edl->session->cursor_on_frames ) {
1053 double fps = mwindow->edl->session->frame_rate;
1054 double aud = floor(paste_audio_length * fps) / fps;
1055 double vid = floor(paste_video_length * fps) / fps;
1056 double length = has_video && has_audio ?
1057 aud < vid ? aud : vid :
1059 has_audio ? aud : 0;
1060 paste_video_length = paste_audio_length = length;
1063 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1065 switch( mwindow->session->track_highlighted->data_type ) {
1066 case TRACK_VIDEO: length = paste_video_length; break;
1067 case TRACK_AUDIO: length = paste_audio_length; break;
1069 int64_t asset_length = mwindow->session->track_highlighted->
1070 to_units(length, 1);
1071 paste_audio_position = mwindow->session->track_highlighted->
1072 from_units(drop_edit_position(&insertion, NULL, asset_length));
1075 int64_t asset_length = mwindow->session->track_highlighted->
1076 to_units(paste_video_length, 1);
1077 paste_video_position = mwindow->session->track_highlighted->
1078 from_units(drop_edit_position(&insertion, NULL, asset_length));
1081 // Get destination track
1082 for(Track *dest = mwindow->session->track_highlighted;
1084 dest = dest->next) {
1086 // Get source width in pixels
1088 // Use start of highlighted edit
1089 if(mwindow->session->edit_highlighted) {
1090 position = mwindow->session->track_highlighted->from_units(
1091 mwindow->session->edit_highlighted->startproject);
1094 // Use end of highlighted track, disregarding effects
1095 position = mwindow->session->track_highlighted->from_units(
1096 mwindow->session->track_highlighted->edits->length());
1099 // Get the x coordinate
1100 x = Units::to_int64(position *
1101 mwindow->edl->session->sample_rate /
1102 mwindow->edl->local_session->zoom_sample) -
1103 mwindow->edl->local_session->view_start[pane->number];
1105 double paste_position = -1.;
1106 if(dest->data_type == TRACK_AUDIO) {
1107 if(indexable && current_atrack < indexable->get_audio_channels()) {
1108 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1109 w = Units::to_int64((double)indexable->get_audio_samples() /
1110 indexable->get_sample_rate() *
1111 mwindow->edl->session->sample_rate /
1112 mwindow->edl->local_session->zoom_sample);
1113 paste_position = paste_audio_position;
1115 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1116 w = Units::to_int64((double)clip->tracks->total_length() *
1117 mwindow->edl->session->sample_rate /
1118 mwindow->edl->local_session->zoom_sample);
1119 paste_position = paste_audio_position;
1120 //printf("draw_paste_destination %d\n", x);
1122 else if(mwindow->session->current_operation == DRAG_EDIT &&
1123 current_aedit < mwindow->session->drag_edits->total) {
1125 while(current_aedit < mwindow->session->drag_edits->total &&
1126 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1129 if(current_aedit < mwindow->session->drag_edits->total) {
1130 edit = mwindow->session->drag_edits->values[current_aedit];
1131 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1132 paste_position = mwindow->session->track_highlighted->
1133 from_units(drop_edit_position(&insertion,
1134 mwindow->session->drag_edit,
1135 mwindow->session->drag_edit->length));
1138 if( paste_position >= 0 ) {
1139 position = paste_position;
1146 else if(dest->data_type == TRACK_VIDEO) {
1147 //printf("draw_paste_destination 1\n");
1148 if(indexable && current_vtrack < indexable->get_video_layers())
1150 w = Units::to_int64((double)indexable->get_video_frames() /
1151 indexable->get_frame_rate() *
1152 mwindow->edl->session->sample_rate /
1153 mwindow->edl->local_session->zoom_sample);
1154 paste_position = paste_video_position;
1156 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1157 w = Units::to_int64(clip->tracks->total_length() *
1158 mwindow->edl->session->sample_rate /
1159 mwindow->edl->local_session->zoom_sample);
1160 paste_position = paste_video_position;
1162 else if(mwindow->session->current_operation == DRAG_EDIT &&
1163 current_vedit < mwindow->session->drag_edits->total) {
1165 while(current_vedit < mwindow->session->drag_edits->total &&
1166 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1169 if(current_vedit < mwindow->session->drag_edits->total) {
1170 edit = mwindow->session->drag_edits->values[current_vedit];
1171 w = Units::to_int64(edit->track->from_units(edit->length) *
1172 mwindow->edl->session->sample_rate /
1173 mwindow->edl->local_session->zoom_sample);
1174 paste_position = mwindow->session->track_highlighted->
1175 from_units(drop_edit_position(&insertion,
1176 mwindow->session->drag_edit,
1177 mwindow->session->drag_edit->length));
1180 if( paste_position >= 0 ) {
1181 position = paste_position;
1190 // Get the x coordinate
1191 x = Units::to_int64(position *
1192 mwindow->edl->session->sample_rate /
1193 mwindow->edl->local_session->zoom_sample) -
1194 mwindow->edl->local_session->view_start[pane->number];
1195 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1196 int h = dest->vertical_span(mwindow->theme);
1198 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1200 draw_highlight_insertion(x, y, w, h);
1202 draw_highlight_rectangle(x, y, w, h);
1203 if(x < -BC_INFINITY) {
1204 w -= -BC_INFINITY - x;
1205 x += -BC_INFINITY - x;
1208 // if(pane->number == TOP_RIGHT_PANE)
1209 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1210 // __LINE__, x, y, w, h);
1211 draw_highlight_rectangle(x, y, w, h);
1218 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1220 x = Units::round(plugin->track->from_units(plugin->startproject) *
1221 mwindow->edl->session->sample_rate /
1222 mwindow->edl->local_session->zoom_sample -
1223 mwindow->edl->local_session->view_start[pane->number]);
1224 w = Units::round(plugin->track->from_units(plugin->length) *
1225 mwindow->edl->session->sample_rate /
1226 mwindow->edl->local_session->zoom_sample);
1227 y = plugin->track->y_pixel -
1228 mwindow->edl->local_session->track_start[pane->number] +
1229 mwindow->edl->local_session->zoom_track +
1230 plugin->plugin_set->get_number() *
1231 mwindow->theme->get_image("plugin_bg_data")->get_h();
1232 if(mwindow->edl->session->show_titles)
1233 y += mwindow->theme->get_image("title_bg_data")->get_h();
1234 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1237 int TrackCanvas::resource_h()
1239 return mwindow->edl->local_session->zoom_track;
1242 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1245 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1246 // just draw arrows, so user has indication that something is there
1247 // FIXME: get better colors
1251 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1256 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1260 // Fix bug in heroines & cvs version as of 22.8.2005:
1261 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1262 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1275 w = MIN(w, get_w() + 20);
1276 h = MIN(h, get_h() + 20);
1281 //draw_rectangle(x, y, w, h);
1282 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1283 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1285 draw_rectangle(x, y, w, h);
1287 //if(pane->number == TOP_RIGHT_PANE)
1288 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1291 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1294 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1295 // just draw arrows, so user has indication that something is there
1296 // FIXME: get better colors
1305 /* these don't look so good
1307 draw_line(x, y, x, y+h);
1308 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1309 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1310 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1311 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1313 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1314 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1316 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1317 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1318 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1319 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1321 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1322 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1324 // draw the box centred around x
1326 // Fix bug in heroines & cvs version as of 22.8.2005:
1327 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1328 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1339 w = MIN(w, get_w() + 20);
1340 h = MIN(h, get_h() + 20);
1343 draw_rectangle(x, y, w, h);
1344 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1346 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1349 void TrackCanvas::draw_playback_cursor()
1351 // Called before playback_cursor exists
1352 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1354 // mwindow->playback_cursor->visible = 0;
1355 // mwindow->playback_cursor->draw();
1359 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1361 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1362 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1364 edit_dimensions(edit, x, y, w, h);
1366 if(mwindow->edl->session->show_titles)
1368 y += mwindow->theme->get_image("title_bg_data")->get_h();
1375 if(side == EDIT_OUT)
1384 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1386 //printf("TrackCanvas::get_transition_coords 1\n");
1387 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1388 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1389 int transition_w = 30;
1390 int transition_h = 30;
1391 //printf("TrackCanvas::get_transition_coords 1\n");
1393 if(mwindow->edl->session->show_titles)
1394 y += mwindow->theme->get_image("title_bg_data")->get_h();
1395 //printf("TrackCanvas::get_transition_coords 2\n");
1397 y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
1398 x -= transition_w / 2;
1404 void TrackCanvas::draw_highlighting()
1409 switch(mwindow->session->current_operation)
1411 case DRAG_ATRANSITION:
1412 case DRAG_VTRANSITION:
1413 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1414 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1415 if(mwindow->session->edit_highlighted) {
1416 //printf("TrackCanvas::draw_highlighting 2\n");
1417 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1418 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1419 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1420 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1421 //printf("TrackCanvas::draw_highlighting 2\n");
1422 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1423 //printf("TrackCanvas::draw_highlighting 2\n");
1425 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1426 MWindowGUI::visible(y, y + h, 0, get_h())) {
1428 get_transition_coords(x, y, w, h);
1430 //printf("TrackCanvas::draw_highlighting 3\n");
1435 // Dragging a new effect from the Resource window
1438 if(mwindow->session->track_highlighted &&
1439 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1440 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1441 (mwindow->session->current_operation == DRAG_VEFFECT &&
1442 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1443 // Put it before another plugin
1444 if(mwindow->session->plugin_highlighted) {
1445 plugin_dimensions(mwindow->session->plugin_highlighted,
1447 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1449 // Put it after a plugin set
1450 else if( mwindow->session->pluginset_highlighted &&
1451 mwindow->session->pluginset_highlighted->last ) {
1452 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1454 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1455 int64_t track_x, track_y, track_w, track_h;
1456 track_dimensions(mwindow->session->track_highlighted,
1457 track_x, track_y, track_w, track_h);
1461 mwindow->session->track_highlighted->get_length() *
1462 mwindow->edl->session->sample_rate /
1463 mwindow->edl->local_session->zoom_sample -
1464 mwindow->edl->local_session->view_start[pane->number]) -
1466 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1467 if(w <= 0) w = track_w;
1470 track_dimensions(mwindow->session->track_highlighted,
1473 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1474 // Put it in a new plugin set determined by the selected range
1475 if(mwindow->edl->local_session->get_selectionend() >
1476 mwindow->edl->local_session->get_selectionstart()) {
1477 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1478 mwindow->edl->session->sample_rate /
1479 mwindow->edl->local_session->zoom_sample -
1480 mwindow->edl->local_session->view_start[pane->number]);
1481 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1482 mwindow->edl->local_session->get_selectionstart()) *
1483 mwindow->edl->session->sample_rate /
1484 mwindow->edl->local_session->zoom_sample);
1486 // Put it in a new plugin set determined by an edit boundary
1487 else if(mwindow->session->edit_highlighted) {
1488 int64_t temp_y, temp_h;
1489 edit_dimensions(mwindow->session->edit_highlighted,
1490 x, temp_y, w, temp_h);
1492 // Put it at the beginning of the track in a new plugin set
1495 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1496 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1497 //printf("TrackCanvas::draw_highlighting 1\n");
1504 if(mwindow->session->track_highlighted) {
1505 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1507 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1509 draw_paste_destination();
1515 if(mwindow->session->track_highlighted) {
1516 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1518 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1519 draw_paste_destination();
1524 // Dragging an effect from the timeline
1525 case DRAG_AEFFECT_COPY:
1526 case DRAG_VEFFECT_COPY:
1527 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1528 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1529 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1530 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1531 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1533 int64_t plugin_position = -1;
1534 Plugin *drag_plugin = mwindow->session->drag_plugin;
1535 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1536 Track *hi_track = mwindow->session->track_highlighted;
1537 Edit *hi_edit = mwindow->session->edit_highlighted;
1538 // Put it into a silence zone
1539 if( hi_plugin_set && hi_plugin_set->last &&
1540 hi_plugin_set->track == drag_plugin->track ) {
1541 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1542 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1543 hi_track = drag_plugin->track;
1545 else if( hi_track ) {
1546 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1547 track_dimensions(hi_track, x, y, w, h);
1548 plugin_position = hi_edit ? hi_edit->startproject : 0;
1551 if( plugin_position < 0 ) break;
1553 // Calculate length of plugin based on data type of track and units
1554 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1555 mwindow->edl->local_session->zoom_sample;
1556 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1557 mwindow->edl->local_session->view_start[pane->number];
1558 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1560 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1561 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1567 case DRAG_PLUGINKEY:
1568 if(mwindow->session->plugin_highlighted &&
1569 mwindow->session->current_operation == DRAG_PLUGINKEY)
1571 // Just highlight the plugin
1572 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1574 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1575 MWindowGUI::visible(y, y + h, 0, get_h()))
1587 draw_highlight_rectangle(x, y, w, h);
1591 void TrackCanvas::draw_plugins()
1593 char string[BCTEXTLEN];
1595 int current_show = 0;
1598 // if(!mwindow->edl->session->show_assets) goto done;
1600 for(int i = 0; i < plugin_on_toggles.total; i++)
1601 plugin_on_toggles.values[i]->in_use = 0;
1602 for(int i = 0; i < plugin_show_toggles.total; i++)
1603 plugin_show_toggles.values[i]->in_use = 0;
1606 for(Track *track = mwindow->edl->tracks->first;
1608 track = track->next)
1610 if(track->expand_view)
1612 for(int i = 0; i < track->plugin_set.total; i++)
1614 PluginSet *pluginset = track->plugin_set.values[i];
1616 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1618 int64_t total_x, y, total_w, h;
1619 plugin_dimensions(plugin, total_x, y, total_w, h);
1621 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1622 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1623 plugin->plugin_type != PLUGIN_NONE)
1625 int x = total_x, w = total_w, left_margin = 5;
1626 int right_margin = 5;
1632 if(w + x > get_w()) w -= (w + x) - get_w();
1639 mwindow->theme->get_image("plugin_bg_data"),
1641 set_color(mwindow->theme->title_color);
1642 set_font(mwindow->theme->title_font);
1643 plugin->calculate_title(string, 0);
1645 // Truncate string to int64_test visible in background
1646 int len = strlen(string), j;
1647 for(j = len; j >= 0; j--)
1649 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1657 // Justify the text on the left boundary of the edit if it is visible.
1658 // Otherwise justify it on the left side of the screen.
1659 int64_t text_x = total_x + left_margin;
1660 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1661 text_x = MAX(left_margin, text_x);
1663 y + get_text_ascent(mwindow->theme->title_font) + 2,
1667 int64_t min_x = total_x + text_w;
1670 // Update plugin toggles
1671 int toggle_x = total_x + total_w;
1673 toggle_x = MIN(get_w() - right_margin, toggle_x);
1676 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1677 if(toggle_x > min_x)
1679 if(current_on >= plugin_on_toggles.total)
1681 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1682 add_subwindow(plugin_on);
1683 plugin_on_toggles.append(plugin_on);
1687 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1692 // Toggles for standalone plugins only
1693 if(plugin->plugin_type == PLUGIN_STANDALONE)
1696 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1697 if(toggle_x > min_x)
1699 if(current_show >= plugin_show_toggles.total)
1701 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1702 add_subwindow(plugin_show);
1703 plugin_show_toggles.append(plugin_show);
1707 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1721 // Remove unused toggles
1723 while(current_show < plugin_show_toggles.total)
1725 plugin_show_toggles.remove_object_number(current_show);
1728 while(current_on < plugin_on_toggles.total)
1730 plugin_on_toggles.remove_object_number(current_on);
1735 void TrackCanvas::refresh_plugintoggles()
1737 for(int i = 0; i < plugin_on_toggles.total; i++)
1739 PluginOn *on = plugin_on_toggles.values[i];
1740 on->reposition_window(on->get_x(), on->get_y());
1742 for(int i = 0; i < plugin_show_toggles.total; i++)
1744 PluginShow *show = plugin_show_toggles.values[i];
1745 show->reposition_window(show->get_x(), show->get_y());
1749 void TrackCanvas::draw_inout_points()
1754 void TrackCanvas::draw_drag_handle()
1756 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1757 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1759 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1760 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1761 mwindow->edl->session->sample_rate /
1762 mwindow->edl->local_session->zoom_sample -
1763 mwindow->edl->local_session->view_start[pane->number]);
1764 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1767 //printf("TrackCanvas::draw_drag_handle 3\n");
1768 draw_line(pixel1, 0, pixel1, get_h());
1770 //printf("TrackCanvas::draw_drag_handle 4\n");
1775 void TrackCanvas::draw_transitions()
1779 // if(!mwindow->edl->session->show_assets) return;
1781 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1782 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1783 if(!edit->transition) continue;
1784 edit_dimensions(edit, x, y, w, h);
1785 int strip_x = x, strip_y = y;
1786 if(mwindow->edl->session->show_titles)
1787 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1788 get_transition_coords(x, y, w, h);
1789 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1790 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1791 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1792 MWindowGUI::visible(y, y + h, 0, get_h()) )
1794 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1796 if( !server ) continue;
1797 VFrame *picon = server->get_picon();
1798 if( !picon ) continue;
1799 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1801 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1802 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1804 int x = strip_x, w = strip_w;
1810 if(w + x > get_w()) w -= (w + x) - get_w();
1812 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1813 mwindow->theme->get_image("plugin_bg_data"), 0);
1819 void TrackCanvas::draw_loop_points()
1821 //printf("TrackCanvas::draw_loop_points 1\n");
1822 if(mwindow->edl->local_session->loop_playback)
1824 //printf("TrackCanvas::draw_loop_points 2\n");
1825 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1826 mwindow->edl->session->sample_rate /
1827 mwindow->edl->local_session->zoom_sample -
1828 mwindow->edl->local_session->view_start[pane->number]);
1829 //printf("TrackCanvas::draw_loop_points 3\n");
1831 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1834 draw_line(x, 0, x, get_h());
1836 //printf("TrackCanvas::draw_loop_points 4\n");
1838 x = Units::round(mwindow->edl->local_session->loop_end *
1839 mwindow->edl->session->sample_rate /
1840 mwindow->edl->local_session->zoom_sample -
1841 mwindow->edl->local_session->view_start[pane->number]);
1842 //printf("TrackCanvas::draw_loop_points 5\n");
1844 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1847 draw_line(x, 0, x, get_h());
1849 //printf("TrackCanvas::draw_loop_points 6\n");
1851 //printf("TrackCanvas::draw_loop_points 7\n");
1854 void TrackCanvas::draw_brender_start()
1856 if(mwindow->preferences->use_brender)
1858 int64_t x = Units::round(mwindow->edl->session->brender_start *
1859 mwindow->edl->session->sample_rate /
1860 mwindow->edl->local_session->zoom_sample -
1861 mwindow->edl->local_session->view_start[pane->number]);
1863 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1866 draw_line(x, 0, x, get_h());
1871 static int auto_colors[AUTOMATION_TOTAL] =
1887 // The operations which correspond to each automation type
1888 static int auto_operations[AUTOMATION_TOTAL] =
1904 // The buttonpress operations, so nothing changes unless the mouse moves
1905 // a certain amount. This allows the keyframe to be used to position the
1906 // insertion point without moving itself.
1907 static int pre_auto_operations[AUTOMATION_TOTAL] =
1924 int TrackCanvas::do_keyframes(int cursor_x,
1932 // Note: button 3 (right mouse button) is not eaten to allow
1933 // track context menu to appear
1935 EDLSession *session = mwindow->edl->session;
1939 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1941 0, 0, 0, 0, 0, 0, 0, 0,
1943 modekeyframe_pixmap,
1944 maskkeyframe_pixmap,
1949 for(Track *track = mwindow->edl->tracks->first;
1951 track = track->next) {
1952 Auto *auto_keyframe = 0;
1953 Automation *automation = track->automation;
1956 // Handle keyframes in reverse drawing order if a button press
1958 int end = AUTOMATION_TOTAL;
1962 start = AUTOMATION_TOTAL - 1;
1966 for(int i = start; i != end && !result; i += step)
1968 // Event not trapped and automation visible
1969 Autos *autos = automation->autos[i];
1970 if(!result && session->auto_conf->autos[i] && autos) {
1972 case AUTOMATION_MODE:
1973 case AUTOMATION_PAN:
1974 case AUTOMATION_MASK:
1975 result = do_autos(track, automation->autos[i],
1976 cursor_x, cursor_y, draw,
1977 buttonpress, auto_pixmaps[i],
1978 auto_keyframe, rerender);
1982 switch(autos->get_type()) {
1983 case Autos::AUTOMATION_TYPE_FLOAT: {
1984 Automation automation(0, track);
1985 int grouptype = automation.autogrouptype(i, track);
1986 if(draw) // Do dropshadow
1987 result = do_float_autos(track, autos,
1988 cursor_x, cursor_y, draw,
1989 buttonpress, 1, 1, MDGREY,
1990 auto_keyframe, grouptype);
1992 result = do_float_autos(track, autos,
1993 cursor_x, cursor_y, draw,
1994 buttonpress, 0, 0, auto_colors[i],
1995 auto_keyframe, grouptype);
1998 case Autos::AUTOMATION_TYPE_INT: {
1999 if(draw) // Do dropshadow
2000 result = do_int_autos(track, autos,
2001 cursor_x, cursor_y, draw,
2002 buttonpress, 1, 1, MDGREY,
2004 result = do_int_autos(track, autos,
2005 cursor_x, cursor_y, draw,
2006 buttonpress, 0, 0, auto_colors[i],
2015 if(mwindow->session->current_operation == auto_operations[i])
2018 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2020 // mwindow->session->current_operation,
2021 // auto_operations[i]);
2024 if (buttonpress != 3)
2026 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2027 synchronize_autos(0,
2029 (FloatAuto*)mwindow->session->drag_auto,
2031 mwindow->session->current_operation = pre_auto_operations[i];
2032 update_drag_caption();
2035 else if( auto_keyframe )
2037 gui->keyframe_menu->update(automation,
2040 gui->keyframe_menu->activate_menu();
2041 rerender = 1; // the position changes
2045 gui->keyframe_hide->update(autos);
2046 gui->keyframe_hide->activate_menu();
2047 rerender = 1; // the position changes
2049 if(buttonpress == 1 && ctrl_down() &&
2050 AUTOMATION_TYPE_FLOAT == autos->get_type())
2051 rerender = 1; // special case: curve mode changed
2058 session->auto_conf->plugins /* &&
2059 mwindow->edl->session->show_assets */) {
2062 result = do_plugin_autos(track, cursor_x, cursor_y,
2063 draw, buttonpress, plugin, keyframe);
2064 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2067 if(result && (buttonpress == 1)) {
2068 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2069 update_drag_caption();
2072 else if (result && (buttonpress == 3)) {
2073 gui->keyframe_menu->update(plugin, keyframe);
2074 gui->keyframe_menu->activate_menu();
2075 rerender = 1; // the position changes
2080 // Final pass to trap event
2081 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2082 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2083 mwindow->session->current_operation == auto_operations[i]) {
2089 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2090 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2096 new_cursor = UPRIGHT_ARROW_CURSOR;
2103 void TrackCanvas::draw_keyframe_reticle()
2105 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2106 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2108 int current_op = mwindow->session->current_operation, dragging = 0;
2109 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2110 if( current_op == auto_operations[i] ) dragging = 1;
2112 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2113 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2114 draw_hairline(mwindow->session->drag_auto, RED);
2119 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2120 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2121 for( Track *track = mwindow->edl->tracks->first; track;
2122 track=track->next ) {
2123 Automation *automation = track->automation;
2124 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2125 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2126 // automation visible
2127 Autos *autos = automation->autos[i];
2128 if( !autos ) continue;
2129 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2130 auto_keyframe = auto_keyframe->next ) {
2131 draw_hairline(auto_keyframe, GREEN);
2135 if( dragging && mwindow->session->drag_auto ) {
2136 draw_hairline(mwindow->session->drag_auto, RED);
2142 void TrackCanvas::draw_auto(Auto *current,
2150 x1 = x - HANDLE_W / 2;
2151 x2 = x + HANDLE_W / 2;
2152 y1 = center_pixel + y - HANDLE_W / 2;
2153 y2 = center_pixel + y + HANDLE_W / 2;
2155 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2156 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2158 draw_box(x1, y1, x2 - x1, y2 - y1);
2162 // This draws lines for bezier in & out controls
2163 void TrackCanvas::draw_cropped_line(int x1,
2172 // Don't care about x since it is clipped by the window.
2173 // Put y coords in ascending order
2175 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2176 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2181 double slope = (double)(x2 - x1) / (y2 - y1);
2182 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2184 x1 = (int)(x1 + (min_y - y1) * slope);
2187 else if(y1 >= max_y) {
2188 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2193 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2196 else if(y2 < min_y) {
2197 x2 = (int)(x2 + (min_y - y2) * slope);
2202 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2203 if( y1 >= min_y && y1 < max_y &&
2204 y2 >= min_y && y2 < max_y )
2205 draw_line(x1, y1, x2, y2);
2209 void TrackCanvas::draw_floatauto(FloatAuto *current,
2220 int x1 = x - HANDLE_W / 2; // Center
2221 int x2 = x + HANDLE_W / 2;
2222 int y1 = center_pixel + y - HANDLE_H / 2;
2223 int y2 = center_pixel + y + HANDLE_H / 2;
2224 int ymin = center_pixel - zoom_track / 2;
2225 int ymax = center_pixel + zoom_track / 2;
2226 CLAMP(y1, ymin, ymax);
2227 CLAMP(y2, ymin, ymax);
2232 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2234 draw_box(x1, y1, x2 - x1, y2 - y1);
2237 // show bezier control points (only) if this
2238 // floatauto doesn't adjust it's tangents automatically
2239 if(current->curve_mode != FloatAuto::FREE &&
2240 current->curve_mode != FloatAuto::TFREE)
2244 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2246 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2249 inline int quantize(float f) { return (int)floor(f + 0.5); }
2251 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2252 int x, int y, int cp_x, int cp_y, int center_pixel,
2253 int zoom_track, int color)
2254 // draw the tangent and a handle for given bézier ctrl point
2256 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2258 float slope = (float)(cp_y - y)/(cp_x - x);
2259 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2261 cp_x = x + quantize((cp_y - y) / slope);
2264 cp_y += center_pixel;
2266 // drawing the tangent as a dashed line...
2267 int const dash = HANDLE_W;
2268 int const gap = HANDLE_W / 2;
2269 float sx = 3 * (cp_x - x) / 4.;
2272 // q is the x displacement for a unit line of slope
2273 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2275 float dist = 1/q * sx;
2281 float sy = slope * sx, ey = slope * ex;
2282 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2289 int r = HANDLE_W / 2;
2290 int cp_x1 = cp_x - r;
2291 int cp_y1 = cp_y - r;
2293 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2295 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2300 int TrackCanvas::test_auto(Auto *current,
2301 int x, int y, int center_pixel, int zoom_track,
2302 int cursor_x, int cursor_y, int buttonpress)
2307 x1 = x - HANDLE_W / 2;
2308 x2 = x + HANDLE_W / 2;
2309 y1 = center_pixel + y - HANDLE_H / 2;
2310 y2 = center_pixel + y + HANDLE_H / 2;
2311 int ymin = center_pixel - zoom_track / 2;
2312 int ymax = center_pixel + zoom_track / 2;
2313 CLAMP(y1, ymin, ymax);
2314 CLAMP(y2, ymin, ymax);
2316 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2318 if(buttonpress && buttonpress != 3)
2320 mwindow->session->drag_auto = current;
2321 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2322 // Toggle Autos don't respond to vertical zoom, they always show up
2323 // with "on" == 100% == line on top
2324 mwindow->session->drag_start_position = current->position;
2325 mwindow->session->drag_origin_x = cursor_x;
2326 mwindow->session->drag_origin_y = cursor_y;
2331 if(buttonpress && buttonpress != 3 && result)
2333 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2334 mwindow->undo->update_undo_before();
2340 // some Helpers for test_floatauto(..)
2341 // and for dragging the tangents/ctrl points
2342 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2343 float cursor_x, float cursor_y)
2345 // Control point switched off?
2346 if( x0 == ctrl_x ) return 0.0;
2347 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2348 double x = cursor_x-x0, y = cursor_y-y0;
2349 // wrong side of ctrl handle
2350 if( x*x1 < 0 ) return 0.0;
2351 // outside handle radius
2352 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2353 double xx1 = x1*x1, yy1 = y1*y1;
2354 double xx = x*x, yy = y*y;
2355 // distance squared from cursor to cursor projected to line from ctrl to handle
2356 // along a line perpendicular to line from ctrl to handle (closest approach)
2357 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2358 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2359 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2364 float levered_position(float position, float ref_pos)
2366 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2368 return ref_pos / position;
2372 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2373 // transforms automation value into current display coords,
2374 // dependant on current automation display range for the given kind of automation
2376 if(!mwindow || !mwindow->edl) return 0;
2377 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2378 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2379 float automation_range = automation_max - automation_min;
2380 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2382 return (auto_value - automation_min) / automation_range;
2387 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2388 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2389 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2393 int x1 = x - HANDLE_W / 2;
2394 int x2 = x + HANDLE_W / 2;
2395 int y1 = center_pixel + y - HANDLE_W / 2;
2396 int y2 = center_pixel + y + HANDLE_W / 2;
2397 int ymin = center_pixel - zoom_track / 2;
2398 int ymax = center_pixel + zoom_track / 2;
2399 CLAMP(y1, ymin, ymax);
2400 CLAMP(y2, ymin, ymax);
2402 int in_x1 = in_x - HANDLE_W / 2;
2403 int in_x2 = in_x + HANDLE_W / 2;
2404 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2405 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2406 CLAMP(in_y1, ymin, ymax);
2407 CLAMP(in_y2, ymin, ymax);
2409 int out_x1 = out_x - HANDLE_W / 2;
2410 int out_x2 = out_x + HANDLE_W / 2;
2411 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2412 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2413 CLAMP(out_y1, ymin, ymax);
2414 CLAMP(out_y2, ymin, ymax);
2417 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2418 // buttonpress could be the start of a drag operation
2419 #define INIT_DRAG(POS,VAL) \
2420 mwindow->session->drag_auto = current; \
2421 mwindow->session->drag_origin_x = cursor_x; \
2422 mwindow->session->drag_origin_y = cursor_y; \
2423 mwindow->session->drag_start_position = (POS); \
2424 mwindow->session->drag_start_percentage = (VAL);
2426 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2429 // without modifier we are manipulating the automation node
2430 // with ALT it's about dragging only the value of the node
2431 // with SHIFT the value snaps to the value of neighbouring nodes
2432 // CTRL indicates we are rather manipulating the tangent(s) of the node
2436 if( WITHIN(x1,x2,y1,y2))
2437 { // cursor hits node
2440 if(buttonpress && (buttonpress != 3))
2442 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2443 mwindow->session->drag_handle = 0;
2448 if( WITHIN(x1,x2,y1,y2))
2451 if(buttonpress && (buttonpress != 3))
2453 // could be ctrl-click or ctrl-drag
2454 // click would cycle through tangent modes
2455 ((FloatAuto*)current)->toggle_curve_mode();
2457 // drag will start dragging the tangent, if applicable
2458 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2459 mwindow->session->drag_handle = 0;
2463 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2466 if( in_x != x && current->position > 0 &&
2467 (FloatAuto::FREE == current->curve_mode ||
2468 FloatAuto::TFREE == current->curve_mode))
2469 // act on in control handle only if
2470 // tangent is significant and is editable (not automatically choosen)
2472 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2473 // either cursor in ctrl-point handle or cursor on tangent line
2474 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2476 if(buttonpress && (buttonpress != 3)) {
2477 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2479 mwindow->session->drag_handle = 1;
2480 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2481 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2482 value_to_percentage(new_invalue, autogrouptype))
2489 (FloatAuto::FREE == current->curve_mode ||
2490 FloatAuto::TFREE == current->curve_mode))
2491 // act on out control only if tangent is significant and is editable
2493 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2494 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2496 if(buttonpress && (buttonpress != 3)) {
2497 if(lever == 0.0) lever=1.0;
2499 mwindow->session->drag_handle = 2;
2500 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2501 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2502 value_to_percentage(new_outvalue, autogrouptype))
2506 } // end ctrl_down()
2512 // 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",
2513 // mwindow->session->drag_handle,
2518 if(buttonpress && (buttonpress != 3) && result)
2520 mwindow->undo->update_undo_before();
2527 // Get the float value & y for position x on the canvas
2528 #define X_TO_FLOATLINE(x) \
2529 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2530 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2531 /* Call by reference fails for some reason here */ \
2532 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2533 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2534 double position = unit_start + x * zoom_units; \
2536 if(position2 > position1) \
2539 (value2 - value1) * \
2540 (position - position1) / \
2541 (position2 - position1); \
2547 AUTOMATIONCLAMPS(value, autogrouptype); \
2548 int y = center_pixel + \
2549 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2552 void TrackCanvas::draw_floatline(int center_pixel,
2553 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2554 double unit_start, double zoom_units, double yscale,
2555 int x1, int y1, int x2, int y2,
2556 int color, int autogrouptype)
2558 // Solve bezier equation for either every pixel or a certain large number of
2561 // Not using slope intercept
2563 int prev_y = y1 + center_pixel;
2566 // Call by reference fails for some reason here
2567 FloatAuto *previous1 = previous, *next1 = next;
2568 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2569 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2570 float automation_range = automation_max - automation_min;
2572 for(int x = x1; x < x2; x++)
2574 // Interpolate value between frames
2578 y >= center_pixel - yscale / 2 &&
2579 y < center_pixel + yscale / 2 - 1)
2581 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2583 // (int)(center_pixel - yscale / 2),
2584 // (int)(center_pixel + yscale / 2 - 1));
2586 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2587 draw_line(x - 1, prev_y , x, y );
2597 int TrackCanvas::test_floatline(int center_pixel,
2612 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2613 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2614 float automation_range = automation_max - automation_min;
2615 FloatAuto *previous1 = 0, *next1 = 0;
2616 X_TO_FLOATLINE(cursor_x);
2618 if(cursor_x >= x1 &&
2620 cursor_y >= y - HANDLE_W / 2 &&
2621 cursor_y < y + HANDLE_W / 2 &&
2627 if(buttonpress == 3)
2635 mwindow->undo->update_undo_before();
2636 current = mwindow->session->drag_auto = autos->insert_auto(position1);
2637 ((FloatAuto*)current)->set_value(value);
2638 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2639 mwindow->session->drag_start_position = current->position;
2640 mwindow->session->drag_origin_x = cursor_x;
2641 mwindow->session->drag_origin_y = cursor_y;
2642 mwindow->session->drag_handle = 0;
2651 void TrackCanvas::synchronize_autos(float change,
2652 Track *skip, FloatAuto *fauto, int fill_gangs)
2654 // Handles the special case of modifying a fadeauto
2655 // when there are ganged faders on several tracks
2656 // (skip and fauto may be NULL if fill_gangs==-1)
2658 if( fill_gangs > 0 && skip->gang ) {
2659 double position = skip->from_units(fauto->position);
2660 int autoidx = fauto->autos->autoidx;
2662 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2663 if( (current->data_type == skip->data_type || get_double_click()) &&
2664 current->gang && current->record && current != skip ) {
2665 int64_t current_position = current->to_units(position, 1);
2666 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2667 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2668 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2669 FloatAuto *previous = 0, *next = 0;
2670 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2672 // create keyframe on neighbouring track at the point in time given by fauto
2673 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2674 float new_value = init_value + change;
2675 CLAMP(new_value, auto_min, auto_max);
2676 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2677 keyframe->set_value(new_value);
2680 // keyframe exists, just change it
2681 float new_value = keyframe->get_value() + change;
2682 CLAMP(new_value, auto_min, auto_max);
2683 keyframe->adjust_to_new_coordinates(current_position, new_value);
2684 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2687 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2691 else if( !fill_gangs ) {
2692 double position = skip->from_units(fauto->position);
2694 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2695 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2696 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2697 float new_value = keyframe->get_value() + change;
2699 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2700 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2701 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2707 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2708 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2709 keyframe->autos->remove_nonsequential(
2712 mwindow->session->drag_auto_gang->remove_all();
2717 void TrackCanvas::draw_toggleline(int center_pixel,
2723 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2727 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2731 int TrackCanvas::test_toggleline(Autos *autos,
2742 if(cursor_x >= x1 && cursor_x < x2)
2744 int miny = center_pixel + y1 - HANDLE_W / 2;
2745 int maxy = center_pixel + y1 + HANDLE_W / 2;
2746 if(cursor_y >= miny && cursor_y < maxy)
2751 if(buttonpress == 3)
2759 double position = (double)(cursor_x +
2760 mwindow->edl->local_session->view_start[pane->number]) *
2761 mwindow->edl->local_session->zoom_sample /
2762 mwindow->edl->session->sample_rate;
2763 int64_t unit_position = autos->track->to_units(position, 0);
2764 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2766 mwindow->undo->update_undo_before();
2768 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2769 ((IntAuto*)current)->value = new_value;
2770 // Toggle Autos don't respond to vertical zoom, they always show up
2771 // with "on" == 100% == line on top
2772 mwindow->session->drag_start_percentage = (float)new_value;
2773 mwindow->session->drag_start_position = current->position;
2774 mwindow->session->drag_origin_x = cursor_x;
2775 mwindow->session->drag_origin_y = cursor_y;
2783 void TrackCanvas::calculate_viewport(Track *track,
2784 double &view_start, // Seconds
2786 double &view_end, // Seconds
2790 double &zoom_sample,
2793 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2794 mwindow->edl->local_session->zoom_sample /
2795 mwindow->edl->session->sample_rate;
2796 unit_start = track->to_doubleunits(view_start);
2797 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2799 mwindow->edl->local_session->zoom_sample /
2800 mwindow->edl->session->sample_rate;
2801 unit_end = track->to_doubleunits(view_end);
2802 yscale = mwindow->edl->local_session->zoom_track;
2803 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2804 center_pixel = (int)(track->y_pixel -
2805 mwindow->edl->local_session->track_start[pane->number] +
2807 (mwindow->edl->session->show_titles ?
2808 mwindow->theme->get_image("title_bg_data")->get_h() :
2810 zoom_sample = mwindow->edl->local_session->zoom_sample;
2812 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2815 float TrackCanvas::percentage_to_value(float percentage,
2823 if(percentage > 0.5)
2830 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2831 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2832 float automation_range = automation_max - automation_min;
2834 result = percentage * automation_range + automation_min;
2837 FloatAuto *ptr = (FloatAuto*)reference;
2838 result -= ptr->get_value();
2840 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2846 void TrackCanvas::calculate_auto_position(double *x, double *y,
2847 double *in_x, double *in_y, double *out_x, double *out_y,
2848 Auto *current, double unit_start, double zoom_units, double yscale,
2851 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2852 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2853 float automation_range = automation_max - automation_min;
2854 FloatAuto *ptr = (FloatAuto*)current;
2855 *x = (double)(ptr->position - unit_start) / zoom_units;
2856 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2859 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2860 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2864 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2865 automation_min) / automation_range - 0.5) * -yscale;
2869 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2870 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2874 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2875 automation_min) / automation_range - 0.5) * -yscale;
2880 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2881 int draw, int buttonpress, int x_offset, int y_offset, int color,
2882 Auto* &auto_instance, int autogrouptype)
2885 int center_pixel, draw_auto;
2886 double view_start, unit_start;
2887 double view_end, unit_end, yscale;
2888 double zoom_sample, zoom_units;
2889 double in_x2, in_y2, out_x2, out_y2;
2895 if(draw) set_color(color);
2897 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2898 yscale, center_pixel, zoom_sample, zoom_units);
2900 // Get first auto before start
2901 Auto *current = 0, *previous = 0;
2903 for( current = autos->last;
2904 current && current->position >= unit_start;
2905 current = PREVIOUS ) ;
2907 Auto *first_auto = current ? current :
2908 autos->first ? autos->first : autos->default_auto;
2910 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2912 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2913 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2918 current = autos->first;
2927 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2928 current, unit_start, zoom_units, yscale, autogrouptype);
2936 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2941 ay2 = ay + slope * (get_w() - ax);
2945 ay = ay + slope * (0 - ax);
2949 // Draw or test handle
2950 if( current && !result && current != autos->default_auto ) {
2951 if( !draw && track->record ) {
2952 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
2953 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
2954 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
2955 buttonpress, autogrouptype);
2957 auto_instance = current;
2959 if( draw && draw_auto ) {
2960 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
2961 (int)in_x2 + x_offset, (int)in_y2,
2962 (int)out_x2 + x_offset, (int)out_y2,
2963 (int)center_pixel + y_offset, (int)yscale, color);
2967 // Draw or test joining line
2968 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
2969 result = test_floatline(center_pixel,
2970 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2971 // Exclude auto coverage from the end of the line. The auto overlaps
2972 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
2973 buttonpress, autogrouptype);
2976 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
2977 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2978 (int)ax, (int)ay, (int)ax2, (int)ay2,
2979 color, autogrouptype);
2987 } while( current && current->position <= unit_end && !result );
2989 if( ax < get_w() && !result ) {
2990 ax2 = get_w(); ay2 = ay;
2991 if(!draw && track->record /* && buttonpress != 3 */ ) {
2992 result = test_floatline(center_pixel,
2993 (FloatAutos*)autos, unit_start, zoom_units, yscale,
2994 (int)ax, (int)ax2, cursor_x, cursor_y,
2995 buttonpress, autogrouptype);
2998 draw_floatline(center_pixel,
2999 (FloatAuto*)previous, (FloatAuto*)current,
3000 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3001 (int)ax, (int)ay, (int)ax2, (int)ay2,
3002 color, autogrouptype);
3009 int TrackCanvas::do_int_autos(Track *track,
3018 Auto *&auto_instance)
3029 double ax, ay, ax2, ay2;
3033 if(draw) set_color(color);
3035 calculate_viewport(track,
3046 double high = -yscale * 0.8 / 2;
3047 double low = yscale * 0.8 / 2;
3049 // Get first auto before start
3051 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3057 ay = ((IntAuto*)current)->value > 0 ? high : low;
3062 current = autos->first ? autos->first : autos->default_auto;
3066 ay = ((IntAuto*)current)->value > 0 ? high : low;
3079 ax2 = (double)(current->position - unit_start) / zoom_units;
3080 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3088 if(ax2 > get_w()) ax2 = get_w();
3090 if(current && !result)
3092 if(current != autos->default_auto)
3098 result = test_auto(current,
3107 auto_instance = current;
3112 (int)ax2 + x_offset,
3113 (int)ay2 + y_offset,
3125 if(track->record /* && buttonpress != 3 */)
3127 result = test_toggleline(autos,
3140 draw_toggleline(center_pixel + y_offset,
3148 }while(current && current->position <= unit_end && !result);
3150 if(ax < get_w() && !result)
3156 if(track->record /* && buttonpress != 3 */)
3158 result = test_toggleline(autos,
3170 draw_toggleline(center_pixel + y_offset,
3179 int TrackCanvas::do_autos(Track *track,
3186 Auto * &auto_instance,
3200 calculate_viewport(track,
3213 for(current = autos->first; current && !result; current = NEXT)
3215 if(current->position >= unit_start && current->position < unit_end)
3218 x = (int64_t)((double)(current->position - unit_start) /
3219 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3220 y = center_pixel - pixmap->get_h() / 2;
3224 if(cursor_x >= x && cursor_y >= y &&
3225 cursor_x < x + pixmap->get_w() &&
3226 cursor_y < y + pixmap->get_h())
3229 auto_instance = current;
3231 if(buttonpress && (buttonpress != 3))
3233 mwindow->session->drag_auto = current;
3234 mwindow->session->drag_start_position = current->position;
3235 mwindow->session->drag_origin_x = cursor_x;
3236 mwindow->session->drag_origin_y = cursor_y;
3238 double position = autos->track->from_units(current->position);
3239 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3240 mwindow->edl->local_session->get_selectionend(1)) /
3245 mwindow->edl->local_session->set_selectionstart(position);
3246 mwindow->edl->local_session->set_selectionend(position);
3249 if(position < center)
3251 mwindow->edl->local_session->set_selectionstart(position);
3254 mwindow->edl->local_session->set_selectionend(position);
3261 draw_pixmap(pixmap, x, y);
3269 // so this means it is always >0 when keyframe is found
3270 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3271 int draw, int buttonpress, Plugin* &keyframe_plugin,
3272 KeyFrame* &keyframe_instance)
3285 if(!track->expand_view) return 0;
3287 calculate_viewport(track,
3299 for(int i = 0; i < track->plugin_set.total && !result; i++)
3301 PluginSet *plugin_set = track->plugin_set.values[i];
3302 int center_pixel = (int)(track->y_pixel -
3303 mwindow->edl->local_session->track_start[pane->number] +
3304 mwindow->edl->local_session->zoom_track +
3305 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3306 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3308 for(Plugin *plugin = (Plugin*)plugin_set->first;
3310 plugin = (Plugin*)plugin->next)
3312 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3313 keyframe && !result;
3314 keyframe = (KeyFrame*)keyframe->next)
3316 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3317 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3319 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3320 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3322 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3325 if(cursor_x >= x && cursor_y >= y &&
3326 cursor_x < x + keyframe_pixmap->get_w() &&
3327 cursor_y < y + keyframe_pixmap->get_h())
3330 keyframe_plugin = plugin;
3331 keyframe_instance = keyframe;
3335 mwindow->session->drag_auto = keyframe;
3336 mwindow->session->drag_start_position = keyframe->position;
3337 mwindow->session->drag_origin_x = cursor_x;
3338 mwindow->session->drag_origin_y = cursor_y;
3340 double position = track->from_units(keyframe->position);
3341 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3342 mwindow->edl->local_session->get_selectionend(1)) /
3347 mwindow->edl->local_session->set_selectionstart(position);
3348 mwindow->edl->local_session->set_selectionend(position);
3351 if(position < center)
3353 mwindow->edl->local_session->set_selectionstart(position);
3356 mwindow->edl->local_session->set_selectionend(position);
3361 draw_pixmap(keyframe_pixmap,
3371 // if(buttonpress && buttonpress != 3 && result)
3373 // mwindow->undo->update_undo_before();
3379 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3381 Track *track = auto_keyframe->autos->track;
3382 int autogrouptype = auto_keyframe->autos->get_type();
3385 double view_start, unit_start;
3386 double view_end, unit_end, yscale;
3387 double zoom_sample, zoom_units;
3389 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3390 yscale, center_pixel, zoom_sample, zoom_units);
3392 double ax = 0, ay = 0;
3393 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3394 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3397 draw_line(ax, 0, ax, get_h());
3401 void TrackCanvas::draw_overlays()
3403 int new_cursor, update_cursor, rerender;
3405 // Move background pixmap to foreground pixmap
3406 draw_pixmap(background_pixmap,
3415 draw_inout_points();
3418 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3425 draw_brender_start();
3427 // Highlighted areas
3428 draw_highlighting();
3431 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3434 if(pane->cursor) pane->cursor->restore(1);
3440 draw_playback_cursor();
3442 draw_keyframe_reticle();
3447 int TrackCanvas::activate()
3451 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3452 //BC_Signals::dump_stack();
3453 get_top_level()->deactivate();
3455 set_active_subwindow(this);
3456 pane->cursor->activate();
3457 gui->focused_pane = pane->number;
3462 int TrackCanvas::deactivate()
3467 pane->cursor->deactivate();
3473 void TrackCanvas::update_drag_handle()
3475 double new_position;
3478 (double)(get_cursor_x() +
3479 mwindow->edl->local_session->view_start[pane->number]) *
3480 mwindow->edl->local_session->zoom_sample /
3481 mwindow->edl->session->sample_rate;
3483 mwindow->edl->align_to_frame(new_position, 0);
3486 if(new_position != mwindow->session->drag_position)
3488 mwindow->session->drag_position = new_position;
3489 gui->mainclock->update(new_position);
3492 timebar_position = new_position;
3493 gui->update_timebar(0);
3494 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3496 // mwindow->cwindow->update(1, 0, 0);
3500 int TrackCanvas::update_drag_edit()
3509 int TrackCanvas::get_drag_values(float *percentage,
3516 //int x = cursor_x - mwindow->session->drag_origin_x;
3517 //int y = cursor_y - mwindow->session->drag_origin_y;
3521 if(!current->autos->track->record) return 1;
3531 calculate_viewport(current->autos->track,
3541 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3543 mwindow->session->drag_start_percentage;
3544 if(do_clamp) CLAMP(*percentage, 0, 1);
3546 *position = Units::to_int64(zoom_units *
3547 (cursor_x - mwindow->session->drag_origin_x) +
3548 mwindow->session->drag_start_position + 0.5);
3550 if((do_clamp) && *position < 0) *position = 0;
3555 #define UPDATE_DRAG_HEAD(do_clamp) \
3556 int result = 0, center_pixel; \
3557 if(!current->autos->track->record) return 0; \
3558 double view_start, unit_start, view_end, unit_end; \
3559 double yscale, zoom_sample, zoom_units; \
3561 calculate_viewport(current->autos->track, \
3562 view_start, unit_start, view_end, unit_end, \
3563 yscale, center_pixel, zoom_sample, zoom_units); \
3565 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3566 yscale + mwindow->session->drag_start_percentage; \
3567 if(do_clamp) CLAMP(percentage, 0, 1); \
3569 int64_t position = Units::to_int64(zoom_units * \
3570 (cursor_x - mwindow->session->drag_origin_x) + \
3571 mwindow->session->drag_start_position); \
3572 if((do_clamp) && position < 0) position = 0;
3575 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3577 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3579 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3580 int x = cursor_x - mwindow->session->drag_origin_x;
3581 int y = cursor_y - mwindow->session->drag_origin_y;
3582 float value, old_value;
3584 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3585 // not really editing the node, rather start editing the curve
3586 // tangent is editable and drag movement is significant
3587 if( (FloatAuto::FREE == current->curve_mode ||
3588 FloatAuto::TFREE==current->curve_mode) &&
3589 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3590 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3593 switch(mwindow->session->drag_handle) {
3595 // Snap to nearby values
3596 old_value = current->get_value();
3598 double value1, value2, distance1, distance2;
3600 if(current->previous) {
3601 int autogrouptype = current->previous->autos->autogrouptype;
3602 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3603 value1 = ((FloatAuto*)current->previous)->get_value();
3604 distance1 = fabs(value - value1);
3605 current->set_value(value1);
3609 int autogrouptype = current->next->autos->autogrouptype;
3610 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3611 value2 = ((FloatAuto*)current->next)->get_value();
3612 distance2 = fabs(value - value2);
3613 if(!current->previous || distance2 < distance1) {
3614 current->set_value(value2);
3618 if(!current->previous && !current->next) {
3619 current->set_value( ((FloatAutos*)current->autos)->default_);
3621 value = current->get_value();
3624 int autogrouptype = current->autos->autogrouptype;
3625 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3628 if(alt_down() && !shift_down())
3629 // ALT constrains movement: fixed position, only changing the value
3630 position = mwindow->session->drag_start_position;
3632 if(value != old_value || position != current->position) {
3634 float change = value - old_value;
3635 current->adjust_to_new_coordinates(position, value);
3636 synchronize_autos(change, current->autos->track, current, 0);
3637 show_message(current, 1,", %.2f", current->get_value());
3643 int autogrouptype = current->autos->autogrouptype;
3644 value = percentage_to_value(percentage, 0, current, autogrouptype);
3645 if(value != current->get_control_in_value())
3648 // note: (position,value) need not be at the location of the ctrl point,
3649 // but could be somewhere in between on the curve (or even outward or
3650 // on the opposit side). We set the new control point such as
3651 // to point the curve through (position,value)
3652 current->set_control_in_value(
3653 value * levered_position(position - current->position,
3654 current->get_control_in_position()));
3655 synchronize_autos(0, current->autos->track, current, 0);
3656 show_message(current, 1,", %.2f", current->get_control_in_value());
3662 int autogrouptype = current->autos->autogrouptype;
3663 value = percentage_to_value(percentage, 0, current, autogrouptype);
3664 if(value != current->get_control_out_value()) {
3666 current->set_control_out_value(
3667 value * levered_position(position - current->position,
3668 current->get_control_out_position()));
3669 synchronize_autos(0, current->autos->track, current, 0);
3670 show_message(current, 1,", %.2f", current->get_control_out_value());
3678 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3680 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3682 UPDATE_DRAG_HEAD(1);
3683 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3685 if(value != current->value || position != current->position)
3688 current->value = value;
3689 current->position = position;
3690 show_message(current, 0,", %d", current->value);
3696 // Autos which can't change value through dragging.
3698 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3700 Auto *current = (Auto*)mwindow->session->drag_auto;
3703 if(position != current->position)
3706 current->position = position;
3707 show_message(current, 0,"");
3709 double position_f = current->autos->track->from_units(current->position);
3710 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3711 mwindow->edl->local_session->get_selectionend(1)) /
3715 mwindow->edl->local_session->set_selectionstart(position_f);
3716 mwindow->edl->local_session->set_selectionend(position_f);
3719 if(position_f < center_f)
3721 mwindow->edl->local_session->set_selectionstart(position_f);
3724 mwindow->edl->local_session->set_selectionend(position_f);
3731 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3733 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3736 if(position != current->position)
3738 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3739 Track *track = current->autos->track;
3740 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3741 PluginSet *pluginset;
3743 // figure out the correct pluginset & correct plugin
3745 for(int i = 0; i < track->plugin_set.total; i++)
3747 pluginset = track->plugin_set.values[i];
3748 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3750 KeyFrames *keyframes = plugin->keyframes;
3751 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3753 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3755 if (currentkeyframe == current)
3767 mwindow->session->plugin_highlighted = plugin;
3768 mwindow->session->track_highlighted = track;
3770 current->position = position;
3771 show_message(current, 0,"");
3773 double position_f = current->autos->track->from_units(current->position);
3774 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3775 mwindow->edl->local_session->get_selectionend(1)) /
3779 mwindow->edl->local_session->set_selectionstart(position_f);
3780 mwindow->edl->local_session->set_selectionend(position_f);
3783 if(position_f < center_f)
3785 mwindow->edl->local_session->set_selectionstart(position_f);
3788 mwindow->edl->local_session->set_selectionend(position_f);
3795 void TrackCanvas::update_drag_caption()
3797 switch(mwindow->session->current_operation)
3807 int TrackCanvas::cursor_motion_event()
3812 int update_clock = 0;
3813 int update_zoom = 0;
3814 int update_scroll = 0;
3815 int update_overlay = 0;
3816 int update_cursor = 0;
3819 double position = 0.;
3820 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3823 switch(mwindow->edl->session->editing_mode)
3825 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3826 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3829 switch(mwindow->session->current_operation)
3831 case DRAG_EDITHANDLE1:
3832 // Outside threshold. Upgrade status
3835 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3837 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3843 case DRAG_EDITHANDLE2:
3846 update_drag_handle();
3851 case DRAG_PLUGINHANDLE1:
3854 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3856 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3862 case DRAG_PLUGINHANDLE2:
3865 update_drag_handle();
3870 // Rubber band curves
3878 case DRAG_PROJECTOR_X:
3879 case DRAG_PROJECTOR_Y:
3880 case DRAG_PROJECTOR_Z:
3881 if(active) rerender = update_overlay =
3882 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3886 if(active) rerender = update_overlay =
3887 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3891 if(active) rerender = update_overlay =
3892 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3895 // Keyframe icons are sticky
3899 case DRAG_PLUGINKEY_PRE:
3901 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3902 mwindow->session->current_operation++;
3905 mwindow->undo->update_undo_before();
3913 if(active) rerender = update_overlay =
3914 update_drag_auto(get_cursor_x(), get_cursor_y());
3917 case DRAG_PLUGINKEY:
3918 if(active) rerender = update_overlay =
3919 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
3924 cursor_x = get_cursor_x();
3925 cursor_y = get_cursor_y();
3926 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
3927 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
3929 position = mwindow->edl->align_to_frame(position, 0);
3930 position = MAX(position, 0);
3932 if(position < selection_midpoint) {
3933 mwindow->edl->local_session->set_selectionend(selection_midpoint);
3934 mwindow->edl->local_session->set_selectionstart(position);
3936 gui->unlock_window();
3937 mwindow->cwindow->update(1, 0, 0, 0, 1);
3938 gui->lock_window("TrackCanvas::cursor_motion_event 1");
3939 // Update the faders
3940 mwindow->update_plugin_guis();
3941 gui->update_patchbay();
3944 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
3945 mwindow->edl->local_session->set_selectionend(position);
3946 // Don't que the CWindow
3949 timebar_position = mwindow->edl->local_session->get_selectionend(1);
3951 gui->hide_cursor(0);
3952 gui->draw_cursor(1);
3953 gui->update_timebar(0);
3954 gui->flash_canvas(1);
3963 if(is_event_win() && cursor_inside()) {
3965 cursor_x = get_cursor_x();
3966 position = (double)cursor_x *
3967 (double)mwindow->edl->local_session->zoom_sample /
3968 (double)mwindow->edl->session->sample_rate +
3969 (double)mwindow->edl->local_session->view_start[pane->number] *
3970 (double)mwindow->edl->local_session->zoom_sample /
3971 (double)mwindow->edl->session->sample_rate;
3972 position = mwindow->edl->align_to_frame(position, 0);
3976 for(int i = 0; i < TOTAL_PANES; i++)
3977 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
3979 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
3980 gui->update_timebar(0);
3982 if(do_transitions(get_cursor_x(), get_cursor_y(),
3983 0, new_cursor, update_cursor)) break;
3984 if(do_keyframes(get_cursor_x(), get_cursor_y(),
3985 0, 0, new_cursor, update_cursor, rerender)) break;
3986 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
3987 0, rerender, update_overlay, new_cursor, update_cursor)) break;
3988 // Plugin boundaries
3989 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
3990 0, rerender, update_overlay, new_cursor, update_cursor)) break;
3991 if(do_edits(get_cursor_x(), get_cursor_y(),
3992 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
3997 //printf("TrackCanvas::cursor_motion_event 1\n");
3998 if(update_cursor && new_cursor != get_cursor())
4000 set_cursor(new_cursor, 0, 1);
4003 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
4004 if(rerender && render_timer->get_difference() > 0.25 ) {
4005 render_timer->update();
4006 mwindow->restart_brender();
4007 mwindow->sync_parameters(CHANGE_PARAMS);
4008 mwindow->update_plugin_guis();
4009 gui->unlock_window();
4010 mwindow->cwindow->update(1, 0, 0, 0, 1);
4011 gui->lock_window("TrackCanvas::cursor_motion_event 2");
4015 gui->update_patchbay();
4020 if(!mwindow->cwindow->playback_engine->is_playing_back)
4021 gui->mainclock->update(position);
4025 gui->zoombar->update();
4030 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4034 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4038 if(update_overlay) {
4039 gui->draw_overlays(1);
4042 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
4046 void TrackCanvas::start_dragscroll()
4050 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4051 //printf("TrackCanvas::start_dragscroll 1\n");
4055 void TrackCanvas::stop_dragscroll()
4059 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4060 //printf("TrackCanvas::stop_dragscroll 1\n");
4064 int TrackCanvas::repeat_event(int64_t duration)
4066 if(!drag_scroll) return 0;
4067 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4069 int sample_movement = 0;
4070 int track_movement = 0;
4071 int64_t x_distance = 0;
4072 int64_t y_distance = 0;
4073 double position = 0;
4076 switch(mwindow->session->current_operation) {
4078 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4079 if(get_cursor_x() > get_w()) {
4080 x_distance = get_cursor_x() - get_w();
4081 sample_movement = 1;
4083 else if(get_cursor_x() < 0) {
4084 x_distance = get_cursor_x();
4085 sample_movement = 1;
4088 if(get_cursor_y() > get_h()) {
4089 y_distance = get_cursor_y() - get_h();
4092 else if(get_cursor_y() < 0) {
4093 y_distance = get_cursor_y();
4100 if(sample_movement) {
4101 position = (double)(get_cursor_x() +
4102 mwindow->edl->local_session->view_start[pane->number] +
4104 mwindow->edl->local_session->zoom_sample /
4105 mwindow->edl->session->sample_rate;
4106 position = mwindow->edl->align_to_frame(position, 0);
4107 position = MAX(position, 0);
4109 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4110 switch(mwindow->session->current_operation) {
4112 if(position < selection_midpoint) {
4113 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4114 mwindow->edl->local_session->set_selectionstart(position);
4116 gui->unlock_window();
4117 mwindow->cwindow->update(1, 0, 0);
4118 gui->lock_window("TrackCanvas::repeat_event");
4119 // Update the faders
4120 mwindow->update_plugin_guis();
4121 gui->update_patchbay();
4124 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4125 mwindow->edl->local_session->set_selectionend(position);
4126 // Don't que the CWindow
4131 mwindow->samplemovement(
4132 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4136 if(track_movement) {
4137 mwindow->trackmovement(y_distance, pane->number);
4143 int TrackCanvas::button_release_event()
4145 int redraw = 0, update_overlay = 0, result = 0;
4147 // printf("TrackCanvas::button_release_event %d\n",
4148 // mwindow->session->current_operation);
4150 switch(mwindow->session->current_operation) {
4151 case DRAG_EDITHANDLE2:
4152 mwindow->session->current_operation = NO_OPERATION;
4156 end_edithandle_selection();
4159 case DRAG_EDITHANDLE1:
4160 mwindow->session->current_operation = NO_OPERATION;
4165 case DRAG_PLUGINHANDLE2:
4166 mwindow->session->current_operation = NO_OPERATION;
4170 end_pluginhandle_selection();
4173 case DRAG_PLUGINHANDLE1:
4174 mwindow->session->current_operation = NO_OPERATION;
4181 // delete the drag_auto_gang first and remove out of order keys
4182 synchronize_autos(0, 0, 0, -1);
4193 case DRAG_PROJECTOR_X:
4194 case DRAG_PROJECTOR_Y:
4195 case DRAG_PROJECTOR_Z:
4196 case DRAG_PLUGINKEY:
4197 mwindow->session->current_operation = NO_OPERATION;
4198 mwindow->session->drag_handle = 0;
4199 // Remove any out-of-order keyframe
4200 if(mwindow->session->drag_auto) {
4201 mwindow->session->drag_auto->autos->remove_nonsequential(
4202 mwindow->session->drag_auto);
4203 // mwindow->session->drag_auto->autos->optimize();
4208 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4213 case DRAG_AEFFECT_COPY:
4214 case DRAG_VEFFECT_COPY:
4215 // Trap in drag stop
4220 if( !mwindow->session->current_operation ) {
4221 if( get_buttonpress() == 3 )
4222 result = do_edit_popup();
4225 // if(mwindow->session->current_operation == SELECT_REGION) {
4226 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4229 mwindow->session->current_operation = NO_OPERATION;
4231 // Traps button release events
4239 cursor_motion_event();
4241 if(update_overlay) {
4242 gui->draw_overlays(1);
4245 gui->draw_canvas(NORMAL_DRAW, 0);
4250 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4251 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4253 Edit *edit_result = 0;
4254 int handle_result = 0;
4257 if(!mwindow->edl->session->show_assets) return 0;
4259 for(Track *track = mwindow->edl->tracks->first;
4261 track = track->next) {
4262 for(Edit *edit = track->edits->first;
4264 edit = edit->next) {
4265 int64_t edit_x, edit_y, edit_w, edit_h;
4266 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4268 if(cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4269 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4270 if(cursor_x < edit_x + HANDLE_W) {
4275 else if(cursor_x >= edit_x + edit_w - HANDLE_W) {
4289 double position = 0;
4290 if(handle_result == 0) {
4291 position = edit_result->track->from_units(edit_result->startproject);
4292 new_cursor = LEFT_CURSOR;
4294 else if(handle_result == 1) {
4295 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4296 new_cursor = RIGHT_CURSOR;
4299 // Reposition cursor
4301 mwindow->session->drag_edit = edit_result;
4302 mwindow->session->drag_handle = handle_result;
4303 mwindow->session->drag_button = get_buttonpress() - 1;
4304 mwindow->session->drag_position = position;
4305 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4306 mwindow->session->drag_origin_x = get_cursor_x();
4307 mwindow->session->drag_origin_y = get_cursor_y();
4308 mwindow->session->drag_start = position;
4310 rerender = start_selection(position);
4318 int TrackCanvas::do_plugin_handles(int cursor_x,
4322 int &update_overlay,
4326 Plugin *plugin_result = 0;
4327 int handle_result = 0;
4330 // if(!mwindow->edl->session->show_assets) return 0;
4332 for(Track *track = mwindow->edl->tracks->first;
4334 track = track->next) {
4335 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4336 PluginSet *plugin_set = track->plugin_set.values[i];
4337 for(Plugin *plugin = (Plugin*)plugin_set->first;
4339 plugin = (Plugin*)plugin->next) {
4340 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4341 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4343 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4344 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4345 if(cursor_x < plugin_x + HANDLE_W) {
4346 plugin_result = plugin;
4350 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4351 plugin_result = plugin;
4358 if(result && shift_down())
4359 mwindow->session->trim_edits = plugin_set;
4365 double position = 0;
4366 if(handle_result == 0) {
4367 position = plugin_result->track->from_units(plugin_result->startproject);
4368 new_cursor = LEFT_CURSOR;
4370 else if(handle_result == 1) {
4371 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4372 new_cursor = RIGHT_CURSOR;
4376 mwindow->session->drag_plugin = plugin_result;
4377 mwindow->session->drag_handle = handle_result;
4378 mwindow->session->drag_button = get_buttonpress() - 1;
4379 mwindow->session->drag_position = position;
4380 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4381 mwindow->session->drag_origin_x = get_cursor_x();
4382 mwindow->session->drag_origin_y = get_cursor_y();
4383 mwindow->session->drag_start = position;
4385 rerender = start_selection(position);
4394 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4399 int TrackCanvas::do_edit_popup()
4402 int cursor_y = get_cursor_y();
4403 // if(!mwindow->edl->session->show_assets) return 0;
4405 for(Track *track = mwindow->edl->tracks->first;
4407 track = track->next) {
4408 int64_t track_x, track_y, track_w, track_h;
4409 track_dimensions(track, track_x, track_y, track_w, track_h);
4411 if( cursor_y >= track_y && cursor_y < track_y + track_h ) {
4412 gui->edit_menu->update(track, 0);
4413 gui->edit_menu->activate_menu();
4421 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4422 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4426 if(!mwindow->edl->session->show_assets) return 0;
4428 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4430 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4431 int64_t edit_x, edit_y, edit_w, edit_h;
4432 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4434 // Cursor inside a track
4435 // Cursor inside an edit
4436 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4437 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4438 // Select duration of edit
4440 if(get_double_click() && !drag_start) {
4441 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4442 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4443 edit->track->from_units(edit->length));
4444 if(mwindow->edl->session->cursor_on_frames)
4446 mwindow->edl->local_session->set_selectionstart(
4447 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4448 mwindow->edl->local_session->set_selectionend(
4449 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4457 else if(drag_start && track->record) {
4458 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4459 // Need to create drag window
4460 mwindow->session->current_operation = DRAG_EDIT;
4461 mwindow->session->drag_edit = edit;
4462 //printf("TrackCanvas::do_edits 2\n");
4464 // Drag only one edit if ctrl is initially down
4466 mwindow->session->drag_edits->remove_all();
4467 mwindow->session->drag_edits->append(edit);
4470 // Construct list of all affected edits
4471 mwindow->edl->tracks->get_affected_edits(
4472 mwindow->session->drag_edits,
4473 edit->track->from_units(edit->startproject),
4476 mwindow->session->drag_origin_x = cursor_x;
4477 mwindow->session->drag_origin_y = cursor_y;
4478 // Where the drag started, so we know relative position inside the edit later
4479 mwindow->session->drag_position = (double)cursor_x *
4480 mwindow->edl->local_session->zoom_sample /
4481 mwindow->edl->session->sample_rate +
4482 (double)mwindow->edl->local_session->view_start[pane->number] *
4483 mwindow->edl->local_session->zoom_sample /
4484 mwindow->edl->session->sample_rate;
4486 gui->drag_popup = new BC_DragWindow(gui,
4487 mwindow->theme->get_image("clip_icon") /*,
4488 get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
4489 get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
4501 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4506 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4507 int button_press, int &redraw, int &rerender)
4516 // if(!mwindow->edl->session->show_assets) return 0;
4519 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4520 if(!track->expand_view) continue;
4522 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4523 // first check if plugins are visible at all
4524 if (!track->expand_view)
4526 PluginSet *plugin_set = track->plugin_set.values[i];
4527 for(plugin = (Plugin*)plugin_set->first;
4529 plugin = (Plugin*)plugin->next) {
4530 plugin_dimensions(plugin, x, y, w, h);
4531 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4532 MWindowGUI::visible(y, y + h, 0, get_h())) {
4533 if(cursor_x >= x && cursor_x < x + w &&
4534 cursor_y >= y && cursor_y < y + h) {
4544 // Start plugin popup
4546 if(get_buttonpress() == 3) {
4547 gui->plugin_menu->update(plugin);
4548 gui->plugin_menu->activate_menu();
4551 else if (get_double_click() && !drag_start) {
4552 // Select range of plugin on doubleclick over plugin
4553 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4554 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4555 plugin->track->from_units(plugin->length));
4556 if(mwindow->edl->session->cursor_on_frames) {
4557 mwindow->edl->local_session->set_selectionstart(
4558 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4559 mwindow->edl->local_session->set_selectionend(
4560 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4569 if(drag_start && plugin->track->record) {
4570 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4571 if(plugin->track->data_type == TRACK_AUDIO)
4572 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4573 else if(plugin->track->data_type == TRACK_VIDEO)
4574 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4576 mwindow->session->drag_plugin = plugin;
4577 mwindow->session->drag_origin_x = cursor_x;
4578 mwindow->session->drag_origin_y = cursor_y;
4579 // Where the drag started, so we know relative position inside the edit later
4580 mwindow->session->drag_position =
4581 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4582 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4584 switch(plugin->plugin_type) {
4585 case PLUGIN_STANDALONE: {
4586 PluginServer *server =
4587 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4588 if( !server ) break;
4589 VFrame *frame = server->picon;
4591 if(plugin->track->data_type == TRACK_AUDIO) {
4592 frame = mwindow->theme->get_image("aeffect_icon");
4595 frame = mwindow->theme->get_image("veffect_icon");
4599 gui->drag_popup = new BC_DragWindow(gui, frame /*,
4600 get_abs_cursor_x(0) - frame->get_w() / 2,
4601 get_abs_cursor_y(0) - frame->get_h() / 2 */);
4604 case PLUGIN_SHAREDPLUGIN:
4605 case PLUGIN_SHAREDMODULE:
4606 gui->drag_popup = new BC_DragWindow(gui,
4607 mwindow->theme->get_image("clip_icon") /*,
4608 get_abs_cursor_x(0) - mwindow->theme->get_image("clip_icon")->get_w() / 2,
4609 get_abs_cursor_y(0) - mwindow->theme->get_image("clip_icon")->get_h() / 2 */);
4621 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4622 int button_press, int &new_cursor, int &update_cursor)
4624 Transition *transition = 0;
4628 if(/* !mwindow->edl->session->show_assets || */
4629 !mwindow->edl->session->auto_conf->transitions) return 0;
4631 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4633 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4634 if( edit->transition ) {
4635 edit_dimensions(edit, x, y, w, h);
4636 get_transition_coords(x, y, w, h);
4638 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4639 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4640 if( cursor_x >= x && cursor_x < x + w &&
4641 cursor_y >= y && cursor_y < y + h ) {
4642 transition = edit->transition;
4654 new_cursor = UPRIGHT_ARROW_CURSOR;
4656 else if(get_buttonpress() == 3) {
4657 gui->transition_menu->update(transition);
4658 gui->transition_menu->activate_menu();
4665 int TrackCanvas::button_press_event()
4668 int cursor_x, cursor_y;
4671 cursor_x = get_cursor_x();
4672 cursor_y = get_cursor_y();
4673 mwindow->session->trim_edits = 0;
4675 if(is_event_win() && cursor_inside()) {
4676 // double position = (double)cursor_x *
4677 // mwindow->edl->local_session->zoom_sample /
4678 // mwindow->edl->session->sample_rate +
4679 // (double)mwindow->edl->local_session->view_start[pane->number] *
4680 // mwindow->edl->local_session->zoom_sample /
4681 // mwindow->edl->session->sample_rate;
4688 if( get_buttonpress() == LEFT_BUTTON ) {
4689 gui->unlock_window();
4690 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4691 gui->lock_window("TrackCanvas::button_press_event");
4694 int update_overlay = 0, update_cursor = 0, rerender = 0;
4696 if(get_buttonpress() == WHEEL_UP) {
4698 mwindow->expand_sample();
4699 else if(ctrl_down())
4700 mwindow->move_left(get_w()/ 10);
4702 mwindow->move_up(get_h() / 10);
4704 else if(get_buttonpress() == WHEEL_DOWN) {
4706 mwindow->zoom_in_sample();
4707 else if(ctrl_down())
4708 mwindow->move_right(get_w() / 10);
4710 mwindow->move_down(get_h() / 10);
4712 else if(get_buttonpress() == 6) {
4714 mwindow->move_left(get_w());
4716 mwindow->move_left(get_w() / 20);
4718 mwindow->move_left(get_w() / 5);
4720 else if(get_buttonpress() == 7) {
4722 mwindow->move_right(get_w());
4724 mwindow->move_right(get_w() / 20);
4726 mwindow->move_right(get_w() / 5);
4729 switch(mwindow->edl->session->editing_mode) {
4730 // Test handles and resource boundaries and highlight a track
4731 case EDITING_ARROW: {
4732 if( do_transitions(cursor_x, cursor_y,
4733 1, new_cursor, update_cursor) ) break;
4735 if( do_keyframes(cursor_x, cursor_y,
4736 0, get_buttonpress(), new_cursor,
4737 update_cursor, rerender) ) break;
4738 // Test edit boundaries
4739 if( do_edit_handles(cursor_x, cursor_y,
4740 1, rerender, update_overlay, new_cursor,
4741 update_cursor) ) break;
4742 // Test plugin boundaries
4743 if( do_plugin_handles(cursor_x, cursor_y,
4744 1, rerender, update_overlay, new_cursor,
4745 update_cursor) ) break;
4747 if( do_edits(cursor_x, cursor_y, 1, 0,
4748 update_cursor, rerender, new_cursor,
4749 update_cursor) ) break;
4751 if( do_plugins(cursor_x, cursor_y, 0, 1,
4752 update_cursor, rerender) ) break;
4754 if( test_resources(cursor_x, cursor_y) ) break;
4756 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4761 // Test handles only and select a region
4762 case EDITING_IBEAM: {
4763 double position = (double)cursor_x *
4764 mwindow->edl->local_session->zoom_sample /
4765 mwindow->edl->session->sample_rate +
4766 (double)mwindow->edl->local_session->view_start[pane->number] *
4767 mwindow->edl->local_session->zoom_sample /
4768 mwindow->edl->session->sample_rate;
4769 //printf("TrackCanvas::button_press_event %d\n", position);
4771 if( do_transitions(cursor_x, cursor_y,
4772 1, new_cursor, update_cursor)) break;
4773 if(do_keyframes(cursor_x, cursor_y,
4774 0, get_buttonpress(), new_cursor,
4775 update_cursor, rerender)) {
4779 // Test edit boundaries
4780 if( do_edit_handles(cursor_x, cursor_y,
4781 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4782 // Test plugin boundaries
4783 if( do_plugin_handles(cursor_x, cursor_y,
4784 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4786 if( do_edits(cursor_x, cursor_y,
4787 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4789 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4791 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4792 // Highlight selection
4793 if( get_buttonpress() != LEFT_BUTTON ) break;
4794 rerender = start_selection(position);
4795 mwindow->session->current_operation = SELECT_REGION;
4802 gui->unlock_window();
4803 mwindow->cwindow->update(1, 0, 0, 0, 1);
4804 gui->lock_window("TrackCanvas::button_press_event 2");
4806 mwindow->update_plugin_guis();
4807 gui->update_patchbay();
4810 if( update_overlay ) {
4811 gui->draw_overlays(1);
4813 if( update_cursor < 0 ) {
4814 // double_click edit
4815 gui->swindow->update_selection();
4817 if( update_cursor ) {
4818 gui->update_timebar(0);
4819 gui->hide_cursor(0);
4820 gui->show_cursor(1);
4821 gui->zoombar->update();
4822 gui->flash_canvas(1);
4828 int TrackCanvas::start_selection(double position)
4831 position = mwindow->edl->align_to_frame(position, 0);
4837 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4838 mwindow->edl->local_session->get_selectionend(1)) / 2;
4840 if(position < midpoint)
4842 mwindow->edl->local_session->set_selectionstart(position);
4843 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4849 mwindow->edl->local_session->set_selectionend(position);
4850 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4851 // Don't que the CWindow for the end
4855 // Start a new selection
4857 //printf("TrackCanvas::start_selection %f\n", position);
4858 mwindow->edl->local_session->set_selectionstart(position);
4859 mwindow->edl->local_session->set_selectionend(position);
4860 selection_midpoint = position;
4868 void TrackCanvas::end_edithandle_selection()
4870 mwindow->modify_edithandles();
4873 void TrackCanvas::end_pluginhandle_selection()
4875 mwindow->modify_pluginhandles();
4879 double TrackCanvas::time_visible()
4881 return (double)get_w() *
4882 mwindow->edl->local_session->zoom_sample /
4883 mwindow->edl->session->sample_rate;
4887 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
4889 char string[BCTEXTLEN];
4890 char *cp = string, *ep = cp + sizeof(string)-1;
4891 if( show_curve_type ) {
4892 cp += snprintf(string, ep-cp, "%-8s ",
4893 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
4895 char string2[BCTEXTLEN];
4896 Units::totext(string2,
4897 current->autos->track->from_units(current->position),
4898 mwindow->edl->session->time_format,
4899 mwindow->edl->session->sample_rate,
4900 mwindow->edl->session->frame_rate,
4901 mwindow->edl->session->frames_per_foot);
4902 cp += snprintf(cp, ep-cp, "%s", string2);
4905 vsnprintf(cp, ep-cp, fmt, ap);
4907 gui->show_message(string);
4910 // Patchbay* TrackCanvas::get_patchbay()
4912 // if(pane->patchbay) return pane->patchbay;
4913 // if(gui->total_panes() == 2 &&
4914 // gui->pane[TOP_LEFT_PANE] &&
4915 // gui->pane[TOP_RIGHT_PANE])
4916 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4917 // if(gui->total_panes() == 4)
4919 // if(pane->number == TOP_RIGHT_PANE)
4920 // return gui->pane[TOP_LEFT_PANE]->patchbay;
4922 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;