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/session.h"
37 #include "ardour/panner.h"
38 #include "ardour/route.h"
43 using namespace ARDOUR;
45 using namespace Gtkmm2ext;
49 const int PannerUI::pan_bar_height = 30;
51 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 ("")
62 ignore_toggle = false;
66 in_pan_update = false;
68 pan_automation_style_button.set_name ("MixerAutomationModeButton");
69 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
71 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
72 ARDOUR_UI::instance()->tooltips().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_bar_packer.set_size_request (-1, 61);
78 panning_viewport.set_size_request (-1, 61);
79 panning_viewport.set_name (X_("BaseFrame"));
81 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
82 _("panning link control"));
83 ARDOUR_UI::instance()->tooltips().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 (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
90 pan_automation_state_button.signal_button_press_event().connect (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 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
107 panning_link_button.signal_button_press_event().connect
108 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
109 panning_link_button.signal_button_release_event().connect
110 (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_io (boost::shared_ptr<IO> io)
137 cerr << "PannerUI::set_io IO has no panners" << endl;
141 connections.clear ();
143 delete pan_astyle_menu;
146 delete pan_astate_menu;
151 connections.push_back (_io->panner()->Changed.connect (
152 mem_fun(*this, &PannerUI::panner_changed)));
153 connections.push_back (_io->panner()->LinkStateChanged.connect (
154 mem_fun(*this, &PannerUI::update_pan_linkage)));
155 connections.push_back (_io->panner()->StateChanged.connect (
156 mem_fun(*this, &PannerUI::update_pan_state)));
164 update_pan_sensitive ();
165 update_pan_linkage ();
166 pan_automation_state_changed ();
168 #if WHERE_DOES_THIS_LIVE
169 pan_bar_packer.show();
170 panning_viewport.show();
172 panning_up_arrow.show();
174 panning_down_arrow.show();
176 panning_link_button.show();
177 panning_link_direction_button.show();
178 panning_link_box.show();
179 pan_automation_style_button.show();
180 pan_automation_state_button.show();
186 PannerUI::build_astate_menu ()
188 using namespace Menu_Helpers;
190 if (pan_astate_menu == 0) {
191 pan_astate_menu = new Menu;
192 pan_astate_menu->set_name ("ArdourContextMenu");
194 pan_astate_menu->items().clear ();
197 pan_astate_menu->items().push_back (MenuElem (_("Manual"), bind (
198 mem_fun (_io->panner().get(), &Panner::set_automation_state),
200 pan_astate_menu->items().push_back (MenuElem (_("Play"), bind (
201 mem_fun (_io->panner().get(), &Panner::set_automation_state),
203 pan_astate_menu->items().push_back (MenuElem (_("Write"), bind (
204 mem_fun (_io->panner().get(), &Panner::set_automation_state),
205 (AutoState) Write)));
206 pan_astate_menu->items().push_back (MenuElem (_("Touch"), bind (
207 mem_fun (_io->panner().get(), &Panner::set_automation_state),
208 (AutoState) Touch)));
213 PannerUI::build_astyle_menu ()
215 using namespace Menu_Helpers;
217 if (pan_astyle_menu == 0) {
218 pan_astyle_menu = new Menu;
219 pan_astyle_menu->set_name ("ArdourContextMenu");
221 pan_astyle_menu->items().clear();
224 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
225 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
228 boost::shared_ptr<PBD::Controllable>
229 PannerUI::get_controllable()
231 return pan_bars[0]->get_controllable();
235 PannerUI::panning_link_button_press (GdkEventButton* ev)
241 PannerUI::panning_link_button_release (GdkEventButton* ev)
243 if (!ignore_toggle) {
244 _io->panner()->set_linked (!_io->panner()->linked());
250 PannerUI::panning_link_direction_clicked()
252 switch (_io->panner()->link_direction()) {
253 case Panner::SameDirection:
254 _io->panner()->set_link_direction (Panner::OppositeDirection);
257 _io->panner()->set_link_direction (Panner::SameDirection);
263 PannerUI::update_pan_linkage ()
265 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
267 bool x = _io->panner()->linked();
268 bool bx = panning_link_button.get_active();
272 ignore_toggle = true;
273 panning_link_button.set_active (x);
274 ignore_toggle = false;
277 panning_link_direction_button.set_sensitive (x);
279 switch (_io->panner()->link_direction()) {
280 case Panner::SameDirection:
281 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
284 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
290 PannerUI::set_width (Width w)
294 panning_link_button.set_label (_("link"));
297 panning_link_button.set_label (_("L"));
305 PannerUI::~PannerUI ()
307 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
311 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
318 delete pan_astyle_menu;
319 delete pan_astate_menu;
324 PannerUI::panner_changed ()
326 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
332 PannerUI::update_pan_state ()
334 /* currently nothing to do */
335 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
339 PannerUI::setup_pan ()
341 if (!_io->panner()) {
345 uint32_t nouts = _io->n_outputs ().n_audio();
347 if (nouts == 0 || nouts == 1) {
349 while (!pan_adjustments.empty()) {
350 delete pan_bars.back();
351 pan_bars.pop_back ();
352 delete pan_adjustments.back();
353 pan_adjustments.pop_back ();
356 /* stick something into the panning viewport so that it redraws */
358 EventBox* eb = manage (new EventBox());
359 panning_viewport.remove ();
360 panning_viewport.add (*eb);
361 panning_viewport.show_all ();
363 } else if (nouts == 2) {
365 vector<Adjustment*>::size_type asz;
366 uint32_t npans = _io->panner()->npanners();
368 while (!pan_adjustments.empty()) {
369 delete pan_bars.back();
370 pan_bars.pop_back ();
371 delete pan_adjustments.back();
372 pan_adjustments.pop_back ();
375 while ((asz = pan_adjustments.size()) < npans) {
380 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
381 which serves as a default, otherwise use current value */
383 rx = _io->panner()->pan_control( asz)->get_value();
387 } else if (asz == 0) {
389 } else if (asz == 1) {
395 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
396 bc = new PannerBar (*pan_adjustments[asz],
397 boost::static_pointer_cast<PBD::Controllable>( _io->panner()->pan_control( asz )) );
399 /* now set adjustment with current value of panner, then connect the signals */
400 pan_adjustments.back()->set_value(rx);
401 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
403 _io->panner()->pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
406 bc->set_name ("PanSlider");
407 bc->set_shadow_type (Gtk::SHADOW_NONE);
409 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
410 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
413 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
414 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
416 bc->event_widget().signal_button_release_event().connect
417 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
419 bc->set_size_request (-1, pan_bar_height);
421 pan_bars.push_back (bc);
422 pan_bar_packer.pack_start (*bc, false, false);
425 /* now that we actually have the pan bars,
426 set their sensitivity based on current
430 update_pan_sensitive ();
432 panning_viewport.remove ();
433 panning_viewport.add (pan_bar_packer);
434 panning_viewport.show_all ();
439 panner = new Panner2d (_io->panner(), 61);
440 panner->set_name ("MixerPanZone");
443 panner->signal_button_press_event().connect
444 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
447 update_pan_sensitive ();
448 panner->reset (_io->n_inputs().n_audio());
450 big_window->reset (_io->n_inputs().n_audio());
452 panner->set_size_request (-1, 61);
454 /* and finally, add it to the panner frame */
456 panning_viewport.remove ();
457 panning_viewport.add (*panner);
458 panning_viewport.show_all ();
463 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
465 switch (ev->button) {
467 if (panner && ev->type == GDK_2BUTTON_PRESS) {
469 big_window = new Panner2dWindow (panner->get_panner(), 400, _io->n_inputs().n_audio());
478 pan_menu = manage (new Menu);
479 pan_menu->set_name ("ArdourContextMenu");
481 build_pan_menu (which);
482 pan_menu->popup (1, ev->time);
489 return false; // what's wrong with gcc?
493 PannerUI::build_pan_menu (uint32_t which)
495 using namespace Menu_Helpers;
496 MenuList& items (pan_menu->items());
500 items.push_back (CheckMenuElem (_("Mute")));
502 /* set state first, connect second */
504 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()->streampanner(which).muted());
505 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
506 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
508 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
509 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
511 /* set state first, connect second */
513 bypass_menu_item->set_active (_io->panner()->bypassed());
514 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
516 items.push_back (MenuElem (_("Reset"), bind (mem_fun (*this, &PannerUI::pan_reset), which)));
517 items.push_back (SeparatorElem());
518 items.push_back (MenuElem (_("Reset all"), mem_fun (*this, &PannerUI::pan_reset_all)));
522 PannerUI::pan_mute (uint32_t which)
524 StreamPanner& sp = _io->panner()->streampanner(which);
525 sp.set_muted (!sp.muted());
529 PannerUI::pan_bypass_toggle ()
531 if (bypass_menu_item && (_io->panner()->bypassed() != bypass_menu_item->get_active())) {
532 _io->panner()->set_bypassed (!_io->panner()->bypassed());
537 PannerUI::pan_reset (uint32_t which)
539 _io->panner()->reset_streampanner (which);
543 PannerUI::pan_reset_all ()
545 _io->panner()->reset_to_default ();
549 PannerUI::effective_pan_display ()
551 if (_io->panner()->empty()) {
555 switch (_io->n_outputs().n_audio()) {
562 update_pan_bars (true);
566 //panner->move_puck (pan_value (v, right), 0.5);
572 PannerUI::pan_changed (void *src)
578 switch (_io->panner()->npanners()) {
580 panning_link_direction_button.set_sensitive (false);
581 panning_link_button.set_sensitive (false);
584 panning_link_direction_button.set_sensitive (false);
585 panning_link_button.set_sensitive (false);
588 panning_link_direction_button.set_sensitive (true);
589 panning_link_button.set_sensitive (true);
592 uint32_t nouts = _io->n_outputs().n_audio();
601 /* bring pan bar state up to date */
602 update_pan_bars (false);
606 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
612 PannerUI::pan_adjustment_changed (uint32_t which)
614 if (!in_pan_update && which < _io->panner()->npanners()) {
617 float val = pan_adjustments[which]->get_value ();
618 xpos = _io->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 _io->panner()->streampanner(which).set_position (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 (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
650 if (_io->n_outputs().n_audio() > 1 && which < _io->panner()->npanners()) {
652 float val = pan_adjustments[which]->get_value ();
654 _io->panner()->streampanner(which).get_position (xpos);
656 if (!Panner::equivalent (val, xpos)) {
657 in_pan_update = true;
658 pan_adjustments[which]->set_value (xpos);
659 in_pan_update = false;
665 PannerUI::update_pan_bars (bool only_if_aplay)
668 vector<Adjustment*>::iterator i;
670 in_pan_update = true;
672 /* this runs during automation playback, and moves the bar controllers
676 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
680 boost::shared_ptr<AutomationList> alist (_io->panner()->streampanner(n).pan_control()->alist());
682 if (!alist->automation_playback()) {
687 _io->panner()->streampanner(n).get_effective_position (xpos);
688 val = (*i)->get_value ();
690 if (!Panner::equivalent (val, xpos)) {
691 (*i)->set_value (xpos);
695 in_pan_update = false;
699 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
701 float val = adj->get_value();
704 snprintf (buf, len, X_("L"));
705 } else if (val == 1.0f) {
706 snprintf (buf, len, X_("R"));
707 } else if (Panner::equivalent (val, 0.5f)) {
708 snprintf (buf, len, X_("C"));
710 /* don't print anything */
716 PannerUI::update_pan_sensitive ()
718 bool sensitive = !(_io->panner()->automation_state() & Play);
720 switch (_io->n_outputs().n_audio()) {
725 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
726 (*i)->set_sensitive (sensitive);
731 panner->set_sensitive (sensitive);
734 big_window->set_sensitive (sensitive);
741 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
743 using namespace Menu_Helpers;
745 if (ev->type == GDK_BUTTON_RELEASE) {
749 switch (ev->button) {
751 if (pan_astate_menu == 0) {
752 build_astate_menu ();
754 pan_astate_menu->popup (1, ev->time);
764 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
766 if (ev->type == GDK_BUTTON_RELEASE) {
770 switch (ev->button) {
772 if (pan_astyle_menu == 0) {
773 build_astyle_menu ();
775 pan_astyle_menu->popup (1, ev->time);
784 PannerUI::pan_automation_style_changed ()
786 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
790 pan_automation_style_button.set_label (astyle_string(_io->panner()->automation_style()));
793 pan_automation_style_button.set_label (short_astyle_string(_io->panner()->automation_style()));
799 PannerUI::pan_automation_state_changed ()
801 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
807 pan_automation_state_button.set_label (astate_string(_io->panner()->automation_state()));
810 pan_automation_state_button.set_label (short_astate_string(_io->panner()->automation_state()));
814 /* when creating a new session, we get to create busses (and
815 sometimes tracks) with no outputs by the time they get
819 if (_io->panner()->empty()) {
823 x = (_io->panner()->streampanner(0).pan_control()->alist()->automation_state() != Off);
825 if (pan_automation_state_button.get_active() != x) {
826 ignore_toggle = true;
827 pan_automation_state_button.set_active (x);
828 ignore_toggle = false;
831 update_pan_sensitive ();
833 /* start watching automation so that things move */
835 pan_watching.disconnect();
838 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
843 PannerUI::astate_string (AutoState state)
845 return _astate_string (state, false);
849 PannerUI::short_astate_string (AutoState state)
851 return _astate_string (state, true);
855 PannerUI::_astate_string (AutoState state, bool shrt)
861 sstr = (shrt ? "M" : _("M"));
864 sstr = (shrt ? "P" : _("P"));
867 sstr = (shrt ? "T" : _("T"));
870 sstr = (shrt ? "W" : _("W"));
878 PannerUI::astyle_string (AutoStyle style)
880 return _astyle_string (style, false);
884 PannerUI::short_astyle_string (AutoStyle style)
886 return _astyle_string (style, true);
890 PannerUI::_astyle_string (AutoStyle style, bool shrt)
895 /* XXX it might different in different languages */
897 return (shrt ? _("Abs") : _("Abs"));