no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / trackcanvas.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2014 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 #ifndef TRACKCANVAS_H
24 #define TRACKCANVAS_H
25
26 #include "asset.inc"
27 #include "auto.inc"
28 #include "autos.inc"
29 #include "bctimer.inc"
30 #include "edit.inc"
31 #include "edithandles.inc"
32 #include "edl.inc"
33 #include "floatauto.inc"
34 #include "floatautos.inc"
35 #include "intauto.inc"
36 #include "guicast.h"
37 #include "indexable.h"
38 #include "keyframe.inc"
39 #include "mwindow.inc"
40 #include "mwindowgui.inc"
41 #include "plugin.inc"
42 #include "pluginset.inc"
43 #include "plugintoggles.inc"
44 #include "resourcepixmap.inc"
45 #include "timelinepane.inc"
46 #include "track.inc"
47 #include "trackcanvas.inc"
48 #include "tracks.inc"
49 #include "transitionhandles.inc"
50 #include "keyframe.inc"
51
52 #include <stdarg.h>
53
54 class TrackCanvas : public BC_SubWindow
55 {
56 public:
57         TrackCanvas(MWindow *mwindow, MWindowGUI *gui);
58         TrackCanvas(MWindow *mwindow, TimelinePane *pane, int x, int y, int w, int h);
59         ~TrackCanvas();
60
61         void create_objects();
62         void resize_event();
63         int drag_start_event();
64         int cursor_leave_event();
65         int keypress_event();
66
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);
78
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);
90
91 // User can either call draw or draw_overlays to copy a fresh
92 // canvas and just draw the overlays over it
93         void draw_overlays();
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,
99                 int64_t &x,
100                 int64_t &y,
101                 int64_t &w,
102                 int64_t &h,
103                 int side);
104         int get_drag_values(float *percentage,
105                 int64_t *position,
106                 int do_clamp,
107                 int cursor_x,
108                 int cursor_y,
109                 Auto *current);
110         void draw_title(Edit *edit,
111                 int64_t edit_x,
112                 int64_t edit_y,
113                 int64_t edit_w,
114                 int64_t edit_h);
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,
123                 int autogrouptype);
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,
130                 int autogrouptype);
131         void draw_floatline(int center_pixel,
132                 FloatAuto *previous,
133                 FloatAuto *current,
134                 FloatAutos *autos,
135                 double unit_start,
136                 double zoom_units,
137                 double yscale,
138                 int ax,
139                 int ay,
140                 int ax2,
141                 int ay2,
142                 int color,
143                 int autogrouptype);
144         int test_floatline(int center_pixel,
145                 FloatAutos *autos,
146                 double unit_start,
147                 double zoom_units,
148                 double yscale,
149                 int x1,
150                 int x2,
151                 int cursor_x,
152                 int cursor_y,
153                 int buttonpress,
154                 int autogrouptype);
155         void draw_toggleline(int center_pixel,
156                 int ax,
157                 int ay,
158                 int ax2,
159                 int ay2);
160         int test_toggleline(Autos *autos,
161                 int center_pixel,
162                 int x1,
163                 int y1,
164                 int x2,
165                 int y2,
166                 int cursor_x,
167                 int cursor_y,
168                 int buttonpress);
169         int do_keyframes(int cursor_x,
170                 int cursor_y,
171                 int draw,
172                 int buttonpress,
173                 int &new_cursor,
174                 int &update_cursor,
175                 int &rerender);
176
177         int do_float_autos(Track *track,
178                 Autos *autos,
179                 int cursor_x,
180                 int cursor_y,
181                 int draw,
182                 int buttonpress,
183                 int x_offset,
184                 int y_offset,
185                 int color,
186                 Auto* &auto_instance,
187                 int autogrouptype);
188         int do_int_autos(Track *track,
189                 Autos *autos,
190                 int cursor_x,
191                 int cursor_y,
192                 int draw,
193                 int buttonpress,
194                 int x_offset,
195                 int y_offset,
196                 int color,
197                 Auto * &auto_instance);
198         int do_autos(Track *track,
199                 Autos *autos,
200                 int cursor_x,
201                 int cursor_y,
202                 int draw,
203                 int buttonpress,
204                 BC_Pixmap *pixmap,
205                 Auto* &auto_instance,
206                 int &rerender);
207         int do_plugin_autos(Track *track,
208                 int cursor_x,
209                 int cursor_y,
210                 int draw,
211                 int buttonpress,
212                 Plugin* &keyframe_plugin,
213                 KeyFrame* &keyframe_instance);
214
215
216         void calculate_viewport(Track *track,
217                 double &view_start,
218                 double &unit_start,
219                 double &view_end,
220                 double &unit_end,
221                 double &yscale,
222                 int &center_pixel,
223                 double &zoom_sample,
224                 double &zoom_units);
225
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();
240
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);
246         void draw_plugins();
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);
263         int arrow_mode();
264         int ibeam_mode();
265
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,
279                 int cursor_y,
280                 int button_press);
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();
293         int activate();
294         int deactivate();
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, ...);
322
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);
326
327         int get_title_h();
328
329 // Display hourglass if timer expired
330         void test_timer();
331 // get the relevant patchbay by traversing the panes
332 //      Patchbay* get_patchbay();
333
334         MWindow *mwindow;
335         MWindowGUI *gui;
336         TimelinePane *pane;
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;
348
349         int active;
350 // Currently in a drag scroll operation
351         int drag_scroll;
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;
356
357 // Temporary for picon drawing
358         VFrame *temp_picon;
359 // Timer for hourglass
360         Timer *resource_timer;
361         Timer *render_timer;
362
363 // Plugin toggle interfaces
364         ArrayList<PluginOn*> plugin_on_toggles;
365         ArrayList<PluginShow*> plugin_show_toggles;
366         ArrayList<PluginPresetEdit*> preset_edit_buttons;
367
368         static int auto_operations[];
369 // event handlers
370         void draw_paste_destination();
371
372         void draw_floatauto_ctrlpoint(int x, int y, int cp_x, int cp_y,
373                 int center_pixel, int zoom_track, int color);
374
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
378
379 // ====================================== cursor selection type
380
381         double selection_midpoint;        // division between current ends
382         int snapped;                    // drag handle snapping
383         EDL *speed_edl;                 // drag speed handle start edl
384 };
385
386 #endif