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.
23 #include <ardour/io.h>
24 #include <ardour/dB.h>
25 #include <gtkmm2ext/utils.h>
26 #include <gtkmm2ext/stop_signal.h>
27 #include <gtkmm2ext/barcontroller.h>
28 #include <midi++/manager.h>
29 #include <pbd/fastlog.h>
31 #include "ardour_ui.h"
32 #include "panner_ui.h"
35 #include "gui_thread.h"
37 #include <ardour/session.h>
38 #include <ardour/panner.h>
39 #include <ardour/route.h>
43 using namespace ARDOUR;
44 using namespace Gtkmm2ext;
49 PannerUI::PannerUI (IO& io, Session& s)
52 hAdjustment(0.0, 0.0, 0.0),
53 vAdjustment(0.0, 0.0, 0.0),
54 panning_viewport(hAdjustment, vAdjustment),
55 panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
56 panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
57 panning_link_button (_("link")),
58 pan_automation_style_button (""),
59 pan_automation_state_button ("")
61 ignore_toggle = false;
63 in_pan_update = false;
65 pan_automation_style_button.set_name ("MixerAutomationModeButton");
66 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
68 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
69 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
71 set_size_request_to_display_given_text (pan_automation_state_button, X_("M"), 2, 2);
72 set_size_request_to_display_given_text (pan_automation_style_button, X_("M"), 2, 2);
74 pan_bar_packer.set_size_request (-1, 61);
75 panning_viewport.set_size_request (61, 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 Gtk::HBox* pan_button_hbox = manage (new Gtk::HBox());
108 panning_link_box.pack_start (panning_link_button, true, true);
109 panning_link_box.pack_start (panning_link_direction_button, true, true);
110 pan_button_hbox->pack_start (panning_link_box, true, true);
111 pan_button_hbox->pack_start (pan_automation_state_button, true, true);
113 panning_link_button.set_name (X_("PanningLinkButton"));
114 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
116 /* the pixmap will be reset at some point, but the key thing is that
117 we need a pixmap in the button just to get started.
120 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
122 panning_link_direction_button.signal_clicked().connect
123 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
125 panning_link_button.signal_button_press_event().connect
126 (mem_fun(*this, &PannerUI::panning_link_button_press));
127 panning_link_button.signal_button_release_event().connect
128 (mem_fun(*this, &PannerUI::panning_link_button_release));
130 panning_up.set_border_width (3);
131 panning_down.set_border_width (3);
132 panning_up.add (panning_up_arrow);
133 panning_down.add (panning_down_arrow);
134 panning_up.set_name (X_("PanScrollerBase"));
135 panning_down.set_name (X_("PanScrollerBase"));
136 panning_up_arrow.set_name (X_("PanScrollerArrow"));
137 panning_down_arrow.set_name (X_("PanScrollerArrow"));
139 pan_vbox.set_spacing (4);
140 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
141 pan_vbox.pack_start (*pan_button_hbox, Gtk::PACK_SHRINK);
143 pack_start (pan_vbox, true, false);
147 _io.panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
148 _io.panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
149 _io.panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
152 update_pan_sensitive ();
153 update_pan_linkage ();
154 pan_automation_state_changed ();
158 PannerUI::panning_link_button_press (GdkEventButton* ev)
160 return stop_signal (panning_link_button, "button-press-event");
164 PannerUI::panning_link_button_release (GdkEventButton* ev)
166 if (!ignore_toggle) {
167 _io.panner().set_linked (!_io.panner().linked());
173 PannerUI::panning_link_direction_clicked()
175 switch (_io.panner().link_direction()) {
176 case Panner::SameDirection:
177 _io.panner().set_link_direction (Panner::OppositeDirection);
180 _io.panner().set_link_direction (Panner::SameDirection);
186 PannerUI::update_pan_linkage ()
188 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
190 bool x = _io.panner().linked();
191 bool bx = panning_link_button.get_active();
195 ignore_toggle = true;
196 panning_link_button.set_active (x);
197 ignore_toggle = false;
200 panning_link_direction_button.set_sensitive (x);
202 switch (_io.panner().link_direction()) {
203 case Panner::SameDirection:
204 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
207 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
213 PannerUI::set_width (Width w)
217 panning_viewport.set_size_request (61, 61);
219 panner->set_size_request (61, 61);
221 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
222 (*i)->set_size_request (61, 15);
224 panning_link_button.set_label (_("link"));
227 panning_viewport.set_size_request (31, 61);
229 panner->set_size_request (31, 61);
231 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
232 (*i)->set_size_request (31, 15);
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<BarController*>::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 ();
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 } else if (nouts == 2) {
293 vector<Adjustment*>::size_type asz;
294 uint32_t npans = _io.panner().size();
296 while (!pan_adjustments.empty()) {
297 delete pan_bars.back();
298 pan_bars.pop_back ();
299 delete pan_adjustments.back();
300 pan_adjustments.pop_back ();
303 while ((asz = pan_adjustments.size()) < npans) {
308 /* initialize adjustment with current value of panner */
310 _io.panner()[asz]->get_position (x);
312 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
313 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
315 _io.panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
317 bc = new BarController (*pan_adjustments[asz],
318 &_io.panner()[asz]->midi_control(),
319 bind (mem_fun(*this, &PannerUI::pan_printer), pan_adjustments[asz]));
321 if (_session.midi_port()) {
322 _io.panner()[asz]->reset_midi_control (_session.midi_port(), true);
325 bc->set_name ("PanSlider");
326 bc->set_shadow_type (Gtk::SHADOW_NONE);
327 bc->set_style (BarController::Line);
329 bc->StartGesture.connect (bind (mem_fun (_io, &IO::start_pan_touch), (uint32_t) asz));
330 bc->StopGesture.connect (bind (mem_fun (_io, &IO::end_pan_touch), (uint32_t) asz));
334 snprintf (buf, sizeof (buf), _("panner for channel %lu"), asz + 1);
336 snprintf (buf, sizeof (buf), _("panner for channel %u"), asz + 1);
338 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
340 bc->event_widget().signal_button_release_event().connect
341 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
343 pan_bars.push_back (bc);
346 pan_bars.back()->set_size_request (61, 15);
349 pan_bars.back()->set_size_request (31, 15);
353 pan_bar_packer.pack_start (*pan_bars.back(), false, false);
356 /* now that we actually have the pan bars,
357 set their sensitivity based on current
361 update_pan_sensitive ();
363 panning_viewport.remove ();
364 panning_viewport.add (pan_bar_packer);
365 panning_viewport.show_all ();
381 panner = new Panner2d (_io.panner(), w, 61);
382 panner->set_name ("MixerPanZone");
386 update_pan_sensitive ();
387 panner->reset (_io.n_inputs());
388 panner->set_size_request (w, 61);
390 /* and finally, add it to the panner frame */
392 panning_viewport.remove ();
393 panning_viewport.add (*panner);
394 panning_viewport.show_all ();
399 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
401 switch (ev->button) {
404 pan_menu = manage (new Menu);
405 pan_menu->set_name ("ArdourContextMenu");
407 build_pan_menu (which);
408 pan_menu->popup (1, ev->time);
415 return FALSE; // what's wrong with gcc?
419 PannerUI::build_pan_menu (uint32_t which)
421 using namespace Menu_Helpers;
422 MenuList& items (pan_menu->items());
426 items.push_back (CheckMenuElem (_("Mute")));
428 /* set state first, connect second */
430 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io.panner()[which]->muted());
431 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
432 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
434 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
435 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
437 /* set state first, connect second */
439 bypass_menu_item->set_active (_io.panner().bypassed());
440 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
442 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
443 items.push_back (SeparatorElem());
444 items.push_back (MenuElem (_("Reset all")));
448 PannerUI::pan_mute (uint32_t which)
450 StreamPanner* sp = _io.panner()[which];
451 sp->set_muted (!sp->muted());
455 PannerUI::pan_bypass_toggle ()
457 if (bypass_menu_item && (_io.panner().bypassed() != bypass_menu_item->get_active())) {
458 _io.panner().set_bypassed (!_io.panner().bypassed());
463 PannerUI::pan_reset ()
468 PannerUI::effective_pan_display ()
470 if (_io.panner().empty()) {
474 switch (_io.n_outputs()) {
481 update_pan_bars (true);
485 //panner->move_puck (pan_value (v, right), 0.5);
491 PannerUI::pan_changed (void *src)
497 switch (_io.panner().size()) {
499 panning_link_box.set_sensitive (false);
502 panning_link_box.set_sensitive (false);
505 panning_link_box.set_sensitive (true);
508 uint32_t nouts = _io.n_outputs();
517 update_pan_bars (false);
521 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
527 PannerUI::pan_adjustment_changed (uint32_t which)
529 if (!in_pan_update && which < _io.panner().size()) {
532 float val = pan_adjustments[which]->get_value ();
533 _io.panner()[which]->get_position (xpos);
535 /* add a kinda-sorta detent for the middle */
537 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
538 /* this is going to be reentrant, so just
542 in_pan_update = true;
543 pan_adjustments[which]->set_value (0.5);
544 in_pan_update = false;
548 if (!Panner::equivalent (val, xpos)) {
550 _io.panner()[which]->set_position (val);
552 the panner objects have no access to the session,
553 so do this here. ick.
555 _session.set_dirty();
561 PannerUI::pan_value_changed (uint32_t which)
563 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
565 if (_io.n_outputs() > 1 && which < _io.panner().size()) {
567 float val = pan_adjustments[which]->get_value ();
569 _io.panner()[which]->get_position (xpos);
571 if (!Panner::equivalent (val, xpos)) {
572 in_pan_update = true;
573 pan_adjustments[which]->set_value (xpos);
574 in_pan_update = false;
580 PannerUI::update_pan_bars (bool only_if_aplay)
583 vector<Adjustment*>::iterator i;
585 in_pan_update = true;
587 /* this runs during automation playback, and moves the bar controllers
591 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
595 AutomationList& alist (_io.panner()[n]->automation());
597 if (!alist.automation_playback()) {
602 _io.panner()[n]->get_effective_position (xpos);
603 val = (*i)->get_value ();
605 if (!Panner::equivalent (val, xpos)) {
606 (*i)->set_value (xpos);
610 in_pan_update = false;
614 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
616 float val = adj->get_value();
619 snprintf (buf, len, X_("L"));
620 } else if (val == 1.0f) {
621 snprintf (buf, len, X_("R"));
622 } else if (Panner::equivalent (val, 0.5f)) {
623 snprintf (buf, len, X_("C"));
625 /* don't print anything */
631 PannerUI::update_pan_sensitive ()
633 bool sensitive = !(_io.panner().automation_state() & Play);
635 switch (_io.n_outputs()) {
640 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
641 (*i)->set_sensitive (sensitive);
646 panner->set_sensitive (sensitive);
653 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
655 using namespace Menu_Helpers;
657 if (ev->type == GDK_BUTTON_RELEASE) {
661 switch (ev->button) {
663 pan_astate_menu.popup (1, ev->time);
673 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
675 if (ev->type == GDK_BUTTON_RELEASE) {
679 switch (ev->button) {
681 pan_astyle_menu.popup (1, ev->time);
690 PannerUI::pan_automation_style_changed ()
692 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
696 pan_automation_style_button.set_label (astyle_string(_io.panner().automation_style()));
699 pan_automation_style_button.set_label (short_astyle_string(_io.panner().automation_style()));
705 PannerUI::pan_automation_state_changed ()
707 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
713 pan_automation_state_button.set_label (astate_string(_io.panner().automation_state()));
716 pan_automation_state_button.set_label (short_astate_string(_io.panner().automation_state()));
720 /* when creating a new session, we get to create busses (and
721 sometimes tracks) with no outputs by the time they get
725 if (_io.panner().empty()) {
729 x = (_io.panner().front()->automation().automation_state() != Off);
731 if (pan_automation_state_button.get_active() != x) {
732 ignore_toggle = true;
733 pan_automation_state_button.set_active (x);
734 ignore_toggle = false;
737 update_pan_sensitive ();
739 /* start watching automation so that things move */
741 pan_watching.disconnect();
744 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
749 PannerUI::astate_string (AutoState state)
751 return _astate_string (state, false);
755 PannerUI::short_astate_string (AutoState state)
757 return _astate_string (state, true);
761 PannerUI::_astate_string (AutoState state, bool shrt)
767 sstr = (shrt ? "M" : _("M"));
770 sstr = (shrt ? "P" : _("P"));
773 sstr = (shrt ? "T" : _("T"));
776 sstr = (shrt ? "W" : _("W"));
784 PannerUI::astyle_string (AutoStyle style)
786 return _astyle_string (style, false);
790 PannerUI::short_astyle_string (AutoStyle style)
792 return _astyle_string (style, true);
796 PannerUI::_astyle_string (AutoStyle style, bool shrt)
801 /* XXX it might different in different languages */
803 return (shrt ? _("Abs") : _("Abs"));