4 #include "confirmsave.h"
7 #include "edlsession.h"
10 #include "filesystem.h"
13 #include "localsession.h"
14 #include "mainsession.h"
16 #include "mwindowgui.h"
18 #include "exportedl.h"
20 #include "transition.h"
23 #define _(String) gettext(String)
24 #define gettext_noop(String) String
25 #define N_(String) gettext_noop (String)
32 ExportEDLAsset::ExportEDLAsset(MWindow *mwindow, EDL *edl)
34 this->mwindow = mwindow;
38 edl_type = EDLTYPE_CMX3600;
42 ExportEDLAsset::~ExportEDLAsset()
46 void ExportEDLAsset::double_to_CMX3600(double seconds, double frame_rate, char *str)
52 0, // sample_rate ... unnecessary
54 0); // frames per foot
55 if ((int)(seconds / 3600) <= 9)
66 //sprintf(str, "%02d:%02d:%02d:%02d", hour, minute, second, hundredths);
69 int ExportEDLAsset::edit_to_timecodes(Edit *edit, char *sourceinpoint, char *sourceoutpoint, char *destinpoint, char *destoutpoint, char *reel_name)
71 Asset *asset = edit->asset;
72 Track *track = edit->track;
73 double frame_rate = edit->track->edl->session->frame_rate;
75 double edit_sourcestart;
76 double edit_sourceend;
77 double edit_deststart;
82 // reelname should be 8 chars long
84 strncpy(reel_name, asset->reel_name, 9);
85 if (strlen(asset->reel_name) > 8)
87 printf(_("Warning: chopping the reel name to eight characters!\n"));
90 for (int i = strlen(reel_name); i<8; i++)
93 edit_sourcestart = (double)asset->tcstart / asset->frame_rate
94 + track->from_units(edit->startsource);
95 edit_sourceend = (double)asset->tcstart / asset->frame_rate
96 + track->from_units(edit->startsource + edit->length);
100 strcpy(reel_name, " BL ");
101 edit_sourcestart = 0;
102 edit_sourceend = track->from_units(edit->length);
105 edit_deststart = track->from_units(edit->startproject);
106 edit_destend = track->from_units(edit->startproject + edit->length);
108 double_to_CMX3600(edit_sourcestart, frame_rate, sourceinpoint);
109 double_to_CMX3600(edit_sourceend, frame_rate, sourceoutpoint);
110 double_to_CMX3600(edit_deststart, frame_rate, destinpoint);
111 double_to_CMX3600(edit_destend, frame_rate, destoutpoint);
117 int ExportEDLAsset::export_it()
120 fh = fopen(path, "w+");
122 // We currently only support exporting one track at a time
126 for(track = edl->tracks->first;
130 if (serial == track_number)
136 int last_dissolve = 1;
138 if (edl_type == EDLTYPE_CMX3600)
141 // TODO: Find docs about exact header for CMX3600
142 fprintf(fh, "TITLE: Cinproj FORMAT: CMX 3600 4-Ch\n");
147 for (Edit *edit = track->edits->first;
151 char reel_name[BCTEXTLEN];
153 char edittype[5] = "C ";
154 char cutinfo[4] = " ";
155 char sourceinpoint[12];
156 char sourceoutpoint[12];
157 char destinpoint[12];
158 char destoutpoint[12];
159 if (track->data_type == TRACK_AUDIO)
160 strcpy(avselect, "A ");
162 strcpy(avselect, "V ");
164 //if (edit->transition)
165 // printf("title: %s, length: %i\n", edit->transition->title, edit->transition->length);
166 if (edit->transition && !strcmp(edit->transition->title, "Dissolve"))
168 char last_sourceout[12];
169 edit_to_timecodes(edit->previous, sourceinpoint, last_sourceout, destinpoint, destoutpoint, reel_name);
170 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
174 fprintf(fh, "%03d %8s %s %4s %03s", colnum, reel_name, avselect, edittype, cutinfo);
175 fprintf(fh, " %s %s", last_sourceout, last_sourceout);
176 fprintf(fh, " %s %s", destinpoint, destinpoint);
183 fprintf(fh, "%03d %8s %s %4s %03d", colnum, reel_name, avselect, edittype, edit->transition->length);
184 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
185 fprintf(fh, " %s %s", destinpoint, destoutpoint);
190 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
191 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
192 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
193 fprintf(fh, " %s %s", destinpoint, destoutpoint);
211 int ExportEDLAsset::load_defaults()
213 mwindow->defaults->get("EDLEXPORT_PATH", path);
214 mwindow->defaults->get("EDLEXPORT_TYPE", edl_type);
215 mwindow->defaults->get("EDLEXPORT_TRACKNUMBER", track_number);
216 //load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOAD_NEW_TRACKS);
222 int ExportEDLAsset::save_defaults()
224 mwindow->defaults->update("EDLEXPORT_PATH", path);
225 mwindow->defaults->update("EDLEXPORT_TYPE", edl_type);
226 mwindow->defaults->update("EDLEXPORT_TRACKNUMBER", track_number);
233 ExportEDLItem::ExportEDLItem(MWindow *mwindow)
234 : BC_MenuItem(_("Export EDL..."), "Shift+E", 'E')
236 this->mwindow = mwindow;
240 int ExportEDLItem::handle_event()
242 mwindow->exportedl->start_interactive();
250 ExportEDL::ExportEDL(MWindow *mwindow)
253 this->mwindow = mwindow;
254 // package_lock = new Mutex("ExportEDL::package_lock");
255 // counter_lock = new Mutex("ExportEDL::counter_lock");
256 // completion = new Condition(0, "ExportEDL::completion");
257 // progress_timer = new Timer;
260 ExportEDL::~ExportEDL()
262 // delete package_lock;
263 // delete counter_lock;
264 // delete completion;
265 /// if(preferences) delete preferences;
266 // delete progress_timer;
269 void ExportEDL::start_interactive()
271 if(!Thread::running())
277 void ExportEDL::run()
280 exportasset = new ExportEDLAsset(mwindow, mwindow->edl);
282 exportasset->load_defaults();
284 // Get format from user
291 exportedl_window = new ExportEDLWindow(mwindow, this, exportasset);
292 exportedl_window->create_objects();
293 result = exportedl_window->run_window();
295 // add to recentlist only on OK
297 exportedl_window->path_recent->add_item("EDLPATH", exportasset->path);
299 exportasset->track_number = exportedl_window->track_list->get_selection_number(0, 0);
301 delete exportedl_window;
302 exportedl_window = 0;
305 ArrayList<char*> paths;
307 paths.append(exportasset->path);
308 filesok = ConfirmSave::test_files(mwindow, &paths);
311 } while (!result && filesok);
312 mwindow->save_defaults();
313 exportasset->save_defaults();
316 if(!result) exportasset->export_it();
333 static char *list_titles[] =
340 static int list_widths[] =
346 ExportEDLWindow::ExportEDLWindow(MWindow *mwindow, ExportEDL *exportedl, ExportEDLAsset *exportasset)
347 : BC_Window(PROGRAM_NAME ": Export EDL",
348 mwindow->gui->get_root_w(0, 1) / 2 - WIDTH / 2,
349 mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2,
358 this->mwindow = mwindow;
359 this->exportasset = exportasset;
362 ExportEDLWindow::~ExportEDLWindow()
364 // delete format_tools;
370 int ExportEDLWindow::create_objects()
373 add_subwindow(new BC_Title(x,
375 _("Select a file to export to:")));
378 add_subwindow(path_textbox = new ExportEDLPathText(x, y, this));
380 path_recent = new BC_RecentList("EDLPATH", mwindow->defaults,
381 path_textbox, 10, x, y, 300, 100);
382 add_subwindow(path_recent);
384 path_recent->load_items("EDLPATH");
387 add_subwindow(path_button = new BrowseButton(
395 _("Select a file to write to:"),
400 add_subwindow(new BC_Title(x, y, _("Select track to be exported:")));
404 items_tracks[0].remove_all_objects();
405 items_tracks[1].remove_all_objects();
407 if (exportasset->track_number == -1)
408 exportasset->track_number = 0;
409 for(Track *track = mwindow->edl->tracks->first;
415 sprintf(tmp, "%i\n", serial+1);
417 BC_ListBoxItem *listitem = new BC_ListBoxItem(tmp);
418 if (serial == exportasset->track_number)
419 listitem->set_selected(1);
420 items_tracks[0].append(listitem);
421 items_tracks[1].append(new BC_ListBoxItem(track->title));
427 add_subwindow(track_list = new ExportEDLWindowTrackList(this, x, y, 400, 200, items_tracks));
429 y += 5 + track_list->get_h();
430 add_subwindow(new BC_Title(x, y, _("Currently only CMX 3600 format is supported")));
433 add_subwindow(new BC_OKButton(this));
434 add_subwindow(new BC_CancelButton(this));
440 ExportEDLPathText::ExportEDLPathText(int x, int y, ExportEDLWindow *window)
441 : BC_TextBox(x, y, 300, 1, window->exportasset->path)
443 this->window = window;
445 ExportEDLPathText::~ExportEDLPathText()
448 int ExportEDLPathText::handle_event()
450 strcpy(window->exportasset->path, get_text());
451 // window->handle_event();
454 ExportEDLWindowTrackList::ExportEDLWindowTrackList(ExportEDLWindow *window,
459 ArrayList<BC_ListBoxItem*> *track_list)
470 this->window = window;
473 int ExportEDLWindowTrackList::handle_event()
475 // window->exportasset->track_number = get_selection_number(0, 0);
476 // printf("aaaaa %i\n", window->exportasset->track_number );
477 // window->set_done(0);