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/compose.h"
25 #include "pbd/error.h"
27 #include "ardour/automatable.h"
28 #include "ardour/automation_control.h"
29 #include "ardour/session.h"
30 #include "ardour/tempo.h"
32 #include "ardour_ui.h"
33 #include "automation_controller.h"
34 #include "gui_thread.h"
35 #include "note_select_dialog.h"
39 using namespace ARDOUR;
42 AutomationController::AutomationController(boost::shared_ptr<Automatable> printer,
43 boost::shared_ptr<AutomationControl> ac,
45 : BarController (*adj, ac)
46 , _ignore_change(false)
53 set_name (X_("ProcessorControlSlider"));
55 StartGesture.connect (sigc::mem_fun(*this, &AutomationController::start_touch));
56 StopGesture.connect (sigc::mem_fun(*this, &AutomationController::end_touch));
58 signal_button_release_event().connect(
59 sigc::mem_fun(*this, &AutomationController::on_button_release));
61 _adjustment->signal_value_changed().connect (
62 sigc::mem_fun(*this, &AutomationController::value_adjusted));
64 _screen_update_connection = ARDOUR_UI::RapidScreenUpdate.connect (
65 sigc::mem_fun (*this, &AutomationController::display_effective_value));
67 ac->Changed.connect (_changed_connection, invalidator (*this), boost::bind (&AutomationController::value_changed, this), gui_context());
70 AutomationController::~AutomationController()
74 boost::shared_ptr<AutomationController>
75 AutomationController::create(boost::shared_ptr<Automatable> printer,
76 const Evoral::Parameter& param,
77 const ParameterDescriptor& desc,
78 boost::shared_ptr<AutomationControl> ac)
80 const double lo = ac->internal_to_interface(desc.lower);
81 const double up = ac->internal_to_interface(desc.upper);
82 const double normal = ac->internal_to_interface(desc.normal);
83 double smallstep = desc.smallstep;
84 double largestep = desc.largestep;
85 if (smallstep == 0.0) {
86 smallstep = (up - lo) / 100;
88 if (largestep == 0.0) {
89 largestep = (up - lo) / 10;
91 smallstep = ac->internal_to_interface(smallstep);
92 largestep = ac->internal_to_interface(largestep);
94 Gtk::Adjustment* adjustment = manage (
95 new Gtk::Adjustment (normal, lo, up, smallstep, largestep));
98 assert(ac->parameter() == param);
99 return boost::shared_ptr<AutomationController>(new AutomationController(printer, ac, adjustment));
103 AutomationController::get_label (double& xpos)
106 return _printer->value_as_string (_controllable);
110 AutomationController::display_effective_value()
112 double const interface_value = _controllable->internal_to_interface(_controllable->get_value());
114 if (_adjustment->get_value () != interface_value) {
115 _ignore_change = true;
116 _adjustment->set_value (interface_value);
117 _ignore_change = false;
122 AutomationController::value_adjusted ()
124 if (!_ignore_change) {
125 _controllable->set_value (_controllable->interface_to_internal(_adjustment->get_value()));
130 AutomationController::start_touch()
132 _controllable->start_touch (_controllable->session().transport_frame());
136 AutomationController::end_touch ()
138 if (!_controllable->alist()) return;
139 if (_controllable->automation_state() == Touch) {
144 if (_controllable->session().transport_rolling()) {
146 when = _controllable->session().transport_frame();
149 _controllable->stop_touch (mark, when);
154 AutomationController::run_note_select_dialog()
156 NoteSelectDialog* dialog = new NoteSelectDialog();
157 if (dialog->run() == Gtk::RESPONSE_ACCEPT) {
158 _controllable->set_value(dialog->note_number());
164 AutomationController::set_freq_beats(double beats)
166 const ARDOUR::Session& session = _controllable->session();
167 const ARDOUR::Tempo& tempo = session.tempo_map().tempo_at(0);
168 const double bpm = tempo.beats_per_minute();
169 const double bps = bpm / 60.0;
170 _controllable->set_value(bps / beats);
174 AutomationController::set_ratio(double ratio)
176 _controllable->set_value(_controllable->get_value() * ratio);
180 AutomationController::on_button_release(GdkEventButton* ev)
182 using namespace Gtk::Menu_Helpers;
184 if (ev->button != 3) {
188 if (_controllable->desc().unit == ARDOUR::ParameterDescriptor::MIDI_NOTE) {
189 Gtk::Menu* menu = manage(new Menu());
190 MenuList& items = menu->items();
191 items.push_back(MenuElem(_("Select Note..."),
192 sigc::mem_fun(*this, &AutomationController::run_note_select_dialog)));
193 menu->popup(1, ev->time);
195 } else if (_controllable->desc().unit == ARDOUR::ParameterDescriptor::HZ) {
196 Gtk::Menu* menu = manage(new Menu());
197 MenuList& items = menu->items();
198 items.push_back(MenuElem(_("Halve"),
199 sigc::bind(sigc::mem_fun(*this, &AutomationController::set_ratio),
201 items.push_back(MenuElem(_("Double"),
202 sigc::bind(sigc::mem_fun(*this, &AutomationController::set_ratio),
204 for (double beats = 1.0; beats <= 16; ++beats) {
205 items.push_back(MenuElem(string_compose(_("Set to %1 beat(s)"), (int)beats),
206 sigc::bind(sigc::mem_fun(*this, &AutomationController::set_freq_beats),
209 menu->popup(1, ev->time);
217 AutomationController::value_changed ()
219 Gtkmm2ext::UI::instance()->call_slot (invalidator (*this), boost::bind (&AutomationController::display_effective_value, this));
222 /** Stop updating our value from our controllable */
224 AutomationController::stop_updating ()
226 _screen_update_connection.disconnect ();