sanitycheck should be looking for SCHED_FIFO
[ardour2.git] / gtk2_ardour / automation_controller.cc
blob5c00d5a779296f52362775104e60b7c17986fa27
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 <cmath>
24 #include "pbd/error.h"
26 #include "ardour/automation_list.h"
27 #include "ardour/automation_control.h"
28 #include "ardour/event_type_map.h"
29 #include "ardour/automatable.h"
30 #include "ardour/panner.h"
31 #include "ardour/pan_controllable.h"
32 #include "ardour/session.h"
34 #include "ardour_ui.h"
35 #include "utils.h"
36 #include "automation_controller.h"
37 #include "gui_thread.h"
39 #include "i18n.h"
41 using namespace ARDOUR;
42 using namespace Gtk;
44 AutomationController::AutomationController(boost::shared_ptr<Automatable> owner, boost::shared_ptr<AutomationControl> ac, Adjustment* adj)
45 : BarController (*adj, ac)
46 , _ignore_change(false)
47 , _owner (owner)
48 , _controllable(ac)
49 , _adjustment(adj)
51 set_name (X_("PluginSlider")); // FIXME: get yer own name!
52 set_style (BarController::LeftToRight);
53 set_use_parent (true);
55 StartGesture.connect (sigc::mem_fun(*this, &AutomationController::start_touch));
56 StopGesture.connect (sigc::mem_fun(*this, &AutomationController::end_touch));
58 _adjustment->signal_value_changed().connect (
59 sigc::mem_fun(*this, &AutomationController::value_adjusted));
61 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
62 sigc::mem_fun (*this, &AutomationController::display_effective_value));
64 ac->Changed.connect (_changed_connection, invalidator (*this), boost::bind (&AutomationController::value_changed, this), gui_context());
67 AutomationController::~AutomationController()
71 boost::shared_ptr<AutomationController>
72 AutomationController::create(
73 boost::shared_ptr<Automatable> parent,
74 const Evoral::Parameter& param,
75 boost::shared_ptr<AutomationControl> ac)
77 Gtk::Adjustment* adjustment = manage(new Gtk::Adjustment(param.normal(), param.min(), param.max()));
78 if (!ac) {
79 PBD::warning << "Creating AutomationController for " << EventTypeMap::instance().to_symbol(param) << endmsg;
80 ac = boost::dynamic_pointer_cast<AutomationControl>(parent->control_factory(param));
81 } else {
82 assert(ac->parameter() == param);
84 return boost::shared_ptr<AutomationController>(new AutomationController(parent, ac, adjustment));
87 std::string
88 AutomationController::get_label (double& xpos)
90 xpos = 0.5;
91 return _owner->value_as_string (_controllable);
94 void
95 AutomationController::display_effective_value()
97 float value = _controllable->get_value();
99 if (_adjustment->get_value() != value) {
100 _ignore_change = true;
101 _adjustment->set_value (value);
102 _ignore_change = false;
106 void
107 AutomationController::value_adjusted()
109 if (!_ignore_change) {
110 _controllable->set_value(_adjustment->get_value());
114 void
115 AutomationController::start_touch()
117 _controllable->start_touch (_controllable->session().transport_frame());
120 void
121 AutomationController::end_touch ()
123 if (_controllable->automation_state() == Touch) {
125 bool mark = false;
126 double when = 0;
128 if (_controllable->session().transport_rolling()) {
129 mark = true;
130 when = _controllable->session().transport_frame();
133 _controllable->stop_touch (mark, when);
137 void
138 AutomationController::automation_state_changed ()
140 ENSURE_GUI_THREAD (*this, &AutomationController::automation_state_changed)
142 bool x = (_controllable->automation_state() != Off);
144 /* start watching automation so that things move */
146 _screen_update_connection.disconnect();
148 if (x) {
149 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
150 sigc::mem_fun (*this, &AutomationController::display_effective_value));
154 void
155 AutomationController::value_changed ()
157 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationController::display_effective_value, this));
160 /** Stop updating our value from our controllable */
161 void
162 AutomationController::stop_updating ()
164 _screen_update_connection.disconnect ();