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, "");
68 loop_start = loop_end = 0;
71 preview_start = 0; preview_end = -1;
72 zoom_sample = DEFAULT_ZOOM_TIME;
77 for(int i = 0; i < TOTAL_PANES; i++) {
82 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
83 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
85 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
86 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
88 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.005;
89 automation_maxs[AUTOGROUPTYPE_ZOOM] = 5.000;
91 automation_mins[AUTOGROUPTYPE_SPEED] = 0.005;
92 automation_maxs[AUTOGROUPTYPE_SPEED] = 5.000;
94 automation_mins[AUTOGROUPTYPE_X] = -100;
95 automation_maxs[AUTOGROUPTYPE_X] = 100;
97 automation_mins[AUTOGROUPTYPE_Y] = -100;
98 automation_maxs[AUTOGROUPTYPE_Y] = 100;
100 automation_mins[AUTOGROUPTYPE_INT255] = 0;
101 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
103 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
105 floatauto_type = FloatAuto::SMOOTH;
107 red = green = blue = 0;
108 red_max = green_max = blue_max = 0;
112 LocalSession::~LocalSession()
116 void LocalSession::copy_from(LocalSession *that)
118 strcpy(clip_title, that->clip_title);
119 strcpy(clip_notes, that->clip_notes);
120 strcpy(clip_icon, that->clip_icon);
121 in_point = that->in_point;
122 loop_playback = that->loop_playback;
123 loop_start = that->loop_start;
124 loop_end = that->loop_end;
125 out_point = that->out_point;
126 selectionend = that->selectionend;
127 selectionstart = that->selectionstart;
128 x_pane = that->x_pane;
129 y_pane = that->y_pane;
131 for(int i = 0; i < TOTAL_PANES; i++)
133 view_start[i] = that->view_start[i];
134 track_start[i] = that->track_start[i];
137 zoom_sample = that->zoom_sample;
138 zoom_y = that->zoom_y;
139 zoom_track = that->zoom_track;
140 preview_start = that->preview_start;
141 preview_end = that->preview_end;
145 red_max = that->red_max;
146 green_max = that->green_max;
147 blue_max = that->blue_max;
148 use_max = that->use_max;
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 //printf("EDLSession::save_session 1 %d\n", zoom_track);
186 file->tag.set_property("ZOOM_TRACK", zoom_track);
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);
204 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
205 if (!Automation::autogrouptypes_fixedrange[i]) {
206 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
207 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
211 file->append_newline();
213 //this used to be a property, now used as tag member
214 // file->tag.set_property("CLIP_NOTES", clip_notes);
215 file->tag.set_title("CLIP_NOTES"); file->append_tag();
216 file->append_text(clip_notes);
217 file->tag.set_title("/CLIP_NOTES"); file->append_tag();
218 file->append_newline();
220 file->tag.set_title("/LOCALSESSION");
222 file->append_newline();
223 file->append_newline();
226 void LocalSession::synchronize_params(LocalSession *that)
228 loop_playback = that->loop_playback;
229 loop_start = that->loop_start;
230 loop_end = that->loop_end;
231 preview_start = that->preview_start;
232 preview_end = that->preview_end;
236 red_max = that->red_max;
237 green_max = that->green_max;
238 blue_max = that->blue_max;
242 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
244 if(load_flags & LOAD_SESSION)
246 // moved to EDL::load_xml for paste to fill silence.
247 // clipboard_length = 0;
248 // Overwritten by MWindow::load_filenames
249 file->tag.get_property("CLIP_TITLE", clip_title);
251 file->tag.get_property("CLIP_NOTES", clip_notes);
253 file->tag.get_property("CLIP_ICON", clip_icon);
254 // kludge if possible
255 if( !clip_icon[0] ) {
256 char *cp = clip_notes;
257 int year, mon, mday, hour, min, sec;
258 while( *cp && *cp++ != ':' );
259 if( *cp && sscanf(cp, "%d/%02d/%02d %02d:%02d:%02d,",
260 &year, &mon, &mday, &hour, &min, &sec) == 6 ) {
261 sprintf(clip_icon, "clip_%02d%02d%02d-%02d%02d%02d.png",
262 year, mon, mday, hour, min, sec);
265 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
266 loop_start = file->tag.get_property("LOOP_START", (double)0);
267 loop_end = file->tag.get_property("LOOP_END", (double)0);
268 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
269 selectionend = file->tag.get_property("SELECTION_END", (double)0);
270 x_pane = file->tag.get_property("X_PANE", -1);
271 y_pane = file->tag.get_property("Y_PANE", -1);
274 char string[BCTEXTLEN];
275 for(int i = 0; i < TOTAL_PANES; i++)
277 sprintf(string, "TRACK_START%d", i);
278 track_start[i] = file->tag.get_property(string, track_start[i]);
279 sprintf(string, "VIEW_START%d", i);
280 view_start[i] = file->tag.get_property(string, view_start[i]);
283 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
284 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
285 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
286 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
287 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
288 red = file->tag.get_property("RED", red);
289 green = file->tag.get_property("GREEN", green);
290 blue = file->tag.get_property("BLUE", blue);
291 red_max = file->tag.get_property("RED_MAX", red_max);
292 green_max = file->tag.get_property("GREEN_MAX", green_max);
293 blue_max = file->tag.get_property("BLUE_MAX", blue_max);
294 use_max = file->tag.get_property("USE_MAX", use_max);
296 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
297 if (!Automation::autogrouptypes_fixedrange[i]) {
298 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
299 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
302 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
306 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
307 // expect - this is additionally important in keyboard-only editing in viewer window
308 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
310 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
311 selectionend = file->tag.get_property("SELECTION_END", (double)0);
316 if(load_flags & LOAD_TIMEBAR)
318 in_point = file->tag.get_property("IN_POINT", (double)-1);
319 out_point = file->tag.get_property("OUT_POINT", (double)-1);
322 while( !file->read_tag() ) {
323 if( file->tag.title_is("/LOCALSESSION") ) break;
324 if( file->tag.title_is("CLIP_NOTES") ) {
326 file->read_text_until("/CLIP_NOTES", ¬es, 1);
327 memset(clip_notes, 0, sizeof(clip_notes));
328 strncpy(clip_notes, notes.cstr(), sizeof(clip_notes)-1);
333 void LocalSession::boundaries()
335 zoom_sample = MAX(1, zoom_sample);
338 int LocalSession::load_defaults(BC_Hash *defaults)
340 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
341 loop_start = defaults->get("LOOP_START", (double)0);
342 loop_end = defaults->get("LOOP_END", (double)0);
343 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
344 selectionend = defaults->get("SELECTIONEND", selectionend);
345 // track_start = defaults->get("TRACK_START", 0);
346 // view_start = defaults->get("VIEW_START", 0);
347 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
348 zoom_y = defaults->get("ZOOMY", 64);
349 zoom_track = defaults->get("ZOOM_TRACK", 64);
350 red = defaults->get("RED", 0.0);
351 green = defaults->get("GREEN", 0.0);
352 blue = defaults->get("BLUE", 0.0);
353 red_max = defaults->get("RED_MAX", 0.0);
354 green_max = defaults->get("GREEN_MAX", 0.0);
355 blue_max = defaults->get("BLUE_MAX", 0.0);
356 use_max = defaults->get("USE_MAX", 0);
358 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
359 if (!Automation::autogrouptypes_fixedrange[i]) {
360 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
361 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
365 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
366 x_pane = defaults->get("X_PANE", x_pane);
367 y_pane = defaults->get("Y_PANE", y_pane);
372 int LocalSession::save_defaults(BC_Hash *defaults)
374 defaults->update("LOOP_PLAYBACK", loop_playback);
375 defaults->update("LOOP_START", loop_start);
376 defaults->update("LOOP_END", loop_end);
377 defaults->update("SELECTIONSTART", selectionstart);
378 defaults->update("SELECTIONEND", selectionend);
379 // defaults->update("TRACK_START", track_start);
380 // defaults->update("VIEW_START", view_start);
381 defaults->update("ZOOM_SAMPLE", zoom_sample);
382 defaults->update("ZOOMY", zoom_y);
383 defaults->update("ZOOM_TRACK", zoom_track);
384 defaults->update("RED", red);
385 defaults->update("GREEN", green);
386 defaults->update("BLUE", blue);
387 defaults->update("RED_MAX", red_max);
388 defaults->update("GREEN_MAX", green_max);
389 defaults->update("BLUE_MAX", blue_max);
390 defaults->update("USE_MAX", use_max);
392 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
393 if (!Automation::autogrouptypes_fixedrange[i]) {
394 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
395 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
399 defaults->update("FLOATAUTO_TYPE", floatauto_type);
400 defaults->update("X_PANE", x_pane);
401 defaults->update("Y_PANE", y_pane);
405 void LocalSession::set_selectionstart(double value)
407 this->selectionstart = value;
410 void LocalSession::set_selectionend(double value)
412 this->selectionend = value;
415 void LocalSession::set_inpoint(double value)
420 void LocalSession::set_outpoint(double value)
425 void LocalSession::unset_inpoint()
430 void LocalSession::unset_outpoint()
435 void LocalSession::set_playback_start(double value)
437 if( playback_end < 0 ) return;
438 playback_start = value;
442 void LocalSession::set_playback_end(double value)
444 if( value < playback_start ) {
445 if( playback_end < 0 )
446 playback_end = playback_start;
447 playback_start = value;
449 else if( playback_end < 0 || value > playback_end )
450 playback_end = value;
454 double LocalSession::get_selectionstart(int highlight_only)
456 if(highlight_only || !EQUIV(selectionstart, selectionend))
457 return selectionstart;
465 return selectionstart;
468 double LocalSession::get_selectionend(int highlight_only)
470 if(highlight_only || !EQUIV(selectionstart, selectionend))
482 double LocalSession::get_inpoint()
487 double LocalSession::get_outpoint()
492 int LocalSession::inpoint_valid()
494 return in_point >= 0;
497 int LocalSession::outpoint_valid()
499 return out_point >= 0;