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 hAdjustment(0.0, 0.0, 0.0),
89 vAdjustment(0.0, 0.0, 0.0),
90 panning_viewport(hAdjustment, vAdjustment),
91 panning_up_arrow (Gtk::ARROW_UP, Gtk::SHADOW_OUT),
92 panning_down_arrow (Gtk::ARROW_DOWN, Gtk::SHADOW_OUT),
93 panning_link_button (_("link"))
96 ignore_toggle = false;
98 in_pan_update = false;
100 pan_bar_packer.set_size_request (-1, 61);
101 panning_viewport.set_size_request (61, 61);
103 panning_viewport.set_name (X_("BaseFrame"));
105 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_button,
106 _("panning link control"));
107 ARDOUR_UI::instance()->tooltips().set_tip (panning_link_direction_button,
108 _("panning link direction"));
110 panning_link_box.pack_start (panning_link_button, true, true);
111 panning_link_box.pack_start (panning_link_direction_button, true, true);
113 panning_link_button.set_name (X_("PanningLinkButton"));
114 panning_link_direction_button.set_name (X_("PanningLinkDirectionButton"));
116 /* the pixmap will be reset at some point, but the key thing is that
117 we need a pixmap in the button just to get started.
120 panning_link_direction_button.add (*(manage (new Image (Gdk::Pixbuf::create_from_xpm_data(forwdblarrow_xpm)))));
122 panning_link_direction_button.signal_clicked().connect
123 (mem_fun(*this, &PannerUI::panning_link_direction_clicked));
125 panning_link_button.signal_button_press_event().connect
126 (mem_fun(*this, &PannerUI::panning_link_button_press));
127 panning_link_button.signal_button_release_event().connect
128 (mem_fun(*this, &PannerUI::panning_link_button_release));
130 panning_up.set_border_width (3);
131 panning_down.set_border_width (3);
132 panning_up.add (panning_up_arrow);
133 panning_down.add (panning_down_arrow);
134 panning_up.set_name (X_("PanScrollerBase"));
135 panning_down.set_name (X_("PanScrollerBase"));
136 panning_up_arrow.set_name (X_("PanScrollerArrow"));
137 panning_down_arrow.set_name (X_("PanScrollerArrow"));
139 pan_vbox.set_spacing (4);
140 pan_vbox.pack_start (panning_viewport, false, false);
141 pan_vbox.pack_start (panning_link_box, false, false);
143 pack_start (pan_vbox, true, false);
144 pan_vbox.show_all ();
149 _io.panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
150 _io.panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
151 _io.panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
154 update_pan_sensitive ();
155 update_pan_linkage ();
159 PannerUI::panning_link_button_press (GdkEventButton* ev)
161 return stop_signal (panning_link_button, "button-press-event");
165 PannerUI::panning_link_button_release (GdkEventButton* ev)
167 if (!ignore_toggle) {
168 _io.panner().set_linked (!_io.panner().linked());
174 PannerUI::panning_link_direction_clicked()
176 switch (_io.panner().link_direction()) {
177 case Panner::SameDirection:
178 _io.panner().set_link_direction (Panner::OppositeDirection);
181 _io.panner().set_link_direction (Panner::SameDirection);
187 PannerUI::update_pan_linkage ()
189 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
191 bool x = _io.panner().linked();
192 bool bx = panning_link_button.get_active();
196 ignore_toggle = true;
197 panning_link_button.set_active (x);
198 ignore_toggle = false;
201 panning_link_direction_button.set_sensitive (x);
203 switch (_io.panner().link_direction()) {
204 case Panner::SameDirection:
205 panning_link_direction_button.set_image (*(manage (new Image (Gdk::Pixbuf::create_from_xpm_data (forwdblarrow_xpm)))));
208 panning_link_direction_button.set_image (*(manage (new Image (Gdk::Pixbuf::create_from_xpm_data (revdblarrow_xpm)))));
214 PannerUI::set_width (Width w)
218 panning_viewport.set_size_request (61, 61);
220 panner->set_size_request (61, 61);
222 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
223 (*i)->set_size_request (61, 15);
225 static_cast<Gtk::Label*> (panning_link_button.get_child())->set_text (_("link"));
228 panning_viewport.set_size_request (31, 61);
230 panner->set_size_request (31, 61);
232 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
233 (*i)->set_size_request (31, 15);
235 static_cast<Gtk::Label*> (panning_link_button.get_child())->set_text (_("L"));
243 PannerUI::~PannerUI ()
245 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
249 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
265 PannerUI::entry_focus_event (GdkEventFocus* ev)
268 ARDOUR_UI::instance()->allow_focus (true);
270 ARDOUR_UI::instance()->allow_focus (false);
276 PannerUI::panner_changed ()
278 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
283 PannerUI::update_pan_state ()
285 /* currently nothing to do */
286 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
290 PannerUI::setup_pan ()
292 uint32_t nouts = _io.n_outputs ();
294 if (nouts == 0 || nouts == 1) {
296 while (!pan_adjustments.empty()) {
297 delete pan_bars.back();
298 pan_bars.pop_back ();
299 delete pan_adjustments.back();
300 pan_adjustments.pop_back ();
303 } else if (nouts == 2) {
305 vector<Adjustment*>::size_type asz;
306 uint32_t npans = _io.panner().size();
308 while (!pan_adjustments.empty()) {
309 delete pan_bars.back();
310 pan_bars.pop_back ();
311 delete pan_adjustments.back();
312 pan_adjustments.pop_back ();
315 while ((asz = pan_adjustments.size()) < npans) {
320 /* initialize adjustment with current value of panner */
322 _io.panner()[asz]->get_position (x);
324 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
325 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
327 _io.panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
329 bc = new BarController (*pan_adjustments[asz],
330 &_io.panner()[asz]->midi_control(),
331 bind (mem_fun(*this, &PannerUI::pan_printer), pan_adjustments[asz]));
333 if (_session.midi_port()) {
334 _io.panner()[asz]->reset_midi_control (_session.midi_port(), true);
337 bc->set_name ("PanSlider");
338 bc->set_shadow_type (Gtk::SHADOW_NONE);
339 bc->set_style (BarController::Line);
340 bc->get_spin_button().signal_focus_in_event().connect (mem_fun(*this, &PannerUI::entry_focus_event));
341 bc->get_spin_button().signal_focus_out_event().connect (mem_fun(*this, &PannerUI::entry_focus_event));
343 bc->StartGesture.connect (bind (mem_fun (_io, &IO::start_pan_touch), (uint32_t) asz));
344 bc->StopGesture.connect (bind (mem_fun (_io, &IO::end_pan_touch), (uint32_t) asz));
347 snprintf (buf, sizeof (buf), _("panner for channel %u"), asz + 1);
348 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
350 bc->event_widget().signal_button_release_event().connect
351 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
353 pan_bars.push_back (bc);
356 pan_bars.back()->set_size_request (61, 15);
359 pan_bars.back()->set_size_request (31, 15);
363 pan_bar_packer.pack_start (*pan_bars.back(), false, false);
366 /* now that we actually have the pan bars,
367 set their sensitivity based on current
371 update_pan_sensitive ();
373 panning_viewport.remove ();
374 panning_viewport.add (pan_bar_packer);
375 panning_viewport.show_all ();
391 panner = new Panner2d (_io.panner(), w, 61);
392 panner->set_name ("MixerPanZone");
396 update_pan_sensitive ();
397 panner->reset (_io.n_inputs());
398 panner->set_size_request (w, 61);
400 /* and finally, add it to the panner frame */
402 panning_viewport.remove ();
403 panning_viewport.add (*panner);
404 panning_viewport.show_all ();
409 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
411 switch (ev->button) {
414 pan_menu = manage (new Menu);
415 pan_menu->set_name ("ArdourContextMenu");
417 build_pan_menu (which);
418 pan_menu->popup (1, ev->time);
425 return FALSE; // what's wrong with gcc?
429 PannerUI::build_pan_menu (uint32_t which)
431 using namespace Menu_Helpers;
432 MenuList& items (pan_menu->items());
436 items.push_back (CheckMenuElem (_("Mute")));
438 /* set state first, connect second */
440 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io.panner()[which]->muted());
441 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
442 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
444 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
445 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
447 /* set state first, connect second */
449 bypass_menu_item->set_active (_io.panner().bypassed());
450 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
452 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
453 items.push_back (SeparatorElem());
454 items.push_back (MenuElem (_("Reset all")));
458 PannerUI::pan_mute (uint32_t which)
460 StreamPanner* sp = _io.panner()[which];
461 sp->set_muted (!sp->muted());
465 PannerUI::pan_bypass_toggle ()
467 if (bypass_menu_item && (_io.panner().bypassed() != bypass_menu_item->get_active())) {
468 _io.panner().set_bypassed (!_io.panner().bypassed());
473 PannerUI::pan_reset ()
478 PannerUI::effective_pan_display ()
480 if (_io.panner().empty()) {
484 switch (_io.n_outputs()) {
491 update_pan_bars (true);
495 //panner->move_puck (pan_value (v, right), 0.5);
501 PannerUI::pan_changed (void *src)
507 switch (_io.panner().size()) {
509 panning_link_box.set_sensitive (false);
512 panning_link_box.set_sensitive (false);
515 panning_link_box.set_sensitive (true);
518 uint32_t nouts = _io.n_outputs();
527 update_pan_bars (false);
531 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
537 PannerUI::pan_adjustment_changed (uint32_t which)
539 if (!in_pan_update && which < _io.panner().size()) {
542 float val = pan_adjustments[which]->get_value ();
543 _io.panner()[which]->get_position (xpos);
545 /* add a kinda-sorta detent for the middle */
547 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
548 /* this is going to be reentrant, so just
552 in_pan_update = true;
553 pan_adjustments[which]->set_value (0.5);
554 in_pan_update = false;
558 if (!Panner::equivalent (val, xpos)) {
560 _io.panner()[which]->set_position (val);
562 the panner objects have no access to the session,
563 so do this here. ick.
565 _session.set_dirty();
571 PannerUI::pan_value_changed (uint32_t which)
573 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
575 if (which < _io.panner().size()) {
577 float val = pan_adjustments[which]->get_value ();
579 _io.panner()[which]->get_position (xpos);
581 if (!Panner::equivalent (val, xpos)) {
582 in_pan_update = true;
583 pan_adjustments[which]->set_value (xpos);
584 in_pan_update = false;
590 PannerUI::update_pan_bars (bool only_if_aplay)
593 vector<Adjustment*>::iterator i;
595 in_pan_update = true;
597 /* this runs during automation playback, and moves the bar controllers
601 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
605 AutomationList& alist (_io.panner()[n]->automation());
607 if (!alist.automation_playback()) {
612 _io.panner()[n]->get_effective_position (xpos);
613 val = (*i)->get_value ();
615 if (!Panner::equivalent (val, xpos)) {
616 (*i)->set_value (xpos);
620 in_pan_update = false;
624 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
626 float val = adj->get_value();
629 snprintf (buf, len, X_("L"));
630 } else if (val == 1.0f) {
631 snprintf (buf, len, X_("R"));
632 } else if (Panner::equivalent (val, 0.5f)) {
633 snprintf (buf, len, X_("C"));
635 /* don't print anything */
641 PannerUI::update_pan_sensitive ()
643 bool sensitive = !(_io.panner().automation_state() & Play);
645 switch (_io.n_outputs()) {
650 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
651 (*i)->set_sensitive (sensitive);
656 panner->set_sensitive (sensitive);