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