4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "automation.h"
27 #include "floatauto.h"
29 #include "localsession.h"
32 static const char *xml_autogrouptypes_titlesmax[] =
34 "AUTOGROUPTYPE_AUDIO_FADE_MAX",
35 "AUTOGROUPTYPE_VIDEO_FADE_MAX",
36 "AUTOGROUPTYPE_ZOOM_MAX",
37 "AUTOGROUPTYPE_X_MAX",
38 "AUTOGROUPTYPE_Y_MAX",
39 "AUTOGROUPTYPE_INT255_MAX"
42 static const char *xml_autogrouptypes_titlesmin[] =
44 "AUTOGROUPTYPE_AUDIO_FADE_MIN",
45 "AUTOGROUPTYPE_VIDEO_FADE_MIN",
46 "AUTOGROUPTYPE_ZOOM_MIN",
47 "AUTOGROUPTYPE_X_MIN",
48 "AUTOGROUPTYPE_Y_MIN",
49 "AUTOGROUPTYPE_INT255_MIN"
53 LocalSession::LocalSession(EDL *edl)
57 selectionstart = selectionend = 0;
58 in_point = out_point = -1;
59 strcpy(folder, CLIP_FOLDER);
60 sprintf(clip_title, _("Program"));
61 strcpy(clip_notes, _("Hello world"));
64 loop_start = loop_end = 0;
67 preview_start = preview_end = 0;
68 zoom_sample = DEFAULT_ZOOM_TIME;
73 for(int i = 0; i < TOTAL_PANES; i++) {
78 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
79 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
81 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
82 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
84 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.001;
85 automation_maxs[AUTOGROUPTYPE_ZOOM] = 4;
87 automation_mins[AUTOGROUPTYPE_X] = -100;
88 automation_maxs[AUTOGROUPTYPE_X] = 100;
90 automation_mins[AUTOGROUPTYPE_Y] = -100;
91 automation_maxs[AUTOGROUPTYPE_Y] = 100;
93 automation_mins[AUTOGROUPTYPE_INT255] = 0;
94 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
96 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
98 floatauto_type = FloatAuto::SMOOTH;
100 red = green = blue = 0;
103 LocalSession::~LocalSession()
107 void LocalSession::copy_from(LocalSession *that)
109 strcpy(clip_title, that->clip_title);
110 strcpy(clip_notes, that->clip_notes);
111 strcpy(folder, that->folder);
112 in_point = that->in_point;
113 loop_playback = that->loop_playback;
114 loop_start = that->loop_start;
115 loop_end = that->loop_end;
116 out_point = that->out_point;
117 selectionend = that->selectionend;
118 selectionstart = that->selectionstart;
119 x_pane = that->x_pane;
120 y_pane = that->y_pane;
122 for(int i = 0; i < TOTAL_PANES; i++)
124 view_start[i] = that->view_start[i];
125 track_start[i] = that->track_start[i];
128 zoom_sample = that->zoom_sample;
129 zoom_y = that->zoom_y;
130 zoom_track = that->zoom_track;
131 preview_start = that->preview_start;
132 preview_end = that->preview_end;
136 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
137 automation_mins[i] = that->automation_mins[i];
138 automation_maxs[i] = that->automation_maxs[i];
140 floatauto_type = that->floatauto_type;
145 void LocalSession::save_xml(FileXML *file, double start)
147 file->tag.set_title("LOCALSESSION");
149 file->tag.set_property("IN_POINT", in_point - start);
150 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
151 file->tag.set_property("LOOP_START", loop_start - start);
152 file->tag.set_property("LOOP_END", loop_end - start);
153 file->tag.set_property("OUT_POINT", out_point - start);
154 file->tag.set_property("SELECTION_START", selectionstart - start);
155 file->tag.set_property("SELECTION_END", selectionend - start);
156 file->tag.set_property("CLIP_TITLE", clip_title);
157 file->tag.set_property("CLIP_NOTES", clip_notes);
158 file->tag.set_property("FOLDER", folder);
159 file->tag.set_property("X_PANE", x_pane);
160 file->tag.set_property("Y_PANE", y_pane);
162 char string[BCTEXTLEN];
163 for(int i = 0; i < TOTAL_PANES; i++)
165 sprintf(string, "TRACK_START%d", i);
166 file->tag.set_property(string, track_start[i]);
167 sprintf(string, "VIEW_START%d", i);
168 file->tag.set_property(string, view_start[i]);
171 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
172 //printf("EDLSession::save_session 1\n");
173 file->tag.set_property("ZOOMY", zoom_y);
174 //printf("EDLSession::save_session 1 %d\n", zoom_track);
175 file->tag.set_property("ZOOM_TRACK", zoom_track);
177 double preview_start = this->preview_start - start;
178 if(preview_start < 0) preview_start = 0;
179 double preview_end = this->preview_end - start;
180 if(preview_end < 0) preview_end = 0;
182 file->tag.set_property("PREVIEW_START", preview_start);
183 file->tag.set_property("PREVIEW_END", preview_end);
184 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
186 file->tag.set_property("RED", red);
187 file->tag.set_property("GREEN", green);
188 file->tag.set_property("BLUE", blue);
190 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
191 if (!Automation::autogrouptypes_fixedrange[i]) {
192 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
193 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
198 file->tag.set_title("/LOCALSESSION");
200 file->append_newline();
201 file->append_newline();
204 void LocalSession::synchronize_params(LocalSession *that)
206 loop_playback = that->loop_playback;
207 loop_start = that->loop_start;
208 loop_end = that->loop_end;
209 preview_start = that->preview_start;
210 preview_end = that->preview_end;
217 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
219 if(load_flags & LOAD_SESSION)
221 // moved to EDL::load_xml for paste to fill silence.
222 // clipboard_length = 0;
223 // Overwritten by MWindow::load_filenames
224 file->tag.get_property("CLIP_TITLE", clip_title);
225 file->tag.get_property("CLIP_NOTES", clip_notes);
226 file->tag.get_property("FOLDER", folder);
227 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
228 loop_start = file->tag.get_property("LOOP_START", (double)0);
229 loop_end = file->tag.get_property("LOOP_END", (double)0);
230 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
231 selectionend = file->tag.get_property("SELECTION_END", (double)0);
232 x_pane = file->tag.get_property("X_PANE", -1);
233 y_pane = file->tag.get_property("Y_PANE", -1);
236 char string[BCTEXTLEN];
237 for(int i = 0; i < TOTAL_PANES; i++)
239 sprintf(string, "TRACK_START%d", i);
240 track_start[i] = file->tag.get_property(string, track_start[i]);
241 sprintf(string, "VIEW_START%d", i);
242 view_start[i] = file->tag.get_property(string, view_start[i]);
245 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
246 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
247 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
248 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
249 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
250 red = file->tag.get_property("RED", red);
251 green = file->tag.get_property("GREEN", green);
252 blue = file->tag.get_property("BLUE", blue);
255 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
256 if (!Automation::autogrouptypes_fixedrange[i]) {
257 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
258 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
261 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
265 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
266 // expect - this is additionally important in keyboard-only editing in viewer window
267 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
269 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
270 selectionend = file->tag.get_property("SELECTION_END", (double)0);
275 if(load_flags & LOAD_TIMEBAR)
277 in_point = file->tag.get_property("IN_POINT", (double)-1);
278 out_point = file->tag.get_property("OUT_POINT", (double)-1);
282 void LocalSession::boundaries()
284 zoom_sample = MAX(1, zoom_sample);
287 int LocalSession::load_defaults(BC_Hash *defaults)
289 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
290 loop_start = defaults->get("LOOP_START", (double)0);
291 loop_end = defaults->get("LOOP_END", (double)0);
292 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
293 selectionend = defaults->get("SELECTIONEND", selectionend);
294 // track_start = defaults->get("TRACK_START", 0);
295 // view_start = defaults->get("VIEW_START", 0);
296 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
297 zoom_y = defaults->get("ZOOMY", 64);
298 zoom_track = defaults->get("ZOOM_TRACK", 64);
299 red = defaults->get("RED", 0.0);
300 green = defaults->get("GREEN", 0.0);
301 blue = defaults->get("BLUE", 0.0);
303 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
304 if (!Automation::autogrouptypes_fixedrange[i]) {
305 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
306 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
310 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
311 x_pane = defaults->get("X_PANE", x_pane);
312 y_pane = defaults->get("Y_PANE", y_pane);
317 int LocalSession::save_defaults(BC_Hash *defaults)
319 defaults->update("LOOP_PLAYBACK", loop_playback);
320 defaults->update("LOOP_START", loop_start);
321 defaults->update("LOOP_END", loop_end);
322 defaults->update("SELECTIONSTART", selectionstart);
323 defaults->update("SELECTIONEND", selectionend);
324 // defaults->update("TRACK_START", track_start);
325 // defaults->update("VIEW_START", view_start);
326 defaults->update("ZOOM_SAMPLE", zoom_sample);
327 defaults->update("ZOOMY", zoom_y);
328 defaults->update("ZOOM_TRACK", zoom_track);
329 defaults->update("RED", red);
330 defaults->update("GREEN", green);
331 defaults->update("BLUE", blue);
333 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
334 if (!Automation::autogrouptypes_fixedrange[i]) {
335 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
336 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
340 defaults->update("FLOATAUTO_TYPE", floatauto_type);
341 defaults->update("X_PANE", x_pane);
342 defaults->update("Y_PANE", y_pane);
346 void LocalSession::set_selectionstart(double value)
348 this->selectionstart = value;
351 void LocalSession::set_selectionend(double value)
353 this->selectionend = value;
356 void LocalSession::set_inpoint(double value)
361 void LocalSession::set_outpoint(double value)
366 void LocalSession::unset_inpoint()
371 void LocalSession::unset_outpoint()
376 void LocalSession::set_playback_start(double value)
378 if( playback_end < 0 ) return;
379 playback_start = value;
383 void LocalSession::set_playback_end(double value)
385 if( value < playback_start ) {
386 if( playback_end < 0 )
387 playback_end = playback_start;
388 playback_start = value;
390 else if( playback_end < 0 || value > playback_end )
391 playback_end = value;
395 double LocalSession::get_selectionstart(int highlight_only)
397 if(highlight_only || !EQUIV(selectionstart, selectionend))
398 return selectionstart;
406 return selectionstart;
409 double LocalSession::get_selectionend(int highlight_only)
411 if(highlight_only || !EQUIV(selectionstart, selectionend))
423 double LocalSession::get_inpoint()
428 double LocalSession::get_outpoint()
433 int LocalSession::inpoint_valid()
435 return in_point >= 0;
438 int LocalSession::outpoint_valid()
440 return out_point >= 0;