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)
136 cerr << "PannerUI::set_io IO has no panners" << endl;
140 connections.clear ();
142 delete pan_astyle_menu;
145 delete pan_astate_menu;
150 connections.push_back (_io->panner()->Changed.connect (
151 mem_fun(*this, &PannerUI::panner_changed)));
152 connections.push_back (_io->panner()->LinkStateChanged.connect (
153 mem_fun(*this, &PannerUI::update_pan_linkage)));
154 connections.push_back (_io->panner()->StateChanged.connect (
155 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 (_io->panner().get(), &Panner::set_automation_state),
199 pan_astate_menu->items().push_back (MenuElem (_("Play"), bind (
200 mem_fun (_io->panner().get(), &Panner::set_automation_state),
202 pan_astate_menu->items().push_back (MenuElem (_("Write"), bind (
203 mem_fun (_io->panner().get(), &Panner::set_automation_state),
204 (AutoState) Write)));
205 pan_astate_menu->items().push_back (MenuElem (_("Touch"), bind (
206 mem_fun (_io->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* ev)
240 PannerUI::panning_link_button_release (GdkEventButton* ev)
242 if (!ignore_toggle) {
243 _io->panner()->set_linked (!_io->panner()->linked());
249 PannerUI::panning_link_direction_clicked()
251 switch (_io->panner()->link_direction()) {
252 case Panner::SameDirection:
253 _io->panner()->set_link_direction (Panner::OppositeDirection);
256 _io->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 = _io->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 (_io->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 ()
340 if (!_io->panner()) {
344 uint32_t nouts = _io->n_outputs ().n_audio();
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 = _io->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 = _io->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.05, 0.1));
395 bc = new PannerBar (*pan_adjustments[asz],
396 boost::static_pointer_cast<PBD::Controllable>( _io->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 _io->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 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
409 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
412 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
413 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
415 bc->event_widget().signal_button_release_event().connect
416 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
418 bc->set_size_request (-1, pan_bar_height);
420 pan_bars.push_back (bc);
421 pan_bar_packer.pack_start (*bc, false, false);
424 /* now that we actually have the pan bars,
425 set their sensitivity based on current
429 update_pan_sensitive ();
431 panning_viewport.remove ();
432 panning_viewport.add (pan_bar_packer);
433 panning_viewport.show_all ();
438 panner = new Panner2d (_io->panner(), 61);
439 panner->set_name ("MixerPanZone");
442 panner->signal_button_press_event().connect
443 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
446 update_pan_sensitive ();
447 panner->reset (_io->n_inputs().n_audio());
449 big_window->reset (_io->n_inputs().n_audio());
451 panner->set_size_request (-1, 61);
453 /* and finally, add it to the panner frame */
455 panning_viewport.remove ();
456 panning_viewport.add (*panner);
457 panning_viewport.show_all ();
462 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
464 switch (ev->button) {
466 if (panner && ev->type == GDK_2BUTTON_PRESS) {
468 big_window = new Panner2dWindow (panner->get_panner(), 400, _io->n_inputs().n_audio());
477 pan_menu = manage (new Menu);
478 pan_menu->set_name ("ArdourContextMenu");
480 build_pan_menu (which);
481 pan_menu->popup (1, ev->time);
488 return false; // what's wrong with gcc?
492 PannerUI::build_pan_menu (uint32_t which)
494 using namespace Menu_Helpers;
495 MenuList& items (pan_menu->items());
499 items.push_back (CheckMenuElem (_("Mute")));
501 /* set state first, connect second */
503 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()->streampanner(which).muted());
504 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
505 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
507 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
508 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
510 /* set state first, connect second */
512 bypass_menu_item->set_active (_io->panner()->bypassed());
513 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
515 items.push_back (MenuElem (_("Reset"), bind (mem_fun (*this, &PannerUI::pan_reset), which)));
516 items.push_back (SeparatorElem());
517 items.push_back (MenuElem (_("Reset all"), mem_fun (*this, &PannerUI::pan_reset_all)));
521 PannerUI::pan_mute (uint32_t which)
523 StreamPanner& sp = _io->panner()->streampanner(which);
524 sp.set_muted (!sp.muted());
528 PannerUI::pan_bypass_toggle ()
530 if (bypass_menu_item && (_io->panner()->bypassed() != bypass_menu_item->get_active())) {
531 _io->panner()->set_bypassed (!_io->panner()->bypassed());
536 PannerUI::pan_reset (uint32_t which)
538 _io->panner()->reset_streampanner (which);
542 PannerUI::pan_reset_all ()
544 _io->panner()->reset_to_default ();
548 PannerUI::effective_pan_display ()
550 if (_io->panner()->empty()) {
554 switch (_io->n_outputs().n_audio()) {
561 update_pan_bars (true);
565 //panner->move_puck (pan_value (v, right), 0.5);
571 PannerUI::pan_changed (void *src)
577 switch (_io->panner()->npanners()) {
579 panning_link_direction_button.set_sensitive (false);
580 panning_link_button.set_sensitive (false);
583 panning_link_direction_button.set_sensitive (false);
584 panning_link_button.set_sensitive (false);
587 panning_link_direction_button.set_sensitive (true);
588 panning_link_button.set_sensitive (true);
591 uint32_t nouts = _io->n_outputs().n_audio();
600 /* bring pan bar state up to date */
601 update_pan_bars (false);
605 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
611 PannerUI::pan_adjustment_changed (uint32_t which)
613 if (!in_pan_update && which < _io->panner()->npanners()) {
616 float val = pan_adjustments[which]->get_value ();
617 xpos = _io->panner()->pan_control( which )->get_value();
619 /* add a kinda-sorta detent for the middle */
621 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
622 /* this is going to be reentrant, so just
626 in_pan_update = true;
627 pan_adjustments[which]->set_value (0.5);
628 in_pan_update = false;
632 if (!Panner::equivalent (val, xpos)) {
634 _io->panner()->streampanner(which).set_position (val);
636 the panner objects have no access to the session,
637 so do this here. ick.
639 _session.set_dirty();
645 PannerUI::pan_value_changed (uint32_t which)
647 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
649 if (_io->n_outputs().n_audio() > 1 && which < _io->panner()->npanners()) {
651 float val = pan_adjustments[which]->get_value ();
653 _io->panner()->streampanner(which).get_position (xpos);
655 if (!Panner::equivalent (val, xpos)) {
656 in_pan_update = true;
657 pan_adjustments[which]->set_value (xpos);
658 in_pan_update = false;
664 PannerUI::update_pan_bars (bool only_if_aplay)
667 vector<Adjustment*>::iterator i;
669 in_pan_update = true;
671 /* this runs during automation playback, and moves the bar controllers
675 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
679 boost::shared_ptr<AutomationList> alist (_io->panner()->streampanner(n).pan_control()->alist());
681 if (!alist->automation_playback()) {
686 _io->panner()->streampanner(n).get_effective_position (xpos);
687 val = (*i)->get_value ();
689 if (!Panner::equivalent (val, xpos)) {
690 (*i)->set_value (xpos);
694 in_pan_update = false;
698 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
700 float val = adj->get_value();
703 snprintf (buf, len, X_("L"));
704 } else if (val == 1.0f) {
705 snprintf (buf, len, X_("R"));
706 } else if (Panner::equivalent (val, 0.5f)) {
707 snprintf (buf, len, X_("C"));
709 /* don't print anything */
715 PannerUI::update_pan_sensitive ()
717 bool sensitive = !(_io->panner()->automation_state() & Play);
719 switch (_io->n_outputs().n_audio()) {
724 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
725 (*i)->set_sensitive (sensitive);
730 panner->set_sensitive (sensitive);
733 big_window->set_sensitive (sensitive);
740 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
742 using namespace Menu_Helpers;
744 if (ev->type == GDK_BUTTON_RELEASE) {
748 switch (ev->button) {
750 if (pan_astate_menu == 0) {
751 build_astate_menu ();
753 pan_astate_menu->popup (1, ev->time);
763 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
765 if (ev->type == GDK_BUTTON_RELEASE) {
769 switch (ev->button) {
771 if (pan_astyle_menu == 0) {
772 build_astyle_menu ();
774 pan_astyle_menu->popup (1, ev->time);
783 PannerUI::pan_automation_style_changed ()
785 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
789 pan_automation_style_button.set_label (astyle_string(_io->panner()->automation_style()));
792 pan_automation_style_button.set_label (short_astyle_string(_io->panner()->automation_style()));
798 PannerUI::pan_automation_state_changed ()
800 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
806 pan_automation_state_button.set_label (astate_string(_io->panner()->automation_state()));
809 pan_automation_state_button.set_label (short_astate_string(_io->panner()->automation_state()));
813 /* when creating a new session, we get to create busses (and
814 sometimes tracks) with no outputs by the time they get
818 if (_io->panner()->empty()) {
822 x = (_io->panner()->streampanner(0).pan_control()->alist()->automation_state() != Off);
824 if (pan_automation_state_button.get_active() != x) {
825 ignore_toggle = true;
826 pan_automation_state_button.set_active (x);
827 ignore_toggle = false;
830 update_pan_sensitive ();
832 /* start watching automation so that things move */
834 pan_watching.disconnect();
837 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
842 PannerUI::astate_string (AutoState state)
844 return _astate_string (state, false);
848 PannerUI::short_astate_string (AutoState state)
850 return _astate_string (state, true);
854 PannerUI::_astate_string (AutoState state, bool shrt)
860 sstr = (shrt ? "M" : _("M"));
863 sstr = (shrt ? "P" : _("P"));
866 sstr = (shrt ? "T" : _("T"));
869 sstr = (shrt ? "W" : _("W"));
877 PannerUI::astyle_string (AutoStyle style)
879 return _astyle_string (style, false);
883 PannerUI::short_astyle_string (AutoStyle style)
885 return _astyle_string (style, true);
889 PannerUI::_astyle_string (AutoStyle style, bool shrt)
894 /* XXX it might different in different languages */
896 return (shrt ? _("Abs") : _("Abs"));