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/stop_signal.h>
25 #include <gtkmm2ext/barcontroller.h>
26 #include "midi++/manager.h"
27 #include "pbd/fastlog.h"
29 #include "ardour_ui.h"
30 #include "panner_ui.h"
34 #include "gui_thread.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 = 30;
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 ("")
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), 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());
161 update_pan_sensitive ();
162 update_pan_linkage ();
163 pan_automation_state_changed ();
167 PannerUI::build_astate_menu ()
169 using namespace Menu_Helpers;
171 if (pan_astate_menu == 0) {
172 pan_astate_menu = new Menu;
173 pan_astate_menu->set_name ("ArdourContextMenu");
175 pan_astate_menu->items().clear ();
178 pan_astate_menu->items().push_back (MenuElem (_("Manual"), sigc::bind (
179 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
181 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
182 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
184 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
185 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
186 (AutoState) Write)));
187 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
188 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
189 (AutoState) Touch)));
194 PannerUI::build_astyle_menu ()
196 using namespace Menu_Helpers;
198 if (pan_astyle_menu == 0) {
199 pan_astyle_menu = new Menu;
200 pan_astyle_menu->set_name ("ArdourContextMenu");
202 pan_astyle_menu->items().clear();
205 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
206 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
209 boost::shared_ptr<PBD::Controllable>
210 PannerUI::get_controllable()
212 return pan_bars[0]->get_controllable();
216 PannerUI::panning_link_button_press (GdkEventButton*)
222 PannerUI::panning_link_button_release (GdkEventButton*)
224 if (!ignore_toggle) {
225 _panner->set_linked (!_panner->linked());
231 PannerUI::panning_link_direction_clicked()
233 switch (_panner->link_direction()) {
234 case Panner::SameDirection:
235 _panner->set_link_direction (Panner::OppositeDirection);
238 _panner->set_link_direction (Panner::SameDirection);
244 PannerUI::update_pan_linkage ()
246 ENSURE_GUI_THREAD (*this, &PannerUI::update_pan_linkage)
248 bool const x = _panner->linked();
249 bool const bx = panning_link_button.get_active();
253 ignore_toggle = true;
254 panning_link_button.set_active (x);
255 ignore_toggle = false;
258 panning_link_direction_button.set_sensitive (x);
260 switch (_panner->link_direction()) {
261 case Panner::SameDirection:
262 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
265 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
271 PannerUI::set_width (Width w)
275 panning_link_button.set_label (_("link"));
278 panning_link_button.set_label (_("L"));
286 PannerUI::~PannerUI ()
288 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
292 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
299 delete pan_astyle_menu;
300 delete pan_astate_menu;
305 PannerUI::panner_changed ()
307 ENSURE_GUI_THREAD (*this, &PannerUI::panner_changed)
313 PannerUI::update_pan_state ()
315 /* currently nothing to do */
316 // ENSURE_GUI_THREAD (*this, &PannerUI::update_panner_state)
320 PannerUI::setup_pan ()
326 uint32_t const nouts = _panner->nouts();
327 uint32_t const npans = _panner->npanners();
329 if (int32_t (nouts) == _current_nouts && int32_t (npans) == _current_npans) {
333 _pan_control_connections.drop_connections ();
334 for (uint32_t i = 0; i < _panner->npanners(); ++i) {
335 connect_to_pan_control (i);
338 _current_nouts = nouts;
339 _current_npans = npans;
341 if (nouts == 0 || nouts == 1) {
343 while (!pan_adjustments.empty()) {
344 delete pan_bars.back();
345 pan_bars.pop_back ();
346 delete pan_adjustments.back();
347 pan_adjustments.pop_back ();
353 /* stick something into the panning viewport so that it redraws */
355 EventBox* eb = manage (new EventBox());
356 panning_viewport.remove ();
357 panning_viewport.add (*eb);
358 panning_viewport.show_all ();
360 } else if (nouts == 2) {
362 vector<Adjustment*>::size_type asz;
364 while (!pan_adjustments.empty()) {
365 delete pan_bars.back();
366 pan_bars.pop_back ();
367 delete pan_adjustments.back();
368 pan_adjustments.pop_back ();
374 while ((asz = pan_adjustments.size()) < npans) {
379 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
380 which serves as a default, otherwise use current value */
382 rx = _panner->pan_control( asz)->get_value();
386 } else if (asz == 0) {
388 } else if (asz == 1) {
394 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
395 bc = new PannerBar (*pan_adjustments[asz],
396 boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
398 /* now set adjustment with current value of panner, then connect the signals */
399 pan_adjustments.back()->set_value(rx);
400 pan_adjustments.back()->signal_value_changed().connect (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
401 connect_to_pan_control (asz);
403 bc->set_name ("PanSlider");
404 bc->set_shadow_type (Gtk::SHADOW_NONE);
406 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
409 bc->StartGesture.connect (sigc::mem_fun (*ac, &AutomationControl::start_touch));
410 bc->StopGesture.connect (sigc::mem_fun (*ac, &AutomationControl::stop_touch));
414 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
415 ARDOUR_UI::instance()->set_tip (bc->event_widget(), buf);
417 bc->event_widget().signal_button_release_event().connect
418 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
420 bc->set_size_request (-1, pan_bar_height);
422 pan_bars.push_back (bc);
423 pan_bar_packer.pack_start (*bc, false, false);
426 /* now that we actually have the pan bars,
427 set their sensitivity based on current
431 update_pan_sensitive ();
433 panning_viewport.remove ();
434 panning_viewport.add (pan_bar_packer);
435 panning_viewport.show_all ();
440 twod_panner = new Panner2d (_panner, 61);
441 twod_panner->set_name ("MixerPanZone");
442 twod_panner->show ();
444 twod_panner->signal_button_press_event().connect
445 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
448 update_pan_sensitive ();
449 twod_panner->reset (npans);
451 big_window->reset (npans);
453 twod_panner->set_size_request (-1, 61);
455 /* and finally, add it to the panner frame */
457 panning_viewport.remove ();
458 panning_viewport.add (*twod_panner);
459 panning_viewport.show_all ();
464 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
466 switch (ev->button) {
468 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
470 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
479 pan_menu = manage (new Menu);
480 pan_menu->set_name ("ArdourContextMenu");
482 build_pan_menu (which);
483 pan_menu->popup (1, ev->time);
490 return false; // what's wrong with gcc?
494 PannerUI::build_pan_menu (uint32_t which)
496 using namespace Menu_Helpers;
497 MenuList& items (pan_menu->items());
501 items.push_back (CheckMenuElem (_("Mute")));
503 /* set state first, connect second */
505 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
506 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
507 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_mute), which));
509 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
510 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
512 /* set state first, connect second */
514 bypass_menu_item->set_active (_panner->bypassed());
515 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
517 items.push_back (MenuElem (_("Reset"), sigc::bind (sigc::mem_fun (*this, &PannerUI::pan_reset), which)));
518 items.push_back (SeparatorElem());
519 items.push_back (MenuElem (_("Reset all"), sigc::mem_fun (*this, &PannerUI::pan_reset_all)));
523 PannerUI::pan_mute (uint32_t which)
525 StreamPanner& sp = _panner->streampanner(which);
526 sp.set_muted (!sp.muted());
530 PannerUI::pan_bypass_toggle ()
532 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
533 _panner->set_bypassed (!_panner->bypassed());
538 PannerUI::pan_reset (uint32_t which)
540 _panner->reset_streampanner (which);
544 PannerUI::pan_reset_all ()
546 _panner->reset_to_default ();
550 PannerUI::effective_pan_display ()
552 if (_panner->empty()) {
556 switch (_panner->nouts()) {
563 update_pan_bars (true);
567 //panner->move_puck (pan_value (v, right), 0.5);
573 PannerUI::pan_changed (void *src)
579 switch (_panner->npanners()) {
581 panning_link_direction_button.set_sensitive (false);
582 panning_link_button.set_sensitive (false);
585 panning_link_direction_button.set_sensitive (false);
586 panning_link_button.set_sensitive (false);
589 panning_link_direction_button.set_sensitive (_panner->linked ());
590 panning_link_button.set_sensitive (true);
593 uint32_t const nouts = _panner->nouts();
602 /* bring pan bar state up to date */
603 update_pan_bars (false);
607 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
613 PannerUI::pan_adjustment_changed (uint32_t which)
615 if (!in_pan_update && which < _panner->npanners()) {
617 float val = pan_adjustments[which]->get_value ();
618 float const xpos = _panner->pan_control(which)->get_value();
620 /* add a kinda-sorta detent for the middle */
622 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
623 /* this is going to be reentrant, so just
627 in_pan_update = true;
628 pan_adjustments[which]->set_value (0.5);
629 in_pan_update = false;
633 if (!Panner::equivalent (val, xpos)) {
635 _panner->pan_control(which)->set_value (val);
637 the panner objects have no access to the session,
638 so do this here. ick.
640 _session->set_dirty();
646 PannerUI::pan_value_changed (uint32_t which)
648 ENSURE_GUI_THREAD (*this, &PannerUI::pan_value_changed, which)
654 _panner->streampanner(which).get_position (x, y);
656 in_pan_update = true;
657 twod_panner->move_puck (which, x, y);
658 in_pan_update = false;
660 } else if (_panner->npanners() > 0 && which < _panner->npanners()) {
662 float val = pan_adjustments[which]->get_value ();
664 _panner->streampanner(which).get_position (xpos);
666 if (!Panner::equivalent (val, xpos)) {
667 in_pan_update = true;
668 pan_adjustments[which]->set_value (xpos);
669 in_pan_update = false;
675 PannerUI::update_pan_bars (bool only_if_aplay)
678 vector<Adjustment*>::iterator i;
680 in_pan_update = true;
682 /* this runs during automation playback, and moves the bar controllers
686 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
690 boost::shared_ptr<AutomationList> alist (_panner->streampanner(n).pan_control()->alist());
692 if (!alist->automation_playback()) {
697 _panner->streampanner(n).get_effective_position (xpos);
698 val = (*i)->get_value ();
700 if (!Panner::equivalent (val, xpos)) {
701 (*i)->set_value (xpos);
705 in_pan_update = false;
709 PannerUI::update_pan_sensitive ()
711 bool const sensitive = !(_panner->mono()) && !(_panner->automation_state() & Play);
713 switch (_panner->nouts()) {
718 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
719 (*i)->set_sensitive (sensitive);
724 twod_panner->set_sensitive (sensitive);
727 big_window->set_sensitive (sensitive);
734 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
736 using namespace Menu_Helpers;
738 if (ev->type == GDK_BUTTON_RELEASE) {
742 switch (ev->button) {
744 if (pan_astate_menu == 0) {
745 build_astate_menu ();
747 pan_astate_menu->popup (1, ev->time);
757 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
759 if (ev->type == GDK_BUTTON_RELEASE) {
763 switch (ev->button) {
765 if (pan_astyle_menu == 0) {
766 build_astyle_menu ();
768 pan_astyle_menu->popup (1, ev->time);
777 PannerUI::pan_automation_style_changed ()
779 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
783 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
786 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
792 PannerUI::pan_automation_state_changed ()
794 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_state_changed)
800 pan_automation_state_button.set_label (astate_string(_panner->automation_state()));
803 pan_automation_state_button.set_label (short_astate_string(_panner->automation_state()));
807 /* when creating a new session, we get to create busses (and
808 sometimes tracks) with no outputs by the time they get
812 if (_panner->empty()) {
816 x = (_panner->streampanner(0).pan_control()->alist()->automation_state() != Off);
818 if (pan_automation_state_button.get_active() != x) {
819 ignore_toggle = true;
820 pan_automation_state_button.set_active (x);
821 ignore_toggle = false;
824 update_pan_sensitive ();
826 /* start watching automation so that things move */
828 pan_watching.disconnect();
831 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
836 PannerUI::astate_string (AutoState state)
838 return _astate_string (state, false);
842 PannerUI::short_astate_string (AutoState state)
844 return _astate_string (state, true);
848 PannerUI::_astate_string (AutoState state, bool shrt)
854 sstr = (shrt ? "M" : _("M"));
857 sstr = (shrt ? "P" : _("P"));
860 sstr = (shrt ? "T" : _("T"));
863 sstr = (shrt ? "W" : _("W"));
871 PannerUI::astyle_string (AutoStyle style)
873 return _astyle_string (style, false);
877 PannerUI::short_astyle_string (AutoStyle style)
879 return _astyle_string (style, true);
883 PannerUI::_astyle_string (AutoStyle style, bool shrt)
888 /* XXX it might different in different languages */
890 return (shrt ? _("Abs") : _("Abs"));
895 PannerUI::set_mono (bool yn)
897 _panner->set_mono (yn);
898 update_pan_sensitive ();
903 PannerUI::connect_to_pan_control (uint32_t i)
905 _panner->pan_control(i)->Changed.connect (
906 _pan_control_connections, invalidator (*this), boost::bind (&PannerUI::pan_value_changed, this, i), gui_context ()