ardour
panner.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004-2011 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 
20 #ifndef __ardour_panner_h__
21 #define __ardour_panner_h__
22 
23 #include <cmath>
24 #include <cassert>
25 #include <vector>
26 #include <string>
27 #include <iostream>
28 
29 #include "pbd/cartesian.h"
30 #include "pbd/signals.h"
31 #include "pbd/stateful.h"
32 
34 #include "ardour/types.h"
36 #include "ardour/automatable.h"
37 
38 
39 /* This section is for actual panners to use. They will include this file,
40  * declare ARDOURPANNER_DLL_EXPORTS during compilation, and ... voila.
41  */
42 
43 #ifdef ARDOURPANNER_DLL_EXPORTS // defined if we are building a panner implementation
44  #define ARDOURPANNER_API LIBARDOUR_DLL_EXPORT
45  #else
46  #define ARDOURPANNER_API LIBARDOUR_DLL_IMPORT
47  #endif
48 #define ARDOURPANNER_LOCAL LIBARDOUR_DLL_LOCAL
49 
50 namespace ARDOUR {
51 
52 class Session;
53 class Pannable;
54 class BufferSet;
55 class AudioBuffer;
56 class Speakers;
57 
59 {
60 public:
62  ~Panner ();
63 
65 
66  virtual ChanCount in() const = 0;
67  virtual ChanCount out() const = 0;
68 
69  virtual void configure_io (ARDOUR::ChanCount /*in*/, ARDOUR::ChanCount /*out*/) {}
70 
71  /* derived implementations of these methods must indicate
72  whether it is legal for a Controllable to use the
73  value of the argument (post-call) in a call to
74  Controllable::set_value().
75 
76  they have a choice of:
77 
78  * return true, leave argument unchanged
79  * return true, modify argument
80  * return false
81  */
82 
83  virtual bool clamp_position (double&) { return true; }
84  virtual bool clamp_width (double&) { return true; }
85  virtual bool clamp_elevation (double&) { return true; }
86 
87  virtual std::pair<double, double> position_range () const { return std::make_pair (-DBL_MAX, DBL_MAX); }
88  virtual std::pair<double, double> width_range () const { return std::make_pair (-DBL_MAX, DBL_MAX); }
89  virtual std::pair<double, double> elevation_range () const { return std::make_pair (-DBL_MAX, DBL_MAX); }
90 
91  virtual void set_position (double) { }
92  virtual void set_width (double) { }
93  virtual void set_elevation (double) { }
94 
95  virtual double position () const { return 0.0; }
96  virtual double width () const { return 0.0; }
97  virtual double elevation () const { return 0.0; }
98 
99  virtual PBD::AngularVector signal_position (uint32_t) const { return PBD::AngularVector(); }
100 
101  virtual void reset () = 0;
102 
103  /* azimut, width or elevation updated -> recalc signal_position -> emit Changed */
104  PBD::Signal0<void> SignalPositionChanged;
105 
106  void set_automation_state (AutoState);
107  AutoState automation_state() const;
108  void set_automation_style (AutoStyle);
109  AutoStyle automation_style() const;
110 
111  virtual std::set<Evoral::Parameter> what_can_be_automated() const;
112  virtual std::string describe_parameter (Evoral::Parameter);
113  virtual std::string value_as_string (boost::shared_ptr<AutomationControl>) const;
114 
115  bool touching() const;
116 
117  static double azimuth_to_lr_fract (double azi) {
118  /* 180.0 degrees=> left => 0.0 */
119  /* 0.0 degrees => right => 1.0 */
120 
121  /* humans can only distinguish 1 degree of arc between two positions,
122  so force azi back to an integral value before computing
123  */
124 
125  return 1.0 - (rint(azi)/180.0);
126  }
127 
128  static double lr_fract_to_azimuth (double fract) {
129  /* fract = 0.0 => degrees = 180.0 => left */
130  /* fract = 1.0 => degrees = 0.0 => right */
131 
132  /* humans can only distinguish 1 degree of arc between two positions,
133  so force azi back to an integral value after computing
134  */
135 
136  return rint (180.0 - (fract * 180.0));
137  }
138 
155  virtual void distribute (BufferSet& ibufs, BufferSet& obufs, gain_t gain_coeff, pframes_t nframes);
156  virtual void distribute_automated (BufferSet& ibufs, BufferSet& obufs,
157  framepos_t start, framepos_t end, pframes_t nframes,
158  pan_t** buffers);
159 
160  int set_state (const XMLNode&, int version);
161  XMLNode& get_state ();
162 
163  boost::shared_ptr<Pannable> pannable() const { return _pannable; }
164 
165  static bool equivalent (pan_t a, pan_t b) {
166  return fabsf (a - b) < 0.002; // about 1 degree of arc for a stereo panner
167  }
168 
169  static bool equivalent (const PBD::AngularVector& a, const PBD::AngularVector& b) {
170  /* XXX azimuth only, at present */
171  return fabs (a.azi - b.azi) < 1.0;
172  }
173 
174  virtual void freeze ();
175  virtual void thaw ();
176 
177 protected:
179 
180  virtual void distribute_one (AudioBuffer&, BufferSet& obufs, gain_t gain_coeff, pframes_t nframes, uint32_t which) = 0;
181  virtual void distribute_one_automated (AudioBuffer&, BufferSet& obufs,
182  framepos_t start, framepos_t end, pframes_t nframes,
183  pan_t** buffers, uint32_t which) = 0;
184 
185  int32_t _frozen;
186 };
187 
188 } // namespace
189 
190 extern "C" {
192  std::string name;
193  std::string panner_uri;
194  std::string gui_uri;
195  int32_t in;
196  int32_t out;
197  uint32_t priority;
199 };
200 }
201 
202 #endif /* __ardour_panner_h__ */
virtual void set_position(double)
Definition: panner.h:91
boost::shared_ptr< Pannable > pannable() const
Definition: panner.h:163
static bool equivalent(pan_t a, pan_t b)
Definition: panner.h:165
uint32_t priority
Definition: panner.h:197
virtual bool clamp_elevation(double &)
Definition: panner.h:85
virtual std::pair< double, double > elevation_range() const
Definition: panner.h:89
virtual void set_width(double)
Definition: panner.h:92
std::string panner_uri
Definition: panner.h:193
virtual void configure_io(ARDOUR::ChanCount, ARDOUR::ChanCount)
Definition: panner.h:69
std::string value_as_string(const ARDOUR::ParameterDescriptor &desc, double v)
float pan_t
Definition: types.h:57
PBD::Signal0< void > SignalPositionChanged
Definition: panner.h:104
uint32_t pframes_t
Definition: types.h:61
float gain_t
Definition: types.h:58
virtual boost::shared_ptr< Speakers > get_speakers() const
Definition: panner.h:64
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > start
Definition: region.cc:63
boost::shared_ptr< Pannable > _pannable
Definition: panner.h:178
AutoStyle
Definition: types.h:155
virtual double elevation() const
Definition: panner.h:97
static double lr_fract_to_azimuth(double fract)
Definition: panner.h:128
virtual double width() const
Definition: panner.h:96
std::string name
Definition: panner.h:192
static bool equivalent(const PBD::AngularVector &a, const PBD::AngularVector &b)
Definition: panner.h:169
Definition: amp.h:29
std::string gui_uri
Definition: panner.h:194
int64_t framepos_t
Definition: types.h:66
virtual bool clamp_width(double &)
Definition: panner.h:84
virtual std::pair< double, double > width_range() const
Definition: panner.h:88
#define LIBARDOUR_API
Definition: xml++.h:95
virtual void set_elevation(double)
Definition: panner.h:93
virtual bool clamp_position(double &)
Definition: panner.h:83
virtual std::pair< double, double > position_range() const
Definition: panner.h:87
static double azimuth_to_lr_fract(double azi)
Definition: panner.h:117
virtual double position() const
Definition: panner.h:95
virtual PBD::AngularVector signal_position(uint32_t) const
Definition: panner.h:99
int32_t _frozen
Definition: panner.h:185
AutoState
Definition: types.h:145