Ardour  9.0-pre0-386-g96ef4d20f2
listed_source.h
Go to the documentation of this file.
1 #ifndef AUDIOGRAPHER_LISTED_SOURCE_H
2 #define AUDIOGRAPHER_LISTED_SOURCE_H
3 
5 #include "audiographer/types.h"
6 #include "audiographer/types.h"
7 #include "audiographer/source.h"
8 
9 #include <list>
10 
11 namespace AudioGrapher
12 {
13 
15 template<typename T = DefaultSampleType>
17 {
18  public:
19  void add_output (typename Source<T>::SinkPtr output) { outputs.push_back(output); }
20  void clear_outputs () { outputs.clear(); }
21  void remove_output (typename Source<T>::SinkPtr output) { outputs.remove(output); }
22 
23  protected:
24 
25  typedef std::list<typename Source<T>::SinkPtr> SinkList;
26 
28  void output (ProcessContext<T> const & c)
29  {
30  for (typename SinkList::iterator i = outputs.begin(); i != outputs.end(); ++i) {
31  (*i)->process (c);
32  }
33  }
34 
36  {
37  if (output_size_is_one()) {
38  // only one output, so we can keep this non-const
39  outputs.front()->process (c);
40  } else {
41  output (const_cast<ProcessContext<T> const &> (c));
42  }
43  }
44 
45  inline bool output_size_is_one () { return (!outputs.empty() && ++outputs.begin() == outputs.end()); }
46 
48 };
49 
50 } // namespace
51 
52 #endif //AUDIOGRAPHER_LISTED_SOURCE_H
53 
An generic Source that uses a std::list for managing outputs.
Definition: listed_source.h:17
void clear_outputs()
Removes all outputs added.
Definition: listed_source.h:20
void remove_output(typename Source< T >::SinkPtr output)
Definition: listed_source.h:21
void add_output(typename Source< T >::SinkPtr output)
Definition: listed_source.h:19
std::list< typename Source< T >::SinkPtr > SinkList
Definition: listed_source.h:25
void output(ProcessContext< T > &c)
Definition: listed_source.h:35
void output(ProcessContext< T > const &c)
Helper for derived classes.
Definition: listed_source.h:28
std::shared_ptr< Sink< T > > SinkPtr