add JAG to author list
[ardour.git] / gtk2_ardour / panner_ui.cc
1 /*
2   Copyright (C) 2004 Paul Davis
3
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.
8
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.
13
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.
17 */
18
19 #include <limits.h>
20
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
29 #include "ardour_ui.h"
30 #include "panner_ui.h"
31 #include "panner2d.h"
32 #include "utils.h"
33 #include "panner.h"
34 #include "gui_thread.h"
35
36 #include <ardour/session.h>
37 #include <ardour/panner.h>
38 #include <ardour/route.h>
39
40 #include "i18n.h"
41
42 using namespace ARDOUR;
43 using namespace PBD;
44 using namespace Gtkmm2ext;
45 using namespace Gtk;
46 using namespace sigc;
47
48 const int PannerUI::pan_bar_height = 30;
49
50 PannerUI::PannerUI (Session& s)
51         : _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 ("")
60 {
61         ignore_toggle = false;
62         pan_menu = 0;
63         pan_astate_menu = 0;
64         pan_astyle_menu = 0;
65         in_pan_update = false;
66
67         pan_automation_style_button.set_name ("MixerAutomationModeButton");
68         pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
69
70         ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_state_button, _("Pan automation mode"));
71         ARDOUR_UI::instance()->tooltips().set_tip (pan_automation_style_button, _("Pan automation type"));
72
73         //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
74         //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
75
76         pan_bar_packer.set_size_request (-1, 61);
77         panning_viewport.set_size_request (-1, 61);
78         panning_viewport.set_name (X_("BaseFrame"));
79
80         ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
81                                                    _("panning link control"));
82         ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
83                                                    _("panning link direction"));
84
85         pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
86         pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
87
88         pan_automation_style_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
89         pan_automation_state_button.signal_button_press_event().connect (mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
90
91         panning_link_button.set_name (X_("PanningLinkButton"));
92         panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
93
94         panning_link_box.pack_start (panning_link_button, true, true);
95         panning_link_box.pack_start (panning_link_direction_button, true, true);
96         panning_link_box.pack_start (pan_automation_state_button, true, true);
97
98         /* the pixmap will be reset at some point, but the key thing is that
99            we need a pixmap in the button just to get started.
100         */
101         panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
102
103         panning_link_direction_button.signal_clicked().connect
104                 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
105
106         panning_link_button.signal_button_press_event().connect
107                 (mem_fun(*this, &PannerUI::panning_link_button_press), false);
108         panning_link_button.signal_button_release_event().connect
109                 (mem_fun(*this, &PannerUI::panning_link_button_release), false);
110
111         panning_up.set_border_width (3);
112         panning_down.set_border_width (3);
113         panning_up.add (panning_up_arrow);
114         panning_down.add (panning_down_arrow);
115         panning_up.set_name (X_("PanScrollerBase"));
116         panning_down.set_name (X_("PanScrollerBase"));
117         panning_up_arrow.set_name (X_("PanScrollerArrow"));
118         panning_down_arrow.set_name (X_("PanScrollerArrow"));
119
120         pan_vbox.set_spacing (2);
121         pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
122         pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
123
124         pack_start (pan_vbox, true, true);
125
126         panner = 0;
127
128         set_width(Narrow);
129 }
130
131 void
132 PannerUI::set_io (boost::shared_ptr<IO> io)
133 {
134         connections.clear ();
135
136         if (pan_astyle_menu) {
137                 delete pan_astyle_menu;
138                 pan_astyle_menu = 0;
139         }
140
141         if (pan_astate_menu) {
142                 delete pan_astate_menu;
143                 pan_astate_menu = 0;
144         }
145                         
146         _io = io;
147
148         connections.push_back (_io->panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed)));
149         connections.push_back (_io->panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage)));
150         connections.push_back (_io->panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state)));
151
152         if (panner) {
153                 delete panner;
154                 panner = 0;
155         }
156         
157         setup_pan ();
158
159         pan_changed (0);
160         update_pan_sensitive ();
161         update_pan_linkage ();
162         pan_automation_state_changed ();
163 }
164
165 void
166 PannerUI::build_astate_menu ()
167 {
168         using namespace Menu_Helpers;
169
170         if (pan_astate_menu == 0) {
171                 pan_astate_menu = new Menu;
172                 pan_astate_menu->set_name ("ArdourContextMenu");
173         } else {
174                 pan_astate_menu->items().clear ();
175         }
176
177         pan_astate_menu->items().push_back (MenuElem (_("Manual"), 
178                                                      bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Off)));
179         pan_astate_menu->items().push_back (MenuElem (_("Play"),
180                                                      bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Play)));
181         pan_astate_menu->items().push_back (MenuElem (_("Write"),
182                                                      bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Write)));
183         pan_astate_menu->items().push_back (MenuElem (_("Touch"),
184                                                      bind (mem_fun (_io->panner(), &Panner::set_automation_state), (AutoState) Touch)));
185
186 }
187
188 void
189 PannerUI::build_astyle_menu ()
190 {
191         using namespace Menu_Helpers;
192
193         if (pan_astyle_menu == 0) {
194                 pan_astyle_menu = new Menu;
195                 pan_astyle_menu->set_name ("ArdourContextMenu");
196         } else {
197                 pan_astyle_menu->items().clear();
198         }
199
200         pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
201         pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
202 }
203
204 PBD::Controllable* 
205 PannerUI::get_controllable() 
206
207         if (pan_bars.empty()) {
208                 return 0;
209         }
210
211         return pan_bars[0]->get_controllable();
212 }
213
214 bool
215 PannerUI::panning_link_button_press (GdkEventButton* ev)
216 {
217         return true;
218 }
219
220 bool
221 PannerUI::panning_link_button_release (GdkEventButton* ev)
222 {
223         if (!ignore_toggle) {
224                 _io->panner().set_linked (!_io->panner().linked());
225         }
226         return true;
227 }
228
229 void
230 PannerUI::panning_link_direction_clicked()
231 {
232         switch (_io->panner().link_direction()) {
233         case Panner::SameDirection:
234                 _io->panner().set_link_direction (Panner::OppositeDirection);
235                 break;
236         default:
237                 _io->panner().set_link_direction (Panner::SameDirection);
238                 break;
239         }
240 }
241
242 void
243 PannerUI::update_pan_linkage ()
244 {
245         ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
246         
247         bool x = _io->panner().linked();
248         bool bx = panning_link_button.get_active();
249
250         if (x != bx) {
251                 
252                 ignore_toggle = true;
253                 panning_link_button.set_active (x);
254                 ignore_toggle = false;
255         }
256
257         panning_link_direction_button.set_sensitive (x);
258
259         switch (_io->panner().link_direction()) {
260         case Panner::SameDirection:
261                 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
262                 break;
263         default:
264                 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
265                 break;
266         }
267 }
268
269 void
270 PannerUI::set_width (Width w)
271 {
272         switch (w) {
273         case Wide:
274                 panning_link_button.set_label (_("link"));
275                 break;
276         case Narrow:
277                 panning_link_button.set_label (_("L"));
278                 break;
279         }
280
281         _width = w;
282 }
283
284
285 PannerUI::~PannerUI ()
286 {
287         for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
288                 delete (*i);
289         }
290         
291         for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
292                 delete (*i);
293         }
294
295         if (panner) {
296                 delete panner;
297         }
298
299         if (pan_menu) {
300                 delete pan_menu;
301         }
302         
303         if (pan_astyle_menu) {
304                 delete pan_astyle_menu;
305         }
306         
307         if (pan_astate_menu) {
308                 delete pan_astate_menu;
309         }
310 }
311
312
313 void
314 PannerUI::panner_changed ()
315 {
316         ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
317         setup_pan ();
318         pan_changed (0);
319 }
320
321 void
322 PannerUI::update_pan_state ()
323 {
324         /* currently nothing to do */
325         // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
326 }
327
328 void
329 PannerUI::setup_pan ()
330 {
331         uint32_t nouts = _io->n_outputs ();
332
333         if (nouts == 0 || nouts == 1) {
334
335                 while (!pan_adjustments.empty()) {
336                         delete pan_bars.back();
337                         pan_bars.pop_back ();
338                         delete pan_adjustments.back();
339                         pan_adjustments.pop_back ();
340                 }
341
342                 /* stick something into the panning viewport so that it redraws */
343
344                 EventBox* eb = manage (new EventBox());
345                 panning_viewport.remove ();
346                 panning_viewport.add (*eb);
347                 panning_viewport.show_all ();
348
349         } else if (nouts == 2) {
350
351                 vector<Adjustment*>::size_type asz;
352                 uint32_t npans = _io->panner().size();
353
354                 while (!pan_adjustments.empty()) {
355                         delete pan_bars.back();
356                         pan_bars.pop_back ();
357                         delete pan_adjustments.back();
358                         pan_adjustments.pop_back ();
359                 }
360
361                 while ((asz = pan_adjustments.size()) < npans) {
362
363                         float x, rx;
364                         PannerBar* bc;
365
366                         /* initialize adjustment with 0.0 (L) or 1.0 (R) for the first and second panners,
367                            which serves as a default, otherwise use current value */
368
369                         _io->panner()[asz]->get_position (rx);
370
371                         if (npans == 1) {
372                                 x = 0.5;
373                         } else if (asz == 0) {
374                                 x = 0.0;
375                         } else if (asz == 1) {
376                                 x = 1.0;
377                         } else {
378                                 x = rx;
379                         }
380
381                         pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
382                         bc = new PannerBar (*pan_adjustments[asz], _io->panner()[asz]->control());
383
384                         /* now set adjustment with current value of panner, then connect the signals */
385                         pan_adjustments.back()->set_value(rx);
386                         pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
387
388                         _io->panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
389
390                         
391                         bc->set_name ("PanSlider");
392                         bc->set_shadow_type (Gtk::SHADOW_NONE);
393
394                         bc->StartGesture.connect (bind (mem_fun (*_io, &IO::start_pan_touch), (uint32_t) asz));
395                         bc->StopGesture.connect (bind (mem_fun (*_io, &IO::end_pan_touch), (uint32_t) asz));
396
397                         char buf[64];
398                         snprintf (buf, sizeof (buf), _("panner for channel %zu"), asz + 1);
399                         ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
400
401                         bc->event_widget().signal_button_release_event().connect
402                                 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
403
404                         bc->set_size_request (-1, pan_bar_height);
405
406                         pan_bars.push_back (bc);
407                         pan_bar_packer.pack_start (*bc, false, false);
408                 }
409
410                 /* now that we actually have the pan bars,
411                    set their sensitivity based on current
412                    automation state.
413                 */
414
415                 update_pan_sensitive ();
416
417                 panning_viewport.remove ();
418                 panning_viewport.add (pan_bar_packer);
419                 panning_viewport.show_all ();
420
421         } else {
422
423                 if (panner == 0) {
424                         panner = new Panner2d (_io->panner(), 61);
425                         panner->set_name ("MixerPanZone");
426                         panner->show ();
427                 }
428                 
429                 update_pan_sensitive ();
430                 panner->reset (_io->n_inputs());
431                 panner->set_size_request (-1, 61);
432
433                 /* and finally, add it to the panner frame */
434
435                 panning_viewport.remove ();
436                 panning_viewport.add (*panner);
437                 panning_viewport.show_all ();
438         }
439 }
440
441 bool
442 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
443 {
444         switch (ev->button) {
445         case 3:
446                 if (pan_menu == 0) {
447                         pan_menu = manage (new Menu);
448                         pan_menu->set_name ("ArdourContextMenu");
449                 }
450                 build_pan_menu (which);
451                 pan_menu->popup (1, ev->time);
452                 return true;
453                 break;
454         default:
455                 return false;
456         }
457
458         return false; // what's wrong with gcc?
459 }
460
461 void
462 PannerUI::build_pan_menu (uint32_t which)
463 {
464         using namespace Menu_Helpers;
465         MenuList& items (pan_menu->items());
466
467         items.clear ();
468
469         items.push_back (CheckMenuElem (_("Mute")));
470         
471         /* set state first, connect second */
472
473         (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io->panner()[which]->muted());
474         (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
475                 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
476
477         items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
478         bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
479
480         /* set state first, connect second */
481
482         bypass_menu_item->set_active (_io->panner().bypassed());
483         bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
484
485         items.push_back (MenuElem (_("Reset"), bind (mem_fun(*this, &PannerUI::pan_reset), which)));
486         items.push_back (SeparatorElem());
487         items.push_back (MenuElem (_("Reset all"), mem_fun (*this, &PannerUI::pan_reset_all)));
488 }
489
490 void
491 PannerUI::pan_mute (uint32_t which)
492 {
493         StreamPanner* sp = _io->panner()[which];
494         sp->set_muted (!sp->muted());
495 }
496
497 void
498 PannerUI::pan_bypass_toggle ()
499 {
500         if (bypass_menu_item && (_io->panner().bypassed() != bypass_menu_item->get_active())) {
501                 _io->panner().set_bypassed (!_io->panner().bypassed());
502         }
503 }
504
505 void
506 PannerUI::pan_reset (uint32_t which)
507 {
508         _io->panner().reset_streampanner (which);
509 }
510
511 void
512 PannerUI::pan_reset_all ()
513 {
514         _io->panner().reset_to_default ();
515 }
516
517 void
518 PannerUI::effective_pan_display ()
519 {
520         if (_io->panner().empty()) {
521                 return;
522         }
523
524         switch (_io->n_outputs()) {
525         case 0: 
526         case 1:
527                 /* relax */
528                 break;
529
530         case 2:
531                 update_pan_bars (true);
532                 break;
533
534         default:
535                 //panner->move_puck (pan_value (v, right), 0.5);
536                 break;
537         }
538 }
539
540 void
541 PannerUI::pan_changed (void *src)
542 {
543         if (src == this) {
544                 return;
545         }
546
547         switch (_io->panner().size()) {
548         case 0:
549                 panning_link_direction_button.set_sensitive (false);
550                 panning_link_button.set_sensitive (false);
551                 return;
552         case 1:
553                 panning_link_direction_button.set_sensitive (false);
554                 panning_link_button.set_sensitive (false);
555                 break;
556         default:
557                 panning_link_direction_button.set_sensitive (true);
558                 panning_link_button.set_sensitive (true);
559         }
560
561         uint32_t nouts = _io->n_outputs();
562
563         switch (nouts) {
564         case 0:
565         case 1:
566                 /* relax */
567                 break;
568
569         case 2:
570                 /* bring pan bar state up to date */
571                 update_pan_bars (false);
572                 break;
573
574         default:
575                 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
576                 break;
577         }
578 }
579
580 void
581 PannerUI::pan_adjustment_changed (uint32_t which)
582 {
583         if (!in_pan_update && which < _io->panner().size()) {
584
585                 float xpos;
586                 float val = pan_adjustments[which]->get_value ();
587                 _io->panner()[which]->get_position (xpos);
588
589                 /* add a kinda-sorta detent for the middle */
590                 
591                 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
592                         /* this is going to be reentrant, so just 
593                            return after it.
594                         */
595
596                         in_pan_update = true;
597                         pan_adjustments[which]->set_value (0.5);
598                         in_pan_update = false;
599                         return;
600                 }
601                 
602                 if (!Panner::equivalent (val, xpos)) {
603
604                         _io->panner()[which]->set_position (val);
605                         /* XXX 
606                            the panner objects have no access to the session,
607                            so do this here. ick.
608                         */
609                         _session.set_dirty();
610                 }
611         }
612 }
613
614 void
615 PannerUI::pan_value_changed (uint32_t which)
616 {
617         ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
618                                                            
619         if (_io->n_outputs() > 1 && which < _io->panner().size()) {
620                 float xpos;
621                 float val = pan_adjustments[which]->get_value ();
622
623                 _io->panner()[which]->get_position (xpos);
624
625                 if (!Panner::equivalent (val, xpos)) {
626                         in_pan_update = true;
627                         pan_adjustments[which]->set_value (xpos);
628                         in_pan_update = false;
629                 }
630         }
631 }       
632
633 void
634 PannerUI::update_pan_bars (bool only_if_aplay)
635 {
636         uint32_t n;
637         vector<Adjustment*>::iterator i;
638
639         in_pan_update = true;
640
641         /* this runs during automation playback, and moves the bar controllers
642            and/or pucks around.
643         */
644
645         for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
646                 float xpos, val;
647
648                 if (only_if_aplay) {
649                         AutomationList& alist (_io->panner()[n]->automation());
650                         
651                         if (!alist.automation_playback()) {
652                                 continue;
653                         }
654                 }
655
656                 _io->panner()[n]->get_effective_position (xpos);
657                 val = (*i)->get_value ();
658                 
659                 if (!Panner::equivalent (val, xpos)) {
660                         (*i)->set_value (xpos);
661                 }
662         }
663
664         in_pan_update = false;
665 }
666
667 void
668 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
669 {
670         float val = adj->get_value();
671
672         if (val == 0.0f) {
673                 snprintf (buf, len, X_("L"));
674         } else if (val == 1.0f) {
675                 snprintf (buf, len, X_("R"));
676         } else if (Panner::equivalent (val, 0.5f)) {
677                 snprintf (buf, len, X_("C"));
678         } else {
679                 /* don't print anything */
680                 buf[0] = '\0';
681         }
682 }
683
684 void
685 PannerUI::update_pan_sensitive ()
686 {
687         bool sensitive = !(_io->panner().automation_state() & Play);
688
689         switch (_io->n_outputs()) {
690         case 0:
691         case 1:
692                 break;
693         case 2:
694                 for (vector<PannerBar*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
695                         (*i)->set_sensitive (sensitive);
696                 }
697                 break;
698         default:
699                 if (panner) {
700                         panner->set_sensitive (sensitive);
701                 }
702                 break;
703         }
704 }
705
706 gint
707 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
708 {
709         using namespace Menu_Helpers;
710
711         if (ev->type == GDK_BUTTON_RELEASE) {
712                 return TRUE;
713         }
714
715         switch (ev->button) {
716         case 1:
717                 if (pan_astate_menu == 0) {
718                         build_astate_menu ();
719                 }
720                 pan_astate_menu->popup (1, ev->time);
721                 break;
722         default:
723                 break;
724         }
725
726         return TRUE;
727 }
728
729 gint
730 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
731 {
732         if (ev->type == GDK_BUTTON_RELEASE) {
733                 return TRUE;
734         }
735
736         switch (ev->button) {
737         case 1:
738                 if (pan_astyle_menu == 0) {
739                         build_astyle_menu ();
740                 }
741                 pan_astyle_menu->popup (1, ev->time);
742                 break;
743         default:
744                 break;
745         }
746         return TRUE;
747 }
748
749 void
750 PannerUI::pan_automation_style_changed ()
751 {
752         ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_style_changed));
753         
754         switch (_width) {
755         case Wide:
756                 pan_automation_style_button.set_label (astyle_string(_io->panner().automation_style()));
757                 break;
758         case Narrow:
759                 pan_automation_style_button.set_label (short_astyle_string(_io->panner().automation_style()));
760                 break;
761         }
762 }
763
764 void
765 PannerUI::pan_automation_state_changed ()
766 {
767         ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::pan_automation_state_changed));
768         
769         bool x;
770
771         switch (_width) {
772         case Wide:
773           pan_automation_state_button.set_label (astate_string(_io->panner().automation_state()));
774                 break;
775         case Narrow:
776           pan_automation_state_button.set_label (short_astate_string(_io->panner().automation_state()));
777                 break;
778         }
779
780         /* when creating a new session, we get to create busses (and
781            sometimes tracks) with no outputs by the time they get
782            here.
783         */
784
785         if (_io->panner().empty()) {
786                 return;
787         }
788
789         x = (_io->panner().front()->automation().automation_state() != Off);
790
791         if (pan_automation_state_button.get_active() != x) {
792         ignore_toggle = true;
793                 pan_automation_state_button.set_active (x);
794                 ignore_toggle = false;
795         }
796
797         update_pan_sensitive ();
798
799         /* start watching automation so that things move */
800
801         pan_watching.disconnect();
802
803         if (x) {
804                 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (mem_fun (*this, &PannerUI::effective_pan_display));
805         }
806 }
807
808 string
809 PannerUI::astate_string (AutoState state)
810 {
811         return _astate_string (state, false);
812 }
813
814 string
815 PannerUI::short_astate_string (AutoState state)
816 {
817         return _astate_string (state, true);
818 }
819
820 string
821 PannerUI::_astate_string (AutoState state, bool shrt)
822 {
823         string sstr;
824
825         switch (state) {
826         case Off:
827                 sstr = (shrt ? "M" : _("M"));
828                 break;
829         case Play:
830                 sstr = (shrt ? "P" : _("P"));
831                 break;
832         case Touch:
833                 sstr = (shrt ? "T" : _("T"));
834                 break;
835         case Write:
836                 sstr = (shrt ? "W" : _("W"));
837                 break;
838         }
839
840         return sstr;
841 }
842
843 string
844 PannerUI::astyle_string (AutoStyle style)
845 {
846         return _astyle_string (style, false);
847 }
848
849 string
850 PannerUI::short_astyle_string (AutoStyle style)
851 {
852         return _astyle_string (style, true);
853 }
854
855 string
856 PannerUI::_astyle_string (AutoStyle style, bool shrt)
857 {
858         if (style & Trim) {
859                 return _("Trim");
860         } else {
861                 /* XXX it might different in different languages */
862
863                 return (shrt ? _("Abs") : _("Abs"));
864         }
865 }