the big Route structure refactor. !!!! THIS WILL ***NOT LOAD*** PRIOR 3.0 or 2.X...
[ardour.git] / libs / ardour / ardour / export_multiplication.h
1 /* This file is not used at the moment. It includes code related to export a
2  * multiplication graph system that can be used together with the ExportMultiplicator
3  * class in the gtk2_ardour folder.
4  * - Sakari Bergen 6.8.2008 -
5  */
6
7 /*** Graph classes ***/
8   public:
9
10         /// A node in the hierarchical graph that represents a multiplicatable export item
11         class GraphNode {
12           public:
13                 GraphNode ();
14                 virtual ~GraphNode ();
15         
16                 uint32_t id() const { return _id; }
17         
18                 /* Children and parents. Note: only children are kept in order! */
19                 
20                 list<GraphNode *> const & get_parents () const { return parents; }
21                 
22                 void add_child (GraphNode * child, GraphNode * left_sibling);
23                 void remove_child (GraphNode * child);
24                 GraphNode * first_child () const { return children.front(); }
25                 GraphNode * last_child () const { return children.back(); }
26                 list<GraphNode *> const & get_children () const { return children; }
27                 
28                 /* Relation functions */
29                 
30                 bool is_ancestor_of (GraphNode const * node) const;
31                 bool is_descendant_of (GraphNode const * node) const;
32                 bool equals (GraphNode const * node) const { return node == this; }
33                 
34                 /* Selection functions */
35                 
36                 bool selected () const { return _selected; }
37                 void select (bool value);
38                 
39                 sigc::signal<void, bool> SelectChanged;
40         
41           protected:
42         
43                 /* Parent manipulation functions should be used only from child manipulation functions! */
44         
45                 void add_parent (GraphNode * parent);
46                 void remove_parent (GraphNode * parent);
47         
48                 list<GraphNode *> parents;
49                 list<GraphNode *> children;
50                 
51                 bool           _selected;
52                 uint32_t       _id;
53                 static uint32_t id_counter;
54         };
55
56         /// A graph node that contains data
57         template <typename T>
58         class DataNode : public GraphNode {
59           private:
60                 typedef boost::shared_ptr<T> DataPtr;
61                 typedef boost::shared_ptr<DataNode<T> > SelfPtr;
62                 typedef boost::weak_ptr<DataNode<T> > WeakSelfPtr;
63                 
64                 DataNode (DataPtr data) : _data (data) {}
65                 void set_self_ptr (boost::shared_ptr<DataNode<T> > ptr) { _self_ptr = ptr; }
66                 
67           public:
68                 static SelfPtr create (T * data)
69                 {
70                         SelfPtr ptr = SelfPtr (new DataNode<T> (DataPtr (data)));
71                         ptr->set_self_ptr (ptr);
72                         return ptr;
73                 }
74         
75                 static SelfPtr create (DataPtr data)
76                 {
77                         SelfPtr ptr = SelfPtr (new DataNode<T> (data));
78                         ptr->set_self_ptr (ptr);
79                         return ptr;
80                 }
81         
82                 DataPtr data() { return _data; }
83                 SelfPtr self_ptr () { return _self_ptr.lock(); }
84
85                 template<typename P> // Parent's data type
86                 void sort_parents (list<boost::shared_ptr<DataNode<P> > > const & sort_list)
87                 {
88                         parents.sort (NodeSorter<P> (sort_list));
89                 }
90         
91           private:
92                 DataPtr     _data;
93                 WeakSelfPtr _self_ptr;
94         };
95
96   private:
97         /* Sorts GraphNodes according to a list of DataNodes */
98         
99         template<typename T>
100         class NodeSorter {
101           public:
102                 typedef list<boost::shared_ptr<DataNode<T> > > ListType;
103                 
104                 NodeSorter (ListType const & list) : list (list) {}
105                 
106                 bool operator() (GraphNode * one, GraphNode * other) // '<' operator
107                 {
108                         if (one == other) { return false; } // Strict weak ordering
109                         for (typename ListType::const_iterator it = list.begin(); it != list.end(); ++it) {
110                                 if (it->get() == one) {
111                                         return true;
112                                 }
113                                 if (it->get() == other) {
114                                         return false;
115                                 }
116                         }
117                         
118                         std::cerr << "Invalid comparison list given to NodeSorter" << std::endl;
119                         
120                         abort();
121                 }
122         
123           private:
124                 ListType const & list;
125         };
126
127 /*** Multiplication management ***/
128   public:
129
130         typedef DataNode<TimespanState> TimespanNode;
131         typedef boost::shared_ptr<TimespanNode> TimespanNodePtr;
132         
133         typedef DataNode<ChannelConfigState> ChannelConfigNode;
134         typedef boost::shared_ptr<ChannelConfigNode> ChannelConfigNodePtr;
135         
136         typedef DataNode<FormatState> FormatNode;
137         typedef boost::shared_ptr<FormatNode> FormatNodePtr;
138         
139         typedef DataNode<FilenameState> FilenameNode;
140         typedef boost::shared_ptr<FilenameNode> FilenameNodePtr;
141         
142         struct MultiplicationGraph {
143                 list<TimespanNodePtr>      timespans;
144                 list<ChannelConfigNodePtr> channel_configs;
145                 list<FormatNodePtr>        formats;
146                 list<FilenameNodePtr>      filenames;
147         };
148
149         MultiplicationGraph const & get_graph () { return graph; }
150         
151         void split_node (GraphNode * node, float position);
152         void remove_node (GraphNode * node);
153         
154         sigc::signal<void> GraphChanged;
155
156   private:
157
158         void purge_graph ();
159         
160         template<typename T>
161         static void insert_after (list<T> & the_list, T const & position, T const & element);
162         
163         template<typename T>
164         static void remove_by_element (list<T> & the_list, T const & element);
165         
166         bool nodes_have_one_common_child (list<GraphNode *> const & the_list);
167         list<GraphNode *>::const_iterator end_of_common_child_range (list<GraphNode *> const & the_list, list<GraphNode *>::const_iterator beginning);
168         void split_node_at_position (GraphNode * old_node, GraphNode * new_node, float position);
169         
170         void split_timespan (TimespanNodePtr node, float position = 0.5);
171         void split_channel_config (ChannelConfigNodePtr node, float position = 0.5);
172         void split_format (FormatNodePtr node, float position = 0.5);
173         void split_filename (FilenameNodePtr node, float position = 0.5);
174         
175         void duplicate_timespan_children (TimespanNodePtr source, TimespanNodePtr target, GraphNode * insertion_point = 0);
176         void duplicate_channel_config_children (ChannelConfigNodePtr source, ChannelConfigNodePtr target, GraphNode * insertion_point = 0);
177         void duplicate_format_children (FormatNodePtr source, FormatNodePtr target, GraphNode * insertion_point = 0);
178         
179         TimespanNodePtr duplicate_timespan_node (TimespanNodePtr node);
180         ChannelConfigNodePtr duplicate_channel_config_node (ChannelConfigNodePtr node);
181         FormatNodePtr duplicate_format_node (FormatNodePtr node);
182         FilenameNodePtr duplicate_filename_node (FilenameNodePtr node);
183
184         void remove_timespan (TimespanNodePtr node);
185         void remove_channel_config (ChannelConfigNodePtr node);
186         void remove_format (FormatNodePtr node);
187         void remove_filename (FilenameNodePtr node);
188
189         MultiplicationGraph graph;