2 Copyright (C) 2010 Paul Davis
3 Copyright (C) 2017 Robin Gareus <robin@gareus.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef __ardour_graph_h__
23 #define __ardour_graph_h__
30 #include <boost/shared_ptr.hpp>
34 #include "pbd/semutils.h"
36 #include "ardour/libardour_visibility.h"
37 #include "ardour/types.h"
38 #include "ardour/audio_backend.h"
39 #include "ardour/session_handle.h"
51 typedef boost::shared_ptr<GraphNode> node_ptr_t;
53 typedef std::list< node_ptr_t > node_list_t;
54 typedef std::set< node_ptr_t > node_set_t;
56 class LIBARDOUR_API Graph : public SessionHandleRef
59 Graph (Session & session);
61 void trigger (GraphNode * n);
62 void rechain (boost::shared_ptr<RouteList>, GraphEdges const &);
64 void dump (int chain);
69 int process_routes (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool& need_butler);
71 int routes_no_roll (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool non_rt_pending );
73 void process_one_route (Route * route);
75 void clear_other_chain ();
77 bool in_process_thread () const;
80 virtual void session_going_away ();
83 volatile bool _threads_active;
85 void reset_thread_list ();
92 node_list_t _nodes_rt[2];
94 node_list_t _init_trigger_list[2];
96 std::vector<GraphNode *> _trigger_queue;
97 pthread_mutex_t _trigger_mutex;
99 PBD::Semaphore _execution_sem;
101 /** Signalled to start a run of the graph for a process callback */
102 PBD::Semaphore _callback_start_sem;
103 PBD::Semaphore _callback_done_sem;
105 /** The number of processing threads that are asleep */
106 volatile gint _execution_tokens;
107 /** The number of unprocessed nodes that do not feed any other node; updated during processing */
108 volatile gint _finished_refcount;
109 /** The initial number of nodes that do not feed any other node (for each chain) */
110 volatile gint _init_finished_refcount[2];
115 Glib::Threads::Mutex _swap_mutex;
116 Glib::Threads::Cond _cleanup_cond;
118 volatile int _current_chain;
119 volatile int _pending_chain;
120 volatile int _setup_chain;
122 /* parameter caches */
123 pframes_t _process_nframes;
124 samplepos_t _process_start_sample;
125 samplepos_t _process_end_sample;
126 bool _process_can_record;
127 bool _process_non_rt_pending;
129 bool _process_noroll;
131 bool _process_need_butler;
133 /* engine / thread connection */
134 PBD::ScopedConnectionList engine_connections;
135 void engine_stopped ();
140 #endif /* __ardour_graph_h__ */