Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / strack.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2016-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21 #include "clip.h"
22 #include "edit.h"
23 #include "edits.h"
24 #include "edl.h"
25 #include "edlsession.h"
26 #include "datatype.h"
27 #include "filexml.h"
28 #include "localsession.h"
29 #include "mainsession.h"
30 #include "strack.h"
31 #include "theme.h"
32 #include "trackcanvas.h"
33 #include "tracks.h"
34
35 #include <string.h>
36
37 STrack::STrack(EDL *edl, Tracks *tracks)
38  : Track(edl, tracks)
39 {
40         data_type = TRACK_SUBTITLE;
41         data_h = edl->local_session->zoom_atrack;
42 }
43
44 STrack::~STrack()
45 {
46 }
47
48
49 // Used by PlaybackEngine
50 void STrack::synchronize_params(Track *track)
51 {
52         Track::synchronize_params(track);
53 }
54
55 int STrack::copy_settings(Track *track)
56 {
57         Track::copy_settings(track);
58         return 0;
59 }
60
61 int STrack::load_defaults(BC_Hash *defaults)
62 {
63         Track::load_defaults(defaults);
64         return 0;
65 }
66
67 void STrack::set_default_title()
68 {
69         Track *current = ListItem<Track>::list->first;
70         int i;
71         for(i = 0; current; current = NEXT)
72         {
73                 if(current->data_type == TRACK_SUBTITLE) i++;
74         }
75         sprintf(title, _("Subttl %d"), i);
76 }
77
78 void STrack::create_objects()
79 {
80         Track::create_objects();
81         automation = new SAutomation(edl, this);
82         automation->create_objects();
83         edits = new SEdits(edl, this);
84 }
85
86 int STrack::vertical_span(Theme *theme)
87 {
88         int track_h = Track::vertical_span(theme);
89         int patch_h = theme->title_h;
90         if( expand_view )
91                 patch_h += theme->play_h;
92         return MAX(track_h, patch_h);
93 }
94
95
96 int64_t STrack::to_units(double position, int round)
97 {
98         if(round)
99         {
100                 return Units::round(position * edl->session->frame_rate);
101         }
102         else
103         {
104 // Kludge for rounding errors, just on a smaller scale than formal rounding
105                 position *= edl->session->frame_rate;
106                 return Units::to_int64(position);
107         }
108 }
109
110 double STrack::to_doubleunits(double position)
111 {
112         return position * edl->session->frame_rate;
113 }
114
115
116 double STrack::from_units(int64_t position)
117 {
118         return (double)position / edl->session->frame_rate;
119 }
120
121
122
123
124 int STrack::identical(int64_t sample1, int64_t sample2)
125 {
126 // Units of frames
127         if(labs(sample1 - sample2) <= 1) return 1; else return 0;
128 }
129
130 int STrack::save_header(FileXML *file)
131 {
132         file->tag.set_property("TYPE", "SUBTTL");
133         return 0;
134 }
135
136 int STrack::save_derived(FileXML *file)
137 {
138         file->append_newline();
139         return 0;
140 }
141
142 int STrack::load_header(FileXML *file, uint32_t load_flags)
143 {
144         return 0;
145 }
146
147 int STrack::load_derived(FileXML *file, uint32_t load_flags)
148 {
149         return 0;
150 }
151
152
153 int STrack::get_dimensions(int pane_number,
154         double &view_start,
155         double &view_units,
156         double &zoom_units)
157 {
158         view_start = edl->local_session->view_start[pane_number] * edl->session->frame_rate;
159         view_units = 0;
160 //      view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
161         zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
162         return 0;
163 }
164
165 int64_t STrack::length()
166 {
167         return edits->length();
168 }
169
170 SEdit::SEdit(EDL *edl, Edits *edits)
171  : Edit(edl, edits)
172 {
173         text[0] = 0;
174 }
175
176 SEdit::~SEdit()
177 {
178 }
179
180
181
182 void SEdit::
183 copy_from(Edit *edit)
184 {
185         Edit::copy_from(edit);
186         SEdit *sedit = (SEdit*)edit;
187         strcpy(text,sedit->text);
188 }
189
190 int SEdit::load_properties_derived(FileXML *xml)
191 {
192         xml->tag.get_property("TEXT", text);
193         return 0;
194 }
195
196 int SEdit::copy_properties_derived(FileXML *xml, int64_t length_in_selection)
197 {
198         xml->tag.set_property("TEXT", text);
199         return 0;
200 }
201
202
203 int SEdit::dump_derived()
204 {
205         return 0;
206 }
207
208
209 int64_t SEdit::get_source_end(int64_t default_)
210 {
211         return default_;   // Infinity
212 }
213