Rename internal sends when their send-to bus changes.
[ardour.git] / libs / ardour / ardour / export_profile_manager.h
index 1a855d68684fc392407f879d6b3f48d17f99bf78..47acacd387283ae0b3a98619fe93d60b100a8248 100644 (file)
 #include <list>
 #include <vector>
 #include <map>
-#include <set>
+#include <stdexcept>
 
 #include <boost/shared_ptr.hpp>
 #include <boost/weak_ptr.hpp>
 #include <sigc++/signal.h>
 #include <glibmm/ustring.h>
 
-#include <pbd/file_utils.h>
-#include <pbd/xml++.h>
+#include "pbd/uuid.h"
+#include "pbd/file_utils.h"
+#include "pbd/xml++.h"
 
-#include <ardour/filesystem_paths.h>
-#include <ardour/location.h>
-#include <ardour/types.h>
-
-using std::string;
-using std::list;
-using std::set;
+#include "ardour/filesystem_paths.h"
+#include "ardour/location.h"
+#include "ardour/types.h"
 
 namespace ARDOUR
 {
@@ -50,52 +47,13 @@ class ExportTimespan;
 class ExportChannelConfiguration;
 class ExportFormatSpecification;
 class ExportFilename;
+class ExportPreset;
 class Location;
 class Session;
 
 /// Manages (de)serialization of export profiles and related classes
 class ExportProfileManager
 {
-  public:
-       class Preset {
-         public:
-               Preset (string filename, Session & s);
-               ~Preset ();
-       
-               uint32_t id () const { return _id; }
-               string name () const { return _name; }
-       
-               void set_name (string name);
-               void set_id (uint32_t id);
-       
-               // Note: The set_..._state functions take ownership of the XMLNode
-               void set_global_state (XMLNode & state);
-               void set_local_state (XMLNode & state);
-               
-               XMLNode const * get_global_state () const { return global.root(); }
-               XMLNode const * get_local_state () const { return local; }
-               
-               void save () const;
-               void remove_local () const;
-       
-         private:
-       
-               XMLNode * get_instant_xml () const;
-               void save_instant_xml () const;
-               void remove_instant_xml () const;
-       
-               uint32_t   _id;
-               string     _name;
-       
-               Session &   session;
-               XMLTree     global;
-               XMLNode *   local;
-               
-       };
-
-       typedef boost::shared_ptr<Preset> PresetPtr;
-       typedef std::list<PresetPtr> PresetList;
-
   public:
 
        ExportProfileManager (Session & s);
@@ -103,39 +61,41 @@ class ExportProfileManager
 
        void load_profile ();
        void prepare_for_export ();
-       
+
+       typedef boost::shared_ptr<ExportPreset> PresetPtr;
+       typedef std::list<PresetPtr> PresetList;
+
        PresetList const & get_presets () { return preset_list; }
-       void load_preset (PresetPtr preset);
-       PresetPtr save_preset (string const & name);
+       bool load_preset (PresetPtr preset);
+       PresetPtr save_preset (std::string const & name);
        void remove_preset ();
 
   private:
        typedef boost::shared_ptr<ExportHandler> HandlerPtr;
 
-       typedef std::pair<uint32_t, PBD::sys::path> FilePair;
-       typedef std::map<uint32_t, PBD::sys::path> FileMap;
-       
+       typedef std::pair<PBD::UUID, PBD::sys::path> FilePair;
+       typedef std::map<PBD::UUID, PBD::sys::path> FileMap;
+
        HandlerPtr  handler;
        Session &   session;
-       
+
        void load_presets ();
-       uint32_t load_preset_from_disk (PBD::sys::path const & path); // Returns preset id
-       
-       void set_state (XMLNode const & root);
-       void set_global_state (XMLNode const & root);
-       void set_local_state (XMLNode const & root);
-       
+       void load_preset_from_disk (PBD::sys::path const & path);
+
+       bool set_state (XMLNode const & root);
+       bool set_global_state (XMLNode const & root);
+       bool set_local_state (XMLNode const & root);
+
        void serialize_profile (XMLNode & root);
        void serialize_global_profile (XMLNode & root);
        void serialize_local_profile (XMLNode & root);
-       
+
        PresetList preset_list;
        PresetPtr  current_preset;
-       uint32_t   preset_id_counter;
        FileMap    preset_file_map;
-       
+
        std::vector<PBD::sys::path> find_file (std::string const & pattern);
-       
+
        PBD::sys::path  export_config_dir;
        PBD::SearchPath search_path;
 
@@ -148,7 +108,7 @@ class ExportProfileManager
        typedef std::list<Location *> LocationList;
 
        enum TimeFormat {
-               SMPTE,
+               Timecode,
                BBT,
                MinSec,
                Frames,
@@ -158,46 +118,50 @@ class ExportProfileManager
        struct TimespanState {
                TimespanListPtr timespans;
                TimeFormat      time_format;
-               
+
                boost::shared_ptr<Location> session_range;
                boost::shared_ptr<Location> selection_range;
                boost::shared_ptr<LocationList> ranges;
-               
+
                TimespanState (boost::shared_ptr<Location> session_range,
                               boost::shared_ptr<Location> selection_range,
                               boost::shared_ptr<LocationList> ranges) :
                  timespans (new TimespanList ()),
-                 time_format (SMPTE),
-               
+                 time_format (Timecode),
+
                  session_range (session_range),
                  selection_range (selection_range),
                  ranges (ranges)
                {}
        };
-       
+
        typedef boost::shared_ptr<TimespanState> TimespanStatePtr;
        typedef std::list<TimespanStatePtr> TimespanStateList;
-       
+
        void set_selection_range (nframes_t start = 0, nframes_t end = 0);
-       TimespanStateList const & get_timespans () { return timespans; }
-       
+       std::string set_single_range (nframes_t start, nframes_t end, Glib::ustring name);
+       TimespanStateList const & get_timespans () { return check_list (timespans); }
+
   private:
 
        TimespanStateList timespans;
 
-       void init_timespans (XMLNodeList nodes);
-       
+       bool init_timespans (XMLNodeList nodes);
+
        TimespanStatePtr deserialize_timespan (XMLNode & root);
        XMLNode & serialize_timespan (TimespanStatePtr state);
-       
+
        /* Locations */
-       
+
        void update_ranges ();
-       
+
        boost::shared_ptr<Location>     session_range;
        boost::shared_ptr<Location>     selection_range;
        boost::shared_ptr<LocationList> ranges;
 
+       bool                            single_range_mode;
+       boost::shared_ptr<Location>     single_range;
+
 /* Channel Configs */
   public:
 
@@ -205,22 +169,19 @@ class ExportProfileManager
 
        struct ChannelConfigState {
                ChannelConfigPtr config;
-               
+
                ChannelConfigState (ChannelConfigPtr ptr) : config (ptr) {}
        };
        typedef boost::shared_ptr<ChannelConfigState> ChannelConfigStatePtr;
        typedef std::list<ChannelConfigStatePtr> ChannelConfigStateList;
-       
-       ChannelConfigStateList const & get_channel_configs () { return channel_configs; }
+
+       ChannelConfigStateList const & get_channel_configs () { return check_list (channel_configs); }
 
   private:
 
        ChannelConfigStateList channel_configs;
 
-       void init_channel_configs (XMLNodeList nodes);
-
-       ChannelConfigStatePtr deserialize_channel_config (XMLNode & root);
-       XMLNode & serialize_channel_config (ChannelConfigStatePtr state);
+       bool init_channel_configs (XMLNodeList nodes);
 
 /* Formats */
   public:
@@ -231,65 +192,61 @@ class ExportProfileManager
        struct FormatState {
                boost::shared_ptr<FormatList const> list;
                FormatPtr                           format;
-               
+
                FormatState (boost::shared_ptr<FormatList const> list, FormatPtr format) :
                  list (list), format (format) {}
        };
        typedef boost::shared_ptr<FormatState> FormatStatePtr;
        typedef std::list<FormatStatePtr> FormatStateList;
-       
-       FormatStateList const & get_formats () { return formats; }
+
+       FormatStateList const & get_formats () { return check_list (formats); }
        FormatStatePtr duplicate_format_state (FormatStatePtr state);
        void remove_format_state (FormatStatePtr state);
-       
+
        PBD::sys::path save_format_to_disk (FormatPtr format);
        void remove_format_profile (FormatPtr format);
        FormatPtr get_new_format (FormatPtr original);
-       
+
        sigc::signal<void> FormatListChanged;
 
   private:
 
        FormatStateList formats;
 
-       void init_formats (XMLNodeList nodes);
+       bool init_formats (XMLNodeList nodes);
        FormatStatePtr deserialize_format (XMLNode & root);
        XMLNode & serialize_format (FormatStatePtr state);
 
        void load_formats ();
-       
+
        FormatPtr load_format (XMLNode & node);
        void load_format_from_disk (PBD::sys::path const & path);
 
        boost::shared_ptr<FormatList> format_list;
        FileMap                       format_file_map;
-       
+
 /* Filenames */
   public:
-       
+
        typedef boost::shared_ptr<ExportFilename> FilenamePtr;
-       
+
        struct FilenameState {
                FilenamePtr  filename;
-               
+
                FilenameState (FilenamePtr ptr) : filename (ptr) {}
        };
        typedef boost::shared_ptr<FilenameState> FilenameStatePtr;
        typedef std::list<FilenameStatePtr> FilenameStateList;
-       
-       FilenameStateList const & get_filenames () { return filenames; }
+
+       FilenameStateList const & get_filenames () { return check_list (filenames); }
        FilenameStatePtr duplicate_filename_state (FilenameStatePtr state);
        void remove_filename_state (FilenameStatePtr state);
 
   private:
 
        FilenameStateList filenames;
-       
-       void init_filenames (XMLNodeList nodes);
-       
-       FilenameStatePtr deserialize_filename (XMLNode & root);
-       XMLNode & serialize_filename (FilenameStatePtr state);
 
+       bool init_filenames (XMLNodeList nodes);
        FilenamePtr load_filename (XMLNode & node);
 
 /* Warnings */
@@ -299,15 +256,29 @@ class ExportProfileManager
                std::list<Glib::ustring> warnings;
                std::list<Glib::ustring> conflicting_filenames;
        };
-       
+
        boost::shared_ptr<Warnings> get_warnings ();
-       
+
   private:
        void check_config (boost::shared_ptr<Warnings> warnings,
                           TimespanStatePtr timespan_state,
                           ChannelConfigStatePtr channel_config_state,
                           FormatStatePtr format_state,
                           FilenameStatePtr filename_state);
+
+ /* Utilities */
+
+       /* Element state lists should never be empty, this is used to check them */
+       template<typename T>
+       std::list<T> const &
+       check_list (std::list<T> const & list)
+       {
+               if (list.empty()) {
+                       throw std::runtime_error ("Programming error: Uninitialized list in ExportProfileManager");
+               }
+               return list;
+       }
+
 };