Fix a panner crash when reducing a route's output count down to 2. Remove some unused code.

git-svn-id: svn://localhost/ardour2/branches/3.0@7560 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Carl Hetherington 2010-08-07 23:30:37 +00:00
parent 66aeda8d8a
commit 8367132a85
3 changed files with 32 additions and 147 deletions

View file

@ -405,7 +405,7 @@ int main (int argc, char *argv[])
} }
if (no_splash) { if (no_splash) {
cerr << _("Copyright (C) 1999-2008 Paul Davis") << endl cerr << _("Copyright (C) 1999-2010 Paul Davis") << endl
<< _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl << _("Some portions Copyright (C) Steve Harris, Ari Johnson, Brett Viren, Joel Baker") << endl
<< endl << endl
<< string_compose (_("%1 comes with ABSOLUTELY NO WARRANTY"), PROGRAM_NAME) << endl << string_compose (_("%1 comes with ABSOLUTELY NO WARRANTY"), PROGRAM_NAME) << endl

View file

@ -82,7 +82,7 @@ Panner2d::Panner2d (boost::shared_ptr<Panner> p, int32_t h)
Panner2d::~Panner2d() Panner2d::~Panner2d()
{ {
for (Targets::iterator i = targets.begin(); i != targets.end(); ++i) { for (Targets::iterator i = targets.begin(); i != targets.end(); ++i) {
delete i->second; delete *i;
} }
} }
@ -97,12 +97,16 @@ Panner2d::reset (uint32_t n_inputs)
add_puck ("", 0.0, 0.0); add_puck ("", 0.0, 0.0);
} }
while (pucks.size() > n_inputs) { if (pucks.size() > n_inputs) {
pucks.erase (pucks.begin()); for (uint32_t i = pucks.size(); i < n_inputs; ++i) {
delete pucks[i];
}
pucks.resize (n_inputs);
} }
for (Targets::iterator x = pucks.begin(); x != pucks.end(); ++x) { for (Targets::iterator x = pucks.begin(); x != pucks.end(); ++x) {
(*x).second->visible = false; (*x)->visible = false;
} }
switch (n_inputs) { switch (n_inputs) {
@ -141,12 +145,16 @@ Panner2d::reset (uint32_t n_inputs)
add_target (0.0, 0.0); add_target (0.0, 0.0);
} }
while (targets.size() > panner->nouts()) { if (targets.size() > panner->nouts()) {
targets.erase (targets.begin()); for (uint32_t i = panner->nouts(); i < targets.size(); ++i) {
delete targets[i];
}
targets.resize (panner->nouts ());
} }
for (Targets::iterator x = targets.begin(); x != targets.end(); ++x) { for (Targets::iterator x = targets.begin(); x != targets.end(); ++x) {
(*x).second->visible = false; (*x)->visible = false;
} }
for (uint32_t n = 0; n < panner->nouts(); ++n) { for (uint32_t n = 0; n < panner->nouts(); ++n) {
@ -191,12 +199,7 @@ int
Panner2d::add_puck (const char* text, float x, float y) Panner2d::add_puck (const char* text, float x, float y)
{ {
Target* puck = new Target (x, y, text); Target* puck = new Target (x, y, text);
pucks.push_back (puck);
pair<int,Target *> newpair;
newpair.first = pucks.size();
newpair.second = puck;
pucks.insert (newpair);
puck->visible = true; puck->visible = true;
return 0; return 0;
@ -206,47 +209,11 @@ int
Panner2d::add_target (float x, float y) Panner2d::add_target (float x, float y)
{ {
Target* target = new Target (x, y, ""); Target* target = new Target (x, y, "");
targets.push_back (target);
pair<int,Target *> newpair;
newpair.first = targets.size();
newpair.second = target;
targets.insert (newpair);
target->visible = true; target->visible = true;
queue_draw (); queue_draw ();
return newpair.first; return targets.size() - 1;
}
void
Panner2d::drop_targets ()
{
for (Targets::iterator i = targets.begin(); i != targets.end(); ) {
Targets::iterator tmp;
tmp = i;
++tmp;
delete i->second;
targets.erase (i);
i = tmp;
}
queue_draw ();
}
void
Panner2d::remove_target (int which)
{
Targets::iterator i = targets.find (which);
if (i != targets.end()) {
delete i->second;
targets.erase (i);
queue_draw ();
}
} }
void void
@ -279,90 +246,16 @@ Panner2d::handle_position_change ()
} }
void void
Panner2d::move_target (int which, float x, float y) Panner2d::move_puck (int which, float x, float y)
{ {
Targets::iterator i = targets.find (which); if (which >= int (targets.size())) {
Target *target;
if (!allow_target) {
return; return;
} }
if (i != targets.end()) { targets[which]->x.set_value (x);
target = i->second; targets[which]->y.set_value (y);
target->x.set_value (x);
target->y.set_value (y);
queue_draw (); queue_draw ();
} }
}
void
Panner2d::move_puck (int which, float x, float y)
{
Targets::iterator i = pucks.find (which);
Target *target;
if (i != pucks.end()) {
target = i->second;
target->x.set_value (x);
target->y.set_value (y);
queue_draw ();
}
}
void
Panner2d::show_puck (int which)
{
Targets::iterator i = pucks.find (which);
if (i != pucks.end()) {
Target* puck = i->second;
if (!puck->visible) {
puck->visible = true;
queue_draw ();
}
}
}
void
Panner2d::hide_puck (int which)
{
Targets::iterator i = pucks.find (which);
if (i != pucks.end()) {
Target* puck = i->second;
if (!puck->visible) {
puck->visible = false;
queue_draw ();
}
}
}
void
Panner2d::show_target (int which)
{
Targets::iterator i = targets.find (which);
if (i != targets.end()) {
if (!i->second->visible) {
i->second->visible = true;
queue_draw ();
}
}
}
void
Panner2d::hide_target (int which)
{
Targets::iterator i = targets.find (which);
if (i != targets.end()) {
if (i->second->visible) {
i->second->visible = false;
queue_draw ();
}
}
}
Panner2d::Target * Panner2d::Target *
Panner2d::find_closest_object (gdouble x, gdouble y, int& which, bool& is_puck) const Panner2d::find_closest_object (gdouble x, gdouble y, int& which, bool& is_puck) const
@ -382,7 +275,7 @@ Panner2d::find_closest_object (gdouble x, gdouble y, int& which, bool& is_puck)
is_puck = false; is_puck = false;
for (Targets::const_iterator i = targets.begin(); i != targets.end(); ++i, ++which) { for (Targets::const_iterator i = targets.begin(); i != targets.end(); ++i, ++which) {
candidate = i->second; candidate = *i;
cx = candidate->x.get_value(); cx = candidate->x.get_value();
cy = candidate->y.get_value(); cy = candidate->y.get_value();
@ -397,7 +290,7 @@ Panner2d::find_closest_object (gdouble x, gdouble y, int& which, bool& is_puck)
} }
for (Targets::const_iterator i = pucks.begin(); i != pucks.end(); ++i, ++pwhich) { for (Targets::const_iterator i = pucks.begin(); i != pucks.end(); ++i, ++pwhich) {
candidate = i->second; candidate = *i;
cx = candidate->x.get_value(); cx = candidate->x.get_value();
cy = candidate->y.get_value(); cy = candidate->y.get_value();
@ -483,7 +376,7 @@ Panner2d::on_expose_event (GdkEventExpose *event)
for (Targets::iterator i = pucks.begin(); i != pucks.end(); ++i) { for (Targets::iterator i = pucks.begin(); i != pucks.end(); ++i) {
Target* puck = i->second; Target* puck = *i;
if (puck->visible) { if (puck->visible) {
/* redraw puck */ /* redraw puck */
@ -545,7 +438,7 @@ Panner2d::on_expose_event (GdkEventExpose *event)
int n = 0; int n = 0;
for (Targets::iterator i = targets.begin(); i != targets.end(); ++i) { for (Targets::iterator i = targets.begin(); i != targets.end(); ++i) {
Target *target = i->second; Target *target = *i;
char buf[256]; char buf[256];
++n; ++n;

View file

@ -57,16 +57,8 @@ class Panner2d : public Gtk::DrawingArea
void allow_y_motion(bool); void allow_y_motion(bool);
void allow_target_motion (bool); void allow_target_motion (bool);
void hide_puck (int which);
void show_puck (int which);
int add_target (float x, float y); int add_target (float x, float y);
int add_puck (const char* text, float x, float y); int add_puck (const char* text, float x, float y);
void hide_target (int);
void show_target (int);
void remove_target (int);
void drop_targets ();
void drop_pucks ();
void move_target (int, float x, float y);
void move_puck (int, float x, float y); void move_puck (int, float x, float y);
void reset (uint32_t n_inputs); void reset (uint32_t n_inputs);
@ -101,7 +93,7 @@ class Panner2d : public Gtk::DrawingArea
boost::shared_ptr<ARDOUR::Panner> panner; boost::shared_ptr<ARDOUR::Panner> panner;
Glib::RefPtr<Pango::Layout> layout; Glib::RefPtr<Pango::Layout> layout;
typedef std::map<int,Target *> Targets; typedef std::vector<Target*> Targets;
Targets targets; Targets targets;
Targets pucks; Targets pucks;