From c2bdb00b0c595375d4c38e1a24bd680c73a61805 Mon Sep 17 00:00:00 2001 From: Colin Fletcher Date: Thu, 10 Oct 2013 19:54:22 +0100 Subject: [PATCH] Use SystemExec for post-export hook Use the new command-line parsing constructor for SystemExec to construct the args array for the post-export hook from the entered command string, with some simple substitutions for filename, directory, &c. Conflicts: gtk2_ardour/export_format_dialog.cc libs/ardour/export_handler.cc --- libs/ardour/ardour/export_handler.h | 2 ++ libs/ardour/export_handler.cc | 32 +++++++++++++++++++---------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/libs/ardour/ardour/export_handler.h b/libs/ardour/ardour/export_handler.h index f4c533f0f7..8336cea732 100644 --- a/libs/ardour/ardour/export_handler.h +++ b/libs/ardour/ardour/export_handler.h @@ -96,6 +96,8 @@ class LIBARDOUR_API ExportHandler : public ExportElementFactory, public sigc::tr friend boost::shared_ptr Session::get_export_handler(); ExportHandler (Session & session); + void command_output(std::string output, size_t size); + public: ~ExportHandler (); diff --git a/libs/ardour/export_handler.cc b/libs/ardour/export_handler.cc index e084aa9506..7c5399a7ae 100644 --- a/libs/ardour/export_handler.cc +++ b/libs/ardour/export_handler.cc @@ -38,8 +38,9 @@ #include "ardour/export_filename.h" #include "ardour/session_metadata.h" #include "ardour/soundcloud_upload.h" -#include "ardour/system_exec.h" -#include "ardour/session_metadata.h" +#include "pbd/openuri.h" +#include "pbd/basename.h" +#include "pbd/system_exec.h" #include "i18n.h" @@ -283,6 +284,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 () { @@ -307,9 +315,9 @@ ExportHandler::finish_timespan () #if 0 // would be nicer with C++11 initialiser... std::map subs { - { 'f', filename }, - { 'd', Glib::path_get_dirname(filename) }, - { 'b', PBD::basename_nosuffix(filename) }, + { 'f', filepath }, + { 'd', Glib::path_get_dirname(filepath) }, + { 'b', PBD::basename_nosuffix(filepath) }, { 'u', upload_username }, { 'p', upload_password} }; @@ -317,15 +325,16 @@ ExportHandler::finish_timespan () 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 ('f', filepath)); + subs.insert (std::pair ('d', Glib::path_get_dirname(filepath))); + subs.insert (std::pair ('b', PBD::basename_nosuffix(filepath))); + subs.insert (std::pair ('u', upload_username)); + subs.insert (std::pair ('p', upload_password)); std::cerr << "running command: " << fmt->command() << "..." << std::endl; - ARDOUR::SystemExec *se = new ARDOUR::SystemExec(fmt->command(), subs); + SystemExec *se = new 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 @@ -333,6 +342,7 @@ ExportHandler::finish_timespan () while (se->is_running ()) { // wait for system exec to terminate // std::cerr << "waiting..." << std::endl; + Glib::usleep (1000); } }