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"
46 ExportEDLAsset::ExportEDLAsset(MWindow *mwindow, EDL *edl)
48 this->mwindow = mwindow;
52 edl_type = EDLTYPE_CMX3600;
56 ExportEDLAsset::~ExportEDLAsset()
60 void ExportEDLAsset::double_to_CMX3600(double seconds, double frame_rate, char *str)
66 0, // sample_rate ... unnecessary
68 0); // frames per foot
69 if ((int)(seconds / 3600) <= 9)
80 //sprintf(str, "%02d:%02d:%02d:%02d", hour, minute, second, hundredths);
83 int ExportEDLAsset::edit_to_timecodes(Edit *edit, char *sourceinpoint, char *sourceoutpoint, char *destinpoint, char *destoutpoint, char *reel_name)
85 Asset *asset = edit->asset;
86 Track *track = edit->track;
87 double frame_rate = edit->track->edl->session->frame_rate;
89 double edit_sourcestart;
90 double edit_sourceend;
91 double edit_deststart;
96 // reelname should be 8 chars long
98 strncpy(reel_name, asset->reel_name, 9);
99 if (strlen(asset->reel_name) > 8)
101 printf(_("Warning: chopping the reel name to eight characters!\n"));
104 for (int i = strlen(reel_name); i<8; i++)
107 edit_sourcestart = (double)asset->tcstart / asset->frame_rate
108 + track->from_units(edit->startsource);
109 edit_sourceend = (double)asset->tcstart / asset->frame_rate
110 + track->from_units(edit->startsource + edit->length);
114 strcpy(reel_name, " BL ");
115 edit_sourcestart = 0;
116 edit_sourceend = track->from_units(edit->length);
119 edit_deststart = track->from_units(edit->startproject);
120 edit_destend = track->from_units(edit->startproject + edit->length);
122 double_to_CMX3600(edit_sourcestart, frame_rate, sourceinpoint);
123 double_to_CMX3600(edit_sourceend, frame_rate, sourceoutpoint);
124 double_to_CMX3600(edit_deststart, frame_rate, destinpoint);
125 double_to_CMX3600(edit_destend, frame_rate, destoutpoint);
131 void ExportEDLAsset::export_it()
134 fh = fopen(path, "w+");
136 // We currently only support exporting one track at a time
140 for(track = edl->tracks->first;
144 if (serial == track_number)
150 int last_dissolve = 1;
152 if (edl_type == EDLTYPE_CMX3600)
155 // TODO: Find docs about exact header for CMX3600
156 fprintf(fh, "TITLE: Cinproj FORMAT: CMX 3600 4-Ch\n");
161 for (Edit *edit = track->edits->first;
165 char reel_name[BCTEXTLEN];
167 char edittype[5] = "C ";
168 char cutinfo[4] = " ";
169 char sourceinpoint[12];
170 char sourceoutpoint[12];
171 char destinpoint[12];
172 char destoutpoint[12];
173 if (track->data_type == TRACK_AUDIO)
174 strcpy(avselect, "A ");
176 strcpy(avselect, "V ");
178 //if (edit->transition)
179 // printf("title: %s, length: %i\n", edit->transition->title, edit->transition->length);
180 if (edit->transition && !strcmp(edit->transition->title, "Dissolve"))
182 char last_sourceout[12];
183 edit_to_timecodes(edit->previous, sourceinpoint, last_sourceout, destinpoint, destoutpoint, reel_name);
184 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
188 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
189 fprintf(fh, " %s %s", last_sourceout, last_sourceout);
190 fprintf(fh, " %s %s", destinpoint, destinpoint);
197 fprintf(fh, "%03d %8s %s %4s %03jd", colnum, reel_name, avselect, edittype, edit->transition->length);
198 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
199 fprintf(fh, " %s %s", destinpoint, destoutpoint);
204 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
205 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
206 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
207 fprintf(fh, " %s %s", destinpoint, destoutpoint);
225 int ExportEDLAsset::load_defaults()
227 mwindow->defaults->get("EDLEXPORT_PATH", path);
228 mwindow->defaults->get("EDLEXPORT_TYPE", edl_type);
229 mwindow->defaults->get("EDLEXPORT_TRACKNUMBER", track_number);
230 //load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOADMODE_NEW_TRACKS);
236 int ExportEDLAsset::save_defaults()
238 mwindow->defaults->update("EDLEXPORT_PATH", path);
239 mwindow->defaults->update("EDLEXPORT_TYPE", edl_type);
240 mwindow->defaults->update("EDLEXPORT_TRACKNUMBER", track_number);
247 ExportEDLItem::ExportEDLItem(MWindow *mwindow)
248 : BC_MenuItem(_("Export EDL..."), "Shift-E", 'E')
250 this->mwindow = mwindow;
254 int ExportEDLItem::handle_event()
256 mwindow->exportedl->start_interactive();
264 ExportEDL::ExportEDL(MWindow *mwindow)
267 this->mwindow = mwindow;
268 // package_lock = new Mutex("ExportEDL::package_lock");
269 // counter_lock = new Mutex("ExportEDL::counter_lock");
270 // completion = new Condition(0, "ExportEDL::completion");
271 // progress_timer = new Timer;
274 ExportEDL::~ExportEDL()
276 // delete package_lock;
277 // delete counter_lock;
278 // delete completion;
279 /// if(preferences) delete preferences;
280 // delete progress_timer;
283 void ExportEDL::start_interactive()
285 if(!Thread::running())
291 void ExportEDL::run()
294 exportasset = new ExportEDLAsset(mwindow, mwindow->edl);
296 exportasset->load_defaults();
298 // Get format from user
305 exportedl_window = new ExportEDLWindow(mwindow, this, exportasset);
306 exportedl_window->create_objects();
307 result = exportedl_window->run_window();
309 // add to recentlist only on OK
311 exportedl_window->path_recent->add_item("EDLPATH", exportasset->path);
313 exportasset->track_number = exportedl_window->track_list->get_selection_number(0, 0);
315 delete exportedl_window;
316 exportedl_window = 0;
319 ArrayList<char*> paths;
321 paths.append(exportasset->path);
322 filesok = ConfirmSave::test_files(mwindow, &paths);
325 } while (!result && filesok);
326 mwindow->save_defaults();
327 exportasset->save_defaults();
330 if(!result) exportasset->export_it();
347 static const char *list_titles[] =
354 static int list_widths[] =
360 ExportEDLWindow::ExportEDLWindow(MWindow *mwindow, ExportEDL *exportedl, ExportEDLAsset *exportasset)
361 : BC_Window(_(PROGRAM_NAME ": Export EDL"),
362 mwindow->gui->get_screen_w(1, 0) / 2 - WIDTH / 2,
363 mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2,
372 this->mwindow = mwindow;
373 this->exportasset = exportasset;
376 ExportEDLWindow::~ExportEDLWindow()
378 // delete format_tools;
384 void ExportEDLWindow::create_objects()
387 add_subwindow(new BC_Title(x,
389 _("Select a file to export to:")));
392 add_subwindow(path_textbox = new ExportEDLPathText(x, y, this));
394 path_recent = new BC_RecentList("EDLPATH", mwindow->defaults,
395 path_textbox, 10, x, y, 300, 100);
396 add_subwindow(path_recent);
398 path_recent->load_items("EDLPATH");
401 add_subwindow(path_button = new BrowseButton(
402 mwindow->theme, this, path_textbox, x, y - 4, exportasset->path,
403 _("Output to file"), _("Select a file to write to:"), 0));
407 add_subwindow(new BC_Title(x, y, _("Select track to be exported:")));
411 items_tracks[0].remove_all_objects();
412 items_tracks[1].remove_all_objects();
414 if (exportasset->track_number == -1)
415 exportasset->track_number = 0;
416 for(Track *track = mwindow->edl->tracks->first;
422 sprintf(tmp, "%i\n", serial+1);
424 BC_ListBoxItem *listitem = new BC_ListBoxItem(tmp);
425 if (serial == exportasset->track_number)
426 listitem->set_selected(1);
427 items_tracks[0].append(listitem);
428 items_tracks[1].append(new BC_ListBoxItem(track->title));
434 add_subwindow(track_list = new ExportEDLWindowTrackList(this, x, y, 400, 200, items_tracks));
436 y += 5 + track_list->get_h();
437 add_subwindow(new BC_Title(x, y, _("Currently only CMX 3600 format is supported")));
440 add_subwindow(new BC_OKButton(this));
441 add_subwindow(new BC_CancelButton(this));
446 ExportEDLPathText::ExportEDLPathText(int x, int y, ExportEDLWindow *window)
447 : BC_TextBox(x, y, 300, 1, window->exportasset->path)
449 this->window = window;
451 ExportEDLPathText::~ExportEDLPathText()
454 int ExportEDLPathText::handle_event()
456 strcpy(window->exportasset->path, get_text());
457 // window->handle_event();
461 ExportEDLWindowTrackList::ExportEDLWindowTrackList(ExportEDLWindow *window,
466 ArrayList<BC_ListBoxItem*> *track_list)
477 this->window = window;
480 int ExportEDLWindowTrackList::handle_event()
482 // window->exportasset->track_number = get_selection_number(0, 0);
483 // printf("aaaaa %i\n", window->exportasset->track_number );
484 // window->set_done(0);