af3c1c0df2263e4fe4919c1599befeb496fbac4b
[ardour.git] / libs / panners / vbap / vbap.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 #ifndef __libardour_vbap_h__
20 #define __libardour_vbap_h__
21
22 #include <string>
23 #include <map>
24
25 #include "pbd/cartesian.h"
26
27 #include "ardour/panner.h"
28 #include "ardour/panner_shell.h"
29
30 #include "vbap_speakers.h"
31
32 namespace ARDOUR {
33
34 class Speakers;
35 class Pannable;
36
37 class VBAPanner : public Panner 
38
39 public:
40         VBAPanner (boost::shared_ptr<Pannable>, boost::shared_ptr<Speakers>);
41         ~VBAPanner ();
42
43         void configure_io (ChanCount in, ChanCount /* ignored - we use Speakers */);
44         ChanCount in() const;
45         ChanCount out() const;
46
47         std::set<Evoral::Parameter> what_can_be_automated() const;
48
49         static Panner* factory (boost::shared_ptr<Pannable>, boost::shared_ptr<Speakers>);
50
51         void distribute (BufferSet& ibufs, BufferSet& obufs, gain_t gain_coeff, pframes_t nframes);
52
53         void set_azimuth_elevation (double azimuth, double elevation);
54
55         std::string describe_parameter (Evoral::Parameter);
56         std::string value_as_string (boost::shared_ptr<AutomationControl>) const;
57
58         XMLNode& state (bool full_state);
59         XMLNode& get_state ();
60         int set_state (const XMLNode&, int version);
61
62         PBD::AngularVector signal_position (uint32_t n) const;
63         boost::shared_ptr<Speakers> get_speakers() const;
64
65 private:
66         struct Signal {
67             PBD::AngularVector direction;
68             double gains[3];
69             double desired_gains[3];
70             int    outputs[3];
71             int    desired_outputs[3];
72
73             Signal (Session&, VBAPanner&, uint32_t which);
74         };
75
76         std::vector<Signal*> _signals;
77         boost::shared_ptr<VBAPSpeakers>  _speakers;
78         
79         void compute_gains (double g[3], int ls[3], int azi, int ele);
80         void update ();
81         void clear_signals ();
82
83         void distribute_one (AudioBuffer& src, BufferSet& obufs, gain_t gain_coeff, pframes_t nframes, uint32_t which);
84         void distribute_one_automated (AudioBuffer& src, BufferSet& obufs,
85                                           framepos_t start, framepos_t end, pframes_t nframes, 
86                                           pan_t** buffers, uint32_t which);
87 };
88
89 } /* namespace */
90
91 #endif /* __libardour_vbap_h__ */