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 awindow_folder = AW_CLIP_FOLDER;
64 sprintf(clip_title, _("Program"));
65 strcpy(clip_notes, _("Hello world"));
66 strcpy(clip_icon, "");
69 loop_start = loop_end = 0;
72 preview_start = preview_end = 0;
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;
106 floatauto_type = FloatAuto::SMOOTH;
108 red = green = blue = 0;
109 red_max = green_max = blue_max = 0;
113 LocalSession::~LocalSession()
117 void LocalSession::copy_from(LocalSession *that)
119 strcpy(clip_title, that->clip_title);
120 strcpy(clip_notes, that->clip_notes);
121 strcpy(clip_icon, that->clip_icon);
122 awindow_folder = that->awindow_folder;
123 in_point = that->in_point;
124 loop_playback = that->loop_playback;
125 loop_start = that->loop_start;
126 loop_end = that->loop_end;
127 out_point = that->out_point;
128 selectionend = that->selectionend;
129 selectionstart = that->selectionstart;
130 x_pane = that->x_pane;
131 y_pane = that->y_pane;
133 for(int i = 0; i < TOTAL_PANES; i++)
135 view_start[i] = that->view_start[i];
136 track_start[i] = that->track_start[i];
139 zoom_sample = that->zoom_sample;
140 zoom_y = that->zoom_y;
141 zoom_track = that->zoom_track;
142 preview_start = that->preview_start;
143 preview_end = that->preview_end;
147 red_max = that->red_max;
148 green_max = that->green_max;
149 blue_max = that->blue_max;
150 use_max = that->use_max;
152 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
153 automation_mins[i] = that->automation_mins[i];
154 automation_maxs[i] = that->automation_maxs[i];
156 floatauto_type = that->floatauto_type;
159 void LocalSession::save_xml(FileXML *file, double start)
161 file->tag.set_title("LOCALSESSION");
163 file->tag.set_property("IN_POINT", in_point - start);
164 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
165 file->tag.set_property("LOOP_START", loop_start - start);
166 file->tag.set_property("LOOP_END", loop_end - start);
167 file->tag.set_property("OUT_POINT", out_point - start);
168 file->tag.set_property("SELECTION_START", selectionstart - start);
169 file->tag.set_property("SELECTION_END", selectionend - start);
170 file->tag.set_property("CLIP_TITLE", clip_title);
171 file->tag.set_property("CLIP_NOTES", clip_notes);
172 file->tag.set_property("CLIP_ICON", clip_icon);
173 file->tag.set_property("AWINDOW_FOLDER", awindow_folder);
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 < 0) preview_end = 0;
197 file->tag.set_property("PREVIEW_START", preview_start);
198 file->tag.set_property("PREVIEW_END", preview_end);
199 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
201 file->tag.set_property("RED", red);
202 file->tag.set_property("GREEN", green);
203 file->tag.set_property("BLUE", blue);
204 file->tag.set_property("RED_MAX", red_max);
205 file->tag.set_property("GREEN_MAX", green_max);
206 file->tag.set_property("BLUE_MAX", blue_max);
207 file->tag.set_property("USE_MAX", use_max);
209 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
210 if (!Automation::autogrouptypes_fixedrange[i]) {
211 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
212 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
217 file->tag.set_title("/LOCALSESSION");
219 file->append_newline();
220 file->append_newline();
223 void LocalSession::synchronize_params(LocalSession *that)
225 loop_playback = that->loop_playback;
226 loop_start = that->loop_start;
227 loop_end = that->loop_end;
228 preview_start = that->preview_start;
229 preview_end = that->preview_end;
233 red_max = that->red_max;
234 green_max = that->green_max;
235 blue_max = that->blue_max;
239 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
241 if(load_flags & LOAD_SESSION)
243 // moved to EDL::load_xml for paste to fill silence.
244 // clipboard_length = 0;
245 // Overwritten by MWindow::load_filenames
246 file->tag.get_property("CLIP_TITLE", clip_title);
247 file->tag.get_property("CLIP_NOTES", clip_notes);
249 file->tag.get_property("CLIP_ICON", clip_icon);
250 // kludge if possible
251 if( !clip_icon[0] ) {
252 char *cp = clip_notes;
253 int year, mon, mday, hour, min, sec;
254 while( *cp && *cp++ != ':' );
255 if( *cp && sscanf(cp, "%d/%02d/%02d %02d:%02d:%02d,",
256 &year, &mon, &mday, &hour, &min, &sec) == 6 ) {
257 sprintf(clip_icon, "clip_%02d%02d%02d-%02d%02d%02d.png",
258 year, mon, mday, hour, min, sec);
261 const char *folder = file->tag.get_property("FOLDER");
263 awindow_folder = AWindowGUI::folder_number(folder);
264 if( awindow_folder < 0 ) awindow_folder = AW_MEDIA_FOLDER;
266 awindow_folder = file->tag.get_property("AWINDOW_FOLDER", awindow_folder);
267 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
268 loop_start = file->tag.get_property("LOOP_START", (double)0);
269 loop_end = file->tag.get_property("LOOP_END", (double)0);
270 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
271 selectionend = file->tag.get_property("SELECTION_END", (double)0);
272 x_pane = file->tag.get_property("X_PANE", -1);
273 y_pane = file->tag.get_property("Y_PANE", -1);
276 char string[BCTEXTLEN];
277 for(int i = 0; i < TOTAL_PANES; i++)
279 sprintf(string, "TRACK_START%d", i);
280 track_start[i] = file->tag.get_property(string, track_start[i]);
281 sprintf(string, "VIEW_START%d", i);
282 view_start[i] = file->tag.get_property(string, view_start[i]);
285 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
286 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
287 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
288 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
289 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
290 red = file->tag.get_property("RED", red);
291 green = file->tag.get_property("GREEN", green);
292 blue = file->tag.get_property("BLUE", blue);
293 red_max = file->tag.get_property("RED_MAX", red_max);
294 green_max = file->tag.get_property("GREEN_MAX", green_max);
295 blue_max = file->tag.get_property("BLUE_MAX", blue_max);
296 use_max = file->tag.get_property("USE_MAX", use_max);
298 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
299 if (!Automation::autogrouptypes_fixedrange[i]) {
300 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
301 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
304 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
308 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
309 // expect - this is additionally important in keyboard-only editing in viewer window
310 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
312 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
313 selectionend = file->tag.get_property("SELECTION_END", (double)0);
318 if(load_flags & LOAD_TIMEBAR)
320 in_point = file->tag.get_property("IN_POINT", (double)-1);
321 out_point = file->tag.get_property("OUT_POINT", (double)-1);
325 void LocalSession::boundaries()
327 zoom_sample = MAX(1, zoom_sample);
330 int LocalSession::load_defaults(BC_Hash *defaults)
332 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
333 loop_start = defaults->get("LOOP_START", (double)0);
334 loop_end = defaults->get("LOOP_END", (double)0);
335 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
336 selectionend = defaults->get("SELECTIONEND", selectionend);
337 // track_start = defaults->get("TRACK_START", 0);
338 // view_start = defaults->get("VIEW_START", 0);
339 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
340 zoom_y = defaults->get("ZOOMY", 64);
341 zoom_track = defaults->get("ZOOM_TRACK", 64);
342 red = defaults->get("RED", 0.0);
343 green = defaults->get("GREEN", 0.0);
344 blue = defaults->get("BLUE", 0.0);
345 red_max = defaults->get("RED_MAX", 0.0);
346 green_max = defaults->get("GREEN_MAX", 0.0);
347 blue_max = defaults->get("BLUE_MAX", 0.0);
348 use_max = defaults->get("USE_MAX", 0);
350 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
351 if (!Automation::autogrouptypes_fixedrange[i]) {
352 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
353 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
357 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
358 x_pane = defaults->get("X_PANE", x_pane);
359 y_pane = defaults->get("Y_PANE", y_pane);
364 int LocalSession::save_defaults(BC_Hash *defaults)
366 defaults->update("LOOP_PLAYBACK", loop_playback);
367 defaults->update("LOOP_START", loop_start);
368 defaults->update("LOOP_END", loop_end);
369 defaults->update("SELECTIONSTART", selectionstart);
370 defaults->update("SELECTIONEND", selectionend);
371 // defaults->update("TRACK_START", track_start);
372 // defaults->update("VIEW_START", view_start);
373 defaults->update("ZOOM_SAMPLE", zoom_sample);
374 defaults->update("ZOOMY", zoom_y);
375 defaults->update("ZOOM_TRACK", zoom_track);
376 defaults->update("RED", red);
377 defaults->update("GREEN", green);
378 defaults->update("BLUE", blue);
379 defaults->update("RED_MAX", red_max);
380 defaults->update("GREEN_MAX", green_max);
381 defaults->update("BLUE_MAX", blue_max);
382 defaults->update("USE_MAX", use_max);
384 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
385 if (!Automation::autogrouptypes_fixedrange[i]) {
386 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
387 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
391 defaults->update("FLOATAUTO_TYPE", floatauto_type);
392 defaults->update("X_PANE", x_pane);
393 defaults->update("Y_PANE", y_pane);
397 void LocalSession::set_selectionstart(double value)
399 this->selectionstart = value;
402 void LocalSession::set_selectionend(double value)
404 this->selectionend = value;
407 void LocalSession::set_inpoint(double value)
412 void LocalSession::set_outpoint(double value)
417 void LocalSession::unset_inpoint()
422 void LocalSession::unset_outpoint()
427 void LocalSession::set_playback_start(double value)
429 if( playback_end < 0 ) return;
430 playback_start = value;
434 void LocalSession::set_playback_end(double value)
436 if( value < playback_start ) {
437 if( playback_end < 0 )
438 playback_end = playback_start;
439 playback_start = value;
441 else if( playback_end < 0 || value > playback_end )
442 playback_end = value;
446 double LocalSession::get_selectionstart(int highlight_only)
448 if(highlight_only || !EQUIV(selectionstart, selectionend))
449 return selectionstart;
457 return selectionstart;
460 double LocalSession::get_selectionend(int highlight_only)
462 if(highlight_only || !EQUIV(selectionstart, selectionend))
474 double LocalSession::get_inpoint()
479 double LocalSession::get_outpoint()
484 int LocalSession::inpoint_valid()
486 return in_point >= 0;
489 int LocalSession::outpoint_valid()
491 return out_point >= 0;
494 void LocalSession::set_clip_path(Indexable *indexable)
496 char string[BCTEXTLEN];
498 fs.extract_name(string, indexable->path);
499 strcpy(clip_title, string);