4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "apatchgui.inc"
25 #include "automation.h"
26 #include "bcsignals.h"
30 #include "cplayback.h"
32 #include "cwindowgui.h"
34 #include "edithandles.h"
35 #include "editpopup.h"
38 #include "edlsession.h"
39 #include "floatauto.h"
40 #include "floatautos.h"
41 #include "gwindowgui.h"
42 #include "indexstate.h"
46 #include "keyframepopup.h"
47 #include "keyframes.h"
50 #include "localsession.h"
51 #include "mainclock.h"
52 #include "maincursor.h"
53 #include "mainsession.h"
55 #include "maskautos.h"
58 #include "mwindowgui.h"
62 #include "playbackengine.h"
63 #include "playtransport.h"
65 #include "pluginpopup.h"
66 #include "pluginserver.h"
67 #include "pluginset.h"
68 #include "plugintoggles.h"
69 #include "preferences.h"
70 #include "resourcepixmap.h"
71 #include "resourcethread.h"
74 #include "trackcanvas.h"
77 #include "transition.h"
78 #include "transitionhandles.h"
79 #include "transitionpopup.h"
80 #include "transportque.h"
82 #include "vpatchgui.inc"
87 //#define PIXMAP_AGE -5
88 #define PIXMAP_AGE -32
90 TrackCanvas::TrackCanvas(MWindow *mwindow,
101 this->mwindow = mwindow;
102 this->gui = mwindow->gui;
105 selection_midpoint = 0;
109 resource_timer = new Timer;
110 render_timer = new Timer;
111 hourglass_enabled = 0;
112 timebar_position = -1;
116 TrackCanvas::~TrackCanvas()
118 // delete transition_handles;
120 delete keyframe_pixmap;
121 delete camerakeyframe_pixmap;
122 delete modekeyframe_pixmap;
123 delete pankeyframe_pixmap;
124 delete projectorkeyframe_pixmap;
125 delete maskkeyframe_pixmap;
126 delete background_pixmap;
127 if(temp_picon) delete temp_picon;
129 delete resource_timer;
132 void TrackCanvas::create_objects()
134 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
135 // transition_handles = new TransitionHandles(mwindow, this);
136 edit_handles = new EditHandles(mwindow, this);
137 keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
138 camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
139 modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
140 pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
141 projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
142 maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
148 void TrackCanvas::resize_event()
150 //printf("TrackCanvas::resize_event 1\n");
153 //printf("TrackCanvas::resize_event 2\n");
156 int TrackCanvas::keypress_event()
161 int TrackCanvas::cursor_leave_event()
163 // Because drag motion calls get_cursor_over_window we can be sure that
164 // all highlights get deleted now.
165 // This ended up blocking keyboard input from the drag operations.
166 if( timebar_position >= 0 )
168 timebar_position = -1;
170 pane->timebar->update(1);
174 // return drag_motion();
177 int TrackCanvas::drag_motion_event()
179 return gui->drag_motion();
182 int TrackCanvas::drag_motion(Track **over_track,
184 PluginSet **over_pluginset,
185 Plugin **over_plugin)
187 int cursor_x = get_relative_cursor_x();
188 int cursor_y = get_relative_cursor_y();
190 if( get_cursor_over_window() &&
191 cursor_x >= 0 && cursor_y >= 0 &&
192 cursor_x < get_w() && cursor_y < get_h() )
194 //printf("TrackCanvas::drag_motion %d %d\n", __LINE__, pane->number);
195 // Find the edit and track the cursor is over
196 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
198 int64_t track_x, track_y, track_w, track_h;
199 track_dimensions(track, track_x, track_y, track_w, track_h);
201 if(cursor_y >= track_y &&
202 cursor_y < track_y + track_h)
205 for(Edit *edit = track->edits->first; edit; edit = edit->next)
207 int64_t edit_x, edit_y, edit_w, edit_h;
208 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
209 if( cursor_y < edit_y || cursor_y >= edit_y + edit_h ) continue;
210 if( cursor_x >= edit_x && cursor_x < edit_x + edit_w ) {
214 if( edit != track->edits->last ) continue;
215 if( mwindow->session->current_operation != DRAG_ATRANSITION &&
216 mwindow->session->current_operation != DRAG_VTRANSITION ) continue;
217 if( !edit->silence() ) {
218 // add silence to allow drag transition past last edit
219 // will be deleted by Edits::optimize if not used
220 double length = mwindow->edl->session->default_transition_length;
221 int64_t start = edit->startproject+edit->length;
222 int64_t units = track->to_units(length, 1);
223 track->edits->create_silence(start, start+units);
226 if( cursor_x >= edit_x ) { *over_edit = edit; break; }
229 for(int i = 0; i < track->plugin_set.total; i++)
231 PluginSet *pluginset = track->plugin_set.values[i];
232 for(Plugin *plugin = (Plugin*)pluginset->first;
234 plugin = (Plugin*)plugin->next)
236 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
237 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
239 if(cursor_y >= plugin_y &&
240 cursor_y < plugin_y + plugin_h)
242 *over_pluginset = plugin->plugin_set;
244 if(cursor_x >= plugin_x &&
245 cursor_x < plugin_x + plugin_w)
247 *over_plugin = plugin;
259 *over_track = pane->over_patchbay();
265 int TrackCanvas::drag_stop_event()
267 int result = gui->drag_stop();
268 if( !result && mwindow->session->current_operation ) {
269 mwindow->session->current_operation = NO_OPERATION;
275 int TrackCanvas::drag_stop(int *redraw)
280 int cursor_x = -1, cursor_y = -1;
282 if( get_cursor_over_window() ) {
283 if( (cursor_x = get_relative_cursor_x()) >= 0 && cursor_x < get_w() &&
284 (cursor_y = get_relative_cursor_y()) >= 0 && cursor_y < get_h() )
287 Track *track = pane->over_patchbay();
288 if( track && mwindow->session->track_highlighted == track )
294 switch(mwindow->session->current_operation) {
295 case DRAG_VTRANSITION:
296 case DRAG_ATRANSITION:
297 if(mwindow->session->edit_highlighted) {
298 if( (mwindow->session->current_operation == DRAG_ATRANSITION &&
299 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
300 (mwindow->session->current_operation == DRAG_VTRANSITION &&
301 mwindow->session->track_highlighted->data_type == TRACK_VIDEO) ) {
302 mwindow->session->current_operation = NO_OPERATION;
303 mwindow->paste_transition();
310 // Behavior for dragged plugins is limited by the fact that a shared plugin
311 // can only refer to a standalone plugin that exists in the same position in
312 // time. Dragging a plugin from one point in time to another can't produce
313 // a shared plugin to the original plugin. In this case we relocate the
314 // plugin instead of sharing it.
315 case DRAG_AEFFECT_COPY:
316 case DRAG_VEFFECT_COPY:
317 if( mwindow->session->track_highlighted &&
318 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
319 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
320 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
321 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
322 mwindow->session->current_operation = NO_OPERATION;
324 int64_t drop_position = -1;
325 Plugin *drag_plugin = mwindow->session->drag_plugin;
326 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
327 Track *hi_track = mwindow->session->track_highlighted;
329 // Insert shared plugin in source
330 // Move source to different location
331 if( hi_plugin_set && hi_plugin_set->track == drag_plugin->track ) {
332 //printf("TrackCanvas::drag_stop 6\n");
333 drop_position = drop_plugin_position(hi_plugin_set, drag_plugin);
334 if( drop_position >= 0 )
335 mwindow->move_effect(drag_plugin, hi_plugin_set, drop_position);
338 else if( hi_track ) {
339 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
340 Edit *hi_edit = mwindow->session->edit_highlighted;
341 drop_position = hi_edit ? hi_edit->startproject : 0;
342 if( drop_position >= 0 )
343 mwindow->move_effect(drag_plugin, hi_track, drop_position);
351 if( mwindow->session->track_highlighted &&
352 ((mwindow->session->current_operation == DRAG_AEFFECT &&
353 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
354 (mwindow->session->current_operation == DRAG_VEFFECT &&
355 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) ) {
356 // Drop all the effects
357 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
358 Track *track = mwindow->session->track_highlighted;
360 double length = track->get_length();
362 if(mwindow->session->plugin_highlighted) {
363 start = track->from_units(mwindow->session->plugin_highlighted->startproject);
364 length = track->from_units(mwindow->session->plugin_highlighted->length);
365 if(length <= 0) length = track->get_length();
367 else if(mwindow->session->pluginset_highlighted) {
368 start = track->from_units(plugin_set->length());
369 length = track->get_length() - start;
370 if(length <= 0) length = track->get_length();
372 else if(mwindow->edl->local_session->get_selectionend() >
373 mwindow->edl->local_session->get_selectionstart()) {
374 start = mwindow->edl->local_session->get_selectionstart();
375 length = mwindow->edl->local_session->get_selectionend() -
376 mwindow->edl->local_session->get_selectionstart();
378 // Move to a point between two edits
379 else if(mwindow->session->edit_highlighted) {
380 start = mwindow->session->track_highlighted->from_units(
381 mwindow->session->edit_highlighted->startproject);
382 length = mwindow->session->track_highlighted->from_units(
383 mwindow->session->edit_highlighted->length);
386 mwindow->insert_effects_canvas(start, length);
389 if( mwindow->session->track_highlighted )
390 result = 1; // we have to cleanup
394 if(mwindow->session->track_highlighted) {
395 double asset_duration = 0;
396 int64_t asset_length_units = 0;
397 int64_t position = 0;
399 if(mwindow->session->current_operation == DRAG_ASSET &&
400 mwindow->session->drag_assets->total) {
401 Indexable *indexable = mwindow->session->drag_assets->values[0];
402 // we use video if we are over video and audio if we are over audio
403 if( indexable->have_video() &&
404 mwindow->session->track_highlighted->data_type == TRACK_VIDEO ) {
405 // Images have length -1
406 int64_t video_length = indexable->get_video_frames();
407 if (video_length < 0) {
408 if(mwindow->edl->session->si_useduration)
409 video_length = mwindow->edl->session->si_duration;
411 video_length = 1.0 / mwindow->edl->session->frame_rate ;
413 asset_duration = video_length / indexable->get_frame_rate();
415 else if( indexable->have_audio() &&
416 mwindow->session->track_highlighted->data_type == TRACK_AUDIO ) {
417 int64_t audio_length = indexable->get_audio_samples();
418 asset_duration = (double)audio_length / indexable->get_sample_rate();
422 break; // Do not do anything
425 else if( mwindow->session->current_operation == DRAG_ASSET &&
426 mwindow->session->drag_clips->total ) {
427 EDL *clip = mwindow->session->drag_clips->values[0];
428 asset_duration = clip->tracks->total_length();
431 printf("DRAG_ASSET error: Asset dropped, but both drag_clips and drag_assets total is zero\n");
434 asset_length_units = mwindow->session->track_highlighted->to_units(asset_duration, 1);
435 position = drop_edit_position (&insertion, NULL, asset_length_units);
436 if( position == -1 ) {
438 break; // Do not do anything
441 double position_f = mwindow->session->track_highlighted->from_units(position);
442 Track *track = mwindow->session->track_highlighted;
445 // // FIXME, we should create an mwindow/EDL method that overwrites, without clearing the keyframes and autos
446 // // Unfortunately, this is _a lot_ of work to do right
447 // printf("Problematic insertion\n");
448 // mwindow->edl->tracks->clear(position_f,
449 // position_f + asset_duration, 0);
451 mwindow->paste_assets(position_f, track, !insertion);
452 result = 1; // need to be one no matter what, since we have track highlited so we have to cleanup....
457 mwindow->session->current_operation = NO_OPERATION;
458 if(mwindow->session->track_highlighted) {
459 if( mwindow->session->track_highlighted->data_type ==
460 mwindow->session->drag_edit->track->data_type) {
461 int64_t position = 0;
462 position = drop_edit_position(&insertion,
463 mwindow->session->drag_edit,
464 mwindow->session->drag_edit->length);
465 if (position == -1) {
467 break; // Do not do anything
470 double position_f = mwindow->session->track_highlighted->from_units(position);
471 Track *track = mwindow->session->track_highlighted;
472 mwindow->move_edits(mwindow->session->drag_edits,
473 track, position_f, !insertion);
485 int TrackCanvas::drag_start_event()
490 int new_cursor, update_cursor;
492 if(mwindow->session->current_operation != NO_OPERATION) return 0;
495 if(do_plugins(get_drag_x(), get_drag_y(),
496 1, 0, redraw, rerender)) {
499 else if(do_edits(get_drag_x(), get_drag_y(),
500 0, 1, redraw, rerender, new_cursor, update_cursor)) {
508 int64_t TrackCanvas::drop_edit_position(int *is_insertion, Edit *moved_edit, int64_t moved_edit_length)
510 // get the canvas/track position
511 Track *track = mwindow->session->track_highlighted;
512 int cursor_x = get_relative_cursor_x();
513 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
514 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
515 drop_time = mwindow->edl->align_to_frame(drop_time, 0);
516 // we use cursor position for affinity calculations
517 int64_t cursor_position = track->to_units(drop_time, 0);
518 if( cursor_position <= 0 ) {
522 if( moved_edit ) // relative cursor position depends upon drop point
523 drop_time -= mwindow->session->drag_position - moved_edit->track->from_units(moved_edit->startproject);
524 int64_t drop_position = track->to_units(drop_time, 0);
525 if( !moved_edit ) // for clips and assets acts as they were grabbed in the middle
526 drop_position -= moved_edit_length / 2;
527 Edit *last_edit = track->edits->last;
528 if( !last_edit || drop_position > last_edit->startproject+last_edit->length ) {
530 return drop_position;
533 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
534 for( Edit *edit = track->edits->first; edit; ) {
535 int64_t edit_x0 = edit->startproject, edit_x1 = edit_x0 + edit->length;
536 if( Units::round(labs(edit_x0-cursor_position)*zoom_scale) < HANDLE_W ) {
537 *is_insertion = 1; // cursor is close to the beginning of an edit -> insertion
538 return edit->startproject;
540 if( Units::round(labs(edit_x1-cursor_position)*zoom_scale) < HANDLE_W ) {
541 *is_insertion = 1; // cursor is close to the end of an edit -> insertion
542 return edit->startproject + edit->length;
544 if( edit != moved_edit && !edit->silence() )
545 drop_x0 = edit_x1; // reset drop zone
546 if( (edit=edit->next) != 0 ) {
547 if( edit == moved_edit || edit->silence() ) continue;
552 //printf("drop cursor=%jd, x0=%jd, x1=%jd\n", cursor_position, drop_x0, drop_x1);
553 if( drop_position >= drop_x0 && drop_position+moved_edit_length < drop_x1 ) {
554 *is_insertion = 0; // fits in the zone
555 //printf("into %jd\n", drop_position);
556 return drop_position;
558 if( cursor_position < drop_x1 ) { // drop in the zone
559 if( (drop_x1-drop_x0) >= moved_edit_length ) {
560 *is_insertion = 0; // fits in the zone, but over the edge
561 int64_t dx0 = llabs(cursor_position-drop_x0);
562 int64_t dx1 = llabs(cursor_position-drop_x1);
563 //printf("onto %jd\n", dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length);
564 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_edit_length;
566 int edit_center = (edit_x0+edit_x1) / 2;
567 if( cursor_position < edit_center ) {
569 //printf("snap left %jd\n", drop_x0);
570 return drop_x0; // snap left
574 //printf("snap right %jd\n", drop_x1);
575 return drop_x1; // snap right
584 int64_t TrackCanvas::drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin)
586 // get the canvas/track position
587 Track *track = plugin_set->track;
588 int cursor_x = get_relative_cursor_x();
589 double zoom_scale = (double)mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample;
590 double drop_time = (cursor_x + mwindow->edl->local_session->view_start[pane->number]) / zoom_scale;
591 drop_time = mwindow->edl->align_to_frame(drop_time, 0);
592 // we use cursor position for affinity calculations
593 int64_t cursor_position = track->to_units(drop_time, 0);
594 if( cursor_position <= 0 ) return 0;
595 drop_time -= mwindow->session->drag_position - moved_plugin->track->from_units(moved_plugin->startproject);
596 int64_t drop_position = track->to_units(drop_time, 1);
597 Plugin *last_plugin = (Plugin *)plugin_set->last;
598 if( !last_plugin || drop_position > last_plugin->startproject+last_plugin->length ) {
599 return drop_position;
602 int64_t drop_x0 = 0, drop_x1 = 0; // drop zone boundries
603 for( Plugin *plugin = (Plugin *)plugin_set->first; plugin; ) {
604 int64_t plugin_x0 = plugin->startproject, plugin_x1 = plugin_x0 + plugin->length;
605 if( plugin != moved_plugin && !plugin->silence() )
607 if( (plugin=(Plugin *)plugin->next) != 0 ) {
608 if( plugin == moved_plugin || plugin->silence() ) continue;
613 if( drop_position >= drop_x0 && // fits in the zone
614 drop_position+moved_plugin->length < drop_x1 ) {
615 return drop_position;
617 if( cursor_position < drop_x1 ) { // drop in the zone
618 if( (drop_x1-drop_x0) >= moved_plugin->length ) {
619 int64_t dx0 = llabs(cursor_position-drop_x0);
620 int64_t dx1 = llabs(cursor_position-drop_x1);
621 return dx0 < dx1 ? drop_x0 : drop_x1 - moved_plugin->length;
630 void TrackCanvas::draw(int mode, int hide_cursor)
635 // Swap pixmap layers
636 if(get_w() != background_pixmap->get_w() ||
637 get_h() != background_pixmap->get_h())
639 delete background_pixmap;
640 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
643 // Cursor disappears after resize when this is called.
644 // Cursor doesn't redraw after editing when this isn't called.
645 if(pane->cursor && hide_cursor) pane->cursor->hide();
646 draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
648 if(debug) PRINT_TRACE
649 draw_resources(mode);
651 if(debug) PRINT_TRACE
653 if(debug) PRINT_TRACE
656 void TrackCanvas::update_cursor(int flush)
658 switch(mwindow->edl->session->editing_mode)
660 case EDITING_ARROW: set_cursor(ARROW_CURSOR, 0, flush); break;
661 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR, 0, flush); break;
666 void TrackCanvas::test_timer()
668 if(resource_timer->get_difference() > 1000 &&
672 hourglass_enabled = 1;
677 void TrackCanvas::draw_indexes(Indexable *indexable)
679 // Don't redraw raw samples
680 IndexState *index_state = 0;
681 index_state = indexable->index_state;
684 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
688 draw_resources(0, 1, indexable);
694 void TrackCanvas::draw_resources(int mode,
696 Indexable *indexable)
700 if(debug) PRINT_TRACE
702 if(!mwindow->edl->session->show_assets) return;
705 // can't stop thread here, because this is called for every pane
706 // if(mode != IGNORE_THREAD && !indexes_only)
707 // gui->resource_thread->stop_draw(!indexes_only);
709 if(mode != IGNORE_THREAD &&
711 !gui->resource_thread->interrupted)
713 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
716 BC_Signals::dump_stack();
719 if(debug) PRINT_TRACE
721 resource_timer->update();
723 // Age resource pixmaps for deletion
725 for(int i = 0; i < gui->resource_pixmaps.total; i++)
726 gui->resource_pixmaps.values[i]->visible--;
728 if(mode == FORCE_REDRAW)
729 gui->resource_pixmaps.remove_all_objects();
731 if(debug) PRINT_TRACE
734 for(Track *current = mwindow->edl->tracks->first;
738 if(debug) PRINT_TRACE
739 for(Edit *edit = current->edits->first; edit; edit = edit->next)
741 if(debug) PRINT_TRACE
742 if( current->data_type != TRACK_SUBTITLE )
743 if(!edit->asset && !edit->nested_edl) continue;
746 if(edit->track->data_type != TRACK_AUDIO) continue;
748 if(edit->nested_edl &&
749 strcmp(indexable->path, edit->nested_edl->path)) continue;
752 strcmp(indexable->path, edit->asset->path)) continue;
755 if(debug) PRINT_TRACE
757 int64_t edit_x, edit_y, edit_w, edit_h;
758 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
761 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
762 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
764 int64_t pixmap_x, pixmap_w, pixmap_h;
765 if(debug) PRINT_TRACE
767 // Search for existing pixmap containing edit
768 for(int i = 0; i < gui->resource_pixmaps.total; i++)
770 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
771 // Same pointer can be different edit if editing took place
772 if(pixmap->edit_id == edit->id &&
773 pixmap->pane_number == pane->number)
779 if(debug) PRINT_TRACE
781 // Get new size, offset of pixmap needed
782 get_pixmap_size(edit,
788 if(debug) PRINT_TRACE
791 if(pixmap_w && pixmap_h)
793 // Create pixmap if it doesn't exist
794 ResourcePixmap* pixmap = create_pixmap(edit,
799 // Resize it if it's bigger
800 if(pixmap_w > pixmap->pixmap_w ||
801 pixmap_h > pixmap->pixmap_h)
802 pixmap->resize(pixmap_w, pixmap_h);
803 pixmap->draw_data(this,
812 // Resize it if it's smaller
813 if(pixmap_w < pixmap->pixmap_w ||
814 pixmap_h < pixmap->pixmap_h)
815 pixmap->resize(pixmap_w, pixmap_h);
817 // Copy pixmap to background canvas
818 background_pixmap->draw_pixmap(pixmap,
820 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
824 if(debug) PRINT_TRACE
831 // Delete unused pixmaps
832 if(debug) PRINT_TRACE
834 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
835 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
837 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
838 delete gui->resource_pixmaps.values[i];
839 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
841 if(debug) PRINT_TRACE
843 if(hourglass_enabled)
846 hourglass_enabled = 0;
848 if(debug) PRINT_TRACE
850 // can't stop thread here, because this is called for every pane
851 // if(mode != IGNORE_THREAD && !indexes_only)
852 // gui->resource_thread->start_draw();
853 if(debug) PRINT_TRACE
858 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
864 ResourcePixmap *result = 0;
866 for(int i = 0; i < gui->resource_pixmaps.total; i++)
868 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
869 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
870 gui->resource_pixmaps.values[i]->pane_number == pane->number)
872 result = gui->resource_pixmaps.values[i];
880 result = new ResourcePixmap(mwindow,
887 gui->resource_pixmaps.append(result);
890 // result->resize(pixmap_w, pixmap_h);
894 void TrackCanvas::get_pixmap_size(Edit *edit,
902 // Align x on frame boundaries
905 // switch(edit->edits->track->data_type)
917 if(pixmap_x + pixmap_w > get_w())
919 pixmap_w = get_w() - pixmap_x;
926 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
927 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
928 // int64_t pixel_increment = MAX(picon_w, frame_w);
929 // int64_t pixmap_x1 = edit_x;
930 // int64_t pixmap_x2 = edit_x + edit_w;
934 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
939 // if(pixmap_x2 > get_w())
941 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
945 // pixmap_x = pixmap_x1;
946 // pixmap_w = pixmap_x2 - pixmap_x1;
951 pixmap_h = mwindow->edl->local_session->zoom_track;
952 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
953 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
956 void TrackCanvas::edit_dimensions(Edit *edit,
962 // w = Units::round(edit->track->from_units(edit->length) *
963 // mwindow->edl->session->sample_rate /
964 // mwindow->edl->local_session->zoom_sample);
968 x = Units::round(edit->track->from_units(edit->startproject) *
969 mwindow->edl->session->sample_rate /
970 mwindow->edl->local_session->zoom_sample -
971 mwindow->edl->local_session->view_start[pane->number]);
973 // Method for calculating w so when edits are together we never get off by one error due to rounding
974 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
975 mwindow->edl->session->sample_rate /
976 mwindow->edl->local_session->zoom_sample -
977 mwindow->edl->local_session->view_start[pane->number]);
980 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
982 if(mwindow->edl->session->show_titles)
983 h += mwindow->theme->get_image("title_bg_data")->get_h();
986 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
990 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
991 h = track->vertical_span(mwindow->theme);
995 void TrackCanvas::draw_paste_destination()
997 //int cursor_x = get_relative_cursor_x();
998 //int cursor_y = get_relative_cursor_y();
999 int current_atrack = 0;
1000 int current_vtrack = 0;
1001 int current_aedit = 0;
1002 int current_vedit = 0;
1008 //if(pane->number == BOTTOM_RIGHT_PANE)
1009 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1011 if((mwindow->session->current_operation == DRAG_ASSET &&
1012 (mwindow->session->drag_assets->total ||
1013 mwindow->session->drag_clips->total)) ||
1014 (mwindow->session->current_operation == DRAG_EDIT &&
1015 mwindow->session->drag_edits->total)) {
1016 Indexable *indexable = 0;
1020 if(mwindow->session->current_operation == DRAG_ASSET &&
1021 mwindow->session->drag_assets->size())
1022 indexable = mwindow->session->drag_assets->get(0);
1024 if(mwindow->session->current_operation == DRAG_ASSET &&
1025 mwindow->session->drag_clips->size())
1026 clip = mwindow->session->drag_clips->get(0);
1028 int has_audio = 0, has_video = 0;
1029 double paste_audio_length = 0, paste_video_length = 0;
1030 double paste_audio_position = -1, paste_video_position = -1;
1033 has_audio = indexable->have_audio();
1034 paste_audio_length = !has_audio ? 0 :
1035 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1036 has_video = indexable->have_video();
1037 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1038 // Images have length -1
1039 if( asset && asset->video_data && asset->video_length < 0 ) {
1040 paste_video_length = mwindow->edl->session->si_useduration ?
1041 mwindow->edl->session->si_duration / asset->frame_rate :
1042 1.0 / asset->frame_rate ; // 1 frame
1045 paste_video_length = !has_video ? 0 :
1046 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1050 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1051 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1052 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1053 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1056 // 'Align cursor on frame' lengths calculations
1057 if( mwindow->edl->session->cursor_on_frames ) {
1058 double fps = mwindow->edl->session->frame_rate;
1059 double aud = floor(paste_audio_length * fps) / fps;
1060 double vid = floor(paste_video_length * fps) / fps;
1061 double length = has_video && has_audio ?
1062 aud < vid ? aud : vid :
1064 has_audio ? aud : 0;
1065 paste_video_length = paste_audio_length = length;
1068 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1070 switch( mwindow->session->track_highlighted->data_type ) {
1071 case TRACK_VIDEO: length = paste_video_length; break;
1072 case TRACK_AUDIO: length = paste_audio_length; break;
1074 int64_t asset_length = mwindow->session->track_highlighted->
1075 to_units(length, 1);
1076 paste_audio_position = mwindow->session->track_highlighted->
1077 from_units(drop_edit_position(&insertion, NULL, asset_length));
1080 int64_t asset_length = mwindow->session->track_highlighted->
1081 to_units(paste_video_length, 1);
1082 paste_video_position = mwindow->session->track_highlighted->
1083 from_units(drop_edit_position(&insertion, NULL, asset_length));
1086 // Get destination track
1087 for(Track *dest = mwindow->session->track_highlighted;
1089 dest = dest->next) {
1091 // Get source width in pixels
1093 // Use start of highlighted edit
1094 if(mwindow->session->edit_highlighted) {
1095 position = mwindow->session->track_highlighted->from_units(
1096 mwindow->session->edit_highlighted->startproject);
1099 // Use end of highlighted track, disregarding effects
1100 position = mwindow->session->track_highlighted->from_units(
1101 mwindow->session->track_highlighted->edits->length());
1104 // Get the x coordinate
1105 x = Units::to_int64(position *
1106 mwindow->edl->session->sample_rate /
1107 mwindow->edl->local_session->zoom_sample) -
1108 mwindow->edl->local_session->view_start[pane->number];
1110 double paste_position = -1.;
1111 if(dest->data_type == TRACK_AUDIO) {
1112 if(indexable && current_atrack < indexable->get_audio_channels()) {
1113 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1114 w = Units::to_int64((double)indexable->get_audio_samples() /
1115 indexable->get_sample_rate() *
1116 mwindow->edl->session->sample_rate /
1117 mwindow->edl->local_session->zoom_sample);
1118 paste_position = paste_audio_position;
1120 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1121 w = Units::to_int64((double)clip->tracks->total_length() *
1122 mwindow->edl->session->sample_rate /
1123 mwindow->edl->local_session->zoom_sample);
1124 paste_position = paste_audio_position;
1125 //printf("draw_paste_destination %d\n", x);
1127 else if(mwindow->session->current_operation == DRAG_EDIT &&
1128 current_aedit < mwindow->session->drag_edits->total) {
1130 while(current_aedit < mwindow->session->drag_edits->total &&
1131 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1134 if(current_aedit < mwindow->session->drag_edits->total) {
1135 edit = mwindow->session->drag_edits->values[current_aedit];
1136 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1137 paste_position = mwindow->session->track_highlighted->
1138 from_units(drop_edit_position(&insertion,
1139 mwindow->session->drag_edit,
1140 mwindow->session->drag_edit->length));
1143 if( paste_position >= 0 ) {
1144 position = paste_position;
1151 else if(dest->data_type == TRACK_VIDEO) {
1152 //printf("draw_paste_destination 1\n");
1153 if(indexable && current_vtrack < indexable->get_video_layers())
1155 w = Units::to_int64((double)indexable->get_video_frames() /
1156 indexable->get_frame_rate() *
1157 mwindow->edl->session->sample_rate /
1158 mwindow->edl->local_session->zoom_sample);
1159 paste_position = paste_video_position;
1161 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1162 w = Units::to_int64(clip->tracks->total_length() *
1163 mwindow->edl->session->sample_rate /
1164 mwindow->edl->local_session->zoom_sample);
1165 paste_position = paste_video_position;
1167 else if(mwindow->session->current_operation == DRAG_EDIT &&
1168 current_vedit < mwindow->session->drag_edits->total) {
1170 while(current_vedit < mwindow->session->drag_edits->total &&
1171 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1174 if(current_vedit < mwindow->session->drag_edits->total) {
1175 edit = mwindow->session->drag_edits->values[current_vedit];
1176 w = Units::to_int64(edit->track->from_units(edit->length) *
1177 mwindow->edl->session->sample_rate /
1178 mwindow->edl->local_session->zoom_sample);
1179 paste_position = mwindow->session->track_highlighted->
1180 from_units(drop_edit_position(&insertion,
1181 mwindow->session->drag_edit,
1182 mwindow->session->drag_edit->length));
1185 if( paste_position >= 0 ) {
1186 position = paste_position;
1195 // Get the x coordinate
1196 x = Units::to_int64(position *
1197 mwindow->edl->session->sample_rate /
1198 mwindow->edl->local_session->zoom_sample) -
1199 mwindow->edl->local_session->view_start[pane->number];
1200 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1201 int h = dest->vertical_span(mwindow->theme);
1203 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1205 draw_highlight_insertion(x, y, w, h);
1207 draw_highlight_rectangle(x, y, w, h);
1208 if(x < -BC_INFINITY) {
1209 w -= -BC_INFINITY - x;
1210 x += -BC_INFINITY - x;
1213 // if(pane->number == TOP_RIGHT_PANE)
1214 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1215 // __LINE__, x, y, w, h);
1216 draw_highlight_rectangle(x, y, w, h);
1223 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1225 x = Units::round(plugin->track->from_units(plugin->startproject) *
1226 mwindow->edl->session->sample_rate /
1227 mwindow->edl->local_session->zoom_sample -
1228 mwindow->edl->local_session->view_start[pane->number]);
1229 w = Units::round(plugin->track->from_units(plugin->length) *
1230 mwindow->edl->session->sample_rate /
1231 mwindow->edl->local_session->zoom_sample);
1232 y = plugin->track->y_pixel -
1233 mwindow->edl->local_session->track_start[pane->number] +
1234 mwindow->edl->local_session->zoom_track +
1235 plugin->plugin_set->get_number() *
1236 mwindow->theme->get_image("plugin_bg_data")->get_h();
1237 if(mwindow->edl->session->show_titles)
1238 y += mwindow->theme->get_image("title_bg_data")->get_h();
1239 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1242 int TrackCanvas::resource_h()
1244 return mwindow->edl->local_session->zoom_track;
1247 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1250 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1251 // just draw arrows, so user has indication that something is there
1252 // FIXME: get better colors
1256 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1261 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1265 // Fix bug in heroines & cvs version as of 22.8.2005:
1266 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1267 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1280 w = MIN(w, get_w() + 20);
1281 h = MIN(h, get_h() + 20);
1284 set_color(mwindow->preferences->highlight_inverse);
1286 //draw_rectangle(x, y, w, h);
1287 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1288 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1290 draw_rectangle(x, y, w, h);
1292 //if(pane->number == TOP_RIGHT_PANE)
1293 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1296 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1299 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1300 // just draw arrows, so user has indication that something is there
1301 // FIXME: get better colors
1310 /* these don't look so good
1312 draw_line(x, y, x, y+h);
1313 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1314 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1315 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1316 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1318 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1319 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1321 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1322 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1323 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1324 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1326 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1327 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1329 // draw the box centred around x
1331 // Fix bug in heroines & cvs version as of 22.8.2005:
1332 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1333 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1344 w = MIN(w, get_w() + 20);
1345 h = MIN(h, get_h() + 20);
1346 set_color(mwindow->preferences->highlight_inverse);
1348 draw_rectangle(x, y, w, h);
1349 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1351 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1354 void TrackCanvas::draw_playback_cursor()
1356 // Called before playback_cursor exists
1357 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1359 // mwindow->playback_cursor->visible = 0;
1360 // mwindow->playback_cursor->draw();
1364 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1366 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1367 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1369 edit_dimensions(edit, x, y, w, h);
1371 if(mwindow->edl->session->show_titles)
1373 y += mwindow->theme->get_image("title_bg_data")->get_h();
1380 if(side == EDIT_OUT)
1389 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1391 //printf("TrackCanvas::get_transition_coords 1\n");
1392 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1393 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1394 int transition_w = 30;
1395 int transition_h = 30;
1396 //printf("TrackCanvas::get_transition_coords 1\n");
1398 if(mwindow->edl->session->show_titles)
1399 y += mwindow->theme->get_image("title_bg_data")->get_h();
1400 //printf("TrackCanvas::get_transition_coords 2\n");
1402 y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
1403 x -= transition_w / 2;
1409 void TrackCanvas::draw_highlighting()
1414 switch(mwindow->session->current_operation)
1416 case DRAG_ATRANSITION:
1417 case DRAG_VTRANSITION:
1418 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1419 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1420 if(mwindow->session->edit_highlighted) {
1421 //printf("TrackCanvas::draw_highlighting 2\n");
1422 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1423 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1424 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1425 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1426 //printf("TrackCanvas::draw_highlighting 2\n");
1427 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1428 //printf("TrackCanvas::draw_highlighting 2\n");
1430 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1431 MWindowGUI::visible(y, y + h, 0, get_h())) {
1433 get_transition_coords(x, y, w, h);
1435 //printf("TrackCanvas::draw_highlighting 3\n");
1440 // Dragging a new effect from the Resource window
1443 if(mwindow->session->track_highlighted &&
1444 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1445 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1446 (mwindow->session->current_operation == DRAG_VEFFECT &&
1447 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1448 // Put it before another plugin
1449 if(mwindow->session->plugin_highlighted) {
1450 plugin_dimensions(mwindow->session->plugin_highlighted,
1452 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1454 // Put it after a plugin set
1455 else if( mwindow->session->pluginset_highlighted &&
1456 mwindow->session->pluginset_highlighted->last ) {
1457 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1459 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1460 int64_t track_x, track_y, track_w, track_h;
1461 track_dimensions(mwindow->session->track_highlighted,
1462 track_x, track_y, track_w, track_h);
1466 mwindow->session->track_highlighted->get_length() *
1467 mwindow->edl->session->sample_rate /
1468 mwindow->edl->local_session->zoom_sample -
1469 mwindow->edl->local_session->view_start[pane->number]) -
1471 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1472 if(w <= 0) w = track_w;
1475 track_dimensions(mwindow->session->track_highlighted,
1478 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1479 // Put it in a new plugin set determined by the selected range
1480 if(mwindow->edl->local_session->get_selectionend() >
1481 mwindow->edl->local_session->get_selectionstart()) {
1482 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1483 mwindow->edl->session->sample_rate /
1484 mwindow->edl->local_session->zoom_sample -
1485 mwindow->edl->local_session->view_start[pane->number]);
1486 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1487 mwindow->edl->local_session->get_selectionstart()) *
1488 mwindow->edl->session->sample_rate /
1489 mwindow->edl->local_session->zoom_sample);
1491 // Put it in a new plugin set determined by an edit boundary
1492 else if(mwindow->session->edit_highlighted) {
1493 int64_t temp_y, temp_h;
1494 edit_dimensions(mwindow->session->edit_highlighted,
1495 x, temp_y, w, temp_h);
1497 // Put it at the beginning of the track in a new plugin set
1500 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1501 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1502 //printf("TrackCanvas::draw_highlighting 1\n");
1509 if(mwindow->session->track_highlighted) {
1510 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1512 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1514 draw_paste_destination();
1520 if(mwindow->session->track_highlighted) {
1521 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1523 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1524 draw_paste_destination();
1529 // Dragging an effect from the timeline
1530 case DRAG_AEFFECT_COPY:
1531 case DRAG_VEFFECT_COPY:
1532 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1533 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1534 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1535 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1536 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1538 int64_t plugin_position = -1;
1539 Plugin *drag_plugin = mwindow->session->drag_plugin;
1540 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1541 Track *hi_track = mwindow->session->track_highlighted;
1542 Edit *hi_edit = mwindow->session->edit_highlighted;
1543 // Put it into a silence zone
1544 if( hi_plugin_set && hi_plugin_set->last &&
1545 hi_plugin_set->track == drag_plugin->track ) {
1546 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1547 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1548 hi_track = drag_plugin->track;
1550 else if( hi_track ) {
1551 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1552 track_dimensions(hi_track, x, y, w, h);
1553 plugin_position = hi_edit ? hi_edit->startproject : 0;
1556 if( plugin_position < 0 ) break;
1558 // Calculate length of plugin based on data type of track and units
1559 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1560 mwindow->edl->local_session->zoom_sample;
1561 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1562 mwindow->edl->local_session->view_start[pane->number];
1563 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1565 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1566 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1572 case DRAG_PLUGINKEY:
1573 if(mwindow->session->plugin_highlighted &&
1574 mwindow->session->current_operation == DRAG_PLUGINKEY)
1576 // Just highlight the plugin
1577 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1579 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1580 MWindowGUI::visible(y, y + h, 0, get_h()))
1592 draw_highlight_rectangle(x, y, w, h);
1596 void TrackCanvas::draw_plugins()
1598 char string[BCTEXTLEN];
1600 int current_show = 0;
1601 int current_preset = 0;
1603 // if(!mwindow->edl->session->show_assets) goto done;
1605 for(int i = 0; i < plugin_on_toggles.total; i++)
1606 plugin_on_toggles.values[i]->in_use = 0;
1607 for(int i = 0; i < plugin_show_toggles.total; i++)
1608 plugin_show_toggles.values[i]->in_use = 0;
1609 for(int i = 0; i < preset_edit_buttons.total; i++)
1610 plugin_show_toggles.values[i]->in_use = 0;
1613 for(Track *track = mwindow->edl->tracks->first;
1615 track = track->next)
1617 if(track->expand_view)
1619 for(int i = 0; i < track->plugin_set.total; i++)
1621 PluginSet *pluginset = track->plugin_set.values[i];
1623 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1625 int64_t total_x, y, total_w, h;
1626 plugin_dimensions(plugin, total_x, y, total_w, h);
1628 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1629 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1630 plugin->plugin_type != PLUGIN_NONE)
1632 int x = total_x, w = total_w, left_margin = 5;
1633 int right_margin = 5;
1639 if(w + x > get_w()) w -= (w + x) - get_w();
1646 mwindow->theme->get_image("plugin_bg_data"),
1648 set_color(mwindow->theme->title_color);
1649 set_font(mwindow->theme->title_font);
1650 plugin->calculate_title(string, 0);
1652 // Truncate string to int64_test visible in background
1653 int len = strlen(string), j;
1654 for(j = len; j >= 0; j--)
1656 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1664 // Justify the text on the left boundary of the edit if it is visible.
1665 // Otherwise justify it on the left side of the screen.
1666 int64_t text_x = total_x + left_margin;
1667 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1668 text_x = MAX(left_margin, text_x);
1670 y + get_text_ascent(mwindow->theme->title_font) + 2,
1674 int64_t min_x = total_x + text_w;
1677 // Update plugin toggles
1678 int toggle_x = total_x + total_w;
1680 toggle_x = MIN(get_w() - right_margin, toggle_x);
1683 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1684 if(toggle_x > min_x)
1686 if(current_on >= plugin_on_toggles.total)
1688 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1689 add_subwindow(plugin_on);
1690 plugin_on_toggles.append(plugin_on);
1694 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1699 // Toggles for standalone plugins only
1700 if(plugin->plugin_type == PLUGIN_STANDALONE)
1703 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1704 if(toggle_x > min_x)
1706 if(current_show >= plugin_show_toggles.total)
1708 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1709 add_subwindow(plugin_show);
1710 plugin_show_toggles.append(plugin_show);
1714 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1718 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1719 if(toggle_x > min_x)
1721 if(current_preset >= preset_edit_buttons.total)
1723 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1724 add_subwindow(preset_edit);
1725 preset_edit_buttons.append(preset_edit);
1729 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1740 // Remove unused toggles
1742 while(current_preset < preset_edit_buttons.total)
1744 preset_edit_buttons.remove_object_number(current_preset);
1746 while(current_show < plugin_show_toggles.total)
1748 plugin_show_toggles.remove_object_number(current_show);
1751 while(current_on < plugin_on_toggles.total)
1753 plugin_on_toggles.remove_object_number(current_on);
1757 void TrackCanvas::refresh_plugintoggles()
1759 for(int i = 0; i < plugin_on_toggles.total; i++)
1761 PluginOn *on = plugin_on_toggles.values[i];
1762 on->reposition_window(on->get_x(), on->get_y());
1764 for(int i = 0; i < plugin_show_toggles.total; i++)
1766 PluginShow *show = plugin_show_toggles.values[i];
1767 show->reposition_window(show->get_x(), show->get_y());
1769 for(int i = 0; i < preset_edit_buttons.total; i++)
1771 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1772 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1776 void TrackCanvas::draw_hard_edges()
1780 // if(!mwindow->edl->session->show_assets) return;
1782 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1783 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1784 if( !edit->hard_left && !edit->hard_right ) continue;
1785 edit_dimensions(edit, x, y, w, h);
1787 set_opaque(); int y1 = y+h-1;
1788 if( edit->hard_left ) {
1789 ArrayList<int> xpt, ypt;
1790 xpt.append(x); ypt.append(y1);
1791 xpt.append(x+HANDLE_W); ypt.append(y1);
1792 xpt.append(x); ypt.append(y1-HANDLE_H);
1793 fill_polygon(&xpt, &ypt);
1795 if( edit->hard_right ) {
1796 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1797 xpt.append(x1); ypt.append(y1);
1798 xpt.append(x1-HANDLE_W); ypt.append(y1);
1799 xpt.append(x1); ypt.append(y1-HANDLE_H);
1800 fill_polygon(&xpt, &ypt);
1806 void TrackCanvas::draw_inout_points()
1811 void TrackCanvas::draw_drag_handle()
1813 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1814 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1816 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1817 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1818 mwindow->edl->session->sample_rate /
1819 mwindow->edl->local_session->zoom_sample -
1820 mwindow->edl->local_session->view_start[pane->number]);
1821 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1822 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1824 //printf("TrackCanvas::draw_drag_handle 3\n");
1825 draw_line(pixel1, 0, pixel1, get_h());
1827 //printf("TrackCanvas::draw_drag_handle 4\n");
1832 void TrackCanvas::draw_transitions()
1836 // if(!mwindow->edl->session->show_assets) return;
1838 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1839 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1840 if(!edit->transition) continue;
1841 edit_dimensions(edit, x, y, w, h);
1842 int strip_x = x, strip_y = y;
1843 if(mwindow->edl->session->show_titles)
1844 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1845 get_transition_coords(x, y, w, h);
1846 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1847 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1848 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1849 MWindowGUI::visible(y, y + h, 0, get_h()) )
1851 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1853 if( !server ) continue;
1854 VFrame *picon = server->get_picon();
1855 if( !picon ) continue;
1856 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1858 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1859 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1861 int x = strip_x, w = strip_w;
1867 if(w + x > get_w()) w -= (w + x) - get_w();
1869 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1870 mwindow->theme->get_image("plugin_bg_data"), 0);
1876 void TrackCanvas::draw_loop_points()
1878 //printf("TrackCanvas::draw_loop_points 1\n");
1879 if(mwindow->edl->local_session->loop_playback)
1881 //printf("TrackCanvas::draw_loop_points 2\n");
1882 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1883 mwindow->edl->session->sample_rate /
1884 mwindow->edl->local_session->zoom_sample -
1885 mwindow->edl->local_session->view_start[pane->number]);
1886 //printf("TrackCanvas::draw_loop_points 3\n");
1888 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1891 draw_line(x, 0, x, get_h());
1893 //printf("TrackCanvas::draw_loop_points 4\n");
1895 x = Units::round(mwindow->edl->local_session->loop_end *
1896 mwindow->edl->session->sample_rate /
1897 mwindow->edl->local_session->zoom_sample -
1898 mwindow->edl->local_session->view_start[pane->number]);
1899 //printf("TrackCanvas::draw_loop_points 5\n");
1901 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1904 draw_line(x, 0, x, get_h());
1906 //printf("TrackCanvas::draw_loop_points 6\n");
1908 //printf("TrackCanvas::draw_loop_points 7\n");
1911 void TrackCanvas::draw_brender_range()
1913 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1914 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1915 if( mwindow->edl->session->brender_end > 0 )
1917 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1918 mwindow->edl->session->sample_rate /
1919 mwindow->edl->local_session->zoom_sample -
1920 mwindow->edl->local_session->view_start[pane->number]);
1921 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1924 draw_line(x1, 0, x1, get_h());
1926 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1927 mwindow->edl->session->sample_rate /
1928 mwindow->edl->local_session->zoom_sample -
1929 mwindow->edl->local_session->view_start[pane->number]);
1931 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1934 draw_line(x2, 0, x2, get_h());
1939 // The operations which correspond to each automation type
1940 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1956 // The buttonpress operations, so nothing changes unless the mouse moves
1957 // a certain amount. This allows the keyframe to be used to position the
1958 // insertion point without moving itself.
1959 static int pre_auto_operations[AUTOMATION_TOTAL] =
1976 int TrackCanvas::do_keyframes(int cursor_x,
1984 // Note: button 3 (right mouse button) is not eaten to allow
1985 // track context menu to appear
1987 EDLSession *session = mwindow->edl->session;
1991 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1993 0, 0, 0, 0, 0, 0, 0, 0,
1995 modekeyframe_pixmap,
1996 maskkeyframe_pixmap,
2001 for(Track *track = mwindow->edl->tracks->first;
2003 track = track->next) {
2004 Auto *auto_keyframe = 0;
2005 Automation *automation = track->automation;
2008 // Handle keyframes in reverse drawing order if a button press
2010 int end = AUTOMATION_TOTAL;
2014 start = AUTOMATION_TOTAL - 1;
2018 for(int i = start; i != end && !result; i += step)
2020 // Event not trapped and automation visible
2021 Autos *autos = automation->autos[i];
2022 if(!result && session->auto_conf->autos[i] && autos) {
2024 case AUTOMATION_MODE:
2025 case AUTOMATION_PAN:
2026 case AUTOMATION_MASK:
2027 result = do_autos(track, automation->autos[i],
2028 cursor_x, cursor_y, draw,
2029 buttonpress, auto_pixmaps[i],
2030 auto_keyframe, rerender);
2034 switch(autos->get_type()) {
2035 case Autos::AUTOMATION_TYPE_FLOAT: {
2036 Automation automation(0, track);
2037 int grouptype = automation.autogrouptype(i, track);
2038 if(draw) // Do dropshadow
2039 result = do_float_autos(track, autos,
2040 cursor_x, cursor_y, draw,
2041 buttonpress, 1, 1, MDGREY,
2042 auto_keyframe, grouptype);
2044 result = do_float_autos(track, autos,
2045 cursor_x, cursor_y, draw, buttonpress,
2046 0, 0, GWindowGUI::auto_colors[i],
2047 auto_keyframe, grouptype);
2050 case Autos::AUTOMATION_TYPE_INT: {
2051 if(draw) // Do dropshadow
2052 result = do_int_autos(track, autos,
2053 cursor_x, cursor_y, draw,
2054 buttonpress, 1, 1, MDGREY,
2056 result = do_int_autos(track, autos,
2057 cursor_x, cursor_y, draw, buttonpress,
2058 0, 0, GWindowGUI::auto_colors[i],
2067 if(mwindow->session->current_operation == auto_operations[i])
2070 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2072 // mwindow->session->current_operation,
2073 // auto_operations[i]);
2076 if (buttonpress != 3)
2078 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2079 synchronize_autos(0,
2081 (FloatAuto*)mwindow->session->drag_auto,
2083 mwindow->session->current_operation = pre_auto_operations[i];
2084 update_drag_caption();
2087 else if( auto_keyframe )
2089 gui->keyframe_menu->update(automation,
2092 gui->keyframe_menu->activate_menu();
2093 rerender = 1; // the position changes
2097 gui->keyframe_hide->update(autos);
2098 gui->keyframe_hide->activate_menu();
2099 rerender = 1; // the position changes
2101 if(buttonpress == 1 && ctrl_down() &&
2102 AUTOMATION_TYPE_FLOAT == autos->get_type())
2103 rerender = 1; // special case: curve mode changed
2110 session->auto_conf->plugins /* &&
2111 mwindow->edl->session->show_assets */) {
2114 result = do_plugin_autos(track, cursor_x, cursor_y,
2115 draw, buttonpress, plugin, keyframe);
2116 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2119 if(result && (buttonpress == 1)) {
2120 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2121 update_drag_caption();
2124 else if (result && (buttonpress == 3)) {
2125 gui->keyframe_menu->update(plugin, keyframe);
2126 gui->keyframe_menu->activate_menu();
2127 rerender = 1; // the position changes
2132 // Final pass to trap event
2133 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2134 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2135 mwindow->session->current_operation == auto_operations[i]) {
2141 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2142 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2148 new_cursor = UPRIGHT_ARROW_CURSOR;
2155 void TrackCanvas::draw_keyframe_reticle()
2157 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2158 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2160 int current_op = mwindow->session->current_operation, dragging = 0;
2161 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2162 if( current_op == auto_operations[i] ) dragging = 1;
2164 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2165 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2166 draw_hairline(mwindow->session->drag_auto, RED);
2171 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2172 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2173 for( Track *track = mwindow->edl->tracks->first; track;
2174 track=track->next ) {
2175 Automation *automation = track->automation;
2176 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2177 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2178 // automation visible
2179 Autos *autos = automation->autos[i];
2180 if( !autos ) continue;
2181 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2182 auto_keyframe = auto_keyframe->next ) {
2183 draw_hairline(auto_keyframe, BLUE);
2187 if( dragging && mwindow->session->drag_auto ) {
2188 draw_hairline(mwindow->session->drag_auto, RED);
2194 void TrackCanvas::draw_auto(Auto *current,
2202 x1 = x - HANDLE_W / 2;
2203 x2 = x + HANDLE_W / 2;
2204 y1 = center_pixel + y - HANDLE_W / 2;
2205 y2 = center_pixel + y + HANDLE_W / 2;
2207 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2208 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2210 draw_box(x1, y1, x2 - x1, y2 - y1);
2214 // This draws lines for bezier in & out controls
2215 void TrackCanvas::draw_cropped_line(int x1,
2224 // Don't care about x since it is clipped by the window.
2225 // Put y coords in ascending order
2227 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2228 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2233 double slope = (double)(x2 - x1) / (y2 - y1);
2234 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2236 x1 = (int)(x1 + (min_y - y1) * slope);
2239 else if(y1 >= max_y) {
2240 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2245 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2248 else if(y2 < min_y) {
2249 x2 = (int)(x2 + (min_y - y2) * slope);
2254 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2255 if( y1 >= min_y && y1 < max_y &&
2256 y2 >= min_y && y2 < max_y )
2257 draw_line(x1, y1, x2, y2);
2261 void TrackCanvas::draw_floatauto(FloatAuto *current,
2272 int x1 = x - HANDLE_W / 2; // Center
2273 int x2 = x + HANDLE_W / 2;
2274 int y1 = center_pixel + y - HANDLE_H / 2;
2275 int y2 = center_pixel + y + HANDLE_H / 2;
2276 int ymin = center_pixel - zoom_track / 2;
2277 int ymax = center_pixel + zoom_track / 2;
2278 CLAMP(y1, ymin, ymax);
2279 CLAMP(y2, ymin, ymax);
2284 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2286 draw_box(x1, y1, x2 - x1, y2 - y1);
2289 // show bezier control points (only) if this
2290 // floatauto doesn't adjust it's tangents automatically
2291 if(current->curve_mode != FloatAuto::FREE &&
2292 current->curve_mode != FloatAuto::TFREE)
2296 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2298 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2301 inline int quantize(float f) { return (int)floor(f + 0.5); }
2303 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2304 int x, int y, int cp_x, int cp_y, int center_pixel,
2305 int zoom_track, int color)
2306 // draw the tangent and a handle for given bézier ctrl point
2308 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2310 float slope = (float)(cp_y - y)/(cp_x - x);
2311 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2313 cp_x = x + quantize((cp_y - y) / slope);
2316 cp_y += center_pixel;
2318 // drawing the tangent as a dashed line...
2319 int const dash = HANDLE_W;
2320 int const gap = HANDLE_W / 2;
2321 float sx = 3 * (cp_x - x) / 4.;
2324 // q is the x displacement for a unit line of slope
2325 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2327 float dist = 1/q * sx;
2333 float sy = slope * sx, ey = slope * ex;
2334 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2341 int r = HANDLE_W / 2;
2342 int cp_x1 = cp_x - r;
2343 int cp_y1 = cp_y - r;
2345 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2347 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2352 int TrackCanvas::test_auto(Auto *current,
2353 int x, int y, int center_pixel, int zoom_track,
2354 int cursor_x, int cursor_y, int buttonpress)
2359 x1 = x - HANDLE_W / 2;
2360 x2 = x + HANDLE_W / 2;
2361 y1 = center_pixel + y - HANDLE_H / 2;
2362 y2 = center_pixel + y + HANDLE_H / 2;
2363 int ymin = center_pixel - zoom_track / 2;
2364 int ymax = center_pixel + zoom_track / 2;
2365 CLAMP(y1, ymin, ymax);
2366 CLAMP(y2, ymin, ymax);
2368 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2370 if(buttonpress && buttonpress != 3)
2372 mwindow->session->drag_auto = current;
2373 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2374 // Toggle Autos don't respond to vertical zoom, they always show up
2375 // with "on" == 100% == line on top
2376 mwindow->session->drag_start_position = current->position;
2377 mwindow->session->drag_origin_x = cursor_x;
2378 mwindow->session->drag_origin_y = cursor_y;
2383 if(buttonpress && buttonpress != 3 && result)
2385 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2386 mwindow->undo->update_undo_before();
2392 // some Helpers for test_floatauto(..)
2393 // and for dragging the tangents/ctrl points
2394 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2395 float cursor_x, float cursor_y)
2397 // Control point switched off?
2398 if( x0 == ctrl_x ) return 0.0;
2399 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2400 double x = cursor_x-x0, y = cursor_y-y0;
2401 // wrong side of ctrl handle
2402 if( x*x1 < 0 ) return 0.0;
2403 // outside handle radius
2404 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2405 double xx1 = x1*x1, yy1 = y1*y1;
2406 double xx = x*x, yy = y*y;
2407 // distance squared from cursor to cursor projected to line from ctrl to handle
2408 // along a line perpendicular to line from ctrl to handle (closest approach)
2409 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2410 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2411 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2416 float levered_position(float position, float ref_pos)
2418 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2420 return ref_pos / position;
2424 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2425 // transforms automation value into current display coords,
2426 // dependant on current automation display range for the given kind of automation
2428 if(!mwindow || !mwindow->edl) return 0;
2429 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2430 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2431 float automation_range = automation_max - automation_min;
2432 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2434 return (auto_value - automation_min) / automation_range;
2439 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2440 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2441 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2445 int x1 = x - HANDLE_W / 2;
2446 int x2 = x + HANDLE_W / 2;
2447 int y1 = center_pixel + y - HANDLE_W / 2;
2448 int y2 = center_pixel + y + HANDLE_W / 2;
2449 int ymin = center_pixel - zoom_track / 2;
2450 int ymax = center_pixel + zoom_track / 2;
2451 CLAMP(y1, ymin, ymax);
2452 CLAMP(y2, ymin, ymax);
2454 int in_x1 = in_x - HANDLE_W / 2;
2455 int in_x2 = in_x + HANDLE_W / 2;
2456 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2457 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2458 CLAMP(in_y1, ymin, ymax);
2459 CLAMP(in_y2, ymin, ymax);
2461 int out_x1 = out_x - HANDLE_W / 2;
2462 int out_x2 = out_x + HANDLE_W / 2;
2463 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2464 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2465 CLAMP(out_y1, ymin, ymax);
2466 CLAMP(out_y2, ymin, ymax);
2469 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2470 // buttonpress could be the start of a drag operation
2471 #define INIT_DRAG(POS,VAL) \
2472 mwindow->session->drag_auto = current; \
2473 mwindow->session->drag_origin_x = cursor_x; \
2474 mwindow->session->drag_origin_y = cursor_y; \
2475 mwindow->session->drag_start_position = (POS); \
2476 mwindow->session->drag_start_percentage = (VAL);
2478 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2481 // without modifier we are manipulating the automation node
2482 // with ALT it's about dragging only the value of the node
2483 // with SHIFT the value snaps to the value of neighbouring nodes
2484 // CTRL indicates we are rather manipulating the tangent(s) of the node
2488 if( WITHIN(x1,x2,y1,y2))
2489 { // cursor hits node
2492 if(buttonpress && (buttonpress != 3))
2494 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2495 mwindow->session->drag_handle = 0;
2500 if( WITHIN(x1,x2,y1,y2))
2503 if(buttonpress && (buttonpress != 3))
2505 // could be ctrl-click or ctrl-drag
2506 // click would cycle through tangent modes
2507 ((FloatAuto*)current)->toggle_curve_mode();
2509 // drag will start dragging the tangent, if applicable
2510 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2511 mwindow->session->drag_handle = 0;
2515 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2518 if( in_x != x && current->position > 0 &&
2519 (FloatAuto::FREE == current->curve_mode ||
2520 FloatAuto::TFREE == current->curve_mode))
2521 // act on in control handle only if
2522 // tangent is significant and is editable (not automatically choosen)
2524 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2525 // either cursor in ctrl-point handle or cursor on tangent line
2526 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2528 if(buttonpress && (buttonpress != 3)) {
2529 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2531 mwindow->session->drag_handle = 1;
2532 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2533 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2534 value_to_percentage(new_invalue, autogrouptype))
2541 (FloatAuto::FREE == current->curve_mode ||
2542 FloatAuto::TFREE == current->curve_mode))
2543 // act on out control only if tangent is significant and is editable
2545 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2546 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2548 if(buttonpress && (buttonpress != 3)) {
2549 if(lever == 0.0) lever=1.0;
2551 mwindow->session->drag_handle = 2;
2552 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2553 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2554 value_to_percentage(new_outvalue, autogrouptype))
2558 } // end ctrl_down()
2564 // 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",
2565 // mwindow->session->drag_handle,
2570 if(buttonpress && (buttonpress != 3) && result)
2572 mwindow->undo->update_undo_before();
2579 // Get the float value & y for position x on the canvas
2580 #define X_TO_FLOATLINE(x) \
2581 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2582 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2583 /* Call by reference fails for some reason here */ \
2584 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2585 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2586 double position = unit_start + x * zoom_units; \
2588 if(position2 > position1) \
2591 (value2 - value1) * \
2592 (position - position1) / \
2593 (position2 - position1); \
2599 AUTOMATIONCLAMPS(value, autogrouptype); \
2600 int y = center_pixel + \
2601 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2604 void TrackCanvas::draw_floatline(int center_pixel,
2605 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2606 double unit_start, double zoom_units, double yscale,
2607 int x1, int y1, int x2, int y2,
2608 int color, int autogrouptype)
2610 // Solve bezier equation for either every pixel or a certain large number of
2613 // Not using slope intercept
2615 int prev_y = y1 + center_pixel;
2618 // Call by reference fails for some reason here
2619 FloatAuto *previous1 = previous, *next1 = next;
2620 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2621 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2622 float automation_range = automation_max - automation_min;
2624 for(int x = x1; x < x2; x++)
2626 // Interpolate value between frames
2630 y >= center_pixel - yscale / 2 &&
2631 y < center_pixel + yscale / 2 - 1)
2633 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2635 // (int)(center_pixel - yscale / 2),
2636 // (int)(center_pixel + yscale / 2 - 1));
2638 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2639 draw_line(x - 1, prev_y , x, y );
2649 int TrackCanvas::test_floatline(int center_pixel,
2664 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2665 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2666 float automation_range = automation_max - automation_min;
2667 FloatAuto *previous1 = 0, *next1 = 0;
2668 X_TO_FLOATLINE(cursor_x);
2670 if(cursor_x >= x1 &&
2672 cursor_y >= y - HANDLE_W / 2 &&
2673 cursor_y < y + HANDLE_W / 2 &&
2679 if(buttonpress == 3)
2687 mwindow->undo->update_undo_before();
2688 double position = autos->track->from_units(position1);
2689 position = mwindow->edl->align_to_frame(position, 0);
2690 int64_t new_position = autos->track->to_units(position,0);
2691 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2692 ((FloatAuto*)current)->set_value(value);
2693 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2694 mwindow->session->drag_start_position = current->position;
2695 mwindow->session->drag_origin_x = cursor_x;
2696 mwindow->session->drag_origin_y = cursor_y;
2697 mwindow->session->drag_handle = 0;
2706 void TrackCanvas::synchronize_autos(float change,
2707 Track *skip, FloatAuto *fauto, int fill_gangs)
2709 // Handles the special case of modifying a fadeauto
2710 // when there are ganged faders on several tracks
2711 // (skip and fauto may be NULL if fill_gangs==-1)
2713 if( fill_gangs > 0 && skip->gang ) {
2714 double position = skip->from_units(fauto->position);
2715 int autoidx = fauto->autos->autoidx;
2717 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2718 if( (current->data_type == skip->data_type || get_double_click()) &&
2719 current->gang && current->record && current != skip ) {
2720 int64_t current_position = current->to_units(position, 1);
2721 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2722 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2723 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2724 FloatAuto *previous = 0, *next = 0;
2725 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2727 // create keyframe on neighbouring track at the point in time given by fauto
2728 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2729 float new_value = init_value + change;
2730 CLAMP(new_value, auto_min, auto_max);
2731 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2732 keyframe->set_value(new_value);
2735 // keyframe exists, just change it
2736 float new_value = keyframe->get_value() + change;
2737 CLAMP(new_value, auto_min, auto_max);
2738 keyframe->adjust_to_new_coordinates(current_position, new_value);
2739 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2742 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2746 else if( !fill_gangs ) {
2747 double position = skip->from_units(fauto->position);
2749 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2750 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2751 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2752 float new_value = keyframe->get_value() + change;
2754 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2755 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2756 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2762 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2763 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2764 keyframe->autos->remove_nonsequential(
2767 mwindow->session->drag_auto_gang->remove_all();
2772 void TrackCanvas::draw_toggleline(int center_pixel,
2778 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2782 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2786 int TrackCanvas::test_toggleline(Autos *autos,
2797 if(cursor_x >= x1 && cursor_x < x2)
2799 int miny = center_pixel + y1 - HANDLE_W / 2;
2800 int maxy = center_pixel + y1 + HANDLE_W / 2;
2801 if(cursor_y >= miny && cursor_y < maxy)
2806 if(buttonpress == 3)
2814 double position = (double)(cursor_x +
2815 mwindow->edl->local_session->view_start[pane->number]) *
2816 mwindow->edl->local_session->zoom_sample /
2817 mwindow->edl->session->sample_rate;
2818 int64_t unit_position = autos->track->to_units(position, 0);
2819 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2821 mwindow->undo->update_undo_before();
2823 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2824 ((IntAuto*)current)->value = new_value;
2825 // Toggle Autos don't respond to vertical zoom, they always show up
2826 // with "on" == 100% == line on top
2827 mwindow->session->drag_start_percentage = (float)new_value;
2828 mwindow->session->drag_start_position = current->position;
2829 mwindow->session->drag_origin_x = cursor_x;
2830 mwindow->session->drag_origin_y = cursor_y;
2838 void TrackCanvas::calculate_viewport(Track *track,
2839 double &view_start, // Seconds
2841 double &view_end, // Seconds
2845 double &zoom_sample,
2848 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2849 mwindow->edl->local_session->zoom_sample /
2850 mwindow->edl->session->sample_rate;
2851 unit_start = track->to_doubleunits(view_start);
2852 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2854 mwindow->edl->local_session->zoom_sample /
2855 mwindow->edl->session->sample_rate;
2856 unit_end = track->to_doubleunits(view_end);
2857 yscale = mwindow->edl->local_session->zoom_track;
2858 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2859 center_pixel = (int)(track->y_pixel -
2860 mwindow->edl->local_session->track_start[pane->number] +
2862 (mwindow->edl->session->show_titles ?
2863 mwindow->theme->get_image("title_bg_data")->get_h() :
2865 zoom_sample = mwindow->edl->local_session->zoom_sample;
2867 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2870 float TrackCanvas::percentage_to_value(float percentage,
2878 if(percentage > 0.5)
2885 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2886 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2887 float automation_range = automation_max - automation_min;
2889 result = percentage * automation_range + automation_min;
2892 FloatAuto *ptr = (FloatAuto*)reference;
2893 result -= ptr->get_value();
2895 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2901 void TrackCanvas::calculate_auto_position(double *x, double *y,
2902 double *in_x, double *in_y, double *out_x, double *out_y,
2903 Auto *current, double unit_start, double zoom_units, double yscale,
2906 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2907 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2908 float automation_range = automation_max - automation_min;
2909 FloatAuto *ptr = (FloatAuto*)current;
2910 *x = (double)(ptr->position - unit_start) / zoom_units;
2911 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2914 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2915 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2919 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2920 automation_min) / automation_range - 0.5) * -yscale;
2924 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2925 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2929 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2930 automation_min) / automation_range - 0.5) * -yscale;
2935 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2936 int draw, int buttonpress, int x_offset, int y_offset, int color,
2937 Auto* &auto_instance, int autogrouptype)
2940 int center_pixel, draw_auto;
2941 double view_start, unit_start;
2942 double view_end, unit_end, yscale;
2943 double zoom_sample, zoom_units;
2944 double in_x2, in_y2, out_x2, out_y2;
2950 if(draw) set_color(color);
2952 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2953 yscale, center_pixel, zoom_sample, zoom_units);
2955 // Get first auto before start
2956 Auto *current = 0, *previous = 0;
2958 for( current = autos->last;
2959 current && current->position >= unit_start;
2960 current = PREVIOUS ) ;
2962 Auto *first_auto = current ? current :
2963 autos->first ? autos->first : autos->default_auto;
2965 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2967 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2968 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2973 current = autos->first;
2982 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2983 current, unit_start, zoom_units, yscale, autogrouptype);
2991 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2996 ay2 = ay + slope * (get_w() - ax);
3000 ay = ay + slope * (0 - ax);
3004 // Draw or test handle
3005 if( current && !result && current != autos->default_auto ) {
3006 if( !draw && track->record ) {
3007 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3008 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3009 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3010 buttonpress, autogrouptype);
3012 auto_instance = current;
3014 if( draw && draw_auto ) {
3015 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3016 (int)in_x2 + x_offset, (int)in_y2,
3017 (int)out_x2 + x_offset, (int)out_y2,
3018 (int)center_pixel + y_offset, (int)yscale, color);
3022 // Draw or test joining line
3023 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3024 result = test_floatline(center_pixel,
3025 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3026 // Exclude auto coverage from the end of the line. The auto overlaps
3027 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3028 buttonpress, autogrouptype);
3031 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3032 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3033 (int)ax, (int)ay, (int)ax2, (int)ay2,
3034 color, autogrouptype);
3042 } while( current && current->position <= unit_end && !result );
3044 if( ax < get_w() && !result ) {
3045 ax2 = get_w(); ay2 = ay;
3046 if(!draw && track->record /* && buttonpress != 3 */ ) {
3047 result = test_floatline(center_pixel,
3048 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3049 (int)ax, (int)ax2, cursor_x, cursor_y,
3050 buttonpress, autogrouptype);
3053 draw_floatline(center_pixel,
3054 (FloatAuto*)previous, (FloatAuto*)current,
3055 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3056 (int)ax, (int)ay, (int)ax2, (int)ay2,
3057 color, autogrouptype);
3064 int TrackCanvas::do_int_autos(Track *track,
3073 Auto *&auto_instance)
3084 double ax, ay, ax2, ay2;
3088 if(draw) set_color(color);
3090 calculate_viewport(track,
3101 double high = -yscale * 0.8 / 2;
3102 double low = yscale * 0.8 / 2;
3104 // Get first auto before start
3106 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3112 ay = ((IntAuto*)current)->value > 0 ? high : low;
3117 current = autos->first ? autos->first : autos->default_auto;
3121 ay = ((IntAuto*)current)->value > 0 ? high : low;
3134 ax2 = (double)(current->position - unit_start) / zoom_units;
3135 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3143 if(ax2 > get_w()) ax2 = get_w();
3145 if(current && !result)
3147 if(current != autos->default_auto)
3153 result = test_auto(current,
3162 auto_instance = current;
3167 (int)ax2 + x_offset,
3168 (int)ay2 + y_offset,
3180 if(track->record /* && buttonpress != 3 */)
3182 result = test_toggleline(autos,
3195 draw_toggleline(center_pixel + y_offset,
3203 }while(current && current->position <= unit_end && !result);
3205 if(ax < get_w() && !result)
3211 if(track->record /* && buttonpress != 3 */)
3213 result = test_toggleline(autos,
3225 draw_toggleline(center_pixel + y_offset,
3234 int TrackCanvas::do_autos(Track *track,
3241 Auto * &auto_instance,
3255 calculate_viewport(track,
3268 for(current = autos->first; current && !result; current = NEXT)
3270 if(current->position >= unit_start && current->position < unit_end)
3273 x = (int64_t)((double)(current->position - unit_start) /
3274 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3275 y = center_pixel - pixmap->get_h() / 2;
3279 if(cursor_x >= x && cursor_y >= y &&
3280 cursor_x < x + pixmap->get_w() &&
3281 cursor_y < y + pixmap->get_h())
3284 auto_instance = current;
3286 if(buttonpress && (buttonpress != 3))
3288 mwindow->session->drag_auto = current;
3289 mwindow->session->drag_start_position = current->position;
3290 mwindow->session->drag_origin_x = cursor_x;
3291 mwindow->session->drag_origin_y = cursor_y;
3293 double position = autos->track->from_units(current->position);
3294 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3295 mwindow->edl->local_session->get_selectionend(1)) /
3300 mwindow->edl->local_session->set_selectionstart(position);
3301 mwindow->edl->local_session->set_selectionend(position);
3304 if(position < center)
3306 mwindow->edl->local_session->set_selectionstart(position);
3309 mwindow->edl->local_session->set_selectionend(position);
3316 draw_pixmap(pixmap, x, y);
3324 // so this means it is always >0 when keyframe is found
3325 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3326 int draw, int buttonpress, Plugin* &keyframe_plugin,
3327 KeyFrame* &keyframe_instance)
3340 if(!track->expand_view) return 0;
3342 calculate_viewport(track,
3354 for(int i = 0; i < track->plugin_set.total && !result; i++)
3356 PluginSet *plugin_set = track->plugin_set.values[i];
3357 int center_pixel = (int)(track->y_pixel -
3358 mwindow->edl->local_session->track_start[pane->number] +
3359 mwindow->edl->local_session->zoom_track +
3360 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3361 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3363 for(Plugin *plugin = (Plugin*)plugin_set->first;
3365 plugin = (Plugin*)plugin->next)
3367 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3368 keyframe && !result;
3369 keyframe = (KeyFrame*)keyframe->next)
3371 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3372 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3374 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3375 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3377 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3380 if(cursor_x >= x && cursor_y >= y &&
3381 cursor_x < x + keyframe_pixmap->get_w() &&
3382 cursor_y < y + keyframe_pixmap->get_h())
3385 keyframe_plugin = plugin;
3386 keyframe_instance = keyframe;
3390 mwindow->session->drag_auto = keyframe;
3391 mwindow->session->drag_start_position = keyframe->position;
3392 mwindow->session->drag_origin_x = cursor_x;
3393 mwindow->session->drag_origin_y = cursor_y;
3395 double position = track->from_units(keyframe->position);
3396 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3397 mwindow->edl->local_session->get_selectionend(1)) /
3402 mwindow->edl->local_session->set_selectionstart(position);
3403 mwindow->edl->local_session->set_selectionend(position);
3406 if(position < center)
3408 mwindow->edl->local_session->set_selectionstart(position);
3411 mwindow->edl->local_session->set_selectionend(position);
3416 draw_pixmap(keyframe_pixmap,
3426 // if(buttonpress && buttonpress != 3 && result)
3428 // mwindow->undo->update_undo_before();
3434 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3436 Track *track = auto_keyframe->autos->track;
3437 int autogrouptype = auto_keyframe->autos->get_type();
3440 double view_start, unit_start;
3441 double view_end, unit_end, yscale;
3442 double zoom_sample, zoom_units;
3444 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3445 yscale, center_pixel, zoom_sample, zoom_units);
3447 double ax = 0, ay = 0;
3448 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3449 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3452 draw_line(ax, 0, ax, get_h());
3456 void TrackCanvas::draw_overlays()
3458 int new_cursor, update_cursor, rerender;
3460 // Move background pixmap to foreground pixmap
3461 draw_pixmap(background_pixmap,
3470 draw_inout_points();
3473 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3481 draw_brender_range();
3483 // Highlighted areas
3484 draw_highlighting();
3487 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3490 if(pane->cursor) pane->cursor->restore(1);
3496 draw_playback_cursor();
3498 draw_keyframe_reticle();
3503 int TrackCanvas::activate()
3507 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3508 //BC_Signals::dump_stack();
3509 get_top_level()->deactivate();
3511 set_active_subwindow(this);
3512 pane->cursor->activate();
3513 gui->focused_pane = pane->number;
3518 int TrackCanvas::deactivate()
3523 pane->cursor->deactivate();
3529 void TrackCanvas::update_drag_handle()
3531 double new_position;
3532 int cursor_x = get_cursor_x();
3536 mwindow->edl->local_session->view_start[pane->number]) *
3537 mwindow->edl->local_session->zoom_sample /
3538 mwindow->edl->session->sample_rate;
3541 mwindow->edl->align_to_frame(new_position, 0);
3543 if( ctrl_down() && alt_down() ) {
3544 #define snapper(v) do { \
3546 if( pos < 0 ) break; \
3547 double dist = fabs(new_position - pos); \
3548 if( dist >= snap_min ) break; \
3549 snap_position = pos; snap_min = dist; \
3551 double snap_position = new_position;
3552 double snap_min = DBL_MAX;
3553 if( mwindow->edl->local_session->inpoint_valid() )
3554 snapper(mwindow->edl->local_session->get_inpoint());
3555 if( mwindow->edl->local_session->outpoint_valid() )
3556 snapper(mwindow->edl->local_session->get_outpoint());
3557 snapper(mwindow->edl->prev_edit(new_position));
3558 snapper(mwindow->edl->next_edit(new_position));
3559 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3560 if( prev_label ) snapper(prev_label->position);
3561 Label *next_label = mwindow->edl->labels->next_label(new_position);
3562 if( next_label ) snapper(next_label->position);
3563 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3564 mwindow->edl->local_session->zoom_sample -
3565 mwindow->edl->local_session->view_start[pane->number];
3566 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3568 new_position = snap_position;
3573 if(new_position != mwindow->session->drag_position)
3575 mwindow->session->drag_position = new_position;
3576 gui->mainclock->update(new_position);
3579 timebar_position = new_position;
3580 gui->update_timebar(0);
3581 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3583 // mwindow->cwindow->update(1, 0, 0);
3587 int TrackCanvas::update_drag_edit()
3596 int TrackCanvas::get_drag_values(float *percentage,
3603 //int x = cursor_x - mwindow->session->drag_origin_x;
3604 //int y = cursor_y - mwindow->session->drag_origin_y;
3608 if(!current->autos->track->record) return 1;
3618 calculate_viewport(current->autos->track,
3628 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3630 mwindow->session->drag_start_percentage;
3631 if(do_clamp) CLAMP(*percentage, 0, 1);
3633 *position = Units::to_int64(zoom_units *
3634 (cursor_x - mwindow->session->drag_origin_x) +
3635 mwindow->session->drag_start_position + 0.5);
3637 if((do_clamp) && *position < 0) *position = 0;
3642 #define UPDATE_DRAG_HEAD(do_clamp) \
3643 int result = 0, center_pixel; \
3644 if(!current->autos->track->record) return 0; \
3645 double view_start, unit_start, view_end, unit_end; \
3646 double yscale, zoom_sample, zoom_units; \
3648 calculate_viewport(current->autos->track, \
3649 view_start, unit_start, view_end, unit_end, \
3650 yscale, center_pixel, zoom_sample, zoom_units); \
3652 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3653 yscale + mwindow->session->drag_start_percentage; \
3654 if(do_clamp) CLAMP(percentage, 0, 1); \
3656 int64_t position = Units::to_int64(zoom_units * \
3657 (cursor_x - mwindow->session->drag_origin_x) + \
3658 mwindow->session->drag_start_position); \
3659 if((do_clamp) && position < 0) position = 0;
3662 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3664 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3666 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3667 int x = cursor_x - mwindow->session->drag_origin_x;
3668 int y = cursor_y - mwindow->session->drag_origin_y;
3669 float value, old_value;
3671 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3672 // not really editing the node, rather start editing the curve
3673 // tangent is editable and drag movement is significant
3674 if( (FloatAuto::FREE == current->curve_mode ||
3675 FloatAuto::TFREE==current->curve_mode) &&
3676 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3677 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3680 switch(mwindow->session->drag_handle) {
3682 // Snap to nearby values
3683 old_value = current->get_value();
3685 double value1, value2, distance1, distance2;
3687 if(current->previous) {
3688 int autogrouptype = current->previous->autos->autogrouptype;
3689 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3690 value1 = ((FloatAuto*)current->previous)->get_value();
3691 distance1 = fabs(value - value1);
3692 current->set_value(value1);
3696 int autogrouptype = current->next->autos->autogrouptype;
3697 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3698 value2 = ((FloatAuto*)current->next)->get_value();
3699 distance2 = fabs(value - value2);
3700 if(!current->previous || distance2 < distance1) {
3701 current->set_value(value2);
3705 if(!current->previous && !current->next) {
3706 current->set_value( ((FloatAutos*)current->autos)->default_);
3708 value = current->get_value();
3711 int autogrouptype = current->autos->autogrouptype;
3712 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3715 if(alt_down() && !shift_down())
3716 // ALT constrains movement: fixed position, only changing the value
3717 position = mwindow->session->drag_start_position;
3719 if(value != old_value || position != current->position) {
3721 float change = value - old_value;
3722 current->adjust_to_new_coordinates(position, value);
3723 synchronize_autos(change, current->autos->track, current, 0);
3724 show_message(current, 1,", %.2f", current->get_value());
3730 int autogrouptype = current->autos->autogrouptype;
3731 value = percentage_to_value(percentage, 0, current, autogrouptype);
3732 if(value != current->get_control_in_value())
3735 // note: (position,value) need not be at the location of the ctrl point,
3736 // but could be somewhere in between on the curve (or even outward or
3737 // on the opposit side). We set the new control point such as
3738 // to point the curve through (position,value)
3739 current->set_control_in_value(
3740 value * levered_position(position - current->position,
3741 current->get_control_in_position()));
3742 synchronize_autos(0, current->autos->track, current, 0);
3743 show_message(current, 1,", %.2f", current->get_control_in_value());
3749 int autogrouptype = current->autos->autogrouptype;
3750 value = percentage_to_value(percentage, 0, current, autogrouptype);
3751 if(value != current->get_control_out_value()) {
3753 current->set_control_out_value(
3754 value * levered_position(position - current->position,
3755 current->get_control_out_position()));
3756 synchronize_autos(0, current->autos->track, current, 0);
3757 show_message(current, 1,", %.2f", current->get_control_out_value());
3765 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3767 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3769 UPDATE_DRAG_HEAD(1);
3770 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3772 if(value != current->value || position != current->position)
3775 current->value = value;
3776 current->position = position;
3777 show_message(current, 0,", %d", current->value);
3783 // Autos which can't change value through dragging.
3785 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3787 Auto *current = (Auto*)mwindow->session->drag_auto;
3790 if(position != current->position)
3793 current->position = position;
3794 show_message(current, 0,"");
3796 double position_f = current->autos->track->from_units(current->position);
3797 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3798 mwindow->edl->local_session->get_selectionend(1)) /
3802 mwindow->edl->local_session->set_selectionstart(position_f);
3803 mwindow->edl->local_session->set_selectionend(position_f);
3806 if(position_f < center_f)
3808 mwindow->edl->local_session->set_selectionstart(position_f);
3811 mwindow->edl->local_session->set_selectionend(position_f);
3818 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3820 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3823 if(position != current->position)
3825 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3826 Track *track = current->autos->track;
3827 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3828 PluginSet *pluginset;
3830 // figure out the correct pluginset & correct plugin
3832 for(int i = 0; i < track->plugin_set.total; i++)
3834 pluginset = track->plugin_set.values[i];
3835 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3837 KeyFrames *keyframes = plugin->keyframes;
3838 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3840 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3842 if (currentkeyframe == current)
3854 mwindow->session->plugin_highlighted = plugin;
3855 mwindow->session->track_highlighted = track;
3857 current->position = position;
3858 show_message(current, 0,"");
3860 double position_f = current->autos->track->from_units(current->position);
3861 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3862 mwindow->edl->local_session->get_selectionend(1)) /
3866 mwindow->edl->local_session->set_selectionstart(position_f);
3867 mwindow->edl->local_session->set_selectionend(position_f);
3870 if(position_f < center_f)
3872 mwindow->edl->local_session->set_selectionstart(position_f);
3875 mwindow->edl->local_session->set_selectionend(position_f);
3882 void TrackCanvas::update_drag_caption()
3884 switch(mwindow->session->current_operation)
3894 int TrackCanvas::cursor_motion_event()
3899 int update_clock = 0;
3900 int update_zoom = 0;
3901 int update_scroll = 0;
3902 int update_overlay = 0;
3903 int update_cursor = 0;
3906 double position = 0.;
3907 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3910 switch(mwindow->edl->session->editing_mode)
3912 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3913 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3916 switch(mwindow->session->current_operation)
3918 case DRAG_EDITHANDLE1:
3919 // Outside threshold. Upgrade status
3922 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3924 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3930 case DRAG_EDITHANDLE2:
3933 update_drag_handle();
3938 case DRAG_PLUGINHANDLE1:
3941 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3943 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3949 case DRAG_PLUGINHANDLE2:
3952 update_drag_handle();
3957 // Rubber band curves
3965 case DRAG_PROJECTOR_X:
3966 case DRAG_PROJECTOR_Y:
3967 case DRAG_PROJECTOR_Z:
3968 if(active) rerender = update_overlay =
3969 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3973 if(active) rerender = update_overlay =
3974 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3978 if(active) rerender = update_overlay =
3979 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3982 // Keyframe icons are sticky
3986 case DRAG_PLUGINKEY_PRE:
3988 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3989 mwindow->session->current_operation++;
3992 mwindow->undo->update_undo_before();
4000 if(active) rerender = update_overlay =
4001 update_drag_auto(get_cursor_x(), get_cursor_y());
4004 case DRAG_PLUGINKEY:
4005 if(active) rerender = update_overlay =
4006 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4011 cursor_x = get_cursor_x();
4012 cursor_y = get_cursor_y();
4013 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4014 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4016 position = mwindow->edl->align_to_frame(position, 0);
4017 position = MAX(position, 0);
4019 if(position < selection_midpoint) {
4020 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4021 mwindow->edl->local_session->set_selectionstart(position);
4023 gui->unlock_window();
4024 mwindow->cwindow->update(1, 0, 0, 0, 1);
4025 gui->lock_window("TrackCanvas::cursor_motion_event 1");
4026 // Update the faders
4027 mwindow->update_plugin_guis();
4028 gui->update_patchbay();
4031 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4032 mwindow->edl->local_session->set_selectionend(position);
4033 // Don't que the CWindow
4036 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4038 gui->hide_cursor(0);
4039 gui->draw_cursor(1);
4040 gui->update_timebar(0);
4041 gui->flash_canvas(1);
4050 if(is_event_win() && cursor_inside()) {
4052 cursor_x = get_cursor_x();
4053 position = (double)cursor_x *
4054 (double)mwindow->edl->local_session->zoom_sample /
4055 (double)mwindow->edl->session->sample_rate +
4056 (double)mwindow->edl->local_session->view_start[pane->number] *
4057 (double)mwindow->edl->local_session->zoom_sample /
4058 (double)mwindow->edl->session->sample_rate;
4059 position = mwindow->edl->align_to_frame(position, 0);
4063 for(int i = 0; i < TOTAL_PANES; i++)
4064 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4066 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4067 gui->update_timebar(0);
4069 if(do_transitions(get_cursor_x(), get_cursor_y(),
4070 0, new_cursor, update_cursor)) break;
4071 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4072 0, 0, new_cursor, update_cursor, rerender)) break;
4073 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4074 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4075 // Plugin boundaries
4076 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4077 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4078 if(do_edits(get_cursor_x(), get_cursor_y(),
4079 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4084 //printf("TrackCanvas::cursor_motion_event 1\n");
4085 if(update_cursor && new_cursor != get_cursor())
4087 set_cursor(new_cursor, 0, 1);
4090 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
4091 if(rerender && render_timer->get_difference() > 0.25 ) {
4092 render_timer->update();
4093 mwindow->restart_brender();
4094 mwindow->sync_parameters(CHANGE_PARAMS);
4095 mwindow->update_plugin_guis();
4096 gui->unlock_window();
4097 mwindow->cwindow->update(1, 0, 0, 0, 1);
4098 gui->lock_window("TrackCanvas::cursor_motion_event 2");
4102 gui->update_patchbay();
4107 if(!mwindow->cwindow->playback_engine->is_playing_back)
4108 gui->mainclock->update(position);
4112 gui->zoombar->update();
4117 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4121 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4125 if(update_overlay) {
4126 gui->draw_overlays(1);
4129 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
4133 void TrackCanvas::start_dragscroll()
4137 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4138 //printf("TrackCanvas::start_dragscroll 1\n");
4142 void TrackCanvas::stop_dragscroll()
4146 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4147 //printf("TrackCanvas::stop_dragscroll 1\n");
4151 int TrackCanvas::repeat_event(int64_t duration)
4153 if(!drag_scroll) return 0;
4154 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4156 int sample_movement = 0;
4157 int track_movement = 0;
4158 int64_t x_distance = 0;
4159 int64_t y_distance = 0;
4160 double position = 0;
4163 switch(mwindow->session->current_operation) {
4165 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4166 if(get_cursor_x() > get_w()) {
4167 x_distance = get_cursor_x() - get_w();
4168 sample_movement = 1;
4170 else if(get_cursor_x() < 0) {
4171 x_distance = get_cursor_x();
4172 sample_movement = 1;
4175 if(get_cursor_y() > get_h()) {
4176 y_distance = get_cursor_y() - get_h();
4179 else if(get_cursor_y() < 0) {
4180 y_distance = get_cursor_y();
4187 if(sample_movement) {
4188 position = (double)(get_cursor_x() +
4189 mwindow->edl->local_session->view_start[pane->number] +
4191 mwindow->edl->local_session->zoom_sample /
4192 mwindow->edl->session->sample_rate;
4193 position = mwindow->edl->align_to_frame(position, 0);
4194 position = MAX(position, 0);
4196 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4197 switch(mwindow->session->current_operation) {
4199 if(position < selection_midpoint) {
4200 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4201 mwindow->edl->local_session->set_selectionstart(position);
4203 gui->unlock_window();
4204 mwindow->cwindow->update(1, 0, 0);
4205 gui->lock_window("TrackCanvas::repeat_event");
4206 // Update the faders
4207 mwindow->update_plugin_guis();
4208 gui->update_patchbay();
4211 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4212 mwindow->edl->local_session->set_selectionend(position);
4213 // Don't que the CWindow
4218 mwindow->samplemovement(
4219 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4223 if(track_movement) {
4224 mwindow->trackmovement(y_distance, pane->number);
4230 int TrackCanvas::button_release_event()
4232 int redraw = 0, update_overlay = 0, result = 0;
4234 // printf("TrackCanvas::button_release_event %d\n",
4235 // mwindow->session->current_operation);
4237 switch(mwindow->session->current_operation) {
4238 case DRAG_EDITHANDLE2:
4239 mwindow->session->current_operation = NO_OPERATION;
4243 end_edithandle_selection();
4246 case DRAG_EDITHANDLE1:
4247 mwindow->session->current_operation = NO_OPERATION;
4252 case DRAG_PLUGINHANDLE2:
4253 mwindow->session->current_operation = NO_OPERATION;
4257 end_pluginhandle_selection();
4260 case DRAG_PLUGINHANDLE1:
4261 mwindow->session->current_operation = NO_OPERATION;
4268 // delete the drag_auto_gang first and remove out of order keys
4269 synchronize_autos(0, 0, 0, -1);
4280 case DRAG_PROJECTOR_X:
4281 case DRAG_PROJECTOR_Y:
4282 case DRAG_PROJECTOR_Z:
4283 case DRAG_PLUGINKEY:
4284 mwindow->session->current_operation = NO_OPERATION;
4285 mwindow->session->drag_handle = 0;
4286 // Remove any out-of-order keyframe
4287 if(mwindow->session->drag_auto) {
4288 mwindow->session->drag_auto->autos->remove_nonsequential(
4289 mwindow->session->drag_auto);
4290 // mwindow->session->drag_auto->autos->optimize();
4295 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4300 case DRAG_AEFFECT_COPY:
4301 case DRAG_VEFFECT_COPY:
4302 // Trap in drag stop
4307 if(mwindow->session->current_operation) {
4308 // if(mwindow->session->current_operation == SELECT_REGION) {
4309 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4312 mwindow->session->current_operation = NO_OPERATION;
4314 // Traps button release events
4322 cursor_motion_event();
4324 if(update_overlay) {
4325 gui->draw_overlays(1);
4328 gui->draw_canvas(NORMAL_DRAW, 0);
4333 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4334 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4336 Edit *edit_result = 0;
4337 int handle_result = -1;
4340 if( !mwindow->edl->session->show_assets ) return 0;
4342 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4343 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4344 int64_t edit_x, edit_y, edit_w, edit_h;
4345 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4347 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4348 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4349 if( cursor_x < edit_x + HANDLE_W ) {
4352 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4353 new_cursor = DOWNLEFT_RESIZE;
4354 if( button_press == LEFT_BUTTON )
4360 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4363 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4364 new_cursor = DOWNRIGHT_RESIZE;
4365 if( button_press == LEFT_BUTTON )
4377 double position = 0;
4378 if( handle_result == 0 ) {
4379 position = edit_result->track->from_units(edit_result->startproject);
4380 new_cursor = LEFT_CURSOR;
4382 else if( handle_result == 1 ) {
4383 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4384 new_cursor = RIGHT_CURSOR;
4387 // Reposition cursor
4388 if( button_press ) {
4389 mwindow->session->drag_edit = edit_result;
4390 mwindow->session->drag_handle = handle_result;
4391 mwindow->session->drag_button = get_buttonpress() - 1;
4392 mwindow->session->drag_position = position;
4393 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4394 mwindow->session->drag_origin_x = get_cursor_x();
4395 mwindow->session->drag_origin_y = get_cursor_y();
4396 mwindow->session->drag_start = position;
4398 rerender = start_selection(position);
4402 else if( result < 0) {
4403 mwindow->undo->update_undo_before();
4404 if( !shift_down() ) {
4405 if( handle_result == 0 )
4406 edit_result->hard_left = !edit_result->hard_left;
4407 else if( handle_result == 1 )
4408 edit_result->hard_right = !edit_result->hard_right;
4411 int status = handle_result == 0 ? edit_result->hard_left :
4412 handle_result == 1 ? edit_result->hard_right : 0;
4413 int new_status = !status;
4414 int64_t edit_edge = edit_result->startproject;
4415 if( handle_result == 1 ) edit_edge += edit_result->length;
4416 double edge_position = edit_result->track->from_units(edit_edge);
4417 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4418 int64_t track_position = track->to_units(edge_position, 1);
4419 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4421 int64_t left_edge = left_edit->startproject;
4422 double left_position = track->from_units(left_edge);
4423 if( EQUIV(edge_position, left_position) ) {
4424 left_edit->hard_left = new_status;
4425 if( left_edit->previous )
4426 left_edit->previous->hard_right = new_status;
4429 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4431 int64_t right_edge = right_edit->startproject + right_edit->length;
4432 double right_position = track->from_units(right_edge);
4433 if( EQUIV(edge_position, right_position) ) {
4434 right_edit->hard_right = new_status;
4435 if( right_edit->next )
4436 right_edit->next->hard_left = new_status;
4441 rerender = update_overlay = 1;
4442 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4449 int TrackCanvas::do_plugin_handles(int cursor_x,
4453 int &update_overlay,
4457 Plugin *plugin_result = 0;
4458 int handle_result = 0;
4461 // if(!mwindow->edl->session->show_assets) return 0;
4463 for(Track *track = mwindow->edl->tracks->first;
4465 track = track->next) {
4466 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4467 PluginSet *plugin_set = track->plugin_set.values[i];
4468 for(Plugin *plugin = (Plugin*)plugin_set->first;
4470 plugin = (Plugin*)plugin->next) {
4471 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4472 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4474 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4475 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4476 if(cursor_x < plugin_x + HANDLE_W) {
4477 plugin_result = plugin;
4481 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4482 plugin_result = plugin;
4489 if(result && shift_down())
4490 mwindow->session->trim_edits = plugin_set;
4496 double position = 0;
4497 if(handle_result == 0) {
4498 position = plugin_result->track->from_units(plugin_result->startproject);
4499 new_cursor = LEFT_CURSOR;
4501 else if(handle_result == 1) {
4502 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4503 new_cursor = RIGHT_CURSOR;
4507 mwindow->session->drag_plugin = plugin_result;
4508 mwindow->session->drag_handle = handle_result;
4509 mwindow->session->drag_button = get_buttonpress() - 1;
4510 mwindow->session->drag_position = position;
4511 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4512 mwindow->session->drag_origin_x = get_cursor_x();
4513 mwindow->session->drag_origin_y = get_cursor_y();
4514 mwindow->session->drag_start = position;
4516 rerender = start_selection(position);
4525 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4529 // if(!mwindow->edl->session->show_assets) return 0;
4531 for(Track *track = mwindow->edl->tracks->first;
4533 track = track->next) {
4534 int64_t track_x, track_y, track_w, track_h;
4535 track_dimensions(track, track_x, track_y, track_w, track_h);
4537 if(button_press && get_buttonpress() == RIGHT_BUTTON &&
4538 cursor_y >= track_y && cursor_y < track_y + track_h) {
4539 gui->edit_menu->update(track, 0);
4540 gui->edit_menu->activate_menu();
4548 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4549 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4553 if(!mwindow->edl->session->show_assets) return 0;
4555 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4557 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4558 int64_t edit_x, edit_y, edit_w, edit_h;
4559 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4561 // Cursor inside a track
4562 // Cursor inside an edit
4563 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4564 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4565 // Select duration of edit
4567 if(get_double_click() && !drag_start) {
4568 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4569 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4570 edit->track->from_units(edit->length));
4571 if(mwindow->edl->session->cursor_on_frames)
4573 mwindow->edl->local_session->set_selectionstart(
4574 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4575 mwindow->edl->local_session->set_selectionend(
4576 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4584 else if(drag_start && track->record) {
4585 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4586 // Need to create drag window
4587 mwindow->session->current_operation = DRAG_EDIT;
4588 mwindow->session->drag_edit = edit;
4589 //printf("TrackCanvas::do_edits 2\n");
4591 // Drag only one edit if ctrl is initially down
4593 mwindow->session->drag_edits->remove_all();
4594 mwindow->session->drag_edits->append(edit);
4597 // Construct list of all affected edits
4598 mwindow->edl->tracks->get_affected_edits(
4599 mwindow->session->drag_edits,
4600 edit->track->from_units(edit->startproject),
4603 mwindow->session->drag_origin_x = cursor_x;
4604 mwindow->session->drag_origin_y = cursor_y;
4605 // Where the drag started, so we know relative position inside the edit later
4606 mwindow->session->drag_position = (double)cursor_x *
4607 mwindow->edl->local_session->zoom_sample /
4608 mwindow->edl->session->sample_rate +
4609 (double)mwindow->edl->local_session->view_start[pane->number] *
4610 mwindow->edl->local_session->zoom_sample /
4611 mwindow->edl->session->sample_rate;
4614 get_abs_cursor(cx, cy);
4615 gui->drag_popup = new BC_DragWindow(gui,
4616 mwindow->theme->get_image("clip_icon"), cx, cy);
4628 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4633 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4634 int button_press, int &redraw, int &rerender)
4643 // if(!mwindow->edl->session->show_assets) return 0;
4646 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4647 if(!track->expand_view) continue;
4649 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4650 // first check if plugins are visible at all
4651 if (!track->expand_view)
4653 PluginSet *plugin_set = track->plugin_set.values[i];
4654 for(plugin = (Plugin*)plugin_set->first;
4656 plugin = (Plugin*)plugin->next) {
4657 plugin_dimensions(plugin, x, y, w, h);
4658 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4659 MWindowGUI::visible(y, y + h, 0, get_h())) {
4660 if(cursor_x >= x && cursor_x < x + w &&
4661 cursor_y >= y && cursor_y < y + h) {
4671 // Start plugin popup
4673 if(get_buttonpress() == 3) {
4674 gui->plugin_menu->update(plugin);
4675 gui->plugin_menu->activate_menu();
4678 else if (get_double_click() && !drag_start) {
4679 // Select range of plugin on doubleclick over plugin
4680 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4681 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4682 plugin->track->from_units(plugin->length));
4683 if(mwindow->edl->session->cursor_on_frames) {
4684 mwindow->edl->local_session->set_selectionstart(
4685 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4686 mwindow->edl->local_session->set_selectionend(
4687 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4696 if(drag_start && plugin->track->record) {
4697 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4698 if(plugin->track->data_type == TRACK_AUDIO)
4699 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4700 else if(plugin->track->data_type == TRACK_VIDEO)
4701 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4703 mwindow->session->drag_plugin = plugin;
4704 mwindow->session->drag_origin_x = cursor_x;
4705 mwindow->session->drag_origin_y = cursor_y;
4706 // Where the drag started, so we know relative position inside the edit later
4707 mwindow->session->drag_position =
4708 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4709 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4711 switch(plugin->plugin_type) {
4712 case PLUGIN_STANDALONE: {
4713 PluginServer *server =
4714 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4715 if( !server ) break;
4716 VFrame *frame = server->picon;
4718 if(plugin->track->data_type == TRACK_AUDIO) {
4719 frame = mwindow->theme->get_image("aeffect_icon");
4722 frame = mwindow->theme->get_image("veffect_icon");
4726 get_abs_cursor(cx, cy);
4727 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4730 case PLUGIN_SHAREDPLUGIN:
4731 case PLUGIN_SHAREDMODULE: {
4732 VFrame *frame = mwindow->theme->get_image("clip_icon");
4734 get_abs_cursor(cx, cy);
4735 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4747 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4748 int button_press, int &new_cursor, int &update_cursor)
4750 Transition *transition = 0;
4754 if(/* !mwindow->edl->session->show_assets || */
4755 !mwindow->edl->session->auto_conf->transitions) return 0;
4757 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4759 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4760 if( edit->transition ) {
4761 edit_dimensions(edit, x, y, w, h);
4762 get_transition_coords(x, y, w, h);
4764 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4765 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4766 if( cursor_x >= x && cursor_x < x + w &&
4767 cursor_y >= y && cursor_y < y + h ) {
4768 transition = edit->transition;
4780 new_cursor = UPRIGHT_ARROW_CURSOR;
4782 else if(get_buttonpress() == 3) {
4783 gui->transition_menu->update(transition);
4784 gui->transition_menu->activate_menu();
4791 int TrackCanvas::button_press_event()
4794 int cursor_x, cursor_y;
4797 cursor_x = get_cursor_x();
4798 cursor_y = get_cursor_y();
4799 mwindow->session->trim_edits = 0;
4801 if(is_event_win() && cursor_inside()) {
4802 // double position = (double)cursor_x *
4803 // mwindow->edl->local_session->zoom_sample /
4804 // mwindow->edl->session->sample_rate +
4805 // (double)mwindow->edl->local_session->view_start[pane->number] *
4806 // mwindow->edl->local_session->zoom_sample /
4807 // mwindow->edl->session->sample_rate;
4814 if( get_buttonpress() == LEFT_BUTTON &&
4815 gui->mbuttons->transport->engine->command->command != STOP ) {
4816 gui->unlock_window();
4817 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4818 gui->lock_window("TrackCanvas::button_press_event");
4821 int update_overlay = 0, update_cursor = 0, rerender = 0;
4823 if(get_buttonpress() == WHEEL_UP) {
4825 mwindow->expand_sample();
4826 else if(ctrl_down())
4827 mwindow->move_left(get_w()/ 10);
4829 mwindow->move_up(get_h() / 10);
4831 else if(get_buttonpress() == WHEEL_DOWN) {
4833 mwindow->zoom_in_sample();
4834 else if(ctrl_down())
4835 mwindow->move_right(get_w() / 10);
4837 mwindow->move_down(get_h() / 10);
4839 else if(get_buttonpress() == 6) {
4841 mwindow->move_left(get_w());
4843 mwindow->move_left(get_w() / 20);
4845 mwindow->move_left(get_w() / 5);
4847 else if(get_buttonpress() == 7) {
4849 mwindow->move_right(get_w());
4851 mwindow->move_right(get_w() / 20);
4853 mwindow->move_right(get_w() / 5);
4856 switch(mwindow->edl->session->editing_mode) {
4857 // Test handles and resource boundaries and highlight a track
4858 case EDITING_ARROW: {
4859 if( do_transitions(cursor_x, cursor_y,
4860 1, new_cursor, update_cursor) ) break;
4862 if( do_keyframes(cursor_x, cursor_y,
4863 0, get_buttonpress(), new_cursor,
4864 update_cursor, rerender) ) break;
4865 // Test edit boundaries
4866 if( do_edit_handles(cursor_x, cursor_y,
4867 1, rerender, update_overlay, new_cursor,
4868 update_cursor) ) break;
4869 // Test plugin boundaries
4870 if( do_plugin_handles(cursor_x, cursor_y,
4871 1, rerender, update_overlay, new_cursor,
4872 update_cursor) ) break;
4874 if( do_edits(cursor_x, cursor_y, 1, 0,
4875 update_cursor, rerender, new_cursor,
4876 update_cursor) ) break;
4878 if( do_plugins(cursor_x, cursor_y, 0, 1,
4879 update_cursor, rerender) ) break;
4881 if( test_resources(cursor_x, cursor_y) ) break;
4883 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4888 // Test handles only and select a region
4889 case EDITING_IBEAM: {
4890 double position = (double)cursor_x *
4891 mwindow->edl->local_session->zoom_sample /
4892 mwindow->edl->session->sample_rate +
4893 (double)mwindow->edl->local_session->view_start[pane->number] *
4894 mwindow->edl->local_session->zoom_sample /
4895 mwindow->edl->session->sample_rate;
4896 //printf("TrackCanvas::button_press_event %d\n", position);
4898 if( do_transitions(cursor_x, cursor_y,
4899 1, new_cursor, update_cursor)) break;
4900 if(do_keyframes(cursor_x, cursor_y,
4901 0, get_buttonpress(), new_cursor,
4902 update_cursor, rerender)) {
4906 // Test edit boundaries
4907 if( do_edit_handles(cursor_x, cursor_y,
4908 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4909 // Test plugin boundaries
4910 if( do_plugin_handles(cursor_x, cursor_y,
4911 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4913 if( do_edits(cursor_x, cursor_y,
4914 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4916 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4918 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4919 // Highlight selection
4920 if( get_buttonpress() != LEFT_BUTTON ) break;
4921 rerender = start_selection(position);
4922 mwindow->session->current_operation = SELECT_REGION;
4929 gui->unlock_window();
4930 mwindow->cwindow->update(1, 0, 0, 0, 1);
4931 gui->lock_window("TrackCanvas::button_press_event 2");
4933 mwindow->update_plugin_guis();
4934 gui->update_patchbay();
4937 if( update_overlay ) {
4938 gui->draw_overlays(1);
4940 if( update_cursor < 0 ) {
4941 // double_click edit
4942 gui->swindow->update_selection();
4944 if( update_cursor ) {
4945 gui->update_timebar(0);
4946 gui->hide_cursor(0);
4947 gui->show_cursor(1);
4948 gui->zoombar->update();
4949 gui->flash_canvas(1);
4956 int TrackCanvas::start_selection(double position)
4959 position = mwindow->edl->align_to_frame(position, 1);
4965 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4966 mwindow->edl->local_session->get_selectionend(1)) / 2;
4968 if(position < midpoint)
4970 mwindow->edl->local_session->set_selectionstart(position);
4971 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4977 mwindow->edl->local_session->set_selectionend(position);
4978 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4979 // Don't que the CWindow for the end
4983 // Start a new selection
4985 //printf("TrackCanvas::start_selection %f\n", position);
4986 mwindow->edl->local_session->set_selectionstart(position);
4987 mwindow->edl->local_session->set_selectionend(position);
4988 selection_midpoint = position;
4996 void TrackCanvas::end_edithandle_selection()
4998 mwindow->modify_edithandles();
5001 void TrackCanvas::end_pluginhandle_selection()
5003 mwindow->modify_pluginhandles();
5007 double TrackCanvas::time_visible()
5009 return (double)get_w() *
5010 mwindow->edl->local_session->zoom_sample /
5011 mwindow->edl->session->sample_rate;
5015 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
5017 char string[BCTEXTLEN];
5018 char *cp = string, *ep = cp + sizeof(string)-1;
5019 if( show_curve_type ) {
5020 cp += snprintf(string, ep-cp, "%-8s ",
5021 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5023 char string2[BCTEXTLEN];
5024 Units::totext(string2,
5025 current->autos->track->from_units(current->position),
5026 mwindow->edl->session->time_format,
5027 mwindow->edl->session->sample_rate,
5028 mwindow->edl->session->frame_rate,
5029 mwindow->edl->session->frames_per_foot);
5030 cp += snprintf(cp, ep-cp, "%s", string2);
5033 vsnprintf(cp, ep-cp, fmt, ap);
5035 gui->show_message(string);
5038 // Patchbay* TrackCanvas::get_patchbay()
5040 // if(pane->patchbay) return pane->patchbay;
5041 // if(gui->total_panes() == 2 &&
5042 // gui->pane[TOP_LEFT_PANE] &&
5043 // gui->pane[TOP_RIGHT_PANE])
5044 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5045 // if(gui->total_panes() == 4)
5047 // if(pane->number == TOP_RIGHT_PANE)
5048 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5050 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;