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, Gtk::PACK_SHRINK);
141 pan_vbox.pack_start (panning_link_box, Gtk::PACK_SHRINK);
143 pack_start (pan_vbox, true, false);
147 _io.panner().Changed.connect (mem_fun(*this, &PannerUI::panner_changed));
148 _io.panner().LinkStateChanged.connect (mem_fun(*this, &PannerUI::update_pan_linkage));
149 _io.panner().StateChanged.connect (mem_fun(*this, &PannerUI::update_pan_state));
152 update_pan_sensitive ();
153 update_pan_linkage ();
157 PannerUI::panning_link_button_press (GdkEventButton* ev)
159 return stop_signal (panning_link_button, "button-press-event");
163 PannerUI::panning_link_button_release (GdkEventButton* ev)
165 if (!ignore_toggle) {
166 _io.panner().set_linked (!_io.panner().linked());
172 PannerUI::panning_link_direction_clicked()
174 switch (_io.panner().link_direction()) {
175 case Panner::SameDirection:
176 _io.panner().set_link_direction (Panner::OppositeDirection);
179 _io.panner().set_link_direction (Panner::SameDirection);
185 PannerUI::update_pan_linkage ()
187 ENSURE_GUI_THREAD(mem_fun(*this, &PannerUI::update_pan_linkage));
189 bool x = _io.panner().linked();
190 bool bx = panning_link_button.get_active();
194 ignore_toggle = true;
195 panning_link_button.set_active (x);
196 ignore_toggle = false;
199 panning_link_direction_button.set_sensitive (x);
201 switch (_io.panner().link_direction()) {
202 case Panner::SameDirection:
203 panning_link_direction_button.set_image (*(manage (new Image (Gdk::Pixbuf::create_from_xpm_data (forwdblarrow_xpm)))));
206 panning_link_direction_button.set_image (*(manage (new Image (Gdk::Pixbuf::create_from_xpm_data (revdblarrow_xpm)))));
212 PannerUI::set_width (Width w)
216 panning_viewport.set_size_request (61, 61);
218 panner->set_size_request (61, 61);
220 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
221 (*i)->set_size_request (61, 15);
223 static_cast<Gtk::Label*> (panning_link_button.get_child())->set_text (_("link"));
226 panning_viewport.set_size_request (31, 61);
228 panner->set_size_request (31, 61);
230 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
231 (*i)->set_size_request (31, 15);
233 static_cast<Gtk::Label*> (panning_link_button.get_child())->set_text (_("L"));
241 PannerUI::~PannerUI ()
243 for (vector<Adjustment*>::iterator i = pan_adjustments.begin(); i != pan_adjustments.end(); ++i) {
247 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
263 PannerUI::panner_changed ()
265 ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::panner_changed));
270 PannerUI::update_pan_state ()
272 /* currently nothing to do */
273 // ENSURE_GUI_THREAD (mem_fun(*this, &PannerUI::update_panner_state));
277 PannerUI::setup_pan ()
279 uint32_t nouts = _io.n_outputs ();
281 if (nouts == 0 || nouts == 1) {
283 while (!pan_adjustments.empty()) {
284 delete pan_bars.back();
285 pan_bars.pop_back ();
286 delete pan_adjustments.back();
287 pan_adjustments.pop_back ();
290 } else if (nouts == 2) {
292 vector<Adjustment*>::size_type asz;
293 uint32_t npans = _io.panner().size();
295 while (!pan_adjustments.empty()) {
296 delete pan_bars.back();
297 pan_bars.pop_back ();
298 delete pan_adjustments.back();
299 pan_adjustments.pop_back ();
302 while ((asz = pan_adjustments.size()) < npans) {
307 /* initialize adjustment with current value of panner */
309 _io.panner()[asz]->get_position (x);
311 pan_adjustments.push_back (new Adjustment (x, 0, 1.0, 0.05, 0.1));
312 pan_adjustments.back()->signal_value_changed().connect (bind (mem_fun(*this, &PannerUI::pan_adjustment_changed), (uint32_t) asz));
314 _io.panner()[asz]->Changed.connect (bind (mem_fun(*this, &PannerUI::pan_value_changed), (uint32_t) asz));
316 bc = new BarController (*pan_adjustments[asz],
317 &_io.panner()[asz]->midi_control(),
318 bind (mem_fun(*this, &PannerUI::pan_printer), pan_adjustments[asz]));
320 if (_session.midi_port()) {
321 _io.panner()[asz]->reset_midi_control (_session.midi_port(), true);
324 bc->set_name ("PanSlider");
325 bc->set_shadow_type (Gtk::SHADOW_NONE);
326 bc->set_style (BarController::Line);
328 bc->StartGesture.connect (bind (mem_fun (_io, &IO::start_pan_touch), (uint32_t) asz));
329 bc->StopGesture.connect (bind (mem_fun (_io, &IO::end_pan_touch), (uint32_t) asz));
332 snprintf (buf, sizeof (buf), _("panner for channel %u"), asz + 1);
333 ARDOUR_UI::instance()->tooltips().set_tip (bc->event_widget(), buf);
335 bc->event_widget().signal_button_release_event().connect
336 (bind (mem_fun(*this, &PannerUI::pan_button_event), (uint32_t) asz));
338 pan_bars.push_back (bc);
341 pan_bars.back()->set_size_request (61, 15);
344 pan_bars.back()->set_size_request (31, 15);
348 pan_bar_packer.pack_start (*pan_bars.back(), false, false);
351 /* now that we actually have the pan bars,
352 set their sensitivity based on current
356 update_pan_sensitive ();
358 panning_viewport.remove ();
359 panning_viewport.add (pan_bar_packer);
360 panning_viewport.show_all ();
376 panner = new Panner2d (_io.panner(), w, 61);
377 panner->set_name ("MixerPanZone");
381 update_pan_sensitive ();
382 panner->reset (_io.n_inputs());
383 panner->set_size_request (w, 61);
385 /* and finally, add it to the panner frame */
387 panning_viewport.remove ();
388 panning_viewport.add (*panner);
389 panning_viewport.show_all ();
394 PannerUI::pan_button_event (GdkEventButton* ev, uint32_t which)
396 switch (ev->button) {
399 pan_menu = manage (new Menu);
400 pan_menu->set_name ("ArdourContextMenu");
402 build_pan_menu (which);
403 pan_menu->popup (1, ev->time);
410 return FALSE; // what's wrong with gcc?
414 PannerUI::build_pan_menu (uint32_t which)
416 using namespace Menu_Helpers;
417 MenuList& items (pan_menu->items());
421 items.push_back (CheckMenuElem (_("Mute")));
423 /* set state first, connect second */
425 (dynamic_cast<CheckMenuItem*> (&items.back()))->set_active (_io.panner()[which]->muted());
426 (dynamic_cast<CheckMenuItem*> (&items.back()))->signal_toggled().connect
427 (bind (mem_fun(*this, &PannerUI::pan_mute), which));
429 items.push_back (CheckMenuElem (_("Bypass"), mem_fun(*this, &PannerUI::pan_bypass_toggle)));
430 bypass_menu_item = static_cast<CheckMenuItem*> (&items.back());
432 /* set state first, connect second */
434 bypass_menu_item->set_active (_io.panner().bypassed());
435 bypass_menu_item->signal_toggled().connect (mem_fun(*this, &PannerUI::pan_bypass_toggle));
437 items.push_back (MenuElem (_("Reset"), mem_fun(*this, &PannerUI::pan_reset)));
438 items.push_back (SeparatorElem());
439 items.push_back (MenuElem (_("Reset all")));
443 PannerUI::pan_mute (uint32_t which)
445 StreamPanner* sp = _io.panner()[which];
446 sp->set_muted (!sp->muted());
450 PannerUI::pan_bypass_toggle ()
452 if (bypass_menu_item && (_io.panner().bypassed() != bypass_menu_item->get_active())) {
453 _io.panner().set_bypassed (!_io.panner().bypassed());
458 PannerUI::pan_reset ()
463 PannerUI::effective_pan_display ()
465 if (_io.panner().empty()) {
469 switch (_io.n_outputs()) {
476 update_pan_bars (true);
480 //panner->move_puck (pan_value (v, right), 0.5);
486 PannerUI::pan_changed (void *src)
492 switch (_io.panner().size()) {
494 panning_link_box.set_sensitive (false);
497 panning_link_box.set_sensitive (false);
500 panning_link_box.set_sensitive (true);
503 uint32_t nouts = _io.n_outputs();
512 update_pan_bars (false);
516 // panner->move_puck (pan_value (pans[0], pans[1]), 0.5);
522 PannerUI::pan_adjustment_changed (uint32_t which)
524 if (!in_pan_update && which < _io.panner().size()) {
527 float val = pan_adjustments[which]->get_value ();
528 _io.panner()[which]->get_position (xpos);
530 /* add a kinda-sorta detent for the middle */
532 if (val != 0.5 && Panner::equivalent (val, 0.5)) {
533 /* this is going to be reentrant, so just
537 in_pan_update = true;
538 pan_adjustments[which]->set_value (0.5);
539 in_pan_update = false;
543 if (!Panner::equivalent (val, xpos)) {
545 _io.panner()[which]->set_position (val);
547 the panner objects have no access to the session,
548 so do this here. ick.
550 _session.set_dirty();
556 PannerUI::pan_value_changed (uint32_t which)
558 ENSURE_GUI_THREAD (bind (mem_fun(*this, &PannerUI::pan_value_changed), which));
560 if (which < _io.panner().size()) {
562 float val = pan_adjustments[which]->get_value ();
564 _io.panner()[which]->get_position (xpos);
566 if (!Panner::equivalent (val, xpos)) {
567 in_pan_update = true;
568 pan_adjustments[which]->set_value (xpos);
569 in_pan_update = false;
575 PannerUI::update_pan_bars (bool only_if_aplay)
578 vector<Adjustment*>::iterator i;
580 in_pan_update = true;
582 /* this runs during automation playback, and moves the bar controllers
586 for (i = pan_adjustments.begin(), n = 0; i != pan_adjustments.end(); ++i, ++n) {
590 AutomationList& alist (_io.panner()[n]->automation());
592 if (!alist.automation_playback()) {
597 _io.panner()[n]->get_effective_position (xpos);
598 val = (*i)->get_value ();
600 if (!Panner::equivalent (val, xpos)) {
601 (*i)->set_value (xpos);
605 in_pan_update = false;
609 PannerUI::pan_printer (char *buf, uint32_t len, Adjustment* adj)
611 float val = adj->get_value();
614 snprintf (buf, len, X_("L"));
615 } else if (val == 1.0f) {
616 snprintf (buf, len, X_("R"));
617 } else if (Panner::equivalent (val, 0.5f)) {
618 snprintf (buf, len, X_("C"));
620 /* don't print anything */
626 PannerUI::update_pan_sensitive ()
628 bool sensitive = !(_io.panner().automation_state() & Play);
630 switch (_io.n_outputs()) {
635 for (vector<BarController*>::iterator i = pan_bars.begin(); i != pan_bars.end(); ++i) {
636 (*i)->set_sensitive (sensitive);
641 panner->set_sensitive (sensitive);