Ardour  8.12
graph.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2017 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2009-2014 David Robillard <d@drobilla.net>
4  * Copyright (C) 2010-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013 Tim Mayberry <mojofunk@gmail.com>
6  * Copyright (C) 2015-2019 Robin Gareus <robin@gareus.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #ifndef __ardour_graph_h__
24 #define __ardour_graph_h__
25 
26 #include <atomic>
27 #include <list>
28 #include <memory>
29 #include <set>
30 #include <string>
31 #include <vector>
32 
33 
34 #include "pbd/mpmc_queue.h"
35 #include "pbd/semutils.h"
36 
37 #include "ardour/audio_backend.h"
39 #include "ardour/session_handle.h"
40 #include "ardour/types.h"
41 
42 namespace ARDOUR
43 {
44 class ProcessNode;
45 class GraphNode;
46 class Graph;
47 
48 class IOPlug;
49 class Route;
50 class RTTaskList;
51 class Session;
52 class GraphEdges;
53 
54 typedef std::shared_ptr<GraphNode> node_ptr_t;
55 
56 typedef std::list<node_ptr_t> node_list_t;
57 typedef std::set<node_ptr_t> node_set_t;
58 
59 struct GraphChain {
62  void dump () const;
63  bool plot (std::string const&) const;
64 
70 };
71 
73 {
74 public:
76 
77  /* public API for use by session-process */
78  int process_routes (std::shared_ptr<GraphChain> chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler);
79  int routes_no_roll (std::shared_ptr<GraphChain> chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool non_rt_pending);
80  int silence_routes (std::shared_ptr<GraphChain> chain, pframes_t nframes);
81  int process_io_plugs (std::shared_ptr<GraphChain> chain, pframes_t nframes, samplepos_t start_sample);
82 
83  bool in_process_thread () const;
84  uint32_t n_threads () const;
85 
86  /* called by GraphNode */
87  void trigger (ProcessNode* n);
89 
90  /* called by virtual GraphNode::process() */
91  void process_one_route (Route* route);
93 
94  /* RTTasks */
96 
97 protected:
98  virtual void session_going_away ();
99 
100 private:
102  void drop_threads ();
103  void run_one ();
104  void main_thread ();
105  void prep ();
106 
107  void helper_thread ();
108 
110  std::atomic<uint32_t> _trigger_queue_size;
111 
114 
116  std::atomic<uint32_t> _idle_thread_cnt;
117 
121 
123  std::atomic<uint32_t> _terminal_refcnt;
124 
126 
127  /* number of background worker threads >= 0 */
128  std::atomic<uint32_t> _n_workers;
129 
130  /* flag to terminate background threads */
131  std::atomic<int> _terminate;
132 
133  /* graph chain */
135 
136  /* parameter caches */
141 
142  enum ProcessMode {
143  Roll, NoRoll, Silence
144  } _process_mode;
145 
148 
149  /* engine / thread connection */
151  void engine_stopped ();
152 };
153 
154 } // namespace ARDOUR
155 
156 #endif /* __ardour_graph_h__ */
bool _graph_empty
Definition: graph.h:125
void helper_thread()
void process_tasklist(RTTaskList const &)
int process_routes(std::shared_ptr< GraphChain > chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool &need_butler)
bool _process_need_butler
Definition: graph.h:147
void process_one_ioplug(IOPlug *)
void drop_threads()
void process_one_route(Route *route)
void reached_terminal_node()
int _process_retval
Definition: graph.h:146
bool _process_non_rt_pending
Definition: graph.h:140
int routes_no_roll(std::shared_ptr< GraphChain > chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool non_rt_pending)
PBD::Semaphore _callback_done_sem
Definition: graph.h:120
uint32_t n_threads() const
virtual void session_going_away()
pframes_t _process_nframes
Definition: graph.h:137
std::atomic< uint32_t > _idle_thread_cnt
Definition: graph.h:116
samplepos_t _process_start_sample
Definition: graph.h:138
void reset_thread_list()
samplepos_t _process_end_sample
Definition: graph.h:139
PBD::Semaphore _callback_start_sem
Definition: graph.h:119
PBD::ScopedConnectionList engine_connections
Definition: graph.h:150
std::atomic< uint32_t > _terminal_refcnt
Definition: graph.h:123
void main_thread()
std::atomic< uint32_t > _trigger_queue_size
number of entries in trigger-queue
Definition: graph.h:110
int silence_routes(std::shared_ptr< GraphChain > chain, pframes_t nframes)
std::atomic< uint32_t > _n_workers
Definition: graph.h:128
PBD::MPMCQueue< ProcessNode * > _trigger_queue
nodes that can be processed
Definition: graph.h:109
GraphChain const * _graph_chain
Definition: graph.h:134
Graph(Session &session)
int process_io_plugs(std::shared_ptr< GraphChain > chain, pframes_t nframes, samplepos_t start_sample)
std::atomic< int > _terminate
Definition: graph.h:131
bool in_process_thread() const
void trigger(ProcessNode *n)
void engine_stopped()
PBD::Semaphore _execution_sem
Definition: graph.h:113
A node in the hierarchical graph that represents a multiplicatable export item.
#define LIBARDOUR_API
void session(lua_State *L)
uint32_t pframes_t
std::list< node_ptr_t > node_list_t
Definition: graph.h:56
std::shared_ptr< GraphNode > node_ptr_t
Definition: graph.h:52
std::list< std::shared_ptr< GraphNode > > GraphNodeList
std::set< node_ptr_t > node_set_t
Definition: graph.h:57
Temporal::samplepos_t samplepos_t
DebugBits Graph
bool plot(std::string const &) const
node_list_t _nodes_rt
Definition: graph.h:65
GraphChain(GraphNodeList const &, GraphEdges const &)
int _n_terminal_nodes
Definition: graph.h:69
void dump() const
node_list_t _init_trigger_list
Definition: graph.h:67