4 * Copyright (C) 2008-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "bctimer.inc"
30 #include "edithandles.inc"
32 #include "floatauto.inc"
33 #include "floatautos.inc"
34 #include "intauto.inc"
36 #include "indexable.h"
37 #include "keyframe.inc"
38 #include "mwindow.inc"
39 #include "mwindowgui.inc"
41 #include "pluginset.inc"
42 #include "plugintoggles.inc"
43 #include "resourcepixmap.inc"
44 #include "timelinepane.inc"
46 #include "trackcanvas.inc"
48 #include "transitionhandles.inc"
49 #include "keyframe.inc"
53 class TrackCanvas : public BC_SubWindow
56 TrackCanvas(MWindow *mwindow, MWindowGUI *gui);
57 TrackCanvas(MWindow *mwindow, TimelinePane *pane, int x, int y, int w, int h);
60 void create_objects();
62 int drag_start_event();
63 int cursor_leave_event();
65 void draw_resources(int mode = 0,
66 int indexes_only = 0, // Redraw only certain audio resources with indexes
67 Indexable *indexable = 0);
68 void draw_highlight_rectangle(int x, int y, int w, int h);
69 void draw_highlight_insertion(int x, int y, int w, int h);
70 void draw_playback_cursor();
71 void draw_highlighting();
72 void draw_keyframe_reticle();
73 int draw_hairline(Auto *auto_keyframe, int color, int show);
75 // User can either call draw or draw_overlays to copy a fresh
76 // canvas and just draw the overlays over it
78 void update_handles();
79 // Convert edit coords to transition coords
80 void get_transition_coords(Edit *edit,
81 int64_t &x, int64_t &y, int64_t &w, int64_t &h);
82 void get_handle_coords(Edit *edit,
88 int get_drag_values(float *percentage,
94 void draw_title(Edit *edit,
99 void draw_automation();
100 void draw_hard_edges();
101 void draw_inout_points();
102 void draw_auto(Auto *current, int x, int y,
103 int center_pixel, int data_h);
104 void draw_floatauto(FloatAuto *current,
105 int x_offset, int center_pixel, int data_h, int color,
106 double unit_start, double zoom_units, double yscale,
108 int test_auto(Auto *current, int x, int y,
109 int center_pixel, int data_h,
110 int cursor_x, int cursor_y, int buttonpress);
111 int test_floatauto(FloatAuto *current, int buttonpress,
112 int center_pixel, int data_h, int cursor_x, int cursor_y,
113 double unit_start, double zoom_units, double yscale,
115 void draw_floatline(int center_pixel,
128 int test_floatline(int center_pixel,
139 void draw_toggleline(int center_pixel,
144 int test_toggleline(Autos *autos,
153 int do_keyframes(int cursor_x,
161 int do_float_autos(Track *track,
170 Auto* &auto_instance,
172 int do_int_autos(Track *track,
181 Auto * &auto_instance);
182 int do_autos(Track *track,
189 Auto* &auto_instance,
191 int do_plugin_autos(Track *track,
196 Plugin* &keyframe_plugin,
197 KeyFrame* &keyframe_instance);
200 void calculate_viewport(Track *track,
210 // Convert percentage position inside track to value.
211 // if is_toggle is 1, the result is either 0 or 1.
212 // if reference is nonzero and a FloatAuto,
213 // the result is made relative to the value in reference.
214 float percentage_to_value(float percentage,
215 int is_toggle, Auto *reference, int autogrouptype);
216 // Get x and y of a FloatAuto relative to center_pixel
217 void calculate_auto_position(int edge, double *x, double *y,
218 double *in_x, double *in_y, double *out_x, double *out_y,
219 Auto *current, double unit_start, double zoom_units,
220 double yscale, int autogrouptype);
221 void fill_ganged_autos(int gang, float change, Track *skip, FloatAuto *fauto);
222 void update_ganged_autos(float change, Track *skip, FloatAuto *fauto);
223 void clear_ganged_autos();
225 void draw_brender_range();
226 void draw_loop_points();
227 void draw_transitions();
228 void draw_drag_handle();
229 void draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1);
231 void refresh_plugintoggles();
232 void update_edit_handles(Edit *edit, int64_t edit_x, int64_t edit_y, int64_t edit_w, int64_t edit_h);
233 void update_transitions();
234 void update_keyframe_handles(Track *track);
235 // Draw everything to synchronize with the view.
236 void draw(int mode, int hide_cursor);
237 // Draw resources during index building
238 void draw_indexes(Indexable *indexable);
239 // Get location of edit on screen without boundary checking
240 void edit_dimensions(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
241 void track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
242 void plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
243 void get_pixmap_size(Edit *edit, int64_t edit_x, int64_t edit_w, int64_t &pixmap_x, int64_t &pixmap_w, int64_t &pixmap_h);
244 ResourcePixmap* create_pixmap(Edit *edit, int64_t edit_x, int64_t pixmap_x, int64_t pixmap_w, int64_t pixmap_h);
245 void update_cursor(int flush);
246 void draw_selected(int x, int y, int w, int h);
250 // Get edit and handle the cursor is over
251 int do_edit_handles(int cursor_x,
258 // Get plugin and handle the cursor if over
259 int do_plugin_handles(int cursor_x,
266 // Get edit the cursor is over
267 int do_edits(int cursor_x,
275 int do_tracks(int cursor_x,
278 int test_track_group(EDL *group, Track *first_track, double &pos);
279 int edit_intersects(Track *track, Edit *src_edit, double &pos);
280 int test_resources(int cursor_x, int cursor_y);
281 int do_plugins(int cursor_x,
287 int do_transitions(int cursor_x,
292 void draw_cropped_line(int x1,
298 int button_press_event();
299 int button_release_event();
300 int cursor_update(int in_motion);
301 int cursor_motion_event();
304 int repeat_event(int64_t duration);
305 void start_dragscroll();
306 void stop_dragscroll();
307 int start_selection(double position);
308 int drag_motion_event();
309 int drag_stop_event();
310 int drag_motion(Track **over_track, Edit **over_edit,
311 PluginSet **over_pluginset, Plugin **over_plugin);
312 int drag_cursor_motion(int cursor_x, int cursor_y,
313 Track **over_track, Edit **over_edit,
314 PluginSet **over_pluginset, Plugin **over_plugin);
315 int drag_stop(int *redraw);
316 int64_t drop_edit_position (int *is_insertion, Edit *moved_edit, int64_t moved_edit_length);
317 int64_t drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin);
318 void end_edithandle_selection();
319 void end_pluginhandle_selection();
320 // Number of seconds spanned by the trackcanvas
321 double time_visible();
322 void update_drag_handle();
323 int update_drag_edit();
324 int render_handle_frame(EDL *edl, int64_t pos, int mode);
325 int update_drag_floatauto(int cursor_x, int cursor_y);
326 int update_drag_toggleauto(int cursor_x, int cursor_y);
327 int update_drag_auto(int cursor_x, int cursor_y);
328 int update_drag_pluginauto(int cursor_x, int cursor_y);
329 void show_message(Auto *current, int box_color, const char *fmt, ...);
331 // Update status bar to reflect drag operation
332 void update_drag_caption();
336 // Display hourglass if timer expired
338 // get the relevant patchbay by traversing the panes
339 // Patchbay* get_patchbay();
344 // Allows overlays to get redrawn without redrawing the resources
345 BC_Pixmap *background_pixmap;
346 BC_Pixmap *transition_pixmap;
347 EditHandles *edit_handles;
348 // TransitionHandles *transition_handles;
349 BC_Pixmap *keyframe_pixmap;
350 BC_Pixmap *camerakeyframe_pixmap;
351 BC_Pixmap *modekeyframe_pixmap;
352 BC_Pixmap *pankeyframe_pixmap;
353 BC_Pixmap *projectorkeyframe_pixmap;
354 BC_Pixmap *maskkeyframe_pixmap;
357 // Currently in a drag scroll operation
359 // Don't stop hourglass if it was never started before the operation.
360 int hourglass_enabled;
361 // position used by timebar, when the timebar needs to draw a highlight
362 double timebar_position;
364 // Temporary for picon drawing
366 // Timer for hourglass
367 Timer *resource_timer;
370 // Plugin toggle interfaces
371 ArrayList<PluginOn*> plugin_on_toggles;
372 ArrayList<PluginShow*> plugin_show_toggles;
373 ArrayList<PluginPresetEdit*> preset_edit_buttons;
375 static int auto_operations[];
377 void draw_paste_destination();
379 void draw_floatauto_ctrlpoint(int x, int y, int cp_x, int cp_y,
380 int center_pixel, int zoom_track, int color);
382 float value_to_percentage(float auto_value, int autogrouptype);
383 // transforms automation value into current display coords
384 // dependant on current automation display range for given kind of automation
386 // ====================================== cursor selection type
388 double selection_midpoint; // division between current ends
389 int snapped; // drag handle snapping
390 EDL *speed_edl; // drag speed handle start edl