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