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