4 * Copyright (C) 2006 Andraz Tori
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "condition.h"
25 #include "confirmsave.h"
28 #include "edlsession.h"
31 #include "filesystem.h"
34 #include "localsession.h"
35 #include "mainsession.h"
37 #include "mwindowgui.h"
39 #include "exportedl.h"
41 #include "transition.h"
44 #define _(String) gettext(String)
45 #define gettext_noop(String) String
46 #define N_(String) gettext_noop (String)
53 ExportEDLAsset::ExportEDLAsset(MWindow *mwindow, EDL *edl)
55 this->mwindow = mwindow;
59 edl_type = EDLTYPE_CMX3600;
63 ExportEDLAsset::~ExportEDLAsset()
67 void ExportEDLAsset::double_to_CMX3600(double seconds, double frame_rate, char *str)
73 0, // sample_rate ... unnecessary
75 0); // frames per foot
76 if ((int)(seconds / 3600) <= 9)
87 //sprintf(str, "%02d:%02d:%02d:%02d", hour, minute, second, hundredths);
90 int ExportEDLAsset::edit_to_timecodes(Edit *edit, char *sourceinpoint, char *sourceoutpoint, char *destinpoint, char *destoutpoint, char *reel_name)
92 Asset *asset = edit->asset;
93 Track *track = edit->track;
94 double frame_rate = edit->track->edl->session->frame_rate;
96 double edit_sourcestart;
97 double edit_sourceend;
98 double edit_deststart;
103 // reelname should be 8 chars long
105 strncpy(reel_name, asset->reel_name, 9);
106 if (strlen(asset->reel_name) > 8)
108 printf(_("Warning: chopping the reel name to eight characters!\n"));
111 for (int i = strlen(reel_name); i<8; i++)
114 edit_sourcestart = (double)asset->tcstart / asset->frame_rate
115 + track->from_units(edit->startsource);
116 edit_sourceend = (double)asset->tcstart / asset->frame_rate
117 + track->from_units(edit->startsource + edit->length);
121 strcpy(reel_name, " BL ");
122 edit_sourcestart = 0;
123 edit_sourceend = track->from_units(edit->length);
126 edit_deststart = track->from_units(edit->startproject);
127 edit_destend = track->from_units(edit->startproject + edit->length);
129 double_to_CMX3600(edit_sourcestart, frame_rate, sourceinpoint);
130 double_to_CMX3600(edit_sourceend, frame_rate, sourceoutpoint);
131 double_to_CMX3600(edit_deststart, frame_rate, destinpoint);
132 double_to_CMX3600(edit_destend, frame_rate, destoutpoint);
138 void ExportEDLAsset::export_it()
141 fh = fopen(path, "w+");
143 // We currently only support exporting one track at a time
147 for(track = edl->tracks->first;
151 if (serial == track_number)
157 int last_dissolve = 1;
159 if (edl_type == EDLTYPE_CMX3600)
162 // TODO: Find docs about exact header for CMX3600
163 fprintf(fh, "TITLE: Cinproj FORMAT: CMX 3600 4-Ch\n");
168 for (Edit *edit = track->edits->first;
172 char reel_name[BCTEXTLEN];
174 char edittype[5] = "C ";
175 char cutinfo[4] = " ";
176 char sourceinpoint[12];
177 char sourceoutpoint[12];
178 char destinpoint[12];
179 char destoutpoint[12];
180 if (track->data_type == TRACK_AUDIO)
181 strcpy(avselect, "A ");
183 strcpy(avselect, "V ");
185 //if (edit->transition)
186 // printf("title: %s, length: %i\n", edit->transition->title, edit->transition->length);
187 if (edit->transition && !strcmp(edit->transition->title, "Dissolve"))
189 char last_sourceout[12];
190 edit_to_timecodes(edit->previous, sourceinpoint, last_sourceout, destinpoint, destoutpoint, reel_name);
191 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
195 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
196 fprintf(fh, " %s %s", last_sourceout, last_sourceout);
197 fprintf(fh, " %s %s", destinpoint, destinpoint);
204 fprintf(fh, "%03d %8s %s %4s %03jd", colnum, reel_name, avselect, edittype, edit->transition->length);
205 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
206 fprintf(fh, " %s %s", destinpoint, destoutpoint);
211 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
212 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
213 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
214 fprintf(fh, " %s %s", destinpoint, destoutpoint);
232 int ExportEDLAsset::load_defaults()
234 mwindow->defaults->get("EDLEXPORT_PATH", path);
235 mwindow->defaults->get("EDLEXPORT_TYPE", edl_type);
236 mwindow->defaults->get("EDLEXPORT_TRACKNUMBER", track_number);
237 //load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOADMODE_NEW_TRACKS);
243 int ExportEDLAsset::save_defaults()
245 mwindow->defaults->update("EDLEXPORT_PATH", path);
246 mwindow->defaults->update("EDLEXPORT_TYPE", edl_type);
247 mwindow->defaults->update("EDLEXPORT_TRACKNUMBER", track_number);
254 ExportEDLItem::ExportEDLItem(MWindow *mwindow)
255 : BC_MenuItem(_("Export EDL..."), "Shift-E", 'E')
257 this->mwindow = mwindow;
261 int ExportEDLItem::handle_event()
263 mwindow->exportedl->start_interactive();
271 ExportEDL::ExportEDL(MWindow *mwindow)
274 this->mwindow = mwindow;
275 // package_lock = new Mutex("ExportEDL::package_lock");
276 // counter_lock = new Mutex("ExportEDL::counter_lock");
277 // completion = new Condition(0, "ExportEDL::completion");
278 // progress_timer = new Timer;
281 ExportEDL::~ExportEDL()
283 // delete package_lock;
284 // delete counter_lock;
285 // delete completion;
286 /// if(preferences) delete preferences;
287 // delete progress_timer;
290 void ExportEDL::start_interactive()
292 if(!Thread::running())
298 void ExportEDL::run()
301 exportasset = new ExportEDLAsset(mwindow, mwindow->edl);
303 exportasset->load_defaults();
305 // Get format from user
312 exportedl_window = new ExportEDLWindow(mwindow, this, exportasset);
313 exportedl_window->create_objects();
314 result = exportedl_window->run_window();
316 // add to recentlist only on OK
318 exportedl_window->path_recent->add_item("EDLPATH", exportasset->path);
320 exportasset->track_number = exportedl_window->track_list->get_selection_number(0, 0);
322 delete exportedl_window;
323 exportedl_window = 0;
326 ArrayList<char*> paths;
328 paths.append(exportasset->path);
329 filesok = ConfirmSave::test_files(mwindow, &paths);
332 } while (!result && filesok);
333 mwindow->save_defaults();
334 exportasset->save_defaults();
337 if(!result) exportasset->export_it();
354 static const char *list_titles[] =
361 static int list_widths[] =
367 ExportEDLWindow::ExportEDLWindow(MWindow *mwindow, ExportEDL *exportedl, ExportEDLAsset *exportasset)
368 : BC_Window(_(PROGRAM_NAME ": Export EDL"),
369 mwindow->gui->get_screen_w(1, 0) / 2 - WIDTH / 2,
370 mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2,
379 this->mwindow = mwindow;
380 this->exportasset = exportasset;
383 ExportEDLWindow::~ExportEDLWindow()
385 // delete format_tools;
391 void ExportEDLWindow::create_objects()
394 add_subwindow(new BC_Title(x,
396 _("Select a file to export to:")));
399 add_subwindow(path_textbox = new ExportEDLPathText(x, y, this));
401 path_recent = new BC_RecentList("EDLPATH", mwindow->defaults,
402 path_textbox, 10, x, y, 300, 100);
403 add_subwindow(path_recent);
405 path_recent->load_items("EDLPATH");
408 add_subwindow(path_button = new BrowseButton(
409 mwindow->theme, this, path_textbox, x, y - 4, exportasset->path,
410 _("Output to file"), _("Select a file to write to:"), 0));
414 add_subwindow(new BC_Title(x, y, _("Select track to be exported:")));
418 items_tracks[0].remove_all_objects();
419 items_tracks[1].remove_all_objects();
421 if (exportasset->track_number == -1)
422 exportasset->track_number = 0;
423 for(Track *track = mwindow->edl->tracks->first;
429 sprintf(tmp, "%i\n", serial+1);
431 BC_ListBoxItem *listitem = new BC_ListBoxItem(tmp);
432 if (serial == exportasset->track_number)
433 listitem->set_selected(1);
434 items_tracks[0].append(listitem);
435 items_tracks[1].append(new BC_ListBoxItem(track->title));
441 add_subwindow(track_list = new ExportEDLWindowTrackList(this, x, y, 400, 200, items_tracks));
443 y += 5 + track_list->get_h();
444 add_subwindow(new BC_Title(x, y, _("Currently only CMX 3600 format is supported")));
447 add_subwindow(new BC_OKButton(this));
448 add_subwindow(new BC_CancelButton(this));
453 ExportEDLPathText::ExportEDLPathText(int x, int y, ExportEDLWindow *window)
454 : BC_TextBox(x, y, 300, 1, window->exportasset->path)
456 this->window = window;
458 ExportEDLPathText::~ExportEDLPathText()
461 int ExportEDLPathText::handle_event()
463 strcpy(window->exportasset->path, get_text());
464 // window->handle_event();
468 ExportEDLWindowTrackList::ExportEDLWindowTrackList(ExportEDLWindow *window,
473 ArrayList<BC_ListBoxItem*> *track_list)
484 this->window = window;
487 int ExportEDLWindowTrackList::handle_event()
489 // window->exportasset->track_number = get_selection_number(0, 0);
490 // printf("aaaaa %i\n", window->exportasset->track_number );
491 // window->set_done(0);