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::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().size();
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 _io->panner()[asz]->get_position (rx);
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], _io->panner()[asz]->pan_control());
339 /* now set adjustment with current value of panner, then connect the signals */
340 pan_adjustments.back()->set_value(rx);
341 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
343 _io->panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
346 bc->set_name ("PanSlider");
347 bc->set_shadow_type (Gtk::SHADOW_NONE);
349 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
350 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
353 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
354 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
356 bc->event_widget().signal_button_release_event().connect
357 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
359 bc->set_size_request (-1, pan_bar_height);
361 pan_bars.push_back (bc);
362 pan_bar_packer.pack_start (*bc, false, false);
365 /* now that we actually have the pan bars,
366 set their sensitivity based on current
370 update_pan_sensitive ();
372 panning_viewport.remove ();
373 panning_viewport.add (pan_bar_packer);
374 panning_viewport.show_all ();
379 panner = new Panner2d (_io->panner(), 61);
380 panner->set_name ("MixerPanZone");
384 update_pan_sensitive ();
385 panner->reset (_io->n_inputs().n_audio());
386 panner->set_size_request (-1, 61);
388 /* and finally, add it to the panner frame */
390 panning_viewport.remove ();
391 panning_viewport.add (*panner);
392 panning_viewport.show_all ();
397 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
399 switch (ev->button) {
402 pan_menu = manage (new Menu);
403 pan_menu->set_name ("ArdourContextMenu");
405 build_pan_menu (which);
406 pan_menu->popup (1, ev->time);
413 return false; // what's wrong with gcc?
417 PannerUI::build_pan_menu (uint32_t which)
419 using namespace Menu_Helpers;
420 MenuList& items (pan_menu->items());
424 items.push_back (CheckMenuElem (_("Mute")));
426 /* set state first, connect second */
428 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()[which]->muted());
429 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
430 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
432 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
433 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
435 /* set state first, connect second */
437 bypass_menu_item->set_active (_io->panner().bypassed());
438 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
440 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
441 items.push_back (SeparatorElem());
442 items.push_back (MenuElem (_("Reset all")));
446 PannerUI::pan_mute (uint32_t which)
448 StreamPanner* sp = _io->panner()[which];
449 sp->set_muted (!sp->muted());
453 PannerUI::pan_bypass_toggle ()
455 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
456 _io->panner().set_bypassed (!_io->panner().bypassed());
461 PannerUI::pan_reset ()
466 PannerUI::effective_pan_display ()
468 if (_io->panner().empty()) {
472 switch (_io->n_outputs().n_audio()) {
479 update_pan_bars (true);
483 //panner->move_puck (pan_value (v, right), 0.5);
489 PannerUI::pan_changed (void *src)
495 switch (_io->panner().size()) {
497 panning_link_direction_button.set_sensitive (false);
498 panning_link_button.set_sensitive (false);
501 panning_link_direction_button.set_sensitive (false);
502 panning_link_button.set_sensitive (false);
505 panning_link_direction_button.set_sensitive (true);
506 panning_link_button.set_sensitive (true);
509 uint32_t nouts = _io->n_outputs().n_audio();
518 update_pan_bars (false);
522 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
528 PannerUI::pan_adjustment_changed (uint32_t which)
530 if (!in_pan_update && which < _io->panner().size()) {
533 float val = pan_adjustments[which]->get_value ();
534 _io->panner()[which]->get_position (xpos);
536 /* add a kinda-sorta detent for the middle */
538 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
539 /* this is going to be reentrant, so just
543 in_pan_update = true;
544 pan_adjustments[which]->set_value (0.5);
545 in_pan_update = false;
549 if (!Panner::equivalent (val, xpos)) {
551 _io->panner()[which]->set_position (val);
553 the panner objects have no access to the session,
554 so do this here. ick.
556 _session.set_dirty();
562 PannerUI::pan_value_changed (uint32_t which)
564 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
566 if (_io->n_outputs().n_audio() > 1 && which < _io->panner().size()) {
568 float val = pan_adjustments[which]->get_value ();
570 _io->panner()[which]->get_position (xpos);
572 if (!Panner::equivalent (val, xpos)) {
573 in_pan_update = true;
574 pan_adjustments[which]->set_value (xpos);
575 in_pan_update = false;
581 PannerUI::update_pan_bars (bool only_if_aplay)
584 vector<Adjustment*>::iterator i;
586 in_pan_update = true;
588 /* this runs during automation playback, and moves the bar controllers
592 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
596 boost::shared_ptr<AutomationList> alist (_io->panner()[n]->pan_control()->list());
598 if (!alist->automation_playback()) {
603 _io->panner()[n]->get_effective_position (xpos);
604 val = (*i)->get_value ();
606 if (!Panner::equivalent (val, xpos)) {
607 (*i)->set_value (xpos);
611 in_pan_update = false;
615 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
617 float val = adj->get_value();
620 snprintf (buf, len, X_("L"));
621 } else if (val == 1.0f) {
622 snprintf (buf, len, X_("R"));
623 } else if (Panner::equivalent (val, 0.5f)) {
624 snprintf (buf, len, X_("C"));
626 /* don't print anything */
632 PannerUI::update_pan_sensitive ()
634 bool sensitive = !(_io->panner().automation_state() & Play);
636 switch (_io->n_outputs().n_audio()) {
641 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
642 (*i)->set_sensitive (sensitive);
647 panner->set_sensitive (sensitive);
654 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
656 using namespace Menu_Helpers;
658 if (ev->type == GDK_BUTTON_RELEASE) {
662 switch (ev->button) {
664 pan_astate_menu.popup (1, ev->time);
674 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
676 if (ev->type == GDK_BUTTON_RELEASE) {
680 switch (ev->button) {
682 pan_astyle_menu.popup (1, ev->time);
691 PannerUI::pan_automation_style_changed ()
693 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
697 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
700 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
706 PannerUI::pan_automation_state_changed ()
708 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
714 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
717 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
721 /* when creating a new session, we get to create busses (and
722 sometimes tracks) with no outputs by the time they get
726 if (_io->panner().empty()) {
730 x = (_io->panner().front()->pan_control()->list()->automation_state() != Off);
732 if (pan_automation_state_button.get_active() != x) {
733 ignore_toggle = true;
734 pan_automation_state_button.set_active (x);
735 ignore_toggle = false;
738 update_pan_sensitive ();
740 /* start watching automation so that things move */
742 pan_watching.disconnect();
745 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
750 PannerUI::astate_string (AutoState state)
752 return _astate_string (state, false);
756 PannerUI::short_astate_string (AutoState state)
758 return _astate_string (state, true);
762 PannerUI::_astate_string (AutoState state, bool shrt)
768 sstr = (shrt ? "M" : _("M"));
771 sstr = (shrt ? "P" : _("P"));
774 sstr = (shrt ? "T" : _("T"));
777 sstr = (shrt ? "W" : _("W"));
785 PannerUI::astyle_string (AutoStyle style)
787 return _astyle_string (style, false);
791 PannerUI::short_astyle_string (AutoStyle style)
793 return _astyle_string (style, true);
797 PannerUI::_astyle_string (AutoStyle style, bool shrt)
802 /* XXX it might different in different languages */
804 return (shrt ? _("Abs") : _("Abs"));