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.
23 #include <ardour/io.h>
24 #include <ardour/dB.h>
25 #include <gtkmm2ext/utils.h>
26 #include <gtkmm2ext/stop_signal.h>
27 #include <gtkmm2ext/barcontroller.h>
28 #include <midi++/manager.h>
29 #include <pbd/fastlog.h>
31 #include "ardour_ui.h"
32 #include "panner_ui.h"
35 #include "gui_thread.h"
37 #include <ardour/session.h>
38 #include <ardour/route.h>
39 #include <ardour/panner.h>
43 using namespace ARDOUR;
44 using namespace Gtkmm2ext;
49 PannerUI::PannerUI (IO& io, 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"))
60 ignore_toggle = false;
62 in_pan_update = false;
64 pan_bar_packer.set_size_request (-1, 61);
65 panning_viewport.set_size_request (61, 61);
67 panning_viewport.set_name (X_("BaseFrame"));
69 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
70 _("panning link control"));
71 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
72 _("panning link direction"));
74 panning_link_box.pack_start (panning_link_button, true, true);
75 panning_link_box.pack_start (panning_link_direction_button, true, true);
77 panning_link_button.set_name (X_("PanningLinkButton"));
78 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
80 /* the pixmap will be reset at some point, but the key thing is that
81 we need a pixmap in the button just to get started.
84 panning_link_direction_button.add (*(manage (new Image (get_xpm("forwardblarrow.xpm")))));
86 panning_link_direction_button.signal_clicked().connect
87 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
89 panning_link_button.signal_button_press_event().connect
90 (mem_fun(*this, &PannerUI::panning_link_button_press));
91 panning_link_button.signal_button_release_event().connect
92 (mem_fun(*this, &PannerUI::panning_link_button_release));
94 panning_up.set_border_width (3);
95 panning_down.set_border_width (3);
96 panning_up.add (panning_up_arrow);
97 panning_down.add (panning_down_arrow);
98 panning_up.set_name (X_("PanScrollerBase"));
99 panning_down.set_name (X_("PanScrollerBase"));
100 panning_up_arrow.set_name (X_("PanScrollerArrow"));
101 panning_down_arrow.set_name (X_("PanScrollerArrow"));
103 pan_vbox.set_spacing (4);
104 pan_vbox.pack_start (panning_viewport, Gtk::PACK_SHRINK);
105 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
107 pack_start (pan_vbox, true, false);
111 _io.panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
112 _io.panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
113 _io.panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
116 update_pan_sensitive ();
117 update_pan_linkage ();
121 PannerUI::panning_link_button_press (GdkEventButton* ev)
123 return stop_signal (panning_link_button, "button-press-event");
127 PannerUI::panning_link_button_release (GdkEventButton* ev)
129 if (!ignore_toggle) {
130 _io.panner().set_linked (!_io.panner().linked());
136 PannerUI::panning_link_direction_clicked()
138 switch (_io.panner().link_direction()) {
139 case Panner::SameDirection:
140 _io.panner().set_link_direction (Panner::OppositeDirection);
143 _io.panner().set_link_direction (Panner::SameDirection);
149 PannerUI::update_pan_linkage ()
151 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
153 bool x = _io.panner().linked();
154 bool bx = panning_link_button.get_active();
158 ignore_toggle = true;
159 panning_link_button.set_active (x);
160 ignore_toggle = false;
163 panning_link_direction_button.set_sensitive (x);
165 switch (_io.panner().link_direction()) {
166 case Panner::SameDirection:
167 panning_link_direction_button.set_image (*(manage (new Image (get_xpm ("forwardblarrow.xpm")))));
170 panning_link_direction_button.set_image (*(manage (new Image (get_xpm("revdblarrow.xpm")))));
176 PannerUI::set_width (Width w)
180 panning_viewport.set_size_request (61, 61);
182 panner->set_size_request (61, 61);
184 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
185 (*i)->set_size_request (61, 15);
187 panning_link_button.set_label (_("link"));
190 panning_viewport.set_size_request (31, 61);
192 panner->set_size_request (31, 61);
194 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
195 (*i)->set_size_request (31, 15);
197 panning_link_button.set_label (_("L"));
205 PannerUI::~PannerUI ()
207 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
211 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
227 PannerUI::panner_changed ()
229 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
234 PannerUI::update_pan_state ()
236 /* currently nothing to do */
237 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
241 PannerUI::setup_pan ()
243 uint32_t nouts = _io.n_outputs ();
245 if (nouts == 0 || nouts == 1) {
247 while (!pan_adjustments.empty()) {
248 delete pan_bars.back();
249 pan_bars.pop_back ();
250 delete pan_adjustments.back();
251 pan_adjustments.pop_back ();
254 } else if (nouts == 2) {
256 vector<Adjustment*>::size_type asz;
257 uint32_t npans = _io.panner().size();
259 while (!pan_adjustments.empty()) {
260 delete pan_bars.back();
261 pan_bars.pop_back ();
262 delete pan_adjustments.back();
263 pan_adjustments.pop_back ();
266 while ((asz = pan_adjustments.size()) < npans) {
271 /* initialize adjustment with current value of panner */
273 _io.panner()[asz]->get_position (x);
275 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
276 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
278 _io.panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
280 bc = new BarController (*pan_adjustments[asz],
281 &_io.panner()[asz]->midi_control(),
282 bind (mem_fun(*this, &PannerUI::pan_printer), pan_adjustments[asz]));
284 if (_session.midi_port()) {
285 _io.panner()[asz]->reset_midi_control (_session.midi_port(), true);
288 bc->set_name ("PanSlider");
289 bc->set_shadow_type (Gtk::SHADOW_NONE);
290 bc->set_style (BarController::Line);
292 bc->StartGesture.connect (bind (mem_fun (_io, &IO::start_pan_touch), (uint32_t) asz));
293 bc->StopGesture.connect (bind (mem_fun (_io, &IO::end_pan_touch), (uint32_t) asz));
297 snprintf (buf, sizeof (buf), _("panner for channel %lu"), asz + 1);
299 snprintf (buf, sizeof (buf), _("panner for channel %u"), asz + 1);
301 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
303 bc->event_widget().signal_button_release_event().connect
304 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
306 pan_bars.push_back (bc);
309 pan_bars.back()->set_size_request (61, 15);
312 pan_bars.back()->set_size_request (31, 15);
316 pan_bar_packer.pack_start (*pan_bars.back(), false, false);
319 /* now that we actually have the pan bars,
320 set their sensitivity based on current
324 update_pan_sensitive ();
326 panning_viewport.remove ();
327 panning_viewport.add (pan_bar_packer);
328 panning_viewport.show_all ();
344 panner = new Panner2d (_io.panner(), w, 61);
345 panner->set_name ("MixerPanZone");
349 update_pan_sensitive ();
350 panner->reset (_io.n_inputs());
351 panner->set_size_request (w, 61);
353 /* and finally, add it to the panner frame */
355 panning_viewport.remove ();
356 panning_viewport.add (*panner);
357 panning_viewport.show_all ();
362 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
364 switch (ev->button) {
367 pan_menu = manage (new Menu);
368 pan_menu->set_name ("ArdourContextMenu");
370 build_pan_menu (which);
371 pan_menu->popup (1, ev->time);
378 return FALSE; // what's wrong with gcc?
382 PannerUI::build_pan_menu (uint32_t which)
384 using namespace Menu_Helpers;
385 MenuList& items (pan_menu->items());
389 items.push_back (CheckMenuElem (_("Mute")));
391 /* set state first, connect second */
393 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io.panner()[which]->muted());
394 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
395 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
397 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
398 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
400 /* set state first, connect second */
402 bypass_menu_item->set_active (_io.panner().bypassed());
403 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
405 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
406 items.push_back (SeparatorElem());
407 items.push_back (MenuElem (_("Reset all")));
411 PannerUI::pan_mute (uint32_t which)
413 StreamPanner* sp = _io.panner()[which];
414 sp->set_muted (!sp->muted());
418 PannerUI::pan_bypass_toggle ()
420 if (bypass_menu_item && (_io.panner().bypassed() != bypass_menu_item->get_active())) {
421 _io.panner().set_bypassed (!_io.panner().bypassed());
426 PannerUI::pan_reset ()
431 PannerUI::effective_pan_display ()
433 if (_io.panner().empty()) {
437 switch (_io.n_outputs()) {
444 update_pan_bars (true);
448 //panner->move_puck (pan_value (v, right), 0.5);
454 PannerUI::pan_changed (void *src)
460 switch (_io.panner().size()) {
462 panning_link_box.set_sensitive (false);
465 panning_link_box.set_sensitive (false);
468 panning_link_box.set_sensitive (true);
471 uint32_t nouts = _io.n_outputs();
480 update_pan_bars (false);
484 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
490 PannerUI::pan_adjustment_changed (uint32_t which)
492 if (!in_pan_update && which < _io.panner().size()) {
495 float val = pan_adjustments[which]->get_value ();
496 _io.panner()[which]->get_position (xpos);
498 /* add a kinda-sorta detent for the middle */
500 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
501 /* this is going to be reentrant, so just
505 in_pan_update = true;
506 pan_adjustments[which]->set_value (0.5);
507 in_pan_update = false;
511 if (!Panner::equivalent (val, xpos)) {
513 _io.panner()[which]->set_position (val);
515 the panner objects have no access to the session,
516 so do this here. ick.
518 _session.set_dirty();
524 PannerUI::pan_value_changed (uint32_t which)
526 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
528 if (_io.n_outputs() > 1 && which < _io.panner().size()) {
530 float val = pan_adjustments[which]->get_value ();
532 _io.panner()[which]->get_position (xpos);
534 if (!Panner::equivalent (val, xpos)) {
535 in_pan_update = true;
536 pan_adjustments[which]->set_value (xpos);
537 in_pan_update = false;
543 PannerUI::update_pan_bars (bool only_if_aplay)
546 vector<Adjustment*>::iterator i;
548 in_pan_update = true;
550 /* this runs during automation playback, and moves the bar controllers
554 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
558 AutomationList& alist (_io.panner()[n]->automation());
560 if (!alist.automation_playback()) {
565 _io.panner()[n]->get_effective_position (xpos);
566 val = (*i)->get_value ();
568 if (!Panner::equivalent (val, xpos)) {
569 (*i)->set_value (xpos);
573 in_pan_update = false;
577 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
579 float val = adj->get_value();
582 snprintf (buf, len, X_("L"));
583 } else if (val == 1.0f) {
584 snprintf (buf, len, X_("R"));
585 } else if (Panner::equivalent (val, 0.5f)) {
586 snprintf (buf, len, X_("C"));
588 /* don't print anything */
594 PannerUI::update_pan_sensitive ()
596 bool sensitive = !(_io.panner().automation_state() & Play);
598 switch (_io.n_outputs()) {
603 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
604 (*i)->set_sensitive (sensitive);
609 panner->set_sensitive (sensitive);