Remove idiocy.
[ardour2.git] / gtk2_ardour / automation_controller.cc
blob5d601cd829d60f52f470db2efd7db4dbd3747d36
1 /*
2 Copyright (C) 2007 Paul Davis
3 Author: Dave 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.
21 #include <iomanip>
22 #include "pbd/error.h"
23 #include "ardour/automation_list.h"
24 #include "ardour/automation_control.h"
25 #include "ardour/event_type_map.h"
26 #include "ardour/automatable.h"
27 #include "ardour_ui.h"
28 #include "utils.h"
29 #include "automation_controller.h"
30 #include "gui_thread.h"
32 #include "i18n.h"
34 using namespace ARDOUR;
35 using namespace Gtk;
38 AutomationController::AutomationController(boost::shared_ptr<AutomationControl> ac, Adjustment* adj)
39 : BarController (*adj, ac)
40 , _ignore_change(false)
41 , _controllable(ac)
42 , _adjustment(adj)
44 set_name (X_("PluginSlider")); // FIXME: get yer own name!
45 set_style (BarController::LeftToRight);
46 set_use_parent (true);
48 StartGesture.connect (mem_fun(*this, &AutomationController::start_touch));
49 StopGesture.connect (mem_fun(*this, &AutomationController::end_touch));
51 _adjustment->signal_value_changed().connect (
52 mem_fun(*this, &AutomationController::value_adjusted));
54 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
55 mem_fun (*this, &AutomationController::display_effective_value));
57 ac->Changed.connect (mem_fun(*this, &AutomationController::value_changed));
60 AutomationController::~AutomationController()
64 boost::shared_ptr<AutomationController>
65 AutomationController::create(
66 boost::shared_ptr<Automatable> parent,
67 const Evoral::Parameter& param,
68 boost::shared_ptr<AutomationControl> ac)
70 Gtk::Adjustment* adjustment = manage(new Gtk::Adjustment(param.normal(), param.min(), param.max()));
71 if (!ac) {
72 PBD::warning << "Creating AutomationController for " << EventTypeMap::instance().to_symbol(param) << endmsg;
73 ac = boost::dynamic_pointer_cast<AutomationControl>(parent->control_factory(param));
74 } else {
75 assert(ac->parameter() == param);
77 return boost::shared_ptr<AutomationController>(new AutomationController(ac, adjustment));
80 std::string
81 AutomationController::get_label (int&)
83 std::stringstream s;
85 // Hack to display CC rounded to int
86 if (_controllable->parameter().type() == MidiCCAutomation) {
87 s << (int)_controllable->get_value();
88 } else {
89 s << std::fixed << std::setprecision(3) << _controllable->get_value();
92 return s.str ();
95 void
96 AutomationController::display_effective_value()
98 //if ( ! _controllable->list()->automation_playback())
99 // return;
101 float value = _controllable->get_value();
103 if (_adjustment->get_value() != value) {
104 _ignore_change = true;
105 _adjustment->set_value (value);
106 _ignore_change = false;
110 void
111 AutomationController::value_adjusted()
113 if (!_ignore_change) {
114 _controllable->set_value(_adjustment->get_value());
118 void
119 AutomationController::start_touch()
121 _controllable->start_touch();
124 void
125 AutomationController::end_touch()
127 _controllable->stop_touch();
130 void
131 AutomationController::automation_state_changed ()
133 ENSURE_GUI_THREAD(mem_fun(*this, &AutomationController::automation_state_changed));
135 bool x = (_controllable->automation_state() != Off);
137 /* start watching automation so that things move */
139 _screen_update_connection.disconnect();
141 if (x) {
142 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
143 mem_fun (*this, &AutomationController::display_effective_value));
147 void
148 AutomationController::value_changed ()
150 Gtkmm2ext::UI::instance()->call_slot (
151 mem_fun(*this, &AutomationController::display_effective_value));