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"
35 #include "ardour/delivery.h"
36 #include "ardour/session.h"
37 #include "ardour/panner.h"
38 #include "ardour/route.h"
43 using namespace ARDOUR;
45 using namespace Gtkmm2ext;
48 const int PannerUI::pan_bar_height = 30;
50 PannerUI::PannerUI (Session* s)
53 , hAdjustment(0.0, 0.0, 0.0)
54 , vAdjustment(0.0, 0.0, 0.0)
55 , panning_viewport(hAdjustment, vAdjustment)
56 , panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT)
57 , panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT)
58 , panning_link_button (_("link"))
59 , pan_automation_style_button ("")
60 , pan_automation_state_button ("")
61 , _bar_spinner_active (false)
65 ignore_toggle = false;
69 in_pan_update = false;
71 pan_automation_style_button.set_name ("MixerAutomationModeButton");
72 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
74 ARDOUR_UI::instance()->set_tip (pan_automation_state_button, _("Pan automation mode"));
75 ARDOUR_UI::instance()->set_tip (pan_automation_style_button, _("Pan automation type"));
77 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
78 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
80 panning_viewport.set_name (X_("BaseFrame"));
82 ARDOUR_UI::instance()->set_tip (panning_link_button,
83 _("panning link control"));
84 ARDOUR_UI::instance()->set_tip (panning_link_direction_button,
85 _("panning link direction"));
87 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
88 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
90 pan_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
91 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
93 panning_link_button.set_name (X_("PanningLinkButton"));
94 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
96 panning_link_box.pack_start (panning_link_button, true, true);
97 panning_link_box.pack_start (panning_link_direction_button, true, true);
98 panning_link_box.pack_start (pan_automation_state_button, true, true);
100 /* the pixmap will be reset at some point, but the key thing is that
101 we need a pixmap in the button just to get started.
103 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
105 panning_link_direction_button.signal_clicked().connect
106 (sigc::mem_fun(*this, &PannerUI::panning_link_direction_clicked));
108 panning_link_button.signal_button_press_event().connect
109 (sigc::mem_fun(*this, &PannerUI::panning_link_button_press), false);
110 panning_link_button.signal_button_release_event().connect
111 (sigc::mem_fun(*this, &PannerUI::panning_link_button_release), false);
113 panning_up.set_border_width (3);
114 panning_down.set_border_width (3);
115 panning_up.add (panning_up_arrow);
116 panning_down.add (panning_down_arrow);
117 panning_up.set_name (X_("PanScrollerBase"));
118 panning_down.set_name (X_("PanScrollerBase"));
119 panning_up_arrow.set_name (X_("PanScrollerArrow"));
120 panning_down_arrow.set_name (X_("PanScrollerArrow"));
122 pan_vbox.set_spacing (2);
123 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
124 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
126 pack_start (pan_vbox, true, true);
135 PannerUI::set_panner (boost::shared_ptr<Panner> p)
137 connections.drop_connections ();
139 delete pan_astyle_menu;
142 delete pan_astate_menu;
154 _panner->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panner_changed, this, this), gui_context());
155 _panner->LinkStateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_linkage, this), gui_context());
156 _panner->StateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_state, this), gui_context());
159 update_pan_sensitive ();
160 update_pan_linkage ();
161 pan_automation_state_changed ();
165 PannerUI::build_astate_menu ()
167 using namespace Menu_Helpers;
169 if (pan_astate_menu == 0) {
170 pan_astate_menu = new Menu;
171 pan_astate_menu->set_name ("ArdourContextMenu");
173 pan_astate_menu->items().clear ();
176 pan_astate_menu->items().push_back (MenuElem (_("Manual"), sigc::bind (
177 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
179 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
180 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
182 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
183 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
184 (AutoState) Write)));
185 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
186 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
187 (AutoState) Touch)));
192 PannerUI::build_astyle_menu ()
194 using namespace Menu_Helpers;
196 if (pan_astyle_menu == 0) {
197 pan_astyle_menu = new Menu;
198 pan_astyle_menu->set_name ("ArdourContextMenu");
200 pan_astyle_menu->items().clear();
203 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
204 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
207 boost::shared_ptr<PBD::Controllable>
208 PannerUI::get_controllable()
210 return pan_bars[0]->get_controllable();
214 PannerUI::panning_link_button_press (GdkEventButton*)
220 PannerUI::panning_link_button_release (GdkEventButton*)
222 if (!ignore_toggle) {
223 _panner->set_linked (!_panner->linked());
229 PannerUI::panning_link_direction_clicked()
231 switch (_panner->link_direction()) {
232 case Panner::SameDirection:
233 _panner->set_link_direction (Panner::OppositeDirection);
236 _panner->set_link_direction (Panner::SameDirection);
242 PannerUI::update_pan_linkage ()
244 ENSURE_GUI_THREAD (*this, &PannerUI::update_pan_linkage)
246 bool const x = _panner->linked();
247 bool const bx = panning_link_button.get_active();
251 ignore_toggle = true;
252 panning_link_button.set_active (x);
253 ignore_toggle = false;
256 panning_link_direction_button.set_sensitive (x);
258 switch (_panner->link_direction()) {
259 case Panner::SameDirection:
260 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
263 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
269 PannerUI::set_width (Width w)
273 panning_link_button.set_label (_("link"));
276 panning_link_button.set_label (_("L"));
284 PannerUI::~PannerUI ()
286 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
290 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
297 delete pan_astyle_menu;
298 delete pan_astate_menu;
303 PannerUI::panner_changed (void* src)
305 ENSURE_GUI_THREAD (*this, &PannerUI::panner_changed)
313 switch (_panner->npanners()) {
315 panning_link_direction_button.set_sensitive (false);
316 panning_link_button.set_sensitive (false);
319 panning_link_direction_button.set_sensitive (false);
320 panning_link_button.set_sensitive (false);
323 panning_link_direction_button.set_sensitive (_panner->linked ());
324 panning_link_button.set_sensitive (true);
327 uint32_t const nouts = _panner->nouts();
336 /* bring pan bar state up to date */
337 update_pan_bars (false);
341 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
347 PannerUI::update_pan_state ()
349 /* currently nothing to do */
350 // ENSURE_GUI_THREAD (*this, &PannerUI::update_panner_state)
354 PannerUI::setup_pan ()
360 uint32_t const nouts = _panner->nouts();
361 uint32_t const npans = _panner->npanners();
363 if (int32_t (nouts) == _current_nouts && int32_t (npans) == _current_npans) {
367 _pan_control_connections.drop_connections ();
368 for (uint32_t i = 0; i < _panner->npanners(); ++i) {
369 connect_to_pan_control (i);
372 _current_nouts = nouts;
373 _current_npans = npans;
375 if (nouts == 0 || nouts == 1) {
377 while (!pan_adjustments.empty()) {
378 delete pan_bars.back();
379 pan_bars.pop_back ();
380 delete pan_adjustments.back();
381 pan_adjustments.pop_back ();
387 /* stick something into the panning viewport so that it redraws */
389 EventBox* eb = manage (new EventBox());
390 panning_viewport.remove ();
391 panning_viewport.add (*eb);
392 panning_viewport.show_all ();
394 } else if (nouts == 2) {
396 vector<Adjustment*>::size_type asz;
398 while (!pan_adjustments.empty()) {
399 delete pan_bars.back();
400 pan_bars.pop_back ();
401 delete pan_adjustments.back();
402 pan_adjustments.pop_back ();
408 while ((asz = pan_adjustments.size()) < npans) {
413 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
414 which serves as a default, otherwise use current value */
416 rx = _panner->pan_control( asz)->get_value();
420 } else if (asz == 0) {
422 } else if (asz == 1) {
428 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
429 bc = new PannerBar (*pan_adjustments[asz],
430 boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
432 /* now set adjustment with current value of panner, then connect the signals */
433 pan_adjustments.back()->set_value(rx);
434 pan_adjustments.back()->signal_value_changed().connect (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
435 connect_to_pan_control (asz);
437 bc->set_name ("PanSlider");
438 bc->set_shadow_type (Gtk::SHADOW_NONE);
440 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
443 bc->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
444 boost::weak_ptr<AutomationControl> (ac)));
445 bc->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
446 boost::weak_ptr<AutomationControl>(ac)));
450 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
451 ARDOUR_UI::instance()->set_tip (bc->event_widget(), buf);
453 bc->event_widget().signal_button_release_event().connect
454 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
456 bc->set_size_request (-1, pan_bar_height);
457 bc->SpinnerActive.connect (sigc::mem_fun (*this, &PannerUI::bar_spinner_activate));
459 pan_bars.push_back (bc);
460 pan_bar_packer.pack_start (*bc, false, false);
463 /* now that we actually have the pan bars,
464 set their sensitivity based on current
468 update_pan_sensitive ();
470 panning_viewport.remove ();
471 panning_viewport.add (pan_bar_packer);
472 panning_viewport.show_all ();
477 twod_panner = new Panner2d (_panner, 61);
478 twod_panner->set_name ("MixerPanZone");
479 twod_panner->show ();
481 twod_panner->signal_button_press_event().connect
482 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
485 update_pan_sensitive ();
486 twod_panner->reset (npans);
488 big_window->reset (npans);
490 twod_panner->set_size_request (-1, 61);
492 /* and finally, add it to the panner frame */
494 panning_viewport.remove ();
495 panning_viewport.add (*twod_panner);
496 panning_viewport.show_all ();
501 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
503 boost::shared_ptr<AutomationControl> ac = wac.lock();
507 ac->start_touch (ac->session().transport_frame());
511 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
513 boost::shared_ptr<AutomationControl> ac = wac.lock();
517 ac->stop_touch (false, ac->session().transport_frame());
521 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
523 switch (ev->button) {
525 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
527 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
536 pan_menu = manage (new Menu);
537 pan_menu->set_name ("ArdourContextMenu");
539 build_pan_menu (which);
540 pan_menu->popup (1, ev->time);
547 return false; // what's wrong with gcc?
551 PannerUI::build_pan_menu (uint32_t which)
553 using namespace Menu_Helpers;
554 MenuList& items (pan_menu->items());
558 items.push_back (CheckMenuElem (_("Mute")));
560 /* set state first, connect second */
562 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
563 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
564 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_mute), which));
566 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
567 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
569 /* set state first, connect second */
571 bypass_menu_item->set_active (_panner->bypassed());
572 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
574 items.push_back (MenuElem (_("Reset"), sigc::bind (sigc::mem_fun (*this, &PannerUI::pan_reset), which)));
575 items.push_back (SeparatorElem());
576 items.push_back (MenuElem (_("Reset all"), sigc::mem_fun (*this, &PannerUI::pan_reset_all)));
580 PannerUI::pan_mute (uint32_t which)
582 StreamPanner& sp = _panner->streampanner(which);
583 sp.set_muted (!sp.muted());
587 PannerUI::pan_bypass_toggle ()
589 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
590 _panner->set_bypassed (!_panner->bypassed());
595 PannerUI::pan_reset (uint32_t which)
597 _panner->reset_streampanner (which);
601 PannerUI::pan_reset_all ()
603 _panner->reset_to_default ();
607 PannerUI::effective_pan_display ()
609 if (_panner->empty()) {
613 switch (_panner->nouts()) {
620 update_pan_bars (true);
624 //panner->move_puck (pan_value (v, right), 0.5);
630 PannerUI::pan_adjustment_changed (uint32_t which)
632 if (!in_pan_update && which < _panner->npanners()) {
634 float val = pan_adjustments[which]->get_value ();
635 float const xpos = _panner->pan_control(which)->get_value();
637 /* add a kinda-sorta detent for the middle */
639 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
640 /* this is going to be reentrant, so just
644 in_pan_update = true;
645 pan_adjustments[which]->set_value (0.5);
646 in_pan_update = false;
650 if (!Panner::equivalent (val, xpos)) {
652 _panner->pan_control(which)->set_value (val);
654 the panner objects have no access to the session,
655 so do this here. ick.
657 _session->set_dirty();
663 PannerUI::pan_value_changed (uint32_t which)
665 ENSURE_GUI_THREAD (*this, &PannerUI::pan_value_changed, which)
671 _panner->streampanner(which).get_position (x, y);
673 in_pan_update = true;
674 twod_panner->move_puck (which, x, y);
675 in_pan_update = false;
677 } else if (_panner->npanners() > 0 && which < _panner->npanners()) {
679 float val = pan_adjustments[which]->get_value ();
681 _panner->streampanner(which).get_position (xpos);
683 if (!Panner::equivalent (val, xpos)) {
684 in_pan_update = true;
685 pan_adjustments[which]->set_value (xpos);
686 in_pan_update = false;
692 PannerUI::update_pan_bars (bool only_if_aplay)
695 vector<Adjustment*>::iterator i;
697 in_pan_update = true;
699 /* this runs during automation playback, and moves the bar controllers
703 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
707 boost::shared_ptr<AutomationList> alist (_panner->streampanner(n).pan_control()->alist());
709 if (!alist->automation_playback()) {
714 _panner->streampanner(n).get_effective_position (xpos);
715 val = (*i)->get_value ();
717 if (!Panner::equivalent (val, xpos)) {
718 (*i)->set_value (xpos);
722 in_pan_update = false;
726 PannerUI::update_pan_sensitive ()
728 bool const sensitive = !(_panner->mono()) && !(_panner->automation_state() & Play);
730 switch (_panner->nouts()) {
735 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
736 (*i)->set_sensitive (sensitive);
741 twod_panner->set_sensitive (sensitive);
744 big_window->set_sensitive (sensitive);
751 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
753 using namespace Menu_Helpers;
755 if (ev->type == GDK_BUTTON_RELEASE) {
759 switch (ev->button) {
761 if (pan_astate_menu == 0) {
762 build_astate_menu ();
764 pan_astate_menu->popup (1, ev->time);
774 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
776 if (ev->type == GDK_BUTTON_RELEASE) {
780 switch (ev->button) {
782 if (pan_astyle_menu == 0) {
783 build_astyle_menu ();
785 pan_astyle_menu->popup (1, ev->time);
794 PannerUI::pan_automation_style_changed ()
796 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
800 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
803 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
809 PannerUI::pan_automation_state_changed ()
811 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_state_changed)
817 pan_automation_state_button.set_label (astate_string(_panner->automation_state()));
820 pan_automation_state_button.set_label (short_astate_string(_panner->automation_state()));
824 /* when creating a new session, we get to create busses (and
825 sometimes tracks) with no outputs by the time they get
829 if (_panner->empty()) {
833 x = (_panner->streampanner(0).pan_control()->alist()->automation_state() != Off);
835 if (pan_automation_state_button.get_active() != x) {
836 ignore_toggle = true;
837 pan_automation_state_button.set_active (x);
838 ignore_toggle = false;
841 update_pan_sensitive ();
843 /* start watching automation so that things move */
845 pan_watching.disconnect();
848 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
853 PannerUI::astate_string (AutoState state)
855 return _astate_string (state, false);
859 PannerUI::short_astate_string (AutoState state)
861 return _astate_string (state, true);
865 PannerUI::_astate_string (AutoState state, bool shrt)
871 sstr = (shrt ? "M" : _("M"));
874 sstr = (shrt ? "P" : _("P"));
877 sstr = (shrt ? "T" : _("T"));
880 sstr = (shrt ? "W" : _("W"));
888 PannerUI::astyle_string (AutoStyle style)
890 return _astyle_string (style, false);
894 PannerUI::short_astyle_string (AutoStyle style)
896 return _astyle_string (style, true);
900 PannerUI::_astyle_string (AutoStyle style, bool shrt)
905 /* XXX it might different in different languages */
907 return (shrt ? _("Abs") : _("Abs"));
912 PannerUI::set_mono (bool yn)
914 _panner->set_mono (yn);
915 update_pan_sensitive ();
920 PannerUI::connect_to_pan_control (uint32_t i)
922 _panner->pan_control(i)->Changed.connect (
923 _pan_control_connections, invalidator (*this), boost::bind (&PannerUI::pan_value_changed, this, i), gui_context ()
928 PannerUI::bar_spinner_activate (bool a)
930 _bar_spinner_active = a;