2011-02-16 23:45:49 -05:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2011-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2011-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2011 David Robillard <d@drobilla.net>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
#include "pbd/cartesian.h"
|
|
|
|
|
|
|
|
#include "gtkmm2ext/keyboard.h"
|
|
|
|
|
|
|
|
#include "speaker_dialog.h"
|
2011-03-04 12:35:02 -05:00
|
|
|
#include "gui_thread.h"
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
|
|
|
|
SpeakerDialog::SpeakerDialog ()
|
2017-07-01 12:42:24 -04:00
|
|
|
: ArdourWindow (_("Speaker Configuration"))
|
2017-09-18 14:45:56 -04:00
|
|
|
, aspect_frame ("", 0.5, 0.5, 1.5, false)
|
2017-07-01 12:42:24 -04:00
|
|
|
, azimuth_adjustment (0, 0.0, 360.0, 10.0, 1.0)
|
|
|
|
, azimuth_spinner (azimuth_adjustment)
|
|
|
|
, add_speaker_button (_("Add Speaker"))
|
2011-03-04 12:35:02 -05:00
|
|
|
, remove_speaker_button (_("Remove Speaker"))
|
|
|
|
/* initialize to 0 so that set_selected works below */
|
|
|
|
, selected_index (0)
|
|
|
|
, ignore_speaker_position_change (false)
|
|
|
|
, ignore_azimuth_change (false)
|
2011-02-16 23:45:49 -05:00
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
side_vbox.set_homogeneous (false);
|
|
|
|
side_vbox.set_border_width (6);
|
|
|
|
side_vbox.set_spacing (6);
|
|
|
|
side_vbox.pack_start (add_speaker_button, false, false);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2017-09-18 14:45:56 -04:00
|
|
|
aspect_frame.set_size_request (300, 200);
|
|
|
|
aspect_frame.set_shadow_type (SHADOW_NONE);
|
|
|
|
aspect_frame.add (darea);
|
2011-02-17 11:43:55 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
hbox.set_spacing (6);
|
|
|
|
hbox.set_border_width (6);
|
2017-09-18 14:45:56 -04:00
|
|
|
hbox.pack_start (aspect_frame, true, true);
|
2017-07-01 12:42:24 -04:00
|
|
|
hbox.pack_start (side_vbox, false, false);
|
2011-03-04 12:35:02 -05:00
|
|
|
|
|
|
|
HBox* current_speaker_hbox = manage (new HBox);
|
|
|
|
current_speaker_hbox->set_spacing (4);
|
|
|
|
current_speaker_hbox->pack_start (*manage (new Label (_("Azimuth:"))), false, false);
|
|
|
|
current_speaker_hbox->pack_start (azimuth_spinner, true, true);
|
|
|
|
current_speaker_hbox->pack_start (remove_speaker_button, true, true);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
VBox* vbox = manage (new VBox);
|
|
|
|
vbox->pack_start (hbox);
|
|
|
|
vbox->pack_start (*current_speaker_hbox, true, true);
|
|
|
|
vbox->show_all ();
|
|
|
|
add (*vbox);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
|
2011-02-17 11:43:55 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
darea.signal_size_allocate().connect (sigc::mem_fun (*this, &SpeakerDialog::darea_size_allocate));
|
|
|
|
darea.signal_expose_event().connect (sigc::mem_fun (*this, &SpeakerDialog::darea_expose_event));
|
|
|
|
darea.signal_button_press_event().connect (sigc::mem_fun (*this, &SpeakerDialog::darea_button_press_event));
|
|
|
|
darea.signal_button_release_event().connect (sigc::mem_fun (*this, &SpeakerDialog::darea_button_release_event));
|
|
|
|
darea.signal_motion_notify_event().connect (sigc::mem_fun (*this, &SpeakerDialog::darea_motion_notify_event));
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2011-03-04 12:34:42 -05:00
|
|
|
add_speaker_button.signal_clicked().connect (sigc::mem_fun (*this, &SpeakerDialog::add_speaker));
|
2011-03-04 12:35:02 -05:00
|
|
|
remove_speaker_button.signal_clicked().connect (sigc::mem_fun (*this, &SpeakerDialog::remove_speaker));
|
|
|
|
azimuth_adjustment.signal_value_changed().connect (sigc::mem_fun (*this, &SpeakerDialog::azimuth_changed));
|
2011-03-04 12:34:42 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
drag_index = -1;
|
2011-03-04 12:35:02 -05:00
|
|
|
|
|
|
|
/* selected index initialised to 0 above; this will set `no selection' and
|
|
|
|
sensitize widgets accordingly.
|
|
|
|
*/
|
|
|
|
set_selected (-1);
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
SpeakerDialog::set_speakers (std::shared_ptr<Speakers> s)
|
2011-02-16 23:45:49 -05:00
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
_speakers = s;
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers>
|
2011-02-16 23:45:49 -05:00
|
|
|
SpeakerDialog::get_speakers () const
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
return _speakers.lock ();
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpeakerDialog::darea_expose_event (GdkEventExpose* event)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
gint x, y;
|
|
|
|
cairo_t* cr;
|
|
|
|
|
|
|
|
cr = gdk_cairo_create (darea.get_window()->gobj());
|
|
|
|
|
|
|
|
cairo_set_line_width (cr, 1.0);
|
|
|
|
|
|
|
|
cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height);
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 1.0);
|
2011-02-16 23:45:49 -05:00
|
|
|
cairo_fill_preserve (cr);
|
|
|
|
cairo_clip (cr);
|
|
|
|
|
2011-03-04 12:34:50 -05:00
|
|
|
cairo_translate (cr, x_origin, y_origin);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
/* horizontal line of "crosshairs" */
|
|
|
|
|
|
|
|
cairo_set_source_rgb (cr, 0.0, 0.1, 0.7);
|
|
|
|
cairo_move_to (cr, 0.5, height/2.0+0.5);
|
|
|
|
cairo_line_to (cr, width+0.5, height/2+0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
/* vertical line of "crosshairs" */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
cairo_move_to (cr, width/2+0.5, 0.5);
|
|
|
|
cairo_line_to (cr, width/2+0.5, height+0.5);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
/* the circle on which signals live */
|
|
|
|
|
|
|
|
cairo_arc (cr, width/2, height/2, height/2, 0, 2.0 * M_PI);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
float arc_radius;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_select_font_face (cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
if (height < 100) {
|
|
|
|
cairo_set_font_size (cr, 10);
|
|
|
|
arc_radius = 2.0;
|
|
|
|
} else {
|
|
|
|
cairo_set_font_size (cr, 16);
|
|
|
|
arc_radius = 4.0;
|
|
|
|
}
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
int n = 0;
|
|
|
|
for (vector<Speaker>::iterator i = speakers->speakers().begin(); i != speakers->speakers().end(); ++i) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
Speaker& s (*i);
|
|
|
|
CartesianVector c (s.coords());
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
cart_to_gtk (c);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2012-06-03 11:25:21 -04:00
|
|
|
/* We have already moved our plotting origin to x_origin, y_origin,
|
|
|
|
so compensate for that.
|
|
|
|
*/
|
|
|
|
c.x -= x_origin;
|
|
|
|
c.y -= y_origin;
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
x = (gint) floor (c.x);
|
|
|
|
y = (gint) floor (c.y);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
/* XXX need to shift circles so that they are centered on the circle */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_arc (cr, x, y, arc_radius, 0, 2.0 * M_PI);
|
2011-03-04 12:35:02 -05:00
|
|
|
if (selected_index == n) {
|
|
|
|
cairo_set_source_rgb (cr, 0.8, 0.8, 0.2);
|
|
|
|
} else {
|
|
|
|
cairo_set_source_rgb (cr, 0.8, 0.2, 0.1);
|
|
|
|
}
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_close_path (cr);
|
|
|
|
cairo_fill (cr);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_move_to (cr, x + 6, y + 6);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
char buf[256];
|
2012-06-03 11:25:21 -04:00
|
|
|
if (n == selected_index) {
|
|
|
|
snprintf (buf, sizeof (buf), "%d:%d", n+1, (int) lrint (s.angles().azi));
|
|
|
|
} else {
|
|
|
|
snprintf (buf, sizeof (buf), "%d", n + 1);
|
|
|
|
}
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_show_text (cr, buf);
|
|
|
|
++n;
|
|
|
|
}
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_destroy (cr);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
return true;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::cart_to_gtk (CartesianVector& c) const
|
|
|
|
{
|
|
|
|
/* "c" uses a coordinate space that is:
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
center = 0.0
|
|
|
|
dimension = 2.0 * 2.0
|
|
|
|
so max values along each axis are -1..+1
|
|
|
|
|
|
|
|
GTK uses a coordinate space that is:
|
|
|
|
|
|
|
|
top left = 0.0
|
|
|
|
dimension = width * height
|
|
|
|
so max values along each axis are 0,width and
|
|
|
|
0,height
|
|
|
|
*/
|
|
|
|
|
2012-06-03 11:25:21 -04:00
|
|
|
c.x = (width / 2) * (c.x + 1) + x_origin;
|
|
|
|
c.y = (height / 2) * (1 - c.y) + y_origin;
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
/* XXX z-axis not handled - 2D for now */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::gtk_to_cart (CartesianVector& c) const
|
|
|
|
{
|
2012-06-03 11:25:21 -04:00
|
|
|
c.x = ((c.x - x_origin) / (width / 2.0)) - 1.0;
|
|
|
|
c.y = -(((c.y - y_origin) / (height / 2.0)) - 1.0);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
/* XXX z-axis not handled - 2D for now */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::clamp_to_circle (double& x, double& y)
|
|
|
|
{
|
|
|
|
double azi, ele;
|
|
|
|
double z = 0.0;
|
2017-07-01 12:42:24 -04:00
|
|
|
double l;
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2011-02-24 13:55:33 -05:00
|
|
|
PBD::cartesian_to_spherical (x, y, z, azi, ele, l);
|
|
|
|
PBD::spherical_to_cartesian (azi, ele, 1.0, x, y, z);
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::darea_size_allocate (Gtk::Allocation& alloc)
|
|
|
|
{
|
2019-04-13 11:48:27 -04:00
|
|
|
width = alloc.get_width();
|
|
|
|
height = alloc.get_height();
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2012-06-03 11:25:21 -04:00
|
|
|
/* The allocation will (should) be rectangualar, but make the basic
|
2019-04-13 11:48:27 -04:00
|
|
|
* drawing square; space to the right of the square is for over-hanging
|
|
|
|
* text labels.
|
|
|
|
*/
|
2012-06-03 11:25:21 -04:00
|
|
|
width = height;
|
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
if (height > 100) {
|
|
|
|
width -= 20;
|
|
|
|
height -= 20;
|
|
|
|
}
|
2011-03-04 12:34:50 -05:00
|
|
|
|
2012-06-03 11:25:21 -04:00
|
|
|
/* Put the x origin to the left of the rectangular allocation */
|
|
|
|
x_origin = (alloc.get_width() - width) / 3;
|
2011-03-04 12:34:50 -05:00
|
|
|
y_origin = (alloc.get_height() - height) / 2;
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpeakerDialog::darea_button_press_event (GdkEventButton *ev)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
GdkModifierType state;
|
|
|
|
|
|
|
|
if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
drag_index = -1;
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
2011-03-04 12:34:50 -05:00
|
|
|
{
|
2011-03-04 12:35:02 -05:00
|
|
|
int const index = find_closest_object (ev->x, ev->y);
|
|
|
|
set_selected (index);
|
|
|
|
|
|
|
|
drag_index = index;
|
2011-03-04 12:34:50 -05:00
|
|
|
int const drag_x = (int) floor (ev->x);
|
|
|
|
int const drag_y = (int) floor (ev->y);
|
2011-02-16 23:45:49 -05:00
|
|
|
state = (GdkModifierType) ev->state;
|
|
|
|
|
2011-03-04 12:34:50 -05:00
|
|
|
if (drag_index >= 0) {
|
|
|
|
CartesianVector c;
|
2011-03-04 12:35:02 -05:00
|
|
|
speakers->speakers()[drag_index].angles().cartesian (c);
|
2011-03-04 12:34:50 -05:00
|
|
|
cart_to_gtk (c);
|
|
|
|
drag_offset_x = drag_x - x_origin - c.x;
|
|
|
|
drag_offset_y = drag_y - y_origin - c.y;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
return handle_motion (drag_x, drag_y, state);
|
|
|
|
break;
|
2011-03-04 12:34:50 -05:00
|
|
|
}
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpeakerDialog::darea_button_release_event (GdkEventButton *ev)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
gint x, y;
|
|
|
|
GdkModifierType state;
|
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
|
|
|
x = (int) floor (ev->x);
|
|
|
|
y = (int) floor (ev->y);
|
|
|
|
state = (GdkModifierType) ev->state;
|
|
|
|
|
|
|
|
if (Keyboard::modifier_state_contains (state, Keyboard::TertiaryModifier)) {
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
for (vector<Speaker>::iterator i = speakers->speakers().begin(); i != speakers->speakers().end(); ++i) {
|
2011-02-16 23:45:49 -05:00
|
|
|
/* XXX DO SOMETHING TO SET SPEAKER BACK TO "normal" */
|
|
|
|
}
|
|
|
|
|
|
|
|
queue_draw ();
|
|
|
|
ret = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ret = handle_motion (x, y, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
x = (int) floor (ev->x);
|
|
|
|
y = (int) floor (ev->y);
|
|
|
|
state = (GdkModifierType) ev->state;
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
ret = handle_motion (x, y, state);
|
2011-02-16 23:45:49 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
drag_index = -1;
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-01 13:00:29 -04:00
|
|
|
SpeakerDialog::find_closest_object (gdouble x, gdouble y)
|
2011-02-16 23:45:49 -05:00
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
float distance;
|
|
|
|
float best_distance = FLT_MAX;
|
2011-02-17 11:43:55 -05:00
|
|
|
int n = 0;
|
2017-07-01 12:42:24 -04:00
|
|
|
int which = -1;
|
2011-02-16 23:45:49 -05:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
for (vector<Speaker>::iterator i = speakers->speakers().begin(); i != speakers->speakers().end(); ++i, ++n) {
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
Speaker& candidate (*i);
|
|
|
|
CartesianVector c;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
candidate.angles().cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
|
|
|
|
|
|
|
distance = sqrt ((c.x - x) * (c.x - x) +
|
|
|
|
(c.y - y) * (c.y - y));
|
|
|
|
|
2011-02-17 11:43:55 -05:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
if (distance < best_distance) {
|
|
|
|
best_distance = distance;
|
2011-02-17 11:43:55 -05:00
|
|
|
which = n;
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-01 13:00:29 -04:00
|
|
|
if (best_distance > 20) { // arbitrary
|
2017-07-01 12:42:24 -04:00
|
|
|
return -1;
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
return which;
|
2011-02-16 23:45:49 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpeakerDialog::darea_motion_notify_event (GdkEventMotion *ev)
|
|
|
|
{
|
|
|
|
gint x, y;
|
|
|
|
GdkModifierType state;
|
|
|
|
|
|
|
|
if (ev->is_hint) {
|
|
|
|
gdk_window_get_pointer (ev->window, &x, &y, &state);
|
|
|
|
} else {
|
|
|
|
x = (int) floor (ev->x);
|
|
|
|
y = (int) floor (ev->y);
|
|
|
|
state = (GdkModifierType) ev->state;
|
|
|
|
}
|
|
|
|
|
|
|
|
return handle_motion (x, y, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SpeakerDialog::handle_motion (gint evx, gint evy, GdkModifierType state)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
if (drag_index < 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((state & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK)) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-03-04 12:34:50 -05:00
|
|
|
/* correct event coordinates to have their origin at the corner of our graphic
|
|
|
|
rather than the corner of our allocation */
|
|
|
|
|
|
|
|
double obx = evx - x_origin;
|
|
|
|
double oby = evy - y_origin;
|
|
|
|
|
|
|
|
/* and compensate for any distance between the mouse pointer and the centre
|
|
|
|
of the object being dragged */
|
|
|
|
|
|
|
|
obx -= drag_offset_x;
|
|
|
|
oby -= drag_offset_y;
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
if (state & GDK_BUTTON1_MASK && !(state & GDK_BUTTON2_MASK)) {
|
|
|
|
CartesianVector c;
|
|
|
|
bool need_move = false;
|
2017-07-01 12:42:24 -04:00
|
|
|
Speaker& moving (speakers->speakers()[drag_index]);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
moving.angles().cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
|
|
|
|
2011-03-04 12:34:50 -05:00
|
|
|
if (obx != c.x || oby != c.y) {
|
2011-02-16 23:45:49 -05:00
|
|
|
need_move = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_move) {
|
2011-03-04 12:34:50 -05:00
|
|
|
CartesianVector cp (obx, oby, 0.0);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
/* canonicalize position */
|
|
|
|
|
|
|
|
gtk_to_cart (cp);
|
|
|
|
|
|
|
|
/* position actual signal on circle */
|
|
|
|
|
|
|
|
clamp_to_circle (cp.x, cp.y);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
/* generate an angular representation and set drag target (GUI) position */
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
AngularVector a;
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
cp.angular (a);
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
moving.move (a);
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
queue_draw ();
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
}
|
2011-02-16 23:45:49 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2011-03-04 12:34:42 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::add_speaker ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
speakers->add_speaker (PBD::AngularVector (0, 0, 0));
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::set_selected (int i)
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
if (i == selected_index) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
selected_index = i;
|
|
|
|
queue_draw ();
|
|
|
|
|
|
|
|
selected_speaker_connection.disconnect ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
azimuth_spinner.set_sensitive (selected_index != -1);
|
|
|
|
remove_speaker_button.set_sensitive (selected_index != -1);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
if (selected_index != -1) {
|
|
|
|
azimuth_adjustment.set_value (speakers->speakers()[selected_index].angles().azi);
|
|
|
|
speakers->speakers()[selected_index].PositionChanged.connect (
|
|
|
|
selected_speaker_connection, MISSING_INVALIDATOR,
|
|
|
|
boost::bind (&SpeakerDialog::speaker_position_changed, this),
|
|
|
|
gui_context ()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::azimuth_changed ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (selected_index != -1);
|
|
|
|
|
|
|
|
if (ignore_azimuth_change) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
ignore_speaker_position_change = true;
|
|
|
|
speakers->move_speaker (speakers->speakers()[selected_index].id, PBD::AngularVector (azimuth_adjustment.get_value (), 0, 0));
|
|
|
|
ignore_speaker_position_change = false;
|
|
|
|
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SpeakerDialog::speaker_position_changed ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
assert (selected_index != -1);
|
|
|
|
|
|
|
|
if (ignore_speaker_position_change) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
ignore_azimuth_change = true;
|
|
|
|
azimuth_adjustment.set_value (speakers->speakers()[selected_index].angles().azi);
|
|
|
|
ignore_azimuth_change = false;
|
|
|
|
|
|
|
|
queue_draw ();
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
void
|
|
|
|
SpeakerDialog::remove_speaker ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Speakers> speakers = _speakers.lock ();
|
2011-03-04 12:35:02 -05:00
|
|
|
if (!speakers) {
|
|
|
|
return;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:35:02 -05:00
|
|
|
assert (selected_index != -1);
|
|
|
|
|
|
|
|
speakers->remove_speaker (speakers->speakers()[selected_index].id);
|
|
|
|
set_selected (-1);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-04 12:34:42 -05:00
|
|
|
queue_draw ();
|
|
|
|
}
|