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;
50 const int PannerUI::pan_bar_height = 30;
52 PannerUI::PannerUI (Session& s)
56 hAdjustment(0.0, 0.0, 0.0),
57 vAdjustment(0.0, 0.0, 0.0),
58 panning_viewport(hAdjustment, vAdjustment),
59 panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
60 panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
61 panning_link_button (_("link")),
62 pan_automation_style_button (""),
63 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()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
75 ARDOUR_UI::instance()->tooltips().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 pan_bar_packer.set_size_request (-1, 61);
81 panning_viewport.set_size_request (-1, 61);
82 panning_viewport.set_name (X_("BaseFrame"));
84 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
85 _("panning link control"));
86 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
87 _("panning link direction"));
89 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
90 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
92 pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
93 pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
95 panning_link_button.set_name (X_("PanningLinkButton"));
96 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
98 panning_link_box.pack_start (panning_link_button, true, true);
99 panning_link_box.pack_start (panning_link_direction_button, true, true);
100 panning_link_box.pack_start (pan_automation_state_button, true, true);
102 /* the pixmap will be reset at some point, but the key thing is that
103 we need a pixmap in the button just to get started.
105 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
107 panning_link_direction_button.signal_clicked().connect
108 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
110 panning_link_button.signal_button_press_event().connect
111 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
112 panning_link_button.signal_button_release_event().connect
113 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
115 panning_up.set_border_width (3);
116 panning_down.set_border_width (3);
117 panning_up.add (panning_up_arrow);
118 panning_down.add (panning_down_arrow);
119 panning_up.set_name (X_("PanScrollerBase"));
120 panning_down.set_name (X_("PanScrollerBase"));
121 panning_up_arrow.set_name (X_("PanScrollerArrow"));
122 panning_down_arrow.set_name (X_("PanScrollerArrow"));
124 pan_vbox.set_spacing (2);
125 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
126 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
128 pack_start (pan_vbox, true, true);
137 PannerUI::set_panner (boost::shared_ptr<Panner> p)
139 connections.clear ();
141 delete pan_astyle_menu;
144 delete pan_astate_menu;
156 connections.push_back (_panner->Changed.connect (mem_fun(*this, &PannerUI::panner_changed)));
157 connections.push_back (_panner->LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage)));
158 connections.push_back (_panner->StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state)));
163 update_pan_sensitive ();
164 update_pan_linkage ();
165 pan_automation_state_changed ();
167 #if WHERE_DOES_THIS_LIVE
168 pan_bar_packer.show();
169 panning_viewport.show();
171 panning_up_arrow.show();
173 panning_down_arrow.show();
175 panning_link_button.show();
176 panning_link_direction_button.show();
177 panning_link_box.show();
178 pan_automation_style_button.show();
179 pan_automation_state_button.show();
185 PannerUI::build_astate_menu ()
187 using namespace Menu_Helpers;
189 if (pan_astate_menu == 0) {
190 pan_astate_menu = new Menu;
191 pan_astate_menu->set_name ("ArdourContextMenu");
193 pan_astate_menu->items().clear ();
196 pan_astate_menu->items().push_back (MenuElem (_("Manual"), bind (
197 mem_fun (_panner.get(), &Panner::set_automation_state),
199 pan_astate_menu->items().push_back (MenuElem (_("Play"), bind (
200 mem_fun (_panner.get(), &Panner::set_automation_state),
202 pan_astate_menu->items().push_back (MenuElem (_("Write"), bind (
203 mem_fun (_panner.get(), &Panner::set_automation_state),
204 (AutoState) Write)));
205 pan_astate_menu->items().push_back (MenuElem (_("Touch"), bind (
206 mem_fun (_panner.get(), &Panner::set_automation_state),
207 (AutoState) Touch)));
212 PannerUI::build_astyle_menu ()
214 using namespace Menu_Helpers;
216 if (pan_astyle_menu == 0) {
217 pan_astyle_menu = new Menu;
218 pan_astyle_menu->set_name ("ArdourContextMenu");
220 pan_astyle_menu->items().clear();
223 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
224 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
227 boost::shared_ptr<PBD::Controllable>
228 PannerUI::get_controllable()
230 return pan_bars[0]->get_controllable();
234 PannerUI::panning_link_button_press (GdkEventButton*)
240 PannerUI::panning_link_button_release (GdkEventButton*)
242 if (!ignore_toggle) {
243 _panner->set_linked (!_panner->linked());
249 PannerUI::panning_link_direction_clicked()
251 switch (_panner->link_direction()) {
252 case Panner::SameDirection:
253 _panner->set_link_direction (Panner::OppositeDirection);
256 _panner->set_link_direction (Panner::SameDirection);
262 PannerUI::update_pan_linkage ()
264 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
266 bool x = _panner->linked();
267 bool bx = panning_link_button.get_active();
271 ignore_toggle = true;
272 panning_link_button.set_active (x);
273 ignore_toggle = false;
276 panning_link_direction_button.set_sensitive (x);
278 switch (_panner->link_direction()) {
279 case Panner::SameDirection:
280 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
283 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
289 PannerUI::set_width (Width w)
293 panning_link_button.set_label (_("link"));
296 panning_link_button.set_label (_("L"));
304 PannerUI::~PannerUI ()
306 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
310 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
317 delete pan_astyle_menu;
318 delete pan_astate_menu;
323 PannerUI::panner_changed ()
325 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
331 PannerUI::update_pan_state ()
333 /* currently nothing to do */
334 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
338 PannerUI::setup_pan ()
344 uint32_t const nouts = _panner->nouts();
345 uint32_t const npans = _panner->npanners();
347 if (int32_t (nouts) == _current_nouts && int32_t (npans) == _current_npans) {
351 _current_nouts = nouts;
352 _current_npans = npans;
354 if (nouts == 0 || nouts == 1) {
356 while (!pan_adjustments.empty()) {
357 delete pan_bars.back();
358 pan_bars.pop_back ();
359 delete pan_adjustments.back();
360 pan_adjustments.pop_back ();
363 /* stick something into the panning viewport so that it redraws */
365 EventBox* eb = manage (new EventBox());
366 panning_viewport.remove ();
367 panning_viewport.add (*eb);
368 panning_viewport.show_all ();
370 } else if (nouts == 2) {
372 vector<Adjustment*>::size_type asz;
374 while (!pan_adjustments.empty()) {
375 delete pan_bars.back();
376 pan_bars.pop_back ();
377 delete pan_adjustments.back();
378 pan_adjustments.pop_back ();
381 while ((asz = pan_adjustments.size()) < npans) {
386 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
387 which serves as a default, otherwise use current value */
389 rx = _panner->pan_control( asz)->get_value();
393 } else if (asz == 0) {
395 } else if (asz == 1) {
401 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
402 bc = new PannerBar (*pan_adjustments[asz],
403 boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
405 /* now set adjustment with current value of panner, then connect the signals */
406 pan_adjustments.back()->set_value(rx);
407 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
409 _panner->pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
412 bc->set_name ("PanSlider");
413 bc->set_shadow_type (Gtk::SHADOW_NONE);
415 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
418 bc->StartGesture.connect (mem_fun (*ac, &AutomationControl::start_touch));
419 bc->StopGesture.connect (mem_fun (*ac, &AutomationControl::stop_touch));
423 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
424 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
426 bc->event_widget().signal_button_release_event().connect
427 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
429 bc->set_size_request (-1, pan_bar_height);
431 pan_bars.push_back (bc);
432 pan_bar_packer.pack_start (*bc, false, false);
435 /* now that we actually have the pan bars,
436 set their sensitivity based on current
440 update_pan_sensitive ();
442 panning_viewport.remove ();
443 panning_viewport.add (pan_bar_packer);
444 panning_viewport.show_all ();
449 panner = new Panner2d (_panner, 61);
450 panner->set_name ("MixerPanZone");
453 panner->signal_button_press_event().connect
454 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
457 update_pan_sensitive ();
458 panner->reset (npans);
460 big_window->reset (npans);
462 panner->set_size_request (-1, 61);
464 /* and finally, add it to the panner frame */
466 panning_viewport.remove ();
467 panning_viewport.add (*panner);
468 panning_viewport.show_all ();
473 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
475 switch (ev->button) {
477 if (panner && ev->type == GDK_2BUTTON_PRESS) {
479 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
488 pan_menu = manage (new Menu);
489 pan_menu->set_name ("ArdourContextMenu");
491 build_pan_menu (which);
492 pan_menu->popup (1, ev->time);
499 return false; // what's wrong with gcc?
503 PannerUI::build_pan_menu (uint32_t which)
505 using namespace Menu_Helpers;
506 MenuList& items (pan_menu->items());
510 items.push_back (CheckMenuElem (_("Mute")));
512 /* set state first, connect second */
514 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
515 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
516 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
518 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
519 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
521 /* set state first, connect second */
523 bypass_menu_item->set_active (_panner->bypassed());
524 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
526 items.push_back (MenuElem (_("Reset"), bind (mem_fun (*this, &PannerUI::pan_reset), which)));
527 items.push_back (SeparatorElem());
528 items.push_back (MenuElem (_("Reset all"), mem_fun (*this, &PannerUI::pan_reset_all)));
532 PannerUI::pan_mute (uint32_t which)
534 StreamPanner& sp = _panner->streampanner(which);
535 sp.set_muted (!sp.muted());
539 PannerUI::pan_bypass_toggle ()
541 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
542 _panner->set_bypassed (!_panner->bypassed());
547 PannerUI::pan_reset (uint32_t which)
549 _panner->reset_streampanner (which);
553 PannerUI::pan_reset_all ()
555 _panner->reset_to_default ();
559 PannerUI::effective_pan_display ()
561 if (_panner->empty()) {
565 switch (_panner->nouts()) {
572 update_pan_bars (true);
576 //panner->move_puck (pan_value (v, right), 0.5);
582 PannerUI::pan_changed (void *src)
588 switch (_panner->npanners()) {
590 panning_link_direction_button.set_sensitive (false);
591 panning_link_button.set_sensitive (false);
594 panning_link_direction_button.set_sensitive (false);
595 panning_link_button.set_sensitive (false);
598 panning_link_direction_button.set_sensitive (true);
599 panning_link_button.set_sensitive (true);
602 uint32_t nouts = _panner->nouts();
611 /* bring pan bar state up to date */
612 update_pan_bars (false);
616 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
622 PannerUI::pan_adjustment_changed (uint32_t which)
624 if (!in_pan_update && which < _panner->npanners()) {
627 float val = pan_adjustments[which]->get_value ();
628 xpos = _panner->pan_control( which )->get_value();
630 /* add a kinda-sorta detent for the middle */
632 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
633 /* this is going to be reentrant, so just
637 in_pan_update = true;
638 pan_adjustments[which]->set_value (0.5);
639 in_pan_update = false;
643 if (!Panner::equivalent (val, xpos)) {
645 _panner->streampanner(which).set_position (val);
647 the panner objects have no access to the session,
648 so do this here. ick.
650 _session.set_dirty();
656 PannerUI::pan_value_changed (uint32_t which)
658 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
660 if (_panner->npanners() > 1 && 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 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(mem_fun(*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(mem_fun(*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 (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 ();