r899: autogrouptypes given better names in xml; Decibels / video fade units need...
[cinelerra_cv/mob.git] / cinelerra / localsession.C
blob884edfd259dd5f89c6fdb59553a91938aa6bb844
1 #include "automation.inc"
2 #include "clip.h"
3 #include "bchash.h"
4 #include "edl.h"
5 #include "filexml.h"
6 #include "localsession.h"
9 static char *xml_autogrouptypes_titlesmax[] = 
11         "AUTOGROUPTYPE_AUDIO_FADE_MAX",
12         "AUTOGROUPTYPE_VIDEO_FADE_MAX",
13         "AUTOGROUPTYPE_ZOOM_MAX",
14         "AUTOGROUPTYPE_X_MAX",
15         "AUTOGROUPTYPE_Y_MAX",
16         "AUTOGROUPTYPE_INT255_MAX"
19 static char *xml_autogrouptypes_titlesmin[] = 
21         "AUTOGROUPTYPE_AUDIO_FADE_MIN",
22         "AUTOGROUPTYPE_VIDEO_FADE_MIN",
23         "AUTOGROUPTYPE_ZOOM_MIN",
24         "AUTOGROUPTYPE_X_MIN",
25         "AUTOGROUPTYPE_Y_MIN",
26         "AUTOGROUPTYPE_INT255_MIN"
29 static int xml_autogrouptypes_save[] =
31         1,
32         1,
33         1,
34         1,
35         1,
36         0
39 LocalSession::LocalSession(EDL *edl)
41         this->edl = edl;
43         selectionstart = selectionend = 0;
44         in_point = out_point = -1;
45         strcpy(folder, CLIP_FOLDER);
46         sprintf(clip_title, "Program");
47         strcpy(clip_notes, "Hello world");
48         clipboard_length = 0;
49         preview_start = preview_end = 0;
50         loop_playback = 0;
51         loop_start = 0;
52         loop_end = 0;
53         zoom_sample = 0;
54         zoom_y = 0;
55         zoom_track = 0;
56         view_start = 0;
57         track_start = 0;
59         automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
60         automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
62         automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
63         automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
65         automation_mins[AUTOGROUPTYPE_ZOOM] = 0.001;
66         automation_maxs[AUTOGROUPTYPE_ZOOM] = 4;
68         automation_mins[AUTOGROUPTYPE_X] = -100;
69         automation_maxs[AUTOGROUPTYPE_X] = 100;
71         automation_mins[AUTOGROUPTYPE_Y] = -100;
72         automation_maxs[AUTOGROUPTYPE_Y] = 100;
74         automation_mins[AUTOGROUPTYPE_INT255] = 0;
75         automation_maxs[AUTOGROUPTYPE_INT255] = 255;
77         automation_min = -10;
78         automation_max = 10;
79         zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
80         red = green = blue = 0;
83 LocalSession::~LocalSession()
87 void LocalSession::copy_from(LocalSession *that)
89         strcpy(clip_title, that->clip_title);
90         strcpy(clip_notes, that->clip_notes);
91         strcpy(folder, that->folder);
92         in_point = that->in_point;
93         loop_playback = that->loop_playback;
94         loop_start = that->loop_start;
95         loop_end = that->loop_end;
96         out_point = that->out_point;
97         selectionend = that->selectionend;
98         selectionstart = that->selectionstart;
99         track_start = that->track_start;
100         view_start = that->view_start;
101         zoom_sample = that->zoom_sample;
102         zoom_y = that->zoom_y;
103         zoom_track = that->zoom_track;
104         preview_start = that->preview_start;
105         preview_end = that->preview_end;
106         red = that->red;
107         green = that->green;
108         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
109                 automation_mins[i] = that->automation_mins[i];
110                 automation_maxs[i] = that->automation_maxs[i];
111         }
112         automation_min = that->automation_min;
113         automation_max = that->automation_max;
114         blue = that->blue;
117 void LocalSession::save_xml(FileXML *file, double start)
119         file->tag.set_title("LOCALSESSION");
121         file->tag.set_property("IN_POINT", in_point - start);
122         file->tag.set_property("LOOP_PLAYBACK", loop_playback);
123         file->tag.set_property("LOOP_START", loop_start - start);
124         file->tag.set_property("LOOP_END", loop_end - start);
125         file->tag.set_property("OUT_POINT", out_point - start);
126         file->tag.set_property("SELECTION_START", selectionstart - start);
127         file->tag.set_property("SELECTION_END", selectionend - start);
128         file->tag.set_property("CLIP_TITLE", clip_title);
129         file->tag.set_property("CLIP_NOTES", clip_notes);
130         file->tag.set_property("FOLDER", folder);
131         file->tag.set_property("TRACK_START", track_start);
132         file->tag.set_property("VIEW_START", view_start);
133         file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
134 //printf("EDLSession::save_session 1\n");
135         file->tag.set_property("ZOOMY", zoom_y);
136 //printf("EDLSession::save_session 1 %d\n", zoom_track);
137         file->tag.set_property("ZOOM_TRACK", zoom_track);
138         
139         double preview_start = this->preview_start - start;
140         if(preview_start < 0) preview_start = 0;
141         double preview_end = this->preview_end - start;
142         if(preview_end < 0) preview_end = 0;
143         
144         file->tag.set_property("PREVIEW_START", preview_start);
145         file->tag.set_property("PREVIEW_END", preview_end);
146         file->tag.set_property("RED", red);
147         file->tag.set_property("GREEN", green);
148         file->tag.set_property("BLUE", blue);
150         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
151                 if (xml_autogrouptypes_save[i]) {
152                         file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
153                         file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
154                 }
155         }
156         file->append_tag();
157         file->tag.set_title("/LOCALSESSION");
158         file->append_tag();
159         file->append_newline();
160         file->append_newline();
163 void LocalSession::synchronize_params(LocalSession *that)
165         loop_playback = that->loop_playback;
166         loop_start = that->loop_start;
167         loop_end = that->loop_end;
168         preview_start = that->preview_start;
169         preview_end = that->preview_end;
170         red = that->red;
171         green = that->green;
172         blue = that->blue;
176 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
178         if(load_flags & LOAD_SESSION)
179         {
180                 clipboard_length = 0;
181 // Overwritten by MWindow::load_filenames       
182                 file->tag.get_property("CLIP_TITLE", clip_title);
183                 file->tag.get_property("CLIP_NOTES", clip_notes);
184                 file->tag.get_property("FOLDER", folder);
185                 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
186                 loop_start = file->tag.get_property("LOOP_START", (double)0);
187                 loop_end = file->tag.get_property("LOOP_END", (double)0);
188                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
189                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
190                 track_start = file->tag.get_property("TRACK_START", track_start);
191                 view_start = file->tag.get_property("VIEW_START", view_start);
192                 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
193                 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
194                 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
195                 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
196                 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
197                 red = file->tag.get_property("RED", red);
198                 green = file->tag.get_property("GREEN", green);
199                 blue = file->tag.get_property("BLUE", blue);
201                 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
202                         if (xml_autogrouptypes_save[i]) {
203                                 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
204                                 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
205                         }
206                 }
207         }
210 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
211 // expect - this is additionally important in keyboard-only editing in viewer window
212         if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
213         {
214                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
215                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
216         }
220         if(load_flags & LOAD_TIMEBAR)
221         {
222                 in_point = file->tag.get_property("IN_POINT", (double)-1);
223                 out_point = file->tag.get_property("OUT_POINT", (double)-1);
224         }
227 void LocalSession::boundaries()
229         zoom_sample = MAX(1, zoom_sample);
232 int LocalSession::load_defaults(BC_Hash *defaults)
234         loop_playback = defaults->get("LOOP_PLAYBACK", 0);
235         loop_start = defaults->get("LOOP_START", (double)0);
236         loop_end = defaults->get("LOOP_END", (double)0);
237         selectionstart = defaults->get("SELECTIONSTART", selectionstart);
238         selectionend = defaults->get("SELECTIONEND", selectionend);
239 //      track_start = defaults->get("TRACK_START", 0);
240 //      view_start = defaults->get("VIEW_START", 0);
241         zoom_sample = defaults->get("ZOOM_SAMPLE", 1);
242         zoom_y = defaults->get("ZOOMY", 64);
243         zoom_track = defaults->get("ZOOM_TRACK", 64);
244         red = defaults->get("RED", 0.0);
245         green = defaults->get("GREEN", 0.0);
246         blue = defaults->get("BLUE", 0.0);
248         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
249                 if (xml_autogrouptypes_save[i]) {
250                         automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
251                         automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
252                 }
253         }
255         return 0;
258 int LocalSession::save_defaults(BC_Hash *defaults)
260         defaults->update("LOOP_PLAYBACK", loop_playback);
261         defaults->update("LOOP_START", loop_start);
262         defaults->update("LOOP_END", loop_end);
263         defaults->update("SELECTIONSTART", selectionstart);
264         defaults->update("SELECTIONEND", selectionend);
265         defaults->update("TRACK_START", track_start);
266         defaults->update("VIEW_START", view_start);
267         defaults->update("ZOOM_SAMPLE", zoom_sample);
268         defaults->update("ZOOMY", zoom_y);
269         defaults->update("ZOOM_TRACK", zoom_track);
270         defaults->update("RED", red);
271         defaults->update("GREEN", green);
272         defaults->update("BLUE", blue);
274         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
275                 if (xml_autogrouptypes_save[i]) {
276                         defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
277                         defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
278                 }
279         }
281         return 0;
284 void LocalSession::set_selectionstart(double value)
286         this->selectionstart = value;
289 void LocalSession::set_selectionend(double value)
291         this->selectionend = value;
294 void LocalSession::set_inpoint(double value)
296         in_point = value;
299 void LocalSession::set_outpoint(double value)
301         out_point = value;
304 void LocalSession::unset_inpoint()
306         in_point = -1;
309 void LocalSession::unset_outpoint()
311         out_point = -1;
316 double LocalSession::get_selectionstart(int highlight_only)
318         if(highlight_only || !EQUIV(selectionstart, selectionend))
319                 return selectionstart;
321         if(in_point >= 0)
322                 return in_point;
323         else
324         if(out_point >= 0)
325                 return out_point;
326         else
327                 return selectionstart;
330 double LocalSession::get_selectionend(int highlight_only)
332         if(highlight_only || !EQUIV(selectionstart, selectionend))
333                 return selectionend;
335         if(out_point >= 0)
336                 return out_point;
337         else
338         if(in_point >= 0)
339                 return in_point;
340         else
341                 return selectionend;
344 double LocalSession::get_inpoint()
346         return in_point;
349 double LocalSession::get_outpoint()
351         return out_point;
354 int LocalSession::inpoint_valid()
356         return in_point >= 0;
359 int LocalSession::outpoint_valid()
361         return out_point >= 0;