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