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 ("")
64 ignore_toggle = false;
68 in_pan_update = false;
70 pan_automation_style_button.set_name ("MixerAutomationModeButton");
71 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
73 ARDOUR_UI::instance()->set_tip (pan_automation_state_button, _("Pan automation mode"));
74 ARDOUR_UI::instance()->set_tip (pan_automation_style_button, _("Pan automation type"));
76 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
77 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
79 panning_viewport.set_name (X_("BaseFrame"));
81 ARDOUR_UI::instance()->set_tip (panning_link_button,
82 _("panning link control"));
83 ARDOUR_UI::instance()->set_tip (panning_link_direction_button,
84 _("panning link direction"));
86 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
87 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
89 pan_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
90 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
92 panning_link_button.set_name (X_("PanningLinkButton"));
93 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
95 panning_link_box.pack_start (panning_link_button, true, true);
96 panning_link_box.pack_start (panning_link_direction_button, true, true);
97 panning_link_box.pack_start (pan_automation_state_button, true, true);
99 /* the pixmap will be reset at some point, but the key thing is that
100 we need a pixmap in the button just to get started.
102 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
104 panning_link_direction_button.signal_clicked().connect
105 (sigc::mem_fun(*this, &PannerUI::panning_link_direction_clicked));
107 panning_link_button.signal_button_press_event().connect
108 (sigc::mem_fun(*this, &PannerUI::panning_link_button_press), false);
109 panning_link_button.signal_button_release_event().connect
110 (sigc::mem_fun(*this, &PannerUI::panning_link_button_release), false);
112 panning_up.set_border_width (3);
113 panning_down.set_border_width (3);
114 panning_up.add (panning_up_arrow);
115 panning_down.add (panning_down_arrow);
116 panning_up.set_name (X_("PanScrollerBase"));
117 panning_down.set_name (X_("PanScrollerBase"));
118 panning_up_arrow.set_name (X_("PanScrollerArrow"));
119 panning_down_arrow.set_name (X_("PanScrollerArrow"));
121 pan_vbox.set_spacing (2);
122 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
123 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
125 pack_start (pan_vbox, true, true);
134 PannerUI::set_panner (boost::shared_ptr<Panner> p)
136 connections.drop_connections ();
138 delete pan_astyle_menu;
141 delete pan_astate_menu;
153 _panner->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panner_changed, this, this), gui_context());
154 _panner->LinkStateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_linkage, this), gui_context());
155 _panner->StateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_state, this), gui_context());
158 update_pan_sensitive ();
159 update_pan_linkage ();
160 pan_automation_state_changed ();
164 PannerUI::build_astate_menu ()
166 using namespace Menu_Helpers;
168 if (pan_astate_menu == 0) {
169 pan_astate_menu = new Menu;
170 pan_astate_menu->set_name ("ArdourContextMenu");
172 pan_astate_menu->items().clear ();
175 pan_astate_menu->items().push_back (MenuElem (_("Manual"), sigc::bind (
176 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
178 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
179 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
181 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
182 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
183 (AutoState) Write)));
184 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
185 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
186 (AutoState) Touch)));
191 PannerUI::build_astyle_menu ()
193 using namespace Menu_Helpers;
195 if (pan_astyle_menu == 0) {
196 pan_astyle_menu = new Menu;
197 pan_astyle_menu->set_name ("ArdourContextMenu");
199 pan_astyle_menu->items().clear();
202 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
203 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
206 boost::shared_ptr<PBD::Controllable>
207 PannerUI::get_controllable()
209 return pan_bars[0]->get_controllable();
213 PannerUI::panning_link_button_press (GdkEventButton*)
219 PannerUI::panning_link_button_release (GdkEventButton*)
221 if (!ignore_toggle) {
222 _panner->set_linked (!_panner->linked());
228 PannerUI::panning_link_direction_clicked()
230 switch (_panner->link_direction()) {
231 case Panner::SameDirection:
232 _panner->set_link_direction (Panner::OppositeDirection);
235 _panner->set_link_direction (Panner::SameDirection);
241 PannerUI::update_pan_linkage ()
243 ENSURE_GUI_THREAD (*this, &PannerUI::update_pan_linkage)
245 bool const x = _panner->linked();
246 bool const bx = panning_link_button.get_active();
250 ignore_toggle = true;
251 panning_link_button.set_active (x);
252 ignore_toggle = false;
255 panning_link_direction_button.set_sensitive (x);
257 switch (_panner->link_direction()) {
258 case Panner::SameDirection:
259 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
262 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
268 PannerUI::set_width (Width w)
272 panning_link_button.set_label (_("link"));
275 panning_link_button.set_label (_("L"));
283 PannerUI::~PannerUI ()
285 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
289 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
296 delete pan_astyle_menu;
297 delete pan_astate_menu;
302 PannerUI::panner_changed (void* src)
304 ENSURE_GUI_THREAD (*this, &PannerUI::panner_changed)
312 switch (_panner->npanners()) {
314 panning_link_direction_button.set_sensitive (false);
315 panning_link_button.set_sensitive (false);
318 panning_link_direction_button.set_sensitive (false);
319 panning_link_button.set_sensitive (false);
322 panning_link_direction_button.set_sensitive (_panner->linked ());
323 panning_link_button.set_sensitive (true);
326 uint32_t const nouts = _panner->nouts();
335 /* bring pan bar state up to date */
336 update_pan_bars (false);
340 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
346 PannerUI::update_pan_state ()
348 /* currently nothing to do */
349 // ENSURE_GUI_THREAD (*this, &PannerUI::update_panner_state)
353 PannerUI::setup_pan ()
359 uint32_t const nouts = _panner->nouts();
360 uint32_t const npans = _panner->npanners();
362 if (int32_t (nouts) == _current_nouts && int32_t (npans) == _current_npans) {
366 _pan_control_connections.drop_connections ();
367 for (uint32_t i = 0; i < _panner->npanners(); ++i) {
368 connect_to_pan_control (i);
371 _current_nouts = nouts;
372 _current_npans = npans;
374 if (nouts == 0 || nouts == 1) {
376 while (!pan_adjustments.empty()) {
377 delete pan_bars.back();
378 pan_bars.pop_back ();
379 delete pan_adjustments.back();
380 pan_adjustments.pop_back ();
386 /* stick something into the panning viewport so that it redraws */
388 EventBox* eb = manage (new EventBox());
389 panning_viewport.remove ();
390 panning_viewport.add (*eb);
391 panning_viewport.show_all ();
393 } else if (nouts == 2) {
395 vector<Adjustment*>::size_type asz;
397 while (!pan_adjustments.empty()) {
398 delete pan_bars.back();
399 pan_bars.pop_back ();
400 delete pan_adjustments.back();
401 pan_adjustments.pop_back ();
407 while ((asz = pan_adjustments.size()) < npans) {
412 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
413 which serves as a default, otherwise use current value */
415 rx = _panner->pan_control( asz)->get_value();
419 } else if (asz == 0) {
421 } else if (asz == 1) {
427 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
428 bc = new PannerBar (*pan_adjustments[asz],
429 boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
431 /* now set adjustment with current value of panner, then connect the signals */
432 pan_adjustments.back()->set_value(rx);
433 pan_adjustments.back()->signal_value_changed().connect (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
434 connect_to_pan_control (asz);
436 bc->set_name ("PanSlider");
437 bc->set_shadow_type (Gtk::SHADOW_NONE);
439 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
442 bc->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
443 boost::weak_ptr<AutomationControl> (ac)));
444 bc->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
445 boost::weak_ptr<AutomationControl>(ac)));
449 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
450 ARDOUR_UI::instance()->set_tip (bc->event_widget(), buf);
452 bc->event_widget().signal_button_release_event().connect
453 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
455 bc->set_size_request (-1, pan_bar_height);
457 pan_bars.push_back (bc);
458 pan_bar_packer.pack_start (*bc, false, false);
461 /* now that we actually have the pan bars,
462 set their sensitivity based on current
466 update_pan_sensitive ();
468 panning_viewport.remove ();
469 panning_viewport.add (pan_bar_packer);
470 panning_viewport.show_all ();
475 twod_panner = new Panner2d (_panner, 61);
476 twod_panner->set_name ("MixerPanZone");
477 twod_panner->show ();
479 twod_panner->signal_button_press_event().connect
480 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
483 update_pan_sensitive ();
484 twod_panner->reset (npans);
486 big_window->reset (npans);
488 twod_panner->set_size_request (-1, 61);
490 /* and finally, add it to the panner frame */
492 panning_viewport.remove ();
493 panning_viewport.add (*twod_panner);
494 panning_viewport.show_all ();
499 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
501 boost::shared_ptr<AutomationControl> ac = wac.lock();
505 ac->start_touch (ac->session().transport_frame());
509 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
511 boost::shared_ptr<AutomationControl> ac = wac.lock();
515 ac->stop_touch (false, ac->session().transport_frame());
519 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
521 switch (ev->button) {
523 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
525 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
534 pan_menu = manage (new Menu);
535 pan_menu->set_name ("ArdourContextMenu");
537 build_pan_menu (which);
538 pan_menu->popup (1, ev->time);
545 return false; // what's wrong with gcc?
549 PannerUI::build_pan_menu (uint32_t which)
551 using namespace Menu_Helpers;
552 MenuList& items (pan_menu->items());
556 items.push_back (CheckMenuElem (_("Mute")));
558 /* set state first, connect second */
560 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
561 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
562 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_mute), which));
564 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
565 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
567 /* set state first, connect second */
569 bypass_menu_item->set_active (_panner->bypassed());
570 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
572 items.push_back (MenuElem (_("Reset"), sigc::bind (sigc::mem_fun (*this, &PannerUI::pan_reset), which)));
573 items.push_back (SeparatorElem());
574 items.push_back (MenuElem (_("Reset all"), sigc::mem_fun (*this, &PannerUI::pan_reset_all)));
578 PannerUI::pan_mute (uint32_t which)
580 StreamPanner& sp = _panner->streampanner(which);
581 sp.set_muted (!sp.muted());
585 PannerUI::pan_bypass_toggle ()
587 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
588 _panner->set_bypassed (!_panner->bypassed());
593 PannerUI::pan_reset (uint32_t which)
595 _panner->reset_streampanner (which);
599 PannerUI::pan_reset_all ()
601 _panner->reset_to_default ();
605 PannerUI::effective_pan_display ()
607 if (_panner->empty()) {
611 switch (_panner->nouts()) {
618 update_pan_bars (true);
622 //panner->move_puck (pan_value (v, right), 0.5);
628 PannerUI::pan_adjustment_changed (uint32_t which)
630 if (!in_pan_update && which < _panner->npanners()) {
632 float val = pan_adjustments[which]->get_value ();
633 float const xpos = _panner->pan_control(which)->get_value();
635 /* add a kinda-sorta detent for the middle */
637 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
638 /* this is going to be reentrant, so just
642 in_pan_update = true;
643 pan_adjustments[which]->set_value (0.5);
644 in_pan_update = false;
648 if (!Panner::equivalent (val, xpos)) {
650 _panner->pan_control(which)->set_value (val);
652 the panner objects have no access to the session,
653 so do this here. ick.
655 _session->set_dirty();
661 PannerUI::pan_value_changed (uint32_t which)
663 ENSURE_GUI_THREAD (*this, &PannerUI::pan_value_changed, which)
669 _panner->streampanner(which).get_position (x, y);
671 in_pan_update = true;
672 twod_panner->move_puck (which, x, y);
673 in_pan_update = false;
675 } else if (_panner->npanners() > 0 && which < _panner->npanners()) {
677 float val = pan_adjustments[which]->get_value ();
679 _panner->streampanner(which).get_position (xpos);
681 if (!Panner::equivalent (val, xpos)) {
682 in_pan_update = true;
683 pan_adjustments[which]->set_value (xpos);
684 in_pan_update = false;
690 PannerUI::update_pan_bars (bool only_if_aplay)
693 vector<Adjustment*>::iterator i;
695 in_pan_update = true;
697 /* this runs during automation playback, and moves the bar controllers
701 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
705 boost::shared_ptr<AutomationList> alist (_panner->streampanner(n).pan_control()->alist());
707 if (!alist->automation_playback()) {
712 _panner->streampanner(n).get_effective_position (xpos);
713 val = (*i)->get_value ();
715 if (!Panner::equivalent (val, xpos)) {
716 (*i)->set_value (xpos);
720 in_pan_update = false;
724 PannerUI::update_pan_sensitive ()
726 bool const sensitive = !(_panner->mono()) && !(_panner->automation_state() & Play);
728 switch (_panner->nouts()) {
733 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
734 (*i)->set_sensitive (sensitive);
739 twod_panner->set_sensitive (sensitive);
742 big_window->set_sensitive (sensitive);
749 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
751 using namespace Menu_Helpers;
753 if (ev->type == GDK_BUTTON_RELEASE) {
757 switch (ev->button) {
759 if (pan_astate_menu == 0) {
760 build_astate_menu ();
762 pan_astate_menu->popup (1, ev->time);
772 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
774 if (ev->type == GDK_BUTTON_RELEASE) {
778 switch (ev->button) {
780 if (pan_astyle_menu == 0) {
781 build_astyle_menu ();
783 pan_astyle_menu->popup (1, ev->time);
792 PannerUI::pan_automation_style_changed ()
794 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
798 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
801 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
807 PannerUI::pan_automation_state_changed ()
809 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_state_changed)
815 pan_automation_state_button.set_label (astate_string(_panner->automation_state()));
818 pan_automation_state_button.set_label (short_astate_string(_panner->automation_state()));
822 /* when creating a new session, we get to create busses (and
823 sometimes tracks) with no outputs by the time they get
827 if (_panner->empty()) {
831 x = (_panner->streampanner(0).pan_control()->alist()->automation_state() != Off);
833 if (pan_automation_state_button.get_active() != x) {
834 ignore_toggle = true;
835 pan_automation_state_button.set_active (x);
836 ignore_toggle = false;
839 update_pan_sensitive ();
841 /* start watching automation so that things move */
843 pan_watching.disconnect();
846 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
851 PannerUI::astate_string (AutoState state)
853 return _astate_string (state, false);
857 PannerUI::short_astate_string (AutoState state)
859 return _astate_string (state, true);
863 PannerUI::_astate_string (AutoState state, bool shrt)
869 sstr = (shrt ? "M" : _("M"));
872 sstr = (shrt ? "P" : _("P"));
875 sstr = (shrt ? "T" : _("T"));
878 sstr = (shrt ? "W" : _("W"));
886 PannerUI::astyle_string (AutoStyle style)
888 return _astyle_string (style, false);
892 PannerUI::short_astyle_string (AutoStyle style)
894 return _astyle_string (style, true);
898 PannerUI::_astyle_string (AutoStyle style, bool shrt)
903 /* XXX it might different in different languages */
905 return (shrt ? _("Abs") : _("Abs"));
910 PannerUI::set_mono (bool yn)
912 _panner->set_mono (yn);
913 update_pan_sensitive ();
918 PannerUI::connect_to_pan_control (uint32_t i)
920 _panner->pan_control(i)->Changed.connect (
921 _pan_control_connections, invalidator (*this), boost::bind (&PannerUI::pan_value_changed, this, i), gui_context ()