Fix export, which has been broken since the boost::signals2 changes. Also update...
[ardour.git] / libs / audiographer / audiographer / utils / listed_source.h
1 #ifndef AUDIOGRAPHER_LISTED_SOURCE_H
2 #define AUDIOGRAPHER_LISTED_SOURCE_H
3
4 #include "audiographer/types.h"
5 #include "audiographer/source.h"
6
7 #include <list>
8
9 namespace AudioGrapher
10 {
11
12 /// An generic \a Source that uses a \a std::list for managing outputs
13 template<typename T = DefaultSampleType>
14 class ListedSource : public Source<T>
15 {
16   public:
17         void add_output (typename Source<T>::SinkPtr output) { outputs.push_back(output); }
18         void clear_outputs () { outputs.clear(); }
19         void remove_output (typename Source<T>::SinkPtr output) { outputs.remove(output); }
20         
21   protected:
22         
23         typedef std::list<typename Source<T>::SinkPtr> SinkList;
24         
25         /// Helper for derived classes
26         void output (ProcessContext<T> const & c)
27         {
28                 for (typename SinkList::iterator i = outputs.begin(); i != outputs.end(); ++i) {
29                         (*i)->process (c);
30                 }
31         }
32
33         void output (ProcessContext<T> & c)
34         {
35                 if (output_size_is_one()) {
36                         // only one output, so we can keep this non-const
37                         outputs.front()->process (c);
38                 } else {
39                         output (const_cast<ProcessContext<T> const &> (c));
40                 }
41         }
42
43         inline bool output_size_is_one () { return (!outputs.empty() && ++outputs.begin() == outputs.end()); }
44
45         SinkList outputs;
46 };
47
48 } // namespace
49
50 #endif //AUDIOGRAPHER_LISTED_SOURCE_H
51