ff tooltip, shcmds doc, bld_prepare fix, edl load_xml fix
[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 }
108
109 LocalSession::~LocalSession()
110 {
111 }
112
113 void LocalSession::copy_from(LocalSession *that)
114 {
115         strcpy(clip_title, that->clip_title);
116         strcpy(clip_notes, that->clip_notes);
117         awindow_folder = that->awindow_folder;
118         in_point = that->in_point;
119         loop_playback = that->loop_playback;
120         loop_start = that->loop_start;
121         loop_end = that->loop_end;
122         out_point = that->out_point;
123         selectionend = that->selectionend;
124         selectionstart = that->selectionstart;
125         x_pane = that->x_pane;
126         y_pane = that->y_pane;
127
128         for(int i = 0; i < TOTAL_PANES; i++)
129         {
130                 view_start[i] = that->view_start[i];
131                 track_start[i] = that->track_start[i];
132         }
133
134         zoom_sample = that->zoom_sample;
135         zoom_y = that->zoom_y;
136         zoom_track = that->zoom_track;
137         preview_start = that->preview_start;
138         preview_end = that->preview_end;
139         red = that->red;
140         green = that->green;
141
142         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
143                 automation_mins[i] = that->automation_mins[i];
144                 automation_maxs[i] = that->automation_maxs[i];
145         }
146         floatauto_type = that->floatauto_type;
147
148         blue = that->blue;
149 }
150
151 void LocalSession::save_xml(FileXML *file, double start)
152 {
153         file->tag.set_title("LOCALSESSION");
154
155         file->tag.set_property("IN_POINT", in_point - start);
156         file->tag.set_property("LOOP_PLAYBACK", loop_playback);
157         file->tag.set_property("LOOP_START", loop_start - start);
158         file->tag.set_property("LOOP_END", loop_end - start);
159         file->tag.set_property("OUT_POINT", out_point - start);
160         file->tag.set_property("SELECTION_START", selectionstart - start);
161         file->tag.set_property("SELECTION_END", selectionend - start);
162         file->tag.set_property("CLIP_TITLE", clip_title);
163         file->tag.set_property("CLIP_NOTES", clip_notes);
164         file->tag.set_property("AWINDOW_FOLDER", awindow_folder);
165         file->tag.set_property("X_PANE", x_pane);
166         file->tag.set_property("Y_PANE", y_pane);
167
168         char string[BCTEXTLEN];
169         for(int i = 0; i < TOTAL_PANES; i++)
170         {
171                 sprintf(string, "TRACK_START%d", i);
172                 file->tag.set_property(string, track_start[i]);
173                 sprintf(string, "VIEW_START%d", i);
174                 file->tag.set_property(string, view_start[i]);
175         }
176
177         file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
178 //printf("EDLSession::save_session 1\n");
179         file->tag.set_property("ZOOMY", zoom_y);
180 //printf("EDLSession::save_session 1 %d\n", zoom_track);
181         file->tag.set_property("ZOOM_TRACK", zoom_track);
182
183         double preview_start = this->preview_start - start;
184         if(preview_start < 0) preview_start = 0;
185         double preview_end = this->preview_end - start;
186         if(preview_end < 0) preview_end = 0;
187
188         file->tag.set_property("PREVIEW_START", preview_start);
189         file->tag.set_property("PREVIEW_END", preview_end);
190         file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
191
192         file->tag.set_property("RED", red);
193         file->tag.set_property("GREEN", green);
194         file->tag.set_property("BLUE", blue);
195
196         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
197                 if (!Automation::autogrouptypes_fixedrange[i]) {
198                         file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
199                         file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
200                 }
201         }
202         file->append_tag();
203
204         file->tag.set_title("/LOCALSESSION");
205         file->append_tag();
206         file->append_newline();
207         file->append_newline();
208 }
209
210 void LocalSession::synchronize_params(LocalSession *that)
211 {
212         loop_playback = that->loop_playback;
213         loop_start = that->loop_start;
214         loop_end = that->loop_end;
215         preview_start = that->preview_start;
216         preview_end = that->preview_end;
217         red = that->red;
218         green = that->green;
219         blue = that->blue;
220 }
221
222
223 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
224 {
225         if(load_flags & LOAD_SESSION)
226         {
227 // moved to EDL::load_xml for paste to fill silence.
228 //              clipboard_length = 0;
229 // Overwritten by MWindow::load_filenames
230                 file->tag.get_property("CLIP_TITLE", clip_title);
231                 file->tag.get_property("CLIP_NOTES", clip_notes);
232                 const char *folder = file->tag.get_property("FOLDER");
233                 if( folder ) {
234                         awindow_folder = AWindowGUI::folder_number(folder);
235                         if( awindow_folder < 0 ) awindow_folder = AW_MEDIA_FOLDER;
236                 }
237                 awindow_folder = file->tag.get_property("AWINDOW_FOLDER", awindow_folder);
238                 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
239                 loop_start = file->tag.get_property("LOOP_START", (double)0);
240                 loop_end = file->tag.get_property("LOOP_END", (double)0);
241                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
242                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
243                 x_pane = file->tag.get_property("X_PANE", -1);
244                 y_pane = file->tag.get_property("Y_PANE", -1);
245
246
247                 char string[BCTEXTLEN];
248                 for(int i = 0; i < TOTAL_PANES; i++)
249                 {
250                         sprintf(string, "TRACK_START%d", i);
251                         track_start[i] = file->tag.get_property(string, track_start[i]);
252                         sprintf(string, "VIEW_START%d", i);
253                         view_start[i] = file->tag.get_property(string, view_start[i]);
254                 }
255
256                 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
257                 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
258                 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
259                 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
260                 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
261                 red = file->tag.get_property("RED", red);
262                 green = file->tag.get_property("GREEN", green);
263                 blue = file->tag.get_property("BLUE", blue);
264
265
266                 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
267                         if (!Automation::autogrouptypes_fixedrange[i]) {
268                                 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
269                                 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
270                         }
271                 }
272                 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
273         }
274
275
276 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
277 // expect - this is additionally important in keyboard-only editing in viewer window
278         if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
279         {
280                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
281                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
282         }
283
284
285
286         if(load_flags & LOAD_TIMEBAR)
287         {
288                 in_point = file->tag.get_property("IN_POINT", (double)-1);
289                 out_point = file->tag.get_property("OUT_POINT", (double)-1);
290         }
291 }
292
293 void LocalSession::boundaries()
294 {
295         zoom_sample = MAX(1, zoom_sample);
296 }
297
298 int LocalSession::load_defaults(BC_Hash *defaults)
299 {
300         loop_playback = defaults->get("LOOP_PLAYBACK", 0);
301         loop_start = defaults->get("LOOP_START", (double)0);
302         loop_end = defaults->get("LOOP_END", (double)0);
303         selectionstart = defaults->get("SELECTIONSTART", selectionstart);
304         selectionend = defaults->get("SELECTIONEND", selectionend);
305 //      track_start = defaults->get("TRACK_START", 0);
306 //      view_start = defaults->get("VIEW_START", 0);
307         zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
308         zoom_y = defaults->get("ZOOMY", 64);
309         zoom_track = defaults->get("ZOOM_TRACK", 64);
310         red = defaults->get("RED", 0.0);
311         green = defaults->get("GREEN", 0.0);
312         blue = defaults->get("BLUE", 0.0);
313
314         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
315                 if (!Automation::autogrouptypes_fixedrange[i]) {
316                         automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
317                         automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
318                 }
319         }
320
321         floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
322         x_pane = defaults->get("X_PANE", x_pane);
323         y_pane = defaults->get("Y_PANE", y_pane);
324
325         return 0;
326 }
327
328 int LocalSession::save_defaults(BC_Hash *defaults)
329 {
330         defaults->update("LOOP_PLAYBACK", loop_playback);
331         defaults->update("LOOP_START", loop_start);
332         defaults->update("LOOP_END", loop_end);
333         defaults->update("SELECTIONSTART", selectionstart);
334         defaults->update("SELECTIONEND", selectionend);
335 //      defaults->update("TRACK_START", track_start);
336 //      defaults->update("VIEW_START", view_start);
337         defaults->update("ZOOM_SAMPLE", zoom_sample);
338         defaults->update("ZOOMY", zoom_y);
339         defaults->update("ZOOM_TRACK", zoom_track);
340         defaults->update("RED", red);
341         defaults->update("GREEN", green);
342         defaults->update("BLUE", blue);
343
344         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
345                 if (!Automation::autogrouptypes_fixedrange[i]) {
346                         defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
347                         defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
348                 }
349         }
350
351         defaults->update("FLOATAUTO_TYPE", floatauto_type);
352         defaults->update("X_PANE", x_pane);
353         defaults->update("Y_PANE", y_pane);
354         return 0;
355 }
356
357 void LocalSession::set_selectionstart(double value)
358 {
359         this->selectionstart = value;
360 }
361
362 void LocalSession::set_selectionend(double value)
363 {
364         this->selectionend = value;
365 }
366
367 void LocalSession::set_inpoint(double value)
368 {
369         in_point = value;
370 }
371
372 void LocalSession::set_outpoint(double value)
373 {
374         out_point = value;
375 }
376
377 void LocalSession::unset_inpoint()
378 {
379         in_point = -1;
380 }
381
382 void LocalSession::unset_outpoint()
383 {
384         out_point = -1;
385 }
386
387 void LocalSession::set_playback_start(double value)
388 {
389         if( playback_end < 0 ) return;
390         playback_start = value;
391         playback_end = -1;
392 }
393
394 void LocalSession::set_playback_end(double value)
395 {
396         if( value < playback_start ) {
397                 if( playback_end < 0 )
398                         playback_end = playback_start;
399                 playback_start = value;
400         }
401         else if( playback_end < 0 || value > playback_end )
402                 playback_end = value;
403 }
404
405
406 double LocalSession::get_selectionstart(int highlight_only)
407 {
408         if(highlight_only || !EQUIV(selectionstart, selectionend))
409                 return selectionstart;
410
411         if(in_point >= 0)
412                 return in_point;
413         else
414         if(out_point >= 0)
415                 return out_point;
416         else
417                 return selectionstart;
418 }
419
420 double LocalSession::get_selectionend(int highlight_only)
421 {
422         if(highlight_only || !EQUIV(selectionstart, selectionend))
423                 return selectionend;
424
425         if(out_point >= 0)
426                 return out_point;
427         else
428         if(in_point >= 0)
429                 return in_point;
430         else
431                 return selectionend;
432 }
433
434 double LocalSession::get_inpoint()
435 {
436         return in_point;
437 }
438
439 double LocalSession::get_outpoint()
440 {
441         return out_point;
442 }
443
444 int LocalSession::inpoint_valid()
445 {
446         return in_point >= 0;
447 }
448
449 int LocalSession::outpoint_valid()
450 {
451         return out_point >= 0;
452 }
453
454
455
456