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 (_("Off"),
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 /* the pixmap will be reset at some point, but the key thing is that
110 we need a pixmap in the button just to get started.
113 Gtk::HBox* pan_button_hbox = manage (new Gtk::HBox());
115 panning_link_box.pack_start (panning_link_button, true, true);
116 panning_link_box.pack_start (panning_link_direction_button, true, true);
117 pan_button_hbox->pack_start (panning_link_box, true, true);
118 pan_button_hbox->pack_start (pan_automation_state_button, true, true);
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), false);
127 panning_link_button.signal_button_release_event().connect
128 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
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 cerr << "link press\n";
165 PannerUI::panning_link_button_release (GdkEventButton* ev)
167 cerr << "link release\n";
168 if (!ignore_toggle) {
169 _io.panner().set_linked (!_io.panner().linked());
175 PannerUI::panning_link_direction_clicked()
177 switch (_io.panner().link_direction()) {
178 case Panner::SameDirection:
179 _io.panner().set_link_direction (Panner::OppositeDirection);
182 _io.panner().set_link_direction (Panner::SameDirection);
188 PannerUI::update_pan_linkage ()
190 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
192 bool x = _io.panner().linked();
193 bool bx = panning_link_button.get_active();
197 ignore_toggle = true;
198 panning_link_button.set_active (x);
199 ignore_toggle = false;
202 panning_link_direction_button.set_sensitive (x);
204 switch (_io.panner().link_direction()) {
205 case Panner::SameDirection:
206 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
209 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
215 PannerUI::set_width (Width w)
219 panning_viewport.set_size_request (61, 61);
221 panner->set_size_request (61, 61);
223 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
224 (*i)->set_size_request (61, 15);
226 panning_link_button.set_label (_("link"));
229 panning_viewport.set_size_request (31, 61);
231 panner->set_size_request (31, 61);
233 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
234 (*i)->set_size_request (31, 15);
236 panning_link_button.set_label (_("L"));
244 PannerUI::~PannerUI ()
246 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
250 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
266 PannerUI::panner_changed ()
268 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
273 PannerUI::update_pan_state ()
275 /* currently nothing to do */
276 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
280 PannerUI::setup_pan ()
282 uint32_t nouts = _io.n_outputs ();
284 if (nouts == 0 || nouts == 1) {
286 while (!pan_adjustments.empty()) {
287 delete pan_bars.back();
288 pan_bars.pop_back ();
289 delete pan_adjustments.back();
290 pan_adjustments.pop_back ();
293 } else if (nouts == 2) {
295 vector<Adjustment*>::size_type asz;
296 uint32_t npans = _io.panner().size();
298 while (!pan_adjustments.empty()) {
299 delete pan_bars.back();
300 pan_bars.pop_back ();
301 delete pan_adjustments.back();
302 pan_adjustments.pop_back ();
305 while ((asz = pan_adjustments.size()) < npans) {
310 /* initialize adjustment with current value of panner */
312 _io.panner()[asz]->get_position (x);
314 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
315 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
317 _io.panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
319 bc = new BarController (*pan_adjustments[asz],
320 &_io.panner()[asz]->midi_control(),
321 bind (mem_fun(*this, &PannerUI::pan_printer), pan_adjustments[asz]));
323 if (_session.midi_port()) {
324 _io.panner()[asz]->reset_midi_control (_session.midi_port(), true);
327 bc->set_name ("PanSlider");
328 bc->set_shadow_type (Gtk::SHADOW_NONE);
329 bc->set_style (BarController::Line);
331 bc->StartGesture.connect (bind (mem_fun (_io, &IO::start_pan_touch), (uint32_t) asz));
332 bc->StopGesture.connect (bind (mem_fun (_io, &IO::end_pan_touch), (uint32_t) asz));
336 snprintf (buf, sizeof (buf), _("panner for channel %lu"), asz + 1);
338 snprintf (buf, sizeof (buf), _("panner for channel %u"), asz + 1);
340 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
342 bc->event_widget().signal_button_release_event().connect
343 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
345 pan_bars.push_back (bc);
348 pan_bars.back()->set_size_request (61, 15);
351 pan_bars.back()->set_size_request (31, 15);
355 pan_bar_packer.pack_start (*pan_bars.back(), false, false);
358 /* now that we actually have the pan bars,
359 set their sensitivity based on current
363 update_pan_sensitive ();
365 panning_viewport.remove ();
366 panning_viewport.add (pan_bar_packer);
367 panning_viewport.show_all ();
383 panner = new Panner2d (_io.panner(), w, 61);
384 panner->set_name ("MixerPanZone");
388 update_pan_sensitive ();
389 panner->reset (_io.n_inputs());
390 panner->set_size_request (w, 61);
392 /* and finally, add it to the panner frame */
394 panning_viewport.remove ();
395 panning_viewport.add (*panner);
396 panning_viewport.show_all ();
401 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
403 switch (ev->button) {
406 pan_menu = manage (new Menu);
407 pan_menu->set_name ("ArdourContextMenu");
409 build_pan_menu (which);
410 pan_menu->popup (1, ev->time);
417 return false; // what's wrong with gcc?
421 PannerUI::build_pan_menu (uint32_t which)
423 using namespace Menu_Helpers;
424 MenuList& items (pan_menu->items());
428 items.push_back (CheckMenuElem (_("Mute")));
430 /* set state first, connect second */
432 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io.panner()[which]->muted());
433 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
434 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
436 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
437 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
439 /* set state first, connect second */
441 bypass_menu_item->set_active (_io.panner().bypassed());
442 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
444 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
445 items.push_back (SeparatorElem());
446 items.push_back (MenuElem (_("Reset all")));
450 PannerUI::pan_mute (uint32_t which)
452 StreamPanner* sp = _io.panner()[which];
453 sp->set_muted (!sp->muted());
457 PannerUI::pan_bypass_toggle ()
459 if (bypass_menu_item && (_io.panner().bypassed() != bypass_menu_item->get_active())) {
460 _io.panner().set_bypassed (!_io.panner().bypassed());
465 PannerUI::pan_reset ()
470 PannerUI::effective_pan_display ()
472 if (_io.panner().empty()) {
476 switch (_io.n_outputs()) {
483 update_pan_bars (true);
487 //panner->move_puck (pan_value (v, right), 0.5);
493 PannerUI::pan_changed (void *src)
499 switch (_io.panner().size()) {
501 panning_link_box.set_sensitive (false);
504 panning_link_box.set_sensitive (false);
507 panning_link_box.set_sensitive (true);
510 uint32_t nouts = _io.n_outputs();
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().size()) {
534 float val = pan_adjustments[which]->get_value ();
535 _io.panner()[which]->get_position (xpos);
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()[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() > 1 && which < _io.panner().size()) {
569 float val = pan_adjustments[which]->get_value ();
571 _io.panner()[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 AutomationList& alist (_io.panner()[n]->automation());
599 if (!alist.automation_playback()) {
604 _io.panner()[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()) {
642 for (vector<BarController*>::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().front()->automation().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 ? "O" : _("O"));
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"));