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