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,
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 // We currently only support exporting one track at a time
121 for(track = edl->tracks->first;
125 if (serial == track_number)
131 int last_dissolve = 1;
133 if (edl_type == EDLTYPE_CMX3600)
136 // TODO: Find docs about exact header for CMX3600
137 fprintf(fh, "TITLE: Cinproj FORMAT: CMX 3600 4-Ch\n");
142 for (Edit *edit = track->edits->first;
146 char reel_name[BCTEXTLEN];
148 char edittype[5] = "C ";
149 char cutinfo[4] = " ";
150 char sourceinpoint[12];
151 char sourceoutpoint[12];
152 char destinpoint[12];
153 char destoutpoint[12];
154 if (track->data_type == TRACK_AUDIO)
155 strcpy(avselect, "A ");
157 strcpy(avselect, "V ");
159 //if (edit->transition)
160 // printf("title: %s, length: %i\n", edit->transition->title, edit->transition->length);
161 if (edit->transition && !strcmp(edit->transition->title, "Dissolve"))
163 char last_sourceout[12];
164 edit_to_timecodes(edit->previous, sourceinpoint, last_sourceout, destinpoint, destoutpoint, reel_name);
165 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
169 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
170 fprintf(fh, " %s %s", last_sourceout, last_sourceout);
171 fprintf(fh, " %s %s", destinpoint, destinpoint);
178 fprintf(fh, "%03d %8s %s %4s %03jd", colnum, reel_name, avselect, edittype, edit->transition->length);
179 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
180 fprintf(fh, " %s %s", destinpoint, destoutpoint);
185 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
186 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
187 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
188 fprintf(fh, " %s %s", destinpoint, destoutpoint);
206 int ExportEDLAsset::load_defaults()
208 mwindow->defaults->get("EDLEXPORT_PATH", path);
209 mwindow->defaults->get("EDLEXPORT_TYPE", edl_type);
210 mwindow->defaults->get("EDLEXPORT_TRACKNUMBER", track_number);
211 //load_mode = mwindow->defaults->get("RENDER_LOADMODE", LOADMODE_NEW_TRACKS);
217 int ExportEDLAsset::save_defaults()
219 mwindow->defaults->update("EDLEXPORT_PATH", path);
220 mwindow->defaults->update("EDLEXPORT_TYPE", edl_type);
221 mwindow->defaults->update("EDLEXPORT_TRACKNUMBER", track_number);
228 ExportEDLItem::ExportEDLItem(MWindow *mwindow)
229 : BC_MenuItem(_("Export EDL..."), "Shift-E", 'E')
231 this->mwindow = mwindow;
235 int ExportEDLItem::handle_event()
237 mwindow->exportedl->start_interactive();
245 ExportEDL::ExportEDL(MWindow *mwindow)
248 this->mwindow = mwindow;
249 // package_lock = new Mutex("ExportEDL::package_lock");
250 // counter_lock = new Mutex("ExportEDL::counter_lock");
251 // completion = new Condition(0, "ExportEDL::completion");
252 // progress_timer = new Timer;
255 ExportEDL::~ExportEDL()
257 // delete package_lock;
258 // delete counter_lock;
259 // delete completion;
260 /// if(preferences) delete preferences;
261 // delete progress_timer;
264 void ExportEDL::start_interactive()
266 if(!Thread::running())
272 void ExportEDL::run()
275 exportasset = new ExportEDLAsset(mwindow, mwindow->edl);
277 exportasset->load_defaults();
279 // Get format from user
286 exportedl_window = new ExportEDLWindow(mwindow, this, exportasset);
287 exportedl_window->create_objects();
288 result = exportedl_window->run_window();
290 // add to recentlist only on OK
292 exportedl_window->path_recent->add_item("EDLPATH", exportasset->path);
294 exportasset->track_number = exportedl_window->track_list->get_selection_number(0, 0);
296 delete exportedl_window;
297 exportedl_window = 0;
300 ArrayList<char*> paths;
302 paths.append(exportasset->path);
303 filesok = ConfirmSave::test_files(mwindow, &paths);
306 } while (!result && filesok);
307 mwindow->save_defaults();
308 exportasset->save_defaults();
311 if(!result) exportasset->export_it();
328 static const char *list_titles[] =
335 static int list_widths[] =
341 ExportEDLWindow::ExportEDLWindow(MWindow *mwindow, ExportEDL *exportedl, ExportEDLAsset *exportasset)
342 : BC_Window(_(PROGRAM_NAME ": Export EDL"),
343 mwindow->gui->get_screen_w(1, 0) / 2 - WIDTH / 2,
344 mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2,
353 this->mwindow = mwindow;
354 this->exportasset = exportasset;
357 ExportEDLWindow::~ExportEDLWindow()
359 // delete format_tools;
365 void ExportEDLWindow::create_objects()
368 add_subwindow(new BC_Title(x, y,
369 _("Select a file to export to:")));
372 add_subwindow(path_textbox = new ExportEDLPathText(x, y, this));
374 path_recent = new BC_RecentList("EDLPATH", mwindow->defaults,
375 path_textbox, 10, x, y, 300, 100);
376 add_subwindow(path_recent);
378 path_recent->load_items("EDLPATH");
381 add_subwindow(path_button = new BrowseButton(
382 mwindow->theme, this, path_textbox, x, y - 4, exportasset->path,
383 _("Output to file"), _("Select a file to write to:"), 0));
387 add_subwindow(new BC_Title(x, y, _("Select track to be exported:")));
391 items_tracks[0].remove_all_objects();
392 items_tracks[1].remove_all_objects();
394 if (exportasset->track_number == -1)
395 exportasset->track_number = 0;
396 for(Track *track = mwindow->edl->tracks->first;
402 sprintf(tmp, "%i\n", serial+1);
404 BC_ListBoxItem *listitem = new BC_ListBoxItem(tmp);
405 if (serial == exportasset->track_number)
406 listitem->set_selected(1);
407 items_tracks[0].append(listitem);
408 items_tracks[1].append(new BC_ListBoxItem(track->title));
414 add_subwindow(track_list = new ExportEDLWindowTrackList(this, x, y, 400, 200, items_tracks));
416 y += 5 + track_list->get_h();
417 add_subwindow(new BC_Title(x, y, _("Currently only CMX 3600 format is supported")));
420 add_subwindow(new BC_OKButton(this));
421 add_subwindow(new BC_CancelButton(this));
426 ExportEDLPathText::ExportEDLPathText(int x, int y, ExportEDLWindow *window)
427 : BC_TextBox(x, y, 300, 1, window->exportasset->path)
429 this->window = window;
431 ExportEDLPathText::~ExportEDLPathText()
434 int ExportEDLPathText::handle_event()
436 strcpy(window->exportasset->path, get_text());
437 // window->handle_event();
441 ExportEDLWindowTrackList::ExportEDLWindowTrackList(ExportEDLWindow *window,
446 ArrayList<BC_ListBoxItem*> *track_list)
457 this->window = window;
460 int ExportEDLWindowTrackList::handle_event()
462 // window->exportasset->track_number = get_selection_number(0, 0);
463 // printf("aaaaa %i\n", window->exportasset->track_number );
464 // window->set_done(0);