Strip trailing whitespace and fix other whitespace errors (e.g. space/tab mixing...
[ardour.git] / libs / ardour / ardour / graph.h
1 /*
2     Copyright (C) 2008 Paul Davis
3     Author: Sakari Bergen
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20
21 #ifndef __ardour_graph_h__
22 #define __ardour_graph_h__
23
24 #include <boost/shared_ptr.hpp>
25
26 #include "ardour/types.h"
27
28 namespace ARDOUR
29 {
30
31 /// Takes data in
32 template <typename T>
33 class GraphSink  {
34   public:
35         GraphSink () : end_of_input (false) {}
36         virtual ~GraphSink () { end_of_input = false; }
37
38         // writes data and return number of frames written
39         virtual nframes_t write (T * data, nframes_t frames) = 0;
40
41         // Notifies end of input. All left over data must be written at this stage
42         virtual void set_end_of_input (bool state = true)
43         {
44                 end_of_input = state;
45         }
46
47   protected:
48         bool end_of_input;
49 };
50
51 /// is a source for data
52 template <typename T>
53 class GraphSource  {
54   public:
55         GraphSource () {}
56         virtual ~GraphSource () {}
57
58         virtual nframes_t read (T * data, nframes_t frames) = 0;
59 };
60
61 /// Takes data in, processes it and passes it on to another sink
62 template <typename TIn, typename TOut>
63 class GraphSinkVertex : public GraphSink<TIn> {
64   public:
65         GraphSinkVertex () {}
66         virtual ~GraphSinkVertex () {}
67
68         void pipe_to (boost::shared_ptr<GraphSink<TOut> > dest) {
69                 piped_to = dest;
70         }
71
72         nframes_t write (TIn * data, nframes_t frames)
73         {
74                 if (!piped_to) {
75                         return -1;
76                 }
77                 return process (data, frames);
78         }
79
80         virtual void set_end_of_input (bool state = true)
81         {
82                 if (!piped_to) {
83                         return;
84                 }
85                 piped_to->set_end_of_input (state);
86                 GraphSink<TIn>::end_of_input = state;
87         }
88
89   protected:
90         boost::shared_ptr<GraphSink<TOut> > piped_to;
91
92         /* process must process data,
93            use piped_to->write to write the data
94            and return number of frames written */
95         virtual nframes_t process (TIn * data, nframes_t frames) = 0;
96 };
97
98 } // namespace ARDOUR
99
100 #endif /* __ardour_graph_h__ */
101