add missing graph.cc and friends :S
[ardour.git] / libs / ardour / ardour / graph.h
1 /*
2     Copyright (C) 2010 Paul Davis
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
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20
21 #ifndef __ardour_graph_h__
22 #define __ardour_graph_h__
23
24
25 #include <list>
26 #include <set>
27 #include <vector>
28 #include <string>
29
30 #include <boost/shared_ptr.hpp>
31
32 #include <glib/gatomic.h>
33 #include <cassert>
34
35 #include <pthread.h>
36 #include <semaphore.h>
37
38 #include <ardour/types.h>
39 #include <ardour/session_handle.h>
40
41 namespace ARDOUR
42 {
43
44 class GraphNode;
45 class Graph;
46
47 class Route;
48 class Session;
49
50 typedef boost::shared_ptr<GraphNode> node_ptr_t;
51 typedef boost::shared_ptr<Graph> graph_ptr_t;
52
53 typedef std::list< node_ptr_t > node_list_t;
54 typedef std::set< node_ptr_t > node_set_t;
55
56
57
58 class Graph : public SessionHandleRef
59 {
60     public:
61         Graph( Session & session );
62
63         void prep();
64         void trigger( GraphNode * n );
65         void rechain( boost::shared_ptr<RouteList> r );
66
67         void dump( int chain );
68         void process();
69         void dec_ref();
70         void restart_cycle();
71
72         bool run_one();
73         void helper_thread();
74         void main_thread();
75
76         int silent_process_routes (nframes_t nframes, sframes_t start_frame, sframes_t end_frame,
77                 bool can_record, bool rec_monitors_input, bool& need_butler );
78
79         int process_routes (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, int declick,
80                 bool can_record, bool rec_monitors_input, bool& need_butler );
81
82         int routes_no_roll (nframes_t nframes, sframes_t start_frame, sframes_t end_frame, 
83                 bool non_rt_pending, bool can_record, int declick);
84
85         void process_one_route( Route * route );
86
87     protected:
88         virtual void session_going_away ();
89
90     private:
91         std::list<Glib::Thread *> _thread_list;
92         volatile bool _quit_threads;
93         
94         node_list_t _nodes;
95         node_list_t _nodes_rt[2];
96
97         node_list_t _init_trigger_list[2];
98
99         std::vector<GraphNode *> _trigger_queue;
100         pthread_mutex_t _trigger_mutex;
101
102
103         sem_t _execution_sem;
104
105         sem_t _callback_start_sem;
106         sem_t _callback_done_sem;
107
108         volatile gint _execution_tokens;
109         volatile gint _finished_refcount;
110         volatile gint _init_finished_refcount[2];
111
112         bool _graph_empty;
113
114         // chain swapping
115         pthread_mutex_t _swap_mutex;
116         volatile int _current_chain;
117         volatile int _pending_chain;
118         volatile int _setup_chain;
119
120         // parameter caches.
121         nframes_t       _process_nframes;
122         sframes_t       _process_start_frame;
123         sframes_t       _process_end_frame;
124         bool            _process_can_record;
125         bool            _process_rec_monitors_input;
126         bool            _process_non_rt_pending;
127         int             _process_declick;
128
129         bool            _process_silent;
130         bool            _process_noroll;
131         int             _process_retval;
132         bool            _process_need_butler;
133 };
134
135 }
136
137 #endif