00001 #include "asset.h"
00002 #include "bchash.h"
00003 #include "condition.h"
00004 #include "confirmsave.h"
00005 #include "edits.h"
00006 #include "edl.h"
00007 #include "edlsession.h"
00008 #include "errorbox.h"
00009 #include "file.h"
00010 #include "filesystem.h"
00011 #include "filexml.h"
00012 #include "language.h"
00013 #include "localsession.h"
00014 #include "mainsession.h"
00015 #include "mutex.h"
00016 #include "mwindowgui.h"
00017 #include "mwindow.h"
00018 #include "exportedl.h"
00019 #include "tracks.h"
00020 #include "transition.h"
00021
00022 #include <libintl.h>
00023 #define _(String) gettext(String)
00024 #define gettext_noop(String) String
00025 #define N_(String) gettext_noop (String)
00026
00027
00028
00029 #include <ctype.h>
00030 #include <string.h>
00031
00032 ExportEDLAsset::ExportEDLAsset(MWindow *mwindow, EDL *edl)
00033 {
00034 this->mwindow = mwindow;
00035 this->edl = edl;
00036
00037 path[0] = 0;
00038 edl_type = EDLTYPE_CMX3600;
00039 track_number = -1;
00040 }
00041
00042 ExportEDLAsset::~ExportEDLAsset()
00043 {
00044 }
00045
00046 void ExportEDLAsset::double_to_CMX3600(double seconds, double frame_rate, char *str)
00047 {
00048 char tmp[20];
00049 Units::totext(tmp,
00050 seconds,
00051 TIME_HMSF,
00052 0,
00053 frame_rate,
00054 0);
00055 if ((int)(seconds / 3600) <= 9)
00056 {
00057 str[0]='0';
00058 strcpy(str+1, tmp);
00059 } else
00060 {
00061 strcpy(str, tmp);
00062 }
00063
00064
00065
00066
00067 }
00068
00069 int ExportEDLAsset::edit_to_timecodes(Edit *edit, char *sourceinpoint, char *sourceoutpoint, char *destinpoint, char *destoutpoint, char *reel_name)
00070 {
00071 Asset *asset = edit->asset;
00072 Track *track = edit->track;
00073 double frame_rate = edit->track->edl->session->frame_rate;
00074
00075 double edit_sourcestart;
00076 double edit_sourceend;
00077 double edit_deststart;
00078 double edit_destend;
00079
00080 if (asset)
00081 {
00082
00083
00084 strncpy(reel_name, asset->reel_name, 9);
00085 if (strlen(asset->reel_name) > 8)
00086 {
00087 printf(_("Warning: chopping the reel name to eight characters!\n"));
00088 };
00089 reel_name[8] = 0;
00090 for (int i = strlen(reel_name); i<8; i++)
00091 reel_name[i] = ' ';
00092
00093 edit_sourcestart = (double)asset->tcstart / asset->frame_rate
00094 + track->from_units(edit->startsource);
00095 edit_sourceend = (double)asset->tcstart / asset->frame_rate
00096 + track->from_units(edit->startsource + edit->length);
00097
00098 } else
00099 {
00100 strcpy(reel_name, " BL ");
00101 edit_sourcestart = 0;
00102 edit_sourceend = track->from_units(edit->length);
00103 }
00104
00105 edit_deststart = track->from_units(edit->startproject);
00106 edit_destend = track->from_units(edit->startproject + edit->length);
00107
00108 double_to_CMX3600(edit_sourcestart, frame_rate, sourceinpoint);
00109 double_to_CMX3600(edit_sourceend, frame_rate, sourceoutpoint);
00110 double_to_CMX3600(edit_deststart, frame_rate, destinpoint);
00111 double_to_CMX3600(edit_destend, frame_rate, destoutpoint);
00112
00113 return 0;
00114 }
00115
00116
00117 int ExportEDLAsset::export_it()
00118 {
00119 FILE *fh;
00120 fh = fopen(path, "w+");
00121
00122
00123
00124 int serial = 0;
00125 Track *track;
00126 for(track = edl->tracks->first;
00127 track;
00128 track = track->next)
00129 {
00130 if (serial == track_number)
00131 break;
00132 serial ++;
00133 }
00134
00135
00136 int last_dissolve = 1;
00137
00138 if (edl_type == EDLTYPE_CMX3600)
00139 {
00140
00141
00142 fprintf(fh, "TITLE: Cinproj FORMAT: CMX 3600 4-Ch\n");
00143
00144 int colnum = 1;
00145
00146
00147 for (Edit *edit = track->edits->first;
00148 edit;
00149 edit = edit->next)
00150 {
00151 char reel_name[BCTEXTLEN];
00152 char avselect[5];
00153 char edittype[5] = "C ";
00154 char cutinfo[4] = " ";
00155 char sourceinpoint[12];
00156 char sourceoutpoint[12];
00157 char destinpoint[12];
00158 char destoutpoint[12];
00159 if (track->data_type == TRACK_AUDIO)
00160 strcpy(avselect, "A ");
00161 else
00162 strcpy(avselect, "V ");
00163
00164
00165
00166 if (edit->transition && !strcmp(edit->transition->title, "Dissolve"))
00167 {
00168 char last_sourceout[12];
00169 edit_to_timecodes(edit->previous, sourceinpoint, last_sourceout, destinpoint, destoutpoint, reel_name);
00170 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
00171
00172 if (last_dissolve)
00173 {
00174 fprintf(fh, "%03d %8s %s %4s %03s", colnum, reel_name, avselect, edittype, cutinfo);
00175 fprintf(fh, " %s %s", last_sourceout, last_sourceout);
00176 fprintf(fh, " %s %s", destinpoint, destinpoint);
00177 fprintf(fh,"\n");
00178 } else
00179 {
00180 colnum --;
00181 }
00182 edittype[0] = 'D';
00183 fprintf(fh, "%03d %8s %s %4s %03d", colnum, reel_name, avselect, edittype, edit->transition->length);
00184 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
00185 fprintf(fh, " %s %s", destinpoint, destoutpoint);
00186 fprintf(fh,"\n");
00187 last_dissolve = 1;
00188 } else
00189 {
00190 edit_to_timecodes(edit, sourceinpoint, sourceoutpoint, destinpoint, destoutpoint, reel_name);
00191 fprintf(fh, "%03d %8s %s %4s %3s", colnum, reel_name, avselect, edittype, cutinfo);
00192 fprintf(fh, " %s %s", sourceinpoint, sourceoutpoint);
00193 fprintf(fh, " %s %s", destinpoint, destoutpoint);
00194 fprintf(fh,"\n");
00195 last_dissolve = 0;
00196 }
00197
00198 colnum ++;
00199
00200 }
00201
00202 }
00203
00204 fclose(fh);
00205
00206
00207 }
00208
00209
00210
00211 int ExportEDLAsset::load_defaults()
00212 {
00213 mwindow->defaults->get("EDLEXPORT_PATH", path);
00214 mwindow->defaults->get("EDLEXPORT_TYPE", edl_type);
00215 mwindow->defaults->get("EDLEXPORT_TRACKNUMBER", track_number);
00216
00217
00218
00219 return 0;
00220 }
00221
00222 int ExportEDLAsset::save_defaults()
00223 {
00224 mwindow->defaults->update("EDLEXPORT_PATH", path);
00225 mwindow->defaults->update("EDLEXPORT_TYPE", edl_type);
00226 mwindow->defaults->update("EDLEXPORT_TRACKNUMBER", track_number);
00227 return 0;
00228 }
00229
00230
00231
00232
00233 ExportEDLItem::ExportEDLItem(MWindow *mwindow)
00234 : BC_MenuItem(_("Export EDL..."), "Shift+E", 'E')
00235 {
00236 this->mwindow = mwindow;
00237 set_shift(1);
00238 }
00239
00240 int ExportEDLItem::handle_event()
00241 {
00242 mwindow->exportedl->start_interactive();
00243 return 1;
00244 }
00245
00246
00247
00248
00249
00250 ExportEDL::ExportEDL(MWindow *mwindow)
00251 : Thread(0, 0, 0)
00252 {
00253 this->mwindow = mwindow;
00254
00255
00256
00257
00258 }
00259
00260 ExportEDL::~ExportEDL()
00261 {
00262
00263
00264
00266
00267 }
00268
00269 void ExportEDL::start_interactive()
00270 {
00271 if(!Thread::running())
00272 {
00273 Thread::start();
00274 }
00275 }
00276
00277 void ExportEDL::run()
00278 {
00279 int result = 0;
00280 exportasset = new ExportEDLAsset(mwindow, mwindow->edl);
00281
00282 exportasset->load_defaults();
00283
00284
00285 result = 0;
00286 int filesok;
00287
00288 do {
00289
00290 filesok = 0;
00291 exportedl_window = new ExportEDLWindow(mwindow, this, exportasset);
00292 exportedl_window->create_objects();
00293 result = exportedl_window->run_window();
00294 if (! result) {
00295
00296
00297 exportedl_window->path_recent->add_item("EDLPATH", exportasset->path);
00298 }
00299 exportasset->track_number = exportedl_window->track_list->get_selection_number(0, 0);
00300
00301 delete exportedl_window;
00302 exportedl_window = 0;
00303 if (!result)
00304 {
00305 ArrayList<char*> paths;
00306
00307 paths.append(exportasset->path);
00308 filesok = ConfirmSave::test_files(mwindow, &paths);
00309 }
00310
00311 } while (!result && filesok);
00312 mwindow->save_defaults();
00313 exportasset->save_defaults();
00314
00315
00316 if(!result) exportasset->export_it();
00317
00318
00319 delete exportasset;
00320
00321 }
00322
00323
00324
00325
00326
00327
00328
00329
00330 #define WIDTH 410
00331 #define HEIGHT 400
00332
00333 static char *list_titles[] =
00334 {
00335 N_("No."),
00336 N_("Track name")
00337 };
00338
00339
00340 static int list_widths[] =
00341 {
00342 40,
00343 200
00344 };
00345
00346 ExportEDLWindow::ExportEDLWindow(MWindow *mwindow, ExportEDL *exportedl, ExportEDLAsset *exportasset)
00347 : BC_Window(PROGRAM_NAME ": Export EDL",
00348 mwindow->gui->get_root_w(0, 1) / 2 - WIDTH / 2,
00349 mwindow->gui->get_root_h(1) / 2 - HEIGHT / 2,
00350 WIDTH,
00351 HEIGHT,
00352 (int)BC_INFINITY,
00353 (int)BC_INFINITY,
00354 0,
00355 0,
00356 1)
00357 {
00358 this->mwindow = mwindow;
00359 this->exportasset = exportasset;
00360 }
00361
00362 ExportEDLWindow::~ExportEDLWindow()
00363 {
00364
00365
00366 }
00367
00368
00369
00370 int ExportEDLWindow::create_objects()
00371 {
00372 int x = 5, y = 5;
00373 add_subwindow(new BC_Title(x,
00374 y,
00375 _("Select a file to export to:")));
00376 y += 25;
00377
00378 add_subwindow(path_textbox = new ExportEDLPathText(x, y, this));
00379 x += 300;
00380 path_recent = new BC_RecentList("EDLPATH", mwindow->defaults,
00381 path_textbox, 10, x, y, 300, 100);
00382 add_subwindow(path_recent);
00383
00384 path_recent->load_items("EDLPATH");
00385
00386 x += 24;
00387 add_subwindow(path_button = new BrowseButton(
00388 mwindow,
00389 this,
00390 path_textbox,
00391 x,
00392 y - 4,
00393 exportasset->path,
00394 _("Output to file"),
00395 _("Select a file to write to:"),
00396 0));
00397
00398 y += 34;
00399 x = 5;
00400 add_subwindow(new BC_Title(x, y, _("Select track to be exported:")));
00401 y += 25;
00402
00403
00404 items_tracks[0].remove_all_objects();
00405 items_tracks[1].remove_all_objects();
00406 int serial = 0;
00407 if (exportasset->track_number == -1)
00408 exportasset->track_number = 0;
00409 for(Track *track = mwindow->edl->tracks->first;
00410 track;
00411 track = track->next)
00412 {
00413
00414 char tmp[10];
00415 sprintf(tmp, "%i\n", serial+1);
00416
00417 BC_ListBoxItem *listitem = new BC_ListBoxItem(tmp);
00418 if (serial == exportasset->track_number)
00419 listitem->set_selected(1);
00420 items_tracks[0].append(listitem);
00421 items_tracks[1].append(new BC_ListBoxItem(track->title));
00422 serial ++;
00423
00424 }
00425
00426
00427 add_subwindow(track_list = new ExportEDLWindowTrackList(this, x, y, 400, 200, items_tracks));
00428
00429 y += 5 + track_list->get_h();
00430 add_subwindow(new BC_Title(x, y, _("Currently only CMX 3600 format is supported")));
00431
00432
00433 add_subwindow(new BC_OKButton(this));
00434 add_subwindow(new BC_CancelButton(this));
00435 show_window();
00436 return 0;
00437 }
00438
00439
00440 ExportEDLPathText::ExportEDLPathText(int x, int y, ExportEDLWindow *window)
00441 : BC_TextBox(x, y, 300, 1, window->exportasset->path)
00442 {
00443 this->window = window;
00444 }
00445 ExportEDLPathText::~ExportEDLPathText()
00446 {
00447 }
00448 int ExportEDLPathText::handle_event()
00449 {
00450 strcpy(window->exportasset->path, get_text());
00451
00452 }
00453
00454 ExportEDLWindowTrackList::ExportEDLWindowTrackList(ExportEDLWindow *window,
00455 int x,
00456 int y,
00457 int w,
00458 int h,
00459 ArrayList<BC_ListBoxItem*> *track_list)
00460 : BC_ListBox(x,
00461 y,
00462 w,
00463 h,
00464 LISTBOX_TEXT,
00465 track_list,
00466 list_titles,
00467 list_widths,
00468 2)
00469 {
00470 this->window = window;
00471 }
00472
00473 int ExportEDLWindowTrackList::handle_event()
00474 {
00475
00476
00477
00478 }
00479
00480
00481