add missing GPL information in guicast program files
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / strack.C
1 #include "clip.h"
2 #include "edit.h"
3 #include "edits.h"
4 #include "edl.h"
5 #include "edlsession.h"
6 #include "datatype.h"
7 #include "filexml.h"
8 #include "localsession.h"
9 #include "mainsession.h"
10 #include "strack.h"
11 #include "theme.h"
12 #include "trackcanvas.h"
13 #include "tracks.h"
14
15 #include <string.h>
16
17 STrack::STrack(EDL *edl, Tracks *tracks)
18  : Track(edl, tracks)
19 {
20         data_type = TRACK_SUBTITLE;
21         data_h = edl->local_session->zoom_atrack;
22 }
23
24 STrack::~STrack()
25 {
26 }
27
28
29 // Used by PlaybackEngine
30 void STrack::synchronize_params(Track *track)
31 {
32         Track::synchronize_params(track);
33 }
34
35 int STrack::copy_settings(Track *track)
36 {
37         Track::copy_settings(track);
38         return 0;
39 }
40
41 int STrack::load_defaults(BC_Hash *defaults)
42 {
43         Track::load_defaults(defaults);
44         return 0;
45 }
46
47 void STrack::set_default_title()
48 {
49         Track *current = ListItem<Track>::list->first;
50         int i;
51         for(i = 0; current; current = NEXT)
52         {
53                 if(current->data_type == TRACK_SUBTITLE) i++;
54         }
55         sprintf(title, _("Subttl %d"), i);
56 }
57
58 void STrack::create_objects()
59 {
60         Track::create_objects();
61         automation = new SAutomation(edl, this);
62         automation->create_objects();
63         edits = new SEdits(edl, this);
64 }
65
66 int STrack::vertical_span(Theme *theme)
67 {
68         int track_h = Track::vertical_span(theme);
69         int patch_h = theme->title_h;
70         if( expand_view )
71                 patch_h += theme->play_h;
72         return MAX(track_h, patch_h);
73 }
74
75
76 int64_t STrack::to_units(double position, int round)
77 {
78         if(round)
79         {
80                 return Units::round(position * edl->session->frame_rate);
81         }
82         else
83         {
84 // Kludge for rounding errors, just on a smaller scale than formal rounding
85                 position *= edl->session->frame_rate;
86                 return Units::to_int64(position);
87         }
88 }
89
90 double STrack::to_doubleunits(double position)
91 {
92         return position * edl->session->frame_rate;
93 }
94
95
96 double STrack::from_units(int64_t position)
97 {
98         return (double)position / edl->session->frame_rate;
99 }
100
101
102
103
104 int STrack::identical(int64_t sample1, int64_t sample2)
105 {
106 // Units of frames
107         if(labs(sample1 - sample2) <= 1) return 1; else return 0;
108 }
109
110 int STrack::save_header(FileXML *file)
111 {
112         file->tag.set_property("TYPE", "SUBTTL");
113         return 0;
114 }
115
116 int STrack::save_derived(FileXML *file)
117 {
118         file->append_newline();
119         return 0;
120 }
121
122 int STrack::load_header(FileXML *file, uint32_t load_flags)
123 {
124         return 0;
125 }
126
127 int STrack::load_derived(FileXML *file, uint32_t load_flags)
128 {
129         return 0;
130 }
131
132
133 int STrack::get_dimensions(int pane_number,
134         double &view_start,
135         double &view_units,
136         double &zoom_units)
137 {
138         view_start = edl->local_session->view_start[pane_number] * edl->session->frame_rate;
139         view_units = 0;
140 //      view_units = Units::toframes(tracks->view_samples(), mwindow->session->sample_rate, mwindow->session->frame_rate);
141         zoom_units = edl->local_session->zoom_sample / edl->session->sample_rate * edl->session->frame_rate;
142         return 0;
143 }
144
145 int64_t STrack::length()
146 {
147         return edits->length();
148 }
149
150 SEdit::SEdit(EDL *edl, Edits *edits)
151  : Edit(edl, edits)
152 {
153         text[0] = 0;
154 }
155
156 SEdit::~SEdit()
157 {
158 }
159
160
161
162 void SEdit::
163 copy_from(Edit *edit)
164 {
165         Edit::copy_from(edit);
166         SEdit *sedit = (SEdit*)edit;
167         strcpy(text,sedit->text);
168 }
169
170 int SEdit::load_properties_derived(FileXML *xml)
171 {
172         xml->tag.get_property("TEXT", text);
173         return 0;
174 }
175
176 int SEdit::copy_properties_derived(FileXML *xml, int64_t length_in_selection)
177 {
178         xml->tag.set_property("TEXT", text);
179         return 0;
180 }
181
182
183 int SEdit::dump_derived()
184 {
185         return 0;
186 }
187
188
189 int64_t SEdit::get_source_end(int64_t default_)
190 {
191         return default_;   // Infinity
192 }
193