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 (boost::shared_ptr<IO> io, Session& s)
53 hAdjustment(0.0, 0.0, 0.0),
54 vAdjustment(0.0, 0.0, 0.0),
55 panning_viewport(hAdjustment, vAdjustment),
56 panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
57 panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
58 panning_link_button (_("link")),
59 pan_automation_style_button (""),
60 pan_automation_state_button ("")
62 ignore_toggle = false;
64 in_pan_update = false;
66 pan_automation_style_button.set_name ("MixerAutomationModeButton");
67 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
69 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
70 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
72 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
73 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
75 pan_bar_packer.set_size_request (-1, 61);
76 panning_viewport.set_size_request (64, 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 using namespace Menu_Helpers;
89 pan_astate_menu.items().push_back (MenuElem (_("Off"),
90 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Off)));
91 pan_astate_menu.items().push_back (MenuElem (_("Play"),
92 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Play)));
93 pan_astate_menu.items().push_back (MenuElem (_("Write"),
94 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Write)));
95 pan_astate_menu.items().push_back (MenuElem (_("Touch"),
96 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Touch)));
98 pan_astyle_menu.items().push_back (MenuElem (_("Trim")));
99 pan_astyle_menu.items().push_back (MenuElem (_("Abs")));
101 pan_astate_menu.set_name ("ArdourContextMenu");
102 pan_astyle_menu.set_name ("ArdourContextMenu");
104 pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
105 pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
107 panning_link_button.set_name (X_("PanningLinkButton"));
108 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
110 panning_link_box.pack_start (panning_link_button, true, true);
111 panning_link_box.pack_start (panning_link_direction_button, true, true);
112 panning_link_box.pack_start (pan_automation_state_button, true, true);
114 /* the pixmap will be reset at some point, but the key thing is that
115 we need a pixmap in the button just to get started.
117 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
119 panning_link_direction_button.signal_clicked().connect
120 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
122 panning_link_button.signal_button_press_event().connect
123 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
124 panning_link_button.signal_button_release_event().connect
125 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
127 panning_up.set_border_width (3);
128 panning_down.set_border_width (3);
129 panning_up.add (panning_up_arrow);
130 panning_down.add (panning_down_arrow);
131 panning_up.set_name (X_("PanScrollerBase"));
132 panning_down.set_name (X_("PanScrollerBase"));
133 panning_up_arrow.set_name (X_("PanScrollerArrow"));
134 panning_down_arrow.set_name (X_("PanScrollerArrow"));
136 pan_vbox.set_spacing (2);
137 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
138 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
140 pack_start (pan_vbox, true, false);
146 _io->panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
147 _io->panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
148 _io->panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
151 update_pan_sensitive ();
152 update_pan_linkage ();
153 pan_automation_state_changed ();
157 PannerUI::panning_link_button_press (GdkEventButton* ev)
159 cerr << "link press\n";
164 PannerUI::panning_link_button_release (GdkEventButton* ev)
166 cerr << "link release\n";
167 if (!ignore_toggle) {
168 _io->panner().set_linked (!_io->panner().linked());
174 PannerUI::panning_link_direction_clicked()
176 switch (_io->panner().link_direction()) {
177 case Panner::SameDirection:
178 _io->panner().set_link_direction (Panner::OppositeDirection);
181 _io->panner().set_link_direction (Panner::SameDirection);
187 PannerUI::update_pan_linkage ()
189 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
191 bool x = _io->panner().linked();
192 bool bx = panning_link_button.get_active();
196 ignore_toggle = true;
197 panning_link_button.set_active (x);
198 ignore_toggle = false;
201 panning_link_direction_button.set_sensitive (x);
203 switch (_io->panner().link_direction()) {
204 case Panner::SameDirection:
205 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
208 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
214 PannerUI::set_width (Width w)
218 panning_viewport.set_size_request (64, 61);
220 panner->set_size_request (63, 61);
222 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
223 (*i)->set_size_request (63, pan_bar_height);
225 panning_link_button.set_label (_("link"));
228 panning_viewport.set_size_request (34, 61);
230 panner->set_size_request (33, 61);
232 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
233 (*i)->set_size_request (33, pan_bar_height);
235 panning_link_button.set_label (_("L"));
243 PannerUI::~PannerUI ()
245 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
249 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
265 PannerUI::panner_changed ()
267 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
272 PannerUI::update_pan_state ()
274 /* currently nothing to do */
275 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
279 PannerUI::setup_pan ()
281 uint32_t nouts = _io->n_outputs ();
283 if (nouts == 0 || nouts == 1) {
285 while (!pan_adjustments.empty()) {
286 delete pan_bars.back();
287 pan_bars.pop_back ();
288 delete pan_adjustments.back();
289 pan_adjustments.pop_back ();
292 } else if (nouts == 2) {
294 vector<Adjustment*>::size_type asz;
295 uint32_t npans = _io->panner().size();
297 while (!pan_adjustments.empty()) {
298 delete pan_bars.back();
299 pan_bars.pop_back ();
300 delete pan_adjustments.back();
301 pan_adjustments.pop_back ();
304 while ((asz = pan_adjustments.size()) < npans) {
309 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
310 which serves as a default, otherwise use current value */
312 _io->panner()[asz]->get_position (rx);
316 } else if (asz == 0) {
318 } else if (asz == 1) {
324 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
325 bc = new PannerBar (*pan_adjustments[asz], _io->panner()[asz]->control());
327 /* now set adjustment with current value of panner, then connect the signals */
328 pan_adjustments.back()->set_value(rx);
329 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
331 _io->panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
334 bc->set_name ("PanSlider");
335 bc->set_shadow_type (Gtk::SHADOW_NONE);
337 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
338 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
341 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
342 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
344 bc->event_widget().signal_button_release_event().connect
345 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
347 pan_bars.push_back (bc);
350 bc->set_size_request (63, pan_bar_height);
353 bc->set_size_request (33, pan_bar_height);
357 pan_bar_packer.pack_start (*bc, false, false);
360 /* now that we actually have the pan bars,
361 set their sensitivity based on current
365 update_pan_sensitive ();
367 panning_viewport.remove ();
368 panning_viewport.add (pan_bar_packer);
369 panning_viewport.show_all ();
385 panner = new Panner2d (_io->panner(), w, 61);
386 panner->set_name ("MixerPanZone");
390 update_pan_sensitive ();
391 panner->reset (_io->n_inputs());
392 panner->set_size_request (w, 61);
394 /* and finally, add it to the panner frame */
396 panning_viewport.remove ();
397 panning_viewport.add (*panner);
398 panning_viewport.show_all ();
403 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
405 switch (ev->button) {
408 pan_menu = manage (new Menu);
409 pan_menu->set_name ("ArdourContextMenu");
411 build_pan_menu (which);
412 pan_menu->popup (1, ev->time);
419 return false; // what's wrong with gcc?
423 PannerUI::build_pan_menu (uint32_t which)
425 using namespace Menu_Helpers;
426 MenuList& items (pan_menu->items());
430 items.push_back (CheckMenuElem (_("Mute")));
432 /* set state first, connect second */
434 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()[which]->muted());
435 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
436 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
438 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
439 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
441 /* set state first, connect second */
443 bypass_menu_item->set_active (_io->panner().bypassed());
444 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
446 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
447 items.push_back (SeparatorElem());
448 items.push_back (MenuElem (_("Reset all")));
452 PannerUI::pan_mute (uint32_t which)
454 StreamPanner* sp = _io->panner()[which];
455 sp->set_muted (!sp->muted());
459 PannerUI::pan_bypass_toggle ()
461 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
462 _io->panner().set_bypassed (!_io->panner().bypassed());
467 PannerUI::pan_reset ()
472 PannerUI::effective_pan_display ()
474 if (_io->panner().empty()) {
478 switch (_io->n_outputs()) {
485 update_pan_bars (true);
489 //panner->move_puck (pan_value (v, right), 0.5);
495 PannerUI::pan_changed (void *src)
501 switch (_io->panner().size()) {
503 panning_link_direction_button.set_sensitive (false);
504 panning_link_button.set_sensitive (false);
507 panning_link_direction_button.set_sensitive (false);
508 panning_link_button.set_sensitive (false);
511 panning_link_direction_button.set_sensitive (true);
512 panning_link_button.set_sensitive (true);
515 uint32_t nouts = _io->n_outputs();
524 update_pan_bars (false);
528 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
534 PannerUI::pan_adjustment_changed (uint32_t which)
536 if (!in_pan_update && which < _io->panner().size()) {
539 float val = pan_adjustments[which]->get_value ();
540 _io->panner()[which]->get_position (xpos);
542 /* add a kinda-sorta detent for the middle */
544 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
545 /* this is going to be reentrant, so just
549 in_pan_update = true;
550 pan_adjustments[which]->set_value (0.5);
551 in_pan_update = false;
555 if (!Panner::equivalent (val, xpos)) {
557 _io->panner()[which]->set_position (val);
559 the panner objects have no access to the session,
560 so do this here. ick.
562 _session.set_dirty();
568 PannerUI::pan_value_changed (uint32_t which)
570 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
572 if (_io->n_outputs() > 1 && which < _io->panner().size()) {
574 float val = pan_adjustments[which]->get_value ();
576 _io->panner()[which]->get_position (xpos);
578 if (!Panner::equivalent (val, xpos)) {
579 in_pan_update = true;
580 pan_adjustments[which]->set_value (xpos);
581 in_pan_update = false;
587 PannerUI::update_pan_bars (bool only_if_aplay)
590 vector<Adjustment*>::iterator i;
592 in_pan_update = true;
594 /* this runs during automation playback, and moves the bar controllers
598 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
602 AutomationList& alist (_io->panner()[n]->automation());
604 if (!alist.automation_playback()) {
609 _io->panner()[n]->get_effective_position (xpos);
610 val = (*i)->get_value ();
612 if (!Panner::equivalent (val, xpos)) {
613 (*i)->set_value (xpos);
617 in_pan_update = false;
621 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
623 float val = adj->get_value();
626 snprintf (buf, len, X_("L"));
627 } else if (val == 1.0f) {
628 snprintf (buf, len, X_("R"));
629 } else if (Panner::equivalent (val, 0.5f)) {
630 snprintf (buf, len, X_("C"));
632 /* don't print anything */
638 PannerUI::update_pan_sensitive ()
640 bool sensitive = !(_io->panner().automation_state() & Play);
642 switch (_io->n_outputs()) {
647 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
648 (*i)->set_sensitive (sensitive);
653 panner->set_sensitive (sensitive);
660 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
662 using namespace Menu_Helpers;
664 if (ev->type == GDK_BUTTON_RELEASE) {
668 switch (ev->button) {
670 pan_astate_menu.popup (1, ev->time);
680 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
682 if (ev->type == GDK_BUTTON_RELEASE) {
686 switch (ev->button) {
688 pan_astyle_menu.popup (1, ev->time);
697 PannerUI::pan_automation_style_changed ()
699 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
703 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
706 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
712 PannerUI::pan_automation_state_changed ()
714 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
720 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
723 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
727 /* when creating a new session, we get to create busses (and
728 sometimes tracks) with no outputs by the time they get
732 if (_io->panner().empty()) {
736 x = (_io->panner().front()->automation().automation_state() != Off);
738 if (pan_automation_state_button.get_active() != x) {
739 ignore_toggle = true;
740 pan_automation_state_button.set_active (x);
741 ignore_toggle = false;
744 update_pan_sensitive ();
746 /* start watching automation so that things move */
748 pan_watching.disconnect();
751 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
756 PannerUI::astate_string (AutoState state)
758 return _astate_string (state, false);
762 PannerUI::short_astate_string (AutoState state)
764 return _astate_string (state, true);
768 PannerUI::_astate_string (AutoState state, bool shrt)
774 sstr = (shrt ? "O" : _("O"));
777 sstr = (shrt ? "P" : _("P"));
780 sstr = (shrt ? "T" : _("T"));
783 sstr = (shrt ? "W" : _("W"));
791 PannerUI::astyle_string (AutoStyle style)
793 return _astyle_string (style, false);
797 PannerUI::short_astyle_string (AutoStyle style)
799 return _astyle_string (style, true);
803 PannerUI::_astyle_string (AutoStyle style, bool shrt)
808 /* XXX it might different in different languages */
810 return (shrt ? _("Abs") : _("Abs"));