r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / trackcanvas.C
blobb748a4e66128d9c88a295dd5f84bf9535ef2ad15
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                 case TAB:
198                 case LEFTTAB:
199                         int cursor_x = get_relative_cursor_x();
200                         int cursor_y = get_relative_cursor_y();
201                         if(get_keypress() == TAB)
202                         {
203                                 // Switch the record button
204                                 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
205                                 {
206                                         int64_t track_x, track_y, track_w, track_h;
207                                         track_dimensions(track, track_x, track_y, track_w, track_h);
208         
209                                         if(cursor_y >= track_y && 
210                                                 cursor_y < track_y + track_h)
211                                         {
212                                                 if (track->record)
213                                                         track->record = 0;
214                                                 else
215                                                         track->record = 1;
216                                                 result = 1; 
217                                                 break;
218                                         }
219                                 }
220                         } else 
221                         {
222                                 Track *this_track;
223                                 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
224                                 {
225                                         int64_t track_x, track_y, track_w, track_h;
226                                         track_dimensions(track, track_x, track_y, track_w, track_h);
227         
228                                         if(cursor_y >= track_y && 
229                                                 cursor_y < track_y + track_h)
230                                         {
231                                                 // This is our track
232                                                 this_track = track;
233                                                 break;
234                                         }
235                                 }
237                                 int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
239 // nothing previously selected
240                                 if(total_selected == 0)
241                                 {
242                                         mwindow->edl->tracks->select_all(Tracks::RECORD,
243                                                 1);
244                                 }
245                                 else
246                                 if(total_selected == 1)
247                                 {
248 // this patch was previously the only one on
249                                         if(this_track && this_track->record)
250                                         {
251                                                 mwindow->edl->tracks->select_all(Tracks::RECORD,
252                                                         1);
253                                         }
254 // another patch was previously the only one on
255                                         else
256                                         {
257                                                 mwindow->edl->tracks->select_all(Tracks::RECORD,
258                                                         0);
259                                                 if (this_track) 
260                                                         this_track->record = 1;
261                                                 
262                                         }
263                                 }
264                                 else
265                                 if(total_selected > 1)
266                                 {
267                                         mwindow->edl->tracks->select_all(Tracks::RECORD,
268                                                 0);
269                                         if (this_track) 
270                                                 this_track->record = 1;
271                                 }
273                         }
275                         gui->update (0,
276                                         1,
277                                         0,
278                                         0,
279                                         1,
280                                         0,
281                                         1);
282                         mwindow->cwindow->update(0, 1, 1);
284                         result = 1;
285                         break;
286         }
288 // since things under cursor have changed...
289         if (result) 
290                 cursor_motion_event(); 
292         return result;
295 int TrackCanvas::drag_motion()
298         int cursor_x = get_relative_cursor_x();
299         int cursor_y = get_relative_cursor_y();
300         Track *over_track = 0;
301         Edit *over_edit = 0;
302         PluginSet *over_pluginset = 0;
303         Plugin *over_plugin = 0;
304         int redraw = 0;
307         if(drag_popup)
308         {
309                 drag_popup->cursor_motion_event();
310         }
313 // there's no point in drawing highlights has until drag operation has been set
314         if (!mwindow->session->current_operation)
315                 return 0;
317         if(get_cursor_over_window() &&
318                 cursor_x >= 0 && 
319                 cursor_y >= 0 && 
320                 cursor_x < get_w() && 
321                 cursor_y < get_h())
322         {
323 // Find the edit and track the cursor is over
324                 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
325                 {
326                         int64_t track_x, track_y, track_w, track_h;
327                         track_dimensions(track, track_x, track_y, track_w, track_h);
329                         if(cursor_y >= track_y && 
330                                 cursor_y < track_y + track_h)
331                         {
332                                 over_track = track;
333                                 for(Edit *edit = track->edits->first; edit; edit = edit->next)
334                                 {
335                                         int64_t edit_x, edit_y, edit_w, edit_h;
336                                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
338                                         if(cursor_x >= edit_x && 
339                                                 cursor_y >= edit_y && 
340                                                 cursor_x < edit_x + edit_w && 
341                                                 cursor_y < edit_y + edit_h)
342                                         {
343                                                 over_edit = edit;
344                                                 break;
345                                         }
346                                 }
348                                 for(int i = 0; i < track->plugin_set.total; i++)
349                                 {
350                                         PluginSet *pluginset = track->plugin_set.values[i];
351                                         
354                                         for(Plugin *plugin = (Plugin*)pluginset->first;
355                                                 plugin;
356                                                 plugin = (Plugin*)plugin->next)
357                                         {
358                                                 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
359                                                 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
360                                                 
361                                                 if(cursor_y >= plugin_y &&
362                                                         cursor_y < plugin_y + plugin_h)
363                                                 {
364                                                         over_pluginset = plugin->plugin_set;
365                                                 
366                                                         if(cursor_x >= plugin_x &&
367                                                                 cursor_x < plugin_x + plugin_w)
368                                                         {
369                                                                 over_plugin = plugin;
370                                                                 break;
371                                                         }
372                                                 }
373                                         }
374                                 }
375                                 break;
376                         }
377                 }
378         }
380         if (!over_track)        // check for pastes from patchbay
381                 over_track = mwindow->gui->patchbay->is_over_track();
383         if(mwindow->session->track_highlighted != over_track) 
384         {
385                 mwindow->session->track_highlighted = over_track;
386                 redraw = 1;
387         }
389         if(mwindow->session->edit_highlighted != over_edit)
390         {
391                 mwindow->session->edit_highlighted = over_edit;
392                 redraw = 1;
393         }
395         if(mwindow->session->pluginset_highlighted != over_pluginset)
396         {
397                 mwindow->session->pluginset_highlighted = over_pluginset;
398                 redraw = 1;
399         }
401         if(mwindow->session->plugin_highlighted != over_plugin)
402         {
403                 mwindow->session->plugin_highlighted = over_plugin;
404                 redraw = 1;
405         }
407 //printf("TrackCanvas::drag_motion 2 %p\n", mwindow->session->track_highlighted);
408         if(redraw)
409         {
410                 lock_window("TrackCanvas::drag_motion");
411                 draw_overlays();
412                 flash();
413                 unlock_window();
414         }
416         return 0;
419 int TrackCanvas::drag_start_event()
421         int result = 0;
422         int redraw = 0;
423         int rerender = 0;
424         int new_cursor, update_cursor;
426         if(mwindow->session->current_operation != NO_OPERATION) return 0;
428         if(is_event_win())
429         {
430                 if(test_plugins(get_drag_x(), 
431                         get_drag_y(), 
432                         1,
433                         0,
434                         redraw,
435                         rerender))
436                 {
437                         result = 1;
438                 }
439                 else
440                 if(test_edits(get_drag_x(),
441                         get_drag_y(),
442                         0,
443                         1,
444                         redraw,
445                         rerender,
446                         new_cursor,
447                         update_cursor))
448                 {
449                         result = 1;
450                 }
451         }
453         return result;
456 int TrackCanvas::drag_motion_event()
458         return drag_motion();
461 int TrackCanvas::cursor_leave_event()
463 // because drag motion calls get_cursor_over_window we can be sure that
464 // all highlights get deleted now
465         drag_motion();
466         return 0;
470 int TrackCanvas::drag_stop_event()
472         int result = drag_stop();
474         if(drag_popup)
475         {
476                 delete drag_popup;
477                 drag_popup = 0;
478         }
479         return result;
483 int TrackCanvas::drag_stop()
485 // In most cases the editing routine redraws and not the drag_stop
486         int result = 0, redraw = 0;
488         switch(mwindow->session->current_operation)
489         {
490                 case DRAG_VTRANSITION:
491                 case DRAG_ATRANSITION:
492                         if(mwindow->session->edit_highlighted)
493                         {
494                                 if((mwindow->session->current_operation == DRAG_ATRANSITION &&
495                                         mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
496                                         (mwindow->session->current_operation == DRAG_VTRANSITION &&
497                                         mwindow->session->track_highlighted->data_type == TRACK_VIDEO))
498                                 {
499                                         mwindow->session->current_operation = NO_OPERATION;
500                                         mwindow->paste_transition();
501                                         result = 1;
502                                 }
503                         }
504                         redraw = 1;
505                         break;
510 // Behavior for dragged plugins is limited by the fact that a shared plugin
511 // can only refer to a standalone plugin that exists in the same position in
512 // time.  Dragging a plugin from one point in time to another can't produce
513 // a shared plugin to the original plugin.  In this case we relocate the
514 // plugin instead of sharing it.
515                 case DRAG_AEFFECT_COPY:
516                 case DRAG_VEFFECT_COPY:
517                         if(mwindow->session->track_highlighted &&
518                                 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY &&
519                                         mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
520                                         (mwindow->session->current_operation == DRAG_VEFFECT_COPY &&
521                                         mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
522                         {
523                                 mwindow->session->current_operation = NO_OPERATION;
525 // Insert shared plugin in source
526                                 if(mwindow->session->track_highlighted != mwindow->session->drag_plugin->track &&
527                                         !mwindow->session->plugin_highlighted &&
528                                         !mwindow->session->pluginset_highlighted)
529                                 {
530 // Move plugin if different startproject
531                                         mwindow->move_effect(mwindow->session->drag_plugin,
532                                                 0,
533                                                 mwindow->session->track_highlighted,
534                                                 0);
535                                         result = 1;
536                                 }
537                                 else
538 // Move source to different location
539                                 if(mwindow->session->pluginset_highlighted)
540                                 {
541 //printf("TrackCanvas::drag_stop 6\n");
542                                         if(mwindow->session->plugin_highlighted)
543                                         {
544                                                 mwindow->move_effect(mwindow->session->drag_plugin,
545                                                         mwindow->session->plugin_highlighted->plugin_set,
546                                                         0,
547                                                         mwindow->session->plugin_highlighted->startproject);
548                                         }
549                                         else
550                                         {
551                                                 mwindow->move_effect(mwindow->session->drag_plugin,
552                                                         mwindow->session->pluginset_highlighted,
553                                                         0,
554                                                         mwindow->session->pluginset_highlighted->length());
555                                         }
556                                         result = 1;
557                                 }
558                                 else
559 // Move to a new plugin set between two edits
560                                 if(mwindow->session->edit_highlighted)
561                                 {
562                                         mwindow->move_effect(mwindow->session->drag_plugin,
563                                                 0,
564                                                 mwindow->session->track_highlighted,
565                                                 mwindow->session->edit_highlighted->startproject);
566                                         result = 1;
567                                 }
568                                 else
569 // Move to a new plugin set
570                                 if(mwindow->session->track_highlighted)
571                                 {
572                                         mwindow->move_effect(mwindow->session->drag_plugin,
573                                                 0,
574                                                 mwindow->session->track_highlighted,
575                                                 0);
576                                         result = 1;
577                                 }
578                         }
579                         break;
581                 case DRAG_AEFFECT:
582                 case DRAG_VEFFECT:
583                         if(mwindow->session->track_highlighted && 
584                                 ((mwindow->session->current_operation == DRAG_AEFFECT &&
585                                 mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
586                                 (mwindow->session->current_operation == DRAG_VEFFECT &&
587                                 mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
588                         {
589 // Drop all the effects
590                                 PluginSet *plugin_set = mwindow->session->pluginset_highlighted;
591                                 Track *track = mwindow->session->track_highlighted;
592                                 double start = 0;
593                                 double length = track->get_length();
595                                 if(mwindow->session->plugin_highlighted)
596                                 {
597                                         start = track->from_units(mwindow->session->plugin_highlighted->startproject);
598                                         length = track->from_units(mwindow->session->plugin_highlighted->length);
599                                         if(length <= 0) length = track->get_length();
600                                 }
601                                 else
602                                 if(mwindow->session->pluginset_highlighted)
603                                 {
604                                         start = track->from_units(plugin_set->length());
605                                         length = track->get_length() - start;
606                                         if(length <= 0) length = track->get_length();
607                                 }
608                                 else
609                                 if(mwindow->edl->local_session->get_selectionend() > 
610                                         mwindow->edl->local_session->get_selectionstart())
611                                 {
612                                         start = mwindow->edl->local_session->get_selectionstart();
613                                         length = mwindow->edl->local_session->get_selectionend() - 
614                                                 mwindow->edl->local_session->get_selectionstart();
615                                 }
616 // Move to a point between two edits
617                                 else
618                                 if(mwindow->session->edit_highlighted)
619                                 {
620                                         start = mwindow->session->track_highlighted->from_units(
621                                                 mwindow->session->edit_highlighted->startproject);
622                                         length = mwindow->session->track_highlighted->from_units(
623                                                 mwindow->session->edit_highlighted->length);
624                                 }
626                                 mwindow->insert_effects_canvas(start, length);
627                                 redraw = 1;
628                         }
629                         if (mwindow->session->track_highlighted)
630                                 result = 1;  // we have to cleanup
631                         break;
633                 case DRAG_ASSET:
634                         if(mwindow->session->track_highlighted)
635                         {
636                                 int64_t position = mwindow->session->edit_highlighted ?
637                                         mwindow->session->edit_highlighted->startproject :
638                                         mwindow->session->track_highlighted->edits->length();
639                                 double position_f = mwindow->session->track_highlighted->from_units(position);
640                                 Track *track = mwindow->session->track_highlighted;
641                                 mwindow->paste_assets(position_f, track);
642                                 result = 1;    // need to be one no matter what, since we have track highlited so we have to cleanup....
643                         }
644                         break;
646                 case DRAG_EDIT:
647                         mwindow->session->current_operation = NO_OPERATION;
648                         if(mwindow->session->track_highlighted)
649                         {
650                                 if(mwindow->session->track_highlighted->data_type == mwindow->session->drag_edit->track->data_type)
651                                 {
652                                         int64_t position = mwindow->session->edit_highlighted ?
653                                                 mwindow->session->edit_highlighted->startproject :
654                                                 mwindow->session->track_highlighted->edits->length();
655                                         double position_f = mwindow->session->track_highlighted->from_units(position);
656                                         Track *track = mwindow->session->track_highlighted;
657                                         mwindow->move_edits(mwindow->session->drag_edits,
658                                                 track,
659                                                 position_f);
660                                 }
662                                 result = 1;
663                         }
664                         break;
665         }
667 // since we don't have subwindows we have to terminate any drag operation
668         if(result)
669         {
670                 if (mwindow->session->track_highlighted
671                         || mwindow->session->edit_highlighted
672                         || mwindow->session->plugin_highlighted
673                         || mwindow->session->pluginset_highlighted) 
674                         redraw = 1;
675                 mwindow->session->track_highlighted = 0;
676                 mwindow->session->edit_highlighted = 0;
677                 mwindow->session->plugin_highlighted = 0;
678                 mwindow->session->pluginset_highlighted = 0;
679                 mwindow->session->current_operation = NO_OPERATION;
680         }
683 //printf("TrackCanvas::drag_stop %d %d\n", redraw, mwindow->session->current_operation);
684         if(redraw)
685         {
686                 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
687                 gui->get_scrollbars();
688                 draw();
689                 gui->patchbay->update();
690                 gui->cursor->update();
691                 flash();
692                 flush();
693         }
695         return result;
699 void TrackCanvas::draw(int force, int hide_cursor)
701 // Swap pixmap layers
702 TRACE("TrackCanvas::draw 1")
703         if(get_w() != background_pixmap->get_w() ||
704                 get_h() != background_pixmap->get_h())
705         {
706                 delete background_pixmap;
707                 background_pixmap = new BC_Pixmap(this, get_w(), get_h());
708         }
710 TRACE("TrackCanvas::draw 10")
711 // Cursor disappears after resize when this is called.
712 // Cursor doesn't redraw after editing when this isn't called.
713         if(gui->cursor && hide_cursor) gui->cursor->hide();
714 TRACE("TrackCanvas::draw 20")
715         draw_top_background(get_parent(), 0, 0, get_w(), get_h(), background_pixmap);
716 TRACE("TrackCanvas::draw 30")
717         draw_resources(force);
718 TRACE("TrackCanvas::draw 40")
719         draw_overlays();
720 UNTRACE
723 void TrackCanvas::update_cursor()
725         switch(mwindow->edl->session->editing_mode)
726         {
727                 case EDITING_ARROW: set_cursor(ARROW_CURSOR); break;
728                 case EDITING_IBEAM: set_cursor(IBEAM_CURSOR); break;
729         }
733 void TrackCanvas::draw_indexes(Asset *asset)
735 // Don't redraw raw samples
736         if(asset->index_zoom > mwindow->edl->local_session->zoom_sample)
737                 return;
739         draw_resources(0, 1, asset);
741         draw_overlays();
742         draw_automation();
743         flash();
744         flush();
747 void TrackCanvas::draw_resources(int force, 
748         int indexes_only, 
749         Asset *index_asset)
751 // Age resource pixmaps for deletion
752         if(!indexes_only)
753                 for(int i = 0; i < resource_pixmaps.total; i++)
754                         resource_pixmaps.values[i]->visible--;
756         if(force)
757                 resource_pixmaps.remove_all_objects();
759 //printf("TrackCanvas::draw_resources 1 %d %d\n", force, indexes_only);
761 // Search every edit
762         for(Track *current = mwindow->edl->tracks->first;
763                 current;
764                 current = NEXT)
765         {
766 //printf("TrackCanvas::draw_resources 2\n");
767                 for(Edit *edit = current->edits->first; edit; edit = edit->next)
768                 {
769 //printf("TrackCanvas::draw_resources 3\n");
770                         if(!edit->asset) continue;
771 //printf("TrackCanvas::draw_resources 4\n");
772                         if(indexes_only)
773                         {
774                                 if(edit->track->data_type != TRACK_AUDIO) continue;
775                                 if(!edit->asset->test_path(index_asset->path)) continue;
776                         }
778                         int64_t edit_x, edit_y, edit_w, edit_h;
779                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
780 //printf("TrackCanvas::draw_resources 10\n");
782 // Edit is visible
783                         if(MWindowGUI::visible(edit_x, edit_x + edit_w, 0, get_w()) &&
784                                 MWindowGUI::visible(edit_y, edit_y + edit_h, 0, get_h()))
785                         {
786                                 int64_t pixmap_x, pixmap_w, pixmap_h;
788 //printf("TrackCanvas::draw_resources 20\n");
789 // Search for existing pixmap containing edit
790                                 for(int i = 0; i < resource_pixmaps.total; i++)
791                                 {
792                                         ResourcePixmap* pixmap = resource_pixmaps.values[i];
793 //printf("TrackCanvas::draw_resources 30\n");
794 // Same pointer can be different edit if editing took place
795                                         if(pixmap->edit_id == edit->id)
796                                         {
797 //printf("TrackCanvas::draw_resources 40\n");
798                                                 pixmap->visible = 1;
799                                                 break;
800                                         }
801 //printf("TrackCanvas::draw_resources 50\n");
802                                 }
804 // Get new size, offset of pixmap needed
805                                 get_pixmap_size(edit, 
806                                         edit_x, 
807                                         edit_w, 
808                                         pixmap_x, 
809                                         pixmap_w, 
810                                         pixmap_h);
811 //printf("TrackCanvas::draw_resources 60\n");
813 // Draw new data
814                                 if(pixmap_w && pixmap_h)
815                                 {
816 // Create pixmap if it doesn't exist
817                                         ResourcePixmap* pixmap = create_pixmap(edit, 
818                                                 edit_x, 
819                                                 pixmap_x, 
820                                                 pixmap_w, 
821                                                 pixmap_h);
822 //printf("TrackCanvas::draw_resources 70\n");
823 // Resize it if it's bigger
824                                         if(pixmap_w > pixmap->pixmap_w ||
825                                                 pixmap_h > pixmap->pixmap_h)
826                                                 pixmap->resize(pixmap_w, pixmap_h);
827 //printf("TrackCanvas::draw_resources 80\n");
828                                         pixmap->draw_data(edit,
829                                                 edit_x, 
830                                                 edit_w, 
831                                                 pixmap_x, 
832                                                 pixmap_w, 
833                                                 pixmap_h, 
834                                                 force,
835                                                 indexes_only);
836 //printf("TrackCanvas::draw_resources 90\n");
837 // Resize it if it's smaller
838                                         if(pixmap_w < pixmap->pixmap_w ||
839                                                 pixmap_h < pixmap->pixmap_h)
840                                                 pixmap->resize(pixmap_w, pixmap_h);
841 //printf("TrackCanvas::draw_resources 100\n");
842 // Copy pixmap to background canvas
843                                         background_pixmap->draw_pixmap(pixmap, 
844                                                 pixmap->pixmap_x, 
845                                                 current->y_pixel,
846                                                 pixmap->pixmap_w,
847                                                 edit_h);
848 //printf("TrackCanvas::draw_resources 110\n");
849                                 }
850                         }
851                 }
852         }
853 //printf("TrackCanvas::draw_resources 200\n");
855 // Delete unused pixmaps
856         if(!indexes_only)
857                 for(int i = resource_pixmaps.total - 1; i >= 0; i--)
858                         if(resource_pixmaps.values[i]->visible < -5)
859                         {
860                                 delete resource_pixmaps.values[i];
861                                 resource_pixmaps.remove(resource_pixmaps.values[i]);
862                         }
865 ResourcePixmap* TrackCanvas::create_pixmap(Edit *edit, 
866         int64_t edit_x, 
867         int64_t pixmap_x, 
868         int64_t pixmap_w, 
869         int64_t pixmap_h)
871         ResourcePixmap *result = 0;
873         for(int i = 0; i < resource_pixmaps.total; i++)
874         {
875 //printf("TrackCanvas::create_pixmap 1 %d %d\n", edit->id, resource_pixmaps.values[i]->edit->id);
876                 if(resource_pixmaps.values[i]->edit_id == edit->id) 
877                 {
878                         result = resource_pixmaps.values[i];
879                         break;
880                 }
881         }
883         if(!result)
884         {
885 //printf("TrackCanvas::create_pixmap 2\n");
886                 result = new ResourcePixmap(mwindow, 
887                         this, 
888                         edit, 
889                         pixmap_w, 
890                         pixmap_h);
891                 resource_pixmaps.append(result);
892         }
894 //      result->resize(pixmap_w, pixmap_h);
895         return result;
898 void TrackCanvas::get_pixmap_size(Edit *edit, 
899         int64_t edit_x, 
900         int64_t edit_w, 
901         int64_t &pixmap_x, 
902         int64_t &pixmap_w,
903         int64_t &pixmap_h)
906 // Align x on frame boundaries
909 //      switch(edit->edits->track->data_type)
910 //      {
911 //              case TRACK_AUDIO:
913                         pixmap_x = edit_x;
914                         pixmap_w = edit_w;
915                         if(pixmap_x < 0)
916                         {
917                                 pixmap_w -= -edit_x;
918                                 pixmap_x = 0;
919                         }
921                         if(pixmap_x + pixmap_w > get_w())
922                         {
923                                 pixmap_w = get_w() - pixmap_x;
924                         }
926 //                      break;
927 // 
928 //              case TRACK_VIDEO:
929 //              {
930 //                      int64_t picon_w = (int64_t)(edit->picon_w() + 0.5);
931 //                      int64_t frame_w = (int64_t)(edit->frame_w() + 0.5);
932 //                      int64_t pixel_increment = MAX(picon_w, frame_w);
933 //                      int64_t pixmap_x1 = edit_x;
934 //                      int64_t pixmap_x2 = edit_x + edit_w;
935 // 
936 //                      if(pixmap_x1 < 0)
937 //                      {
938 //                              pixmap_x1 = (int64_t)((double)-edit_x / pixel_increment) * 
939 //                                      pixel_increment + 
940 //                                      edit_x;
941 //                      }
942 // 
943 //                      if(pixmap_x2 > get_w())
944 //                      {
945 //                              pixmap_x2 = (int64_t)((double)(get_w() - edit_x) / pixel_increment + 1) * 
946 //                                      pixel_increment + 
947 //                                      edit_x;
948 //                      }
949 //                      pixmap_x = pixmap_x1;
950 //                      pixmap_w = pixmap_x2 - pixmap_x1;
951 //                      break;
952 //              }
953 //      }
955         pixmap_h = mwindow->edl->local_session->zoom_track;
956         if(mwindow->edl->session->show_titles) pixmap_h += mwindow->theme->title_bg_data->get_h();
957 //printf("get_pixmap_size %d %d %d %d\n", edit_x, edit_w, pixmap_x, pixmap_w);
960 void TrackCanvas::edit_dimensions(Edit *edit, 
961         int64_t &x, 
962         int64_t &y, 
963         int64_t &w, 
964         int64_t &h)
966 //printf("TrackCanvas::edit_dimensions 1 %p\n", edit->track);
968         h = resource_h();
970 //printf("TrackCanvas::edit_dimensions 1\n");
971         x = Units::round(edit->track->from_units(edit->startproject) * 
972                         mwindow->edl->session->sample_rate /
973                         mwindow->edl->local_session->zoom_sample - 
974                         mwindow->edl->local_session->view_start);
976 // Method for calculating w so when edits are together we never get off by one error due to rounding
977         int64_t x_next = Units::round(edit->track->from_units(edit->startproject + edit->length) * 
978                         mwindow->edl->session->sample_rate /
979                         mwindow->edl->local_session->zoom_sample - 
980                         mwindow->edl->local_session->view_start);
981         w = x_next - x;
983 //printf("TrackCanvas::edit_dimensions 1\n");
984         y = edit->edits->track->y_pixel;
985 //printf("TrackCanvas::edit_dimensions 1\n");
987         if(mwindow->edl->session->show_titles) 
988                 h += mwindow->theme->title_bg_data->get_h();
989 //printf("TrackCanvas::edit_dimensions 2\n");
992 void TrackCanvas::track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
994         x = 0;
995         w = get_w();
996         y = track->y_pixel;
997         h = track->vertical_span(mwindow->theme);
1001 void TrackCanvas::draw_paste_destination()
1003         int current_atrack = 0;
1004         int current_vtrack = 0;
1005         int current_aedit = 0;
1006         int current_vedit = 0;
1007         int64_t w = 0;
1008         int64_t x;
1009         double position;
1011 //printf("TrackCanvas::draw_paste_destination 1\n");
1012         if((mwindow->session->current_operation == DRAG_ASSET &&
1013                         (mwindow->session->drag_assets->total ||
1014                         mwindow->session->drag_clips->total)) ||
1015                 (mwindow->session->current_operation == DRAG_EDIT &&
1016                         mwindow->session->drag_edits->total))
1017         {
1018 //printf("TrackCanvas::draw_paste_destination 1\n");
1019                 Asset *asset = 0;
1020                 EDL *clip = 0;
1021                 int draw_box = 0;
1023                 if(mwindow->session->current_operation == DRAG_ASSET &&
1024                         mwindow->session->drag_assets->total)
1025                         asset = mwindow->session->drag_assets->values[0];
1027                 if(mwindow->session->current_operation == DRAG_ASSET &&
1028                         mwindow->session->drag_clips->total)
1029                         clip = mwindow->session->drag_clips->values[0];
1031 // Get destination track
1032                 for(Track *dest = mwindow->session->track_highlighted; 
1033                         dest; 
1034                         dest = dest->next)
1035                 {
1036                         if(dest->record)
1037                         {
1038 // Get source width in pixels
1039                                 w = 0;
1042 // Use start of highlighted edit
1043                                 if(mwindow->session->edit_highlighted)
1044                                         position = mwindow->session->track_highlighted->from_units(
1045                                                 mwindow->session->edit_highlighted->startproject);
1046                                 else
1047 // Use end of highlighted track, disregarding effects
1048                                         position = mwindow->session->track_highlighted->from_units(
1049                                                 mwindow->session->track_highlighted->edits->length());
1051 // Get the x coordinate
1052                                 x = Units::to_int64(position * 
1053                                         mwindow->edl->session->sample_rate /
1054                                         mwindow->edl->local_session->zoom_sample) - 
1055                                         mwindow->edl->local_session->view_start;
1057                                 if(dest->data_type == TRACK_AUDIO)
1058                                 {
1059                                         if(asset && current_atrack < asset->channels)
1060                                         {
1061                                                 w = Units::to_int64((double)asset->audio_length /
1062                                                         asset->sample_rate *
1063                                                         mwindow->edl->session->sample_rate / 
1064                                                         mwindow->edl->local_session->zoom_sample);
1065                                                 current_atrack++;
1066                                                 draw_box = 1;
1067                                         }
1068                                         else
1069                                         if(clip && current_atrack < clip->tracks->total_audio_tracks())
1070                                         {
1071                                                 w = Units::to_int64((double)clip->tracks->total_length() *
1072                                                         mwindow->edl->session->sample_rate / 
1073                                                         mwindow->edl->local_session->zoom_sample);
1074 //printf("draw_paste_destination %d\n", x);
1075                                                 current_atrack++;
1076                                                 draw_box = 1;
1077                                         }
1078                                         else
1079                                         if(mwindow->session->current_operation == DRAG_EDIT &&
1080                                                 current_aedit < mwindow->session->drag_edits->total)
1081                                         {
1082                                                 Edit *edit;
1083                                                 while(current_aedit < mwindow->session->drag_edits->total &&
1084                                                         mwindow->session->drag_edits->values[current_aedit]->track->data_type != TRACK_AUDIO)
1085                                                         current_aedit++;
1087                                                 if(current_aedit < mwindow->session->drag_edits->total)
1088                                                 {
1089                                                         edit = mwindow->session->drag_edits->values[current_aedit];
1090                                                         w = Units::to_int64(edit->length / mwindow->edl->local_session->zoom_sample);
1092                                                         current_aedit++;
1093                                                         draw_box = 1;
1094                                                 }
1095                                         }
1096                                 }
1097                                 else
1098                                 if(dest->data_type == TRACK_VIDEO)
1099                                 {
1100 //printf("draw_paste_destination 1\n");
1101                                         if(asset && current_vtrack < asset->layers)
1102                                         {
1103                                                 w = Units::to_int64((double)asset->video_length / 
1104                                                         asset->frame_rate *
1105                                                         mwindow->edl->session->sample_rate /
1106                                                         mwindow->edl->local_session->zoom_sample);
1107                                                 current_vtrack++;
1108                                                 draw_box = 1;
1109                                         }
1110                                         else
1111                                         if(clip && current_vtrack < clip->tracks->total_video_tracks())
1112                                         {
1113                                                 w = Units::to_int64(clip->tracks->total_length() *
1114                                                         mwindow->edl->session->sample_rate / 
1115                                                         mwindow->edl->local_session->zoom_sample);
1116                                                 current_vtrack++;
1117                                                 draw_box = 1;
1118                                         }
1119                                         else
1120                                         if(mwindow->session->current_operation == DRAG_EDIT &&
1121                                                 current_vedit < mwindow->session->drag_edits->total)
1122                                         {
1123 //printf("draw_paste_destination 2\n");
1124                                                 Edit *edit;
1125                                                 while(current_vedit < mwindow->session->drag_edits->total &&
1126                                                         mwindow->session->drag_edits->values[current_vedit]->track->data_type != TRACK_VIDEO)
1127                                                         current_vedit++;
1129                                                 if(current_vedit < mwindow->session->drag_edits->total)
1130                                                 {
1131 //printf("draw_paste_destination 3\n");
1132                                                         edit = mwindow->session->drag_edits->values[current_vedit];
1133                                                         w = Units::to_int64(edit->track->from_units(edit->length) *
1134                                                                 mwindow->edl->session->sample_rate / 
1135                                                                 mwindow->edl->local_session->zoom_sample);
1137                                                         current_vedit++;
1138                                                         draw_box = 1;
1139                                                 }
1140                                         }
1141                                 }
1143                                 if(w)
1144                                 {
1145                                         int y = dest->y_pixel;
1146                                         int h = dest->vertical_span(mwindow->theme);
1149 //printf("TrackCanvas::draw_paste_destination 2 %d %d %d %d\n", x, y, w, h);
1150                                         if(x < -BC_INFINITY)
1151                                         {
1152                                                 w -= -BC_INFINITY - x;
1153                                                 x += -BC_INFINITY - x;
1154                                         }
1155                                         w = MIN(65535, w);
1156                                         draw_highlight_rectangle(x, y, w, h);
1157                                 }
1158                         }
1159                 }
1160         }
1163 void TrackCanvas::plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1165         x = Units::round(plugin->track->from_units(plugin->startproject) *
1166                 mwindow->edl->session->sample_rate / 
1167                 mwindow->edl->local_session->zoom_sample - 
1168                 mwindow->edl->local_session->view_start);
1169         w = Units::round(plugin->track->from_units(plugin->length) *
1170                 mwindow->edl->session->sample_rate / 
1171                 mwindow->edl->local_session->zoom_sample);
1172         y = plugin->track->y_pixel + 
1173                         mwindow->edl->local_session->zoom_track +
1174                         plugin->plugin_set->get_number() * 
1175                         mwindow->theme->plugin_bg_data->get_h();
1176         if(mwindow->edl->session->show_titles)
1177                 y += mwindow->theme->title_bg_data->get_h();
1178         h = mwindow->theme->plugin_bg_data->get_h();
1181 int TrackCanvas::resource_h()
1183         return mwindow->edl->local_session->zoom_track;
1186 void TrackCanvas::draw_highlight_rectangle(int x, int y, int w, int h)
1188         if(x < -10)
1189         {
1190                 w += x - -10;
1191                 x = -10;
1192         }
1193         if(y < -10)
1194         {
1195                 h += y - -10;
1196                 y = -10;
1197         }
1198         w = MIN(w, get_w() + 20);
1199         h = MIN(h, get_h() + 20);
1200         set_color(WHITE);
1201         set_inverse();
1202         draw_rectangle(x, y, w, h);
1203         draw_rectangle(x + 1, y + 1, w - 2, h - 2);
1204         set_opaque();
1205 //printf("TrackCanvas::draw_highlight_rectangle %d %d %d %d\n", x, y, w, h);
1208 void TrackCanvas::draw_playback_cursor()
1210 // Called before playback_cursor exists
1211 //      if(mwindow->playback_cursor && mwindow->playback_cursor->visible)
1212 //      {
1213 //              mwindow->playback_cursor->visible = 0;
1214 //              mwindow->playback_cursor->draw();
1215 //      }
1218 void TrackCanvas::get_handle_coords(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h, int side)
1220         int handle_w = mwindow->theme->edithandlein_data[0]->get_w();
1221         int handle_h = mwindow->theme->edithandlein_data[0]->get_h();
1223         edit_dimensions(edit, x, y, w, h);
1225         if(mwindow->edl->session->show_titles)
1226         {
1227                 y += mwindow->theme->title_bg_data->get_h();
1228         }
1229         else
1230         {
1231                 y = 0;
1232         }
1234         if(side == EDIT_OUT)
1235         {
1236                 x += w - handle_w;
1237         }
1239         h = handle_h;
1240         w = handle_w;
1243 void TrackCanvas::get_transition_coords(int64_t &x, int64_t &y, int64_t &w, int64_t &h)
1245 //printf("TrackCanvas::get_transition_coords 1\n");
1246 //      int transition_w = mwindow->theme->transitionhandle_data[0]->get_w();
1247 //      int transition_h = mwindow->theme->transitionhandle_data[0]->get_h();
1248         int transition_w = 30;
1249         int transition_h = 30;
1250 //printf("TrackCanvas::get_transition_coords 1\n");
1252         if(mwindow->edl->session->show_titles)
1253                 y += mwindow->theme->title_bg_data->get_h();
1254 //printf("TrackCanvas::get_transition_coords 2\n");
1256         y += (h - mwindow->theme->title_bg_data->get_h()) / 2 - transition_h / 2;
1257         x -= transition_w / 2;
1259         h = transition_h;
1260         w = transition_w;
1263 void TrackCanvas::draw_highlighting()
1265         int64_t x, y, w, h;
1266         int draw_box = 0;
1267 //printf("TrackCanvas::draw_highlighting 1 %p %d\n", mwindow->session->track_highlighted, mwindow->session->current_operation);
1271         switch(mwindow->session->current_operation)
1272         {
1273                 case DRAG_ATRANSITION:
1274                 case DRAG_VTRANSITION:
1275 //printf("TrackCanvas::draw_highlighting 1 %p %p\n", 
1276 //      mwindow->session->track_highlighted, mwindow->session->edit_highlighted);
1277                         if(mwindow->session->edit_highlighted)
1278                         {
1279 //printf("TrackCanvas::draw_highlighting 2\n");
1280                                 if((mwindow->session->current_operation == DRAG_ATRANSITION && 
1281                                         mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1282                                         (mwindow->session->current_operation == DRAG_VTRANSITION && 
1283                                         mwindow->session->track_highlighted->data_type == TRACK_VIDEO))
1284                                 {
1285 //printf("TrackCanvas::draw_highlighting 2\n");
1286                                         edit_dimensions(mwindow->session->edit_highlighted, x, y, w, h);
1287 //printf("TrackCanvas::draw_highlighting 2\n");
1289                                         if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1290                                                 MWindowGUI::visible(y, y + h, 0, get_h()))
1291                                         {
1292                                                 draw_box = 1;
1293                                                 get_transition_coords(x, y, w, h);
1294                                         }
1295 //printf("TrackCanvas::draw_highlighting 3\n");
1296                                 }
1297                         }
1298                         break;
1302 // Dragging a new effect from the Resource window
1303                 case DRAG_AEFFECT:
1304                 case DRAG_VEFFECT:
1305                         if(mwindow->session->track_highlighted &&
1306                                 ((mwindow->session->current_operation == DRAG_AEFFECT && mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1307                                         (mwindow->session->current_operation == DRAG_VEFFECT && mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
1308                         {
1309 // Put it before another plugin
1310                                 if(mwindow->session->plugin_highlighted)
1311                                 {
1312                                         plugin_dimensions(mwindow->session->plugin_highlighted, 
1313                                                 x, 
1314                                                 y, 
1315                                                 w, 
1316                                                 h);
1317 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1318                                 }
1319                                 else
1320 // Put it after a plugin set
1321                                 if(mwindow->session->pluginset_highlighted &&
1322                                         mwindow->session->pluginset_highlighted->last)
1323                                 {
1324                                         plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last, 
1325                                                 x, 
1326                                                 y, 
1327                                                 w, 
1328                                                 h);
1329 //printf("TrackCanvas::draw_highlighting 1 %d %d\n", x, w);
1330                                         int64_t track_x, track_y, track_w, track_h;
1331                                         track_dimensions(mwindow->session->track_highlighted, 
1332                                                 track_x, 
1333                                                 track_y, 
1334                                                 track_w, 
1335                                                 track_h);
1337                                         x += w;
1338                                         w = Units::round(
1339                                                         mwindow->session->track_highlighted->get_length() *
1340                                                         mwindow->edl->session->sample_rate / 
1341                                                         mwindow->edl->local_session->zoom_sample - 
1342                                                         mwindow->edl->local_session->view_start) -
1343                                                 x;
1344 //printf("TrackCanvas::draw_highlighting 2 %d\n", w);
1345                                         if(w <= 0) w = track_w;
1346                                 }
1347                                 else
1348                                 {
1349                                         track_dimensions(mwindow->session->track_highlighted, 
1350                                                 x, 
1351                                                 y, 
1352                                                 w, 
1353                                                 h);
1355 //printf("TrackCanvas::draw_highlighting 1 %d %d %d %d\n", x, y, w, h);
1356 // Put it in a new plugin set determined by the selected range
1357                                         if(mwindow->edl->local_session->get_selectionend() > 
1358                                                 mwindow->edl->local_session->get_selectionstart())
1359                                         {
1360                                                 x = Units::to_int64(mwindow->edl->local_session->get_selectionstart() *
1361                                                         mwindow->edl->session->sample_rate / 
1362                                                         mwindow->edl->local_session->zoom_sample -
1363                                                         mwindow->edl->local_session->view_start);
1364                                                 w = Units::to_int64((mwindow->edl->local_session->get_selectionend() - 
1365                                                         mwindow->edl->local_session->get_selectionstart()) *
1366                                                         mwindow->edl->session->sample_rate / 
1367                                                         mwindow->edl->local_session->zoom_sample);
1368                                         }
1369 // Put it in a new plugin set determined by an edit boundary
1370                                         else
1371                                         if(mwindow->session->edit_highlighted)
1372                                         {
1373                                                 int64_t temp_y, temp_h;
1374                                                 edit_dimensions(mwindow->session->edit_highlighted, 
1375                                                         x, 
1376                                                         temp_y, 
1377                                                         w, 
1378                                                         temp_h);
1379                                         }
1380 // Put it at the beginning of the track in a new plugin set
1381                                 }
1383                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1384                                         MWindowGUI::visible(y, y + h, 0, get_h()))
1385                                 {
1386 //printf("TrackCanvas::draw_highlighting 1\n");
1387                                         draw_box = 1;
1388                                 }
1389                         }
1390                         break;
1391                 
1392                 case DRAG_ASSET:
1393                         if(mwindow->session->track_highlighted)
1394                         {
1395                                 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1397                                 if(MWindowGUI::visible(y, y + h, 0, get_h()))
1398                                 {
1399                                         draw_paste_destination();
1400                                 }
1401                         }
1402                         break;
1404 // Dragging an effect from the timeline
1405                 case DRAG_AEFFECT_COPY:
1406                 case DRAG_VEFFECT_COPY:
1407                         if((mwindow->session->plugin_highlighted || mwindow->session->track_highlighted) &&
1408                                 ((mwindow->session->current_operation == DRAG_AEFFECT_COPY && mwindow->session->track_highlighted->data_type == TRACK_AUDIO) ||
1409                                 (mwindow->session->current_operation == DRAG_VEFFECT_COPY && mwindow->session->track_highlighted->data_type == TRACK_VIDEO)))
1410                         {
1411 // Put it before another plugin
1412                                 if(mwindow->session->plugin_highlighted)
1413                                         plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1414                                 else
1415 // Put it after a plugin set
1416                                 if(mwindow->session->pluginset_highlighted &&
1417                                         mwindow->session->pluginset_highlighted->last)
1418                                 {
1419                                         plugin_dimensions((Plugin*)mwindow->session->pluginset_highlighted->last, x, y, w, h);
1420                                         x += w;
1421                                 }
1422                                 else
1423                                 if(mwindow->session->track_highlighted)
1424                                 {
1425                                         track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1427 // Put it in a new plugin set determined by an edit boundary
1428                                         if(mwindow->session->edit_highlighted)
1429                                         {
1430                                                 int64_t temp_y, temp_h;
1431                                                 edit_dimensions(mwindow->session->edit_highlighted, 
1432                                                         x, 
1433                                                         temp_y, 
1434                                                         w, 
1435                                                         temp_h);
1436                                         }
1437 // Put it in a new plugin set at the start of the track
1438                                 }
1440 // Calculate length of plugin based on data type of track and units
1441                                 if(mwindow->session->track_highlighted->data_type == TRACK_VIDEO)
1442                                 {
1443                                         w = (int64_t)((double)mwindow->session->drag_plugin->length / 
1444                                                 mwindow->edl->session->frame_rate *
1445                                                 mwindow->edl->session->sample_rate /
1446                                                 mwindow->edl->local_session->zoom_sample);
1447                                 }
1448                                 else
1449                                 {
1450                                         w = (int64_t)mwindow->session->drag_plugin->length /
1451                                                 mwindow->edl->local_session->zoom_sample;
1452                                 }
1454                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1455                                         MWindowGUI::visible(y, y + h, 0, get_h()))
1456                                 {
1457                                         draw_box = 1;
1458                                 }
1459                         }
1460                         break;
1462                 case DRAG_PLUGINKEY:
1463                         if(mwindow->session->plugin_highlighted && 
1464                            mwindow->session->current_operation == DRAG_PLUGINKEY)
1465                         {
1466 // Just highlight the plugin
1467                                 plugin_dimensions(mwindow->session->plugin_highlighted, x, y, w, h);
1469                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1470                                         MWindowGUI::visible(y, y + h, 0, get_h()))
1471                                 {
1472                                         draw_box = 1;
1473                                 }
1474                         }
1475                         break;
1477                 case DRAG_EDIT:
1478 //printf("TrackCanvas::draw_highlighting 1\n");
1479                         if(mwindow->session->track_highlighted)
1480                         {
1481                                 track_dimensions(mwindow->session->track_highlighted, x, y, w, h);
1483                                 if(MWindowGUI::visible(y, y + h, 0, get_h()))
1484                                 {
1485                                         draw_paste_destination();
1486                                 }
1487                         }
1488                         break;
1489         }
1492         if(draw_box)
1493         {
1494                 draw_highlight_rectangle(x, y, w, h);
1495         }
1498 void TrackCanvas::draw_plugins()
1500         char string[BCTEXTLEN];
1502         for(Track *track = mwindow->edl->tracks->first;
1503                 track;
1504                 track = track->next)
1505         {
1506                 if(track->expand_view)
1507                 {
1508                         for(int i = 0; i < track->plugin_set.total; i++)
1509                         {
1510                                 PluginSet *pluginset = track->plugin_set.values[i];
1512                                 for(Plugin *plugin = (Plugin*)pluginset->first; plugin; plugin = (Plugin*)plugin->next)
1513                                 {
1514                                         int64_t total_x, y, total_w, h;
1515                                         plugin_dimensions(plugin, total_x, y, total_w, h);
1516                                         
1517                                         if(MWindowGUI::visible(total_x, total_x + total_w, 0, get_w()) &&
1518                                                 MWindowGUI::visible(y, y + h, 0, get_h()) &&
1519                                                 plugin->plugin_type != PLUGIN_NONE)
1520                                         {
1521                                                 int x = total_x, w = total_w, left_margin = 5;
1522                                                 if(x < 0)
1523                                                 {
1524                                                         w -= -x;
1525                                                         x = 0;
1526                                                 }
1527                                                 if(w + x > get_w()) w -= (w + x) - get_w();
1529                                                 draw_3segmenth(x, 
1530                                                         y, 
1531                                                         w, 
1532                                                         total_x,
1533                                                         total_w,
1534                                                         mwindow->theme->plugin_bg_data,
1535                                                         0);
1536                                                 set_color(WHITE);
1537                                                 set_font(MEDIUMFONT_3D);
1538                                                 plugin->calculate_title(string, 0);
1540 // Truncate string to int64_test visible in background
1541                                                 int len = strlen(string), j;
1542                                                 for(j = len; j >= 0; j--)
1543                                                 {
1544                                                         if(left_margin + get_text_width(MEDIUMFONT_3D, string) > w)
1545                                                         {
1546                                                                 string[j] = 0;
1547                                                         }
1548                                                         else
1549                                                                 break;
1550                                                 }
1552 // Justify the text on the left boundary of the edit if it is visible.
1553 // Otherwise justify it on the left side of the screen.
1554                                                 int text_x = total_x + left_margin;
1555                                                 text_x = MAX(left_margin, text_x);
1556                                                 draw_text(text_x, 
1557                                                         y + get_text_ascent(MEDIUMFONT_3D) + 2, 
1558                                                         string,
1559                                                         strlen(string),
1560                                                         0);
1561                                         }
1562                                 }
1563                         }
1564                 }
1565         }
1569 void TrackCanvas::draw_inout_points()
1574 void TrackCanvas::draw_drag_handle()
1576         if(mwindow->session->current_operation == DRAG_EDITHANDLE2 ||
1577                 mwindow->session->current_operation == DRAG_PLUGINHANDLE2)
1578         {
1579 //printf("TrackCanvas::draw_drag_handle 1 %ld %ld\n", mwindow->session->drag_sample, mwindow->edl->local_session->view_start);
1580                 int64_t pixel1 = Units::round(mwindow->session->drag_position * 
1581                         mwindow->edl->session->sample_rate /
1582                         mwindow->edl->local_session->zoom_sample - 
1583                         mwindow->edl->local_session->view_start);
1584 //printf("TrackCanvas::draw_drag_handle 2 %d\n", pixel1);
1585                 set_color(GREEN);
1586                 set_inverse();
1587 //printf("TrackCanvas::draw_drag_handle 3\n");
1588                 draw_line(pixel1, 0, pixel1, get_h());
1589                 set_opaque();
1590 //printf("TrackCanvas::draw_drag_handle 4\n");
1591         }
1595 void TrackCanvas::draw_transitions()
1597         int64_t x, y, w, h;
1599         for(Track *track = mwindow->edl->tracks->first;
1600                 track;
1601                 track = track->next)
1602         {
1603                 for(Edit *edit = track->edits->first;
1604                         edit;
1605                         edit = edit->next)
1606                 {
1607                         if(edit->transition)
1608                         {
1609                                 int64_t strip_w, strip_x, strip_y;
1610                                 edit_dimensions(edit, x, y, w, h);
1611                                 strip_x = x ;
1612                                 strip_y = y;
1613                                 if(mwindow->edl->session->show_titles)
1614                                         strip_y += mwindow->theme->title_bg_data->get_h();
1616                                 get_transition_coords(x, y, w, h);
1617                                 strip_w = Units::round(edit->track->from_units(edit->transition->length) * 
1618                                         mwindow->edl->session->sample_rate / 
1619                                         mwindow->edl->local_session->zoom_sample);
1621                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
1622                                         MWindowGUI::visible(y, y + h, 0, get_h()))
1623                                 {
1624                                         PluginServer *server = mwindow->scan_plugindb(edit->transition->title,
1625                                                 track->data_type);
1626                                         draw_vframe(server->picon, 
1627                                                 x, 
1628                                                 y, 
1629                                                 w, 
1630                                                 h, 
1631                                                 0, 
1632                                                 0, 
1633                                                 server->picon->get_w(), 
1634                                                 server->picon->get_h());
1635                                 }
1636                                 if(MWindowGUI::visible(strip_x, strip_x + strip_w, 0, get_w()) &&
1637                                         MWindowGUI::visible(strip_y, strip_y + h, 0, get_h()))
1638                                 {
1639                                         int x = strip_x, w = strip_w, left_margin = 5;
1640                                         if(x < 0)
1641                                         {
1642                                                 w -= -x;
1643                                                 x = 0;
1644                                         }
1645                                         if(w + x > get_w()) w -= (w + x) - get_w();
1646                                 
1647                                         draw_3segmenth(
1648                                                 x, 
1649                                                 strip_y, 
1650                                                 w, 
1651                                                 strip_x,
1652                                                 strip_w,
1653                                                 mwindow->theme->plugin_bg_data,
1654                                                 0);
1656                                 }
1657                         }
1658                 }
1659         }
1662 void TrackCanvas::draw_loop_points()
1664 //printf("TrackCanvas::draw_loop_points 1\n");
1665         if(mwindow->edl->local_session->loop_playback)
1666         {
1667 //printf("TrackCanvas::draw_loop_points 2\n");
1668                 int64_t x = Units::round(mwindow->edl->local_session->loop_start *
1669                         mwindow->edl->session->sample_rate /
1670                         mwindow->edl->local_session->zoom_sample - 
1671                         mwindow->edl->local_session->view_start);
1672 //printf("TrackCanvas::draw_loop_points 3\n");
1674                 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1675                 {
1676                         set_color(GREEN);
1677                         draw_line(x, 0, x, get_h());
1678                 }
1679 //printf("TrackCanvas::draw_loop_points 4\n");
1681                 x = Units::round(mwindow->edl->local_session->loop_end *
1682                         mwindow->edl->session->sample_rate /
1683                         mwindow->edl->local_session->zoom_sample - 
1684                         mwindow->edl->local_session->view_start);
1685 //printf("TrackCanvas::draw_loop_points 5\n");
1687                 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1688                 {
1689                         set_color(GREEN);
1690                         draw_line(x, 0, x, get_h());
1691                 }
1692 //printf("TrackCanvas::draw_loop_points 6\n");
1693         }
1694 //printf("TrackCanvas::draw_loop_points 7\n");
1697 void TrackCanvas::draw_brender_start()
1699         if(mwindow->preferences->use_brender)
1700         {
1701                 int64_t x = Units::round(mwindow->edl->session->brender_start *
1702                         mwindow->edl->session->sample_rate /
1703                         mwindow->edl->local_session->zoom_sample - 
1704                         mwindow->edl->local_session->view_start);
1706                 if(MWindowGUI::visible(x, x + 1, 0, get_w()))
1707                 {
1708                         set_color(RED);
1709                         draw_line(x, 0, x, get_h());
1710                 }
1711         }
1714 int TrackCanvas::do_keyframes(int cursor_x, 
1715         int cursor_y, 
1716         int draw, 
1717         int buttonpress, 
1718         int &new_cursor,
1719         int &update_cursor,
1720         int &rerender)
1722 // Note: button 3 (right mouse button) is not eaten to allow
1723 // track context menu to appear
1724         int current_tool = 0;
1725         int result = 0;
1726         EDLSession *session = mwindow->edl->session;
1728         for(Track *track = mwindow->edl->tracks->first;
1729                 track && !result;
1730                 track = track->next)
1731         {
1732                 Automation *automation = track->automation;
1734 //printf("TrackCanvas::draw_keyframes 1\n");
1735                 if(!result && session->auto_conf->fade)
1736                 {
1737                         Auto *auto_keyframe;
1738                         result = do_float_autos(track, 
1739                                 automation->fade_autos,
1740                                 cursor_x, 
1741                                 cursor_y, 
1742                                 draw, 
1743                                 buttonpress, 
1744                                 WHITE,
1745                                 auto_keyframe);
1746                         if(result && mwindow->session->current_operation == DRAG_FADE && (buttonpress != 3))
1747                         {
1748                                 rerender = 1;
1749                         }
1750                         if(result && buttonpress && (buttonpress != 3))
1751                         {
1752                                 synchronize_autos(0, track, (FloatAuto*)mwindow->session->drag_auto, 1);
1753                                 mwindow->session->current_operation = DRAG_FADE;
1754                                 update_drag_caption();
1755                         }
1756                         if (result && (buttonpress == 3))
1757                         {
1758                                 gui->keyframe_menu->update(automation, automation->fade_autos, auto_keyframe);
1759                                 gui->keyframe_menu->activate_menu();
1760                                 rerender = 1; // the position changes
1761                         }
1762                 }
1764 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1766                 if(!result && session->auto_conf->czoom && automation->czoom_autos)
1767                 {
1768                         Auto *auto_keyframe;
1769                         result = do_float_autos(track, 
1770                                 automation->czoom_autos,
1771                                 cursor_x, 
1772                                 cursor_y, 
1773                                 draw, 
1774                                 buttonpress,
1775                                 MEPURPLE,
1776                                 auto_keyframe);
1777                         if(result && mwindow->session->current_operation == DRAG_CZOOM && (buttonpress != 3))
1778                         {
1779                                 rerender = 1;
1780                         }
1781                         if(result && buttonpress && (buttonpress != 3))
1782                         {
1783                                 mwindow->session->current_operation = DRAG_CZOOM;
1784                                 update_drag_caption();
1785                         }
1786                         if (result && (buttonpress == 3))
1787                         {
1788                                 gui->keyframe_menu->update(automation, automation->czoom_autos, auto_keyframe);
1789                                 gui->keyframe_menu->activate_menu();
1790                                 rerender = 1; // the position changes
1791                         }
1792                 }
1794 //printf("TrackCanvas::draw_keyframes 2 %d\n", result);
1795                 if(!result && session->auto_conf->pzoom && automation->pzoom_autos)
1796                 {
1797                         Auto *auto_keyframe;
1798                         result = do_float_autos(track, 
1799                                 automation->pzoom_autos,
1800                                 cursor_x, 
1801                                 cursor_y, 
1802                                 draw, 
1803                                 buttonpress,
1804                                 PINK,
1805                                 auto_keyframe);
1806                         if(result && mwindow->session->current_operation == DRAG_PZOOM && (buttonpress != 3))
1807                         {
1808                                 rerender = 1;
1809                         }
1810                         if(result && buttonpress && (buttonpress != 3))
1811                         {
1812                                 mwindow->session->current_operation = DRAG_PZOOM;
1813                                 update_drag_caption();
1814                         }
1815                         if (result && (buttonpress == 3))
1816                         {
1817                                 gui->keyframe_menu->update(automation, automation->pzoom_autos, auto_keyframe);
1818                                 gui->keyframe_menu->activate_menu();
1819                                 rerender = 1; // the position changes
1820                         }
1821                 }
1823 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1824                 if(!result && session->auto_conf->mute)
1825                 {
1826                         Auto *auto_keyframe;
1827                         result = do_toggle_autos(track, 
1828                                 automation->mute_autos,
1829                                 cursor_x, 
1830                                 cursor_y, 
1831                                 draw, 
1832                                 buttonpress,
1833                                 BLUE,
1834                                 auto_keyframe);
1835                         if(result && mwindow->session->current_operation == DRAG_MUTE && (buttonpress != 3))
1836                         {
1837                                 rerender = 1;
1838                         }
1839                         if(result && buttonpress && (buttonpress != 3))
1840                         {
1841                                 mwindow->session->current_operation = DRAG_MUTE;
1842                                 update_drag_caption();
1843                         }
1844                         if (result && (buttonpress == 3))
1845                         {
1846                                 gui->keyframe_menu->update(automation, automation->mute_autos, auto_keyframe);
1847                                 gui->keyframe_menu->activate_menu();
1848                                 rerender = 1; // the position changes
1849                         }
1850                 }
1852 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1853                 if(!result && session->auto_conf->camera && automation->camera_autos)
1854                 {
1855                         Auto *auto_keyframe;
1856                         result = do_autos(track, 
1857                                 automation->camera_autos,
1858                                 cursor_x, 
1859                                 cursor_y, 
1860                                 draw, 
1861                                 buttonpress,
1862                                 camerakeyframe_pixmap,
1863                                 auto_keyframe);
1864                         if(result && mwindow->session->current_operation == DRAG_CAMERA && (buttonpress != 3))
1865                         {
1866                                 rerender = 1;
1867                         }
1868                         if(result && buttonpress && (buttonpress != 3))
1869                         {
1870                                 mwindow->session->current_operation = DRAG_CAMERA_PRE;
1871                                 update_drag_caption();
1872                                 rerender = 1;
1873                         }
1874                         if (result && (buttonpress == 3))
1875                         {
1876                                 gui->keyframe_menu->update(automation, automation->camera_autos, auto_keyframe);
1877                                 gui->keyframe_menu->activate_menu();
1878                                 rerender = 1; // the position changes
1879                         }
1881                 }
1883                 if(!result && session->auto_conf->mode && automation->mode_autos)
1884                 {
1885                         Auto *auto_keyframe;
1886                         result = do_autos(track, 
1887                                 automation->mode_autos,
1888                                 cursor_x, 
1889                                 cursor_y, 
1890                                 draw, 
1891                                 buttonpress,
1892                                 modekeyframe_pixmap,
1893                                 auto_keyframe);
1894                         if(result && mwindow->session->current_operation == DRAG_MODE && (buttonpress != 3))
1895                         {
1896                                 rerender = 1;
1897                         }
1898                         if(result && buttonpress && (buttonpress != 3))
1899                         {
1900                                 mwindow->session->current_operation = DRAG_MODE_PRE;
1901                                 update_drag_caption();
1902                                 rerender = 1;
1903                         }
1904                         if (result && (buttonpress == 3))
1905                         {
1906                                 gui->keyframe_menu->update(automation, automation->mode_autos, auto_keyframe);
1907                                 gui->keyframe_menu->activate_menu();
1908                                 rerender = 1; // the position changes
1909                         }
1910                 }
1912 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1913                 if(!result && session->auto_conf->projector && automation->projector_autos)
1914                 {
1915                         Auto *auto_keyframe;
1916                         result = do_autos(track, 
1917                                 automation->projector_autos,
1918                                 cursor_x, 
1919                                 cursor_y, 
1920                                 draw, 
1921                                 buttonpress,
1922                                 projectorkeyframe_pixmap,
1923                                 auto_keyframe);
1924                         if(result && mwindow->session->current_operation == DRAG_PROJECTOR && (buttonpress != 3))
1925                         {
1926                                 rerender = 1;
1927                         }
1928                         if(result && buttonpress && (buttonpress != 3))
1929                         {
1930                                 mwindow->session->current_operation = DRAG_PROJECTOR_PRE;
1931                                 update_drag_caption();
1932                                 rerender = 1;
1933                         }
1934                         if (result && (buttonpress == 3))
1935                         {
1936                                 gui->keyframe_menu->update(automation, automation->projector_autos, auto_keyframe);
1937                                 gui->keyframe_menu->activate_menu();
1938                                 rerender = 1; // the position changes
1939                         }
1940                 }
1942                 if(!result && session->auto_conf->mask && automation->mask_autos)
1943                 {
1944                         Auto *auto_keyframe;
1945                         result = do_autos(track, 
1946                                 automation->mask_autos,
1947                                 cursor_x, 
1948                                 cursor_y, 
1949                                 draw, 
1950                                 buttonpress,
1951                                 maskkeyframe_pixmap,
1952                                 auto_keyframe);
1953                         if(result && mwindow->session->current_operation == DRAG_MASK && (buttonpress != 3))
1954                         {
1955                                 rerender = 1;
1956                         }
1957                         if(result && buttonpress && (buttonpress != 3))
1958                         {
1959                                 mwindow->session->current_operation = DRAG_MASK_PRE;
1960                                 update_drag_caption();
1961                                 rerender = 1;
1962                         }
1963                         if (result && (buttonpress == 3))
1964                         {
1965                                 gui->keyframe_menu->update(automation, automation->mask_autos, auto_keyframe);
1966                                 gui->keyframe_menu->activate_menu();
1967                                 rerender = 1; // the position changes
1968                         }
1969                 }
1971 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
1972                 if(!result && session->auto_conf->pan && automation->pan_autos)
1973                 {
1974                         Auto *auto_keyframe;
1975                         result = do_autos(track, 
1976                                 automation->pan_autos,
1977                                 cursor_x, 
1978                                 cursor_y, 
1979                                 draw, 
1980                                 buttonpress,
1981                                 pankeyframe_pixmap,
1982                                 auto_keyframe);
1984                         if(result && mwindow->session->current_operation == DRAG_PAN && (buttonpress != 3))
1985                         {
1986                                 rerender = 1;
1987                         }
1988                         if(result && buttonpress && (buttonpress != 3))
1989                         {
1990                                 mwindow->session->current_operation = DRAG_PAN_PRE;
1991                                 update_drag_caption();
1992                                 rerender = 1;
1993                         }
1994                         if (result && (buttonpress == 3))
1995                         {
1996                                 gui->keyframe_menu->update(automation, automation->pan_autos, auto_keyframe);
1997                                 gui->keyframe_menu->activate_menu();
1998                                 rerender = 1; // the position changes
1999                         }
2000                 }
2002 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
2003                 if(!result && session->auto_conf->plugins)
2004                 {
2005                         Plugin *plugin;
2006                         KeyFrame *keyframe;
2007                         result = do_plugin_autos(track,
2008                                 cursor_x, 
2009                                 cursor_y, 
2010                                 draw, 
2011                                 buttonpress,
2012                                 plugin,
2013                                 keyframe);
2014                         if(result && mwindow->session->current_operation == DRAG_PLUGINKEY)
2015                         {
2016                                 rerender = 1;
2017                         }
2018                         if(result && (buttonpress == 1))
2019                         {
2020                                 mwindow->session->current_operation = DRAG_PLUGINKEY_PRE;
2021                                 update_drag_caption();
2022                                 rerender = 1;
2023                         } else
2024                         if (result && (buttonpress == 3))
2025                         {
2026                                 gui->keyframe_menu->update(plugin, keyframe);
2027                                 gui->keyframe_menu->activate_menu();
2028                                 rerender = 1; // the position changes
2029                         }
2030                 }
2031 //printf("TrackCanvas::draw_keyframes 1 %d\n", result);
2032         }
2034         if(mwindow->session->current_operation == DRAG_FADE ||
2035                 mwindow->session->current_operation == DRAG_CZOOM ||
2036                 mwindow->session->current_operation == DRAG_PZOOM ||
2037                 mwindow->session->current_operation == DRAG_PLAY ||
2038                 mwindow->session->current_operation == DRAG_MUTE ||
2039                 mwindow->session->current_operation == DRAG_CAMERA ||
2040                 mwindow->session->current_operation == DRAG_CAMERA_PRE ||
2041                 mwindow->session->current_operation == DRAG_MASK ||
2042                 mwindow->session->current_operation == DRAG_MASK_PRE ||
2043                 mwindow->session->current_operation == DRAG_MODE ||
2044                 mwindow->session->current_operation == DRAG_MODE_PRE ||
2045                 mwindow->session->current_operation == DRAG_PAN ||
2046                 mwindow->session->current_operation == DRAG_PAN_PRE ||
2047                 mwindow->session->current_operation == DRAG_PLUGINKEY ||
2048                 mwindow->session->current_operation == DRAG_PLUGINKEY_PRE ||
2049                 mwindow->session->current_operation == DRAG_PROJECTOR ||
2050                 mwindow->session->current_operation == DRAG_PROJECTOR_PRE)
2051         {
2052                 result = 1;
2053         }
2055 //printf("TrackCanvas::draw_keyframes 2 %d\n", result);
2056         update_cursor = 1;
2057         if(result)
2058         {
2059                 new_cursor = UPRIGHT_ARROW_CURSOR;
2060 //              rerender = 1;
2061         }
2063 //printf("TrackCanvas::do_keyframes 3 %d\n", result);
2064         return result;
2067 void TrackCanvas::draw_auto(Auto *current, 
2068         int x, 
2069         int y, 
2070         int center_pixel, 
2071         int zoom_track,
2072         int color)
2074         int x1, y1, x2, y2;
2075         char string[BCTEXTLEN];
2077         x1 = x - HANDLE_W / 2;
2078         x2 = x + HANDLE_W / 2;
2079         y1 = center_pixel + y - HANDLE_W / 2;
2080         y2 = center_pixel + y + HANDLE_W / 2;
2082         if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2083         if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2085         set_color(BLACK);
2086         draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2087         set_color(color);
2088         draw_box(x1, y1, x2 - x1, y2 - y1);
2091 void TrackCanvas::draw_floatauto(Auto *current, 
2092         int x, 
2093         int y, 
2094         int in_x, 
2095         int in_y, 
2096         int out_x, 
2097         int out_y, 
2098         int center_pixel, 
2099         int zoom_track,
2100         int color)
2102         int x1, y1, x2, y2;
2103         int in_x1, in_y1, in_x2, in_y2;
2104         int out_x1, out_y1, out_x2, out_y2;
2105         char string[BCTEXTLEN];
2107 // Center
2108         x1 = x - HANDLE_W / 2;
2109         x2 = x + HANDLE_W / 2;
2110         y1 = center_pixel + y - HANDLE_W / 2;
2111         y2 = center_pixel + y + HANDLE_W / 2;
2113         CLAMP(y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
2114         CLAMP(y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
2116         set_color(BLACK);
2117         draw_box(x1 + 1, y1 + 1, x2 - x1, y2 - y1);
2118         set_color(color);
2119         draw_box(x1, y1, x2 - x1, y2 - y1);
2121 // In handle
2122         in_x1 = in_x - HANDLE_W / 2;
2123         in_x2 = in_x + HANDLE_W / 2;
2124         in_y1 = center_pixel + in_y - HANDLE_W / 2;
2125         in_y2 = center_pixel + in_y + HANDLE_W / 2;
2127         CLAMP(in_y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
2128         CLAMP(in_y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
2129         CLAMP(in_y, -zoom_track / 2, zoom_track / 2);
2131         set_color(BLACK);
2132         draw_line(x + 1, center_pixel + y + 1, in_x + 1, center_pixel + in_y + 1);
2133         draw_box(in_x1 + 1, in_y1 + 1, in_x2 - in_x1, in_y2 - in_y1);
2134         set_color(color);
2135         draw_line(x, center_pixel + y, in_x, center_pixel + in_y);
2136         draw_box(in_x1, in_y1, in_x2 - in_x1, in_y2 - in_y1);
2140 // Out handle
2141         out_x1 = out_x - HANDLE_W / 2;
2142         out_x2 = out_x + HANDLE_W / 2;
2143         out_y1 = center_pixel + out_y - HANDLE_W / 2;
2144         out_y2 = center_pixel + out_y + HANDLE_W / 2;
2146         CLAMP(out_y1, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
2147         CLAMP(out_y2, center_pixel + -zoom_track / 2, center_pixel + zoom_track / 2);
2148         CLAMP(out_y, -zoom_track / 2, zoom_track / 2);
2151         set_color(BLACK);
2152         draw_line(x + 1, center_pixel + y + 1, out_x + 1, center_pixel + out_y + 1);
2153         draw_box(out_x1 + 1, out_y1 + 1, out_x2 - out_x1, out_y2 - out_y1);
2154         set_color(color);
2155         draw_line(x, center_pixel + y, out_x, center_pixel + out_y);
2156         draw_box(out_x1, out_y1, out_x2 - out_x1, out_y2 - out_y1);
2160 int TrackCanvas::test_auto(Auto *current, 
2161         int x, 
2162         int y, 
2163         int center_pixel, 
2164         int zoom_track, 
2165         int cursor_x, 
2166         int cursor_y, 
2167         int buttonpress)
2169         int x1, y1, x2, y2;
2170         char string[BCTEXTLEN];
2171         int result = 0;
2173         x1 = x - HANDLE_W / 2;
2174         x2 = x + HANDLE_W / 2;
2175         y1 = center_pixel + y - HANDLE_W / 2;
2176         y2 = center_pixel + y + HANDLE_W / 2;
2178         if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2179         if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2180 //printf("test_auto 1 %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2182         if(cursor_x >= x1 && cursor_x < x2 && cursor_y >= y1 && cursor_y < y2)
2183         {
2184 //printf("test_auto 2 %d\n", buttonpress);
2185                 if(buttonpress && buttonpress != 3)
2186                 {
2187 //printf("test_auto 3\n");
2188                         mwindow->session->drag_auto = current;
2189                         mwindow->session->drag_start_percentage = current->value_to_percentage();
2190                         mwindow->session->drag_start_position = current->position;
2191                         mwindow->session->drag_origin_x = cursor_x;
2192                         mwindow->session->drag_origin_y = cursor_y;
2193                 }
2194                 result = 1;
2195         }
2197         return result;
2200 int TrackCanvas::test_floatauto(Auto *current, 
2201         int x, 
2202         int y, 
2203         int in_x,
2204         int in_y,
2205         int out_x,
2206         int out_y,
2207         int center_pixel, 
2208         int zoom_track, 
2209         int cursor_x, 
2210         int cursor_y, 
2211         int buttonpress)
2213         int x1, y1, x2, y2;
2214         int in_x1, in_y1, in_x2, in_y2;
2215         int out_x1, out_y1, out_x2, out_y2;
2216         char string[BCTEXTLEN];
2217         int result = 0;
2219         x1 = x - HANDLE_W / 2;
2220         x2 = x + HANDLE_W / 2;
2221         y1 = center_pixel + y - HANDLE_W / 2;
2222         y2 = center_pixel + y + HANDLE_W / 2;
2224         if(y1 < center_pixel + -zoom_track / 2) y1 = center_pixel + -zoom_track / 2;
2225         if(y2 > center_pixel + zoom_track / 2) y2 = center_pixel + zoom_track / 2;
2227         in_x1 = in_x - HANDLE_W / 2;
2228         in_x2 = in_x + HANDLE_W / 2;
2229         in_y1 = center_pixel + in_y - HANDLE_W / 2;
2230         in_y2 = center_pixel + in_y + HANDLE_W / 2;
2232         if(in_y1 < center_pixel + -zoom_track / 2) in_y1 = center_pixel + -zoom_track / 2;
2233         if(in_y2 > center_pixel + zoom_track / 2) in_y2 = center_pixel + zoom_track / 2;
2235         out_x1 = out_x - HANDLE_W / 2;
2236         out_x2 = out_x + HANDLE_W / 2;
2237         out_y1 = center_pixel + out_y - HANDLE_W / 2;
2238         out_y2 = center_pixel + out_y + HANDLE_W / 2;
2240         if(out_y1 < center_pixel + -zoom_track / 2) out_y1 = center_pixel + -zoom_track / 2;
2241         if(out_y2 > center_pixel + zoom_track / 2) out_y2 = center_pixel + zoom_track / 2;
2245 //printf("TrackCanvas::test_floatauto %d %d %d %d %d %d\n", cursor_x, cursor_y, x1, x2, y1, y2);
2246 // Test value
2247         if(!ctrl_down() &&
2248                 cursor_x >= x1 && 
2249                 cursor_x < x2 && 
2250                 cursor_y >= y1 && 
2251                 cursor_y < y2)
2252         {
2253                 if(buttonpress && (buttonpress != 3))
2254                 {
2255                         mwindow->session->drag_auto = current;
2256                         mwindow->session->drag_start_percentage = current->value_to_percentage();
2257                         mwindow->session->drag_start_position = current->position;
2258                         mwindow->session->drag_origin_x = cursor_x;
2259                         mwindow->session->drag_origin_y = cursor_y;
2260                         mwindow->session->drag_handle = 0;
2261                 }
2262                 result = 1;
2263         }
2264         else
2265 // Test in control
2266         if(ctrl_down() &&
2267                 cursor_x >= in_x1 && 
2268                 cursor_x < in_x2 && 
2269                 cursor_y >= in_y1 && 
2270                 cursor_y < in_y2 &&
2271                 current->position > 0)
2272         {
2273                 if(buttonpress && (buttonpress != 3))
2274                 {
2275                         mwindow->session->drag_auto = current;
2276                         mwindow->session->drag_start_percentage = 
2277                                 current->invalue_to_percentage();
2278                         mwindow->session->drag_start_position = 
2279                                 ((FloatAuto*)current)->control_in_position;
2280                         mwindow->session->drag_origin_x = cursor_x;
2281                         mwindow->session->drag_origin_y = cursor_y;
2282                         mwindow->session->drag_handle = 1;
2283                 }
2284                 result = 1;
2285         }
2286         else
2287 // Test out control
2288         if(ctrl_down() &&
2289                 cursor_x >= out_x1 && 
2290                 cursor_x < out_x2 && 
2291                 cursor_y >= out_y1 && 
2292                 cursor_y < out_y2)
2293         {
2294                 if(buttonpress && (buttonpress != 3))
2295                 {
2296                         mwindow->session->drag_auto = current;
2297                         mwindow->session->drag_start_percentage = 
2298                                 current->outvalue_to_percentage();
2299                         mwindow->session->drag_start_position = 
2300                                 ((FloatAuto*)current)->control_out_position;
2301                         mwindow->session->drag_origin_x = cursor_x;
2302                         mwindow->session->drag_origin_y = cursor_y;
2303                         mwindow->session->drag_handle = 2;
2304                 }
2305                 result = 1;
2306         }
2308 // if(buttonpress) 
2309 // 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", 
2310 // mwindow->session->drag_handle,
2311 // ctrl_down(),
2312 // cursor_x,
2313 // cursor_y,
2314 // x1, x2, y1, y2);
2316         return result;
2319 void TrackCanvas::draw_floatline(int center_pixel, 
2320         FloatAuto *previous,
2321         FloatAuto *next,
2322         FloatAutos *autos,
2323         double unit_start,
2324         double zoom_units,
2325         double yscale,
2326         int x1,
2327         int y1,
2328         int x2,
2329         int y2,
2330         int color)
2332 // Solve bezier equation for either every pixel or a certain large number of
2333 // points.
2337 // Not using slope intercept
2338         x1 = MAX(0, x1);
2343         int prev_y;
2344 // Call by reference fails for some reason here
2345         FloatAuto *previous1 = previous, *next1 = next;
2346         for(int x = x1; x < x2; x++)
2347         {
2348                 int64_t position = (int64_t)(unit_start + x * zoom_units);
2349                 float value = autos->get_value(position, PLAY_FORWARD, previous1, next1);
2351                 int y = (int)(center_pixel + 
2352                         (autos->value_to_percentage(value) - 0.5) * -yscale);
2354                 if(x > x1)
2355                 {
2356                         set_color(BLACK);
2357                         draw_line(x - 1, prev_y + 1, x, y + 1);
2358                         set_color(color);
2359                         draw_line(x - 1, prev_y, x, y);
2360                 }
2361                 prev_y = y;
2362         }
2366 //      set_color(BLACK);
2367 //      draw_line(x1, center_pixel + y1 + 1, x2, center_pixel + y2 + 1);
2368 //      set_color(WHITE);
2369 //      draw_line(x1, center_pixel + y1, x2, center_pixel + y2);
2377 void TrackCanvas::synchronize_autos(float change, Track *skip, FloatAuto *fauto, int fill_gangs)
2379         if (fill_gangs == 1 && skip->gang) // fill mwindow->session->drag_auto_gang
2380         {
2381                 for(Track *current = mwindow->edl->tracks->first;
2382                         current;
2383                         current = NEXT)
2384                 {
2385                         if(current->data_type == skip->data_type &&
2386                                 current->gang && 
2387                                 current->record && 
2388                                 current != skip)
2389                         {
2390                                 FloatAutos *fade_autos = current->automation->fade_autos;
2391                                 double position = skip->from_units(fauto->position);
2392                                 FloatAuto *previous = 0, *next = 0;
2394                                 float init_value = fade_autos->get_value(fauto->position, PLAY_FORWARD, previous, next);
2395                                 FloatAuto *keyframe;
2396                                 keyframe = (FloatAuto*)fade_autos->get_auto_at_position(position);
2397                                 
2398                                 if (!keyframe)
2399                                 {
2400 // create keyframe at exactly this point in time
2401                                         keyframe = (FloatAuto*)fade_autos->insert_auto(fauto->position);
2402                                         keyframe->value = init_value;
2403                                 } 
2404                                 else
2405                                 { 
2406 // keyframe exists, just change it
2407                                         keyframe->value += change;              
2408                                 } 
2409                                 
2410                                 keyframe->position = fauto->position;
2411                                 keyframe->control_out_position = fauto->control_out_position;
2412                                 keyframe->control_in_position = fauto->control_in_position;
2413                                 keyframe->control_out_value = fauto->control_out_value;
2414                                 keyframe->control_in_value = fauto->control_in_value;
2416                                 mwindow->session->drag_auto_gang->append((Auto *)keyframe);
2417                         }
2418                 }
2419         } else 
2420         if (fill_gangs == 0)      // move the gangs
2421         {
2423                 // Move the gang!
2424                 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++)
2425                 {
2426                         FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2427                         
2428                         keyframe->value += change;
2429                         keyframe->position = fauto->position;
2430                         if(skip->data_type == TRACK_AUDIO)
2431                                 CLAMP(keyframe->value, INFINITYGAIN, MAX_AUDIO_FADE);
2432                         else
2433                                 CLAMP(keyframe->value, 0, MAX_VIDEO_FADE);
2434                         keyframe->control_out_position = fauto->control_out_position;
2435                         keyframe->control_in_position = fauto->control_in_position;
2436                         keyframe->control_out_value = fauto->control_out_value;
2437                         keyframe->control_in_value = fauto->control_in_value;
2438                 } 
2440         } else
2441         if (fill_gangs == -1)      // remove the gangs
2442         {
2443                 for (int i = 0; i < mwindow->session->drag_auto_gang->total; i++)
2444                 {
2445                         FloatAuto *keyframe = (FloatAuto *)mwindow->session->drag_auto_gang->values[i];
2446                         keyframe->autos->remove_nonsequential(
2447                                         keyframe);
2448                 } 
2449                 mwindow->session->drag_auto_gang->remove_all();
2450         }
2454 int TrackCanvas::test_floatline(int center_pixel, 
2455                 FloatAutos *autos,
2456                 double unit_start,
2457                 double zoom_units,
2458                 double yscale,
2459                 int x1,
2460                 int x2,
2461                 int cursor_x, 
2462                 int cursor_y, 
2463                 int buttonpress)
2465         int result = 0;
2468         int64_t position = (int64_t)(unit_start + cursor_x * zoom_units);
2469 // Call by reference fails for some reason here
2470         FloatAuto *previous = 0, *next = 0;
2471         float value = autos->get_value(position, PLAY_FORWARD, previous, next);
2472         int y = (int)(center_pixel + 
2473                 (autos->value_to_percentage(value) - 0.5) * -yscale);
2475         if(cursor_x >= x1 && 
2476                 cursor_x < x2 &&
2477                 cursor_y >= y - HANDLE_W / 2 && 
2478                 cursor_y < y + HANDLE_W / 2 &&
2479                 !ctrl_down())
2480         {
2481                 result = 1;
2484                 if(buttonpress)
2485                 {
2486                         mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
2489                         Auto *current;
2490                         current = mwindow->session->drag_auto = autos->insert_auto(position);
2491                         ((FloatAuto*)current)->value = value;
2492                         mwindow->session->drag_start_percentage = current->value_to_percentage();
2493                         mwindow->session->drag_start_position = current->position;
2494                         mwindow->session->drag_origin_x = cursor_x;
2495                         mwindow->session->drag_origin_y = cursor_y;
2496                         mwindow->session->drag_handle = 0;
2498                 }
2499         }
2502         return result;
2505 void TrackCanvas::draw_toggleline(int center_pixel, 
2506         int x1,
2507         int y1,
2508         int x2,
2509         int y2,
2510         int color)
2512         set_color(BLACK);
2513         draw_line(x1, center_pixel + y1 + 1, x2, center_pixel + y1 + 1);
2514         set_color(color);
2515         draw_line(x1, center_pixel + y1, x2, center_pixel + y1);
2517         if(y2 != y1)
2518         {
2519                 set_color(BLACK);
2520                 draw_line(x2 + 1, center_pixel + y1, x2 + 1, center_pixel + y2);
2521                 set_color(color);
2522                 draw_line(x2, center_pixel + y1, x2, center_pixel + y2);
2523         }
2526 int TrackCanvas::test_toggleline(Autos *autos,
2527         int center_pixel, 
2528         int x1,
2529         int y1,
2530         int x2,
2531         int y2, 
2532         int cursor_x, 
2533         int cursor_y, 
2534         int buttonpress)
2536         int result = 0;
2537         if(cursor_x >= x1 && cursor_x < x2)
2538         {
2539                 int miny = center_pixel + y1 - HANDLE_W / 2;
2540                 int maxy = center_pixel + y1 + HANDLE_W / 2;
2541                 if(cursor_y >= miny && cursor_y < maxy) 
2542                 {
2543                         result = 1;
2545                         if(buttonpress)
2546                         {
2547                                 mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
2550                                 Auto *current;
2551                                 double position = (double)(cursor_x +
2552                                                 mwindow->edl->local_session->view_start) * 
2553                                         mwindow->edl->local_session->zoom_sample / 
2554                                         mwindow->edl->session->sample_rate;
2555                                 int64_t unit_position = autos->track->to_units(position, 0);
2556                                 int new_value = (int)((IntAutos*)autos)->get_automation_constant(unit_position, unit_position);
2558                                 current = mwindow->session->drag_auto = autos->insert_auto(unit_position);
2559                                 ((IntAuto*)current)->value = new_value;
2560                                 mwindow->session->drag_start_percentage = current->value_to_percentage();
2561                                 mwindow->session->drag_start_position = current->position;
2562                                 mwindow->session->drag_origin_x = cursor_x;
2563                                 mwindow->session->drag_origin_y = cursor_y;
2565                         }
2566                 }
2567         };
2568         return result;
2571 void TrackCanvas::calculate_viewport(Track *track, 
2572         double &view_start,   // Seconds
2573         double &unit_start,
2574         double &view_end,     // Seconds
2575         double &unit_end,
2576         double &yscale,
2577         int &center_pixel,
2578         double &zoom_sample,
2579         double &zoom_units)
2581         view_start = (double)mwindow->edl->local_session->view_start * 
2582                 mwindow->edl->local_session->zoom_sample /
2583                 mwindow->edl->session->sample_rate;
2584         unit_start = track->to_doubleunits(view_start);
2585         view_end = (double)(mwindow->edl->local_session->view_start + 
2586                 get_w()) * 
2587                 mwindow->edl->local_session->zoom_sample / 
2588                 mwindow->edl->session->sample_rate;
2589         unit_end = track->to_doubleunits(view_end);
2590         yscale = mwindow->edl->local_session->zoom_track;
2591         center_pixel = (int)(track->y_pixel + yscale / 2) + 
2592                 (mwindow->edl->session->show_titles ? 
2593                         mwindow->theme->title_bg_data->get_h() : 
2594                         0);
2595         zoom_sample = mwindow->edl->local_session->zoom_sample;
2597         zoom_units = track->to_doubleunits(zoom_sample / mwindow->edl->session->sample_rate);
2600 int TrackCanvas::do_float_autos(Track *track, 
2601                 Autos *autos, 
2602                 int cursor_x, 
2603                 int cursor_y, 
2604                 int draw, 
2605                 int buttonpress,
2606                 int color,
2607                 Auto * &auto_instance)
2609         int result = 0;
2611         double view_start;
2612         double unit_start;
2613         double view_end;
2614         double unit_end;
2615         double yscale;
2616         int center_pixel;
2617         double zoom_sample;
2618         double zoom_units;
2619         double ax, ay, ax2, ay2;
2620         double in_x2, in_y2, out_x2, out_y2;
2621         int draw_auto;
2622         double slope;
2623         int skip = 0;
2624         
2625         auto_instance = 0;
2627         calculate_viewport(track, 
2628                 view_start,
2629                 unit_start,
2630                 view_end,
2631                 unit_end,
2632                 yscale,
2633                 center_pixel,
2634                 zoom_sample,
2635                 zoom_units);
2639 // Get first auto before start
2640         Auto *current = 0;
2641         Auto *previous = 0;
2642         for(current = autos->last; 
2643                 current && current->position >= unit_start; 
2644                 current = PREVIOUS)
2645                 ;
2647         if(current)
2648         {
2649                 ax = (double)(current->position - unit_start) / zoom_units;
2650                 ay = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2651                 current = NEXT;
2652         }
2653         else
2654         {
2655                 current = autos->first ? autos->first : autos->default_auto;
2656                 if(current)
2657                 {               
2658                         ax = 0;
2659                         ay = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2660                 }
2661                 else
2662                 {
2663                         ax = 0;
2664                         ay = 0;
2665                 }
2666         }
2669 //printf("TrackCanvas::do_float_autos 1\n");
2673         do
2674         {
2675                 skip = 0;
2676                 draw_auto = 1;
2678                 if(current)
2679                 {
2680                         ax2 = (double)(current->position - unit_start) / zoom_units;
2681                         ay2 = (((FloatAuto*)current)->value_to_percentage() - 0.5) * -yscale;
2682                         in_x2 = (double)(current->position + 
2683                                 ((FloatAuto*)current)->control_in_position - 
2684                                 unit_start) / 
2685                                 zoom_units;
2686                         in_y2 = (((FloatAuto*)current)->invalue_to_percentage() - 0.5) * -yscale;
2687                         out_x2 = (double)(current->position + 
2688                                 ((FloatAuto*)current)->control_out_position - 
2689                                 unit_start) / 
2690                                 zoom_units;
2691                         out_y2 = (((FloatAuto*)current)->outvalue_to_percentage() - 0.5) * -yscale;
2692                 }
2693                 else
2694                 {
2695                         ax2 = get_w();
2696                         ay2 = ay;
2697                         skip = 1;
2698                 }
2700                 slope = (ay2 - ay) / (ax2 - ax);
2702                 if(ax2 > get_w())
2703                 {
2704                         draw_auto = 0;
2705                         ax2 = get_w();
2706                         ay2 = ay + slope * (get_w() - ax);
2707                 }
2708                 
2709                 if(ax < 0)
2710                 {
2711                         ay = ay + slope * (0 - ax);
2712                         ax = 0;
2713                 }
2728 // Draw handle
2729                 if(current && !result)
2730                 {
2731                         if(current != autos->default_auto)
2732                         {
2733                                 if(!draw)
2734                                 {
2735                                         if(track->record)
2736                                                 result = test_floatauto(current, 
2737                                                         (int)ax2, 
2738                                                         (int)ay2, 
2739                                                         (int)in_x2,
2740                                                         (int)in_y2,
2741                                                         (int)out_x2,
2742                                                         (int)out_y2,
2743                                                         (int)center_pixel, 
2744                                                         (int)yscale, 
2745                                                         cursor_x, 
2746                                                         cursor_y, 
2747                                                         buttonpress);
2748                                         if (result) 
2749                                                 auto_instance = current;
2750                                 }
2751                                 else
2752                                 if(draw_auto)
2753                                         draw_floatauto(current, 
2754                                                 (int)ax2, 
2755                                                 (int)ay2, 
2756                                                 (int)in_x2,
2757                                                 (int)in_y2,
2758                                                 (int)out_x2,
2759                                                 (int)out_y2,
2760                                                 (int)center_pixel, 
2761                                                 (int)yscale,
2762                                                 color);
2763                         }
2764                 }
2770 // Draw joining line
2771                 if(!draw)
2772                 {
2773                         if(!result)
2774                         {
2775                                 if(track->record && buttonpress != 3)
2776                                 {
2777                                         result = test_floatline(center_pixel, 
2778                                                 (FloatAutos*)autos,
2779                                                 unit_start,
2780                                                 zoom_units,
2781                                                 yscale,
2782                                                 (int)ax,
2783 // Exclude auto coverage from the end of the line.  The auto overlaps
2784                                                 (int)ax2 - HANDLE_W / 2,
2785                                                 cursor_x, 
2786                                                 cursor_y, 
2787                                                 buttonpress);
2788                                 }
2789                         }
2790                 }
2791                 else
2792                         draw_floatline(center_pixel,
2793                                 (FloatAuto*)previous,
2794                                 (FloatAuto*)current,
2795                                 (FloatAutos*)autos,
2796                                 unit_start,
2797                                 zoom_units,
2798                                 yscale,
2799                                 (int)ax, 
2800                                 (int)ay, 
2801                                 (int)ax2, 
2802                                 (int)ay2,
2803                                 color);
2811                 if(current)
2812                 {
2813                         previous = current;
2814                         current = NEXT;
2815                 }
2819                 ax = ax2;
2820                 ay = ay2;
2821         }while(current && 
2822                 current->position <= unit_end && 
2823                 !result);
2825 //printf("TrackCanvas::do_float_autos 100\n");
2834         if(ax < get_w() && !result)
2835         {
2836                 ax2 = get_w();
2837                 ay2 = ay;
2838                 if(!draw)
2839                 {
2840                         if(track->record && buttonpress != 3)
2841                         {
2842                                 result = test_floatline(center_pixel, 
2843                                         (FloatAutos*)autos,
2844                                         unit_start,
2845                                         zoom_units,
2846                                         yscale,
2847                                         (int)ax,
2848                                         (int)ax2,
2849                                         cursor_x, 
2850                                         cursor_y, 
2851                                         buttonpress);
2852                         }
2853                 }
2854                 else
2855                         draw_floatline(center_pixel, 
2856                                 (FloatAuto*)previous,
2857                                 (FloatAuto*)current,
2858                                 (FloatAutos*)autos,
2859                                 unit_start,
2860                                 zoom_units,
2861                                 yscale,
2862                                 (int)ax, 
2863                                 (int)ay, 
2864                                 (int)ax2, 
2865                                 (int)ay2,
2866                                 color);
2867         }
2876         return result;
2880 int TrackCanvas::do_toggle_autos(Track *track, 
2881                 Autos *autos, 
2882                 int cursor_x, 
2883                 int cursor_y, 
2884                 int draw, 
2885                 int buttonpress,
2886                 int color,
2887                 Auto * &auto_instance)
2889         int result = 0;
2890         double view_start;
2891         double unit_start;
2892         double view_end;
2893         double unit_end;
2894         double yscale;
2895         int center_pixel;
2896         double zoom_sample;
2897         double zoom_units;
2898         double ax, ay, ax2, ay2;
2899         
2900         auto_instance = 0;
2902         calculate_viewport(track, 
2903                 view_start,
2904                 unit_start,
2905                 view_end,
2906                 unit_end,
2907                 yscale,
2908                 center_pixel,
2909                 zoom_sample,
2910                 zoom_units);
2913         double high = -yscale * 0.8 / 2;
2914         double low = yscale * 0.8 / 2;
2916 // Get first auto before start
2917         Auto *current;
2918         for(current = autos->last; current && current->position >= unit_start; current = PREVIOUS)
2919                 ;
2921         if(current)
2922         {
2923                 ax = 0;
2924                 ay = ((IntAuto*)current)->value > 0 ? high : low;
2925                 current = NEXT;
2926         }
2927         else
2928         {
2929                 current = autos->first ? autos->first : autos->default_auto;
2930                 if(current)
2931                 {
2932                         ax = 0;
2933                         ay = ((IntAuto*)current)->value > 0 ? high : low;
2934                 }
2935                 else
2936                 {
2937                         ax = 0;
2938                         ay = yscale;
2939                 }
2940         }
2942         do
2943         {
2944                 if(current)
2945                 {
2946                         ax2 = (double)(current->position - unit_start) / zoom_units;
2947                         ay2 = ((IntAuto*)current)->value > 0 ? high : low;
2948                 }
2949                 else
2950                 {
2951                         ax2 = get_w();
2952                         ay2 = ay;
2953                 }
2955                 if(ax2 > get_w()) ax2 = get_w();
2957             if(current && !result) 
2958                 {
2959                         if(current != autos->default_auto)
2960                         {
2961                                 if(!draw)
2962                                 {
2963                                         if(track->record)
2964                                         {
2965                                                 result = test_auto(current, 
2966                                                         (int)ax2, 
2967                                                         (int)ay2, 
2968                                                         (int)center_pixel, 
2969                                                         (int)yscale, 
2970                                                         cursor_x, 
2971                                                         cursor_y, 
2972                                                         buttonpress);
2973                                                 if (result)
2974                                                         auto_instance = current;
2975                                         }
2976                                 }
2977                                 else
2978                                         draw_auto(current, 
2979                                                 (int)ax2, 
2980                                                 (int)ay2, 
2981                                                 (int)center_pixel, 
2982                                                 (int)yscale,
2983                                                 color);
2984                         }
2986                         current = NEXT;
2987                 }
2989                 if(!draw)
2990                 {
2991                         if(!result)
2992                         {
2993                                 if(track->record && buttonpress != 3)
2994                                 {
2995                                         result = test_toggleline(autos, 
2996                                                 center_pixel, 
2997                                                 (int)ax, 
2998                                                 (int)ay, 
2999                                                 (int)ax2, 
3000                                                 (int)ay2,
3001                                                 cursor_x, 
3002                                                 cursor_y, 
3003                                                 buttonpress);
3004                                 }
3005                         }
3006                 }
3007                 else
3008                         draw_toggleline(center_pixel, 
3009                                 (int)ax, 
3010                                 (int)ay, 
3011                                 (int)ax2, 
3012                                 (int)ay2,
3013                                 color);
3015                 ax = ax2;
3016                 ay = ay2;
3017         }while(current && current->position <= unit_end && !result);
3019         if(ax < get_w() && !result)
3020         {
3021                 ax2 = get_w();
3022                 ay2 = ay;
3023                 if(!draw)
3024                 {
3025                         if(track->record && buttonpress != 3)
3026                         {
3027                                 result = test_toggleline(autos,
3028                                         center_pixel, 
3029                                         (int)ax, 
3030                                         (int)ay, 
3031                                         (int)ax2, 
3032                                         (int)ay2,
3033                                         cursor_x, 
3034                                         cursor_y, 
3035                                         buttonpress);
3036                         }
3037                 }
3038                 else
3039                         draw_toggleline(center_pixel, 
3040                                 (int)ax, 
3041                                 (int)ay, 
3042                                 (int)ax2, 
3043                                 (int)ay2,
3044                                 color);
3045         }
3046         return result;
3049 int TrackCanvas::do_autos(Track *track, 
3050                 Autos *autos, 
3051                 int cursor_x, 
3052                 int cursor_y, 
3053                 int draw, 
3054                 int buttonpress,
3055                 BC_Pixmap *pixmap,
3056                 Auto * &auto_instance)
3058         int result = 0;
3060         double view_start;
3061         double unit_start;
3062         double view_end;
3063         double unit_end;
3064         double yscale;
3065         int center_pixel;
3066         double zoom_sample;
3067         double zoom_units;
3069         calculate_viewport(track, 
3070                 view_start,
3071                 unit_start,
3072                 view_end,
3073                 unit_end,
3074                 yscale,
3075                 center_pixel,
3076                 zoom_sample,
3077                 zoom_units);
3079         Auto *current;
3080         auto_instance = 0;
3082         for(current = autos->first; current && !result; current = NEXT)
3083         {
3084                 if(current->position >= unit_start && current->position < unit_end)
3085                 {
3086                         int64_t x, y;
3087                         x = (int64_t)((double)(current->position - unit_start) / 
3088                                 zoom_units - (pixmap->get_w() / 2 + 0.5));
3089                         y = center_pixel - pixmap->get_h() / 2;
3091                         if(!draw)
3092                         {
3093                                 if(cursor_x >= x && cursor_y >= y &&
3094                                         cursor_x < x + pixmap->get_w() &&
3095                                         cursor_y < y + pixmap->get_h())
3096                                 {
3097                                         result = 1;
3098                                         auto_instance = current;
3100                                         if(buttonpress && (buttonpress != 3))
3101                                         {
3102                                                 mwindow->session->drag_auto = current;
3103                                                 mwindow->session->drag_start_position = current->position;
3104                                                 mwindow->session->drag_origin_x = cursor_x;
3105                                                 mwindow->session->drag_origin_y = cursor_y;
3107                                                 double position = autos->track->from_units(current->position);
3108                                                 double center = (mwindow->edl->local_session->selectionstart +
3109                                                         mwindow->edl->local_session->selectionend) / 
3110                                                         2;
3112                                                 if(!shift_down())
3113                                                 {
3114                                                         mwindow->edl->local_session->selectionstart = position;
3115                                                         mwindow->edl->local_session->selectionend = position;
3116                                                 }
3117                                                 else
3118                                                 if(position < center)
3119                                                 {
3120                                                         mwindow->edl->local_session->selectionstart = position;
3121                                                 }
3122                                                 else
3123                                                         mwindow->edl->local_session->selectionend = position;
3124                                         }
3125                                 }
3126                         }
3127                         else
3128                                 draw_pixmap(pixmap, x, y);
3129                 }
3130         }
3131         return result;
3134 // so this means it is always >0 when keyframe is found 
3135 int TrackCanvas::do_plugin_autos(Track *track, 
3136                 int cursor_x, 
3137                 int cursor_y, 
3138                 int draw, 
3139                 int buttonpress,
3140                 Plugin* &keyframe_plugin,
3141                 KeyFrame* &keyframe_instance)
3143         int result = 0;
3145         double view_start;
3146         double unit_start;
3147         double view_end;
3148         double unit_end;
3149         double yscale;
3150         int center_pixel;
3151         double zoom_sample;
3152         double zoom_units;
3154         if(!track->expand_view) return 0;
3156         calculate_viewport(track, 
3157                 view_start,
3158                 unit_start,
3159                 view_end,
3160                 unit_end,
3161                 yscale,
3162                 center_pixel,
3163                 zoom_sample,
3164                 zoom_units);
3168         for(int i = 0; i < track->plugin_set.total && !result; i++)
3169         {
3170                 PluginSet *plugin_set = track->plugin_set.values[i];
3171                 int center_pixel = (int)(track->y_pixel + 
3172                         mwindow->edl->local_session->zoom_track +
3173                         (i + 0.5) * mwindow->theme->plugin_bg_data->get_h() + 
3174                         (mwindow->edl->session->show_titles ? mwindow->theme->title_bg_data->get_h() : 0));
3176                 for(Plugin *plugin = (Plugin*)plugin_set->first; 
3177                         plugin && !result; 
3178                         plugin = (Plugin*)plugin->next)
3179                 {
3180                         for(KeyFrame *keyframe = (KeyFrame*)plugin->keyframes->first; 
3181                                 keyframe && !result; 
3182                                 keyframe = (KeyFrame*)keyframe->next)
3183                         {
3184 //printf("TrackCanvas::draw_plugin_autos 3 %d\n", keyframe->position);
3185                                 if(keyframe->position >= unit_start && keyframe->position < unit_end)
3186                                 {
3187                                         int64_t x = (int64_t)((keyframe->position - unit_start) / zoom_units);
3188                                         int y = center_pixel - keyframe_pixmap->get_h() / 2;
3190 //printf("TrackCanvas::draw_plugin_autos 4 %d %d\n", x, center_pixel);
3191                                         if(!draw)
3192                                         {
3193                                                 if(cursor_x >= x && cursor_y >= y &&
3194                                                         cursor_x < x + keyframe_pixmap->get_w() &&
3195                                                         cursor_y < y + keyframe_pixmap->get_h())
3196                                                 {
3197                                                         result = 1;
3198                                                         keyframe_plugin = plugin;
3199                                                         keyframe_instance = keyframe;
3201                                                         if(buttonpress)
3202                                                         {
3203                                                                 mwindow->session->drag_auto = keyframe;
3204                                                                 mwindow->session->drag_start_position = keyframe->position;
3205                                                                 mwindow->session->drag_origin_x = cursor_x;
3206                                                                 mwindow->session->drag_origin_y = cursor_y;
3208                                                                 double position = track->from_units(keyframe->position);
3209                                                                 double center = (mwindow->edl->local_session->selectionstart +
3210                                                                         mwindow->edl->local_session->selectionend) / 
3211                                                                         2;
3213                                                                 if(!shift_down())
3214                                                                 {
3215                                                                         mwindow->edl->local_session->selectionstart = position;
3216                                                                         mwindow->edl->local_session->selectionend = position;
3217                                                                 }
3218                                                                 else
3219                                                                 if(position < center)
3220                                                                 {
3221                                                                         mwindow->edl->local_session->selectionstart = position;
3222                                                                 }
3223                                                                 else
3224                                                                         mwindow->edl->local_session->selectionend = position;
3225                                                         }
3226                                                 }
3227                                         }
3228                                         else
3229                                                 draw_pixmap(keyframe_pixmap, 
3230                                                         x, 
3231                                                         y);
3232                                 }
3233                         }
3234                 }
3235         }
3236 //printf("TrackCanvas::draw_plugin_autos 5\n");
3237         return result;
3240 void TrackCanvas::draw_overlays()
3242         int new_cursor, update_cursor, rerender;
3243 //TRACE("TrackCanvas::draw_overlays 1")
3245 // Move background pixmap to foreground pixmap
3246         draw_pixmap(background_pixmap, 
3247                 0, 
3248                 0,
3249                 get_w(),
3250                 get_h(),
3251                 0,
3252                 0);
3253 //TRACE("TrackCanvas::draw_overlays 10")
3255 // In/Out points
3256         draw_inout_points();
3258 //TRACE("TrackCanvas::draw_overlays 11");
3259 // Transitions
3260         if(mwindow->edl->session->auto_conf->transitions) draw_transitions();
3262 //TRACE("TrackCanvas::draw_overlays 12");
3263 // Plugins
3264         draw_plugins();
3266 //TRACE("TrackCanvas::draw_overlays 13");
3267 // Loop points
3268         draw_loop_points();
3269         draw_brender_start();
3271 //TRACE("TrackCanvas::draw_overlays 14");
3272 // Highlighted areas
3273         draw_highlighting();
3275 //TRACE("TrackCanvas::draw_overlays 15");
3276 // Automation
3277         do_keyframes(0, 
3278                 0, 
3279                 1, 
3280                 0, 
3281                 new_cursor, 
3282                 update_cursor,
3283                 rerender);
3285 //TRACE("TrackCanvas::draw_overlays 16\n");
3286 // Selection cursor
3287         if(gui->cursor) gui->cursor->restore();
3289 //TRACE("TrackCanvas::draw_overlays 17\n");
3290 // Handle dragging
3291         draw_drag_handle();
3293 //TRACE("TrackCanvas::draw_overlays 20");
3294 // Playback cursor
3295         draw_playback_cursor();
3299 int TrackCanvas::activate()
3301         if(!active)
3302         {
3303                 get_top_level()->deactivate();
3304                 active = 1;
3305                 set_active_subwindow(this);
3306                 gui->cursor->activate();
3307         }
3308         return 0;
3311 int TrackCanvas::deactivate()
3313         if(active)
3314         {
3315                 active = 0;
3316                 gui->cursor->deactivate();
3317         }
3318         return 0;
3322 void TrackCanvas::update_drag_handle()
3324         double new_position;
3326         new_position = 
3327                 (double)(get_cursor_x() + mwindow->edl->local_session->view_start) *
3328                 mwindow->edl->local_session->zoom_sample /
3329                 mwindow->edl->session->sample_rate;
3330         new_position = 
3331                 mwindow->edl->align_to_frame(new_position, 0);
3334         if(new_position != mwindow->session->drag_position)
3335         {
3336                 mwindow->session->drag_position = new_position;
3337                 gui->mainclock->update(new_position);
3338 // Que the CWindow.  Doesn't do anything if selectionstart and selection end 
3339 // aren't changed.
3340 //              mwindow->cwindow->update(1, 0, 0);
3341         }
3344 int TrackCanvas::update_drag_edit()
3346         int result = 0;
3347         
3348         
3349         
3350         return result;
3353 #define UPDATE_DRAG_HEAD(do_clamp) \
3354         int result = 0; \
3355         int x = cursor_x - mwindow->session->drag_origin_x; \
3356         int y = cursor_y - mwindow->session->drag_origin_y; \
3358         if(!current->autos->track->record) return 0; \
3359         double view_start; \
3360         double unit_start; \
3361         double view_end; \
3362         double unit_end; \
3363         double yscale; \
3364         int center_pixel; \
3365         double zoom_sample; \
3366         double zoom_units; \
3368         mwindow->undo->update_undo_before(_("tweek"), LOAD_AUTOMATION); \
3369         calculate_viewport(current->autos->track,  \
3370                 view_start, \
3371                 unit_start, \
3372                 view_end, \
3373                 unit_end, \
3374                 yscale, \
3375                 center_pixel, \
3376                 zoom_sample, \
3377                 zoom_units); \
3379         float percentage = (float)(mwindow->session->drag_origin_y - cursor_y) / \
3380                 MAX(128, yscale) +  \
3381                 mwindow->session->drag_start_percentage; \
3382         if(do_clamp) CLAMP(percentage, 0, 1); \
3384         int64_t position = Units::to_int64(zoom_units * \
3385                 (cursor_x - mwindow->session->drag_origin_x) + \
3386                 mwindow->session->drag_start_position); \
3388         if((do_clamp) && position < 0) position = 0;
3398 int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
3400         FloatAuto *current = (FloatAuto*)mwindow->session->drag_auto;
3402         UPDATE_DRAG_HEAD(mwindow->session->drag_handle == 0);
3404         float value;
3405         float old_value;
3406 //printf("TrackCanvas::update_drag_floatauto %ld %d\n", 
3407 //position, 
3408 //mwindow->session->drag_handle);
3410         switch(mwindow->session->drag_handle)
3411         {
3412 // Center
3413                 case 0:
3414 // Snap to nearby values
3415                         old_value = current->value;
3416                         if(shift_down())
3417                         {
3418                                 double value1;
3419                                 double distance1;
3420                                 double value2;
3421                                 double distance2;
3422                                 value = ((FloatAuto*)current)->percentage_to_value(percentage);
3424                                 if(current->previous)
3425                                 {
3426                                         value1 = ((FloatAuto*)current->previous)->value;
3427                                         distance1 = fabs(value - value1);
3428                                         current->value = value1;
3429                                 }
3431                                 if(current->next)
3432                                 {
3433                                         value2 = ((FloatAuto*)current->next)->value;
3434                                         distance2 = fabs(value - value2);
3435                                         if(!current->previous || distance2 < distance1)
3436                                         {
3437                                                 current->value = value2;
3438                                         }
3439                                 }
3441                                 if(!current->previous && !current->next)
3442                                 {
3443                                         current->value = ((FloatAutos*)current->autos)->default_;
3444                                 }
3445                                 value = current->value;
3446                         }
3447                         else
3448                                 value = ((FloatAuto*)current)->percentage_to_value(percentage);
3450 //printf("TrackCanvas::update_drag_floatauto 1 %f\n", value);
3451                         if(value != old_value || position != current->position)
3452                         {
3453                                 result = 1;
3454                                 float change = value - old_value;               
3455                                 current->value = value;
3456                                 current->position = position;
3457                                 synchronize_autos(change, current->autos->track, current, 0);
3459                                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3460                                 Units::totext(string2, 
3461                                         current->autos->track->from_units(current->position),
3462                                         mwindow->edl->session->time_format,
3463                                         mwindow->edl->session->sample_rate,
3464                                         mwindow->edl->session->frame_rate,
3465                                         mwindow->edl->session->frames_per_foot);
3466                                 sprintf(string, "%s, %.2f", string2, current->value);
3467                                 gui->show_message(string);
3468                         }
3469                         break;
3471 // In control
3472                 case 1:
3473                         value = ((FloatAuto*)current)->percentage_to_invalue(percentage);
3474                         position = MIN(0, position);
3475                         if(value != current->control_in_value || 
3476                                 position != current->control_in_position)
3477                         {
3478                                 result = 1;
3479                                 current->control_in_value = value;
3480                                 current->control_in_position = position;
3481                                 synchronize_autos(0, current->autos->track, current, 0);
3483                                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3484                                 Units::totext(string2, 
3485                                         current->autos->track->from_units(current->control_in_position),
3486                                         mwindow->edl->session->time_format,
3487                                         mwindow->edl->session->sample_rate,
3488                                         mwindow->edl->session->frame_rate,
3489                                         mwindow->edl->session->frames_per_foot);
3490                                 sprintf(string, "%s, %.2f", string2, current->control_in_value);
3491                                 gui->show_message(string);
3492                         }
3493                         break;
3495 // Out control
3496                 case 2:
3497                         value = ((FloatAuto*)current)->percentage_to_outvalue(percentage);
3498                         position = MAX(0, position);
3499                         if(value != current->control_out_value || 
3500                                 position != current->control_out_position)
3501                         {
3502                                 result = 1;
3503                                 current->control_out_value = value;
3504                                 current->control_out_position = position;
3505                                 synchronize_autos(0, current->autos->track, current, 0);
3507                                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3508                                 Units::totext(string2, 
3509                                         current->autos->track->from_units(
3510                                                 ((FloatAuto*)current)->control_out_position),
3511                                         mwindow->edl->session->time_format,
3512                                         mwindow->edl->session->sample_rate,
3513                                         mwindow->edl->session->frame_rate,
3514                                         mwindow->edl->session->frames_per_foot);
3515                                 sprintf(string, "%s, %.2f", 
3516                                         string2, 
3517                                         ((FloatAuto*)current)->control_out_value);
3518                                 gui->show_message(string);
3519                         }
3520                         break;
3521         }
3523         return result;
3526 int TrackCanvas::update_drag_toggleauto(int cursor_x, int cursor_y)
3528         IntAuto *current = (IntAuto*)mwindow->session->drag_auto;
3530         UPDATE_DRAG_HEAD(1);
3532         int value = ((IntAuto*)current)->percentage_to_value(percentage);
3534         if(value != current->value || position != current->position)
3535         {
3536                 result = 1;
3537                 current->value = value;
3538                 current->position = position;
3540                 char string[BCTEXTLEN], string2[BCTEXTLEN];
3541                 Units::totext(string2, 
3542                         current->autos->track->from_units(current->position),
3543                         mwindow->edl->session->time_format,
3544                         mwindow->edl->session->sample_rate,
3545                         mwindow->edl->session->frame_rate,
3546                         mwindow->edl->session->frames_per_foot);
3547                 sprintf(string, "%s, %d", string2, current->value);
3548                 gui->show_message(string);
3549         }
3551         return result;
3554 // Autos which can't change value through dragging.
3556 int TrackCanvas::update_drag_auto(int cursor_x, int cursor_y)
3558         Auto *current = (Auto*)mwindow->session->drag_auto;
3560         UPDATE_DRAG_HEAD(1)
3561         if(position != current->position)
3562         {
3563                 result = 1;
3564                 current->position = position;
3566                 char string[BCTEXTLEN];
3567                 Units::totext(string, 
3568                         current->autos->track->from_units(current->position),
3569                         mwindow->edl->session->time_format,
3570                         mwindow->edl->session->sample_rate,
3571                         mwindow->edl->session->frame_rate,
3572                         mwindow->edl->session->frames_per_foot);
3573                 gui->show_message(string);
3575                 double position_f = current->autos->track->from_units(current->position);
3576                 double center_f = (mwindow->edl->local_session->selectionstart +
3577                         mwindow->edl->local_session->selectionend) / 
3578                         2;
3579                 if(!shift_down())
3580                 {
3581                         mwindow->edl->local_session->selectionstart = position_f;
3582                         mwindow->edl->local_session->selectionend = position_f;
3583                 }
3584                 else
3585                 if(position_f < center_f)
3586                 {
3587                         mwindow->edl->local_session->selectionstart = position_f;
3588                 }
3589                 else
3590                         mwindow->edl->local_session->selectionend = position_f;
3591         }
3594         return result;
3597 int TrackCanvas::update_drag_pluginauto(int cursor_x, int cursor_y)
3599         KeyFrame *current = (KeyFrame*)mwindow->session->drag_auto;
3601         UPDATE_DRAG_HEAD(1)
3602         if(position != current->position)
3603         {
3604 //      printf("uida: autos: %p, track: %p ta: %p\n", current->autos, current->autos->track, current->autos->track->automation);
3605                 Track *track = current->autos->track;
3606                 PluginAutos *pluginautos = (PluginAutos *)current->autos;
3607                 PluginSet *pluginset;
3608                 Plugin *plugin;
3609                 // figure out the correct pluginset & correct plugin 
3610                 int found = 0;
3611                 for(int i = 0; i < track->plugin_set.total; i++)
3612                 {
3613                         pluginset = track->plugin_set.values[i];
3614                         for(plugin = (Plugin *)pluginset->first; plugin; plugin = (Plugin *)plugin->next)
3615                         {
3616                                 KeyFrames *keyframes = plugin->keyframes;
3617                                 for(KeyFrame *currentkeyframe = (KeyFrame *)keyframes->first; currentkeyframe; currentkeyframe = (KeyFrame *) currentkeyframe->next)
3618                                 {
3619                                         if (currentkeyframe == current) 
3620                                         {
3621                                                 found = 1;
3622                                                 break;
3623                                         }
3625                                 }
3626                                 if (found) break;                       
3627                         }
3628                         if (found) break;                       
3629                 }       
3630         
3631                 mwindow->session->plugin_highlighted = plugin;
3632                 mwindow->session->track_highlighted = track;
3633                 result = 1;
3634                 current->position = position;
3636                 char string[BCTEXTLEN];
3637                 Units::totext(string, 
3638                         current->autos->track->from_units(current->position),
3639                         mwindow->edl->session->time_format,
3640                         mwindow->edl->session->sample_rate,
3641                         mwindow->edl->session->frame_rate,
3642                         mwindow->edl->session->frames_per_foot);
3643                 gui->show_message(string);
3645                 double position_f = current->autos->track->from_units(current->position);
3646                 double center_f = (mwindow->edl->local_session->selectionstart +
3647                         mwindow->edl->local_session->selectionend) / 
3648                         2;
3649                 if(!shift_down())
3650                 {
3651                         mwindow->edl->local_session->selectionstart = position_f;
3652                         mwindow->edl->local_session->selectionend = position_f;
3653                 }
3654                 else
3655                 if(position_f < center_f)
3656                 {
3657                         mwindow->edl->local_session->selectionstart = position_f;
3658                 }
3659                 else
3660                         mwindow->edl->local_session->selectionend = position_f;
3661         }
3664         return result;
3667 void TrackCanvas::update_drag_caption()
3669         switch(mwindow->session->current_operation)
3670         {
3671                 case DRAG_FADE:
3672                         
3673                         break;
3674         }
3679 int TrackCanvas::cursor_motion_event()
3681         int result, cursor_x, cursor_y;
3682         int update_clock = 0;
3683         int update_zoom = 0;
3684         int update_scroll = 0;
3685         int update_overlay = 0;
3686         int update_cursor = 0;
3687         int new_cursor = 0;
3688         int rerender = 0;
3689         double position = 0;
3690 //printf("TrackCanvas::cursor_motion_event 1\n");
3691         result = 0;
3693 // Default cursor
3694         switch(mwindow->edl->session->editing_mode)
3695         {
3696                 case EDITING_ARROW: new_cursor = ARROW_CURSOR; break;
3697                 case EDITING_IBEAM: new_cursor = IBEAM_CURSOR; break;
3698         }
3700         switch(mwindow->session->current_operation)
3701         {
3702                 case DRAG_EDITHANDLE1:
3703 // Outside threshold.  Upgrade status
3704 //printf("TrackCanvas::cursor_motion_event 1\n");
3705                         if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3706                         {
3707 //printf("TrackCanvas::cursor_motion_event 2\n");
3708                                 mwindow->session->current_operation = DRAG_EDITHANDLE2;
3709                                 update_overlay = 1;
3710                         }
3711                         break;
3713                 case DRAG_EDITHANDLE2:
3714                         update_drag_handle();
3715                         update_overlay = 1;
3716                         break;
3718                 case DRAG_PLUGINHANDLE1:
3719                         if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3720                         {
3721 //printf("TrackCanvas::cursor_motion_event 2\n");
3722                                 mwindow->session->current_operation = DRAG_PLUGINHANDLE2;
3723                                 update_overlay = 1;
3724                         }
3725                         break;
3727                 case DRAG_PLUGINHANDLE2:
3728                         update_drag_handle();
3729                         update_overlay = 1;
3730                         break;
3732 // Rubber band curves
3733                 case DRAG_FADE:
3734                         rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3735                         break;
3737                 case DRAG_CZOOM:
3738                         rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3739                         break;
3741                 case DRAG_PZOOM:
3742                         rerender = update_overlay = update_drag_floatauto(get_cursor_x(), get_cursor_y());
3743                         break;
3745                 case DRAG_PLAY:
3746                         rerender = update_overlay = update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3747                         break;
3749                 case DRAG_MUTE:
3750                         rerender = update_overlay = update_drag_toggleauto(get_cursor_x(), get_cursor_y());
3751                         break;
3753 // Keyframe icons are sticky
3754                 case DRAG_PAN_PRE:
3755                 case DRAG_CAMERA_PRE:
3756                 case DRAG_MASK_PRE:
3757                 case DRAG_MODE_PRE:
3758                 case DRAG_PROJECTOR_PRE:
3759                 case DRAG_PLUGINKEY_PRE:
3760                         if(labs(get_cursor_x() - mwindow->session->drag_origin_x) > HANDLE_W)
3761                         {
3762 //printf("TrackCanvas::cursor_motion_event 2\n");
3763                                 mwindow->session->current_operation++;
3764                                 update_overlay = 1;
3765                         }
3766                         break;
3768                 case DRAG_PAN:
3769                 case DRAG_CAMERA:
3770                 case DRAG_MASK:
3771                 case DRAG_MODE:
3772                 case DRAG_PROJECTOR:
3773                         rerender = update_overlay = 
3774                                 update_drag_auto(get_cursor_x(), get_cursor_y());
3775                         break;
3776                 case DRAG_PLUGINKEY:
3777                         rerender = update_overlay = 
3778                                 update_drag_pluginauto(get_cursor_x(), get_cursor_y());
3779                         break;
3781                 case SELECT_REGION:
3782                 {
3783                         cursor_x = get_cursor_x();
3784                         cursor_y = get_cursor_y();
3785                         position = (double)(cursor_x + mwindow->edl->local_session->view_start) * 
3786                                 mwindow->edl->local_session->zoom_sample /
3787                                 mwindow->edl->session->sample_rate;
3789                         position = mwindow->edl->align_to_frame(position, 0);
3790                         position = MAX(position, 0);
3792                         if(position < selection_midpoint1)
3793                         {
3794                                 mwindow->edl->local_session->selectionend = selection_midpoint1;
3795                                 mwindow->edl->local_session->selectionstart = position;
3796 // Que the CWindow
3797                                 mwindow->cwindow->update(1, 0, 0, 0, 1);
3798 // Update the faders
3799                                 mwindow->update_plugin_guis();
3800                                 gui->patchbay->update();
3801                         }
3802                         else
3803                         {
3804                                 mwindow->edl->local_session->selectionstart = selection_midpoint1;
3805                                 mwindow->edl->local_session->selectionend = position;
3806 // Don't que the CWindow
3807                         }
3808 //printf("TrackCanvas::cursor_motion_event 1 %f %f %f\n", position, mwindow->edl->local_session->selectionstart, mwindow->edl->local_session->selectionend);
3810                         gui->cursor->hide();
3811                         gui->cursor->draw();
3812                         flash();
3813                         result = 1;
3814                         update_clock = 1;
3815                         update_zoom = 1;
3816                         update_scroll = 1;
3817                         break;
3818                 }
3820                 default:
3821                         if(is_event_win() && cursor_inside())
3822                         {
3823 // Update clocks
3824                                 cursor_x = get_cursor_x();
3825                                 position = (double)cursor_x * 
3826                                         (double)mwindow->edl->local_session->zoom_sample / 
3827                                         (double)mwindow->edl->session->sample_rate + 
3828                                         (double)mwindow->edl->local_session->view_start * 
3829                                         (double)mwindow->edl->local_session->zoom_sample / 
3830                                         (double)mwindow->edl->session->sample_rate;
3831                                 position = mwindow->edl->align_to_frame(position, 0);
3832                                 update_clock = 1;
3834 // Update cursor
3835                                 if(mwindow->edl->session->auto_conf->transitions && 
3836                                         test_transitions(get_cursor_x(), 
3837                                                 get_cursor_y(), 
3838                                                 0, 
3839                                                 new_cursor, 
3840                                                 update_cursor))
3841                                 {
3842                                         break;
3843                                 }
3844                                 else
3845 // Update cursor
3846                                 if(do_keyframes(get_cursor_x(), 
3847                                         get_cursor_y(), 
3848                                         0, 
3849                                         0, 
3850                                         new_cursor,
3851                                         update_cursor,
3852                                         rerender))
3853                                 {
3854                                         break;
3855                                 }
3856                                 else
3857 // Edit boundaries
3858                                 if(test_edit_handles(get_cursor_x(), 
3859                                         get_cursor_y(), 
3860                                         0, 
3861                                         new_cursor,
3862                                         update_cursor))
3863                                 {
3864                                         break;
3865                                 }
3866                                 else
3867 // Plugin boundaries
3868                                 if(test_plugin_handles(get_cursor_x(), 
3869                                         get_cursor_y(), 
3870                                         0, 
3871                                         new_cursor,
3872                                         update_cursor))
3873                                 {
3874                                         break;
3875                                 }
3876                                 else
3877                                 if(test_edits(get_cursor_x(), 
3878                                         get_cursor_y(), 
3879                                         0, 
3880                                         0, 
3881                                         update_overlay, 
3882                                         rerender,
3883                                         new_cursor,
3884                                         update_cursor))
3885                                 {
3886                                         break;
3887                                 }
3888                         }
3889                         break;
3890         }
3892 //printf("TrackCanvas::cursor_motion_event 1\n");
3893         if(update_cursor && new_cursor != get_cursor())
3894         {
3895                 set_cursor(new_cursor);
3896         }
3898 //printf("TrackCanvas::cursor_motion_event 1 %d\n", rerender);
3899         if(rerender)
3900         {
3901                 mwindow->restart_brender();
3902                 mwindow->sync_parameters(CHANGE_PARAMS);
3903                 mwindow->update_plugin_guis();
3904                 mwindow->cwindow->update(1, 0, 0, 0, 1);
3905 // Update faders
3906                 gui->patchbay->update();
3907         }
3910         if(update_clock)
3911         {
3912                 if(!mwindow->cwindow->playback_engine->is_playing_back)
3913                         gui->mainclock->update(position);
3914         }
3916         if(update_zoom)
3917         {
3918                 gui->zoombar->update();
3919         }
3921         if(update_scroll)
3922         {
3923                 if(!drag_scroll && 
3924                         (cursor_x >= get_w() || cursor_x < 0 || cursor_y >= get_h() || cursor_y < 0))
3925                         start_dragscroll();
3926                 else
3927                 if(drag_scroll &&
3928                         (cursor_x < get_w() && cursor_x >= 0 && cursor_y < get_h() && cursor_y >= 0))
3929                         stop_dragscroll();
3930         }
3932         if(update_overlay)
3933         {
3934                 draw_overlays();
3935                 flash();
3936                 flush();
3937         }
3940 //printf("TrackCanvas::cursor_motion_event 100\n");
3941         return result;
3944 void TrackCanvas::start_dragscroll()
3946         if(!drag_scroll)
3947         {
3948                 drag_scroll = 1;
3949                 set_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3950 //printf("TrackCanvas::start_dragscroll 1\n");
3951         }
3954 void TrackCanvas::stop_dragscroll()
3956         if(drag_scroll)
3957         {
3958                 drag_scroll = 0;
3959                 unset_repeat(BC_WindowBase::get_resources()->scroll_repeat);
3960 //printf("TrackCanvas::stop_dragscroll 1\n");
3961         }
3964 int TrackCanvas::repeat_event(int64_t duration)
3966         if(!drag_scroll) return 0;
3967         if(duration != BC_WindowBase::get_resources()->scroll_repeat) return 0;
3969         int sample_movement = 0;
3970         int track_movement = 0;
3971         int64_t x_distance = 0;
3972         int64_t y_distance = 0;
3973         double position = 0;
3974         int result = 0;
3976         switch(mwindow->session->current_operation)
3977         {
3978                 case SELECT_REGION:
3979 //printf("TrackCanvas::repeat_event 1 %d\n", mwindow->edl->local_session->view_start);
3980                         if(get_cursor_x() > get_w())
3981                         {
3982                                 x_distance = get_cursor_x() - get_w();
3983                                 sample_movement = 1;
3984                         }
3985                         else
3986                         if(get_cursor_x() < 0)
3987                         {
3988                                 x_distance = get_cursor_x();
3989                                 sample_movement = 1;
3990                         }
3992                         if(get_cursor_y() > get_h())
3993                         {
3994                                 y_distance = get_cursor_y() - get_h();
3995                                 track_movement = 1;
3996                         }
3997                         else
3998                         if(get_cursor_y() < 0)
3999                         {
4000                                 y_distance = get_cursor_y();
4001                                 track_movement = 1;
4002                         }
4003                         result = 1;
4004                         break;
4005         }
4008         if(sample_movement)
4009         {
4010                 position = (double)(get_cursor_x() + 
4011                         mwindow->edl->local_session->view_start + 
4012                         x_distance) * 
4013                         mwindow->edl->local_session->zoom_sample /
4014                         mwindow->edl->session->sample_rate;
4015                 position = mwindow->edl->align_to_frame(position, 0);
4016                 position = MAX(position, 0);
4018 //printf("TrackCanvas::repeat_event 1 %f\n", position);
4019                 switch(mwindow->session->current_operation)
4020                 {
4021                         case SELECT_REGION:
4022                                 if(position < selection_midpoint1)
4023                                 {
4024                                         mwindow->edl->local_session->selectionend = selection_midpoint1;
4025                                         mwindow->edl->local_session->selectionstart = position;
4026 // Que the CWindow
4027                                         mwindow->cwindow->update(1, 0, 0);
4028 // Update the faders
4029                                         mwindow->update_plugin_guis();
4030                                         gui->patchbay->update();
4031                                 }
4032                                 else
4033                                 {
4034                                         mwindow->edl->local_session->selectionstart = selection_midpoint1;
4035                                         mwindow->edl->local_session->selectionend = position;
4036 // Don't que the CWindow
4037                                 }
4038                                 break;
4039                 }
4041                 mwindow->samplemovement(mwindow->edl->local_session->view_start + 
4042                         x_distance);
4043         }
4045         if(track_movement)
4046         {
4047                 mwindow->trackmovement(mwindow->edl->local_session->track_start + 
4048                         y_distance);
4049         }
4051         return result;
4054 int TrackCanvas::button_release_event()
4056         int redraw = 0, update_overlay = 0, result = 0;
4058         switch(mwindow->session->current_operation)
4059         {
4060                 case DRAG_EDITHANDLE2:
4061                         mwindow->session->current_operation = NO_OPERATION;
4062                         drag_scroll = 0;
4063                         result = 1;
4064                         
4065                         end_edithandle_selection();
4066                         break;
4068                 case DRAG_EDITHANDLE1:
4069                         mwindow->session->current_operation = NO_OPERATION;
4070                         drag_scroll = 0;
4071                         result = 1;
4072                         break;
4074                 case DRAG_PLUGINHANDLE2:
4075                         mwindow->session->current_operation = NO_OPERATION;
4076                         drag_scroll = 0;
4077                         result = 1;
4078                         
4079                         end_pluginhandle_selection();
4080                         break;
4082                 case DRAG_PLUGINHANDLE1:
4083                         mwindow->session->current_operation = NO_OPERATION;
4084                         drag_scroll = 0;
4085                         result = 1;
4086                         break;
4088                 case DRAG_FADE:
4089                         synchronize_autos(0, 0, 0, -1); // delete the drag_auto_gang first and remove out of order keys
4090                 case DRAG_CZOOM:
4091                 case DRAG_PZOOM:
4092                 case DRAG_PLAY:
4093                 case DRAG_MUTE:
4094                 case DRAG_MASK:
4095                 case DRAG_MODE:
4096                 case DRAG_PAN:
4097                 case DRAG_CAMERA:
4098                 case DRAG_PROJECTOR:
4099                 case DRAG_PLUGINKEY:
4100                         mwindow->session->current_operation = NO_OPERATION;
4101                         mwindow->session->drag_handle = 0;
4102 // Remove any out-of-order keyframe
4103                         if(mwindow->session->drag_auto)
4104                         {
4105                                 mwindow->session->drag_auto->autos->remove_nonsequential(
4106                                         mwindow->session->drag_auto);
4107 //                              mwindow->session->drag_auto->autos->optimize();
4108                                 update_overlay = 1;
4109                         }
4110                         mwindow->undo->update_undo_after();
4111                         result = 1;
4112                         break;
4114                 case DRAG_EDIT:
4115                 case DRAG_AEFFECT_COPY:
4116                 case DRAG_VEFFECT_COPY:
4117 // Trap in drag stop
4119                         break;
4122                 default:
4123                         if(mwindow->session->current_operation)
4124                         {
4125                                 mwindow->session->current_operation = NO_OPERATION;
4126                                 drag_scroll = 0;
4127 // Traps button release events
4128 //                              result = 1;
4129                         }
4130                         break;
4131         }
4132         if (result) 
4133                 cursor_motion_event();
4134         if(update_overlay)
4135         {
4136                 draw_overlays();
4137                 flash();
4138                 flush();
4139         }
4140         if(redraw)
4141         {
4142                 draw();
4143                 flash();
4144                 flush();
4145         }
4146         return result;
4149 int TrackCanvas::test_edit_handles(int cursor_x, 
4150         int cursor_y, 
4151         int button_press, 
4152         int &new_cursor,
4153         int &update_cursor)
4155         Edit *edit_result = 0;
4156         int handle_result = 0;
4157         int result = 0;
4159         for(Track *track = mwindow->edl->tracks->first;
4160                 track && !result;
4161                 track = track->next)
4162         {
4163                 for(Edit *edit = track->edits->first;
4164                         edit && !result;
4165                         edit = edit->next)
4166                 {
4167                         int64_t edit_x, edit_y, edit_w, edit_h;
4168                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4170                         if(cursor_x >= edit_x && cursor_x <= edit_x + edit_w &&
4171                                 cursor_y >= edit_y && cursor_y < edit_y + edit_h)
4172                         {
4173                                 if(cursor_x < edit_x + HANDLE_W)
4174                                 {
4175                                         edit_result = edit;
4176                                         handle_result = 0;
4177                                         result = 1;
4178                                 }
4179                                 else
4180                                 if(cursor_x >= edit_x + edit_w - HANDLE_W)
4181                                 {
4182                                         edit_result = edit;
4183                                         handle_result = 1;
4184                                         result = 1;
4185                                 }
4186                                 else
4187                                 {
4188                                         result = 0;
4189                                 }
4190                         }
4191                 }
4192         }
4194         update_cursor = 1;
4195         if(result)
4196         {
4197                 double position;
4198                 if(handle_result == 0)
4199                 {
4200                         position = edit_result->track->from_units(edit_result->startproject);
4201                         new_cursor = LEFT_CURSOR;
4202                 }
4203                 else
4204                 if(handle_result == 1)
4205                 {
4206                         position = edit_result->track->from_units(edit_result->startproject + edit_result->length);
4207                         new_cursor = RIGHT_CURSOR;
4208                 }
4210 // Reposition cursor
4211                 if(button_press)
4212                 {
4213                         mwindow->session->drag_edit = edit_result;
4214                         mwindow->session->drag_handle = handle_result;
4215                         mwindow->session->drag_button = get_buttonpress() - 1;
4216                         mwindow->session->drag_position = position;
4217                         mwindow->session->current_operation = DRAG_EDITHANDLE1;
4218                         mwindow->session->drag_origin_x = get_cursor_x();
4219                         mwindow->session->drag_origin_y = get_cursor_y();
4220                         mwindow->session->drag_start = position;
4222                         int rerender = start_selection(position);
4223                         if(rerender)
4224                                 mwindow->cwindow->update(1, 0, 0);
4225                         gui->timebar->update_highlights();
4226                         gui->zoombar->update();
4227                         gui->cursor->hide();
4228                         gui->cursor->draw();
4229                         draw_overlays();
4230                         flash();
4231                         flush();
4232                 }
4233         }
4235         return result;
4238 int TrackCanvas::test_plugin_handles(int cursor_x, 
4239         int cursor_y, 
4240         int button_press,
4241         int &new_cursor,
4242         int &update_cursor)
4244         Plugin *plugin_result = 0;
4245         int handle_result = 0;
4246         int result = 0;
4247         
4248         for(Track *track = mwindow->edl->tracks->first;
4249                 track && !result;
4250                 track = track->next)
4251         {
4252                 for(int i = 0; i < track->plugin_set.total && !result; i++)
4253                 {
4254                         PluginSet *plugin_set = track->plugin_set.values[i];
4255                         for(Plugin *plugin = (Plugin*)plugin_set->first; 
4256                                 plugin && !result; 
4257                                 plugin = (Plugin*)plugin->next)
4258                         {
4259                                 int64_t plugin_x, plugin_y, plugin_w, plugin_h;
4260                                 plugin_dimensions(plugin, plugin_x, plugin_y, plugin_w, plugin_h);
4262                                 if(cursor_x >= plugin_x && cursor_x <= plugin_x + plugin_w &&
4263                                         cursor_y >= plugin_y && cursor_y < plugin_y + plugin_h)
4264                                 {
4265                                         if(cursor_x < plugin_x + HANDLE_W)
4266                                         {
4267                                                 plugin_result = plugin;
4268                                                 handle_result = 0;
4269                                                 result = 1;
4270                                         }
4271                                         else
4272                                         if(cursor_x >= plugin_x + plugin_w - HANDLE_W)
4273                                         {
4274                                                 plugin_result = plugin;
4275                                                 handle_result = 1;
4276                                                 result = 1;
4277                                         }
4278                                 }
4279                         }
4281                         if(result && shift_down())
4282                                 mwindow->session->trim_edits = plugin_set;
4283                 }
4284         }
4286 //printf("TrackCanvas::test_plugin_handles %d %d %d\n", button_press, handle_result, result);
4287         update_cursor = 1;
4288         if(result)
4289         {
4290                 double position;
4291                 if(handle_result == 0)
4292                 {
4293                         position = plugin_result->track->from_units(plugin_result->startproject);
4294                         new_cursor = LEFT_CURSOR;
4295                 }
4296                 else
4297                 if(handle_result == 1)
4298                 {
4299                         position = plugin_result->track->from_units(plugin_result->startproject + plugin_result->length);
4300                         new_cursor = RIGHT_CURSOR;
4301                 }
4302                 
4303                 if(button_press)
4304                 {
4305                         mwindow->session->drag_plugin = plugin_result;
4306                         mwindow->session->drag_handle = handle_result;
4307                         mwindow->session->drag_button = get_buttonpress() - 1;
4308                         mwindow->session->drag_position = position;
4309                         mwindow->session->current_operation = DRAG_PLUGINHANDLE1;
4310                         mwindow->session->drag_origin_x = get_cursor_x();
4311                         mwindow->session->drag_origin_y = get_cursor_y();
4312                         mwindow->session->drag_start = position;
4314                         int rerender = start_selection(position);
4315                         if(rerender) mwindow->cwindow->update(1, 0, 0);
4316                         gui->timebar->update_highlights();
4317                         gui->zoombar->update();
4318                         gui->cursor->hide();
4319                         gui->cursor->draw();
4320                         draw_overlays();
4321                         flash();
4322                         flush();
4323                 }
4324         }
4325         
4326         return result;
4330 int TrackCanvas::test_tracks(int cursor_x, 
4331                 int cursor_y,
4332                 int button_press)
4334         int result = 0;
4335         for(Track *track = mwindow->edl->tracks->first;
4336                 track && !result;
4337                 track = track->next)
4338         {
4339                 int64_t track_x, track_y, track_w, track_h;
4340                 track_dimensions(track, track_x, track_y, track_w, track_h);
4342                 if(button_press && 
4343                         get_buttonpress() == 3 &&
4344                         cursor_y >= track_y && 
4345                         cursor_y < track_y + track_h)
4346                 {
4347                         gui->edit_menu->update(track, 0);
4348                         gui->edit_menu->activate_menu();
4349                         result = 1;
4350                 }
4351         }
4352         return result;
4355 int TrackCanvas::test_edits(int cursor_x, 
4356         int cursor_y, 
4357         int button_press,
4358         int drag_start,
4359         int &redraw,
4360         int &rerender,
4361         int &new_cursor,
4362         int &update_cursor)
4364         int result = 0;
4365         int over_edit_handle = 0;
4367 //printf("TrackCanvas::test_edits 1\n");
4368         for(Track *track = mwindow->edl->tracks->first;
4369                 track && !result;
4370                 track = track->next)
4371         {
4372                 for(Edit *edit = track->edits->first;
4373                         edit && !result;
4374                         edit = edit->next)
4375                 {
4376                         int64_t edit_x, edit_y, edit_w, edit_h;
4377 //printf("TrackCanvas::test_edits 1\n");
4378                         edit_dimensions(edit, edit_x, edit_y, edit_w, edit_h);
4380 // Cursor inside a track
4381 // Cursor inside an edit
4382                         if(cursor_x >= edit_x && cursor_x < edit_x + edit_w &&
4383                                 cursor_y >= edit_y && cursor_y < edit_y + edit_h)
4384                         {
4385 // Select duration of edit
4386 //printf("TrackCanvas::test_edits 2\n");
4387                                 if(button_press)
4388                                 {
4389                                         if(get_double_click() && !drag_start)
4390                                         {
4391 //printf("TrackCanvas::test_edits 3\n");
4392                                                 mwindow->edl->local_session->selectionstart = 
4393                                                         edit->track->from_units(edit->startproject);
4394                                                 mwindow->edl->local_session->selectionend = 
4395                                                         edit->track->from_units(edit->startproject) + 
4396                                                         edit->track->from_units(edit->length);
4397                                                 if(mwindow->edl->session->cursor_on_frames) 
4398                                                 {
4399                                                         mwindow->edl->local_session->selectionstart = 
4400                                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionstart, 0);
4401                                                         mwindow->edl->local_session->selectionend = 
4402                                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionend, 1);
4403                                                 }
4404                                                 redraw = 1;
4405                                                 rerender = 1;
4406                                                 result = 1;
4407                                         }
4408                                 }
4409                                 else
4410                                 if(drag_start && track->record)
4411                                 {
4412                                         if(mwindow->edl->session->editing_mode == EDITING_ARROW)
4413                                         {
4414 // Need to create drag window
4415                                                 mwindow->session->current_operation = DRAG_EDIT;
4416                                                 mwindow->session->drag_edit = edit;
4417 //printf("TrackCanvas::test_edits 2\n");
4419 // Drag only one edit
4420                                                 if(ctrl_down())
4421                                                 {
4422                                                         mwindow->session->drag_edits->remove_all();
4423                                                         mwindow->session->drag_edits->append(edit);
4424                                                 }
4425                                                 else
4426 // Construct list of all affected edits
4427                                                 {
4428                                                         mwindow->edl->tracks->get_affected_edits(
4429                                                                 mwindow->session->drag_edits, 
4430                                                                 edit->track->from_units(edit->startproject),
4431                                                                 edit->track);
4432                                                 }
4433                                                 mwindow->session->drag_origin_x = cursor_x;
4434                                                 mwindow->session->drag_origin_y = cursor_y;
4436                                                 drag_popup = new BC_DragWindow(gui, 
4437                                                         mwindow->theme->clip_icon, 
4438                                                         get_abs_cursor_x(0) - mwindow->theme->clip_icon->get_w() / 2,
4439                                                         get_abs_cursor_y(0) - mwindow->theme->clip_icon->get_h() / 2);
4440 //printf("TrackCanvas::test_edits 3 %p\n", drag_popup);
4442                                                 result = 1;
4443                                         }
4444                                 }
4445                         }
4446                 }
4447         }
4448         return result;
4452 int TrackCanvas::test_resources(int cursor_x, int cursor_y)
4454         return 0;
4457 int TrackCanvas::test_plugins(int cursor_x, 
4458         int cursor_y, 
4459         int drag_start,
4460         int button_press,
4461         int &redraw,
4462         int &rerender)
4464         Plugin *plugin = 0;
4465         int result = 0;
4466         int done = 0;
4467         int64_t x, y, w, h;
4468         Track *track = 0;
4470 //printf("TrackCanvas::test_plugins 1\n");
4471         for(track = mwindow->edl->tracks->first;
4472                 track && !done;
4473                 track = track->next)
4474         {
4475                 if(!track->expand_view) continue;
4478                 for(int i = 0; i < track->plugin_set.total && !done; i++)
4479                 {
4480                         // first check if plugins are visible at all
4481                         if (!track->expand_view)
4482                                 continue;
4483                         PluginSet *plugin_set = track->plugin_set.values[i];
4484                         for(plugin = (Plugin*)plugin_set->first;
4485                                 plugin && !done;
4486                                 plugin = (Plugin*)plugin->next)
4487                         {
4488                                 plugin_dimensions(plugin, x, y, w, h);
4489                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4490                                         MWindowGUI::visible(y, y + h, 0, get_h()))
4491                                 {
4492                                         if(cursor_x >= x && cursor_x < x + w &&
4493                                                 cursor_y >= y && cursor_y < y + h)
4494                                         {
4495                                                 done = 1;
4496                                                 break;
4497                                         }
4498                                 }
4499                         }
4500                 }
4501         }
4503 //printf("TrackCanvas::test_plugins 1\n");
4504         if(plugin)
4505         {
4506 // Start plugin popup
4507                 if(button_press)
4508                 {
4509 //printf("TrackCanvas::test_plugins 2\n");
4510                         if(get_buttonpress() == 3)
4511                         {
4512                                 gui->plugin_menu->update(plugin);
4513                                 gui->plugin_menu->activate_menu();
4514                                 result = 1;
4515                         } 
4516                         else
4517 // Select range of plugin on doubleclick over plugin
4518                         if (get_double_click() && !drag_start)
4519                         {
4520                                 mwindow->edl->local_session->selectionstart = 
4521                                         plugin->track->from_units(plugin->startproject);
4522                                 mwindow->edl->local_session->selectionend = 
4523                                         plugin->track->from_units(plugin->startproject) + 
4524                                         plugin->track->from_units(plugin->length);
4525                                 if(mwindow->edl->session->cursor_on_frames) 
4526                                 {
4527                                         mwindow->edl->local_session->selectionstart = 
4528                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionstart, 0);
4529                                         mwindow->edl->local_session->selectionend = 
4530                                                 mwindow->edl->align_to_frame(mwindow->edl->local_session->selectionend, 1);
4531                                 }
4532                                 rerender = 1;
4533                                 redraw = 1;
4534                                 result = 1;
4535                         }
4536 //printf("TrackCanvas::test_plugins 3\n");
4537                 }
4538                 else
4539 // Move plugin
4540                 if(drag_start && plugin->track->record)
4541                 {
4542 //printf("TrackCanvas::test_plugins 4\n");
4543                         if(mwindow->edl->session->editing_mode == EDITING_ARROW)
4544                         {
4545 //printf("TrackCanvas::test_plugins 5\n");
4546                                 if(plugin->track->data_type == TRACK_AUDIO)
4547                                         mwindow->session->current_operation = DRAG_AEFFECT_COPY;
4548                                 else
4549                                 if(plugin->track->data_type == TRACK_VIDEO)
4550                                         mwindow->session->current_operation = DRAG_VEFFECT_COPY;
4552                                 mwindow->session->drag_plugin = plugin;
4553 //printf("TrackCanvas::test_plugins 6\n");
4559 // Create picon
4560                                 switch(plugin->plugin_type)
4561                                 {
4562                                         case PLUGIN_STANDALONE:
4563                                         {
4564                                                 PluginServer *server = mwindow->scan_plugindb(
4565                                                         plugin->title,
4566                                                         plugin->track->data_type);
4567                                                 if (server) 
4568                                                 {
4569                                                         VFrame *frame = server->picon;
4570 //printf("TrackCanvas::test_plugins 7\n");
4571                                                         drag_popup = new BC_DragWindow(gui, 
4572                                                                 frame, 
4573                                                                 get_abs_cursor_x(0) - frame->get_w() / 2,
4574                                                                 get_abs_cursor_y(0) - frame->get_h() / 2);
4575                                                 }
4576                                                 break;
4577                                         }
4578                                         
4579                                         case PLUGIN_SHAREDPLUGIN:
4580                                         case PLUGIN_SHAREDMODULE:
4581                                                 drag_popup = new BC_DragWindow(gui, 
4582                                                         mwindow->theme->clip_icon, 
4583                                                         get_abs_cursor_x(0) - mwindow->theme->clip_icon->get_w() / 2,
4584                                                         get_abs_cursor_y(0) - mwindow->theme->clip_icon->get_h() / 2);
4585                                                 break;
4586 //printf("test plugins %d %p\n", mwindow->edl->session->editing_mode, mwindow->session->drag_plugin);
4587                                 }
4589 //printf("TrackCanvas::test_plugins 9 %p\n");
4591 //printf("TrackCanvas::test_plugins 10\n");
4592                                 result = 1;
4593                         }
4594                 }
4595         }
4597 //printf("TrackCanvas::test_plugins 11\n");
4598         return result;
4601 int TrackCanvas::test_transitions(int cursor_x, 
4602         int cursor_y, 
4603         int button_press,
4604         int &new_cursor,
4605         int &update_cursor)
4607         Transition *transition = 0;
4608         int result = 0;
4609         int64_t x, y, w, h;
4610         
4611         for(Track *track = mwindow->edl->tracks->first;
4612                 track && !result;
4613                 track = track->next)
4614         {
4615                 for(Edit *edit = track->edits->first;
4616                         edit;
4617                         edit = edit->next)
4618                 {
4619                         if(edit->transition)
4620                         {
4621                                 edit_dimensions(edit, x, y, w, h);
4622                                 get_transition_coords(x, y, w, h);
4624                                 if(MWindowGUI::visible(x, x + w, 0, get_w()) &&
4625                                         MWindowGUI::visible(y, y + h, 0, get_h()))
4626                                 {
4627                                         if(cursor_x >= x && cursor_x < x + w &&
4628                                                 cursor_y >= y && cursor_y < y + h)
4629                                         {
4630                                                 transition = edit->transition;
4631                                                 result = 1;
4632                                                 break;
4633                                         }
4634                                 }
4635                         }
4636                 }
4637         }
4638         
4639         update_cursor = 1;
4640         if(transition)
4641         {
4642                 if(!button_press)
4643                 {
4644                         new_cursor = UPRIGHT_ARROW_CURSOR;
4645                 }
4646                 else
4647                 if(get_buttonpress() == 3)
4648                 {
4649                         gui->transition_menu->update(transition);
4650                         gui->transition_menu->activate_menu();
4651                 }
4652         }
4654         return result;
4657 int TrackCanvas::button_press_event()
4659         int result = 0;
4660         int cursor_x, cursor_y;
4661         int new_cursor, update_cursor;
4663 //printf("TrackCanvas::button_press_event 1\n");
4664         cursor_x = get_cursor_x();
4665         cursor_y = get_cursor_y();
4666         mwindow->session->trim_edits = 0;
4668         if(is_event_win() && cursor_inside())
4669         {
4670                 if(!active)
4671                 {
4672                         activate();
4673                 }
4675                 if(get_buttonpress() == 1)
4676                 {
4677                         gui->unlock_window();
4678                         gui->mbuttons->transport->handle_transport(STOP, 1);
4679                         gui->lock_window("TrackCanvas::button_press_event");
4680                 }
4682                 int update_overlay = 0, update_cursor = 0, rerender = 0;
4684                 if(get_buttonpress() == 4)
4685                 {
4686 //printf("TrackCanvas::button_press_event 1\n");
4687                         mwindow->move_up(get_h() / 10);
4688                         result = 1;
4689                 }
4690                 else
4691                 if(get_buttonpress() == 5)
4692                 {
4693 //printf("TrackCanvas::button_press_event 2\n");
4694                         mwindow->move_down(get_h() / 10);
4695                         result = 1;
4696                 }
4697                 else
4698                 switch(mwindow->edl->session->editing_mode)
4699                 {
4700 // Test handles and resource boundaries and highlight a track
4701                         case EDITING_ARROW:
4702                         {
4703                                 Edit *edit;
4704                                 int handle;
4705                                 if(mwindow->edl->session->auto_conf->transitions && 
4706                                         test_transitions(cursor_x, 
4707                                                 cursor_y, 
4708                                                 1, 
4709                                                 new_cursor, 
4710                                                 update_cursor))
4711                                 {
4712                                         break;
4713                                 }
4714                                 else
4715                                 if(do_keyframes(cursor_x, 
4716                                         cursor_y, 
4717                                         0, 
4718                                         get_buttonpress(), 
4719                                         new_cursor, 
4720                                         update_cursor,
4721                                         rerender))
4722                                 {
4723                                         break;
4724                                 }
4725                                 else
4726 // Test edit boundaries
4727                                 if(test_edit_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4728                                 {
4729                                         break;
4730                                 }
4731                                 else
4732 // Test plugin boundaries
4733                                 if(test_plugin_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4734                                 {
4735                                         break;
4736                                 }
4737                                 else
4738                                 if(test_edits(cursor_x, cursor_y, 1, 0, update_cursor, rerender, new_cursor, update_cursor))
4739                                 {
4740                                         break;
4741                                 }
4742                                 else
4743                                 if(test_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender))
4744                                 {
4745                                         break;
4746                                 }
4747                                 else
4748                                 if(test_resources(cursor_x, cursor_y))
4749                                 {
4750                                         break;
4751                                 }
4752                                 else
4753                                 if(test_tracks(cursor_x, cursor_y, 1))
4754                                 {
4755                                         break;
4756                                 }
4757                                 break;
4758                         }
4760 // Test handles only and select a region
4761                         case EDITING_IBEAM:
4762                         {
4763                                 double position = (double)cursor_x * 
4764                                         mwindow->edl->local_session->zoom_sample /
4765                                         mwindow->edl->session->sample_rate + 
4766                                         (double)mwindow->edl->local_session->view_start * 
4767                                         mwindow->edl->local_session->zoom_sample /
4768                                         mwindow->edl->session->sample_rate;
4769 //printf("TrackCanvas::button_press_event %d\n", position);
4771                                 if(mwindow->edl->session->auto_conf->transitions && 
4772                                         test_transitions(cursor_x, 
4773                                                 cursor_y, 
4774                                                 1, 
4775                                                 new_cursor, 
4776                                                 update_cursor))
4777                                 {
4778                                         break;
4779                                 }
4780                                 else
4781                                 if(do_keyframes(cursor_x, 
4782                                         cursor_y, 
4783                                         0, 
4784                                         get_buttonpress(), 
4785                                         new_cursor, 
4786                                         update_cursor,
4787                                         rerender))
4788                                 {
4789                                         update_overlay = 1;
4790                                         break;
4791                                 }
4792                                 else
4793 // Test edit boundaries
4794                                 if(test_edit_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4795                                 {
4796                                         break;
4797                                 }
4798                                 else
4799 // Test plugin boundaries
4800                                 if(test_plugin_handles(cursor_x, cursor_y, 1, new_cursor, update_cursor))
4801                                 {
4802                                         break;
4803                                 }
4804                                 else
4805                                 if(test_edits(cursor_x, cursor_y, 1, 0, update_cursor, rerender, new_cursor, update_cursor))
4806                                 {
4807                                         break;
4808                                 }
4809                                 else
4810                                 if(test_plugins(cursor_x, cursor_y, 0, 1, update_cursor, rerender))
4811                                 {
4812                                         break;
4813                                 }
4814                                 else
4815                                 if(test_tracks(cursor_x, cursor_y, 1))
4816                                 {
4817                                         break;
4818                                 }
4819 // Highlight selection
4820                                 else
4821                                 {
4822                                         rerender = start_selection(position);
4823                                         mwindow->session->current_operation = SELECT_REGION;
4824                                         update_cursor = 1;
4825                                 }
4827                                 break;
4828                         }
4829                 }
4832                 if(rerender)
4833                 {
4834                         mwindow->cwindow->update(1, 0, 0, 0, 1);
4835 // Update faders
4836                         mwindow->update_plugin_guis();
4837                         gui->patchbay->update();
4838                 }
4840                 if(update_overlay)
4841                 {
4842                         draw_overlays();
4843                         flash();
4844                 }
4846                 if(update_cursor)
4847                 {
4848                         gui->timebar->update_highlights();
4849                         gui->cursor->hide();
4850                         gui->cursor->show();
4851                         gui->zoombar->update();
4852                         flash();
4853                         result = 1;
4854                 }
4858         }
4859         return result;
4862 int TrackCanvas::start_selection(double position)
4864         int rerender = 0;
4865         position = mwindow->edl->align_to_frame(position, 0);
4867 // Extend a border
4868         if(shift_down())
4869         {
4870                 double midpoint = (mwindow->edl->local_session->selectionstart + 
4871                         mwindow->edl->local_session->selectionend) / 2;
4873                 if(position < midpoint)
4874                 {
4875                         mwindow->edl->local_session->selectionstart = position;
4876                         selection_midpoint1 = mwindow->edl->local_session->selectionend;
4877 // Que the CWindow
4878                         rerender = 1;
4879                 }
4880                 else
4881                 {
4882                         mwindow->edl->local_session->selectionend = position;
4883                         selection_midpoint1 = mwindow->edl->local_session->selectionstart;
4884 // Don't que the CWindow for the end
4885                 }
4886         }
4887         else
4888 // Start a new selection
4889         {
4890 //printf("TrackCanvas::start_selection %f\n", position);
4891                 mwindow->edl->local_session->selectionstart = 
4892                         mwindow->edl->local_session->selectionend = 
4893                         position;
4894                 selection_midpoint1 = position;
4895 // Que the CWindow
4896                 rerender = 1;
4897         }
4898         
4899         return rerender;
4902 void TrackCanvas::end_edithandle_selection()
4904         mwindow->modify_edithandles();
4907 void TrackCanvas::end_pluginhandle_selection()
4909         mwindow->modify_pluginhandles();
4913 double TrackCanvas::time_visible()
4915         return (double)get_w() * 
4916                 mwindow->edl->local_session->zoom_sample / 
4917                 mwindow->edl->session->sample_rate;
4960 void TrackCanvas::draw_automation()
4965 int TrackCanvas::set_index_file(int flash, Asset *asset)
4967         return 0;
4971 int TrackCanvas::button_release()
4973         return 0;
4977 int TrackCanvas::auto_reposition(int &cursor_x, int &cursor_y, int64_t cursor_position)
4979         return 0;
4983 int TrackCanvas::draw_floating_handle(int flash)
4985         return 0;
4988 int TrackCanvas::draw_loop_point(int64_t position, int flash)
4990         return 0;
4993 int TrackCanvas::draw_playback_cursor(int pixel, int flash)
4995         return 0;
4999 int TrackCanvas::update_handle_selection(int64_t cursor_position)
5001         return 0;
5004 int TrackCanvas::end_translation()
5006         return 0;