r901: Automation::fit_autos() now works and automation_{min,max} variable removed
[cinelerra_cv/pmdumuid.git] / cinelerra / localsession.C
blobca9fda501d8964cc577ed2d5d533985e4477b703
1 #include "automation.h"
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"
30 LocalSession::LocalSession(EDL *edl)
32         this->edl = edl;
34         selectionstart = selectionend = 0;
35         in_point = out_point = -1;
36         strcpy(folder, CLIP_FOLDER);
37         sprintf(clip_title, "Program");
38         strcpy(clip_notes, "Hello world");
39         clipboard_length = 0;
40         preview_start = preview_end = 0;
41         loop_playback = 0;
42         loop_start = 0;
43         loop_end = 0;
44         zoom_sample = 0;
45         zoom_y = 0;
46         zoom_track = 0;
47         view_start = 0;
48         track_start = 0;
50         automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
51         automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
53         automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
54         automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
56         automation_mins[AUTOGROUPTYPE_ZOOM] = 0.001;
57         automation_maxs[AUTOGROUPTYPE_ZOOM] = 4;
59         automation_mins[AUTOGROUPTYPE_X] = -100;
60         automation_maxs[AUTOGROUPTYPE_X] = 100;
62         automation_mins[AUTOGROUPTYPE_Y] = -100;
63         automation_maxs[AUTOGROUPTYPE_Y] = 100;
65         automation_mins[AUTOGROUPTYPE_INT255] = 0;
66         automation_maxs[AUTOGROUPTYPE_INT255] = 255;
68         zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
69         red = green = blue = 0;
72 LocalSession::~LocalSession()
76 void LocalSession::copy_from(LocalSession *that)
78         strcpy(clip_title, that->clip_title);
79         strcpy(clip_notes, that->clip_notes);
80         strcpy(folder, that->folder);
81         in_point = that->in_point;
82         loop_playback = that->loop_playback;
83         loop_start = that->loop_start;
84         loop_end = that->loop_end;
85         out_point = that->out_point;
86         selectionend = that->selectionend;
87         selectionstart = that->selectionstart;
88         track_start = that->track_start;
89         view_start = that->view_start;
90         zoom_sample = that->zoom_sample;
91         zoom_y = that->zoom_y;
92         zoom_track = that->zoom_track;
93         preview_start = that->preview_start;
94         preview_end = that->preview_end;
95         red = that->red;
96         green = that->green;
97         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
98                 automation_mins[i] = that->automation_mins[i];
99                 automation_maxs[i] = that->automation_maxs[i];
100         }
101         blue = that->blue;
104 void LocalSession::save_xml(FileXML *file, double start)
106         file->tag.set_title("LOCALSESSION");
108         file->tag.set_property("IN_POINT", in_point - start);
109         file->tag.set_property("LOOP_PLAYBACK", loop_playback);
110         file->tag.set_property("LOOP_START", loop_start - start);
111         file->tag.set_property("LOOP_END", loop_end - start);
112         file->tag.set_property("OUT_POINT", out_point - start);
113         file->tag.set_property("SELECTION_START", selectionstart - start);
114         file->tag.set_property("SELECTION_END", selectionend - start);
115         file->tag.set_property("CLIP_TITLE", clip_title);
116         file->tag.set_property("CLIP_NOTES", clip_notes);
117         file->tag.set_property("FOLDER", folder);
118         file->tag.set_property("TRACK_START", track_start);
119         file->tag.set_property("VIEW_START", view_start);
120         file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
121 //printf("EDLSession::save_session 1\n");
122         file->tag.set_property("ZOOMY", zoom_y);
123 //printf("EDLSession::save_session 1 %d\n", zoom_track);
124         file->tag.set_property("ZOOM_TRACK", zoom_track);
125         
126         double preview_start = this->preview_start - start;
127         if(preview_start < 0) preview_start = 0;
128         double preview_end = this->preview_end - start;
129         if(preview_end < 0) preview_end = 0;
130         
131         file->tag.set_property("PREVIEW_START", preview_start);
132         file->tag.set_property("PREVIEW_END", preview_end);
133         file->tag.set_property("RED", red);
134         file->tag.set_property("GREEN", green);
135         file->tag.set_property("BLUE", blue);
137         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
138                 if (!Automation::autogrouptypes_fixedrange[i]) {
139                         file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
140                         file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
141                 }
142         }
143         file->append_tag();
144         file->tag.set_title("/LOCALSESSION");
145         file->append_tag();
146         file->append_newline();
147         file->append_newline();
150 void LocalSession::synchronize_params(LocalSession *that)
152         loop_playback = that->loop_playback;
153         loop_start = that->loop_start;
154         loop_end = that->loop_end;
155         preview_start = that->preview_start;
156         preview_end = that->preview_end;
157         red = that->red;
158         green = that->green;
159         blue = that->blue;
163 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
165         if(load_flags & LOAD_SESSION)
166         {
167                 clipboard_length = 0;
168 // Overwritten by MWindow::load_filenames       
169                 file->tag.get_property("CLIP_TITLE", clip_title);
170                 file->tag.get_property("CLIP_NOTES", clip_notes);
171                 file->tag.get_property("FOLDER", folder);
172                 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
173                 loop_start = file->tag.get_property("LOOP_START", (double)0);
174                 loop_end = file->tag.get_property("LOOP_END", (double)0);
175                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
176                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
177                 track_start = file->tag.get_property("TRACK_START", track_start);
178                 view_start = file->tag.get_property("VIEW_START", view_start);
179                 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
180                 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
181                 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
182                 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
183                 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
184                 red = file->tag.get_property("RED", red);
185                 green = file->tag.get_property("GREEN", green);
186                 blue = file->tag.get_property("BLUE", blue);
188                 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
189                         if (!Automation::autogrouptypes_fixedrange[i]) {
190                                 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
191                                 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
192                         }
193                 }
194         }
197 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
198 // expect - this is additionally important in keyboard-only editing in viewer window
199         if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
200         {
201                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
202                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
203         }
207         if(load_flags & LOAD_TIMEBAR)
208         {
209                 in_point = file->tag.get_property("IN_POINT", (double)-1);
210                 out_point = file->tag.get_property("OUT_POINT", (double)-1);
211         }
214 void LocalSession::boundaries()
216         zoom_sample = MAX(1, zoom_sample);
219 int LocalSession::load_defaults(BC_Hash *defaults)
221         loop_playback = defaults->get("LOOP_PLAYBACK", 0);
222         loop_start = defaults->get("LOOP_START", (double)0);
223         loop_end = defaults->get("LOOP_END", (double)0);
224         selectionstart = defaults->get("SELECTIONSTART", selectionstart);
225         selectionend = defaults->get("SELECTIONEND", selectionend);
226 //      track_start = defaults->get("TRACK_START", 0);
227 //      view_start = defaults->get("VIEW_START", 0);
228         zoom_sample = defaults->get("ZOOM_SAMPLE", 1);
229         zoom_y = defaults->get("ZOOMY", 64);
230         zoom_track = defaults->get("ZOOM_TRACK", 64);
231         red = defaults->get("RED", 0.0);
232         green = defaults->get("GREEN", 0.0);
233         blue = defaults->get("BLUE", 0.0);
235         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
236                 if (!Automation::autogrouptypes_fixedrange[i]) {
237                         automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
238                         automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
239                 }
240         }
242         return 0;
245 int LocalSession::save_defaults(BC_Hash *defaults)
247         defaults->update("LOOP_PLAYBACK", loop_playback);
248         defaults->update("LOOP_START", loop_start);
249         defaults->update("LOOP_END", loop_end);
250         defaults->update("SELECTIONSTART", selectionstart);
251         defaults->update("SELECTIONEND", selectionend);
252         defaults->update("TRACK_START", track_start);
253         defaults->update("VIEW_START", view_start);
254         defaults->update("ZOOM_SAMPLE", zoom_sample);
255         defaults->update("ZOOMY", zoom_y);
256         defaults->update("ZOOM_TRACK", zoom_track);
257         defaults->update("RED", red);
258         defaults->update("GREEN", green);
259         defaults->update("BLUE", blue);
261         for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
262                 if (!Automation::autogrouptypes_fixedrange[i]) {
263                         defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
264                         defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
265                 }
266         }
268         return 0;
271 void LocalSession::set_selectionstart(double value)
273         this->selectionstart = value;
276 void LocalSession::set_selectionend(double value)
278         this->selectionend = value;
281 void LocalSession::set_inpoint(double value)
283         in_point = value;
286 void LocalSession::set_outpoint(double value)
288         out_point = value;
291 void LocalSession::unset_inpoint()
293         in_point = -1;
296 void LocalSession::unset_outpoint()
298         out_point = -1;
303 double LocalSession::get_selectionstart(int highlight_only)
305         if(highlight_only || !EQUIV(selectionstart, selectionend))
306                 return selectionstart;
308         if(in_point >= 0)
309                 return in_point;
310         else
311         if(out_point >= 0)
312                 return out_point;
313         else
314                 return selectionstart;
317 double LocalSession::get_selectionend(int highlight_only)
319         if(highlight_only || !EQUIV(selectionstart, selectionend))
320                 return selectionend;
322         if(out_point >= 0)
323                 return out_point;
324         else
325         if(in_point >= 0)
326                 return in_point;
327         else
328                 return selectionend;
331 double LocalSession::get_inpoint()
333         return in_point;
336 double LocalSession::get_outpoint()
338         return out_point;
341 int LocalSession::inpoint_valid()
343         return in_point >= 0;
346 int LocalSession::outpoint_valid()
348         return out_point >= 0;