summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Fletcher <colin.m.fletcher@googlemail.com>2013-10-10 19:54:22 +0100
committerColin Fletcher <colin.m.fletcher@googlemail.com>2013-10-10 19:54:22 +0100
commitcac644270a8626904a4a21f527cdcf5083defa60 (patch)
treed6bc0ef98cf255f2fcdddcb53820b4ccaefdb6b9
parente1562961c0bf87daa98417f2a660fbf8ebd04a35 (diff)
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.
-rw-r--r--gtk2_ardour/export_format_dialog.cc2
-rw-r--r--libs/ardour/ardour/export_handler.h2
-rw-r--r--libs/ardour/export_handler.cc49
3 files changed, 45 insertions, 8 deletions
diff --git a/gtk2_ardour/export_format_dialog.cc b/gtk2_ardour/export_format_dialog.cc
index a05a6e549a..0e2da53cfd 100644
--- a/gtk2_ardour/export_format_dialog.cc
+++ b/gtk2_ardour/export_format_dialog.cc
@@ -52,7 +52,7 @@ ExportFormatDialog::ExportFormatDialog (FormatPtr format, bool new_dialog) :
silence_end_clock ("silence_end", true, "", true, false, true),
upload_checkbox(_("Upload to Soundcloud")),
- command_label(_("Command to run post-export (%1=full path & filename, %2=directory, %3=basename):")),
+ command_label(_("Command to run post-export\n(%f=full path & filename, %d=directory, %b=basename, %u=username, %p=password):")),
format_table (3, 4),
compatibility_label (_("Compatibility"), Gtk::ALIGN_LEFT),
diff --git a/libs/ardour/ardour/export_handler.h b/libs/ardour/ardour/export_handler.h
index 7f667d2dee..e2c0a7b2b7 100644
--- a/libs/ardour/ardour/export_handler.h
+++ b/libs/ardour/ardour/export_handler.h
@@ -95,6 +95,8 @@ class ExportHandler : public ExportElementFactory, public sigc::trackable
friend boost::shared_ptr<ExportHandler> 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 042edaf788..f2fb895b91 100644
--- a/libs/ardour/export_handler.cc
+++ b/libs/ardour/export_handler.cc
@@ -34,6 +34,7 @@
#include "ardour/soundcloud_upload.h"
#include "pbd/openuri.h"
#include "pbd/basename.h"
+#include "pbd/system_exec.h"
#include "i18n.h"
@@ -278,6 +279,13 @@ ExportHandler::process_normalize ()
}
void
+ExportHandler::command_output(std::string output, size_t size)
+{
+ std::cerr << "command: " << size << ", " << output << std::endl;
+ info << output << endmsg;
+}
+
+void
ExportHandler::finish_timespan ()
{
while (config_map.begin() != timespan_bounds.second) {
@@ -294,13 +302,40 @@ ExportHandler::finish_timespan ()
}
if (!fmt->command().empty()) {
- std::string command = string_compose(fmt->command(),
- filepath,
- Glib::path_get_dirname(filepath),
- PBD::basename_nosuffix(filepath)
- );
- std::cerr << "running command: " << command << "..." << std::endl;
- system(command.c_str());
+
+#if 0 // would be nicer with C++11 initialiser...
+ std::map<char, std::string> subs {
+ { 'f', filepath },
+ { 'd', Glib::path_get_dirname(filepath) },
+ { 'b', PBD::basename_nosuffix(filepath) },
+ { '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', filepath));
+ subs.insert (std::pair<char, std::string> ('d', Glib::path_get_dirname(filepath)));
+ subs.insert (std::pair<char, std::string> ('b', PBD::basename_nosuffix(filepath)));
+ subs.insert (std::pair<char, std::string> ('u', upload_username));
+ subs.insert (std::pair<char, std::string> ('p', upload_password));
+
+
+ std::cerr << "running command: " << fmt->command() << "..." << std::endl;
+ 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
+ std::cerr << "started!" << std::endl;
+ while (se->is_running ()) {
+ // wait for system exec to terminate
+ // std::cerr << "waiting..." << std::endl;
+ usleep (1000);
+ }
+ }
+ std::cerr << "done! deleting..." << std::endl;
+ delete (se);
}
if (fmt->upload()) {