4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "automation.h"
24 #include "awindowgui.h"
28 #include "edlsession.h"
29 #include "filesystem.h"
31 #include "floatauto.h"
33 #include "localsession.h"
36 static const char *xml_autogrouptypes_titlesmax[] =
38 "AUTOGROUPTYPE_AUDIO_FADE_MAX",
39 "AUTOGROUPTYPE_VIDEO_FADE_MAX",
40 "AUTOGROUPTYPE_ZOOM_MAX",
41 "AUTOGROUPTYPE_SPEED_MAX",
42 "AUTOGROUPTYPE_X_MAX",
43 "AUTOGROUPTYPE_Y_MAX",
44 "AUTOGROUPTYPE_INT255_MAX"
47 static const char *xml_autogrouptypes_titlesmin[] =
49 "AUTOGROUPTYPE_AUDIO_FADE_MIN",
50 "AUTOGROUPTYPE_VIDEO_FADE_MIN",
51 "AUTOGROUPTYPE_ZOOM_MIN",
52 "AUTOGROUPTYPE_SPEED_MIN",
53 "AUTOGROUPTYPE_X_MIN",
54 "AUTOGROUPTYPE_Y_MIN",
55 "AUTOGROUPTYPE_INT255_MIN"
59 LocalSession::LocalSession(EDL *edl)
63 selectionstart = selectionend = 0;
64 in_point = out_point = -1;
65 sprintf(clip_title, _("Program"));
66 strcpy(clip_notes, _("Hello world"));
67 strcpy(clip_icon, "");
71 loop_start = loop_end = 0;
74 preview_start = 0; preview_end = -1;
75 zoom_sample = DEFAULT_ZOOM_TIME;
80 gang_tracks = GANG_NONE;
82 for(int i = 0; i < TOTAL_PANES; i++) {
88 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
89 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
90 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
91 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
92 automation_mins[AUTOGROUPTYPE_SPEED] = SPEED_MIN;
93 automation_maxs[AUTOGROUPTYPE_SPEED] = 5.000;
94 automation_mins[AUTOGROUPTYPE_INT255] = 0;
95 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
97 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
98 zoombar_showautocolor = -1;
100 floatauto_type = FloatAuto::SMOOTH;
102 red = green = blue = 0;
103 red_max = green_max = blue_max = 0;
106 gang_tracks = GANG_NONE;
109 LocalSession::~LocalSession()
113 void LocalSession::copy_from(LocalSession *that)
115 strcpy(clip_title, that->clip_title);
116 strcpy(clip_notes, that->clip_notes);
117 strcpy(clip_icon, that->clip_icon);
118 in_point = that->in_point;
119 loop_playback = that->loop_playback;
120 loop_start = that->loop_start;
121 loop_end = that->loop_end;
122 out_point = that->out_point;
123 selectionend = that->selectionend;
124 selectionstart = that->selectionstart;
125 x_pane = that->x_pane;
126 y_pane = that->y_pane;
128 for(int i = 0; i < TOTAL_PANES; i++)
130 view_start[i] = that->view_start[i];
131 track_start[i] = that->track_start[i];
134 zoom_sample = that->zoom_sample;
135 zoom_y = that->zoom_y;
136 zoom_atrack = that->zoom_atrack;
137 zoom_vtrack = that->zoom_vtrack;
138 preview_start = that->preview_start;
139 preview_end = that->preview_end;
143 red_max = that->red_max;
144 green_max = that->green_max;
145 blue_max = that->blue_max;
146 use_max = that->use_max;
147 solo_track_id = that->solo_track_id;
148 gang_tracks = that->gang_tracks;
150 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
151 automation_mins[i] = that->automation_mins[i];
152 automation_maxs[i] = that->automation_maxs[i];
154 floatauto_type = that->floatauto_type;
157 void LocalSession::save_xml(FileXML *file, double start)
159 file->tag.set_title("LOCALSESSION");
161 file->tag.set_property("IN_POINT", in_point - start);
162 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
163 file->tag.set_property("LOOP_START", loop_start - start);
164 file->tag.set_property("LOOP_END", loop_end - start);
165 file->tag.set_property("OUT_POINT", out_point - start);
166 file->tag.set_property("SELECTION_START", selectionstart - start);
167 file->tag.set_property("SELECTION_END", selectionend - start);
168 file->tag.set_property("CLIP_TITLE", clip_title);
169 file->tag.set_property("CLIP_ICON", clip_icon);
170 file->tag.set_property("X_PANE", x_pane);
171 file->tag.set_property("Y_PANE", y_pane);
173 char string[BCTEXTLEN];
174 for(int i = 0; i < TOTAL_PANES; i++)
176 sprintf(string, "TRACK_START%d", i);
177 file->tag.set_property(string, track_start[i]);
178 sprintf(string, "VIEW_START%d", i);
179 file->tag.set_property(string, view_start[i]);
182 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
183 //printf("EDLSession::save_session 1\n");
184 file->tag.set_property("ZOOMY", zoom_y);
185 file->tag.set_property("ZOOM_ATRACK", zoom_atrack);
186 file->tag.set_property("ZOOM_VTRACK", zoom_vtrack);
188 double preview_start = this->preview_start - start;
189 if( preview_start < 0 ) preview_start = 0;
190 double preview_end = this->preview_end - start;
191 if( preview_end < preview_start ) preview_end = -1;
192 file->tag.set_property("PREVIEW_START", preview_start);
193 file->tag.set_property("PREVIEW_END", preview_end);
194 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
196 file->tag.set_property("RED", red);
197 file->tag.set_property("GREEN", green);
198 file->tag.set_property("BLUE", blue);
199 file->tag.set_property("RED_MAX", red_max);
200 file->tag.set_property("GREEN_MAX", green_max);
201 file->tag.set_property("BLUE_MAX", blue_max);
202 file->tag.set_property("USE_MAX", use_max);
203 file->tag.set_property("GANG_TRACKS", gang_tracks);
206 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
207 if (!Automation::autogrouptypes_fixedrange[i]) {
208 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
209 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
213 file->append_newline();
215 //this used to be a property, now used as tag member
216 // file->tag.set_property("CLIP_NOTES", clip_notes);
217 file->tag.set_title("CLIP_NOTES"); file->append_tag();
218 file->append_text(clip_notes);
219 file->tag.set_title("/CLIP_NOTES"); file->append_tag();
220 file->append_newline();
222 file->tag.set_title("/LOCALSESSION");
224 file->append_newline();
225 file->append_newline();
228 void LocalSession::synchronize_params(LocalSession *that)
230 loop_playback = that->loop_playback;
231 loop_start = that->loop_start;
232 loop_end = that->loop_end;
233 preview_start = that->preview_start;
234 preview_end = that->preview_end;
238 red_max = that->red_max;
239 green_max = that->green_max;
240 blue_max = that->blue_max;
241 if( solo_track_id < 0 || that->solo_track_id < 0 )
242 solo_track_id = that->solo_track_id;
243 gang_tracks = that->gang_tracks;
247 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
249 if(load_flags & LOAD_SESSION)
251 // moved to EDL::load_xml for paste to fill silence.
252 // clipboard_length = 0;
253 // Overwritten by MWindow::load_filenames
254 file->tag.get_property("CLIP_TITLE", clip_title);
256 file->tag.get_property("CLIP_NOTES", clip_notes);
258 file->tag.get_property("CLIP_ICON", clip_icon);
259 // kludge if possible
260 if( !clip_icon[0] ) {
261 char *cp = clip_notes;
262 int year, mon, mday, hour, min, sec;
263 while( *cp && *cp++ != ':' );
264 if( *cp && sscanf(cp, "%d/%02d/%02d %02d:%02d:%02d,",
265 &year, &mon, &mday, &hour, &min, &sec) == 6 ) {
266 sprintf(clip_icon, "clip_%02d%02d%02d-%02d%02d%02d.png",
267 year, mon, mday, hour, min, sec);
270 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
271 loop_start = file->tag.get_property("LOOP_START", (double)0);
272 loop_end = file->tag.get_property("LOOP_END", (double)0);
273 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
274 selectionend = file->tag.get_property("SELECTION_END", (double)0);
275 x_pane = file->tag.get_property("X_PANE", -1);
276 y_pane = file->tag.get_property("Y_PANE", -1);
279 char string[BCTEXTLEN];
280 for(int i = 0; i < TOTAL_PANES; i++)
282 sprintf(string, "TRACK_START%d", i);
283 track_start[i] = file->tag.get_property(string, track_start[i]);
284 sprintf(string, "VIEW_START%d", i);
285 view_start[i] = file->tag.get_property(string, view_start[i]);
288 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
289 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
290 int64_t zoom_track = file->tag.get_property("ZOOM_TRACK", 0);
291 if( zoom_track > 0 ) zoom_atrack = zoom_vtrack = zoom_track;
292 zoom_atrack = file->tag.get_property("ZOOM_ATRACK", zoom_atrack);
293 zoom_vtrack = file->tag.get_property("ZOOM_VTRACK", zoom_vtrack);
294 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
295 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
296 red = file->tag.get_property("RED", red);
297 green = file->tag.get_property("GREEN", green);
298 blue = file->tag.get_property("BLUE", blue);
299 red_max = file->tag.get_property("RED_MAX", red_max);
300 green_max = file->tag.get_property("GREEN_MAX", green_max);
301 blue_max = file->tag.get_property("BLUE_MAX", blue_max);
302 use_max = file->tag.get_property("USE_MAX", use_max);
303 gang_tracks = file->tag.get_property("GANG_TRACKS", gang_tracks);
304 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
305 if (!Automation::autogrouptypes_fixedrange[i]) {
306 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
307 AUTOMATIONCLAMPS(automation_mins[i], i);
308 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
309 AUTOMATIONCLAMPS(automation_maxs[i], i);
312 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
316 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
317 // expect - this is additionally important in keyboard-only editing in viewer window
318 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
320 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
321 selectionend = file->tag.get_property("SELECTION_END", (double)0);
326 if(load_flags & LOAD_TIMEBAR)
328 in_point = file->tag.get_property("IN_POINT", (double)-1);
329 out_point = file->tag.get_property("OUT_POINT", (double)-1);
332 while( !file->read_tag() ) {
333 if( file->tag.title_is("/LOCALSESSION") ) break;
334 if( file->tag.title_is("CLIP_NOTES") ) {
336 file->read_text_until("/CLIP_NOTES", ¬es, 1);
337 memset(clip_notes, 0, sizeof(clip_notes));
338 strncpy(clip_notes, notes.cstr(), sizeof(clip_notes)-1);
343 void LocalSession::boundaries()
345 zoom_sample = MAX(1, zoom_sample);
348 int LocalSession::load_defaults(BC_Hash *defaults)
350 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
351 loop_start = defaults->get("LOOP_START", (double)0);
352 loop_end = defaults->get("LOOP_END", (double)0);
353 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
354 selectionend = defaults->get("SELECTIONEND", selectionend);
355 // track_start = defaults->get("TRACK_START", 0);
356 // view_start = defaults->get("VIEW_START", 0);
357 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
358 zoom_y = defaults->get("ZOOMY", DEFAULT_ZOOM_TRACK);
359 int64_t zoom_track = defaults->get("ZOOM_TRACK", 0);
360 if( zoom_track == 0 ) zoom_track = DEFAULT_ZOOM_TRACK;
361 zoom_atrack = defaults->get("ZOOM_ATRACK", zoom_track);
362 zoom_vtrack = defaults->get("ZOOM_VTRACK", zoom_track);
363 red = defaults->get("RED", 0.0);
364 green = defaults->get("GREEN", 0.0);
365 blue = defaults->get("BLUE", 0.0);
366 red_max = defaults->get("RED_MAX", 0.0);
367 green_max = defaults->get("GREEN_MAX", 0.0);
368 blue_max = defaults->get("BLUE_MAX", 0.0);
369 use_max = defaults->get("USE_MAX", 0);
370 gang_tracks = defaults->get("GANG_TRACKS", GANG_NONE);
372 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
373 if (!Automation::autogrouptypes_fixedrange[i]) {
374 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
375 AUTOMATIONCLAMPS(automation_mins[i], i);
376 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
377 AUTOMATIONCLAMPS(automation_maxs[i], i);
381 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
382 x_pane = defaults->get("X_PANE", x_pane);
383 y_pane = defaults->get("Y_PANE", y_pane);
388 int LocalSession::save_defaults(BC_Hash *defaults)
390 defaults->update("LOOP_PLAYBACK", loop_playback);
391 defaults->update("LOOP_START", loop_start);
392 defaults->update("LOOP_END", loop_end);
393 defaults->update("SELECTIONSTART", selectionstart);
394 defaults->update("SELECTIONEND", selectionend);
395 // defaults->update("TRACK_START", track_start);
396 // defaults->update("VIEW_START", view_start);
397 defaults->update("ZOOM_SAMPLE", zoom_sample);
398 defaults->update("ZOOMY", zoom_y);
399 defaults->update("ZOOM_ATRACK", zoom_atrack);
400 defaults->update("ZOOM_VTRACK", zoom_vtrack);
401 defaults->update("RED", red);
402 defaults->update("GREEN", green);
403 defaults->update("BLUE", blue);
404 defaults->update("RED_MAX", red_max);
405 defaults->update("GREEN_MAX", green_max);
406 defaults->update("BLUE_MAX", blue_max);
407 defaults->update("USE_MAX", use_max);
408 defaults->update("GANG_TRACKS", gang_tracks);
410 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
411 if (!Automation::autogrouptypes_fixedrange[i]) {
412 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
413 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
417 defaults->update("FLOATAUTO_TYPE", floatauto_type);
418 defaults->update("X_PANE", x_pane);
419 defaults->update("Y_PANE", y_pane);
423 void LocalSession::set_selectionstart(double value)
425 this->selectionstart = value;
428 void LocalSession::set_selectionend(double value)
430 this->selectionend = value;
433 void LocalSession::set_inpoint(double value)
438 void LocalSession::set_outpoint(double value)
443 void LocalSession::unset_inpoint()
448 void LocalSession::unset_outpoint()
453 void LocalSession::set_playback_start(double value)
455 if( playback_end < 0 ) return;
456 playback_start = value;
460 void LocalSession::set_playback_end(double value)
462 if( value < playback_start ) {
463 if( playback_end < 0 )
464 playback_end = playback_start;
465 playback_start = value;
467 else if( playback_end < 0 || value > playback_end )
468 playback_end = value;
472 double LocalSession::get_selectionstart(int highlight_only)
474 if(highlight_only || !EQUIV(selectionstart, selectionend))
475 return selectionstart;
483 return selectionstart;
486 double LocalSession::get_selectionend(int highlight_only)
488 if(highlight_only || !EQUIV(selectionstart, selectionend))
500 double LocalSession::get_inpoint()
505 double LocalSession::get_outpoint()
510 int LocalSession::inpoint_valid()
512 return in_point >= 0;
515 int LocalSession::outpoint_valid()
517 return out_point >= 0;
520 void LocalSession::reset_view_limits()
522 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.005;
523 automation_maxs[AUTOGROUPTYPE_ZOOM] = 5.000;
524 int out_w = edl->session->output_w;
525 automation_mins[AUTOGROUPTYPE_X] = -out_w;
526 automation_maxs[AUTOGROUPTYPE_X] = out_w;
527 int out_h = edl->session->output_h;
528 automation_mins[AUTOGROUPTYPE_Y] = -out_h;
529 automation_maxs[AUTOGROUPTYPE_Y] = out_h;