r689: Fixed that changes made by dragging a control would often store each
[cinelerra_cv.git] / cinelerra / localsession.C
blobc48b329d19bee82c34a787d691fb0ad97acd9266
1 #include "clip.h"
2 #include "defaults.h"
3 #include "edl.h"
4 #include "filexml.h"
5 #include "localsession.h"
11 LocalSession::LocalSession(EDL *edl)
13         this->edl = edl;
15         selectionstart = selectionend = 0;
16         in_point = out_point = -1;
17         strcpy(folder, CLIP_FOLDER);
18         sprintf(clip_title, "Program");
19         strcpy(clip_notes, "Hello world");
20         clipboard_length = 0;
21         preview_start = preview_end = 0;
22         loop_playback = 0;
23         loop_start = 0;
24         loop_end = 0;
25         zoom_sample = 0;
26         zoom_y = 0;
27         zoom_track = 0;
28         view_start = 0;
29         track_start = 0;
30         automation_min = -10;
31         automation_max = 10;
32         red = green = blue = 0;
35 LocalSession::~LocalSession()
39 void LocalSession::copy_from(LocalSession *that)
41         strcpy(clip_title, that->clip_title);
42         strcpy(clip_notes, that->clip_notes);
43         strcpy(folder, that->folder);
44         in_point = that->in_point;
45         loop_playback = that->loop_playback;
46         loop_start = that->loop_start;
47         loop_end = that->loop_end;
48         out_point = that->out_point;
49         selectionend = that->selectionend;
50         selectionstart = that->selectionstart;
51         track_start = that->track_start;
52         view_start = that->view_start;
53         zoom_sample = that->zoom_sample;
54         zoom_y = that->zoom_y;
55         zoom_track = that->zoom_track;
56         preview_start = that->preview_start;
57         preview_end = that->preview_end;
58         red = that->red;
59         green = that->green;
60         automation_min = that->automation_min;
61         automation_max = that->automation_max;
62         blue = that->blue;
65 void LocalSession::save_xml(FileXML *file, double start)
67         file->tag.set_title("LOCALSESSION");
69         file->tag.set_property("IN_POINT", in_point - start);
70         file->tag.set_property("LOOP_PLAYBACK", loop_playback);
71         file->tag.set_property("LOOP_START", loop_start - start);
72         file->tag.set_property("LOOP_END", loop_end - start);
73         file->tag.set_property("OUT_POINT", out_point - start);
74         file->tag.set_property("SELECTION_START", selectionstart - start);
75         file->tag.set_property("SELECTION_END", selectionend - start);
76         file->tag.set_property("CLIP_TITLE", clip_title);
77         file->tag.set_property("CLIP_NOTES", clip_notes);
78         file->tag.set_property("FOLDER", folder);
79         file->tag.set_property("TRACK_START", track_start);
80         file->tag.set_property("VIEW_START", view_start);
81         file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
82 //printf("EDLSession::save_session 1\n");
83         file->tag.set_property("ZOOMY", zoom_y);
84 //printf("EDLSession::save_session 1 %d\n", zoom_track);
85         file->tag.set_property("ZOOM_TRACK", zoom_track);
86         
87         double preview_start = this->preview_start - start;
88         if(preview_start < 0) preview_start = 0;
89         double preview_end = this->preview_end - start;
90         if(preview_end < 0) preview_end = 0;
91         
92         file->tag.set_property("PREVIEW_START", preview_start);
93         file->tag.set_property("PREVIEW_END", preview_end);
94         file->tag.set_property("RED", red);
95         file->tag.set_property("GREEN", green);
96         file->tag.set_property("BLUE", blue);
97         file->tag.set_property("AUTOMATION_MIN", automation_min);
98         file->tag.set_property("AUTOMATION_MAX", automation_max);
99         file->append_tag();
100         file->tag.set_title("/LOCALSESSION");
101         file->append_tag();
102         file->append_newline();
103         file->append_newline();
106 void LocalSession::synchronize_params(LocalSession *that)
108         loop_playback = that->loop_playback;
109         loop_start = that->loop_start;
110         loop_end = that->loop_end;
111         preview_start = that->preview_start;
112         preview_end = that->preview_end;
113         red = that->red;
114         green = that->green;
115         blue = that->blue;
119 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
121         if(load_flags & LOAD_SESSION)
122         {
123                 clipboard_length = 0;
124 // Overwritten by MWindow::load_filenames       
125                 file->tag.get_property("CLIP_TITLE", clip_title);
126                 file->tag.get_property("CLIP_NOTES", clip_notes);
127                 file->tag.get_property("FOLDER", folder);
128                 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
129                 loop_start = file->tag.get_property("LOOP_START", (double)0);
130                 loop_end = file->tag.get_property("LOOP_END", (double)0);
131                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
132                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
133                 track_start = file->tag.get_property("TRACK_START", track_start);
134                 view_start = file->tag.get_property("VIEW_START", view_start);
135                 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
136                 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
137                 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
138                 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
139                 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
140                 red = file->tag.get_property("RED", red);
141                 green = file->tag.get_property("GREEN", green);
142                 blue = file->tag.get_property("BLUE", blue);
143                 automation_min = file->tag.get_property("AUTOMATION_MIN", automation_min);
144                 automation_max = file->tag.get_property("AUTOMATION_MAX", automation_max);
145         }
148 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
149 // expect - this is additionally important in keyboard-only editing in viewer window
150         if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
151         {
152                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
153                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
154         }
158         if(load_flags & LOAD_TIMEBAR)
159         {
160                 in_point = file->tag.get_property("IN_POINT", (double)-1);
161                 out_point = file->tag.get_property("OUT_POINT", (double)-1);
162         }
165 void LocalSession::boundaries()
167         zoom_sample = MAX(1, zoom_sample);
170 int LocalSession::load_defaults(Defaults *defaults)
172         loop_playback = defaults->get("LOOP_PLAYBACK", 0);
173         loop_start = defaults->get("LOOP_START", (double)0);
174         loop_end = defaults->get("LOOP_END", (double)0);
175         selectionstart = defaults->get("SELECTIONSTART", selectionstart);
176         selectionend = defaults->get("SELECTIONEND", selectionend);
177 //      track_start = defaults->get("TRACK_START", 0);
178 //      view_start = defaults->get("VIEW_START", 0);
179         zoom_sample = defaults->get("ZOOM_SAMPLE", 1);
180         zoom_y = defaults->get("ZOOMY", 64);
181         zoom_track = defaults->get("ZOOM_TRACK", 64);
182         red = defaults->get("RED", 0.0);
183         green = defaults->get("GREEN", 0.0);
184         blue = defaults->get("BLUE", 0.0);
185         automation_min = defaults->get("AUTOMATION_MIN", automation_min);
186         automation_max = defaults->get("AUTOMATION_MAX", automation_max);
187         return 0;
190 int LocalSession::save_defaults(Defaults *defaults)
192         defaults->update("LOOP_PLAYBACK", loop_playback);
193         defaults->update("LOOP_START", loop_start);
194         defaults->update("LOOP_END", loop_end);
195         defaults->update("SELECTIONSTART", selectionstart);
196         defaults->update("SELECTIONEND", selectionend);
197         defaults->update("TRACK_START", track_start);
198         defaults->update("VIEW_START", view_start);
199         defaults->update("ZOOM_SAMPLE", zoom_sample);
200         defaults->update("ZOOMY", zoom_y);
201         defaults->update("ZOOM_TRACK", zoom_track);
202         defaults->update("RED", red);
203         defaults->update("GREEN", green);
204         defaults->update("BLUE", blue);
205         defaults->update("AUTOMATION_MIN", automation_min);
206         defaults->update("AUTOMATION_MAX", automation_max);
207         return 0;
210 void LocalSession::set_selectionstart(double value)
212         this->selectionstart = value;
215 void LocalSession::set_selectionend(double value)
217         this->selectionend = value;
220 void LocalSession::set_inpoint(double value)
222         in_point = value;
225 void LocalSession::set_outpoint(double value)
227         out_point = value;
230 void LocalSession::unset_inpoint()
232         in_point = -1;
235 void LocalSession::unset_outpoint()
237         out_point = -1;
242 double LocalSession::get_selectionstart(int highlight_only)
244         if(highlight_only || !EQUIV(selectionstart, selectionend))
245                 return selectionstart;
247         if(in_point >= 0)
248                 return in_point;
249         else
250         if(out_point >= 0)
251                 return out_point;
252         else
253                 return selectionstart;
256 double LocalSession::get_selectionend(int highlight_only)
258         if(highlight_only || !EQUIV(selectionstart, selectionend))
259                 return selectionend;
261         if(out_point >= 0)
262                 return out_point;
263         else
264         if(in_point >= 0)
265                 return in_point;
266         else
267                 return selectionend;
270 double LocalSession::get_inpoint()
272         return in_point;
275 double LocalSession::get_outpoint()
277         return out_point;
280 int LocalSession::inpoint_valid()
282         return in_point >= 0;
285 int LocalSession::outpoint_valid()
287         return out_point >= 0;