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