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