Ardour  9.0-pre0-427-gd2a3450e2f
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 #pragma once
24 
25 #include <atomic>
26 #include <list>
27 #include <memory>
28 #include <set>
29 #include <string>
30 #include <vector>
31 
32 
33 #include "pbd/mpmc_queue.h"
34 #include "pbd/semutils.h"
35 
36 #include "ardour/audio_backend.h"
38 #include "ardour/session_handle.h"
39 #include "ardour/types.h"
40 
41 namespace ARDOUR
42 {
43 class ProcessNode;
44 class GraphNode;
45 class Graph;
46 
47 class IOPlug;
48 class Route;
49 class RTTaskList;
50 class Session;
51 class GraphEdges;
52 
53 typedef std::shared_ptr<GraphNode> node_ptr_t;
54 
55 typedef std::list<node_ptr_t> node_list_t;
56 typedef std::set<node_ptr_t> node_set_t;
57 
58 struct GraphChain {
61  void dump () const;
62  bool plot (std::string const&) const;
63 
69 };
70 
72 {
73 public:
75 
76  /* public API for use by session-process */
77  int process_routes (std::shared_ptr<GraphChain> chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler);
78  int routes_no_roll (std::shared_ptr<GraphChain> chain, pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool non_rt_pending);
79  int silence_routes (std::shared_ptr<GraphChain> chain, pframes_t nframes);
80  int process_io_plugs (std::shared_ptr<GraphChain> chain, pframes_t nframes, samplepos_t start_sample);
81 
82  bool in_process_thread () const;
83  uint32_t n_threads () const;
84 
85  /* called by GraphNode */
86  void trigger (ProcessNode* n);
88 
89  /* called by virtual GraphNode::process() */
90  void process_one_route (Route* route);
92 
93  /* RTTasks */
95 
96 protected:
97  virtual void session_going_away ();
98 
99 private:
101  void drop_threads ();
102  void run_one ();
103  void main_thread ();
104  void prep ();
105 
106  void helper_thread ();
107 
109  std::atomic<uint32_t> _trigger_queue_size;
110 
113 
115  std::atomic<uint32_t> _idle_thread_cnt;
116 
120 
122  std::atomic<uint32_t> _terminal_refcnt;
123 
125 
126  /* number of background worker threads >= 0 */
127  std::atomic<uint32_t> _n_workers;
128 
129  /* flag to terminate background threads */
130  std::atomic<int> _terminate;
131 
132  /* graph chain */
134 
135  /* parameter caches */
140 
141  enum ProcessMode {
142  Roll, NoRoll, Silence
143  } _process_mode;
144 
147 
148  /* engine / thread connection */
150  void engine_stopped ();
151 };
152 
153 } // namespace ARDOUR
154 
bool _graph_empty
Definition: graph.h:124
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:146
void process_one_ioplug(IOPlug *)
void drop_threads()
void process_one_route(Route *route)
void reached_terminal_node()
int _process_retval
Definition: graph.h:145
bool _process_non_rt_pending
Definition: graph.h:139
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:119
uint32_t n_threads() const
virtual void session_going_away()
pframes_t _process_nframes
Definition: graph.h:136
std::atomic< uint32_t > _idle_thread_cnt
Definition: graph.h:115
samplepos_t _process_start_sample
Definition: graph.h:137
void reset_thread_list()
samplepos_t _process_end_sample
Definition: graph.h:138
PBD::Semaphore _callback_start_sem
Definition: graph.h:118
PBD::ScopedConnectionList engine_connections
Definition: graph.h:149
std::atomic< uint32_t > _terminal_refcnt
Definition: graph.h:122
void main_thread()
std::atomic< uint32_t > _trigger_queue_size
number of entries in trigger-queue
Definition: graph.h:109
int silence_routes(std::shared_ptr< GraphChain > chain, pframes_t nframes)
std::atomic< uint32_t > _n_workers
Definition: graph.h:127
PBD::MPMCQueue< ProcessNode * > _trigger_queue
nodes that can be processed
Definition: graph.h:108
GraphChain const * _graph_chain
Definition: graph.h:133
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:130
bool in_process_thread() const
void trigger(ProcessNode *n)
void engine_stopped()
PBD::Semaphore _execution_sem
Definition: graph.h:112
#define LIBARDOUR_API
void session(lua_State *L)
uint32_t pframes_t
std::list< node_ptr_t > node_list_t
Definition: graph.h:55
std::shared_ptr< GraphNode > node_ptr_t
Definition: graph.h:51
std::list< std::shared_ptr< GraphNode > > GraphNodeList
std::set< node_ptr_t > node_set_t
Definition: graph.h:56
Temporal::samplepos_t samplepos_t
DebugBits Graph
bool plot(std::string const &) const
node_list_t _nodes_rt
Definition: graph.h:64
GraphChain(GraphNodeList const &, GraphEdges const &)
int _n_terminal_nodes
Definition: graph.h:68
void dump() const
node_list_t _init_trigger_list
Definition: graph.h:66