r1014: Enable horizontal scrolling with the mouse wheel by pressing Ctrl.
[cinelerra_cv/ct.git] / cinelerra / edlsession.C
blob34c3d6dc4147495f00a88e0c411dd6ec93313515
1 #include "asset.h"
2 #include "assets.h"
3 #include "autoconf.h"
4 #include "colormodels.h"
5 #include "bchash.h"
6 #include "edl.h"
7 #include "edlsession.h"
8 #include "filexml.h"
9 #include "interlacemodes.h"
10 #include "overlayframe.inc"
11 #include "playbackconfig.h"
12 #include "recordconfig.h"
13 #include "tracks.h"
14 #include "workarounds.h"
16 int EDLSession::current_id = 0;
18 EDLSession::EDLSession(EDL *edl)
20         highlighted_track = 0;
21         playback_cursor_visible = 0;
22         aconfig_in = new AudioInConfig;
23         aconfig_duplex = new AudioOutConfig(1);
24         vconfig_in = new VideoInConfig;
25         recording_format = new Asset;
26         interpolation_type = CUBIC_LINEAR;
27         interpolate_raw = 1;
28         white_balance_raw = 1;
29         test_playback_edits = 1;
30         brender_start = 0.0;
31         mpeg4_deblock = 1;
33         playback_config = new PlaybackConfig;
34         auto_conf = new AutoConf;
35         strcpy(vwindow_folder, "");
36         strcpy(current_folder, "");
37         strcpy(default_atransition, "");
38         strcpy(default_vtransition, "");
39         default_transition_length = 1.0;
40         folderlist_format = ASSETS_ICONS;
41         frame_rate = 25; // just has to be something by default
42         autos_follow_edits = 1; // this is needed for predictability
43         labels_follow_edits = 1;
44         plugins_follow_edits = 1;
45         audio_tracks = -10;     // these insane values let us crash early if something is forgotten to be set
46         audio_channels = -10;
47         video_tracks = -10;
48         video_channels = -10;
49         sample_rate = -10;
50         frame_rate = -10;
51         frames_per_foot = -10;
52         min_meter_db = -1000;
53         max_meter_db = -1000;
54         output_w = -1000;
55         output_h = -1000;
56         video_write_length = -1000;
57         color_model = -100;
58         interlace_mode = BC_ILACE_MODE_UNDETECTED;
59         record_speed = 24;
60         decode_subtitles = 0;
61         subtitle_number = 0;
64 EDLSession::~EDLSession()
66         delete aconfig_in;
67         delete aconfig_duplex;
68         delete auto_conf;
69         delete vconfig_in;
70         delete playback_config;
71         Garbage::delete_object(recording_format);
75 char* EDLSession::get_cwindow_display()
77         if(playback_config->vconfig->x11_host[0])
78                 return playback_config->vconfig->x11_host;
79         else
80                 return 0;
83 int EDLSession::need_rerender(EDLSession *ptr)
85         return (playback_preload != ptr->playback_preload) ||
86                 (interpolation_type != ptr->interpolation_type) ||
87                 (video_every_frame != ptr->video_every_frame) ||
88                 (video_asynchronous != ptr->video_asynchronous) ||
89                 (real_time_playback != ptr->real_time_playback) ||
90                 (playback_software_position != ptr->playback_software_position) ||
91                 (test_playback_edits != ptr->test_playback_edits) ||
92                 (playback_buffer != ptr->playback_buffer) ||
93                 (decode_subtitles != ptr->decode_subtitles) ||
94                 (subtitle_number != ptr->subtitle_number) ||
95                 (interpolate_raw != ptr->interpolate_raw) ||
96                 (white_balance_raw != ptr->white_balance_raw);
99 void EDLSession::equivalent_output(EDLSession *session, double *result)
101         if(session->output_w != output_w ||
102                 session->output_h != output_h ||
103                 session->frame_rate != frame_rate ||
104                 session->color_model != color_model ||
105                 session->interpolation_type != interpolation_type ||
106                 session->interpolate_raw != interpolate_raw ||
107                 session->white_balance_raw != white_balance_raw ||
108                 session->mpeg4_deblock != mpeg4_deblock ||
109                 session->decode_subtitles != decode_subtitles ||
110                 session->subtitle_number != subtitle_number)
111                 *result = 0;
113 // If it's before the current brender_start, render extra data.
114 // If it's after brender_start, check brender map.
115         if(brender_start != session->brender_start &&
116                 (*result < 0 || *result > brender_start))
117                 *result = brender_start;
121 int EDLSession::load_defaults(BC_Hash *defaults)
123         char string[BCTEXTLEN];
125 // Default channel positions
126         for(int i = 0; i < MAXCHANNELS; i++)
127         {
128                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
129                 int default_position = i * 30;
131                 if(i == 0) default_position = 180;
132                 else
133                 if(i == 1) default_position = 0;
134                 else
135                 if(default_position == 90) default_position = 300;
136                 else
137                 if(default_position == 0) default_position = 330;
139                 achannel_positions[i] = defaults->get(string, default_position);
140         }
141         aconfig_duplex->load_defaults(defaults);
142         aconfig_in->load_defaults(defaults);
143         actual_frame_rate = defaults->get("ACTUAL_FRAME_RATE", (float)-1);
144         assetlist_format = defaults->get("ASSETLIST_FORMAT", ASSETS_ICONS);
145         aspect_w = defaults->get("ASPECTW", (float)4);
146         aspect_h = defaults->get("ASPECTH", (float)3);
147         for(int i = 0; i < ASSET_COLUMNS; i++)
148         {
149                 sprintf(string, "ASSET_COLUMN%d", i);
150                 asset_columns[i] = defaults->get(string, 100);
151         }
152         audio_channels = defaults->get("ACHANNELS", 2);
153         audio_tracks = defaults->get("ATRACKS", 2);
154         auto_conf->load_defaults(defaults);
155         autos_follow_edits = defaults->get("AUTOS_FOLLOW_EDITS", 1);
156         brender_start = defaults->get("BRENDER_START", brender_start);
157         cmodel_to_text(string, BC_RGBA8888);
158         color_model = cmodel_from_text(defaults->get("COLOR_MODEL", string));
159         ilacemode_to_xmltext(string, BC_ILACE_MODE_NOTINTERLACED);
160         interlace_mode = ilacemode_from_xmltext(defaults->get("INTERLACE_MODE",string), BC_ILACE_MODE_NOTINTERLACED);
161         crop_x1 = defaults->get("CROP_X1", 0);
162         crop_x2 = defaults->get("CROP_X2", 320);
163         crop_y1 = defaults->get("CROP_Y1", 0);
164         crop_y2 = defaults->get("CROP_Y2", 240);
165         sprintf(current_folder, MEDIA_FOLDER);
166         defaults->get("CURRENT_FOLDER", current_folder);
167         cursor_on_frames = defaults->get("CURSOR_ON_FRAMES", 1);
168         cwindow_dest = defaults->get("CWINDOW_DEST", 0);
169         cwindow_mask = defaults->get("CWINDOW_MASK", 0);
170         cwindow_meter = defaults->get("CWINDOW_METER", 1);
171         cwindow_operation = defaults->get("CWINDOW_OPERATION", 0);
172         cwindow_scrollbars = defaults->get("CWINDOW_SCROLLBARS", 1);
173         cwindow_xscroll = defaults->get("CWINDOW_XSCROLL", 0);
174         cwindow_yscroll = defaults->get("CWINDOW_YSCROLL", 0);
175         cwindow_zoom = defaults->get("CWINDOW_ZOOM", (float)1);
176         sprintf(default_atransition, "Crossfade");
177         defaults->get("DEFAULT_ATRANSITION", default_atransition);
178         sprintf(default_vtransition, "Dissolve");
179         defaults->get("DEFAULT_VTRANSITION", default_vtransition);
180         default_transition_length = defaults->get("DEFAULT_TRANSITION_LENGTH", (double)1);
181         edit_handle_mode[0] = defaults->get("EDIT_HANDLE_MODE0", MOVE_ALL_EDITS);
182         edit_handle_mode[1] = defaults->get("EDIT_HANDLE_MODE1", MOVE_ONE_EDIT);
183         edit_handle_mode[2] = defaults->get("EDIT_HANDLE_MODE2", MOVE_NO_EDITS);
184         editing_mode = defaults->get("EDITING_MODE", EDITING_IBEAM);
185         enable_duplex = defaults->get("ENABLE_DUPLEX", 1);
186         folderlist_format = defaults->get("FOLDERLIST_FORMAT", FOLDERS_ICONS);
187         frame_rate = defaults->get("FRAMERATE", (double)30000.0/1001);
188         frames_per_foot = defaults->get("FRAMES_PER_FOOT", (float)16);
189         interpolation_type = defaults->get("INTERPOLATION_TYPE", interpolation_type);
190         interpolate_raw = defaults->get("INTERPOLATE_RAW", interpolate_raw);
191         white_balance_raw = defaults->get("WHITE_BALANCE_RAW", white_balance_raw);
192         labels_follow_edits = defaults->get("LABELS_FOLLOW_EDITS", 1);
193         plugins_follow_edits = defaults->get("PLUGINS_FOLLOW_EDITS", 1);
194         auto_keyframes = defaults->get("AUTO_KEYFRAMES", 0);
195         meter_format = defaults->get("METER_FORMAT", METER_DB);
196         min_meter_db = defaults->get("MIN_METER_DB", -85);
197         max_meter_db = defaults->get("MAX_METER_DB", 6);
198         mpeg4_deblock = defaults->get("MPEG4_DEBLOCK", mpeg4_deblock);
199         output_w = defaults->get("OUTPUTW", 720);
200         output_h = defaults->get("OUTPUTH", 480);
201         playback_buffer = defaults->get("PLAYBACK_BUFFER", 4096);
202         playback_preload = defaults->get("PLAYBACK_PRELOAD", 0);
203         playback_software_position = defaults->get("PLAYBACK_SOFTWARE_POSITION", 0);
204         delete playback_config;
205         playback_config = new PlaybackConfig;
206         playback_config->load_defaults(defaults);
207         real_time_playback = defaults->get("PLAYBACK_REALTIME", 0);
208         real_time_record = defaults->get("REALTIME_RECORD", 0);
209         record_software_position = defaults->get("RECORD_SOFTWARE_POSITION", 1);
210         record_sync_drives = defaults->get("RECORD_SYNC_DRIVES", 0);
211 //      record_speed = defaults->get("RECORD_SPEED", 24);
212         record_write_length = defaults->get("RECORD_WRITE_LENGTH", 131072);
213         recording_format->load_defaults(defaults,
214                 "RECORD_", 
215                 1,
216                 1,
217                 1,
218                 1,
219                 1);
220         safe_regions = defaults->get("SAFE_REGIONS", 1);
221         sample_rate = defaults->get("SAMPLERATE", 48000);
222         scrub_speed = defaults->get("SCRUB_SPEED", (float)2);
223         si_useduration = defaults->get("SI_USEDURATION",0);
224         si_duration = defaults->get("SI_DURATION",5);
225         
226         show_assets = defaults->get("SHOW_ASSETS", 1);
227         show_titles = defaults->get("SHOW_TITLES", 1);
228 //      test_playback_edits = defaults->get("TEST_PLAYBACK_EDITS", 1);
229         time_format = defaults->get("TIME_FORMAT", TIME_HMS);
230         for(int i = 0; i < 4; i++)
231         {
232                 sprintf(string, "TIMECODE_OFFSET_%d", i);
233            timecode_offset[i] = defaults->get(string, 0);
234         }
235         nudge_seconds = defaults->get("NUDGE_FORMAT", 1);
236         tool_window = defaults->get("TOOL_WINDOW", 0);
237         vconfig_in->load_defaults(defaults);
238         for(int i = 0; i < MAXCHANNELS; i++)
239         {
240                 int default_position = i * output_w;
241                 sprintf(string, "VCHANNEL_X_%d", i);
242                 vchannel_x[i] = defaults->get(string, default_position);
243                 sprintf(string, "VCHANNEL_Y_%d", i);
244                 vchannel_y[i] = defaults->get(string, 0);
245         }
246         video_channels = defaults->get("VCHANNELS", 1);
247         video_every_frame = defaults->get("VIDEO_EVERY_FRAME", 1);
248         video_asynchronous = defaults->get("VIDEO_ASYNCHRONOUS", 0);
249         video_tracks = defaults->get("VTRACKS", 1);
250         video_write_length = defaults->get("VIDEO_WRITE_LENGTH", 30);
251         view_follows_playback = defaults->get("VIEW_FOLLOWS_PLAYBACK", 1);
252         vwindow_meter = defaults->get("VWINDOW_METER", 1);
255         decode_subtitles = defaults->get("DECODE_SUBTITLES", decode_subtitles);
256         subtitle_number = defaults->get("SUBTITLE_NUMBER", subtitle_number);
258         vwindow_folder[0] = 0;
259         vwindow_source = -1;
260         vwindow_zoom = defaults->get("VWINDOW_ZOOM", (float)1);
261         boundaries();
263         return 0;
266 int EDLSession::save_defaults(BC_Hash *defaults)
268         char string[BCTEXTLEN];
270 // Session
271         for(int i = 0; i < MAXCHANNELS; i++)
272         {
273                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
274                 defaults->update(string, achannel_positions[i]);
275         }
276         defaults->update("ACHANNELS", audio_channels);
277         aconfig_duplex->save_defaults(defaults);
278         aconfig_in->save_defaults(defaults);
279         for(int i = 0; i < ASSET_COLUMNS; i++)
280         {
281                 sprintf(string, "ASSET_COLUMN%d", i);
282                 defaults->update(string, asset_columns[i]);
283         }
284         auto_conf->save_defaults(defaults);
285     defaults->update("ACTUAL_FRAME_RATE", actual_frame_rate);
286     defaults->update("ASSETLIST_FORMAT", assetlist_format);
287     defaults->update("ASPECTW", aspect_w);
288     defaults->update("ASPECTH", aspect_h);
289         defaults->update("ATRACKS", audio_tracks);
290         defaults->update("AUTOS_FOLLOW_EDITS", autos_follow_edits);
291         defaults->update("BRENDER_START", brender_start);
292         cmodel_to_text(string, color_model);
293         defaults->update("COLOR_MODEL", string);
294         ilacemode_to_xmltext(string, interlace_mode);
295         defaults->update("INTERLACE_MODE", string);
296         defaults->update("CROP_X1", crop_x1);
297         defaults->update("CROP_X2", crop_x2);
298         defaults->update("CROP_Y1", crop_y1);
299         defaults->update("CROP_Y2", crop_y2);
300         defaults->update("CURRENT_FOLDER", current_folder);
301         defaults->update("CURSOR_ON_FRAMES", cursor_on_frames);
302         defaults->update("CWINDOW_DEST", cwindow_dest);
303         defaults->update("CWINDOW_MASK", cwindow_mask);
304         defaults->update("CWINDOW_METER", cwindow_meter);
305         defaults->update("CWINDOW_OPERATION", cwindow_operation);
306         defaults->update("CWINDOW_SCROLLBARS", cwindow_scrollbars);
307         defaults->update("CWINDOW_XSCROLL", cwindow_xscroll);
308         defaults->update("CWINDOW_YSCROLL", cwindow_yscroll);
309         defaults->update("CWINDOW_ZOOM", cwindow_zoom);
310         defaults->update("DEFAULT_ATRANSITION", default_atransition);
311         defaults->update("DEFAULT_VTRANSITION", default_vtransition);
312         defaults->update("DEFAULT_TRANSITION_LENGTH", default_transition_length);
313     defaults->update("EDIT_HANDLE_MODE0", edit_handle_mode[0]);
314     defaults->update("EDIT_HANDLE_MODE1", edit_handle_mode[1]);
315     defaults->update("EDIT_HANDLE_MODE2", edit_handle_mode[2]);
316         defaults->update("EDITING_MODE", editing_mode);
317         defaults->update("ENABLE_DUPLEX", enable_duplex);
318     defaults->update("FOLDERLIST_FORMAT", folderlist_format);
319         defaults->update("FRAMERATE", frame_rate);
320         defaults->update("FRAMES_PER_FOOT", frames_per_foot);
321         defaults->update("HIGHLIGHTED_TRACK", highlighted_track);
322     defaults->update("INTERPOLATION_TYPE", interpolation_type);
323     defaults->update("INTERPOLATE_RAW", interpolate_raw);
324     defaults->update("WHITE_BALANCE_RAW", white_balance_raw);
325         defaults->update("LABELS_FOLLOW_EDITS", labels_follow_edits);
326         defaults->update("PLUGINS_FOLLOW_EDITS", plugins_follow_edits);
327         defaults->update("AUTO_KEYFRAMES", auto_keyframes);
328     defaults->update("METER_FORMAT", meter_format);
329     defaults->update("MIN_METER_DB", min_meter_db);
330     defaults->update("MAX_METER_DB", max_meter_db);
331         defaults->update("MPEG4_DEBLOCK", mpeg4_deblock);
332         defaults->update("OUTPUTW", output_w);
333         defaults->update("OUTPUTH", output_h);
334     defaults->update("PLAYBACK_BUFFER", playback_buffer);
335         defaults->update("PLAYBACK_PRELOAD", playback_preload);
336     defaults->update("PLAYBACK_SOFTWARE_POSITION", playback_software_position);
337         playback_config->save_defaults(defaults);
338     defaults->update("PLAYBACK_REALTIME", real_time_playback);
339         defaults->update("REALTIME_RECORD", real_time_record);
340     defaults->update("RECORD_SOFTWARE_POSITION", record_software_position);
341         defaults->update("RECORD_SYNC_DRIVES", record_sync_drives);
342 //      defaults->update("RECORD_SPEED", record_speed);  
343         defaults->update("RECORD_WRITE_LENGTH", record_write_length); // Heroine kernel 2.2 scheduling sucks.
344         recording_format->save_defaults(defaults,
345                 "RECORD_",
346                 1,
347                 1,
348                 1,
349                 1,
350                 1);
351         defaults->update("SAFE_REGIONS", safe_regions);
352         defaults->update("SAMPLERATE", sample_rate);
353     defaults->update("SCRUB_SPEED", scrub_speed);
354         defaults->update("SI_USEDURATION",si_useduration);
355         defaults->update("SI_DURATION",si_duration);
356         defaults->update("SHOW_ASSETS", show_assets);
357         defaults->update("SHOW_TITLES", show_titles);
358 //      defaults->update("TEST_PLAYBACK_EDITS", test_playback_edits);
359         defaults->update("TIME_FORMAT", time_format);
360         for(int i = 0; i < 4; i++)
361         {
362                 sprintf(string, "TIMECODE_OFFSET_%d", i);
363            defaults->update(string, timecode_offset[i]);
364         }
365         defaults->update("NUDGE_FORMAT", nudge_seconds);
366         defaults->update("TOOL_WINDOW", tool_window);
367     vconfig_in->save_defaults(defaults);
368         for(int i = 0; i < MAXCHANNELS; i++)
369         {
370                 sprintf(string, "VCHANNEL_X_%d", i);
371                 defaults->update(string, vchannel_x[i]);
372                 sprintf(string, "VCHANNEL_Y_%d", i);
373                 defaults->update(string, vchannel_y[i]);
374         }
375         defaults->update("VCHANNELS", video_channels);
376     defaults->update("VIDEO_EVERY_FRAME", video_every_frame);
377     defaults->update("VIDEO_ASYNCHRONOUS", video_asynchronous);
378         defaults->update("VTRACKS", video_tracks);
379         defaults->update("VIDEO_WRITE_LENGTH", video_write_length);
380     defaults->update("VIEW_FOLLOWS_PLAYBACK", view_follows_playback);
381         defaults->update("VWINDOW_METER", vwindow_meter);
382         defaults->update("VWINDOW_ZOOM", vwindow_zoom);
384         defaults->update("DECODE_SUBTITLES", decode_subtitles);
385         defaults->update("SUBTITLE_NUMBER", subtitle_number);
388         return 0;
393 // GCC 3.0 fails to compile
394 #define BC_INFINITY 65536
397 void EDLSession::boundaries()
399         Workarounds::clamp(audio_tracks, 0, (int)BC_INFINITY);
400         Workarounds::clamp(audio_channels, 1, MAXCHANNELS - 1);
401         Workarounds::clamp(sample_rate, 1, 1000000);
402         Workarounds::clamp(video_tracks, 0, (int)BC_INFINITY);
403         Workarounds::clamp(video_channels, 1, MAXCHANNELS - 1);
404         Workarounds::clamp(frame_rate, 1.0, (double)BC_INFINITY);
405         Workarounds::clamp(min_meter_db, -80, -20);
406         Workarounds::clamp(max_meter_db, 0, 10);
407         Workarounds::clamp(frames_per_foot, 1, 32);
408         Workarounds::clamp(output_w, 16, (int)BC_INFINITY);
409         Workarounds::clamp(output_h, 16, (int)BC_INFINITY);
410         Workarounds::clamp(video_write_length, 1, 1000);
411 //printf("EDLSession::boundaries 1\n");
412         output_w /= 2;
413         output_w *= 2;
414         output_h /= 2;
415         output_h *= 2;
417         Workarounds::clamp(crop_x1, 0, output_w);
418         Workarounds::clamp(crop_x2, 0, output_w);
419         Workarounds::clamp(crop_y1, 0, output_h);
420         Workarounds::clamp(crop_y2, 0, output_h);
421         if(brender_start < 0) brender_start = 0.0;
423         Workarounds::clamp(subtitle_number, 0, 31);
424         
425 // Correct framerates
426         frame_rate = Units::fix_framerate(frame_rate);
427 //printf("EDLSession::boundaries 1 %p %p\n", edl->assets, edl->tracks);
428 //      if(vwindow_source < 0 || vwindow_source >= edl->assets->total() + 1) vwindow_source = 0;
429 //      if(cwindow_dest < 0 || cwindow_dest > edl->tracks->total()) cwindow_dest = 0;
430 //printf("EDLSession::boundaries 2\n");
435 int EDLSession::load_video_config(FileXML *file, int append_mode, uint32_t load_flags)
437         char string[1024];
438         if(append_mode) return 0;
439         interpolation_type = file->tag.get_property("INTERPOLATION_TYPE", interpolation_type);
440         interpolate_raw = file->tag.get_property("INTERPOLATE_RAW", interpolate_raw);
441         white_balance_raw = file->tag.get_property("WHITE_BALANCE_RAW", white_balance_raw);
442         cmodel_to_text(string, color_model);
443         color_model = cmodel_from_text(file->tag.get_property("COLORMODEL", string));
444         interlace_mode = ilacemode_from_xmltext(file->tag.get_property("INTERLACE_MODE"), BC_ILACE_MODE_NOTINTERLACED);
445         video_channels = file->tag.get_property("CHANNELS", video_channels);
446         for(int i = 0; i < video_channels; i++)
447         {
448                 int default_position = i * output_w;
449                 sprintf(string, "VCHANNEL_X_%d", i);
450                 vchannel_x[i] = file->tag.get_property(string, default_position);
451                 sprintf(string, "VCHANNEL_Y_%d", i);
452                 vchannel_y[i] = file->tag.get_property(string, 0);
453         }
455         frame_rate = file->tag.get_property("FRAMERATE", frame_rate);
456         frames_per_foot = file->tag.get_property("FRAMES_PER_FOOT", frames_per_foot);
457         output_w = file->tag.get_property("OUTPUTW", output_w);
458         output_h = file->tag.get_property("OUTPUTH", output_h);
459         aspect_w = file->tag.get_property("ASPECTW", aspect_w);
460         aspect_h = file->tag.get_property("ASPECTH", aspect_h);
461         return 0;
464 int EDLSession::load_audio_config(FileXML *file, int append_mode, uint32_t load_flags)
466         char string[32];
467 // load channels setting
468         if(append_mode) return 0;
469         audio_channels = file->tag.get_property("CHANNELS", (int64_t)audio_channels);
472         for(int i = 0; i < audio_channels; i++)
473         {
474                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
475                 achannel_positions[i] = file->tag.get_property(string, achannel_positions[i]);
476 //printf("EDLSession::load_audio_config 1 %d %d\n", i, achannel_positions[i]);
477         }
479         sample_rate = file->tag.get_property("SAMPLERATE", (int64_t)sample_rate);
480         return 0;
483 int EDLSession::load_xml(FileXML *file, 
484         int append_mode, 
485         uint32_t load_flags)
487         char string[BCTEXTLEN];
489         if(append_mode)
490         {
491         }
492         else
493         {
494                 assetlist_format = file->tag.get_property("ASSETLIST_FORMAT", assetlist_format);
495                 for(int i = 0; i < ASSET_COLUMNS; i++)
496                 {
497                         sprintf(string, "ASSET_COLUMN%d", i);
498                         asset_columns[i] = file->tag.get_property(string, asset_columns[i]);
499                 }
500                 auto_conf->load_xml(file);
501                 auto_keyframes = file->tag.get_property("AUTO_KEYFRAMES", auto_keyframes);
502                 autos_follow_edits = file->tag.get_property("AUTOS_FOLLOW_EDITS", autos_follow_edits);
503                 brender_start = file->tag.get_property("BRENDER_START", brender_start);
504                 crop_x1 = file->tag.get_property("CROP_X1", crop_x1);
505                 crop_y1 = file->tag.get_property("CROP_Y1", crop_y1);
506                 crop_x2 = file->tag.get_property("CROP_X2", crop_x2);
507                 crop_y2 = file->tag.get_property("CROP_Y2", crop_y2);
508                 file->tag.get_property("CURRENT_FOLDER", current_folder);
509                 cursor_on_frames = file->tag.get_property("CURSOR_ON_FRAMES", cursor_on_frames);
510                 cwindow_dest = file->tag.get_property("CWINDOW_DEST", cwindow_dest);
511                 cwindow_mask = file->tag.get_property("CWINDOW_MASK", cwindow_mask);
512                 cwindow_meter = file->tag.get_property("CWINDOW_METER", cwindow_meter);
513                 cwindow_operation = file->tag.get_property("CWINDOW_OPERATION", cwindow_operation);
514                 cwindow_scrollbars = file->tag.get_property("CWINDOW_SCROLLBARS", cwindow_scrollbars);
515                 cwindow_xscroll = file->tag.get_property("CWINDOW_XSCROLL", cwindow_xscroll);
516                 cwindow_yscroll = file->tag.get_property("CWINDOW_YSCROLL", cwindow_yscroll);
517                 cwindow_zoom = file->tag.get_property("CWINDOW_ZOOM", cwindow_zoom);
518                 file->tag.get_property("DEFAULT_ATRANSITION", default_atransition);
519                 file->tag.get_property("DEFAULT_VTRANSITION", default_vtransition);
520                 default_transition_length = file->tag.get_property("DEFAULT_TRANSITION_LENGTH", default_transition_length);
521                 editing_mode = file->tag.get_property("EDITING_MODE", editing_mode);
522                 folderlist_format = file->tag.get_property("FOLDERLIST_FORMAT", folderlist_format);
523                 highlighted_track = file->tag.get_property("HIGHLIGHTED_TRACK", 0);
524                 labels_follow_edits = file->tag.get_property("LABELS_FOLLOW_EDITS", labels_follow_edits);
525                 mpeg4_deblock = file->tag.get_property("MPEG4_DEBLOCK", mpeg4_deblock);
526                 plugins_follow_edits = file->tag.get_property("PLUGINS_FOLLOW_EDITS", plugins_follow_edits);
527                 playback_preload = file->tag.get_property("PLAYBACK_PRELOAD", playback_preload);
528                 safe_regions = file->tag.get_property("SAFE_REGIONS", safe_regions);
529                 show_assets = file->tag.get_property("SHOW_ASSETS", 1);
530                 show_titles = file->tag.get_property("SHOW_TITLES", 1);
531 //              test_playback_edits = file->tag.get_property("TEST_PLAYBACK_EDITS", test_playback_edits);
532                 time_format = file->tag.get_property("TIME_FORMAT", time_format);
533                 for(int i = 0; i < 4; i++)
534                 {
535                         sprintf(string, "TIMECODE_OFFSET_%d", i);
536                         timecode_offset[i] = file->tag.get_property(string, timecode_offset[i]);
537                 }
538                 nudge_seconds = file->tag.get_property("NUDGE_FORMAT", nudge_seconds);
539                 tool_window = file->tag.get_property("TOOL_WINDOW", tool_window);
540                 vwindow_meter = file->tag.get_property("VWINDOW_METER", vwindow_meter);
541                 file->tag.get_property("VWINDOW_FOLDER", vwindow_folder);
542                 vwindow_source = file->tag.get_property("VWINDOW_SOURCE", vwindow_source);
543                 vwindow_zoom = file->tag.get_property("VWINDOW_ZOOM", vwindow_zoom);
545                 decode_subtitles = file->tag.get_property("DECODE_SUBTITLES", decode_subtitles);
546                 subtitle_number = file->tag.get_property("subtitle_number", subtitle_number);
547                 boundaries();
548         }
549         
550         return 0;
553 int EDLSession::save_xml(FileXML *file)
555 //printf("EDLSession::save_session 1\n");
556         char string[BCTEXTLEN];
557         file->tag.set_title("SESSION");
558         file->tag.set_property("ASSETLIST_FORMAT", assetlist_format);
559         for(int i = 0; i < ASSET_COLUMNS; i++)
560         {
561                 sprintf(string, "ASSET_COLUMN%d", i);
562                 file->tag.set_property(string, asset_columns[i]);
563         }
564         auto_conf->save_xml(file);
565         file->tag.set_property("AUTO_KEYFRAMES", auto_keyframes);
566         file->tag.set_property("AUTOS_FOLLOW_EDITS", autos_follow_edits);
567         file->tag.set_property("BRENDER_START", brender_start);
568         file->tag.set_property("CROP_X1", crop_x1);
569         file->tag.set_property("CROP_Y1", crop_y1);
570         file->tag.set_property("CROP_X2", crop_x2);
571         file->tag.set_property("CROP_Y2", crop_y2);
572         file->tag.set_property("CURRENT_FOLDER", current_folder);
573         file->tag.set_property("CURSOR_ON_FRAMES", cursor_on_frames);
574         file->tag.set_property("CWINDOW_DEST", cwindow_dest);
575         file->tag.set_property("CWINDOW_MASK", cwindow_mask);
576         file->tag.set_property("CWINDOW_METER", cwindow_meter);
577         file->tag.set_property("CWINDOW_OPERATION", cwindow_operation);
578         file->tag.set_property("CWINDOW_SCROLLBARS", cwindow_scrollbars);
579         file->tag.set_property("CWINDOW_XSCROLL", cwindow_xscroll);
580         file->tag.set_property("CWINDOW_YSCROLL", cwindow_yscroll);
581         file->tag.set_property("CWINDOW_ZOOM", cwindow_zoom);
582         file->tag.set_property("DEFAULT_ATRANSITION", default_atransition);
583         file->tag.set_property("DEFAULT_VTRANSITION", default_vtransition);
584         file->tag.set_property("DEFAULT_TRANSITION_LENGTH", default_transition_length);
585         file->tag.set_property("EDITING_MODE", editing_mode);
586         file->tag.set_property("FOLDERLIST_FORMAT", folderlist_format);
587         file->tag.set_property("HIGHLIGHTED_TRACK", highlighted_track);
588         file->tag.set_property("LABELS_FOLLOW_EDITS", labels_follow_edits);
589         file->tag.set_property("MPEG4_DEBLOCK", mpeg4_deblock);
590         file->tag.set_property("PLUGINS_FOLLOW_EDITS", plugins_follow_edits);
591         file->tag.set_property("PLAYBACK_PRELOAD", playback_preload);
592         file->tag.set_property("SAFE_REGIONS", safe_regions);
593         file->tag.set_property("SHOW_ASSETS", show_assets);
594         file->tag.set_property("SHOW_TITLES", show_titles);
595         file->tag.set_property("TEST_PLAYBACK_EDITS", test_playback_edits);
596         file->tag.set_property("TIME_FORMAT", time_format);
597         for(int i = 0; i < 4; i++)
598         {
599                 sprintf(string, "TIMECODE_OFFSET_%d", i);
600                 file->tag.set_property(string, timecode_offset[i]);
601         }
602         file->tag.set_property("NUDGE_SECONDS", nudge_seconds);
603         file->tag.set_property("TOOL_WINDOW", tool_window);
604         file->tag.set_property("VWINDOW_METER", vwindow_meter);
605         file->tag.set_property("VWINDOW_FOLDER", vwindow_folder);
606         file->tag.set_property("VWINDOW_SOURCE", vwindow_source);
607         file->tag.set_property("VWINDOW_ZOOM", vwindow_zoom);
610         file->tag.set_property("DECODE_SUBTITLES", decode_subtitles);
611         file->tag.set_property("subtitle_number", subtitle_number);
615         file->append_tag();
616         file->tag.set_title("/SESSION");
617         file->append_tag();
618         file->append_newline();
619         file->append_newline();
620 //printf("EDLSession::save_session 3\n");
621         return 0;
624 int EDLSession::save_video_config(FileXML *file)
626         char string[1024];
627         file->tag.set_title("VIDEO");
628         file->tag.set_property("INTERPOLATION_TYPE", interpolation_type);
629         file->tag.set_property("INTERPOLATE_RAW", interpolate_raw);
630         file->tag.set_property("WHITE_BALANCE_RAW", white_balance_raw);
631         cmodel_to_text(string, color_model);
632         file->tag.set_property("COLORMODEL", string);
633         ilacemode_to_xmltext(string, interlace_mode);
634         file->tag.set_property("INTERLACE_MODE",string);
635     file->tag.set_property("CHANNELS", video_channels);
636         for(int i = 0; i < video_channels; i++)
637         {
638                 sprintf(string, "VCHANNEL_X_%d", i);
639                 file->tag.set_property(string, vchannel_x[i]);
640                 sprintf(string, "VCHANNEL_Y_%d", i);
641                 file->tag.set_property(string, vchannel_y[i]);
642         }
644         file->tag.set_property("FRAMERATE", frame_rate);
645         file->tag.set_property("FRAMES_PER_FOOT", frames_per_foot);
646         file->tag.set_property("OUTPUTW", output_w);
647         file->tag.set_property("OUTPUTH", output_h);
648         file->tag.set_property("ASPECTW", aspect_w);
649         file->tag.set_property("ASPECTH", aspect_h);
650         file->append_tag();
651         file->tag.set_title("/VIDEO");
652         file->append_tag();
653         file->append_newline();
654         file->append_newline();
655         return 0;
658 int EDLSession::save_audio_config(FileXML *file)
660         char string[1024];
661         file->tag.set_title("AUDIO");
662         file->tag.set_property("SAMPLERATE", (int64_t)sample_rate);
663         file->tag.set_property("CHANNELS", (int64_t)audio_channels);
664         
665         for(int i = 0; i < audio_channels; i++)
666         {
667                 sprintf(string, "ACHANNEL_ANGLE_%d", i);
668                 file->tag.set_property(string, achannel_positions[i]);
669         }
670         
671         file->append_tag();
672         file->tag.set_title("/AUDIO");
673         file->append_tag();
674         file->append_newline();
675         file->append_newline();
676         return 0;
679 int EDLSession::copy(EDLSession *session)
681 // Audio channel positions
682         for(int i = 0; i < MAXCHANNELS; i++)
683         {
684                 achannel_positions[i] = session->achannel_positions[i];
685         }
686         aconfig_duplex->copy_from(session->aconfig_duplex);
687         aconfig_in->copy_from(session->aconfig_in);
688         actual_frame_rate = session->actual_frame_rate;
689         for(int i = 0; i < ASSET_COLUMNS; i++)
690         {
691                 asset_columns[i] = session->asset_columns[i];
692         }
693         assetlist_format = session->assetlist_format;
694         auto_conf->copy_from(session->auto_conf);
695         aspect_w = session->aspect_w;
696         aspect_h = session->aspect_h;
697         audio_channels = session->audio_channels;
698         audio_tracks = session->audio_tracks;
699         autos_follow_edits = session->autos_follow_edits;
700         brender_start = session->brender_start;
701         color_model = session->color_model;
702         interlace_mode = session->interlace_mode;
703         crop_x1 = session->crop_x1;
704         crop_y1 = session->crop_y1;
705         crop_x2 = session->crop_x2;
706         crop_y2 = session->crop_y2;
707         strcpy(current_folder, session->current_folder);
708         cursor_on_frames = session->cursor_on_frames;
709         cwindow_dest = session->cwindow_dest;
710         cwindow_mask = session->cwindow_mask;
711         cwindow_meter = session->cwindow_meter;
712         cwindow_operation = session->cwindow_operation;
713         cwindow_scrollbars = session->cwindow_scrollbars;
714         cwindow_xscroll = session->cwindow_xscroll;
715         cwindow_yscroll = session->cwindow_yscroll;
716         cwindow_zoom = session->cwindow_zoom;
717         strcpy(default_atransition, session->default_atransition);
718         strcpy(default_vtransition, session->default_vtransition);
719         default_transition_length = session->default_transition_length;
720         edit_handle_mode[0] = session->edit_handle_mode[0];
721         edit_handle_mode[1] = session->edit_handle_mode[1];
722         edit_handle_mode[2] = session->edit_handle_mode[2];
723         editing_mode = session->editing_mode;
724         enable_duplex = session->enable_duplex;
725         folderlist_format = session->folderlist_format;
726         frame_rate = session->frame_rate;
727         frames_per_foot = session->frames_per_foot;
728         highlighted_track = session->highlighted_track;
729         interpolation_type = session->interpolation_type;
730         interpolate_raw = session->interpolate_raw;
731         white_balance_raw = session->white_balance_raw;
732         labels_follow_edits = session->labels_follow_edits;
733         plugins_follow_edits = session->plugins_follow_edits;
734         auto_keyframes = session->auto_keyframes;
735 //      last_playback_position = session->last_playback_position;
736         meter_format = session->meter_format;
737         min_meter_db = session->min_meter_db;
738         max_meter_db = session->max_meter_db;
739         mpeg4_deblock = session->mpeg4_deblock;
740         output_w = session->output_w;
741         output_h = session->output_h;
742         playback_buffer = session->playback_buffer;
743         delete playback_config;
744         playback_config = new PlaybackConfig;
745         playback_config->copy_from(session->playback_config);
746         playback_cursor_visible = session->playback_cursor_visible;
747         playback_preload = session->playback_preload;
748         playback_software_position = session->playback_software_position;
749         real_time_playback = session->real_time_playback;
750         real_time_record = session->real_time_record;
751         record_software_position = session->record_software_position;
752 //      record_speed = session->record_speed;
753         record_sync_drives = session->record_sync_drives;
754         record_write_length = session->record_write_length;
755         recording_format->copy_from(session->recording_format, 0);
756         safe_regions = session->safe_regions;
757         sample_rate = session->sample_rate;
758         scrub_speed = session->scrub_speed;
759         si_useduration = session->si_useduration;
760         si_duration = session->si_duration;
761         show_assets = session->show_assets;
762         show_titles = session->show_titles;
763         test_playback_edits = session->test_playback_edits;
764         time_format = session->time_format;
765         for(int i = 0; i < 4; i++)
766         {
767                 timecode_offset[i] = session->timecode_offset[i];
768         }
769         nudge_seconds = session->nudge_seconds;
770         tool_window = session->tool_window;
771         for(int i = 0; i < MAXCHANNELS; i++)
772         {
773                 vchannel_x[i] = session->vchannel_x[i];
774                 vchannel_y[i] = session->vchannel_y[i];
775         }
776         video_channels = session->video_channels;
777         *vconfig_in = *session->vconfig_in;
778         video_every_frame = session->video_every_frame;
779         video_asynchronous = session->video_asynchronous;
780         video_tracks = session->video_tracks;
781         video_write_length = session->video_write_length;       
782         view_follows_playback = session->view_follows_playback;
783         vwindow_meter = session->vwindow_meter;
784         strcpy(vwindow_folder, session->vwindow_folder);
785         vwindow_source = session->vwindow_source;
786         vwindow_zoom = session->vwindow_zoom;
788         subtitle_number = session->subtitle_number;
789         decode_subtitles = session->decode_subtitles;
790         
791         return 0;
794 int64_t EDLSession::get_frame_offset()
796         return int64_t((timecode_offset[3] * 3600 +
797                                 timecode_offset[2] * 60 +
798                                 timecode_offset[1]) *
799                                 frame_rate +
800                                 timecode_offset[0]);
803 void EDLSession::dump()
805         printf("EDLSession::dump\n");
806         printf("    audio_tracks=%d audio_channels=%d sample_rate=%lld\n"
807                         "video_tracks=%d frame_rate=%f output_w=%d output_h=%d aspect_w=%f aspect_h=%f decode subtitles=%d subtitle_number=%d\n", 
808                 audio_tracks, 
809                 audio_channels, 
810                 sample_rate, 
811                 video_tracks, 
812                 frame_rate, 
813                 output_w, 
814                 output_h, 
815                 aspect_w, 
816                 aspect_h,
817                 decode_subtitles,
818                 subtitle_number);