prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.0 / 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 "clip.h"
23 #include "bchash.h"
24 #include "edl.h"
25 #include "filexml.h"
26 #include "floatauto.h"
27 #include "language.h"
28 #include "localsession.h"
29
30
31
32
33
34 LocalSession::LocalSession(EDL *edl)
35 {
36         this->edl = edl;
37
38         selectionstart = selectionend = 0;
39         in_point = out_point = -1;
40         strcpy(folder, CLIP_FOLDER);
41         sprintf(clip_title, _("Program"));
42         strcpy(clip_notes, _("Hello world"));
43         clipboard_length = 0;
44         preview_start = preview_end = 0;
45         loop_playback = 0;
46         loop_start = 0;
47         loop_end = 0;
48         zoom_sample = 0;
49         zoom_y = 0;
50         zoom_track = 0;
51         x_pane = -1;
52         y_pane = -1;
53         
54         for(int i = 0; i < TOTAL_PANES; i++)
55         {
56                 view_start[i] = 0;
57                 track_start[i] = 0;
58         }
59         
60         automation_min = -10;
61         automation_max = 10;
62         floatauto_type = Auto::BEZIER;
63         red = green = blue = 0;
64 }
65
66 LocalSession::~LocalSession()
67 {
68 }
69
70 void LocalSession::copy_from(LocalSession *that)
71 {
72         strcpy(clip_title, that->clip_title);
73         strcpy(clip_notes, that->clip_notes);
74         strcpy(folder, that->folder);
75         in_point = that->in_point;
76         loop_playback = that->loop_playback;
77         loop_start = that->loop_start;
78         loop_end = that->loop_end;
79         out_point = that->out_point;
80         selectionend = that->selectionend;
81         selectionstart = that->selectionstart;
82         x_pane = that->x_pane;
83         y_pane = that->y_pane;
84
85         for(int i = 0; i < TOTAL_PANES; i++)
86         {
87                 view_start[i] = that->view_start[i];
88                 track_start[i] = that->track_start[i];
89         }
90         
91         zoom_sample = that->zoom_sample;
92         zoom_y = that->zoom_y;
93         zoom_track = that->zoom_track;
94         preview_start = that->preview_start;
95         preview_end = that->preview_end;
96         red = that->red;
97         green = that->green;
98         automation_min = that->automation_min;
99         automation_max = that->automation_max;
100         floatauto_type = that->floatauto_type;
101         blue = that->blue;
102 }
103
104 void LocalSession::save_xml(FileXML *file, double start)
105 {
106         file->tag.set_title("LOCALSESSION");
107
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("X_PANE", x_pane);
119         file->tag.set_property("Y_PANE", y_pane);
120
121         char string[BCTEXTLEN];
122         for(int i = 0; i < TOTAL_PANES; i++)
123         {
124                 sprintf(string, "TRACK_START%d", i);
125                 file->tag.set_property(string, track_start[i]);
126                 sprintf(string, "VIEW_START%d", i);
127                 file->tag.set_property(string, view_start[i]);
128         }
129
130         file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
131 //printf("EDLSession::save_session 1\n");
132         file->tag.set_property("ZOOMY", zoom_y);
133 //printf("EDLSession::save_session 1 %d\n", zoom_track);
134         file->tag.set_property("ZOOM_TRACK", zoom_track);
135
136         double preview_start = this->preview_start - start;
137         if(preview_start < 0) preview_start = 0;
138         double preview_end = this->preview_end - start;
139         if(preview_end < 0) preview_end = 0;
140         
141         file->tag.set_property("PREVIEW_START", preview_start);
142         file->tag.set_property("PREVIEW_END", preview_end);
143
144         file->tag.set_property("RED", red);
145         file->tag.set_property("GREEN", green);
146         file->tag.set_property("BLUE", blue);
147         file->tag.set_property("AUTOMATION_MIN", automation_min);
148         file->tag.set_property("AUTOMATION_MAX", automation_max);
149         file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
150         file->append_tag();
151         file->append_newline();
152         file->append_newline();
153 }
154
155 void LocalSession::synchronize_params(LocalSession *that)
156 {
157         loop_playback = that->loop_playback;
158         loop_start = that->loop_start;
159         loop_end = that->loop_end;
160         preview_start = that->preview_start;
161         preview_end = that->preview_end;
162         red = that->red;
163         green = that->green;
164         blue = that->blue;
165 }
166
167
168 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
169 {
170         if(load_flags & LOAD_SESSION)
171         {
172 // moved to EDL::load_xml for paste to fill silence.
173 //              clipboard_length = 0;
174 // Overwritten by MWindow::load_filenames       
175                 file->tag.get_property("CLIP_TITLE", clip_title);
176                 file->tag.get_property("CLIP_NOTES", clip_notes);
177                 file->tag.get_property("FOLDER", folder);
178                 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
179                 loop_start = file->tag.get_property("LOOP_START", (double)0);
180                 loop_end = file->tag.get_property("LOOP_END", (double)0);
181                 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
182                 selectionend = file->tag.get_property("SELECTION_END", (double)0);
183                 x_pane = file->tag.get_property("X_PANE", -1);
184                 y_pane = file->tag.get_property("Y_PANE", -1);
185
186
187                 char string[BCTEXTLEN];
188                 for(int i = 0; i < TOTAL_PANES; i++)
189                 {
190                         sprintf(string, "TRACK_START%d", i);
191                         track_start[i] = file->tag.get_property(string, track_start[i]);
192                         sprintf(string, "VIEW_START%d", i);
193                         view_start[i] = file->tag.get_property(string, view_start[i]);
194                 }
195
196                 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
197                 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
198                 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
199                 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
200                 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
201                 red = file->tag.get_property("RED", red);
202                 green = file->tag.get_property("GREEN", green);
203                 blue = file->tag.get_property("BLUE", blue);
204                 automation_min = file->tag.get_property("AUTOMATION_MIN", automation_min);
205                 automation_max = file->tag.get_property("AUTOMATION_MAX", automation_max);
206                 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
207         }
208
209
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         }
217
218
219
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         }
225 }
226
227 void LocalSession::boundaries()
228 {
229         zoom_sample = MAX(1, zoom_sample);
230 }
231
232 int LocalSession::load_defaults(BC_Hash *defaults)
233 {
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);
247         automation_min = defaults->get("AUTOMATION_MIN", automation_min);
248         automation_max = defaults->get("AUTOMATION_MAX", automation_max);
249         floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
250         x_pane = defaults->get("X_PANE", x_pane);
251         y_pane = defaults->get("Y_PANE", y_pane);
252         return 0;
253 }
254
255 int LocalSession::save_defaults(BC_Hash *defaults)
256 {
257         defaults->update("LOOP_PLAYBACK", loop_playback);
258         defaults->update("LOOP_START", loop_start);
259         defaults->update("LOOP_END", loop_end);
260         defaults->update("SELECTIONSTART", selectionstart);
261         defaults->update("SELECTIONEND", selectionend);
262 //      defaults->update("TRACK_START", track_start);
263 //      defaults->update("VIEW_START", view_start);
264         defaults->update("ZOOM_SAMPLE", zoom_sample);
265         defaults->update("ZOOMY", zoom_y);
266         defaults->update("ZOOM_TRACK", zoom_track);
267         defaults->update("RED", red);
268         defaults->update("GREEN", green);
269         defaults->update("BLUE", blue);
270         defaults->update("AUTOMATION_MIN", automation_min);
271         defaults->update("AUTOMATION_MAX", automation_max);
272         defaults->update("FLOATAUTO_TYPE", floatauto_type);
273         defaults->update("X_PANE", x_pane);
274         defaults->update("Y_PANE", y_pane);
275         return 0;
276 }
277
278 void LocalSession::set_selectionstart(double value)
279 {
280         this->selectionstart = value;
281 }
282
283 void LocalSession::set_selectionend(double value)
284 {
285         this->selectionend = value;
286 }
287
288 void LocalSession::set_inpoint(double value)
289 {
290         in_point = value;
291 }
292
293 void LocalSession::set_outpoint(double value)
294 {
295         out_point = value;
296 }
297
298 void LocalSession::unset_inpoint()
299 {
300         in_point = -1;
301 }
302
303 void LocalSession::unset_outpoint()
304 {
305         out_point = -1;
306 }
307
308
309
310 double LocalSession::get_selectionstart(int highlight_only)
311 {
312         if(highlight_only || !EQUIV(selectionstart, selectionend))
313                 return selectionstart;
314
315         if(in_point >= 0)
316                 return in_point;
317         else
318         if(out_point >= 0)
319                 return out_point;
320         else
321                 return selectionstart;
322 }
323
324 double LocalSession::get_selectionend(int highlight_only)
325 {
326         if(highlight_only || !EQUIV(selectionstart, selectionend))
327                 return selectionend;
328
329         if(out_point >= 0)
330                 return out_point;
331         else
332         if(in_point >= 0)
333                 return in_point;
334         else
335                 return selectionend;
336 }
337
338 double LocalSession::get_inpoint()
339 {
340         return in_point;
341 }
342
343 double LocalSession::get_outpoint()
344 {
345         return out_point;
346 }
347
348 int LocalSession::inpoint_valid()
349 {
350         return in_point >= 0;
351 }
352
353 int LocalSession::outpoint_valid()
354 {
355         return out_point >= 0;
356 }
357
358
359
360