move ownership of an RT MIDI buffer from DiskIO to MidiPlaylist
[ardour.git] / libs / ardour / pan_controllable.cc
1 /*
2  * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2017-2019 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19
20 #include "ardour/pannable.h"
21 #include "ardour/panner.h"
22 #include "ardour/pan_controllable.h"
23
24 using namespace ARDOUR;
25
26 void
27 PanControllable::actually_set_value (double v, Controllable::GroupControlDisposition group_override)
28 {
29         boost::shared_ptr<Panner> p = owner->panner();
30
31         if (!p) {
32                 /* no panner: just do it */
33                 AutomationControl::actually_set_value (v, group_override);
34                 return;
35         }
36
37         bool can_set = false;
38
39         switch (parameter().type()) {
40                 case PanWidthAutomation:
41                         can_set = p->clamp_width (v);
42                         break;
43                 case PanAzimuthAutomation:
44                         can_set = p->clamp_position (v);
45                         break;
46                 case PanElevationAutomation:
47                         can_set = p->clamp_elevation (v);
48                         break;
49                 default:
50                         break;
51         }
52
53         if (can_set) {
54                 AutomationControl::actually_set_value (v, group_override);
55         }
56 }
57
58 std::string
59 PanControllable::get_user_string () const
60 {
61         if (!owner) {
62                 /* assume PanAzimuthAutomation, 0..1 */
63                 float v = get_value ();
64                 char buf[32];
65                 snprintf(buf, sizeof(buf), "%.0f%%", 100.f * v);
66                 return buf;
67         }
68         return owner->value_as_string (boost::dynamic_pointer_cast<const AutomationControl>(shared_from_this()));
69 }