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
26 #include "floatauto.h"
27 #include "localsession.h"
33 LocalSession::LocalSession(EDL *edl)
37 selectionstart = selectionend = 0;
38 in_point = out_point = -1;
39 strcpy(folder, CLIP_FOLDER);
40 sprintf(clip_title, "Program");
41 strcpy(clip_notes, "Hello world");
43 preview_start = preview_end = 0;
53 for(int i = 0; i < TOTAL_PANES; i++)
61 floatauto_type = Auto::BEZIER;
62 red = green = blue = 0;
65 LocalSession::~LocalSession()
69 void LocalSession::copy_from(LocalSession *that)
71 strcpy(clip_title, that->clip_title);
72 strcpy(clip_notes, that->clip_notes);
73 strcpy(folder, that->folder);
74 in_point = that->in_point;
75 loop_playback = that->loop_playback;
76 loop_start = that->loop_start;
77 loop_end = that->loop_end;
78 out_point = that->out_point;
79 selectionend = that->selectionend;
80 selectionstart = that->selectionstart;
81 x_pane = that->x_pane;
82 y_pane = that->y_pane;
84 for(int i = 0; i < TOTAL_PANES; i++)
86 view_start[i] = that->view_start[i];
87 track_start[i] = that->track_start[i];
90 zoom_sample = that->zoom_sample;
91 zoom_y = that->zoom_y;
92 zoom_track = that->zoom_track;
93 preview_start = that->preview_start;
94 preview_end = that->preview_end;
97 automation_min = that->automation_min;
98 automation_max = that->automation_max;
99 floatauto_type = that->floatauto_type;
103 void LocalSession::save_xml(FileXML *file, double start)
105 file->tag.set_title("LOCALSESSION");
107 file->tag.set_property("IN_POINT", in_point - start);
108 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
109 file->tag.set_property("LOOP_START", loop_start - start);
110 file->tag.set_property("LOOP_END", loop_end - start);
111 file->tag.set_property("OUT_POINT", out_point - start);
112 file->tag.set_property("SELECTION_START", selectionstart - start);
113 file->tag.set_property("SELECTION_END", selectionend - start);
114 file->tag.set_property("CLIP_TITLE", clip_title);
115 file->tag.set_property("CLIP_NOTES", clip_notes);
116 file->tag.set_property("FOLDER", folder);
117 file->tag.set_property("X_PANE", x_pane);
118 file->tag.set_property("Y_PANE", y_pane);
120 char string[BCTEXTLEN];
121 for(int i = 0; i < TOTAL_PANES; i++)
123 sprintf(string, "TRACK_START%d", i);
124 file->tag.set_property(string, track_start[i]);
125 sprintf(string, "VIEW_START%d", i);
126 file->tag.set_property(string, view_start[i]);
129 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
130 //printf("EDLSession::save_session 1\n");
131 file->tag.set_property("ZOOMY", zoom_y);
132 //printf("EDLSession::save_session 1 %d\n", zoom_track);
133 file->tag.set_property("ZOOM_TRACK", zoom_track);
135 double preview_start = this->preview_start - start;
136 if(preview_start < 0) preview_start = 0;
137 double preview_end = this->preview_end - start;
138 if(preview_end < 0) preview_end = 0;
140 file->tag.set_property("PREVIEW_START", preview_start);
141 file->tag.set_property("PREVIEW_END", preview_end);
143 file->tag.set_property("RED", red);
144 file->tag.set_property("GREEN", green);
145 file->tag.set_property("BLUE", blue);
146 file->tag.set_property("AUTOMATION_MIN", automation_min);
147 file->tag.set_property("AUTOMATION_MAX", automation_max);
148 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
150 file->append_newline();
151 file->append_newline();
154 void LocalSession::synchronize_params(LocalSession *that)
156 loop_playback = that->loop_playback;
157 loop_start = that->loop_start;
158 loop_end = that->loop_end;
159 preview_start = that->preview_start;
160 preview_end = that->preview_end;
167 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
169 if(load_flags & LOAD_SESSION)
171 // moved to EDL::load_xml for paste to fill silence.
172 // clipboard_length = 0;
173 // Overwritten by MWindow::load_filenames
174 file->tag.get_property("CLIP_TITLE", clip_title);
175 file->tag.get_property("CLIP_NOTES", clip_notes);
176 file->tag.get_property("FOLDER", folder);
177 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
178 loop_start = file->tag.get_property("LOOP_START", (double)0);
179 loop_end = file->tag.get_property("LOOP_END", (double)0);
180 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
181 selectionend = file->tag.get_property("SELECTION_END", (double)0);
182 x_pane = file->tag.get_property("X_PANE", -1);
183 y_pane = file->tag.get_property("Y_PANE", -1);
186 char string[BCTEXTLEN];
187 for(int i = 0; i < TOTAL_PANES; i++)
189 sprintf(string, "TRACK_START%d", i);
190 track_start[i] = file->tag.get_property(string, track_start[i]);
191 sprintf(string, "VIEW_START%d", i);
192 view_start[i] = file->tag.get_property(string, view_start[i]);
195 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
196 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
197 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
198 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
199 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
200 red = file->tag.get_property("RED", red);
201 green = file->tag.get_property("GREEN", green);
202 blue = file->tag.get_property("BLUE", blue);
203 automation_min = file->tag.get_property("AUTOMATION_MIN", automation_min);
204 automation_max = file->tag.get_property("AUTOMATION_MAX", automation_max);
205 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
209 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
210 // expect - this is additionally important in keyboard-only editing in viewer window
211 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
213 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
214 selectionend = file->tag.get_property("SELECTION_END", (double)0);
219 if(load_flags & LOAD_TIMEBAR)
221 in_point = file->tag.get_property("IN_POINT", (double)-1);
222 out_point = file->tag.get_property("OUT_POINT", (double)-1);
226 void LocalSession::boundaries()
228 zoom_sample = MAX(1, zoom_sample);
231 int LocalSession::load_defaults(BC_Hash *defaults)
233 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
234 loop_start = defaults->get("LOOP_START", (double)0);
235 loop_end = defaults->get("LOOP_END", (double)0);
236 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
237 selectionend = defaults->get("SELECTIONEND", selectionend);
238 // track_start = defaults->get("TRACK_START", 0);
239 // view_start = defaults->get("VIEW_START", 0);
240 zoom_sample = defaults->get("ZOOM_SAMPLE", 1);
241 zoom_y = defaults->get("ZOOMY", 64);
242 zoom_track = defaults->get("ZOOM_TRACK", 64);
243 red = defaults->get("RED", 0.0);
244 green = defaults->get("GREEN", 0.0);
245 blue = defaults->get("BLUE", 0.0);
246 automation_min = defaults->get("AUTOMATION_MIN", automation_min);
247 automation_max = defaults->get("AUTOMATION_MAX", automation_max);
248 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
249 x_pane = defaults->get("X_PANE", x_pane);
250 y_pane = defaults->get("Y_PANE", y_pane);
254 int LocalSession::save_defaults(BC_Hash *defaults)
256 defaults->update("LOOP_PLAYBACK", loop_playback);
257 defaults->update("LOOP_START", loop_start);
258 defaults->update("LOOP_END", loop_end);
259 defaults->update("SELECTIONSTART", selectionstart);
260 defaults->update("SELECTIONEND", selectionend);
261 // defaults->update("TRACK_START", track_start);
262 // defaults->update("VIEW_START", view_start);
263 defaults->update("ZOOM_SAMPLE", zoom_sample);
264 defaults->update("ZOOMY", zoom_y);
265 defaults->update("ZOOM_TRACK", zoom_track);
266 defaults->update("RED", red);
267 defaults->update("GREEN", green);
268 defaults->update("BLUE", blue);
269 defaults->update("AUTOMATION_MIN", automation_min);
270 defaults->update("AUTOMATION_MAX", automation_max);
271 defaults->update("FLOATAUTO_TYPE", floatauto_type);
272 defaults->update("X_PANE", x_pane);
273 defaults->update("Y_PANE", y_pane);
277 void LocalSession::set_selectionstart(double value)
279 this->selectionstart = value;
282 void LocalSession::set_selectionend(double value)
284 this->selectionend = value;
287 void LocalSession::set_inpoint(double value)
292 void LocalSession::set_outpoint(double value)
297 void LocalSession::unset_inpoint()
302 void LocalSession::unset_outpoint()
309 double LocalSession::get_selectionstart(int highlight_only)
311 if(highlight_only || !EQUIV(selectionstart, selectionend))
312 return selectionstart;
320 return selectionstart;
323 double LocalSession::get_selectionend(int highlight_only)
325 if(highlight_only || !EQUIV(selectionstart, selectionend))
337 double LocalSession::get_inpoint()
342 double LocalSession::get_outpoint()
347 int LocalSession::inpoint_valid()
349 return in_point >= 0;
352 int LocalSession::outpoint_valid()
354 return out_point >= 0;