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::panning_link_button_press (GdkEventButton* ev)
158 cerr << "link press\n";
163 PannerUI::panning_link_button_release (GdkEventButton* ev)
165 cerr << "link release\n";
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_link_button.set_label (_("link"));
220 panning_link_button.set_label (_("L"));
228 PannerUI::~PannerUI ()
230 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
234 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
250 PannerUI::panner_changed ()
252 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
257 PannerUI::update_pan_state ()
259 /* currently nothing to do */
260 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
264 PannerUI::setup_pan ()
266 uint32_t nouts = _io->n_outputs ();
268 if (nouts == 0 || nouts == 1) {
270 while (!pan_adjustments.empty()) {
271 delete pan_bars.back();
272 pan_bars.pop_back ();
273 delete pan_adjustments.back();
274 pan_adjustments.pop_back ();
277 /* stick something into the panning viewport so that it redraws */
279 EventBox* eb = manage (new EventBox());
280 panning_viewport.remove ();
281 panning_viewport.add (*eb);
282 panning_viewport.show_all ();
284 } else if (nouts == 2) {
286 vector<Adjustment*>::size_type asz;
287 uint32_t npans = _io->panner().size();
289 while (!pan_adjustments.empty()) {
290 delete pan_bars.back();
291 pan_bars.pop_back ();
292 delete pan_adjustments.back();
293 pan_adjustments.pop_back ();
296 while ((asz = pan_adjustments.size()) < npans) {
301 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
302 which serves as a default, otherwise use current value */
304 _io->panner()[asz]->get_position (rx);
308 } else if (asz == 0) {
310 } else if (asz == 1) {
316 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
317 bc = new PannerBar (*pan_adjustments[asz], _io->panner()[asz]->control());
319 /* now set adjustment with current value of panner, then connect the signals */
320 pan_adjustments.back()->set_value(rx);
321 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
323 _io->panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
326 bc->set_name ("PanSlider");
327 bc->set_shadow_type (Gtk::SHADOW_NONE);
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));
333 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
334 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
336 bc->event_widget().signal_button_release_event().connect
337 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
339 bc->set_size_request (-1, pan_bar_height);
341 pan_bars.push_back (bc);
342 pan_bar_packer.pack_start (*bc, false, false);
345 /* now that we actually have the pan bars,
346 set their sensitivity based on current
350 update_pan_sensitive ();
352 panning_viewport.remove ();
353 panning_viewport.add (pan_bar_packer);
354 panning_viewport.show_all ();
359 panner = new Panner2d (_io->panner(), 61);
360 panner->set_name ("MixerPanZone");
364 update_pan_sensitive ();
365 panner->reset (_io->n_inputs());
366 panner->set_size_request (-1, 61);
368 /* and finally, add it to the panner frame */
370 panning_viewport.remove ();
371 panning_viewport.add (*panner);
372 panning_viewport.show_all ();
377 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
379 switch (ev->button) {
382 pan_menu = manage (new Menu);
383 pan_menu->set_name ("ArdourContextMenu");
385 build_pan_menu (which);
386 pan_menu->popup (1, ev->time);
393 return false; // what's wrong with gcc?
397 PannerUI::build_pan_menu (uint32_t which)
399 using namespace Menu_Helpers;
400 MenuList& items (pan_menu->items());
404 items.push_back (CheckMenuElem (_("Mute")));
406 /* set state first, connect second */
408 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()[which]->muted());
409 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
410 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
412 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
413 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
415 /* set state first, connect second */
417 bypass_menu_item->set_active (_io->panner().bypassed());
418 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
420 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
421 items.push_back (SeparatorElem());
422 items.push_back (MenuElem (_("Reset all")));
426 PannerUI::pan_mute (uint32_t which)
428 StreamPanner* sp = _io->panner()[which];
429 sp->set_muted (!sp->muted());
433 PannerUI::pan_bypass_toggle ()
435 if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
436 _io->panner().set_bypassed (!_io->panner().bypassed());
441 PannerUI::pan_reset ()
446 PannerUI::effective_pan_display ()
448 if (_io->panner().empty()) {
452 switch (_io->n_outputs()) {
459 update_pan_bars (true);
463 //panner->move_puck (pan_value (v, right), 0.5);
469 PannerUI::pan_changed (void *src)
475 switch (_io->panner().size()) {
477 panning_link_direction_button.set_sensitive (false);
478 panning_link_button.set_sensitive (false);
481 panning_link_direction_button.set_sensitive (false);
482 panning_link_button.set_sensitive (false);
485 panning_link_direction_button.set_sensitive (true);
486 panning_link_button.set_sensitive (true);
489 uint32_t nouts = _io->n_outputs();
498 update_pan_bars (false);
502 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
508 PannerUI::pan_adjustment_changed (uint32_t which)
510 if (!in_pan_update && which < _io->panner().size()) {
513 float val = pan_adjustments[which]->get_value ();
514 _io->panner()[which]->get_position (xpos);
516 /* add a kinda-sorta detent for the middle */
518 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
519 /* this is going to be reentrant, so just
523 in_pan_update = true;
524 pan_adjustments[which]->set_value (0.5);
525 in_pan_update = false;
529 if (!Panner::equivalent (val, xpos)) {
531 _io->panner()[which]->set_position (val);
533 the panner objects have no access to the session,
534 so do this here. ick.
536 _session.set_dirty();
542 PannerUI::pan_value_changed (uint32_t which)
544 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
546 if (_io->n_outputs() > 1 && which < _io->panner().size()) {
548 float val = pan_adjustments[which]->get_value ();
550 _io->panner()[which]->get_position (xpos);
552 if (!Panner::equivalent (val, xpos)) {
553 in_pan_update = true;
554 pan_adjustments[which]->set_value (xpos);
555 in_pan_update = false;
561 PannerUI::update_pan_bars (bool only_if_aplay)
564 vector<Adjustment*>::iterator i;
566 in_pan_update = true;
568 /* this runs during automation playback, and moves the bar controllers
572 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
576 AutomationList& alist (_io->panner()[n]->automation());
578 if (!alist.automation_playback()) {
583 _io->panner()[n]->get_effective_position (xpos);
584 val = (*i)->get_value ();
586 if (!Panner::equivalent (val, xpos)) {
587 (*i)->set_value (xpos);
591 in_pan_update = false;
595 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
597 float val = adj->get_value();
600 snprintf (buf, len, X_("L"));
601 } else if (val == 1.0f) {
602 snprintf (buf, len, X_("R"));
603 } else if (Panner::equivalent (val, 0.5f)) {
604 snprintf (buf, len, X_("C"));
606 /* don't print anything */
612 PannerUI::update_pan_sensitive ()
614 bool sensitive = !(_io->panner().automation_state() & Play);
616 switch (_io->n_outputs()) {
621 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
622 (*i)->set_sensitive (sensitive);
627 panner->set_sensitive (sensitive);
634 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
636 using namespace Menu_Helpers;
638 if (ev->type == GDK_BUTTON_RELEASE) {
642 switch (ev->button) {
644 pan_astate_menu.popup (1, ev->time);
654 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
656 if (ev->type == GDK_BUTTON_RELEASE) {
660 switch (ev->button) {
662 pan_astyle_menu.popup (1, ev->time);
671 PannerUI::pan_automation_style_changed ()
673 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
677 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
680 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
686 PannerUI::pan_automation_state_changed ()
688 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
694 pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
697 pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
701 /* when creating a new session, we get to create busses (and
702 sometimes tracks) with no outputs by the time they get
706 if (_io->panner().empty()) {
710 x = (_io->panner().front()->automation().automation_state() != Off);
712 if (pan_automation_state_button.get_active() != x) {
713 ignore_toggle = true;
714 pan_automation_state_button.set_active (x);
715 ignore_toggle = false;
718 update_pan_sensitive ();
720 /* start watching automation so that things move */
722 pan_watching.disconnect();
725 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
730 PannerUI::astate_string (AutoState state)
732 return _astate_string (state, false);
736 PannerUI::short_astate_string (AutoState state)
738 return _astate_string (state, true);
742 PannerUI::_astate_string (AutoState state, bool shrt)
748 sstr = (shrt ? "M" : _("M"));
751 sstr = (shrt ? "P" : _("P"));
754 sstr = (shrt ? "T" : _("T"));
757 sstr = (shrt ? "W" : _("W"));
765 PannerUI::astyle_string (AutoStyle style)
767 return _astyle_string (style, false);
771 PannerUI::short_astyle_string (AutoStyle style)
773 return _astyle_string (style, true);
777 PannerUI::_astyle_string (AutoStyle style, bool shrt)
782 /* XXX it might different in different languages */
784 return (shrt ? _("Abs") : _("Abs"));