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