Ardour  9.0-pre0-582-g084a23a80d
proxy_controllable.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2014 David Robillard <d@drobilla.net>
3  * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
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 #pragma once
21 
22 
23 #include <functional>
24 
25 #include "pbd/controllable.h"
26 
27 #include "ardour/dB.h"
29 
30 namespace ARDOUR {
31 
37  public:
38  ProxyControllable (const std::string& name, PBD::Controllable::Flag flags,
39  std::function<bool (double)> setter,
40  std::function<double ()> getter)
41  : PBD::Controllable (name, flags)
42  , _setter (setter)
43  , _getter (getter)
44  {}
45 
46  void set_value (double v, PBD::Controllable::GroupControlDisposition gcd) { if (_setter (v)) { Changed (true, gcd); /* EMIT SIGNAL */ } }
47  double get_value () const { return _getter (); }
48 
49  std::string get_user_string () const {
50  char theBuf[32]; sprintf( theBuf, "%3.1f dB", accurate_coefficient_to_dB (get_value()));
51  return std::string(theBuf);
52  }
53 
54  private:
55  std::function<bool (double)> _setter;
56  std::function<double ()> _getter;
57 };
58 
59 } // namespace
60 
std::string get_user_string() const
std::function< double()> _getter
std::function< bool(double)> _setter
ProxyControllable(const std::string &name, PBD::Controllable::Flag flags, std::function< bool(double)> setter, std::function< double()> getter)
void set_value(double v, PBD::Controllable::GroupControlDisposition gcd)
static float accurate_coefficient_to_dB(float coeff)
Definition: dB.h:39
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
std::shared_ptr< PBD::Controllable > Controllable
Definition: console1.h:80
Definition: axis_view.h:42