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 IndexState *index_state = indexable->index_state;
680 // Don't redraw raw samples
681 if(index_state->index_zoom > mwindow->edl->local_session->zoom_sample)
683 draw_resources(0, 1, indexable);
688 void TrackCanvas::draw_resources(int mode,
690 Indexable *indexable)
694 if(debug) PRINT_TRACE
696 if(!mwindow->edl->session->show_assets) return;
699 // can't stop thread here, because this is called for every pane
700 // if(mode != IGNORE_THREAD && !indexes_only)
701 // gui->resource_thread->stop_draw(!indexes_only);
703 if(mode != IGNORE_THREAD &&
705 !gui->resource_thread->interrupted)
707 printf("TrackCanvas::draw_resources %d: called without stopping ResourceThread\n",
710 BC_Signals::dump_stack();
713 if(debug) PRINT_TRACE
715 resource_timer->update();
717 // Age resource pixmaps for deletion
719 for(int i = 0; i < gui->resource_pixmaps.total; i++)
720 gui->resource_pixmaps.values[i]->visible--;
722 if(mode == FORCE_REDRAW)
723 gui->resource_pixmaps.remove_all_objects();
725 if(debug) PRINT_TRACE
728 for(Track *current = mwindow->edl->tracks->first;
732 if(debug) PRINT_TRACE
733 for(Edit *edit = current->edits->first; edit; edit = edit->next)
735 if(debug) PRINT_TRACE
736 if( current->data_type != TRACK_SUBTITLE )
737 if(!edit->asset && !edit->nested_edl) continue;
740 if(edit->track->data_type != TRACK_AUDIO) continue;
742 if(edit->nested_edl &&
743 strcmp(indexable->path, edit->nested_edl->path)) continue;
746 strcmp(indexable->path, edit->asset->path)) continue;
749 if(debug) PRINT_TRACE
751 int64_t edit_x, edit_y, edit_w, edit_h;
752 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
755 if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
756 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
758 int64_t pixmap_x, pixmap_w, pixmap_h;
759 if(debug) PRINT_TRACE
761 // Search for existing pixmap containing edit
762 for(int i = 0; i < gui->resource_pixmaps.total; i++)
764 ResourcePixmap* pixmap = gui->resource_pixmaps.values[i];
765 // Same pointer can be different edit if editing took place
766 if(pixmap->edit_id == edit->id &&
767 pixmap->pane_number == pane->number)
773 if(debug) PRINT_TRACE
775 // Get new size, offset of pixmap needed
776 get_pixmap_size(edit,
782 if(debug) PRINT_TRACE
785 if(pixmap_w && pixmap_h)
787 // Create pixmap if it doesn't exist
788 ResourcePixmap* pixmap = create_pixmap(edit,
793 // Resize it if it's bigger
794 if(pixmap_w > pixmap->pixmap_w ||
795 pixmap_h > pixmap->pixmap_h)
796 pixmap->resize(pixmap_w, pixmap_h);
797 pixmap->draw_data(this,
806 // Resize it if it's smaller
807 if(pixmap_w < pixmap->pixmap_w ||
808 pixmap_h < pixmap->pixmap_h)
809 pixmap->resize(pixmap_w, pixmap_h);
811 // Copy pixmap to background canvas
812 background_pixmap->draw_pixmap(pixmap,
814 current->y_pixel - mwindow->edl->local_session->track_start[pane->number],
818 if(debug) PRINT_TRACE
825 // Delete unused pixmaps
826 if(debug) PRINT_TRACE
828 for(int i = gui->resource_pixmaps.total - 1; i >= 0; i--)
829 if(gui->resource_pixmaps.values[i]->visible < PIXMAP_AGE)
831 //printf("TrackCanvas::draw_resources %d\n", __LINE__);
832 delete gui->resource_pixmaps.values[i];
833 gui->resource_pixmaps.remove(gui->resource_pixmaps.values[i]);
835 if(debug) PRINT_TRACE
837 if(hourglass_enabled)
840 hourglass_enabled = 0;
842 if(debug) PRINT_TRACE
844 // can't stop thread here, because this is called for every pane
845 // if(mode != IGNORE_THREAD && !indexes_only)
846 // gui->resource_thread->start_draw();
847 if(debug) PRINT_TRACE
852 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit,
858 ResourcePixmap *result = 0;
860 for(int i = 0; i < gui->resource_pixmaps.total; i++)
862 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
863 if(gui->resource_pixmaps.values[i]->edit_id == edit->id &&
864 gui->resource_pixmaps.values[i]->pane_number == pane->number)
866 result = gui->resource_pixmaps.values[i];
874 result = new ResourcePixmap(mwindow,
881 gui->resource_pixmaps.append(result);
884 // result->resize(pixmap_w, pixmap_h);
888 void TrackCanvas::get_pixmap_size(Edit *edit,
896 // Align x on frame boundaries
899 // switch(edit->edits->track->data_type)
911 if(pixmap_x + pixmap_w > get_w())
913 pixmap_w = get_w() - pixmap_x;
920 // int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
921 // int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
922 // int64_t pixel_increment = MAX(picon_w, frame_w);
923 // int64_t pixmap_x1 = edit_x;
924 // int64_t pixmap_x2 = edit_x + edit_w;
928 // pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) *
933 // if(pixmap_x2 > get_w())
935 // pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) *
939 // pixmap_x = pixmap_x1;
940 // pixmap_w = pixmap_x2 - pixmap_x1;
945 pixmap_h = mwindow->edl->local_session->zoom_track;
946 if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->get_image("title_bg_data")->get_h();
947 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
950 void TrackCanvas::edit_dimensions(Edit *edit,
956 // w = Units::round(edit->track->from_units(edit->length) *
957 // mwindow->edl->session->sample_rate /
958 // mwindow->edl->local_session->zoom_sample);
962 x = Units::round(edit->track->from_units(edit->startproject) *
963 mwindow->edl->session->sample_rate /
964 mwindow->edl->local_session->zoom_sample -
965 mwindow->edl->local_session->view_start[pane->number]);
967 // Method for calculating w so when edits are together we never get off by one error due to rounding
968 int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) *
969 mwindow->edl->session->sample_rate /
970 mwindow->edl->local_session->zoom_sample -
971 mwindow->edl->local_session->view_start[pane->number]);
974 y = edit->edits->track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
976 if(mwindow->edl->session->show_titles)
977 h += mwindow->theme->get_image("title_bg_data")->get_h();
980 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
984 y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
985 h = track->vertical_span(mwindow->theme);
989 void TrackCanvas::draw_paste_destination()
991 //int cursor_x = get_relative_cursor_x();
992 //int cursor_y = get_relative_cursor_y();
993 int current_atrack = 0;
994 int current_vtrack = 0;
995 int current_aedit = 0;
996 int current_vedit = 0;
1002 //if(pane->number == BOTTOM_RIGHT_PANE)
1003 //printf("TrackCanvas::draw_paste_destination %d %p\n", __LINE__, mwindow->session->track_highlighted);
1005 if((mwindow->session->current_operation == DRAG_ASSET &&
1006 (mwindow->session->drag_assets->total ||
1007 mwindow->session->drag_clips->total)) ||
1008 (mwindow->session->current_operation == DRAG_EDIT &&
1009 mwindow->session->drag_edits->total)) {
1010 Indexable *indexable = 0;
1014 if(mwindow->session->current_operation == DRAG_ASSET &&
1015 mwindow->session->drag_assets->size())
1016 indexable = mwindow->session->drag_assets->get(0);
1018 if(mwindow->session->current_operation == DRAG_ASSET &&
1019 mwindow->session->drag_clips->size())
1020 clip = mwindow->session->drag_clips->get(0);
1022 int has_audio = 0, has_video = 0;
1023 double paste_audio_length = 0, paste_video_length = 0;
1024 double paste_audio_position = -1, paste_video_position = -1;
1027 has_audio = indexable->have_audio();
1028 paste_audio_length = !has_audio ? 0 :
1029 (double)indexable->get_audio_samples() / indexable->get_sample_rate();
1030 has_video = indexable->have_video();
1031 Asset *asset = indexable->is_asset ? (Asset *)indexable : 0;
1032 // Images have length -1
1033 if( asset && asset->video_data && asset->video_length < 0 ) {
1034 paste_video_length = mwindow->edl->session->si_useduration ?
1035 mwindow->edl->session->si_duration / asset->frame_rate :
1036 1.0 / asset->frame_rate ; // 1 frame
1039 paste_video_length = !has_video ? 0 :
1040 (double)indexable->get_video_frames() / indexable->get_frame_rate();
1044 has_audio = clip->tracks->total_audio_tracks() > 0 ? 1 : 0;
1045 paste_audio_length = !has_audio ? 0 : clip->tracks->total_audio_length();
1046 has_video = clip->tracks->total_video_tracks() > 0 ? 1 : 0;
1047 paste_video_length = !has_video ? 0 : clip->tracks->total_video_length();
1050 // 'Align cursor on frame' lengths calculations
1051 if( mwindow->edl->session->cursor_on_frames ) {
1052 double fps = mwindow->edl->session->frame_rate;
1053 double aud = floor(paste_audio_length * fps) / fps;
1054 double vid = floor(paste_video_length * fps) / fps;
1055 double length = has_video && has_audio ?
1056 aud < vid ? aud : vid :
1058 has_audio ? aud : 0;
1059 paste_video_length = paste_audio_length = length;
1062 if( has_audio ) { // we use video if we are over video and audio if we are over audio
1064 switch( mwindow->session->track_highlighted->data_type ) {
1065 case TRACK_VIDEO: length = paste_video_length; break;
1066 case TRACK_AUDIO: length = paste_audio_length; break;
1068 int64_t asset_length = mwindow->session->track_highlighted->
1069 to_units(length, 1);
1070 paste_audio_position = mwindow->session->track_highlighted->
1071 from_units(drop_edit_position(&insertion, NULL, asset_length));
1074 int64_t asset_length = mwindow->session->track_highlighted->
1075 to_units(paste_video_length, 1);
1076 paste_video_position = mwindow->session->track_highlighted->
1077 from_units(drop_edit_position(&insertion, NULL, asset_length));
1080 // Get destination track
1081 for(Track *dest = mwindow->session->track_highlighted;
1083 dest = dest->next) {
1085 // Get source width in pixels
1087 // Use start of highlighted edit
1088 if(mwindow->session->edit_highlighted) {
1089 position = mwindow->session->track_highlighted->from_units(
1090 mwindow->session->edit_highlighted->startproject);
1093 // Use end of highlighted track, disregarding effects
1094 position = mwindow->session->track_highlighted->from_units(
1095 mwindow->session->track_highlighted->edits->length());
1098 // Get the x coordinate
1099 x = Units::to_int64(position *
1100 mwindow->edl->session->sample_rate /
1101 mwindow->edl->local_session->zoom_sample) -
1102 mwindow->edl->local_session->view_start[pane->number];
1104 double paste_position = -1.;
1105 if(dest->data_type == TRACK_AUDIO) {
1106 if(indexable && current_atrack < indexable->get_audio_channels()) {
1107 //printf("TrackCanvas::draw_paste_destination %d %d\n", __LINE__, current_atrack);
1108 w = Units::to_int64((double)indexable->get_audio_samples() /
1109 indexable->get_sample_rate() *
1110 mwindow->edl->session->sample_rate /
1111 mwindow->edl->local_session->zoom_sample);
1112 paste_position = paste_audio_position;
1114 else if(clip && current_atrack < clip->tracks->total_audio_tracks()) {
1115 w = Units::to_int64((double)clip->tracks->total_length() *
1116 mwindow->edl->session->sample_rate /
1117 mwindow->edl->local_session->zoom_sample);
1118 paste_position = paste_audio_position;
1119 //printf("draw_paste_destination %d\n", x);
1121 else if(mwindow->session->current_operation == DRAG_EDIT &&
1122 current_aedit < mwindow->session->drag_edits->total) {
1124 while(current_aedit < mwindow->session->drag_edits->total &&
1125 mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1128 if(current_aedit < mwindow->session->drag_edits->total) {
1129 edit = mwindow->session->drag_edits->values[current_aedit];
1130 w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1131 paste_position = mwindow->session->track_highlighted->
1132 from_units(drop_edit_position(&insertion,
1133 mwindow->session->drag_edit,
1134 mwindow->session->drag_edit->length));
1137 if( paste_position >= 0 ) {
1138 position = paste_position;
1145 else if(dest->data_type == TRACK_VIDEO) {
1146 //printf("draw_paste_destination 1\n");
1147 if(indexable && current_vtrack < indexable->get_video_layers())
1149 w = Units::to_int64((double)indexable->get_video_frames() /
1150 indexable->get_frame_rate() *
1151 mwindow->edl->session->sample_rate /
1152 mwindow->edl->local_session->zoom_sample);
1153 paste_position = paste_video_position;
1155 else if(clip && current_vtrack < clip->tracks->total_video_tracks()) {
1156 w = Units::to_int64(clip->tracks->total_length() *
1157 mwindow->edl->session->sample_rate /
1158 mwindow->edl->local_session->zoom_sample);
1159 paste_position = paste_video_position;
1161 else if(mwindow->session->current_operation == DRAG_EDIT &&
1162 current_vedit < mwindow->session->drag_edits->total) {
1164 while(current_vedit < mwindow->session->drag_edits->total &&
1165 mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1168 if(current_vedit < mwindow->session->drag_edits->total) {
1169 edit = mwindow->session->drag_edits->values[current_vedit];
1170 w = Units::to_int64(edit->track->from_units(edit->length) *
1171 mwindow->edl->session->sample_rate /
1172 mwindow->edl->local_session->zoom_sample);
1173 paste_position = mwindow->session->track_highlighted->
1174 from_units(drop_edit_position(&insertion,
1175 mwindow->session->drag_edit,
1176 mwindow->session->drag_edit->length));
1179 if( paste_position >= 0 ) {
1180 position = paste_position;
1189 // Get the x coordinate
1190 x = Units::to_int64(position *
1191 mwindow->edl->session->sample_rate /
1192 mwindow->edl->local_session->zoom_sample) -
1193 mwindow->edl->local_session->view_start[pane->number];
1194 int y = dest->y_pixel - mwindow->edl->local_session->track_start[pane->number];
1195 int h = dest->vertical_span(mwindow->theme);
1197 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1199 draw_highlight_insertion(x, y, w, h);
1201 draw_highlight_rectangle(x, y, w, h);
1202 if(x < -BC_INFINITY) {
1203 w -= -BC_INFINITY - x;
1204 x += -BC_INFINITY - x;
1207 // if(pane->number == TOP_RIGHT_PANE)
1208 // printf("TrackCanvas::draw_paste_destination %d %d %d %d %d\n",
1209 // __LINE__, x, y, w, h);
1210 draw_highlight_rectangle(x, y, w, h);
1217 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1219 x = Units::round(plugin->track->from_units(plugin->startproject) *
1220 mwindow->edl->session->sample_rate /
1221 mwindow->edl->local_session->zoom_sample -
1222 mwindow->edl->local_session->view_start[pane->number]);
1223 w = Units::round(plugin->track->from_units(plugin->length) *
1224 mwindow->edl->session->sample_rate /
1225 mwindow->edl->local_session->zoom_sample);
1226 y = plugin->track->y_pixel -
1227 mwindow->edl->local_session->track_start[pane->number] +
1228 mwindow->edl->local_session->zoom_track +
1229 plugin->plugin_set->get_number() *
1230 mwindow->theme->get_image("plugin_bg_data")->get_h();
1231 if(mwindow->edl->session->show_titles)
1232 y += mwindow->theme->get_image("title_bg_data")->get_h();
1233 h = mwindow->theme->get_image("plugin_bg_data")->get_h();
1236 int TrackCanvas::resource_h()
1238 return mwindow->edl->local_session->zoom_track;
1241 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1244 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1245 // just draw arrows, so user has indication that something is there
1246 // FIXME: get better colors
1250 draw_triangle_left(0, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1255 draw_triangle_right(get_w() - h * 2/3, y + h /6, h * 2/3, h * 2/3, BLACK, GREEN, YELLOW, RED, BLUE);
1259 // Fix bug in heroines & cvs version as of 22.8.2005:
1260 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1261 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1274 w = MIN(w, get_w() + 20);
1275 h = MIN(h, get_h() + 20);
1278 set_color(mwindow->preferences->highlight_inverse);
1280 //draw_rectangle(x, y, w, h);
1281 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1282 draw_rectangle(x + 2, y + 2, w - 4, h - 4);
1284 draw_rectangle(x, y, w, h);
1286 //if(pane->number == TOP_RIGHT_PANE)
1287 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d %d\n", __LINE__, x, y, w, h);
1290 void TrackCanvas::draw_highlight_insertion(int x, int y, int w, int h)
1293 // if we have to draw a highlighted rectangle completely on the left or completely on the right of the viewport,
1294 // just draw arrows, so user has indication that something is there
1295 // FIXME: get better colors
1304 /* these don't look so good
1306 draw_line(x, y, x, y+h);
1307 draw_line(x - h2 * 2, y + h1*2, x - h2, y+h1*2);
1308 draw_line(x - h2 * 2, y + h1*2+1, x - h2, y+h1*2+1);
1309 draw_line(x - h2 * 2, y + h1*6, x - h2, y+h1*6);
1310 draw_line(x - h2 * 2, y + h1*6+1, x - h2, y+h1*6+1);
1312 draw_triangle_right(x - h2, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1313 draw_triangle_right(x - h2, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1315 /* draw_line(x + h2 * 2, y + h1*2, x + h2, y+h1*2);
1316 draw_line(x + h2 * 2, y + h1*2+1, x + h2, y+h1*2+1);
1317 draw_line(x + h2 * 2, y + h1*6, x + h2, y+h1*6);
1318 draw_line(x - h2 * 2, y + h1*6+1, x + h2, y+h1*6+1);
1320 draw_triangle_left(x, y + h1, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1321 draw_triangle_left(x, y + h1*5, h2, h2, BLACK, GREEN, YELLOW, RED, BLUE);
1323 // draw the box centred around x
1325 // Fix bug in heroines & cvs version as of 22.8.2005:
1326 // If we grab when zoomed in and zoom out while dragging, when edit gets really narrow strange things start happening
1327 if (w >= 0 && w < 3) {x -= w /2; w = 3;};
1338 w = MIN(w, get_w() + 20);
1339 h = MIN(h, get_h() + 20);
1340 set_color(mwindow->preferences->highlight_inverse);
1342 draw_rectangle(x, y, w, h);
1343 draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1345 //printf("TrackCanvas::draw_highlight_insertion %d %d %d %d\n", x, y, w, h);
1348 void TrackCanvas::draw_playback_cursor()
1350 // Called before playback_cursor exists
1351 // if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1353 // mwindow->playback_cursor->visible = 0;
1354 // mwindow->playback_cursor->draw();
1358 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1360 int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1361 int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1363 edit_dimensions(edit, x, y, w, h);
1365 if(mwindow->edl->session->show_titles)
1367 y += mwindow->theme->get_image("title_bg_data")->get_h();
1374 if(side == EDIT_OUT)
1383 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1385 //printf("TrackCanvas::get_transition_coords 1\n");
1386 // int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1387 // int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1388 int transition_w = 30;
1389 int transition_h = 30;
1390 //printf("TrackCanvas::get_transition_coords 1\n");
1392 if(mwindow->edl->session->show_titles)
1393 y += mwindow->theme->get_image("title_bg_data")->get_h();
1394 //printf("TrackCanvas::get_transition_coords 2\n");
1396 y += (h - mwindow->theme->get_image("title_bg_data")->get_h()) / 2 - transition_h / 2;
1397 x -= transition_w / 2;
1403 void TrackCanvas::draw_highlighting()
1408 switch(mwindow->session->current_operation)
1410 case DRAG_ATRANSITION:
1411 case DRAG_VTRANSITION:
1412 //printf("TrackCanvas::draw_highlighting 1 %p %p\n",
1413 // mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1414 if(mwindow->session->edit_highlighted) {
1415 //printf("TrackCanvas::draw_highlighting 2\n");
1416 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
1417 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1418 (mwindow->session->current_operation == DRAG_VTRANSITION &&
1419 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)) {
1420 //printf("TrackCanvas::draw_highlighting 2\n");
1421 edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1422 //printf("TrackCanvas::draw_highlighting 2\n");
1424 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1425 MWindowGUI::visible(y, y + h, 0, get_h())) {
1427 get_transition_coords(x, y, w, h);
1429 //printf("TrackCanvas::draw_highlighting 3\n");
1434 // Dragging a new effect from the Resource window
1437 if(mwindow->session->track_highlighted &&
1438 ((mwindow->session->current_operation == DRAG_AEFFECT &&
1439 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1440 (mwindow->session->current_operation == DRAG_VEFFECT &&
1441 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1442 // Put it before another plugin
1443 if(mwindow->session->plugin_highlighted) {
1444 plugin_dimensions(mwindow->session->plugin_highlighted,
1446 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1448 // Put it after a plugin set
1449 else if( mwindow->session->pluginset_highlighted &&
1450 mwindow->session->pluginset_highlighted->last ) {
1451 plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last,
1453 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1454 int64_t track_x, track_y, track_w, track_h;
1455 track_dimensions(mwindow->session->track_highlighted,
1456 track_x, track_y, track_w, track_h);
1460 mwindow->session->track_highlighted->get_length() *
1461 mwindow->edl->session->sample_rate /
1462 mwindow->edl->local_session->zoom_sample -
1463 mwindow->edl->local_session->view_start[pane->number]) -
1465 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1466 if(w <= 0) w = track_w;
1469 track_dimensions(mwindow->session->track_highlighted,
1472 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1473 // Put it in a new plugin set determined by the selected range
1474 if(mwindow->edl->local_session->get_selectionend() >
1475 mwindow->edl->local_session->get_selectionstart()) {
1476 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1477 mwindow->edl->session->sample_rate /
1478 mwindow->edl->local_session->zoom_sample -
1479 mwindow->edl->local_session->view_start[pane->number]);
1480 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() -
1481 mwindow->edl->local_session->get_selectionstart()) *
1482 mwindow->edl->session->sample_rate /
1483 mwindow->edl->local_session->zoom_sample);
1485 // Put it in a new plugin set determined by an edit boundary
1486 else if(mwindow->session->edit_highlighted) {
1487 int64_t temp_y, temp_h;
1488 edit_dimensions(mwindow->session->edit_highlighted,
1489 x, temp_y, w, temp_h);
1491 // Put it at the beginning of the track in a new plugin set
1494 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1495 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1496 //printf("TrackCanvas::draw_highlighting 1\n");
1503 if(mwindow->session->track_highlighted) {
1504 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1506 // if(MWindowGUI::visible(y, y + h, 0, get_h()))
1508 draw_paste_destination();
1514 if(mwindow->session->track_highlighted) {
1515 // track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1517 // if(MWindowGUI::visible(y, y + h, 0, get_h())) {
1518 draw_paste_destination();
1523 // Dragging an effect from the timeline
1524 case DRAG_AEFFECT_COPY:
1525 case DRAG_VEFFECT_COPY:
1526 if( (mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1527 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
1528 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1529 (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
1530 mwindow->session->track_highlighted->data_type == TRACK_VIDEO))) {
1532 int64_t plugin_position = -1;
1533 Plugin *drag_plugin = mwindow->session->drag_plugin;
1534 PluginSet *hi_plugin_set = mwindow->session->pluginset_highlighted;
1535 Track *hi_track = mwindow->session->track_highlighted;
1536 Edit *hi_edit = mwindow->session->edit_highlighted;
1537 // Put it into a silence zone
1538 if( hi_plugin_set && hi_plugin_set->last &&
1539 hi_plugin_set->track == drag_plugin->track ) {
1540 plugin_dimensions((Plugin *)hi_plugin_set->last, x, y, w, h);
1541 plugin_position = drop_plugin_position(hi_plugin_set, drag_plugin);
1542 hi_track = drag_plugin->track;
1544 else if( hi_track ) {
1545 // Put it in a new plugin set determined by an edit boundary, or at the start of the track
1546 track_dimensions(hi_track, x, y, w, h);
1547 plugin_position = hi_edit ? hi_edit->startproject : 0;
1550 if( plugin_position < 0 ) break;
1552 // Calculate length of plugin based on data type of track and units
1553 double zoom_scale = (double)mwindow->edl->session->sample_rate /
1554 mwindow->edl->local_session->zoom_sample;
1555 x = Units::round(hi_track->from_units(plugin_position) * zoom_scale) -
1556 mwindow->edl->local_session->view_start[pane->number];
1557 w = Units::round(hi_track->from_units(drag_plugin->length) * zoom_scale);
1559 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1560 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
1566 case DRAG_PLUGINKEY:
1567 if(mwindow->session->plugin_highlighted &&
1568 mwindow->session->current_operation == DRAG_PLUGINKEY)
1570 // Just highlight the plugin
1571 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1573 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1574 MWindowGUI::visible(y, y + h, 0, get_h()))
1586 draw_highlight_rectangle(x, y, w, h);
1590 void TrackCanvas::draw_plugins()
1592 char string[BCTEXTLEN];
1594 int current_show = 0;
1595 int current_preset = 0;
1597 // if(!mwindow->edl->session->show_assets) goto done;
1599 for(int i = 0; i < plugin_on_toggles.total; i++)
1600 plugin_on_toggles.values[i]->in_use = 0;
1601 for(int i = 0; i < plugin_show_toggles.total; i++)
1602 plugin_show_toggles.values[i]->in_use = 0;
1603 for(int i = 0; i < preset_edit_buttons.total; i++)
1604 plugin_show_toggles.values[i]->in_use = 0;
1607 for(Track *track = mwindow->edl->tracks->first;
1609 track = track->next)
1611 if(track->expand_view)
1613 for(int i = 0; i < track->plugin_set.total; i++)
1615 PluginSet *pluginset = track->plugin_set.values[i];
1617 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1619 int64_t total_x, y, total_w, h;
1620 plugin_dimensions(plugin, total_x, y, total_w, h);
1622 if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1623 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1624 plugin->plugin_type != PLUGIN_NONE)
1626 int x = total_x, w = total_w, left_margin = 5;
1627 int right_margin = 5;
1633 if(w + x > get_w()) w -= (w + x) - get_w();
1640 mwindow->theme->get_image("plugin_bg_data"),
1642 set_color(mwindow->theme->title_color);
1643 set_font(mwindow->theme->title_font);
1644 plugin->calculate_title(string, 0);
1646 // Truncate string to int64_test visible in background
1647 int len = strlen(string), j;
1648 for(j = len; j >= 0; j--)
1650 if(left_margin + get_text_width(mwindow->theme->title_font, string) > w)
1658 // Justify the text on the left boundary of the edit if it is visible.
1659 // Otherwise justify it on the left side of the screen.
1660 int64_t text_x = total_x + left_margin;
1661 int64_t text_w = get_text_width(mwindow->theme->title_font, string, strlen(string));
1662 text_x = MAX(left_margin, text_x);
1664 y + get_text_ascent(mwindow->theme->title_font) + 2,
1668 int64_t min_x = total_x + text_w;
1671 // Update plugin toggles
1672 int toggle_x = total_x + total_w;
1674 toggle_x = MIN(get_w() - right_margin, toggle_x);
1677 toggle_x -= PluginOn::calculate_w(mwindow) + 10;
1678 if(toggle_x > min_x)
1680 if(current_on >= plugin_on_toggles.total)
1682 PluginOn *plugin_on = new PluginOn(mwindow, toggle_x, toggle_y, plugin);
1683 add_subwindow(plugin_on);
1684 plugin_on_toggles.append(plugin_on);
1688 plugin_on_toggles.values[current_on]->update(toggle_x, toggle_y, plugin);
1693 // Toggles for standalone plugins only
1694 if(plugin->plugin_type == PLUGIN_STANDALONE)
1697 toggle_x -= PluginShow::calculate_w(mwindow) + 10;
1698 if(toggle_x > min_x)
1700 if(current_show >= plugin_show_toggles.total)
1702 PluginShow *plugin_show = new PluginShow(mwindow, toggle_x, toggle_y, plugin);
1703 add_subwindow(plugin_show);
1704 plugin_show_toggles.append(plugin_show);
1708 plugin_show_toggles.values[current_show]->update(toggle_x, toggle_y, plugin);
1712 toggle_x -= PluginPresetEdit::calculate_w(mwindow) + 10;
1713 if(toggle_x > min_x)
1715 if(current_preset >= preset_edit_buttons.total)
1717 PluginPresetEdit *preset_edit = new PluginPresetEdit(mwindow, toggle_x, toggle_y, plugin);
1718 add_subwindow(preset_edit);
1719 preset_edit_buttons.append(preset_edit);
1723 preset_edit_buttons.values[current_preset]->update(toggle_x, toggle_y, plugin);
1734 // Remove unused toggles
1736 while(current_preset < preset_edit_buttons.total)
1738 preset_edit_buttons.remove_object_number(current_preset);
1740 while(current_show < plugin_show_toggles.total)
1742 plugin_show_toggles.remove_object_number(current_show);
1745 while(current_on < plugin_on_toggles.total)
1747 plugin_on_toggles.remove_object_number(current_on);
1751 void TrackCanvas::refresh_plugintoggles()
1753 for(int i = 0; i < plugin_on_toggles.total; i++)
1755 PluginOn *on = plugin_on_toggles.values[i];
1756 on->reposition_window(on->get_x(), on->get_y());
1758 for(int i = 0; i < plugin_show_toggles.total; i++)
1760 PluginShow *show = plugin_show_toggles.values[i];
1761 show->reposition_window(show->get_x(), show->get_y());
1763 for(int i = 0; i < preset_edit_buttons.total; i++)
1765 PluginPresetEdit *preset_edit = preset_edit_buttons.values[i];
1766 preset_edit->reposition_window(preset_edit->get_x(), preset_edit->get_y());
1770 void TrackCanvas::draw_hard_edges()
1774 // if(!mwindow->edl->session->show_assets) return;
1776 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1777 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1778 if( !edit->hard_left && !edit->hard_right ) continue;
1779 edit_dimensions(edit, x, y, w, h);
1781 set_opaque(); int y1 = y+h-1;
1782 if( edit->hard_left ) {
1783 ArrayList<int> xpt, ypt;
1784 xpt.append(x); ypt.append(y1);
1785 xpt.append(x+HANDLE_W); ypt.append(y1);
1786 xpt.append(x); ypt.append(y1-HANDLE_H);
1787 fill_polygon(&xpt, &ypt);
1789 if( edit->hard_right ) {
1790 ArrayList<int> xpt, ypt; int x1 = x+w-1;
1791 xpt.append(x1); ypt.append(y1);
1792 xpt.append(x1-HANDLE_W); ypt.append(y1);
1793 xpt.append(x1); ypt.append(y1-HANDLE_H);
1794 fill_polygon(&xpt, &ypt);
1800 void TrackCanvas::draw_inout_points()
1805 void TrackCanvas::draw_drag_handle()
1807 if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1808 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1810 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1811 int64_t pixel1 = Units::round(mwindow->session->drag_position *
1812 mwindow->edl->session->sample_rate /
1813 mwindow->edl->local_session->zoom_sample -
1814 mwindow->edl->local_session->view_start[pane->number]);
1815 //printf("TrackCanvas::draw_drag_handle 2 %d %jd\n", pane->number, pixel1);
1816 set_color(!snapped ? GREEN : (snapped=0, YELLOW));
1818 //printf("TrackCanvas::draw_drag_handle 3\n");
1819 draw_line(pixel1, 0, pixel1, get_h());
1821 //printf("TrackCanvas::draw_drag_handle 4\n");
1826 void TrackCanvas::draw_transitions()
1830 // if(!mwindow->edl->session->show_assets) return;
1832 for(Track *track = mwindow->edl->tracks->first; track; track = track->next) {
1833 for(Edit *edit = track->edits->first; edit; edit = edit->next) {
1834 if(!edit->transition) continue;
1835 edit_dimensions(edit, x, y, w, h);
1836 int strip_x = x, strip_y = y;
1837 if(mwindow->edl->session->show_titles)
1838 strip_y += mwindow->theme->get_image("title_bg_data")->get_h();
1839 get_transition_coords(x, y, w, h);
1840 int strip_w = Units::round(edit->track->from_units(edit->transition->length) *
1841 mwindow->edl->session->sample_rate / mwindow->edl->local_session->zoom_sample);
1842 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
1843 MWindowGUI::visible(y, y + h, 0, get_h()) )
1845 PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1847 if( !server ) continue;
1848 VFrame *picon = server->get_picon();
1849 if( !picon ) continue;
1850 draw_vframe(picon, x, y, w, h, 0, 0, picon->get_w(), picon->get_h());
1852 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1853 MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1855 int x = strip_x, w = strip_w;
1861 if(w + x > get_w()) w -= (w + x) - get_w();
1863 draw_3segmenth( x, strip_y, w, strip_x, strip_w,
1864 mwindow->theme->get_image("plugin_bg_data"), 0);
1870 void TrackCanvas::draw_loop_points()
1872 //printf("TrackCanvas::draw_loop_points 1\n");
1873 if(mwindow->edl->local_session->loop_playback)
1875 //printf("TrackCanvas::draw_loop_points 2\n");
1876 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1877 mwindow->edl->session->sample_rate /
1878 mwindow->edl->local_session->zoom_sample -
1879 mwindow->edl->local_session->view_start[pane->number]);
1880 //printf("TrackCanvas::draw_loop_points 3\n");
1882 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1885 draw_line(x, 0, x, get_h());
1887 //printf("TrackCanvas::draw_loop_points 4\n");
1889 x = Units::round(mwindow->edl->local_session->loop_end *
1890 mwindow->edl->session->sample_rate /
1891 mwindow->edl->local_session->zoom_sample -
1892 mwindow->edl->local_session->view_start[pane->number]);
1893 //printf("TrackCanvas::draw_loop_points 5\n");
1895 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1898 draw_line(x, 0, x, get_h());
1900 //printf("TrackCanvas::draw_loop_points 6\n");
1902 //printf("TrackCanvas::draw_loop_points 7\n");
1905 void TrackCanvas::draw_brender_range()
1907 if( !mwindow->preferences->use_brender || !mwindow->brender_active ) return;
1908 if( mwindow->edl->session->brender_start >= mwindow->edl->session->brender_end ) return;
1909 if( mwindow->edl->session->brender_end > 0 )
1911 int64_t x1 = Units::round(mwindow->edl->session->brender_start *
1912 mwindow->edl->session->sample_rate /
1913 mwindow->edl->local_session->zoom_sample -
1914 mwindow->edl->local_session->view_start[pane->number]);
1915 if(MWindowGUI::visible(x1, x1 + 1, 0, get_w()))
1918 draw_line(x1, 0, x1, get_h());
1920 int64_t x2 = Units::round(mwindow->edl->session->brender_end *
1921 mwindow->edl->session->sample_rate /
1922 mwindow->edl->local_session->zoom_sample -
1923 mwindow->edl->local_session->view_start[pane->number]);
1925 if(MWindowGUI::visible(x2, x2 + 1, 0, get_w()))
1928 draw_line(x2, 0, x2, get_h());
1933 // The operations which correspond to each automation type
1934 int TrackCanvas::auto_operations[AUTOMATION_TOTAL] =
1950 // The buttonpress operations, so nothing changes unless the mouse moves
1951 // a certain amount. This allows the keyframe to be used to position the
1952 // insertion point without moving itself.
1953 static int pre_auto_operations[AUTOMATION_TOTAL] =
1970 int TrackCanvas::do_keyframes(int cursor_x,
1978 // Note: button 3 (right mouse button) is not eaten to allow
1979 // track context menu to appear
1981 EDLSession *session = mwindow->edl->session;
1985 static BC_Pixmap *auto_pixmaps[AUTOMATION_TOTAL] =
1987 0, 0, 0, 0, 0, 0, 0, 0,
1989 modekeyframe_pixmap,
1990 maskkeyframe_pixmap,
1995 for(Track *track = mwindow->edl->tracks->first;
1997 track = track->next) {
1998 Auto *auto_keyframe = 0;
1999 Automation *automation = track->automation;
2002 // Handle keyframes in reverse drawing order if a button press
2004 int end = AUTOMATION_TOTAL;
2008 start = AUTOMATION_TOTAL - 1;
2012 for(int i = start; i != end && !result; i += step)
2014 // Event not trapped and automation visible
2015 Autos *autos = automation->autos[i];
2016 if(!result && session->auto_conf->autos[i] && autos) {
2018 case AUTOMATION_MODE:
2019 case AUTOMATION_PAN:
2020 case AUTOMATION_MASK:
2021 result = do_autos(track, automation->autos[i],
2022 cursor_x, cursor_y, draw,
2023 buttonpress, auto_pixmaps[i],
2024 auto_keyframe, rerender);
2028 switch(autos->get_type()) {
2029 case Autos::AUTOMATION_TYPE_FLOAT: {
2030 Automation automation(0, track);
2031 int grouptype = automation.autogrouptype(i, track);
2032 if(draw) // Do dropshadow
2033 result = do_float_autos(track, autos,
2034 cursor_x, cursor_y, draw,
2035 buttonpress, 1, 1, MDGREY,
2036 auto_keyframe, grouptype);
2038 result = do_float_autos(track, autos,
2039 cursor_x, cursor_y, draw, buttonpress,
2040 0, 0, GWindowGUI::auto_colors[i],
2041 auto_keyframe, grouptype);
2044 case Autos::AUTOMATION_TYPE_INT: {
2045 if(draw) // Do dropshadow
2046 result = do_int_autos(track, autos,
2047 cursor_x, cursor_y, draw,
2048 buttonpress, 1, 1, MDGREY,
2050 result = do_int_autos(track, autos,
2051 cursor_x, cursor_y, draw, buttonpress,
2052 0, 0, GWindowGUI::auto_colors[i],
2061 if(mwindow->session->current_operation == auto_operations[i])
2064 // printf("TrackCanvas::do_keyframes %d %d %d\n",
2066 // mwindow->session->current_operation,
2067 // auto_operations[i]);
2070 if (buttonpress != 3)
2072 if(i == AUTOMATION_FADE || i == AUTOMATION_SPEED)
2073 synchronize_autos(0,
2075 (FloatAuto*)mwindow->session->drag_auto,
2077 mwindow->session->current_operation = pre_auto_operations[i];
2078 update_drag_caption();
2081 else if( auto_keyframe )
2083 gui->keyframe_menu->update(automation,
2086 gui->keyframe_menu->activate_menu();
2087 rerender = 1; // the position changes
2091 gui->keyframe_hide->update(autos);
2092 gui->keyframe_hide->activate_menu();
2093 rerender = 1; // the position changes
2095 if(buttonpress == 1 && ctrl_down() &&
2096 AUTOMATION_TYPE_FLOAT == autos->get_type())
2097 rerender = 1; // special case: curve mode changed
2104 session->auto_conf->plugins /* &&
2105 mwindow->edl->session->show_assets */) {
2108 result = do_plugin_autos(track, cursor_x, cursor_y,
2109 draw, buttonpress, plugin, keyframe);
2110 if(result && mwindow->session->current_operation == DRAG_PLUGINKEY) {
2113 if(result && (buttonpress == 1)) {
2114 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2115 update_drag_caption();
2118 else if (result && (buttonpress == 3)) {
2119 gui->keyframe_menu->update(plugin, keyframe);
2120 gui->keyframe_menu->activate_menu();
2121 rerender = 1; // the position changes
2126 // Final pass to trap event
2127 for(int i = 0; i < AUTOMATION_TOTAL; i++) {
2128 if(mwindow->session->current_operation == pre_auto_operations[i] ||
2129 mwindow->session->current_operation == auto_operations[i]) {
2135 if(mwindow->session->current_operation == DRAG_PLUGINKEY ||
2136 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE) {
2142 new_cursor = UPRIGHT_ARROW_CURSOR;
2149 void TrackCanvas::draw_keyframe_reticle()
2151 int keyframe_hairline = mwindow->preferences->keyframe_reticle;
2152 if( keyframe_hairline == HAIRLINE_NEVER ) return;
2154 int current_op = mwindow->session->current_operation, dragging = 0;
2155 for( int i=0; !dragging && i<AUTOMATION_TOTAL; ++i )
2156 if( current_op == auto_operations[i] ) dragging = 1;
2158 if( keyframe_hairline == HAIRLINE_DRAGGING && dragging ) {
2159 if( mwindow->session->drag_auto && get_buttonpress() == 1 ) {
2160 draw_hairline(mwindow->session->drag_auto, RED);
2165 if( keyframe_hairline == HAIRLINE_ALWAYS || ( get_buttonpress() == 2 &&
2166 keyframe_hairline == HAIRLINE_DRAGGING && dragging ) ) {
2167 for( Track *track = mwindow->edl->tracks->first; track;
2168 track=track->next ) {
2169 Automation *automation = track->automation;
2170 for( int i=0; i<AUTOMATION_TOTAL; ++i ) {
2171 if( !mwindow->edl->session->auto_conf->autos[i] ) continue;
2172 // automation visible
2173 Autos *autos = automation->autos[i];
2174 if( !autos ) continue;
2175 for( Auto *auto_keyframe=autos->first; auto_keyframe;
2176 auto_keyframe = auto_keyframe->next ) {
2177 draw_hairline(auto_keyframe, BLUE);
2181 if( dragging && mwindow->session->drag_auto ) {
2182 draw_hairline(mwindow->session->drag_auto, RED);
2188 void TrackCanvas::draw_auto(Auto *current,
2196 x1 = x - HANDLE_W / 2;
2197 x2 = x + HANDLE_W / 2;
2198 y1 = center_pixel + y - HANDLE_W / 2;
2199 y2 = center_pixel + y + HANDLE_W / 2;
2201 if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2202 if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2204 draw_box(x1, y1, x2 - x1, y2 - y1);
2208 // This draws lines for bezier in & out controls
2209 void TrackCanvas::draw_cropped_line(int x1,
2218 // Don't care about x since it is clipped by the window.
2219 // Put y coords in ascending order
2221 y2 ^= y1; y1 ^= y2; y2 ^= y1;
2222 x2 ^= x1; x1 ^= x2; x2 ^= x1;
2227 double slope = (double)(x2 - x1) / (y2 - y1);
2228 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2230 x1 = (int)(x1 + (min_y - y1) * slope);
2233 else if(y1 >= max_y) {
2234 x1 = (int)(x1 + (max_y - 1 - y1) * slope);
2239 x2 = (int)(x2 + (max_y - 1 - y2) * slope);
2242 else if(y2 < min_y) {
2243 x2 = (int)(x2 + (min_y - y2) * slope);
2248 //printf("TrackCanvas::draw_cropped_line %d %d %d %d %d\n", __LINE__, x1, y1, x2, y2);
2249 if( y1 >= min_y && y1 < max_y &&
2250 y2 >= min_y && y2 < max_y )
2251 draw_line(x1, y1, x2, y2);
2255 void TrackCanvas::draw_floatauto(FloatAuto *current,
2266 int x1 = x - HANDLE_W / 2; // Center
2267 int x2 = x + HANDLE_W / 2;
2268 int y1 = center_pixel + y - HANDLE_H / 2;
2269 int y2 = center_pixel + y + HANDLE_H / 2;
2270 int ymin = center_pixel - zoom_track / 2;
2271 int ymax = center_pixel + zoom_track / 2;
2272 CLAMP(y1, ymin, ymax);
2273 CLAMP(y2, ymin, ymax);
2278 draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2280 draw_box(x1, y1, x2 - x1, y2 - y1);
2283 // show bezier control points (only) if this
2284 // floatauto doesn't adjust it's tangents automatically
2285 if(current->curve_mode != FloatAuto::FREE &&
2286 current->curve_mode != FloatAuto::TFREE)
2290 draw_floatauto_ctrlpoint(x, y, in_x, in_y, center_pixel, zoom_track, color);
2292 draw_floatauto_ctrlpoint(x, y, out_x, out_y, center_pixel, zoom_track, color);
2295 inline int quantize(float f) { return (int)floor(f + 0.5); }
2297 inline void TrackCanvas::draw_floatauto_ctrlpoint(
2298 int x, int y, int cp_x, int cp_y, int center_pixel,
2299 int zoom_track, int color)
2300 // draw the tangent and a handle for given bézier ctrl point
2302 bool handle_visible = (abs(cp_y) <= zoom_track / 2);
2304 float slope = (float)(cp_y - y)/(cp_x - x);
2305 CLAMP(cp_y, -zoom_track / 2, zoom_track / 2);
2307 cp_x = x + quantize((cp_y - y) / slope);
2310 cp_y += center_pixel;
2312 // drawing the tangent as a dashed line...
2313 int const dash = HANDLE_W;
2314 int const gap = HANDLE_W / 2;
2315 float sx = 3 * (cp_x - x) / 4.;
2318 // q is the x displacement for a unit line of slope
2319 float q = (sx > 0 ? 1 : -1) / sqrt(1 + slope * slope);
2321 float dist = 1/q * sx;
2327 float sy = slope * sx, ey = slope * ex;
2328 draw_line(quantize(sx + x), quantize(sy + y), quantize(ex + x), quantize(ey + y));
2335 int r = HANDLE_W / 2;
2336 int cp_x1 = cp_x - r;
2337 int cp_y1 = cp_y - r;
2339 draw_disc(cp_x1, cp_y1, 2 * r, 2 * r);
2341 draw_circle(cp_x1, cp_y1, 2 * r, 2 * r);
2346 int TrackCanvas::test_auto(Auto *current,
2347 int x, int y, int center_pixel, int zoom_track,
2348 int cursor_x, int cursor_y, int buttonpress)
2353 x1 = x - HANDLE_W / 2;
2354 x2 = x + HANDLE_W / 2;
2355 y1 = center_pixel + y - HANDLE_H / 2;
2356 y2 = center_pixel + y + HANDLE_H / 2;
2357 int ymin = center_pixel - zoom_track / 2;
2358 int ymax = center_pixel + zoom_track / 2;
2359 CLAMP(y1, ymin, ymax);
2360 CLAMP(y2, ymin, ymax);
2362 if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2364 if(buttonpress && buttonpress != 3)
2366 mwindow->session->drag_auto = current;
2367 mwindow->session->drag_start_percentage = (float)((IntAuto*)current)->value;
2368 // Toggle Autos don't respond to vertical zoom, they always show up
2369 // with "on" == 100% == line on top
2370 mwindow->session->drag_start_position = current->position;
2371 mwindow->session->drag_origin_x = cursor_x;
2372 mwindow->session->drag_origin_y = cursor_y;
2377 if(buttonpress && buttonpress != 3 && result)
2379 //printf("TrackCanvas::test_auto %d\n", __LINE__);
2380 mwindow->undo->update_undo_before();
2386 // some Helpers for test_floatauto(..)
2387 // and for dragging the tangents/ctrl points
2388 inline float test_curve_line( int x0, int y0, int ctrl_x, int ctrl_y,
2389 float cursor_x, float cursor_y)
2391 // Control point switched off?
2392 if( x0 == ctrl_x ) return 0.0;
2393 double x1 = ctrl_x-x0, y1 = ctrl_y-y0;
2394 double x = cursor_x-x0, y = cursor_y-y0;
2395 // wrong side of ctrl handle
2396 if( x*x1 < 0 ) return 0.0;
2397 // outside handle radius
2398 if( (x*x + y*y) > (x1*x1 + y1*y1) ) return 0;
2399 double xx1 = x1*x1, yy1 = y1*y1;
2400 double xx = x*x, yy = y*y;
2401 // distance squared from cursor to cursor projected to line from ctrl to handle
2402 // along a line perpendicular to line from ctrl to handle (closest approach)
2403 // (x**2*y1**2 - 2*x*x1*y*y1 + x1**2*y**2)/(x1**2 + y1**2)
2404 double dist2 = (xx*yy1 - 2*x*x1*y*y1 + xx1*yy)/(xx1 + yy1);
2405 return dist2 < (HANDLE_W*HANDLE_W)/4. ? x/x1 : 0.;
2410 float levered_position(float position, float ref_pos)
2412 if( 1e-6 > fabs(ref_pos) || isnan(ref_pos))
2414 return ref_pos / position;
2418 float TrackCanvas::value_to_percentage(float auto_value, int autogrouptype)
2419 // transforms automation value into current display coords,
2420 // dependant on current automation display range for the given kind of automation
2422 if(!mwindow || !mwindow->edl) return 0;
2423 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2424 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2425 float automation_range = automation_max - automation_min;
2426 if( 0 >= automation_range || isnan(auto_value) || isinf(auto_value) )
2428 return (auto_value - automation_min) / automation_range;
2433 int TrackCanvas::test_floatauto(FloatAuto *current, int x, int y, int in_x,
2434 int in_y, int out_x, int out_y, int center_pixel, int zoom_track,
2435 int cursor_x, int cursor_y, int buttonpress, int autogrouptype)
2439 int x1 = x - HANDLE_W / 2;
2440 int x2 = x + HANDLE_W / 2;
2441 int y1 = center_pixel + y - HANDLE_W / 2;
2442 int y2 = center_pixel + y + HANDLE_W / 2;
2443 int ymin = center_pixel - zoom_track / 2;
2444 int ymax = center_pixel + zoom_track / 2;
2445 CLAMP(y1, ymin, ymax);
2446 CLAMP(y2, ymin, ymax);
2448 int in_x1 = in_x - HANDLE_W / 2;
2449 int in_x2 = in_x + HANDLE_W / 2;
2450 int in_y1 = center_pixel + in_y - HANDLE_W / 2;
2451 int in_y2 = center_pixel + in_y + HANDLE_W / 2;
2452 CLAMP(in_y1, ymin, ymax);
2453 CLAMP(in_y2, ymin, ymax);
2455 int out_x1 = out_x - HANDLE_W / 2;
2456 int out_x2 = out_x + HANDLE_W / 2;
2457 int out_y1 = center_pixel + out_y - HANDLE_W / 2;
2458 int out_y2 = center_pixel + out_y + HANDLE_W / 2;
2459 CLAMP(out_y1, ymin, ymax);
2460 CLAMP(out_y2, ymin, ymax);
2463 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2464 // buttonpress could be the start of a drag operation
2465 #define INIT_DRAG(POS,VAL) \
2466 mwindow->session->drag_auto = current; \
2467 mwindow->session->drag_origin_x = cursor_x; \
2468 mwindow->session->drag_origin_y = cursor_y; \
2469 mwindow->session->drag_start_position = (POS); \
2470 mwindow->session->drag_start_percentage = (VAL);
2472 #define WITHIN(X1,X2,Y1,Y2) (cursor_x >=(X1) && cursor_x <(X2) && cursor_y >=(Y1) && cursor_y <(Y2) )
2475 // without modifier we are manipulating the automation node
2476 // with ALT it's about dragging only the value of the node
2477 // with SHIFT the value snaps to the value of neighbouring nodes
2478 // CTRL indicates we are rather manipulating the tangent(s) of the node
2482 if( WITHIN(x1,x2,y1,y2))
2483 { // cursor hits node
2486 if(buttonpress && (buttonpress != 3))
2488 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2489 mwindow->session->drag_handle = 0;
2494 if( WITHIN(x1,x2,y1,y2))
2497 if(buttonpress && (buttonpress != 3))
2499 // could be ctrl-click or ctrl-drag
2500 // click would cycle through tangent modes
2501 ((FloatAuto*)current)->toggle_curve_mode();
2503 // drag will start dragging the tangent, if applicable
2504 INIT_DRAG(current->position, value_to_percentage(current->get_value(), autogrouptype))
2505 mwindow->session->drag_handle = 0;
2509 float lever = 0.0; // we use the tangent as a draggable lever. 1.0 is at the ctrl point
2512 if( in_x != x && current->position > 0 &&
2513 (FloatAuto::FREE == current->curve_mode ||
2514 FloatAuto::TFREE == current->curve_mode))
2515 // act on in control handle only if
2516 // tangent is significant and is editable (not automatically choosen)
2518 lever = test_curve_line(x, y, in_x, in_y, cursor_x, cursor_y-center_pixel);
2519 // either cursor in ctrl-point handle or cursor on tangent line
2520 if( WITHIN(in_x1,in_x2,in_y1,in_y2) || lever > 0.0 ) {
2522 if(buttonpress && (buttonpress != 3)) {
2523 if(lever == 0.0) lever=1.0; // we entered by dragging the handle...
2525 mwindow->session->drag_handle = 1;
2526 float new_invalue = current->get_value() + lever * current->get_control_in_value();
2527 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_in_position()),
2528 value_to_percentage(new_invalue, autogrouptype))
2535 (FloatAuto::FREE == current->curve_mode ||
2536 FloatAuto::TFREE == current->curve_mode))
2537 // act on out control only if tangent is significant and is editable
2539 lever = test_curve_line(x, y, out_x, out_y, cursor_x, cursor_y-center_pixel);
2540 if(WITHIN(out_x1,out_x2,out_y1,out_y2) || lever > 0.0 ) {
2542 if(buttonpress && (buttonpress != 3)) {
2543 if(lever == 0.0) lever=1.0;
2545 mwindow->session->drag_handle = 2;
2546 float new_outvalue = current->get_value() + lever * current->get_control_out_value();
2547 INIT_DRAG(current->position + (int64_t)(lever * current->get_control_out_position()),
2548 value_to_percentage(new_outvalue, autogrouptype))
2552 } // end ctrl_down()
2558 // 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",
2559 // mwindow->session->drag_handle,
2564 if(buttonpress && (buttonpress != 3) && result)
2566 mwindow->undo->update_undo_before();
2573 // Get the float value & y for position x on the canvas
2574 #define X_TO_FLOATLINE(x) \
2575 int64_t position1 = (int64_t)(unit_start + x * zoom_units); \
2576 int64_t position2 = (int64_t)(unit_start + x * zoom_units) + 1; \
2577 /* Call by reference fails for some reason here */ \
2578 float value1 = autos->get_value(position1, PLAY_FORWARD, previous1, next1); \
2579 float value2 = autos->get_value(position2, PLAY_FORWARD, previous1, next1); \
2580 double position = unit_start + x * zoom_units; \
2582 if(position2 > position1) \
2585 (value2 - value1) * \
2586 (position - position1) / \
2587 (position2 - position1); \
2593 AUTOMATIONCLAMPS(value, autogrouptype); \
2594 int y = center_pixel + \
2595 (int)(((value - automation_min) / automation_range - 0.5) * -yscale);
2598 void TrackCanvas::draw_floatline(int center_pixel,
2599 FloatAuto *previous, FloatAuto *next, FloatAutos *autos,
2600 double unit_start, double zoom_units, double yscale,
2601 int x1, int y1, int x2, int y2,
2602 int color, int autogrouptype)
2604 // Solve bezier equation for either every pixel or a certain large number of
2607 // Not using slope intercept
2609 int prev_y = y1 + center_pixel;
2612 // Call by reference fails for some reason here
2613 FloatAuto *previous1 = previous, *next1 = next;
2614 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2615 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2616 float automation_range = automation_max - automation_min;
2618 for(int x = x1; x < x2; x++)
2620 // Interpolate value between frames
2624 y >= center_pixel - yscale / 2 &&
2625 y < center_pixel + yscale / 2 - 1)
2627 // printf("TrackCanvas::draw_floatline y=%d min=%d max=%d\n",
2629 // (int)(center_pixel - yscale / 2),
2630 // (int)(center_pixel + yscale / 2 - 1));
2632 //printf("draw_line(%d,%d, %d,%d)\n", x - 1, prev_y , x, y);
2633 draw_line(x - 1, prev_y , x, y );
2643 int TrackCanvas::test_floatline(int center_pixel,
2658 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2659 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2660 float automation_range = automation_max - automation_min;
2661 FloatAuto *previous1 = 0, *next1 = 0;
2662 X_TO_FLOATLINE(cursor_x);
2664 if(cursor_x >= x1 &&
2666 cursor_y >= y - HANDLE_W / 2 &&
2667 cursor_y < y + HANDLE_W / 2 &&
2673 if(buttonpress == 3)
2681 mwindow->undo->update_undo_before();
2682 double position = autos->track->from_units(position1);
2683 position = mwindow->edl->align_to_frame(position, 0);
2684 int64_t new_position = autos->track->to_units(position,0);
2685 current = mwindow->session->drag_auto = autos->insert_auto(new_position);
2686 ((FloatAuto*)current)->set_value(value);
2687 mwindow->session->drag_start_percentage = value_to_percentage(value, autogrouptype);
2688 mwindow->session->drag_start_position = current->position;
2689 mwindow->session->drag_origin_x = cursor_x;
2690 mwindow->session->drag_origin_y = cursor_y;
2691 mwindow->session->drag_handle = 0;
2700 void TrackCanvas::synchronize_autos(float change,
2701 Track *skip, FloatAuto *fauto, int fill_gangs)
2703 // Handles the special case of modifying a fadeauto
2704 // when there are ganged faders on several tracks
2705 // (skip and fauto may be NULL if fill_gangs==-1)
2707 if( fill_gangs > 0 && skip->gang ) {
2708 double position = skip->from_units(fauto->position);
2709 int autoidx = fauto->autos->autoidx;
2711 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT) {
2712 if( (current->data_type == skip->data_type || get_double_click()) &&
2713 current->gang && current->record && current != skip ) {
2714 int64_t current_position = current->to_units(position, 1);
2715 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[autoidx];
2716 float auto_min = mwindow->edl->local_session->automation_mins[fade_autos->autogrouptype];
2717 float auto_max = mwindow->edl->local_session->automation_maxs[fade_autos->autogrouptype];
2718 FloatAuto *previous = 0, *next = 0;
2719 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_at_position(current_position);
2721 // create keyframe on neighbouring track at the point in time given by fauto
2722 float init_value = fade_autos->get_value(current_position, PLAY_FORWARD, previous, next);
2723 float new_value = init_value + change;
2724 CLAMP(new_value, auto_min, auto_max);
2725 keyframe = (FloatAuto*)fade_autos->insert_auto(current_position);
2726 keyframe->set_value(new_value);
2729 // keyframe exists, just change it
2730 float new_value = keyframe->get_value() + change;
2731 CLAMP(new_value, auto_min, auto_max);
2732 keyframe->adjust_to_new_coordinates(current_position, new_value);
2733 // need to (re)set the position, as the existing node could be on a "equivalent" position (within half a frame)
2736 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2740 else if( !fill_gangs ) {
2741 double position = skip->from_units(fauto->position);
2743 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2744 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2745 int64_t keyframe_position = keyframe->autos->track->to_units(position, 1);
2746 float new_value = keyframe->get_value() + change;
2748 mwindow->edl->local_session->automation_mins[keyframe->autos->autogrouptype],
2749 mwindow->edl->local_session->automation_maxs[keyframe->autos->autogrouptype]);
2750 keyframe->adjust_to_new_coordinates(keyframe_position, new_value);
2756 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++) {
2757 FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2758 keyframe->autos->remove_nonsequential(
2761 mwindow->session->drag_auto_gang->remove_all();
2766 void TrackCanvas::draw_toggleline(int center_pixel,
2772 draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2776 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2780 int TrackCanvas::test_toggleline(Autos *autos,
2791 if(cursor_x >= x1 && cursor_x < x2)
2793 int miny = center_pixel + y1 - HANDLE_W / 2;
2794 int maxy = center_pixel + y1 + HANDLE_W / 2;
2795 if(cursor_y >= miny && cursor_y < maxy)
2800 if(buttonpress == 3)
2808 double position = (double)(cursor_x +
2809 mwindow->edl->local_session->view_start[pane->number]) *
2810 mwindow->edl->local_session->zoom_sample /
2811 mwindow->edl->session->sample_rate;
2812 int64_t unit_position = autos->track->to_units(position, 0);
2813 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2815 mwindow->undo->update_undo_before();
2817 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2818 ((IntAuto*)current)->value = new_value;
2819 // Toggle Autos don't respond to vertical zoom, they always show up
2820 // with "on" == 100% == line on top
2821 mwindow->session->drag_start_percentage = (float)new_value;
2822 mwindow->session->drag_start_position = current->position;
2823 mwindow->session->drag_origin_x = cursor_x;
2824 mwindow->session->drag_origin_y = cursor_y;
2832 void TrackCanvas::calculate_viewport(Track *track,
2833 double &view_start, // Seconds
2835 double &view_end, // Seconds
2839 double &zoom_sample,
2842 view_start = (double)mwindow->edl->local_session->view_start[pane->number] *
2843 mwindow->edl->local_session->zoom_sample /
2844 mwindow->edl->session->sample_rate;
2845 unit_start = track->to_doubleunits(view_start);
2846 view_end = (double)(mwindow->edl->local_session->view_start[pane->number] +
2848 mwindow->edl->local_session->zoom_sample /
2849 mwindow->edl->session->sample_rate;
2850 unit_end = track->to_doubleunits(view_end);
2851 yscale = mwindow->edl->local_session->zoom_track;
2852 //printf("TrackCanvas::calculate_viewport yscale=%.0f\n", yscale);
2853 center_pixel = (int)(track->y_pixel -
2854 mwindow->edl->local_session->track_start[pane->number] +
2856 (mwindow->edl->session->show_titles ?
2857 mwindow->theme->get_image("title_bg_data")->get_h() :
2859 zoom_sample = mwindow->edl->local_session->zoom_sample;
2861 zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2864 float TrackCanvas::percentage_to_value(float percentage,
2872 if(percentage > 0.5)
2879 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2880 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2881 float automation_range = automation_max - automation_min;
2883 result = percentage * automation_range + automation_min;
2886 FloatAuto *ptr = (FloatAuto*)reference;
2887 result -= ptr->get_value();
2889 //printf("TrackCanvas::percentage_to_value %d %f\n", __LINE__, result);
2895 void TrackCanvas::calculate_auto_position(double *x, double *y,
2896 double *in_x, double *in_y, double *out_x, double *out_y,
2897 Auto *current, double unit_start, double zoom_units, double yscale,
2900 float automation_min = mwindow->edl->local_session->automation_mins[autogrouptype];
2901 float automation_max = mwindow->edl->local_session->automation_maxs[autogrouptype];
2902 float automation_range = automation_max - automation_min;
2903 FloatAuto *ptr = (FloatAuto*)current;
2904 *x = (double)(ptr->position - unit_start) / zoom_units;
2905 *y = ((ptr->get_value() - automation_min) / automation_range - 0.5) * -yscale;
2908 // *in_x = EQUIV(ptr->control_in_value, 0.0) ? *x : *x - mwindow->theme->control_pixels;
2909 *in_x = (double)(ptr->position + ptr->get_control_in_position() - unit_start) / zoom_units;
2913 *in_y = (((ptr->get_value() + ptr->get_control_in_value()) -
2914 automation_min) / automation_range - 0.5) * -yscale;
2918 // *out_x = EQUIV(ptr->control_out_value, 0.0) ? *x : *x + mwindow->theme->control_pixels;
2919 *out_x = (double)(ptr->position + ptr->get_control_out_position() - unit_start) / zoom_units;
2923 *out_y = (((ptr->get_value() + ptr->get_control_out_value()) -
2924 automation_min) / automation_range - 0.5) * -yscale;
2929 int TrackCanvas::do_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y,
2930 int draw, int buttonpress, int x_offset, int y_offset, int color,
2931 Auto* &auto_instance, int autogrouptype)
2934 int center_pixel, draw_auto;
2935 double view_start, unit_start;
2936 double view_end, unit_end, yscale;
2937 double zoom_sample, zoom_units;
2938 double in_x2, in_y2, out_x2, out_y2;
2944 if(draw) set_color(color);
2946 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
2947 yscale, center_pixel, zoom_sample, zoom_units);
2949 // Get first auto before start
2950 Auto *current = 0, *previous = 0;
2952 for( current = autos->last;
2953 current && current->position >= unit_start;
2954 current = PREVIOUS ) ;
2956 Auto *first_auto = current ? current :
2957 autos->first ? autos->first : autos->default_auto;
2959 double ax = 0, ay = 0, ax2 = 0, ay2 = 0;
2961 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
2962 first_auto, unit_start, zoom_units, yscale, autogrouptype);
2967 current = autos->first;
2976 calculate_auto_position(&ax2, &ay2, &in_x2, &in_y2, &out_x2, &out_y2,
2977 current, unit_start, zoom_units, yscale, autogrouptype);
2985 slope = ax2 > ax ? (ay2 - ay) / (ax2 - ax) : 0;
2990 ay2 = ay + slope * (get_w() - ax);
2994 ay = ay + slope * (0 - ax);
2998 // Draw or test handle
2999 if( current && !result && current != autos->default_auto ) {
3000 if( !draw && track->record ) {
3001 result = test_floatauto((FloatAuto*)current, (int)ax2, (int)ay2,
3002 (int)in_x2, (int)in_y2, (int)out_x2, (int)out_y2,
3003 (int)center_pixel, (int)yscale, cursor_x, cursor_y,
3004 buttonpress, autogrouptype);
3006 auto_instance = current;
3008 if( draw && draw_auto ) {
3009 draw_floatauto((FloatAuto*)current, (int)ax2 + x_offset, (int)ay2,
3010 (int)in_x2 + x_offset, (int)in_y2,
3011 (int)out_x2 + x_offset, (int)out_y2,
3012 (int)center_pixel + y_offset, (int)yscale, color);
3016 // Draw or test joining line
3017 if( !draw && !result && track->record /* && buttonpress != 3 */ ) {
3018 result = test_floatline(center_pixel,
3019 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3020 // Exclude auto coverage from the end of the line. The auto overlaps
3021 (int)ax, (int)ax2 - HANDLE_W / 2, cursor_x, cursor_y,
3022 buttonpress, autogrouptype);
3025 draw_floatline(center_pixel, (FloatAuto*)previous, (FloatAuto*)current,
3026 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3027 (int)ax, (int)ay, (int)ax2, (int)ay2,
3028 color, autogrouptype);
3036 } while( current && current->position <= unit_end && !result );
3038 if( ax < get_w() && !result ) {
3039 ax2 = get_w(); ay2 = ay;
3040 if(!draw && track->record /* && buttonpress != 3 */ ) {
3041 result = test_floatline(center_pixel,
3042 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3043 (int)ax, (int)ax2, cursor_x, cursor_y,
3044 buttonpress, autogrouptype);
3047 draw_floatline(center_pixel,
3048 (FloatAuto*)previous, (FloatAuto*)current,
3049 (FloatAutos*)autos, unit_start, zoom_units, yscale,
3050 (int)ax, (int)ay, (int)ax2, (int)ay2,
3051 color, autogrouptype);
3058 int TrackCanvas::do_int_autos(Track *track,
3067 Auto *&auto_instance)
3078 double ax, ay, ax2, ay2;
3082 if(draw) set_color(color);
3084 calculate_viewport(track,
3095 double high = -yscale * 0.8 / 2;
3096 double low = yscale * 0.8 / 2;
3098 // Get first auto before start
3100 for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
3106 ay = ((IntAuto*)current)->value > 0 ? high : low;
3111 current = autos->first ? autos->first : autos->default_auto;
3115 ay = ((IntAuto*)current)->value > 0 ? high : low;
3128 ax2 = (double)(current->position - unit_start) / zoom_units;
3129 ay2 = ((IntAuto*)current)->value > 0 ? high : low;
3137 if(ax2 > get_w()) ax2 = get_w();
3139 if(current && !result)
3141 if(current != autos->default_auto)
3147 result = test_auto(current,
3156 auto_instance = current;
3161 (int)ax2 + x_offset,
3162 (int)ay2 + y_offset,
3174 if(track->record /* && buttonpress != 3 */)
3176 result = test_toggleline(autos,
3189 draw_toggleline(center_pixel + y_offset,
3197 }while(current && current->position <= unit_end && !result);
3199 if(ax < get_w() && !result)
3205 if(track->record /* && buttonpress != 3 */)
3207 result = test_toggleline(autos,
3219 draw_toggleline(center_pixel + y_offset,
3228 int TrackCanvas::do_autos(Track *track,
3235 Auto * &auto_instance,
3249 calculate_viewport(track,
3262 for(current = autos->first; current && !result; current = NEXT)
3264 if(current->position >= unit_start && current->position < unit_end)
3267 x = (int64_t)((double)(current->position - unit_start) /
3268 zoom_units - (pixmap->get_w() / 2.0 + 0.5));
3269 y = center_pixel - pixmap->get_h() / 2;
3273 if(cursor_x >= x && cursor_y >= y &&
3274 cursor_x < x + pixmap->get_w() &&
3275 cursor_y < y + pixmap->get_h())
3278 auto_instance = current;
3280 if(buttonpress && (buttonpress != 3))
3282 mwindow->session->drag_auto = current;
3283 mwindow->session->drag_start_position = current->position;
3284 mwindow->session->drag_origin_x = cursor_x;
3285 mwindow->session->drag_origin_y = cursor_y;
3287 double position = autos->track->from_units(current->position);
3288 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3289 mwindow->edl->local_session->get_selectionend(1)) /
3294 mwindow->edl->local_session->set_selectionstart(position);
3295 mwindow->edl->local_session->set_selectionend(position);
3298 if(position < center)
3300 mwindow->edl->local_session->set_selectionstart(position);
3303 mwindow->edl->local_session->set_selectionend(position);
3310 draw_pixmap(pixmap, x, y);
3318 // so this means it is always >0 when keyframe is found
3319 int TrackCanvas::do_plugin_autos(Track *track, int cursor_x, int cursor_y,
3320 int draw, int buttonpress, Plugin* &keyframe_plugin,
3321 KeyFrame* &keyframe_instance)
3334 if(!track->expand_view) return 0;
3336 calculate_viewport(track,
3348 for(int i = 0; i < track->plugin_set.total && !result; i++)
3350 PluginSet *plugin_set = track->plugin_set.values[i];
3351 int center_pixel = (int)(track->y_pixel -
3352 mwindow->edl->local_session->track_start[pane->number] +
3353 mwindow->edl->local_session->zoom_track +
3354 (i + 0.5) * mwindow->theme->get_image("plugin_bg_data")->get_h() +
3355 (mwindow->edl->session->show_titles ? mwindow->theme->get_image("title_bg_data")->get_h() : 0));
3357 for(Plugin *plugin = (Plugin*)plugin_set->first;
3359 plugin = (Plugin*)plugin->next)
3361 for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first;
3362 keyframe && !result;
3363 keyframe = (KeyFrame*)keyframe->next)
3365 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3366 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3368 int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3369 int y = center_pixel - keyframe_pixmap->get_h() / 2;
3371 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3374 if(cursor_x >= x && cursor_y >= y &&
3375 cursor_x < x + keyframe_pixmap->get_w() &&
3376 cursor_y < y + keyframe_pixmap->get_h())
3379 keyframe_plugin = plugin;
3380 keyframe_instance = keyframe;
3384 mwindow->session->drag_auto = keyframe;
3385 mwindow->session->drag_start_position = keyframe->position;
3386 mwindow->session->drag_origin_x = cursor_x;
3387 mwindow->session->drag_origin_y = cursor_y;
3389 double position = track->from_units(keyframe->position);
3390 double center = (mwindow->edl->local_session->get_selectionstart(1) +
3391 mwindow->edl->local_session->get_selectionend(1)) /
3396 mwindow->edl->local_session->set_selectionstart(position);
3397 mwindow->edl->local_session->set_selectionend(position);
3400 if(position < center)
3402 mwindow->edl->local_session->set_selectionstart(position);
3405 mwindow->edl->local_session->set_selectionend(position);
3410 draw_pixmap(keyframe_pixmap,
3420 // if(buttonpress && buttonpress != 3 && result)
3422 // mwindow->undo->update_undo_before();
3428 int TrackCanvas::draw_hairline(Auto *auto_keyframe, int color)
3430 Track *track = auto_keyframe->autos->track;
3431 int autogrouptype = auto_keyframe->autos->get_type();
3434 double view_start, unit_start;
3435 double view_end, unit_end, yscale;
3436 double zoom_sample, zoom_units;
3438 calculate_viewport(track, view_start, unit_start, view_end, unit_end,
3439 yscale, center_pixel, zoom_sample, zoom_units);
3441 double ax = 0, ay = 0;
3442 calculate_auto_position(&ax, &ay, 0, 0, 0, 0,
3443 auto_keyframe, unit_start, zoom_units, yscale, autogrouptype);
3446 draw_line(ax, 0, ax, get_h());
3450 void TrackCanvas::draw_overlays()
3452 int new_cursor, update_cursor, rerender;
3454 // Move background pixmap to foreground pixmap
3455 draw_pixmap(background_pixmap,
3464 draw_inout_points();
3467 if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3475 draw_brender_range();
3477 // Highlighted areas
3478 draw_highlighting();
3481 do_keyframes(0, 0, 1, 0, new_cursor, update_cursor, rerender);
3484 if(pane->cursor) pane->cursor->restore(1);
3490 draw_playback_cursor();
3492 draw_keyframe_reticle();
3497 int TrackCanvas::activate()
3501 //printf("TrackCanvas::activate %d %d\n", __LINE__, pane->number);
3502 //BC_Signals::dump_stack();
3503 get_top_level()->deactivate();
3505 set_active_subwindow(this);
3506 pane->cursor->activate();
3507 gui->focused_pane = pane->number;
3512 int TrackCanvas::deactivate()
3517 pane->cursor->deactivate();
3523 void TrackCanvas::update_drag_handle()
3525 double new_position;
3526 int cursor_x = get_cursor_x();
3530 mwindow->edl->local_session->view_start[pane->number]) *
3531 mwindow->edl->local_session->zoom_sample /
3532 mwindow->edl->session->sample_rate;
3535 mwindow->edl->align_to_frame(new_position, 0);
3537 if( ctrl_down() && alt_down() ) {
3538 #define snapper(v) do { \
3540 if( pos < 0 ) break; \
3541 double dist = fabs(new_position - pos); \
3542 if( dist >= snap_min ) break; \
3543 snap_position = pos; snap_min = dist; \
3545 double snap_position = new_position;
3546 double snap_min = DBL_MAX;
3547 if( mwindow->edl->local_session->inpoint_valid() )
3548 snapper(mwindow->edl->local_session->get_inpoint());
3549 if( mwindow->edl->local_session->outpoint_valid() )
3550 snapper(mwindow->edl->local_session->get_outpoint());
3551 snapper(mwindow->edl->prev_edit(new_position));
3552 snapper(mwindow->edl->next_edit(new_position));
3553 Label *prev_label = mwindow->edl->labels->prev_label(new_position);
3554 if( prev_label ) snapper(prev_label->position);
3555 Label *next_label = mwindow->edl->labels->next_label(new_position);
3556 if( next_label ) snapper(next_label->position);
3557 int snap_x = snap_position * mwindow->edl->session->sample_rate /
3558 mwindow->edl->local_session->zoom_sample -
3559 mwindow->edl->local_session->view_start[pane->number];
3560 if( abs(snap_x - cursor_x) < HANDLE_W ) {
3562 new_position = snap_position;
3567 if(new_position != mwindow->session->drag_position)
3569 mwindow->session->drag_position = new_position;
3570 gui->mainclock->update(new_position);
3573 timebar_position = new_position;
3574 gui->update_timebar(0);
3575 // Que the CWindow. Doesn't do anything if selectionstart and selection end
3577 // mwindow->cwindow->update(1, 0, 0);
3581 int TrackCanvas::update_drag_edit()
3590 int TrackCanvas::get_drag_values(float *percentage,
3597 //int x = cursor_x - mwindow->session->drag_origin_x;
3598 //int y = cursor_y - mwindow->session->drag_origin_y;
3602 if(!current->autos->track->record) return 1;
3612 calculate_viewport(current->autos->track,
3622 *percentage = (float)(mwindow->session->drag_origin_y - cursor_y) /
3624 mwindow->session->drag_start_percentage;
3625 if(do_clamp) CLAMP(*percentage, 0, 1);
3627 *position = Units::to_int64(zoom_units *
3628 (cursor_x - mwindow->session->drag_origin_x) +
3629 mwindow->session->drag_start_position + 0.5);
3631 if((do_clamp) && *position < 0) *position = 0;
3636 #define UPDATE_DRAG_HEAD(do_clamp) \
3637 int result = 0, center_pixel; \
3638 if(!current->autos->track->record) return 0; \
3639 double view_start, unit_start, view_end, unit_end; \
3640 double yscale, zoom_sample, zoom_units; \
3642 calculate_viewport(current->autos->track, \
3643 view_start, unit_start, view_end, unit_end, \
3644 yscale, center_pixel, zoom_sample, zoom_units); \
3646 float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3647 yscale + mwindow->session->drag_start_percentage; \
3648 if(do_clamp) CLAMP(percentage, 0, 1); \
3650 int64_t position = Units::to_int64(zoom_units * \
3651 (cursor_x - mwindow->session->drag_origin_x) + \
3652 mwindow->session->drag_start_position); \
3653 if((do_clamp) && position < 0) position = 0;
3656 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3658 FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3660 UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3661 int x = cursor_x - mwindow->session->drag_origin_x;
3662 int y = cursor_y - mwindow->session->drag_origin_y;
3663 float value, old_value;
3665 if( mwindow->session->drag_handle == 0 && (ctrl_down() && !shift_down()) ) {
3666 // not really editing the node, rather start editing the curve
3667 // tangent is editable and drag movement is significant
3668 if( (FloatAuto::FREE == current->curve_mode ||
3669 FloatAuto::TFREE==current->curve_mode) &&
3670 (fabs(x) > HANDLE_W / 2 || fabs(y) > HANDLE_W / 2))
3671 mwindow->session->drag_handle = x < 0 ? 1 : 2;
3674 switch(mwindow->session->drag_handle) {
3676 // Snap to nearby values
3677 old_value = current->get_value();
3679 double value1, value2, distance1, distance2;
3681 if(current->previous) {
3682 int autogrouptype = current->previous->autos->autogrouptype;
3683 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3684 value1 = ((FloatAuto*)current->previous)->get_value();
3685 distance1 = fabs(value - value1);
3686 current->set_value(value1);
3690 int autogrouptype = current->next->autos->autogrouptype;
3691 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3692 value2 = ((FloatAuto*)current->next)->get_value();
3693 distance2 = fabs(value - value2);
3694 if(!current->previous || distance2 < distance1) {
3695 current->set_value(value2);
3699 if(!current->previous && !current->next) {
3700 current->set_value( ((FloatAutos*)current->autos)->default_);
3702 value = current->get_value();
3705 int autogrouptype = current->autos->autogrouptype;
3706 value = percentage_to_value(percentage, 0, 0, autogrouptype);
3709 if(alt_down() && !shift_down())
3710 // ALT constrains movement: fixed position, only changing the value
3711 position = mwindow->session->drag_start_position;
3713 if(value != old_value || position != current->position) {
3715 float change = value - old_value;
3716 current->adjust_to_new_coordinates(position, value);
3717 synchronize_autos(change, current->autos->track, current, 0);
3718 show_message(current, 1,", %.2f", current->get_value());
3724 int autogrouptype = current->autos->autogrouptype;
3725 value = percentage_to_value(percentage, 0, current, autogrouptype);
3726 if(value != current->get_control_in_value())
3729 // note: (position,value) need not be at the location of the ctrl point,
3730 // but could be somewhere in between on the curve (or even outward or
3731 // on the opposit side). We set the new control point such as
3732 // to point the curve through (position,value)
3733 current->set_control_in_value(
3734 value * levered_position(position - current->position,
3735 current->get_control_in_position()));
3736 synchronize_autos(0, current->autos->track, current, 0);
3737 show_message(current, 1,", %.2f", current->get_control_in_value());
3743 int autogrouptype = current->autos->autogrouptype;
3744 value = percentage_to_value(percentage, 0, current, autogrouptype);
3745 if(value != current->get_control_out_value()) {
3747 current->set_control_out_value(
3748 value * levered_position(position - current->position,
3749 current->get_control_out_position()));
3750 synchronize_autos(0, current->autos->track, current, 0);
3751 show_message(current, 1,", %.2f", current->get_control_out_value());
3759 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3761 IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3763 UPDATE_DRAG_HEAD(1);
3764 int value = (int)percentage_to_value(percentage, 1, 0, AUTOGROUPTYPE_INT255);
3766 if(value != current->value || position != current->position)
3769 current->value = value;
3770 current->position = position;
3771 show_message(current, 0,", %d", current->value);
3777 // Autos which can't change value through dragging.
3779 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3781 Auto *current = (Auto*)mwindow->session->drag_auto;
3784 if(position != current->position)
3787 current->position = position;
3788 show_message(current, 0,"");
3790 double position_f = current->autos->track->from_units(current->position);
3791 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3792 mwindow->edl->local_session->get_selectionend(1)) /
3796 mwindow->edl->local_session->set_selectionstart(position_f);
3797 mwindow->edl->local_session->set_selectionend(position_f);
3800 if(position_f < center_f)
3802 mwindow->edl->local_session->set_selectionstart(position_f);
3805 mwindow->edl->local_session->set_selectionend(position_f);
3812 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3814 KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3817 if(position != current->position)
3819 // printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3820 Track *track = current->autos->track;
3821 //PluginAutos *pluginautos = (PluginAutos *)current->autos;
3822 PluginSet *pluginset;
3824 // figure out the correct pluginset & correct plugin
3826 for(int i = 0; i < track->plugin_set.total; i++)
3828 pluginset = track->plugin_set.values[i];
3829 for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3831 KeyFrames *keyframes = plugin->keyframes;
3832 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first;
3834 currentkeyframe = (KeyFrame *) currentkeyframe->next)
3836 if (currentkeyframe == current)
3848 mwindow->session->plugin_highlighted = plugin;
3849 mwindow->session->track_highlighted = track;
3851 current->position = position;
3852 show_message(current, 0,"");
3854 double position_f = current->autos->track->from_units(current->position);
3855 double center_f = (mwindow->edl->local_session->get_selectionstart(1) +
3856 mwindow->edl->local_session->get_selectionend(1)) /
3860 mwindow->edl->local_session->set_selectionstart(position_f);
3861 mwindow->edl->local_session->set_selectionend(position_f);
3864 if(position_f < center_f)
3866 mwindow->edl->local_session->set_selectionstart(position_f);
3869 mwindow->edl->local_session->set_selectionend(position_f);
3876 void TrackCanvas::update_drag_caption()
3878 switch(mwindow->session->current_operation)
3888 int TrackCanvas::cursor_motion_event()
3893 int update_clock = 0;
3894 int update_zoom = 0;
3895 int update_scroll = 0;
3896 int update_overlay = 0;
3897 int update_cursor = 0;
3900 double position = 0.;
3901 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
3904 switch(mwindow->edl->session->editing_mode)
3906 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3907 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3910 switch(mwindow->session->current_operation)
3912 case DRAG_EDITHANDLE1:
3913 // Outside threshold. Upgrade status
3916 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3918 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3924 case DRAG_EDITHANDLE2:
3927 update_drag_handle();
3932 case DRAG_PLUGINHANDLE1:
3935 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3937 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3943 case DRAG_PLUGINHANDLE2:
3946 update_drag_handle();
3951 // Rubber band curves
3959 case DRAG_PROJECTOR_X:
3960 case DRAG_PROJECTOR_Y:
3961 case DRAG_PROJECTOR_Z:
3962 if(active) rerender = update_overlay =
3963 update_drag_floatauto(get_cursor_x(), get_cursor_y());
3967 if(active) rerender = update_overlay =
3968 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3972 if(active) rerender = update_overlay =
3973 update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3976 // Keyframe icons are sticky
3980 case DRAG_PLUGINKEY_PRE:
3982 if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W) {
3983 mwindow->session->current_operation++;
3986 mwindow->undo->update_undo_before();
3994 if(active) rerender = update_overlay =
3995 update_drag_auto(get_cursor_x(), get_cursor_y());
3998 case DRAG_PLUGINKEY:
3999 if(active) rerender = update_overlay =
4000 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
4005 cursor_x = get_cursor_x();
4006 cursor_y = get_cursor_y();
4007 position = (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4008 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4010 position = mwindow->edl->align_to_frame(position, 0);
4011 position = MAX(position, 0);
4013 if(position < selection_midpoint) {
4014 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4015 mwindow->edl->local_session->set_selectionstart(position);
4017 gui->unlock_window();
4018 mwindow->cwindow->update(1, 0, 0, 0, 1);
4019 gui->lock_window("TrackCanvas::cursor_motion_event 1");
4020 // Update the faders
4021 mwindow->update_plugin_guis();
4022 gui->update_patchbay();
4025 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4026 mwindow->edl->local_session->set_selectionend(position);
4027 // Don't que the CWindow
4030 timebar_position = mwindow->edl->local_session->get_selectionend(1);
4032 gui->hide_cursor(0);
4033 gui->draw_cursor(1);
4034 gui->update_timebar(0);
4035 gui->flash_canvas(1);
4044 if(is_event_win() && cursor_inside()) {
4046 cursor_x = get_cursor_x();
4047 position = (double)cursor_x *
4048 (double)mwindow->edl->local_session->zoom_sample /
4049 (double)mwindow->edl->session->sample_rate +
4050 (double)mwindow->edl->local_session->view_start[pane->number] *
4051 (double)mwindow->edl->local_session->zoom_sample /
4052 (double)mwindow->edl->session->sample_rate;
4053 position = mwindow->edl->align_to_frame(position, 0);
4057 for(int i = 0; i < TOTAL_PANES; i++)
4058 if(gui->pane[i]) gui->pane[i]->canvas->timebar_position = position;
4060 //printf("TrackCanvas::cursor_motion_event %d %d %p %p\n", __LINE__, pane->number, pane, pane->timebar);
4061 gui->update_timebar(0);
4063 if(do_transitions(get_cursor_x(), get_cursor_y(),
4064 0, new_cursor, update_cursor)) break;
4065 if(do_keyframes(get_cursor_x(), get_cursor_y(),
4066 0, 0, new_cursor, update_cursor, rerender)) break;
4067 if(do_edit_handles(get_cursor_x(), get_cursor_y(),
4068 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4069 // Plugin boundaries
4070 if(do_plugin_handles(get_cursor_x(), get_cursor_y(),
4071 0, rerender, update_overlay, new_cursor, update_cursor)) break;
4072 if(do_edits(get_cursor_x(), get_cursor_y(),
4073 0, 0, update_overlay, rerender, new_cursor, update_cursor)) break;
4078 //printf("TrackCanvas::cursor_motion_event 1\n");
4079 if(update_cursor && new_cursor != get_cursor())
4081 set_cursor(new_cursor, 0, 1);
4084 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
4085 if(rerender && render_timer->get_difference() > 0.25 ) {
4086 render_timer->update();
4087 mwindow->restart_brender();
4088 mwindow->sync_parameters(CHANGE_PARAMS);
4089 mwindow->update_plugin_guis();
4090 gui->unlock_window();
4091 mwindow->cwindow->update(1, 0, 0, 0, 1);
4092 gui->lock_window("TrackCanvas::cursor_motion_event 2");
4096 gui->update_patchbay();
4101 if(!mwindow->cwindow->playback_engine->is_playing_back)
4102 gui->mainclock->update(position);
4106 gui->zoombar->update();
4111 (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
4115 (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
4119 if(update_overlay) {
4120 gui->draw_overlays(1);
4123 //printf("TrackCanvas::cursor_motion_event %d\n", __LINE__);
4127 void TrackCanvas::start_dragscroll()
4131 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4132 //printf("TrackCanvas::start_dragscroll 1\n");
4136 void TrackCanvas::stop_dragscroll()
4140 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
4141 //printf("TrackCanvas::stop_dragscroll 1\n");
4145 int TrackCanvas::repeat_event(int64_t duration)
4147 if(!drag_scroll) return 0;
4148 if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
4150 int sample_movement = 0;
4151 int track_movement = 0;
4152 int64_t x_distance = 0;
4153 int64_t y_distance = 0;
4154 double position = 0;
4157 switch(mwindow->session->current_operation) {
4159 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
4160 if(get_cursor_x() > get_w()) {
4161 x_distance = get_cursor_x() - get_w();
4162 sample_movement = 1;
4164 else if(get_cursor_x() < 0) {
4165 x_distance = get_cursor_x();
4166 sample_movement = 1;
4169 if(get_cursor_y() > get_h()) {
4170 y_distance = get_cursor_y() - get_h();
4173 else if(get_cursor_y() < 0) {
4174 y_distance = get_cursor_y();
4181 if(sample_movement) {
4182 position = (double)(get_cursor_x() +
4183 mwindow->edl->local_session->view_start[pane->number] +
4185 mwindow->edl->local_session->zoom_sample /
4186 mwindow->edl->session->sample_rate;
4187 position = mwindow->edl->align_to_frame(position, 0);
4188 position = MAX(position, 0);
4190 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4191 switch(mwindow->session->current_operation) {
4193 if(position < selection_midpoint) {
4194 mwindow->edl->local_session->set_selectionend(selection_midpoint);
4195 mwindow->edl->local_session->set_selectionstart(position);
4197 gui->unlock_window();
4198 mwindow->cwindow->update(1, 0, 0);
4199 gui->lock_window("TrackCanvas::repeat_event");
4200 // Update the faders
4201 mwindow->update_plugin_guis();
4202 gui->update_patchbay();
4205 mwindow->edl->local_session->set_selectionstart(selection_midpoint);
4206 mwindow->edl->local_session->set_selectionend(position);
4207 // Don't que the CWindow
4212 mwindow->samplemovement(
4213 mwindow->edl->local_session->view_start[pane->number] + x_distance,
4217 if(track_movement) {
4218 mwindow->trackmovement(y_distance, pane->number);
4224 int TrackCanvas::button_release_event()
4226 int redraw = 0, update_overlay = 0, result = 0;
4228 // printf("TrackCanvas::button_release_event %d\n",
4229 // mwindow->session->current_operation);
4231 switch(mwindow->session->current_operation) {
4232 case DRAG_EDITHANDLE2:
4233 mwindow->session->current_operation = NO_OPERATION;
4237 end_edithandle_selection();
4240 case DRAG_EDITHANDLE1:
4241 mwindow->session->current_operation = NO_OPERATION;
4246 case DRAG_PLUGINHANDLE2:
4247 mwindow->session->current_operation = NO_OPERATION;
4251 end_pluginhandle_selection();
4254 case DRAG_PLUGINHANDLE1:
4255 mwindow->session->current_operation = NO_OPERATION;
4262 // delete the drag_auto_gang first and remove out of order keys
4263 synchronize_autos(0, 0, 0, -1);
4274 case DRAG_PROJECTOR_X:
4275 case DRAG_PROJECTOR_Y:
4276 case DRAG_PROJECTOR_Z:
4277 case DRAG_PLUGINKEY:
4278 mwindow->session->current_operation = NO_OPERATION;
4279 mwindow->session->drag_handle = 0;
4280 // Remove any out-of-order keyframe
4281 if(mwindow->session->drag_auto) {
4282 mwindow->session->drag_auto->autos->remove_nonsequential(
4283 mwindow->session->drag_auto);
4284 // mwindow->session->drag_auto->autos->optimize();
4289 mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
4294 case DRAG_AEFFECT_COPY:
4295 case DRAG_VEFFECT_COPY:
4296 // Trap in drag stop
4301 if(mwindow->session->current_operation) {
4302 // if(mwindow->session->current_operation == SELECT_REGION) {
4303 // mwindow->undo->update_undo_after(_("select"), LOAD_SESSION, 0, 0);
4306 mwindow->session->current_operation = NO_OPERATION;
4308 // Traps button release events
4316 cursor_motion_event();
4318 if(update_overlay) {
4319 gui->draw_overlays(1);
4322 gui->draw_canvas(NORMAL_DRAW, 0);
4327 int TrackCanvas::do_edit_handles(int cursor_x, int cursor_y, int button_press,
4328 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor)
4330 Edit *edit_result = 0;
4331 int handle_result = -1;
4334 if( !mwindow->edl->session->show_assets ) return 0;
4336 for( Track *track=mwindow->edl->tracks->first; track && !result; track=track->next) {
4337 for( Edit *edit=track->edits->first; edit && !result; edit=edit->next ) {
4338 int64_t edit_x, edit_y, edit_w, edit_h;
4339 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4341 if( cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4342 cursor_y >= edit_y && cursor_y < edit_y + edit_h ) {
4343 if( cursor_x < edit_x + HANDLE_W ) {
4346 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4347 new_cursor = DOWNLEFT_RESIZE;
4348 if( button_press == LEFT_BUTTON )
4354 else if( cursor_x >= edit_x + edit_w - HANDLE_W ) {
4357 if( cursor_y >= edit_y+edit_h - HANDLE_W ) {
4358 new_cursor = DOWNRIGHT_RESIZE;
4359 if( button_press == LEFT_BUTTON )
4371 double position = 0;
4372 if( handle_result == 0 ) {
4373 position = edit_result->track->from_units(edit_result->startproject);
4374 new_cursor = LEFT_CURSOR;
4376 else if( handle_result == 1 ) {
4377 position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4378 new_cursor = RIGHT_CURSOR;
4381 // Reposition cursor
4382 if( button_press ) {
4383 mwindow->session->drag_edit = edit_result;
4384 mwindow->session->drag_handle = handle_result;
4385 mwindow->session->drag_button = get_buttonpress() - 1;
4386 mwindow->session->drag_position = position;
4387 mwindow->session->current_operation = DRAG_EDITHANDLE1;
4388 mwindow->session->drag_origin_x = get_cursor_x();
4389 mwindow->session->drag_origin_y = get_cursor_y();
4390 mwindow->session->drag_start = position;
4392 rerender = start_selection(position);
4396 else if( result < 0) {
4397 mwindow->undo->update_undo_before();
4398 if( !shift_down() ) {
4399 if( handle_result == 0 )
4400 edit_result->hard_left = !edit_result->hard_left;
4401 else if( handle_result == 1 )
4402 edit_result->hard_right = !edit_result->hard_right;
4405 int status = handle_result == 0 ? edit_result->hard_left :
4406 handle_result == 1 ? edit_result->hard_right : 0;
4407 int new_status = !status;
4408 int64_t edit_edge = edit_result->startproject;
4409 if( handle_result == 1 ) edit_edge += edit_result->length;
4410 double edge_position = edit_result->track->from_units(edit_edge);
4411 for( Track *track=mwindow->edl->tracks->first; track!=0; track=track->next ) {
4412 int64_t track_position = track->to_units(edge_position, 1);
4413 Edit *left_edit = track->edits->editof(track_position, PLAY_FORWARD, 0);
4415 int64_t left_edge = left_edit->startproject;
4416 double left_position = track->from_units(left_edge);
4417 if( EQUIV(edge_position, left_position) ) {
4418 left_edit->hard_left = new_status;
4419 if( left_edit->previous )
4420 left_edit->previous->hard_right = new_status;
4423 Edit *right_edit = track->edits->editof(track_position, PLAY_REVERSE, 0);
4425 int64_t right_edge = right_edit->startproject + right_edit->length;
4426 double right_position = track->from_units(right_edge);
4427 if( EQUIV(edge_position, right_position) ) {
4428 right_edit->hard_right = new_status;
4429 if( right_edit->next )
4430 right_edit->next->hard_left = new_status;
4435 rerender = update_overlay = 1;
4436 mwindow->undo->update_undo_after(_("hard_edge"), LOAD_EDITS);
4443 int TrackCanvas::do_plugin_handles(int cursor_x,
4447 int &update_overlay,
4451 Plugin *plugin_result = 0;
4452 int handle_result = 0;
4455 // if(!mwindow->edl->session->show_assets) return 0;
4457 for(Track *track = mwindow->edl->tracks->first;
4459 track = track->next) {
4460 for(int i = 0; i < track->plugin_set.total && !result; i++) {
4461 PluginSet *plugin_set = track->plugin_set.values[i];
4462 for(Plugin *plugin = (Plugin*)plugin_set->first;
4464 plugin = (Plugin*)plugin->next) {
4465 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4466 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4468 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4469 cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h) {
4470 if(cursor_x < plugin_x + HANDLE_W) {
4471 plugin_result = plugin;
4475 else if(cursor_x >= plugin_x + plugin_w - HANDLE_W) {
4476 plugin_result = plugin;
4483 if(result && shift_down())
4484 mwindow->session->trim_edits = plugin_set;
4490 double position = 0;
4491 if(handle_result == 0) {
4492 position = plugin_result->track->from_units(plugin_result->startproject);
4493 new_cursor = LEFT_CURSOR;
4495 else if(handle_result == 1) {
4496 position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4497 new_cursor = RIGHT_CURSOR;
4501 mwindow->session->drag_plugin = plugin_result;
4502 mwindow->session->drag_handle = handle_result;
4503 mwindow->session->drag_button = get_buttonpress() - 1;
4504 mwindow->session->drag_position = position;
4505 mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4506 mwindow->session->drag_origin_x = get_cursor_x();
4507 mwindow->session->drag_origin_y = get_cursor_y();
4508 mwindow->session->drag_start = position;
4510 rerender = start_selection(position);
4519 int TrackCanvas::do_tracks(int cursor_x, int cursor_y, int button_press)
4523 // if(!mwindow->edl->session->show_assets) return 0;
4525 for(Track *track = mwindow->edl->tracks->first;
4527 track = track->next) {
4528 int64_t track_x, track_y, track_w, track_h;
4529 track_dimensions(track, track_x, track_y, track_w, track_h);
4531 if(button_press && get_buttonpress() == RIGHT_BUTTON &&
4532 cursor_y >= track_y && cursor_y < track_y + track_h) {
4533 gui->edit_menu->update(track, 0);
4534 gui->edit_menu->activate_menu();
4542 int TrackCanvas::do_edits(int cursor_x, int cursor_y, int button_press, int drag_start,
4543 int &redraw, int &rerender, int &new_cursor, int &update_cursor)
4547 if(!mwindow->edl->session->show_assets) return 0;
4549 for(Track *track = mwindow->edl->tracks->first; track && !result; track = track->next) {
4551 for(Edit *edit = track->edits->first; edit && !result; edit = edit->next) {
4552 int64_t edit_x, edit_y, edit_w, edit_h;
4553 edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4555 // Cursor inside a track
4556 // Cursor inside an edit
4557 if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4558 cursor_y >= edit_y && cursor_y < edit_y + edit_h) {
4559 // Select duration of edit
4561 if(get_double_click() && !drag_start) {
4562 mwindow->edl->local_session->set_selectionstart(edit->track->from_units(edit->startproject));
4563 mwindow->edl->local_session->set_selectionend(edit->track->from_units(edit->startproject) +
4564 edit->track->from_units(edit->length));
4565 if(mwindow->edl->session->cursor_on_frames)
4567 mwindow->edl->local_session->set_selectionstart(
4568 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4569 mwindow->edl->local_session->set_selectionend(
4570 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4578 else if(drag_start && track->record) {
4579 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4580 // Need to create drag window
4581 mwindow->session->current_operation = DRAG_EDIT;
4582 mwindow->session->drag_edit = edit;
4583 //printf("TrackCanvas::do_edits 2\n");
4585 // Drag only one edit if ctrl is initially down
4587 mwindow->session->drag_edits->remove_all();
4588 mwindow->session->drag_edits->append(edit);
4591 // Construct list of all affected edits
4592 mwindow->edl->tracks->get_affected_edits(
4593 mwindow->session->drag_edits,
4594 edit->track->from_units(edit->startproject),
4597 mwindow->session->drag_origin_x = cursor_x;
4598 mwindow->session->drag_origin_y = cursor_y;
4599 // Where the drag started, so we know relative position inside the edit later
4600 mwindow->session->drag_position = (double)cursor_x *
4601 mwindow->edl->local_session->zoom_sample /
4602 mwindow->edl->session->sample_rate +
4603 (double)mwindow->edl->local_session->view_start[pane->number] *
4604 mwindow->edl->local_session->zoom_sample /
4605 mwindow->edl->session->sample_rate;
4608 get_abs_cursor(cx, cy);
4609 gui->drag_popup = new BC_DragWindow(gui,
4610 mwindow->theme->get_image("clip_icon"), cx, cy);
4622 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4627 int TrackCanvas::do_plugins(int cursor_x, int cursor_y, int drag_start,
4628 int button_press, int &redraw, int &rerender)
4637 // if(!mwindow->edl->session->show_assets) return 0;
4640 for(track = mwindow->edl->tracks->first; track && !done; track = track->next) {
4641 if(!track->expand_view) continue;
4643 for(int i = 0; i < track->plugin_set.total && !done; i++) {
4644 // first check if plugins are visible at all
4645 if (!track->expand_view)
4647 PluginSet *plugin_set = track->plugin_set.values[i];
4648 for(plugin = (Plugin*)plugin_set->first;
4650 plugin = (Plugin*)plugin->next) {
4651 plugin_dimensions(plugin, x, y, w, h);
4652 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4653 MWindowGUI::visible(y, y + h, 0, get_h())) {
4654 if(cursor_x >= x && cursor_x < x + w &&
4655 cursor_y >= y && cursor_y < y + h) {
4665 // Start plugin popup
4667 if(get_buttonpress() == 3) {
4668 gui->plugin_menu->update(plugin);
4669 gui->plugin_menu->activate_menu();
4672 else if (get_double_click() && !drag_start) {
4673 // Select range of plugin on doubleclick over plugin
4674 mwindow->edl->local_session->set_selectionstart(plugin->track->from_units(plugin->startproject));
4675 mwindow->edl->local_session->set_selectionend(plugin->track->from_units(plugin->startproject) +
4676 plugin->track->from_units(plugin->length));
4677 if(mwindow->edl->session->cursor_on_frames) {
4678 mwindow->edl->local_session->set_selectionstart(
4679 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionstart(1), 0));
4680 mwindow->edl->local_session->set_selectionend(
4681 mwindow->edl->align_to_frame(mwindow->edl->local_session->get_selectionend(1), 1));
4690 if(drag_start && plugin->track->record) {
4691 if(mwindow->edl->session->editing_mode == EDITING_ARROW) {
4692 if(plugin->track->data_type == TRACK_AUDIO)
4693 mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4694 else if(plugin->track->data_type == TRACK_VIDEO)
4695 mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4697 mwindow->session->drag_plugin = plugin;
4698 mwindow->session->drag_origin_x = cursor_x;
4699 mwindow->session->drag_origin_y = cursor_y;
4700 // Where the drag started, so we know relative position inside the edit later
4701 mwindow->session->drag_position =
4702 (double)(cursor_x + mwindow->edl->local_session->view_start[pane->number]) *
4703 mwindow->edl->local_session->zoom_sample / mwindow->edl->session->sample_rate;
4705 switch(plugin->plugin_type) {
4706 case PLUGIN_STANDALONE: {
4707 PluginServer *server =
4708 mwindow->scan_plugindb(plugin->title, plugin->track->data_type);
4709 if( !server ) break;
4710 VFrame *frame = server->picon;
4712 if(plugin->track->data_type == TRACK_AUDIO) {
4713 frame = mwindow->theme->get_image("aeffect_icon");
4716 frame = mwindow->theme->get_image("veffect_icon");
4720 get_abs_cursor(cx, cy);
4721 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4724 case PLUGIN_SHAREDPLUGIN:
4725 case PLUGIN_SHAREDMODULE: {
4726 VFrame *frame = mwindow->theme->get_image("clip_icon");
4728 get_abs_cursor(cx, cy);
4729 gui->drag_popup = new BC_DragWindow(gui, frame, cx, cy);
4741 int TrackCanvas::do_transitions(int cursor_x, int cursor_y,
4742 int button_press, int &new_cursor, int &update_cursor)
4744 Transition *transition = 0;
4748 if(/* !mwindow->edl->session->show_assets || */
4749 !mwindow->edl->session->auto_conf->transitions) return 0;
4751 for( Track *track = mwindow->edl->tracks->first; track && !result; track = track->next ) {
4753 for( Edit *edit = track->edits->first; edit; edit = edit->next ) {
4754 if( edit->transition ) {
4755 edit_dimensions(edit, x, y, w, h);
4756 get_transition_coords(x, y, w, h);
4758 if( MWindowGUI::visible(x, x + w, 0, get_w()) &&
4759 MWindowGUI::visible(y, y + h, 0, get_h()) ) {
4760 if( cursor_x >= x && cursor_x < x + w &&
4761 cursor_y >= y && cursor_y < y + h ) {
4762 transition = edit->transition;
4774 new_cursor = UPRIGHT_ARROW_CURSOR;
4776 else if(get_buttonpress() == 3) {
4777 gui->transition_menu->update(transition);
4778 gui->transition_menu->activate_menu();
4785 int TrackCanvas::button_press_event()
4788 int cursor_x, cursor_y;
4791 cursor_x = get_cursor_x();
4792 cursor_y = get_cursor_y();
4793 mwindow->session->trim_edits = 0;
4795 if(is_event_win() && cursor_inside()) {
4796 // double position = (double)cursor_x *
4797 // mwindow->edl->local_session->zoom_sample /
4798 // mwindow->edl->session->sample_rate +
4799 // (double)mwindow->edl->local_session->view_start[pane->number] *
4800 // mwindow->edl->local_session->zoom_sample /
4801 // mwindow->edl->session->sample_rate;
4808 if( get_buttonpress() == LEFT_BUTTON &&
4809 gui->mbuttons->transport->engine->command->command != STOP ) {
4810 gui->unlock_window();
4811 gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
4812 gui->lock_window("TrackCanvas::button_press_event");
4815 int update_overlay = 0, update_cursor = 0, rerender = 0;
4817 if(get_buttonpress() == WHEEL_UP) {
4819 mwindow->expand_sample();
4820 else if(ctrl_down())
4821 mwindow->move_left(get_w()/ 10);
4823 mwindow->move_up(get_h() / 10);
4825 else if(get_buttonpress() == WHEEL_DOWN) {
4827 mwindow->zoom_in_sample();
4828 else if(ctrl_down())
4829 mwindow->move_right(get_w() / 10);
4831 mwindow->move_down(get_h() / 10);
4833 else if(get_buttonpress() == 6) {
4835 mwindow->move_left(get_w());
4837 mwindow->move_left(get_w() / 20);
4839 mwindow->move_left(get_w() / 5);
4841 else if(get_buttonpress() == 7) {
4843 mwindow->move_right(get_w());
4845 mwindow->move_right(get_w() / 20);
4847 mwindow->move_right(get_w() / 5);
4850 switch(mwindow->edl->session->editing_mode) {
4851 // Test handles and resource boundaries and highlight a track
4852 case EDITING_ARROW: {
4853 if( do_transitions(cursor_x, cursor_y,
4854 1, new_cursor, update_cursor) ) break;
4856 if( do_keyframes(cursor_x, cursor_y,
4857 0, get_buttonpress(), new_cursor,
4858 update_cursor, rerender) ) break;
4859 // Test edit boundaries
4860 if( do_edit_handles(cursor_x, cursor_y,
4861 1, rerender, update_overlay, new_cursor,
4862 update_cursor) ) break;
4863 // Test plugin boundaries
4864 if( do_plugin_handles(cursor_x, cursor_y,
4865 1, rerender, update_overlay, new_cursor,
4866 update_cursor) ) break;
4868 if( do_edits(cursor_x, cursor_y, 1, 0,
4869 update_cursor, rerender, new_cursor,
4870 update_cursor) ) break;
4872 if( do_plugins(cursor_x, cursor_y, 0, 1,
4873 update_cursor, rerender) ) break;
4875 if( test_resources(cursor_x, cursor_y) ) break;
4877 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4882 // Test handles only and select a region
4883 case EDITING_IBEAM: {
4884 double position = (double)cursor_x *
4885 mwindow->edl->local_session->zoom_sample /
4886 mwindow->edl->session->sample_rate +
4887 (double)mwindow->edl->local_session->view_start[pane->number] *
4888 mwindow->edl->local_session->zoom_sample /
4889 mwindow->edl->session->sample_rate;
4890 //printf("TrackCanvas::button_press_event %d\n", position);
4892 if( do_transitions(cursor_x, cursor_y,
4893 1, new_cursor, update_cursor)) break;
4894 if(do_keyframes(cursor_x, cursor_y,
4895 0, get_buttonpress(), new_cursor,
4896 update_cursor, rerender)) {
4900 // Test edit boundaries
4901 if( do_edit_handles(cursor_x, cursor_y,
4902 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4903 // Test plugin boundaries
4904 if( do_plugin_handles(cursor_x, cursor_y,
4905 1, rerender, update_overlay, new_cursor, update_cursor) ) break;
4907 if( do_edits(cursor_x, cursor_y,
4908 1, 0, update_cursor, rerender, new_cursor, update_cursor) ) break;
4910 if( do_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender) ) break;
4912 if( do_tracks(cursor_x, cursor_y, 1) ) break;
4913 // Highlight selection
4914 if( get_buttonpress() != LEFT_BUTTON ) break;
4915 rerender = start_selection(position);
4916 mwindow->session->current_operation = SELECT_REGION;
4923 gui->unlock_window();
4924 mwindow->cwindow->update(1, 0, 0, 0, 1);
4925 gui->lock_window("TrackCanvas::button_press_event 2");
4927 mwindow->update_plugin_guis();
4928 gui->update_patchbay();
4931 if( update_overlay ) {
4932 gui->draw_overlays(1);
4934 if( update_cursor < 0 ) {
4935 // double_click edit
4936 gui->swindow->update_selection();
4938 if( update_cursor ) {
4939 gui->update_timebar(0);
4940 gui->hide_cursor(0);
4941 gui->show_cursor(1);
4942 gui->zoombar->update();
4943 gui->flash_canvas(1);
4950 int TrackCanvas::start_selection(double position)
4953 position = mwindow->edl->align_to_frame(position, 1);
4959 double midpoint = (mwindow->edl->local_session->get_selectionstart(1) +
4960 mwindow->edl->local_session->get_selectionend(1)) / 2;
4962 if(position < midpoint)
4964 mwindow->edl->local_session->set_selectionstart(position);
4965 selection_midpoint = mwindow->edl->local_session->get_selectionend(1);
4971 mwindow->edl->local_session->set_selectionend(position);
4972 selection_midpoint = mwindow->edl->local_session->get_selectionstart(1);
4973 // Don't que the CWindow for the end
4977 // Start a new selection
4979 //printf("TrackCanvas::start_selection %f\n", position);
4980 mwindow->edl->local_session->set_selectionstart(position);
4981 mwindow->edl->local_session->set_selectionend(position);
4982 selection_midpoint = position;
4990 void TrackCanvas::end_edithandle_selection()
4992 mwindow->modify_edithandles();
4995 void TrackCanvas::end_pluginhandle_selection()
4997 mwindow->modify_pluginhandles();
5001 double TrackCanvas::time_visible()
5003 return (double)get_w() *
5004 mwindow->edl->local_session->zoom_sample /
5005 mwindow->edl->session->sample_rate;
5009 void TrackCanvas::show_message(Auto *current, int show_curve_type, const char *fmt, ...)
5011 char string[BCTEXTLEN];
5012 char *cp = string, *ep = cp + sizeof(string)-1;
5013 if( show_curve_type ) {
5014 cp += snprintf(string, ep-cp, "%-8s ",
5015 FloatAuto::curve_name(((FloatAuto*)current)->curve_mode));
5017 char string2[BCTEXTLEN];
5018 Units::totext(string2,
5019 current->autos->track->from_units(current->position),
5020 mwindow->edl->session->time_format,
5021 mwindow->edl->session->sample_rate,
5022 mwindow->edl->session->frame_rate,
5023 mwindow->edl->session->frames_per_foot);
5024 cp += snprintf(cp, ep-cp, "%s", string2);
5027 vsnprintf(cp, ep-cp, fmt, ap);
5029 gui->show_message(string);
5032 // Patchbay* TrackCanvas::get_patchbay()
5034 // if(pane->patchbay) return pane->patchbay;
5035 // if(gui->total_panes() == 2 &&
5036 // gui->pane[TOP_LEFT_PANE] &&
5037 // gui->pane[TOP_RIGHT_PANE])
5038 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5039 // if(gui->total_panes() == 4)
5041 // if(pane->number == TOP_RIGHT_PANE)
5042 // return gui->pane[TOP_LEFT_PANE]->patchbay;
5044 // return gui->pane[BOTTOM_LEFT_PANE]->patchbay;