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"
33 #include "gui_thread.h"
35 #include <ardour/session.h>
36 #include <ardour/panner.h>
37 #include <ardour/route.h>
41 using namespace ARDOUR;
43 using namespace Gtkmm2ext;
48 PannerUI::PannerUI (boost::shared_ptr<IO> io, Session& s)
51 hAdjustment(0.0, 0.0, 0.0),
52 vAdjustment(0.0, 0.0, 0.0),
53 panning_viewport(hAdjustment, vAdjustment),
54 panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
55 panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
56 panning_link_button (_("link")),
57 pan_automation_style_button (""),
58 pan_automation_state_button ("")
60 ignore_toggle = false;
62 in_pan_update = false;
64 pan_automation_style_button.set_name ("MixerAutomationModeButton");
65 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
67 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
68 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
70 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
71 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
73 pan_bar_packer.set_size_request (-1, 61);
74 panning_viewport.set_size_request (61, 61);
76 panning_viewport.set_name (X_("BaseFrame"));
78 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
79 _("panning link control"));
80 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
81 _("panning link direction"));
83 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
84 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
86 using namespace Menu_Helpers;
87 pan_astate_menu.items().push_back (MenuElem (_("Off"),
88 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Off)));
89 pan_astate_menu.items().push_back (MenuElem (_("Play"),
90 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Play)));
91 pan_astate_menu.items().push_back (MenuElem (_("Write"),
92 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Write)));
93 pan_astate_menu.items().push_back (MenuElem (_("Touch"),
94 bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Touch)));
96 pan_astyle_menu.items().push_back (MenuElem (_("Trim")));
97 pan_astyle_menu.items().push_back (MenuElem (_("Abs")));
99 pan_astate_menu.set_name ("ArdourContextMenu");
100 pan_astyle_menu.set_name ("ArdourContextMenu");
102 pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
103 pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
105 panning_link_button.set_name (X_("PanningLinkButton"));
106 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
108 panning_link_box.pack_start (panning_link_button, true, true);
109 panning_link_box.pack_start (panning_link_direction_button, true, true);
110 panning_link_box.pack_start (pan_automation_state_button, true, true);
112 /* the pixmap will be reset at some point, but the key thing is that
113 we need a pixmap in the button just to get started.
115 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
117 panning_link_direction_button.signal_clicked().connect
118 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
120 panning_link_button.signal_button_press_event().connect
121 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
122 panning_link_button.signal_button_release_event().connect
123 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
125 panning_up.set_border_width (3);
126 panning_down.set_border_width (3);
127 panning_up.add (panning_up_arrow);
128 panning_down.add (panning_down_arrow);
129 panning_up.set_name (X_("PanScrollerBase"));
130 panning_down.set_name (X_("PanScrollerBase"));
131 panning_up_arrow.set_name (X_("PanScrollerArrow"));
132 panning_down_arrow.set_name (X_("PanScrollerArrow"));
134 pan_vbox.set_spacing (4);
135 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
136 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
138 pack_start (pan_vbox, true, false);
144 _io->panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
145 _io->panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
146 _io->panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
149 update_pan_sensitive ();
150 update_pan_linkage ();
151 pan_automation_state_changed ();
155 PannerUI::panning_link_button_press (GdkEventButton* ev)
157 cerr << "link press\n";
162 PannerUI::panning_link_button_release (GdkEventButton* ev)
164 cerr << "link release\n";
165 if (!ignore_toggle) {
166 _io->panner().set_linked (!_io->panner().linked());
172 PannerUI::panning_link_direction_clicked()
174 switch (_io->panner().link_direction()) {
175 case Panner::SameDirection:
176 _io->panner().set_link_direction (Panner::OppositeDirection);
179 _io->panner().set_link_direction (Panner::SameDirection);
185 PannerUI::update_pan_linkage ()
187 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
189 bool x = _io->panner().linked();
190 bool bx = panning_link_button.get_active();
194 ignore_toggle = true;
195 panning_link_button.set_active (x);
196 ignore_toggle = false;
199 panning_link_direction_button.set_sensitive (x);
201 switch (_io->panner().link_direction()) {
202 case Panner::SameDirection:
203 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
206 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
212 PannerUI::set_width (Width w)
216 panning_viewport.set_size_request (61, 61);
218 panner->set_size_request (61, 61);
220 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
221 (*i)->set_size_request (61, 15);
223 panning_link_button.set_label (_("link"));
226 panning_viewport.set_size_request (31, 61);
228 panner->set_size_request (31, 61);
230 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
231 (*i)->set_size_request (31, 15);
233 panning_link_button.set_label (_("L"));
241 PannerUI::~PannerUI ()
243 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
247 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
263 PannerUI::panner_changed ()
265 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
270 PannerUI::update_pan_state ()
272 /* currently nothing to do */
273 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
277 PannerUI::setup_pan ()
279 uint32_t nouts = _io->n_outputs ();
281 if (nouts == 0 || nouts == 1) {
283 while (!pan_adjustments.empty()) {
284 delete pan_bars.back();
285 pan_bars.pop_back ();
286 delete pan_adjustments.back();
287 pan_adjustments.pop_back ();
290 } else if (nouts == 2) {
292 vector<Adjustment*>::size_type asz;
293 uint32_t npans = _io->panner().size();
295 while (!pan_adjustments.empty()) {
296 delete pan_bars.back();
297 pan_bars.pop_back ();
298 delete pan_adjustments.back();
299 pan_adjustments.pop_back ();
302 while ((asz = pan_adjustments.size()) < npans) {
307 /* initialize adjustment with current value of panner */
309 _io->panner()[asz]->get_position (x);
311 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
312 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
314 _io->panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
316 bc = new BarController (*pan_adjustments[asz],
317 _io->panner()[asz]->control(),
318 bind (mem_fun(*this, &PannerUI::pan_printer), pan_adjustments[asz]));
320 bc->set_name ("PanSlider");
321 bc->set_shadow_type (Gtk::SHADOW_NONE);
322 bc->set_style (BarController::Line);
324 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
325 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
328 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
329 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
331 bc->event_widget().signal_button_release_event().connect
332 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
334 pan_bars.push_back (bc);
337 pan_bars.back()->set_size_request (61, 15);
340 pan_bars.back()->set_size_request (31, 15);
344 pan_bar_packer.pack_start (*pan_bars.back(), false, false);
347 /* now that we actually have the pan bars,
348 set their sensitivity based on current
352 update_pan_sensitive ();
354 panning_viewport.remove ();
355 panning_viewport.add (pan_bar_packer);
356 panning_viewport.show_all ();
372 panner = new Panner2d (_io->panner(), w, 61);
373 panner->set_name ("MixerPanZone");
377 update_pan_sensitive ();
378 panner->reset (_io->n_inputs());
379 panner->set_size_request (w, 61);
381 /* and finally, add it to the panner frame */
383 panning_viewport.remove ();
384 panning_viewport.add (*panner);
385 panning_viewport.show_all ();
390 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
392 switch (ev->button) {
395 pan_menu = manage (new Menu);
396 pan_menu->set_name ("ArdourContextMenu");
398 build_pan_menu (which);
399 pan_menu->popup (1, ev->time);
406 return false; // what's wrong with gcc?
410 PannerUI::build_pan_menu (uint32_t which)
412 using namespace Menu_Helpers;
413 MenuList& items (pan_menu->items());
417 items.push_back (CheckMenuElem (_("Mute")));
419 /* set state first, connect second */
421 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()[which]->muted());
422 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
423 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
425 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
426 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
428 /* set state first, connect second */
430 bypass_menu_item->set_active (_io->panner().bypassed());
431 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
433 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
434 items.push_back (SeparatorElem());
435 items.push_back (MenuElem (_("Reset all")));
439 PannerUI::pan_mute (uint32_t which)
441 StreamPanner* sp = _io->panner()[which];
442 sp->set_muted (!sp->muted());
446 PannerUI::pan_bypass_toggle ()
448 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
449 _io->panner().set_bypassed (!_io->panner().bypassed());
454 PannerUI::pan_reset ()
459 PannerUI::effective_pan_display ()
461 if (_io->panner().empty()) {
465 switch (_io->n_outputs()) {
472 update_pan_bars (true);
476 //panner->move_puck (pan_value (v, right), 0.5);
482 PannerUI::pan_changed (void *src)
488 switch (_io->panner().size()) {
490 panning_link_direction_button.set_sensitive (false);
491 panning_link_button.set_sensitive (false);
494 panning_link_direction_button.set_sensitive (false);
495 panning_link_button.set_sensitive (false);
498 panning_link_direction_button.set_sensitive (true);
499 panning_link_button.set_sensitive (true);
502 uint32_t nouts = _io->n_outputs();
511 update_pan_bars (false);
515 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
521 PannerUI::pan_adjustment_changed (uint32_t which)
523 if (!in_pan_update && which < _io->panner().size()) {
526 float val = pan_adjustments[which]->get_value ();
527 _io->panner()[which]->get_position (xpos);
529 /* add a kinda-sorta detent for the middle */
531 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
532 /* this is going to be reentrant, so just
536 in_pan_update = true;
537 pan_adjustments[which]->set_value (0.5);
538 in_pan_update = false;
542 if (!Panner::equivalent (val, xpos)) {
544 _io->panner()[which]->set_position (val);
546 the panner objects have no access to the session,
547 so do this here. ick.
549 _session.set_dirty();
555 PannerUI::pan_value_changed (uint32_t which)
557 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
559 if (_io->n_outputs() > 1 && which < _io->panner().size()) {
561 float val = pan_adjustments[which]->get_value ();
563 _io->panner()[which]->get_position (xpos);
565 if (!Panner::equivalent (val, xpos)) {
566 in_pan_update = true;
567 pan_adjustments[which]->set_value (xpos);
568 in_pan_update = false;
574 PannerUI::update_pan_bars (bool only_if_aplay)
577 vector<Adjustment*>::iterator i;
579 in_pan_update = true;
581 /* this runs during automation playback, and moves the bar controllers
585 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
589 AutomationList& alist (_io->panner()[n]->automation());
591 if (!alist.automation_playback()) {
596 _io->panner()[n]->get_effective_position (xpos);
597 val = (*i)->get_value ();
599 if (!Panner::equivalent (val, xpos)) {
600 (*i)->set_value (xpos);
604 in_pan_update = false;
608 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
610 float val = adj->get_value();
613 snprintf (buf, len, X_("L"));
614 } else if (val == 1.0f) {
615 snprintf (buf, len, X_("R"));
616 } else if (Panner::equivalent (val, 0.5f)) {
617 snprintf (buf, len, X_("C"));
619 /* don't print anything */
625 PannerUI::update_pan_sensitive ()
627 bool sensitive = !(_io->panner().automation_state() & Play);
629 switch (_io->n_outputs()) {
634 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
635 (*i)->set_sensitive (sensitive);
640 panner->set_sensitive (sensitive);
647 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
649 using namespace Menu_Helpers;
651 if (ev->type == GDK_BUTTON_RELEASE) {
655 switch (ev->button) {
657 pan_astate_menu.popup (1, ev->time);
667 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
669 if (ev->type == GDK_BUTTON_RELEASE) {
673 switch (ev->button) {
675 pan_astyle_menu.popup (1, ev->time);
684 PannerUI::pan_automation_style_changed ()
686 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
690 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
693 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
699 PannerUI::pan_automation_state_changed ()
701 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
707 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
710 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
714 /* when creating a new session, we get to create busses (and
715 sometimes tracks) with no outputs by the time they get
719 if (_io->panner().empty()) {
723 x = (_io->panner().front()->automation().automation_state() != Off);
725 if (pan_automation_state_button.get_active() != x) {
726 ignore_toggle = true;
727 pan_automation_state_button.set_active (x);
728 ignore_toggle = false;
731 update_pan_sensitive ();
733 /* start watching automation so that things move */
735 pan_watching.disconnect();
738 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
743 PannerUI::astate_string (AutoState state)
745 return _astate_string (state, false);
749 PannerUI::short_astate_string (AutoState state)
751 return _astate_string (state, true);
755 PannerUI::_astate_string (AutoState state, bool shrt)
761 sstr = (shrt ? "O" : _("O"));
764 sstr = (shrt ? "P" : _("P"));
767 sstr = (shrt ? "T" : _("T"));
770 sstr = (shrt ? "W" : _("W"));
778 PannerUI::astyle_string (AutoStyle style)
780 return _astyle_string (style, false);
784 PannerUI::short_astyle_string (AutoStyle style)
786 return _astyle_string (style, true);
790 PannerUI::_astyle_string (AutoStyle style, bool shrt)
795 /* XXX it might different in different languages */
797 return (shrt ? _("Abs") : _("Abs"));