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);
132 PannerUI::set_io (boost::shared_ptr<IO> io)
134 connections.clear ();
136 if (pan_astyle_menu) {
137 delete pan_astyle_menu;
141 if (pan_astate_menu) {
142 delete pan_astate_menu;
148 connections.push_back (_io->panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed)));
149 connections.push_back (_io->panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage)));
150 connections.push_back (_io->panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state)));
159 update_pan_sensitive ();
160 update_pan_linkage ();
161 pan_automation_state_changed ();
163 #if WHERE_DOES_THIS_LIVE
164 pan_bar_packer.show();
165 panning_viewport.show();
167 panning_up_arrow.show();
169 panning_down_arrow.show();
171 panning_link_button.show();
172 panning_link_direction_button.show();
173 panning_link_box.show();
174 pan_automation_style_button.show();
175 pan_automation_state_button.show();
181 PannerUI::build_astate_menu ()
183 using namespace Menu_Helpers;
185 if (pan_astate_menu == 0) {
186 pan_astate_menu = new Menu;
187 pan_astate_menu->set_name ("ArdourContextMenu");
189 pan_astate_menu->items().clear ();
192 pan_astate_menu->items().push_back (MenuElem (_("Manual"),
193 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Off)));
194 pan_astate_menu->items().push_back (MenuElem (_("Play"),
195 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Play)));
196 pan_astate_menu->items().push_back (MenuElem (_("Write"),
197 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Write)));
198 pan_astate_menu->items().push_back (MenuElem (_("Touch"),
199 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Touch)));
204 PannerUI::build_astyle_menu ()
206 using namespace Menu_Helpers;
208 if (pan_astyle_menu == 0) {
209 pan_astyle_menu = new Menu;
210 pan_astyle_menu->set_name ("ArdourContextMenu");
212 pan_astyle_menu->items().clear();
215 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
216 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
219 boost::shared_ptr<PBD::Controllable>
220 PannerUI::get_controllable()
222 return pan_bars[0]->get_controllable();
226 PannerUI::panning_link_button_press (GdkEventButton* ev)
228 cerr << "link press\n";
233 PannerUI::panning_link_button_release (GdkEventButton* ev)
235 cerr << "link release\n";
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) {
316 if (pan_astyle_menu) {
317 delete pan_astyle_menu;
320 if (pan_astate_menu) {
321 delete pan_astate_menu;
327 PannerUI::panner_changed ()
329 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
334 PannerUI::update_pan_state ()
336 /* currently nothing to do */
337 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
341 PannerUI::setup_pan ()
343 uint32_t nouts = _io->n_outputs ().n_audio();
345 if (nouts == 0 || nouts == 1) {
347 while (!pan_adjustments.empty()) {
348 delete pan_bars.back();
349 pan_bars.pop_back ();
350 delete pan_adjustments.back();
351 pan_adjustments.pop_back ();
354 /* stick something into the panning viewport so that it redraws */
356 EventBox* eb = manage (new EventBox());
357 panning_viewport.remove ();
358 panning_viewport.add (*eb);
359 panning_viewport.show_all ();
361 } else if (nouts == 2) {
363 vector<Adjustment*>::size_type asz;
364 uint32_t npans = _io->panner().npanners();
366 while (!pan_adjustments.empty()) {
367 delete pan_bars.back();
368 pan_bars.pop_back ();
369 delete pan_adjustments.back();
370 pan_adjustments.pop_back ();
373 while ((asz = pan_adjustments.size()) < npans) {
378 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
379 which serves as a default, otherwise use current value */
381 rx = _io->panner().pan_control( asz)->get_value();
385 } else if (asz == 0) {
387 } else if (asz == 1) {
393 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
394 bc = new PannerBar (*pan_adjustments[asz],
395 boost::static_pointer_cast<PBD::Controllable>( _io->panner().pan_control( asz )) );
397 /* now set adjustment with current value of panner, then connect the signals */
398 pan_adjustments.back()->set_value(rx);
399 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
401 _io->panner().pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
404 bc->set_name ("PanSlider");
405 bc->set_shadow_type (Gtk::SHADOW_NONE);
407 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
408 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
411 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
412 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
414 bc->event_widget().signal_button_release_event().connect
415 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
417 bc->set_size_request (-1, pan_bar_height);
419 pan_bars.push_back (bc);
420 pan_bar_packer.pack_start (*bc, false, false);
423 /* now that we actually have the pan bars,
424 set their sensitivity based on current
428 update_pan_sensitive ();
430 panning_viewport.remove ();
431 panning_viewport.add (pan_bar_packer);
432 panning_viewport.show_all ();
437 panner = new Panner2d (_io->panner(), 61);
438 panner->set_name ("MixerPanZone");
442 update_pan_sensitive ();
443 panner->reset (_io->n_inputs().n_audio());
444 panner->set_size_request (-1, 61);
446 /* and finally, add it to the panner frame */
448 panning_viewport.remove ();
449 panning_viewport.add (*panner);
450 panning_viewport.show_all ();
455 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
457 switch (ev->button) {
460 pan_menu = manage (new Menu);
461 pan_menu->set_name ("ArdourContextMenu");
463 build_pan_menu (which);
464 pan_menu->popup (1, ev->time);
471 return false; // what's wrong with gcc?
475 PannerUI::build_pan_menu (uint32_t which)
477 using namespace Menu_Helpers;
478 MenuList& items (pan_menu->items());
482 items.push_back (CheckMenuElem (_("Mute")));
484 /* set state first, connect second */
486 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner().streampanner(which).muted());
487 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
488 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
490 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
491 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
493 /* set state first, connect second */
495 bypass_menu_item->set_active (_io->panner().bypassed());
496 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
498 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
499 items.push_back (SeparatorElem());
500 items.push_back (MenuElem (_("Reset all")));
504 PannerUI::pan_mute (uint32_t which)
506 StreamPanner& sp = _io->panner().streampanner(which);
507 sp.set_muted (!sp.muted());
511 PannerUI::pan_bypass_toggle ()
513 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
514 _io->panner().set_bypassed (!_io->panner().bypassed());
519 PannerUI::pan_reset ()
524 PannerUI::effective_pan_display ()
526 if (_io->panner().empty()) {
530 switch (_io->n_outputs().n_audio()) {
537 update_pan_bars (true);
541 //panner->move_puck (pan_value (v, right), 0.5);
547 PannerUI::pan_changed (void *src)
553 switch (_io->panner().npanners()) {
555 panning_link_direction_button.set_sensitive (false);
556 panning_link_button.set_sensitive (false);
559 panning_link_direction_button.set_sensitive (false);
560 panning_link_button.set_sensitive (false);
563 panning_link_direction_button.set_sensitive (true);
564 panning_link_button.set_sensitive (true);
567 uint32_t nouts = _io->n_outputs().n_audio();
576 update_pan_bars (false);
580 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
586 PannerUI::pan_adjustment_changed (uint32_t which)
588 if (!in_pan_update && which < _io->panner().npanners()) {
591 float val = pan_adjustments[which]->get_value ();
592 xpos = _io->panner().pan_control( which )->get_value();
594 /* add a kinda-sorta detent for the middle */
596 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
597 /* this is going to be reentrant, so just
601 in_pan_update = true;
602 pan_adjustments[which]->set_value (0.5);
603 in_pan_update = false;
607 if (!Panner::equivalent (val, xpos)) {
609 _io->panner().streampanner(which).set_position (val);
611 the panner objects have no access to the session,
612 so do this here. ick.
614 _session.set_dirty();
620 PannerUI::pan_value_changed (uint32_t which)
622 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
624 if (_io->n_outputs().n_audio() > 1 && which < _io->panner().npanners()) {
626 float val = pan_adjustments[which]->get_value ();
628 _io->panner().streampanner(which).get_position (xpos);
630 if (!Panner::equivalent (val, xpos)) {
631 in_pan_update = true;
632 pan_adjustments[which]->set_value (xpos);
633 in_pan_update = false;
639 PannerUI::update_pan_bars (bool only_if_aplay)
642 vector<Adjustment*>::iterator i;
644 in_pan_update = true;
646 /* this runs during automation playback, and moves the bar controllers
650 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
654 boost::shared_ptr<AutomationList> alist (_io->panner().streampanner(n).pan_control()->alist());
656 if (!alist->automation_playback()) {
661 _io->panner().streampanner(n).get_effective_position (xpos);
662 val = (*i)->get_value ();
664 if (!Panner::equivalent (val, xpos)) {
665 (*i)->set_value (xpos);
669 in_pan_update = false;
673 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
675 float val = adj->get_value();
678 snprintf (buf, len, X_("L"));
679 } else if (val == 1.0f) {
680 snprintf (buf, len, X_("R"));
681 } else if (Panner::equivalent (val, 0.5f)) {
682 snprintf (buf, len, X_("C"));
684 /* don't print anything */
690 PannerUI::update_pan_sensitive ()
692 bool sensitive = !(_io->panner().automation_state() & Play);
694 switch (_io->n_outputs().n_audio()) {
699 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
700 (*i)->set_sensitive (sensitive);
705 panner->set_sensitive (sensitive);
712 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
714 using namespace Menu_Helpers;
716 if (ev->type == GDK_BUTTON_RELEASE) {
720 switch (ev->button) {
722 if (pan_astate_menu == 0) {
723 build_astate_menu ();
725 pan_astate_menu->popup (1, ev->time);
735 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
737 if (ev->type == GDK_BUTTON_RELEASE) {
741 switch (ev->button) {
743 if (pan_astyle_menu == 0) {
744 build_astyle_menu ();
746 pan_astyle_menu->popup (1, ev->time);
755 PannerUI::pan_automation_style_changed ()
757 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
761 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
764 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
770 PannerUI::pan_automation_state_changed ()
772 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
778 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
781 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
785 /* when creating a new session, we get to create busses (and
786 sometimes tracks) with no outputs by the time they get
790 if (_io->panner().empty()) {
794 x = (_io->panner().streampanner(0).pan_control()->alist()->automation_state() != Off);
796 if (pan_automation_state_button.get_active() != x) {
797 ignore_toggle = true;
798 pan_automation_state_button.set_active (x);
799 ignore_toggle = false;
802 update_pan_sensitive ();
804 /* start watching automation so that things move */
806 pan_watching.disconnect();
809 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
814 PannerUI::astate_string (AutoState state)
816 return _astate_string (state, false);
820 PannerUI::short_astate_string (AutoState state)
822 return _astate_string (state, true);
826 PannerUI::_astate_string (AutoState state, bool shrt)
832 sstr = (shrt ? "M" : _("M"));
835 sstr = (shrt ? "P" : _("P"));
838 sstr = (shrt ? "T" : _("T"));
841 sstr = (shrt ? "W" : _("W"));
849 PannerUI::astyle_string (AutoStyle style)
851 return _astyle_string (style, false);
855 PannerUI::short_astyle_string (AutoStyle style)
857 return _astyle_string (style, true);
861 PannerUI::_astyle_string (AutoStyle style, bool shrt)
866 /* XXX it might different in different languages */
868 return (shrt ? _("Abs") : _("Abs"));