#include "ardour/export_handler.h"
-#include <glib/gstdio.h>
+#include <pbd/gstdio_compat.h>
#include <glibmm.h>
#include <glibmm/convert.h>
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 */
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());
}
#if 0 // would be nicer with C++11 initialiser...
std::map<char, std::string> 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<char, std::string> subs;
subs.insert (std::pair<char, std::string> ('f', filename));
- subs.insert (std::pair<char, std::string> ('d', Glib::path_get_dirname(filename)));
- subs.insert (std::pair<char, std::string> ('b', PBD::basename_nosuffix(filename)));
- subs.insert (std::pair<char, std::string> ('u', soundcloud_username));
- subs.insert (std::pair<char, std::string> ('p', soundcloud_password));
-
+ subs.insert (std::pair<char, std::string> ('d', Glib::path_get_dirname (filename) + G_DIR_SEPARATOR));
+ subs.insert (std::pair<char, std::string> ('b', PBD::basename_nosuffix (filename)));
+ subs.insert (std::pair<char, std::string> ('s', session.path ()));
+ subs.insert (std::pair<char, std::string> ('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);
}
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;
}
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;
}
/* 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) {
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();
}
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
}
}
{
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),
{
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
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)
{
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)
{
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)
{