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