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"
28 #include "localsession.h"
34 LocalSession::LocalSession(EDL *edl)
38 selectionstart = selectionend = 0;
39 in_point = out_point = -1;
40 strcpy(folder, CLIP_FOLDER);
41 sprintf(clip_title, _("Program"));
42 strcpy(clip_notes, _("Hello world"));
44 preview_start = preview_end = 0;
54 for(int i = 0; i < TOTAL_PANES; i++)
62 floatauto_type = Auto::BEZIER;
63 red = green = blue = 0;
66 LocalSession::~LocalSession()
70 void LocalSession::copy_from(LocalSession *that)
72 strcpy(clip_title, that->clip_title);
73 strcpy(clip_notes, that->clip_notes);
74 strcpy(folder, that->folder);
75 in_point = that->in_point;
76 loop_playback = that->loop_playback;
77 loop_start = that->loop_start;
78 loop_end = that->loop_end;
79 out_point = that->out_point;
80 selectionend = that->selectionend;
81 selectionstart = that->selectionstart;
82 x_pane = that->x_pane;
83 y_pane = that->y_pane;
85 for(int i = 0; i < TOTAL_PANES; i++)
87 view_start[i] = that->view_start[i];
88 track_start[i] = that->track_start[i];
91 zoom_sample = that->zoom_sample;
92 zoom_y = that->zoom_y;
93 zoom_track = that->zoom_track;
94 preview_start = that->preview_start;
95 preview_end = that->preview_end;
98 automation_min = that->automation_min;
99 automation_max = that->automation_max;
100 floatauto_type = that->floatauto_type;
104 void LocalSession::save_xml(FileXML *file, double start)
106 file->tag.set_title("LOCALSESSION");
108 file->tag.set_property("IN_POINT", in_point - start);
109 file->tag.set_property("LOOP_PLAYBACK", loop_playback);
110 file->tag.set_property("LOOP_START", loop_start - start);
111 file->tag.set_property("LOOP_END", loop_end - start);
112 file->tag.set_property("OUT_POINT", out_point - start);
113 file->tag.set_property("SELECTION_START", selectionstart - start);
114 file->tag.set_property("SELECTION_END", selectionend - start);
115 file->tag.set_property("CLIP_TITLE", clip_title);
116 file->tag.set_property("CLIP_NOTES", clip_notes);
117 file->tag.set_property("FOLDER", folder);
118 file->tag.set_property("X_PANE", x_pane);
119 file->tag.set_property("Y_PANE", y_pane);
121 char string[BCTEXTLEN];
122 for(int i = 0; i < TOTAL_PANES; i++)
124 sprintf(string, "TRACK_START%d", i);
125 file->tag.set_property(string, track_start[i]);
126 sprintf(string, "VIEW_START%d", i);
127 file->tag.set_property(string, view_start[i]);
130 file->tag.set_property("ZOOM_SAMPLE", zoom_sample);
131 //printf("EDLSession::save_session 1\n");
132 file->tag.set_property("ZOOMY", zoom_y);
133 //printf("EDLSession::save_session 1 %d\n", zoom_track);
134 file->tag.set_property("ZOOM_TRACK", zoom_track);
136 double preview_start = this->preview_start - start;
137 if(preview_start < 0) preview_start = 0;
138 double preview_end = this->preview_end - start;
139 if(preview_end < 0) preview_end = 0;
141 file->tag.set_property("PREVIEW_START", preview_start);
142 file->tag.set_property("PREVIEW_END", preview_end);
144 file->tag.set_property("RED", red);
145 file->tag.set_property("GREEN", green);
146 file->tag.set_property("BLUE", blue);
147 file->tag.set_property("AUTOMATION_MIN", automation_min);
148 file->tag.set_property("AUTOMATION_MAX", automation_max);
149 file->tag.set_property("FLOATAUTO_TYPE", floatauto_type);
151 file->append_newline();
152 file->append_newline();
155 void LocalSession::synchronize_params(LocalSession *that)
157 loop_playback = that->loop_playback;
158 loop_start = that->loop_start;
159 loop_end = that->loop_end;
160 preview_start = that->preview_start;
161 preview_end = that->preview_end;
168 void LocalSession::load_xml(FileXML *file, unsigned long load_flags)
170 if(load_flags & LOAD_SESSION)
172 // moved to EDL::load_xml for paste to fill silence.
173 // clipboard_length = 0;
174 // Overwritten by MWindow::load_filenames
175 file->tag.get_property("CLIP_TITLE", clip_title);
176 file->tag.get_property("CLIP_NOTES", clip_notes);
177 file->tag.get_property("FOLDER", folder);
178 loop_playback = file->tag.get_property("LOOP_PLAYBACK", 0);
179 loop_start = file->tag.get_property("LOOP_START", (double)0);
180 loop_end = file->tag.get_property("LOOP_END", (double)0);
181 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
182 selectionend = file->tag.get_property("SELECTION_END", (double)0);
183 x_pane = file->tag.get_property("X_PANE", -1);
184 y_pane = file->tag.get_property("Y_PANE", -1);
187 char string[BCTEXTLEN];
188 for(int i = 0; i < TOTAL_PANES; i++)
190 sprintf(string, "TRACK_START%d", i);
191 track_start[i] = file->tag.get_property(string, track_start[i]);
192 sprintf(string, "VIEW_START%d", i);
193 view_start[i] = file->tag.get_property(string, view_start[i]);
196 zoom_sample = file->tag.get_property("ZOOM_SAMPLE", zoom_sample);
197 zoom_y = file->tag.get_property("ZOOMY", zoom_y);
198 zoom_track = file->tag.get_property("ZOOM_TRACK", zoom_track);
199 preview_start = file->tag.get_property("PREVIEW_START", preview_start);
200 preview_end = file->tag.get_property("PREVIEW_END", preview_end);
201 red = file->tag.get_property("RED", red);
202 green = file->tag.get_property("GREEN", green);
203 blue = file->tag.get_property("BLUE", blue);
204 automation_min = file->tag.get_property("AUTOMATION_MIN", automation_min);
205 automation_max = file->tag.get_property("AUTOMATION_MAX", automation_max);
206 floatauto_type = file->tag.get_property("FLOATAUTO_TYPE", floatauto_type);
210 // on operations like cut, paste, slice, clear... we should also undo the cursor position as users
211 // expect - this is additionally important in keyboard-only editing in viewer window
212 if(load_flags & LOAD_SESSION || load_flags & LOAD_TIMEBAR)
214 selectionstart = file->tag.get_property("SELECTION_START", (double)0);
215 selectionend = file->tag.get_property("SELECTION_END", (double)0);
220 if(load_flags & LOAD_TIMEBAR)
222 in_point = file->tag.get_property("IN_POINT", (double)-1);
223 out_point = file->tag.get_property("OUT_POINT", (double)-1);
227 void LocalSession::boundaries()
229 zoom_sample = MAX(1, zoom_sample);
232 int LocalSession::load_defaults(BC_Hash *defaults)
234 loop_playback = defaults->get("LOOP_PLAYBACK", 0);
235 loop_start = defaults->get("LOOP_START", (double)0);
236 loop_end = defaults->get("LOOP_END", (double)0);
237 selectionstart = defaults->get("SELECTIONSTART", selectionstart);
238 selectionend = defaults->get("SELECTIONEND", selectionend);
239 // track_start = defaults->get("TRACK_START", 0);
240 // view_start = defaults->get("VIEW_START", 0);
241 zoom_sample = defaults->get("ZOOM_SAMPLE", 1);
242 zoom_y = defaults->get("ZOOMY", 64);
243 zoom_track = defaults->get("ZOOM_TRACK", 64);
244 red = defaults->get("RED", 0.0);
245 green = defaults->get("GREEN", 0.0);
246 blue = defaults->get("BLUE", 0.0);
247 automation_min = defaults->get("AUTOMATION_MIN", automation_min);
248 automation_max = defaults->get("AUTOMATION_MAX", automation_max);
249 floatauto_type = defaults->get("FLOATAUTO_TYPE", floatauto_type);
250 x_pane = defaults->get("X_PANE", x_pane);
251 y_pane = defaults->get("Y_PANE", y_pane);
255 int LocalSession::save_defaults(BC_Hash *defaults)
257 defaults->update("LOOP_PLAYBACK", loop_playback);
258 defaults->update("LOOP_START", loop_start);
259 defaults->update("LOOP_END", loop_end);
260 defaults->update("SELECTIONSTART", selectionstart);
261 defaults->update("SELECTIONEND", selectionend);
262 // defaults->update("TRACK_START", track_start);
263 // defaults->update("VIEW_START", view_start);
264 defaults->update("ZOOM_SAMPLE", zoom_sample);
265 defaults->update("ZOOMY", zoom_y);
266 defaults->update("ZOOM_TRACK", zoom_track);
267 defaults->update("RED", red);
268 defaults->update("GREEN", green);
269 defaults->update("BLUE", blue);
270 defaults->update("AUTOMATION_MIN", automation_min);
271 defaults->update("AUTOMATION_MAX", automation_max);
272 defaults->update("FLOATAUTO_TYPE", floatauto_type);
273 defaults->update("X_PANE", x_pane);
274 defaults->update("Y_PANE", y_pane);
278 void LocalSession::set_selectionstart(double value)
280 this->selectionstart = value;
283 void LocalSession::set_selectionend(double value)
285 this->selectionend = value;
288 void LocalSession::set_inpoint(double value)
293 void LocalSession::set_outpoint(double value)
298 void LocalSession::unset_inpoint()
303 void LocalSession::unset_outpoint()
310 double LocalSession::get_selectionstart(int highlight_only)
312 if(highlight_only || !EQUIV(selectionstart, selectionend))
313 return selectionstart;
321 return selectionstart;
324 double LocalSession::get_selectionend(int highlight_only)
326 if(highlight_only || !EQUIV(selectionstart, selectionend))
338 double LocalSession::get_inpoint()
343 double LocalSession::get_outpoint()
348 int LocalSession::inpoint_valid()
350 return in_point >= 0;
353 int LocalSession::outpoint_valid()
355 return out_point >= 0;