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"
23 #include "awindowgui.h"
27 #include "filesystem.h"
29 #include "floatauto.h"
31 #include "localsession.h"
34 static const char *xml_autogrouptypes_titlesmax[] =
36 "AUTOGROUPTYPE_AUDIO_FADE_MAX",
37 "AUTOGROUPTYPE_VIDEO_FADE_MAX",
38 "AUTOGROUPTYPE_ZOOM_MAX",
39 "AUTOGROUPTYPE_SPEED_MAX",
40 "AUTOGROUPTYPE_X_MAX",
41 "AUTOGROUPTYPE_Y_MAX",
42 "AUTOGROUPTYPE_INT255_MAX"
45 static const char *xml_autogrouptypes_titlesmin[] =
47 "AUTOGROUPTYPE_AUDIO_FADE_MIN",
48 "AUTOGROUPTYPE_VIDEO_FADE_MIN",
49 "AUTOGROUPTYPE_ZOOM_MIN",
50 "AUTOGROUPTYPE_SPEED_MIN",
51 "AUTOGROUPTYPE_X_MIN",
52 "AUTOGROUPTYPE_Y_MIN",
53 "AUTOGROUPTYPE_INT255_MIN"
57 LocalSession::LocalSession(EDL *edl)
61 selectionstart = selectionend = 0;
62 in_point = out_point = -1;
63 sprintf(clip_title, _("Program"));
64 strcpy(clip_notes, _("Hello world"));
65 strcpy(clip_icon, "");
69 loop_start = loop_end = 0;
72 preview_start = 0; preview_end = -1;
73 zoom_sample = DEFAULT_ZOOM_TIME;
78 for(int i = 0; i < TOTAL_PANES; i++) {
83 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
84 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
86 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
87 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
89 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.005;
90 automation_maxs[AUTOGROUPTYPE_ZOOM] = 5.000;
92 automation_mins[AUTOGROUPTYPE_SPEED] = 0.005;
93 automation_maxs[AUTOGROUPTYPE_SPEED] = 5.000;
95 automation_mins[AUTOGROUPTYPE_X] = -100;
96 automation_maxs[AUTOGROUPTYPE_X] = 100;
98 automation_mins[AUTOGROUPTYPE_Y] = -100;
99 automation_maxs[AUTOGROUPTYPE_Y] = 100;
101 automation_mins[AUTOGROUPTYPE_INT255] = 0;
102 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
104 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
105 zoombar_showautocolor = -1;
107 floatauto_type = FloatAuto::SMOOTH;
109 red = green = blue = 0;
110 red_max = green_max = blue_max = 0;
115 LocalSession::~LocalSession()
119 void LocalSession::copy_from(LocalSession *that)
121 strcpy(clip_title, that->clip_title);
122 strcpy(clip_notes, that->clip_notes);
123 strcpy(clip_icon, that->clip_icon);
124 in_point = that->in_point;
125 loop_playback = that->loop_playback;
126 loop_start = that->loop_start;
127 loop_end = that->loop_end;
128 out_point = that->out_point;
129 selectionend = that->selectionend;
130 selectionstart = that->selectionstart;
131 x_pane = that->x_pane;
132 y_pane = that->y_pane;
134 for(int i = 0; i < TOTAL_PANES; i++)
136 view_start[i] = that->view_start[i];
137 track_start[i] = that->track_start[i];
140 zoom_sample = that->zoom_sample;
141 zoom_y = that->zoom_y;
142 zoom_track = that->zoom_track;
143 preview_start = that->preview_start;
144 preview_end = that->preview_end;
148 red_max = that->red_max;
149 green_max = that->green_max;
150 blue_max = that->blue_max;
151 use_max = that->use_max;
152 solo_track_id = that->solo_track_id;
154 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
155 automation_mins[i] = that->automation_mins[i];
156 automation_maxs[i] = that->automation_maxs[i];
158 floatauto_type = that->floatauto_type;
161 void LocalSession::save_xml(FileXML *file, double start)
163 file->tag.set_title("LOCALSESSION");
165 file->tag.set_property("IN_POINT", in_point - start);
166 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
167 file->tag.set_property("LOOP_START", loop_start - start);
168 file->tag.set_property("LOOP_END", loop_end - start);
169 file->tag.set_property("OUT_POINT", out_point - start);
170 file->tag.set_property("SELECTION_START", selectionstart - start);
171 file->tag.set_property("SELECTION_END", selectionend - start);
172 file->tag.set_property("CLIP_TITLE", clip_title);
173 file->tag.set_property("CLIP_ICON", clip_icon);
174 file->tag.set_property("X_PANE", x_pane);
175 file->tag.set_property("Y_PANE", y_pane);
177 char string[BCTEXTLEN];
178 for(int i = 0; i < TOTAL_PANES; i++)
180 sprintf(string, "TRACK_START%d", i);
181 file->tag.set_property(string, track_start[i]);
182 sprintf(string, "VIEW_START%d", i);
183 file->tag.set_property(string, view_start[i]);
186 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
187 //printf("EDLSession::save_session 1\n");
188 file->tag.set_property("ZOOMY", zoom_y);
189 //printf("EDLSession::save_session 1 %d\n", zoom_track);
190 file->tag.set_property("ZOOM_TRACK", zoom_track);
192 double preview_start = this->preview_start - start;
193 if( preview_start < 0 ) preview_start = 0;
194 double preview_end = this->preview_end - start;
195 if( preview_end < preview_start ) preview_end = -1;
196 file->tag.set_property("PREVIEW_START", preview_start);
197 file->tag.set_property("PREVIEW_END", preview_end);
198 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
200 file->tag.set_property("RED", red);
201 file->tag.set_property("GREEN", green);
202 file->tag.set_property("BLUE", blue);
203 file->tag.set_property("RED_MAX", red_max);
204 file->tag.set_property("GREEN_MAX", green_max);
205 file->tag.set_property("BLUE_MAX", blue_max);
206 file->tag.set_property("USE_MAX", use_max);
208 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
209 if (!Automation::autogrouptypes_fixedrange[i]) {
210 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
211 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
215 file->append_newline();
217 //this used to be a property, now used as tag member
218 // file->tag.set_property("CLIP_NOTES", clip_notes);
219 file->tag.set_title("CLIP_NOTES"); file->append_tag();
220 file->append_text(clip_notes);
221 file->tag.set_title("/CLIP_NOTES"); file->append_tag();
222 file->append_newline();
224 file->tag.set_title("/LOCALSESSION");
226 file->append_newline();
227 file->append_newline();
230 void LocalSession::synchronize_params(LocalSession *that)
232 loop_playback = that->loop_playback;
233 loop_start = that->loop_start;
234 loop_end = that->loop_end;
235 preview_start = that->preview_start;
236 preview_end = that->preview_end;
240 red_max = that->red_max;
241 green_max = that->green_max;
242 blue_max = that->blue_max;
243 if( solo_track_id < 0 || that->solo_track_id < 0 )
244 solo_track_id = that->solo_track_id;
248 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
250 if(load_flags & LOAD_SESSION)
252 // moved to EDL::load_xml for paste to fill silence.
253 // clipboard_length = 0;
254 // Overwritten by MWindow::load_filenames
255 file->tag.get_property("CLIP_TITLE", clip_title);
257 file->tag.get_property("CLIP_NOTES", clip_notes);
259 file->tag.get_property("CLIP_ICON", clip_icon);
260 // kludge if possible
261 if( !clip_icon[0] ) {
262 char *cp = clip_notes;
263 int year, mon, mday, hour, min, sec;
264 while( *cp && *cp++ != ':' );
265 if( *cp && sscanf(cp, "%d/%02d/%02d %02d:%02d:%02d,",
266 &year, &mon, &mday, &hour, &min, &sec) == 6 ) {
267 sprintf(clip_icon, "clip_%02d%02d%02d-%02d%02d%02d.png",
268 year, mon, mday, hour, min, sec);
271 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
272 loop_start = file->tag.get_property("LOOP_START", (double)0);
273 loop_end = file->tag.get_property("LOOP_END", (double)0);
274 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
275 selectionend = file->tag.get_property("SELECTION_END", (double)0);
276 x_pane = file->tag.get_property("X_PANE", -1);
277 y_pane = file->tag.get_property("Y_PANE", -1);
280 char string[BCTEXTLEN];
281 for(int i = 0; i < TOTAL_PANES; i++)
283 sprintf(string, "TRACK_START%d", i);
284 track_start[i] = file->tag.get_property(string, track_start[i]);
285 sprintf(string, "VIEW_START%d", i);
286 view_start[i] = file->tag.get_property(string, view_start[i]);
289 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
290 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
291 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
292 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
293 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
294 red = file->tag.get_property("RED", red);
295 green = file->tag.get_property("GREEN", green);
296 blue = file->tag.get_property("BLUE", blue);
297 red_max = file->tag.get_property("RED_MAX", red_max);
298 green_max = file->tag.get_property("GREEN_MAX", green_max);
299 blue_max = file->tag.get_property("BLUE_MAX", blue_max);
300 use_max = file->tag.get_property("USE_MAX", use_max);
302 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
303 if (!Automation::autogrouptypes_fixedrange[i]) {
304 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
305 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
308 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
312 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
313 // expect - this is additionally important in keyboard-only editing in viewer window
314 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
316 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
317 selectionend = file->tag.get_property("SELECTION_END", (double)0);
322 if(load_flags & LOAD_TIMEBAR)
324 in_point = file->tag.get_property("IN_POINT", (double)-1);
325 out_point = file->tag.get_property("OUT_POINT", (double)-1);
328 while( !file->read_tag() ) {
329 if( file->tag.title_is("/LOCALSESSION") ) break;
330 if( file->tag.title_is("CLIP_NOTES") ) {
332 file->read_text_until("/CLIP_NOTES", ¬es, 1);
333 memset(clip_notes, 0, sizeof(clip_notes));
334 strncpy(clip_notes, notes.cstr(), sizeof(clip_notes)-1);
339 void LocalSession::boundaries()
341 zoom_sample = MAX(1, zoom_sample);
344 int LocalSession::load_defaults(BC_Hash *defaults)
346 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
347 loop_start = defaults->get("LOOP_START", (double)0);
348 loop_end = defaults->get("LOOP_END", (double)0);
349 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
350 selectionend = defaults->get("SELECTIONEND", selectionend);
351 // track_start = defaults->get("TRACK_START", 0);
352 // view_start = defaults->get("VIEW_START", 0);
353 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
354 zoom_y = defaults->get("ZOOMY", 64);
355 zoom_track = defaults->get("ZOOM_TRACK", 64);
356 red = defaults->get("RED", 0.0);
357 green = defaults->get("GREEN", 0.0);
358 blue = defaults->get("BLUE", 0.0);
359 red_max = defaults->get("RED_MAX", 0.0);
360 green_max = defaults->get("GREEN_MAX", 0.0);
361 blue_max = defaults->get("BLUE_MAX", 0.0);
362 use_max = defaults->get("USE_MAX", 0);
364 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
365 if (!Automation::autogrouptypes_fixedrange[i]) {
366 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
367 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
371 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
372 x_pane = defaults->get("X_PANE", x_pane);
373 y_pane = defaults->get("Y_PANE", y_pane);
378 int LocalSession::save_defaults(BC_Hash *defaults)
380 defaults->update("LOOP_PLAYBACK", loop_playback);
381 defaults->update("LOOP_START", loop_start);
382 defaults->update("LOOP_END", loop_end);
383 defaults->update("SELECTIONSTART", selectionstart);
384 defaults->update("SELECTIONEND", selectionend);
385 // defaults->update("TRACK_START", track_start);
386 // defaults->update("VIEW_START", view_start);
387 defaults->update("ZOOM_SAMPLE", zoom_sample);
388 defaults->update("ZOOMY", zoom_y);
389 defaults->update("ZOOM_TRACK", zoom_track);
390 defaults->update("RED", red);
391 defaults->update("GREEN", green);
392 defaults->update("BLUE", blue);
393 defaults->update("RED_MAX", red_max);
394 defaults->update("GREEN_MAX", green_max);
395 defaults->update("BLUE_MAX", blue_max);
396 defaults->update("USE_MAX", use_max);
398 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
399 if (!Automation::autogrouptypes_fixedrange[i]) {
400 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
401 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
405 defaults->update("FLOATAUTO_TYPE", floatauto_type);
406 defaults->update("X_PANE", x_pane);
407 defaults->update("Y_PANE", y_pane);
411 void LocalSession::set_selectionstart(double value)
413 this->selectionstart = value;
416 void LocalSession::set_selectionend(double value)
418 this->selectionend = value;
421 void LocalSession::set_inpoint(double value)
426 void LocalSession::set_outpoint(double value)
431 void LocalSession::unset_inpoint()
436 void LocalSession::unset_outpoint()
441 void LocalSession::set_playback_start(double value)
443 if( playback_end < 0 ) return;
444 playback_start = value;
448 void LocalSession::set_playback_end(double value)
450 if( value < playback_start ) {
451 if( playback_end < 0 )
452 playback_end = playback_start;
453 playback_start = value;
455 else if( playback_end < 0 || value > playback_end )
456 playback_end = value;
460 double LocalSession::get_selectionstart(int highlight_only)
462 if(highlight_only || !EQUIV(selectionstart, selectionend))
463 return selectionstart;
471 return selectionstart;
474 double LocalSession::get_selectionend(int highlight_only)
476 if(highlight_only || !EQUIV(selectionstart, selectionend))
488 double LocalSession::get_inpoint()
493 double LocalSession::get_outpoint()
498 int LocalSession::inpoint_valid()
500 return in_point >= 0;
503 int LocalSession::outpoint_valid()
505 return out_point >= 0;