2005-09-25 14:42:24 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2002 Paul Davis
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
|
#include "panner2d.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "gui_thread.h"
|
2011-02-23 23:28:48 -05:00
|
|
|
#include "utils.h"
|
|
|
|
#include "public_editor.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace ARDOUR;
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
Panner2d::Panner2d (boost::shared_ptr<PannerShell> p, int32_t h)
|
|
|
|
: panner_shell (p)
|
2011-02-23 23:28:48 -05:00
|
|
|
, position (AngularVector (0.0, 0.0), "")
|
|
|
|
, width (0)
|
|
|
|
, height (h)
|
2011-02-24 22:20:47 -05:00
|
|
|
, last_width (0)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-07-14 18:17:43 -04:00
|
|
|
panner_shell->Changed.connect (connections, invalidator (*this), boost::bind (&Panner2d::handle_state_change, this), gui_context());
|
2011-02-17 15:15:26 -05:00
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
panner_shell->pannable()->pan_azimuth_control->Changed.connect (connections, invalidator(*this), boost::bind (&Panner2d::handle_position_change, this), gui_context());
|
|
|
|
panner_shell->pannable()->pan_width_control->Changed.connect (connections, invalidator(*this), boost::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
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Panner2d::reset (uint32_t n_inputs)
|
|
|
|
{
|
2011-07-14 18:17:43 -04: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
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
label_signals ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-02-17 13:54:13 -05:00
|
|
|
for (uint32_t i = 0; i < n_inputs; ++i) {
|
2011-07-14 18:17:43 -04:00
|
|
|
signals[i]->position = panner_shell->panner()->signal_position (i);
|
2011-02-17 13:54:13 -05:00
|
|
|
}
|
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
|
|
|
|
2011-07-14 18:17:43 -04: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
|
|
|
{
|
2005-10-06 00:59:20 -04:00
|
|
|
width = alloc.get_width();
|
|
|
|
height = alloc.get_height();
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (height > large_size_threshold) {
|
|
|
|
border = large_border_width;
|
|
|
|
} else {
|
|
|
|
border = small_border_width;
|
|
|
|
}
|
2011-02-17 13:54:13 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
radius = min (width, height);
|
|
|
|
radius -= border;
|
|
|
|
radius /= 2;
|
|
|
|
|
|
|
|
hoffset = max ((double) (width - height), border);
|
|
|
|
voffset = max ((double) (height - width), border);
|
|
|
|
|
|
|
|
hoffset /= 2.0;
|
|
|
|
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 ()
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2011-07-14 18:17:43 -04:00
|
|
|
double w = panner_shell->pannable()->pan_width_control->get_value();
|
2011-03-01 16:52:59 -05:00
|
|
|
uint32_t sz = signals.size();
|
2011-02-24 22:20:47 -05:00
|
|
|
|
|
|
|
switch (sz) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2011-03-01 16:52:59 -05:00
|
|
|
signals[0]->set_text ("");
|
2011-02-24 22:20:47 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
if (w >= 0.0) {
|
2011-03-01 16:52:59 -05:00
|
|
|
signals[0]->set_text ("R");
|
|
|
|
signals[1]->set_text ("L");
|
2011-02-24 22:20:47 -05:00
|
|
|
} else {
|
2011-03-01 16:52:59 -05:00
|
|
|
signals[0]->set_text ("L");
|
|
|
|
signals[1]->set_text ("R");
|
2011-02-24 22:20:47 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
for (uint32_t i = 0; i < sz; ++i) {
|
|
|
|
char buf[64];
|
|
|
|
if (w >= 0.0) {
|
|
|
|
snprintf (buf, sizeof (buf), "%" PRIu32, i + 1);
|
|
|
|
} else {
|
|
|
|
snprintf (buf, sizeof (buf), "%" PRIu32, sz - i);
|
|
|
|
}
|
2011-03-01 16:52:59 -05:00
|
|
|
signals[i]->set_text (buf);
|
2011-02-24 22:20:47 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
void
|
|
|
|
Panner2d::handle_position_change ()
|
|
|
|
{
|
|
|
|
uint32_t n;
|
2011-07-14 18:17:43 -04:00
|
|
|
double w = panner_shell->pannable()->pan_width_control->get_value();
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
position.position = AngularVector (panner_shell->pannable()->pan_azimuth_control->get_value() * 360.0, 0.0);
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
for (uint32_t i = 0; i < signals.size(); ++i) {
|
2011-07-14 18:17:43 -04:00
|
|
|
signals[i]->position = panner_shell->panner()->signal_position (i);
|
2011-02-17 15:15:26 -05:00
|
|
|
}
|
|
|
|
|
2011-02-24 22:20:47 -05:00
|
|
|
if (w * last_width <= 0) {
|
|
|
|
/* changed sign */
|
2011-03-01 16:52:59 -05:00
|
|
|
label_signals ();
|
2011-02-24 22:20:47 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
last_width = w;
|
|
|
|
|
2011-07-14 18:17:43 -04: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;
|
2011-02-23 23:28:48 -05:00
|
|
|
CartesianVector c;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
/* start with the position itself
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
position.position.cartesian (c);
|
|
|
|
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
|
|
|
|
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) +
|
2010-11-26 14:57:03 -05:00
|
|
|
(c.y - y) * (c.y - y));
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
if (distance < best_distance) {
|
2005-09-25 14:42:24 -04:00
|
|
|
closest = candidate;
|
|
|
|
best_distance = distance;
|
|
|
|
}
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
is_signal = true;
|
|
|
|
|
|
|
|
if (height > large_size_threshold) {
|
2011-02-24 22:20:47 -05:00
|
|
|
/* "big" */
|
2011-06-01 13:00:29 -04:00
|
|
|
if (best_distance > 30) { // arbitrary
|
2011-03-01 16:52:59 -05:00
|
|
|
closest = 0;
|
2011-02-24 22:20:47 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* "small" */
|
2011-06-01 13:00:29 -04:00
|
|
|
if (best_distance > 10) { // arbitrary
|
2011-03-01 16:52:59 -05:00
|
|
|
closest = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if we didn't find a signal close by, check the speakers */
|
|
|
|
|
|
|
|
if (!closest) {
|
|
|
|
for (Targets::const_iterator i = speakers.begin(); i != speakers.end(); ++i) {
|
|
|
|
candidate = *i;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
candidate->position.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
distance = sqrt ((c.x - x) * (c.x - x) +
|
|
|
|
(c.y - y) * (c.y - y));
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (distance < best_distance) {
|
|
|
|
closest = candidate;
|
|
|
|
best_distance = distance;
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (height > large_size_threshold) {
|
|
|
|
/* "big" */
|
2011-06-01 13:00:29 -04:00
|
|
|
if (best_distance < 30) { // arbitrary
|
2011-03-01 16:52:59 -05:00
|
|
|
is_signal = false;
|
|
|
|
} else {
|
|
|
|
closest = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* "small" */
|
2011-06-01 13:00:29 -04:00
|
|
|
if (best_distance < 10) { // arbitrary
|
2011-03-01 16:52:59 -05:00
|
|
|
is_signal = false;
|
|
|
|
} else {
|
|
|
|
closest = 0;
|
|
|
|
}
|
2011-02-24 22:20:47 -05:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
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
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (ev->state & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK)) {
|
|
|
|
did_move = true;
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
return handle_motion (x, y, state);
|
|
|
|
}
|
2011-02-22 16:55:25 -05:00
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
bool
|
|
|
|
Panner2d::on_expose_event (GdkEventExpose *event)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2011-02-23 23:28:48 -05:00
|
|
|
CartesianVector c;
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_t* cr;
|
2013-07-13 08:20:01 -04:00
|
|
|
bool small_size = (height <= large_size_threshold);
|
2011-03-01 16:52:59 -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
|
|
|
|
2011-03-01 16:52:59 -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);
|
2011-07-14 18:17:43 -04:00
|
|
|
if (!panner_shell->bypassed()) {
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 1.0);
|
|
|
|
} else {
|
|
|
|
cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 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
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
/* offset to give us some border */
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_translate (cr, hoffset, voffset);
|
|
|
|
|
|
|
|
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
|
|
|
|
2011-02-24 22:20:47 -05:00
|
|
|
cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0);
|
2011-03-01 16:52:59 -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
|
|
|
|
2011-03-01 16:52:59 -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
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_set_line_width (cr, 2.0);
|
|
|
|
cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, 1.0);
|
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
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
/* 3 other circles of smaller diameter circle on which signals live */
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_set_line_width (cr, 1.0);
|
|
|
|
cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0);
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_arc (cr, radius, radius, radius * 0.75, 0, 2.0 * M_PI);
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_stroke (cr);
|
|
|
|
cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.85);
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_arc (cr, radius, radius, radius * 0.50, 0, 2.0 * M_PI);
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_stroke (cr);
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_arc (cr, radius, radius, radius * 0.25, 0, 2.0 * M_PI);
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_stroke (cr);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (signals.size() > 1) {
|
2011-02-23 23:28:48 -05:00
|
|
|
/* arc to show "diffusion" */
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
double width_angle = fabs (panner_shell->pannable()->pan_width_control->get_value()) * 2 * M_PI;
|
|
|
|
double position_angle = (2 * M_PI) - panner_shell->pannable()->pan_azimuth_control->get_value() * 2 * M_PI;
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2011-02-24 22:20:47 -05:00
|
|
|
cairo_save (cr);
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_translate (cr, radius, radius);
|
|
|
|
cairo_rotate (cr, position_angle - (width_angle/2.0));
|
2011-02-24 22:20:47 -05:00
|
|
|
cairo_move_to (cr, 0, 0);
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_arc_negative (cr, 0, 0, radius, width_angle, 0.0);
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_close_path (cr);
|
2011-07-14 18:17:43 -04:00
|
|
|
if (panner_shell->pannable()->pan_width_control->get_value() >= 0.0) {
|
2011-03-01 16:52:59 -05:00
|
|
|
/* normal width */
|
|
|
|
cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.45);
|
|
|
|
} else {
|
|
|
|
/* inverse width */
|
|
|
|
cairo_set_source_rgba (cr, 1.0, 0.419, 0.419, 0.45);
|
|
|
|
}
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_fill (cr);
|
2011-02-24 22:20:47 -05:00
|
|
|
cairo_restore (cr);
|
2011-02-23 23:28:48 -05:00
|
|
|
}
|
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
if (!panner_shell->bypassed()) {
|
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
|
|
|
|
2013-07-13 08:20:01 -04:00
|
|
|
if (small_size) {
|
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
|
|
|
}
|
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
/* signals */
|
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (signals.size() > 1) {
|
|
|
|
for (Targets::iterator i = signals.begin(); i != signals.end(); ++i) {
|
|
|
|
Target* signal = *i;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
if (signal->visible) {
|
|
|
|
|
|
|
|
signal->position.cartesian (c);
|
2011-02-23 23:28:48 -05:00
|
|
|
cart_to_gtk (c);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_new_path (cr);
|
|
|
|
cairo_arc (cr, c.x, c.y, arc_radius, 0, 2.0 * M_PI);
|
|
|
|
cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 0.85);
|
|
|
|
cairo_fill_preserve (cr);
|
|
|
|
cairo_set_source_rgba (cr, 0.517, 0.772, 0.882, 1.0);
|
|
|
|
cairo_stroke (cr);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2013-07-13 08:20:01 -04:00
|
|
|
if (!small_size && !signal->text.empty()) {
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_set_source_rgb (cr, 0.517, 0.772, 0.882);
|
|
|
|
/* the +/- adjustments are a hack to try to center the text in the circle */
|
2013-07-13 08:20:01 -04:00
|
|
|
if (small_size) {
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_move_to (cr, c.x - 1, c.y + 1);
|
|
|
|
} else {
|
|
|
|
cairo_move_to (cr, c.x - 4, c.y + 4);
|
|
|
|
}
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_show_text (cr, signal->text.c_str());
|
2011-02-23 23:28:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
CartesianVector c;
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
speaker->position.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);
|
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
/* stroke out a speaker shape */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_move_to (cr, c.x, c.y);
|
|
|
|
cairo_save (cr);
|
2011-03-01 16:52:59 -05:00
|
|
|
cairo_rotate (cr, -(speaker->position.azi/360.0) * (2.0 * M_PI));
|
2013-07-13 08:20:01 -04:00
|
|
|
if (small_size) {
|
2011-02-23 23:28:48 -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);
|
|
|
|
cairo_set_source_rgba (cr, 0.282, 0.517, 0.662, 1.0);
|
2008-12-13 10:18:32 -05:00
|
|
|
cairo_fill (cr);
|
2011-02-23 23:28:48 -05:00
|
|
|
cairo_restore (cr);
|
|
|
|
|
2013-07-13 08:20:01 -04:00
|
|
|
if (!small_size) {
|
2011-02-24 13:55:33 -05:00
|
|
|
cairo_set_font_size (cr, 16);
|
|
|
|
|
|
|
|
/* move the text in just a bit */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
AngularVector textpos (speaker->position.azi, speaker->position.ele, 0.85);
|
2011-02-24 13:55:33 -05:00
|
|
|
textpos.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
2011-02-23 23:28:48 -05:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2011-02-23 23:28:48 -05:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
/* draw position */
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
position.position.cartesian (c);
|
|
|
|
cart_to_gtk (c);
|
|
|
|
|
|
|
|
cairo_new_path (cr);
|
|
|
|
cairo_arc (cr, c.x, c.y, arc_radius, 0, 2.0 * M_PI);
|
|
|
|
cairo_set_source_rgba (cr, 1.0, 0.419, 0.419, 0.85);
|
|
|
|
cairo_fill_preserve (cr);
|
|
|
|
cairo_set_source_rgba (cr, 1.0, 0.905, 0.905, 0.85);
|
|
|
|
cairo_stroke (cr);
|
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;
|
2011-03-01 16:52:59 -05: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;
|
|
|
|
}
|
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
did_move = false;
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
switch (ev->button) {
|
|
|
|
case 1:
|
2008-12-13 10:18:32 -05:00
|
|
|
case 2:
|
2011-03-01 16:52:59 -05:00
|
|
|
x = ev->x - border;
|
|
|
|
y = ev->y - border;
|
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) {
|
|
|
|
if (!is_signal) {
|
2011-07-14 18:17:43 -04:00
|
|
|
panner_shell->panner()->set_position (drag_target->position.azi/360.0);
|
2011-03-01 16:52:59 -05:00
|
|
|
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
|
|
|
|
2011-06-01 13:00:29 -04:00
|
|
|
drag_x = ev->x;
|
2011-03-01 16:52:59 -05:00
|
|
|
drag_y = ev->y;
|
2005-09-25 14:42:24 -04:00
|
|
|
state = (GdkModifierType) ev->state;
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
return handle_motion (drag_x, drag_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;
|
2011-03-01 16:52:59 -05: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
|
|
|
|
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) {
|
|
|
|
CartesianVector cp (evx, evy, 0.0);
|
2011-02-23 23:28:48 -05:00
|
|
|
AngularVector av;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-01 16:52:59 -05:00
|
|
|
/* canonicalize position and then clamp to the circle */
|
2008-12-13 10:18:32 -05:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
gtk_to_cart (cp);
|
|
|
|
clamp_to_circle (cp.x, cp.y);
|
2010-11-26 12:43:03 -05:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
/* generate an angular representation of the current mouse position */
|
2010-11-26 12:43:03 -05:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
cp.angular (av);
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-23 23:28:48 -05:00
|
|
|
if (drag_target == &position) {
|
|
|
|
double degree_fract = av.azi / 360.0;
|
2011-07-14 18:17:43 -04:00
|
|
|
panner_shell->panner()->set_position (degree_fract);
|
2011-02-23 23:28:48 -05:00
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
switch (ev->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
case GDK_SCROLL_RIGHT:
|
2011-07-14 18:17:43 -04:00
|
|
|
panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() - 1.0/360.0);
|
2011-02-22 16:55:25 -05:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
case GDK_SCROLL_LEFT:
|
2011-07-14 18:17:43 -04:00
|
|
|
panner_shell->panner()->set_position (panner_shell->pannable()->pan_azimuth_control->get_value() + 1.0/360.0);
|
2011-02-22 16:55:25 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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:
|
|
|
|
center = 0.0
|
|
|
|
dimension = 2.0 * 2.0
|
|
|
|
increasing y moves up
|
|
|
|
so max values along each axis are -1..+1
|
2010-11-26 12:43:03 -05:00
|
|
|
|
2010-11-26 14:57:03 -05:00
|
|
|
GTK uses a coordinate space that is:
|
2011-03-01 16:52:59 -05:00
|
|
|
top left = 0.0
|
|
|
|
dimension = (radius*2.0) * (radius*2.0)
|
|
|
|
increasing y moves down
|
2010-11-26 14:57:03 -05:00
|
|
|
*/
|
2011-03-01 16:52:59 -05:00
|
|
|
const double diameter = radius*2.0;
|
2010-11-26 12:43:03 -05:00
|
|
|
|
2011-03-01 16:52:59 -05: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
|
|
|
{
|
2011-03-01 16:52:59 -05:00
|
|
|
const double diameter = radius*2.0;
|
|
|
|
c.x = ((c.x / diameter) * 2.0) - 1.0;
|
|
|
|
c.y = (((diameter - c.y) / diameter) * 2.0) - 1.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;
|
2011-02-24 13:55:33 -05: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);
|
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
|
|
|
}
|
|
|
|
|
2011-07-14 18:17:43 -04:00
|
|
|
Panner2dWindow::Panner2dWindow (boost::shared_ptr<PannerShell> p, int32_t h, uint32_t inputs)
|
2011-11-18 19:56:35 -05:00
|
|
|
: ArdourWindow (_("Panner (2D)"))
|
2011-02-17 14:47:53 -05:00
|
|
|
, widget (p, h)
|
2008-12-13 10:18:32 -05:00
|
|
|
, bypass_button (_("Bypass"))
|
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
|
|
|
|
2011-02-22 15:49:04 -05:00
|
|
|
bypass_button.signal_toggled().connect (sigc::mem_fun (*this, &Panner2dWindow::bypass_toggled));
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
button_box.set_spacing (6);
|
|
|
|
button_box.pack_start (bypass_button, false, false);
|
|
|
|
|
|
|
|
spinner_box.set_spacing (6);
|
|
|
|
left_side.set_spacing (6);
|
|
|
|
|
|
|
|
left_side.pack_start (button_box, false, false);
|
|
|
|
left_side.pack_start (spinner_box, false, false);
|
|
|
|
|
|
|
|
bypass_button.show ();
|
|
|
|
button_box.show ();
|
|
|
|
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);
|
|
|
|
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
|
|
|
|
2010-11-26 12:43:03 -05:00
|
|
|
#if 0
|
2008-12-13 10:18:32 -05:00
|
|
|
while (spinners.size() < n_inputs) {
|
2010-11-26 12:43:03 -05:00
|
|
|
// spinners.push_back (new Gtk::SpinButton (widget.azimuth (spinners.size())));
|
|
|
|
//spinner_box.pack_start (*spinners.back(), false, false);
|
|
|
|
//spinners.back()->set_digits (4);
|
2008-12-13 10:18:32 -05:00
|
|
|
spinners.back()->show ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
2008-12-13 10:18:32 -05:00
|
|
|
while (spinners.size() > n_inputs) {
|
|
|
|
spinner_box.remove (*spinners.back());
|
|
|
|
delete spinners.back();
|
|
|
|
spinners.erase (--spinners.end());
|
|
|
|
}
|
2010-11-26 12:43:03 -05:00
|
|
|
#endif
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2011-02-22 15:49:04 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
Panner2dWindow::bypass_toggled ()
|
|
|
|
{
|
|
|
|
bool view = bypass_button.get_active ();
|
2011-07-14 18:17:43 -04:00
|
|
|
bool model = widget.get_panner_shell()->bypassed ();
|
2011-06-01 13:00:29 -04:00
|
|
|
|
2011-02-22 15:49:04 -05:00
|
|
|
if (model != view) {
|
2011-07-14 18:17:43 -04:00
|
|
|
widget.get_panner_shell()->set_bypassed (view);
|
2011-02-22 15:49:04 -05:00
|
|
|
}
|
|
|
|
}
|
2011-02-23 23:28:48 -05:00
|
|
|
|
|
|
|
bool
|
|
|
|
Panner2dWindow::on_key_press_event (GdkEventKey* event)
|
|
|
|
{
|
|
|
|
return relay_key_press (event, &PublicEditor::instance());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2011-09-30 13:55:14 -04:00
|
|
|
Panner2dWindow::on_key_release_event (GdkEventKey*)
|
2011-02-23 23:28:48 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|