1 /*
2  * Copyright (C) 2006-2009 David Robillard <d@drobilla.net>
3  * Copyright (C) 2007-2017 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
5  * Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
6  * Copyright (C) 2018 Len Ovens <len@ovenwerks.net>
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_send_h__
24 #define __ardour_send_h__
25 
26 #include <string>
27 
28 #include "pbd/stateful.h"
29 
30 #include "ardour/ardour.h"
31 #include "ardour/delivery.h"
32 
33 namespace ARDOUR {
34 
35 class PeakMeter;
36 class Amp;
37 class GainControl;
38 class DelayLine;
39 
40 /** Internal Abstraction for Sends (and MixbusSends) */
41 class LIBARDOUR_API LatentSend
42 {
43 public:
44 	LatentSend ();
~LatentSend()45 	virtual ~LatentSend() {}
46 
get_delay_in()47 	samplecnt_t get_delay_in () const { return _delay_in; }
get_delay_out()48 	samplecnt_t get_delay_out () const { return _delay_out; }
49 
50 	/* should only be called by Route::update_signal_latency */
51 	virtual void set_delay_in (samplecnt_t) = 0;
52 
53 	/* should only be called by InternalReturn::set_playback_offset
54 	 * (via Route::update_signal_latency)
55 	 */
56 	virtual void set_delay_out (samplecnt_t, size_t bus = 0) = 0;
57 
58 	static PBD::Signal0<void> ChangedLatency;
59 
60 protected:
61 	samplecnt_t _delay_in;
62 	samplecnt_t _delay_out;
63 };
64 
65 class LIBARDOUR_API Send : public Delivery, public LatentSend
66 {
67 public:
68 	Send (Session&, boost::shared_ptr<Pannable> pannable, boost::shared_ptr<MuteMaster>, Delivery::Role r = Delivery::Send, bool ignore_bitslot = false);
69 	virtual ~Send ();
70 
71 	bool display_to_user() const;
is_foldback()72 	bool is_foldback () const { return _role == Foldback; }
73 
amp()74 	boost::shared_ptr<Amp> amp() const { return _amp; }
meter()75 	boost::shared_ptr<PeakMeter> meter() const { return _meter; }
gain_control()76 	boost::shared_ptr<GainControl> gain_control() const { return _gain_control; }
77 
metering()78 	bool metering() const { return _metering; }
set_metering(bool yn)79 	void set_metering (bool yn) { _metering = yn; }
80 
81 	int set_state(const XMLNode&, int version);
82 
83 	PBD::Signal0<void> SelfDestruct;
set_remove_on_disconnect(bool b)84 	void set_remove_on_disconnect (bool b) { _remove_on_disconnect = b; }
remove_on_disconnect()85 	bool remove_on_disconnect () const { return _remove_on_disconnect; }
86 
87 	bool has_panner () const;
88 	bool panner_linked_to_route () const;
89 	void set_panner_linked_to_route (bool);
90 
pans_required()91 	uint32_t pans_required() const { return _configured_input.n_audio(); }
92 
93 	void run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double speed, pframes_t nframes, bool);
94 
95 	bool can_support_io_configuration (const ChanCount& in, ChanCount& out);
96 	bool configure_io (ChanCount in, ChanCount out);
97 
98 	/* latency compensation */
99 	void set_delay_in (samplecnt_t);
100 	void set_delay_out (samplecnt_t, size_t bus = 0);
get_delay_in()101 	samplecnt_t get_delay_in () const { return _delay_in; }
get_delay_out()102 	samplecnt_t get_delay_out () const { return _delay_out; }
103 	samplecnt_t signal_latency () const;
104 
105 	void activate ();
106 	void deactivate ();
107 
108 	bool set_name (const std::string& str);
109 
110 	static std::string name_and_id_new_send (Session&, Delivery::Role r, uint32_t&, bool);
111 
112 protected:
113 	XMLNode& state ();
114 
115 	bool _metering;
116 	boost::shared_ptr<GainControl> _gain_control;
117 	boost::shared_ptr<Amp> _amp;
118 	boost::shared_ptr<PeakMeter> _meter;
119 	boost::shared_ptr<DelayLine> _send_delay;
120 	boost::shared_ptr<DelayLine> _thru_delay;
121 
122 private:
123 	/* disallow copy construction */
124 	Send (const Send&);
125 
126 	void panshell_changed ();
127 	void pannable_changed ();
128 	void snd_output_changed (IOChange, void*);
129 
130 	void update_delaylines ();
131 
132 	int set_state_2X (XMLNode const &, int);
133 
134 	bool _remove_on_disconnect;
135 };
136 
137 } // namespace ARDOUR
138 
139 #endif /* __ardour_send_h__ */
140