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();
169 boost::shared_ptr<PBD::Controllable>
170 PannerUI::get_controllable()
172 return pan_bars[0]->get_controllable();
176 PannerUI::panning_link_button_press (GdkEventButton* ev)
178 cerr << "link press\n";
183 PannerUI::panning_link_button_release (GdkEventButton* ev)
185 cerr << "link release\n";
186 if (!ignore_toggle) {
187 _io->panner().set_linked (!_io->panner().linked());
193 PannerUI::panning_link_direction_clicked()
195 switch (_io->panner().link_direction()) {
196 case Panner::SameDirection:
197 _io->panner().set_link_direction (Panner::OppositeDirection);
200 _io->panner().set_link_direction (Panner::SameDirection);
206 PannerUI::update_pan_linkage ()
208 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
210 bool x = _io->panner().linked();
211 bool bx = panning_link_button.get_active();
215 ignore_toggle = true;
216 panning_link_button.set_active (x);
217 ignore_toggle = false;
220 panning_link_direction_button.set_sensitive (x);
222 switch (_io->panner().link_direction()) {
223 case Panner::SameDirection:
224 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
227 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
233 PannerUI::set_width (Width w)
237 panning_link_button.set_label (_("link"));
240 panning_link_button.set_label (_("L"));
248 PannerUI::~PannerUI ()
250 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
254 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
270 PannerUI::panner_changed ()
272 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
277 PannerUI::update_pan_state ()
279 /* currently nothing to do */
280 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
284 PannerUI::setup_pan ()
286 uint32_t nouts = _io->n_outputs ().n_audio();
288 if (nouts == 0 || nouts == 1) {
290 while (!pan_adjustments.empty()) {
291 delete pan_bars.back();
292 pan_bars.pop_back ();
293 delete pan_adjustments.back();
294 pan_adjustments.pop_back ();
297 /* stick something into the panning viewport so that it redraws */
299 EventBox* eb = manage (new EventBox());
300 panning_viewport.remove ();
301 panning_viewport.add (*eb);
302 panning_viewport.show_all ();
304 } else if (nouts == 2) {
306 vector<Adjustment*>::size_type asz;
307 uint32_t npans = _io->panner().npanners();
309 while (!pan_adjustments.empty()) {
310 delete pan_bars.back();
311 pan_bars.pop_back ();
312 delete pan_adjustments.back();
313 pan_adjustments.pop_back ();
316 while ((asz = pan_adjustments.size()) < npans) {
321 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
322 which serves as a default, otherwise use current value */
324 rx = _io->panner().pan_control( asz)->get_value();
328 } else if (asz == 0) {
330 } else if (asz == 1) {
336 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
337 bc = new PannerBar (*pan_adjustments[asz],
338 boost::static_pointer_cast<PBD::Controllable>( _io->panner().pan_control( asz )) );
340 /* now set adjustment with current value of panner, then connect the signals */
341 pan_adjustments.back()->set_value(rx);
342 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
344 _io->panner().pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
347 bc->set_name ("PanSlider");
348 bc->set_shadow_type (Gtk::SHADOW_NONE);
350 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
351 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
354 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
355 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
357 bc->event_widget().signal_button_release_event().connect
358 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
360 bc->set_size_request (-1, pan_bar_height);
362 pan_bars.push_back (bc);
363 pan_bar_packer.pack_start (*bc, false, false);
366 /* now that we actually have the pan bars,
367 set their sensitivity based on current
371 update_pan_sensitive ();
373 panning_viewport.remove ();
374 panning_viewport.add (pan_bar_packer);
375 panning_viewport.show_all ();
380 panner = new Panner2d (_io->panner(), 61);
381 panner->set_name ("MixerPanZone");
385 update_pan_sensitive ();
386 panner->reset (_io->n_inputs().n_audio());
387 panner->set_size_request (-1, 61);
389 /* and finally, add it to the panner frame */
391 panning_viewport.remove ();
392 panning_viewport.add (*panner);
393 panning_viewport.show_all ();
398 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
400 switch (ev->button) {
403 pan_menu = manage (new Menu);
404 pan_menu->set_name ("ArdourContextMenu");
406 build_pan_menu (which);
407 pan_menu->popup (1, ev->time);
414 return false; // what's wrong with gcc?
418 PannerUI::build_pan_menu (uint32_t which)
420 using namespace Menu_Helpers;
421 MenuList& items (pan_menu->items());
425 items.push_back (CheckMenuElem (_("Mute")));
427 /* set state first, connect second */
429 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner().streampanner(which).muted());
430 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
431 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
433 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
434 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
436 /* set state first, connect second */
438 bypass_menu_item->set_active (_io->panner().bypassed());
439 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
441 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
442 items.push_back (SeparatorElem());
443 items.push_back (MenuElem (_("Reset all")));
447 PannerUI::pan_mute (uint32_t which)
449 StreamPanner& sp = _io->panner().streampanner(which);
450 sp.set_muted (!sp.muted());
454 PannerUI::pan_bypass_toggle ()
456 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
457 _io->panner().set_bypassed (!_io->panner().bypassed());
462 PannerUI::pan_reset ()
467 PannerUI::effective_pan_display ()
469 if (_io->panner().empty()) {
473 switch (_io->n_outputs().n_audio()) {
480 update_pan_bars (true);
484 //panner->move_puck (pan_value (v, right), 0.5);
490 PannerUI::pan_changed (void *src)
496 switch (_io->panner().npanners()) {
498 panning_link_direction_button.set_sensitive (false);
499 panning_link_button.set_sensitive (false);
502 panning_link_direction_button.set_sensitive (false);
503 panning_link_button.set_sensitive (false);
506 panning_link_direction_button.set_sensitive (true);
507 panning_link_button.set_sensitive (true);
510 uint32_t nouts = _io->n_outputs().n_audio();
519 update_pan_bars (false);
523 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
529 PannerUI::pan_adjustment_changed (uint32_t which)
531 if (!in_pan_update && which < _io->panner().npanners()) {
534 float val = pan_adjustments[which]->get_value ();
535 xpos = _io->panner().pan_control( which )->get_value();
537 /* add a kinda-sorta detent for the middle */
539 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
540 /* this is going to be reentrant, so just
544 in_pan_update = true;
545 pan_adjustments[which]->set_value (0.5);
546 in_pan_update = false;
550 if (!Panner::equivalent (val, xpos)) {
552 _io->panner().streampanner(which).set_position (val);
554 the panner objects have no access to the session,
555 so do this here. ick.
557 _session.set_dirty();
563 PannerUI::pan_value_changed (uint32_t which)
565 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
567 if (_io->n_outputs().n_audio() > 1 && which < _io->panner().npanners()) {
569 float val = pan_adjustments[which]->get_value ();
571 _io->panner().streampanner(which).get_position (xpos);
573 if (!Panner::equivalent (val, xpos)) {
574 in_pan_update = true;
575 pan_adjustments[which]->set_value (xpos);
576 in_pan_update = false;
582 PannerUI::update_pan_bars (bool only_if_aplay)
585 vector<Adjustment*>::iterator i;
587 in_pan_update = true;
589 /* this runs during automation playback, and moves the bar controllers
593 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
597 boost::shared_ptr<AutomationList> alist (_io->panner().streampanner(n).pan_control()->alist());
599 if (!alist->automation_playback()) {
604 _io->panner().streampanner(n).get_effective_position (xpos);
605 val = (*i)->get_value ();
607 if (!Panner::equivalent (val, xpos)) {
608 (*i)->set_value (xpos);
612 in_pan_update = false;
616 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
618 float val = adj->get_value();
621 snprintf (buf, len, X_("L"));
622 } else if (val == 1.0f) {
623 snprintf (buf, len, X_("R"));
624 } else if (Panner::equivalent (val, 0.5f)) {
625 snprintf (buf, len, X_("C"));
627 /* don't print anything */
633 PannerUI::update_pan_sensitive ()
635 bool sensitive = !(_io->panner().automation_state() & Play);
637 switch (_io->n_outputs().n_audio()) {
642 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
643 (*i)->set_sensitive (sensitive);
648 panner->set_sensitive (sensitive);
655 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
657 using namespace Menu_Helpers;
659 if (ev->type == GDK_BUTTON_RELEASE) {
663 switch (ev->button) {
665 pan_astate_menu.popup (1, ev->time);
675 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
677 if (ev->type == GDK_BUTTON_RELEASE) {
681 switch (ev->button) {
683 pan_astyle_menu.popup (1, ev->time);
692 PannerUI::pan_automation_style_changed ()
694 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
698 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
701 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
707 PannerUI::pan_automation_state_changed ()
709 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
715 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
718 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
722 /* when creating a new session, we get to create busses (and
723 sometimes tracks) with no outputs by the time they get
727 if (_io->panner().empty()) {
731 x = (_io->panner().streampanner(0).pan_control()->alist()->automation_state() != Off);
733 if (pan_automation_state_button.get_active() != x) {
734 ignore_toggle = true;
735 pan_automation_state_button.set_active (x);
736 ignore_toggle = false;
739 update_pan_sensitive ();
741 /* start watching automation so that things move */
743 pan_watching.disconnect();
746 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
751 PannerUI::astate_string (AutoState state)
753 return _astate_string (state, false);
757 PannerUI::short_astate_string (AutoState state)
759 return _astate_string (state, true);
763 PannerUI::_astate_string (AutoState state, bool shrt)
769 sstr = (shrt ? "M" : _("M"));
772 sstr = (shrt ? "P" : _("P"));
775 sstr = (shrt ? "T" : _("T"));
778 sstr = (shrt ? "W" : _("W"));
786 PannerUI::astyle_string (AutoStyle style)
788 return _astyle_string (style, false);
792 PannerUI::short_astyle_string (AutoStyle style)
794 return _astyle_string (style, true);
798 PannerUI::_astyle_string (AutoStyle style, bool shrt)
803 /* XXX it might different in different languages */
805 return (shrt ? _("Abs") : _("Abs"));