2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2019-08-02 17:26:43 -04:00
|
|
|
* Copyright (C) 2005-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
|
|
|
|
* Copyright (C) 2008-2011 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2010-2011 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <climits>
|
2008-12-13 10:18:32 -05:00
|
|
|
#include <string.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
#include <cairo.h>
|
2005-11-28 23:41:15 -05:00
|
|
|
#include <gtkmm/menu.h>
|
|
|
|
|
2011-02-17 13:54:13 -05:00
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/error.h"
|
2010-11-23 11:38:17 -05:00
|
|
|
#include "pbd/cartesian.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/panner.h"
|
2011-07-14 18:17:43 -04:00
|
|
|
#include "ardour/panner_shell.h"
|
2011-02-17 15:15:26 -05:00
|
|
|
#include "ardour/pannable.h"
|
2011-02-17 14:47:53 -05:00
|
|
|
#include "ardour/speakers.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2017-07-17 12:34:35 -04:00
|
|
|
#include "gtkmm2ext/colors.h"
|
2014-12-08 10:13:27 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "panner2d.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "gui_thread.h"
|
2015-08-08 11:33:18 -04:00
|
|
|
#include "rgb_macros.h"
|
2011-02-23 23:28:48 -05:00
|
|
|
#include "utils.h"
|
|
|
|
#include "public_editor.h"
|
2015-01-02 09:44:54 -05:00
|
|
|
#include "ui_config.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace ARDOUR;
|
2014-06-25 15:27:37 -04:00
|
|
|
using namespace ARDOUR_UI_UTILS;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2009-12-04 17:51:32 -05:00
|
|
|
using Gtkmm2ext::Keyboard;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2015-08-08 11:33:18 -04:00
|
|
|
Panner2d::ColorScheme Panner2d::colors;
|
|
|
|
bool Panner2d::have_colors = false;
|
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
static const int large_size_threshold = 100;
|
|
|
|
static const int large_border_width = 25;
|
|
|
|
static const int small_border_width = 8;
|
|
|
|
|
2010-11-26 12:43:03 -05:00
|
|
|
Panner2d::Target::Target (const AngularVector& a, const char *txt)
|
|
|
|
: position (a)
|
2010-11-23 11:38:17 -05:00
|
|
|
, text (txt)
|
2010-11-26 14:57:03 -05:00
|
|
|
, _selected (false)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Panner2d::Target::~Target ()
|
2009-10-14 12:10:01 -04:00
|
|
|
{
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
void
|
|
|
|
Panner2d::Target::set_text (const char* txt)
|
|
|
|
{
|
2010-11-23 11:38:17 -05:00
|
|
|
text = txt;
|
2008-12-13 10:18:32 -05:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
Panner2d::Panner2d (std::shared_ptr<PannerShell> p, int32_t h)
|
2014-01-14 15:11:41 -05:00
|
|
|
: panner_shell (p)
|
|
|
|
, position (AngularVector (0.0, 0.0), "")
|
|
|
|
, width (0)
|
|
|
|
, height (h)
|
|
|
|
, last_width (0)
|
|
|
|
, have_elevation (false)
|
2014-06-17 09:51:49 -04:00
|
|
|
, _send_mode (false)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2015-08-08 11:33:18 -04:00
|
|
|
if (!have_colors) {
|
|
|
|
set_colors ();
|
|
|
|
have_colors = true;
|
|
|
|
}
|
|
|
|
|
2015-01-02 09:44:54 -05:00
|
|
|
UIConfiguration::instance().ColorsChanged.connect (sigc::mem_fun (*this, &Panner2d::color_handler));
|
2015-08-08 11:33:18 -04:00
|
|
|
|
2024-10-18 19:51:44 -04:00
|
|
|
panner_shell->Changed.connect (panshell_connections, invalidator (*this), std::bind (&Panner2d::handle_state_change, this), gui_context());
|
2011-02-17 15:15:26 -05:00
|
|
|
|
2024-10-18 19:51:44 -04:00
|
|
|
panner_shell->panner()->SignalPositionChanged.connect (panner_connections, invalidator(*this), std::bind (&Panner2d::handle_position_change, this), gui_context());
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
drag_target = 0;
|
2005-09-25 16:33:00 -04:00
|
|
|
set_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::POINTER_MOTION_MASK);
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2014-01-11 21:56:35 -05:00
|
|
|
handle_state_change ();
|
2014-01-11 17:30:01 -05:00
|
|
|
handle_position_change ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Panner2d::~Panner2d()
|
|
|
|
{
|
2011-03-01 16:52:59 -05:00
|
|
|
for (Targets::iterator i = speakers.begin(); i != speakers.end(); ++i) {
|
2010-08-07 19:30:37 -04:00
|
|
|
delete *i;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2017-01-20 05:54:02 -05:00
|
|
|
for (Targets::iterator i = signals.begin(); i != signals.end(); ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2015-08-08 11:33:18 -04:00
|
|
|
void
|
|
|
|
Panner2d::set_colors ()
|
|
|
|
{
|
|
|
|
// TODO get all colors from theme, resolve dups
|
2015-01-02 09:44:54 -05:00
|
|
|
colors.background = UIConfiguration::instance().color ("mono panner bg");
|
2015-08-08 11:33:18 -04:00
|
|
|
colors.crosshairs = 0x4884a9ff; // 0.282, 0.517, 0.662, 1.0
|
|
|
|
colors.signalcircle_border = 0x84c5e1ff; // 0.517, 0.772, 0.882, 1.0
|
|
|
|
colors.signalcircle = 0x4884a9ff; // 0.282, 0.517, 0.662, 1.0 // also used with a = 0.9
|
|
|
|
colors.diffusion = 0x4884a973; // 0.282, 0.517, 0.662, 0.45
|
|
|
|
colors.diffusion_inv = 0xff6b6b73; // 1.0, 0.419, 0.419, 0.45
|
|
|
|
colors.pos_outline = 0xffe7e7d9; // 1.0, 0.905, 0.905, 0.85
|
|
|
|
colors.pos_fill = 0xff6b6bd9; // 1.0, 0.419, 0.419, 0.85
|
|
|
|
colors.signal_outline = 0x84c5e1cc; // 0.517, 0.772, 0.882, 0.8
|
|
|
|
colors.signal_fill = 0x4884a9bf; // 0.282, 0.517, 0.662, 0.75
|
|
|
|
colors.speaker_fill = 0x4884a9ff; // 0.282, 0.517, 0.662, 1.0
|
|
|
|
colors.text = 0x84c5e1e6; // 0.517, 0.772, 0.882, 0.9
|
2020-04-23 18:51:29 -04:00
|
|
|
|
|
|
|
colors.send_bg = UIConfiguration::instance().color ("send bg");
|
|
|
|
colors.send_pan = UIConfiguration::instance().color ("send pan");
|
2015-08-08 11:33:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Panner2d::color_handler ()
|
|
|
|
{
|
|
|
|
set_colors ();
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
|
|
|
Panner2d::reset (uint32_t n_inputs)
|
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
uint32_t nouts = panner_shell->panner()->out().n_audio();
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
/* signals */
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
while (signals.size() < n_inputs) {
|
|
|
|
add_signal ("", AngularVector());
|
2008-12-13 10:18:32 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (signals.size() > n_inputs) {
|
|
|
|
for (uint32_t i = signals.size(); i < n_inputs; ++i) {
|
|
|
|
delete signals[i];
|
2010-08-07 19:30:37 -04:00
|
|
|
}
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
signals.resize (n_inputs);
|
2010-08-07 19:30:37 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
label_signals ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
for (uint32_t i = 0; i < n_inputs; ++i) {
|
|
|
|
signals[i]->position = panner_shell->panner()->signal_position (i);
|
|
|
|
}
|
2010-05-01 21:33:25 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
/* add all outputs */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
while (speakers.size() < nouts) {
|
|
|
|
add_speaker (AngularVector());
|
2008-12-13 10:18:32 -05:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (speakers.size() > nouts) {
|
|
|
|
for (uint32_t i = nouts; i < speakers.size(); ++i) {
|
|
|
|
delete speakers[i];
|
2010-08-07 19:30:37 -04:00
|
|
|
}
|
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
speakers.resize (nouts);
|
2008-12-13 10:18:32 -05:00
|
|
|
}
|
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
for (Targets::iterator x = speakers.begin(); x != speakers.end(); ++x) {
|
2010-08-07 19:30:37 -04:00
|
|
|
(*x)->visible = false;
|
2008-12-13 10:18:32 -05:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
vector<Speaker>& the_speakers (panner_shell->panner()->get_speakers()->speakers());
|
2011-02-17 14:47:53 -05:00
|
|
|
|
2011-01-26 20:31:03 -05:00
|
|
|
for (uint32_t n = 0; n < nouts; ++n) {
|
2008-12-13 10:18:32 -05:00
|
|
|
char buf[16];
|
|
|
|
|
|
|
|
snprintf (buf, sizeof (buf), "%d", n+1);
|
2011-03-01 16:52:59 -05:00
|
|
|
speakers[n]->set_text (buf);
|
|
|
|
speakers[n]->position = the_speakers[n].angles();
|
|
|
|
speakers[n]->visible = true;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2006-06-20 14:50:38 -04:00
|
|
|
Panner2d::on_size_allocate (Gtk::Allocation& alloc)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
width = alloc.get_width();
|
|
|
|
height = alloc.get_height();
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (height > large_size_threshold) {
|
|
|
|
border = large_border_width;
|
|
|
|
} else {
|
|
|
|
border = small_border_width;
|
|
|
|
}
|
2011-02-17 13:54:13 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
radius = min (width, height);
|
|
|
|
radius -= border;
|
|
|
|
radius /= 2;
|
2014-01-15 03:37:20 -05:00
|
|
|
radius = rint(radius) + .5;
|
2011-03-01 16:52:59 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
hoffset = max ((double) (width - height), border);
|
|
|
|
voffset = max ((double) (height - width), border);
|
2011-03-01 16:52:59 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
hoffset = rint(hoffset / 2.0);
|
|
|
|
voffset = rint(voffset / 2.0);
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2005-09-25 22:48:59 -04:00
|
|
|
DrawingArea::on_size_allocate (alloc);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-03-01 16:52:59 -05:00
|
|
|
Panner2d::add_signal (const char* text, const AngularVector& a)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-03-01 16:52:59 -05:00
|
|
|
Target* signal = new Target (a, text);
|
|
|
|
signals.push_back (signal);
|
|
|
|
signal->visible = true;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-03-01 16:52:59 -05:00
|
|
|
Panner2d::add_speaker (const AngularVector& a)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-03-01 16:52:59 -05:00
|
|
|
Target* speaker = new Target (a, "");
|
|
|
|
speakers.push_back (speaker);
|
|
|
|
speaker->visible = true;
|
2005-09-25 14:42:24 -04:00
|
|
|
queue_draw ();
|
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
return speakers.size() - 1;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
Panner2d::handle_state_change ()
|
|
|
|
{
|
2014-01-14 17:08:34 -05:00
|
|
|
panner_connections.drop_connections();
|
2014-01-13 05:08:37 -05:00
|
|
|
if (!panner_shell->panner()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-10-18 19:51:44 -04:00
|
|
|
panner_shell->panner()->SignalPositionChanged.connect (panner_connections, invalidator(*this), std::bind (&Panner2d::handle_position_change, this), gui_context());
|
2014-01-11 21:56:35 -05:00
|
|
|
|
2020-03-20 22:43:21 -04:00
|
|
|
set<Evoral::Parameter> params = panner_shell->pannable()->what_can_be_automated();
|
2014-01-14 15:11:41 -05:00
|
|
|
set<Evoral::Parameter>::iterator p = params.find(PanElevationAutomation);
|
|
|
|
bool elev = have_elevation;
|
|
|
|
have_elevation = (p == params.end()) ? false : true;
|
|
|
|
if (elev != have_elevation) {
|
|
|
|
handle_position_change();
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
2011-02-24 22:20:47 -05:00
|
|
|
void
|
2011-03-01 16:52:59 -05:00
|
|
|
Panner2d::label_signals ()
|
2011-02-24 22:20:47 -05:00
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
uint32_t sz = signals.size();
|
2011-02-24 22:20:47 -05:00
|
|
|
|
|
|
|
switch (sz) {
|
2014-01-14 15:11:41 -05:00
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
signals[0]->set_text ("");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2015-04-04 18:17:53 -04:00
|
|
|
signals[0]->set_text (S_("Panner|L"));
|
|
|
|
signals[1]->set_text (S_("Panner|R"));
|
2014-01-14 15:11:41 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (uint32_t i = 0; i < sz; ++i) {
|
|
|
|
char buf[64];
|
|
|
|
snprintf (buf, sizeof (buf), "%" PRIu32, i + 1);
|
|
|
|
signals[i]->set_text (buf);
|
|
|
|
}
|
|
|
|
break;
|
2011-02-24 22:20:47 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
void
|
|
|
|
Panner2d::handle_position_change ()
|
|
|
|
{
|
|
|
|
uint32_t n;
|
2014-01-14 15:11:41 -05:00
|
|
|
double w = panner_shell->pannable()->pan_width_control->get_value();
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
position.position = AngularVector (panner_shell->pannable()->pan_azimuth_control->get_value() * 360.0,
|
|
|
|
panner_shell->pannable()->pan_elevation_control->get_value() * 90.0);
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
for (uint32_t i = 0; i < signals.size(); ++i) {
|
|
|
|
signals[i]->position = panner_shell->panner()->signal_position (i);
|
|
|
|
}
|
2011-02-17 15:15:26 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (w * last_width <= 0) {
|
|
|
|
/* changed sign */
|
|
|
|
label_signals ();
|
|
|
|
}
|
2011-02-24 22:20:47 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
last_width = w;
|
2011-02-24 22:20:47 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
vector<Speaker>& the_speakers (panner_shell->panner()->get_speakers()->speakers());
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
for (n = 0; n < speakers.size(); ++n) {
|
|
|
|
speakers[n]->position = the_speakers[n].angles();
|
2008-12-13 10:18:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
2011-03-01 16:52:59 -05:00
|
|
|
Panner2d::move_signal (int which, const AngularVector& a)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-03-01 16:52:59 -05:00
|
|
|
if (which >= int (speakers.size())) {
|
2010-08-07 19:30:37 -04:00
|
|
|
return;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
speakers[which]->position = a;
|
2010-08-07 19:30:37 -04:00
|
|
|
queue_draw ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Panner2d::Target *
|
2011-03-01 16:52:59 -05:00
|
|
|
Panner2d::find_closest_object (gdouble x, gdouble y, bool& is_signal)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
Target *closest = 0;
|
|
|
|
Target *candidate;
|
|
|
|
float distance;
|
|
|
|
float best_distance = FLT_MAX;
|
2014-01-14 15:11:41 -05:00
|
|
|
CartesianVector c;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
/* start with the position itself */
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
PBD::AngularVector dp = position.position;
|
|
|
|
if (!have_elevation) dp.ele = 0;
|
|
|
|
dp.azi = 270 - dp.azi;
|
|
|
|
dp.cartesian (c);
|
2014-01-15 03:37:20 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
cart_to_gtk (c);
|
|
|
|
best_distance = sqrt ((c.x - x) * (c.x - x) +
|
|
|
|
(c.y - y) * (c.y - y));
|
|
|
|
closest = &position;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-12 15:41:02 -05:00
|
|
|
#if 0 // TODO signal grab -> change width, not position
|
2011-03-01 16:52:59 -05:00
|
|
|
for (Targets::const_iterator i = signals.begin(); i != signals.end(); ++i) {
|
2010-08-07 19:30:37 -04:00
|
|
|
candidate = *i;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
candidate->position.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
2010-11-26 12:43:03 -05:00
|
|
|
|
|
|
|
distance = sqrt ((c.x - x) * (c.x - x) +
|
2014-01-14 15:11:41 -05:00
|
|
|
(c.y - y) * (c.y - y));
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (distance < best_distance) {
|
2005-09-25 14:42:24 -04:00
|
|
|
closest = candidate;
|
|
|
|
best_distance = distance;
|
|
|
|
}
|
|
|
|
}
|
2014-01-12 15:41:02 -05:00
|
|
|
#endif
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
is_signal = true;
|
|
|
|
|
|
|
|
if (height > large_size_threshold) {
|
|
|
|
/* "big" */
|
|
|
|
if (best_distance > 30) { // arbitrary
|
|
|
|
closest = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* "small" */
|
|
|
|
if (best_distance > 10) { // arbitrary
|
|
|
|
closest = 0;
|
|
|
|
}
|
|
|
|
}
|
2011-03-01 16:52:59 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
/* if we didn't find a signal close by, check the speakers */
|
2011-03-01 16:52:59 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (!closest) {
|
|
|
|
for (Targets::const_iterator i = speakers.begin(); i != speakers.end(); ++i) {
|
|
|
|
candidate = *i;
|
2017-07-01 12:42:24 -04:00
|
|
|
PBD::AngularVector sp = candidate->position;
|
|
|
|
sp.azi = 270 -sp.azi;
|
|
|
|
CartesianVector c;
|
|
|
|
sp.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
distance = sqrt ((c.x - x) * (c.x - x) +
|
|
|
|
(c.y - y) * (c.y - y));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (distance < best_distance) {
|
|
|
|
closest = candidate;
|
|
|
|
best_distance = distance;
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (height > large_size_threshold) {
|
|
|
|
/* "big" */
|
|
|
|
if (best_distance < 30) { // arbitrary
|
|
|
|
is_signal = false;
|
|
|
|
} else {
|
|
|
|
closest = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* "small" */
|
|
|
|
if (best_distance < 10) { // arbitrary
|
|
|
|
is_signal = false;
|
|
|
|
} else {
|
|
|
|
closest = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-11-23 11:38:17 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
return closest;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2014-06-17 09:51:49 -04:00
|
|
|
void
|
|
|
|
Panner2d::set_send_drawing_mode (bool onoff)
|
|
|
|
{
|
|
|
|
if (_send_mode != onoff) {
|
|
|
|
_send_mode = onoff;
|
|
|
|
queue_draw ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-06 00:59:20 -04:00
|
|
|
bool
|
2005-09-25 22:48:59 -04:00
|
|
|
Panner2d::on_motion_notify_event (GdkEventMotion *ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (ev->state & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK)) {
|
|
|
|
did_move = true;
|
|
|
|
}
|
2011-03-01 16:52:59 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
return handle_motion (x, y, state);
|
|
|
|
}
|
2011-02-22 16:55:25 -05:00
|
|
|
|
2015-08-08 11:33:18 -04:00
|
|
|
#define CSSRGBA(CL) \
|
|
|
|
cairo_set_source_rgba (cr, UINT_RGBA_R_FLT(CL), UINT_RGBA_G_FLT(CL), UINT_RGBA_B_FLT(CL), UINT_RGBA_A_FLT(CL));
|
|
|
|
|
|
|
|
#define CSSRGB(CL, A) \
|
|
|
|
cairo_set_source_rgba (cr, UINT_RGBA_R_FLT(CL), UINT_RGBA_G_FLT(CL), UINT_RGBA_B_FLT(CL), A);
|
2008-12-13 10:18:32 -05:00
|
|
|
bool
|
|
|
|
Panner2d::on_expose_event (GdkEventExpose *event)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
CartesianVector c;
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_t* cr;
|
2014-09-30 12:50:41 -04:00
|
|
|
bool xsmall = (height <= large_size_threshold);
|
2014-01-14 15:11:41 -05:00
|
|
|
const double diameter = radius*2.0;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
cr = gdk_cairo_create (get_window()->gobj());
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
/* background */
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_rectangle (cr, event->area.x, event->area.y, event->area.width, event->area.height);
|
2014-06-17 09:51:49 -04:00
|
|
|
|
2020-04-23 18:51:29 -04:00
|
|
|
uint32_t bg = _send_mode ? colors.send_bg : colors.background;
|
2015-08-08 11:33:18 -04:00
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
if (!panner_shell->bypassed()) {
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(bg);
|
2008-12-13 10:18:32 -05:00
|
|
|
} else {
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGB(bg, 0.2);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_fill_preserve (cr);
|
|
|
|
cairo_clip (cr);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
/* offset to give us some border */
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_translate (cr, hoffset, voffset);
|
2011-03-01 16:52:59 -05:00
|
|
|
|
|
|
|
cairo_set_line_width (cr, 1.0);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
/* horizontal line of "crosshairs" */
|
2010-11-23 11:38:17 -05:00
|
|
|
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.crosshairs);
|
2014-01-15 03:37:20 -05:00
|
|
|
cairo_move_to (cr, 0.0, radius);
|
|
|
|
cairo_line_to (cr, diameter, radius);
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_stroke (cr);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
/* vertical line of "crosshairs" */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-15 03:37:20 -05:00
|
|
|
cairo_move_to (cr, radius, 0);
|
|
|
|
cairo_line_to (cr, radius, diameter);
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_stroke (cr);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
/* the circle on which signals live */
|
2010-11-23 11:38:17 -05:00
|
|
|
|
2014-01-12 15:41:02 -05:00
|
|
|
cairo_set_line_width (cr, 1.5);
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.signalcircle_border);
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_arc (cr, radius, radius, radius, 0.0, 2.0 * M_PI);
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_stroke (cr);
|
2005-11-24 22:36:42 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
for (uint32_t rad = 15; rad < 90; rad += 15) {
|
|
|
|
cairo_set_line_width (cr, .5 + (float)rad / 150.0);
|
|
|
|
if (rad == 45) {
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.signalcircle);
|
2014-01-14 15:11:41 -05:00
|
|
|
} else {
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGB(colors.signalcircle, 0.9);
|
2014-01-14 15:11:41 -05:00
|
|
|
}
|
|
|
|
cairo_new_path (cr);
|
|
|
|
cairo_arc (cr, radius, radius, radius * sin(M_PI * (float) rad / 180.0), 0, 2.0 * M_PI);
|
|
|
|
cairo_stroke (cr);
|
|
|
|
}
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
if (!panner_shell->bypassed()) {
|
2017-07-01 12:42:24 -04:00
|
|
|
/* convention top == front ^= azimuth == .5 (same as stereo/mono panners) */
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (signals.size() > 1) {
|
|
|
|
/* arc to show "diffusion" */
|
|
|
|
|
|
|
|
double width_angle = fabs (panner_shell->pannable()->pan_width_control->get_value()) * 2 * M_PI;
|
2014-01-15 03:37:20 -05:00
|
|
|
double position_angle = panner_shell->pannable()->pan_azimuth_control->get_value() * 2 * M_PI;
|
2014-01-14 15:11:41 -05:00
|
|
|
|
|
|
|
cairo_save (cr);
|
|
|
|
cairo_translate (cr, radius, radius);
|
2017-07-01 12:42:24 -04:00
|
|
|
cairo_rotate (cr, M_PI / 2.0);
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_rotate (cr, position_angle - (width_angle/2.0));
|
|
|
|
cairo_move_to (cr, 0, 0);
|
|
|
|
cairo_arc_negative (cr, 0, 0, radius, width_angle, 0.0);
|
|
|
|
cairo_close_path (cr);
|
|
|
|
if (panner_shell->pannable()->pan_width_control->get_value() >= 0.0) {
|
|
|
|
/* normal width */
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.diffusion);
|
2014-01-14 15:11:41 -05:00
|
|
|
} else {
|
|
|
|
/* inverse width */
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.diffusion_inv);
|
2014-01-14 15:11:41 -05:00
|
|
|
}
|
|
|
|
cairo_fill (cr);
|
|
|
|
cairo_restore (cr);
|
|
|
|
}
|
2014-01-12 15:41:02 -05:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
double arc_radius;
|
|
|
|
|
|
|
|
cairo_select_font_face (cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-09-30 12:50:41 -04:00
|
|
|
if (xsmall) {
|
2011-02-23 23:28:48 -05:00
|
|
|
arc_radius = 4.0;
|
|
|
|
} else {
|
|
|
|
cairo_set_font_size (cr, 10);
|
|
|
|
arc_radius = 12.0;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
/* draw position */
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
PBD::AngularVector dp = position.position;
|
|
|
|
if (!have_elevation) dp.ele = 0;
|
|
|
|
dp.azi = 270 - dp.azi;
|
2014-01-15 03:37:20 -05:00
|
|
|
dp.cartesian (c);
|
2014-01-14 15:11:41 -05:00
|
|
|
cart_to_gtk (c);
|
|
|
|
|
|
|
|
cairo_new_path (cr);
|
|
|
|
cairo_arc (cr, c.x, c.y, arc_radius + 1.0, 0, 2.0 * M_PI);
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.pos_fill);
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_fill_preserve (cr);
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.pos_outline);
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_stroke (cr);
|
|
|
|
|
|
|
|
/* signals */
|
|
|
|
|
2014-01-15 03:37:20 -05:00
|
|
|
if (signals.size() > 0) {
|
2014-01-14 15:11:41 -05:00
|
|
|
for (Targets::iterator i = signals.begin(); i != signals.end(); ++i) {
|
|
|
|
Target* signal = *i;
|
|
|
|
|
|
|
|
if (signal->visible) {
|
|
|
|
|
|
|
|
/* TODO check for overlap - multiple src at same position
|
|
|
|
* -> visualize it properly
|
|
|
|
*/
|
|
|
|
PBD::AngularVector sp = signal->position;
|
|
|
|
if (!have_elevation) sp.ele = 0;
|
2017-07-01 12:42:24 -04:00
|
|
|
sp.azi += 270.0;
|
2014-01-14 15:11:41 -05:00
|
|
|
sp.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
|
|
|
|
|
|
|
cairo_new_path (cr);
|
|
|
|
cairo_arc (cr, c.x, c.y, arc_radius, 0, 2.0 * M_PI);
|
2020-04-23 18:51:29 -04:00
|
|
|
if (_send_mode && !panner_shell->is_linked_to_route()) {
|
|
|
|
CSSRGBA(colors.send_pan);
|
|
|
|
} else {
|
|
|
|
CSSRGBA(colors.signal_fill);
|
|
|
|
}
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_fill_preserve (cr);
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.signal_outline);
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_stroke (cr);
|
|
|
|
|
2014-09-30 12:50:41 -04:00
|
|
|
if (!xsmall && !signal->text.empty()) {
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.text);
|
2014-01-14 15:11:41 -05:00
|
|
|
/* the +/- adjustments are a hack to try to center the text in the circle
|
|
|
|
* TODO use pango get_pixel_size() -- see mono_panner.cc
|
|
|
|
*/
|
2014-09-30 12:50:41 -04:00
|
|
|
if (xsmall) {
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_move_to (cr, c.x - 1, c.y + 1);
|
|
|
|
} else {
|
|
|
|
cairo_move_to (cr, c.x - 4, c.y + 4);
|
|
|
|
}
|
|
|
|
cairo_show_text (cr, signal->text.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* speakers */
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
int n = 0;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
for (Targets::iterator i = speakers.begin(); i != speakers.end(); ++i) {
|
|
|
|
Target *speaker = *i;
|
2008-12-13 10:18:32 -05:00
|
|
|
char buf[256];
|
|
|
|
++n;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (speaker->visible) {
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
PBD::AngularVector sp = speaker->position;
|
|
|
|
sp.azi += 270.0;
|
2010-11-26 14:57:03 -05:00
|
|
|
CartesianVector c;
|
2014-01-15 03:37:20 -05:00
|
|
|
sp.cartesian (c);
|
2010-11-26 14:57:03 -05:00
|
|
|
cart_to_gtk (c);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
snprintf (buf, sizeof (buf), "%d", n);
|
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
/* stroke out a speaker shape */
|
|
|
|
|
|
|
|
cairo_move_to (cr, c.x, c.y);
|
|
|
|
cairo_save (cr);
|
2014-01-15 03:37:20 -05:00
|
|
|
cairo_rotate (cr, -(sp.azi/360.0) * (2.0 * M_PI));
|
2014-09-30 12:50:41 -04:00
|
|
|
if (xsmall) {
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_scale (cr, 0.8, 0.8);
|
|
|
|
} else {
|
|
|
|
cairo_scale (cr, 1.2, 1.2);
|
|
|
|
}
|
|
|
|
cairo_rel_line_to (cr, 4, -2);
|
|
|
|
cairo_rel_line_to (cr, 0, -7);
|
|
|
|
cairo_rel_line_to (cr, 5, +5);
|
|
|
|
cairo_rel_line_to (cr, 5, 0);
|
|
|
|
cairo_rel_line_to (cr, 0, 5);
|
|
|
|
cairo_rel_line_to (cr, -5, 0);
|
|
|
|
cairo_rel_line_to (cr, -5, +5);
|
|
|
|
cairo_rel_line_to (cr, 0, -7);
|
|
|
|
cairo_close_path (cr);
|
2015-08-08 11:33:18 -04:00
|
|
|
CSSRGBA(colors.speaker_fill);
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_fill (cr);
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_restore (cr);
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2014-09-30 12:50:41 -04:00
|
|
|
if (!xsmall) {
|
2014-01-14 15:11:41 -05:00
|
|
|
cairo_set_font_size (cr, 16);
|
2011-02-24 13:55:33 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
/* move the text in just a bit */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-15 03:37:20 -05:00
|
|
|
AngularVector textpos (speaker->position.azi + 270.0, speaker->position.ele, 0.85);
|
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
textpos.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
|
|
|
cairo_move_to (cr, c.x, c.y);
|
|
|
|
cairo_show_text (cr, buf);
|
|
|
|
}
|
2010-11-26 12:43:03 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_destroy (cr);
|
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
return true;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2005-10-06 00:59:20 -04:00
|
|
|
bool
|
2005-09-25 22:48:59 -04:00
|
|
|
Panner2d::on_button_press_event (GdkEventButton *ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2008-12-13 10:18:32 -05:00
|
|
|
GdkModifierType state;
|
2017-07-01 12:42:24 -04:00
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
bool is_signal;
|
2008-12-13 10:18:32 -05:00
|
|
|
|
|
|
|
if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
did_move = false;
|
2011-03-01 16:52:59 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
2008-12-13 10:18:32 -05:00
|
|
|
case 2:
|
2017-07-01 12:42:24 -04:00
|
|
|
x = ev->x - hoffset;
|
|
|
|
y = ev->y - voffset;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if ((drag_target = find_closest_object (x, y, is_signal)) != 0) {
|
2017-07-01 12:42:24 -04:00
|
|
|
if (!is_signal) {
|
|
|
|
panner_shell->panner()->set_position (drag_target->position.azi/360.0);
|
|
|
|
drag_target = 0;
|
|
|
|
} else {
|
|
|
|
drag_target->set_selected (true);
|
|
|
|
}
|
2010-11-26 14:57:03 -05:00
|
|
|
}
|
2010-11-23 11:38:17 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
state = (GdkModifierType) ev->state;
|
2014-01-11 21:56:35 -05:00
|
|
|
return handle_motion (ev->x, ev->y, state);
|
2005-09-25 14:42:24 -04:00
|
|
|
break;
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-02-16 23:45:49 -05:00
|
|
|
return false;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2005-10-06 00:59:20 -04:00
|
|
|
bool
|
2005-09-25 22:48:59 -04:00
|
|
|
Panner2d::on_button_release_event (GdkEventButton *ev)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2008-12-13 10:18:32 -05:00
|
|
|
gint x, y;
|
|
|
|
GdkModifierType state;
|
|
|
|
bool ret = false;
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
|
|
|
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);
|
2005-09-25 14:42:24 -04:00
|
|
|
drag_target = 0;
|
|
|
|
break;
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
case 2:
|
2008-12-13 10:18:32 -05:00
|
|
|
x = (int) floor (ev->x);
|
|
|
|
y = (int) floor (ev->y);
|
|
|
|
state = (GdkModifierType) ev->state;
|
|
|
|
|
2010-11-23 11:38:17 -05:00
|
|
|
if (Keyboard::modifier_state_contains (state, Keyboard::TertiaryModifier)) {
|
2008-12-13 10:18:32 -05:00
|
|
|
toggle_bypass ();
|
|
|
|
ret = true;
|
|
|
|
} else {
|
|
|
|
ret = handle_motion (x, y, state);
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
drag_target = 0;
|
|
|
|
break;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
case 3:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
return ret;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
gint
|
|
|
|
Panner2d::handle_motion (gint evx, gint evy, GdkModifierType state)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2008-12-13 10:18:32 -05:00
|
|
|
if (drag_target == 0) {
|
|
|
|
return false;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
if ((state & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK)) == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-11 18:57:27 -05:00
|
|
|
evx -= hoffset;
|
|
|
|
evy -= voffset;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
if (state & GDK_BUTTON1_MASK && !(state & GDK_BUTTON2_MASK)) {
|
2010-11-26 14:57:03 -05:00
|
|
|
CartesianVector c;
|
|
|
|
bool need_move = false;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
drag_target->position.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
if ((evx != c.x) || (evy != c.y)) {
|
|
|
|
need_move = true;
|
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
if (need_move) {
|
2014-01-11 18:57:27 -05:00
|
|
|
CartesianVector cp (evx, evy, 0.0);
|
2014-01-11 17:30:01 -05:00
|
|
|
AngularVector av;
|
2010-11-26 14:57:03 -05:00
|
|
|
gtk_to_cart (cp);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-11 21:56:35 -05:00
|
|
|
if (!have_elevation) {
|
2014-01-11 17:30:01 -05:00
|
|
|
clamp_to_circle (cp.x, cp.y);
|
|
|
|
cp.angular (av);
|
2017-07-01 12:42:24 -04:00
|
|
|
av.azi = fmod(270 - av.azi, 360);
|
2014-01-11 17:30:01 -05:00
|
|
|
if (drag_target == &position) {
|
|
|
|
double degree_fract = av.azi / 360.0;
|
|
|
|
panner_shell->panner()->set_position (degree_fract);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* sphere projection */
|
|
|
|
sphere_project (cp.x, cp.y, cp.z);
|
|
|
|
|
|
|
|
double r2d = 180.0 / M_PI;
|
|
|
|
av.azi = r2d * atan2(cp.y, cp.x);
|
|
|
|
av.ele = r2d * asin(cp.z);
|
2017-07-01 12:42:24 -04:00
|
|
|
av.azi = fmod(270 - av.azi, 360);
|
2014-01-11 17:30:01 -05:00
|
|
|
|
|
|
|
if (drag_target == &position) {
|
|
|
|
double azi_fract = av.azi / 360.0;
|
|
|
|
double ele_fract = av.ele / 90.0;
|
|
|
|
panner_shell->panner()->set_position (azi_fract);
|
|
|
|
panner_shell->panner()->set_elevation (ele_fract);
|
|
|
|
}
|
|
|
|
}
|
2010-11-26 12:43:03 -05:00
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
}
|
2008-12-13 10:18:32 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-02-22 16:55:25 -05:00
|
|
|
bool
|
|
|
|
Panner2d::on_scroll_event (GdkEventScroll* ev)
|
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
switch (ev->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
case GDK_SCROLL_RIGHT:
|
|
|
|
panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() - 1.0/360.0);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
case GDK_SCROLL_LEFT:
|
|
|
|
panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() + 1.0/360.0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
2011-02-22 16:55:25 -05:00
|
|
|
}
|
|
|
|
|
2010-11-23 11:38:17 -05:00
|
|
|
void
|
2010-11-26 12:43:03 -05:00
|
|
|
Panner2d::cart_to_gtk (CartesianVector& c) const
|
2010-11-23 11:38:17 -05:00
|
|
|
{
|
2011-03-01 16:52:59 -05:00
|
|
|
/* cartesian coordinate space:
|
2019-04-13 11:48:27 -04:00
|
|
|
* center = 0.0
|
|
|
|
* dimension = 2.0 * 2.0
|
|
|
|
* increasing y moves up
|
|
|
|
* so max values along each axis are -1..+1
|
|
|
|
*
|
|
|
|
* GTK uses a coordinate space that is:
|
|
|
|
* top left = 0.0
|
|
|
|
* dimension = (radius*2.0) * (radius*2.0)
|
|
|
|
* increasing y moves down
|
2010-11-26 14:57:03 -05:00
|
|
|
*/
|
2017-07-01 12:42:24 -04:00
|
|
|
const double diameter = radius*2.0;
|
2010-11-26 12:43:03 -05:00
|
|
|
|
2017-07-01 12:42:24 -04:00
|
|
|
c.x = diameter * ((c.x + 1.0) / 2.0);
|
|
|
|
/* extra subtraction inverts the y-axis to match "increasing y moves down" */
|
|
|
|
c.y = diameter - (diameter * ((c.y + 1.0) / 2.0));
|
2010-11-23 11:38:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-11-26 12:43:03 -05:00
|
|
|
Panner2d::gtk_to_cart (CartesianVector& c) const
|
2010-11-23 11:38:17 -05:00
|
|
|
{
|
2017-07-01 12:42:24 -04:00
|
|
|
const double diameter = radius*2.0;
|
2011-03-01 16:52:59 -05:00
|
|
|
c.x = ((c.x / diameter) * 2.0) - 1.0;
|
2017-07-01 12:42:24 -04:00
|
|
|
c.y = (((diameter - c.y) / diameter) * 2.0) - 1.0;
|
2010-11-23 11:38:17 -05:00
|
|
|
}
|
|
|
|
|
2014-01-11 17:30:01 -05:00
|
|
|
void
|
|
|
|
Panner2d::sphere_project (double& x, double& y, double& z)
|
|
|
|
{
|
|
|
|
double r, r2;
|
|
|
|
r2 = x * x + y * y;
|
|
|
|
if (r2 < 1.0) {
|
|
|
|
z = sqrt (1.0 - r2);
|
|
|
|
} else {
|
|
|
|
r = sqrt (r2);
|
|
|
|
x = x / r;
|
|
|
|
y = y / r;
|
|
|
|
z = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-23 11:38:17 -05:00
|
|
|
void
|
|
|
|
Panner2d::clamp_to_circle (double& x, double& y)
|
|
|
|
{
|
2010-11-26 14:57:03 -05:00
|
|
|
double azi, ele;
|
|
|
|
double z = 0.0;
|
2014-01-11 17:30:01 -05:00
|
|
|
double l;
|
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);
|
2010-11-23 11:38:17 -05:00
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
void
|
|
|
|
Panner2d::toggle_bypass ()
|
|
|
|
{
|
2011-07-14 18:17:43 -04:00
|
|
|
panner_shell->set_bypassed (!panner_shell->bypassed());
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
Panner2dWindow::Panner2dWindow (std::shared_ptr<PannerShell> p, int32_t h, uint32_t inputs)
|
2011-11-18 19:56:35 -05:00
|
|
|
: ArdourWindow (_("Panner (2D)"))
|
2014-01-14 15:11:41 -05:00
|
|
|
, widget (p, h)
|
2008-12-13 10:18:32 -05:00
|
|
|
, bypass_button (_("Bypass"))
|
2014-01-11 17:30:13 -05:00
|
|
|
, width_adjustment (0, -100, 100, 1, 5, 0)
|
2014-01-14 15:11:41 -05:00
|
|
|
, width_spinner (width_adjustment)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2008-12-13 10:18:32 -05:00
|
|
|
widget.set_name ("MixerPanZone");
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
set_title (_("Panner"));
|
|
|
|
widget.set_size_request (h, h);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
bypass_button.signal_toggled().connect (sigc::mem_fun (*this, &Panner2dWindow::bypass_toggled));
|
|
|
|
width_spinner.signal_changed().connect (sigc::mem_fun (*this, &Panner2dWindow::width_changed));
|
2014-01-11 17:30:13 -05:00
|
|
|
|
2024-10-18 19:51:44 -04:00
|
|
|
p->Changed.connect (panshell_connections, invalidator (*this), std::bind (&Panner2dWindow::set_bypassed, this), gui_context());
|
2014-01-14 17:08:34 -05:00
|
|
|
/* needed for the width-spinbox in the main window */
|
2024-10-18 19:51:44 -04:00
|
|
|
p->PannableChanged.connect (panshell_connections, invalidator (*this), std::bind (&Panner2dWindow::pannable_handler, this), gui_context());
|
|
|
|
p->pannable()->pan_width_control->Changed.connect (panvalue_connections, invalidator(*this), std::bind (&Panner2dWindow::set_width, this), gui_context());
|
2014-01-14 17:08:34 -05:00
|
|
|
|
2011-02-22 15:49:04 -05:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
button_box.set_spacing (6);
|
|
|
|
button_box.pack_start (bypass_button, false, false);
|
|
|
|
|
|
|
|
left_side.set_spacing (6);
|
|
|
|
|
|
|
|
left_side.pack_start (button_box, false, false);
|
2014-01-11 17:30:13 -05:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
Gtk::Label* l = manage (new Label (
|
2020-03-20 21:42:34 -04:00
|
|
|
p->pannable()->describe_parameter(PanWidthAutomation),
|
2022-01-26 16:19:32 -05:00
|
|
|
Gtk::ALIGN_START, Gtk::ALIGN_CENTER, false));
|
2014-01-11 17:30:13 -05:00
|
|
|
spinner_box.pack_start (*l, false, false);
|
|
|
|
spinner_box.pack_start (width_spinner, false, false);
|
2008-12-13 10:18:32 -05:00
|
|
|
left_side.pack_start (spinner_box, false, false);
|
|
|
|
|
2014-01-11 17:30:13 -05:00
|
|
|
l->show ();
|
2008-12-13 10:18:32 -05:00
|
|
|
bypass_button.show ();
|
|
|
|
button_box.show ();
|
2014-01-11 17:30:13 -05:00
|
|
|
width_spinner.show ();
|
2008-12-13 10:18:32 -05:00
|
|
|
spinner_box.show ();
|
|
|
|
left_side.show ();
|
|
|
|
|
|
|
|
hpacker.set_spacing (6);
|
|
|
|
hpacker.set_border_width (12);
|
|
|
|
hpacker.pack_start (widget, false, false);
|
|
|
|
hpacker.pack_start (left_side, false, false);
|
|
|
|
hpacker.show ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-11-18 19:56:35 -05:00
|
|
|
add (hpacker);
|
2008-12-13 10:18:32 -05:00
|
|
|
reset (inputs);
|
2014-01-14 15:11:41 -05:00
|
|
|
set_width();
|
|
|
|
set_bypassed();
|
2008-12-13 10:18:32 -05:00
|
|
|
widget.show ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
void
|
|
|
|
Panner2dWindow::reset (uint32_t n_inputs)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2008-12-13 10:18:32 -05:00
|
|
|
widget.reset (n_inputs);
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2011-02-22 15:49:04 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
Panner2dWindow::bypass_toggled ()
|
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
bool view = bypass_button.get_active ();
|
|
|
|
bool model = widget.get_panner_shell()->bypassed ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2014-01-14 15:11:41 -05:00
|
|
|
if (model != view) {
|
|
|
|
widget.get_panner_shell()->set_bypassed (view);
|
|
|
|
}
|
2011-02-22 15:49:04 -05:00
|
|
|
}
|
2014-01-11 17:30:13 -05:00
|
|
|
void
|
|
|
|
Panner2dWindow::width_changed ()
|
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
float model = widget.get_panner_shell()->pannable()->pan_width_control->get_value();
|
|
|
|
float view = width_spinner.get_value() / 100.0;
|
|
|
|
if (model != view) {
|
|
|
|
widget.get_panner_shell()->panner()->set_width (view);
|
|
|
|
}
|
2014-01-11 17:30:13 -05:00
|
|
|
}
|
|
|
|
|
2014-01-14 17:08:34 -05:00
|
|
|
void
|
|
|
|
Panner2dWindow::pannable_handler ()
|
|
|
|
{
|
|
|
|
panvalue_connections.drop_connections();
|
2024-10-18 19:51:44 -04:00
|
|
|
widget.get_panner_shell()->pannable()->pan_width_control->Changed.connect (panvalue_connections, invalidator(*this), std::bind (&Panner2dWindow::set_width, this), gui_context());
|
2014-01-14 17:08:34 -05:00
|
|
|
set_width();
|
|
|
|
}
|
|
|
|
|
2014-01-11 17:30:13 -05:00
|
|
|
void
|
|
|
|
Panner2dWindow::set_bypassed ()
|
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
bool view = bypass_button.get_active ();
|
|
|
|
bool model = widget.get_panner_shell()->bypassed ();
|
|
|
|
if (model != view) {
|
|
|
|
bypass_button.set_active(model);
|
|
|
|
}
|
2014-01-11 17:30:13 -05:00
|
|
|
|
2020-03-20 22:43:21 -04:00
|
|
|
set<Evoral::Parameter> params = widget.get_panner_shell()->pannable()->what_can_be_automated();
|
2014-01-14 15:11:41 -05:00
|
|
|
set<Evoral::Parameter>::iterator p = params.find(PanWidthAutomation);
|
|
|
|
if (p == params.end()) {
|
|
|
|
spinner_box.set_sensitive(false);
|
|
|
|
} else {
|
|
|
|
spinner_box.set_sensitive(true);
|
|
|
|
}
|
2014-01-11 17:30:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Panner2dWindow::set_width ()
|
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
// rounding of spinbox is different from slider -- TODO use slider
|
|
|
|
float model = (widget.get_panner_shell()->pannable()->pan_width_control->get_value() * 100.0);
|
|
|
|
float view = (width_spinner.get_value());
|
|
|
|
if (model != view) {
|
|
|
|
width_spinner.set_value (model);
|
|
|
|
}
|
2014-01-11 17:30:13 -05:00
|
|
|
}
|
2011-02-23 23:28:48 -05:00
|
|
|
|
|
|
|
bool
|
|
|
|
Panner2dWindow::on_key_press_event (GdkEventKey* event)
|
|
|
|
{
|
2015-09-04 11:49:56 -04:00
|
|
|
return relay_key_press (event, this);
|
2011-02-23 23:28:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-30 13:55:14 -04:00
|
|
|
Panner2dWindow::on_key_release_event (GdkEventKey*)
|
2011-02-23 23:28:48 -05:00
|
|
|
{
|
2014-01-14 15:11:41 -05:00
|
|
|
return true;
|
2011-02-23 23:28:48 -05:00
|
|
|
}
|