X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Fexport_handler.cc;h=ec89f270ca832534d212b04ab0f01c9fa872e100;hb=21ea94c000bb30b7da111930aa4095b87f390cdd;hp=20abc80de1995866ff8befb89228d04bd1e83845;hpb=e279b9892b467aa823e253d97b6e9504cca0e252;p=ardour.git diff --git a/libs/ardour/export_handler.cc b/libs/ardour/export_handler.cc index 20abc80de1..ec89f270ca 100644 --- a/libs/ardour/export_handler.cc +++ b/libs/ardour/export_handler.cc @@ -27,12 +27,17 @@ #include "pbd/convert.h" #include "ardour/audiofile_tagger.h" +#include "ardour/debug.h" #include "ardour/export_graph_builder.h" #include "ardour/export_timespan.h" #include "ardour/export_channel_configuration.h" #include "ardour/export_status.h" #include "ardour/export_format_specification.h" #include "ardour/export_filename.h" +#include "ardour/soundcloud_upload.h" +#include "ardour/system_exec.h" +#include "pbd/openuri.h" +#include "pbd/basename.h" #include "ardour/session_metadata.h" #include "i18n.h" @@ -277,6 +282,13 @@ ExportHandler::process_normalize () return 0; } +void +ExportHandler::command_output(std::string output, size_t size) +{ + std::cerr << "command: " << size << ", " << output << std::endl; + info << output << endmsg; +} + void ExportHandler::finish_timespan () { @@ -297,13 +309,71 @@ ExportHandler::finish_timespan () AudiofileTagger::tag_file(filename, *SessionMetadata::Metadata()); } + if (!fmt->command().empty()) { + +#if 0 // would be nicer with C++11 initialiser... + std::map subs { + { 'f', filename }, + { 'd', Glib::path_get_dirname(filename) + G_DIR_SEPARATOR }, + { 'b', PBD::basename_nosuffix(filename) }, + ... + }; +#endif + + PBD::ScopedConnection command_connection; + std::map subs; + subs.insert (std::pair ('f', filename)); + 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 ())); + + 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 + while (se->is_running ()) { + // wait for system exec to terminate + Glib::usleep (1000); + } + } else { + error << "post-export hook failed! " << fmt->command() << endmsg; + } + delete (se); + } + + if (fmt->soundcloud_upload()) { + SoundcloudUploader *soundcloud_uploader = new SoundcloudUploader; + std::string token = soundcloud_uploader->Get_Auth_Token(soundcloud_username, soundcloud_password); + DEBUG_TRACE (DEBUG::Soundcloud, string_compose( + "uploading %1 - username=%2, password=%3, token=%4", + filename, soundcloud_username, soundcloud_password, token) ); + std::string path = soundcloud_uploader->Upload ( + filename, + PBD::basename_nosuffix(filename), // title + token, + soundcloud_make_public, + soundcloud_downloadable, + this); + + if (path.length() != 0) { + info << string_compose ( _("File %1 uploaded to %2"), filename, path) << endmsg; + if (soundcloud_open_page) { + DEBUG_TRACE (DEBUG::Soundcloud, string_compose ("opening %1", path) ); + 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; + } + delete soundcloud_uploader; + } config_map.erase (config_map.begin()); } start_timespan (); } -/*** CD Marker sutff ***/ +/*** CD Marker stuff ***/ struct LocationSortByStart { bool operator() (Location *a, Location *b) {