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;
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 awindow_folder = that->awindow_folder;
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_track = that->zoom_track;
137 preview_start = that->preview_start;
138 preview_end = that->preview_end;
142 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
143 automation_mins[i] = that->automation_mins[i];
144 automation_maxs[i] = that->automation_maxs[i];
146 floatauto_type = that->floatauto_type;
151 void LocalSession::save_xml(FileXML *file, double start)
153 file->tag.set_title("LOCALSESSION");
155 file->tag.set_property("IN_POINT", in_point - start);
156 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
157 file->tag.set_property("LOOP_START", loop_start - start);
158 file->tag.set_property("LOOP_END", loop_end - start);
159 file->tag.set_property("OUT_POINT", out_point - start);
160 file->tag.set_property("SELECTION_START", selectionstart - start);
161 file->tag.set_property("SELECTION_END", selectionend - start);
162 file->tag.set_property("CLIP_TITLE", clip_title);
163 file->tag.set_property("CLIP_NOTES", clip_notes);
164 file->tag.set_property("AWINDOW_FOLDER", awindow_folder);
165 file->tag.set_property("X_PANE", x_pane);
166 file->tag.set_property("Y_PANE", y_pane);
168 char string[BCTEXTLEN];
169 for(int i = 0; i < TOTAL_PANES; i++)
171 sprintf(string, "TRACK_START%d", i);
172 file->tag.set_property(string, track_start[i]);
173 sprintf(string, "VIEW_START%d", i);
174 file->tag.set_property(string, view_start[i]);
177 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
178 //printf("EDLSession::save_session 1\n");
179 file->tag.set_property("ZOOMY", zoom_y);
180 //printf("EDLSession::save_session 1 %d\n", zoom_track);
181 file->tag.set_property("ZOOM_TRACK", zoom_track);
183 double preview_start = this->preview_start - start;
184 if(preview_start < 0) preview_start = 0;
185 double preview_end = this->preview_end - start;
186 if(preview_end < 0) preview_end = 0;
188 file->tag.set_property("PREVIEW_START", preview_start);
189 file->tag.set_property("PREVIEW_END", preview_end);
190 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
192 file->tag.set_property("RED", red);
193 file->tag.set_property("GREEN", green);
194 file->tag.set_property("BLUE", blue);
196 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
197 if (!Automation::autogrouptypes_fixedrange[i]) {
198 file->tag.set_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
199 file->tag.set_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
204 file->tag.set_title("/LOCALSESSION");
206 file->append_newline();
207 file->append_newline();
210 void LocalSession::synchronize_params(LocalSession *that)
212 loop_playback = that->loop_playback;
213 loop_start = that->loop_start;
214 loop_end = that->loop_end;
215 preview_start = that->preview_start;
216 preview_end = that->preview_end;
223 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
225 if(load_flags & LOAD_SESSION)
227 // moved to EDL::load_xml for paste to fill silence.
228 // clipboard_length = 0;
229 // Overwritten by MWindow::load_filenames
230 file->tag.get_property("CLIP_TITLE", clip_title);
231 file->tag.get_property("CLIP_NOTES", clip_notes);
232 const char *folder = file->tag.get_property("FOLDER");
234 awindow_folder = AWindowGUI::folder_number(folder);
235 if( awindow_folder < 0 ) awindow_folder = AW_MEDIA_FOLDER;
237 awindow_folder = file->tag.get_property("AWINDOW_FOLDER", awindow_folder);
238 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
239 loop_start = file->tag.get_property("LOOP_START", (double)0);
240 loop_end = file->tag.get_property("LOOP_END", (double)0);
241 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
242 selectionend = file->tag.get_property("SELECTION_END", (double)0);
243 x_pane = file->tag.get_property("X_PANE", -1);
244 y_pane = file->tag.get_property("Y_PANE", -1);
247 char string[BCTEXTLEN];
248 for(int i = 0; i < TOTAL_PANES; i++)
250 sprintf(string, "TRACK_START%d", i);
251 track_start[i] = file->tag.get_property(string, track_start[i]);
252 sprintf(string, "VIEW_START%d", i);
253 view_start[i] = file->tag.get_property(string, view_start[i]);
256 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
257 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
258 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
259 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
260 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
261 red = file->tag.get_property("RED", red);
262 green = file->tag.get_property("GREEN", green);
263 blue = file->tag.get_property("BLUE", blue);
266 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
267 if (!Automation::autogrouptypes_fixedrange[i]) {
268 automation_mins[i] = file->tag.get_property(xml_autogrouptypes_titlesmin[i],automation_mins[i]);
269 automation_maxs[i] = file->tag.get_property(xml_autogrouptypes_titlesmax[i],automation_maxs[i]);
272 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
276 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
277 // expect - this is additionally important in keyboard-only editing in viewer window
278 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
280 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
281 selectionend = file->tag.get_property("SELECTION_END", (double)0);
286 if(load_flags & LOAD_TIMEBAR)
288 in_point = file->tag.get_property("IN_POINT", (double)-1);
289 out_point = file->tag.get_property("OUT_POINT", (double)-1);
293 void LocalSession::boundaries()
295 zoom_sample = MAX(1, zoom_sample);
298 int LocalSession::load_defaults(BC_Hash *defaults)
300 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
301 loop_start = defaults->get("LOOP_START", (double)0);
302 loop_end = defaults->get("LOOP_END", (double)0);
303 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
304 selectionend = defaults->get("SELECTIONEND", selectionend);
305 // track_start = defaults->get("TRACK_START", 0);
306 // view_start = defaults->get("VIEW_START", 0);
307 zoom_sample = defaults->get("ZOOM_SAMPLE", DEFAULT_ZOOM_TIME);
308 zoom_y = defaults->get("ZOOMY", 64);
309 zoom_track = defaults->get("ZOOM_TRACK", 64);
310 red = defaults->get("RED", 0.0);
311 green = defaults->get("GREEN", 0.0);
312 blue = defaults->get("BLUE", 0.0);
314 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
315 if (!Automation::autogrouptypes_fixedrange[i]) {
316 automation_mins[i] = defaults->get(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
317 automation_maxs[i] = defaults->get(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
321 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
322 x_pane = defaults->get("X_PANE", x_pane);
323 y_pane = defaults->get("Y_PANE", y_pane);
328 int LocalSession::save_defaults(BC_Hash *defaults)
330 defaults->update("LOOP_PLAYBACK", loop_playback);
331 defaults->update("LOOP_START", loop_start);
332 defaults->update("LOOP_END", loop_end);
333 defaults->update("SELECTIONSTART", selectionstart);
334 defaults->update("SELECTIONEND", selectionend);
335 // defaults->update("TRACK_START", track_start);
336 // defaults->update("VIEW_START", view_start);
337 defaults->update("ZOOM_SAMPLE", zoom_sample);
338 defaults->update("ZOOMY", zoom_y);
339 defaults->update("ZOOM_TRACK", zoom_track);
340 defaults->update("RED", red);
341 defaults->update("GREEN", green);
342 defaults->update("BLUE", blue);
344 for (int i = 0; i < AUTOGROUPTYPE_COUNT; i++) {
345 if (!Automation::autogrouptypes_fixedrange[i]) {
346 defaults->update(xml_autogrouptypes_titlesmin[i], automation_mins[i]);
347 defaults->update(xml_autogrouptypes_titlesmax[i], automation_maxs[i]);
351 defaults->update("FLOATAUTO_TYPE", floatauto_type);
352 defaults->update("X_PANE", x_pane);
353 defaults->update("Y_PANE", y_pane);
357 void LocalSession::set_selectionstart(double value)
359 this->selectionstart = value;
362 void LocalSession::set_selectionend(double value)
364 this->selectionend = value;
367 void LocalSession::set_inpoint(double value)
372 void LocalSession::set_outpoint(double value)
377 void LocalSession::unset_inpoint()
382 void LocalSession::unset_outpoint()
387 void LocalSession::set_playback_start(double value)
389 if( playback_end < 0 ) return;
390 playback_start = value;
394 void LocalSession::set_playback_end(double value)
396 if( value < playback_start ) {
397 if( playback_end < 0 )
398 playback_end = playback_start;
399 playback_start = value;
401 else if( playback_end < 0 || value > playback_end )
402 playback_end = value;
406 double LocalSession::get_selectionstart(int highlight_only)
408 if(highlight_only || !EQUIV(selectionstart, selectionend))
409 return selectionstart;
417 return selectionstart;
420 double LocalSession::get_selectionend(int highlight_only)
422 if(highlight_only || !EQUIV(selectionstart, selectionend))
434 double LocalSession::get_inpoint()
439 double LocalSession::get_outpoint()
444 int LocalSession::inpoint_valid()
446 return in_point >= 0;
449 int LocalSession::outpoint_valid()
451 return out_point >= 0;