color coded keyframe curves, keyframe popups, cwin scrollbar fixes
[goodguy/history.git] / cinelerra-5.1 / 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 "automation.h"
23 #include "clip.h"
24 #include "bchash.h"
25 #include "edl.h"
26 #include "filexml.h"
27 #include "floatauto.h"
28 #include "language.h"
29 #include "localsession.h"
30
31
32 static const char *xml_autogrouptypes_titlesmax[] =
33 {
34         "AUTOGROUPTYPE_AUDIO_FADE_MAX",
35         "AUTOGROUPTYPE_VIDEO_FADE_MAX",
36         "AUTOGROUPTYPE_ZOOM_MAX",
37         "AUTOGROUPTYPE_SPEED_MAX",
38         "AUTOGROUPTYPE_X_MAX",
39         "AUTOGROUPTYPE_Y_MAX",
40         "AUTOGROUPTYPE_INT255_MAX"
41 };
42
43 static const char *xml_autogrouptypes_titlesmin[] =
44 {
45         "AUTOGROUPTYPE_AUDIO_FADE_MIN",
46         "AUTOGROUPTYPE_VIDEO_FADE_MIN",
47         "AUTOGROUPTYPE_ZOOM_MIN",
48         "AUTOGROUPTYPE_SPEED_MIN",
49         "AUTOGROUPTYPE_X_MIN",
50         "AUTOGROUPTYPE_Y_MIN",
51         "AUTOGROUPTYPE_INT255_MIN"
52 };
53
54
55 LocalSession::LocalSession(EDL *edl)
56 {
57         this->edl = edl;
58
59         selectionstart = selectionend = 0;
60         in_point = out_point = -1;
61         strcpy(folder, CLIP_FOLDER);
62         sprintf(clip_title, _("Program"));
63         strcpy(clip_notes, _("Hello world"));
64         clipboard_length = 0;
65         loop_playback = 0;
66         loop_start = loop_end = 0;
67         playback_start = -1;
68         playback_end = 0;
69         preview_start = preview_end = 0;
70         zoom_sample = DEFAULT_ZOOM_TIME;
71         zoom_y = 0;
72         zoom_track = 0;
73         x_pane = y_pane = -1;
74
75         for(int i = 0; i < TOTAL_PANES; i++) {
76                 view_start[i] = 0;
77                 track_start[i] = 0;
78         }
79
80         automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
81         automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
82
83         automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
84         automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
85
86         automation_mins[AUTOGROUPTYPE_ZOOM] = 0.005;
87         automation_maxs[AUTOGROUPTYPE_ZOOM] = 5.000;
88
89         automation_mins[AUTOGROUPTYPE_SPEED] = 0.005;
90         automation_maxs[AUTOGROUPTYPE_SPEED] = 5.000;
91
92         automation_mins[AUTOGROUPTYPE_X] = -100;
93         automation_maxs[AUTOGROUPTYPE_X] = 100;
94
95         automation_mins[AUTOGROUPTYPE_Y] = -100;
96         automation_maxs[AUTOGROUPTYPE_Y] = 100;
97
98         automation_mins[AUTOGROUPTYPE_INT255] = 0;
99         automation_maxs[AUTOGROUPTYPE_INT255] = 255;
100
101         zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
102
103         floatauto_type = FloatAuto::SMOOTH;
104
105         red = green = blue = 0;
106 }
107
108 LocalSession::~LocalSession()
109 {
110 }
111
112 void LocalSession::copy_from(LocalSession *that)
113 {
114         strcpy(clip_title, that->clip_title);
115         strcpy(clip_notes, that->clip_notes);
116         strcpy(folder, that->folder);
117         in_point = that->in_point;
118         loop_playback = that->loop_playback;
119         loop_start = that->loop_start;
120         loop_end = that->loop_end;
121         out_point = that->out_point;
122         selectionend = that->selectionend;
123         selectionstart = that->selectionstart;
124         x_pane = that->x_pane;
125         y_pane = that->y_pane;
126
127         for(int i = 0; i < TOTAL_PANES; i++)
128         {
129                 view_start[i] = that->view_start[i];
130                 track_start[i] = that->track_start[i];
131         }
132
133         zoom_sample = that->zoom_sample;
134         zoom_y = that->zoom_y;
135         zoom_track = that->zoom_track;
136         preview_start = that->preview_start;
137         preview_end = that->preview_end;
138         red = that->red;
139         green = that->green;
140
141         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
142                 automation_mins[i] = that->automation_mins[i];
143                 automation_maxs[i] = that->automation_maxs[i];
144         }
145         floatauto_type = that->floatauto_type;
146
147         blue = that->blue;
148 }
149
150 void LocalSession::save_xml(FileXML *file, double start)
151 {
152         file->tag.set_title("LOCALSESSION");
153
154         file->tag.set_property("IN_POINT", in_point - start);
155         file->tag.set_property("LOOP_PLAYBACK", loop_playback);
156         file->tag.set_property("LOOP_START", loop_start - start);
157         file->tag.set_property("LOOP_END", loop_end - start);
158         file->tag.set_property("OUT_POINT", out_point - start);
159         file->tag.set_property("SELECTION_START", selectionstart - start);
160         file->tag.set_property("SELECTION_END", selectionend - start);
161         file->tag.set_property("CLIP_TITLE", clip_title);
162         file->tag.set_property("CLIP_NOTES", clip_notes);
163         file->tag.set_property("FOLDER", folder);
164         file->tag.set_property("X_PANE", x_pane);
165         file->tag.set_property("Y_PANE", y_pane);
166
167         char string[BCTEXTLEN];
168         for(int i = 0; i < TOTAL_PANES; i++)
169         {
170                 sprintf(string, "TRACK_START%d", i);
171                 file->tag.set_property(string, track_start[i]);
172                 sprintf(string, "VIEW_START%d", i);
173                 file->tag.set_property(string, view_start[i]);
174         }
175
176         file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
177 //printf("EDLSession::save_session 1\n");
178         file->tag.set_property("ZOOMY", zoom_y);
179 //printf("EDLSession::save_session 1 %d\n", zoom_track);
180         file->tag.set_property("ZOOM_TRACK", zoom_track);
181
182         double preview_start = this->preview_start - start;
183         if(preview_start < 0) preview_start = 0;
184         double preview_end = this->preview_end - start;
185         if(preview_end < 0) preview_end = 0;
186
187         file->tag.set_property("PREVIEW_START", preview_start);
188         file->tag.set_property("PREVIEW_END", preview_end);
189         file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
190
191         file->tag.set_property("RED", red);
192         file->tag.set_property("GREEN", green);
193         file->tag.set_property("BLUE", blue);
194
195         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
196                 if (!Automation::autogrouptypes_fixedrange[i]) {
197                         file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
198                         file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
199                 }
200         }
201         file->append_tag();
202
203         file->tag.set_title("/LOCALSESSION");
204         file->append_tag();
205         file->append_newline();
206         file->append_newline();
207 }
208
209 void LocalSession::synchronize_params(LocalSession *that)
210 {
211         loop_playback = that->loop_playback;
212         loop_start = that->loop_start;
213         loop_end = that->loop_end;
214         preview_start = that->preview_start;
215         preview_end = that->preview_end;
216         red = that->red;
217         green = that->green;
218         blue = that->blue;
219 }
220
221
222 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
223 {
224         if(load_flags & LOAD_SESSION)
225         {
226 // moved to EDL::load_xml for paste to fill silence.
227 //              clipboard_length = 0;
228 // Overwritten by MWindow::load_filenames
229                 file->tag.get_property("CLIP_TITLE", clip_title);
230                 file->tag.get_property("CLIP_NOTES", clip_notes);
231                 file->tag.get_property("FOLDER", folder);
232                 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
233                 loop_start = file->tag.get_property("LOOP_START", (double)0);
234                 loop_end = file->tag.get_property("LOOP_END", (double)0);
235                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
236                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
237                 x_pane = file->tag.get_property("X_PANE", -1);
238                 y_pane = file->tag.get_property("Y_PANE", -1);
239
240
241                 char string[BCTEXTLEN];
242                 for(int i = 0; i < TOTAL_PANES; i++)
243                 {
244                         sprintf(string, "TRACK_START%d", i);
245                         track_start[i] = file->tag.get_property(string, track_start[i]);
246                         sprintf(string, "VIEW_START%d", i);
247                         view_start[i] = file->tag.get_property(string, view_start[i]);
248                 }
249
250                 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
251                 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
252                 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
253                 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
254                 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
255                 red = file->tag.get_property("RED", red);
256                 green = file->tag.get_property("GREEN", green);
257                 blue = file->tag.get_property("BLUE", blue);
258
259
260                 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
261                         if (!Automation::autogrouptypes_fixedrange[i]) {
262                                 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
263                                 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
264                         }
265                 }
266                 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
267         }
268
269
270 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
271 // expect - this is additionally important in keyboard-only editing in viewer window
272         if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
273         {
274                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
275                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
276         }
277
278
279
280         if(load_flags & LOAD_TIMEBAR)
281         {
282                 in_point = file->tag.get_property("IN_POINT", (double)-1);
283                 out_point = file->tag.get_property("OUT_POINT", (double)-1);
284         }
285 }
286
287 void LocalSession::boundaries()
288 {
289         zoom_sample = MAX(1, zoom_sample);
290 }
291
292 int LocalSession::load_defaults(BC_Hash *defaults)
293 {
294         loop_playback = defaults->get("LOOP_PLAYBACK", 0);
295         loop_start = defaults->get("LOOP_START", (double)0);
296         loop_end = defaults->get("LOOP_END", (double)0);
297         selectionstart = defaults->get("SELECTIONSTART", selectionstart);
298         selectionend = defaults->get("SELECTIONEND", selectionend);
299 //      track_start = defaults->get("TRACK_START", 0);
300 //      view_start = defaults->get("VIEW_START", 0);
301         zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
302         zoom_y = defaults->get("ZOOMY", 64);
303         zoom_track = defaults->get("ZOOM_TRACK", 64);
304         red = defaults->get("RED", 0.0);
305         green = defaults->get("GREEN", 0.0);
306         blue = defaults->get("BLUE", 0.0);
307
308         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
309                 if (!Automation::autogrouptypes_fixedrange[i]) {
310                         automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
311                         automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
312                 }
313         }
314
315         floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
316         x_pane = defaults->get("X_PANE", x_pane);
317         y_pane = defaults->get("Y_PANE", y_pane);
318
319         return 0;
320 }
321
322 int LocalSession::save_defaults(BC_Hash *defaults)
323 {
324         defaults->update("LOOP_PLAYBACK", loop_playback);
325         defaults->update("LOOP_START", loop_start);
326         defaults->update("LOOP_END", loop_end);
327         defaults->update("SELECTIONSTART", selectionstart);
328         defaults->update("SELECTIONEND", selectionend);
329 //      defaults->update("TRACK_START", track_start);
330 //      defaults->update("VIEW_START", view_start);
331         defaults->update("ZOOM_SAMPLE", zoom_sample);
332         defaults->update("ZOOMY", zoom_y);
333         defaults->update("ZOOM_TRACK", zoom_track);
334         defaults->update("RED", red);
335         defaults->update("GREEN", green);
336         defaults->update("BLUE", blue);
337
338         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
339                 if (!Automation::autogrouptypes_fixedrange[i]) {
340                         defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
341                         defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
342                 }
343         }
344
345         defaults->update("FLOATAUTO_TYPE", floatauto_type);
346         defaults->update("X_PANE", x_pane);
347         defaults->update("Y_PANE", y_pane);
348         return 0;
349 }
350
351 void LocalSession::set_selectionstart(double value)
352 {
353         this->selectionstart = value;
354 }
355
356 void LocalSession::set_selectionend(double value)
357 {
358         this->selectionend = value;
359 }
360
361 void LocalSession::set_inpoint(double value)
362 {
363         in_point = value;
364 }
365
366 void LocalSession::set_outpoint(double value)
367 {
368         out_point = value;
369 }
370
371 void LocalSession::unset_inpoint()
372 {
373         in_point = -1;
374 }
375
376 void LocalSession::unset_outpoint()
377 {
378         out_point = -1;
379 }
380
381 void LocalSession::set_playback_start(double value)
382 {
383         if( playback_end < 0 ) return;
384         playback_start = value;
385         playback_end = -1;
386 }
387
388 void LocalSession::set_playback_end(double value)
389 {
390         if( value < playback_start ) {
391                 if( playback_end < 0 )
392                         playback_end = playback_start;
393                 playback_start = value;
394         }
395         else if( playback_end < 0 || value > playback_end )
396                 playback_end = value;
397 }
398
399
400 double LocalSession::get_selectionstart(int highlight_only)
401 {
402         if(highlight_only || !EQUIV(selectionstart, selectionend))
403                 return selectionstart;
404
405         if(in_point >= 0)
406                 return in_point;
407         else
408         if(out_point >= 0)
409                 return out_point;
410         else
411                 return selectionstart;
412 }
413
414 double LocalSession::get_selectionend(int highlight_only)
415 {
416         if(highlight_only || !EQUIV(selectionstart, selectionend))
417                 return selectionend;
418
419         if(out_point >= 0)
420                 return out_point;
421         else
422         if(in_point >= 0)
423                 return in_point;
424         else
425                 return selectionend;
426 }
427
428 double LocalSession::get_inpoint()
429 {
430         return in_point;
431 }
432
433 double LocalSession::get_outpoint()
434 {
435         return out_point;
436 }
437
438 int LocalSession::inpoint_valid()
439 {
440         return in_point >= 0;
441 }
442
443 int LocalSession::outpoint_valid()
444 {
445         return out_point >= 0;
446 }
447
448
449
450