2 Copyright (C) 2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gtkmm2ext/utils.h>
22 #include <gtkmm2ext/barcontroller.h>
24 #include "pbd/fastlog.h"
26 #include "ardour/pannable.h"
27 #include "ardour/panner.h"
28 #include "ardour/panner_shell.h"
29 #include "ardour/session.h"
31 #include "ardour_ui.h"
32 #include "panner_ui.h"
34 #include "gui_thread.h"
35 #include "stereo_panner.h"
36 #include "mono_panner.h"
41 using namespace ARDOUR;
43 using namespace Gtkmm2ext;
46 const int PannerUI::pan_bar_height = 35;
48 PannerUI::PannerUI (Session* s)
53 , pan_automation_style_button ("")
54 , pan_automation_state_button ("")
59 ignore_toggle = false;
63 in_pan_update = false;
66 _ignore_width_change = false;
67 _ignore_position_change = false;
69 pan_automation_style_button.set_name ("MixerAutomationModeButton");
70 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
72 ARDOUR_UI::instance()->set_tip (pan_automation_state_button, _("Pan automation mode"));
73 ARDOUR_UI::instance()->set_tip (pan_automation_style_button, _("Pan automation type"));
75 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
76 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
78 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
79 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
81 pan_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
82 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
84 pan_vbox.set_spacing (2);
85 pack_start (pan_vbox, true, true);
94 PannerUI::set_panner (boost::shared_ptr<PannerShell> ps, boost::shared_ptr<Panner> p)
96 /* note that the panshell might not change here (i.e. ps == _panshell)
99 connections.drop_connections ();
101 delete pan_astyle_menu;
104 delete pan_astate_menu;
113 delete _stereo_panner;
123 _panshell->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panshell_changed, this), gui_context());
125 /* new panner object, force complete reset of panner GUI
132 update_pan_sensitive ();
133 pan_automation_state_changed ();
137 PannerUI::build_astate_menu ()
139 using namespace Menu_Helpers;
141 if (pan_astate_menu == 0) {
142 pan_astate_menu = new Menu;
143 pan_astate_menu->set_name ("ArdourContextMenu");
145 pan_astate_menu->items().clear ();
148 /** TRANSLATORS: this is `Manual' in the sense of automation not being played,
149 so that changes to pan must be done by hand.
151 pan_astate_menu->items().push_back (MenuElem (S_("Automation|Manual"), sigc::bind (
152 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
153 (AutoState) ARDOUR::Off)));
154 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
155 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
157 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
158 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
159 (AutoState) Write)));
160 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
161 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
162 (AutoState) Touch)));
167 PannerUI::build_astyle_menu ()
169 using namespace Menu_Helpers;
171 if (pan_astyle_menu == 0) {
172 pan_astyle_menu = new Menu;
173 pan_astyle_menu->set_name ("ArdourContextMenu");
175 pan_astyle_menu->items().clear();
178 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
179 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
183 PannerUI::on_size_allocate (Allocation& a)
185 HBox::on_size_allocate (a);
189 PannerUI::set_width (Width w)
194 PannerUI::~PannerUI ()
199 delete pan_astyle_menu;
200 delete pan_astate_menu;
201 delete _stereo_panner;
206 PannerUI::panshell_changed ()
208 set_panner (_panshell, _panshell->panner());
213 PannerUI::setup_pan ()
215 int const nouts = _panner ? _panner->out().n_audio() : -1;
216 int const nins = _panner ? _panner->in().n_audio() : -1;
218 if (nouts == _current_nouts
219 && nins == _current_nins
220 && _current_uri == _panshell->panner_gui_uri()
226 _current_nins = nins;
227 _current_nouts = nouts;
228 _current_uri = _panshell->panner_gui_uri();
230 container_clear (pan_vbox);
234 delete _stereo_panner;
245 if (_current_uri == "http://ardour.org/plugin/panner_2in2out#ui")
250 boost::shared_ptr<Pannable> pannable = _panner->pannable();
252 _stereo_panner = new StereoPanner (_panshell);
253 _stereo_panner->set_size_request (-1, pan_bar_height);
254 _stereo_panner->set_send_drawing_mode (_send_mode);
255 pan_vbox.pack_start (*_stereo_panner, false, false);
257 boost::shared_ptr<AutomationControl> ac;
259 ac = pannable->pan_azimuth_control;
260 _stereo_panner->StartPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
261 boost::weak_ptr<AutomationControl> (ac)));
262 _stereo_panner->StopPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
263 boost::weak_ptr<AutomationControl>(ac)));
265 ac = pannable->pan_width_control;
266 _stereo_panner->StartWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
267 boost::weak_ptr<AutomationControl> (ac)));
268 _stereo_panner->StopWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
269 boost::weak_ptr<AutomationControl>(ac)));
270 _stereo_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
272 else if (_current_uri == "http://ardour.org/plugin/panner_1in2out#ui"
273 || _current_uri == "http://ardour.org/plugin/panner_balance#ui")
277 boost::shared_ptr<Pannable> pannable = _panner->pannable();
278 boost::shared_ptr<AutomationControl> ac = pannable->pan_azimuth_control;
280 _mono_panner = new MonoPanner (_panshell);
282 _mono_panner->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
283 boost::weak_ptr<AutomationControl> (ac)));
284 _mono_panner->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
285 boost::weak_ptr<AutomationControl>(ac)));
287 _mono_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
289 _mono_panner->set_size_request (-1, pan_bar_height);
290 _mono_panner->set_send_drawing_mode (_send_mode);
292 update_pan_sensitive ();
293 pan_vbox.pack_start (*_mono_panner, false, false);
295 else if (_current_uri == "http://ardour.org/plugin/panner_vbap#ui")
298 twod_panner = new Panner2d (_panshell, 61);
299 twod_panner->set_name ("MixerPanZone");
300 twod_panner->show ();
301 twod_panner->signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event), false);
304 update_pan_sensitive ();
305 twod_panner->reset (nins);
307 big_window->reset (nins);
309 twod_panner->set_size_request (-1, 61);
310 twod_panner->set_send_drawing_mode (_send_mode);
312 /* and finally, add it to the panner frame */
314 pan_vbox.pack_start (*twod_panner, false, false);
318 /* stick something into the panning viewport so that it redraws */
319 EventBox* eb = manage (new EventBox());
320 pan_vbox.pack_start (*eb, false, false);
326 pan_vbox.show_all ();
330 PannerUI::set_send_drawing_mode (bool onoff)
332 if (_stereo_panner) {
333 _stereo_panner->set_send_drawing_mode (onoff);
334 } else if (_mono_panner) {
335 _mono_panner->set_send_drawing_mode (onoff);
336 } else if (twod_panner) {
337 twod_panner->set_send_drawing_mode (onoff);
343 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
345 boost::shared_ptr<AutomationControl> ac = wac.lock();
349 ac->start_touch (ac->session().transport_frame());
353 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
355 boost::shared_ptr<AutomationControl> ac = wac.lock();
359 ac->stop_touch (false, ac->session().transport_frame());
363 PannerUI::pan_button_event (GdkEventButton* ev)
365 switch (ev->button) {
367 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
369 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
378 pan_menu = manage (new Menu);
379 pan_menu->set_name ("ArdourContextMenu");
382 pan_menu->popup (1, ev->time);
389 return false; // what's wrong with gcc?
393 PannerUI::build_pan_menu ()
395 using namespace Menu_Helpers;
396 MenuList& items (pan_menu->items());
400 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
401 bypass_menu_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
403 /* set state first, connect second */
405 bypass_menu_item->set_active (_panshell->bypassed());
406 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
408 if (!_panshell->bypassed()) {
409 items.push_back (MenuElem (_("Reset"), sigc::mem_fun (*this, &PannerUI::pan_reset)));
410 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun (*this, &PannerUI::pan_edit)));
413 if (_panner_list.size() > 1 && !_panshell->bypassed()) {
414 RadioMenuItem::Group group;
415 items.push_back (SeparatorElem());
417 _suspend_menu_callbacks = true;
418 for (std::map<std::string,std::string>::const_iterator p = _panner_list.begin(); p != _panner_list.end(); ++p) {
419 items.push_back (RadioMenuElem (group, p->second,
420 sigc::bind(sigc::mem_fun (*this, &PannerUI::pan_set_custom_type), p->first)));
421 RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&items.back ());
422 i->set_active (_panshell->current_panner_uri() == p->first);
424 _suspend_menu_callbacks = false;
429 PannerUI::pan_bypass_toggle ()
431 if (bypass_menu_item && (_panshell->bypassed() != bypass_menu_item->get_active())) {
432 _panshell->set_bypassed (!_panshell->bypassed());
437 PannerUI::pan_edit ()
439 if (_panshell->bypassed()) {
443 _mono_panner->edit ();
444 } else if (_stereo_panner) {
445 _stereo_panner->edit ();
446 } else if (twod_panner) {
448 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
455 PannerUI::pan_reset ()
457 if (_panshell->bypassed()) {
464 PannerUI::pan_set_custom_type (std::string uri) {
465 if (_suspend_menu_callbacks) return;
466 _panshell->select_panner_by_uri(uri);
470 PannerUI::effective_pan_display ()
472 if (_stereo_panner) {
473 _stereo_panner->queue_draw ();
474 } else if (_mono_panner) {
475 _mono_panner->queue_draw ();
476 } else if (twod_panner) {
477 twod_panner->queue_draw ();
482 PannerUI::update_pan_sensitive ()
484 bool const sensitive = !(_panner->pannable()->automation_state() & Play);
486 pan_vbox.set_sensitive (sensitive);
489 big_window->set_sensitive (sensitive);
494 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
496 using namespace Menu_Helpers;
498 if (ev->type == GDK_BUTTON_RELEASE) {
502 switch (ev->button) {
504 if (pan_astate_menu == 0) {
505 build_astate_menu ();
507 pan_astate_menu->popup (1, ev->time);
517 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
519 if (ev->type == GDK_BUTTON_RELEASE) {
523 switch (ev->button) {
525 if (pan_astyle_menu == 0) {
526 build_astyle_menu ();
528 pan_astyle_menu->popup (1, ev->time);
537 PannerUI::pan_automation_style_changed ()
539 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
543 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
546 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
552 PannerUI::pan_automation_state_changed ()
554 boost::shared_ptr<Pannable> pannable (_panner->pannable());
558 pan_automation_state_button.set_label (astate_string(pannable->automation_state()));
561 pan_automation_state_button.set_label (short_astate_string(pannable->automation_state()));
565 bool x = (pannable->automation_state() != ARDOUR::Off);
567 if (pan_automation_state_button.get_active() != x) {
568 ignore_toggle = true;
569 pan_automation_state_button.set_active (x);
570 ignore_toggle = false;
573 update_pan_sensitive ();
575 /* start watching automation so that things move */
577 pan_watching.disconnect();
580 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
585 PannerUI::astate_string (AutoState state)
587 return _astate_string (state, false);
591 PannerUI::short_astate_string (AutoState state)
593 return _astate_string (state, true);
597 PannerUI::_astate_string (AutoState state, bool shrt)
603 sstr = (shrt ? "M" : _("M"));
606 sstr = (shrt ? "P" : _("P"));
609 sstr = (shrt ? "T" : _("T"));
612 sstr = (shrt ? "W" : _("W"));
620 PannerUI::astyle_string (AutoStyle style)
622 return _astyle_string (style, false);
626 PannerUI::short_astyle_string (AutoStyle style)
628 return _astyle_string (style, true);
632 PannerUI::_astyle_string (AutoStyle style, bool shrt)
637 /* XXX it might different in different languages */
639 return (shrt ? _("Abs") : _("Abs"));
644 PannerUI::show_width ()
649 PannerUI::width_adjusted ()
654 PannerUI::show_position ()
659 PannerUI::position_adjusted ()
664 PannerUI::set_available_panners(std::map<std::string,std::string> p)