**
** \legal
** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
-** Copyright (c) 2007 Chris Moore
+** Copyright (c) 2007, 2008 Chris Moore
**
** This package is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License as
ValueNode_Duplicate::ValueNode_Duplicate(const ValueBase &x):
LinkableValueNode(x.get_type())
{
- set_link("from", ValueNode_Const::create(int(1)));
- set_link("to", ValueNode_Const::create(x.get(int())));
- set_link("step", ValueNode_Const::create(int(1)));
- index = 1;
+ set_link("from", ValueNode_Const::create(Real(1.0)));
+ set_link("to", ValueNode_Const::create(x.get(Real())));
+ set_link("step", ValueNode_Const::create(Real(1.0)));
+ index = 1.0;
}
ValueNode_Duplicate*
}
bool
-ValueNode_Duplicate::set_link_vfunc(int i,ValueNode::Handle x)
+ValueNode_Duplicate::set_link_vfunc(int i,ValueNode::Handle value)
{
- assert(i >= 0 && i < link_count());
+ assert(i>=0 && i<link_count());
+
switch(i)
{
- case 0: from_ = x; break;
- case 1: to_ = x; break;
- case 2: step_ = x; break;
- default: return false;
+ case 0: CHECK_TYPE_AND_SET_VALUE(from_, ValueBase::TYPE_REAL);
+ case 1: CHECK_TYPE_AND_SET_VALUE(to_, ValueBase::TYPE_REAL);
+ case 2: CHECK_TYPE_AND_SET_VALUE(step_, ValueBase::TYPE_REAL);
}
-
- signal_child_changed()(i);
- signal_value_changed()();
- return true;
+ return false;
}
ValueNode::LooseHandle
ValueNode_Duplicate::get_link_vfunc(int i)const
{
- assert(i >= 0 && i < link_count());
+ assert(i>=0 && i<link_count());
+
if(i==0) return from_;
if(i==1) return to_;
if(i==2) return step_;
String
ValueNode_Duplicate::link_local_name(int i)const
{
- assert(i >= 0 && i < link_count());
+ assert(i>=0 && i<link_count());
+
if(i==0) return _("From");
if(i==1) return _("To");
if(i==2) return _("Step");
String
ValueNode_Duplicate::link_name(int i)const
{
- assert(i >= 0 && i < link_count());
+ assert(i>=0 && i<link_count());
+
if(i==0) return "from";
if(i==1) return "to";
if(i==2) return "step";
void
ValueNode_Duplicate::reset_index(Time t)const
{
- int from = (*from_)(t).get(int());
+ Real from = (*from_)(t).get(Real());
index = from;
}
bool
ValueNode_Duplicate::step(Time t)const
{
- int from = (*from_)(t).get(int());
- int to = (*to_ )(t).get(int());
- int step = (*step_)(t).get(int());
+ Real from = (*from_)(t).get(Real());
+ Real to = (*to_ )(t).get(Real());
+ Real step = (*step_)(t).get(Real());
+ Real prev = index;
if (step == 0) return false;
if (from < to)
{
- index += step;
- return index <= to;
+ if ((index += step) <= to) return true;
}
else
- {
- index -= step;
- return index >= to;
- }
+ if ((index -= step) >= to) return true;
+
+ // at the end of the loop, leave the index at the last value that was used
+ index = prev;
+ return false;
}
int
ValueNode_Duplicate::count_steps(Time t)const
{
- int from = (*from_)(t).get(int());
- int to = (*to_ )(t).get(int());
- int step = (*step_)(t).get(int());
+ Real from = (*from_)(t).get(Real());
+ Real to = (*to_ )(t).get(Real());
+ Real step = (*step_)(t).get(Real());
if (step == 0) return 1;
}
ValueBase
-ValueNode_Duplicate::operator()(Time t)const
+ValueNode_Duplicate::operator()(Time t __attribute__ ((unused)))const
{
return index;
}
}
bool
-ValueNode_Duplicate::check_type(ValueBase::Type type)
+ValueNode_Duplicate::check_type(ValueBase::Type type __attribute__ ((unused)))
{
- return type==ValueBase::TYPE_INTEGER;
+ // never offer this as a choice. it's used automatically by the 'Duplicate' layer.
+ return false;
}