Rudimentary post-processing of exported files.
authorColin Fletcher <colin.m.fletcher@googlemail.com>
Mon, 7 Oct 2013 19:28:13 +0000 (20:28 +0100)
committerColin Fletcher <colin.m.fletcher@googlemail.com>
Mon, 7 Oct 2013 19:28:13 +0000 (20:28 +0100)
Export format contains a string to be passed to system() after expanding
%1, %2, & %3 via string_compose() to the full path & filename, containing
directory, and basename respectively. No error-checking or any niceties
like that - real programmers will of course always type the command
correctly, and know to watch Ardour's standard output for the results...

gtk2_ardour/export_format_dialog.cc
gtk2_ardour/export_format_dialog.h
libs/ardour/ardour/export_format_manager.h
libs/ardour/ardour/export_format_specification.h
libs/ardour/export_format_manager.cc
libs/ardour/export_format_specification.cc
libs/ardour/export_handler.cc

index 62d98c5cd29831070ed8e0694cc657802eefc86b..a05a6e549a046994ca7c4ed222714c2cf95735ee 100644 (file)
@@ -52,6 +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):")),
 
   format_table (3, 4),
   compatibility_label (_("Compatibility"), Gtk::ALIGN_LEFT),
@@ -116,6 +117,9 @@ ExportFormatDialog::ExportFormatDialog (FormatPtr format, bool new_dialog) :
        silence_table.attach (silence_end_clock, 2, 3, 2, 3);
 
        get_vbox()->pack_start (upload_checkbox, false, false);
+       get_vbox()->pack_start (command_label, false, false);
+       get_vbox()->pack_start (command_entry, false, false);
+
        /* Format table */
 
        init_format_table();
@@ -146,6 +150,7 @@ ExportFormatDialog::ExportFormatDialog (FormatPtr format, bool new_dialog) :
        with_cue.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_with_cue));
        with_toc.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_with_toc));
        upload_checkbox.signal_toggled().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_upload));
+       command_entry.signal_changed().connect (sigc::mem_fun (*this, &ExportFormatDialog::update_command));
 
        cue_toc_vbox.pack_start (with_cue, false, false);
        cue_toc_vbox.pack_start (with_toc, false, false);
@@ -301,6 +306,7 @@ ExportFormatDialog::load_state (FormatPtr spec)
 
        tag_checkbox.set_active (spec->tag());
        upload_checkbox.set_active (spec->upload());
+       command_entry.set_text (spec->command());
 }
 
 void
@@ -728,6 +734,13 @@ ExportFormatDialog::update_upload ()
        manager.select_upload (upload_checkbox.get_active());
 }
 
+void
+ExportFormatDialog::update_command ()
+{
+       manager.set_command (command_entry.get_text());
+}
+
+void
 ExportFormatDialog::update_description()
 {
        std::string text = ": " + format->description(false);
index 96405c33dd8f8e7580cdd859f213b282573a730a..42ed1a988665f5dd448e5fc2b182f10f2a3ee37c 100644 (file)
@@ -178,6 +178,8 @@ class ExportFormatDialog : public ArdourDialog, public PBD::ScopedConnectionList
        /* Upload */
        
        Gtk::CheckButton upload_checkbox;
+       Gtk::Label       command_label;
+       Gtk::Entry       command_entry;
 
        /* Format table */
 
@@ -312,6 +314,7 @@ class ExportFormatDialog : public ArdourDialog, public PBD::ScopedConnectionList
        void update_with_toc ();
        void update_with_cue ();
        void update_upload ();
+       void update_command ();
 
        Gtk::TreeView sample_format_view;
        Gtk::TreeView dither_type_view;
index 4b4e43ae9c58d9f2bffbea921e5f9d44ee9240b2..9fce8282a1dca3f30f1adc8e2802504773fa75c7 100644 (file)
@@ -101,6 +101,7 @@ class ExportFormatManager : public PBD::ScopedConnectionList
        void select_with_cue (bool);
        void select_with_toc (bool);
        void select_upload (bool);
+       void set_command (std::string);
        void select_src_quality (ExportFormatBase::SRCQuality value);
        void select_trim_beginning (bool value);
        void select_silence_beginning (AnyTime const & time);
index cb99afdfa270c861b7c71f880762a638f3e8415b..768fbb3bb3add9aee136e5958d3e399f76eb6dcc 100644 (file)
@@ -96,6 +96,7 @@ class ExportFormatSpecification : public ExportFormatBase {
        void set_with_cue (bool yn) { _with_cue = yn; }
        void set_with_toc (bool yn) { _with_toc = yn; }
        void set_upload (bool yn) { _upload = yn; }
+       void set_command (std::string command) { _command = command; }
 
        void set_silence_beginning (AnyTime const & value) { _silence_beginning = value; }
        void set_silence_end (AnyTime const & value) { _silence_end = value; }
@@ -126,6 +127,7 @@ class ExportFormatSpecification : public ExportFormatBase {
        bool with_toc() const { return _with_toc; }
        bool with_cue() const { return _with_cue; }
        bool upload() const { return _upload; }
+       std::string command() const { return _command; }
 
        bool tag () const { return _tag && supports_tagging; }
 
@@ -176,6 +178,7 @@ class ExportFormatSpecification : public ExportFormatBase {
        bool            _with_toc;
        bool            _with_cue;
        bool            _upload;
+       std::string     _command;
 
        /* serialization helpers */
 
index c8bd0c0aa912b012eeda7fbdf2e1e70abcb7288a..3ee940ffb6367ff50c5ddf2e7d6dda521deda007 100644 (file)
@@ -300,6 +300,14 @@ ExportFormatManager::select_upload (bool value)
        check_for_description_change ();
 }
 
+void
+ExportFormatManager::set_command (std::string command)
+{
+       current_selection->set_command (command);
+       check_for_description_change ();
+}
+
+void
 ExportFormatManager::select_trim_beginning (bool value)
 {
        current_selection->set_trim_beginning (value);
index 588a156d4a10e6cb3d56f36d52b771e21ac8ba68..8b921519f71fd9ccf60ab44f4651d85f93f166db 100644 (file)
@@ -171,6 +171,7 @@ ExportFormatSpecification::ExportFormatSpecification (Session & s)
        , _with_toc (false)
        , _with_cue (false)
        , _upload (false)
+       , _command ("")
 {
        format_ids.insert (F_None);
        endiannesses.insert (E_FileDefault);
@@ -246,6 +247,7 @@ ExportFormatSpecification::get_state ()
        root->add_property ("with-cue", _with_cue ? "true" : "false");
        root->add_property ("with-toc", _with_toc ? "true" : "false");
        root->add_property ("upload", _upload ? "true" : "false");
+       root->add_property ("command", _command);
 
        node = root->add_child ("Encoding");
        node->add_property ("id", enum_2_string (format_id()));
@@ -329,6 +331,12 @@ ExportFormatSpecification::set_state (const XMLNode & root)
                _upload = false;
        }
        
+       if ((prop = root.property ("command"))) {
+               _command = prop->value();
+       } else {
+               _command = "";
+       }
+
        /* Encoding and SRC */
 
        if ((child = root.child ("Encoding"))) {
@@ -601,6 +609,11 @@ ExportFormatSpecification::description (bool include_name)
        if (_upload) {
                components.push_back ("Upload");
        }
+
+       if (!_command.empty()) {
+               components.push_back ("+");
+       }
+
        string desc;
        if (include_name) {
                desc = _name + ": ";
index 7ca6cb8c53dea1b28d94b02845a72b57d1ba98f0..042edaf788bf8599a2f9f32c8705aa92fec96b92 100644 (file)
@@ -293,6 +293,16 @@ ExportHandler::finish_timespan ()
                        export_cd_marker_file (current_timespan, fmt, filepath, CDMarkerTOC);
                }
 
+               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 (fmt->upload()) {
                        SoundcloudUploader *soundcloud_uploader = new SoundcloudUploader;
                        std::string token = soundcloud_uploader->Get_Auth_Token(upload_username, upload_password);