2 * Copyright (C) 2005-2006 Nick Mainsbridge <mainsbridge@gmail.com>
3 * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4 * Copyright (C) 2005-2017 Paul Davis <paul@linuxaudiosystems.com>
5 * Copyright (C) 2006-2007 Doug McLain <doug@nostar.net>
6 * Copyright (C) 2006-2012 David Robillard <d@drobilla.net>
7 * Copyright (C) 2006 Sampo Savolainen <v2@iki.fi>
8 * Copyright (C) 2008-2012 Carl Hetherington <carl@carlh.net>
9 * Copyright (C) 2012-2019 Robin Gareus <robin@gareus.org>
10 * Copyright (C) 2014-2015 Tim Mayberry <mojofunk@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <gtkmm2ext/utils.h>
31 #include "pbd/fastlog.h"
33 #include "ardour/pannable.h"
34 #include "ardour/panner.h"
35 #include "ardour/panner_shell.h"
36 #include "ardour/session.h"
38 #include "widgets/tooltips.h"
40 #include "gain_meter.h"
41 #include "panner_ui.h"
43 #include "gui_thread.h"
44 #include "stereo_panner.h"
46 #include "mono_panner.h"
47 #include "ui_config.h"
52 using namespace ARDOUR;
54 using namespace Gtkmm2ext;
57 PannerUI::PannerUI (Session* s)
62 , pan_automation_state_button ("")
67 ignore_toggle = false;
71 in_pan_update = false;
74 _ignore_width_change = false;
75 _ignore_position_change = false;
77 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
79 ArdourWidgets::set_tooltip (pan_automation_state_button, _("Pan automation mode"));
81 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
83 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
85 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
87 pan_vbox.set_spacing (2);
88 pack_start (pan_vbox, true, true);
97 PannerUI::set_panner (boost::shared_ptr<PannerShell> ps, boost::shared_ptr<Panner> p)
99 /* note that the panshell might not change here (i.e. ps == _panshell)
102 connections.drop_connections ();
104 delete pan_astyle_menu;
107 delete pan_astate_menu;
116 delete _stereo_panner;
126 _panshell->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panshell_changed, this), gui_context());
128 /* new panner object, force complete reset of panner GUI
135 update_pan_sensitive ();
136 pan_automation_state_changed ();
140 PannerUI::build_astate_menu ()
142 using namespace Menu_Helpers;
144 if (pan_astate_menu == 0) {
145 pan_astate_menu = new Menu;
146 pan_astate_menu->set_name ("ArdourContextMenu");
148 pan_astate_menu->items().clear ();
151 /** TRANSLATORS: this is `Manual' in the sense of automation not being played,
152 so that changes to pan must be done by hand.
154 pan_astate_menu->items().push_back (MenuElem (GainMeterBase::astate_string (ARDOUR::Off),
155 sigc::bind ( sigc::mem_fun (_panner.get(), &Panner::set_automation_state), (AutoState) ARDOUR::Off)));
156 pan_astate_menu->items().push_back (MenuElem (GainMeterBase::astate_string (ARDOUR::Play),
157 sigc::bind ( sigc::mem_fun (_panner.get(), &Panner::set_automation_state), (AutoState) Play)));
158 pan_astate_menu->items().push_back (MenuElem (GainMeterBase::astate_string (ARDOUR::Write),
159 sigc::bind ( sigc::mem_fun (_panner.get(), &Panner::set_automation_state), (AutoState) Write)));
160 pan_astate_menu->items().push_back (MenuElem (GainMeterBase::astate_string (ARDOUR::Touch),
161 sigc::bind (sigc::mem_fun (_panner.get(), &Panner::set_automation_state), (AutoState) Touch)));
162 pan_astate_menu->items().push_back (MenuElem (GainMeterBase::astate_string (ARDOUR::Latch),
163 sigc::bind ( sigc::mem_fun (_panner.get(), &Panner::set_automation_state), (AutoState) Latch)));
168 PannerUI::build_astyle_menu ()
170 using namespace Menu_Helpers;
172 if (pan_astyle_menu == 0) {
173 pan_astyle_menu = new Menu;
174 pan_astyle_menu->set_name ("ArdourContextMenu");
176 pan_astyle_menu->items().clear();
179 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
180 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
184 PannerUI::on_size_allocate (Allocation& a)
186 HBox::on_size_allocate (a);
190 PannerUI::set_width (Width w)
195 PannerUI::~PannerUI ()
200 delete pan_astyle_menu;
201 delete pan_astate_menu;
202 delete _stereo_panner;
207 PannerUI::panshell_changed ()
209 set_panner (_panshell, _panshell->panner());
214 PannerUI::setup_pan ()
216 int const nouts = _panner ? _panner->out().n_audio() : -1;
217 int const nins = _panner ? _panner->in().n_audio() : -1;
221 if (nouts == _current_nouts
222 && nins == _current_nins
223 && _current_uri == _panshell->panner_gui_uri()
229 _current_nins = nins;
230 _current_nouts = nouts;
231 _current_uri = _panshell->panner_gui_uri();
233 container_clear (pan_vbox);
237 delete _stereo_panner;
248 const float scale = std::max (1.f, UIConfiguration::instance().get_ui_scale());
250 if (_current_uri == "http://ardour.org/plugin/panner_2in2out#ui")
255 boost::shared_ptr<Pannable> pannable = _panner->pannable();
257 _stereo_panner = new StereoPanner (_panshell);
258 _stereo_panner->set_size_request (-1, 5 * ceilf(7.f * scale));
259 _stereo_panner->set_send_drawing_mode (_send_mode);
260 pan_vbox.pack_start (*_stereo_panner, false, false);
262 boost::shared_ptr<AutomationControl> ac;
264 ac = pannable->pan_azimuth_control;
265 _stereo_panner->StartPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
266 boost::weak_ptr<AutomationControl> (ac)));
267 _stereo_panner->StopPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
268 boost::weak_ptr<AutomationControl>(ac)));
270 ac = pannable->pan_width_control;
271 _stereo_panner->StartWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
272 boost::weak_ptr<AutomationControl> (ac)));
273 _stereo_panner->StopWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
274 boost::weak_ptr<AutomationControl>(ac)));
275 _stereo_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
277 else if (_current_uri == "http://ardour.org/plugin/panner_1in2out#ui"
278 || _current_uri == "http://ardour.org/plugin/panner_balance#ui")
282 boost::shared_ptr<Pannable> pannable = _panner->pannable();
283 boost::shared_ptr<AutomationControl> ac = pannable->pan_azimuth_control;
285 _mono_panner = new MonoPanner (_panshell);
287 _mono_panner->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
288 boost::weak_ptr<AutomationControl> (ac)));
289 _mono_panner->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
290 boost::weak_ptr<AutomationControl>(ac)));
292 _mono_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
294 _mono_panner->set_size_request (-1, 5 * ceilf(7.f * scale));
295 _mono_panner->set_send_drawing_mode (_send_mode);
297 update_pan_sensitive ();
298 pan_vbox.pack_start (*_mono_panner, false, false);
300 else if (_current_uri == "http://ardour.org/plugin/panner_vbap#ui")
303 twod_panner = new Panner2d (_panshell, rintf(61.f * scale));
304 twod_panner->set_name ("MixerPanZone");
305 twod_panner->show ();
306 twod_panner->signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event), false);
309 update_pan_sensitive ();
310 twod_panner->reset (nins);
312 big_window->reset (nins);
314 twod_panner->set_size_request (-1, rintf(61.f * scale));
315 twod_panner->set_send_drawing_mode (_send_mode);
317 /* and finally, add it to the panner frame */
319 pan_vbox.pack_start (*twod_panner, false, false);
323 /* stick something into the panning viewport so that it redraws */
324 EventBox* eb = manage (new EventBox());
325 pan_vbox.pack_start (*eb, false, false);
331 pan_vbox.show_all ();
335 PannerUI::set_send_drawing_mode (bool onoff)
337 if (_stereo_panner) {
338 _stereo_panner->set_send_drawing_mode (onoff);
339 } else if (_mono_panner) {
340 _mono_panner->set_send_drawing_mode (onoff);
341 } else if (twod_panner) {
342 twod_panner->set_send_drawing_mode (onoff);
348 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
350 boost::shared_ptr<AutomationControl> ac = wac.lock();
354 ac->start_touch (ac->session().transport_sample());
358 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
360 boost::shared_ptr<AutomationControl> ac = wac.lock();
364 ac->stop_touch (ac->session().transport_sample());
368 PannerUI::pan_button_event (GdkEventButton* ev)
370 switch (ev->button) {
372 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
374 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
384 pan_menu->set_name ("ArdourContextMenu");
387 pan_menu->popup (1, ev->time);
394 return false; // what's wrong with gcc?
398 PannerUI::build_pan_menu ()
400 using namespace Menu_Helpers;
401 MenuList& items (pan_menu->items());
405 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
406 bypass_menu_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
408 /* set state first, connect second */
410 bypass_menu_item->set_active (_panshell->bypassed());
411 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
413 if (!_panshell->bypassed()) {
414 items.push_back (MenuElem (_("Reset"), sigc::mem_fun (*this, &PannerUI::pan_reset)));
415 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun (*this, &PannerUI::pan_edit)));
418 if (_panner_list.size() > 1 && !_panshell->bypassed()) {
419 RadioMenuItem::Group group;
420 items.push_back (SeparatorElem());
422 _suspend_menu_callbacks = true;
423 for (std::map<std::string,std::string>::const_iterator p = _panner_list.begin(); p != _panner_list.end(); ++p) {
424 items.push_back (RadioMenuElem (group, p->second,
425 sigc::bind(sigc::mem_fun (*this, &PannerUI::pan_set_custom_type), p->first)));
426 RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&items.back ());
427 i->set_active (_panshell->current_panner_uri() == p->first);
429 _suspend_menu_callbacks = false;
434 PannerUI::pan_bypass_toggle ()
436 if (bypass_menu_item && (_panshell->bypassed() != bypass_menu_item->get_active())) {
437 _panshell->set_bypassed (!_panshell->bypassed());
442 PannerUI::pan_edit ()
444 if (_panshell->bypassed()) {
448 _mono_panner->edit ();
449 } else if (_stereo_panner) {
450 _stereo_panner->edit ();
451 } else if (twod_panner) {
453 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
460 PannerUI::pan_reset ()
462 if (_panshell->bypassed()) {
469 PannerUI::pan_set_custom_type (std::string uri) {
470 if (_suspend_menu_callbacks) return;
471 _panshell->select_panner_by_uri(uri);
475 PannerUI::effective_pan_display ()
477 if (_stereo_panner) {
478 _stereo_panner->queue_draw ();
479 } else if (_mono_panner) {
480 _mono_panner->queue_draw ();
481 } else if (twod_panner) {
482 twod_panner->queue_draw ();
487 PannerUI::update_pan_sensitive ()
489 bool const sensitive = !(_panner->pannable()->automation_state() & Play);
491 pan_vbox.set_sensitive (sensitive);
494 big_window->set_sensitive (sensitive);
499 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
501 using namespace Menu_Helpers;
503 if (ev->type == GDK_BUTTON_RELEASE) {
507 switch (ev->button) {
509 if (pan_astate_menu == 0) {
510 build_astate_menu ();
512 pan_astate_menu->popup (1, ev->time);
522 PannerUI::pan_automation_state_changed ()
524 boost::shared_ptr<Pannable> pannable (_panner->pannable());
525 pan_automation_state_button.set_label (GainMeterBase::short_astate_string(pannable->automation_state()));
527 bool x = (pannable->automation_state() != ARDOUR::Off);
529 if (pan_automation_state_button.get_active() != x) {
530 ignore_toggle = true;
531 pan_automation_state_button.set_active (x);
532 ignore_toggle = false;
535 update_pan_sensitive ();
539 PannerUI::show_width ()
544 PannerUI::width_adjusted ()
549 PannerUI::show_position ()
554 PannerUI::position_adjusted ()
559 PannerUI::set_available_panners(std::map<std::string,std::string> p)