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/barcontroller.h>
25 #include "midi++/manager.h"
26 #include "pbd/fastlog.h"
28 #include "ardour_ui.h"
29 #include "panner_ui.h"
32 #include "gui_thread.h"
33 #include "stereo_panner.h"
34 #include "mono_panner.h"
36 #include "ardour/delivery.h"
37 #include "ardour/session.h"
38 #include "ardour/panner.h"
39 #include "ardour/route.h"
44 using namespace ARDOUR;
46 using namespace Gtkmm2ext;
49 const int PannerUI::pan_bar_height = 40;
51 PannerUI::PannerUI (Session* s)
54 , hAdjustment(0.0, 0.0, 0.0)
55 , vAdjustment(0.0, 0.0, 0.0)
56 , panning_viewport(hAdjustment, vAdjustment)
57 , panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT)
58 , panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT)
59 , panning_link_button (_("link"))
60 , pan_automation_style_button ("")
61 , pan_automation_state_button ("")
65 ignore_toggle = false;
69 in_pan_update = false;
71 _ignore_width_change = false;
72 _ignore_position_change = false;
74 pan_automation_style_button.set_name ("MixerAutomationModeButton");
75 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
77 ARDOUR_UI::instance()->set_tip (pan_automation_state_button, _("Pan automation mode"));
78 ARDOUR_UI::instance()->set_tip (pan_automation_style_button, _("Pan automation type"));
80 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
81 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
83 panning_viewport.set_name (X_("BaseFrame"));
85 ARDOUR_UI::instance()->set_tip (panning_link_button,
86 _("panning link control"));
87 ARDOUR_UI::instance()->set_tip (panning_link_direction_button,
88 _("panning link direction"));
90 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
91 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
93 pan_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
94 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
96 panning_link_button.set_name (X_("PanningLinkButton"));
97 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
99 panning_link_box.pack_start (panning_link_button, true, true);
100 panning_link_box.pack_start (panning_link_direction_button, true, true);
101 panning_link_box.pack_start (pan_automation_state_button, true, true);
103 /* the pixmap will be reset at some point, but the key thing is that
104 we need a pixmap in the button just to get started.
106 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
108 panning_link_direction_button.signal_clicked().connect
109 (sigc::mem_fun(*this, &PannerUI::panning_link_direction_clicked));
111 panning_link_button.signal_button_press_event().connect
112 (sigc::mem_fun(*this, &PannerUI::panning_link_button_press), false);
113 panning_link_button.signal_button_release_event().connect
114 (sigc::mem_fun(*this, &PannerUI::panning_link_button_release), false);
116 panning_up.set_border_width (3);
117 panning_down.set_border_width (3);
118 panning_up.add (panning_up_arrow);
119 panning_down.add (panning_down_arrow);
120 panning_up.set_name (X_("PanScrollerBase"));
121 panning_down.set_name (X_("PanScrollerBase"));
122 panning_up_arrow.set_name (X_("PanScrollerArrow"));
123 panning_down_arrow.set_name (X_("PanScrollerArrow"));
125 pan_vbox.set_spacing (2);
126 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
127 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
129 pack_start (pan_vbox, true, true);
138 PannerUI::set_panner (boost::shared_ptr<Panner> p)
140 connections.drop_connections ();
142 delete pan_astyle_menu;
145 delete pan_astate_menu;
153 delete _stereo_panner;
160 _panner->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panner_changed, this, this), gui_context());
161 _panner->LinkStateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_linkage, this), gui_context());
162 _panner->StateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_state, this), gui_context());
164 /* new panner object, force complete reset of panner GUI
171 update_pan_sensitive ();
172 update_pan_linkage ();
173 pan_automation_state_changed ();
178 PannerUI::build_astate_menu ()
180 using namespace Menu_Helpers;
182 if (pan_astate_menu == 0) {
183 pan_astate_menu = new Menu;
184 pan_astate_menu->set_name ("ArdourContextMenu");
186 pan_astate_menu->items().clear ();
189 pan_astate_menu->items().push_back (MenuElem (_("Manual"), sigc::bind (
190 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
192 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
193 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
195 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
196 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
197 (AutoState) Write)));
198 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
199 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
200 (AutoState) Touch)));
205 PannerUI::build_astyle_menu ()
207 using namespace Menu_Helpers;
209 if (pan_astyle_menu == 0) {
210 pan_astyle_menu = new Menu;
211 pan_astyle_menu->set_name ("ArdourContextMenu");
213 pan_astyle_menu->items().clear();
216 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
217 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
220 boost::shared_ptr<PBD::Controllable>
221 PannerUI::get_controllable()
223 assert (!pan_bars.empty());
224 return pan_bars[0]->get_controllable();
228 PannerUI::panning_link_button_press (GdkEventButton*)
234 PannerUI::panning_link_button_release (GdkEventButton*)
236 if (!ignore_toggle) {
237 _panner->set_linked (!_panner->linked());
243 PannerUI::panning_link_direction_clicked()
245 switch (_panner->link_direction()) {
246 case Panner::SameDirection:
247 _panner->set_link_direction (Panner::OppositeDirection);
250 _panner->set_link_direction (Panner::SameDirection);
256 PannerUI::update_pan_linkage ()
258 ENSURE_GUI_THREAD (*this, &PannerUI::update_pan_linkage)
260 bool const x = _panner->linked();
261 bool const bx = panning_link_button.get_active();
265 ignore_toggle = true;
266 panning_link_button.set_active (x);
267 ignore_toggle = false;
270 panning_link_direction_button.set_sensitive (x);
272 switch (_panner->link_direction()) {
273 case Panner::SameDirection:
274 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
277 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
283 PannerUI::on_size_allocate (Allocation& a)
285 HBox::on_size_allocate (a);
289 PannerUI::set_width (Width w)
293 panning_link_button.set_label (_("link"));
296 panning_link_button.set_label (_("L"));
304 PannerUI::~PannerUI ()
306 for (vector<MonoPanner*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
313 delete pan_astyle_menu;
314 delete pan_astate_menu;
315 delete _stereo_panner;
320 PannerUI::panner_changed (void* src)
322 ENSURE_GUI_THREAD (*this, &PannerUI::panner_changed)
330 switch (_panner->npanners()) {
332 panning_link_direction_button.set_sensitive (false);
333 panning_link_button.set_sensitive (false);
336 panning_link_direction_button.set_sensitive (false);
337 panning_link_button.set_sensitive (false);
340 panning_link_direction_button.set_sensitive (_panner->linked ());
341 panning_link_button.set_sensitive (true);
344 uint32_t const nouts = _panner->nouts();
356 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
362 PannerUI::update_pan_state ()
364 /* currently nothing to do */
365 // ENSURE_GUI_THREAD (*this, &PannerUI::update_panner_state)
369 PannerUI::setup_pan ()
375 uint32_t const nouts = _panner->nouts();
376 uint32_t const npans = _panner->npanners();
378 cerr << "Pan setup, outs == " << nouts << " pans = " << npans << endl;
380 if (int32_t (nouts) == _current_nouts && int32_t (npans) == _current_npans) {
384 _current_nouts = nouts;
385 _current_npans = npans;
387 panning_viewport.remove ();
391 delete _stereo_panner;
394 if (nouts == 0 || nouts == 1) {
396 while (!pan_bars.empty()) {
397 delete pan_bars.back();
398 pan_bars.pop_back ();
401 /* stick something into the panning viewport so that it redraws */
403 EventBox* eb = manage (new EventBox());
404 panning_viewport.add (*eb);
406 } else if (nouts == 2) {
408 vector<Adjustment*>::size_type p;
410 while (!pan_bars.empty()) {
411 delete pan_bars.back();
412 pan_bars.pop_back ();
417 /* add integrated 2in/2out panner GUI */
419 _stereo_panner = new StereoPanner (_panner->direction_control(),
420 _panner->width_control());
421 _stereo_panner->set_size_request (-1, pan_bar_height);
422 panning_viewport.add (*_stereo_panner);
426 /* N-in/2out - just use a set of single-channel panners */
428 while ((p = pan_bars.size()) < npans) {
431 boost::shared_ptr<AutomationControl> ac = _panner->pan_control (p);
433 mp = new MonoPanner (_panner->pan_control (p));
435 mp->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
436 boost::weak_ptr<AutomationControl> (ac)));
437 mp->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
438 boost::weak_ptr<AutomationControl>(ac)));
440 mp->signal_button_release_event().connect
441 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) p));
443 mp->set_size_request (-1, pan_bar_height);
445 pan_bars.push_back (mp);
446 pan_bar_packer.pack_start (*mp, false, false);
449 /* now that we actually have the pan bars,
450 set their sensitivity based on current
454 update_pan_sensitive ();
455 panning_viewport.add (pan_bar_packer);
462 twod_panner = new Panner2d (_panner, 61);
463 twod_panner->set_name ("MixerPanZone");
464 twod_panner->show ();
466 twod_panner->signal_button_press_event().connect
467 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) 0), false);
470 update_pan_sensitive ();
471 twod_panner->reset (npans);
473 big_window->reset (npans);
475 twod_panner->set_size_request (-1, 61);
477 /* and finally, add it to the panner frame */
479 panning_viewport.add (*twod_panner);
482 panning_viewport.show_all ();
486 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
488 boost::shared_ptr<AutomationControl> ac = wac.lock();
492 ac->start_touch (ac->session().transport_frame());
496 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
498 boost::shared_ptr<AutomationControl> ac = wac.lock();
502 ac->stop_touch (false, ac->session().transport_frame());
506 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
508 switch (ev->button) {
510 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
512 big_window = new Panner2dWindow (_panner, 400, _panner->npanners());
521 pan_menu = manage (new Menu);
522 pan_menu->set_name ("ArdourContextMenu");
524 build_pan_menu (which);
525 pan_menu->popup (1, ev->time);
532 return false; // what's wrong with gcc?
536 PannerUI::build_pan_menu (uint32_t which)
538 using namespace Menu_Helpers;
539 MenuList& items (pan_menu->items());
543 items.push_back (CheckMenuElem (_("Mute")));
545 /* set state first, connect second */
547 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_panner->streampanner(which).muted());
548 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
549 (sigc::bind (sigc::mem_fun(*this, &PannerUI::pan_mute), which));
551 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
552 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
554 /* set state first, connect second */
556 bypass_menu_item->set_active (_panner->bypassed());
557 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
559 items.push_back (MenuElem (_("Reset"), sigc::bind (sigc::mem_fun (*this, &PannerUI::pan_reset), which)));
560 items.push_back (SeparatorElem());
561 items.push_back (MenuElem (_("Reset all"), sigc::mem_fun (*this, &PannerUI::pan_reset_all)));
565 PannerUI::pan_mute (uint32_t which)
567 StreamPanner& sp = _panner->streampanner(which);
568 sp.set_muted (!sp.muted());
572 PannerUI::pan_bypass_toggle ()
574 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
575 _panner->set_bypassed (!_panner->bypassed());
580 PannerUI::pan_reset (uint32_t which)
582 _panner->reset_streampanner (which);
586 PannerUI::pan_reset_all ()
588 _panner->reset_to_default ();
592 PannerUI::effective_pan_display ()
594 if (_stereo_panner) {
595 _stereo_panner->queue_draw ();
596 } else if (twod_panner) {
597 twod_panner->queue_draw ();
599 for (vector<MonoPanner*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
606 PannerUI::update_pan_sensitive ()
608 bool const sensitive = !(_panner->mono()) && !(_panner->automation_state() & Play);
610 switch (_panner->nouts()) {
615 for (vector<MonoPanner*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
616 (*i)->set_sensitive (sensitive);
621 twod_panner->set_sensitive (sensitive);
624 big_window->set_sensitive (sensitive);
631 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
633 using namespace Menu_Helpers;
635 if (ev->type == GDK_BUTTON_RELEASE) {
639 switch (ev->button) {
641 if (pan_astate_menu == 0) {
642 build_astate_menu ();
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 if (pan_astyle_menu == 0) {
663 build_astyle_menu ();
665 pan_astyle_menu->popup (1, ev->time);
674 PannerUI::pan_automation_style_changed ()
676 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
680 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
683 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
689 PannerUI::pan_automation_state_changed ()
691 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_state_changed)
697 pan_automation_state_button.set_label (astate_string(_panner->automation_state()));
700 pan_automation_state_button.set_label (short_astate_string(_panner->automation_state()));
704 /* when creating a new session, we get to create busses (and
705 sometimes tracks) with no outputs by the time they get
709 if (_panner->empty()) {
713 x = (_panner->streampanner(0).pan_control()->alist()->automation_state() != Off);
715 if (pan_automation_state_button.get_active() != x) {
716 ignore_toggle = true;
717 pan_automation_state_button.set_active (x);
718 ignore_toggle = false;
721 update_pan_sensitive ();
723 /* start watching automation so that things move */
725 pan_watching.disconnect();
728 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
733 PannerUI::astate_string (AutoState state)
735 return _astate_string (state, false);
739 PannerUI::short_astate_string (AutoState state)
741 return _astate_string (state, true);
745 PannerUI::_astate_string (AutoState state, bool shrt)
751 sstr = (shrt ? "M" : _("M"));
754 sstr = (shrt ? "P" : _("P"));
757 sstr = (shrt ? "T" : _("T"));
760 sstr = (shrt ? "W" : _("W"));
768 PannerUI::astyle_string (AutoStyle style)
770 return _astyle_string (style, false);
774 PannerUI::short_astyle_string (AutoStyle style)
776 return _astyle_string (style, true);
780 PannerUI::_astyle_string (AutoStyle style, bool shrt)
785 /* XXX it might different in different languages */
787 return (shrt ? _("Abs") : _("Abs"));
792 PannerUI::set_mono (bool yn)
794 _panner->set_mono (yn);
795 update_pan_sensitive ();
799 PannerUI::show_width ()
804 PannerUI::width_adjusted ()
809 PannerUI::show_position ()
814 PannerUI::position_adjusted ()