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"
28 #include "pbd/stacktrace.h"
30 #include "ardour_ui.h"
31 #include "panner_ui.h"
35 #include "gui_thread.h"
37 #include "ardour/delivery.h"
38 #include "ardour/session.h"
39 #include "ardour/panner.h"
40 #include "ardour/route.h"
45 using namespace ARDOUR;
47 using namespace Gtkmm2ext;
51 const int PannerUI::pan_bar_height = 30;
53 PannerUI::PannerUI (Session& s)
55 hAdjustment(0.0, 0.0, 0.0),
56 vAdjustment(0.0, 0.0, 0.0),
57 panning_viewport(hAdjustment, vAdjustment),
58 panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
59 panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
60 panning_link_button (_("link")),
61 pan_automation_style_button (""),
62 pan_automation_state_button ("")
64 ignore_toggle = false;
68 in_pan_update = false;
70 pan_automation_style_button.set_name ("MixerAutomationModeButton");
71 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
73 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
74 ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
76 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
77 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
79 pan_bar_packer.set_size_request (-1, 61);
80 panning_viewport.set_size_request (-1, 61);
81 panning_viewport.set_name (X_("BaseFrame"));
83 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
84 _("panning link control"));
85 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
86 _("panning link direction"));
88 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
89 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
91 pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
92 pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
94 panning_link_button.set_name (X_("PanningLinkButton"));
95 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
97 panning_link_box.pack_start (panning_link_button, true, true);
98 panning_link_box.pack_start (panning_link_direction_button, true, true);
99 panning_link_box.pack_start (pan_automation_state_button, true, true);
101 /* the pixmap will be reset at some point, but the key thing is that
102 we need a pixmap in the button just to get started.
104 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
106 panning_link_direction_button.signal_clicked().connect
107 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
109 panning_link_button.signal_button_press_event().connect
110 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
111 panning_link_button.signal_button_release_event().connect
112 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
114 panning_up.set_border_width (3);
115 panning_down.set_border_width (3);
116 panning_up.add (panning_up_arrow);
117 panning_down.add (panning_down_arrow);
118 panning_up.set_name (X_("PanScrollerBase"));
119 panning_down.set_name (X_("PanScrollerBase"));
120 panning_up_arrow.set_name (X_("PanScrollerArrow"));
121 panning_down_arrow.set_name (X_("PanScrollerArrow"));
123 pan_vbox.set_spacing (2);
124 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
125 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
127 pack_start (pan_vbox, true, true);
136 PannerUI::set_panner (boost::shared_ptr<Panner> p)
138 connections.clear ();
140 delete pan_astyle_menu;
143 delete pan_astate_menu;
155 connections.push_back (_panner->Changed.connect (mem_fun(*this, &PannerUI::panner_changed)));
156 connections.push_back (_panner->LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage)));
157 connections.push_back (_panner->StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state)));
162 update_pan_sensitive ();
163 update_pan_linkage ();
164 pan_automation_state_changed ();
166 #if WHERE_DOES_THIS_LIVE
167 pan_bar_packer.show();
168 panning_viewport.show();
170 panning_up_arrow.show();
172 panning_down_arrow.show();
174 panning_link_button.show();
175 panning_link_direction_button.show();
176 panning_link_box.show();
177 pan_automation_style_button.show();
178 pan_automation_state_button.show();
184 PannerUI::build_astate_menu ()
186 using namespace Menu_Helpers;
188 if (pan_astate_menu == 0) {
189 pan_astate_menu = new Menu;
190 pan_astate_menu->set_name ("ArdourContextMenu");
192 pan_astate_menu->items().clear ();
195 pan_astate_menu->items().push_back (MenuElem (_("Manual"), bind (
196 mem_fun (_panner.get(), &Panner::set_automation_state),
198 pan_astate_menu->items().push_back (MenuElem (_("Play"), bind (
199 mem_fun (_panner.get(), &Panner::set_automation_state),
201 pan_astate_menu->items().push_back (MenuElem (_("Write"), bind (
202 mem_fun (_panner.get(), &Panner::set_automation_state),
203 (AutoState) Write)));
204 pan_astate_menu->items().push_back (MenuElem (_("Touch"), bind (
205 mem_fun (_panner.get(), &Panner::set_automation_state),
206 (AutoState) Touch)));
211 PannerUI::build_astyle_menu ()
213 using namespace Menu_Helpers;
215 if (pan_astyle_menu == 0) {
216 pan_astyle_menu = new Menu;
217 pan_astyle_menu->set_name ("ArdourContextMenu");
219 pan_astyle_menu->items().clear();
222 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
223 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
226 boost::shared_ptr<PBD::Controllable>
227 PannerUI::get_controllable()
229 return pan_bars[0]->get_controllable();
233 PannerUI::panning_link_button_press (GdkEventButton* ev)
239 PannerUI::panning_link_button_release (GdkEventButton* ev)
241 if (!ignore_toggle) {
242 _panner->set_linked (!_panner->linked());
248 PannerUI::panning_link_direction_clicked()
250 switch (_panner->link_direction()) {
251 case Panner::SameDirection:
252 _panner->set_link_direction (Panner::OppositeDirection);
255 _panner->set_link_direction (Panner::SameDirection);
261 PannerUI::update_pan_linkage ()
263 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
265 bool x = _panner->linked();
266 bool bx = panning_link_button.get_active();
270 ignore_toggle = true;
271 panning_link_button.set_active (x);
272 ignore_toggle = false;
275 panning_link_direction_button.set_sensitive (x);
277 switch (_panner->link_direction()) {
278 case Panner::SameDirection:
279 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
282 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
288 PannerUI::set_width (Width w)
292 panning_link_button.set_label (_("link"));
295 panning_link_button.set_label (_("L"));
303 PannerUI::~PannerUI ()
305 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
309 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
316 delete pan_astyle_menu;
317 delete pan_astate_menu;
322 PannerUI::panner_changed ()
324 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
330 PannerUI::update_pan_state ()
332 /* currently nothing to do */
333 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
337 PannerUI::setup_pan ()
339 cerr << "Setup pan for " << _panner->name() << endl;
340 // PBD::stacktrace (cerr, 5);
346 uint32_t nouts = _panner->nouts();
348 cerr << "\tnouts = " << nouts << endl;
350 if (nouts == 0 || nouts == 1) {
352 while (!pan_adjustments.empty()) {
353 delete pan_bars.back();
354 pan_bars.pop_back ();
355 delete pan_adjustments.back();
356 pan_adjustments.pop_back ();
359 /* stick something into the panning viewport so that it redraws */
361 EventBox* eb = manage (new EventBox());
362 panning_viewport.remove ();
363 panning_viewport.add (*eb);
364 panning_viewport.show_all ();
366 } else if (nouts == 2) {
368 vector<Adjustment*>::size_type asz;
369 uint32_t npans = _panner->npanners();
371 while (!pan_adjustments.empty()) {
372 delete pan_bars.back();
373 pan_bars.pop_back ();
374 delete pan_adjustments.back();
375 pan_adjustments.pop_back ();
378 while ((asz = pan_adjustments.size()) < npans) {
383 /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
384 which serves as a default, otherwise use current value */
386 rx = _panner->pan_control( asz)->get_value();
390 } else if (asz == 0) {
392 } else if (asz == 1) {
398 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.005, 0.05));
399 bc = new PannerBar (*pan_adjustments[asz],
400 boost::static_pointer_cast<PBD::Controllable>( _panner->pan_control( asz )) );
402 /* now set adjustment with current value of panner, then connect the signals */
403 pan_adjustments.back()->set_value(rx);
404 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
406 _panner->pan_control( asz )->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
409 bc->set_name ("PanSlider");
410 bc->set_shadow_type (Gtk::SHADOW_NONE);
412 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (asz);
415 bc->StartGesture.connect (mem_fun (*ac, &AutomationControl::start_touch));
416 bc->StopGesture.connect (mem_fun (*ac, &AutomationControl::stop_touch));
420 snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
421 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
423 bc->event_widget().signal_button_release_event().connect
424 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
426 bc->set_size_request (-1, pan_bar_height);
428 pan_bars.push_back (bc);
429 pan_bar_packer.pack_start (*bc, false, false);
432 /* now that we actually have the pan bars,
433 set their sensitivity based on current
437 update_pan_sensitive ();
439 panning_viewport.remove ();
440 panning_viewport.add (pan_bar_packer);
441 panning_viewport.show_all ();
446 panner = new Panner2d (_panner, 61);
447 panner->set_name ("MixerPanZone");
450 panner->signal_button_press_event().connect
451 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
454 update_pan_sensitive ();
455 panner->reset (nouts);
457 big_window->reset (_panner->npanners());
459 panner->set_size_request (-1, 61);
461 /* and finally, add it to the panner frame */
463 panning_viewport.remove ();
464 panning_viewport.add (*panner);
465 panning_viewport.show_all ();
470 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
472 switch (ev->button) {
474 if (panner && ev->type == GDK_2BUTTON_PRESS) {
476 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
485 pan_menu = manage (new Menu);
486 pan_menu->set_name ("ArdourContextMenu");
488 build_pan_menu (which);
489 pan_menu->popup (1, ev->time);
496 return false; // what's wrong with gcc?
500 PannerUI::build_pan_menu (uint32_t which)
502 using namespace Menu_Helpers;
503 MenuList& items (pan_menu->items());
507 items.push_back (CheckMenuElem (_("Mute")));
509 /* set state first, connect second */
511 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
512 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
513 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
515 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
516 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
518 /* set state first, connect second */
520 bypass_menu_item->set_active (_panner->bypassed());
521 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
523 items.push_back (MenuElem (_("Reset"), bind (mem_fun (*this, &PannerUI::pan_reset), which)));
524 items.push_back (SeparatorElem());
525 items.push_back (MenuElem (_("Reset all"), mem_fun (*this, &PannerUI::pan_reset_all)));
529 PannerUI::pan_mute (uint32_t which)
531 StreamPanner& sp = _panner->streampanner(which);
532 sp.set_muted (!sp.muted());
536 PannerUI::pan_bypass_toggle ()
538 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
539 _panner->set_bypassed (!_panner->bypassed());
544 PannerUI::pan_reset (uint32_t which)
546 _panner->reset_streampanner (which);
550 PannerUI::pan_reset_all ()
552 _panner->reset_to_default ();
556 PannerUI::effective_pan_display ()
558 if (_panner->empty()) {
562 switch (_panner->nouts()) {
569 update_pan_bars (true);
573 //panner->move_puck (pan_value (v, right), 0.5);
579 PannerUI::pan_changed (void *src)
585 switch (_panner->npanners()) {
587 panning_link_direction_button.set_sensitive (false);
588 panning_link_button.set_sensitive (false);
591 panning_link_direction_button.set_sensitive (false);
592 panning_link_button.set_sensitive (false);
595 panning_link_direction_button.set_sensitive (true);
596 panning_link_button.set_sensitive (true);
599 uint32_t nouts = _panner->nouts();
608 /* bring pan bar state up to date */
609 update_pan_bars (false);
613 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
619 PannerUI::pan_adjustment_changed (uint32_t which)
621 if (!in_pan_update && which < _panner->npanners()) {
624 float val = pan_adjustments[which]->get_value ();
625 xpos = _panner->pan_control( which )->get_value();
627 /* add a kinda-sorta detent for the middle */
629 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
630 /* this is going to be reentrant, so just
634 in_pan_update = true;
635 pan_adjustments[which]->set_value (0.5);
636 in_pan_update = false;
640 if (!Panner::equivalent (val, xpos)) {
642 _panner->streampanner(which).set_position (val);
644 the panner objects have no access to the session,
645 so do this here. ick.
647 _session.set_dirty();
653 PannerUI::pan_value_changed (uint32_t which)
655 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
657 if (_panner->npanners() > 1 && which < _panner->npanners()) {
659 float val = pan_adjustments[which]->get_value ();
661 _panner->streampanner(which).get_position (xpos);
663 if (!Panner::equivalent (val, xpos)) {
664 in_pan_update = true;
665 pan_adjustments[which]->set_value (xpos);
666 in_pan_update = false;
672 PannerUI::update_pan_bars (bool only_if_aplay)
675 vector<Adjustment*>::iterator i;
677 in_pan_update = true;
679 /* this runs during automation playback, and moves the bar controllers
683 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
687 boost::shared_ptr<AutomationList> alist (_panner->streampanner(n).pan_control()->alist());
689 if (!alist->automation_playback()) {
694 _panner->streampanner(n).get_effective_position (xpos);
695 val = (*i)->get_value ();
697 if (!Panner::equivalent (val, xpos)) {
698 (*i)->set_value (xpos);
702 in_pan_update = false;
706 PannerUI::update_pan_sensitive ()
708 bool sensitive = !(_panner->automation_state() & Play);
710 switch (_panner->nouts()) {
715 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
716 (*i)->set_sensitive (sensitive);
721 panner->set_sensitive (sensitive);
724 big_window->set_sensitive (sensitive);
731 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
733 using namespace Menu_Helpers;
735 if (ev->type == GDK_BUTTON_RELEASE) {
739 switch (ev->button) {
741 if (pan_astate_menu == 0) {
742 build_astate_menu ();
744 pan_astate_menu->popup (1, ev->time);
754 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
756 if (ev->type == GDK_BUTTON_RELEASE) {
760 switch (ev->button) {
762 if (pan_astyle_menu == 0) {
763 build_astyle_menu ();
765 pan_astyle_menu->popup (1, ev->time);
774 PannerUI::pan_automation_style_changed ()
776 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
780 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
783 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
789 PannerUI::pan_automation_state_changed ()
791 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
797 pan_automation_state_button.set_label (astate_string(_panner->automation_state()));
800 pan_automation_state_button.set_label (short_astate_string(_panner->automation_state()));
804 /* when creating a new session, we get to create busses (and
805 sometimes tracks) with no outputs by the time they get
809 if (_panner->empty()) {
813 x = (_panner->streampanner(0).pan_control()->alist()->automation_state() != Off);
815 if (pan_automation_state_button.get_active() != x) {
816 ignore_toggle = true;
817 pan_automation_state_button.set_active (x);
818 ignore_toggle = false;
821 update_pan_sensitive ();
823 /* start watching automation so that things move */
825 pan_watching.disconnect();
828 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
833 PannerUI::astate_string (AutoState state)
835 return _astate_string (state, false);
839 PannerUI::short_astate_string (AutoState state)
841 return _astate_string (state, true);
845 PannerUI::_astate_string (AutoState state, bool shrt)
851 sstr = (shrt ? "M" : _("M"));
854 sstr = (shrt ? "P" : _("P"));
857 sstr = (shrt ? "T" : _("T"));
860 sstr = (shrt ? "W" : _("W"));
868 PannerUI::astyle_string (AutoStyle style)
870 return _astyle_string (style, false);
874 PannerUI::short_astyle_string (AutoStyle style)
876 return _astyle_string (style, true);
880 PannerUI::_astyle_string (AutoStyle style, bool shrt)
885 /* XXX it might different in different languages */
887 return (shrt ? _("Abs") : _("Abs"));