4 * Copyright (C) 2008-2014 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include "bctimer.inc"
31 #include "edithandles.inc"
33 #include "floatauto.inc"
34 #include "floatautos.inc"
35 #include "intauto.inc"
37 #include "indexable.h"
38 #include "keyframe.inc"
39 #include "mwindow.inc"
40 #include "mwindowgui.inc"
42 #include "pluginset.inc"
43 #include "plugintoggles.inc"
44 #include "resourcepixmap.inc"
45 #include "timelinepane.inc"
47 #include "trackcanvas.inc"
49 #include "transitionhandles.inc"
50 #include "keyframe.inc"
54 class TrackCanvas : public BC_SubWindow
57 TrackCanvas(MWindow *mwindow, MWindowGUI *gui);
58 TrackCanvas(MWindow *mwindow, TimelinePane *pane, int x, int y, int w, int h);
61 void create_objects();
63 int drag_start_event();
64 int cursor_leave_event();
67 // *** CONTEXT_HELP ***
68 int help_transitions(int cursor_x, int cursor_y);
69 int help_transition_handles(int cursor_x, int cursor_y);
70 int help_keyframes(int cursor_x, int cursor_y);
71 int help_edit_handles(int cursor_x, int cursor_y);
72 int help_plugin_handles(int cursor_x, int cursor_y);
73 int help_plugins(int cursor_x, int cursor_y);
74 int help_plugin_autos(Track *track, int cursor_x, int cursor_y);
75 int help_autos(Track *track, Autos *autos, int cursor_x, int cursor_y, BC_Pixmap *pixmap);
76 int help_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y, int autogrouptype);
77 int help_int_autos(Track *track, Autos *autos, int cursor_x, int cursor_y);
79 void draw_resources(int mode = 0,
80 int indexes_only = 0, // Redraw only certain audio resources with indexes
81 Indexable *indexable = 0);
82 void draw_highlight_rectangle(int x, int y, int w, int h);
83 void draw_highlight_insertion(int x, int y, int w, int h);
84 void draw_playback_cursor();
85 void draw_highlighting();
86 void draw_keyframe_reticle();
87 int draw_hairline(Auto *auto_keyframe, int color, int show);
88 void draw_speed_highlight();
89 void draw_speed_track(Track *track);
91 // User can either call draw or draw_overlays to copy a fresh
92 // canvas and just draw the overlays over it
94 void update_handles();
95 // Convert edit coords to transition coords
96 void get_transition_coords(Edit *edit,
97 int64_t &x, int64_t &y, int64_t &w, int64_t &h);
98 void get_handle_coords(Edit *edit,
104 int get_drag_values(float *percentage,
110 void draw_title(Edit *edit,
115 void draw_automation();
116 void draw_hard_edges();
117 void draw_inout_points();
118 void draw_auto(Auto *current, int x, int y,
119 int center_pixel, int data_h);
120 void draw_floatauto(FloatAuto *current,
121 int x_offset, int center_pixel, int data_h, int color,
122 double unit_start, double zoom_units, double yscale,
124 int test_auto(Auto *current, int x, int y,
125 int center_pixel, int data_h,
126 int cursor_x, int cursor_y, int buttonpress);
127 int test_floatauto(FloatAuto *current, int buttonpress,
128 int center_pixel, int data_h, int cursor_x, int cursor_y,
129 double unit_start, double zoom_units, double yscale,
131 void draw_floatline(int center_pixel,
144 int test_floatline(int center_pixel,
155 void draw_toggleline(int center_pixel,
160 int test_toggleline(Autos *autos,
169 int do_keyframes(int cursor_x,
177 int do_float_autos(Track *track,
186 Auto* &auto_instance,
188 int do_int_autos(Track *track,
197 Auto * &auto_instance);
198 int do_autos(Track *track,
205 Auto* &auto_instance,
207 int do_plugin_autos(Track *track,
212 Plugin* &keyframe_plugin,
213 KeyFrame* &keyframe_instance);
216 void calculate_viewport(Track *track,
226 // Convert percentage position inside track to value.
227 // if is_toggle is 1, the result is either 0 or 1.
228 // if reference is nonzero and a FloatAuto,
229 // the result is made relative to the value in reference.
230 float percentage_to_value(float percentage,
231 int is_toggle, Auto *reference, int autogrouptype);
232 // Get x and y of a FloatAuto relative to center_pixel
233 void calculate_auto_position(int edge, double *x, double *y,
234 double *in_x, double *in_y, double *out_x, double *out_y,
235 Auto *current, double unit_start, double zoom_units,
236 double yscale, int autogrouptype);
237 void fill_ganged_autos(int gang, float change, Track *skip, FloatAuto *fauto);
238 void update_ganged_autos(float change, Track *skip, FloatAuto *fauto);
239 void clear_ganged_autos();
241 void draw_brender_range();
242 void draw_loop_points();
243 void draw_transitions();
244 void draw_drag_handle();
245 void draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1);
247 void refresh_plugintoggles();
248 void update_edit_handles(Edit *edit, int64_t edit_x, int64_t edit_y, int64_t edit_w, int64_t edit_h);
249 void update_transitions();
250 void update_keyframe_handles(Track *track);
251 // Draw everything to synchronize with the view.
252 void draw(int mode, int hide_cursor);
253 // Draw resources during index building
254 void draw_indexes(Indexable *indexable);
255 // Get location of edit on screen without boundary checking
256 void edit_dimensions(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
257 void track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
258 void plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
259 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);
260 ResourcePixmap* create_pixmap(Edit *edit, int64_t edit_x, int64_t pixmap_x, int64_t pixmap_w, int64_t pixmap_h);
261 void update_cursor(int flush);
262 void draw_selected(int x, int y, int w, int h);
266 // Get edit and handle the cursor is over
267 int do_edit_handles(int cursor_x, int cursor_y, int button_press,
268 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor);
269 // Get plugin and handle the cursor if over
270 int do_plugin_handles(int cursor_x, int cursor_y, int button_press,
271 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor);
272 int do_transition_handles(int cursor_x, int cursor_y, int button_press,
273 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor);
274 int drag_transition_handle(double position);
275 // Get edit the cursor is over
276 int do_edits(int cursor_x, int cursor_y, int button_press,
277 int drag_start, int &redraw, int &rerender, int &new_cursor, int &update_cursor);
278 int do_tracks(int cursor_x,
281 int test_track_group(EDL *group, Track *first_track, double &pos);
282 int edit_intersects(Track *track, Edit *src_edit, double &pos);
283 int test_resources(int cursor_x, int cursor_y);
284 int do_plugins(int cursor_x, int cursor_y, int drag_start, int button_press,
285 int &redraw, int &rerender);
286 int do_transitions(int cursor_x, int cursor_y, int button_press,
287 int &new_cursor, int &update_cursor);
288 void draw_cropped_line(int x1, int y1, int x2, int y2, int min_y, int max_y);
289 int button_press_event();
290 int button_release_event();
291 int cursor_update(int in_motion);
292 int cursor_motion_event();
295 int repeat_event(int64_t duration);
296 void start_dragscroll();
297 void stop_dragscroll();
298 int start_selection(double position);
299 int drag_motion_event();
300 int drag_stop_event();
301 int drag_motion(Track **over_track, Edit **over_edit,
302 PluginSet **over_pluginset, Plugin **over_plugin);
303 int drag_cursor_motion(int cursor_x, int cursor_y,
304 Track **over_track, Edit **over_edit,
305 PluginSet **over_pluginset, Plugin **over_plugin);
306 int drag_stop(int *redraw);
307 int64_t drop_edit_position (int *is_insertion, Edit *moved_edit, int64_t moved_edit_length);
308 int64_t drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin);
309 void end_edithandle_selection();
310 void end_pluginhandle_selection();
311 void end_transnhandle_selection();
312 // Number of seconds spanned by the trackcanvas
313 double time_visible();
314 void update_drag_handle();
315 int update_drag_edit();
316 int render_handle_frame(EDL *edl, int64_t pos, int mode);
317 int update_drag_floatauto(int cursor_x, int cursor_y);
318 int update_drag_toggleauto(int cursor_x, int cursor_y);
319 int update_drag_auto(int cursor_x, int cursor_y);
320 int update_drag_pluginauto(int cursor_x, int cursor_y);
321 void show_message(Auto *current, int box_color, const char *fmt, ...);
323 // Update status bar to reflect drag operation
324 void update_drag_caption();
325 void drag_edit_select(Edit *over_edit, int select, int draw);
329 // Display hourglass if timer expired
331 // get the relevant patchbay by traversing the panes
332 // Patchbay* get_patchbay();
337 // Allows overlays to get redrawn without redrawing the resources
338 BC_Pixmap *background_pixmap;
339 BC_Pixmap *transition_pixmap;
340 EditHandles *edit_handles;
341 // TransitionHandles *transition_handles;
342 BC_Pixmap *keyframe_pixmap;
343 BC_Pixmap *camerakeyframe_pixmap;
344 BC_Pixmap *modekeyframe_pixmap;
345 BC_Pixmap *pankeyframe_pixmap;
346 BC_Pixmap *projectorkeyframe_pixmap;
347 BC_Pixmap *maskkeyframe_pixmap;
350 // Currently in a drag scroll operation
352 // Don't stop hourglass if it was never started before the operation.
353 int hourglass_enabled;
354 // position used by timebar, when the timebar needs to draw a highlight
355 double timebar_position;
357 // Temporary for picon drawing
359 // Timer for hourglass
360 Timer *resource_timer;
363 // Plugin toggle interfaces
364 ArrayList<PluginOn*> plugin_on_toggles;
365 ArrayList<PluginShow*> plugin_show_toggles;
366 ArrayList<PluginPresetEdit*> preset_edit_buttons;
368 static int auto_operations[];
370 void draw_paste_destination();
372 void draw_floatauto_ctrlpoint(int x, int y, int cp_x, int cp_y,
373 int center_pixel, int zoom_track, int color);
375 float value_to_percentage(float auto_value, int autogrouptype);
376 // transforms automation value into current display coords
377 // dependant on current automation display range for given kind of automation
379 // ====================================== cursor selection type
381 double selection_midpoint; // division between current ends
382 int snapped; // drag handle snapping
383 EDL *speed_edl; // drag speed handle start edl