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 -
7 /*** Graph classes ***/
10 /// A node in the hierarchical graph that represents a multiplicatable export item
14 virtual ~GraphNode ();
16 uint32_t id() const { return _id; }
18 /* Children and parents. Note: only children are kept in order! */
20 list<GraphNode *> const & get_parents () const { return parents; }
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; }
28 /* Relation functions */
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; }
34 /* Selection functions */
36 bool selected () const { return _selected; }
37 void select (bool value);
39 PBD::Signal1<void,bool> SelectChanged;
43 /* Parent manipulation functions should be used only from child manipulation functions! */
45 void add_parent (GraphNode * parent);
46 void remove_parent (GraphNode * parent);
48 list<GraphNode *> parents;
49 list<GraphNode *> children;
53 static uint32_t id_counter;
56 /// A graph node that contains data
58 class DataNode : public GraphNode {
60 typedef boost::shared_ptr<T> DataPtr;
61 typedef boost::shared_ptr<DataNode<T> > SelfPtr;
62 typedef boost::weak_ptr<DataNode<T> > WeakSelfPtr;
64 DataNode (DataPtr data) : _data (data) {}
65 void set_self_ptr (boost::shared_ptr<DataNode<T> > ptr) { _self_ptr = ptr; }
68 static SelfPtr create (T * data)
70 SelfPtr ptr = SelfPtr (new DataNode<T> (DataPtr (data)));
71 ptr->set_self_ptr (ptr);
75 static SelfPtr create (DataPtr data)
77 SelfPtr ptr = SelfPtr (new DataNode<T> (data));
78 ptr->set_self_ptr (ptr);
82 DataPtr data() { return _data; }
83 SelfPtr self_ptr () { return _self_ptr.lock(); }
85 template<typename P> // Parent's data type
86 void sort_parents (list<boost::shared_ptr<DataNode<P> > > const & sort_list)
88 parents.sort (NodeSorter<P> (sort_list));
93 WeakSelfPtr _self_ptr;
97 /* Sorts GraphNodes according to a list of DataNodes */
102 typedef list<boost::shared_ptr<DataNode<T> > > ListType;
104 NodeSorter (ListType const & list) : list (list) {}
106 bool operator() (GraphNode * one, GraphNode * other) // '<' operator
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) {
113 if (it->get() == other) {
118 std::cerr << "Invalid comparison list given to NodeSorter" << std::endl;
124 ListType const & list;
127 /*** Multiplication management ***/
130 typedef DataNode<TimespanState> TimespanNode;
131 typedef boost::shared_ptr<TimespanNode> TimespanNodePtr;
133 typedef DataNode<ChannelConfigState> ChannelConfigNode;
134 typedef boost::shared_ptr<ChannelConfigNode> ChannelConfigNodePtr;
136 typedef DataNode<FormatState> FormatNode;
137 typedef boost::shared_ptr<FormatNode> FormatNodePtr;
139 typedef DataNode<FilenameState> FilenameNode;
140 typedef boost::shared_ptr<FilenameNode> FilenameNodePtr;
142 struct MultiplicationGraph {
143 list<TimespanNodePtr> timespans;
144 list<ChannelConfigNodePtr> channel_configs;
145 list<FormatNodePtr> formats;
146 list<FilenameNodePtr> filenames;
149 MultiplicationGraph const & get_graph () { return graph; }
151 void split_node (GraphNode * node, float position);
152 void remove_node (GraphNode * node);
154 PBD::Signal0<void> GraphChanged;
161 static void insert_after (list<T> & the_list, T const & position, T const & element);
164 static void remove_by_element (list<T> & the_list, T const & element);
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);
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);
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);
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);
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);
189 MultiplicationGraph graph;