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"
30 #include "filesystem.h"
33 #include "localsession.h"
34 #include "mainerror.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,
84 char *sourceinpoint, char *sourceoutpoint,
85 char *destinpoint, char *destoutpoint,
88 Track *track = edit->track;
89 double frame_rate = edit->track->edl->session->frame_rate;
91 double edit_sourcestart;
92 double edit_sourceend;
93 double edit_deststart;
96 strcpy(reel_name, " BL ");
98 edit_sourceend = track->from_units(edit->length);
100 edit_deststart = track->from_units(edit->startproject);
101 edit_destend = track->from_units(edit->startproject + edit->length);
103 double_to_CMX3600(edit_sourcestart, frame_rate, sourceinpoint);
104 double_to_CMX3600(edit_sourceend, frame_rate, sourceoutpoint);
105 double_to_CMX3600(edit_deststart, frame_rate, destinpoint);
106 double_to_CMX3600(edit_destend, frame_rate, destoutpoint);
112 void ExportEDLAsset::export_it()
115 fh = fopen(path, "w+");
117 eprintf("unable to open file: %s", path);
121 // We currently only support exporting one track at a time
125 for(track = edl->tracks->first;
129 if (serial == track_number)
135 int last_dissolve = 1;
137 if (edl_type == EDLTYPE_CMX3600)
140 // TODO: Find docs about exact header for CMX3600
141 fprintf(fh, "TITLE: Cinproj FORMAT: CMX 3600 4-Ch\n");
146 for (Edit *edit = track->edits->first;
150 char reel_name[BCTEXTLEN];
152 char edittype[5] = "C ";
153 char cutinfo[4] = " ";
154 char sourceinpoint[12];
155 char sourceoutpoint[12];
156 char destinpoint[12];
157 char destoutpoint[12];
158 if (track->data_type == TRACK_AUDIO)
159 strcpy(avselect, "A ");
161 strcpy(avselect, "V ");
163 //if (edit->transition)
164 // printf("title: %s, length: %i\n", edit->transition->title, edit->transition->length);
165 if (edit->transition && !strcmp(edit->transition->title, "Dissolve"))
167 char last_sourceout[12];
168 edit_to_timecodes(edit->previous, sourceinpoint, last_sourceout, destinpoint, destoutpoint, reel_name);
169 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
173 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
174 fprintf(fh, " %s %s", last_sourceout, last_sourceout);
175 fprintf(fh, " %s %s", destinpoint, destinpoint);
182 fprintf(fh, "%03d %8s %s %4s %03jd", colnum, reel_name, avselect, edittype, edit->transition->length);
183 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
184 fprintf(fh, " %s %s", destinpoint, destoutpoint);
189 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
190 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
191 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
192 fprintf(fh, " %s %s", destinpoint, destoutpoint);
210 int ExportEDLAsset::load_defaults()
212 mwindow->defaults->get("EDLEXPORT_PATH", path);
213 mwindow->defaults->get("EDLEXPORT_TYPE", edl_type);
214 mwindow->defaults->get("EDLEXPORT_TRACKNUMBER", track_number);
215 //load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOADMODE_NEW_TRACKS);
221 int ExportEDLAsset::save_defaults()
223 mwindow->defaults->update("EDLEXPORT_PATH", path);
224 mwindow->defaults->update("EDLEXPORT_TYPE", edl_type);
225 mwindow->defaults->update("EDLEXPORT_TRACKNUMBER", track_number);
232 ExportEDLItem::ExportEDLItem(MWindow *mwindow)
233 : BC_MenuItem(_("Export EDL..."), "Shift-E", 'E')
235 this->mwindow = mwindow;
239 int ExportEDLItem::handle_event()
241 mwindow->exportedl->start_interactive();
249 ExportEDL::ExportEDL(MWindow *mwindow)
252 this->mwindow = mwindow;
253 // package_lock = new Mutex("ExportEDL::package_lock");
254 // counter_lock = new Mutex("ExportEDL::counter_lock");
255 // completion = new Condition(0, "ExportEDL::completion");
256 // progress_timer = new Timer;
259 ExportEDL::~ExportEDL()
261 // delete package_lock;
262 // delete counter_lock;
263 // delete completion;
264 /// if(preferences) delete preferences;
265 // delete progress_timer;
268 void ExportEDL::start_interactive()
270 if(!Thread::running())
276 void ExportEDL::run()
279 exportasset = new ExportEDLAsset(mwindow, mwindow->edl);
281 exportasset->load_defaults();
283 // Get format from user
290 exportedl_window = new ExportEDLWindow(mwindow, this, exportasset);
291 exportedl_window->create_objects();
292 result = exportedl_window->run_window();
294 // add to recentlist only on OK
296 exportedl_window->path_recent->add_item("EDLPATH", exportasset->path);
298 exportasset->track_number = exportedl_window->track_list->get_selection_number(0, 0);
300 delete exportedl_window;
301 exportedl_window = 0;
304 ArrayList<char*> paths;
306 paths.append(exportasset->path);
307 filesok = ConfirmSave::test_files(mwindow, &paths);
310 } while (!result && filesok);
311 mwindow->save_defaults();
312 exportasset->save_defaults();
315 if(!result) exportasset->export_it();
322 #define WIDTH xS(410)
323 #define HEIGHT yS(400)
325 static const char *default_list_titles[] = {
330 static int default_list_widths[] = {
336 ExportEDLWindow::ExportEDLWindow(MWindow *mwindow, ExportEDL *exportedl, ExportEDLAsset *exportasset)
337 : BC_Window(_(PROGRAM_NAME ": Export EDL"),
338 mwindow->gui->get_screen_w(1, 0) / 2 - WIDTH / 2,
339 mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2,
340 WIDTH, HEIGHT, (int)BC_INFINITY, (int)BC_INFINITY, 0, 0, 1)
342 this->mwindow = mwindow;
343 this->exportasset = exportasset;
344 for( int i=0; i<2; ++i ) {
345 list_titles[i] = _(default_list_titles[i]);
346 list_widths[i] = xS(default_list_widths[i]);
350 ExportEDLWindow::~ExportEDLWindow()
352 // delete format_tools;
357 void ExportEDLWindow::create_objects()
360 int ys5 = yS(5), ys25 = yS(25);
361 lock_window("ExportEDLWindow::create_objects");
362 int x = xs5, y = ys5;
363 add_subwindow(new BC_Title(x, y,
364 _("Select a file to export to:")));
367 add_subwindow(path_textbox = new ExportEDLPathText(x, y, this));
369 path_recent = new BC_RecentList("EDLPATH", mwindow->defaults,
370 path_textbox, 10, x, y, xS(300), yS(100));
371 add_subwindow(path_recent);
373 path_recent->load_items("EDLPATH");
376 add_subwindow(path_button = new BrowseButton(
377 mwindow->theme, this, path_textbox, x, y - 4, exportasset->path,
378 _("Output to file"), _("Select a file to write to:"), 0));
382 add_subwindow(new BC_Title(x, y, _("Select track to be exported:")));
386 items_tracks[0].remove_all_objects();
387 items_tracks[1].remove_all_objects();
389 if (exportasset->track_number == -1)
390 exportasset->track_number = 0;
391 for(Track *track = mwindow->edl->tracks->first;
397 sprintf(tmp, "%i\n", serial+1);
399 BC_ListBoxItem *listitem = new BC_ListBoxItem(tmp);
400 if (serial == exportasset->track_number)
401 listitem->set_selected(1);
402 items_tracks[0].append(listitem);
403 items_tracks[1].append(new BC_ListBoxItem(track->title));
409 add_subwindow(track_list = new ExportEDLWindowTrackList(this, x, y, xS(400), yS(200)));
411 y += 5 + track_list->get_h();
412 add_subwindow(new BC_Title(x, y, _("Currently only CMX 3600 format is supported")));
415 add_subwindow(new BC_OKButton(this));
416 add_subwindow(new BC_CancelButton(this));
422 ExportEDLPathText::ExportEDLPathText(int x, int y, ExportEDLWindow *window)
423 : BC_TextBox(x, y, xS(300), 1, window->exportasset->path)
425 this->window = window;
427 ExportEDLPathText::~ExportEDLPathText()
430 int ExportEDLPathText::handle_event()
432 strcpy(window->exportasset->path, get_text());
433 // window->handle_event();
437 ExportEDLWindowTrackList::ExportEDLWindowTrackList(ExportEDLWindow *window,
438 int x, int y, int w, int h)
439 : BC_ListBox(x, y, w, h, LISTBOX_TEXT,
440 window->items_tracks,
445 this->window = window;
448 int ExportEDLWindowTrackList::handle_event()
450 // window->exportasset->track_number = get_selection_number(0, 0);
451 // printf("aaaaa %i\n", window->exportasset->track_number );
452 // window->set_done(0);