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