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  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #ifndef TRACKCANVAS_H
23 #define TRACKCANVAS_H
24
25 #include "asset.inc"
26 #include "auto.inc"
27 #include "autos.inc"
28 #include "bctimer.inc"
29 #include "edit.inc"
30 #include "edithandles.inc"
31 #include "edl.inc"
32 #include "floatauto.inc"
33 #include "floatautos.inc"
34 #include "intauto.inc"
35 #include "guicast.h"
36 #include "indexable.h"
37 #include "keyframe.inc"
38 #include "mwindow.inc"
39 #include "mwindowgui.inc"
40 #include "plugin.inc"
41 #include "pluginset.inc"
42 #include "plugintoggles.inc"
43 #include "resourcepixmap.inc"
44 #include "timelinepane.inc"
45 #include "track.inc"
46 #include "trackcanvas.inc"
47 #include "tracks.inc"
48 #include "transitionhandles.inc"
49 #include "keyframe.inc"
50
51 #include <stdarg.h>
52
53 class TrackCanvas : public BC_SubWindow
54 {
55 public:
56         TrackCanvas(MWindow *mwindow, MWindowGUI *gui);
57         TrackCanvas(MWindow *mwindow, TimelinePane *pane, int x, int y, int w, int h);
58         ~TrackCanvas();
59
60         void create_objects();
61         void resize_event();
62         int drag_start_event();
63         int cursor_leave_event();
64         int keypress_event();
65
66 // *** CONTEXT_HELP ***
67         int help_transitions(int cursor_x, int cursor_y);
68         int help_transition_handles(int cursor_x, int cursor_y);
69         int help_keyframes(int cursor_x, int cursor_y);
70         int help_edit_handles(int cursor_x, int cursor_y);
71         int help_plugin_handles(int cursor_x, int cursor_y);
72         int help_plugins(int cursor_x, int cursor_y);
73         int help_plugin_autos(Track *track, int cursor_x, int cursor_y);
74         int help_autos(Track *track, Autos *autos, int cursor_x, int cursor_y, BC_Pixmap *pixmap);
75         int help_float_autos(Track *track, Autos *autos, int cursor_x, int cursor_y, int autogrouptype);
76         int help_int_autos(Track *track, Autos *autos, int cursor_x, int cursor_y);
77
78         void draw_resources(int mode = 0,
79                 int indexes_only = 0,     // Redraw only certain audio resources with indexes
80                 Indexable *indexable = 0);
81         void draw_highlight_rectangle(int x, int y, int w, int h);
82         void draw_highlight_insertion(int x, int y, int w, int h);
83         void draw_playback_cursor();
84         void draw_highlighting();
85         void draw_keyframe_reticle();
86         int draw_hairline(Auto *auto_keyframe, int color, int show);
87         void draw_speed_highlight();
88         void draw_speed_track(Track *track);
89
90 // User can either call draw or draw_overlays to copy a fresh
91 // canvas and just draw the overlays over it
92         void draw_overlays();
93         void update_handles();
94 // Convert edit coords to transition coords
95         void get_transition_coords(Edit *edit,
96                 int64_t &x, int64_t &y, int64_t &w, int64_t &h);
97         void get_handle_coords(Edit *edit,
98                 int64_t &x,
99                 int64_t &y,
100                 int64_t &w,
101                 int64_t &h,
102                 int side);
103         int get_drag_values(float *percentage,
104                 int64_t *position,
105                 int do_clamp,
106                 int cursor_x,
107                 int cursor_y,
108                 Auto *current);
109         void draw_title(Edit *edit,
110                 int64_t edit_x,
111                 int64_t edit_y,
112                 int64_t edit_w,
113                 int64_t edit_h);
114         void draw_automation();
115         void draw_hard_edges();
116         void draw_inout_points();
117         void draw_auto(Auto *current, int x, int y,
118                 int center_pixel, int data_h);
119         void draw_floatauto(FloatAuto *current,
120                 int x_offset, int center_pixel, int data_h, int color,
121                 double unit_start, double zoom_units, double yscale,
122                 int autogrouptype);
123         int test_auto(Auto *current, int x, int y,
124                 int center_pixel, int data_h,
125                 int cursor_x, int cursor_y, int buttonpress);
126         int test_floatauto(FloatAuto *current, int buttonpress,
127                 int center_pixel, int data_h, int cursor_x, int cursor_y,
128                 double unit_start, double zoom_units, double yscale,
129                 int autogrouptype);
130         void draw_floatline(int center_pixel,
131                 FloatAuto *previous,
132                 FloatAuto *current,
133                 FloatAutos *autos,
134                 double unit_start,
135                 double zoom_units,
136                 double yscale,
137                 int ax,
138                 int ay,
139                 int ax2,
140                 int ay2,
141                 int color,
142                 int autogrouptype);
143         int test_floatline(int center_pixel,
144                 FloatAutos *autos,
145                 double unit_start,
146                 double zoom_units,
147                 double yscale,
148                 int x1,
149                 int x2,
150                 int cursor_x,
151                 int cursor_y,
152                 int buttonpress,
153                 int autogrouptype);
154         void draw_toggleline(int center_pixel,
155                 int ax,
156                 int ay,
157                 int ax2,
158                 int ay2);
159         int test_toggleline(Autos *autos,
160                 int center_pixel,
161                 int x1,
162                 int y1,
163                 int x2,
164                 int y2,
165                 int cursor_x,
166                 int cursor_y,
167                 int buttonpress);
168         int do_keyframes(int cursor_x,
169                 int cursor_y,
170                 int draw,
171                 int buttonpress,
172                 int &new_cursor,
173                 int &update_cursor,
174                 int &rerender);
175
176         int do_float_autos(Track *track,
177                 Autos *autos,
178                 int cursor_x,
179                 int cursor_y,
180                 int draw,
181                 int buttonpress,
182                 int x_offset,
183                 int y_offset,
184                 int color,
185                 Auto* &auto_instance,
186                 int autogrouptype);
187         int do_int_autos(Track *track,
188                 Autos *autos,
189                 int cursor_x,
190                 int cursor_y,
191                 int draw,
192                 int buttonpress,
193                 int x_offset,
194                 int y_offset,
195                 int color,
196                 Auto * &auto_instance);
197         int do_autos(Track *track,
198                 Autos *autos,
199                 int cursor_x,
200                 int cursor_y,
201                 int draw,
202                 int buttonpress,
203                 BC_Pixmap *pixmap,
204                 Auto* &auto_instance,
205                 int &rerender);
206         int do_plugin_autos(Track *track,
207                 int cursor_x,
208                 int cursor_y,
209                 int draw,
210                 int buttonpress,
211                 Plugin* &keyframe_plugin,
212                 KeyFrame* &keyframe_instance);
213
214
215         void calculate_viewport(Track *track,
216                 double &view_start,
217                 double &unit_start,
218                 double &view_end,
219                 double &unit_end,
220                 double &yscale,
221                 int &center_pixel,
222                 double &zoom_sample,
223                 double &zoom_units);
224
225 // Convert percentage position inside track to value.
226 // if is_toggle is 1, the result is either 0 or 1.
227 // if reference is nonzero and a FloatAuto,
228 //     the result is made relative to the value in reference.
229         float percentage_to_value(float percentage,
230                 int is_toggle, Auto *reference, int autogrouptype);
231 // Get x and y of a FloatAuto relative to center_pixel
232         void calculate_auto_position(int edge, double *x, double *y,
233                 double *in_x, double *in_y, double *out_x, double *out_y,
234                 Auto *current, double unit_start, double zoom_units,
235                 double yscale, int autogrouptype);
236         void fill_ganged_autos(int gang, float change, Track *skip, FloatAuto *fauto);
237         void update_ganged_autos(float change, Track *skip, FloatAuto *fauto);
238         void clear_ganged_autos();
239
240         void draw_brender_range();
241         void draw_loop_points();
242         void draw_transitions();
243         void draw_drag_handle();
244         void draw_selected_edits(EDL *edl, int dx, int dy, int color0, int color1);
245         void draw_plugins();
246         void refresh_plugintoggles();
247         void update_edit_handles(Edit *edit, int64_t edit_x, int64_t edit_y, int64_t edit_w, int64_t edit_h);
248         void update_transitions();
249         void update_keyframe_handles(Track *track);
250 // Draw everything to synchronize with the view.
251         void draw(int mode, int hide_cursor);
252 // Draw resources during index building
253         void draw_indexes(Indexable *indexable);
254 // Get location of edit on screen without boundary checking
255         void edit_dimensions(Edit *edit, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
256         void track_dimensions(Track *track, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
257         void plugin_dimensions(Plugin *plugin, int64_t &x, int64_t &y, int64_t &w, int64_t &h);
258         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);
259         ResourcePixmap* create_pixmap(Edit *edit, int64_t edit_x, int64_t pixmap_x, int64_t pixmap_w, int64_t pixmap_h);
260         void update_cursor(int flush);
261         void draw_selected(int x, int y, int w, int h);
262         int arrow_mode();
263         int ibeam_mode();
264
265 // Get edit and handle the cursor is over
266         int do_edit_handles(int cursor_x, int cursor_y, int button_press,
267                 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor);
268 // Get plugin and handle the cursor if over
269         int do_plugin_handles(int cursor_x, int cursor_y, int button_press,
270                 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor);
271         int do_transition_handles(int cursor_x, int cursor_y, int button_press,
272                 int &rerender, int &update_overlay, int &new_cursor, int &update_cursor);
273         int drag_transition_handle(double position);
274 // Get edit the cursor is over
275         int do_edits(int cursor_x, int cursor_y, int button_press,
276                 int drag_start, int &redraw, int &rerender, int &new_cursor, int &update_cursor);
277         int do_tracks(int cursor_x,
278                 int cursor_y,
279                 int button_press);
280         int test_track_group(EDL *group, Track *first_track, double &pos);
281         int edit_intersects(Track *track, Edit *src_edit, double &pos);
282         int test_resources(int cursor_x, int cursor_y);
283         int do_plugins(int cursor_x, int cursor_y, int drag_start, int button_press,
284                 int &redraw, int &rerender);
285         int do_transitions(int cursor_x, int cursor_y, int button_press,
286                 int &new_cursor, int &update_cursor);
287         void draw_cropped_line(int x1, int y1, int x2, int y2, int min_y, int max_y);
288         int button_press_event();
289         int button_release_event();
290         int cursor_update(int in_motion);
291         int cursor_motion_event();
292         int activate();
293         int deactivate();
294         int repeat_event(int64_t duration);
295         void start_dragscroll();
296         void stop_dragscroll();
297         int start_selection(double position);
298         int drag_motion_event();
299         int drag_stop_event();
300         int drag_motion(Track **over_track, Edit **over_edit,
301                 PluginSet **over_pluginset, Plugin **over_plugin);
302         int drag_cursor_motion(int cursor_x, int cursor_y,
303                 Track **over_track, Edit **over_edit,
304                 PluginSet **over_pluginset, Plugin **over_plugin);
305         int drag_stop(int *redraw);
306         int64_t drop_edit_position (int *is_insertion, Edit *moved_edit, int64_t moved_edit_length);
307         int64_t drop_plugin_position(PluginSet *plugin_set, Plugin *moved_plugin);
308         void end_edithandle_selection();
309         void end_pluginhandle_selection();
310         void end_transnhandle_selection();
311 // Number of seconds spanned by the trackcanvas
312         double time_visible();
313         void update_drag_handle();
314         int update_drag_edit();
315         int render_handle_frame(EDL *edl, int64_t pos, int mode);
316         int update_drag_floatauto(int cursor_x, int cursor_y);
317         int update_drag_toggleauto(int cursor_x, int cursor_y);
318         int update_drag_auto(int cursor_x, int cursor_y);
319         int update_drag_pluginauto(int cursor_x, int cursor_y);
320         void show_message(Auto *current, int box_color, const char *fmt, ...);
321
322 // Update status bar to reflect drag operation
323         void update_drag_caption();
324         void drag_edit_select(Edit *over_edit, int select, int draw);
325
326         int get_title_h();
327
328 // Display hourglass if timer expired
329         void test_timer();
330 // get the relevant patchbay by traversing the panes
331 //      Patchbay* get_patchbay();
332
333         MWindow *mwindow;
334         MWindowGUI *gui;
335         TimelinePane *pane;
336 // Allows overlays to get redrawn without redrawing the resources
337         BC_Pixmap *background_pixmap;
338         BC_Pixmap *transition_pixmap;
339         EditHandles *edit_handles;
340 //      TransitionHandles *transition_handles;
341         BC_Pixmap *keyframe_pixmap;
342         BC_Pixmap *camerakeyframe_pixmap;
343         BC_Pixmap *modekeyframe_pixmap;
344         BC_Pixmap *pankeyframe_pixmap;
345         BC_Pixmap *projectorkeyframe_pixmap;
346         BC_Pixmap *maskkeyframe_pixmap;
347
348         int active;
349 // Currently in a drag scroll operation
350         int drag_scroll;
351 // Don't stop hourglass if it was never started before the operation.
352         int hourglass_enabled;
353 // position used by timebar, when the timebar needs to draw a highlight
354         double timebar_position;
355
356 // Temporary for picon drawing
357         VFrame *temp_picon;
358 // Timer for hourglass
359         Timer *resource_timer;
360         Timer *render_timer;
361
362 // Plugin toggle interfaces
363         ArrayList<PluginOn*> plugin_on_toggles;
364         ArrayList<PluginShow*> plugin_show_toggles;
365         ArrayList<PluginPresetEdit*> preset_edit_buttons;
366
367         static int auto_operations[];
368 // event handlers
369         void draw_paste_destination();
370
371         void draw_floatauto_ctrlpoint(int x, int y, int cp_x, int cp_y,
372                 int center_pixel, int zoom_track, int color);
373
374         float value_to_percentage(float auto_value, int autogrouptype);
375         // transforms automation value into current display coords
376         // dependant on current automation display range for given kind of automation
377
378 // ====================================== cursor selection type
379
380         double selection_midpoint;        // division between current ends
381         int snapped;                    // drag handle snapping
382         EDL *speed_edl;                 // drag speed handle start edl
383 };
384
385 #endif