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)
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 ("")
63 ignore_toggle = false;
67 in_pan_update = false;
69 pan_automation_style_button.set_name ("MixerAutomationModeButton");
70 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
72 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
73 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
75 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
76 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
78 pan_bar_packer.set_size_request (-1, 61);
79 panning_viewport.set_size_request (-1, 61);
80 panning_viewport.set_name (X_("BaseFrame"));
82 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
83 _("panning link control"));
84 ARDOUR_UI::instance()->tooltips().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 (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
91 pan_automation_state_button.signal_button_press_event().connect (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 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
108 panning_link_button.signal_button_press_event().connect
109 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
110 panning_link_button.signal_button_release_event().connect
111 (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.clear ();
139 delete pan_astyle_menu;
142 delete pan_astate_menu;
154 connections.push_back (_panner->Changed.connect (mem_fun(*this, &PannerUI::panner_changed)));
155 connections.push_back (_panner->LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage)));
156 connections.push_back (_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"), bind (
195 mem_fun (_panner.get(), &Panner::set_automation_state),
197 pan_astate_menu->items().push_back (MenuElem (_("Play"), bind (
198 mem_fun (_panner.get(), &Panner::set_automation_state),
200 pan_astate_menu->items().push_back (MenuElem (_("Write"), bind (
201 mem_fun (_panner.get(), &Panner::set_automation_state),
202 (AutoState) Write)));
203 pan_astate_menu->items().push_back (MenuElem (_("Touch"), bind (
204 mem_fun (_panner.get(), &Panner::set_automation_state),
205 (AutoState) Touch)));
210 PannerUI::build_astyle_menu ()
212 using namespace Menu_Helpers;
214 if (pan_astyle_menu == 0) {
215 pan_astyle_menu = new Menu;
216 pan_astyle_menu->set_name ("ArdourContextMenu");
218 pan_astyle_menu->items().clear();
221 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
222 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
225 boost::shared_ptr<PBD::Controllable>
226 PannerUI::get_controllable()
228 return pan_bars[0]->get_controllable();
232 PannerUI::panning_link_button_press (GdkEventButton* ev)
238 PannerUI::panning_link_button_release (GdkEventButton* ev)
240 if (!ignore_toggle) {
241 _panner->set_linked (!_panner->linked());
247 PannerUI::panning_link_direction_clicked()
249 switch (_panner->link_direction()) {
250 case Panner::SameDirection:
251 _panner->set_link_direction (Panner::OppositeDirection);
254 _panner->set_link_direction (Panner::SameDirection);
260 PannerUI::update_pan_linkage ()
262 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
264 bool x = _panner->linked();
265 bool bx = panning_link_button.get_active();
269 ignore_toggle = true;
270 panning_link_button.set_active (x);
271 ignore_toggle = false;
274 panning_link_direction_button.set_sensitive (x);
276 switch (_panner->link_direction()) {
277 case Panner::SameDirection:
278 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
281 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
287 PannerUI::set_width (Width w)
291 panning_link_button.set_label (_("link"));
294 panning_link_button.set_label (_("L"));
302 PannerUI::~PannerUI ()
304 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
308 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
315 delete pan_astyle_menu;
316 delete pan_astate_menu;
321 PannerUI::panner_changed ()
323 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
329 PannerUI::update_pan_state ()
331 /* currently nothing to do */
332 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
336 PannerUI::setup_pan ()
338 cerr << "Setup pan for " << _panner->name() << endl;
344 uint32_t nouts = _panner->nouts();
346 if (nouts == 0 || nouts == 1) {
348 while (!pan_adjustments.empty()) {
349 delete pan_bars.back();
350 pan_bars.pop_back ();
351 delete pan_adjustments.back();
352 pan_adjustments.pop_back ();
355 /* stick something into the panning viewport so that it redraws */
357 EventBox* eb = manage (new EventBox());
358 panning_viewport.remove ();
359 panning_viewport.add (*eb);
360 panning_viewport.show_all ();
362 } else if (nouts == 2) {
364 vector<Adjustment*>::size_type asz;
365 uint32_t npans = _panner->npanners();
367 while (!pan_adjustments.empty()) {
368 delete pan_bars.back();
369 pan_bars.pop_back ();
370 delete pan_adjustments.back();
371 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 (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
402 _panner->pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
405 bc->set_name ("PanSlider");
406 bc->set_shadow_type (Gtk::SHADOW_NONE);
408 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
411 bc->StartGesture.connect (mem_fun (*ac, &AutomationControl::start_touch));
412 bc->StopGesture.connect (mem_fun (*ac, &AutomationControl::stop_touch));
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 (_panner, 61);
443 panner->set_name ("MixerPanZone");
446 panner->signal_button_press_event().connect
447 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
450 update_pan_sensitive ();
451 panner->reset (nouts);
453 big_window->reset (_panner->npanners());
455 panner->set_size_request (-1, 61);
457 /* and finally, add it to the panner frame */
459 panning_viewport.remove ();
460 panning_viewport.add (*panner);
461 panning_viewport.show_all ();
466 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
468 switch (ev->button) {
470 if (panner && ev->type == GDK_2BUTTON_PRESS) {
472 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
481 pan_menu = manage (new Menu);
482 pan_menu->set_name ("ArdourContextMenu");
484 build_pan_menu (which);
485 pan_menu->popup (1, ev->time);
492 return false; // what's wrong with gcc?
496 PannerUI::build_pan_menu (uint32_t which)
498 using namespace Menu_Helpers;
499 MenuList& items (pan_menu->items());
503 items.push_back (CheckMenuElem (_("Mute")));
505 /* set state first, connect second */
507 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
508 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
509 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
511 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
512 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
514 /* set state first, connect second */
516 bypass_menu_item->set_active (_panner->bypassed());
517 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
519 items.push_back (MenuElem (_("Reset"), bind (mem_fun (*this, &PannerUI::pan_reset), which)));
520 items.push_back (SeparatorElem());
521 items.push_back (MenuElem (_("Reset all"), mem_fun (*this, &PannerUI::pan_reset_all)));
525 PannerUI::pan_mute (uint32_t which)
527 StreamPanner& sp = _panner->streampanner(which);
528 sp.set_muted (!sp.muted());
532 PannerUI::pan_bypass_toggle ()
534 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
535 _panner->set_bypassed (!_panner->bypassed());
540 PannerUI::pan_reset (uint32_t which)
542 _panner->reset_streampanner (which);
546 PannerUI::pan_reset_all ()
548 _panner->reset_to_default ();
552 PannerUI::effective_pan_display ()
554 if (_panner->empty()) {
558 switch (_panner->nouts()) {
565 update_pan_bars (true);
569 //panner->move_puck (pan_value (v, right), 0.5);
575 PannerUI::pan_changed (void *src)
581 switch (_panner->npanners()) {
583 panning_link_direction_button.set_sensitive (false);
584 panning_link_button.set_sensitive (false);
587 panning_link_direction_button.set_sensitive (false);
588 panning_link_button.set_sensitive (false);
591 panning_link_direction_button.set_sensitive (true);
592 panning_link_button.set_sensitive (true);
595 uint32_t nouts = _panner->nouts();
604 /* bring pan bar state up to date */
605 update_pan_bars (false);
609 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
615 PannerUI::pan_adjustment_changed (uint32_t which)
617 if (!in_pan_update && which < _panner->npanners()) {
620 float val = pan_adjustments[which]->get_value ();
621 xpos = _panner->pan_control( which )->get_value();
623 /* add a kinda-sorta detent for the middle */
625 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
626 /* this is going to be reentrant, so just
630 in_pan_update = true;
631 pan_adjustments[which]->set_value (0.5);
632 in_pan_update = false;
636 if (!Panner::equivalent (val, xpos)) {
638 _panner->streampanner(which).set_position (val);
640 the panner objects have no access to the session,
641 so do this here. ick.
643 _session.set_dirty();
649 PannerUI::pan_value_changed (uint32_t which)
651 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
653 if (_panner->npanners() > 1 && which < _panner->npanners()) {
655 float val = pan_adjustments[which]->get_value ();
657 _panner->streampanner(which).get_position (xpos);
659 if (!Panner::equivalent (val, xpos)) {
660 in_pan_update = true;
661 pan_adjustments[which]->set_value (xpos);
662 in_pan_update = false;
668 PannerUI::update_pan_bars (bool only_if_aplay)
671 vector<Adjustment*>::iterator i;
673 in_pan_update = true;
675 /* this runs during automation playback, and moves the bar controllers
679 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
683 boost::shared_ptr<AutomationList> alist (_panner->streampanner(n).pan_control()->alist());
685 if (!alist->automation_playback()) {
690 _panner->streampanner(n).get_effective_position (xpos);
691 val = (*i)->get_value ();
693 if (!Panner::equivalent (val, xpos)) {
694 (*i)->set_value (xpos);
698 in_pan_update = false;
702 PannerUI::update_pan_sensitive ()
704 bool sensitive = !(_panner->automation_state() & Play);
706 switch (_panner->nouts()) {
711 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
712 (*i)->set_sensitive (sensitive);
717 panner->set_sensitive (sensitive);
720 big_window->set_sensitive (sensitive);
727 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
729 using namespace Menu_Helpers;
731 if (ev->type == GDK_BUTTON_RELEASE) {
735 switch (ev->button) {
737 if (pan_astate_menu == 0) {
738 build_astate_menu ();
740 pan_astate_menu->popup (1, ev->time);
750 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
752 if (ev->type == GDK_BUTTON_RELEASE) {
756 switch (ev->button) {
758 if (pan_astyle_menu == 0) {
759 build_astyle_menu ();
761 pan_astyle_menu->popup (1, ev->time);
770 PannerUI::pan_automation_style_changed ()
772 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
776 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
779 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
785 PannerUI::pan_automation_state_changed ()
787 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
793 pan_automation_state_button.set_label (astate_string(_panner->automation_state()));
796 pan_automation_state_button.set_label (short_astate_string(_panner->automation_state()));
800 /* when creating a new session, we get to create busses (and
801 sometimes tracks) with no outputs by the time they get
805 if (_panner->empty()) {
809 x = (_panner->streampanner(0).pan_control()->alist()->automation_state() != Off);
811 if (pan_automation_state_button.get_active() != x) {
812 ignore_toggle = true;
813 pan_automation_state_button.set_active (x);
814 ignore_toggle = false;
817 update_pan_sensitive ();
819 /* start watching automation so that things move */
821 pan_watching.disconnect();
824 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
829 PannerUI::astate_string (AutoState state)
831 return _astate_string (state, false);
835 PannerUI::short_astate_string (AutoState state)
837 return _astate_string (state, true);
841 PannerUI::_astate_string (AutoState state, bool shrt)
847 sstr = (shrt ? "M" : _("M"));
850 sstr = (shrt ? "P" : _("P"));
853 sstr = (shrt ? "T" : _("T"));
856 sstr = (shrt ? "W" : _("W"));
864 PannerUI::astyle_string (AutoStyle style)
866 return _astyle_string (style, false);
870 PannerUI::short_astyle_string (AutoStyle style)
872 return _astyle_string (style, true);
876 PannerUI::_astyle_string (AutoStyle style, bool shrt)
881 /* XXX it might different in different languages */
883 return (shrt ? _("Abs") : _("Abs"));