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"
28 #include "floatauto.h"
30 #include "localsession.h"
33 static const char *xml_autogrouptypes_titlesmax[] =
35 "AUTOGROUPTYPE_AUDIO_FADE_MAX",
36 "AUTOGROUPTYPE_VIDEO_FADE_MAX",
37 "AUTOGROUPTYPE_ZOOM_MAX",
38 "AUTOGROUPTYPE_SPEED_MAX",
39 "AUTOGROUPTYPE_X_MAX",
40 "AUTOGROUPTYPE_Y_MAX",
41 "AUTOGROUPTYPE_INT255_MAX"
44 static const char *xml_autogrouptypes_titlesmin[] =
46 "AUTOGROUPTYPE_AUDIO_FADE_MIN",
47 "AUTOGROUPTYPE_VIDEO_FADE_MIN",
48 "AUTOGROUPTYPE_ZOOM_MIN",
49 "AUTOGROUPTYPE_SPEED_MIN",
50 "AUTOGROUPTYPE_X_MIN",
51 "AUTOGROUPTYPE_Y_MIN",
52 "AUTOGROUPTYPE_INT255_MIN"
56 LocalSession::LocalSession(EDL *edl)
60 selectionstart = selectionend = 0;
61 in_point = out_point = -1;
62 awindow_folder = AW_CLIP_FOLDER;
63 sprintf(clip_title, _("Program"));
64 strcpy(clip_notes, _("Hello world"));
67 loop_start = loop_end = 0;
70 preview_start = preview_end = 0;
71 zoom_sample = DEFAULT_ZOOM_TIME;
76 for(int i = 0; i < TOTAL_PANES; i++) {
81 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
82 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
84 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
85 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
87 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.005;
88 automation_maxs[AUTOGROUPTYPE_ZOOM] = 5.000;
90 automation_mins[AUTOGROUPTYPE_SPEED] = 0.005;
91 automation_maxs[AUTOGROUPTYPE_SPEED] = 5.000;
93 automation_mins[AUTOGROUPTYPE_X] = -100;
94 automation_maxs[AUTOGROUPTYPE_X] = 100;
96 automation_mins[AUTOGROUPTYPE_Y] = -100;
97 automation_maxs[AUTOGROUPTYPE_Y] = 100;
99 automation_mins[AUTOGROUPTYPE_INT255] = 0;
100 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
102 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
104 floatauto_type = FloatAuto::SMOOTH;
106 red = green = blue = 0;
107 red_max = green_max = blue_max = 0;
111 LocalSession::~LocalSession()
115 void LocalSession::copy_from(LocalSession *that)
117 strcpy(clip_title, that->clip_title);
118 strcpy(clip_notes, that->clip_notes);
119 awindow_folder = that->awindow_folder;
120 in_point = that->in_point;
121 loop_playback = that->loop_playback;
122 loop_start = that->loop_start;
123 loop_end = that->loop_end;
124 out_point = that->out_point;
125 selectionend = that->selectionend;
126 selectionstart = that->selectionstart;
127 x_pane = that->x_pane;
128 y_pane = that->y_pane;
130 for(int i = 0; i < TOTAL_PANES; i++)
132 view_start[i] = that->view_start[i];
133 track_start[i] = that->track_start[i];
136 zoom_sample = that->zoom_sample;
137 zoom_y = that->zoom_y;
138 zoom_track = that->zoom_track;
139 preview_start = that->preview_start;
140 preview_end = that->preview_end;
144 red_max = that->red_max;
145 green_max = that->green_max;
146 blue_max = that->blue_max;
147 use_max = that->use_max;
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_NOTES", clip_notes);
169 file->tag.set_property("AWINDOW_FOLDER", awindow_folder);
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 < 0) preview_end = 0;
193 file->tag.set_property("PREVIEW_START", preview_start);
194 file->tag.set_property("PREVIEW_END", preview_end);
195 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
197 file->tag.set_property("RED", red);
198 file->tag.set_property("GREEN", green);
199 file->tag.set_property("BLUE", blue);
200 file->tag.set_property("RED_MAX", red_max);
201 file->tag.set_property("GREEN_MAX", green_max);
202 file->tag.set_property("BLUE_MAX", blue_max);
203 file->tag.set_property("USE_MAX", use_max);
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]);
213 file->tag.set_title("/LOCALSESSION");
215 file->append_newline();
216 file->append_newline();
219 void LocalSession::synchronize_params(LocalSession *that)
221 loop_playback = that->loop_playback;
222 loop_start = that->loop_start;
223 loop_end = that->loop_end;
224 preview_start = that->preview_start;
225 preview_end = that->preview_end;
229 red_max = that->red_max;
230 green_max = that->green_max;
231 blue_max = that->blue_max;
235 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
237 if(load_flags & LOAD_SESSION)
239 // moved to EDL::load_xml for paste to fill silence.
240 // clipboard_length = 0;
241 // Overwritten by MWindow::load_filenames
242 file->tag.get_property("CLIP_TITLE", clip_title);
243 file->tag.get_property("CLIP_NOTES", clip_notes);
244 const char *folder = file->tag.get_property("FOLDER");
246 awindow_folder = AWindowGUI::folder_number(folder);
247 if( awindow_folder < 0 ) awindow_folder = AW_MEDIA_FOLDER;
249 awindow_folder = file->tag.get_property("AWINDOW_FOLDER", awindow_folder);
250 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
251 loop_start = file->tag.get_property("LOOP_START", (double)0);
252 loop_end = file->tag.get_property("LOOP_END", (double)0);
253 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
254 selectionend = file->tag.get_property("SELECTION_END", (double)0);
255 x_pane = file->tag.get_property("X_PANE", -1);
256 y_pane = file->tag.get_property("Y_PANE", -1);
259 char string[BCTEXTLEN];
260 for(int i = 0; i < TOTAL_PANES; i++)
262 sprintf(string, "TRACK_START%d", i);
263 track_start[i] = file->tag.get_property(string, track_start[i]);
264 sprintf(string, "VIEW_START%d", i);
265 view_start[i] = file->tag.get_property(string, view_start[i]);
268 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
269 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
270 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
271 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
272 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
273 red = file->tag.get_property("RED", red);
274 green = file->tag.get_property("GREEN", green);
275 blue = file->tag.get_property("BLUE", blue);
276 red_max = file->tag.get_property("RED_MAX", red_max);
277 green_max = file->tag.get_property("GREEN_MAX", green_max);
278 blue_max = file->tag.get_property("BLUE_MAX", blue_max);
279 use_max = file->tag.get_property("USE_MAX", use_max);
281 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
282 if (!Automation::autogrouptypes_fixedrange[i]) {
283 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
284 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
287 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
291 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
292 // expect - this is additionally important in keyboard-only editing in viewer window
293 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
295 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
296 selectionend = file->tag.get_property("SELECTION_END", (double)0);
301 if(load_flags & LOAD_TIMEBAR)
303 in_point = file->tag.get_property("IN_POINT", (double)-1);
304 out_point = file->tag.get_property("OUT_POINT", (double)-1);
308 void LocalSession::boundaries()
310 zoom_sample = MAX(1, zoom_sample);
313 int LocalSession::load_defaults(BC_Hash *defaults)
315 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
316 loop_start = defaults->get("LOOP_START", (double)0);
317 loop_end = defaults->get("LOOP_END", (double)0);
318 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
319 selectionend = defaults->get("SELECTIONEND", selectionend);
320 // track_start = defaults->get("TRACK_START", 0);
321 // view_start = defaults->get("VIEW_START", 0);
322 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
323 zoom_y = defaults->get("ZOOMY", 64);
324 zoom_track = defaults->get("ZOOM_TRACK", 64);
325 red = defaults->get("RED", 0.0);
326 green = defaults->get("GREEN", 0.0);
327 blue = defaults->get("BLUE", 0.0);
328 red_max = defaults->get("RED_MAX", 0.0);
329 green_max = defaults->get("GREEN_MAX", 0.0);
330 blue_max = defaults->get("BLUE_MAX", 0.0);
331 use_max = defaults->get("USE_MAX", 0);
333 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
334 if (!Automation::autogrouptypes_fixedrange[i]) {
335 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
336 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
340 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
341 x_pane = defaults->get("X_PANE", x_pane);
342 y_pane = defaults->get("Y_PANE", y_pane);
347 int LocalSession::save_defaults(BC_Hash *defaults)
349 defaults->update("LOOP_PLAYBACK", loop_playback);
350 defaults->update("LOOP_START", loop_start);
351 defaults->update("LOOP_END", loop_end);
352 defaults->update("SELECTIONSTART", selectionstart);
353 defaults->update("SELECTIONEND", selectionend);
354 // defaults->update("TRACK_START", track_start);
355 // defaults->update("VIEW_START", view_start);
356 defaults->update("ZOOM_SAMPLE", zoom_sample);
357 defaults->update("ZOOMY", zoom_y);
358 defaults->update("ZOOM_TRACK", zoom_track);
359 defaults->update("RED", red);
360 defaults->update("GREEN", green);
361 defaults->update("BLUE", blue);
362 defaults->update("RED_MAX", red_max);
363 defaults->update("GREEN_MAX", green_max);
364 defaults->update("BLUE_MAX", blue_max);
365 defaults->update("USE_MAX", use_max);
367 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
368 if (!Automation::autogrouptypes_fixedrange[i]) {
369 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
370 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
374 defaults->update("FLOATAUTO_TYPE", floatauto_type);
375 defaults->update("X_PANE", x_pane);
376 defaults->update("Y_PANE", y_pane);
380 void LocalSession::set_selectionstart(double value)
382 this->selectionstart = value;
385 void LocalSession::set_selectionend(double value)
387 this->selectionend = value;
390 void LocalSession::set_inpoint(double value)
395 void LocalSession::set_outpoint(double value)
400 void LocalSession::unset_inpoint()
405 void LocalSession::unset_outpoint()
410 void LocalSession::set_playback_start(double value)
412 if( playback_end < 0 ) return;
413 playback_start = value;
417 void LocalSession::set_playback_end(double value)
419 if( value < playback_start ) {
420 if( playback_end < 0 )
421 playback_end = playback_start;
422 playback_start = value;
424 else if( playback_end < 0 || value > playback_end )
425 playback_end = value;
429 double LocalSession::get_selectionstart(int highlight_only)
431 if(highlight_only || !EQUIV(selectionstart, selectionend))
432 return selectionstart;
440 return selectionstart;
443 double LocalSession::get_selectionend(int highlight_only)
445 if(highlight_only || !EQUIV(selectionstart, selectionend))
457 double LocalSession::get_inpoint()
462 double LocalSession::get_outpoint()
467 int LocalSession::inpoint_valid()
469 return in_point >= 0;
472 int LocalSession::outpoint_valid()
474 return out_point >= 0;