summaryrefslogtreecommitdiff
path: root/libs/audiographer/audiographer/listed_source.h
blob: bc8f144d84708736488477d3900300ceaea6003a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#ifndef AUDIOGRAPHER_LISTED_SOURCE_H
#define AUDIOGRAPHER_LISTED_SOURCE_H

#include "types.h"
#include "source.h"

#include <list>

namespace AudioGrapher
{

template<typename T>
class ListedSource : public Source<T>
{
  public:
	void add_output (typename Source<T>::SinkPtr output) { outputs.push_back(output); }
	void clear_outputs () { outputs.clear(); }
	void remove_output (typename Source<T>::SinkPtr output) { outputs.remove(output); }
	
  protected:
	
	typedef std::list<typename Source<T>::SinkPtr> SinkList;
	
	/// Helper for derived classes
	void output (ProcessContext<T> const & c)
	{
		for (typename SinkList::iterator i = outputs.begin(); i != outputs.end(); ++i) {
			(*i)->process (c);
		}
	}

	void output (ProcessContext<T> & c)
	{
		if (output_size_is_one()) {
			// only one output, so we can keep this non-const
			outputs.front()->process (c);
		} else {
			output (const_cast<ProcessContext<T> const &> (c));
		}
	}

	inline bool output_size_is_one () { return (!outputs.empty() && ++outputs.begin() == outputs.end()); }

	SinkList outputs;
};

} // namespace

#endif //AUDIOGRAPHER_LISTED_SOURCE_H