2 Copyright (C) 2012 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 /* This file is not used at the moment. It includes code related to export a
21 * multiplication graph system that can be used together with the ExportMultiplicator
22 * class in the gtk2_ardour folder.
23 * - Sakari Bergen 6.8.2008 -
26 /*** Graph classes ***/
29 /// A node in the hierarchical graph that represents a multiplicatable export item
33 virtual ~GraphNode ();
35 uint32_t id() const { return _id; }
37 /* Children and parents. Note: only children are kept in order! */
39 list<GraphNode *> const & get_parents () const { return parents; }
41 void add_child (GraphNode * child, GraphNode * left_sibling);
42 void remove_child (GraphNode * child);
43 GraphNode * first_child () const { return children.front(); }
44 GraphNode * last_child () const { return children.back(); }
45 list<GraphNode *> const & get_children () const { return children; }
47 /* Relation functions */
49 bool is_ancestor_of (GraphNode const * node) const;
50 bool is_descendant_of (GraphNode const * node) const;
51 bool equals (GraphNode const * node) const { return node == this; }
53 /* Selection functions */
55 bool selected () const { return _selected; }
56 void select (bool value);
58 PBD::Signal1<void,bool> SelectChanged;
62 /* Parent manipulation functions should be used only from child manipulation functions! */
64 void add_parent (GraphNode * parent);
65 void remove_parent (GraphNode * parent);
67 list<GraphNode *> parents;
68 list<GraphNode *> children;
72 static uint32_t id_counter;
75 /// A graph node that contains data
77 class DataNode : public GraphNode {
79 typedef boost::shared_ptr<T> DataPtr;
80 typedef boost::shared_ptr<DataNode<T> > SelfPtr;
81 typedef boost::weak_ptr<DataNode<T> > WeakSelfPtr;
83 DataNode (DataPtr data) : _data (data) {}
84 void set_self_ptr (boost::shared_ptr<DataNode<T> > ptr) { _self_ptr = ptr; }
87 static SelfPtr create (T * data)
89 SelfPtr ptr = SelfPtr (new DataNode<T> (DataPtr (data)));
90 ptr->set_self_ptr (ptr);
94 static SelfPtr create (DataPtr data)
96 SelfPtr ptr = SelfPtr (new DataNode<T> (data));
97 ptr->set_self_ptr (ptr);
101 DataPtr data() { return _data; }
102 SelfPtr self_ptr () { return _self_ptr.lock(); }
104 template<typename P> // Parent's data type
105 void sort_parents (list<boost::shared_ptr<DataNode<P> > > const & sort_list)
107 parents.sort (NodeSorter<P> (sort_list));
112 WeakSelfPtr _self_ptr;
116 /* Sorts GraphNodes according to a list of DataNodes */
121 typedef list<boost::shared_ptr<DataNode<T> > > ListType;
123 NodeSorter (ListType const & list) : list (list) {}
125 bool operator() (GraphNode * one, GraphNode * other) // '<' operator
127 if (one == other) { return false; } // Strict weak ordering
128 for (typename ListType::const_iterator it = list.begin(); it != list.end(); ++it) {
129 if (it->get() == one) {
132 if (it->get() == other) {
137 std::cerr << "Invalid comparison list given to NodeSorter" << std::endl;
143 ListType const & list;
146 /*** Multiplication management ***/
149 typedef DataNode<TimespanState> TimespanNode;
150 typedef boost::shared_ptr<TimespanNode> TimespanNodePtr;
152 typedef DataNode<ChannelConfigState> ChannelConfigNode;
153 typedef boost::shared_ptr<ChannelConfigNode> ChannelConfigNodePtr;
155 typedef DataNode<FormatState> FormatNode;
156 typedef boost::shared_ptr<FormatNode> FormatNodePtr;
158 typedef DataNode<FilenameState> FilenameNode;
159 typedef boost::shared_ptr<FilenameNode> FilenameNodePtr;
161 struct MultiplicationGraph {
162 list<TimespanNodePtr> timespans;
163 list<ChannelConfigNodePtr> channel_configs;
164 list<FormatNodePtr> formats;
165 list<FilenameNodePtr> filenames;
168 MultiplicationGraph const & get_graph () { return graph; }
170 void split_node (GraphNode * node, float position);
171 void remove_node (GraphNode * node);
173 PBD::Signal0<void> GraphChanged;
180 static void insert_after (list<T> & the_list, T const & position, T const & element);
183 static void remove_by_element (list<T> & the_list, T const & element);
185 bool nodes_have_one_common_child (list<GraphNode *> const & the_list);
186 list<GraphNode *>::const_iterator end_of_common_child_range (list<GraphNode *> const & the_list, list<GraphNode *>::const_iterator beginning);
187 void split_node_at_position (GraphNode * old_node, GraphNode * new_node, float position);
189 void split_timespan (TimespanNodePtr node, float position = 0.5);
190 void split_channel_config (ChannelConfigNodePtr node, float position = 0.5);
191 void split_format (FormatNodePtr node, float position = 0.5);
192 void split_filename (FilenameNodePtr node, float position = 0.5);
194 void duplicate_timespan_children (TimespanNodePtr source, TimespanNodePtr target, GraphNode * insertion_point = 0);
195 void duplicate_channel_config_children (ChannelConfigNodePtr source, ChannelConfigNodePtr target, GraphNode * insertion_point = 0);
196 void duplicate_format_children (FormatNodePtr source, FormatNodePtr target, GraphNode * insertion_point = 0);
198 TimespanNodePtr duplicate_timespan_node (TimespanNodePtr node);
199 ChannelConfigNodePtr duplicate_channel_config_node (ChannelConfigNodePtr node);
200 FormatNodePtr duplicate_format_node (FormatNodePtr node);
201 FilenameNodePtr duplicate_filename_node (FilenameNodePtr node);
203 void remove_timespan (TimespanNodePtr node);
204 void remove_channel_config (ChannelConfigNodePtr node);
205 void remove_format (FormatNodePtr node);
206 void remove_filename (FilenameNodePtr node);
208 MultiplicationGraph graph;