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 (S_("Automation|Manual"), sigc::bind (
155 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
156 (AutoState) ARDOUR::Off)));
157 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
158 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
160 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
161 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
162 (AutoState) Write)));
163 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
164 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
165 (AutoState) Touch)));
166 pan_astate_menu->items().push_back (MenuElem (_("Latch"), sigc::bind (
167 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
168 (AutoState) Latch)));
173 PannerUI::build_astyle_menu ()
175 using namespace Menu_Helpers;
177 if (pan_astyle_menu == 0) {
178 pan_astyle_menu = new Menu;
179 pan_astyle_menu->set_name ("ArdourContextMenu");
181 pan_astyle_menu->items().clear();
184 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
185 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
189 PannerUI::on_size_allocate (Allocation& a)
191 HBox::on_size_allocate (a);
195 PannerUI::set_width (Width w)
200 PannerUI::~PannerUI ()
205 delete pan_astyle_menu;
206 delete pan_astate_menu;
207 delete _stereo_panner;
212 PannerUI::panshell_changed ()
214 set_panner (_panshell, _panshell->panner());
219 PannerUI::setup_pan ()
221 int const nouts = _panner ? _panner->out().n_audio() : -1;
222 int const nins = _panner ? _panner->in().n_audio() : -1;
226 if (nouts == _current_nouts
227 && nins == _current_nins
228 && _current_uri == _panshell->panner_gui_uri()
234 _current_nins = nins;
235 _current_nouts = nouts;
236 _current_uri = _panshell->panner_gui_uri();
238 container_clear (pan_vbox);
242 delete _stereo_panner;
253 const float scale = std::max (1.f, UIConfiguration::instance().get_ui_scale());
255 if (_current_uri == "http://ardour.org/plugin/panner_2in2out#ui")
260 boost::shared_ptr<Pannable> pannable = _panner->pannable();
262 _stereo_panner = new StereoPanner (_panshell);
263 _stereo_panner->set_size_request (-1, 5 * ceilf(7.f * scale));
264 _stereo_panner->set_send_drawing_mode (_send_mode);
265 pan_vbox.pack_start (*_stereo_panner, false, false);
267 boost::shared_ptr<AutomationControl> ac;
269 ac = pannable->pan_azimuth_control;
270 _stereo_panner->StartPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
271 boost::weak_ptr<AutomationControl> (ac)));
272 _stereo_panner->StopPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
273 boost::weak_ptr<AutomationControl>(ac)));
275 ac = pannable->pan_width_control;
276 _stereo_panner->StartWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
277 boost::weak_ptr<AutomationControl> (ac)));
278 _stereo_panner->StopWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
279 boost::weak_ptr<AutomationControl>(ac)));
280 _stereo_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
282 else if (_current_uri == "http://ardour.org/plugin/panner_1in2out#ui"
283 || _current_uri == "http://ardour.org/plugin/panner_balance#ui")
287 boost::shared_ptr<Pannable> pannable = _panner->pannable();
288 boost::shared_ptr<AutomationControl> ac = pannable->pan_azimuth_control;
290 _mono_panner = new MonoPanner (_panshell);
292 _mono_panner->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
293 boost::weak_ptr<AutomationControl> (ac)));
294 _mono_panner->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
295 boost::weak_ptr<AutomationControl>(ac)));
297 _mono_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
299 _mono_panner->set_size_request (-1, 5 * ceilf(7.f * scale));
300 _mono_panner->set_send_drawing_mode (_send_mode);
302 update_pan_sensitive ();
303 pan_vbox.pack_start (*_mono_panner, false, false);
305 else if (_current_uri == "http://ardour.org/plugin/panner_vbap#ui")
308 twod_panner = new Panner2d (_panshell, rintf(61.f * scale));
309 twod_panner->set_name ("MixerPanZone");
310 twod_panner->show ();
311 twod_panner->signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event), false);
314 update_pan_sensitive ();
315 twod_panner->reset (nins);
317 big_window->reset (nins);
319 twod_panner->set_size_request (-1, rintf(61.f * scale));
320 twod_panner->set_send_drawing_mode (_send_mode);
322 /* and finally, add it to the panner frame */
324 pan_vbox.pack_start (*twod_panner, false, false);
328 /* stick something into the panning viewport so that it redraws */
329 EventBox* eb = manage (new EventBox());
330 pan_vbox.pack_start (*eb, false, false);
336 pan_vbox.show_all ();
340 PannerUI::set_send_drawing_mode (bool onoff)
342 if (_stereo_panner) {
343 _stereo_panner->set_send_drawing_mode (onoff);
344 } else if (_mono_panner) {
345 _mono_panner->set_send_drawing_mode (onoff);
346 } else if (twod_panner) {
347 twod_panner->set_send_drawing_mode (onoff);
353 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
355 boost::shared_ptr<AutomationControl> ac = wac.lock();
359 ac->start_touch (ac->session().transport_sample());
363 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
365 boost::shared_ptr<AutomationControl> ac = wac.lock();
369 ac->stop_touch (ac->session().transport_sample());
373 PannerUI::pan_button_event (GdkEventButton* ev)
375 switch (ev->button) {
377 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
379 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
389 pan_menu->set_name ("ArdourContextMenu");
392 pan_menu->popup (1, ev->time);
399 return false; // what's wrong with gcc?
403 PannerUI::build_pan_menu ()
405 using namespace Menu_Helpers;
406 MenuList& items (pan_menu->items());
410 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
411 bypass_menu_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
413 /* set state first, connect second */
415 bypass_menu_item->set_active (_panshell->bypassed());
416 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
418 if (!_panshell->bypassed()) {
419 items.push_back (MenuElem (_("Reset"), sigc::mem_fun (*this, &PannerUI::pan_reset)));
420 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun (*this, &PannerUI::pan_edit)));
423 if (_panner_list.size() > 1 && !_panshell->bypassed()) {
424 RadioMenuItem::Group group;
425 items.push_back (SeparatorElem());
427 _suspend_menu_callbacks = true;
428 for (std::map<std::string,std::string>::const_iterator p = _panner_list.begin(); p != _panner_list.end(); ++p) {
429 items.push_back (RadioMenuElem (group, p->second,
430 sigc::bind(sigc::mem_fun (*this, &PannerUI::pan_set_custom_type), p->first)));
431 RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&items.back ());
432 i->set_active (_panshell->current_panner_uri() == p->first);
434 _suspend_menu_callbacks = false;
439 PannerUI::pan_bypass_toggle ()
441 if (bypass_menu_item && (_panshell->bypassed() != bypass_menu_item->get_active())) {
442 _panshell->set_bypassed (!_panshell->bypassed());
447 PannerUI::pan_edit ()
449 if (_panshell->bypassed()) {
453 _mono_panner->edit ();
454 } else if (_stereo_panner) {
455 _stereo_panner->edit ();
456 } else if (twod_panner) {
458 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
465 PannerUI::pan_reset ()
467 if (_panshell->bypassed()) {
474 PannerUI::pan_set_custom_type (std::string uri) {
475 if (_suspend_menu_callbacks) return;
476 _panshell->select_panner_by_uri(uri);
480 PannerUI::effective_pan_display ()
482 if (_stereo_panner) {
483 _stereo_panner->queue_draw ();
484 } else if (_mono_panner) {
485 _mono_panner->queue_draw ();
486 } else if (twod_panner) {
487 twod_panner->queue_draw ();
492 PannerUI::update_pan_sensitive ()
494 bool const sensitive = !(_panner->pannable()->automation_state() & Play);
496 pan_vbox.set_sensitive (sensitive);
499 big_window->set_sensitive (sensitive);
504 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
506 using namespace Menu_Helpers;
508 if (ev->type == GDK_BUTTON_RELEASE) {
512 switch (ev->button) {
514 if (pan_astate_menu == 0) {
515 build_astate_menu ();
517 pan_astate_menu->popup (1, ev->time);
527 PannerUI::pan_automation_state_changed ()
529 boost::shared_ptr<Pannable> pannable (_panner->pannable());
530 pan_automation_state_button.set_label (GainMeterBase::short_astate_string(pannable->automation_state()));
532 bool x = (pannable->automation_state() != ARDOUR::Off);
534 if (pan_automation_state_button.get_active() != x) {
535 ignore_toggle = true;
536 pan_automation_state_button.set_active (x);
537 ignore_toggle = false;
540 update_pan_sensitive ();
544 PannerUI::show_width ()
549 PannerUI::width_adjusted ()
554 PannerUI::show_position ()
559 PannerUI::position_adjusted ()
564 PannerUI::set_available_panners(std::map<std::string,std::string> p)