asset menu size fixups, new picons+prefs, more timecode del, stretch scrollbars,...
[goodguy/history.git] / cinelerra-5.1 / cinelerra / edlsession.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "asset.h"
23 #include "assets.h"
24 #include "autoconf.h"
25 #include "awindowgui.h"
26 #include "bccmodels.h"
27 #include "bchash.h"
28 #include "clip.h"
29 #include "edl.h"
30 #include "edlsession.h"
31 #include "filexml.h"
32 #include "interlacemodes.h"
33 #include "overlayframe.inc"
34 #include "playbackconfig.h"
35 #include "recordconfig.h"
36 #include "tracks.h"
37 #include "workarounds.h"
38
39 int EDLSession::current_id = 0;
40
41 EDLSession::EDLSession(EDL *edl)
42 {
43         this->edl = edl;
44         for(int i = 0; i < MAXCHANNELS; i++)
45                 achannel_positions[i] = 0;
46         assetlist_format = ASSETS_ICONS;
47         for(int i = 0; i < ASSET_COLUMNS; i++)
48                 asset_columns[i] = 100;
49         auto_conf = new AutoConf;
50         awindow_folder = AW_MEDIA_FOLDER;
51         aspect_w = 4;  aspect_h = 3;
52         audio_channels = 2;
53         audio_tracks = 2;
54         autos_follow_edits = 1; // this is needed for predictability
55         auto_keyframes = 0;
56         brender_start = brender_end = 0.0;
57         clipboard_length = 0; // unused
58         color_model = BC_RGBA8888;
59         interlace_mode = ILACE_MODE_UNDETECTED;
60         crop_x1 = 0; crop_x2 = 320;
61         crop_y1 = 0; crop_y2 = 240;
62         eyedrop_radius = 0;
63         ruler_x1 = ruler_y1 = 0.0;
64         ruler_x2 = ruler_y2 = 0.0;
65         cursor_on_frames = 1;
66         typeless_keyframes = 0;
67         cwindow_dest = 0;
68         cwindow_mask = 0;
69         cwindow_meter = 0;
70         cwindow_operation = 0;
71         cwindow_scrollbars = 0;
72         cwindow_xscroll = cwindow_yscroll = 0;
73         cwindow_zoom = 1.0;
74         strcpy(default_atransition, "");
75         strcpy(default_vtransition, "");
76         default_transition_length = 1.0;
77         edit_handle_mode[0] = MOVE_ALL_EDITS;
78         edit_handle_mode[1] = MOVE_ONE_EDIT;
79         edit_handle_mode[2] = MOVE_NO_EDITS;
80         editing_mode = EDITING_IBEAM;
81         enable_duplex = 1;
82         folderlist_format = FOLDERS_ICONS;
83         frame_rate = 30000./1001;
84         frames_per_foot = 16;
85         highlighted_track = 0;
86         interpolation_type = CUBIC_CUBIC;
87         interpolate_raw = 1;
88         white_balance_raw = 1;
89         labels_follow_edits = 1;
90         mpeg4_deblock = 1;
91         plugins_follow_edits = 1;
92         single_standalone = 1;
93         meter_format = METER_DB;
94         min_meter_db = -85;
95         max_meter_db = 6;
96         output_w = 720;
97         output_h = 480;
98         playback_buffer = 4096;
99         playback_cursor_visible = 0;
100         playback_preload = 0;
101         decode_subtitles = 0;
102         subtitle_number = 0;
103         label_cells = 0;
104         program_no = 0;
105         playback_software_position = 0;
106 //      playback_strategy
107         real_time_playback = 0;
108         real_time_record = 0;
109         record_positioning = 1;
110         record_raw_stream = 0;
111         record_sync_drives = 0;
112         record_speed = frame_rate;
113         record_fragment_size = 2048;
114         record_write_length = 131072;
115         record_realtime_toc = 1;
116
117         safe_regions = 0;
118         sample_rate = 48000;
119         scrub_speed = 2.;
120         show_assets = 1;
121         show_titles = 1;
122         test_playback_edits = 1;
123         time_format = TIME_HMSF;
124         nudge_format = 1;
125         tool_window = 0;
126         for(int i = 0; i < MAXCHANNELS; i++) {
127                 vchannel_x[i] = 64*i;
128                 vchannel_y[i] = 0;
129         }
130         video_channels = 1;
131         aconfig_in = new AudioInConfig;
132         vconfig_in = new VideoInConfig;
133         recording_format = new Asset;
134         video_every_frame = 0;
135         video_asynchronous = 0;
136         video_tracks = 1;
137         video_write_length = 30;
138         view_follows_playback = 1;
139         vwindow_meter = 0;
140         vwindow_zoom = 1.;
141
142         playback_config = new PlaybackConfig;
143 }
144
145 EDLSession::~EDLSession()
146 {
147         delete aconfig_in;
148         delete auto_conf;
149         delete vconfig_in;
150         delete playback_config;
151         recording_format->Garbage::remove_user();
152 }
153
154
155 int EDLSession::need_rerender(EDLSession *ptr)
156 {
157         return ((playback_preload != ptr->playback_preload) ||
158                 (interpolation_type != ptr->interpolation_type) ||
159                 (video_every_frame != ptr->video_every_frame) ||
160                 (video_asynchronous != ptr->video_asynchronous) ||
161                 (real_time_playback != ptr->real_time_playback) ||
162                 (playback_software_position != ptr->playback_software_position) ||
163                 (test_playback_edits != ptr->test_playback_edits) ||
164                 (playback_buffer != ptr->playback_buffer) ||
165                 (decode_subtitles != ptr->decode_subtitles) ||
166                 (subtitle_number != ptr->subtitle_number) ||
167                 (interpolate_raw != ptr->interpolate_raw) ||
168                 (white_balance_raw != ptr->white_balance_raw));
169 }
170
171 void EDLSession::equivalent_output(EDLSession *session, double *result)
172 {
173         if(session->output_w != output_w ||
174                 session->output_h != output_h ||
175                 !EQUIV(session->frame_rate, frame_rate) ||
176                 session->color_model != color_model ||
177                 session->interpolation_type != interpolation_type ||
178                 session->interpolate_raw != interpolate_raw ||
179                 session->white_balance_raw != white_balance_raw ||
180                 session->mpeg4_deblock != mpeg4_deblock ||
181                 session->decode_subtitles != decode_subtitles ||
182                 session->subtitle_number != subtitle_number)
183                 *result = 0;
184
185 // If it's before the current brender_start, render extra data.
186 // If it's after brender_start, check brender map.
187         if(brender_start != session->brender_start &&
188                 (*result < 0 || *result > brender_start))
189                 *result = brender_start;
190 }
191
192
193 int EDLSession::load_defaults(BC_Hash *defaults)
194 {
195         char string[BCTEXTLEN];
196 // Default channel positions
197         for(int i = 0; i < MAXCHANNELS; i++)
198         {
199                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
200                 int default_position = i * 30;
201
202                 if(i == 0) default_position = 180;
203                 else
204                 if(i == 1) default_position = 0;
205                 else
206                 if(default_position == 90) default_position = 300;
207                 else
208                 if(default_position == 0) default_position = 330;
209
210                 achannel_positions[i] = defaults->get(string, default_position);
211         }
212         aconfig_in->load_defaults(defaults);
213         assetlist_format = defaults->get("ASSETLIST_FORMAT", ASSETS_ICONS);
214         aspect_w = defaults->get("ASPECTW", aspect_w);
215         aspect_h = defaults->get("ASPECTH", aspect_h);
216         for(int i = 0; i < ASSET_COLUMNS; i++)
217         {
218                 sprintf(string, "ASSET_COLUMN%d", i);
219                 asset_columns[i] = defaults->get(string, 100);
220         }
221         audio_channels = defaults->get("ACHANNELS", audio_channels);
222         audio_tracks = defaults->get("ATRACKS", audio_tracks);
223         auto_conf->load_defaults(defaults);
224         autos_follow_edits = defaults->get("AUTOS_FOLLOW_EDITS", 1);
225         brender_start = defaults->get("BRENDER_START", brender_start);
226         brender_end = defaults->get("BRENDER_END", brender_end);
227         BC_CModels::to_text(string, BC_RGBA8888);
228         color_model = BC_CModels::from_text(defaults->get("COLOR_MODEL", string));
229         eyedrop_radius = defaults->get("EYEDROP_RADIUS", 0);
230         ilacemode_to_xmltext(string, interlace_mode);
231         const char *ilace_mode = defaults->get("INTERLACE_MODE",string);
232         interlace_mode = ilacemode_from_xmltext(ilace_mode, ILACE_MODE_NOTINTERLACED);
233         crop_x1 = defaults->get("CROP_X1", 0);
234         crop_x2 = defaults->get("CROP_X2", 320);
235         crop_y1 = defaults->get("CROP_Y1", 0);
236         crop_y2 = defaults->get("CROP_Y2", 240);
237         ruler_x1 = defaults->get("RULER_X1", 0.0);
238         ruler_x2 = defaults->get("RULER_X2", 0.0);
239         ruler_y1 = defaults->get("RULER_Y1", 0.0);
240         ruler_y2 = defaults->get("RULER_Y2", 0.0);
241         awindow_folder = defaults->get("AWINDOW_FOLDER", awindow_folder);
242         cursor_on_frames = defaults->get("CURSOR_ON_FRAMES", 1);
243         typeless_keyframes = defaults->get("TYPELESS_KEYFRAMES", 0);
244         cwindow_dest = defaults->get("CWINDOW_DEST", 0);
245         cwindow_mask = defaults->get("CWINDOW_MASK", 0);
246         cwindow_meter = defaults->get("CWINDOW_METER", 0);
247         cwindow_operation = defaults->get("CWINDOW_OPERATION", 0);
248         cwindow_scrollbars = defaults->get("CWINDOW_SCROLLBARS", 0);
249         cwindow_xscroll = defaults->get("CWINDOW_XSCROLL", 0);
250         cwindow_yscroll = defaults->get("CWINDOW_YSCROLL", 0);
251         cwindow_zoom = defaults->get("CWINDOW_ZOOM", (float)1);
252         sprintf(default_atransition, _("Crossfade"));
253         defaults->get("DEFAULT_ATRANSITION", default_atransition);
254         sprintf(default_vtransition, _("Dissolve"));
255         defaults->get("DEFAULT_VTRANSITION", default_vtransition);
256         default_transition_length = defaults->get("DEFAULT_TRANSITION_LENGTH", (double)1);
257         edit_handle_mode[0] = defaults->get("EDIT_HANDLE_MODE0", MOVE_ALL_EDITS);
258         edit_handle_mode[1] = defaults->get("EDIT_HANDLE_MODE1", MOVE_ONE_EDIT);
259         edit_handle_mode[2] = defaults->get("EDIT_HANDLE_MODE2", MOVE_NO_EDITS);
260         editing_mode = defaults->get("EDITING_MODE", EDITING_IBEAM);
261         enable_duplex = defaults->get("ENABLE_DUPLEX", 1);
262         folderlist_format = defaults->get("FOLDERLIST_FORMAT", FOLDERS_TEXT);
263         frame_rate = defaults->get("FRAMERATE", frame_rate);
264         frames_per_foot = defaults->get("FRAMES_PER_FOOT", (float)16);
265         interpolation_type = defaults->get("INTERPOLATION_TYPE", interpolation_type);
266         interpolate_raw = defaults->get("INTERPOLATE_RAW", interpolate_raw);
267         white_balance_raw = defaults->get("WHITE_BALANCE_RAW", white_balance_raw);
268         labels_follow_edits = defaults->get("LABELS_FOLLOW_EDITS", 1);
269         plugins_follow_edits = defaults->get("PLUGINS_FOLLOW_EDITS", 1);
270         single_standalone = defaults->get("SINGLE_STANDALONE", 1);
271         playback_preload = defaults->get("PLAYBACK_PRELOAD", 0);
272         auto_keyframes = defaults->get("AUTO_KEYFRAMES", 0);
273         meter_format = defaults->get("METER_FORMAT", METER_DB);
274         min_meter_db = defaults->get("MIN_METER_DB", -85);
275         max_meter_db = defaults->get("MAX_METER_DB", 6);
276         mpeg4_deblock = defaults->get("MPEG4_DEBLOCK", mpeg4_deblock);
277         output_w = defaults->get("OUTPUTW", output_w);
278         output_h = defaults->get("OUTPUTH", output_h);
279         playback_buffer = defaults->get("PLAYBACK_BUFFER", 4096);
280         playback_software_position = defaults->get("PLAYBACK_SOFTWARE_POSITION", 0);
281         delete playback_config;
282         playback_config = new PlaybackConfig;
283         playback_config->load_defaults(defaults);
284         real_time_playback = defaults->get("PLAYBACK_REALTIME", 0);
285         real_time_record = defaults->get("REALTIME_RECORD", 0);
286         record_positioning = defaults->get("RECORD_POSITIONING", 1);
287         record_raw_stream = defaults->get("RECORD_RAW_STREAM", 0);
288         record_sync_drives = defaults->get("RECORD_SYNC_DRIVES", 0);
289 //      record_speed = defaults->get("RECORD_SPEED", 24);
290         record_fragment_size = defaults->get("RECORD_FRAGMENT_SIZE", 2048);
291         record_write_length = defaults->get("RECORD_WRITE_LENGTH", 131072);
292
293 // set some defaults that work
294         recording_format->video_data = 1;
295         recording_format->audio_data = 1;
296         recording_format->format = FILE_FFMPEG;
297         strcpy(recording_format->acodec, "mp4.qt");
298         strcpy(recording_format->vcodec, "mp4.qt");
299         recording_format->channels = 2;
300         recording_format->sample_rate = 48000;
301         recording_format->bits = 16;
302         recording_format->dither = 0;
303
304         record_realtime_toc = defaults->get("RECORD_REALTIME_TOC", 1);
305         recording_format->load_defaults(defaults, "RECORD_", 1, 1, 1, 1, 1);
306
307         safe_regions = defaults->get("SAFE_REGIONS", 0);
308         sample_rate = defaults->get("SAMPLERATE", sample_rate);
309         scrub_speed = defaults->get("SCRUB_SPEED", (float)2);
310         si_useduration = defaults->get("SI_USEDURATION",1);
311         si_duration = defaults->get("SI_DURATION",3);
312
313         show_assets = defaults->get("SHOW_ASSETS", 1);
314         show_titles = defaults->get("SHOW_TITLES", 1);
315 //      test_playback_edits = defaults->get("TEST_PLAYBACK_EDITS", 1);
316         time_format = defaults->get("TIME_FORMAT", TIME_HMSF);
317         nudge_format = defaults->get("NUDGE_FORMAT", 1);
318         tool_window = defaults->get("TOOL_WINDOW", 0);
319         vconfig_in->load_defaults(defaults);
320         for(int i = 0; i < MAXCHANNELS; i++) {
321                 int default_position = i * output_w;
322                 sprintf(string, "VCHANNEL_X_%d", i);
323                 vchannel_x[i] = defaults->get(string, default_position);
324                 sprintf(string, "VCHANNEL_Y_%d", i);
325                 vchannel_y[i] = defaults->get(string, 0);
326         }
327         video_channels = defaults->get("VCHANNELS", video_channels);
328         video_every_frame = defaults->get("VIDEO_EVERY_FRAME", 0);
329         video_asynchronous = defaults->get("VIDEO_ASYNCHRONOUS", 0);
330         video_tracks = defaults->get("VTRACKS", video_tracks);
331         video_write_length = defaults->get("VIDEO_WRITE_LENGTH", 30);
332         view_follows_playback = defaults->get("VIEW_FOLLOWS_PLAYBACK", 1);
333         vwindow_meter = defaults->get("VWINDOW_METER", 0);
334         vwindow_zoom = defaults->get("VWINDOW_ZOOM", (float)1);
335
336         decode_subtitles = defaults->get("DECODE_SUBTITLES", decode_subtitles);
337         subtitle_number = defaults->get("SUBTITLE_NUMBER", subtitle_number);
338         label_cells = defaults->get("LABEL_CELLS", label_cells);
339         program_no = defaults->get("PROGRAM_NO", program_no);
340
341         boundaries();
342
343         return 0;
344 }
345
346 int EDLSession::save_defaults(BC_Hash *defaults)
347 {
348         char string[BCTEXTLEN];
349
350 // Session
351         for(int i = 0; i < MAXCHANNELS; i++)
352         {
353                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
354                 defaults->update(string, achannel_positions[i]);
355         }
356         defaults->update("ACHANNELS", audio_channels);
357         aconfig_in->save_defaults(defaults);
358         for(int i = 0; i < ASSET_COLUMNS; i++)
359         {
360                 sprintf(string, "ASSET_COLUMN%d", i);
361                 defaults->update(string, asset_columns[i]);
362         }
363         auto_conf->save_defaults(defaults);
364         defaults->update("ASSETLIST_FORMAT", assetlist_format);
365         defaults->update("ASPECTW", aspect_w);
366         defaults->update("ASPECTH", aspect_h);
367         defaults->update("ATRACKS", audio_tracks);
368         defaults->update("AUTOS_FOLLOW_EDITS", autos_follow_edits);
369         defaults->update("BRENDER_START", brender_start);
370         defaults->update("BRENDER_END", brender_end);
371         BC_CModels::to_text(string, color_model);
372         defaults->update("COLOR_MODEL", string);
373         ilacemode_to_xmltext(string, interlace_mode);
374         defaults->update("INTERLACE_MODE", string);
375         defaults->update("EYEDROP_RADIUS", eyedrop_radius);
376         defaults->update("CROP_X1", crop_x1);
377         defaults->update("CROP_X2", crop_x2);
378         defaults->update("CROP_Y1", crop_y1);
379         defaults->update("CROP_Y2", crop_y2);
380         defaults->update("RULER_X1", ruler_x1);
381         defaults->update("RULER_X2", ruler_x2);
382         defaults->update("RULER_Y1", ruler_y1);
383         defaults->update("RULER_Y2", ruler_y2);
384         defaults->update("AWINDOW_FOLDER", awindow_folder);
385         defaults->update("CURSOR_ON_FRAMES", cursor_on_frames);
386         defaults->update("TYPELESS_KEYFRAMES", typeless_keyframes);
387         defaults->update("CWINDOW_DEST", cwindow_dest);
388         defaults->update("CWINDOW_MASK", cwindow_mask);
389         defaults->update("CWINDOW_METER", cwindow_meter);
390         defaults->update("CWINDOW_OPERATION", cwindow_operation);
391         defaults->update("CWINDOW_SCROLLBARS", cwindow_scrollbars);
392         defaults->update("CWINDOW_XSCROLL", cwindow_xscroll);
393         defaults->update("CWINDOW_YSCROLL", cwindow_yscroll);
394         defaults->update("CWINDOW_ZOOM", cwindow_zoom);
395         defaults->update("DEFAULT_ATRANSITION", default_atransition);
396         defaults->update("DEFAULT_VTRANSITION", default_vtransition);
397         defaults->update("DEFAULT_TRANSITION_LENGTH", default_transition_length);
398         defaults->update("EDIT_HANDLE_MODE0", edit_handle_mode[0]);
399         defaults->update("EDIT_HANDLE_MODE1", edit_handle_mode[1]);
400         defaults->update("EDIT_HANDLE_MODE2", edit_handle_mode[2]);
401         defaults->update("EDITING_MODE", editing_mode);
402         defaults->update("ENABLE_DUPLEX", enable_duplex);
403         defaults->update("FOLDERLIST_FORMAT", folderlist_format);
404         defaults->update("FRAMERATE", frame_rate);
405         defaults->update("FRAMES_PER_FOOT", frames_per_foot);
406         defaults->update("HIGHLIGHTED_TRACK", highlighted_track);
407         defaults->update("INTERPOLATION_TYPE", interpolation_type);
408         defaults->update("INTERPOLATE_RAW", interpolate_raw);
409         defaults->update("WHITE_BALANCE_RAW", white_balance_raw);
410         defaults->update("LABELS_FOLLOW_EDITS", labels_follow_edits);
411         defaults->update("PLUGINS_FOLLOW_EDITS", plugins_follow_edits);
412         defaults->update("SINGLE_STANDALONE", single_standalone);
413         defaults->update("PLAYBACK_PRELOAD", playback_preload);
414         defaults->update("AUTO_KEYFRAMES", auto_keyframes);
415         defaults->update("METER_FORMAT", meter_format);
416         defaults->update("MIN_METER_DB", min_meter_db);
417         defaults->update("MAX_METER_DB", max_meter_db);
418         defaults->update("MPEG4_DEBLOCK", mpeg4_deblock);
419         defaults->update("OUTPUTW", output_w);
420         defaults->update("OUTPUTH", output_h);
421         defaults->update("PLAYBACK_BUFFER", playback_buffer);
422         defaults->update("PLAYBACK_SOFTWARE_POSITION", playback_software_position);
423         playback_config->save_defaults(defaults);
424         defaults->update("PLAYBACK_REALTIME", real_time_playback);
425         defaults->update("REALTIME_RECORD", real_time_record);
426         defaults->update("RECORD_POSITIONING", record_positioning);
427         defaults->update("RECORD_RAW_STREAM", record_raw_stream);
428         defaults->update("RECORD_SYNC_DRIVES", record_sync_drives);
429 //      defaults->update("RECORD_SPEED", record_speed);
430         defaults->update("RECORD_FRAGMENT_SIZE", record_fragment_size);
431         defaults->update("RECORD_WRITE_LENGTH", record_write_length); // Heroine kernel 2.2 scheduling sucks.
432         defaults->update("RECORD_REALTIME_TOC", record_realtime_toc);
433         recording_format->save_defaults(defaults,
434                 "RECORD_",
435                 1,
436                 1,
437                 1,
438                 1,
439                 1);
440         defaults->update("SAFE_REGIONS", safe_regions);
441         defaults->update("SAMPLERATE", sample_rate);
442         defaults->update("SCRUB_SPEED", scrub_speed);
443         defaults->update("SI_USEDURATION",si_useduration);
444         defaults->update("SI_DURATION",si_duration);
445         defaults->update("SHOW_ASSETS", show_assets);
446         defaults->update("SHOW_TITLES", show_titles);
447 //      defaults->update("TEST_PLAYBACK_EDITS", test_playback_edits);
448         defaults->update("TIME_FORMAT", time_format);
449         defaults->update("NUDGE_FORMAT", nudge_format);
450         defaults->update("TOOL_WINDOW", tool_window);
451         vconfig_in->save_defaults(defaults);
452         for(int i = 0; i < MAXCHANNELS; i++) {
453                 sprintf(string, "VCHANNEL_X_%d", i);
454                 defaults->update(string, vchannel_x[i]);
455                 sprintf(string, "VCHANNEL_Y_%d", i);
456                 defaults->update(string, vchannel_y[i]);
457         }
458         defaults->update("VCHANNELS", video_channels);
459         defaults->update("VIDEO_EVERY_FRAME", video_every_frame);
460         defaults->update("VIDEO_ASYNCHRONOUS", video_asynchronous);
461         defaults->update("VTRACKS", video_tracks);
462         defaults->update("VIDEO_WRITE_LENGTH", video_write_length);
463         defaults->update("VIEW_FOLLOWS_PLAYBACK", view_follows_playback);
464         defaults->update("VWINDOW_METER", vwindow_meter);
465         defaults->update("VWINDOW_ZOOM", vwindow_zoom);
466
467         defaults->update("DECODE_SUBTITLES", decode_subtitles);
468         defaults->update("SUBTITLE_NUMBER", subtitle_number);
469         defaults->update("LABEL_CELLS", label_cells);
470         defaults->update("PROGRAM_NO", program_no);
471
472         return 0;
473 }
474
475
476
477 // GCC 3.0 fails to compile
478 #define BC_INFINITY 65536
479
480
481 void EDLSession::boundaries()
482 {
483         Workarounds::clamp(audio_tracks, 0, (int)BC_INFINITY);
484         Workarounds::clamp(audio_channels, 1, MAXCHANNELS - 1);
485         Workarounds::clamp(sample_rate, 1, 1000000);
486         Workarounds::clamp(video_tracks, 0, (int)BC_INFINITY);
487         Workarounds::clamp(video_channels, 1, MAXCHANNELS - 1);
488         Workarounds::clamp(frame_rate, 1.0, (double)BC_INFINITY);
489         Workarounds::clamp(min_meter_db, -80, -20);
490         Workarounds::clamp(max_meter_db, 0, 10);
491         Workarounds::clamp(frames_per_foot, 1, 32);
492         Workarounds::clamp(output_w, 16, (int)BC_INFINITY);
493         Workarounds::clamp(output_h, 16, (int)BC_INFINITY);
494         Workarounds::clamp(video_write_length, 1, 1000);
495 //printf("EDLSession::boundaries 1\n");
496         output_w /= 2;
497         output_w *= 2;
498         output_h /= 2;
499         output_h *= 2;
500
501         Workarounds::clamp(eyedrop_radius, 0, 255);
502         Workarounds::clamp(crop_x1, 0, output_w);
503         Workarounds::clamp(crop_x2, 0, output_w);
504         Workarounds::clamp(crop_y1, 0, output_h);
505         Workarounds::clamp(crop_y2, 0, output_h);
506         Workarounds::clamp(ruler_x1, 0.0, output_w);
507         Workarounds::clamp(ruler_x2, 0.0, output_w);
508         Workarounds::clamp(ruler_y1, 0.0, output_h);
509         Workarounds::clamp(ruler_y2, 0.0, output_h);
510         if(brender_start < 0) brender_start = 0.0;
511         if(brender_end < 0) brender_end = 0.0;
512
513         Workarounds::clamp(subtitle_number, 0, 31);
514         Workarounds::clamp(awindow_folder, 0, AWINDOW_FOLDERS - 1);
515
516 // Correct framerates
517         frame_rate = Units::fix_framerate(frame_rate);
518 }
519
520
521
522 int EDLSession::load_video_config(FileXML *file, int append_mode, uint32_t load_flags)
523 {
524         char string[BCTEXTLEN];
525         if(append_mode) return 0;
526         interpolation_type = file->tag.get_property("INTERPOLATION_TYPE", interpolation_type);
527         interpolate_raw = file->tag.get_property("INTERPOLATE_RAW", interpolate_raw);
528         white_balance_raw = file->tag.get_property("WHITE_BALANCE_RAW", white_balance_raw);
529         BC_CModels::to_text(string, color_model);
530         color_model = BC_CModels::from_text(file->tag.get_property("COLORMODEL", string));
531         const char *ilace_mode = file->tag.get_property("INTERLACE_MODE");
532         interlace_mode = ilacemode_from_xmltext(ilace_mode, ILACE_MODE_NOTINTERLACED);
533         video_channels = file->tag.get_property("CHANNELS", video_channels);
534         for(int i = 0; i < video_channels; i++)
535         {
536                 int default_position = i * output_w;
537                 sprintf(string, "VCHANNEL_X_%d", i);
538                 vchannel_x[i] = file->tag.get_property(string, default_position);
539                 sprintf(string, "VCHANNEL_Y_%d", i);
540                 vchannel_y[i] = file->tag.get_property(string, 0);
541         }
542
543         frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
544         frames_per_foot = file->tag.get_property("FRAMES_PER_FOOT", frames_per_foot);
545         output_w = file->tag.get_property("OUTPUTW", output_w);
546         output_h = file->tag.get_property("OUTPUTH", output_h);
547         aspect_w = file->tag.get_property("ASPECTW", aspect_w);
548         aspect_h = file->tag.get_property("ASPECTH", aspect_h);
549         return 0;
550 }
551
552 int EDLSession::load_audio_config(FileXML *file, int append_mode, uint32_t load_flags)
553 {
554         char string[32];
555 // load channels setting
556         if(append_mode) return 0;
557         audio_channels = file->tag.get_property("CHANNELS", (int64_t)audio_channels);
558
559
560         for(int i = 0; i < audio_channels; i++)
561         {
562                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
563                 achannel_positions[i] = file->tag.get_property(string, achannel_positions[i]);
564 //printf("EDLSession::load_audio_config 1 %d %d\n", i, achannel_positions[i]);
565         }
566
567         sample_rate = file->tag.get_property("SAMPLERATE", (int64_t)sample_rate);
568         return 0;
569 }
570
571 int EDLSession::load_xml(FileXML *file,
572         int append_mode,
573         uint32_t load_flags)
574 {
575         char string[BCTEXTLEN];
576
577         if(append_mode)
578         {
579         }
580         else
581         {
582                 assetlist_format = file->tag.get_property("ASSETLIST_FORMAT", assetlist_format);
583                 for(int i = 0; i < ASSET_COLUMNS; i++) {
584                         sprintf(string, "ASSET_COLUMN%d", i);
585                         asset_columns[i] = file->tag.get_property(string, asset_columns[i]);
586                 }
587                 auto_conf->load_xml(file);
588                 auto_keyframes = file->tag.get_property("AUTO_KEYFRAMES", auto_keyframes);
589                 autos_follow_edits = file->tag.get_property("AUTOS_FOLLOW_EDITS", autos_follow_edits);
590                 brender_start = file->tag.get_property("BRENDER_START", brender_start);
591                 brender_end = file->tag.get_property("BRENDER_END", brender_end);
592                 eyedrop_radius = file->tag.get_property("EYEDROP_RADIUS", eyedrop_radius);
593                 crop_x1 = file->tag.get_property("CROP_X1", crop_x1);
594                 crop_y1 = file->tag.get_property("CROP_Y1", crop_y1);
595                 crop_x2 = file->tag.get_property("CROP_X2", crop_x2);
596                 crop_y2 = file->tag.get_property("CROP_Y2", crop_y2);
597                 ruler_x1 = file->tag.get_property("RULER_X1", ruler_x1);
598                 ruler_y1 = file->tag.get_property("RULER_Y1", ruler_y1);
599                 ruler_x2 = file->tag.get_property("RULER_X2", ruler_x2);
600                 ruler_y2 = file->tag.get_property("RULER_Y2", ruler_y2);
601                 string[0] = 0;
602                 file->tag.get_property("CURRENT_FOLDER", string);
603                 if( string[0] ) {
604                         awindow_folder = AWindowGUI::folder_number(string);
605                         if( awindow_folder < 0 ) awindow_folder = AW_MEDIA_FOLDER;
606                 }
607                 file->tag.get_property("AWINDOW_FOLDER", awindow_folder);
608                 cursor_on_frames = file->tag.get_property("CURSOR_ON_FRAMES", cursor_on_frames);
609                 typeless_keyframes = file->tag.get_property("TYPELESS_KEYFRAMES", typeless_keyframes);
610                 cwindow_dest = file->tag.get_property("CWINDOW_DEST", cwindow_dest);
611                 cwindow_mask = file->tag.get_property("CWINDOW_MASK", cwindow_mask);
612                 cwindow_meter = file->tag.get_property("CWINDOW_METER", cwindow_meter);
613                 cwindow_operation = file->tag.get_property("CWINDOW_OPERATION", cwindow_operation);
614                 cwindow_scrollbars = file->tag.get_property("CWINDOW_SCROLLBARS", cwindow_scrollbars);
615                 cwindow_xscroll = file->tag.get_property("CWINDOW_XSCROLL", cwindow_xscroll);
616                 cwindow_yscroll = file->tag.get_property("CWINDOW_YSCROLL", cwindow_yscroll);
617                 cwindow_zoom = file->tag.get_property("CWINDOW_ZOOM", cwindow_zoom);
618                 editing_mode = file->tag.get_property("EDITING_MODE", editing_mode);
619                 folderlist_format = file->tag.get_property("FOLDERLIST_FORMAT", folderlist_format);
620                 highlighted_track = file->tag.get_property("HIGHLIGHTED_TRACK", 0);
621                 labels_follow_edits = file->tag.get_property("LABELS_FOLLOW_EDITS", labels_follow_edits);
622                 mpeg4_deblock = file->tag.get_property("MPEG4_DEBLOCK", mpeg4_deblock);
623                 plugins_follow_edits = file->tag.get_property("PLUGINS_FOLLOW_EDITS", plugins_follow_edits);
624                 single_standalone = file->tag.get_property("SINGLE_STANDALONE", single_standalone);
625                 playback_preload = file->tag.get_property("PLAYBACK_PRELOAD", playback_preload);
626                 safe_regions = file->tag.get_property("SAFE_REGIONS", safe_regions);
627                 show_assets = file->tag.get_property("SHOW_ASSETS", 1);
628                 show_titles = file->tag.get_property("SHOW_TITLES", 1);
629 //              test_playback_edits = file->tag.get_property("TEST_PLAYBACK_EDITS", test_playback_edits);
630                 time_format = file->tag.get_property("TIME_FORMAT", time_format);
631                 nudge_format = file->tag.get_property("NUDGE_FORMAT", nudge_format);
632                 tool_window = file->tag.get_property("TOOL_WINDOW", tool_window);
633                 vwindow_meter = file->tag.get_property("VWINDOW_METER", vwindow_meter);
634                 vwindow_zoom = file->tag.get_property("VWINDOW_ZOOM", vwindow_zoom);
635
636                 decode_subtitles = file->tag.get_property("DECODE_SUBTITLES", decode_subtitles);
637                 subtitle_number = file->tag.get_property("SUBTITLE_NUMBER", subtitle_number);
638                 label_cells = file->tag.get_property("LABEL_CELLS", label_cells);
639                 program_no = file->tag.get_property("PROGRAM_NO", program_no);
640
641                 boundaries();
642         }
643
644         return 0;
645 }
646
647 int EDLSession::save_xml(FileXML *file)
648 {
649 //printf("EDLSession::save_session 1\n");
650         char string[BCTEXTLEN];
651         file->tag.set_title("SESSION");
652         file->tag.set_property("ASSETLIST_FORMAT", assetlist_format);
653         for(int i = 0; i < ASSET_COLUMNS; i++) {
654                 sprintf(string, "ASSET_COLUMN%d", i);
655                 file->tag.set_property(string, asset_columns[i]);
656         }
657         auto_conf->save_xml(file);
658         file->tag.set_property("AUTO_KEYFRAMES", auto_keyframes);
659         file->tag.set_property("AUTOS_FOLLOW_EDITS", autos_follow_edits);
660         file->tag.set_property("BRENDER_START", brender_start);
661         file->tag.set_property("BRENDER_END", brender_end);
662         file->tag.set_property("EYEDROP_RADIUS", eyedrop_radius);
663         file->tag.set_property("CROP_X1", crop_x1);
664         file->tag.set_property("CROP_Y1", crop_y1);
665         file->tag.set_property("CROP_X2", crop_x2);
666         file->tag.set_property("CROP_Y2", crop_y2);
667         file->tag.set_property("RULER_X1", ruler_x1);
668         file->tag.set_property("RULER_Y1", ruler_y1);
669         file->tag.set_property("RULER_X2", ruler_x2);
670         file->tag.set_property("RULER_Y2", ruler_y2);
671         file->tag.set_property("AWINDOW_FOLDER", awindow_folder);
672         file->tag.set_property("CURSOR_ON_FRAMES", cursor_on_frames);
673         file->tag.set_property("TYPELESS_KEYFRAMES", typeless_keyframes);
674         file->tag.set_property("CWINDOW_DEST", cwindow_dest);
675         file->tag.set_property("CWINDOW_MASK", cwindow_mask);
676         file->tag.set_property("CWINDOW_METER", cwindow_meter);
677         file->tag.set_property("CWINDOW_OPERATION", cwindow_operation);
678         file->tag.set_property("CWINDOW_SCROLLBARS", cwindow_scrollbars);
679         file->tag.set_property("CWINDOW_XSCROLL", cwindow_xscroll);
680         file->tag.set_property("CWINDOW_YSCROLL", cwindow_yscroll);
681         file->tag.set_property("CWINDOW_ZOOM", cwindow_zoom);
682         file->tag.set_property("EDITING_MODE", editing_mode);
683         file->tag.set_property("FOLDERLIST_FORMAT", folderlist_format);
684         file->tag.set_property("HIGHLIGHTED_TRACK", highlighted_track);
685         file->tag.set_property("LABELS_FOLLOW_EDITS", labels_follow_edits);
686         file->tag.set_property("MPEG4_DEBLOCK", mpeg4_deblock);
687         file->tag.set_property("PLUGINS_FOLLOW_EDITS", plugins_follow_edits);
688         file->tag.set_property("SINGLE_STANDALONE", single_standalone);
689         file->tag.set_property("PLAYBACK_PRELOAD", playback_preload);
690         file->tag.set_property("SAFE_REGIONS", safe_regions);
691         file->tag.set_property("SHOW_ASSETS", show_assets);
692         file->tag.set_property("SHOW_TITLES", show_titles);
693         file->tag.set_property("TEST_PLAYBACK_EDITS", test_playback_edits);
694         file->tag.set_property("TIME_FORMAT", time_format);
695         file->tag.set_property("NUDGE_FORMAT", nudge_format);
696         file->tag.set_property("TOOL_WINDOW", tool_window);
697         file->tag.set_property("VWINDOW_METER", vwindow_meter);
698         file->tag.set_property("VWINDOW_ZOOM", vwindow_zoom);
699
700         file->tag.set_property("DECODE_SUBTITLES", decode_subtitles);
701         file->tag.set_property("SUBTITLE_NUMBER", subtitle_number);
702
703         file->append_tag();
704         file->tag.set_title("/SESSION");
705         file->append_tag();
706         file->append_newline();
707         file->append_newline();
708 //printf("EDLSession::save_session 3\n");
709         return 0;
710 }
711
712 int EDLSession::save_video_config(FileXML *file)
713 {
714         char string[BCTEXTLEN];
715         file->tag.set_title("VIDEO");
716         file->tag.set_property("INTERPOLATION_TYPE", interpolation_type);
717         file->tag.set_property("INTERPOLATE_RAW", interpolate_raw);
718         file->tag.set_property("WHITE_BALANCE_RAW", white_balance_raw);
719         BC_CModels::to_text(string, color_model);
720         file->tag.set_property("COLORMODEL", string);
721         ilacemode_to_xmltext(string, interlace_mode);
722         file->tag.set_property("INTERLACE_MODE",string);
723     file->tag.set_property("CHANNELS", video_channels);
724         for(int i = 0; i < video_channels; i++)
725         {
726                 sprintf(string, "VCHANNEL_X_%d", i);
727                 file->tag.set_property(string, vchannel_x[i]);
728                 sprintf(string, "VCHANNEL_Y_%d", i);
729                 file->tag.set_property(string, vchannel_y[i]);
730         }
731
732         file->tag.set_property("FRAMERATE", frame_rate);
733         file->tag.set_property("FRAMES_PER_FOOT", frames_per_foot);
734         file->tag.set_property("OUTPUTW", output_w);
735         file->tag.set_property("OUTPUTH", output_h);
736         file->tag.set_property("ASPECTW", aspect_w);
737         file->tag.set_property("ASPECTH", aspect_h);
738         file->append_tag();
739         file->tag.set_title("/VIDEO");
740         file->append_tag();
741         file->append_newline();
742         file->append_newline();
743         return 0;
744 }
745
746 int EDLSession::save_audio_config(FileXML *file)
747 {
748         char string[1024];
749         file->tag.set_title("AUDIO");
750         file->tag.set_property("SAMPLERATE", (int64_t)sample_rate);
751         file->tag.set_property("CHANNELS", (int64_t)audio_channels);
752
753         for(int i = 0; i < audio_channels; i++)
754         {
755                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
756                 file->tag.set_property(string, achannel_positions[i]);
757         }
758
759         file->append_tag();
760         file->tag.set_title("/AUDIO");
761         file->append_tag();
762         file->append_newline();
763         file->append_newline();
764         return 0;
765 }
766
767 int EDLSession::copy(EDLSession *session)
768 {
769 // Audio channel positions
770         for(int i = 0; i < MAXCHANNELS; i++)
771         {
772                 achannel_positions[i] = session->achannel_positions[i];
773         }
774         aconfig_in->copy_from(session->aconfig_in);
775         for(int i = 0; i < ASSET_COLUMNS; i++)
776         {
777                 asset_columns[i] = session->asset_columns[i];
778         }
779         assetlist_format = session->assetlist_format;
780         auto_conf->copy_from(session->auto_conf);
781         aspect_w = session->aspect_w;
782         aspect_h = session->aspect_h;
783         audio_channels = session->audio_channels;
784         audio_tracks = session->audio_tracks;
785         autos_follow_edits = session->autos_follow_edits;
786         brender_start = session->brender_start;
787         brender_end = session->brender_end;
788         color_model = session->color_model;
789         interlace_mode = session->interlace_mode;
790         eyedrop_radius = session->eyedrop_radius;
791         crop_x1 = session->crop_x1;
792         crop_y1 = session->crop_y1;
793         crop_x2 = session->crop_x2;
794         crop_y2 = session->crop_y2;
795         ruler_x1 = session->ruler_x1;
796         ruler_y1 = session->ruler_y1;
797         ruler_x2 = session->ruler_x2;
798         ruler_y2 = session->ruler_y2;
799         awindow_folder = session->awindow_folder;
800         cursor_on_frames = session->cursor_on_frames;
801         typeless_keyframes = session->typeless_keyframes;
802         cwindow_dest = session->cwindow_dest;
803         cwindow_mask = session->cwindow_mask;
804         cwindow_meter = session->cwindow_meter;
805         cwindow_operation = session->cwindow_operation;
806         cwindow_scrollbars = session->cwindow_scrollbars;
807         cwindow_xscroll = session->cwindow_xscroll;
808         cwindow_yscroll = session->cwindow_yscroll;
809         cwindow_zoom = session->cwindow_zoom;
810         strcpy(default_atransition, session->default_atransition);
811         strcpy(default_vtransition, session->default_vtransition);
812         default_transition_length = session->default_transition_length;
813         edit_handle_mode[0] = session->edit_handle_mode[0];
814         edit_handle_mode[1] = session->edit_handle_mode[1];
815         edit_handle_mode[2] = session->edit_handle_mode[2];
816         editing_mode = session->editing_mode;
817         enable_duplex = session->enable_duplex;
818         folderlist_format = session->folderlist_format;
819         frame_rate = session->frame_rate;
820         frames_per_foot = session->frames_per_foot;
821         highlighted_track = session->highlighted_track;
822         interpolation_type = session->interpolation_type;
823         interpolate_raw = session->interpolate_raw;
824         white_balance_raw = session->white_balance_raw;
825         labels_follow_edits = session->labels_follow_edits;
826         plugins_follow_edits = session->plugins_follow_edits;
827         single_standalone = session->single_standalone;
828         auto_keyframes = session->auto_keyframes;
829 //      last_playback_position = session->last_playback_position;
830         meter_format = session->meter_format;
831         min_meter_db = session->min_meter_db;
832         max_meter_db = session->max_meter_db;
833         mpeg4_deblock = session->mpeg4_deblock;
834         output_w = session->output_w;
835         output_h = session->output_h;
836         playback_buffer = session->playback_buffer;
837         delete playback_config;
838         playback_config = new PlaybackConfig;
839         playback_config->copy_from(session->playback_config);
840         playback_cursor_visible = session->playback_cursor_visible;
841         playback_software_position = session->playback_software_position;
842         real_time_playback = session->real_time_playback;
843         real_time_record = session->real_time_record;
844         record_positioning = session->record_positioning;
845         record_raw_stream = session->record_raw_stream;
846         record_speed = session->record_speed;
847         record_sync_drives = session->record_sync_drives;
848         record_fragment_size = session->record_fragment_size;
849         record_write_length = session->record_write_length;
850         record_realtime_toc = session->record_realtime_toc;
851         recording_format->copy_from(session->recording_format, 0);
852         safe_regions = session->safe_regions;
853         sample_rate = session->sample_rate;
854         scrub_speed = session->scrub_speed;
855         si_useduration = session->si_useduration;
856         si_duration = session->si_duration;
857         show_assets = session->show_assets;
858         show_titles = session->show_titles;
859         test_playback_edits = session->test_playback_edits;
860         time_format = session->time_format;
861         nudge_format = session->nudge_format;
862         tool_window = session->tool_window;
863         for(int i = 0; i < MAXCHANNELS; i++) {
864                 vchannel_x[i] = session->vchannel_x[i];
865                 vchannel_y[i] = session->vchannel_y[i];
866         }
867         video_channels = session->video_channels;
868         *vconfig_in = *session->vconfig_in;
869         video_every_frame = session->video_every_frame;
870         video_asynchronous = session->video_asynchronous;
871         video_tracks = session->video_tracks;
872         video_write_length = session->video_write_length;
873         view_follows_playback = session->view_follows_playback;
874         vwindow_meter = session->vwindow_meter;
875         vwindow_zoom = session->vwindow_zoom;
876
877         subtitle_number = session->subtitle_number;
878         decode_subtitles = session->decode_subtitles;
879         label_cells = session->label_cells;
880         program_no = session->program_no;
881
882         return 0;
883 }
884
885 void EDLSession::dump()
886 {
887         printf("EDLSession::dump\n");
888         printf("    audio_tracks=%d audio_channels=%d sample_rate=%jd\n"
889                 "    video_tracks=%d frame_rate=%f output_w=%d output_h=%d aspect_w=%f aspect_h=%f\n"
890                 "    decode subtitles=%d subtitle_number=%d label_cells=%d program_no=%d\n",
891                 audio_tracks, audio_channels, sample_rate, video_tracks,
892                 frame_rate, output_w, output_h, aspect_w, aspect_h,
893                 decode_subtitles, subtitle_number, label_cells, program_no);
894 }
895