preparations for a working speaker editing dialog

git-svn-id: svn://localhost/ardour2/branches/3.0@8878 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2011-02-17 04:45:49 +00:00
parent 70d246fbe3
commit fee3709438
12 changed files with 559 additions and 31 deletions

View File

@ -470,6 +470,7 @@
<menuitem action='ToggleBundleManager'/>
<menuitem action='ToggleThemeManager'/>
<menuitem action='ToggleBigClock'/>
<menuitem action='toggle-speaker-config'/>
<separator/>

View File

@ -80,34 +80,35 @@
typedef uint64_t microseconds_t;
#include "actions.h"
#include "ardour_ui.h"
#include "public_editor.h"
#include "audio_clock.h"
#include "keyboard.h"
#include "mixer_ui.h"
#include "prompter.h"
#include "opts.h"
#include "add_route_dialog.h"
#include "about.h"
#include "splash.h"
#include "utils.h"
#include "gui_thread.h"
#include "theme_manager.h"
#include "actions.h"
#include "add_route_dialog.h"
#include "ambiguous_file_dialog.h"
#include "ardour_ui.h"
#include "audio_clock.h"
#include "bundle_manager.h"
#include "session_metadata_dialog.h"
#include "gain_meter.h"
#include "route_time_axis.h"
#include "startup.h"
#include "engine_dialog.h"
#include "processor_box.h"
#include "time_axis_view_item.h"
#include "window_proxy.h"
#include "gain_meter.h"
#include "global_port_matrix.h"
#include "gui_thread.h"
#include "keyboard.h"
#include "location_ui.h"
#include "missing_file_dialog.h"
#include "missing_plugin_dialog.h"
#include "ambiguous_file_dialog.h"
#include "mixer_ui.h"
#include "opts.h"
#include "processor_box.h"
#include "prompter.h"
#include "public_editor.h"
#include "route_time_axis.h"
#include "session_metadata_dialog.h"
#include "speaker_dialog.h"
#include "splash.h"
#include "startup.h"
#include "theme_manager.h"
#include "time_axis_view_item.h"
#include "utils.h"
#include "window_proxy.h"
#include "i18n.h"
@ -317,6 +318,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
location_ui = new ActionWindowProxy<LocationUIWindow> (X_("locations"), Config->extra_xml (X_("UI")), X_("ToggleLocations"));
big_clock_window = new ActionWindowProxy<Gtk::Window> (X_("bigclock"), Config->extra_xml (X_("UI")), X_("ToggleBigClock"));
speaker_config_window = new ActionWindowProxy<SpeakerDialog> (X_("speakerconf"), Config->extra_xml (X_("UI")), X_("toggle-speaker-config"));
for (ARDOUR::DataType::iterator i = ARDOUR::DataType::begin(); i != ARDOUR::DataType::end(); ++i) {
_global_port_matrix[*i] = new ActionWindowProxy<GlobalPortMatrixWindow> (
@ -327,6 +329,7 @@ ARDOUR_UI::ARDOUR_UI (int *argcp, char **argvp[])
}
setup_clock ();
speaker_config_window->set (new SpeakerDialog);
starting.connect (sigc::mem_fun(*this, &ARDOUR_UI::startup));
stopping.connect (sigc::mem_fun(*this, &ARDOUR_UI::shutdown));

View File

@ -84,6 +84,7 @@ class RCOptionEditor;
class RouteParams_UI;
class SessionOptionEditor;
class Splash;
class SpeakerDialog;
class ThemeManager;
class MidiTracer;
class WindowProxyBase;
@ -161,6 +162,7 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
void toggle_theme_manager ();
void toggle_bundle_manager ();
void toggle_big_clock_window ();
void toggle_speaker_config_window ();
void new_midi_tracer_window ();
void toggle_route_params_window ();
void toggle_editing_space();
@ -328,6 +330,8 @@ class ARDOUR_UI : public Gtkmm2ext::UI, public ARDOUR::SessionHandlePtr
void float_big_clock (Gtk::Window* parent);
bool main_window_state_event_handler (GdkEventWindowState*, bool window_was_editor);
ActionWindowProxy<SpeakerDialog>* speaker_config_window;
void update_transport_clocks (framepos_t pos);
void record_state_changed ();

View File

@ -27,21 +27,22 @@
#include "ardour/audioengine.h"
#include "actions.h"
#include "add_route_dialog.h"
#include "ardour_ui.h"
#include "bundle_manager.h"
#include "global_port_matrix.h"
#include "gui_thread.h"
#include "keyeditor.h"
#include "location_ui.h"
#include "midi_tracer.h"
#include "mixer_ui.h"
#include "rc_option_editor.h"
#include "session_option_editor.h"
#include "public_editor.h"
#include "rc_option_editor.h"
#include "route_params_ui.h"
#include "session_option_editor.h"
#include "speaker_dialog.h"
#include "sfdb_ui.h"
#include "theme_manager.h"
#include "bundle_manager.h"
#include "keyeditor.h"
#include "gui_thread.h"
#include "midi_tracer.h"
#include "add_route_dialog.h"
#include "global_port_matrix.h"
#include "i18n.h"
@ -64,6 +65,10 @@ ARDOUR_UI::set_session (Session *s)
location_ui->get()->set_session(s);
}
if (speaker_config_window->get()) {
speaker_config_window->get()->set_speakers (s->get_speakers());
}
if (route_params) {
route_params->set_session (s);
}
@ -232,6 +237,22 @@ ARDOUR_UI::toggle_big_clock_window ()
}
}
void
ARDOUR_UI::toggle_speaker_config_window ()
{
RefPtr<Action> act = ActionManager::get_action (X_("Common"), X_("toggle-speaker-config"));
if (act) {
RefPtr<ToggleAction> tact = RefPtr<ToggleAction>::cast_dynamic(act);
if (tact->get_active()) {
speaker_config_window->get()->show_all ();
speaker_config_window->get()->present ();
} else {
speaker_config_window->get()->hide ();
}
}
}
void
ARDOUR_UI::new_midi_tracer_window ()
{

View File

@ -232,6 +232,8 @@ ARDOUR_UI::install_actions ()
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_toggle_action (common_actions, X_("ToggleBigClock"), _("Big Clock"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_big_clock_window));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_toggle_action (common_actions, X_("toggle-speaker-config"), _("Speaker Config"), sigc::mem_fun(*this, &ARDOUR_UI::toggle_speaker_config_window));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_toggle_action (common_actions, X_("toggle-audio-connection-manager"), _("Audio Connection Manager"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_global_port_matrix), ARDOUR::DataType::AUDIO));
ActionManager::session_sensitive_actions.push_back (act);
act = ActionManager::register_toggle_action (common_actions, X_("toggle-midi-connection-manager"), _("MIDI Connection Manager"), sigc::bind (sigc::mem_fun(*this, &ARDOUR_UI::toggle_global_port_matrix), ARDOUR::DataType::MIDI));

View File

@ -1,3 +1,22 @@
/*
Copyright (C) 2009 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 <inttypes.h>
#include <iomanip>

View File

@ -409,7 +409,7 @@ Panner2d::on_expose_event (GdkEventExpose *event)
cairo_destroy (cr);
return TRUE;
return true;
}
bool
@ -439,7 +439,7 @@ Panner2d::on_button_press_event (GdkEventButton *ev)
break;
}
return FALSE;
return false;
}
bool

View File

@ -0,0 +1,391 @@
/*
Copyright (C) 2011 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 "pbd/cartesian.h"
#include "gtkmm2ext/keyboard.h"
#include "speaker_dialog.h"
#include "i18n.h"
using namespace ARDOUR;
using namespace PBD;
using namespace std;
using namespace Gtk;
using namespace Gtkmm2ext;
SpeakerDialog::SpeakerDialog ()
: ArdourDialog (_("Speaker Configuration"))
, azimuth_adjustment (0, 0.0, 360.0, 10.0, 1.0)
, azimuth_spinner (azimuth_adjustment)
, add_speaker_button (_("Add Speaker"))
, use_system_button (_("Use System"))
{
set_size_request (400, 200);
side_vbox.set_homogeneous (false);
side_vbox.set_border_width (9);
side_vbox.set_spacing (6);
side_vbox.pack_start (azimuth_spinner, false, false);
side_vbox.pack_start (add_speaker_button, false, false);
side_vbox.pack_start (use_system_button, false, false);
hbox.set_spacing (6);
hbox.set_border_width (6);
hbox.pack_start (darea, true, true);
hbox.pack_start (side_vbox, false, false);
get_vbox()->pack_start (hbox);
get_vbox()->show_all ();
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));
drag_index = -1;
}
void
SpeakerDialog::set_speakers (const Speakers& s)
{
speakers = s;
}
Speakers
SpeakerDialog::get_speakers () const
{
return speakers;
}
bool
SpeakerDialog::darea_expose_event (GdkEventExpose* event)
{
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);
cairo_set_source_rgba (cr, 0.1, 0.1, 0.1, 1.0);
cairo_fill_preserve (cr);
cairo_clip (cr);
if (height > 100) {
cairo_translate (cr, 10.0, 10.0);
}
/* 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" */
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);
float arc_radius;
cairo_select_font_face (cr, "sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
if (height < 100) {
cairo_set_font_size (cr, 10);
arc_radius = 2.0;
} else {
cairo_set_font_size (cr, 16);
arc_radius = 4.0;
}
uint32_t n = 0;
for (vector<Speaker>::iterator i = speakers.speakers().begin(); i != speakers.speakers().end(); ++i) {
Speaker& s (*i);
CartesianVector c (s.coords());
cart_to_gtk (c);
x = (gint) floor (c.x);
y = (gint) floor (c.y);
/* XXX need to shift circles so that they are centered on the circle */
cairo_arc (cr, x, y, arc_radius, 0, 2.0 * M_PI);
cairo_set_source_rgb (cr, 0.8, 0.2, 0.1);
cairo_close_path (cr);
cairo_fill (cr);
cairo_move_to (cr, x + 6, y + 6);
char buf[256];
snprintf (buf, sizeof (buf), "%d:%d", n+1, (int) lrint (s.angles().azi));
cairo_show_text (cr, buf);
++n;
}
cairo_destroy (cr);
return true;
}
void
SpeakerDialog::cart_to_gtk (CartesianVector& c) const
{
/* "c" uses a coordinate space that is:
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
*/
c.x = (width / 2) * (c.x + 1);
c.y = (height / 2) * (1 - c.y);
/* XXX z-axis not handled - 2D for now */
}
void
SpeakerDialog::gtk_to_cart (CartesianVector& c) const
{
c.x = (c.x / (width / 2.0)) - 1.0;
c.y = -((c.y / (height / 2.0)) - 1.0);
/* XXX z-axis not handled - 2D for now */
}
void
SpeakerDialog::clamp_to_circle (double& x, double& y)
{
double azi, ele;
double z = 0.0;
PBD::cart_to_azi_ele (x, y, z, azi, ele);
PBD::azi_ele_to_cart (azi, ele, x, y, z);
}
void
SpeakerDialog::darea_size_allocate (Gtk::Allocation& alloc)
{
width = alloc.get_width();
height = alloc.get_height();
if (height > 100) {
width -= 20;
height -= 20;
}
}
bool
SpeakerDialog::darea_button_press_event (GdkEventButton *ev)
{
GdkModifierType state;
if (ev->type == GDK_2BUTTON_PRESS && ev->button == 1) {
return false;
}
drag_index = -1;
switch (ev->button) {
case 1:
case 2:
find_closest_object (ev->x, ev->y, drag_index);
drag_x = (int) floor (ev->x);
drag_y = (int) floor (ev->y);
state = (GdkModifierType) ev->state;
return handle_motion (drag_x, drag_y, state);
break;
default:
break;
}
return false;
}
bool
SpeakerDialog::darea_button_release_event (GdkEventButton *ev)
{
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)) {
for (vector<Speaker>::iterator i = speakers.speakers().begin(); i != speakers.speakers().end(); ++i) {
/* 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;
ret = handle_motion (x, y, state);
break;
case 3:
break;
}
drag_index = -1;
return ret;
}
int
SpeakerDialog::find_closest_object (gdouble x, gdouble y, int& which)
{
float distance;
float best_distance = FLT_MAX;
int pwhich = -1;
which = 0;
pwhich = 0;
for (vector<Speaker>::iterator i = speakers.speakers().begin(); i != speakers.speakers().end(); ++i, ++pwhich) {
Speaker& candidate (*i);
CartesianVector c;
candidate.angles().cartesian (c);
cart_to_gtk (c);
distance = sqrt ((c.x - x) * (c.x - x) +
(c.y - y) * (c.y - y));
if (distance < best_distance) {
best_distance = distance;
which = pwhich;
}
}
if (best_distance > 20) { // arbitrary
return 0;
}
return 1;
}
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)
{
if (drag_index < 0) {
return false;
}
if ((state & (GDK_BUTTON1_MASK|GDK_BUTTON2_MASK)) == 0) {
return false;
}
if (state & GDK_BUTTON1_MASK && !(state & GDK_BUTTON2_MASK)) {
CartesianVector c;
bool need_move = false;
Speaker& moving (speakers.speakers()[drag_index]);
moving.angles().cartesian (c);
cart_to_gtk (c);
if ((evx != c.x) || (evy != c.y)) {
need_move = true;
}
if (need_move) {
CartesianVector cp (evx, evy, 0.0);
/* canonicalize position */
gtk_to_cart (cp);
/* position actual signal on circle */
clamp_to_circle (cp.x, cp.y);
/* generate an angular representation and set drag target (GUI) position */
AngularVector a;
cp.angular (a);
moving.move (a);
queue_draw ();
}
}
return true;
}

View File

@ -0,0 +1,69 @@
/*
Copyright (C) 2011 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.
*/
#ifndef __ardour_gtk_speaker_dialog_h__
#define __ardour_gtk_speaker_dialog_h__
#include <gtkmm/drawingarea.h>
#include <gtkmm/spinbutton.h>
#include <gtkmm/box.h>
#include <gtkmm/adjustment.h>
#include "ardour/speakers.h"
#include "ardour_dialog.h"
class SpeakerDialog : public ArdourDialog
{
public:
SpeakerDialog ();
ARDOUR::Speakers get_speakers() const;
void set_speakers (const ARDOUR::Speakers&);
private:
ARDOUR::Speakers speakers;
Gtk::HBox hbox;
Gtk::VBox side_vbox;
Gtk::DrawingArea darea;
Gtk::Adjustment azimuth_adjustment;
Gtk::SpinButton azimuth_spinner;
Gtk::Button add_speaker_button;
Gtk::Button use_system_button;
int32_t selected_speaker;
int width;
int height;
int drag_x;
int drag_y;
int drag_index;
bool darea_expose_event (GdkEventExpose*);
void darea_size_allocate (Gtk::Allocation& alloc);
bool darea_motion_notify_event (GdkEventMotion *ev);
bool handle_motion (gint evx, gint evy, GdkModifierType state);
bool darea_button_press_event (GdkEventButton *ev);
bool darea_button_release_event (GdkEventButton *ev);
void clamp_to_circle (double& x, double& y);
void gtk_to_cart (PBD::CartesianVector& c) const;
void cart_to_gtk (PBD::CartesianVector& c) const;
int find_closest_object (gdouble x, gdouble y, int& which);
};
#endif /* __ardour_gtk_speaker_dialog_h__ */

View File

@ -202,6 +202,7 @@ gtk2_ardour_sources = [
'simpleline.cc',
'simplerect.cc',
'splash.cc',
'speaker_dialog.cc',
'startup.cc',
'step_editor.cc',
'step_entry.cc',

View File

@ -34,8 +34,11 @@ namespace ARDOUR {
class Speakers : public PBD::Stateful {
public:
Speakers ();
Speakers (const Speakers&);
virtual ~Speakers ();
Speakers& operator= (const Speakers&);
virtual int add_speaker (const PBD::AngularVector&);
virtual void remove_speaker (int id);
virtual void move_speaker (int id, const PBD::AngularVector& new_position);

View File

@ -46,10 +46,24 @@ Speakers::Speakers ()
{
}
Speakers::Speakers (const Speakers& s)
{
_speakers = s._speakers;
}
Speakers::~Speakers ()
{
}
Speakers&
Speakers::operator= (const Speakers& s)
{
if (&s != this) {
_speakers = s._speakers;
}
return *this;
}
void
Speakers::dump_speakers (ostream& o)
{