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>
42 using namespace ARDOUR;
44 using namespace Gtkmm2ext;
48 const int PannerUI::pan_bar_height = 30;
50 PannerUI::PannerUI (Session& s)
52 hAdjustment(0.0, 0.0, 0.0),
53 vAdjustment(0.0, 0.0, 0.0),
54 panning_viewport(hAdjustment, vAdjustment),
55 panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
56 panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
57 panning_link_button (_("link")),
58 pan_automation_style_button (""),
59 pan_automation_state_button ("")
61 ignore_toggle = false;
65 in_pan_update = false;
67 pan_automation_style_button.set_name ("MixerAutomationModeButton");
68 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
70 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
71 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
73 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
74 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
76 pan_bar_packer.set_size_request (-1, 61);
77 panning_viewport.set_size_request (-1, 61);
78 panning_viewport.set_name (X_("BaseFrame"));
80 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
81 _("panning link control"));
82 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
83 _("panning link direction"));
85 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
86 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
88 pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
89 pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
91 panning_link_button.set_name (X_("PanningLinkButton"));
92 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
94 panning_link_box.pack_start (panning_link_button, true, true);
95 panning_link_box.pack_start (panning_link_direction_button, true, true);
96 panning_link_box.pack_start (pan_automation_state_button, true, true);
98 /* the pixmap will be reset at some point, but the key thing is that
99 we need a pixmap in the button just to get started.
101 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
103 panning_link_direction_button.signal_clicked().connect
104 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
106 panning_link_button.signal_button_press_event().connect
107 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
108 panning_link_button.signal_button_release_event().connect
109 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
111 panning_up.set_border_width (3);
112 panning_down.set_border_width (3);
113 panning_up.add (panning_up_arrow);
114 panning_down.add (panning_down_arrow);
115 panning_up.set_name (X_("PanScrollerBase"));
116 panning_down.set_name (X_("PanScrollerBase"));
117 panning_up_arrow.set_name (X_("PanScrollerArrow"));
118 panning_down_arrow.set_name (X_("PanScrollerArrow"));
120 pan_vbox.set_spacing (2);
121 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
122 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
124 pack_start (pan_vbox, true, true);
133 PannerUI::set_io (boost::shared_ptr<IO> io)
135 connections.clear ();
137 if (pan_astyle_menu) {
138 delete pan_astyle_menu;
142 if (pan_astate_menu) {
143 delete pan_astate_menu;
149 connections.push_back (_io->panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed)));
150 connections.push_back (_io->panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage)));
151 connections.push_back (_io->panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state)));
161 update_pan_sensitive ();
162 update_pan_linkage ();
163 pan_automation_state_changed ();
165 #if WHERE_DOES_THIS_LIVE
166 pan_bar_packer.show();
167 panning_viewport.show();
169 panning_up_arrow.show();
171 panning_down_arrow.show();
173 panning_link_button.show();
174 panning_link_direction_button.show();
175 panning_link_box.show();
176 pan_automation_style_button.show();
177 pan_automation_state_button.show();
183 PannerUI::build_astate_menu ()
185 using namespace Menu_Helpers;
187 if (pan_astate_menu == 0) {
188 pan_astate_menu = new Menu;
189 pan_astate_menu->set_name ("ArdourContextMenu");
191 pan_astate_menu->items().clear ();
194 pan_astate_menu->items().push_back (MenuElem (_("Manual"),
195 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Off)));
196 pan_astate_menu->items().push_back (MenuElem (_("Play"),
197 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Play)));
198 pan_astate_menu->items().push_back (MenuElem (_("Write"),
199 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Write)));
200 pan_astate_menu->items().push_back (MenuElem (_("Touch"),
201 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Touch)));
206 PannerUI::build_astyle_menu ()
208 using namespace Menu_Helpers;
210 if (pan_astyle_menu == 0) {
211 pan_astyle_menu = new Menu;
212 pan_astyle_menu->set_name ("ArdourContextMenu");
214 pan_astyle_menu->items().clear();
217 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
218 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
221 boost::shared_ptr<PBD::Controllable>
222 PannerUI::get_controllable()
224 return pan_bars[0]->get_controllable();
228 PannerUI::panning_link_button_press (GdkEventButton* ev)
234 PannerUI::panning_link_button_release (GdkEventButton* ev)
236 if (!ignore_toggle) {
237 _io->panner().set_linked (!_io->panner().linked());
243 PannerUI::panning_link_direction_clicked()
245 switch (_io->panner().link_direction()) {
246 case Panner::SameDirection:
247 _io->panner().set_link_direction (Panner::OppositeDirection);
250 _io->panner().set_link_direction (Panner::SameDirection);
256 PannerUI::update_pan_linkage ()
258 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
260 bool x = _io->panner().linked();
261 bool bx = panning_link_button.get_active();
265 ignore_toggle = true;
266 panning_link_button.set_active (x);
267 ignore_toggle = false;
270 panning_link_direction_button.set_sensitive (x);
272 switch (_io->panner().link_direction()) {
273 case Panner::SameDirection:
274 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
277 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
283 PannerUI::set_width (Width w)
287 panning_link_button.set_label (_("link"));
290 panning_link_button.set_label (_("L"));
298 PannerUI::~PannerUI ()
300 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
304 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
320 if (pan_astyle_menu) {
321 delete pan_astyle_menu;
324 if (pan_astate_menu) {
325 delete pan_astate_menu;
331 PannerUI::panner_changed ()
333 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
339 PannerUI::update_pan_state ()
341 /* currently nothing to do */
342 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
346 PannerUI::setup_pan ()
348 uint32_t nouts = _io->n_outputs ().n_audio();
350 if (nouts == 0 || nouts == 1) {
352 while (!pan_adjustments.empty()) {
353 delete pan_bars.back();
354 pan_bars.pop_back ();
355 delete pan_adjustments.back();
356 pan_adjustments.pop_back ();
359 /* stick something into the panning viewport so that it redraws */
361 EventBox* eb = manage (new EventBox());
362 panning_viewport.remove ();
363 panning_viewport.add (*eb);
364 panning_viewport.show_all ();
366 } else if (nouts == 2) {
368 vector<Adjustment*>::size_type asz;
369 uint32_t npans = _io->panner().npanners();
371 while (!pan_adjustments.empty()) {
372 delete pan_bars.back();
373 pan_bars.pop_back ();
374 delete pan_adjustments.back();
375 pan_adjustments.pop_back ();
378 while ((asz = pan_adjustments.size()) < npans) {
383 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
384 which serves as a default, otherwise use current value */
386 rx = _io->panner().pan_control( asz)->get_value();
390 } else if (asz == 0) {
392 } else if (asz == 1) {
398 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
399 bc = new PannerBar (*pan_adjustments[asz],
400 boost::static_pointer_cast<PBD::Controllable>( _io->panner().pan_control( asz )) );
402 /* now set adjustment with current value of panner, then connect the signals */
403 pan_adjustments.back()->set_value(rx);
404 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
406 _io->panner().pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
409 bc->set_name ("PanSlider");
410 bc->set_shadow_type (Gtk::SHADOW_NONE);
412 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
413 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
416 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
417 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
419 bc->event_widget().signal_button_release_event().connect
420 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
422 bc->set_size_request (-1, pan_bar_height);
424 pan_bars.push_back (bc);
425 pan_bar_packer.pack_start (*bc, false, false);
428 /* now that we actually have the pan bars,
429 set their sensitivity based on current
433 update_pan_sensitive ();
435 panning_viewport.remove ();
436 panning_viewport.add (pan_bar_packer);
437 panning_viewport.show_all ();
442 panner = new Panner2d (_io->panner(), 61);
443 panner->set_name ("MixerPanZone");
447 panner->signal_button_press_event().connect
448 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
451 update_pan_sensitive ();
452 panner->reset (_io->n_inputs().n_audio());
454 big_window->reset (_io->n_inputs().n_audio());
456 panner->set_size_request (-1, 61);
458 /* and finally, add it to the panner frame */
460 panning_viewport.remove ();
461 panning_viewport.add (*panner);
462 panning_viewport.show_all ();
467 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
469 switch (ev->button) {
471 if (panner && ev->type == GDK_2BUTTON_PRESS) {
473 big_window = new Panner2dWindow (panner->get_panner(), 400, _io->n_inputs().n_audio());
482 pan_menu = manage (new Menu);
483 pan_menu->set_name ("ArdourContextMenu");
485 build_pan_menu (which);
486 pan_menu->popup (1, ev->time);
493 return false; // what's wrong with gcc?
497 PannerUI::build_pan_menu (uint32_t which)
499 using namespace Menu_Helpers;
500 MenuList& items (pan_menu->items());
504 items.push_back (CheckMenuElem (_("Mute")));
506 /* set state first, connect second */
508 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner().streampanner(which).muted());
509 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
510 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
512 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
513 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
515 /* set state first, connect second */
517 bypass_menu_item->set_active (_io->panner().bypassed());
518 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
520 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
521 items.push_back (SeparatorElem());
522 items.push_back (MenuElem (_("Reset all")));
526 PannerUI::pan_mute (uint32_t which)
528 StreamPanner& sp = _io->panner().streampanner(which);
529 sp.set_muted (!sp.muted());
533 PannerUI::pan_bypass_toggle ()
535 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
536 _io->panner().set_bypassed (!_io->panner().bypassed());
541 PannerUI::pan_reset ()
546 PannerUI::effective_pan_display ()
548 if (_io->panner().empty()) {
552 switch (_io->n_outputs().n_audio()) {
559 update_pan_bars (true);
563 //panner->move_puck (pan_value (v, right), 0.5);
569 PannerUI::pan_changed (void *src)
575 switch (_io->panner().npanners()) {
577 panning_link_direction_button.set_sensitive (false);
578 panning_link_button.set_sensitive (false);
581 panning_link_direction_button.set_sensitive (false);
582 panning_link_button.set_sensitive (false);
585 panning_link_direction_button.set_sensitive (true);
586 panning_link_button.set_sensitive (true);
589 uint32_t nouts = _io->n_outputs().n_audio();
598 /* bring pan bar state up to date */
599 update_pan_bars (false);
603 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
609 PannerUI::pan_adjustment_changed (uint32_t which)
611 if (!in_pan_update && which < _io->panner().npanners()) {
614 float val = pan_adjustments[which]->get_value ();
615 xpos = _io->panner().pan_control( which )->get_value();
617 /* add a kinda-sorta detent for the middle */
619 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
620 /* this is going to be reentrant, so just
624 in_pan_update = true;
625 pan_adjustments[which]->set_value (0.5);
626 in_pan_update = false;
630 if (!Panner::equivalent (val, xpos)) {
632 _io->panner().streampanner(which).set_position (val);
634 the panner objects have no access to the session,
635 so do this here. ick.
637 _session.set_dirty();
643 PannerUI::pan_value_changed (uint32_t which)
645 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
647 if (_io->n_outputs().n_audio() > 1 && which < _io->panner().npanners()) {
649 float val = pan_adjustments[which]->get_value ();
651 _io->panner().streampanner(which).get_position (xpos);
653 if (!Panner::equivalent (val, xpos)) {
654 in_pan_update = true;
655 pan_adjustments[which]->set_value (xpos);
656 in_pan_update = false;
662 PannerUI::update_pan_bars (bool only_if_aplay)
665 vector<Adjustment*>::iterator i;
667 in_pan_update = true;
669 /* this runs during automation playback, and moves the bar controllers
673 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
677 boost::shared_ptr<AutomationList> alist (_io->panner().streampanner(n).pan_control()->alist());
679 if (!alist->automation_playback()) {
684 _io->panner().streampanner(n).get_effective_position (xpos);
685 val = (*i)->get_value ();
687 if (!Panner::equivalent (val, xpos)) {
688 (*i)->set_value (xpos);
692 in_pan_update = false;
696 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
698 float val = adj->get_value();
701 snprintf (buf, len, X_("L"));
702 } else if (val == 1.0f) {
703 snprintf (buf, len, X_("R"));
704 } else if (Panner::equivalent (val, 0.5f)) {
705 snprintf (buf, len, X_("C"));
707 /* don't print anything */
713 PannerUI::update_pan_sensitive ()
715 bool sensitive = !(_io->panner().automation_state() & Play);
717 switch (_io->n_outputs().n_audio()) {
722 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
723 (*i)->set_sensitive (sensitive);
728 panner->set_sensitive (sensitive);
731 big_window->set_sensitive (sensitive);
738 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
740 using namespace Menu_Helpers;
742 if (ev->type == GDK_BUTTON_RELEASE) {
746 switch (ev->button) {
748 if (pan_astate_menu == 0) {
749 build_astate_menu ();
751 pan_astate_menu->popup (1, ev->time);
761 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
763 if (ev->type == GDK_BUTTON_RELEASE) {
767 switch (ev->button) {
769 if (pan_astyle_menu == 0) {
770 build_astyle_menu ();
772 pan_astyle_menu->popup (1, ev->time);
781 PannerUI::pan_automation_style_changed ()
783 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
787 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
790 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
796 PannerUI::pan_automation_state_changed ()
798 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
804 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
807 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
811 /* when creating a new session, we get to create busses (and
812 sometimes tracks) with no outputs by the time they get
816 if (_io->panner().empty()) {
820 x = (_io->panner().streampanner(0).pan_control()->alist()->automation_state() != Off);
822 if (pan_automation_state_button.get_active() != x) {
823 ignore_toggle = true;
824 pan_automation_state_button.set_active (x);
825 ignore_toggle = false;
828 update_pan_sensitive ();
830 /* start watching automation so that things move */
832 pan_watching.disconnect();
835 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
840 PannerUI::astate_string (AutoState state)
842 return _astate_string (state, false);
846 PannerUI::short_astate_string (AutoState state)
848 return _astate_string (state, true);
852 PannerUI::_astate_string (AutoState state, bool shrt)
858 sstr = (shrt ? "M" : _("M"));
861 sstr = (shrt ? "P" : _("P"));
864 sstr = (shrt ? "T" : _("T"));
867 sstr = (shrt ? "W" : _("W"));
875 PannerUI::astyle_string (AutoStyle style)
877 return _astyle_string (style, false);
881 PannerUI::short_astyle_string (AutoStyle style)
883 return _astyle_string (style, true);
887 PannerUI::_astyle_string (AutoStyle style, bool shrt)
892 /* XXX it might different in different languages */
894 return (shrt ? _("Abs") : _("Abs"));