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