X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fexport_handler.cc;h=0def821ef623b5bb874268a74c40098cf96b9940;hb=7ac691ec821c1986282ba9e25b3890dcf07e3e51;hp=89e4d96955f58b222d08cabf4fa3c8650be23349;hpb=8c9749e42faf7808034ed8b7afce4a2fe6dc6f33;p=ardour.git diff --git a/libs/ardour/export_handler.cc b/libs/ardour/export_handler.cc index 89e4d96955..0def821ef6 100644 --- a/libs/ardour/export_handler.cc +++ b/libs/ardour/export_handler.cc @@ -20,7 +20,7 @@ #include "ardour/export_handler.h" -#include +#include #include #include @@ -118,7 +118,7 @@ ExportHandler::ExportHandler (Session & session) ExportHandler::~ExportHandler () { - // TODO remove files that were written but not finished + graph_builder->cleanup (export_status->aborted () ); } /** Add an export to the `to-do' list */ @@ -305,7 +305,18 @@ ExportHandler::finish_timespan () export_cd_marker_file (current_timespan, fmt, filename, CDMarkerTOC); } + if (fmt->with_mp4chaps()) { + export_cd_marker_file (current_timespan, fmt, filename, MP4Chaps); + } + if (fmt->tag()) { + /* close file first, otherwise TagLib enounters an ERROR_SHARING_VIOLATION + * The process cannot access the file because it is being used. + * + * TODO: check Umlauts and encoding in filename. + * TagLib eventually calls CreateFileA(), + */ + graph_builder->reset (); AudiofileTagger::tag_file(filename, *SessionMetadata::Metadata()); } @@ -314,35 +325,31 @@ ExportHandler::finish_timespan () #if 0 // would be nicer with C++11 initialiser... std::map subs { { 'f', filename }, - { 'd', Glib::path_get_dirname(filename) }, + { 'd', Glib::path_get_dirname(filename) + G_DIR_SEPARATOR }, { 'b', PBD::basename_nosuffix(filename) }, - { 'u', upload_username }, - { 'p', upload_password} + ... }; #endif PBD::ScopedConnection command_connection; std::map subs; subs.insert (std::pair ('f', filename)); - subs.insert (std::pair ('d', Glib::path_get_dirname(filename))); - subs.insert (std::pair ('b', PBD::basename_nosuffix(filename))); - subs.insert (std::pair ('u', soundcloud_username)); - subs.insert (std::pair ('p', soundcloud_password)); - + subs.insert (std::pair ('d', Glib::path_get_dirname (filename) + G_DIR_SEPARATOR)); + subs.insert (std::pair ('b', PBD::basename_nosuffix (filename))); + subs.insert (std::pair ('s', session.path ())); + subs.insert (std::pair ('n', session.name ())); - std::cerr << "running command: " << fmt->command() << "..." << std::endl; ARDOUR::SystemExec *se = new ARDOUR::SystemExec(fmt->command(), subs); se->ReadStdout.connect_same_thread(command_connection, boost::bind(&ExportHandler::command_output, this, _1, _2)); if (se->start (2) == 0) { // successfully started - std::cerr << "started!" << std::endl; while (se->is_running ()) { // wait for system exec to terminate - // std::cerr << "waiting..." << std::endl; Glib::usleep (1000); } + } else { + error << "post-export hook failed! " << fmt->command() << endmsg; } - std::cerr << "done! deleting..." << std::endl; delete (se); } @@ -367,7 +374,7 @@ ExportHandler::finish_timespan () open_uri(path.c_str()); // open the soundcloud website to the new file } } else { - error << _("upload to Soundcloud failed. Perhaps your email or password are incorrect?\n") << endmsg; + error << _("upload to Soundcloud failed. Perhaps your email or password are incorrect?\n") << endmsg; } delete soundcloud_uploader; } @@ -407,6 +414,11 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp track_func = &ExportHandler::write_track_info_cue; index_func = &ExportHandler::write_index_info_cue; break; + case MP4Chaps: + header_func = &ExportHandler::write_mp4ch_header; + track_func = &ExportHandler::write_track_info_mp4ch; + index_func = &ExportHandler::write_index_info_mp4ch; + break; default: return; } @@ -443,8 +455,8 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp /* Start actual marker stuff */ - framepos_t last_end_time = timespan->get_start(), last_start_time = timespan->get_start(); - status.track_position = last_start_time - timespan->get_start(); + framepos_t last_end_time = timespan->get_start(); + status.track_position = 0; for (i = temp.begin(); i != temp.end(); ++i) { @@ -475,20 +487,17 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp if (nexti != temp.end()) { status.track_duration = (*nexti)->start() - last_end_time; - last_start_time = (*i)->start(); last_end_time = (*nexti)->start(); } else { // this was the last marker, use timespan end status.track_duration = timespan->get_end() - last_end_time; - last_start_time = (*i)->start(); last_end_time = timespan->get_end(); } } else { // range status.track_duration = (*i)->end() - last_end_time; - last_start_time = (*i)->start(); last_end_time = (*i)->end(); } @@ -507,17 +516,22 @@ ExportHandler::export_cd_marker_file (ExportTimespanPtr timespan, ExportFormatSp string ExportHandler::get_cd_marker_filename(std::string filename, CDMarkerFormat format) { - /* do not strip file suffix because there may be more than one format, + /* do not strip file suffix because there may be more than one format, and we do not want the CD marker file from one format to overwrite another (e.g. foo.wav.cue > foo.aiff.cue) */ switch (format) { - case CDMarkerTOC: + case CDMarkerTOC: return filename + ".toc"; - case CDMarkerCUE: + case CDMarkerCUE: return filename + ".cue"; - default: + case MP4Chaps: + { + unsigned lastdot = filename.find_last_of('.'); + return filename.substr(0,lastdot) + ".chapters.txt"; + } + default: return filename + ".marker"; // Should not be reached when actually creating a file } } @@ -527,10 +541,25 @@ ExportHandler::write_cue_header (CDMarkerStatus & status) { string title = status.timespan->name().compare ("Session") ? status.timespan->name() : (string) session.name(); + // Album metadata + string barcode = SessionMetadata::Metadata()->barcode(); + string album_artist = SessionMetadata::Metadata()->album_artist(); + string album_title = SessionMetadata::Metadata()->album(); + status.out << "REM Cue file generated by " << PROGRAM_NAME << endl; + + if (barcode != "") + status.out << "CATALOG " << barcode << endl; + + if (album_artist != "") + status.out << "PERFORMER " << cue_escape_cdtext (album_artist) << endl; + + if (album_title != "") + title = album_title; + status.out << "TITLE " << cue_escape_cdtext (title) << endl; - /* The original cue sheet sepc metions five file types + /* The original cue sheet spec mentions five file types WAVE, AIFF, BINARY = "header-less" audio (44.1 kHz, 16 Bit, little endian), MOTOROLA = "header-less" audio (44.1 kHz, 16 Bit, big endian), @@ -563,10 +592,28 @@ ExportHandler::write_toc_header (CDMarkerStatus & status) { string title = status.timespan->name().compare ("Session") ? status.timespan->name() : (string) session.name(); + // Album metadata + string barcode = SessionMetadata::Metadata()->barcode(); + string album_artist = SessionMetadata::Metadata()->album_artist(); + string album_title = SessionMetadata::Metadata()->album(); + + if (barcode != "") + status.out << "CATALOG \"" << barcode << "\"" << endl; + + if (album_title != "") + title = album_title; + status.out << "CD_DA" << endl; status.out << "CD_TEXT {" << endl << " LANGUAGE_MAP {" << endl << " 0 : EN" << endl << " }" << endl; status.out << " LANGUAGE 0 {" << endl << " TITLE " << toc_escape_cdtext (title) << endl ; - status.out << " PERFORMER \"\"" << endl << " }" << endl << "}" << endl; + status.out << " PERFORMER " << toc_escape_cdtext (album_artist) << endl; + status.out << " }" << endl << "}" << endl; +} + +void +ExportHandler::write_mp4ch_header (CDMarkerStatus & status) +{ + status.out << "00:00:00.000 Intro" << endl; } void @@ -673,6 +720,14 @@ ExportHandler::write_track_info_toc (CDMarkerStatus & status) status.out << "START" << buf << endl; } +void ExportHandler::write_track_info_mp4ch (CDMarkerStatus & status) +{ + gchar buf[18]; + + frames_to_chapter_marks_string(buf, status.track_start_frame); + status.out << buf << " " << status.marker->name() << endl; +} + void ExportHandler::write_index_info_cue (CDMarkerStatus & status) { @@ -695,6 +750,11 @@ ExportHandler::write_index_info_toc (CDMarkerStatus & status) status.out << "INDEX" << buf << endl; } +void +ExportHandler::write_index_info_mp4ch (CDMarkerStatus & status) +{ +} + void ExportHandler::frames_to_cd_frames_string (char* buf, framepos_t when) { @@ -710,6 +770,23 @@ ExportHandler::frames_to_cd_frames_string (char* buf, framepos_t when) sprintf (buf, " %02d:%02d:%02d", mins, secs, frames); } +void +ExportHandler::frames_to_chapter_marks_string (char* buf, framepos_t when) +{ + framecnt_t remainder; + framecnt_t fr = session.nominal_frame_rate(); + int hours, mins, secs, msecs; + + hours = when / (3600 * fr); + remainder = when - (hours * 3600 * fr); + mins = remainder / (60 * fr); + remainder -= mins * 60 * fr; + secs = remainder / fr; + remainder -= secs * fr; + msecs = (remainder * 1000) / fr; + sprintf (buf, "%02d:%02d:%02d.%03d", hours, mins, secs, msecs); +} + std::string ExportHandler::toc_escape_cdtext (const std::string& txt) {