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 "ardour/io.h"
22 #include "ardour/dB.h"
23 #include <gtkmm2ext/utils.h>
24 #include <gtkmm2ext/barcontroller.h>
25 #include "midi++/manager.h"
26 #include "pbd/fastlog.h"
28 #include "ardour_ui.h"
29 #include "panner_ui.h"
33 #include "gui_thread.h"
34 #include "stereo_panner.h"
36 #include "ardour/delivery.h"
37 #include "ardour/session.h"
38 #include "ardour/panner.h"
39 #include "ardour/route.h"
44 using namespace ARDOUR;
46 using namespace Gtkmm2ext;
49 const int PannerUI::pan_bar_height = 20;
51 PannerUI::PannerUI (Session* s)
54 , hAdjustment(0.0, 0.0, 0.0)
55 , vAdjustment(0.0, 0.0, 0.0)
56 , panning_viewport(hAdjustment, vAdjustment)
57 , panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT)
58 , panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT)
59 , panning_link_button (_("link"))
60 , pan_automation_style_button ("")
61 , pan_automation_state_button ("")
62 , _bar_spinner_active (false)
66 ignore_toggle = false;
70 in_pan_update = false;
72 _ignore_width_change = false;
73 _ignore_position_change = false;
75 pan_automation_style_button.set_name ("MixerAutomationModeButton");
76 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
78 ARDOUR_UI::instance()->set_tip (pan_automation_state_button, _("Pan automation mode"));
79 ARDOUR_UI::instance()->set_tip (pan_automation_style_button, _("Pan automation type"));
81 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
82 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
84 panning_viewport.set_name (X_("BaseFrame"));
86 ARDOUR_UI::instance()->set_tip (panning_link_button,
87 _("panning link control"));
88 ARDOUR_UI::instance()->set_tip (panning_link_direction_button,
89 _("panning link direction"));
91 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
92 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
94 pan_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
95 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
97 panning_link_button.set_name (X_("PanningLinkButton"));
98 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
100 panning_link_box.pack_start (panning_link_button, true, true);
101 panning_link_box.pack_start (panning_link_direction_button, true, true);
102 panning_link_box.pack_start (pan_automation_state_button, true, true);
104 /* the pixmap will be reset at some point, but the key thing is that
105 we need a pixmap in the button just to get started.
107 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
109 panning_link_direction_button.signal_clicked().connect
110 (sigc::mem_fun(*this, &PannerUI::panning_link_direction_clicked));
112 panning_link_button.signal_button_press_event().connect
113 (sigc::mem_fun(*this, &PannerUI::panning_link_button_press), false);
114 panning_link_button.signal_button_release_event().connect
115 (sigc::mem_fun(*this, &PannerUI::panning_link_button_release), false);
117 panning_up.set_border_width (3);
118 panning_down.set_border_width (3);
119 panning_up.add (panning_up_arrow);
120 panning_down.add (panning_down_arrow);
121 panning_up.set_name (X_("PanScrollerBase"));
122 panning_down.set_name (X_("PanScrollerBase"));
123 panning_up_arrow.set_name (X_("PanScrollerArrow"));
124 panning_down_arrow.set_name (X_("PanScrollerArrow"));
126 pan_vbox.set_spacing (2);
127 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
128 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
130 pack_start (pan_vbox, true, true);
139 PannerUI::set_panner (boost::shared_ptr<Panner> p)
141 connections.drop_connections ();
143 delete pan_astyle_menu;
146 delete pan_astate_menu;
158 _panner->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panner_changed, this, this), gui_context());
159 _panner->LinkStateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_linkage, this), gui_context());
160 _panner->StateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_state, this), gui_context());
163 update_pan_sensitive ();
164 update_pan_linkage ();
165 pan_automation_state_changed ();
169 PannerUI::build_astate_menu ()
171 using namespace Menu_Helpers;
173 if (pan_astate_menu == 0) {
174 pan_astate_menu = new Menu;
175 pan_astate_menu->set_name ("ArdourContextMenu");
177 pan_astate_menu->items().clear ();
180 pan_astate_menu->items().push_back (MenuElem (_("Manual"), sigc::bind (
181 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
183 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
184 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
186 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
187 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
188 (AutoState) Write)));
189 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
190 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
191 (AutoState) Touch)));
196 PannerUI::build_astyle_menu ()
198 using namespace Menu_Helpers;
200 if (pan_astyle_menu == 0) {
201 pan_astyle_menu = new Menu;
202 pan_astyle_menu->set_name ("ArdourContextMenu");
204 pan_astyle_menu->items().clear();
207 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
208 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
211 boost::shared_ptr<PBD::Controllable>
212 PannerUI::get_controllable()
214 return pan_bars[0]->get_controllable();
218 PannerUI::panning_link_button_press (GdkEventButton*)
224 PannerUI::panning_link_button_release (GdkEventButton*)
226 if (!ignore_toggle) {
227 _panner->set_linked (!_panner->linked());
233 PannerUI::panning_link_direction_clicked()
235 switch (_panner->link_direction()) {
236 case Panner::SameDirection:
237 _panner->set_link_direction (Panner::OppositeDirection);
240 _panner->set_link_direction (Panner::SameDirection);
246 PannerUI::update_pan_linkage ()
248 ENSURE_GUI_THREAD (*this, &PannerUI::update_pan_linkage)
250 bool const x = _panner->linked();
251 bool const bx = panning_link_button.get_active();
255 ignore_toggle = true;
256 panning_link_button.set_active (x);
257 ignore_toggle = false;
260 panning_link_direction_button.set_sensitive (x);
262 switch (_panner->link_direction()) {
263 case Panner::SameDirection:
264 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
267 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
273 PannerUI::on_size_allocate (Allocation& a)
275 HBox::on_size_allocate (a);
279 PannerUI::set_width (Width w)
283 panning_link_button.set_label (_("link"));
286 panning_link_button.set_label (_("L"));
294 PannerUI::~PannerUI ()
296 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
300 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
307 delete pan_astyle_menu;
308 delete pan_astate_menu;
309 delete _stereo_panner;
314 PannerUI::panner_changed (void* src)
316 ENSURE_GUI_THREAD (*this, &PannerUI::panner_changed)
324 switch (_panner->npanners()) {
326 panning_link_direction_button.set_sensitive (false);
327 panning_link_button.set_sensitive (false);
330 panning_link_direction_button.set_sensitive (false);
331 panning_link_button.set_sensitive (false);
334 panning_link_direction_button.set_sensitive (_panner->linked ());
335 panning_link_button.set_sensitive (true);
338 uint32_t const nouts = _panner->nouts();
347 /* bring pan bar state up to date */
348 update_pan_bars (false);
352 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
358 PannerUI::update_pan_state ()
360 /* currently nothing to do */
361 // ENSURE_GUI_THREAD (*this, &PannerUI::update_panner_state)
365 PannerUI::setup_pan ()
371 uint32_t const nouts = _panner->nouts();
372 uint32_t const npans = _panner->npanners();
374 if (int32_t (nouts) == _current_nouts && int32_t (npans) == _current_npans) {
378 _pan_control_connections.drop_connections ();
379 for (uint32_t i = 0; i < _panner->npanners(); ++i) {
380 connect_to_pan_control (i);
383 _current_nouts = nouts;
384 _current_npans = npans;
386 panning_viewport.remove ();
390 delete _stereo_panner;
393 if (nouts == 0 || nouts == 1) {
395 while (!pan_adjustments.empty()) {
396 delete pan_bars.back();
397 pan_bars.pop_back ();
398 delete pan_adjustments.back();
399 pan_adjustments.pop_back ();
402 /* stick something into the panning viewport so that it redraws */
404 EventBox* eb = manage (new EventBox());
405 panning_viewport.add (*eb);
407 } else if (nouts == 2) {
409 vector<Adjustment*>::size_type asz;
411 while (!pan_adjustments.empty()) {
412 delete pan_bars.back();
413 pan_bars.pop_back ();
414 delete pan_adjustments.back();
415 pan_adjustments.pop_back ();
420 /* add integrated 2in/2out panner GUI */
422 _stereo_panner = new StereoPanner (_panner->direction_control(),
423 _panner->width_control());
424 _stereo_panner->set_size_request (-1, 2 * pan_bar_height);
425 panning_viewport.add (*_stereo_panner);
429 /* N-in/2out - just use a set of single-channel panners */
431 while ((asz = pan_adjustments.size()) < npans) {
436 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
437 which serves as a default, otherwise use current value */
439 rx = _panner->pan_control( asz)->get_value();
443 } else if (asz == 0) {
445 } else if (asz == 1) {
451 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
452 bc = new PannerBar (*pan_adjustments[asz],
453 boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
455 /* now set adjustment with current value of panner, then connect the signals */
456 pan_adjustments.back()->set_value(rx);
457 pan_adjustments.back()->signal_value_changed().connect (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
458 connect_to_pan_control (asz);
460 bc->set_name ("PanSlider");
461 bc->set_shadow_type (Gtk::SHADOW_NONE);
463 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
466 bc->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
467 boost::weak_ptr<AutomationControl> (ac)));
468 bc->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
469 boost::weak_ptr<AutomationControl>(ac)));
473 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
474 ARDOUR_UI::instance()->set_tip (bc->event_widget(), buf);
476 bc->event_widget().signal_button_release_event().connect
477 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
479 bc->set_size_request (-1, pan_bar_height);
480 bc->SpinnerActive.connect (sigc::mem_fun (*this, &PannerUI::bar_spinner_activate));
482 pan_bars.push_back (bc);
483 pan_bar_packer.pack_start (*bc, false, false);
486 /* now that we actually have the pan bars,
487 set their sensitivity based on current
492 update_pan_sensitive ();
493 panning_viewport.add (pan_bar_packer);
500 twod_panner = new Panner2d (_panner, 61);
501 twod_panner->set_name ("MixerPanZone");
502 twod_panner->show ();
504 twod_panner->signal_button_press_event().connect
505 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
508 update_pan_sensitive ();
509 twod_panner->reset (npans);
511 big_window->reset (npans);
513 twod_panner->set_size_request (-1, 61);
515 /* and finally, add it to the panner frame */
517 panning_viewport.add (*twod_panner);
520 panning_viewport.show_all ();
524 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
526 boost::shared_ptr<AutomationControl> ac = wac.lock();
530 ac->start_touch (ac->session().transport_frame());
534 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
536 boost::shared_ptr<AutomationControl> ac = wac.lock();
540 ac->stop_touch (false, ac->session().transport_frame());
544 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
546 switch (ev->button) {
548 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
550 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
559 pan_menu = manage (new Menu);
560 pan_menu->set_name ("ArdourContextMenu");
562 build_pan_menu (which);
563 pan_menu->popup (1, ev->time);
570 return false; // what's wrong with gcc?
574 PannerUI::build_pan_menu (uint32_t which)
576 using namespace Menu_Helpers;
577 MenuList& items (pan_menu->items());
581 items.push_back (CheckMenuElem (_("Mute")));
583 /* set state first, connect second */
585 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
586 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
587 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_mute), which));
589 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
590 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
592 /* set state first, connect second */
594 bypass_menu_item->set_active (_panner->bypassed());
595 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
597 items.push_back (MenuElem (_("Reset"), sigc::bind (sigc::mem_fun (*this, &PannerUI::pan_reset), which)));
598 items.push_back (SeparatorElem());
599 items.push_back (MenuElem (_("Reset all"), sigc::mem_fun (*this, &PannerUI::pan_reset_all)));
603 PannerUI::pan_mute (uint32_t which)
605 StreamPanner& sp = _panner->streampanner(which);
606 sp.set_muted (!sp.muted());
610 PannerUI::pan_bypass_toggle ()
612 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
613 _panner->set_bypassed (!_panner->bypassed());
618 PannerUI::pan_reset (uint32_t which)
620 _panner->reset_streampanner (which);
624 PannerUI::pan_reset_all ()
626 _panner->reset_to_default ();
630 PannerUI::effective_pan_display ()
632 if (_panner->empty()) {
636 switch (_panner->nouts()) {
643 update_pan_bars (true);
647 //panner->move_puck (pan_value (v, right), 0.5);
653 PannerUI::pan_adjustment_changed (uint32_t which)
655 if (!in_pan_update && which < _panner->npanners()) {
657 float val = pan_adjustments[which]->get_value ();
658 float const xpos = _panner->pan_control(which)->get_value();
660 /* add a kinda-sorta detent for the middle */
662 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
663 /* this is going to be reentrant, so just
667 in_pan_update = true;
668 pan_adjustments[which]->set_value (0.5);
669 in_pan_update = false;
673 if (!Panner::equivalent (val, xpos)) {
675 _panner->pan_control(which)->set_value (val);
677 the panner objects have no access to the session,
678 so do this here. ick.
680 _session->set_dirty();
686 PannerUI::pan_value_changed (uint32_t which)
688 ENSURE_GUI_THREAD (*this, &PannerUI::pan_value_changed, which)
692 in_pan_update = true;
693 twod_panner->move_puck (which, _panner->streampanner(which).get_position());
694 in_pan_update = false;
696 } else if (_stereo_panner) {
698 /* its taken care of */
700 } else if (_panner->npanners() > 0 && which < _panner->npanners()) {
702 AngularVector model = _panner->streampanner(which).get_position();
703 double fract = pan_adjustments[which]->get_value();
704 AngularVector view (BaseStereoPanner::lr_fract_to_azimuth (fract), 0.0);
706 if (!Panner::equivalent (model, view)) {
707 in_pan_update = true;
708 pan_adjustments[which]->set_value (BaseStereoPanner::azimuth_to_lr_fract (model.azi));
709 in_pan_update = false;
715 PannerUI::update_pan_bars (bool only_if_aplay)
718 vector<Adjustment*>::iterator i;
720 in_pan_update = true;
722 /* this runs during automation playback, and moves the bar controllers
726 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
729 boost::shared_ptr<AutomationList> alist (_panner->streampanner(n).pan_control()->alist());
731 if (!alist->automation_playback()) {
736 AngularVector model = _panner->streampanner(n).get_effective_position();
737 double fract = (*i)->get_value();
738 AngularVector view (BaseStereoPanner::lr_fract_to_azimuth (fract), 0.0);
740 if (!Panner::equivalent (model, view)) {
741 (*i)->set_value (BaseStereoPanner::azimuth_to_lr_fract (model.azi));
745 in_pan_update = false;
749 PannerUI::update_pan_sensitive ()
751 bool const sensitive = !(_panner->mono()) && !(_panner->automation_state() & Play);
753 switch (_panner->nouts()) {
758 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
759 (*i)->set_sensitive (sensitive);
764 twod_panner->set_sensitive (sensitive);
767 big_window->set_sensitive (sensitive);
774 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
776 using namespace Menu_Helpers;
778 if (ev->type == GDK_BUTTON_RELEASE) {
782 switch (ev->button) {
784 if (pan_astate_menu == 0) {
785 build_astate_menu ();
787 pan_astate_menu->popup (1, ev->time);
797 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
799 if (ev->type == GDK_BUTTON_RELEASE) {
803 switch (ev->button) {
805 if (pan_astyle_menu == 0) {
806 build_astyle_menu ();
808 pan_astyle_menu->popup (1, ev->time);
817 PannerUI::pan_automation_style_changed ()
819 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
823 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
826 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
832 PannerUI::pan_automation_state_changed ()
834 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_state_changed)
840 pan_automation_state_button.set_label (astate_string(_panner->automation_state()));
843 pan_automation_state_button.set_label (short_astate_string(_panner->automation_state()));
847 /* when creating a new session, we get to create busses (and
848 sometimes tracks) with no outputs by the time they get
852 if (_panner->empty()) {
856 x = (_panner->streampanner(0).pan_control()->alist()->automation_state() != Off);
858 if (pan_automation_state_button.get_active() != x) {
859 ignore_toggle = true;
860 pan_automation_state_button.set_active (x);
861 ignore_toggle = false;
864 update_pan_sensitive ();
866 /* start watching automation so that things move */
868 pan_watching.disconnect();
871 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
876 PannerUI::astate_string (AutoState state)
878 return _astate_string (state, false);
882 PannerUI::short_astate_string (AutoState state)
884 return _astate_string (state, true);
888 PannerUI::_astate_string (AutoState state, bool shrt)
894 sstr = (shrt ? "M" : _("M"));
897 sstr = (shrt ? "P" : _("P"));
900 sstr = (shrt ? "T" : _("T"));
903 sstr = (shrt ? "W" : _("W"));
911 PannerUI::astyle_string (AutoStyle style)
913 return _astyle_string (style, false);
917 PannerUI::short_astyle_string (AutoStyle style)
919 return _astyle_string (style, true);
923 PannerUI::_astyle_string (AutoStyle style, bool shrt)
928 /* XXX it might different in different languages */
930 return (shrt ? _("Abs") : _("Abs"));
935 PannerUI::set_mono (bool yn)
937 _panner->set_mono (yn);
938 update_pan_sensitive ();
943 PannerUI::connect_to_pan_control (uint32_t i)
945 _panner->pan_control(i)->Changed.connect (
946 _pan_control_connections, invalidator (*this), boost::bind (&PannerUI::pan_value_changed, this, i), gui_context ()
951 PannerUI::bar_spinner_activate (bool a)
953 _bar_spinner_active = a;
957 PannerUI::show_width ()
962 PannerUI::width_adjusted ()
967 PannerUI::show_position ()
972 PannerUI::position_adjusted ()