initial commit
[goodguy/history.git] / cinelerra-5.0 / cinelerra / localsession.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 #include "clip.h"
23 #include "bchash.h"
24 #include "edl.h"
25 #include "filexml.h"
26 #include "floatauto.h"
27 #include "localsession.h"
28
29
30
31
32
33 LocalSession::LocalSession(EDL *edl)
34 {
35         this->edl = edl;
36
37         selectionstart = selectionend = 0;
38         in_point = out_point = -1;
39         strcpy(folder, CLIP_FOLDER);
40         sprintf(clip_title, "Program");
41         strcpy(clip_notes, "Hello world");
42         clipboard_length = 0;
43         preview_start = preview_end = 0;
44         loop_playback = 0;
45         loop_start = 0;
46         loop_end = 0;
47         zoom_sample = 0;
48         zoom_y = 0;
49         zoom_track = 0;
50         x_pane = -1;
51         y_pane = -1;
52         
53         for(int i = 0; i < TOTAL_PANES; i++)
54         {
55                 view_start[i] = 0;
56                 track_start[i] = 0;
57         }
58         
59         automation_min = -10;
60         automation_max = 10;
61         floatauto_type = Auto::BEZIER;
62         red = green = blue = 0;
63 }
64
65 LocalSession::~LocalSession()
66 {
67 }
68
69 void LocalSession::copy_from(LocalSession *that)
70 {
71         strcpy(clip_title, that->clip_title);
72         strcpy(clip_notes, that->clip_notes);
73         strcpy(folder, that->folder);
74         in_point = that->in_point;
75         loop_playback = that->loop_playback;
76         loop_start = that->loop_start;
77         loop_end = that->loop_end;
78         out_point = that->out_point;
79         selectionend = that->selectionend;
80         selectionstart = that->selectionstart;
81         x_pane = that->x_pane;
82         y_pane = that->y_pane;
83
84         for(int i = 0; i < TOTAL_PANES; i++)
85         {
86                 view_start[i] = that->view_start[i];
87                 track_start[i] = that->track_start[i];
88         }
89         
90         zoom_sample = that->zoom_sample;
91         zoom_y = that->zoom_y;
92         zoom_track = that->zoom_track;
93         preview_start = that->preview_start;
94         preview_end = that->preview_end;
95         red = that->red;
96         green = that->green;
97         automation_min = that->automation_min;
98         automation_max = that->automation_max;
99         floatauto_type = that->floatauto_type;
100         blue = that->blue;
101 }
102
103 void LocalSession::save_xml(FileXML *file, double start)
104 {
105         file->tag.set_title("LOCALSESSION");
106
107         file->tag.set_property("IN_POINT", in_point - start);
108         file->tag.set_property("LOOP_PLAYBACK", loop_playback);
109         file->tag.set_property("LOOP_START", loop_start - start);
110         file->tag.set_property("LOOP_END", loop_end - start);
111         file->tag.set_property("OUT_POINT", out_point - start);
112         file->tag.set_property("SELECTION_START", selectionstart - start);
113         file->tag.set_property("SELECTION_END", selectionend - start);
114         file->tag.set_property("CLIP_TITLE", clip_title);
115         file->tag.set_property("CLIP_NOTES", clip_notes);
116         file->tag.set_property("FOLDER", folder);
117         file->tag.set_property("X_PANE", x_pane);
118         file->tag.set_property("Y_PANE", y_pane);
119
120         char string[BCTEXTLEN];
121         for(int i = 0; i < TOTAL_PANES; i++)
122         {
123                 sprintf(string, "TRACK_START%d", i);
124                 file->tag.set_property(string, track_start[i]);
125                 sprintf(string, "VIEW_START%d", i);
126                 file->tag.set_property(string, view_start[i]);
127         }
128
129         file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
130 //printf("EDLSession::save_session 1\n");
131         file->tag.set_property("ZOOMY", zoom_y);
132 //printf("EDLSession::save_session 1 %d\n", zoom_track);
133         file->tag.set_property("ZOOM_TRACK", zoom_track);
134
135         double preview_start = this->preview_start - start;
136         if(preview_start < 0) preview_start = 0;
137         double preview_end = this->preview_end - start;
138         if(preview_end < 0) preview_end = 0;
139         
140         file->tag.set_property("PREVIEW_START", preview_start);
141         file->tag.set_property("PREVIEW_END", preview_end);
142
143         file->tag.set_property("RED", red);
144         file->tag.set_property("GREEN", green);
145         file->tag.set_property("BLUE", blue);
146         file->tag.set_property("AUTOMATION_MIN", automation_min);
147         file->tag.set_property("AUTOMATION_MAX", automation_max);
148         file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
149         file->append_tag();
150         file->append_newline();
151         file->append_newline();
152 }
153
154 void LocalSession::synchronize_params(LocalSession *that)
155 {
156         loop_playback = that->loop_playback;
157         loop_start = that->loop_start;
158         loop_end = that->loop_end;
159         preview_start = that->preview_start;
160         preview_end = that->preview_end;
161         red = that->red;
162         green = that->green;
163         blue = that->blue;
164 }
165
166
167 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
168 {
169         if(load_flags & LOAD_SESSION)
170         {
171 // moved to EDL::load_xml for paste to fill silence.
172 //              clipboard_length = 0;
173 // Overwritten by MWindow::load_filenames       
174                 file->tag.get_property("CLIP_TITLE", clip_title);
175                 file->tag.get_property("CLIP_NOTES", clip_notes);
176                 file->tag.get_property("FOLDER", folder);
177                 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
178                 loop_start = file->tag.get_property("LOOP_START", (double)0);
179                 loop_end = file->tag.get_property("LOOP_END", (double)0);
180                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
181                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
182                 x_pane = file->tag.get_property("X_PANE", -1);
183                 y_pane = file->tag.get_property("Y_PANE", -1);
184
185
186                 char string[BCTEXTLEN];
187                 for(int i = 0; i < TOTAL_PANES; i++)
188                 {
189                         sprintf(string, "TRACK_START%d", i);
190                         track_start[i] = file->tag.get_property(string, track_start[i]);
191                         sprintf(string, "VIEW_START%d", i);
192                         view_start[i] = file->tag.get_property(string, view_start[i]);
193                 }
194
195                 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
196                 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
197                 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
198                 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
199                 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
200                 red = file->tag.get_property("RED", red);
201                 green = file->tag.get_property("GREEN", green);
202                 blue = file->tag.get_property("BLUE", blue);
203                 automation_min = file->tag.get_property("AUTOMATION_MIN", automation_min);
204                 automation_max = file->tag.get_property("AUTOMATION_MAX", automation_max);
205                 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
206         }
207
208
209 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
210 // expect - this is additionally important in keyboard-only editing in viewer window
211         if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
212         {
213                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
214                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
215         }
216
217
218
219         if(load_flags & LOAD_TIMEBAR)
220         {
221                 in_point = file->tag.get_property("IN_POINT", (double)-1);
222                 out_point = file->tag.get_property("OUT_POINT", (double)-1);
223         }
224 }
225
226 void LocalSession::boundaries()
227 {
228         zoom_sample = MAX(1, zoom_sample);
229 }
230
231 int LocalSession::load_defaults(BC_Hash *defaults)
232 {
233         loop_playback = defaults->get("LOOP_PLAYBACK", 0);
234         loop_start = defaults->get("LOOP_START", (double)0);
235         loop_end = defaults->get("LOOP_END", (double)0);
236         selectionstart = defaults->get("SELECTIONSTART", selectionstart);
237         selectionend = defaults->get("SELECTIONEND", selectionend);
238 //      track_start = defaults->get("TRACK_START", 0);
239 //      view_start = defaults->get("VIEW_START", 0);
240         zoom_sample = defaults->get("ZOOM_SAMPLE", 1);
241         zoom_y = defaults->get("ZOOMY", 64);
242         zoom_track = defaults->get("ZOOM_TRACK", 64);
243         red = defaults->get("RED", 0.0);
244         green = defaults->get("GREEN", 0.0);
245         blue = defaults->get("BLUE", 0.0);
246         automation_min = defaults->get("AUTOMATION_MIN", automation_min);
247         automation_max = defaults->get("AUTOMATION_MAX", automation_max);
248         floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
249         x_pane = defaults->get("X_PANE", x_pane);
250         y_pane = defaults->get("Y_PANE", y_pane);
251         return 0;
252 }
253
254 int LocalSession::save_defaults(BC_Hash *defaults)
255 {
256         defaults->update("LOOP_PLAYBACK", loop_playback);
257         defaults->update("LOOP_START", loop_start);
258         defaults->update("LOOP_END", loop_end);
259         defaults->update("SELECTIONSTART", selectionstart);
260         defaults->update("SELECTIONEND", selectionend);
261 //      defaults->update("TRACK_START", track_start);
262 //      defaults->update("VIEW_START", view_start);
263         defaults->update("ZOOM_SAMPLE", zoom_sample);
264         defaults->update("ZOOMY", zoom_y);
265         defaults->update("ZOOM_TRACK", zoom_track);
266         defaults->update("RED", red);
267         defaults->update("GREEN", green);
268         defaults->update("BLUE", blue);
269         defaults->update("AUTOMATION_MIN", automation_min);
270         defaults->update("AUTOMATION_MAX", automation_max);
271         defaults->update("FLOATAUTO_TYPE", floatauto_type);
272         defaults->update("X_PANE", x_pane);
273         defaults->update("Y_PANE", y_pane);
274         return 0;
275 }
276
277 void LocalSession::set_selectionstart(double value)
278 {
279         this->selectionstart = value;
280 }
281
282 void LocalSession::set_selectionend(double value)
283 {
284         this->selectionend = value;
285 }
286
287 void LocalSession::set_inpoint(double value)
288 {
289         in_point = value;
290 }
291
292 void LocalSession::set_outpoint(double value)
293 {
294         out_point = value;
295 }
296
297 void LocalSession::unset_inpoint()
298 {
299         in_point = -1;
300 }
301
302 void LocalSession::unset_outpoint()
303 {
304         out_point = -1;
305 }
306
307
308
309 double LocalSession::get_selectionstart(int highlight_only)
310 {
311         if(highlight_only || !EQUIV(selectionstart, selectionend))
312                 return selectionstart;
313
314         if(in_point >= 0)
315                 return in_point;
316         else
317         if(out_point >= 0)
318                 return out_point;
319         else
320                 return selectionstart;
321 }
322
323 double LocalSession::get_selectionend(int highlight_only)
324 {
325         if(highlight_only || !EQUIV(selectionstart, selectionend))
326                 return selectionend;
327
328         if(out_point >= 0)
329                 return out_point;
330         else
331         if(in_point >= 0)
332                 return in_point;
333         else
334                 return selectionend;
335 }
336
337 double LocalSession::get_inpoint()
338 {
339         return in_point;
340 }
341
342 double LocalSession::get_outpoint()
343 {
344         return out_point;
345 }
346
347 int LocalSession::inpoint_valid()
348 {
349         return in_point >= 0;
350 }
351
352 int LocalSession::outpoint_valid()
353 {
354         return out_point >= 0;
355 }
356
357
358
359