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