2 Copyright (C) 2007 Paul Davis
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 <pbd/error.h>
22 #include "ardour/automation_event.h"
23 #include "ardour/automation_control.h"
24 #include "ardour_ui.h"
26 #include "automation_controller.h"
27 #include "gui_thread.h"
31 using namespace ARDOUR;
35 AutomationController::AutomationController(boost::shared_ptr<AutomationControl> ac, Adjustment* adj)
36 : BarController(*adj, *ac)
37 , _ignore_change(false)
41 set_name (X_("PluginSlider")); // FIXME: get yer own name!
42 set_style (BarController::LeftToRight);
43 set_use_parent (true);
45 label_callback = sigc::mem_fun(this, &AutomationController::update_label);
47 StartGesture.connect (mem_fun(*this, &AutomationController::start_touch));
48 StopGesture.connect (mem_fun(*this, &AutomationController::end_touch));
50 _adjustment->signal_value_changed().connect (
51 mem_fun(*this, &AutomationController::value_adjusted));
53 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
54 mem_fun (*this, &AutomationController::display_effective_value));
56 ac->Changed.connect (mem_fun(*this, &AutomationController::value_changed));
59 AutomationController::~AutomationController()
63 boost::shared_ptr<AutomationController>
64 AutomationController::create(boost::shared_ptr<Automatable> parent, boost::shared_ptr<AutomationList> al, boost::shared_ptr<AutomationControl> ac)
66 Gtk::Adjustment* adjustment = manage(new Gtk::Adjustment(al->default_value(), al->get_min_y(), al->get_max_y()));
68 PBD::warning << "Creating AutomationController for " << al->parameter().to_string() << endmsg;
69 ac = parent->control_factory(al);
71 return boost::shared_ptr<AutomationController>(new AutomationController(ac, adjustment));
75 AutomationController::update_label(char* label, int label_len)
77 if (label && label_len)
78 // Hack to display CC rounded to int
79 if (_controllable->parameter().type() == MidiCCAutomation)
80 snprintf(label, label_len, "%d", (int)_controllable->get_value());
82 snprintf(label, label_len, "%.3f", _controllable->get_value());
86 AutomationController::display_effective_value()
88 //if ( ! _controllable->list()->automation_playback())
91 float value = _controllable->get_value();
93 if (_adjustment->get_value() != value) {
94 _ignore_change = true;
95 _adjustment->set_value (value);
96 _ignore_change = false;
101 AutomationController::value_adjusted()
103 if (!_ignore_change) {
104 _controllable->set_value(_adjustment->get_value());
109 AutomationController::start_touch()
111 _controllable->list()->start_touch();
115 AutomationController::end_touch()
117 _controllable->list()->stop_touch();
121 AutomationController::automation_state_changed ()
123 ENSURE_GUI_THREAD(mem_fun(*this, &AutomationController::automation_state_changed));
125 bool x = (_controllable->list()->automation_state() != Off);
127 /* start watching automation so that things move */
129 _screen_update_connection.disconnect();
132 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
133 mem_fun (*this, &AutomationController::display_effective_value));
138 AutomationController::value_changed ()
140 Gtkmm2ext::UI::instance()->call_slot (
141 mem_fun(*this, &AutomationController::display_effective_value));