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"
27 #include "floatauto.h"
29 #include "localsession.h"
32 static const char *xml_autogrouptypes_titlesmax[] =
34 "AUTOGROUPTYPE_AUDIO_FADE_MAX",
35 "AUTOGROUPTYPE_VIDEO_FADE_MAX",
36 "AUTOGROUPTYPE_ZOOM_MAX",
37 "AUTOGROUPTYPE_SPEED_MAX",
38 "AUTOGROUPTYPE_X_MAX",
39 "AUTOGROUPTYPE_Y_MAX",
40 "AUTOGROUPTYPE_INT255_MAX"
43 static const char *xml_autogrouptypes_titlesmin[] =
45 "AUTOGROUPTYPE_AUDIO_FADE_MIN",
46 "AUTOGROUPTYPE_VIDEO_FADE_MIN",
47 "AUTOGROUPTYPE_ZOOM_MIN",
48 "AUTOGROUPTYPE_SPEED_MIN",
49 "AUTOGROUPTYPE_X_MIN",
50 "AUTOGROUPTYPE_Y_MIN",
51 "AUTOGROUPTYPE_INT255_MIN"
55 LocalSession::LocalSession(EDL *edl)
59 selectionstart = selectionend = 0;
60 in_point = out_point = -1;
61 strcpy(folder, CLIP_FOLDER);
62 sprintf(clip_title, _("Program"));
63 strcpy(clip_notes, _("Hello world"));
66 loop_start = loop_end = 0;
69 preview_start = preview_end = 0;
70 zoom_sample = DEFAULT_ZOOM_TIME;
75 for(int i = 0; i < TOTAL_PANES; i++) {
80 automation_mins[AUTOGROUPTYPE_AUDIO_FADE] = -80;
81 automation_maxs[AUTOGROUPTYPE_AUDIO_FADE] = 6;
83 automation_mins[AUTOGROUPTYPE_VIDEO_FADE] = 0;
84 automation_maxs[AUTOGROUPTYPE_VIDEO_FADE] = 100;
86 automation_mins[AUTOGROUPTYPE_ZOOM] = 0.001;
87 automation_maxs[AUTOGROUPTYPE_ZOOM] = 4;
89 automation_mins[AUTOGROUPTYPE_SPEED] = 0.05;
90 automation_maxs[AUTOGROUPTYPE_SPEED] = 3;
92 automation_mins[AUTOGROUPTYPE_X] = -100;
93 automation_maxs[AUTOGROUPTYPE_X] = 100;
95 automation_mins[AUTOGROUPTYPE_Y] = -100;
96 automation_maxs[AUTOGROUPTYPE_Y] = 100;
98 automation_mins[AUTOGROUPTYPE_INT255] = 0;
99 automation_maxs[AUTOGROUPTYPE_INT255] = 255;
101 zoombar_showautotype = AUTOGROUPTYPE_AUDIO_FADE;
103 floatauto_type = FloatAuto::SMOOTH;
105 red = green = blue = 0;
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(folder, that->folder);
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_track = that->zoom_track;
136 preview_start = that->preview_start;
137 preview_end = that->preview_end;
141 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
142 automation_mins[i] = that->automation_mins[i];
143 automation_maxs[i] = that->automation_maxs[i];
145 floatauto_type = that->floatauto_type;
150 void LocalSession::save_xml(FileXML *file, double start)
152 file->tag.set_title("LOCALSESSION");
154 file->tag.set_property("IN_POINT", in_point - start);
155 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
156 file->tag.set_property("LOOP_START", loop_start - start);
157 file->tag.set_property("LOOP_END", loop_end - start);
158 file->tag.set_property("OUT_POINT", out_point - start);
159 file->tag.set_property("SELECTION_START", selectionstart - start);
160 file->tag.set_property("SELECTION_END", selectionend - start);
161 file->tag.set_property("CLIP_TITLE", clip_title);
162 file->tag.set_property("CLIP_NOTES", clip_notes);
163 file->tag.set_property("FOLDER", folder);
164 file->tag.set_property("X_PANE", x_pane);
165 file->tag.set_property("Y_PANE", y_pane);
167 char string[BCTEXTLEN];
168 for(int i = 0; i < TOTAL_PANES; i++)
170 sprintf(string, "TRACK_START%d", i);
171 file->tag.set_property(string, track_start[i]);
172 sprintf(string, "VIEW_START%d", i);
173 file->tag.set_property(string, view_start[i]);
176 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
177 //printf("EDLSession::save_session 1\n");
178 file->tag.set_property("ZOOMY", zoom_y);
179 //printf("EDLSession::save_session 1 %d\n", zoom_track);
180 file->tag.set_property("ZOOM_TRACK", zoom_track);
182 double preview_start = this->preview_start - start;
183 if(preview_start < 0) preview_start = 0;
184 double preview_end = this->preview_end - start;
185 if(preview_end < 0) preview_end = 0;
187 file->tag.set_property("PREVIEW_START", preview_start);
188 file->tag.set_property("PREVIEW_END", preview_end);
189 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
191 file->tag.set_property("RED", red);
192 file->tag.set_property("GREEN", green);
193 file->tag.set_property("BLUE", blue);
195 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
196 if (!Automation::autogrouptypes_fixedrange[i]) {
197 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
198 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
203 file->tag.set_title("/LOCALSESSION");
205 file->append_newline();
206 file->append_newline();
209 void LocalSession::synchronize_params(LocalSession *that)
211 loop_playback = that->loop_playback;
212 loop_start = that->loop_start;
213 loop_end = that->loop_end;
214 preview_start = that->preview_start;
215 preview_end = that->preview_end;
222 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
224 if(load_flags & LOAD_SESSION)
226 // moved to EDL::load_xml for paste to fill silence.
227 // clipboard_length = 0;
228 // Overwritten by MWindow::load_filenames
229 file->tag.get_property("CLIP_TITLE", clip_title);
230 file->tag.get_property("CLIP_NOTES", clip_notes);
231 file->tag.get_property("FOLDER", folder);
232 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
233 loop_start = file->tag.get_property("LOOP_START", (double)0);
234 loop_end = file->tag.get_property("LOOP_END", (double)0);
235 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
236 selectionend = file->tag.get_property("SELECTION_END", (double)0);
237 x_pane = file->tag.get_property("X_PANE", -1);
238 y_pane = file->tag.get_property("Y_PANE", -1);
241 char string[BCTEXTLEN];
242 for(int i = 0; i < TOTAL_PANES; i++)
244 sprintf(string, "TRACK_START%d", i);
245 track_start[i] = file->tag.get_property(string, track_start[i]);
246 sprintf(string, "VIEW_START%d", i);
247 view_start[i] = file->tag.get_property(string, view_start[i]);
250 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
251 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
252 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
253 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
254 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
255 red = file->tag.get_property("RED", red);
256 green = file->tag.get_property("GREEN", green);
257 blue = file->tag.get_property("BLUE", blue);
260 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
261 if (!Automation::autogrouptypes_fixedrange[i]) {
262 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
263 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
266 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
270 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
271 // expect - this is additionally important in keyboard-only editing in viewer window
272 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
274 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
275 selectionend = file->tag.get_property("SELECTION_END", (double)0);
280 if(load_flags & LOAD_TIMEBAR)
282 in_point = file->tag.get_property("IN_POINT", (double)-1);
283 out_point = file->tag.get_property("OUT_POINT", (double)-1);
287 void LocalSession::boundaries()
289 zoom_sample = MAX(1, zoom_sample);
292 int LocalSession::load_defaults(BC_Hash *defaults)
294 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
295 loop_start = defaults->get("LOOP_START", (double)0);
296 loop_end = defaults->get("LOOP_END", (double)0);
297 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
298 selectionend = defaults->get("SELECTIONEND", selectionend);
299 // track_start = defaults->get("TRACK_START", 0);
300 // view_start = defaults->get("VIEW_START", 0);
301 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
302 zoom_y = defaults->get("ZOOMY", 64);
303 zoom_track = defaults->get("ZOOM_TRACK", 64);
304 red = defaults->get("RED", 0.0);
305 green = defaults->get("GREEN", 0.0);
306 blue = defaults->get("BLUE", 0.0);
308 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
309 if (!Automation::autogrouptypes_fixedrange[i]) {
310 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
311 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
315 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
316 x_pane = defaults->get("X_PANE", x_pane);
317 y_pane = defaults->get("Y_PANE", y_pane);
322 int LocalSession::save_defaults(BC_Hash *defaults)
324 defaults->update("LOOP_PLAYBACK", loop_playback);
325 defaults->update("LOOP_START", loop_start);
326 defaults->update("LOOP_END", loop_end);
327 defaults->update("SELECTIONSTART", selectionstart);
328 defaults->update("SELECTIONEND", selectionend);
329 // defaults->update("TRACK_START", track_start);
330 // defaults->update("VIEW_START", view_start);
331 defaults->update("ZOOM_SAMPLE", zoom_sample);
332 defaults->update("ZOOMY", zoom_y);
333 defaults->update("ZOOM_TRACK", zoom_track);
334 defaults->update("RED", red);
335 defaults->update("GREEN", green);
336 defaults->update("BLUE", blue);
338 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
339 if (!Automation::autogrouptypes_fixedrange[i]) {
340 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
341 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
345 defaults->update("FLOATAUTO_TYPE", floatauto_type);
346 defaults->update("X_PANE", x_pane);
347 defaults->update("Y_PANE", y_pane);
351 void LocalSession::set_selectionstart(double value)
353 this->selectionstart = value;
356 void LocalSession::set_selectionend(double value)
358 this->selectionend = value;
361 void LocalSession::set_inpoint(double value)
366 void LocalSession::set_outpoint(double value)
371 void LocalSession::unset_inpoint()
376 void LocalSession::unset_outpoint()
381 void LocalSession::set_playback_start(double value)
383 if( playback_end < 0 ) return;
384 playback_start = value;
388 void LocalSession::set_playback_end(double value)
390 if( value < playback_start ) {
391 if( playback_end < 0 )
392 playback_end = playback_start;
393 playback_start = value;
395 else if( playback_end < 0 || value > playback_end )
396 playback_end = value;
400 double LocalSession::get_selectionstart(int highlight_only)
402 if(highlight_only || !EQUIV(selectionstart, selectionend))
403 return selectionstart;
411 return selectionstart;
414 double LocalSession::get_selectionend(int highlight_only)
416 if(highlight_only || !EQUIV(selectionstart, selectionend))
428 double LocalSession::get_inpoint()
433 double LocalSession::get_outpoint()
438 int LocalSession::inpoint_valid()
440 return in_point >= 0;
443 int LocalSession::outpoint_valid()
445 return out_point >= 0;