initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / track.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2010 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 TRACK_H
23 #define TRACK_H
24
25 #include <stdio.h>
26 #include <stdint.h>
27
28 #include "arraylist.h"
29 #include "asset.inc"
30 #include "autoconf.inc"
31 #include "automation.inc"
32 #include "datatype.h"
33 #include "bchash.inc"
34 #include "edit.inc"
35 #include "edits.inc"
36 #include "edl.inc"
37 #include "filexml.inc"
38 #include "floatautos.inc"
39 #include "guicast.h"
40 #include "indexable.inc"
41 #include "keyframe.inc"
42 #include "linklist.h"
43 #include "module.inc"
44 #include "patch.inc"
45 #include "plugin.inc"
46 #include "pluginset.inc"
47 #include "sharedlocation.inc"
48 #include "theme.inc"
49 #include "intautos.inc"
50 #include "trackcanvas.inc"
51 #include "tracks.inc"
52 #include "transition.inc"
53
54 // UNITS ARE SAMPLES FOR ALL
55
56 class Track : public ListItem<Track>
57 {
58 public:
59         Track(EDL *edl, Tracks *tracks);
60         Track();
61         virtual ~Track();
62
63         void create_objects();
64         int get_id();
65         virtual int load_defaults(BC_Hash *defaults);
66         int load(FileXML *file, int track_offset, uint32_t load_flags);
67         virtual int save_header(FileXML *file) { return 0; };
68         virtual int save_derived(FileXML *file) { return 0; };
69         virtual int load_header(FileXML *file, uint32_t load_flags) { return 0; };
70         virtual int load_derived(FileXML *file, uint32_t load_flags) { return 0; };
71         void equivalent_output(Track *track, double *result);
72
73         virtual void copy_from(Track *track);
74         Track& operator=(Track& track);
75         virtual PluginSet* new_plugins() { return 0; };
76 // Synchronize playback numbers
77         virtual void synchronize_params(Track *track);
78
79 // Get number of pixels to display
80         virtual int vertical_span(Theme *theme);
81         int64_t horizontal_span();
82         void resample(double old_rate, double new_rate);
83
84 // Speed curve in use
85         int has_speed();
86 // Get length of track in seconds
87         double get_length();
88 // Get dimensions of source for convenience functions
89         void get_source_dimensions(double position, int &w, int &h);
90
91 // Editing
92         void insert_asset(Asset *asset, 
93                 EDL *nested_edl,
94                 double length, 
95                 double position, 
96                 int track_number);
97         Plugin* insert_effect(const char *title, 
98                 SharedLocation *shared_location, 
99                 KeyFrame *keyframe,
100                 PluginSet *plugin_set,
101                 double start,
102                 double length,
103                 int plugin_type);
104         void insert_plugin_set(Track *track, 
105                 int64_t position,
106                 int64_t min_length,
107                 int edit_autos);
108         void detach_effect(Plugin *plugin);
109 // Insert a track from another EDL
110         void insert_track(Track *track, 
111                 double position, 
112                 int replace_default,
113                 int edit_plugins,
114                 int edit_autos,
115 // Pad pasted sections to a minimum of this length.
116                 double edl_length);
117         void shuffle_edits(double start, double end, int first_track);
118         void align_edits(double start, 
119                 double end, 
120                 ArrayList<double> *times);
121 // Optimize editing
122         void optimize();
123         int is_muted(int64_t position, int direction);  // Test muting status
124
125         void move_plugins_up(PluginSet *plugin_set);
126         void move_plugins_down(PluginSet *plugin_set);
127         void remove_pluginset(PluginSet *plugin_set);
128         void remove_asset(Indexable *asset);
129
130 // Used for determining a selection for editing so leave as int.
131 // converts the selection to SAMPLES OR FRAMES and stores in value
132         virtual int64_t to_units(double position, int round);
133 // For drawing
134         virtual double to_doubleunits(double position);
135         virtual double from_units(int64_t position);
136
137
138
139 // Positions are identical for handle modifications
140     virtual int identical(int64_t sample1, int64_t sample2) { return 0; };
141
142 // Get the plugin belonging to the set.
143         Plugin* get_current_plugin(double position, 
144                 int plugin_set, 
145                 int direction, 
146                 int convert_units,
147                 int use_nudge);
148         Plugin* get_current_transition(double position, 
149                 int direction, 
150                 int convert_units,
151                 int use_nudge);
152
153 // detach shared effects referencing module
154         void detach_shared_effects(int module); 
155
156
157 // Called by playable tracks to test for playable server.
158 // Descends the plugin tree without creating a virtual console.
159 // Used by PlayableTracks::is_playable.
160         int is_synthesis(int64_t position, 
161                 int direction);
162
163 // Used by PlayableTracks::is_playable
164 // Returns 1 if the track is in the output boundaries.
165         virtual int is_playable(int64_t position, 
166                 int direction);
167
168 // Test direct copy conditions common to all the rendering routines
169         virtual int direct_copy_possible(int64_t start, int direction, int use_nudge);
170
171 // Used by PlayableTracks::is_playable
172         int plugin_used(int64_t position, int64_t direction);
173
174
175
176
177
178         virtual int copy_settings(Track *track);
179         void shift_keyframes(int64_t position, int64_t length);
180         void shift_effects(int64_t position, int64_t length, int edit_autos);
181         void change_plugins(SharedLocation &old_location, 
182                 SharedLocation &new_location, 
183                 int do_swap);
184         void change_modules(int old_location, 
185                 int new_location, 
186                 int do_swap);
187         int plugin_exists(Plugin *plugin);
188
189         EDL *edl;
190         Tracks *tracks;
191
192         Edits *edits;
193 // Plugin set uses key frames for automation
194         ArrayList<PluginSet*> plugin_set;
195         Automation *automation;
196
197 // Vertical offset from top of timeline
198         int y_pixel;
199         int expand_view;
200         int draw;
201 // There is some debate on whether to expand gang from faders to
202 // dragging operations.  This would allow every edit in a column to get dragged
203 // simultaneously.
204         int gang;
205         char title[BCTEXTLEN];
206         int play;
207         int record;
208 // Nudge in track units.  Positive shifts track earlier in time.  This way
209 // the position variables only need to add the nudge.
210         int64_t nudge;
211 // TRACK_AUDIO or TRACK_VIDEO
212         int data_type;     
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232         int load_automation(FileXML *file);
233         int load_edits(FileXML *file);
234
235         virtual int change_channels(int oldchannels, int newchannels) { return 0; };
236         virtual int dump(FILE *fp);
237
238
239
240 // ===================================== editing
241         int copy(double start, 
242                 double end, 
243                 FileXML *file, 
244                 const char *output_path = "");
245         int copy_assets(double start, 
246                 double end, 
247                 ArrayList<Asset*> *asset_list);
248         virtual int copy_derived(int64_t start, int64_t end, FileXML *file) { return 0; };
249         virtual int paste_derived(int64_t start, int64_t end, int64_t total_length, FileXML *file, int &current_channel) { return 0; };
250         int clear(double start, 
251                 double end, 
252                 int edit_edits,
253                 int edit_labels,
254                 int clear_plugins, 
255                 int edit_autos,
256                 int convert_units,
257                 Edits *trim_edits);
258 // Returns the point to restart background rendering at.
259 // -1 means nothing changed.
260         void clear_automation(double selectionstart, 
261                 double selectionend, 
262                 int shift_autos   /* = 1 */,
263                 int default_only  /* = 0 */);
264         void set_automation_mode(double selectionstart, 
265                 double selectionend,
266                 int mode);
267         virtual int clear_automation_derived(AutoConf *auto_conf, 
268                 double selectionstart, 
269                 double selectionend, 
270                 int shift_autos = 1) { return 0; };
271         virtual int clear_derived(double start, 
272                 double end) { return 0; };
273
274         int copy_automation(double selectionstart, 
275                 double selectionend, 
276                 FileXML *file,
277                 int default_only,
278                 int active_only);
279         virtual int copy_automation_derived(AutoConf *auto_conf, 
280                 double selectionstart, 
281                 double selectionend, 
282                 FileXML *file) { return 0; };
283         int paste_automation(double selectionstart, 
284                 double total_length, 
285                 double frame_rate,
286                 int64_t sample_rate,
287                 FileXML *file,
288                 int default_only,
289                 int active_only);
290         virtual int paste_automation_derived(double selectionstart, 
291                 double selectionend, 
292                 double total_length, 
293                 FileXML *file, 
294                 int shift_autos, 
295                 int &current_pan) { return 0; };
296         int paste_auto_silence(double start, double end);
297         virtual int paste_auto_silence_derived(int64_t start, int64_t end) { return 0; };
298         int scale_time(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end);
299         virtual int scale_time_derived(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end) { return 0; };
300         int purge_asset(Asset *asset);
301         int asset_used(Asset *asset);
302         int clear_handle(double start, 
303                 double end, 
304                 int clear_labels,
305                 int clear_plugins, 
306                 int edit_autos,
307                 double &distance);
308         int paste_silence(double start, double end, int edit_plugins, int edit_autos);
309         virtual int select_translation(int cursor_x, int cursor_y) { return 0; };  // select video coordinates for frame
310         virtual int update_translation(int cursor_x, int cursor_y, int shift_down) { return 0; };  // move video coordinates
311         int select_auto(AutoConf *auto_conf, int cursor_x, int cursor_y);
312         virtual int select_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y) { return 0; };
313         int move_auto(AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down);
314         virtual int move_auto_derived(float zoom_units, float view_start, AutoConf *auto_conf, int cursor_x, int cursor_y, int shift_down) { return 0; };
315         int release_auto();
316         virtual int release_auto_derived() { return 0; };
317 // Return whether automation would prevent direct frame copies.  Not fully implemented.
318         int automation_is_used(int64_t start, int64_t end);
319         virtual int automation_is_used_derived(int64_t start, int64_t end) { return 0; }
320
321         int popup_transition(int cursor_x, int cursor_y);
322
323 // Return 1 if the left handle was selected 2 if the right handle was selected 3 if the track isn't recordable
324         int modify_edithandles(double oldposition, 
325                 double newposition, 
326                 int currentend, 
327                 int handle_mode,
328                 int edit_labels,
329                 int edit_plugins,
330                 int edit_autos);
331         int modify_pluginhandles(double oldposition, 
332                 double newposition, 
333                 int currentend, 
334                 int handle_mode,
335                 int edit_labels,
336                 int edit_autos,
337                 Edits *trim_edits);
338         int select_edit(int cursor_x, 
339                 int cursor_y, 
340                 double &new_start, 
341                 double &new_end);
342         virtual int end_translation() { return 0; };
343         virtual int reset_translation(int64_t start, int64_t end) { return 0; };
344         int feather_edits(int64_t start, int64_t end, int64_t units);
345         int64_t get_feather(int64_t selectionstart, int64_t selectionend);
346
347
348 // Absolute number of this track
349         int number_of();           
350
351 // get_dimensions is used for getting drawing regions so use floats for partial frames
352 // get the display dimensions in SAMPLES OR FRAMES
353 //      virtual int get_dimensions(double &view_start, 
354 //              double &view_units, 
355 //              double &zoom_units) { return 0; };   
356 // Longest time from current_position in which nothing changes
357         int64_t edit_change_duration(int64_t input_position, 
358                 int64_t input_length, 
359                 int reverse, 
360                 int test_transitions,
361                 int use_nudge);
362         int64_t plugin_change_duration(int64_t input_position,
363                 int64_t input_length,
364                 int reverse,
365                 int use_nudge);
366 // Utility for edit_change_duration.
367         int need_edit(Edit *current, int test_transitions);
368 // If the edit under position is playable.
369 // Used by PlayableTracks::is_playable.
370         int playable_edit(int64_t position, int direction);
371
372 // ===================================== for handles, titles, etc
373
374         int64_t old_view_start;
375         int pixel;   // pixel position from top of track view
376 // Dimensions of this track if video
377         int track_w, track_h;
378
379
380
381
382 private:
383 // Identification of the track
384         int id;
385 };
386
387 #endif