r289: Merged the official release 1.2.0.
[cinelerra_cv/ct.git] / cinelerra / trackcanvas.C
blob1c74e097c7bc887fdd3eac9024a3a52fafcff637
1 #include "asset.h"
2 #include "autoconf.h"
3 #include "automation.h"
4 #include "bcsignals.h"
5 #include "bezierauto.h"
6 #include "bezierautos.h"
7 #include "clip.h"
8 #include "colors.h"
9 #include "cplayback.h"
10 #include "cursors.h"
11 #include "cwindow.h"
12 #include "cwindowgui.h"
13 #include "edithandles.h"
14 #include "editpopup.h"
15 #include "edits.h"
16 #include "edl.h"
17 #include "edlsession.h"
18 #include "floatauto.h"
19 #include "floatautos.h"
20 #include "intauto.h"
21 #include "keyframe.h"
22 #include "keyframepopup.h"
23 #include "keyframes.h"
24 #include "keys.h"
25 #include "localsession.h"
26 #include "mainclock.h"
27 #include "maincursor.h"
28 #include "mainundo.h"
29 #include "maskautos.h"
30 #include "mbuttons.h"
31 #include "mtimebar.h"
32 #include "mwindow.h"
33 #include "mwindowgui.h"
34 #include "patchbay.h"
35 #include "tracking.h"
36 #include "panautos.h"
37 #include "playbackengine.h"
38 #include "playtransport.h"
39 #include "plugin.h"
40 #include "pluginpopup.h"
41 #include "pluginset.h"
42 #include "pluginserver.h"
43 #include "preferences.h"
44 #include "resourcepixmap.h"
45 #include "mainsession.h"
46 #include "transitionhandles.h"
47 #include "transitionpopup.h"
48 #include "transportque.h"
49 #include "zoombar.h"
50 #include "theme.h"
51 #include "intautos.h"
52 #include "trackcanvas.h"
53 #include "tracks.h"
54 #include "transition.h"
55 #include "vframe.h"
56 #include "apatchgui.inc"
57 #include "vpatchgui.inc"
59 #include <string.h>
61 TrackCanvas::TrackCanvas(MWindow *mwindow, MWindowGUI *gui)
62  : BC_SubWindow(mwindow->theme->mcanvas_x,
63         mwindow->theme->mcanvas_y,
64         gui->view_w,
65         gui->view_h)
67         this->mwindow = mwindow;
68         this->gui = gui;
69         current_end = 0;
70         selection_midpoint1 = selection_midpoint2 = 0;
71         selection_type = 0;
72         region_selected = 0;
73         handle_selected = 0;
74         auto_selected = 0;
75         translate_selected = 0;
76         which_handle = 0;
77         handle_pixel = 0;
78         drag_scroll = 0;
79         drag_popup = 0;
80         active = 0;
81         temp_picon = 0;
84 TrackCanvas::~TrackCanvas()
86         for(int i = 0; i < resource_pixmaps.total; i++)
87                 delete resource_pixmaps.values[i];
88 //      delete transition_handles;
89         delete edit_handles;
90         delete keyframe_pixmap;
91         delete camerakeyframe_pixmap;
92         delete modekeyframe_pixmap;
93         delete pankeyframe_pixmap;
94         delete projectorkeyframe_pixmap;
95         delete maskkeyframe_pixmap;
96         delete background_pixmap;
97         if(temp_picon) delete temp_picon;
100 int TrackCanvas::create_objects()
102         background_pixmap = new BC_Pixmap(this, get_w(), get_h());
103 //      transition_handles = new TransitionHandles(mwindow, this);
104         edit_handles = new EditHandles(mwindow, this);
105         keyframe_pixmap = new BC_Pixmap(this, mwindow->theme->keyframe_data, PIXMAP_ALPHA);
106         camerakeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->camerakeyframe_data, PIXMAP_ALPHA);
107         modekeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->modekeyframe_data, PIXMAP_ALPHA);
108         pankeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->pankeyframe_data, PIXMAP_ALPHA);
109         projectorkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->projectorkeyframe_data, PIXMAP_ALPHA);
110         maskkeyframe_pixmap = new BC_Pixmap(this, mwindow->theme->maskkeyframe_data, PIXMAP_ALPHA);
111         draw();
112         update_cursor();
113         flash();
114         return 0;
117 void TrackCanvas::resize_event()
119 //printf("TrackCanvas::resize_event 1\n");
120         draw(0, 0);
121         flash();
122 //printf("TrackCanvas::resize_event 2\n");
125 int TrackCanvas::keypress_event()
127         int result = 0;
129         switch(get_keypress())
130         {
131                 case LEFT:
132                         if(!ctrl_down()) 
133                         { 
134                                 mwindow->move_left(); 
135                                 result = 1; 
136                         }
137                         break;
138                 case RIGHT:
139                         if(!ctrl_down()) 
140                         { 
141                                 mwindow->move_right(); 
142                                 result = 1; 
143                         }
144                         break;
146                 case UP:
147                         if(!ctrl_down())
148                         {
149                                 mwindow->expand_sample();
150                                 result = 1;
151                         }
152                         else
153                         {
154                                 mwindow->expand_y();
155                                 result = 1;
156                         }
157                         break;
159                 case DOWN:
160                         if(!ctrl_down())
161                         {
162                                 mwindow->zoom_in_sample();
163                                 result = 1;
164                         }
165                         else
166                         {
167                                 mwindow->zoom_in_y();
168                                 result = 1;
169                         }
170                         break;
172                 case PGUP:
173                         if(!ctrl_down())
174                         {
175                                 mwindow->move_up();
176                                 result = 1;
177                         }
178                         else
179                         {
180                                 mwindow->expand_t();
181                                 result = 1;
182                         }
183                         break;
185                 case PGDN:
186                         if(!ctrl_down())
187                         {
188                                 mwindow->move_down();
189                                 result = 1;
190                         }
191                         else
192                         {
193                                 mwindow->zoom_in_t();
194                                 result = 1;
195                         }
196                         break;
197         }
199 // since things under cursor have changed...
200         if (result) 
201                 cursor_motion_event(); 
203         return result;
206 int TrackCanvas::drag_motion()
209         int cursor_x = get_relative_cursor_x();
210         int cursor_y = get_relative_cursor_y();
211         Track *over_track = 0;
212         Edit *over_edit = 0;
213         PluginSet *over_pluginset = 0;
214         Plugin *over_plugin = 0;
215         int redraw = 0;
218         if(drag_popup)
219         {
220                 drag_popup->cursor_motion_event();
221         }
226         if(get_cursor_over_window() &&
227                 cursor_x >= 0 && 
228                 cursor_y >= 0 && 
229                 cursor_x < get_w() && 
230                 cursor_y < get_h())
231         {
232 // Find the edit and track the cursor is over
233                 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
234                 {
235                         int64_t track_x, track_y, track_w, track_h;
236                         track_dimensions(track, track_x, track_y, track_w, track_h);
238                         if(cursor_y >= track_y && 
239                                 cursor_y < track_y + track_h)
240                         {
241                                 over_track = track;
242                                 for(Edit *edit = track->edits->first; edit; edit = edit->next)
243                                 {
244                                         int64_t edit_x, edit_y, edit_w, edit_h;
245                                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
247                                         if(cursor_x >= edit_x && 
248                                                 cursor_y >= edit_y && 
249                                                 cursor_x < edit_x + edit_w && 
250                                                 cursor_y < edit_y + edit_h)
251                                         {
252                                                 over_edit = edit;
253                                                 break;
254                                         }
255                                 }
257                                 for(int i = 0; i < track->plugin_set.total; i++)
258                                 {
259                                         PluginSet *pluginset = track->plugin_set.values[i];
260                                         
263                                         for(Plugin *plugin = (Plugin*)pluginset->first;
264                                                 plugin;
265                                                 plugin = (Plugin*)plugin->next)
266                                         {
267                                                 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
268                                                 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
269                                                 
270                                                 if(cursor_y >= plugin_y &&
271                                                         cursor_y < plugin_y + plugin_h)
272                                                 {
273                                                         over_pluginset = plugin->plugin_set;
274                                                 
275                                                         if(cursor_x >= plugin_x &&
276                                                                 cursor_x < plugin_x + plugin_w)
277                                                         {
278                                                                 over_plugin = plugin;
279                                                                 break;
280                                                         }
281                                                 }
282                                         }
283                                 }
284                                 break;
285                         }
286                 }
287         }
289         if (!over_track)        // check for pastes from patchbay
290                 over_track = mwindow->gui->patchbay->is_over_track();
292         if(mwindow->session->track_highlighted != over_track) 
293         {
294                 mwindow->session->track_highlighted = over_track;
295                 redraw = 1;
296         }
298         if(mwindow->session->edit_highlighted != over_edit)
299         {
300                 mwindow->session->edit_highlighted = over_edit;
301                 redraw = 1;
302         }
304         if(mwindow->session->pluginset_highlighted != over_pluginset)
305         {
306                 mwindow->session->pluginset_highlighted = over_pluginset;
307                 redraw = 1;
308         }
310         if(mwindow->session->plugin_highlighted != over_plugin)
311         {
312                 mwindow->session->plugin_highlighted = over_plugin;
313                 redraw = 1;
314         }
316 //printf("TrackCanvas::drag_motion 2 %p\n", mwindow->session->track_highlighted);
317         if(redraw)
318         {
319                 lock_window("TrackCanvas::drag_motion");
320                 draw_overlays();
321                 flash();
322                 unlock_window();
323         }
325         return 0;
328 int TrackCanvas::drag_start_event()
330         int result = 0;
331         int redraw = 0;
332         int rerender = 0;
333         int new_cursor, update_cursor;
335         if(mwindow->session->current_operation != NO_OPERATION) return 0;
337         if(is_event_win())
338         {
339                 if(test_plugins(get_drag_x(), 
340                         get_drag_y(), 
341                         1,
342                         0,
343                         redraw,
344                         rerender))
345                 {
346                         result = 1;
347                 }
348                 else
349                 if(test_edits(get_drag_x(),
350                         get_drag_y(),
351                         0,
352                         1,
353                         redraw,
354                         rerender,
355                         new_cursor,
356                         update_cursor))
357                 {
358                         result = 1;
359                 }
360         }
362         return result;
365 int TrackCanvas::drag_motion_event()
367         return drag_motion();
370 int TrackCanvas::cursor_leave_event()
372         // because drag motion calls get_cursor_over_window we can be sure that all highlights get deleted now
373         drag_motion();
374         return 0;
378 int TrackCanvas::drag_stop_event()
380         int result = drag_stop();
382         if(drag_popup)
383         {
384 //printf("TrackCanvas::drag_stop_event 1 %p\n", drag_popup);
385                 delete drag_popup;
386                 drag_popup = 0;
387         }
388         return result;
392 int TrackCanvas::drag_stop()
394 // In most cases the editing routine redraws and not the drag_stop
395         int result = 0, redraw = 0;
397         switch(mwindow->session->current_operation)
398         {
399                 case DRAG_VTRANSITION:
400                 case DRAG_ATRANSITION:
401                         if(mwindow->session->edit_highlighted)
402                         {
403                                 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
404                                         mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
405                                         (mwindow->session->current_operation == DRAG_VTRANSITION &&
406                                         mwindow->session->track_highlighted->data_type == TRACK_VIDEO))
407                                 {
408                                         mwindow->session->current_operation = NO_OPERATION;
409                                         mwindow->paste_transition();
410                                         result = 1;
411                                 }
412                         }
413                         redraw = 1;
414                         break;
419 // Behavior for dragged plugins is limited by the fact that a shared plugin
420 // can only refer to a standalone plugin that exists in the same position in
421 // time.  Dragging a plugin from one point in time to another can't produce
422 // a shared plugin to the original plugin.  In this case we relocate the
423 // plugin instead of sharing it.
424                 case DRAG_AEFFECT_COPY:
425                 case DRAG_VEFFECT_COPY:
426                         if(mwindow->session->track_highlighted &&
427                                 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
428                                         mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
429                                         (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
430                                         mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
431                         {
432                                 mwindow->session->current_operation = NO_OPERATION;
434 // Insert shared plugin in source
435                                 if(mwindow->session->track_highlighted != mwindow->session->drag_plugin->track &&
436                                         !mwindow->session->plugin_highlighted &&
437                                         !mwindow->session->pluginset_highlighted)
438                                 {
439 // Move plugin if different startproject
440                                         mwindow->move_effect(mwindow->session->drag_plugin,
441                                                 0,
442                                                 mwindow->session->track_highlighted,
443                                                 0);
444                                         result = 1;
445                                 }
446                                 else
447 // Move source to different location
448                                 if(mwindow->session->pluginset_highlighted)
449                                 {
450 //printf("TrackCanvas::drag_stop 6\n");
451                                         if(mwindow->session->plugin_highlighted)
452                                         {
453                                                 mwindow->move_effect(mwindow->session->drag_plugin,
454                                                         mwindow->session->plugin_highlighted->plugin_set,
455                                                         0,
456                                                         mwindow->session->plugin_highlighted->startproject);
457                                         }
458                                         else
459                                         {
460                                                 mwindow->move_effect(mwindow->session->drag_plugin,
461                                                         mwindow->session->pluginset_highlighted,
462                                                         0,
463                                                         mwindow->session->pluginset_highlighted->length());
464                                         }
465                                         result = 1;
466                                 }
467                                 else
468 // Move to a new plugin set between two edits
469                                 if(mwindow->session->edit_highlighted)
470                                 {
471                                         mwindow->move_effect(mwindow->session->drag_plugin,
472                                                 0,
473                                                 mwindow->session->track_highlighted,
474                                                 mwindow->session->edit_highlighted->startproject);
475                                         result = 1;
476                                 }
477                                 else
478 // Move to a new plugin set
479                                 if(mwindow->session->track_highlighted)
480                                 {
481                                         mwindow->move_effect(mwindow->session->drag_plugin,
482                                                 0,
483                                                 mwindow->session->track_highlighted,
484                                                 0);
485                                         result = 1;
486                                 }
487                         }
488                         break;
490                 case DRAG_AEFFECT:
491                 case DRAG_VEFFECT:
492                         if(mwindow->session->track_highlighted && 
493                                 ((mwindow->session->current_operation == DRAG_AEFFECT &&
494                                 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
495                                 (mwindow->session->current_operation == DRAG_VEFFECT &&
496                                 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
497                         {
498 // Drop all the effects
499                                 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
500                                 Track *track = mwindow->session->track_highlighted;
501                                 double start = 0;
502                                 double length = track->get_length();
504                                 if(mwindow->session->plugin_highlighted)
505                                 {
506                                         start = track->from_units(mwindow->session->plugin_highlighted->startproject);
507                                         length = track->from_units(mwindow->session->plugin_highlighted->length);
508                                         if(length <= 0) length = track->get_length();
509                                 }
510                                 else
511                                 if(mwindow->session->pluginset_highlighted)
512                                 {
513                                         start = track->from_units(plugin_set->length());
514                                         length = track->get_length() - start;
515                                         if(length <= 0) length = track->get_length();
516                                 }
517                                 else
518                                 if(mwindow->edl->local_session->get_selectionend() > 
519                                         mwindow->edl->local_session->get_selectionstart())
520                                 {
521                                         start = mwindow->edl->local_session->get_selectionstart();
522                                         length = mwindow->edl->local_session->get_selectionend() - 
523                                                 mwindow->edl->local_session->get_selectionstart();
524                                 }
525 // Move to a point between two edits
526                                 else
527                                 if(mwindow->session->edit_highlighted)
528                                 {
529                                         start = mwindow->session->track_highlighted->from_units(
530                                                 mwindow->session->edit_highlighted->startproject);
531                                         length = mwindow->session->track_highlighted->from_units(
532                                                 mwindow->session->edit_highlighted->length);
533                                 }
535                                 mwindow->insert_effects_canvas(start, length);
536                                 redraw = 1;
537                         }
538                         if (mwindow->session->track_highlighted)
539                                 result = 1;  // we have to cleanup
540                         break;
542                 case DRAG_ASSET:
543                         if(mwindow->session->track_highlighted)
544                         {
545                                 int64_t position = mwindow->session->edit_highlighted ?
546                                         mwindow->session->edit_highlighted->startproject :
547                                         mwindow->session->track_highlighted->edits->length();
548                                 double position_f = mwindow->session->track_highlighted->from_units(position);
549                                 Track *track = mwindow->session->track_highlighted;
550                                 mwindow->paste_assets(position_f, track);
551                                 result = 1;    // need to be one no matter what, since we have track highlited so we have to cleanup....
552                         }
553                         break;
555                 case DRAG_EDIT:
556                         mwindow->session->current_operation = NO_OPERATION;
557                         if(mwindow->session->track_highlighted)
558                         {
559                                 if(mwindow->session->track_highlighted->data_type == mwindow->session->drag_edit->track->data_type)
560                                 {
561                                         int64_t position = mwindow->session->edit_highlighted ?
562                                                 mwindow->session->edit_highlighted->startproject :
563                                                 mwindow->session->track_highlighted->edits->length();
564                                         double position_f = mwindow->session->track_highlighted->from_units(position);
565                                         Track *track = mwindow->session->track_highlighted;
566                                         mwindow->move_edits(mwindow->session->drag_edits,
567                                                 track,
568                                                 position_f);
569                                 }
571                                 result = 1;
572                         }
573                         break;
574         }
576 // since we don't have subwindows we have to terminate any drag operation
577         if(result)
578         {
579                 if (mwindow->session->track_highlighted
580                         || mwindow->session->edit_highlighted
581                         || mwindow->session->plugin_highlighted
582                         || mwindow->session->pluginset_highlighted) 
583                         redraw = 1;
584                 mwindow->session->track_highlighted = 0;
585                 mwindow->session->edit_highlighted = 0;
586                 mwindow->session->plugin_highlighted = 0;
587                 mwindow->session->pluginset_highlighted = 0;
588                 mwindow->session->current_operation = NO_OPERATION;
589         }
592 //printf("TrackCanvas::drag_stop %d %d\n", redraw, mwindow->session->current_operation);
593         if(redraw)
594         {
595                 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
596                 gui->get_scrollbars();
597                 draw();
598                 gui->patchbay->update();
599                 gui->cursor->update();
600                 flash();
601                 flush();
602         }
604         return result;
608 void TrackCanvas::draw(int force, int hide_cursor)
610 // Swap pixmap layers
611 TRACE("TrackCanvas::draw 1")
612         if(get_w() != background_pixmap->get_w() ||
613                 get_h() != background_pixmap->get_h())
614         {
615                 delete background_pixmap;
616                 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
617         }
619 TRACE("TrackCanvas::draw 10")
620 // Cursor disappears after resize when this is called.
621 // Cursor doesn't redraw after editing when this isn't called.
622         if(gui->cursor && hide_cursor) gui->cursor->hide();
623 TRACE("TrackCanvas::draw 20")
624         draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
625 TRACE("TrackCanvas::draw 30")
626         draw_resources(force);
627 TRACE("TrackCanvas::draw 40")
628         draw_overlays();
629 UNTRACE
632 void TrackCanvas::update_cursor()
634         switch(mwindow->edl->session->editing_mode)
635         {
636                 case EDITING_ARROW: set_cursor(ARROW_CURSOR); break;
637                 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR); break;
638         }
642 void TrackCanvas::draw_indexes(Asset *asset)
644 // Don't redraw raw samples
645         if(asset->index_zoom > mwindow->edl->local_session->zoom_sample)
646                 return;
648         draw_resources(0, 1, asset);
650         draw_overlays();
651         draw_automation();
652         flash();
653         flush();
656 void TrackCanvas::draw_resources(int force, 
657         int indexes_only, 
658         Asset *index_asset)
660 // Age resource pixmaps for deletion
661         if(!indexes_only)
662                 for(int i = 0; i < resource_pixmaps.total; i++)
663                         resource_pixmaps.values[i]->visible--;
665         if(force)
666                 resource_pixmaps.remove_all_objects();
668 //printf("TrackCanvas::draw_resources 1 %d %d\n", force, indexes_only);
670 // Search every edit
671         for(Track *current = mwindow->edl->tracks->first;
672                 current;
673                 current = NEXT)
674         {
675 //printf("TrackCanvas::draw_resources 2\n");
676                 for(Edit *edit = current->edits->first; edit; edit = edit->next)
677                 {
678 //printf("TrackCanvas::draw_resources 3\n");
679                         if(!edit->asset) continue;
680 //printf("TrackCanvas::draw_resources 4\n");
681                         if(indexes_only)
682                         {
683                                 if(edit->track->data_type != TRACK_AUDIO) continue;
684                                 if(!edit->asset->test_path(index_asset->path)) continue;
685                         }
687                         int64_t edit_x, edit_y, edit_w, edit_h;
688                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
689 //printf("TrackCanvas::draw_resources 10\n");
691 // Edit is visible
692                         if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
693                                 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
694                         {
695                                 int64_t pixmap_x, pixmap_w, pixmap_h;
697 //printf("TrackCanvas::draw_resources 20\n");
698 // Search for existing pixmap containing edit
699                                 for(int i = 0; i < resource_pixmaps.total; i++)
700                                 {
701                                         ResourcePixmap* pixmap = resource_pixmaps.values[i];
702 //printf("TrackCanvas::draw_resources 30\n");
703 // Same pointer can be different edit if editing took place
704                                         if(pixmap->edit_id == edit->id)
705                                         {
706 //printf("TrackCanvas::draw_resources 40\n");
707                                                 pixmap->visible = 1;
708                                                 break;
709                                         }
710 //printf("TrackCanvas::draw_resources 50\n");
711                                 }
713 // Get new size, offset of pixmap needed
714                                 get_pixmap_size(edit, 
715                                         edit_x, 
716                                         edit_w, 
717                                         pixmap_x, 
718                                         pixmap_w, 
719                                         pixmap_h);
720 //printf("TrackCanvas::draw_resources 60\n");
722 // Draw new data
723                                 if(pixmap_w && pixmap_h)
724                                 {
725 // Create pixmap if it doesn't exist
726                                         ResourcePixmap* pixmap = create_pixmap(edit, 
727                                                 edit_x, 
728                                                 pixmap_x, 
729                                                 pixmap_w, 
730                                                 pixmap_h);
731 //printf("TrackCanvas::draw_resources 70\n");
732 // Resize it if it's bigger
733                                         if(pixmap_w > pixmap->pixmap_w ||
734                                                 pixmap_h > pixmap->pixmap_h)
735                                                 pixmap->resize(pixmap_w, pixmap_h);
736 //printf("TrackCanvas::draw_resources 80\n");
737                                         pixmap->draw_data(edit,
738                                                 edit_x, 
739                                                 edit_w, 
740                                                 pixmap_x, 
741                                                 pixmap_w, 
742                                                 pixmap_h, 
743                                                 force,
744                                                 indexes_only);
745 //printf("TrackCanvas::draw_resources 90\n");
746 // Resize it if it's smaller
747                                         if(pixmap_w < pixmap->pixmap_w ||
748                                                 pixmap_h < pixmap->pixmap_h)
749                                                 pixmap->resize(pixmap_w, pixmap_h);
750 //printf("TrackCanvas::draw_resources 100\n");
751 // Copy pixmap to background canvas
752                                         background_pixmap->draw_pixmap(pixmap, 
753                                                 pixmap->pixmap_x, 
754                                                 current->y_pixel,
755                                                 pixmap->pixmap_w,
756                                                 edit_h);
757 //printf("TrackCanvas::draw_resources 110\n");
758                                 }
759                         }
760                 }
761         }
762 //printf("TrackCanvas::draw_resources 200\n");
764 // Delete unused pixmaps
765         if(!indexes_only)
766                 for(int i = resource_pixmaps.total - 1; i >= 0; i--)
767                         if(resource_pixmaps.values[i]->visible < -5)
768                         {
769                                 delete resource_pixmaps.values[i];
770                                 resource_pixmaps.remove(resource_pixmaps.values[i]);
771                         }
774 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit, 
775         int64_t edit_x, 
776         int64_t pixmap_x, 
777         int64_t pixmap_w, 
778         int64_t pixmap_h)
780         ResourcePixmap *result = 0;
782         for(int i = 0; i < resource_pixmaps.total; i++)
783         {
784 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
785                 if(resource_pixmaps.values[i]->edit_id == edit->id) 
786                 {
787                         result = resource_pixmaps.values[i];
788                         break;
789                 }
790         }
792         if(!result)
793         {
794 //printf("TrackCanvas::create_pixmap 2\n");
795                 result = new ResourcePixmap(mwindow, 
796                         this, 
797                         edit, 
798                         pixmap_w, 
799                         pixmap_h);
800                 resource_pixmaps.append(result);
801         }
803 //      result->resize(pixmap_w, pixmap_h);
804         return result;
807 void TrackCanvas::get_pixmap_size(Edit *edit, 
808         int64_t edit_x, 
809         int64_t edit_w, 
810         int64_t &pixmap_x, 
811         int64_t &pixmap_w,
812         int64_t &pixmap_h)
815 // Align x on frame boundaries
818 //      switch(edit->edits->track->data_type)
819 //      {
820 //              case TRACK_AUDIO:
822                         pixmap_x = edit_x;
823                         pixmap_w = edit_w;
824                         if(pixmap_x < 0)
825                         {
826                                 pixmap_w -= -edit_x;
827                                 pixmap_x = 0;
828                         }
830                         if(pixmap_x + pixmap_w > get_w())
831                         {
832                                 pixmap_w = get_w() - pixmap_x;
833                         }
835 //                      break;
836 // 
837 //              case TRACK_VIDEO:
838 //              {
839 //                      int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
840 //                      int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
841 //                      int64_t pixel_increment = MAX(picon_w, frame_w);
842 //                      int64_t pixmap_x1 = edit_x;
843 //                      int64_t pixmap_x2 = edit_x + edit_w;
844 // 
845 //                      if(pixmap_x1 < 0)
846 //                      {
847 //                              pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) * 
848 //                                      pixel_increment + 
849 //                                      edit_x;
850 //                      }
851 // 
852 //                      if(pixmap_x2 > get_w())
853 //                      {
854 //                              pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) * 
855 //                                      pixel_increment + 
856 //                                      edit_x;
857 //                      }
858 //                      pixmap_x = pixmap_x1;
859 //                      pixmap_w = pixmap_x2 - pixmap_x1;
860 //                      break;
861 //              }
862 //      }
864         pixmap_h = mwindow->edl->local_session->zoom_track;
865         if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->title_bg_data->get_h();
866 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
869 void TrackCanvas::edit_dimensions(Edit *edit, 
870         int64_t &x, 
871         int64_t &y, 
872         int64_t &w, 
873         int64_t &h)
875 //printf("TrackCanvas::edit_dimensions 1 %p\n", edit->track);
876         w = Units::round(edit->track->from_units(edit->length) * 
877                 mwindow->edl->session->sample_rate / 
878                 mwindow->edl->local_session->zoom_sample);
879 //printf("TrackCanvas::edit_dimensions 1\n");
881         h = resource_h();
883 //printf("TrackCanvas::edit_dimensions 1\n");
884         x = Units::round(edit->track->from_units(edit->startproject) * 
885                         mwindow->edl->session->sample_rate /
886                         mwindow->edl->local_session->zoom_sample - 
887                         mwindow->edl->local_session->view_start);
889 //printf("TrackCanvas::edit_dimensions 1\n");
890         y = edit->edits->track->y_pixel;
891 //printf("TrackCanvas::edit_dimensions 1\n");
893         if(mwindow->edl->session->show_titles) 
894                 h += mwindow->theme->title_bg_data->get_h();
895 //printf("TrackCanvas::edit_dimensions 2\n");
898 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
900         x = 0;
901         w = get_w();
902         y = track->y_pixel;
903         h = track->vertical_span(mwindow->theme);
907 void TrackCanvas::draw_paste_destination()
909         int current_atrack = 0;
910         int current_vtrack = 0;
911         int current_aedit = 0;
912         int current_vedit = 0;
913         int64_t w = 0;
914         int64_t x;
915         double position;
917 //printf("TrackCanvas::draw_paste_destination 1\n");
918         if((mwindow->session->current_operation == DRAG_ASSET &&
919                         (mwindow->session->drag_assets->total ||
920                         mwindow->session->drag_clips->total)) ||
921                 (mwindow->session->current_operation == DRAG_EDIT &&
922                         mwindow->session->drag_edits->total))
923         {
924 //printf("TrackCanvas::draw_paste_destination 1\n");
925                 Asset *asset = 0;
926                 EDL *clip = 0;
927                 int draw_box = 0;
929                 if(mwindow->session->current_operation == DRAG_ASSET &&
930                         mwindow->session->drag_assets->total)
931                         asset = mwindow->session->drag_assets->values[0];
933                 if(mwindow->session->current_operation == DRAG_ASSET &&
934                         mwindow->session->drag_clips->total)
935                         clip = mwindow->session->drag_clips->values[0];
937 // Get destination track
938                 for(Track *dest = mwindow->session->track_highlighted; 
939                         dest; 
940                         dest = dest->next)
941                 {
942                         if(dest->record)
943                         {
944 // Get source width in pixels
945                                 w = 0;
948 // Use start of highlighted edit
949                                 if(mwindow->session->edit_highlighted)
950                                         position = mwindow->session->track_highlighted->from_units(
951                                                 mwindow->session->edit_highlighted->startproject);
952                                 else
953 // Use end of highlighted track, disregarding effects
954                                         position = mwindow->session->track_highlighted->from_units(
955                                                 mwindow->session->track_highlighted->edits->length());
957 // Get the x coordinate
958                                 x = Units::to_int64(position * 
959                                         mwindow->edl->session->sample_rate /
960                                         mwindow->edl->local_session->zoom_sample) - 
961                                         mwindow->edl->local_session->view_start;
963                                 if(dest->data_type == TRACK_AUDIO)
964                                 {
965                                         if(asset && current_atrack < asset->channels)
966                                         {
967                                                 w = Units::to_int64((double)asset->audio_length /
968                                                         asset->sample_rate *
969                                                         mwindow->edl->session->sample_rate / 
970                                                         mwindow->edl->local_session->zoom_sample);
971                                                 current_atrack++;
972                                                 draw_box = 1;
973                                         }
974                                         else
975                                         if(clip && current_atrack < clip->tracks->total_audio_tracks())
976                                         {
977                                                 w = Units::to_int64((double)clip->tracks->total_length() *
978                                                         mwindow->edl->session->sample_rate / 
979                                                         mwindow->edl->local_session->zoom_sample);
980 //printf("draw_paste_destination %d\n", x);
981                                                 current_atrack++;
982                                                 draw_box = 1;
983                                         }
984                                         else
985                                         if(mwindow->session->current_operation == DRAG_EDIT &&
986                                                 current_aedit < mwindow->session->drag_edits->total)
987                                         {
988                                                 Edit *edit;
989                                                 while(current_aedit < mwindow->session->drag_edits->total &&
990                                                         mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
991                                                         current_aedit++;
993                                                 if(current_aedit < mwindow->session->drag_edits->total)
994                                                 {
995                                                         edit = mwindow->session->drag_edits->values[current_aedit];
996                                                         w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
998                                                         current_aedit++;
999                                                         draw_box = 1;
1000                                                 }
1001                                         }
1002                                 }
1003                                 else
1004                                 if(dest->data_type == TRACK_VIDEO)
1005                                 {
1006 //printf("draw_paste_destination 1\n");
1007                                         if(asset && current_vtrack < asset->layers)
1008                                         {
1009                                                 w = Units::to_int64((double)asset->video_length / 
1010                                                         asset->frame_rate *
1011                                                         mwindow->edl->session->sample_rate /
1012                                                         mwindow->edl->local_session->zoom_sample);
1013                                                 current_vtrack++;
1014                                                 draw_box = 1;
1015                                         }
1016                                         else
1017                                         if(clip && current_vtrack < clip->tracks->total_video_tracks())
1018                                         {
1019                                                 w = Units::to_int64(clip->tracks->total_length() *
1020                                                         mwindow->edl->session->sample_rate / 
1021                                                         mwindow->edl->local_session->zoom_sample);
1022                                                 current_vtrack++;
1023                                                 draw_box = 1;
1024                                         }
1025                                         else
1026                                         if(mwindow->session->current_operation == DRAG_EDIT &&
1027                                                 current_vedit < mwindow->session->drag_edits->total)
1028                                         {
1029 //printf("draw_paste_destination 2\n");
1030                                                 Edit *edit;
1031                                                 while(current_vedit < mwindow->session->drag_edits->total &&
1032                                                         mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1033                                                         current_vedit++;
1035                                                 if(current_vedit < mwindow->session->drag_edits->total)
1036                                                 {
1037 //printf("draw_paste_destination 3\n");
1038                                                         edit = mwindow->session->drag_edits->values[current_vedit];
1039                                                         w = Units::to_int64(edit->track->from_units(edit->length) *
1040                                                                 mwindow->edl->session->sample_rate / 
1041                                                                 mwindow->edl->local_session->zoom_sample);
1043                                                         current_vedit++;
1044                                                         draw_box = 1;
1045                                                 }
1046                                         }
1047                                 }
1049                                 if(w)
1050                                 {
1051                                         int y = dest->y_pixel;
1052                                         int h = dest->vertical_span(mwindow->theme);
1055 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1056                                         if(x < -BC_INFINITY)
1057                                         {
1058                                                 w -= -BC_INFINITY - x;
1059                                                 x += -BC_INFINITY - x;
1060                                         }
1061                                         w = MIN(65535, w);
1062                                         draw_highlight_rectangle(x, y, w, h);
1063                                 }
1064                         }
1065                 }
1066         }
1069 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1071         x = Units::round(plugin->track->from_units(plugin->startproject) *
1072                 mwindow->edl->session->sample_rate / 
1073                 mwindow->edl->local_session->zoom_sample - 
1074                 mwindow->edl->local_session->view_start);
1075         w = Units::round(plugin->track->from_units(plugin->length) *
1076                 mwindow->edl->session->sample_rate / 
1077                 mwindow->edl->local_session->zoom_sample);
1078         y = plugin->track->y_pixel + 
1079                         mwindow->edl->local_session->zoom_track +
1080                         plugin->plugin_set->get_number() * 
1081                         mwindow->theme->plugin_bg_data->get_h();
1082         if(mwindow->edl->session->show_titles)
1083                 y += mwindow->theme->title_bg_data->get_h();
1084         h = mwindow->theme->plugin_bg_data->get_h();
1087 int TrackCanvas::resource_h()
1089         return mwindow->edl->local_session->zoom_track;
1092 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1094         if(x < -10)
1095         {
1096                 w += x - -10;
1097                 x = -10;
1098         }
1099         if(y < -10)
1100         {
1101                 h += y - -10;
1102                 y = -10;
1103         }
1104         w = MIN(w, get_w() + 20);
1105         h = MIN(h, get_h() + 20);
1106         set_color(WHITE);
1107         set_inverse();
1108         draw_rectangle(x, y, w, h);
1109         draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1110         set_opaque();
1111 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d\n", x, y, w, h);
1114 void TrackCanvas::draw_playback_cursor()
1116 // Called before playback_cursor exists
1117 //      if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1118 //      {
1119 //              mwindow->playback_cursor->visible = 0;
1120 //              mwindow->playback_cursor->draw();
1121 //      }
1124 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1126         int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1127         int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1129         edit_dimensions(edit, x, y, w, h);
1131         if(mwindow->edl->session->show_titles)
1132         {
1133                 y += mwindow->theme->title_bg_data->get_h();
1134         }
1135         else
1136         {
1137                 y = 0;
1138         }
1140         if(side == EDIT_OUT)
1141         {
1142                 x += w - handle_w;
1143         }
1145         h = handle_h;
1146         w = handle_w;
1149 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1151 //printf("TrackCanvas::get_transition_coords 1\n");
1152 //      int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1153 //      int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1154         int transition_w = 30;
1155         int transition_h = 30;
1156 //printf("TrackCanvas::get_transition_coords 1\n");
1158         if(mwindow->edl->session->show_titles)
1159                 y += mwindow->theme->title_bg_data->get_h();
1160 //printf("TrackCanvas::get_transition_coords 2\n");
1162         y += (h - mwindow->theme->title_bg_data->get_h()) / 2 - transition_h / 2;
1163         x -= transition_w / 2;
1165         h = transition_h;
1166         w = transition_w;
1169 void TrackCanvas::draw_highlighting()
1171         int64_t x, y, w, h;
1172         int draw_box = 0;
1173 //printf("TrackCanvas::draw_highlighting 1 %p %d\n", mwindow->session->track_highlighted, mwindow->session->current_operation);
1177         switch(mwindow->session->current_operation)
1178         {
1179                 case DRAG_ATRANSITION:
1180                 case DRAG_VTRANSITION:
1181 //printf("TrackCanvas::draw_highlighting 1 %p %p\n", 
1182 //      mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1183                         if(mwindow->session->edit_highlighted)
1184                         {
1185 //printf("TrackCanvas::draw_highlighting 2\n");
1186                                 if((mwindow->session->current_operation == DRAG_ATRANSITION && 
1187                                         mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1188                                         (mwindow->session->current_operation == DRAG_VTRANSITION && 
1189                                         mwindow->session->track_highlighted->data_type == TRACK_VIDEO))
1190                                 {
1191 //printf("TrackCanvas::draw_highlighting 2\n");
1192                                         edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1193 //printf("TrackCanvas::draw_highlighting 2\n");
1195                                         if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1196                                                 MWindowGUI::visible(y, y + h, 0, get_h()))
1197                                         {
1198                                                 draw_box = 1;
1199                                                 get_transition_coords(x, y, w, h);
1200                                         }
1201 //printf("TrackCanvas::draw_highlighting 3\n");
1202                                 }
1203                         }
1204                         break;
1208 // Dragging a new effect from the Resource window
1209                 case DRAG_AEFFECT:
1210                 case DRAG_VEFFECT:
1211                         if(mwindow->session->track_highlighted &&
1212                                 ((mwindow->session->current_operation == DRAG_AEFFECT && mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1213                                         (mwindow->session->current_operation == DRAG_VEFFECT && mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
1214                         {
1215 // Put it before another plugin
1216                                 if(mwindow->session->plugin_highlighted)
1217                                 {
1218                                         plugin_dimensions(mwindow->session->plugin_highlighted, 
1219                                                 x, 
1220                                                 y, 
1221                                                 w, 
1222                                                 h);
1223 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1224                                 }
1225                                 else
1226 // Put it after a plugin set
1227                                 if(mwindow->session->pluginset_highlighted &&
1228                                         mwindow->session->pluginset_highlighted->last)
1229                                 {
1230                                         plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last, 
1231                                                 x, 
1232                                                 y, 
1233                                                 w, 
1234                                                 h);
1235 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1236                                         int64_t track_x, track_y, track_w, track_h;
1237                                         track_dimensions(mwindow->session->track_highlighted, 
1238                                                 track_x, 
1239                                                 track_y, 
1240                                                 track_w, 
1241                                                 track_h);
1243                                         x += w;
1244                                         w = Units::round(
1245                                                         mwindow->session->track_highlighted->get_length() *
1246                                                         mwindow->edl->session->sample_rate / 
1247                                                         mwindow->edl->local_session->zoom_sample - 
1248                                                         mwindow->edl->local_session->view_start) -
1249                                                 x;
1250 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1251                                         if(w <= 0) w = track_w;
1252                                 }
1253                                 else
1254                                 {
1255                                         track_dimensions(mwindow->session->track_highlighted, 
1256                                                 x, 
1257                                                 y, 
1258                                                 w, 
1259                                                 h);
1261 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1262 // Put it in a new plugin set determined by the selected range
1263                                         if(mwindow->edl->local_session->get_selectionend() > 
1264                                                 mwindow->edl->local_session->get_selectionstart())
1265                                         {
1266                                                 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1267                                                         mwindow->edl->session->sample_rate / 
1268                                                         mwindow->edl->local_session->zoom_sample -
1269                                                         mwindow->edl->local_session->view_start);
1270                                                 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() - 
1271                                                         mwindow->edl->local_session->get_selectionstart()) *
1272                                                         mwindow->edl->session->sample_rate / 
1273                                                         mwindow->edl->local_session->zoom_sample);
1274                                         }
1275 // Put it in a new plugin set determined by an edit boundary
1276                                         else
1277                                         if(mwindow->session->edit_highlighted)
1278                                         {
1279                                                 int64_t temp_y, temp_h;
1280                                                 edit_dimensions(mwindow->session->edit_highlighted, 
1281                                                         x, 
1282                                                         temp_y, 
1283                                                         w, 
1284                                                         temp_h);
1285                                         }
1286 // Put it at the beginning of the track in a new plugin set
1287                                 }
1289                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1290                                         MWindowGUI::visible(y, y + h, 0, get_h()))
1291                                 {
1292 //printf("TrackCanvas::draw_highlighting 1\n");
1293                                         draw_box = 1;
1294                                 }
1295                         }
1296                         break;
1297                 
1298                 case DRAG_ASSET:
1299                         if(mwindow->session->track_highlighted)
1300                         {
1301                                 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1303                                 if(MWindowGUI::visible(y, y + h, 0, get_h()))
1304                                 {
1305                                         draw_paste_destination();
1306                                 }
1307                         }
1308                         break;
1310 // Dragging an effect from the timeline
1311                 case DRAG_AEFFECT_COPY:
1312                 case DRAG_VEFFECT_COPY:
1313                         if((mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1314                                 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY && mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1315                                 (mwindow->session->current_operation == DRAG_VEFFECT_COPY && mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
1316                         {
1317 // Put it before another plugin
1318                                 if(mwindow->session->plugin_highlighted)
1319                                         plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1320                                 else
1321 // Put it after a plugin set
1322                                 if(mwindow->session->pluginset_highlighted &&
1323                                         mwindow->session->pluginset_highlighted->last)
1324                                 {
1325                                         plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last, x, y, w, h);
1326                                         x += w;
1327                                 }
1328                                 else
1329                                 if(mwindow->session->track_highlighted)
1330                                 {
1331                                         track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1333 // Put it in a new plugin set determined by an edit boundary
1334                                         if(mwindow->session->edit_highlighted)
1335                                         {
1336                                                 int64_t temp_y, temp_h;
1337                                                 edit_dimensions(mwindow->session->edit_highlighted, 
1338                                                         x, 
1339                                                         temp_y, 
1340                                                         w, 
1341                                                         temp_h);
1342                                         }
1343 // Put it in a new plugin set at the start of the track
1344                                 }
1346 // Calculate length of plugin based on data type of track and units
1347                                 if(mwindow->session->track_highlighted->data_type == TRACK_VIDEO)
1348                                 {
1349                                         w = (int64_t)((double)mwindow->session->drag_plugin->length / 
1350                                                 mwindow->edl->session->frame_rate *
1351                                                 mwindow->edl->session->sample_rate /
1352                                                 mwindow->edl->local_session->zoom_sample);
1353                                 }
1354                                 else
1355                                 {
1356                                         w = (int64_t)mwindow->session->drag_plugin->length /
1357                                                 mwindow->edl->local_session->zoom_sample;
1358                                 }
1360                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1361                                         MWindowGUI::visible(y, y + h, 0, get_h()))
1362                                 {
1363                                         draw_box = 1;
1364                                 }
1366                         }
1367                         break;
1369                 case DRAG_EDIT:
1370 //printf("TrackCanvas::draw_highlighting 1\n");
1371                         if(mwindow->session->track_highlighted)
1372                         {
1373                                 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1375                                 if(MWindowGUI::visible(y, y + h, 0, get_h()))
1376                                 {
1377                                         draw_paste_destination();
1378                                 }
1379                         }
1382                         break;
1383         }
1386         if(draw_box)
1387         {
1388                 draw_highlight_rectangle(x, y, w, h);
1389         }
1392 void TrackCanvas::draw_plugins()
1394         char string[BCTEXTLEN];
1396         for(Track *track = mwindow->edl->tracks->first;
1397                 track;
1398                 track = track->next)
1399         {
1400                 if(track->expand_view)
1401                 {
1402                         for(int i = 0; i < track->plugin_set.total; i++)
1403                         {
1404                                 PluginSet *pluginset = track->plugin_set.values[i];
1406                                 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1407                                 {
1408                                         int64_t total_x, y, total_w, h;
1409                                         plugin_dimensions(plugin, total_x, y, total_w, h);
1410                                         
1411                                         if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1412                                                 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1413                                                 plugin->plugin_type != PLUGIN_NONE)
1414                                         {
1415                                                 int x = total_x, w = total_w, left_margin = 5;
1416                                                 if(x < 0)
1417                                                 {
1418                                                         w -= -x;
1419                                                         x = 0;
1420                                                 }
1421                                                 if(w + x > get_w()) w -= (w + x) - get_w();
1423                                                 draw_3segmenth(x, 
1424                                                         y, 
1425                                                         w, 
1426                                                         total_x,
1427                                                         total_w,
1428                                                         mwindow->theme->plugin_bg_data,
1429                                                         0);
1430                                                 set_color(WHITE);
1431                                                 set_font(MEDIUMFONT_3D);
1432                                                 plugin->calculate_title(string, 0);
1434 // Truncate string to int64_test visible in background
1435                                                 int len = strlen(string), j;
1436                                                 for(j = len; j >= 0; j--)
1437                                                 {
1438                                                         if(left_margin + get_text_width(MEDIUMFONT_3D, string) > w)
1439                                                         {
1440                                                                 string[j] = 0;
1441                                                         }
1442                                                         else
1443                                                                 break;
1444                                                 }
1446 // Justify the text on the left boundary of the edit if it is visible.
1447 // Otherwise justify it on the left side of the screen.
1448                                                 int text_x = total_x + left_margin;
1449                                                 text_x = MAX(left_margin, text_x);
1450                                                 draw_text(text_x, 
1451                                                         y + get_text_ascent(MEDIUMFONT_3D) + 2, 
1452                                                         string,
1453                                                         strlen(string),
1454                                                         0);
1455                                         }
1456                                 }
1457                         }
1458                 }
1459         }
1463 void TrackCanvas::draw_inout_points()
1468 void TrackCanvas::draw_drag_handle()
1470         if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1471                 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1472         {
1473 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1474                 int64_t pixel1 = Units::round(mwindow->session->drag_position * 
1475                         mwindow->edl->session->sample_rate /
1476                         mwindow->edl->local_session->zoom_sample - 
1477                         mwindow->edl->local_session->view_start);
1478 //printf("TrackCanvas::draw_drag_handle 2 %d\n", pixel1);
1479                 set_color(GREEN);
1480                 set_inverse();
1481 //printf("TrackCanvas::draw_drag_handle 3\n");
1482                 draw_line(pixel1, 0, pixel1, get_h());
1483                 set_opaque();
1484 //printf("TrackCanvas::draw_drag_handle 4\n");
1485         }
1489 void TrackCanvas::draw_transitions()
1491         int64_t x, y, w, h;
1493         for(Track *track = mwindow->edl->tracks->first;
1494                 track;
1495                 track = track->next)
1496         {
1497                 for(Edit *edit = track->edits->first;
1498                         edit;
1499                         edit = edit->next)
1500                 {
1501                         if(edit->transition)
1502                         {
1503                                 int64_t strip_w, strip_x, strip_y;
1504                                 edit_dimensions(edit, x, y, w, h);
1505                                 strip_x = x ;
1506                                 strip_y = y;
1507                                 if(mwindow->edl->session->show_titles)
1508                                         strip_y += mwindow->theme->title_bg_data->get_h();
1510                                 get_transition_coords(x, y, w, h);
1511                                 strip_w = Units::round(edit->track->from_units(edit->transition->length) * 
1512                                         mwindow->edl->session->sample_rate / 
1513                                         mwindow->edl->local_session->zoom_sample);
1515                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1516                                         MWindowGUI::visible(y, y + h, 0, get_h()))
1517                                 {
1518                                         PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1519                                                 track->data_type);
1520                                         draw_vframe(server->picon, 
1521                                                 x, 
1522                                                 y, 
1523                                                 w, 
1524                                                 h, 
1525                                                 0, 
1526                                                 0, 
1527                                                 server->picon->get_w(), 
1528                                                 server->picon->get_h());
1529                                 }
1530                                 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1531                                         MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1532                                 {
1533                                         int x = strip_x, w = strip_w, left_margin = 5;
1534                                         if(x < 0)
1535                                         {
1536                                                 w -= -x;
1537                                                 x = 0;
1538                                         }
1539                                         if(w + x > get_w()) w -= (w + x) - get_w();
1540                                 
1541                                         draw_3segmenth(
1542                                                 x, 
1543                                                 strip_y, 
1544                                                 w, 
1545                                                 strip_x,
1546                                                 strip_w,
1547                                                 mwindow->theme->plugin_bg_data,
1548                                                 0);
1550                                 }
1551                         }
1552                 }
1553         }
1556 void TrackCanvas::draw_loop_points()
1558 //printf("TrackCanvas::draw_loop_points 1\n");
1559         if(mwindow->edl->local_session->loop_playback)
1560         {
1561 //printf("TrackCanvas::draw_loop_points 2\n");
1562                 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1563                         mwindow->edl->session->sample_rate /
1564                         mwindow->edl->local_session->zoom_sample - 
1565                         mwindow->edl->local_session->view_start);
1566 //printf("TrackCanvas::draw_loop_points 3\n");
1568                 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1569                 {
1570                         set_color(GREEN);
1571                         draw_line(x, 0, x, get_h());
1572                 }
1573 //printf("TrackCanvas::draw_loop_points 4\n");
1575                 x = Units::round(mwindow->edl->local_session->loop_end *
1576                         mwindow->edl->session->sample_rate /
1577                         mwindow->edl->local_session->zoom_sample - 
1578                         mwindow->edl->local_session->view_start);
1579 //printf("TrackCanvas::draw_loop_points 5\n");
1581                 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1582                 {
1583                         set_color(GREEN);
1584                         draw_line(x, 0, x, get_h());
1585                 }
1586 //printf("TrackCanvas::draw_loop_points 6\n");
1587         }
1588 //printf("TrackCanvas::draw_loop_points 7\n");
1591 void TrackCanvas::draw_brender_start()
1593         if(mwindow->preferences->use_brender)
1594         {
1595                 int64_t x = Units::round(mwindow->edl->session->brender_start *
1596                         mwindow->edl->session->sample_rate /
1597                         mwindow->edl->local_session->zoom_sample - 
1598                         mwindow->edl->local_session->view_start);
1600                 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1601                 {
1602                         set_color(RED);
1603                         draw_line(x, 0, x, get_h());
1604                 }
1605         }
1608 int TrackCanvas::do_keyframes(int cursor_x, 
1609         int cursor_y, 
1610         int draw, 
1611         int buttonpress, 
1612         int &new_cursor,
1613         int &update_cursor,
1614         int &rerender)
1616         int current_tool = 0;
1617         int result = 0;
1618         EDLSession *session = mwindow->edl->session;
1620         for(Track *track = mwindow->edl->tracks->first;
1621                 track && !result;
1622                 track = track->next)
1623         {
1624                 Automation *automation = track->automation;
1626 //printf("TrackCanvas::draw_keyframes 1\n");
1627                 if(!result && session->auto_conf->fade)
1628                 {
1629                         result = do_float_autos(track, 
1630                                 automation->fade_autos,
1631                                 cursor_x, 
1632                                 cursor_y, 
1633                                 draw, 
1634                                 buttonpress, 
1635                                 WHITE);
1636                         if(result && mwindow->session->current_operation == DRAG_FADE)
1637                         {
1638                                 rerender = 1;
1639                         }
1640                         if(result && buttonpress)
1641                         {
1642                                 synchronize_autos(0, track, (FloatAuto*)mwindow->session->drag_auto, 1);
1643                                 mwindow->session->current_operation = DRAG_FADE;
1644                                 update_drag_caption();
1645                         }
1646                 }
1648 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1650                 if(!result && session->auto_conf->czoom && automation->czoom_autos)
1651                 {
1652                         result = do_float_autos(track, 
1653                                 automation->czoom_autos,
1654                                 cursor_x, 
1655                                 cursor_y, 
1656                                 draw, 
1657                                 buttonpress,
1658                                 MEPURPLE);
1659                         if(result && mwindow->session->current_operation == DRAG_CZOOM)
1660                         {
1661                                 rerender = 1;
1662                         }
1663                         if(result && buttonpress)
1664                         {
1665                                 mwindow->session->current_operation = DRAG_CZOOM;
1666                                 update_drag_caption();
1667                         }
1668                 }
1670 //printf("TrackCanvas::draw_keyframes 2 %d\n", result);
1671                 if(!result && session->auto_conf->pzoom && automation->pzoom_autos)
1672                 {
1673                         result = do_float_autos(track, 
1674                                 automation->pzoom_autos,
1675                                 cursor_x, 
1676                                 cursor_y, 
1677                                 draw, 
1678                                 buttonpress,
1679                                 PINK);
1680                         if(result && mwindow->session->current_operation == DRAG_PZOOM)
1681                         {
1682                                 rerender = 1;
1683                         }
1684                         if(result && buttonpress)
1685                         {
1686                                 mwindow->session->current_operation = DRAG_PZOOM;
1687                                 update_drag_caption();
1688                         }
1689                 }
1691 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1692                 if(!result && session->auto_conf->mute)
1693                 {
1694                         result = do_toggle_autos(track, 
1695                                 automation->mute_autos,
1696                                 cursor_x, 
1697                                 cursor_y, 
1698                                 draw, 
1699                                 buttonpress,
1700                                 BLUE);
1701                         if(result && mwindow->session->current_operation == DRAG_MUTE)
1702                         {
1703                                 rerender = 1;
1704                         }
1705                         if(result && buttonpress)
1706                         {
1707                                 mwindow->session->current_operation = DRAG_MUTE;
1708                                 update_drag_caption();
1709                         }
1710                 }
1712 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1713                 if(!result && session->auto_conf->camera && automation->camera_autos)
1714                 {
1715                         result = do_autos(track, 
1716                                 automation->camera_autos,
1717                                 cursor_x, 
1718                                 cursor_y, 
1719                                 draw, 
1720                                 buttonpress,
1721                                 camerakeyframe_pixmap);
1722                         if(result && mwindow->session->current_operation == DRAG_CAMERA)
1723                         {
1724                                 rerender = 1;
1725                         }
1726                         if(result && buttonpress)
1727                         {
1728                                 mwindow->session->current_operation = DRAG_CAMERA_PRE;
1729                                 update_drag_caption();
1730                                 rerender = 1;
1731                         }
1732                 }
1734                 if(!result && session->auto_conf->mode && automation->mode_autos)
1735                 {
1736                         result = do_autos(track, 
1737                                 automation->mode_autos,
1738                                 cursor_x, 
1739                                 cursor_y, 
1740                                 draw, 
1741                                 buttonpress,
1742                                 modekeyframe_pixmap);
1743                         if(result && mwindow->session->current_operation == DRAG_MODE)
1744                         {
1745                                 rerender = 1;
1746                         }
1747                         if(result && buttonpress)
1748                         {
1749                                 mwindow->session->current_operation = DRAG_MODE_PRE;
1750                                 update_drag_caption();
1751                                 rerender = 1;
1752                         }
1753                 }
1755 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1756                 if(!result && session->auto_conf->projector && automation->projector_autos)
1757                 {
1758                         result = do_autos(track, 
1759                                 automation->projector_autos,
1760                                 cursor_x, 
1761                                 cursor_y, 
1762                                 draw, 
1763                                 buttonpress,
1764                                 projectorkeyframe_pixmap);
1765                         if(result && mwindow->session->current_operation == DRAG_PROJECTOR)
1766                         {
1767                                 rerender = 1;
1768                         }
1769                         if(result && buttonpress)
1770                         {
1771                                 mwindow->session->current_operation = DRAG_PROJECTOR_PRE;
1772                                 update_drag_caption();
1773                                 rerender = 1;
1774                         }
1775                 }
1777                 if(!result && session->auto_conf->mask && automation->mask_autos)
1778                 {
1779                         result = do_autos(track, 
1780                                 automation->mask_autos,
1781                                 cursor_x, 
1782                                 cursor_y, 
1783                                 draw, 
1784                                 buttonpress,
1785                                 maskkeyframe_pixmap);
1786                         if(result && mwindow->session->current_operation == DRAG_MASK)
1787                         {
1788                                 rerender = 1;
1789                         }
1790                         if(result && buttonpress)
1791                         {
1792                                 mwindow->session->current_operation = DRAG_MASK_PRE;
1793                                 update_drag_caption();
1794                                 rerender = 1;
1795                         }
1796                 }
1798 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1799                 if(!result && session->auto_conf->pan && automation->pan_autos)
1800                 {
1801                         result = do_autos(track, 
1802                                 automation->pan_autos,
1803                                 cursor_x, 
1804                                 cursor_y, 
1805                                 draw, 
1806                                 buttonpress,
1807                                 pankeyframe_pixmap);
1808                         if(result && mwindow->session->current_operation == DRAG_PAN)
1809                         {
1810                                 rerender = 1;
1811                         }
1812                         if(result && buttonpress)
1813                         {
1814                                 mwindow->session->current_operation = DRAG_PAN_PRE;
1815                                 update_drag_caption();
1816                                 rerender = 1;
1817                         }
1818                 }
1820 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1821                 if(!result && session->auto_conf->plugins)
1822                 {
1823                         Plugin *plugin;
1824                         KeyFrame *keyframe;
1825                         result = do_plugin_autos(track,
1826                                 cursor_x, 
1827                                 cursor_y, 
1828                                 draw, 
1829                                 buttonpress,
1830                                 plugin,
1831                                 keyframe);
1832                         if(result && mwindow->session->current_operation == DRAG_PLUGINKEY)
1833                         {
1834                                 rerender = 1;
1835                         }
1836                         if(result && (buttonpress == 1))
1837                         {
1838                                 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
1839                                 update_drag_caption();
1840                                 rerender = 1;
1841                         } else
1842                         if (result && (buttonpress == 3))
1843                         {
1844                                 gui->keyframe_menu->update(plugin, keyframe);
1845                                 gui->keyframe_menu->activate_menu();
1846                                 rerender = 1; // the position changes
1847                         }
1848                         else
1849                         if(result && (buttonpress == 3))
1850                         {
1851                                 gui->keyframe_menu->update(plugin, keyframe);
1852                                 gui->keyframe_menu->activate_menu();
1853                                 rerender = 1; // the position changes
1854                         }
1855                 }
1856 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1857         }
1859         if(mwindow->session->current_operation == DRAG_FADE ||
1860                 mwindow->session->current_operation == DRAG_CZOOM ||
1861                 mwindow->session->current_operation == DRAG_PZOOM ||
1862                 mwindow->session->current_operation == DRAG_PLAY ||
1863                 mwindow->session->current_operation == DRAG_MUTE ||
1864                 mwindow->session->current_operation == DRAG_CAMERA ||
1865                 mwindow->session->current_operation == DRAG_CAMERA_PRE ||
1866                 mwindow->session->current_operation == DRAG_MASK ||
1867                 mwindow->session->current_operation == DRAG_MASK_PRE ||
1868                 mwindow->session->current_operation == DRAG_MODE ||
1869                 mwindow->session->current_operation == DRAG_MODE_PRE ||
1870                 mwindow->session->current_operation == DRAG_PAN ||
1871                 mwindow->session->current_operation == DRAG_PAN_PRE ||
1872                 mwindow->session->current_operation == DRAG_PLUGINKEY ||
1873                 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE ||
1874                 mwindow->session->current_operation == DRAG_PROJECTOR ||
1875                 mwindow->session->current_operation == DRAG_PROJECTOR_PRE)
1876         {
1877                 result = 1;
1878         }
1880 //printf("TrackCanvas::draw_keyframes 2 %d\n", result);
1881         update_cursor = 1;
1882         if(result)
1883         {
1884                 new_cursor = UPRIGHT_ARROW_CURSOR;
1885 //              rerender = 1;
1886         }
1888 //printf("TrackCanvas::do_keyframes 3 %d\n", result);
1889         return result;
1892 void TrackCanvas::draw_auto(Auto *current, 
1893         int x, 
1894         int y, 
1895         int center_pixel, 
1896         int zoom_track,
1897         int color)
1899         int x1, y1, x2, y2;
1900         char string[BCTEXTLEN];
1902         x1 = x - HANDLE_W / 2;
1903         x2 = x + HANDLE_W / 2;
1904         y1 = center_pixel + y - HANDLE_W / 2;
1905         y2 = center_pixel + y + HANDLE_W / 2;
1907         if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
1908         if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
1910         set_color(BLACK);
1911         draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
1912         set_color(color);
1913         draw_box(x1, y1, x2 - x1, y2 - y1);
1916 void TrackCanvas::draw_floatauto(Auto *current, 
1917         int x, 
1918         int y, 
1919         int in_x, 
1920         int in_y, 
1921         int out_x, 
1922         int out_y, 
1923         int center_pixel, 
1924         int zoom_track,
1925         int color)
1927         int x1, y1, x2, y2;
1928         int in_x1, in_y1, in_x2, in_y2;
1929         int out_x1, out_y1, out_x2, out_y2;
1930         char string[BCTEXTLEN];
1932 // Center
1933         x1 = x - HANDLE_W / 2;
1934         x2 = x + HANDLE_W / 2;
1935         y1 = center_pixel + y - HANDLE_W / 2;
1936         y2 = center_pixel + y + HANDLE_W / 2;
1938         CLAMP(y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1939         CLAMP(y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1941         set_color(BLACK);
1942         draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
1943         set_color(color);
1944         draw_box(x1, y1, x2 - x1, y2 - y1);
1946 // In handle
1947         in_x1 = in_x - HANDLE_W / 2;
1948         in_x2 = in_x + HANDLE_W / 2;
1949         in_y1 = center_pixel + in_y - HANDLE_W / 2;
1950         in_y2 = center_pixel + in_y + HANDLE_W / 2;
1952         CLAMP(in_y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1953         CLAMP(in_y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1954         CLAMP(in_y, -zoom_track / 2, zoom_track / 2);
1956         set_color(BLACK);
1957         draw_line(x + 1, center_pixel + y + 1, in_x + 1, center_pixel + in_y + 1);
1958         draw_box(in_x1 + 1, in_y1 + 1, in_x2 - in_x1, in_y2 - in_y1);
1959         set_color(color);
1960         draw_line(x, center_pixel + y, in_x, center_pixel + in_y);
1961         draw_box(in_x1, in_y1, in_x2 - in_x1, in_y2 - in_y1);
1965 // Out handle
1966         out_x1 = out_x - HANDLE_W / 2;
1967         out_x2 = out_x + HANDLE_W / 2;
1968         out_y1 = center_pixel + out_y - HANDLE_W / 2;
1969         out_y2 = center_pixel + out_y + HANDLE_W / 2;
1971         CLAMP(out_y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1972         CLAMP(out_y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
1973         CLAMP(out_y, -zoom_track / 2, zoom_track / 2);
1976         set_color(BLACK);
1977         draw_line(x + 1, center_pixel + y + 1, out_x + 1, center_pixel + out_y + 1);
1978         draw_box(out_x1 + 1, out_y1 + 1, out_x2 - out_x1, out_y2 - out_y1);
1979         set_color(color);
1980         draw_line(x, center_pixel + y, out_x, center_pixel + out_y);
1981         draw_box(out_x1, out_y1, out_x2 - out_x1, out_y2 - out_y1);
1985 int TrackCanvas::test_auto(Auto *current, 
1986         int x, 
1987         int y, 
1988         int center_pixel, 
1989         int zoom_track, 
1990         int cursor_x, 
1991         int cursor_y, 
1992         int buttonpress)
1994         int x1, y1, x2, y2;
1995         char string[BCTEXTLEN];
1996         int result = 0;
1998         x1 = x - HANDLE_W / 2;
1999         x2 = x + HANDLE_W / 2;
2000         y1 = center_pixel + y - HANDLE_W / 2;
2001         y2 = center_pixel + y + HANDLE_W / 2;
2003         if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2004         if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2005 //printf("test_auto 1 %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2007         if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2008         {
2009 //printf("test_auto 2 %d\n", buttonpress);
2010                 if(buttonpress)
2011                 {
2012 //printf("test_auto 3\n");
2013                         mwindow->session->drag_auto = current;
2014                         mwindow->session->drag_start_percentage = current->value_to_percentage();
2015                         mwindow->session->drag_start_position = current->position;
2016                         mwindow->session->drag_origin_x = cursor_x;
2017                         mwindow->session->drag_origin_y = cursor_y;
2018                 }
2019                 result = 1;
2020         }
2022         return result;
2025 int TrackCanvas::test_floatauto(Auto *current, 
2026         int x, 
2027         int y, 
2028         int in_x,
2029         int in_y,
2030         int out_x,
2031         int out_y,
2032         int center_pixel, 
2033         int zoom_track, 
2034         int cursor_x, 
2035         int cursor_y, 
2036         int buttonpress)
2038         int x1, y1, x2, y2;
2039         int in_x1, in_y1, in_x2, in_y2;
2040         int out_x1, out_y1, out_x2, out_y2;
2041         char string[BCTEXTLEN];
2042         int result = 0;
2044         x1 = x - HANDLE_W / 2;
2045         x2 = x + HANDLE_W / 2;
2046         y1 = center_pixel + y - HANDLE_W / 2;
2047         y2 = center_pixel + y + HANDLE_W / 2;
2049         if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2050         if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2052         in_x1 = in_x - HANDLE_W / 2;
2053         in_x2 = in_x + HANDLE_W / 2;
2054         in_y1 = center_pixel + in_y - HANDLE_W / 2;
2055         in_y2 = center_pixel + in_y + HANDLE_W / 2;
2057         if(in_y1 < center_pixel + -zoom_track / 2) in_y1 = center_pixel + -zoom_track / 2;
2058         if(in_y2 > center_pixel + zoom_track / 2) in_y2 = center_pixel + zoom_track / 2;
2060         out_x1 = out_x - HANDLE_W / 2;
2061         out_x2 = out_x + HANDLE_W / 2;
2062         out_y1 = center_pixel + out_y - HANDLE_W / 2;
2063         out_y2 = center_pixel + out_y + HANDLE_W / 2;
2065         if(out_y1 < center_pixel + -zoom_track / 2) out_y1 = center_pixel + -zoom_track / 2;
2066         if(out_y2 > center_pixel + zoom_track / 2) out_y2 = center_pixel + zoom_track / 2;
2070 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2071 // Test value
2072         if(!ctrl_down() &&
2073                 cursor_x >= x1 && 
2074                 cursor_x < x2 && 
2075                 cursor_y >= y1 && 
2076                 cursor_y < y2)
2077         {
2078                 if(buttonpress)
2079                 {
2080                         mwindow->session->drag_auto = current;
2081                         mwindow->session->drag_start_percentage = current->value_to_percentage();
2082                         mwindow->session->drag_start_position = current->position;
2083                         mwindow->session->drag_origin_x = cursor_x;
2084                         mwindow->session->drag_origin_y = cursor_y;
2085                         mwindow->session->drag_handle = 0;
2086                 }
2087                 result = 1;
2088         }
2089         else
2090 // Test in control
2091         if(ctrl_down() &&
2092                 cursor_x >= in_x1 && 
2093                 cursor_x < in_x2 && 
2094                 cursor_y >= in_y1 && 
2095                 cursor_y < in_y2 &&
2096                 current->position > 0)
2097         {
2098                 if(buttonpress)
2099                 {
2100                         mwindow->session->drag_auto = current;
2101                         mwindow->session->drag_start_percentage = 
2102                                 current->invalue_to_percentage();
2103                         mwindow->session->drag_start_position = 
2104                                 ((FloatAuto*)current)->control_in_position;
2105                         mwindow->session->drag_origin_x = cursor_x;
2106                         mwindow->session->drag_origin_y = cursor_y;
2107                         mwindow->session->drag_handle = 1;
2108                 }
2109                 result = 1;
2110         }
2111         else
2112 // Test out control
2113         if(ctrl_down() &&
2114                 cursor_x >= out_x1 && 
2115                 cursor_x < out_x2 && 
2116                 cursor_y >= out_y1 && 
2117                 cursor_y < out_y2)
2118         {
2119                 if(buttonpress)
2120                 {
2121                         mwindow->session->drag_auto = current;
2122                         mwindow->session->drag_start_percentage = 
2123                                 current->outvalue_to_percentage();
2124                         mwindow->session->drag_start_position = 
2125                                 ((FloatAuto*)current)->control_out_position;
2126                         mwindow->session->drag_origin_x = cursor_x;
2127                         mwindow->session->drag_origin_y = cursor_y;
2128                         mwindow->session->drag_handle = 2;
2129                 }
2130                 result = 1;
2131         }
2133 // if(buttonpress) 
2134 // 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", 
2135 // mwindow->session->drag_handle,
2136 // ctrl_down(),
2137 // cursor_x,
2138 // cursor_y,
2139 // x1, x2, y1, y2);
2141         return result;
2144 void TrackCanvas::draw_floatline(int center_pixel, 
2145         FloatAuto *previous,
2146         FloatAuto *next,
2147         FloatAutos *autos,
2148         int64_t unit_start,
2149         double zoom_units,
2150         double yscale,
2151         int x1,
2152         int y1,
2153         int x2,
2154         int y2,
2155         int color)
2157 // Solve bezier equation for either every pixel or a certain large number of
2158 // points.
2162 // Not using slope intercept
2163         x1 = MAX(0, x1);
2168         int prev_y;
2169 // Call by reference fails for some reason here
2170         FloatAuto *previous1 = previous, *next1 = next;
2171         for(int x = x1; x < x2; x++)
2172         {
2173                 int64_t position = (int64_t)(unit_start + x * zoom_units);
2174                 float value = autos->get_value(position, PLAY_FORWARD, previous1, next1);
2176                 int y = (int)(center_pixel + 
2177                         (autos->value_to_percentage(value) - 0.5) * -yscale);
2179                 if(x > x1)
2180                 {
2181                         set_color(BLACK);
2182                         draw_line(x - 1, prev_y + 1, x, y + 1);
2183                         set_color(color);
2184                         draw_line(x - 1, prev_y, x, y);
2185                 }
2186                 prev_y = y;
2187         }
2191 //      set_color(BLACK);
2192 //      draw_line(x1, center_pixel + y1 + 1, x2, center_pixel + y2 + 1);
2193 //      set_color(WHITE);
2194 //      draw_line(x1, center_pixel + y1, x2, center_pixel + y2);
2202 void TrackCanvas::synchronize_autos(float change, Track *skip, FloatAuto *fauto, int fill_gangs)
2204         if (fill_gangs == 1 && skip->gang) // fill mwindow->session->drag_auto_gang
2205         {
2206                 for(Track *current = mwindow->edl->tracks->first;
2207                         current;
2208                         current = NEXT)
2209                 {
2210                         if(current->data_type == skip->data_type &&
2211                                 current->gang && 
2212                                 current->record && 
2213                                 current != skip)
2214                         {
2215                                 FloatAutos *fade_autos = current->automation->fade_autos;
2216                                 double position = skip->from_units(fauto->position);
2217                                 int tmp_cursor_on_frames = mwindow->edl->session->cursor_on_frames;
2218                                 mwindow->edl->session->cursor_on_frames = 0;
2219                                 FloatAuto *previous = 0, *next = 0;
2220                                 float init_value = fade_autos->get_value(fauto->position, PLAY_FORWARD, previous, next);
2222                                 int update_undo = !fade_autos->auto_exists_for_editing(position);
2223                                 
2224                                 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_for_editing(position);
2225                                 mwindow->edl->session->cursor_on_frames = tmp_cursor_on_frames;         
2226                                 if (update_undo)
2227                                         keyframe->value = init_value;
2228                                 else
2229                                         keyframe->value += change;              
2230                                 keyframe->position = fauto->position;
2231                                 keyframe->control_out_position = fauto->control_out_position;
2232                                 keyframe->control_in_position = fauto->control_in_position;
2233                                 keyframe->control_out_value = fauto->control_out_value;
2234                                 keyframe->control_in_value = fauto->control_in_value;
2236                                 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2237                         }
2238                 }
2239         } else 
2240         if (fill_gangs == 0)      // move the gangs
2241         {
2243                 // Move the gang!
2244                 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++)
2245                 {
2246                         FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2247                         
2248                         keyframe->value += change;
2249                         keyframe->position = fauto->position;
2250                         if(skip->data_type == TRACK_AUDIO)
2251                                 CLAMP(keyframe->value, INFINITYGAIN, MAX_AUDIO_FADE);
2252                         else
2253                                 CLAMP(keyframe->value, 0, MAX_VIDEO_FADE);
2254                         keyframe->control_out_position = fauto->control_out_position;
2255                         keyframe->control_in_position = fauto->control_in_position;
2256                         keyframe->control_out_value = fauto->control_out_value;
2257                         keyframe->control_in_value = fauto->control_in_value;
2258                 } 
2260         } else
2261         if (fill_gangs == -1)      // remove the gangs
2262         {
2263                 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++)
2264                 {
2265                         FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2266                         keyframe->autos->remove_nonsequential(
2267                                         keyframe);
2268                 } 
2269                 mwindow->session->drag_auto_gang->remove_all();
2270         }
2274 int TrackCanvas::test_floatline(int center_pixel, 
2275                 FloatAutos *autos,
2276                 int64_t unit_start,
2277                 double zoom_units,
2278                 double yscale,
2279                 int x1,
2280                 int x2,
2281                 int cursor_x, 
2282                 int cursor_y, 
2283                 int buttonpress)
2285         int result = 0;
2288         int64_t position = (int64_t)(unit_start + cursor_x * zoom_units);
2289 // Call by reference fails for some reason here
2290         FloatAuto *previous = 0, *next = 0;
2291         float value = autos->get_value(position, PLAY_FORWARD, previous, next);
2292         int y = (int)(center_pixel + 
2293                 (autos->value_to_percentage(value) - 0.5) * -yscale);
2295         if(cursor_x >= x1 && 
2296                 cursor_x < x2 &&
2297                 cursor_y >= y - HANDLE_W / 2 && 
2298                 cursor_y < y + HANDLE_W / 2 &&
2299                 !ctrl_down())
2300         {
2301                 result = 1;
2304                 if(buttonpress)
2305                 {
2306                         mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
2309                         Auto *current;
2310                         current = mwindow->session->drag_auto = autos->insert_auto(position);
2311                         ((FloatAuto*)current)->value = value;
2312                         mwindow->session->drag_start_percentage = current->value_to_percentage();
2313                         mwindow->session->drag_start_position = current->position;
2314                         mwindow->session->drag_origin_x = cursor_x;
2315                         mwindow->session->drag_origin_y = cursor_y;
2316                         mwindow->session->drag_handle = 0;
2318                 }
2319         }
2322         return result;
2325 void TrackCanvas::draw_toggleline(int center_pixel, 
2326         int x1,
2327         int y1,
2328         int x2,
2329         int y2,
2330         int color)
2332         set_color(BLACK);
2333         draw_line(x1, center_pixel + y1 + 1, x2, center_pixel + y1 + 1);
2334         set_color(color);
2335         draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2337         if(y2 != y1)
2338         {
2339                 set_color(BLACK);
2340                 draw_line(x2 + 1, center_pixel + y1, x2 + 1, center_pixel + y2);
2341                 set_color(color);
2342                 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2343         }
2346 int TrackCanvas::test_toggleline(Autos *autos,
2347         int center_pixel, 
2348         int x1,
2349         int y1,
2350         int x2,
2351         int y2, 
2352         int cursor_x, 
2353         int cursor_y, 
2354         int buttonpress)
2356         int result = 0;
2357         if(cursor_x >= x1 && cursor_x < x2)
2358         {
2359                 int miny = center_pixel + y1 - HANDLE_W / 2;
2360                 int maxy = center_pixel + y1 + HANDLE_W / 2;
2361                 if(cursor_y >= miny && cursor_y < maxy) 
2362                 {
2363                         result = 1;
2365                         if(buttonpress)
2366                         {
2367                                 mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
2370                                 Auto *current;
2371                                 double position = (double)(cursor_x +
2372                                                 mwindow->edl->local_session->view_start) * 
2373                                         mwindow->edl->local_session->zoom_sample / 
2374                                         mwindow->edl->session->sample_rate;
2375                                 int64_t unit_position = autos->track->to_units(position, 0);
2376                                 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2378                                 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2379                                 ((IntAuto*)current)->value = new_value;
2380                                 mwindow->session->drag_start_percentage = current->value_to_percentage();
2381                                 mwindow->session->drag_start_position = current->position;
2382                                 mwindow->session->drag_origin_x = cursor_x;
2383                                 mwindow->session->drag_origin_y = cursor_y;
2385                         }
2386                 }
2387         }
2388         return result;
2391 void TrackCanvas::calculate_viewport(Track *track, 
2392         double &view_start,   // Seconds
2393         int64_t &unit_start,
2394         double &view_end,     // Seconds
2395         int64_t &unit_end,
2396         double &yscale,
2397         int &center_pixel,
2398         double &zoom_sample,
2399         double &zoom_units)
2401         view_start = (double)mwindow->edl->local_session->view_start * 
2402                 mwindow->edl->local_session->zoom_sample /
2403                 mwindow->edl->session->sample_rate;
2404         unit_start = track->to_units(view_start, 0);
2405         view_end = (double)(mwindow->edl->local_session->view_start + 
2406                 get_w()) * 
2407                 mwindow->edl->local_session->zoom_sample / 
2408                 mwindow->edl->session->sample_rate;
2409         unit_end = (int64_t)(track->to_units(view_end, 1));
2410         yscale = mwindow->edl->local_session->zoom_track;
2411         center_pixel = (int)(track->y_pixel + yscale / 2) + 
2412                 (mwindow->edl->session->show_titles ? 
2413                         mwindow->theme->title_bg_data->get_h() : 
2414                         0);
2415         zoom_sample = mwindow->edl->local_session->zoom_sample;
2417         zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2420 int TrackCanvas::do_float_autos(Track *track, 
2421                 Autos *autos, 
2422                 int cursor_x, 
2423                 int cursor_y, 
2424                 int draw, 
2425                 int buttonpress,
2426                 int color)
2428         int result = 0;
2430         double view_start;
2431         int64_t unit_start;
2432         double view_end;
2433         int64_t unit_end;
2434         double yscale;
2435         int center_pixel;
2436         double zoom_sample;
2437         double zoom_units;
2438         double ax, ay, ax2, ay2;
2439         double in_x2, in_y2, out_x2, out_y2;
2440         int draw_auto;
2441         double slope;
2442         int skip = 0;
2444         calculate_viewport(track, 
2445                 view_start,
2446                 unit_start,
2447                 view_end,
2448                 unit_end,
2449                 yscale,
2450                 center_pixel,
2451                 zoom_sample,
2452                 zoom_units);
2456 // Get first auto before start
2457         Auto *current = 0;
2458         Auto *previous = 0;
2459         for(current = autos->last; 
2460                 current && current->position >= unit_start; 
2461                 current = PREVIOUS)
2462                 ;
2464         if(current)
2465         {
2466                 ax = (double)(current->position - unit_start) / zoom_units;
2467                 ay = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2468                 current = NEXT;
2469         }
2470         else
2471         {
2472                 current = autos->first ? autos->first : autos->default_auto;
2473                 if(current)
2474                 {               
2475                         ax = 0;
2476                         ay = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2477                 }
2478                 else
2479                 {
2480                         ax = 0;
2481                         ay = 0;
2482                 }
2483         }
2486 //printf("TrackCanvas::do_float_autos 1\n");
2490         do
2491         {
2492                 skip = 0;
2493                 draw_auto = 1;
2495                 if(current)
2496                 {
2497                         ax2 = (double)(current->position - unit_start) / zoom_units;
2498                         ay2 = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2499                         in_x2 = (double)(current->position + 
2500                                 ((FloatAuto*)current)->control_in_position - 
2501                                 unit_start) / 
2502                                 zoom_units;
2503                         in_y2 = (((FloatAuto*)current)->invalue_to_percentage() - 0.5) * -yscale;
2504                         out_x2 = (double)(current->position + 
2505                                 ((FloatAuto*)current)->control_out_position - 
2506                                 unit_start) / 
2507                                 zoom_units;
2508                         out_y2 = (((FloatAuto*)current)->outvalue_to_percentage() - 0.5) * -yscale;
2509                 }
2510                 else
2511                 {
2512                         ax2 = get_w();
2513                         ay2 = ay;
2514                         skip = 1;
2515                 }
2517                 slope = (ay2 - ay) / (ax2 - ax);
2519                 if(ax2 > get_w())
2520                 {
2521                         draw_auto = 0;
2522                         ax2 = get_w();
2523                         ay2 = ay + slope * (get_w() - ax);
2524                 }
2525                 
2526                 if(ax < 0)
2527                 {
2528                         ay = ay + slope * (0 - ax);
2529                         ax = 0;
2530                 }
2545 // Draw handle
2546                 if(current && !result)
2547                 {
2548                         if(current != autos->default_auto)
2549                         {
2550                                 if(!draw)
2551                                 {
2552                                         if(track->record)
2553                                                 result = test_floatauto(current, 
2554                                                         (int)ax2, 
2555                                                         (int)ay2, 
2556                                                         (int)in_x2,
2557                                                         (int)in_y2,
2558                                                         (int)out_x2,
2559                                                         (int)out_y2,
2560                                                         (int)center_pixel, 
2561                                                         (int)yscale, 
2562                                                         cursor_x, 
2563                                                         cursor_y, 
2564                                                         buttonpress);
2565                                 }
2566                                 else
2567                                 if(draw_auto)
2568                                         draw_floatauto(current, 
2569                                                 (int)ax2, 
2570                                                 (int)ay2, 
2571                                                 (int)in_x2,
2572                                                 (int)in_y2,
2573                                                 (int)out_x2,
2574                                                 (int)out_y2,
2575                                                 (int)center_pixel, 
2576                                                 (int)yscale,
2577                                                 color);
2578                         }
2579                 }
2585 // Draw joining line
2586                 if(!draw)
2587                 {
2588                         if(!result)
2589                         {
2590                                 if(track->record)
2591                                 {
2592                                         result = test_floatline(center_pixel, 
2593                                                 (FloatAutos*)autos,
2594                                                 unit_start,
2595                                                 zoom_units,
2596                                                 yscale,
2597                                                 (int)ax,
2598 // Exclude auto coverage from the end of the line.  The auto overlaps
2599                                                 (int)ax2 - HANDLE_W / 2,
2600                                                 cursor_x, 
2601                                                 cursor_y, 
2602                                                 buttonpress);
2603                                 }
2604                         }
2605                 }
2606                 else
2607                         draw_floatline(center_pixel,
2608                                 (FloatAuto*)previous,
2609                                 (FloatAuto*)current,
2610                                 (FloatAutos*)autos,
2611                                 unit_start,
2612                                 zoom_units,
2613                                 yscale,
2614                                 (int)ax, 
2615                                 (int)ay, 
2616                                 (int)ax2, 
2617                                 (int)ay2,
2618                                 color);
2626                 if(current)
2627                 {
2628                         previous = current;
2629                         current = NEXT;
2630                 }
2634                 ax = ax2;
2635                 ay = ay2;
2636         }while(current && 
2637                 current->position <= unit_end && 
2638                 !result);
2640 //printf("TrackCanvas::do_float_autos 100\n");
2649         if(ax < get_w() && !result)
2650         {
2651                 ax2 = get_w();
2652                 ay2 = ay;
2653                 if(!draw)
2654                 {
2655                         if(track->record)
2656                         {
2657                                 result = test_floatline(center_pixel, 
2658                                         (FloatAutos*)autos,
2659                                         unit_start,
2660                                         zoom_units,
2661                                         yscale,
2662                                         (int)ax,
2663                                         (int)ax2,
2664                                         cursor_x, 
2665                                         cursor_y, 
2666                                         buttonpress);
2667                         }
2668                 }
2669                 else
2670                         draw_floatline(center_pixel, 
2671                                 (FloatAuto*)previous,
2672                                 (FloatAuto*)current,
2673                                 (FloatAutos*)autos,
2674                                 unit_start,
2675                                 zoom_units,
2676                                 yscale,
2677                                 (int)ax, 
2678                                 (int)ay, 
2679                                 (int)ax2, 
2680                                 (int)ay2,
2681                                 color);
2682         }
2691         return result;
2695 int TrackCanvas::do_toggle_autos(Track *track, 
2696                 Autos *autos, 
2697                 int cursor_x, 
2698                 int cursor_y, 
2699                 int draw, 
2700                 int buttonpress,
2701                 int color)
2703         int result = 0;
2704         double view_start;
2705         int64_t unit_start;
2706         double view_end;
2707         int64_t unit_end;
2708         double yscale;
2709         int center_pixel;
2710         double zoom_sample;
2711         double zoom_units;
2712         double ax, ay, ax2, ay2;
2714         calculate_viewport(track, 
2715                 view_start,
2716                 unit_start,
2717                 view_end,
2718                 unit_end,
2719                 yscale,
2720                 center_pixel,
2721                 zoom_sample,
2722                 zoom_units);
2725         double high = -yscale * 0.8 / 2;
2726         double low = yscale * 0.8 / 2;
2728 // Get first auto before start
2729         Auto *current;
2730         for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
2731                 ;
2733         if(current)
2734         {
2735                 ax = 0;
2736                 ay = ((IntAuto*)current)->value > 0 ? high : low;
2737                 current = NEXT;
2738         }
2739         else
2740         {
2741                 current = autos->first ? autos->first : autos->default_auto;
2742                 if(current)
2743                 {
2744                         ax = 0;
2745                         ay = ((IntAuto*)current)->value > 0 ? high : low;
2746                 }
2747                 else
2748                 {
2749                         ax = 0;
2750                         ay = yscale;
2751                 }
2752         }
2754         do
2755         {
2756                 if(current)
2757                 {
2758                         ax2 = (double)(current->position - unit_start) / zoom_units;
2759                         ay2 = ((IntAuto*)current)->value > 0 ? high : low;
2760                 }
2761                 else
2762                 {
2763                         ax2 = get_w();
2764                         ay2 = ay;
2765                 }
2767                 if(ax2 > get_w()) ax2 = get_w();
2769             if(current && !result) 
2770                 {
2771                         if(current != autos->default_auto)
2772                         {
2773                                 if(!draw)
2774                                 {
2775                                         if(track->record)
2776                                         {
2777                                                 result = test_auto(current, 
2778                                                         (int)ax2, 
2779                                                         (int)ay2, 
2780                                                         (int)center_pixel, 
2781                                                         (int)yscale, 
2782                                                         cursor_x, 
2783                                                         cursor_y, 
2784                                                         buttonpress);
2785                                         }
2786                                 }
2787                                 else
2788                                         draw_auto(current, 
2789                                                 (int)ax2, 
2790                                                 (int)ay2, 
2791                                                 (int)center_pixel, 
2792                                                 (int)yscale,
2793                                                 color);
2794                         }
2796                         current = NEXT;
2797                 }
2799                 if(!draw)
2800                 {
2801                         if(!result)
2802                         {
2803                                 if(track->record)
2804                                 {
2805                                         result = test_toggleline(autos, 
2806                                                 center_pixel, 
2807                                                 (int)ax, 
2808                                                 (int)ay, 
2809                                                 (int)ax2, 
2810                                                 (int)ay2,
2811                                                 cursor_x, 
2812                                                 cursor_y, 
2813                                                 buttonpress);
2814                                 }
2815                         }
2816                 }
2817                 else
2818                         draw_toggleline(center_pixel, 
2819                                 (int)ax, 
2820                                 (int)ay, 
2821                                 (int)ax2, 
2822                                 (int)ay2,
2823                                 color);
2825                 ax = ax2;
2826                 ay = ay2;
2827         }while(current && current->position <= unit_end && !result);
2829         if(ax < get_w() && !result)
2830         {
2831                 ax2 = get_w();
2832                 ay2 = ay;
2833                 if(!draw)
2834                 {
2835                         if(track->record)
2836                         {
2837                                 result = test_toggleline(autos,
2838                                         center_pixel, 
2839                                         (int)ax, 
2840                                         (int)ay, 
2841                                         (int)ax2, 
2842                                         (int)ay2,
2843                                         cursor_x, 
2844                                         cursor_y, 
2845                                         buttonpress);
2846                         }
2847                 }
2848                 else
2849                         draw_toggleline(center_pixel, 
2850                                 (int)ax, 
2851                                 (int)ay, 
2852                                 (int)ax2, 
2853                                 (int)ay2,
2854                                 color);
2855         }
2856         return result;
2859 int TrackCanvas::do_autos(Track *track, 
2860                 Autos *autos, 
2861                 int cursor_x, 
2862                 int cursor_y, 
2863                 int draw, 
2864                 int buttonpress,
2865                 BC_Pixmap *pixmap)
2867         int result = 0;
2869         double view_start;
2870         int64_t unit_start;
2871         double view_end;
2872         int64_t unit_end;
2873         double yscale;
2874         int center_pixel;
2875         double zoom_sample;
2876         double zoom_units;
2878         calculate_viewport(track, 
2879                 view_start,
2880                 unit_start,
2881                 view_end,
2882                 unit_end,
2883                 yscale,
2884                 center_pixel,
2885                 zoom_sample,
2886                 zoom_units);
2888         Auto *current;
2890         for(current = autos->first; current && !result; current = NEXT)
2891         {
2892                 if(current->position >= unit_start && current->position < unit_end)
2893                 {
2894                         int64_t x, y;
2895                         x = (int64_t)((double)(current->position - unit_start) / 
2896                                 zoom_units - (pixmap->get_w() / 2 + 0.5));
2897                         y = center_pixel - pixmap->get_h() / 2;
2899                         if(!draw)
2900                         {
2901                                 if(cursor_x >= x && cursor_y >= y &&
2902                                         cursor_x < x + pixmap->get_w() &&
2903                                         cursor_y < y + pixmap->get_h())
2904                                 {
2905                                         result = 1;
2907                                         if(buttonpress)
2908                                         {
2909                                                 mwindow->session->drag_auto = current;
2910                                                 mwindow->session->drag_start_position = current->position;
2911                                                 mwindow->session->drag_origin_x = cursor_x;
2912                                                 mwindow->session->drag_origin_y = cursor_y;
2914                                                 double position = autos->track->from_units(current->position);
2915                                                 double center = (mwindow->edl->local_session->selectionstart +
2916                                                         mwindow->edl->local_session->selectionend) / 
2917                                                         2;
2919                                                 if(!shift_down())
2920                                                 {
2921                                                         mwindow->edl->local_session->selectionstart = position;
2922                                                         mwindow->edl->local_session->selectionend = position;
2923                                                 }
2924                                                 else
2925                                                 if(position < center)
2926                                                 {
2927                                                         mwindow->edl->local_session->selectionstart = position;
2928                                                 }
2929                                                 else
2930                                                         mwindow->edl->local_session->selectionend = position;
2931                                         }
2932                                 }
2933                         }
2934                         else
2935                                 draw_pixmap(pixmap, x, y);
2936                 }
2937         }
2938         return result;
2941 // so this means it is always >0 when keyframe is found 
2942 int TrackCanvas::do_plugin_autos(Track *track, 
2943                 int cursor_x, 
2944                 int cursor_y, 
2945                 int draw, 
2946                 int buttonpress,
2947                 Plugin* &keyframe_plugin,
2948                 KeyFrame* &keyframe_instance)
2950         int result = 0;
2952         double view_start;
2953         int64_t unit_start;
2954         double view_end;
2955         int64_t unit_end;
2956         double yscale;
2957         int center_pixel;
2958         double zoom_sample;
2959         double zoom_units;
2961         calculate_viewport(track, 
2962                 view_start,
2963                 unit_start,
2964                 view_end,
2965                 unit_end,
2966                 yscale,
2967                 center_pixel,
2968                 zoom_sample,
2969                 zoom_units);
2971 //printf("TrackCanvas::draw_plugin_autos 1 %d\n", track->plugin_set.total);
2972         for(int i = 0; i < track->plugin_set.total && !result; i++)
2973         {
2974                 PluginSet *plugin_set = track->plugin_set.values[i];
2975                 int center_pixel = (int)(track->y_pixel + 
2976                         mwindow->edl->local_session->zoom_track +
2977                         (i + 0.5) * mwindow->theme->plugin_bg_data->get_h() + 
2978                         (mwindow->edl->session->show_titles ? mwindow->theme->title_bg_data->get_h() : 0));
2979                 
2980 //printf("TrackCanvas::draw_plugin_autos 2\n");
2981                 for(Plugin *plugin = (Plugin*)plugin_set->first; 
2982                         plugin && !result; 
2983                         plugin = (Plugin*)plugin->next)
2984                 {
2985                         for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first; 
2986                                 keyframe && !result; 
2987                                 keyframe = (KeyFrame*)keyframe->next)
2988                         {
2989 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
2990                                 if(keyframe->position >= unit_start && keyframe->position < unit_end)
2991                                 {
2992                                         int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
2993                                         int y = center_pixel - keyframe_pixmap->get_h() / 2;
2995 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
2996                                         if(!draw)
2997                                         {
2998                                                 if(cursor_x >= x && cursor_y >= y &&
2999                                                         cursor_x < x + keyframe_pixmap->get_w() &&
3000                                                         cursor_y < y + keyframe_pixmap->get_h())
3001                                                 {
3002                                                         result = 1;
3003                                                         keyframe_plugin = plugin;
3004                                                         keyframe_instance = keyframe;
3006                                                         if(buttonpress)
3007                                                         {
3008                                                                 mwindow->session->drag_auto = keyframe;
3009                                                                 mwindow->session->drag_start_position = keyframe->position;
3010                                                                 mwindow->session->drag_origin_x = cursor_x;
3011                                                                 mwindow->session->drag_origin_y = cursor_y;
3013                                                                 double position = track->from_units(keyframe->position);
3014                                                                 double center = (mwindow->edl->local_session->selectionstart +
3015                                                                         mwindow->edl->local_session->selectionend) / 
3016                                                                         2;
3018                                                                 if(!shift_down())
3019                                                                 {
3020                                                                         mwindow->edl->local_session->selectionstart = position;
3021                                                                         mwindow->edl->local_session->selectionend = position;
3022                                                                 }
3023                                                                 else
3024                                                                 if(position < center)
3025                                                                 {
3026                                                                         mwindow->edl->local_session->selectionstart = position;
3027                                                                 }
3028                                                                 else
3029                                                                         mwindow->edl->local_session->selectionend = position;
3030                                                         }
3031                                                 }
3032                                         }
3033                                         else
3034                                                 draw_pixmap(keyframe_pixmap, 
3035                                                         x, 
3036                                                         y);
3037                                 }
3038                         }
3039                 }
3040         }
3041 //printf("TrackCanvas::draw_plugin_autos 5\n");
3042         return result;
3045 void TrackCanvas::draw_overlays()
3047         int new_cursor, update_cursor, rerender;
3048 TRACE("TrackCanvas::draw_overlays 1")
3050 // Move background pixmap to foreground pixmap
3051         draw_pixmap(background_pixmap, 
3052                 0, 
3053                 0,
3054                 get_w(),
3055                 get_h(),
3056                 0,
3057                 0);
3058 TRACE("TrackCanvas::draw_overlays 10")
3060 // In/Out points
3061         draw_inout_points();
3063 TRACE("TrackCanvas::draw_overlays 11");
3064 // Transitions
3065         if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3067 TRACE("TrackCanvas::draw_overlays 12");
3068 // Plugins
3069         draw_plugins();
3071 TRACE("TrackCanvas::draw_overlays 13");
3072 // Loop points
3073         draw_loop_points();
3074         draw_brender_start();
3076 TRACE("TrackCanvas::draw_overlays 14");
3077 // Highlighted areas
3078         draw_highlighting();
3080 TRACE("TrackCanvas::draw_overlays 15");
3081 // Automation
3082         do_keyframes(0, 
3083                 0, 
3084                 1, 
3085                 0, 
3086                 new_cursor, 
3087                 update_cursor,
3088                 rerender);
3090 TRACE("TrackCanvas::draw_overlays 16\n");
3091 // Selection cursor
3092         if(gui->cursor) gui->cursor->restore();
3094 TRACE("TrackCanvas::draw_overlays 17\n");
3095 // Handle dragging
3096         draw_drag_handle();
3098 TRACE("TrackCanvas::draw_overlays 20");
3099 // Playback cursor
3100         draw_playback_cursor();
3104 int TrackCanvas::activate()
3106         if(!active)
3107         {
3108                 get_top_level()->deactivate();
3109                 active = 1;
3110                 set_active_subwindow(this);
3111                 gui->cursor->activate();
3112         }
3113         return 0;
3116 int TrackCanvas::deactivate()
3118         if(active)
3119         {
3120                 active = 0;
3121                 gui->cursor->deactivate();
3122         }
3123         return 0;
3127 void TrackCanvas::update_drag_handle()
3129         double new_position;
3131         new_position = 
3132                 (double)(get_cursor_x() + mwindow->edl->local_session->view_start) *
3133                 mwindow->edl->local_session->zoom_sample /
3134                 mwindow->edl->session->sample_rate;
3135         new_position = 
3136                 mwindow->edl->align_to_frame(new_position, 0);
3139         if(new_position != mwindow->session->drag_position)
3140         {
3141                 mwindow->session->drag_position = new_position;
3142                 gui->mainclock->update(new_position);
3143 // Que the CWindow.  Doesn't do anything if selectionstart and selection end 
3144 // aren't changed.
3145 //              mwindow->cwindow->update(1, 0, 0);
3146         }
3149 int TrackCanvas::update_drag_edit()
3151         int result = 0;
3152         
3153         
3154         
3155         return result;
3158 #define UPDATE_DRAG_HEAD(do_clamp) \
3159         int result = 0; \
3160         int x = cursor_x - mwindow->session->drag_origin_x; \
3161         int y = cursor_y - mwindow->session->drag_origin_y; \
3163         if(!current->autos->track->record) return 0; \
3164         double view_start; \
3165         int64_t unit_start; \
3166         double view_end; \
3167         int64_t unit_end; \
3168         double yscale; \
3169         int center_pixel; \
3170         double zoom_sample; \
3171         double zoom_units; \
3173         mwindow->undo->update_undo_before(_("tweek"), LOAD_AUTOMATION); \
3174         calculate_viewport(current->autos->track,  \
3175                 view_start, \
3176                 unit_start, \
3177                 view_end, \
3178                 unit_end, \
3179                 yscale, \
3180                 center_pixel, \
3181                 zoom_sample, \
3182                 zoom_units); \
3184         float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3185                 MAX(128, yscale) +  \
3186                 mwindow->session->drag_start_percentage; \
3187         if(do_clamp) CLAMP(percentage, 0, 1); \
3189         int64_t position = Units::to_int64(zoom_units * \
3190                 (cursor_x - mwindow->session->drag_origin_x) + \
3191                 mwindow->session->drag_start_position); \
3193         if((do_clamp) && position < 0) position = 0;
3203 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3205         FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3207         UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3209         float value;
3210 //printf("TrackCanvas::update_drag_floatauto %ld %d\n", 
3211 //position, 
3212 //mwindow->session->drag_handle);
3214         switch(mwindow->session->drag_handle)
3215         {
3216 // Center
3217                 case 0:
3218 // Snap to nearby values
3219                         if(shift_down())
3220                         {
3221                                 double value1;
3222                                 double distance1;
3223                                 double value2;
3224                                 double distance2;
3225                                 value = ((FloatAuto*)current)->percentage_to_value(percentage);
3227                                 if(current->previous)
3228                                 {
3229                                         value1 = ((FloatAuto*)current->previous)->value;
3230                                         distance1 = fabs(value - value1);
3231                                         current->value = value1;
3232                                 }
3234                                 if(current->next)
3235                                 {
3236                                         value2 = ((FloatAuto*)current->next)->value;
3237                                         distance2 = fabs(value - value2);
3238                                         if(!current->previous || distance2 < distance1)
3239                                         {
3240                                                 current->value = value2;
3241                                         }
3242                                 }
3244                                 if(!current->previous && !current->next)
3245                                 {
3246                                         value = ((FloatAutos*)current->autos)->default_;
3247                                 }
3248                                 value = current->value;
3249                         }
3250                         else
3251                                 value = ((FloatAuto*)current)->percentage_to_value(percentage);
3253 //printf("TrackCanvas::update_drag_floatauto 1 %f\n", value);
3254                         if(value != current->value || position != current->position)
3255                         {
3256                                 result = 1;
3257                                 float change = value - current->value;          
3258                                 current->value = value;
3259                                 current->position = position;
3260                                 synchronize_autos(change, current->autos->track, current, 0);
3262                                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3263                                 Units::totext(string2, 
3264                                         current->autos->track->from_units(current->position),
3265                                         mwindow->edl->session->time_format,
3266                                         mwindow->edl->session->sample_rate,
3267                                         mwindow->edl->session->frame_rate,
3268                                         mwindow->edl->session->frames_per_foot);
3269                                 sprintf(string, "%s, %.2f", string2, current->value);
3270                                 gui->show_message(string);
3271                         }
3272                         break;
3274 // In control
3275                 case 1:
3276                         value = ((FloatAuto*)current)->percentage_to_invalue(percentage);
3277                         position = MIN(0, position);
3278                         if(value != current->control_in_value || 
3279                                 position != current->control_in_position)
3280                         {
3281                                 result = 1;
3282                                 current->control_in_value = value;
3283                                 current->control_in_position = position;
3284                                 synchronize_autos(0, current->autos->track, current, 0);
3286                                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3287                                 Units::totext(string2, 
3288                                         current->autos->track->from_units(current->control_in_position),
3289                                         mwindow->edl->session->time_format,
3290                                         mwindow->edl->session->sample_rate,
3291                                         mwindow->edl->session->frame_rate,
3292                                         mwindow->edl->session->frames_per_foot);
3293                                 sprintf(string, "%s, %.2f", string2, current->control_in_value);
3294                                 gui->show_message(string);
3295                         }
3296                         break;
3298 // Out control
3299                 case 2:
3300                         value = ((FloatAuto*)current)->percentage_to_outvalue(percentage);
3301                         position = MAX(0, position);
3302                         if(value != current->control_out_value || 
3303                                 position != current->control_out_position)
3304                         {
3305                                 result = 1;
3306                                 current->control_out_value = value;
3307                                 current->control_out_position = position;
3308                                 synchronize_autos(0, current->autos->track, current, 0);
3310                                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3311                                 Units::totext(string2, 
3312                                         current->autos->track->from_units(
3313                                                 ((FloatAuto*)current)->control_out_position),
3314                                         mwindow->edl->session->time_format,
3315                                         mwindow->edl->session->sample_rate,
3316                                         mwindow->edl->session->frame_rate,
3317                                         mwindow->edl->session->frames_per_foot);
3318                                 sprintf(string, "%s, %.2f", 
3319                                         string2, 
3320                                         ((FloatAuto*)current)->control_out_value);
3321                                 gui->show_message(string);
3322                         }
3323                         break;
3324         }
3326         return result;
3329 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3331         IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3333         UPDATE_DRAG_HEAD(1);
3335         int value = ((IntAuto*)current)->percentage_to_value(percentage);
3337         if(value != current->value || position != current->position)
3338         {
3339                 result = 1;
3340                 current->value = value;
3341                 current->position = position;
3343                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3344                 Units::totext(string2, 
3345                         current->autos->track->from_units(current->position),
3346                         mwindow->edl->session->time_format,
3347                         mwindow->edl->session->sample_rate,
3348                         mwindow->edl->session->frame_rate,
3349                         mwindow->edl->session->frames_per_foot);
3350                 sprintf(string, "%s, %d", string2, current->value);
3351                 gui->show_message(string);
3352         }
3354         return result;
3357 // Autos which can't change value through dragging.
3359 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3361         Auto *current = (Auto*)mwindow->session->drag_auto;
3363         UPDATE_DRAG_HEAD(1)
3365         if(position != current->position)
3366         {
3367                 result = 1;
3368                 current->position = position;
3370                 char string[BCTEXTLEN];
3371                 Units::totext(string, 
3372                         current->autos->track->from_units(current->position),
3373                         mwindow->edl->session->time_format,
3374                         mwindow->edl->session->sample_rate,
3375                         mwindow->edl->session->frame_rate,
3376                         mwindow->edl->session->frames_per_foot);
3377                 gui->show_message(string);
3379                 double position_f = current->autos->track->from_units(current->position);
3380                 double center_f = (mwindow->edl->local_session->selectionstart +
3381                         mwindow->edl->local_session->selectionend) / 
3382                         2;
3383                 if(!shift_down())
3384                 {
3385                         mwindow->edl->local_session->selectionstart = position_f;
3386                         mwindow->edl->local_session->selectionend = position_f;
3387                 }
3388                 else
3389                 if(position_f < center_f)
3390                 {
3391                         mwindow->edl->local_session->selectionstart = position_f;
3392                 }
3393                 else
3394                         mwindow->edl->local_session->selectionend = position_f;
3395         }
3398         return result;
3401 void TrackCanvas::update_drag_caption()
3403         switch(mwindow->session->current_operation)
3404         {
3405                 case DRAG_FADE:
3406                         
3407                         break;
3408         }
3413 int TrackCanvas::cursor_motion_event()
3415         int result, cursor_x, cursor_y;
3416         int update_clock = 0;
3417         int update_zoom = 0;
3418         int update_scroll = 0;
3419         int update_overlay = 0;
3420         int update_cursor = 0;
3421         int new_cursor = 0;
3422         int rerender = 0;
3423         double position = 0;
3424 //printf("TrackCanvas::cursor_motion_event 1\n");
3425         result = 0;
3427 // Default cursor
3428         switch(mwindow->edl->session->editing_mode)
3429         {
3430                 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3431                 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3432         }
3434         switch(mwindow->session->current_operation)
3435         {
3436                 case DRAG_EDITHANDLE1:
3437 // Outside threshold.  Upgrade status
3438 //printf("TrackCanvas::cursor_motion_event 1\n");
3439                         if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3440                         {
3441 //printf("TrackCanvas::cursor_motion_event 2\n");
3442                                 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3443                                 update_overlay = 1;
3444                         }
3445                         break;
3447                 case DRAG_EDITHANDLE2:
3448                         update_drag_handle();
3449                         update_overlay = 1;
3450                         break;
3452                 case DRAG_PLUGINHANDLE1:
3453                         if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3454                         {
3455 //printf("TrackCanvas::cursor_motion_event 2\n");
3456                                 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3457                                 update_overlay = 1;
3458                         }
3459                         break;
3461                 case DRAG_PLUGINHANDLE2:
3462                         update_drag_handle();
3463                         update_overlay = 1;
3464                         break;
3466 // Rubber band curves
3467                 case DRAG_FADE:
3468                         rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3469                         break;
3471                 case DRAG_CZOOM:
3472                         rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3473                         break;
3475                 case DRAG_PZOOM:
3476                         rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3477                         break;
3479                 case DRAG_PLAY:
3480                         rerender = update_overlay = update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3481                         break;
3483                 case DRAG_MUTE:
3484                         rerender = update_overlay = update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3485                         break;
3487 // Keyframe icons are sticky
3488                 case DRAG_PAN_PRE:
3489                 case DRAG_CAMERA_PRE:
3490                 case DRAG_MASK_PRE:
3491                 case DRAG_MODE_PRE:
3492                 case DRAG_PROJECTOR_PRE:
3493                 case DRAG_PLUGINKEY_PRE:
3494                         if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3495                         {
3496 //printf("TrackCanvas::cursor_motion_event 2\n");
3497                                 mwindow->session->current_operation++;
3498                                 update_overlay = 1;
3499                         }
3500                         break;
3502                 case DRAG_PAN:
3503                 case DRAG_CAMERA:
3504                 case DRAG_MASK:
3505                 case DRAG_MODE:
3506                 case DRAG_PROJECTOR:
3507                 case DRAG_PLUGINKEY:
3508                         rerender = update_overlay = 
3509                                 update_drag_auto(get_cursor_x(), get_cursor_y());
3510                         break;
3512                 case SELECT_REGION:
3513                 {
3514                         cursor_x = get_cursor_x();
3515                         cursor_y = get_cursor_y();
3516                         position = (double)(cursor_x + mwindow->edl->local_session->view_start) * 
3517                                 mwindow->edl->local_session->zoom_sample /
3518                                 mwindow->edl->session->sample_rate;
3520                         position = mwindow->edl->align_to_frame(position, 0);
3521                         position = MAX(position, 0);
3523                         if(position < selection_midpoint1)
3524                         {
3525                                 mwindow->edl->local_session->selectionend = selection_midpoint1;
3526                                 mwindow->edl->local_session->selectionstart = position;
3527 // Que the CWindow
3528                                 mwindow->cwindow->update(1, 0, 0, 0, 1);
3529 // Update the faders
3530                                 mwindow->update_plugin_guis();
3531                                 gui->patchbay->update();
3532                         }
3533                         else
3534                         {
3535                                 mwindow->edl->local_session->selectionstart = selection_midpoint1;
3536                                 mwindow->edl->local_session->selectionend = position;
3537 // Don't que the CWindow
3538                         }
3539 //printf("TrackCanvas::cursor_motion_event 1 %f %f %f\n", position, mwindow->edl->local_session->selectionstart, mwindow->edl->local_session->selectionend);
3541                         gui->cursor->hide();
3542                         gui->cursor->draw();
3543                         flash();
3544                         result = 1;
3545                         update_clock = 1;
3546                         update_zoom = 1;
3547                         update_scroll = 1;
3548                         break;
3549                 }
3551                 default:
3552                         if(is_event_win() && cursor_inside())
3553                         {
3554 // Update clocks
3555                                 cursor_x = get_cursor_x();
3556                                 position = (double)cursor_x * 
3557                                         (double)mwindow->edl->local_session->zoom_sample / 
3558                                         (double)mwindow->edl->session->sample_rate + 
3559                                         (double)mwindow->edl->local_session->view_start * 
3560                                         (double)mwindow->edl->local_session->zoom_sample / 
3561                                         (double)mwindow->edl->session->sample_rate;
3562                                 position = mwindow->edl->align_to_frame(position, 0);
3563                                 update_clock = 1;
3565 // Update cursor
3566                                 if(mwindow->edl->session->auto_conf->transitions && 
3567                                         test_transitions(get_cursor_x(), 
3568                                                 get_cursor_y(), 
3569                                                 0, 
3570                                                 new_cursor, 
3571                                                 update_cursor))
3572                                 {
3573                                         break;
3574                                 }
3575                                 else
3576 // Update cursor
3577                                 if(do_keyframes(get_cursor_x(), 
3578                                         get_cursor_y(), 
3579                                         0, 
3580                                         0, 
3581                                         new_cursor,
3582                                         update_cursor,
3583                                         rerender))
3584                                 {
3585                                         break;
3586                                 }
3587                                 else
3588 // Edit boundaries
3589                                 if(test_edit_handles(get_cursor_x(), 
3590                                         get_cursor_y(), 
3591                                         0, 
3592                                         new_cursor,
3593                                         update_cursor))
3594                                 {
3595                                         break;
3596                                 }
3597                                 else
3598 // Plugin boundaries
3599                                 if(test_plugin_handles(get_cursor_x(), 
3600                                         get_cursor_y(), 
3601                                         0, 
3602                                         new_cursor,
3603                                         update_cursor))
3604                                 {
3605                                         break;
3606                                 }
3607                                 else
3608                                 if(test_edits(get_cursor_x(), 
3609                                         get_cursor_y(), 
3610                                         0, 
3611                                         0, 
3612                                         update_overlay, 
3613                                         rerender,
3614                                         new_cursor,
3615                                         update_cursor))
3616                                 {
3617                                         break;
3618                                 }
3619                         }
3620                         break;
3621         }
3623 //printf("TrackCanvas::cursor_motion_event 1\n");
3624         if(update_cursor && new_cursor != get_cursor())
3625         {
3626                 set_cursor(new_cursor);
3627         }
3629 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
3630         if(rerender)
3631         {
3632                 mwindow->restart_brender();
3633                 mwindow->sync_parameters(CHANGE_PARAMS);
3634                 mwindow->update_plugin_guis();
3635                 mwindow->cwindow->update(1, 0, 0, 0, 1);
3636 // Update faders
3637                 gui->patchbay->update();
3638         }
3641         if(update_clock)
3642         {
3643                 if(!mwindow->cwindow->playback_engine->is_playing_back)
3644                         gui->mainclock->update(position);
3645         }
3647         if(update_zoom)
3648         {
3649                 gui->zoombar->update();
3650         }
3652         if(update_scroll)
3653         {
3654                 if(!drag_scroll && 
3655                         (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
3656                         start_dragscroll();
3657                 else
3658                 if(drag_scroll &&
3659                         (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
3660                         stop_dragscroll();
3661         }
3663         if(update_overlay)
3664         {
3665                 draw_overlays();
3666                 flash();
3667         }
3670 //printf("TrackCanvas::cursor_motion_event 100\n");
3671         return result;
3674 void TrackCanvas::start_dragscroll()
3676         if(!drag_scroll)
3677         {
3678                 drag_scroll = 1;
3679                 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3680 //printf("TrackCanvas::start_dragscroll 1\n");
3681         }
3684 void TrackCanvas::stop_dragscroll()
3686         if(drag_scroll)
3687         {
3688                 drag_scroll = 0;
3689                 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3690 //printf("TrackCanvas::stop_dragscroll 1\n");
3691         }
3694 int TrackCanvas::repeat_event(int64_t duration)
3696         if(!drag_scroll) return 0;
3697         if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
3699         int sample_movement = 0;
3700         int track_movement = 0;
3701         int64_t x_distance = 0;
3702         int64_t y_distance = 0;
3703         double position = 0;
3704         int result = 0;
3706         switch(mwindow->session->current_operation)
3707         {
3708                 case SELECT_REGION:
3709 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
3710                         if(get_cursor_x() > get_w())
3711                         {
3712                                 x_distance = get_cursor_x() - get_w();
3713                                 sample_movement = 1;
3714                         }
3715                         else
3716                         if(get_cursor_x() < 0)
3717                         {
3718                                 x_distance = get_cursor_x();
3719                                 sample_movement = 1;
3720                         }
3722                         if(get_cursor_y() > get_h())
3723                         {
3724                                 y_distance = get_cursor_y() - get_h();
3725                                 track_movement = 1;
3726                         }
3727                         else
3728                         if(get_cursor_y() < 0)
3729                         {
3730                                 y_distance = get_cursor_y();
3731                                 track_movement = 1;
3732                         }
3733                         result = 1;
3734                         break;
3735         }
3738         if(sample_movement)
3739         {
3740                 position = (double)(get_cursor_x() + 
3741                         mwindow->edl->local_session->view_start + 
3742                         x_distance) * 
3743                         mwindow->edl->local_session->zoom_sample /
3744                         mwindow->edl->session->sample_rate;
3745                 position = mwindow->edl->align_to_frame(position, 0);
3746                 position = MAX(position, 0);
3748 //printf("TrackCanvas::repeat_event 1 %f\n", position);
3749                 switch(mwindow->session->current_operation)
3750                 {
3751                         case SELECT_REGION:
3752                                 if(position < selection_midpoint1)
3753                                 {
3754                                         mwindow->edl->local_session->selectionend = selection_midpoint1;
3755                                         mwindow->edl->local_session->selectionstart = position;
3756 // Que the CWindow
3757                                         mwindow->cwindow->update(1, 0, 0);
3758 // Update the faders
3759                                         mwindow->update_plugin_guis();
3760                                         gui->patchbay->update();
3761                                 }
3762                                 else
3763                                 {
3764                                         mwindow->edl->local_session->selectionstart = selection_midpoint1;
3765                                         mwindow->edl->local_session->selectionend = position;
3766 // Don't que the CWindow
3767                                 }
3768                                 break;
3769                 }
3771                 mwindow->samplemovement(mwindow->edl->local_session->view_start + 
3772                         x_distance);
3773         }
3775         if(track_movement)
3776         {
3777                 mwindow->trackmovement(mwindow->edl->local_session->track_start + 
3778                         y_distance);
3779         }
3781         return result;
3784 int TrackCanvas::button_release_event()
3786         int redraw = 0, update_overlay = 0, result = 0;
3788         switch(mwindow->session->current_operation)
3789         {
3790                 case DRAG_EDITHANDLE2:
3791                         mwindow->session->current_operation = NO_OPERATION;
3792                         drag_scroll = 0;
3793                         result = 1;
3794                         
3795                         end_edithandle_selection();
3796                         break;
3798                 case DRAG_EDITHANDLE1:
3799                         mwindow->session->current_operation = NO_OPERATION;
3800                         drag_scroll = 0;
3801                         result = 1;
3802                         break;
3804                 case DRAG_PLUGINHANDLE2:
3805                         mwindow->session->current_operation = NO_OPERATION;
3806                         drag_scroll = 0;
3807                         result = 1;
3808                         
3809                         end_pluginhandle_selection();
3810                         break;
3812                 case DRAG_PLUGINHANDLE1:
3813                         mwindow->session->current_operation = NO_OPERATION;
3814                         drag_scroll = 0;
3815                         result = 1;
3816                         break;
3818                 case DRAG_FADE:
3819                         synchronize_autos(0, 0, 0, -1); // delete the drag_auto_gang first and remove out of order keys
3820                 case DRAG_CZOOM:
3821                 case DRAG_PZOOM:
3822                 case DRAG_PLAY:
3823                 case DRAG_MUTE:
3824                 case DRAG_MASK:
3825                 case DRAG_MODE:
3826                 case DRAG_PAN:
3827                 case DRAG_CAMERA:
3828                 case DRAG_PROJECTOR:
3829                 case DRAG_PLUGINKEY:
3830                         mwindow->session->current_operation = NO_OPERATION;
3831                         mwindow->session->drag_handle = 0;
3832 // Remove any out-of-order keyframe
3833                         if(mwindow->session->drag_auto)
3834                         {
3835                                 mwindow->session->drag_auto->autos->remove_nonsequential(
3836                                         mwindow->session->drag_auto);
3837 //                              mwindow->session->drag_auto->autos->optimize();
3838                                 update_overlay = 1;
3839                         }
3840                         mwindow->undo->update_undo_after();
3841                         result = 1;
3842                         break;
3844                 case DRAG_EDIT:
3845                 case DRAG_AEFFECT_COPY:
3846                 case DRAG_VEFFECT_COPY:
3847 // Trap in drag stop
3849                         break;
3852                 default:
3853                         if(mwindow->session->current_operation)
3854                         {
3855                                 mwindow->session->current_operation = NO_OPERATION;
3856                                 drag_scroll = 0;
3857 // Traps button release events
3858 //                              result = 1;
3859                         }
3860                         break;
3861         }
3862         if (result) 
3863                 cursor_motion_event();
3864         if(update_overlay)
3865         {
3866                 draw_overlays();
3867                 flash();
3868         }
3869         if(redraw)
3870         {
3871                 draw();
3872                 flash();
3873         }
3874         return result;
3877 int TrackCanvas::test_edit_handles(int cursor_x, 
3878         int cursor_y, 
3879         int button_press, 
3880         int &new_cursor,
3881         int &update_cursor)
3883         Edit *edit_result = 0;
3884         int handle_result = 0;
3885         int result = 0;
3887         for(Track *track = mwindow->edl->tracks->first;
3888                 track && !result;
3889                 track = track->next)
3890         {
3891                 for(Edit *edit = track->edits->first;
3892                         edit && !result;
3893                         edit = edit->next)
3894                 {
3895                         int64_t edit_x, edit_y, edit_w, edit_h;
3896                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
3898                         if(cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
3899                                 cursor_y >= edit_y && cursor_y < edit_y + edit_h)
3900                         {
3901                                 if(cursor_x < edit_x + HANDLE_W)
3902                                 {
3903                                         edit_result = edit;
3904                                         handle_result = 0;
3905                                         result = 1;
3906                                 }
3907                                 else
3908                                 if(cursor_x >= edit_x + edit_w - HANDLE_W)
3909                                 {
3910                                         edit_result = edit;
3911                                         handle_result = 1;
3912                                         result = 1;
3913                                 }
3914                                 else
3915                                 {
3916                                         result = 0;
3917                                 }
3918                         }
3919                 }
3920         }
3922         update_cursor = 1;
3923         if(result)
3924         {
3925                 double position;
3926                 if(handle_result == 0)
3927                 {
3928                         position = edit_result->track->from_units(edit_result->startproject);
3929                         new_cursor = LEFT_CURSOR;
3930                 }
3931                 else
3932                 if(handle_result == 1)
3933                 {
3934                         position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
3935                         new_cursor = RIGHT_CURSOR;
3936                 }
3938 // Reposition cursor
3939                 if(button_press)
3940                 {
3941                         mwindow->session->drag_edit = edit_result;
3942                         mwindow->session->drag_handle = handle_result;
3943                         mwindow->session->drag_button = get_buttonpress() - 1;
3944                         mwindow->session->drag_position = position;
3945                         mwindow->session->current_operation = DRAG_EDITHANDLE1;
3946                         mwindow->session->drag_origin_x = get_cursor_x();
3947                         mwindow->session->drag_origin_y = get_cursor_y();
3948                         mwindow->session->drag_start = position;
3950                         int rerender = start_selection(position);
3951                         if(rerender)
3952                                 mwindow->cwindow->update(1, 0, 0);
3953                         gui->timebar->update_highlights();
3954                         gui->zoombar->update();
3955                         gui->cursor->hide();
3956                         gui->cursor->draw();
3957                         draw_overlays();
3958                         flash();
3959                         flush();
3960                 }
3961         }
3963         return result;
3966 int TrackCanvas::test_plugin_handles(int cursor_x, 
3967         int cursor_y, 
3968         int button_press,
3969         int &new_cursor,
3970         int &update_cursor)
3972         Plugin *plugin_result = 0;
3973         int handle_result = 0;
3974         int result = 0;
3975         
3976         for(Track *track = mwindow->edl->tracks->first;
3977                 track && !result;
3978                 track = track->next)
3979         {
3980                 for(int i = 0; i < track->plugin_set.total && !result; i++)
3981                 {
3982                         PluginSet *plugin_set = track->plugin_set.values[i];
3983                         for(Plugin *plugin = (Plugin*)plugin_set->first; 
3984                                 plugin && !result; 
3985                                 plugin = (Plugin*)plugin->next)
3986                         {
3987                                 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
3988                                 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
3989                                 
3990                                 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
3991                                         cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h)
3992                                 {
3993                                         if(cursor_x < plugin_x + HANDLE_W)
3994                                         {
3995                                                 plugin_result = plugin;
3996                                                 handle_result = 0;
3997                                                 result = 1;
3998                                         }
3999                                         else
4000                                         if(cursor_x >= plugin_x + plugin_w - HANDLE_W)
4001                                         {
4002                                                 plugin_result = plugin;
4003                                                 handle_result = 1;
4004                                                 result = 1;
4005                                         }
4006                                 }
4007                         }
4008                 }
4009         }
4011 //printf("TrackCanvas::test_plugin_handles %d %d %d\n", button_press, handle_result, result);
4012         update_cursor = 1;
4013         if(result)
4014         {
4015                 double position;
4016                 if(handle_result == 0)
4017                 {
4018                         position = plugin_result->track->from_units(plugin_result->startproject);
4019                         new_cursor = LEFT_CURSOR;
4020                 }
4021                 else
4022                 if(handle_result == 1)
4023                 {
4024                         position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4025                         new_cursor = RIGHT_CURSOR;
4026                 }
4027                 
4028                 if(button_press)
4029                 {
4030                         mwindow->session->drag_plugin = plugin_result;
4031                         mwindow->session->drag_handle = handle_result;
4032                         mwindow->session->drag_button = get_buttonpress() - 1;
4033                         mwindow->session->drag_position = position;
4034                         mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4035                         mwindow->session->drag_origin_x = get_cursor_x();
4036                         mwindow->session->drag_origin_y = get_cursor_y();
4037                         mwindow->session->drag_start = position;
4039                         int rerender = start_selection(position);
4040                         if(rerender) mwindow->cwindow->update(1, 0, 0);
4041                         gui->timebar->update_highlights();
4042                         gui->zoombar->update();
4043                         gui->cursor->hide();
4044                         gui->cursor->draw();
4045                         draw_overlays();
4046                         flash();
4047                         flush();
4048                 }
4049         }
4050         
4051         return result;
4055 int TrackCanvas::test_tracks(int cursor_x, 
4056                 int cursor_y,
4057                 int button_press)
4059         int result = 0;
4060         for(Track *track = mwindow->edl->tracks->first;
4061                 track && !result;
4062                 track = track->next)
4063         {
4064                 int64_t track_x, track_y, track_w, track_h;
4065                 track_dimensions(track, track_x, track_y, track_w, track_h);
4067                 if(button_press && 
4068                         get_buttonpress() == 3 &&
4069                         cursor_y >= track_y && 
4070                         cursor_y < track_y + track_h)
4071                 {
4072                         gui->edit_menu->update(track, 0);
4073                         gui->edit_menu->activate_menu();
4074                         result = 1;
4075                 }
4076         }
4077         return result;
4080 int TrackCanvas::test_edits(int cursor_x, 
4081         int cursor_y, 
4082         int button_press,
4083         int drag_start,
4084         int &redraw,
4085         int &rerender,
4086         int &new_cursor,
4087         int &update_cursor)
4089         int result = 0;
4090         int over_edit_handle = 0;
4092 //printf("TrackCanvas::test_edits 1\n");
4093         for(Track *track = mwindow->edl->tracks->first;
4094                 track && !result;
4095                 track = track->next)
4096         {
4097                 for(Edit *edit = track->edits->first;
4098                         edit && !result;
4099                         edit = edit->next)
4100                 {
4101                         int64_t edit_x, edit_y, edit_w, edit_h;
4102 //printf("TrackCanvas::test_edits 1\n");
4103                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4105 // Cursor inside a track
4106 // Cursor inside an edit
4107                         if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4108                                 cursor_y >= edit_y && cursor_y < edit_y + edit_h)
4109                         {
4110 // Select duration of edit
4111 //printf("TrackCanvas::test_edits 2\n");
4112                                 if(button_press)
4113                                 {
4114                                         if(get_double_click() && !drag_start)
4115                                         {
4116 //printf("TrackCanvas::test_edits 3\n");
4117                                                 mwindow->edl->local_session->selectionstart = 
4118                                                         edit->track->from_units(edit->startproject);
4119                                                 mwindow->edl->local_session->selectionend = 
4120                                                         edit->track->from_units(edit->startproject) + 
4121                                                         edit->track->from_units(edit->length);
4122                                                 if(mwindow->edl->session->cursor_on_frames) 
4123                                                 {
4124                                                         mwindow->edl->local_session->selectionstart = 
4125                                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionstart, 0);
4126                                                         mwindow->edl->local_session->selectionend = 
4127                                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionend, 1);
4128                                                 }
4129                                                 redraw = 1;
4130                                                 rerender = 1;
4131                                                 result = 1;
4132                                         }
4133                                 }
4134                                 else
4135                                 if(drag_start)
4136                                 {
4137                                         if(mwindow->edl->session->editing_mode == EDITING_ARROW)
4138                                         {
4139 // Need to create drag window
4140                                                 mwindow->session->current_operation = DRAG_EDIT;
4141                                                 mwindow->session->drag_edit = edit;
4142 //printf("TrackCanvas::test_edits 2\n");
4144 // Drag only one edit
4145                                                 if(ctrl_down())
4146                                                 {
4147                                                         mwindow->session->drag_edits->remove_all();
4148                                                         mwindow->session->drag_edits->append(edit);
4149                                                 }
4150                                                 else
4151 // Construct list of all affected edits
4152                                                 {
4153                                                         mwindow->edl->tracks->get_affected_edits(
4154                                                                 mwindow->session->drag_edits, 
4155                                                                 edit->track->from_units(edit->startproject),
4156                                                                 edit->track);
4157                                                 }
4158                                                 mwindow->session->drag_origin_x = cursor_x;
4159                                                 mwindow->session->drag_origin_y = cursor_y;
4161                                                 drag_popup = new BC_DragWindow(gui, 
4162                                                         mwindow->theme->clip_icon, 
4163                                                         get_abs_cursor_x() - mwindow->theme->clip_icon->get_w() / 2,
4164                                                         get_abs_cursor_y() - mwindow->theme->clip_icon->get_h() / 2);
4165 //printf("TrackCanvas::test_edits 3 %p\n", drag_popup);
4167                                                 result = 1;
4168                                         }
4169                                 }
4170                         }
4171                 }
4172         }
4173         return result;
4177 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4179         return 0;
4182 int TrackCanvas::test_plugins(int cursor_x, 
4183         int cursor_y, 
4184         int drag_start,
4185         int button_press,
4186         int &redraw,
4187         int &rerender)
4189         Plugin *plugin = 0;
4190         int result = 0;
4191         int done = 0;
4192         int64_t x, y, w, h;
4193         Track *track = 0;
4195 //printf("TrackCanvas::test_plugins 1\n");
4196         for(track = mwindow->edl->tracks->first;
4197                 track && !done;
4198                 track = track->next)
4199         {
4200                 for(int i = 0; i < track->plugin_set.total && !done; i++)
4201                 {
4202                         PluginSet *plugin_set = track->plugin_set.values[i];
4203                         for(plugin = (Plugin*)plugin_set->first;
4204                                 plugin && !done;
4205                                 plugin = (Plugin*)plugin->next)
4206                         {
4207                                 plugin_dimensions(plugin, x, y, w, h);
4208                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4209                                         MWindowGUI::visible(y, y + h, 0, get_h()))
4210                                 {
4211                                         if(cursor_x >= x && cursor_x < x + w &&
4212                                                 cursor_y >= y && cursor_y < y + h)
4213                                         {
4214                                                 done = 1;
4215                                                 break;
4216                                         }
4217                                 }
4218                         }
4219                 }
4220         }
4222 //printf("TrackCanvas::test_plugins 1\n");
4223         if(plugin)
4224         {
4225 // Start plugin popup
4226                 if(button_press)
4227                 {
4228 //printf("TrackCanvas::test_plugins 2\n");
4229                         if(get_buttonpress() == 3)
4230                         {
4231                                 gui->plugin_menu->update(plugin);
4232                                 gui->plugin_menu->activate_menu();
4233                                 result = 1;
4234                         } 
4235                         else
4236 // Select range of plugin on doubleclick over plugin
4237                         if (get_double_click() && !drag_start)
4238                         {
4239                                 mwindow->edl->local_session->selectionstart = 
4240                                         plugin->track->from_units(plugin->startproject);
4241                                 mwindow->edl->local_session->selectionend = 
4242                                         plugin->track->from_units(plugin->startproject) + 
4243                                         plugin->track->from_units(plugin->length);
4244                                 if(mwindow->edl->session->cursor_on_frames) 
4245                                 {
4246                                         mwindow->edl->local_session->selectionstart = 
4247                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionstart, 0);
4248                                         mwindow->edl->local_session->selectionend = 
4249                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionend, 1);
4250                                 }
4251                                 rerender = 1;
4252                                 redraw = 1;
4253                                 result = 1;
4254                         }
4255 //printf("TrackCanvas::test_plugins 3\n");
4256                 }
4257                 else
4258 // Move plugin
4259                 if(drag_start)
4260                 {
4261 //printf("TrackCanvas::test_plugins 4\n");
4262                         if(mwindow->edl->session->editing_mode == EDITING_ARROW)
4263                         {
4264 //printf("TrackCanvas::test_plugins 5\n");
4265                                 if(plugin->track->data_type == TRACK_AUDIO)
4266                                         mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4267                                 else
4268                                 if(plugin->track->data_type == TRACK_VIDEO)
4269                                         mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4271                                 mwindow->session->drag_plugin = plugin;
4272 //printf("TrackCanvas::test_plugins 6\n");
4278 // Create picon
4279                                 switch(plugin->plugin_type)
4280                                 {
4281                                         case PLUGIN_STANDALONE:
4282                                         {
4283                                                 PluginServer *server = mwindow->scan_plugindb(plugin->title,
4284                                                         track->data_type);
4285                                                 VFrame *frame = server->picon;
4286 //printf("TrackCanvas::test_plugins 7\n");
4287                                                 drag_popup = new BC_DragWindow(gui, 
4288                                                         frame, 
4289                                                         get_abs_cursor_x() - frame->get_w() / 2,
4290                                                         get_abs_cursor_y() - frame->get_h() / 2);
4291                                                 break;
4292                                         }
4293                                         
4294                                         case PLUGIN_SHAREDPLUGIN:
4295                                         case PLUGIN_SHAREDMODULE:
4296                                                 drag_popup = new BC_DragWindow(gui, 
4297                                                         mwindow->theme->clip_icon, 
4298                                                         get_abs_cursor_x() - mwindow->theme->clip_icon->get_w() / 2,
4299                                                         get_abs_cursor_y() - mwindow->theme->clip_icon->get_h() / 2);
4300                                                 break;
4301 //printf("test plugins %d %p\n", mwindow->edl->session->editing_mode, mwindow->session->drag_plugin);
4302                                 }
4304 //printf("TrackCanvas::test_plugins 9 %p\n");
4306 //printf("TrackCanvas::test_plugins 10\n");
4307                                 result = 1;
4308                         }
4309                 }
4310         }
4312 //printf("TrackCanvas::test_plugins 11\n");
4313         return result;
4316 int TrackCanvas::test_transitions(int cursor_x, 
4317         int cursor_y, 
4318         int button_press,
4319         int &new_cursor,
4320         int &update_cursor)
4322         Transition *transition = 0;
4323         int result = 0;
4324         int64_t x, y, w, h;
4325         
4326         for(Track *track = mwindow->edl->tracks->first;
4327                 track && !result;
4328                 track = track->next)
4329         {
4330                 for(Edit *edit = track->edits->first;
4331                         edit;
4332                         edit = edit->next)
4333                 {
4334                         if(edit->transition)
4335                         {
4336                                 edit_dimensions(edit, x, y, w, h);
4337                                 get_transition_coords(x, y, w, h);
4339                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4340                                         MWindowGUI::visible(y, y + h, 0, get_h()))
4341                                 {
4342                                         if(cursor_x >= x && cursor_x < x + w &&
4343                                                 cursor_y >= y && cursor_y < y + h)
4344                                         {
4345                                                 transition = edit->transition;
4346                                                 result = 1;
4347                                                 break;
4348                                         }
4349                                 }
4350                         }
4351                 }
4352         }
4353         
4354         update_cursor = 1;
4355         if(transition)
4356         {
4357                 if(!button_press)
4358                 {
4359                         new_cursor = UPRIGHT_ARROW_CURSOR;
4360                 }
4361                 else
4362                 if(get_buttonpress() == 3)
4363                 {
4364                         gui->transition_menu->update(transition);
4365                         gui->transition_menu->activate_menu();
4366                 }
4367         }
4369         return result;
4372 int TrackCanvas::button_press_event()
4374         int result = 0;
4375         int cursor_x, cursor_y;
4376         int new_cursor, update_cursor;
4378 //printf("TrackCanvas::button_press_event 1\n");
4379         cursor_x = get_cursor_x();
4380         cursor_y = get_cursor_y();
4382         if(is_event_win() && cursor_inside())
4383         {
4384                 if(!active)
4385                 {
4386                         activate();
4387                 }
4389                 if(get_buttonpress() == 1)
4390                 {
4391                         gui->unlock_window();
4392                         gui->mbuttons->transport->handle_transport(STOP, 1);
4393                         gui->lock_window("TrackCanvas::button_press_event");
4394                 }
4396                 int update_overlay = 0, update_cursor = 0, rerender = 0;
4398                 if(get_buttonpress() == 4)
4399                 {
4400 //printf("TrackCanvas::button_press_event 1\n");
4401                         mwindow->move_up(get_h() / 10);
4402                         result = 1;
4403                 }
4404                 else
4405                 if(get_buttonpress() == 5)
4406                 {
4407 //printf("TrackCanvas::button_press_event 2\n");
4408                         mwindow->move_down(get_h() / 10);
4409                         result = 1;
4410                 }
4411                 else
4412                 switch(mwindow->edl->session->editing_mode)
4413                 {
4414 // Test handles and resource boundaries and highlight a track
4415                         case EDITING_ARROW:
4416                         {
4417                                 Edit *edit;
4418                                 int handle;
4419                                 if(mwindow->edl->session->auto_conf->transitions && 
4420                                         test_transitions(cursor_x, 
4421                                                 cursor_y, 
4422                                                 1, 
4423                                                 new_cursor, 
4424                                                 update_cursor))
4425                                 {
4426                                         break;
4427                                 }
4428                                 else
4429                                 if(do_keyframes(cursor_x, 
4430                                         cursor_y, 
4431                                         0, 
4432                                         get_buttonpress(), 
4433                                         new_cursor, 
4434                                         update_cursor,
4435                                         rerender))
4436                                 {
4437                                         break;
4438                                 }
4439                                 else
4440 // Test edit boundaries
4441                                 if(test_edit_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4442                                 {
4443                                         break;
4444                                 }
4445                                 else
4446 // Test plugin boundaries
4447                                 if(test_plugin_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4448                                 {
4449                                         break;
4450                                 }
4451                                 else
4452                                 if(test_edits(cursor_x, cursor_y, 1, 0, update_cursor, rerender, new_cursor, update_cursor))
4453                                 {
4454                                         break;
4455                                 }
4456                                 else
4457                                 if(test_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender))
4458                                 {
4459                                         break;
4460                                 }
4461                                 else
4462                                 if(test_resources(cursor_x, cursor_y))
4463                                 {
4464                                         break;
4465                                 }
4466                                 else
4467                                 if(test_tracks(cursor_x, cursor_y, 1))
4468                                 {
4469                                         break;
4470                                 }
4471                                 break;
4472                         }
4474 // Test handles only and select a region
4475                         case EDITING_IBEAM:
4476                         {
4477                                 double position = (double)cursor_x * 
4478                                         mwindow->edl->local_session->zoom_sample /
4479                                         mwindow->edl->session->sample_rate + 
4480                                         (double)mwindow->edl->local_session->view_start * 
4481                                         mwindow->edl->local_session->zoom_sample /
4482                                         mwindow->edl->session->sample_rate;
4483 //printf("TrackCanvas::button_press_event %d\n", position);
4485                                 if(mwindow->edl->session->auto_conf->transitions && 
4486                                         test_transitions(cursor_x, 
4487                                                 cursor_y, 
4488                                                 1, 
4489                                                 new_cursor, 
4490                                                 update_cursor))
4491                                 {
4492                                         break;
4493                                 }
4494                                 else
4495                                 if(do_keyframes(cursor_x, 
4496                                         cursor_y, 
4497                                         0, 
4498                                         get_buttonpress(), 
4499                                         new_cursor, 
4500                                         update_cursor,
4501                                         rerender))
4502                                 {
4503                                         update_overlay = 1;
4504                                         break;
4505                                 }
4506                                 else
4507 // Test edit boundaries
4508                                 if(test_edit_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4509                                 {
4510                                         break;
4511                                 }
4512                                 else
4513 // Test plugin boundaries
4514                                 if(test_plugin_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4515                                 {
4516                                         break;
4517                                 }
4518                                 else
4519                                 if(test_edits(cursor_x, cursor_y, 1, 0, update_cursor, rerender, new_cursor, update_cursor))
4520                                 {
4521                                         break;
4522                                 }
4523                                 else
4524                                 if(test_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender))
4525                                 {
4526                                         break;
4527                                 }
4528                                 else
4529                                 if(test_tracks(cursor_x, cursor_y, 1))
4530                                 {
4531                                         break;
4532                                 }
4533 // Highlight selection
4534                                 else
4535                                 {
4536                                         rerender = start_selection(position);
4537                                         mwindow->session->current_operation = SELECT_REGION;
4538                                         update_cursor = 1;
4539                                 }
4541                                 break;
4542                         }
4543                 }
4546                 if(rerender)
4547                 {
4548                         mwindow->cwindow->update(1, 0, 0, 0, 1);
4549 // Update faders
4550                         mwindow->update_plugin_guis();
4551                         gui->patchbay->update();
4552                 }
4554                 if(update_overlay)
4555                 {
4556                         draw_overlays();
4557                         flash();
4558                 }
4560                 if(update_cursor)
4561                 {
4562                         gui->timebar->update_highlights();
4563                         gui->cursor->hide();
4564                         gui->cursor->show();
4565                         gui->zoombar->update();
4566                         flash();
4567                         result = 1;
4568                 }
4572         }
4573         return result;
4576 int TrackCanvas::start_selection(double position)
4578         int rerender = 0;
4579         position = mwindow->edl->align_to_frame(position, 0);
4581 // Extend a border
4582         if(shift_down())
4583         {
4584                 double midpoint = (mwindow->edl->local_session->selectionstart + 
4585                         mwindow->edl->local_session->selectionend) / 2;
4587                 if(position < midpoint)
4588                 {
4589                         mwindow->edl->local_session->selectionstart = position;
4590                         selection_midpoint1 = mwindow->edl->local_session->selectionend;
4591 // Que the CWindow
4592                         rerender = 1;
4593                 }
4594                 else
4595                 {
4596                         mwindow->edl->local_session->selectionend = position;
4597                         selection_midpoint1 = mwindow->edl->local_session->selectionstart;
4598 // Don't que the CWindow for the end
4599                 }
4600         }
4601         else
4602 // Start a new selection
4603         {
4604 //printf("TrackCanvas::start_selection %f\n", position);
4605                 mwindow->edl->local_session->selectionstart = 
4606                         mwindow->edl->local_session->selectionend = 
4607                         position;
4608                 selection_midpoint1 = position;
4609 // Que the CWindow
4610                 rerender = 1;
4611         }
4612         
4613         return rerender;
4616 void TrackCanvas::end_edithandle_selection()
4618         mwindow->modify_edithandles();
4621 void TrackCanvas::end_pluginhandle_selection()
4623         mwindow->modify_pluginhandles();
4627 double TrackCanvas::time_visible()
4629         return (double)get_w() * 
4630                 mwindow->edl->local_session->zoom_sample / 
4631                 mwindow->edl->session->sample_rate;
4674 void TrackCanvas::draw_automation()
4679 int TrackCanvas::set_index_file(int flash, Asset *asset)
4681         return 0;
4685 int TrackCanvas::button_release()
4687         return 0;
4691 int TrackCanvas::auto_reposition(int &cursor_x, int &cursor_y, int64_t cursor_position)
4693         return 0;
4697 int TrackCanvas::draw_floating_handle(int flash)
4699         return 0;
4702 int TrackCanvas::draw_loop_point(int64_t position, int flash)
4704         return 0;
4707 int TrackCanvas::draw_playback_cursor(int pixel, int flash)
4709         return 0;
4713 int TrackCanvas::update_handle_selection(int64_t cursor_position)
4715         return 0;
4718 int TrackCanvas::end_translation()
4720         return 0;