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;
79 gang_tracks = GANG_NONE;
81 for(int i = 0; i < TOTAL_PANES; i++) {
87 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
88 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
89 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
90 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
91 automation_mins[AUTOGROUPTYPE_SPEED] = SPEED_MIN;
92 automation_maxs[AUTOGROUPTYPE_SPEED] = 5.000;
93 automation_mins[AUTOGROUPTYPE_INT255] = 0;
94 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
96 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
97 zoombar_showautocolor = -1;
99 floatauto_type = FloatAuto::SMOOTH;
101 red = green = blue = 0;
102 red_max = green_max = blue_max = 0;
105 gang_tracks = GANG_NONE;
108 LocalSession::~LocalSession()
112 void LocalSession::copy_from(LocalSession *that)
114 strcpy(clip_title, that->clip_title);
115 strcpy(clip_notes, that->clip_notes);
116 strcpy(clip_icon, that->clip_icon);
117 in_point = that->in_point;
118 loop_playback = that->loop_playback;
119 loop_start = that->loop_start;
120 loop_end = that->loop_end;
121 out_point = that->out_point;
122 selectionend = that->selectionend;
123 selectionstart = that->selectionstart;
124 x_pane = that->x_pane;
125 y_pane = that->y_pane;
127 for(int i = 0; i < TOTAL_PANES; i++)
129 view_start[i] = that->view_start[i];
130 track_start[i] = that->track_start[i];
133 zoom_sample = that->zoom_sample;
134 zoom_y = that->zoom_y;
135 zoom_atrack = that->zoom_atrack;
136 zoom_vtrack = that->zoom_vtrack;
137 preview_start = that->preview_start;
138 preview_end = that->preview_end;
142 red_max = that->red_max;
143 green_max = that->green_max;
144 blue_max = that->blue_max;
145 use_max = that->use_max;
146 solo_track_id = that->solo_track_id;
147 gang_tracks = that->gang_tracks;
149 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
150 automation_mins[i] = that->automation_mins[i];
151 automation_maxs[i] = that->automation_maxs[i];
153 floatauto_type = that->floatauto_type;
156 void LocalSession::save_xml(FileXML *file, double start)
158 file->tag.set_title("LOCALSESSION");
160 file->tag.set_property("IN_POINT", in_point - start);
161 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
162 file->tag.set_property("LOOP_START", loop_start - start);
163 file->tag.set_property("LOOP_END", loop_end - start);
164 file->tag.set_property("OUT_POINT", out_point - start);
165 file->tag.set_property("SELECTION_START", selectionstart - start);
166 file->tag.set_property("SELECTION_END", selectionend - start);
167 file->tag.set_property("CLIP_TITLE", clip_title);
168 file->tag.set_property("CLIP_ICON", clip_icon);
169 file->tag.set_property("X_PANE", x_pane);
170 file->tag.set_property("Y_PANE", y_pane);
172 char string[BCTEXTLEN];
173 for(int i = 0; i < TOTAL_PANES; i++)
175 sprintf(string, "TRACK_START%d", i);
176 file->tag.set_property(string, track_start[i]);
177 sprintf(string, "VIEW_START%d", i);
178 file->tag.set_property(string, view_start[i]);
181 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
182 //printf("EDLSession::save_session 1\n");
183 file->tag.set_property("ZOOMY", zoom_y);
184 file->tag.set_property("ZOOM_ATRACK", zoom_atrack);
185 file->tag.set_property("ZOOM_VTRACK", zoom_vtrack);
187 double preview_start = this->preview_start - start;
188 if( preview_start < 0 ) preview_start = 0;
189 double preview_end = this->preview_end - start;
190 if( preview_end < preview_start ) preview_end = -1;
191 file->tag.set_property("PREVIEW_START", preview_start);
192 file->tag.set_property("PREVIEW_END", preview_end);
193 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
195 file->tag.set_property("RED", red);
196 file->tag.set_property("GREEN", green);
197 file->tag.set_property("BLUE", blue);
198 file->tag.set_property("RED_MAX", red_max);
199 file->tag.set_property("GREEN_MAX", green_max);
200 file->tag.set_property("BLUE_MAX", blue_max);
201 file->tag.set_property("USE_MAX", use_max);
202 file->tag.set_property("GANG_TRACKS", gang_tracks);
205 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
206 if (!Automation::autogrouptypes_fixedrange[i]) {
207 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
208 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
212 file->append_newline();
214 //this used to be a property, now used as tag member
215 // file->tag.set_property("CLIP_NOTES", clip_notes);
216 file->tag.set_title("CLIP_NOTES"); file->append_tag();
217 file->append_text(clip_notes);
218 file->tag.set_title("/CLIP_NOTES"); file->append_tag();
219 file->append_newline();
221 file->tag.set_title("/LOCALSESSION");
223 file->append_newline();
224 file->append_newline();
227 void LocalSession::synchronize_params(LocalSession *that)
229 loop_playback = that->loop_playback;
230 loop_start = that->loop_start;
231 loop_end = that->loop_end;
232 preview_start = that->preview_start;
233 preview_end = that->preview_end;
237 red_max = that->red_max;
238 green_max = that->green_max;
239 blue_max = that->blue_max;
240 if( solo_track_id < 0 || that->solo_track_id < 0 )
241 solo_track_id = that->solo_track_id;
242 gang_tracks = that->gang_tracks;
246 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
248 if(load_flags & LOAD_SESSION)
250 // moved to EDL::load_xml for paste to fill silence.
251 // clipboard_length = 0;
252 // Overwritten by MWindow::load_filenames
253 file->tag.get_property("CLIP_TITLE", clip_title);
255 file->tag.get_property("CLIP_NOTES", clip_notes);
257 file->tag.get_property("CLIP_ICON", clip_icon);
258 // kludge if possible
259 if( !clip_icon[0] ) {
260 char *cp = clip_notes;
261 int year, mon, mday, hour, min, sec;
262 while( *cp && *cp++ != ':' );
263 if( *cp && sscanf(cp, "%d/%02d/%02d %02d:%02d:%02d,",
264 &year, &mon, &mday, &hour, &min, &sec) == 6 ) {
265 sprintf(clip_icon, "clip_%02d%02d%02d-%02d%02d%02d.png",
266 year, mon, mday, hour, min, sec);
269 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
270 loop_start = file->tag.get_property("LOOP_START", (double)0);
271 loop_end = file->tag.get_property("LOOP_END", (double)0);
272 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
273 selectionend = file->tag.get_property("SELECTION_END", (double)0);
274 x_pane = file->tag.get_property("X_PANE", -1);
275 y_pane = file->tag.get_property("Y_PANE", -1);
278 char string[BCTEXTLEN];
279 for(int i = 0; i < TOTAL_PANES; i++)
281 sprintf(string, "TRACK_START%d", i);
282 track_start[i] = file->tag.get_property(string, track_start[i]);
283 sprintf(string, "VIEW_START%d", i);
284 view_start[i] = file->tag.get_property(string, view_start[i]);
287 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
288 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
289 int64_t zoom_track = file->tag.get_property("ZOOM_TRACK", 0);
290 if( zoom_track > 0 ) zoom_atrack = zoom_vtrack = zoom_track;
291 zoom_atrack = file->tag.get_property("ZOOM_ATRACK", zoom_atrack);
292 zoom_vtrack = file->tag.get_property("ZOOM_VTRACK", zoom_vtrack);
293 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
294 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
295 red = file->tag.get_property("RED", red);
296 green = file->tag.get_property("GREEN", green);
297 blue = file->tag.get_property("BLUE", blue);
298 red_max = file->tag.get_property("RED_MAX", red_max);
299 green_max = file->tag.get_property("GREEN_MAX", green_max);
300 blue_max = file->tag.get_property("BLUE_MAX", blue_max);
301 use_max = file->tag.get_property("USE_MAX", use_max);
302 gang_tracks = file->tag.get_property("GANG_TRACKS", gang_tracks);
303 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
304 if (!Automation::autogrouptypes_fixedrange[i]) {
305 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
306 AUTOMATIONCLAMPS(automation_mins[i], i);
307 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
308 AUTOMATIONCLAMPS(automation_maxs[i], i);
311 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
315 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
316 // expect - this is additionally important in keyboard-only editing in viewer window
317 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
319 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
320 selectionend = file->tag.get_property("SELECTION_END", (double)0);
325 if(load_flags & LOAD_TIMEBAR)
327 in_point = file->tag.get_property("IN_POINT", (double)-1);
328 out_point = file->tag.get_property("OUT_POINT", (double)-1);
331 while( !file->read_tag() ) {
332 if( file->tag.title_is("/LOCALSESSION") ) break;
333 if( file->tag.title_is("CLIP_NOTES") ) {
335 file->read_text_until("/CLIP_NOTES", ¬es, 1);
336 memset(clip_notes, 0, sizeof(clip_notes));
337 strncpy(clip_notes, notes.cstr(), sizeof(clip_notes)-1);
342 void LocalSession::boundaries()
344 zoom_sample = MAX(1, zoom_sample);
347 int LocalSession::load_defaults(BC_Hash *defaults)
349 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
350 loop_start = defaults->get("LOOP_START", (double)0);
351 loop_end = defaults->get("LOOP_END", (double)0);
352 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
353 selectionend = defaults->get("SELECTIONEND", selectionend);
354 // track_start = defaults->get("TRACK_START", 0);
355 // view_start = defaults->get("VIEW_START", 0);
356 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
357 zoom_y = defaults->get("ZOOMY", DEFAULT_ZOOM_TRACK);
358 int64_t zoom_track = defaults->get("ZOOM_TRACK", 0);
359 if( zoom_track == 0 ) zoom_track = DEFAULT_ZOOM_TRACK;
360 zoom_atrack = defaults->get("ZOOM_ATRACK", zoom_track);
361 zoom_vtrack = defaults->get("ZOOM_VTRACK", zoom_track);
362 red = defaults->get("RED", 0.0);
363 green = defaults->get("GREEN", 0.0);
364 blue = defaults->get("BLUE", 0.0);
365 red_max = defaults->get("RED_MAX", 0.0);
366 green_max = defaults->get("GREEN_MAX", 0.0);
367 blue_max = defaults->get("BLUE_MAX", 0.0);
368 use_max = defaults->get("USE_MAX", 0);
369 gang_tracks = defaults->get("GANG_TRACKS", GANG_NONE);
371 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
372 if (!Automation::autogrouptypes_fixedrange[i]) {
373 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
374 AUTOMATIONCLAMPS(automation_mins[i], i);
375 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
376 AUTOMATIONCLAMPS(automation_maxs[i], i);
380 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
381 x_pane = defaults->get("X_PANE", x_pane);
382 y_pane = defaults->get("Y_PANE", y_pane);
387 int LocalSession::save_defaults(BC_Hash *defaults)
389 defaults->update("LOOP_PLAYBACK", loop_playback);
390 defaults->update("LOOP_START", loop_start);
391 defaults->update("LOOP_END", loop_end);
392 defaults->update("SELECTIONSTART", selectionstart);
393 defaults->update("SELECTIONEND", selectionend);
394 // defaults->update("TRACK_START", track_start);
395 // defaults->update("VIEW_START", view_start);
396 defaults->update("ZOOM_SAMPLE", zoom_sample);
397 defaults->update("ZOOMY", zoom_y);
398 defaults->update("ZOOM_ATRACK", zoom_atrack);
399 defaults->update("ZOOM_VTRACK", zoom_vtrack);
400 defaults->update("RED", red);
401 defaults->update("GREEN", green);
402 defaults->update("BLUE", blue);
403 defaults->update("RED_MAX", red_max);
404 defaults->update("GREEN_MAX", green_max);
405 defaults->update("BLUE_MAX", blue_max);
406 defaults->update("USE_MAX", use_max);
407 defaults->update("GANG_TRACKS", gang_tracks);
409 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
410 if (!Automation::autogrouptypes_fixedrange[i]) {
411 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
412 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
416 defaults->update("FLOATAUTO_TYPE", floatauto_type);
417 defaults->update("X_PANE", x_pane);
418 defaults->update("Y_PANE", y_pane);
422 void LocalSession::set_selectionstart(double value)
424 this->selectionstart = value;
427 void LocalSession::set_selectionend(double value)
429 this->selectionend = value;
432 void LocalSession::set_inpoint(double value)
437 void LocalSession::set_outpoint(double value)
442 void LocalSession::unset_inpoint()
447 void LocalSession::unset_outpoint()
452 void LocalSession::set_playback_start(double value)
454 if( playback_end < 0 ) return;
455 playback_start = value;
459 void LocalSession::set_playback_end(double value)
461 if( value < playback_start ) {
462 if( playback_end < 0 )
463 playback_end = playback_start;
464 playback_start = value;
466 else if( playback_end < 0 || value > playback_end )
467 playback_end = value;
471 double LocalSession::get_selectionstart(int highlight_only)
473 if(highlight_only || !EQUIV(selectionstart, selectionend))
474 return selectionstart;
482 return selectionstart;
485 double LocalSession::get_selectionend(int highlight_only)
487 if(highlight_only || !EQUIV(selectionstart, selectionend))
499 double LocalSession::get_inpoint()
504 double LocalSession::get_outpoint()
509 int LocalSession::inpoint_valid()
511 return in_point >= 0;
514 int LocalSession::outpoint_valid()
516 return out_point >= 0;
519 void LocalSession::reset_view_limits()
521 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.005;
522 automation_maxs[AUTOGROUPTYPE_ZOOM] = 5.000;
523 int out_w = edl->session->output_w;
524 automation_mins[AUTOGROUPTYPE_X] = -out_w;
525 automation_maxs[AUTOGROUPTYPE_X] = out_w;
526 int out_h = edl->session->output_h;
527 automation_mins[AUTOGROUPTYPE_Y] = -out_h;
528 automation_maxs[AUTOGROUPTYPE_Y] = out_h;