ardour
panner2d.cc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002 Paul Davis
3 
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.
8 
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.
13 
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.
17 
18 */
19 
20 #include <cmath>
21 #include <climits>
22 #include <string.h>
23 
24 #include <cairo.h>
25 #include <gtkmm/menu.h>
26 
27 #include "gtkmm2ext/gtk_ui.h"
28 
29 #include "pbd/error.h"
30 #include "pbd/cartesian.h"
31 #include "ardour/panner.h"
32 #include "ardour/panner_shell.h"
33 #include "ardour/pannable.h"
34 #include "ardour/speakers.h"
35 
36 #include "canvas/colors.h"
37 
38 #include "ardour_ui.h"
39 #include "panner2d.h"
40 #include "keyboard.h"
41 #include "gui_thread.h"
42 #include "utils.h"
43 #include "public_editor.h"
44 
45 #include "i18n.h"
46 
47 using namespace std;
48 using namespace Gtk;
49 using namespace ARDOUR;
50 using namespace ARDOUR_UI_UTILS;
51 using namespace PBD;
53 
54 static const int large_size_threshold = 100;
55 static const int large_border_width = 25;
56 static const int small_border_width = 8;
57 
58 Panner2d::Target::Target (const AngularVector& a, const char *txt)
59  : position (a)
60  , text (txt)
61  , _selected (false)
62 {
63 }
64 
66 {
67 }
68 
69 void
70 Panner2d::Target::set_text (const char* txt)
71 {
72  text = txt;
73 }
74 
76 : panner_shell (p)
77  , position (AngularVector (0.0, 0.0), "")
78  , width (0)
79  , height (h)
80  , last_width (0)
81  , have_elevation (false)
82  , _send_mode (false)
83 {
85 
86  panner_shell->panner()->SignalPositionChanged.connect (panner_connections, invalidator(*this), boost::bind (&Panner2d::handle_position_change, this), gui_context());
87 
88  drag_target = 0;
89  set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
90 
93 }
94 
96 {
97  for (Targets::iterator i = speakers.begin(); i != speakers.end(); ++i) {
98  delete *i;
99  }
100 }
101 
102 void
103 Panner2d::reset (uint32_t n_inputs)
104 {
105  uint32_t nouts = panner_shell->panner()->out().n_audio();
106 
107  /* signals */
108 
109  while (signals.size() < n_inputs) {
110  add_signal ("", AngularVector());
111  }
112 
113  if (signals.size() > n_inputs) {
114  for (uint32_t i = signals.size(); i < n_inputs; ++i) {
115  delete signals[i];
116  }
117 
118  signals.resize (n_inputs);
119  }
120 
121  label_signals ();
122 
123  for (uint32_t i = 0; i < n_inputs; ++i) {
124  signals[i]->position = panner_shell->panner()->signal_position (i);
125  }
126 
127  /* add all outputs */
128 
129  while (speakers.size() < nouts) {
131  }
132 
133  if (speakers.size() > nouts) {
134  for (uint32_t i = nouts; i < speakers.size(); ++i) {
135  delete speakers[i];
136  }
137 
138  speakers.resize (nouts);
139  }
140 
141  for (Targets::iterator x = speakers.begin(); x != speakers.end(); ++x) {
142  (*x)->visible = false;
143  }
144 
145  vector<Speaker>& the_speakers (panner_shell->panner()->get_speakers()->speakers());
146 
147  for (uint32_t n = 0; n < nouts; ++n) {
148  char buf[16];
149 
150  snprintf (buf, sizeof (buf), "%d", n+1);
151  speakers[n]->set_text (buf);
152  speakers[n]->position = the_speakers[n].angles();
153  speakers[n]->visible = true;
154  }
155 
156  queue_draw ();
157 }
158 
159 void
160 Panner2d::on_size_allocate (Gtk::Allocation& alloc)
161 {
162  width = alloc.get_width();
163  height = alloc.get_height();
164 
167  } else {
169  }
170 
171  radius = min (width, height);
172  radius -= border;
173  radius /= 2;
174  radius = rint(radius) + .5;
175 
176  hoffset = max ((double) (width - height), border);
177  voffset = max ((double) (height - width), border);
178 
179  hoffset = rint(hoffset / 2.0);
180  voffset = rint(voffset / 2.0);
181 
182  DrawingArea::on_size_allocate (alloc);
183 }
184 
185 int
186 Panner2d::add_signal (const char* text, const AngularVector& a)
187 {
188  Target* signal = new Target (a, text);
189  signals.push_back (signal);
190  signal->visible = true;
191 
192  return 0;
193 }
194 
195 int
197 {
198  Target* speaker = new Target (a, "");
199  speakers.push_back (speaker);
200  speaker->visible = true;
201  queue_draw ();
202 
203  return speakers.size() - 1;
204 }
205 
206 void
208 {
210  if (!panner_shell->panner()) {
211  return;
212  }
213 
214  panner_shell->panner()->SignalPositionChanged.connect (panner_connections, invalidator(*this), boost::bind (&Panner2d::handle_position_change, this), gui_context());
215 
216  set<Evoral::Parameter> params = panner_shell->panner()->what_can_be_automated();
217  set<Evoral::Parameter>::iterator p = params.find(PanElevationAutomation);
218  bool elev = have_elevation;
219  have_elevation = (p == params.end()) ? false : true;
220  if (elev != have_elevation) {
222  }
223  queue_draw ();
224 }
225 
226 void
228 {
229  uint32_t sz = signals.size();
230 
231  switch (sz) {
232  case 0:
233  break;
234 
235  case 1:
236  signals[0]->set_text ("");
237  break;
238 
239  case 2:
240  signals[0]->set_text (S_("Panner|L"));
241  signals[1]->set_text (S_("Panner|R"));
242  break;
243 
244  default:
245  for (uint32_t i = 0; i < sz; ++i) {
246  char buf[64];
247  snprintf (buf, sizeof (buf), "%" PRIu32, i + 1);
248  signals[i]->set_text (buf);
249  }
250  break;
251  }
252 }
253 
254 void
256 {
257  uint32_t n;
258  double w = panner_shell->pannable()->pan_width_control->get_value();
259 
260  position.position = AngularVector (panner_shell->pannable()->pan_azimuth_control->get_value() * 360.0,
261  panner_shell->pannable()->pan_elevation_control->get_value() * 90.0);
262 
263  for (uint32_t i = 0; i < signals.size(); ++i) {
264  signals[i]->position = panner_shell->panner()->signal_position (i);
265  }
266 
267  if (w * last_width <= 0) {
268  /* changed sign */
269  label_signals ();
270  }
271 
272  last_width = w;
273 
274  vector<Speaker>& the_speakers (panner_shell->panner()->get_speakers()->speakers());
275 
276  for (n = 0; n < speakers.size(); ++n) {
277  speakers[n]->position = the_speakers[n].angles();
278  }
279 
280  queue_draw ();
281 }
282 
283 void
285 {
286  if (which >= int (speakers.size())) {
287  return;
288  }
289 
290  speakers[which]->position = a;
291  queue_draw ();
292 }
293 
295 Panner2d::find_closest_object (gdouble x, gdouble y, bool& is_signal)
296 {
297  Target *closest = 0;
298  Target *candidate;
299  float distance;
300  float best_distance = FLT_MAX;
301  CartesianVector c;
302 
303  /* start with the position itself */
304 
306  if (!have_elevation) dp.ele = 0;
307  dp.azi = 270 - dp.azi;
308  dp.cartesian (c);
309 
310  cart_to_gtk (c);
311  best_distance = sqrt ((c.x - x) * (c.x - x) +
312  (c.y - y) * (c.y - y));
313  closest = &position;
314 
315 #if 0 // TODO signal grab -> change width, not position
316  for (Targets::const_iterator i = signals.begin(); i != signals.end(); ++i) {
317  candidate = *i;
318 
319  candidate->position.cartesian (c);
320  cart_to_gtk (c);
321 
322  distance = sqrt ((c.x - x) * (c.x - x) +
323  (c.y - y) * (c.y - y));
324 
325  if (distance < best_distance) {
326  closest = candidate;
327  best_distance = distance;
328  }
329  }
330 #endif
331 
332  is_signal = true;
333 
335  /* "big" */
336  if (best_distance > 30) { // arbitrary
337  closest = 0;
338  }
339  } else {
340  /* "small" */
341  if (best_distance > 10) { // arbitrary
342  closest = 0;
343  }
344  }
345 
346  /* if we didn't find a signal close by, check the speakers */
347 
348  if (!closest) {
349  for (Targets::const_iterator i = speakers.begin(); i != speakers.end(); ++i) {
350  candidate = *i;
351  PBD::AngularVector sp = candidate->position;
352  sp.azi = 270 -sp.azi;
353  CartesianVector c;
354  sp.cartesian (c);
355  cart_to_gtk (c);
356 
357  distance = sqrt ((c.x - x) * (c.x - x) +
358  (c.y - y) * (c.y - y));
359 
360  if (distance < best_distance) {
361  closest = candidate;
362  best_distance = distance;
363  }
364  }
365 
367  /* "big" */
368  if (best_distance < 30) { // arbitrary
369  is_signal = false;
370  } else {
371  closest = 0;
372  }
373  } else {
374  /* "small" */
375  if (best_distance < 10) { // arbitrary
376  is_signal = false;
377  } else {
378  closest = 0;
379  }
380  }
381  }
382 
383  return closest;
384 }
385 
386 void
388 {
389  if (_send_mode != onoff) {
390  _send_mode = onoff;
391  queue_draw ();
392  }
393 }
394 
395 bool
397 {
398  gint x, y;
399  GdkModifierType state;
400 
401  if (ev->is_hint) {
402  gdk_window_get_pointer (ev->window, &x, &y, &state);
403  } else {
404  x = (int) floor (ev->x);
405  y = (int) floor (ev->y);
406  state = (GdkModifierType) ev->state;
407  }
408 
409  if (ev->state & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK)) {
410  did_move = true;
411  }
412 
413  return handle_motion (x, y, state);
414 }
415 
416 bool
417 Panner2d::on_expose_event (GdkEventExpose *event)
418 {
419  CartesianVector c;
420  cairo_t* cr;
421  bool xsmall = (height <= large_size_threshold);
422  const double diameter = radius*2.0;
423 
424  cr = gdk_cairo_create (get_window()->gobj());
425 
426  /* background */
427 
428  cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height);
429 
430  double r, g, b, a;
431  if (_send_mode) {
432  ArdourCanvas::color_to_rgba (ARDOUR_UI::config()->color ("send bg"), r, g, b, a);
433  }
434  if (!panner_shell->bypassed()) {
435  cairo_set_source_rgba (cr, r, g, b, 1.0);
436  } else {
437  cairo_set_source_rgba (cr, r, g, b , 0.2);
438  }
439  cairo_fill_preserve (cr);
440  cairo_clip (cr);
441 
442  /* offset to give us some border */
443 
444  cairo_translate (cr, hoffset, voffset);
445 
446  cairo_set_line_width (cr, 1.0);
447 
448  /* horizontal line of "crosshairs" */
449 
450  cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0);
451  cairo_move_to (cr, 0.0, radius);
452  cairo_line_to (cr, diameter, radius);
453  cairo_stroke (cr);
454 
455  /* vertical line of "crosshairs" */
456 
457  cairo_move_to (cr, radius, 0);
458  cairo_line_to (cr, radius, diameter);
459  cairo_stroke (cr);
460 
461  /* the circle on which signals live */
462 
463  cairo_set_line_width (cr, 1.5);
464  cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, 1.0);
465  cairo_arc (cr, radius, radius, radius, 0.0, 2.0 * M_PI);
466  cairo_stroke (cr);
467 
468  for (uint32_t rad = 15; rad < 90; rad += 15) {
469  cairo_set_line_width (cr, .5 + (float)rad / 150.0);
470  if (rad == 45) {
471  cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0);
472  } else {
473  cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.8);
474  }
475  cairo_new_path (cr);
476  cairo_arc (cr, radius, radius, radius * sin(M_PI * (float) rad / 180.0), 0, 2.0 * M_PI);
477  cairo_stroke (cr);
478  }
479 
480  if (!panner_shell->bypassed()) {
481  /* convention top == front ^= azimuth == .5 (same as stereo/mono panners) */
482 
483  if (signals.size() > 1) {
484  /* arc to show "diffusion" */
485 
486  double width_angle = fabs (panner_shell->pannable()->pan_width_control->get_value()) * 2 * M_PI;
487  double position_angle = panner_shell->pannable()->pan_azimuth_control->get_value() * 2 * M_PI;
488 
489  cairo_save (cr);
490  cairo_translate (cr, radius, radius);
491  cairo_rotate (cr, M_PI / 2.0);
492  cairo_rotate (cr, position_angle - (width_angle/2.0));
493  cairo_move_to (cr, 0, 0);
494  cairo_arc_negative (cr, 0, 0, radius, width_angle, 0.0);
495  cairo_close_path (cr);
496  if (panner_shell->pannable()->pan_width_control->get_value() >= 0.0) {
497  /* normal width */
498  cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.45);
499  } else {
500  /* inverse width */
501  cairo_set_source_rgba (cr, 1.0, 0.419, 0.419, 0.45);
502  }
503  cairo_fill (cr);
504  cairo_restore (cr);
505  }
506 
507  double arc_radius;
508 
509  cairo_select_font_face (cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
510 
511  if (xsmall) {
512  arc_radius = 4.0;
513  } else {
514  cairo_set_font_size (cr, 10);
515  arc_radius = 12.0;
516  }
517 
518  /* draw position */
519 
521  if (!have_elevation) dp.ele = 0;
522  dp.azi = 270 - dp.azi;
523  dp.cartesian (c);
524  cart_to_gtk (c);
525 
526  cairo_new_path (cr);
527  cairo_arc (cr, c.x, c.y, arc_radius + 1.0, 0, 2.0 * M_PI);
528  cairo_set_source_rgba (cr, 1.0, 0.419, 0.419, 0.85);
529  cairo_fill_preserve (cr);
530  cairo_set_source_rgba (cr, 1.0, 0.905, 0.905, 0.85);
531  cairo_stroke (cr);
532 
533  /* signals */
534 
535  if (signals.size() > 0) {
536  for (Targets::iterator i = signals.begin(); i != signals.end(); ++i) {
537  Target* signal = *i;
538 
539  if (signal->visible) {
540 
541  /* TODO check for overlap - multiple src at same position
542  * -> visualize it properly
543  */
544  PBD::AngularVector sp = signal->position;
545  if (!have_elevation) sp.ele = 0;
546  sp.azi += 270.0;
547  sp.cartesian (c);
548  cart_to_gtk (c);
549 
550  cairo_new_path (cr);
551  cairo_arc (cr, c.x, c.y, arc_radius, 0, 2.0 * M_PI);
552  cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.75);
553  cairo_fill_preserve (cr);
554  cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, 0.8);
555  cairo_stroke (cr);
556 
557  if (!xsmall && !signal->text.empty()) {
558  cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, .9);
559  /* the +/- adjustments are a hack to try to center the text in the circle
560  * TODO use pango get_pixel_size() -- see mono_panner.cc
561  */
562  if (xsmall) {
563  cairo_move_to (cr, c.x - 1, c.y + 1);
564  } else {
565  cairo_move_to (cr, c.x - 4, c.y + 4);
566  }
567  cairo_show_text (cr, signal->text.c_str());
568  }
569  }
570  }
571  }
572 
573  /* speakers */
574 
575  int n = 0;
576 
577  for (Targets::iterator i = speakers.begin(); i != speakers.end(); ++i) {
578  Target *speaker = *i;
579  char buf[256];
580  ++n;
581 
582  if (speaker->visible) {
583 
584  PBD::AngularVector sp = speaker->position;
585  sp.azi += 270.0;
586  CartesianVector c;
587  sp.cartesian (c);
588  cart_to_gtk (c);
589 
590  snprintf (buf, sizeof (buf), "%d", n);
591 
592  /* stroke out a speaker shape */
593 
594  cairo_move_to (cr, c.x, c.y);
595  cairo_save (cr);
596  cairo_rotate (cr, -(sp.azi/360.0) * (2.0 * M_PI));
597  if (xsmall) {
598  cairo_scale (cr, 0.8, 0.8);
599  } else {
600  cairo_scale (cr, 1.2, 1.2);
601  }
602  cairo_rel_line_to (cr, 4, -2);
603  cairo_rel_line_to (cr, 0, -7);
604  cairo_rel_line_to (cr, 5, +5);
605  cairo_rel_line_to (cr, 5, 0);
606  cairo_rel_line_to (cr, 0, 5);
607  cairo_rel_line_to (cr, -5, 0);
608  cairo_rel_line_to (cr, -5, +5);
609  cairo_rel_line_to (cr, 0, -7);
610  cairo_close_path (cr);
611  cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0);
612  cairo_fill (cr);
613  cairo_restore (cr);
614 
615  if (!xsmall) {
616  cairo_set_font_size (cr, 16);
617 
618  /* move the text in just a bit */
619 
620  AngularVector textpos (speaker->position.azi + 270.0, speaker->position.ele, 0.85);
621 
622  textpos.cartesian (c);
623  cart_to_gtk (c);
624  cairo_move_to (cr, c.x, c.y);
625  cairo_show_text (cr, buf);
626  }
627 
628  }
629  }
630  }
631 
632  cairo_destroy (cr);
633 
634  return true;
635 }
636 
637 bool
639 {
640  GdkModifierType state;
641  int x;
642  int y;
643  bool is_signal;
644 
645  if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1) {
646  return false;
647  }
648 
649  did_move = false;
650 
651  switch (ev->button) {
652  case 1:
653  case 2:
654  x = ev->x - hoffset;
655  y = ev->y - voffset;
656 
657  if ((drag_target = find_closest_object (x, y, is_signal)) != 0) {
658  if (!is_signal) {
659  panner_shell->panner()->set_position (drag_target->position.azi/360.0);
660  drag_target = 0;
661  } else {
662  drag_target->set_selected (true);
663  }
664  }
665 
666  state = (GdkModifierType) ev->state;
667  return handle_motion (ev->x, ev->y, state);
668  break;
669 
670  default:
671  break;
672  }
673 
674  return false;
675 }
676 
677 bool
679 {
680  gint x, y;
681  GdkModifierType state;
682  bool ret = false;
683 
684  switch (ev->button) {
685  case 1:
686  x = (int) floor (ev->x);
687  y = (int) floor (ev->y);
688  state = (GdkModifierType) ev->state;
689  ret = handle_motion (x, y, state);
690  drag_target = 0;
691  break;
692 
693  case 2:
694  x = (int) floor (ev->x);
695  y = (int) floor (ev->y);
696  state = (GdkModifierType) ev->state;
697 
698  if (Keyboard::modifier_state_contains (state, Keyboard::TertiaryModifier)) {
699  toggle_bypass ();
700  ret = true;
701  } else {
702  ret = handle_motion (x, y, state);
703  }
704 
705  drag_target = 0;
706  break;
707 
708  case 3:
709  break;
710 
711  }
712 
713  return ret;
714 }
715 
716 gint
717 Panner2d::handle_motion (gint evx, gint evy, GdkModifierType state)
718 {
719  if (drag_target == 0) {
720  return false;
721  }
722 
723  if ((state & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK)) == 0) {
724  return false;
725  }
726 
727  evx -= hoffset;
728  evy -= voffset;
729 
730  if (state & GDK_BUTTON1_MASK && !(state & GDK_BUTTON2_MASK)) {
731  CartesianVector c;
732  bool need_move = false;
733 
735  cart_to_gtk (c);
736 
737  if ((evx != c.x) || (evy != c.y)) {
738  need_move = true;
739  }
740 
741  if (need_move) {
742  CartesianVector cp (evx, evy, 0.0);
743  AngularVector av;
744  gtk_to_cart (cp);
745 
746  if (!have_elevation) {
747  clamp_to_circle (cp.x, cp.y);
748  cp.angular (av);
749  av.azi = fmod(270 - av.azi, 360);
750  if (drag_target == &position) {
751  double degree_fract = av.azi / 360.0;
752  panner_shell->panner()->set_position (degree_fract);
753  }
754  } else {
755  /* sphere projection */
756  sphere_project (cp.x, cp.y, cp.z);
757 
758  double r2d = 180.0 / M_PI;
759  av.azi = r2d * atan2(cp.y, cp.x);
760  av.ele = r2d * asin(cp.z);
761  av.azi = fmod(270 - av.azi, 360);
762 
763  if (drag_target == &position) {
764  double azi_fract = av.azi / 360.0;
765  double ele_fract = av.ele / 90.0;
766  panner_shell->panner()->set_position (azi_fract);
767  panner_shell->panner()->set_elevation (ele_fract);
768  }
769  }
770  }
771  }
772 
773  return true;
774 }
775 
776 bool
777 Panner2d::on_scroll_event (GdkEventScroll* ev)
778 {
779  switch (ev->direction) {
780  case GDK_SCROLL_UP:
781  case GDK_SCROLL_RIGHT:
782  panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() - 1.0/360.0);
783  break;
784 
785  case GDK_SCROLL_DOWN:
786  case GDK_SCROLL_LEFT:
787  panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() + 1.0/360.0);
788  break;
789  }
790  return true;
791 }
792 
793 void
795 {
796  /* cartesian coordinate space:
797  center = 0.0
798  dimension = 2.0 * 2.0
799  increasing y moves up
800  so max values along each axis are -1..+1
801 
802  GTK uses a coordinate space that is:
803  top left = 0.0
804  dimension = (radius*2.0) * (radius*2.0)
805  increasing y moves down
806  */
807  const double diameter = radius*2.0;
808 
809  c.x = diameter * ((c.x + 1.0) / 2.0);
810  /* extra subtraction inverts the y-axis to match "increasing y moves down" */
811  c.y = diameter - (diameter * ((c.y + 1.0) / 2.0));
812 }
813 
814 void
816 {
817  const double diameter = radius*2.0;
818  c.x = ((c.x / diameter) * 2.0) - 1.0;
819  c.y = (((diameter - c.y) / diameter) * 2.0) - 1.0;
820 }
821 
822 void
823 Panner2d::sphere_project (double& x, double& y, double& z)
824 {
825  double r, r2;
826  r2 = x * x + y * y;
827  if (r2 < 1.0) {
828  z = sqrt (1.0 - r2);
829  } else {
830  r = sqrt (r2);
831  x = x / r;
832  y = y / r;
833  z = 0.0;
834  }
835 }
836 
837 void
838 Panner2d::clamp_to_circle (double& x, double& y)
839 {
840  double azi, ele;
841  double z = 0.0;
842  double l;
843  PBD::cartesian_to_spherical (x, y, z, azi, ele, l);
844  PBD::spherical_to_cartesian (azi, ele, 1.0, x, y, z);
845 }
846 
847 void
849 {
851 }
852 
854  : ArdourWindow (_("Panner (2D)"))
855  , widget (p, h)
856  , bypass_button (_("Bypass"))
857  , width_adjustment (0, -100, 100, 1, 5, 0)
858  , width_spinner (width_adjustment)
859 {
860  widget.set_name ("MixerPanZone");
861 
862  set_title (_("Panner"));
863  widget.set_size_request (h, h);
864 
865  bypass_button.signal_toggled().connect (sigc::mem_fun (*this, &Panner2dWindow::bypass_toggled));
866  width_spinner.signal_changed().connect (sigc::mem_fun (*this, &Panner2dWindow::width_changed));
867 
868  p->Changed.connect (panshell_connections, invalidator (*this), boost::bind (&Panner2dWindow::set_bypassed, this), gui_context());
869  /* needed for the width-spinbox in the main window */
871  p->pannable()->pan_width_control->Changed.connect (panvalue_connections, invalidator(*this), boost::bind (&Panner2dWindow::set_width, this), gui_context());
872 
873 
874  button_box.set_spacing (6);
875  button_box.pack_start (bypass_button, false, false);
876 
877  left_side.set_spacing (6);
878 
879  left_side.pack_start (button_box, false, false);
880 
881  Gtk::Label* l = manage (new Label (
882  p->panner()->describe_parameter(PanWidthAutomation),
883  Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
884  spinner_box.pack_start (*l, false, false);
885  spinner_box.pack_start (width_spinner, false, false);
886  left_side.pack_start (spinner_box, false, false);
887 
888  l->show ();
889  bypass_button.show ();
890  button_box.show ();
891  width_spinner.show ();
892  spinner_box.show ();
893  left_side.show ();
894 
895  hpacker.set_spacing (6);
896  hpacker.set_border_width (12);
897  hpacker.pack_start (widget, false, false);
898  hpacker.pack_start (left_side, false, false);
899  hpacker.show ();
900 
901  add (hpacker);
902  reset (inputs);
903  set_width();
904  set_bypassed();
905  widget.show ();
906 }
907 
908 void
909 Panner2dWindow::reset (uint32_t n_inputs)
910 {
911  widget.reset (n_inputs);
912 }
913 
914 void
916 {
917  bool view = bypass_button.get_active ();
918  bool model = widget.get_panner_shell()->bypassed ();
919 
920  if (model != view) {
922  }
923 }
924 void
926 {
927  float model = widget.get_panner_shell()->pannable()->pan_width_control->get_value();
928  float view = width_spinner.get_value() / 100.0;
929  if (model != view) {
930  widget.get_panner_shell()->panner()->set_width (view);
931  }
932 }
933 
934 void
936 {
938  widget.get_panner_shell()->pannable()->pan_width_control->Changed.connect (panvalue_connections, invalidator(*this), boost::bind (&Panner2dWindow::set_width, this), gui_context());
939  set_width();
940 }
941 
942 void
944 {
945  bool view = bypass_button.get_active ();
946  bool model = widget.get_panner_shell()->bypassed ();
947  if (model != view) {
948  bypass_button.set_active(model);
949  }
950 
951  set<Evoral::Parameter> params = widget.get_panner_shell()->panner()->what_can_be_automated();
952  set<Evoral::Parameter>::iterator p = params.find(PanWidthAutomation);
953  if (p == params.end()) {
954  spinner_box.set_sensitive(false);
955  } else {
956  spinner_box.set_sensitive(true);
957  }
958 }
959 
960 void
962 {
963  // rounding of spinbox is different from slider -- TODO use slider
964  float model = (widget.get_panner_shell()->pannable()->pan_width_control->get_value() * 100.0);
965  float view = (width_spinner.get_value());
966  if (model != view) {
967  width_spinner.set_value (model);
968  }
969 }
970 
971 bool
973 {
974  return relay_key_press (event, &PublicEditor::instance());
975 }
976 
977 bool
979 {
980  return true;
981 }
bool relay_key_press(GdkEventKey *ev, Gtk::Window *win)
Definition: utils.cc:301
void set_bypassed(bool)
Targets speakers
Definition: panner2d.h:107
bool on_key_press_event(GdkEventKey *)
Definition: panner2d.cc:972
bool on_button_release_event(GdkEventButton *)
Definition: panner2d.cc:678
std::string text
Definition: panner2d.h:86
bool bypassed() const
PBD::ScopedConnectionList panshell_connections
Definition: panner2d.h:161
Gtk::HBox hpacker
Definition: panner2d.h:152
void handle_state_change()
Definition: panner2d.cc:207
void pannable_handler()
Definition: panner2d.cc:935
void set_selected(bool yn)
Definition: panner2d.h:92
double hoffset
Definition: panner2d.h:116
Gtk::SpinButton width_spinner
Definition: panner2d.h:159
PBD::Signal0< void > PannableChanged
Definition: panner_shell.h:67
Definition: ardour_ui.h:130
void toggle_bypass()
Definition: panner2d.cc:848
void reset(uint32_t n_inputs)
Definition: panner2d.cc:103
void bypass_toggled()
Definition: panner2d.cc:915
void sphere_project(double &x, double &y, double &z)
Definition: panner2d.cc:823
PBD::ScopedConnectionList panvalue_connections
Definition: panner2d.h:162
~Panner2d()
Definition: panner2d.cc:95
Target position
Definition: panner2d.h:109
double radius
Definition: panner2d.h:114
int height
Definition: panner2d.h:113
Definition: Beats.hpp:239
void reset(uint32_t n_inputs)
Definition: panner2d.cc:909
bool did_move
Definition: panner2d.h:119
void set_width()
Definition: panner2d.cc:961
void cartesian(CartesianVector &c) const
Definition: cartesian.h:95
static const int large_size_threshold
Definition: panner2d.cc:54
Target * find_closest_object(gdouble x, gdouble y, bool &is_signal)
Definition: panner2d.cc:295
#define invalidator(x)
Definition: gui_thread.h:40
Panner2d(boost::shared_ptr< ARDOUR::PannerShell >, int32_t height)
Definition: panner2d.cc:75
static const int small_border_width
Definition: panner2d.cc:56
PBD::ScopedConnectionList panshell_connections
Definition: panner2d.h:132
PBD::AngularVector position
Definition: panner2d.h:84
#define _(Text)
Definition: i18n.h:11
static const int large_border_width
Definition: panner2d.cc:55
int add_signal(const char *text, const PBD::AngularVector &)
Definition: panner2d.cc:186
LIBGTKMM2EXT_API uint64_t Keyboard
Definition: debug.cc:23
Target * drag_target
Definition: panner2d.h:111
void angular(AngularVector &a) const
Definition: cartesian.h:100
void set_text(const char *)
Definition: panner2d.cc:70
boost::shared_ptr< ARDOUR::PannerShell > get_panner_shell() const
Definition: panner2d.h:68
void cart_to_gtk(PBD::CartesianVector &) const
Definition: panner2d.cc:794
Definition: amp.h:29
Target(const PBD::AngularVector &, const char *txt=0)
Definition: panner2d.cc:58
Panner2dWindow(boost::shared_ptr< ARDOUR::PannerShell >, int32_t height, uint32_t inputs)
Definition: panner2d.cc:853
void label_signals()
Definition: panner2d.cc:227
#define gui_context()
Definition: gui_thread.h:36
Gtk::VBox left_side
Definition: panner2d.h:156
void handle_position_change()
Definition: panner2d.cc:255
Panner2d widget
Definition: panner2d.h:150
int add_speaker(const PBD::AngularVector &)
Definition: panner2d.cc:196
gint handle_motion(gint, gint, GdkModifierType)
Definition: panner2d.cc:717
double border
Definition: panner2d.h:115
LIBPBD_API void cartesian_to_spherical(double x, double y, double z, double &azi, double &ele, double &len)
Definition: cartesian.cc:42
boost::shared_ptr< ARDOUR::PannerShell > panner_shell
Definition: panner2d.h:103
bool on_button_press_event(GdkEventButton *)
Definition: panner2d.cc:638
bool have_elevation
Definition: panner2d.h:120
static PublicEditor & instance()
bool on_expose_event(GdkEventExpose *)
Definition: panner2d.cc:417
void set_send_drawing_mode(bool)
Definition: panner2d.cc:387
void width_changed()
Definition: panner2d.cc:925
Gtk::ToggleButton bypass_button
Definition: panner2d.h:154
void gtk_to_cart(PBD::CartesianVector &) const
Definition: panner2d.cc:815
PBD::Signal0< void > Changed
Definition: panner_shell.h:68
bool _send_mode
Definition: panner2d.h:121
bool on_motion_notify_event(GdkEventMotion *)
Definition: panner2d.cc:396
void on_size_allocate(Gtk::Allocation &alloc)
Definition: panner2d.cc:160
LIBARDOUR_API PBD::PropertyDescriptor< framepos_t > position
Definition: region.cc:65
static UIConfiguration * config()
Definition: ardour_ui.h:188
void set_bypassed()
Definition: panner2d.cc:943
bool on_key_release_event(GdkEventKey *)
Definition: panner2d.cc:978
Definition: debug.h:30
double last_width
Definition: panner2d.h:118
#define S_(Text)
Definition: i18n.h:18
LIBPBD_API void spherical_to_cartesian(double azi, double ele, double len, double &x, double &y, double &z)
Definition: cartesian.cc:26
boost::shared_ptr< Pannable > pannable() const
Definition: panner_shell.h:71
void move_signal(int which, const PBD::AngularVector &)
Definition: panner2d.cc:284
PBD::ScopedConnectionList panner_connections
Definition: panner2d.h:133
boost::shared_ptr< Panner > panner() const
Definition: panner_shell.h:70
double voffset
Definition: panner2d.h:117
Gtk::VBox spinner_box
Definition: panner2d.h:155
Gtk::VBox button_box
Definition: panner2d.h:153
int width
Definition: panner2d.h:112
bool on_scroll_event(GdkEventScroll *)
Definition: panner2d.cc:777
void clamp_to_circle(double &x, double &y)
Definition: panner2d.cc:838
def signal
Definition: signals.py:53
LIBARDOUR_API PBD::PropertyDescriptor< bool > color
Definition: route_group.cc:50