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