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 static const gchar * forwdblarrow_xpm[] = {
57 " ..............+++. ",
58 " .+++++++++++++++++.",
59 " ...................",
60 " .+++++++++++++++++.",
61 " ..............+++. ",
67 static const gchar * revdblarrow_xpm[] = {
75 " ..............+++. ",
76 " .+++++++++++++++++.",
77 " ...................",
78 " .+++++++++++++++++.",
79 " .+++..............",
85 PannerUI::PannerUI (IO& io, Session& s)
88 panning_up_arrow (GTK_ARROW_UP, Gtk::SHADOW_OUT),
89 panning_down_arrow (GTK_ARROW_DOWN, Gtk::SHADOW_OUT),
90 panning_link_button (_("link"))
93 ignore_toggle = false;
95 in_pan_update = false;
97 pan_bar_packer.set_size_request (-1, 61);
98 panning_viewport.set_size_request (61, 61);
100 panning_viewport.set_name (X_("BaseFrame"));
102 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
103 _("panning link control"));
104 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
105 _("panning link direction"));
107 panning_link_box.pack_start (panning_link_button, true, true);
108 panning_link_box.pack_start (panning_link_direction_button, true, true);
110 panning_link_button.set_name (X_("PanningLinkButton"));
111 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
113 /* the pixmap will be reset at some point, but the key thing is that
114 we need a pixmap in the button just to get started.
117 panning_link_direction_button.add (*(manage (new Pixmap (forwdblarrow_xpm))));
119 panning_link_direction_button.clicked.connect
120 (slot (*this, &PannerUI::panning_link_direction_clicked));
122 panning_link_button.button_press_event.connect
123 (slot (*this, &PannerUI::panning_link_button_press));
124 panning_link_button.button_release_event.connect
125 (slot (*this, &PannerUI::panning_link_button_release));
127 panning_up.set_border_width (3);
128 panning_down.set_border_width (3);
129 panning_up.add (panning_up_arrow);
130 panning_down.add (panning_down_arrow);
131 panning_up.set_name (X_("PanScrollerBase"));
132 panning_down.set_name (X_("PanScrollerBase"));
133 panning_up_arrow.set_name (X_("PanScrollerArrow"));
134 panning_down_arrow.set_name (X_("PanScrollerArrow"));
136 pan_vbox.set_spacing (4);
137 pan_vbox.pack_start (panning_viewport, false, false);
138 pan_vbox.pack_start (panning_link_box, false, false);
140 pack_start (pan_vbox, true, false);
141 pan_vbox.show_all ();
146 _io.panner().Changed.connect (slot (*this, &PannerUI::panner_changed));
147 _io.panner().LinkStateChanged.connect (slot (*this, &PannerUI::update_pan_linkage));
148 _io.panner().StateChanged.connect (slot (*this, &PannerUI::update_pan_state));
151 update_pan_sensitive ();
152 update_pan_linkage ();
156 PannerUI::panning_link_button_press (GdkEventButton* ev)
158 return stop_signal (panning_link_button, "button-press-event");
162 PannerUI::panning_link_button_release (GdkEventButton* ev)
164 if (!ignore_toggle) {
165 _io.panner().set_linked (!_io.panner().linked());
171 PannerUI::panning_link_direction_clicked()
173 switch (_io.panner().link_direction()) {
174 case Panner::SameDirection:
175 _io.panner().set_link_direction (Panner::OppositeDirection);
178 _io.panner().set_link_direction (Panner::SameDirection);
184 PannerUI::update_pan_linkage ()
186 ENSURE_GUI_THREAD(slot (*this, &PannerUI::update_pan_linkage));
188 bool x = _io.panner().linked();
189 bool bx = panning_link_button.get_active();
193 ignore_toggle = true;
194 panning_link_button.set_active (x);
195 ignore_toggle = false;
198 panning_link_direction_button.set_sensitive (x);
200 switch (_io.panner().link_direction()) {
201 case Panner::SameDirection:
202 static_cast<Pixmap*> (panning_link_direction_button.get_child())->set (forwdblarrow_xpm);
205 static_cast<Pixmap*> (panning_link_direction_button.get_child())->set (revdblarrow_xpm);
211 PannerUI::set_width (Width w)
215 panning_viewport.set_size_request (61, 61);
217 panner->set_size_request (61, 61);
219 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
220 (*i)->set_size_request (61, 15);
222 static_cast<Gtk::Label*> (panning_link_button.get_child())->set_text (_("link"));
225 panning_viewport.set_size_request (31, 61);
227 panner->set_size_request (31, 61);
229 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
230 (*i)->set_size_request (31, 15);
232 static_cast<Gtk::Label*> (panning_link_button.get_child())->set_text (_("L"));
240 PannerUI::~PannerUI ()
242 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
246 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
262 PannerUI::entry_focus_event (GdkEventFocus* ev)
265 ARDOUR_UI::instance()->allow_focus (true);
267 ARDOUR_UI::instance()->allow_focus (false);
273 PannerUI::panner_changed ()
275 ENSURE_GUI_THREAD (slot (*this, &PannerUI::panner_changed));
280 PannerUI::update_pan_state ()
282 /* currently nothing to do */
283 // ENSURE_GUI_THREAD (slot (*this, &PannerUI::update_panner_state));
287 PannerUI::setup_pan ()
289 uint32_t nouts = _io.n_outputs ();
291 if (nouts == 0 || nouts == 1) {
293 while (!pan_adjustments.empty()) {
294 delete pan_bars.back();
295 pan_bars.pop_back ();
296 delete pan_adjustments.back();
297 pan_adjustments.pop_back ();
300 } else if (nouts == 2) {
302 vector<Adjustment*>::size_type asz;
303 uint32_t npans = _io.panner().size();
305 while (!pan_adjustments.empty()) {
306 delete pan_bars.back();
307 pan_bars.pop_back ();
308 delete pan_adjustments.back();
309 pan_adjustments.pop_back ();
312 while ((asz = pan_adjustments.size()) < npans) {
317 /* initialize adjustment with current value of panner */
319 _io.panner()[asz]->get_position (x);
321 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
322 pan_adjustments.back()->value_changed.connect (bind (slot (*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
324 _io.panner()[asz]->Changed.connect (bind (slot (*this, &PannerUI::pan_value_changed), (uint32_t) asz));
326 bc = new BarController (*pan_adjustments[asz],
327 &_io.panner()[asz]->midi_control(),
328 bind (slot (*this, &PannerUI::pan_printer), pan_adjustments[asz]));
330 if (_session.midi_port()) {
331 _io.panner()[asz]->reset_midi_control (_session.midi_port(), true);
334 bc->set_name ("PanSlider");
335 bc->set_shadow_type (GTK_SHADOW_NONE);
336 bc->set_style (BarController::Line);
337 bc->get_spin_button().signal_focus_in_event().connect (slot (*this, &PannerUI::entry_focus_event));
338 bc->get_spin_button().signal_focus_out_event().connect (slot (*this, &PannerUI::entry_focus_event));
340 bc->StartGesture.connect (bind (slot (_io, &IO::start_pan_touch), (uint32_t) asz));
341 bc->StopGesture.connect (bind (slot (_io, &IO::end_pan_touch), (uint32_t) asz));
344 snprintf (buf, sizeof (buf), _("panner for channel %u"), asz + 1);
345 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
347 bc->event_widget().button_release_event.connect
348 (bind (slot (*this, &PannerUI::pan_button_event), (uint32_t) asz));
350 pan_bars.push_back (bc);
353 pan_bars.back()->set_size_request (61, 15);
356 pan_bars.back()->set_size_request (31, 15);
360 pan_bar_packer.pack_start (*pan_bars.back(), false, false);
363 /* now that we actually have the pan bars,
364 set their sensitivity based on current
368 update_pan_sensitive ();
370 panning_viewport.remove ();
371 panning_viewport.add (pan_bar_packer);
372 panning_viewport.show_all ();
388 panner = new Panner2d (_io.panner(), w, 61);
389 panner->set_name ("MixerPanZone");
393 update_pan_sensitive ();
394 panner->reset (_io.n_inputs());
395 panner->set_size_request (w, 61);
397 /* and finally, add it to the panner frame */
399 panning_viewport.remove ();
400 panning_viewport.add (*panner);
401 panning_viewport.show_all ();
406 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
408 switch (ev->button) {
411 pan_menu = manage (new Menu);
412 pan_menu->set_name ("ArdourContextMenu");
414 build_pan_menu (which);
415 pan_menu->popup (1, ev->time);
422 return FALSE; // what's wrong with gcc?
426 PannerUI::build_pan_menu (uint32_t which)
428 using namespace Menu_Helpers;
429 MenuList& items (pan_menu->items());
433 items.push_back (CheckMenuElem (_("Mute")));
435 /* set state first, connect second */
437 (dynamic_cast<CheckMenuItem*> (items.back()))->set_active (_io.panner()[which]->muted());
438 (dynamic_cast<CheckMenuItem*> (items.back()))->toggled.connect
439 (bind (slot (*this, &PannerUI::pan_mute), which));
441 items.push_back (CheckMenuElem (_("Bypass"), slot (*this, &PannerUI::pan_bypass_toggle)));
442 bypass_menu_item = static_cast<CheckMenuItem*> (items.back());
444 /* set state first, connect second */
446 bypass_menu_item->set_active (_io.panner().bypassed());
447 bypass_menu_item->toggled.connect (slot (*this, &PannerUI::pan_bypass_toggle));
449 items.push_back (MenuElem (_("Reset"), slot (*this, &PannerUI::pan_reset)));
450 items.push_back (SeparatorElem());
451 items.push_back (MenuElem (_("Reset all")));
455 PannerUI::pan_mute (uint32_t which)
457 StreamPanner* sp = _io.panner()[which];
458 sp->set_muted (!sp->muted());
462 PannerUI::pan_bypass_toggle ()
464 if (bypass_menu_item && (_io.panner().bypassed() != bypass_menu_item->get_active())) {
465 _io.panner().set_bypassed (!_io.panner().bypassed());
470 PannerUI::pan_reset ()
475 PannerUI::effective_pan_display ()
477 if (_io.panner().empty()) {
481 switch (_io.n_outputs()) {
488 update_pan_bars (true);
492 //panner->move_puck (pan_value (v, right), 0.5);
498 PannerUI::pan_changed (void *src)
504 switch (_io.panner().size()) {
506 panning_link_box.set_sensitive (false);
509 panning_link_box.set_sensitive (false);
512 panning_link_box.set_sensitive (true);
515 uint32_t nouts = _io.n_outputs();
524 update_pan_bars (false);
528 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
534 PannerUI::pan_adjustment_changed (uint32_t which)
536 if (!in_pan_update && which < _io.panner().size()) {
539 float val = pan_adjustments[which]->get_value ();
540 _io.panner()[which]->get_position (xpos);
542 /* add a kinda-sorta detent for the middle */
544 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
545 /* this is going to be reentrant, so just
549 in_pan_update = true;
550 pan_adjustments[which]->set_value (0.5);
551 in_pan_update = false;
555 if (!Panner::equivalent (val, xpos)) {
557 _io.panner()[which]->set_position (val);
559 the panner objects have no access to the session,
560 so do this here. ick.
562 _session.set_dirty();
568 PannerUI::pan_value_changed (uint32_t which)
570 ENSURE_GUI_THREAD (bind (slot (*this, &PannerUI::pan_value_changed), which));
572 if (which < _io.panner().size()) {
574 float val = pan_adjustments[which]->get_value ();
576 _io.panner()[which]->get_position (xpos);
578 if (!Panner::equivalent (val, xpos)) {
579 in_pan_update = true;
580 pan_adjustments[which]->set_value (xpos);
581 in_pan_update = false;
587 PannerUI::update_pan_bars (bool only_if_aplay)
590 vector<Adjustment*>::iterator i;
592 in_pan_update = true;
594 /* this runs during automation playback, and moves the bar controllers
598 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
602 AutomationList& alist (_io.panner()[n]->automation());
604 if (!alist.automation_playback()) {
609 _io.panner()[n]->get_effective_position (xpos);
610 val = (*i)->get_value ();
612 if (!Panner::equivalent (val, xpos)) {
613 (*i)->set_value (xpos);
617 in_pan_update = false;
621 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
623 float val = adj->get_value();
626 snprintf (buf, len, X_("L"));
627 } else if (val == 1.0f) {
628 snprintf (buf, len, X_("R"));
629 } else if (Panner::equivalent (val, 0.5f)) {
630 snprintf (buf, len, X_("C"));
632 /* don't print anything */
638 PannerUI::update_pan_sensitive ()
640 bool sensitive = !(_io.panner().automation_state() & Play);
642 switch (_io.n_outputs()) {
647 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
648 (*i)->set_sensitive (sensitive);
653 panner->set_sensitive (sensitive);