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 (-1, 61);
77 panning_viewport.set_name (X_("BaseFrame"));
79 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
80 _("panning link control"));
81 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
82 _("panning link direction"));
84 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
85 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
87 using namespace Menu_Helpers;
88 pan_astate_menu.items().push_back (MenuElem (_("Manual"),
89 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Off)));
90 pan_astate_menu.items().push_back (MenuElem (_("Play"),
91 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Play)));
92 pan_astate_menu.items().push_back (MenuElem (_("Write"),
93 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Write)));
94 pan_astate_menu.items().push_back (MenuElem (_("Touch"),
95 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Touch)));
97 pan_astyle_menu.items().push_back (MenuElem (_("Trim")));
98 pan_astyle_menu.items().push_back (MenuElem (_("Abs")));
100 pan_astate_menu.set_name ("ArdourContextMenu");
101 pan_astyle_menu.set_name ("ArdourContextMenu");
103 pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
104 pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
106 panning_link_button.set_name (X_("PanningLinkButton"));
107 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
109 panning_link_box.pack_start (panning_link_button, true, true);
110 panning_link_box.pack_start (panning_link_direction_button, true, true);
111 panning_link_box.pack_start (pan_automation_state_button, true, true);
113 /* the pixmap will be reset at some point, but the key thing is that
114 we need a pixmap in the button just to get started.
116 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
118 panning_link_direction_button.signal_clicked().connect
119 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
121 panning_link_button.signal_button_press_event().connect
122 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
123 panning_link_button.signal_button_release_event().connect
124 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
126 panning_up.set_border_width (3);
127 panning_down.set_border_width (3);
128 panning_up.add (panning_up_arrow);
129 panning_down.add (panning_down_arrow);
130 panning_up.set_name (X_("PanScrollerBase"));
131 panning_down.set_name (X_("PanScrollerBase"));
132 panning_up_arrow.set_name (X_("PanScrollerArrow"));
133 panning_down_arrow.set_name (X_("PanScrollerArrow"));
135 pan_vbox.set_spacing (2);
136 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
137 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
139 pack_start (pan_vbox, true, true);
145 _io->panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
146 _io->panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
147 _io->panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
150 update_pan_sensitive ();
151 update_pan_linkage ();
152 pan_automation_state_changed ();
154 pan_bar_packer.show();
155 panning_viewport.show();
157 panning_up_arrow.show();
159 panning_down_arrow.show();
161 panning_link_button.show();
162 panning_link_direction_button.show();
163 panning_link_box.show();
164 pan_automation_style_button.show();
165 pan_automation_state_button.show();
170 PannerUI::panning_link_button_press (GdkEventButton* ev)
172 cerr << "link press\n";
177 PannerUI::panning_link_button_release (GdkEventButton* ev)
179 cerr << "link release\n";
180 if (!ignore_toggle) {
181 _io->panner().set_linked (!_io->panner().linked());
187 PannerUI::panning_link_direction_clicked()
189 switch (_io->panner().link_direction()) {
190 case Panner::SameDirection:
191 _io->panner().set_link_direction (Panner::OppositeDirection);
194 _io->panner().set_link_direction (Panner::SameDirection);
200 PannerUI::update_pan_linkage ()
202 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
204 bool x = _io->panner().linked();
205 bool bx = panning_link_button.get_active();
209 ignore_toggle = true;
210 panning_link_button.set_active (x);
211 ignore_toggle = false;
214 panning_link_direction_button.set_sensitive (x);
216 switch (_io->panner().link_direction()) {
217 case Panner::SameDirection:
218 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
221 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
227 PannerUI::set_width (Width w)
231 panning_link_button.set_label (_("link"));
234 panning_link_button.set_label (_("L"));
242 PannerUI::~PannerUI ()
244 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
248 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
264 PannerUI::panner_changed ()
266 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
271 PannerUI::update_pan_state ()
273 /* currently nothing to do */
274 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
278 PannerUI::setup_pan ()
280 uint32_t nouts = _io->n_outputs ().n_audio();
282 if (nouts == 0 || nouts == 1) {
284 while (!pan_adjustments.empty()) {
285 delete pan_bars.back();
286 pan_bars.pop_back ();
287 delete pan_adjustments.back();
288 pan_adjustments.pop_back ();
291 /* stick something into the panning viewport so that it redraws */
293 EventBox* eb = manage (new EventBox());
294 panning_viewport.remove ();
295 panning_viewport.add (*eb);
296 panning_viewport.show_all ();
298 } else if (nouts == 2) {
300 vector<Adjustment*>::size_type asz;
301 uint32_t npans = _io->panner().size();
303 while (!pan_adjustments.empty()) {
304 delete pan_bars.back();
305 pan_bars.pop_back ();
306 delete pan_adjustments.back();
307 pan_adjustments.pop_back ();
310 while ((asz = pan_adjustments.size()) < npans) {
315 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
316 which serves as a default, otherwise use current value */
318 _io->panner()[asz]->get_position (rx);
322 } else if (asz == 0) {
324 } else if (asz == 1) {
330 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
331 bc = new PannerBar (*pan_adjustments[asz], _io->panner()[asz]->pan_control());
333 /* now set adjustment with current value of panner, then connect the signals */
334 pan_adjustments.back()->set_value(rx);
335 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
337 _io->panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
340 bc->set_name ("PanSlider");
341 bc->set_shadow_type (Gtk::SHADOW_NONE);
343 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
344 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
347 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
348 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
350 bc->event_widget().signal_button_release_event().connect
351 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
353 bc->set_size_request (-1, pan_bar_height);
355 pan_bars.push_back (bc);
356 pan_bar_packer.pack_start (*bc, false, false);
359 /* now that we actually have the pan bars,
360 set their sensitivity based on current
364 update_pan_sensitive ();
366 panning_viewport.remove ();
367 panning_viewport.add (pan_bar_packer);
368 panning_viewport.show_all ();
373 panner = new Panner2d (_io->panner(), 61);
374 panner->set_name ("MixerPanZone");
378 update_pan_sensitive ();
379 panner->reset (_io->n_inputs().n_audio());
380 panner->set_size_request (-1, 61);
382 /* and finally, add it to the panner frame */
384 panning_viewport.remove ();
385 panning_viewport.add (*panner);
386 panning_viewport.show_all ();
391 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
393 switch (ev->button) {
396 pan_menu = manage (new Menu);
397 pan_menu->set_name ("ArdourContextMenu");
399 build_pan_menu (which);
400 pan_menu->popup (1, ev->time);
407 return false; // what's wrong with gcc?
411 PannerUI::build_pan_menu (uint32_t which)
413 using namespace Menu_Helpers;
414 MenuList& items (pan_menu->items());
418 items.push_back (CheckMenuElem (_("Mute")));
420 /* set state first, connect second */
422 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()[which]->muted());
423 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
424 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
426 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
427 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
429 /* set state first, connect second */
431 bypass_menu_item->set_active (_io->panner().bypassed());
432 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
434 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
435 items.push_back (SeparatorElem());
436 items.push_back (MenuElem (_("Reset all")));
440 PannerUI::pan_mute (uint32_t which)
442 StreamPanner* sp = _io->panner()[which];
443 sp->set_muted (!sp->muted());
447 PannerUI::pan_bypass_toggle ()
449 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
450 _io->panner().set_bypassed (!_io->panner().bypassed());
455 PannerUI::pan_reset ()
460 PannerUI::effective_pan_display ()
462 if (_io->panner().empty()) {
466 switch (_io->n_outputs().n_audio()) {
473 update_pan_bars (true);
477 //panner->move_puck (pan_value (v, right), 0.5);
483 PannerUI::pan_changed (void *src)
489 switch (_io->panner().size()) {
491 panning_link_direction_button.set_sensitive (false);
492 panning_link_button.set_sensitive (false);
495 panning_link_direction_button.set_sensitive (false);
496 panning_link_button.set_sensitive (false);
499 panning_link_direction_button.set_sensitive (true);
500 panning_link_button.set_sensitive (true);
503 uint32_t nouts = _io->n_outputs().n_audio();
512 update_pan_bars (false);
516 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
522 PannerUI::pan_adjustment_changed (uint32_t which)
524 if (!in_pan_update && which < _io->panner().size()) {
527 float val = pan_adjustments[which]->get_value ();
528 _io->panner()[which]->get_position (xpos);
530 /* add a kinda-sorta detent for the middle */
532 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
533 /* this is going to be reentrant, so just
537 in_pan_update = true;
538 pan_adjustments[which]->set_value (0.5);
539 in_pan_update = false;
543 if (!Panner::equivalent (val, xpos)) {
545 _io->panner()[which]->set_position (val);
547 the panner objects have no access to the session,
548 so do this here. ick.
550 _session.set_dirty();
556 PannerUI::pan_value_changed (uint32_t which)
558 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
560 if (_io->n_outputs().n_audio() > 1 && which < _io->panner().size()) {
562 float val = pan_adjustments[which]->get_value ();
564 _io->panner()[which]->get_position (xpos);
566 if (!Panner::equivalent (val, xpos)) {
567 in_pan_update = true;
568 pan_adjustments[which]->set_value (xpos);
569 in_pan_update = false;
575 PannerUI::update_pan_bars (bool only_if_aplay)
578 vector<Adjustment*>::iterator i;
580 in_pan_update = true;
582 /* this runs during automation playback, and moves the bar controllers
586 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
590 boost::shared_ptr<AutomationList> alist (_io->panner()[n]->pan_control()->list());
592 if (!alist->automation_playback()) {
597 _io->panner()[n]->get_effective_position (xpos);
598 val = (*i)->get_value ();
600 if (!Panner::equivalent (val, xpos)) {
601 (*i)->set_value (xpos);
605 in_pan_update = false;
609 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
611 float val = adj->get_value();
614 snprintf (buf, len, X_("L"));
615 } else if (val == 1.0f) {
616 snprintf (buf, len, X_("R"));
617 } else if (Panner::equivalent (val, 0.5f)) {
618 snprintf (buf, len, X_("C"));
620 /* don't print anything */
626 PannerUI::update_pan_sensitive ()
628 bool sensitive = !(_io->panner().automation_state() & Play);
630 switch (_io->n_outputs().n_audio()) {
635 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
636 (*i)->set_sensitive (sensitive);
641 panner->set_sensitive (sensitive);
648 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
650 using namespace Menu_Helpers;
652 if (ev->type == GDK_BUTTON_RELEASE) {
656 switch (ev->button) {
658 pan_astate_menu.popup (1, ev->time);
668 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
670 if (ev->type == GDK_BUTTON_RELEASE) {
674 switch (ev->button) {
676 pan_astyle_menu.popup (1, ev->time);
685 PannerUI::pan_automation_style_changed ()
687 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
691 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
694 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
700 PannerUI::pan_automation_state_changed ()
702 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
708 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
711 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
715 /* when creating a new session, we get to create busses (and
716 sometimes tracks) with no outputs by the time they get
720 if (_io->panner().empty()) {
724 x = (_io->panner().front()->pan_control()->list()->automation_state() != Off);
726 if (pan_automation_state_button.get_active() != x) {
727 ignore_toggle = true;
728 pan_automation_state_button.set_active (x);
729 ignore_toggle = false;
732 update_pan_sensitive ();
734 /* start watching automation so that things move */
736 pan_watching.disconnect();
739 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
744 PannerUI::astate_string (AutoState state)
746 return _astate_string (state, false);
750 PannerUI::short_astate_string (AutoState state)
752 return _astate_string (state, true);
756 PannerUI::_astate_string (AutoState state, bool shrt)
762 sstr = (shrt ? "M" : _("M"));
765 sstr = (shrt ? "P" : _("P"));
768 sstr = (shrt ? "T" : _("T"));
771 sstr = (shrt ? "W" : _("W"));
779 PannerUI::astyle_string (AutoStyle style)
781 return _astyle_string (style, false);
785 PannerUI::short_astyle_string (AutoStyle style)
787 return _astyle_string (style, true);
791 PannerUI::_astyle_string (AutoStyle style, bool shrt)
796 /* XXX it might different in different languages */
798 return (shrt ? _("Abs") : _("Abs"));