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 "edlsession.h"
28 #include "filesystem.h"
30 #include "floatauto.h"
32 #include "localsession.h"
35 static const char *xml_autogrouptypes_titlesmax[] =
37 "AUTOGROUPTYPE_AUDIO_FADE_MAX",
38 "AUTOGROUPTYPE_VIDEO_FADE_MAX",
39 "AUTOGROUPTYPE_ZOOM_MAX",
40 "AUTOGROUPTYPE_SPEED_MAX",
41 "AUTOGROUPTYPE_X_MAX",
42 "AUTOGROUPTYPE_Y_MAX",
43 "AUTOGROUPTYPE_INT255_MAX"
46 static const char *xml_autogrouptypes_titlesmin[] =
48 "AUTOGROUPTYPE_AUDIO_FADE_MIN",
49 "AUTOGROUPTYPE_VIDEO_FADE_MIN",
50 "AUTOGROUPTYPE_ZOOM_MIN",
51 "AUTOGROUPTYPE_SPEED_MIN",
52 "AUTOGROUPTYPE_X_MIN",
53 "AUTOGROUPTYPE_Y_MIN",
54 "AUTOGROUPTYPE_INT255_MIN"
58 LocalSession::LocalSession(EDL *edl)
62 selectionstart = selectionend = 0;
63 in_point = out_point = -1;
64 sprintf(clip_title, _("Program"));
65 strcpy(clip_notes, _("Hello world"));
66 strcpy(clip_icon, "");
70 loop_start = loop_end = 0;
73 preview_start = 0; preview_end = -1;
74 zoom_sample = DEFAULT_ZOOM_TIME;
80 for(int i = 0; i < TOTAL_PANES; i++) {
86 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
87 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
88 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
89 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
90 automation_mins[AUTOGROUPTYPE_SPEED] = SPEED_MIN;
91 automation_maxs[AUTOGROUPTYPE_SPEED] = 5.000;
92 automation_mins[AUTOGROUPTYPE_INT255] = 0;
93 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
95 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
96 zoombar_showautocolor = -1;
98 floatauto_type = FloatAuto::SMOOTH;
100 red = green = blue = 0;
101 red_max = green_max = blue_max = 0;
106 LocalSession::~LocalSession()
110 void LocalSession::copy_from(LocalSession *that)
112 strcpy(clip_title, that->clip_title);
113 strcpy(clip_notes, that->clip_notes);
114 strcpy(clip_icon, that->clip_icon);
115 in_point = that->in_point;
116 loop_playback = that->loop_playback;
117 loop_start = that->loop_start;
118 loop_end = that->loop_end;
119 out_point = that->out_point;
120 selectionend = that->selectionend;
121 selectionstart = that->selectionstart;
122 x_pane = that->x_pane;
123 y_pane = that->y_pane;
125 for(int i = 0; i < TOTAL_PANES; i++)
127 view_start[i] = that->view_start[i];
128 track_start[i] = that->track_start[i];
131 zoom_sample = that->zoom_sample;
132 zoom_y = that->zoom_y;
133 zoom_atrack = that->zoom_atrack;
134 zoom_vtrack = that->zoom_vtrack;
135 preview_start = that->preview_start;
136 preview_end = that->preview_end;
140 red_max = that->red_max;
141 green_max = that->green_max;
142 blue_max = that->blue_max;
143 use_max = that->use_max;
144 solo_track_id = that->solo_track_id;
146 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
147 automation_mins[i] = that->automation_mins[i];
148 automation_maxs[i] = that->automation_maxs[i];
150 floatauto_type = that->floatauto_type;
153 void LocalSession::save_xml(FileXML *file, double start)
155 file->tag.set_title("LOCALSESSION");
157 file->tag.set_property("IN_POINT", in_point - start);
158 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
159 file->tag.set_property("LOOP_START", loop_start - start);
160 file->tag.set_property("LOOP_END", loop_end - start);
161 file->tag.set_property("OUT_POINT", out_point - start);
162 file->tag.set_property("SELECTION_START", selectionstart - start);
163 file->tag.set_property("SELECTION_END", selectionend - start);
164 file->tag.set_property("CLIP_TITLE", clip_title);
165 file->tag.set_property("CLIP_ICON", clip_icon);
166 file->tag.set_property("X_PANE", x_pane);
167 file->tag.set_property("Y_PANE", y_pane);
169 char string[BCTEXTLEN];
170 for(int i = 0; i < TOTAL_PANES; i++)
172 sprintf(string, "TRACK_START%d", i);
173 file->tag.set_property(string, track_start[i]);
174 sprintf(string, "VIEW_START%d", i);
175 file->tag.set_property(string, view_start[i]);
178 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
179 //printf("EDLSession::save_session 1\n");
180 file->tag.set_property("ZOOMY", zoom_y);
181 file->tag.set_property("ZOOM_ATRACK", zoom_atrack);
182 file->tag.set_property("ZOOM_VTRACK", zoom_vtrack);
184 double preview_start = this->preview_start - start;
185 if( preview_start < 0 ) preview_start = 0;
186 double preview_end = this->preview_end - start;
187 if( preview_end < preview_start ) preview_end = -1;
188 file->tag.set_property("PREVIEW_START", preview_start);
189 file->tag.set_property("PREVIEW_END", preview_end);
190 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
192 file->tag.set_property("RED", red);
193 file->tag.set_property("GREEN", green);
194 file->tag.set_property("BLUE", blue);
195 file->tag.set_property("RED_MAX", red_max);
196 file->tag.set_property("GREEN_MAX", green_max);
197 file->tag.set_property("BLUE_MAX", blue_max);
198 file->tag.set_property("USE_MAX", use_max);
200 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
201 if (!Automation::autogrouptypes_fixedrange[i]) {
202 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
203 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
207 file->append_newline();
209 //this used to be a property, now used as tag member
210 // file->tag.set_property("CLIP_NOTES", clip_notes);
211 file->tag.set_title("CLIP_NOTES"); file->append_tag();
212 file->append_text(clip_notes);
213 file->tag.set_title("/CLIP_NOTES"); file->append_tag();
214 file->append_newline();
216 file->tag.set_title("/LOCALSESSION");
218 file->append_newline();
219 file->append_newline();
222 void LocalSession::synchronize_params(LocalSession *that)
224 loop_playback = that->loop_playback;
225 loop_start = that->loop_start;
226 loop_end = that->loop_end;
227 preview_start = that->preview_start;
228 preview_end = that->preview_end;
232 red_max = that->red_max;
233 green_max = that->green_max;
234 blue_max = that->blue_max;
235 if( solo_track_id < 0 || that->solo_track_id < 0 )
236 solo_track_id = that->solo_track_id;
240 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
242 if(load_flags & LOAD_SESSION)
244 // moved to EDL::load_xml for paste to fill silence.
245 // clipboard_length = 0;
246 // Overwritten by MWindow::load_filenames
247 file->tag.get_property("CLIP_TITLE", clip_title);
249 file->tag.get_property("CLIP_NOTES", clip_notes);
251 file->tag.get_property("CLIP_ICON", clip_icon);
252 // kludge if possible
253 if( !clip_icon[0] ) {
254 char *cp = clip_notes;
255 int year, mon, mday, hour, min, sec;
256 while( *cp && *cp++ != ':' );
257 if( *cp && sscanf(cp, "%d/%02d/%02d %02d:%02d:%02d,",
258 &year, &mon, &mday, &hour, &min, &sec) == 6 ) {
259 sprintf(clip_icon, "clip_%02d%02d%02d-%02d%02d%02d.png",
260 year, mon, mday, hour, min, sec);
263 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
264 loop_start = file->tag.get_property("LOOP_START", (double)0);
265 loop_end = file->tag.get_property("LOOP_END", (double)0);
266 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
267 selectionend = file->tag.get_property("SELECTION_END", (double)0);
268 x_pane = file->tag.get_property("X_PANE", -1);
269 y_pane = file->tag.get_property("Y_PANE", -1);
272 char string[BCTEXTLEN];
273 for(int i = 0; i < TOTAL_PANES; i++)
275 sprintf(string, "TRACK_START%d", i);
276 track_start[i] = file->tag.get_property(string, track_start[i]);
277 sprintf(string, "VIEW_START%d", i);
278 view_start[i] = file->tag.get_property(string, view_start[i]);
281 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
282 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
283 int64_t zoom_track = file->tag.get_property("ZOOM_TRACK", 0);
284 if( zoom_track > 0 ) zoom_atrack = zoom_vtrack = zoom_track;
285 zoom_atrack = file->tag.get_property("ZOOM_ATRACK", zoom_atrack);
286 zoom_vtrack = file->tag.get_property("ZOOM_VTRACK", zoom_vtrack);
287 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
288 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
289 red = file->tag.get_property("RED", red);
290 green = file->tag.get_property("GREEN", green);
291 blue = file->tag.get_property("BLUE", blue);
292 red_max = file->tag.get_property("RED_MAX", red_max);
293 green_max = file->tag.get_property("GREEN_MAX", green_max);
294 blue_max = file->tag.get_property("BLUE_MAX", blue_max);
295 use_max = file->tag.get_property("USE_MAX", use_max);
297 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
298 if (!Automation::autogrouptypes_fixedrange[i]) {
299 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
300 AUTOMATIONCLAMPS(automation_mins[i], i);
301 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
302 AUTOMATIONCLAMPS(automation_maxs[i], i);
305 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
309 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
310 // expect - this is additionally important in keyboard-only editing in viewer window
311 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
313 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
314 selectionend = file->tag.get_property("SELECTION_END", (double)0);
319 if(load_flags & LOAD_TIMEBAR)
321 in_point = file->tag.get_property("IN_POINT", (double)-1);
322 out_point = file->tag.get_property("OUT_POINT", (double)-1);
325 while( !file->read_tag() ) {
326 if( file->tag.title_is("/LOCALSESSION") ) break;
327 if( file->tag.title_is("CLIP_NOTES") ) {
329 file->read_text_until("/CLIP_NOTES", ¬es, 1);
330 memset(clip_notes, 0, sizeof(clip_notes));
331 strncpy(clip_notes, notes.cstr(), sizeof(clip_notes)-1);
336 void LocalSession::boundaries()
338 zoom_sample = MAX(1, zoom_sample);
341 int LocalSession::load_defaults(BC_Hash *defaults)
343 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
344 loop_start = defaults->get("LOOP_START", (double)0);
345 loop_end = defaults->get("LOOP_END", (double)0);
346 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
347 selectionend = defaults->get("SELECTIONEND", selectionend);
348 // track_start = defaults->get("TRACK_START", 0);
349 // view_start = defaults->get("VIEW_START", 0);
350 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
351 zoom_y = defaults->get("ZOOMY", DEFAULT_ZOOM_TRACK);
352 int64_t zoom_track = defaults->get("ZOOM_TRACK", 0);
353 if( zoom_track == 0 ) zoom_track = DEFAULT_ZOOM_TRACK;
354 zoom_atrack = defaults->get("ZOOM_ATRACK", zoom_track);
355 zoom_vtrack = defaults->get("ZOOM_VTRACK", zoom_track);
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 AUTOMATIONCLAMPS(automation_mins[i], i);
368 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
369 AUTOMATIONCLAMPS(automation_maxs[i], i);
373 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
374 x_pane = defaults->get("X_PANE", x_pane);
375 y_pane = defaults->get("Y_PANE", y_pane);
380 int LocalSession::save_defaults(BC_Hash *defaults)
382 defaults->update("LOOP_PLAYBACK", loop_playback);
383 defaults->update("LOOP_START", loop_start);
384 defaults->update("LOOP_END", loop_end);
385 defaults->update("SELECTIONSTART", selectionstart);
386 defaults->update("SELECTIONEND", selectionend);
387 // defaults->update("TRACK_START", track_start);
388 // defaults->update("VIEW_START", view_start);
389 defaults->update("ZOOM_SAMPLE", zoom_sample);
390 defaults->update("ZOOMY", zoom_y);
391 defaults->update("ZOOM_ATRACK", zoom_atrack);
392 defaults->update("ZOOM_VTRACK", zoom_vtrack);
393 defaults->update("RED", red);
394 defaults->update("GREEN", green);
395 defaults->update("BLUE", blue);
396 defaults->update("RED_MAX", red_max);
397 defaults->update("GREEN_MAX", green_max);
398 defaults->update("BLUE_MAX", blue_max);
399 defaults->update("USE_MAX", use_max);
401 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
402 if (!Automation::autogrouptypes_fixedrange[i]) {
403 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
404 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
408 defaults->update("FLOATAUTO_TYPE", floatauto_type);
409 defaults->update("X_PANE", x_pane);
410 defaults->update("Y_PANE", y_pane);
414 void LocalSession::set_selectionstart(double value)
416 this->selectionstart = value;
419 void LocalSession::set_selectionend(double value)
421 this->selectionend = value;
424 void LocalSession::set_inpoint(double value)
429 void LocalSession::set_outpoint(double value)
434 void LocalSession::unset_inpoint()
439 void LocalSession::unset_outpoint()
444 void LocalSession::set_playback_start(double value)
446 if( playback_end < 0 ) return;
447 playback_start = value;
451 void LocalSession::set_playback_end(double value)
453 if( value < playback_start ) {
454 if( playback_end < 0 )
455 playback_end = playback_start;
456 playback_start = value;
458 else if( playback_end < 0 || value > playback_end )
459 playback_end = value;
463 double LocalSession::get_selectionstart(int highlight_only)
465 if(highlight_only || !EQUIV(selectionstart, selectionend))
466 return selectionstart;
474 return selectionstart;
477 double LocalSession::get_selectionend(int highlight_only)
479 if(highlight_only || !EQUIV(selectionstart, selectionend))
491 double LocalSession::get_inpoint()
496 double LocalSession::get_outpoint()
501 int LocalSession::inpoint_valid()
503 return in_point >= 0;
506 int LocalSession::outpoint_valid()
508 return out_point >= 0;
511 void LocalSession::reset_view_limits()
513 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.005;
514 automation_maxs[AUTOGROUPTYPE_ZOOM] = 5.000;
515 int out_w = edl->session->output_w;
516 automation_mins[AUTOGROUPTYPE_X] = -out_w;
517 automation_maxs[AUTOGROUPTYPE_X] = out_w;
518 int out_h = edl->session->output_h;
519 automation_mins[AUTOGROUPTYPE_Y] = -out_h;
520 automation_maxs[AUTOGROUPTYPE_Y] = out_h;