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 ();
156 PannerUI::get_controllable()
158 return pan_bars[0]->get_controllable();
162 PannerUI::panning_link_button_press (GdkEventButton* ev)
164 cerr << "link press\n";
169 PannerUI::panning_link_button_release (GdkEventButton* ev)
171 cerr << "link release\n";
172 if (!ignore_toggle) {
173 _io->panner().set_linked (!_io->panner().linked());
179 PannerUI::panning_link_direction_clicked()
181 switch (_io->panner().link_direction()) {
182 case Panner::SameDirection:
183 _io->panner().set_link_direction (Panner::OppositeDirection);
186 _io->panner().set_link_direction (Panner::SameDirection);
192 PannerUI::update_pan_linkage ()
194 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
196 bool x = _io->panner().linked();
197 bool bx = panning_link_button.get_active();
201 ignore_toggle = true;
202 panning_link_button.set_active (x);
203 ignore_toggle = false;
206 panning_link_direction_button.set_sensitive (x);
208 switch (_io->panner().link_direction()) {
209 case Panner::SameDirection:
210 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
213 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
219 PannerUI::set_width (Width w)
223 panning_link_button.set_label (_("link"));
226 panning_link_button.set_label (_("L"));
234 PannerUI::~PannerUI ()
236 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
240 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
256 PannerUI::panner_changed ()
258 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
263 PannerUI::update_pan_state ()
265 /* currently nothing to do */
266 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
270 PannerUI::setup_pan ()
272 uint32_t nouts = _io->n_outputs ();
274 if (nouts == 0 || nouts == 1) {
276 while (!pan_adjustments.empty()) {
277 delete pan_bars.back();
278 pan_bars.pop_back ();
279 delete pan_adjustments.back();
280 pan_adjustments.pop_back ();
283 /* stick something into the panning viewport so that it redraws */
285 EventBox* eb = manage (new EventBox());
286 panning_viewport.remove ();
287 panning_viewport.add (*eb);
288 panning_viewport.show_all ();
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 0.0 (L) or 1.0 (R) for the first and second panners,
308 which serves as a default, otherwise use current value */
310 _io->panner()[asz]->get_position (rx);
314 } else if (asz == 0) {
316 } else if (asz == 1) {
322 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
323 bc = new PannerBar (*pan_adjustments[asz], _io->panner()[asz]->control());
325 /* now set adjustment with current value of panner, then connect the signals */
326 pan_adjustments.back()->set_value(rx);
327 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
329 _io->panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
332 bc->set_name ("PanSlider");
333 bc->set_shadow_type (Gtk::SHADOW_NONE);
335 bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
336 bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
339 snprintf (buf, sizeof (buf), _("panner for channel %zu"), 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 bc->set_size_request (-1, pan_bar_height);
347 pan_bars.push_back (bc);
348 pan_bar_packer.pack_start (*bc, false, false);
351 /* now that we actually have the pan bars,
352 set their sensitivity based on current
356 update_pan_sensitive ();
358 panning_viewport.remove ();
359 panning_viewport.add (pan_bar_packer);
360 panning_viewport.show_all ();
365 panner = new Panner2d (_io->panner(), 61);
366 panner->set_name ("MixerPanZone");
370 update_pan_sensitive ();
371 panner->reset (_io->n_inputs());
372 panner->set_size_request (-1, 61);
374 /* and finally, add it to the panner frame */
376 panning_viewport.remove ();
377 panning_viewport.add (*panner);
378 panning_viewport.show_all ();
383 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
385 switch (ev->button) {
388 pan_menu = manage (new Menu);
389 pan_menu->set_name ("ArdourContextMenu");
391 build_pan_menu (which);
392 pan_menu->popup (1, ev->time);
399 return false; // what's wrong with gcc?
403 PannerUI::build_pan_menu (uint32_t which)
405 using namespace Menu_Helpers;
406 MenuList& items (pan_menu->items());
410 items.push_back (CheckMenuElem (_("Mute")));
412 /* set state first, connect second */
414 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()[which]->muted());
415 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
416 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
418 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
419 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
421 /* set state first, connect second */
423 bypass_menu_item->set_active (_io->panner().bypassed());
424 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
426 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
427 items.push_back (SeparatorElem());
428 items.push_back (MenuElem (_("Reset all")));
432 PannerUI::pan_mute (uint32_t which)
434 StreamPanner* sp = _io->panner()[which];
435 sp->set_muted (!sp->muted());
439 PannerUI::pan_bypass_toggle ()
441 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
442 _io->panner().set_bypassed (!_io->panner().bypassed());
447 PannerUI::pan_reset ()
452 PannerUI::effective_pan_display ()
454 if (_io->panner().empty()) {
458 switch (_io->n_outputs()) {
465 update_pan_bars (true);
469 //panner->move_puck (pan_value (v, right), 0.5);
475 PannerUI::pan_changed (void *src)
481 switch (_io->panner().size()) {
483 panning_link_direction_button.set_sensitive (false);
484 panning_link_button.set_sensitive (false);
487 panning_link_direction_button.set_sensitive (false);
488 panning_link_button.set_sensitive (false);
491 panning_link_direction_button.set_sensitive (true);
492 panning_link_button.set_sensitive (true);
495 uint32_t nouts = _io->n_outputs();
504 update_pan_bars (false);
508 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
514 PannerUI::pan_adjustment_changed (uint32_t which)
516 if (!in_pan_update && which < _io->panner().size()) {
519 float val = pan_adjustments[which]->get_value ();
520 _io->panner()[which]->get_position (xpos);
522 /* add a kinda-sorta detent for the middle */
524 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
525 /* this is going to be reentrant, so just
529 in_pan_update = true;
530 pan_adjustments[which]->set_value (0.5);
531 in_pan_update = false;
535 if (!Panner::equivalent (val, xpos)) {
537 _io->panner()[which]->set_position (val);
539 the panner objects have no access to the session,
540 so do this here. ick.
542 _session.set_dirty();
548 PannerUI::pan_value_changed (uint32_t which)
550 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
552 if (_io->n_outputs() > 1 && which < _io->panner().size()) {
554 float val = pan_adjustments[which]->get_value ();
556 _io->panner()[which]->get_position (xpos);
558 if (!Panner::equivalent (val, xpos)) {
559 in_pan_update = true;
560 pan_adjustments[which]->set_value (xpos);
561 in_pan_update = false;
567 PannerUI::update_pan_bars (bool only_if_aplay)
570 vector<Adjustment*>::iterator i;
572 in_pan_update = true;
574 /* this runs during automation playback, and moves the bar controllers
578 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
582 AutomationList& alist (_io->panner()[n]->automation());
584 if (!alist.automation_playback()) {
589 _io->panner()[n]->get_effective_position (xpos);
590 val = (*i)->get_value ();
592 if (!Panner::equivalent (val, xpos)) {
593 (*i)->set_value (xpos);
597 in_pan_update = false;
601 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
603 float val = adj->get_value();
606 snprintf (buf, len, X_("L"));
607 } else if (val == 1.0f) {
608 snprintf (buf, len, X_("R"));
609 } else if (Panner::equivalent (val, 0.5f)) {
610 snprintf (buf, len, X_("C"));
612 /* don't print anything */
618 PannerUI::update_pan_sensitive ()
620 bool sensitive = !(_io->panner().automation_state() & Play);
622 switch (_io->n_outputs()) {
627 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
628 (*i)->set_sensitive (sensitive);
633 panner->set_sensitive (sensitive);
640 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
642 using namespace Menu_Helpers;
644 if (ev->type == GDK_BUTTON_RELEASE) {
648 switch (ev->button) {
650 pan_astate_menu.popup (1, ev->time);
660 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
662 if (ev->type == GDK_BUTTON_RELEASE) {
666 switch (ev->button) {
668 pan_astyle_menu.popup (1, ev->time);
677 PannerUI::pan_automation_style_changed ()
679 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
683 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
686 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
692 PannerUI::pan_automation_state_changed ()
694 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
700 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
703 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
707 /* when creating a new session, we get to create busses (and
708 sometimes tracks) with no outputs by the time they get
712 if (_io->panner().empty()) {
716 x = (_io->panner().front()->automation().automation_state() != Off);
718 if (pan_automation_state_button.get_active() != x) {
719 ignore_toggle = true;
720 pan_automation_state_button.set_active (x);
721 ignore_toggle = false;
724 update_pan_sensitive ();
726 /* start watching automation so that things move */
728 pan_watching.disconnect();
731 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
736 PannerUI::astate_string (AutoState state)
738 return _astate_string (state, false);
742 PannerUI::short_astate_string (AutoState state)
744 return _astate_string (state, true);
748 PannerUI::_astate_string (AutoState state, bool shrt)
754 sstr = (shrt ? "M" : _("M"));
757 sstr = (shrt ? "P" : _("P"));
760 sstr = (shrt ? "T" : _("T"));
763 sstr = (shrt ? "W" : _("W"));
771 PannerUI::astyle_string (AutoStyle style)
773 return _astyle_string (style, false);
777 PannerUI::short_astyle_string (AutoStyle style)
779 return _astyle_string (style, true);
783 PannerUI::_astyle_string (AutoStyle style, bool shrt)
788 /* XXX it might different in different languages */
790 return (shrt ? _("Abs") : _("Abs"));