sanitycheck should be looking for SCHED_FIFO
[ardour2.git] / gtk2_ardour / panner_ui.cc
blobaf207c20c13a6a43cb0fbcf8c77a2e9f7bdeba1b
1 /*
2 Copyright (C) 2004 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 #include <limits.h>
21 #include "ardour/io.h"
22 #include "ardour/dB.h"
23 #include <gtkmm2ext/utils.h>
24 #include <gtkmm2ext/barcontroller.h>
25 #include "midi++/manager.h"
26 #include "pbd/fastlog.h"
28 #include "ardour_ui.h"
29 #include "panner_ui.h"
30 #include "panner2d.h"
31 #include "utils.h"
32 #include "gui_thread.h"
33 #include "stereo_panner.h"
34 #include "mono_panner.h"
36 #include "ardour/delivery.h"
37 #include "ardour/session.h"
38 #include "ardour/panner.h"
39 #include "ardour/pannable.h"
40 #include "ardour/route.h"
42 #include "i18n.h"
44 using namespace std;
45 using namespace ARDOUR;
46 using namespace PBD;
47 using namespace Gtkmm2ext;
48 using namespace Gtk;
50 const int PannerUI::pan_bar_height = 40;
52 PannerUI::PannerUI (Session* s)
53 : _current_nouts (-1)
54 , _current_nins (-1)
55 , pan_automation_style_button ("")
56 , pan_automation_state_button ("")
58 set_session (s);
60 ignore_toggle = false;
61 pan_menu = 0;
62 pan_astate_menu = 0;
63 pan_astyle_menu = 0;
64 in_pan_update = false;
65 _stereo_panner = 0;
66 _ignore_width_change = false;
67 _ignore_position_change = false;
69 pan_automation_style_button.set_name ("MixerAutomationModeButton");
70 pan_automation_state_button.set_name ("MixerAutomationPlaybackButton");
72 ARDOUR_UI::instance()->set_tip (pan_automation_state_button, _("Pan automation mode"));
73 ARDOUR_UI::instance()->set_tip (pan_automation_style_button, _("Pan automation type"));
75 //set_size_request_to_display_given_text (pan_automation_state_button, X_("O"), 2, 2);
76 //set_size_request_to_display_given_text (pan_automation_style_button, X_("0"), 2, 2);
78 pan_automation_style_button.unset_flags (Gtk::CAN_FOCUS);
79 pan_automation_state_button.unset_flags (Gtk::CAN_FOCUS);
81 pan_automation_style_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_style_button_event), false);
82 pan_automation_state_button.signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_automation_state_button_event), false);
84 pan_vbox.set_spacing (2);
85 pack_start (pan_vbox, true, true);
87 twod_panner = 0;
88 big_window = 0;
90 set_width(Narrow);
93 void
94 PannerUI::set_panner (boost::shared_ptr<Panner> p)
96 connections.drop_connections ();
98 delete pan_astyle_menu;
99 pan_astyle_menu = 0;
101 delete pan_astate_menu;
102 pan_astate_menu = 0;
104 _panner = p;
106 delete twod_panner;
107 twod_panner = 0;
109 delete _stereo_panner;
110 _stereo_panner = 0;
112 if (!_panner) {
113 return;
116 _panner->Changed.connect (connections, invalidator (*this), boost::bind (&PannerUI::panner_changed, this, this), gui_context());
117 _panner->StateChanged.connect (connections, invalidator (*this), boost::bind (&PannerUI::update_pan_state, this), gui_context());
119 /* new panner object, force complete reset of panner GUI
122 _current_nouts = 0;
123 _current_nins = 0;
125 panner_changed (0);
126 update_pan_sensitive ();
127 pan_automation_state_changed ();
131 void
132 PannerUI::build_astate_menu ()
134 using namespace Menu_Helpers;
136 if (pan_astate_menu == 0) {
137 pan_astate_menu = new Menu;
138 pan_astate_menu->set_name ("ArdourContextMenu");
139 } else {
140 pan_astate_menu->items().clear ();
143 pan_astate_menu->items().push_back (MenuElem (_("Manual"), sigc::bind (
144 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
145 (AutoState) Off)));
146 pan_astate_menu->items().push_back (MenuElem (_("Play"), sigc::bind (
147 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
148 (AutoState) Play)));
149 pan_astate_menu->items().push_back (MenuElem (_("Write"), sigc::bind (
150 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
151 (AutoState) Write)));
152 pan_astate_menu->items().push_back (MenuElem (_("Touch"), sigc::bind (
153 sigc::mem_fun (_panner.get(), &Panner::set_automation_state),
154 (AutoState) Touch)));
158 void
159 PannerUI::build_astyle_menu ()
161 using namespace Menu_Helpers;
163 if (pan_astyle_menu == 0) {
164 pan_astyle_menu = new Menu;
165 pan_astyle_menu->set_name ("ArdourContextMenu");
166 } else {
167 pan_astyle_menu->items().clear();
170 pan_astyle_menu->items().push_back (MenuElem (_("Trim")));
171 pan_astyle_menu->items().push_back (MenuElem (_("Abs")));
174 boost::shared_ptr<PBD::Controllable>
175 PannerUI::get_controllable()
177 assert (!pan_bars.empty());
178 return pan_bars[0]->get_controllable();
181 void
182 PannerUI::on_size_allocate (Allocation& a)
184 HBox::on_size_allocate (a);
187 void
188 PannerUI::set_width (Width w)
190 _width = w;
193 PannerUI::~PannerUI ()
195 for (vector<MonoPanner*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
196 delete (*i);
199 delete twod_panner;
200 delete big_window;
201 delete pan_menu;
202 delete pan_astyle_menu;
203 delete pan_astate_menu;
204 delete _stereo_panner;
208 void
209 PannerUI::panner_changed (void* src)
211 setup_pan ();
214 void
215 PannerUI::update_pan_state ()
217 /* currently nothing to do */
220 void
221 PannerUI::setup_pan ()
223 if (!_panner) {
224 return;
226 uint32_t const nouts = _panner->out().n_audio();
227 uint32_t const nins = _panner->in().n_audio();
229 if (int32_t (nouts) == _current_nouts && int32_t (nins) == _current_nins) {
230 return;
233 container_clear (pan_vbox);
235 delete twod_panner;
236 twod_panner = 0;
237 delete _stereo_panner;
238 _stereo_panner = 0;
240 if (nouts == 0 || nouts == 1) {
242 delete _stereo_panner;
243 delete twod_panner;
245 /* stick something into the panning viewport so that it redraws */
247 EventBox* eb = manage (new EventBox());
248 pan_vbox.pack_start (*eb, false, false);
250 } else if (nouts == 2) {
252 if (nins == 2) {
254 /* add integrated 2in/2out panner GUI */
256 boost::shared_ptr<Pannable> pannable = _panner->pannable();
258 _stereo_panner = new StereoPanner (_panner);
259 _stereo_panner->set_size_request (-1, pan_bar_height);
260 pan_vbox.pack_start (*_stereo_panner, false, false);
262 boost::shared_ptr<AutomationControl> ac;
264 ac = pannable->pan_azimuth_control;
265 _stereo_panner->StartPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
266 boost::weak_ptr<AutomationControl> (ac)));
267 _stereo_panner->StopPositionGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
268 boost::weak_ptr<AutomationControl>(ac)));
270 ac = pannable->pan_width_control;
271 _stereo_panner->StartWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
272 boost::weak_ptr<AutomationControl> (ac)));
273 _stereo_panner->StopWidthGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
274 boost::weak_ptr<AutomationControl>(ac)));
276 } else if (nins == 1) {
277 /* 1-in/2out */
279 MonoPanner* mp;
280 boost::shared_ptr<Pannable> pannable = _panner->pannable();
281 boost::shared_ptr<AutomationControl> ac = pannable->pan_azimuth_control;
283 mp = new MonoPanner (ac);
285 mp->StartGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::start_touch),
286 boost::weak_ptr<AutomationControl> (ac)));
287 mp->StopGesture.connect (sigc::bind (sigc::mem_fun (*this, &PannerUI::stop_touch),
288 boost::weak_ptr<AutomationControl>(ac)));
290 mp->signal_button_release_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event));
292 mp->set_size_request (-1, pan_bar_height);
294 update_pan_sensitive ();
295 pan_vbox.pack_start (*mp, false, false);
297 } else {
298 warning << string_compose (_("No panner user interface is currently available for %1-in/2out tracks/busses"),
299 nins) << endmsg;
303 } else {
305 if (!twod_panner) {
306 twod_panner = new Panner2d (_panner, 61);
307 twod_panner->set_name ("MixerPanZone");
308 twod_panner->show ();
309 twod_panner->signal_button_press_event().connect (sigc::mem_fun(*this, &PannerUI::pan_button_event), false);
312 update_pan_sensitive ();
313 twod_panner->reset (nins);
314 if (big_window) {
315 big_window->reset (nins);
317 twod_panner->set_size_request (-1, 61);
319 /* and finally, add it to the panner frame */
321 pan_vbox.pack_start (*twod_panner, false, false);
324 pan_vbox.show_all ();
327 void
328 PannerUI::start_touch (boost::weak_ptr<AutomationControl> wac)
330 boost::shared_ptr<AutomationControl> ac = wac.lock();
331 if (!ac) {
332 return;
334 ac->start_touch (ac->session().transport_frame());
337 void
338 PannerUI::stop_touch (boost::weak_ptr<AutomationControl> wac)
340 boost::shared_ptr<AutomationControl> ac = wac.lock();
341 if (!ac) {
342 return;
344 ac->stop_touch (false, ac->session().transport_frame());
347 bool
348 PannerUI::pan_button_event (GdkEventButton* ev)
350 switch (ev->button) {
351 case 1:
352 if (twod_panner && ev->type == GDK_2BUTTON_PRESS) {
353 if (!big_window) {
354 big_window = new Panner2dWindow (_panner, 400, _panner->in().n_audio());
356 big_window->show ();
357 return true;
359 break;
361 case 3:
362 if (pan_menu == 0) {
363 pan_menu = manage (new Menu);
364 pan_menu->set_name ("ArdourContextMenu");
366 build_pan_menu ();
367 pan_menu->popup (1, ev->time);
368 return true;
369 break;
370 default:
371 return false;
374 return false; // what's wrong with gcc?
377 void
378 PannerUI::build_pan_menu ()
380 using namespace Menu_Helpers;
381 MenuList& items (pan_menu->items());
383 items.clear ();
385 items.push_back (CheckMenuElem (_("Bypass"), sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle)));
386 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
388 /* set state first, connect second */
390 bypass_menu_item->set_active (_panner->bypassed());
391 bypass_menu_item->signal_toggled().connect (sigc::mem_fun(*this, &PannerUI::pan_bypass_toggle));
393 items.push_back (MenuElem (_("Reset"), sigc::mem_fun (*this, &PannerUI::pan_reset)));
396 void
397 PannerUI::pan_bypass_toggle ()
399 if (bypass_menu_item && (_panner->bypassed() != bypass_menu_item->get_active())) {
400 _panner->set_bypassed (!_panner->bypassed());
404 void
405 PannerUI::pan_reset ()
407 _panner->reset ();
410 void
411 PannerUI::effective_pan_display ()
413 if (_stereo_panner) {
414 _stereo_panner->queue_draw ();
415 } else if (twod_panner) {
416 twod_panner->queue_draw ();
417 } else {
418 for (vector<MonoPanner*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
419 (*i)->queue_draw ();
424 void
425 PannerUI::update_pan_sensitive ()
427 bool const sensitive = !(_panner->pannable()->automation_state() & Play);
429 #ifdef PANNER_HACKS
430 pan_vbox.set_sensitive (sensitive);
431 #endif
432 if (big_window) {
433 big_window->set_sensitive (sensitive);
437 gint
438 PannerUI::pan_automation_state_button_event (GdkEventButton *ev)
440 using namespace Menu_Helpers;
442 if (ev->type == GDK_BUTTON_RELEASE) {
443 return TRUE;
446 switch (ev->button) {
447 case 1:
448 if (pan_astate_menu == 0) {
449 build_astate_menu ();
451 pan_astate_menu->popup (1, ev->time);
452 break;
453 default:
454 break;
457 return TRUE;
460 gint
461 PannerUI::pan_automation_style_button_event (GdkEventButton *ev)
463 if (ev->type == GDK_BUTTON_RELEASE) {
464 return TRUE;
467 switch (ev->button) {
468 case 1:
469 if (pan_astyle_menu == 0) {
470 build_astyle_menu ();
472 pan_astyle_menu->popup (1, ev->time);
473 break;
474 default:
475 break;
477 return TRUE;
480 void
481 PannerUI::pan_automation_style_changed ()
483 ENSURE_GUI_THREAD (*this, &PannerUI::pan_automation_style_changed)
485 switch (_width) {
486 case Wide:
487 pan_automation_style_button.set_label (astyle_string(_panner->automation_style()));
488 break;
489 case Narrow:
490 pan_automation_style_button.set_label (short_astyle_string(_panner->automation_style()));
491 break;
495 void
496 PannerUI::pan_automation_state_changed ()
498 boost::shared_ptr<Pannable> pannable (_panner->pannable());
500 switch (_width) {
501 case Wide:
502 pan_automation_state_button.set_label (astate_string(pannable->automation_state()));
503 break;
504 case Narrow:
505 pan_automation_state_button.set_label (short_astate_string(pannable->automation_state()));
506 break;
509 bool x = (pannable->automation_state() != Off);
511 if (pan_automation_state_button.get_active() != x) {
512 ignore_toggle = true;
513 pan_automation_state_button.set_active (x);
514 ignore_toggle = false;
517 update_pan_sensitive ();
519 /* start watching automation so that things move */
521 pan_watching.disconnect();
523 if (x) {
524 pan_watching = ARDOUR_UI::RapidScreenUpdate.connect (sigc::mem_fun (*this, &PannerUI::effective_pan_display));
528 string
529 PannerUI::astate_string (AutoState state)
531 return _astate_string (state, false);
534 string
535 PannerUI::short_astate_string (AutoState state)
537 return _astate_string (state, true);
540 string
541 PannerUI::_astate_string (AutoState state, bool shrt)
543 string sstr;
545 switch (state) {
546 case Off:
547 sstr = (shrt ? "M" : _("M"));
548 break;
549 case Play:
550 sstr = (shrt ? "P" : _("P"));
551 break;
552 case Touch:
553 sstr = (shrt ? "T" : _("T"));
554 break;
555 case Write:
556 sstr = (shrt ? "W" : _("W"));
557 break;
560 return sstr;
563 string
564 PannerUI::astyle_string (AutoStyle style)
566 return _astyle_string (style, false);
569 string
570 PannerUI::short_astyle_string (AutoStyle style)
572 return _astyle_string (style, true);
575 string
576 PannerUI::_astyle_string (AutoStyle style, bool shrt)
578 if (style & Trim) {
579 return _("Trim");
580 } else {
581 /* XXX it might different in different languages */
583 return (shrt ? _("Abs") : _("Abs"));
587 void
588 PannerUI::show_width ()
592 void
593 PannerUI::width_adjusted ()
597 void
598 PannerUI::show_position ()
602 void
603 PannerUI::position_adjusted ()