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