2 Copyright (C) 2007 Paul Davis
3 Author: David Robillard
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "pbd/error.h"
26 #include "ardour/automatable.h"
27 #include "ardour/automation_control.h"
28 #include "ardour/session.h"
30 #include "ardour_ui.h"
31 #include "automation_controller.h"
32 #include "gui_thread.h"
36 using namespace ARDOUR;
39 AutomationController::AutomationController(boost::shared_ptr<Automatable> printer, boost::shared_ptr<AutomationControl> ac, Adjustment* adj)
40 : BarController (*adj, ac)
41 , _ignore_change(false)
48 set_name (X_("ProcessorControlSlider"));
50 StartGesture.connect (sigc::mem_fun(*this, &AutomationController::start_touch));
51 StopGesture.connect (sigc::mem_fun(*this, &AutomationController::end_touch));
53 _adjustment->signal_value_changed().connect (
54 sigc::mem_fun(*this, &AutomationController::value_adjusted));
56 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
57 sigc::mem_fun (*this, &AutomationController::display_effective_value));
59 ac->Changed.connect (_changed_connection, invalidator (*this), boost::bind (&AutomationController::value_changed, this), gui_context());
62 AutomationController::~AutomationController()
66 boost::shared_ptr<AutomationController>
67 AutomationController::create(
68 boost::shared_ptr<Automatable> printer,
69 const Evoral::Parameter& param,
70 boost::shared_ptr<AutomationControl> ac)
72 double const lo = ac->internal_to_interface(param.min());
73 double const up = ac->internal_to_interface(param.max());
74 Gtk::Adjustment* adjustment = manage (
76 ac->internal_to_interface(param.normal()),
78 // TODO we should use explicit step-sizes if provided by Plugin::ParameterDescriptor
79 (up - lo) / 100, (up - lo) / 10
84 assert(ac->parameter() == param);
85 return boost::shared_ptr<AutomationController>(new AutomationController(printer, ac, adjustment));
89 AutomationController::get_label (double& xpos)
92 return _printer->value_as_string (_controllable);
96 AutomationController::display_effective_value()
98 double const interface_value = _controllable->internal_to_interface(_controllable->get_value());
100 if (_adjustment->get_value () != interface_value) {
101 _ignore_change = true;
102 _adjustment->set_value (interface_value);
103 _ignore_change = false;
108 AutomationController::value_adjusted ()
110 if (!_ignore_change) {
111 _controllable->set_value (_controllable->interface_to_internal(_adjustment->get_value()));
116 AutomationController::start_touch()
118 _controllable->start_touch (_controllable->session().transport_frame());
122 AutomationController::end_touch ()
124 if (!_controllable->alist()) return;
125 if (_controllable->automation_state() == Touch) {
130 if (_controllable->session().transport_rolling()) {
132 when = _controllable->session().transport_frame();
135 _controllable->stop_touch (mark, when);
140 AutomationController::value_changed ()
142 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationController::display_effective_value, this));
145 /** Stop updating our value from our controllable */
147 AutomationController::stop_updating ()
149 _screen_update_connection.disconnect ();