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>
23 #include "pbd/fastlog.h"
25 #include "ardour/pannable.h"
26 #include "ardour/panner.h"
27 #include "ardour/panner_shell.h"
28 #include "ardour/session.h"
30 #include "ardour_ui.h"
31 #include "panner_ui.h"
33 #include "gui_thread.h"
34 #include "stereo_panner.h"
35 #include "mono_panner.h"
40 using namespace ARDOUR;
42 using namespace Gtkmm2ext;
45 const int PannerUI::pan_bar_height = 35;
47 PannerUI::PannerUI (Session* s)
52 , pan_automation_style_button ("")
53 , pan_automation_state_button ("")
58 ignore_toggle = false;
62 in_pan_update = false;
65 _ignore_width_change = false;
66 _ignore_position_change = false;
68 pan_automation_style_button.set_name ("MixerAutomationModeButton");
69 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
71 ARDOUR_UI::instance()->set_tip (pan_automation_state_button, _("Pan automation mode"));
72 ARDOUR_UI::instance()->set_tip (pan_automation_style_button, _("Pan automation type"));
74 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
75 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
77 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
78 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
80 pan_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
81 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
83 pan_vbox.set_spacing (2);
84 pack_start (pan_vbox, true, true);
93 PannerUI::set_panner (boost::shared_ptr<PannerShell> ps, boost::shared_ptr<Panner> p)
95 /* note that the panshell might not change here (i.e. ps == _panshell)
98 connections.drop_connections ();
100 delete pan_astyle_menu;
103 delete pan_astate_menu;
112 delete _stereo_panner;
122 _panshell->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panshell_changed, this), gui_context());
124 /* new panner object, force complete reset of panner GUI
131 update_pan_sensitive ();
132 pan_automation_state_changed ();
136 PannerUI::build_astate_menu ()
138 using namespace Menu_Helpers;
140 if (pan_astate_menu == 0) {
141 pan_astate_menu = new Menu;
142 pan_astate_menu->set_name ("ArdourContextMenu");
144 pan_astate_menu->items().clear ();
147 /** TRANSLATORS: this is `Manual' in the sense of automation not being played,
148 so that changes to pan must be done by hand.
150 pan_astate_menu->items().push_back (MenuElem (S_("Automation|Manual"), sigc::bind (
151 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
152 (AutoState) ARDOUR::Off)));
153 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
154 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
156 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
157 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
158 (AutoState) Write)));
159 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
160 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
161 (AutoState) Touch)));
166 PannerUI::build_astyle_menu ()
168 using namespace Menu_Helpers;
170 if (pan_astyle_menu == 0) {
171 pan_astyle_menu = new Menu;
172 pan_astyle_menu->set_name ("ArdourContextMenu");
174 pan_astyle_menu->items().clear();
177 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
178 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
182 PannerUI::on_size_allocate (Allocation& a)
184 HBox::on_size_allocate (a);
188 PannerUI::set_width (Width w)
193 PannerUI::~PannerUI ()
198 delete pan_astyle_menu;
199 delete pan_astate_menu;
200 delete _stereo_panner;
205 PannerUI::panshell_changed ()
207 set_panner (_panshell, _panshell->panner());
212 PannerUI::setup_pan ()
214 int const nouts = _panner ? _panner->out().n_audio() : -1;
215 int const nins = _panner ? _panner->in().n_audio() : -1;
217 if (nouts == _current_nouts
218 && nins == _current_nins
219 && _current_uri == _panshell->panner_gui_uri()
225 _current_nins = nins;
226 _current_nouts = nouts;
227 _current_uri = _panshell->panner_gui_uri();
229 container_clear (pan_vbox);
233 delete _stereo_panner;
244 if (_current_uri == "http://ardour.org/plugin/panner_2in2out#ui")
249 boost::shared_ptr<Pannable> pannable = _panner->pannable();
251 _stereo_panner = new StereoPanner (_panshell);
252 _stereo_panner->set_size_request (-1, pan_bar_height);
253 _stereo_panner->set_send_drawing_mode (_send_mode);
254 pan_vbox.pack_start (*_stereo_panner, false, false);
256 boost::shared_ptr<AutomationControl> ac;
258 ac = pannable->pan_azimuth_control;
259 _stereo_panner->StartPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
260 boost::weak_ptr<AutomationControl> (ac)));
261 _stereo_panner->StopPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
262 boost::weak_ptr<AutomationControl>(ac)));
264 ac = pannable->pan_width_control;
265 _stereo_panner->StartWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
266 boost::weak_ptr<AutomationControl> (ac)));
267 _stereo_panner->StopWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
268 boost::weak_ptr<AutomationControl>(ac)));
269 _stereo_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
271 else if (_current_uri == "http://ardour.org/plugin/panner_1in2out#ui"
272 || _current_uri == "http://ardour.org/plugin/panner_balance#ui")
276 boost::shared_ptr<Pannable> pannable = _panner->pannable();
277 boost::shared_ptr<AutomationControl> ac = pannable->pan_azimuth_control;
279 _mono_panner = new MonoPanner (_panshell);
281 _mono_panner->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
282 boost::weak_ptr<AutomationControl> (ac)));
283 _mono_panner->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
284 boost::weak_ptr<AutomationControl>(ac)));
286 _mono_panner->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
288 _mono_panner->set_size_request (-1, pan_bar_height);
289 _mono_panner->set_send_drawing_mode (_send_mode);
291 update_pan_sensitive ();
292 pan_vbox.pack_start (*_mono_panner, false, false);
294 else if (_current_uri == "http://ardour.org/plugin/panner_vbap#ui")
297 twod_panner = new Panner2d (_panshell, 61);
298 twod_panner->set_name ("MixerPanZone");
299 twod_panner->show ();
300 twod_panner->signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event), false);
303 update_pan_sensitive ();
304 twod_panner->reset (nins);
306 big_window->reset (nins);
308 twod_panner->set_size_request (-1, 61);
309 twod_panner->set_send_drawing_mode (_send_mode);
311 /* and finally, add it to the panner frame */
313 pan_vbox.pack_start (*twod_panner, false, false);
317 /* stick something into the panning viewport so that it redraws */
318 EventBox* eb = manage (new EventBox());
319 pan_vbox.pack_start (*eb, false, false);
325 pan_vbox.show_all ();
329 PannerUI::set_send_drawing_mode (bool onoff)
331 if (_stereo_panner) {
332 _stereo_panner->set_send_drawing_mode (onoff);
333 } else if (_mono_panner) {
334 _mono_panner->set_send_drawing_mode (onoff);
335 } else if (twod_panner) {
336 twod_panner->set_send_drawing_mode (onoff);
342 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
344 boost::shared_ptr<AutomationControl> ac = wac.lock();
348 ac->start_touch (ac->session().transport_frame());
352 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
354 boost::shared_ptr<AutomationControl> ac = wac.lock();
358 ac->stop_touch (false, ac->session().transport_frame());
362 PannerUI::pan_button_event (GdkEventButton* ev)
364 switch (ev->button) {
366 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
368 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
377 pan_menu = manage (new Menu);
378 pan_menu->set_name ("ArdourContextMenu");
381 pan_menu->popup (1, ev->time);
388 return false; // what's wrong with gcc?
392 PannerUI::build_pan_menu ()
394 using namespace Menu_Helpers;
395 MenuList& items (pan_menu->items());
399 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
400 bypass_menu_item = static_cast<Gtk::CheckMenuItem*> (&items.back());
402 /* set state first, connect second */
404 bypass_menu_item->set_active (_panshell->bypassed());
405 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
407 if (!_panshell->bypassed()) {
408 items.push_back (MenuElem (_("Reset"), sigc::mem_fun (*this, &PannerUI::pan_reset)));
409 items.push_back (MenuElem (_("Edit..."), sigc::mem_fun (*this, &PannerUI::pan_edit)));
412 if (_panner_list.size() > 1 && !_panshell->bypassed()) {
413 RadioMenuItem::Group group;
414 items.push_back (SeparatorElem());
416 _suspend_menu_callbacks = true;
417 for (std::map<std::string,std::string>::const_iterator p = _panner_list.begin(); p != _panner_list.end(); ++p) {
418 items.push_back (RadioMenuElem (group, p->second,
419 sigc::bind(sigc::mem_fun (*this, &PannerUI::pan_set_custom_type), p->first)));
420 RadioMenuItem* i = dynamic_cast<RadioMenuItem *> (&items.back ());
421 i->set_active (_panshell->current_panner_uri() == p->first);
423 _suspend_menu_callbacks = false;
428 PannerUI::pan_bypass_toggle ()
430 if (bypass_menu_item && (_panshell->bypassed() != bypass_menu_item->get_active())) {
431 _panshell->set_bypassed (!_panshell->bypassed());
436 PannerUI::pan_edit ()
438 if (_panshell->bypassed()) {
442 _mono_panner->edit ();
443 } else if (_stereo_panner) {
444 _stereo_panner->edit ();
445 } else if (twod_panner) {
447 big_window = new Panner2dWindow (_panshell, 400, _panner->in().n_audio());
454 PannerUI::pan_reset ()
456 if (_panshell->bypassed()) {
463 PannerUI::pan_set_custom_type (std::string uri) {
464 if (_suspend_menu_callbacks) return;
465 _panshell->select_panner_by_uri(uri);
469 PannerUI::effective_pan_display ()
471 if (_stereo_panner) {
472 _stereo_panner->queue_draw ();
473 } else if (_mono_panner) {
474 _mono_panner->queue_draw ();
475 } else if (twod_panner) {
476 twod_panner->queue_draw ();
481 PannerUI::update_pan_sensitive ()
483 bool const sensitive = !(_panner->pannable()->automation_state() & Play);
485 pan_vbox.set_sensitive (sensitive);
488 big_window->set_sensitive (sensitive);
493 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
495 using namespace Menu_Helpers;
497 if (ev->type == GDK_BUTTON_RELEASE) {
501 switch (ev->button) {
503 if (pan_astate_menu == 0) {
504 build_astate_menu ();
506 pan_astate_menu->popup (1, ev->time);
516 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
518 if (ev->type == GDK_BUTTON_RELEASE) {
522 switch (ev->button) {
524 if (pan_astyle_menu == 0) {
525 build_astyle_menu ();
527 pan_astyle_menu->popup (1, ev->time);
536 PannerUI::pan_automation_style_changed ()
538 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
542 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
545 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
551 PannerUI::pan_automation_state_changed ()
553 boost::shared_ptr<Pannable> pannable (_panner->pannable());
557 pan_automation_state_button.set_label (astate_string(pannable->automation_state()));
560 pan_automation_state_button.set_label (short_astate_string(pannable->automation_state()));
564 bool x = (pannable->automation_state() != ARDOUR::Off);
566 if (pan_automation_state_button.get_active() != x) {
567 ignore_toggle = true;
568 pan_automation_state_button.set_active (x);
569 ignore_toggle = false;
572 update_pan_sensitive ();
574 /* start watching automation so that things move */
576 pan_watching.disconnect();
579 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
584 PannerUI::astate_string (AutoState state)
586 return _astate_string (state, false);
590 PannerUI::short_astate_string (AutoState state)
592 return _astate_string (state, true);
596 PannerUI::_astate_string (AutoState state, bool shrt)
602 sstr = (shrt ? "M" : _("M"));
605 sstr = (shrt ? "P" : _("P"));
608 sstr = (shrt ? "T" : _("T"));
611 sstr = (shrt ? "W" : _("W"));
619 PannerUI::astyle_string (AutoStyle style)
621 return _astyle_string (style, false);
625 PannerUI::short_astyle_string (AutoStyle style)
627 return _astyle_string (style, true);
631 PannerUI::_astyle_string (AutoStyle style, bool shrt)
636 /* XXX it might different in different languages */
638 return (shrt ? _("Abs") : _("Abs"));
643 PannerUI::show_width ()
648 PannerUI::width_adjusted ()
653 PannerUI::show_position ()
658 PannerUI::position_adjusted ()
663 PannerUI::set_available_panners(std::map<std::string,std::string> p)