diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2008-09-17 12:58:33 +0000 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2008-09-17 12:58:33 +0000 |
commit | f2b007195cd75b195e38a4cd7757debac73e7792 (patch) | |
tree | 90474413776806f02794602bbb495663e07a81ea /libs/ardour/ardour/export_multiplication.h | |
parent | 6ba5125e991e08a9d117b39a4c337cf453fd015d (diff) |
new files from sakari, missed last time
git-svn-id: svn://localhost/ardour2/branches/3.0@3740 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/ardour/ardour/export_multiplication.h')
-rw-r--r-- | libs/ardour/ardour/export_multiplication.h | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/libs/ardour/ardour/export_multiplication.h b/libs/ardour/ardour/export_multiplication.h new file mode 100644 index 0000000000..c8fd20c60e --- /dev/null +++ b/libs/ardour/ardour/export_multiplication.h @@ -0,0 +1,189 @@ +/* This file is not used at the moment. It includes code related to export a + * multiplication graph system that can be used together with the ExportMultiplicator + * class in the gtk2_ardour folder. + * - Sakari Bergen 6.8.2008 - + */ + +/*** Graph classes ***/ + public: + + /// A node in the hierarchical graph that represents a multiplicatable export item + class GraphNode { + public: + GraphNode (); + virtual ~GraphNode (); + + uint32_t id() const { return _id; } + + /* Children and parents. Note: only children are kept in order! */ + + list<GraphNode *> const & get_parents () const { return parents; } + + void add_child (GraphNode * child, GraphNode * left_sibling); + void remove_child (GraphNode * child); + GraphNode * first_child () const { return children.front(); } + GraphNode * last_child () const { return children.back(); } + list<GraphNode *> const & get_children () const { return children; } + + /* Relation functions */ + + bool is_ancestor_of (GraphNode const * node) const; + bool is_descendant_of (GraphNode const * node) const; + bool equals (GraphNode const * node) const { return node == this; } + + /* Selection functions */ + + bool selected () const { return _selected; } + void select (bool value); + + sigc::signal<void, bool> SelectChanged; + + protected: + + /* Parent manipulation functions should be used only from child manipulation functions! */ + + void add_parent (GraphNode * parent); + void remove_parent (GraphNode * parent); + + list<GraphNode *> parents; + list<GraphNode *> children; + + bool _selected; + uint32_t _id; + static uint32_t id_counter; + }; + + /// A graph node that contains data + template <typename T> + class DataNode : public GraphNode { + private: + typedef boost::shared_ptr<T> DataPtr; + typedef boost::shared_ptr<DataNode<T> > SelfPtr; + typedef boost::weak_ptr<DataNode<T> > WeakSelfPtr; + + DataNode (DataPtr data) : _data (data) {} + void set_self_ptr (boost::shared_ptr<DataNode<T> > ptr) { _self_ptr = ptr; } + + public: + static SelfPtr create (T * data) + { + SelfPtr ptr = SelfPtr (new DataNode<T> (DataPtr (data))); + ptr->set_self_ptr (ptr); + return ptr; + } + + static SelfPtr create (DataPtr data) + { + SelfPtr ptr = SelfPtr (new DataNode<T> (data)); + ptr->set_self_ptr (ptr); + return ptr; + } + + DataPtr data() { return _data; } + SelfPtr self_ptr () { return _self_ptr.lock(); } + + template<typename P> // Parent's data type + void sort_parents (list<boost::shared_ptr<DataNode<P> > > const & sort_list) + { + parents.sort (NodeSorter<P> (sort_list)); + } + + private: + DataPtr _data; + WeakSelfPtr _self_ptr; + }; + + private: + /* Sorts GraphNodes according to a list of DataNodes */ + + template<typename T> + class NodeSorter { + public: + typedef list<boost::shared_ptr<DataNode<T> > > ListType; + + NodeSorter (ListType const & list) : list (list) {} + + bool operator() (GraphNode * one, GraphNode * other) // '<' operator + { + if (one == other) { return false; } // Strict weak ordering + for (typename ListType::const_iterator it = list.begin(); it != list.end(); ++it) { + if (it->get() == one) { + return true; + } + if (it->get() == other) { + return false; + } + } + + std::cerr << "Invalid comparison list given to NodeSorter" << std::endl; + + abort(); + } + + private: + ListType const & list; + }; + +/*** Multiplication management ***/ + public: + + typedef DataNode<TimespanState> TimespanNode; + typedef boost::shared_ptr<TimespanNode> TimespanNodePtr; + + typedef DataNode<ChannelConfigState> ChannelConfigNode; + typedef boost::shared_ptr<ChannelConfigNode> ChannelConfigNodePtr; + + typedef DataNode<FormatState> FormatNode; + typedef boost::shared_ptr<FormatNode> FormatNodePtr; + + typedef DataNode<FilenameState> FilenameNode; + typedef boost::shared_ptr<FilenameNode> FilenameNodePtr; + + struct MultiplicationGraph { + list<TimespanNodePtr> timespans; + list<ChannelConfigNodePtr> channel_configs; + list<FormatNodePtr> formats; + list<FilenameNodePtr> filenames; + }; + + MultiplicationGraph const & get_graph () { return graph; } + + void split_node (GraphNode * node, float position); + void remove_node (GraphNode * node); + + sigc::signal<void> GraphChanged; + + private: + + void purge_graph (); + + template<typename T> + static void insert_after (list<T> & the_list, T const & position, T const & element); + + template<typename T> + static void remove_by_element (list<T> & the_list, T const & element); + + bool nodes_have_one_common_child (list<GraphNode *> const & the_list); + list<GraphNode *>::const_iterator end_of_common_child_range (list<GraphNode *> const & the_list, list<GraphNode *>::const_iterator beginning); + void split_node_at_position (GraphNode * old_node, GraphNode * new_node, float position); + + void split_timespan (TimespanNodePtr node, float position = 0.5); + void split_channel_config (ChannelConfigNodePtr node, float position = 0.5); + void split_format (FormatNodePtr node, float position = 0.5); + void split_filename (FilenameNodePtr node, float position = 0.5); + + void duplicate_timespan_children (TimespanNodePtr source, TimespanNodePtr target, GraphNode * insertion_point = 0); + void duplicate_channel_config_children (ChannelConfigNodePtr source, ChannelConfigNodePtr target, GraphNode * insertion_point = 0); + void duplicate_format_children (FormatNodePtr source, FormatNodePtr target, GraphNode * insertion_point = 0); + + TimespanNodePtr duplicate_timespan_node (TimespanNodePtr node); + ChannelConfigNodePtr duplicate_channel_config_node (ChannelConfigNodePtr node); + FormatNodePtr duplicate_format_node (FormatNodePtr node); + FilenameNodePtr duplicate_filename_node (FilenameNodePtr node); + + void remove_timespan (TimespanNodePtr node); + void remove_channel_config (ChannelConfigNodePtr node); + void remove_format (FormatNodePtr node); + void remove_filename (FilenameNodePtr node); + + MultiplicationGraph graph;
\ No newline at end of file |