Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / autos.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #ifndef AUTOS_H
24 #define AUTOS_H
25
26 #include <stdio.h>
27 #include <stdint.h>
28
29 // Base class for automation lists.
30 // Units are the native units for the track data type.
31
32 #include "auto.h"
33 #include "edl.inc"
34 #include "guicast.h"
35 #include "filexml.inc"
36 #include "track.inc"
37
38 #define AUTOS_VIRTUAL_HEIGHT 160
39
40 class Autos : public List<Auto>
41 {
42 public:
43         Autos(EDL *edl, Track *track);
44
45         virtual ~Autos();
46
47         void resample(double old_rate, double new_rate);
48
49         virtual void create_objects();
50         void equivalent_output(Autos *autos, int64_t startproject, int64_t *result);
51         void copy_from(Autos *autos);
52         virtual Auto* new_auto();
53 // Get existing auto on or before position.
54 // If use_default is true, return default_auto if none exists
55 // on or before position.
56 // Return 0 if none exists and use_default is false.
57 // If &current is nonzero it is used as a starting point for searching.
58         Auto* get_prev_auto(int64_t position, int direction, Auto* &current, int use_default = 1);
59         Auto* get_prev_auto(int direction, Auto* &current);
60         Auto* get_next_auto(int64_t position, int direction, Auto* &current, int use_default = 1);
61 // Determine if a keyframe exists before creating it.
62         int auto_exists_for_editing(double position);
63 // Returns auto at exact position, null if non-existent. ignores autokeyframming and align on frames
64         Auto* get_auto_at_position(double position = -1);
65         Auto* get_auto(int id);
66
67 // Get keyframe for editing with creation
68 // create: <0: always new keyframe, =0: no new keyframe, >0: auto keyframe
69         Auto* get_auto_for_editing(double position=-1, int create=1);
70
71 // Insert keyframe at the point if it doesn't exist
72 // Interpolate its value if possible
73         Auto* insert_auto(int64_t position, Auto *templ=0);
74         void insert_track(Autos *automation,
75                 int64_t start_unit,
76                 int64_t length_units,
77                 int replace_default);
78         virtual int load(FileXML *xml);
79         void remove_nonsequential(Auto *keyframe);
80         void optimize();
81
82 // Returns a type enumeration
83         int get_type();
84         int64_t get_length();
85         virtual void get_extents(float *min,
86                 float *max,
87                 int *coords_undefined,
88                 int64_t unit_start,
89                 int64_t unit_end);
90
91         EDL *edl;
92         Track *track;
93 // Default settings if no autos.
94 // Having a persistent keyframe created problems when files were loaded and
95 // we wanted to keep only 1 auto.
96 // Default auto has position 0 except in effects, where multiple default autos
97 // exist.
98         Auto *default_auto;
99
100         int autoidx;
101         int autogrouptype;
102         int type;
103         enum
104         {
105                 AUTOMATION_TYPE_FLOAT,
106                 AUTOMATION_TYPE_MASK,
107                 AUTOMATION_TYPE_INT,
108                 AUTOMATION_TYPE_PAN,
109                 AUTOMATION_TYPE_PLUGIN
110         };
111
112
113
114         virtual void dump(FILE *fp);
115
116
117
118
119
120
121         void clear_all();
122         int insert(int64_t start, int64_t end);
123         int paste_silence(int64_t start, int64_t end);
124 // Copy for keyframe clipboard & drag & drop
125 // default_only - only copy the default keyframe
126         int copy(int64_t start,
127                 int64_t end,
128                 FileXML *xml,
129                 int default_only,
130                 int active_only);
131 // Paste for keyframe clipboard & drag & drop
132 // default_only - only paste the default keyframe
133         void paste(int64_t start,
134                 int64_t length,
135                 double scale,
136                 FileXML *file,
137                 int default_only,
138                 int active_only);
139 // Stores the background rendering position in result
140         void clear(int64_t start,
141                 int64_t end,
142                 int shift_autos);
143         virtual void set_automation_mode(int64_t start, int64_t end, int mode);
144         int clear_auto(int64_t position);
145         int save(FileXML *xml);
146         virtual int slope_adjustment(int64_t ax, double slope);
147         int release_auto();
148         virtual int release_auto_derived() { return 0; }
149         Auto* append_auto();
150         int scale_time(float rate_scale, int scale_edits, int scale_autos, int64_t start, int64_t end);
151
152 // rendering utilities
153         int get_neighbors(int64_t start, int64_t end, Auto **before, Auto **after);
154 // 1 if automation doesn't change
155         virtual int automation_is_constant(int64_t start, int64_t end);
156         virtual double get_automation_constant(int64_t start, int64_t end);
157         int init_automation(int64_t &buffer_position,
158                                 int64_t &input_start,
159                                 int64_t &input_end,
160                                 int &automate,
161                                 double &constant,
162                                 int64_t input_position,
163                                 int64_t buffer_len,
164                                 Auto **before,
165                                 Auto **after,
166                                 int reverse);
167
168         int init_slope(Auto **current_auto,
169                                 double &slope_start,
170                                 double &slope_value,
171                                 double &slope_position,
172                                 int64_t &input_start,
173                                 int64_t &input_end,
174                                 Auto **before,
175                                 Auto **after,
176                                 int reverse);
177
178         int get_slope(Auto **current_auto,
179                                 double &slope_start,
180                                 double &slope_end,
181                                 double &slope_value,
182                                 double &slope,
183                                 int64_t buffer_len,
184                                 int64_t buffer_position,
185                                 int reverse);
186
187         int advance_slope(Auto **current_auto,
188                                 double &slope_start,
189                                 double &slope_value,
190                                 double &slope_position,
191                                 int reverse);
192
193         Auto* autoof(int64_t position);   // return nearest auto equal to or after position
194                                                                                                   // 0 if after all autos
195         Auto* nearest_before(int64_t position);    // return nearest auto before or 0
196         Auto* nearest_after(int64_t position);     // return nearest auto after or 0
197 };
198
199 #endif