Example #1
0
double Interpolation::MinValueInTimeRange(double startTime,double endTime)
{

   //double cursor =mymin(mymax(0.0,time-mStartTime)/mymax(1.0/44100.0,mDuration),1.0);
   switch(mType)
   {
      case eLinear:
        return mEndCoef<1.0?ValueAtTime(endTime):ValueAtTime(startTime);
        break;
      
      case eExp2:
         return mEndCoef<1.0?ValueAtTime(endTime):ValueAtTime(startTime);
         break;
         
	  case eExp2Step:
      case eStep:
         return mEndCoef<1.0?ValueAtTime(endTime):ValueAtTime(startTime);
         break;
         
         
 	   case ePeriodic:
      case eSquare:
   		return mEndCoef<1.0?mEndCoef:1.0;
   }
}
void DelayedExpressionResult::storeValue(const scalar &time)
{
    Pbug << "Storing value " << name() << " at t="
        << time << endl;

    bool append=false;

    if(storedValues_.size()<=0) {
        Pbug << "First value - appending" << endl;

        append=true;
    } else {
        const scalar lastTime=storedValues_.last().first();

        Pbug << "Last stored time t=" << lastTime << flush;

        if(lastTime+SMALL>=time) {
            // basically the same. Fall through to replace
            Pbug << " Almost same - replacing" << endl;
        } else if((time-lastTime)>=0.999*storeInterval_) {
            Pbug << " Interval " << storeInterval_
                << "passed - appending"<< endl;

            append=true;
        } else {
            Pbug << " Middle. Nothing done" << endl;

            // we're in the middle. Forget it
            return;
        }
    }

    if(append) {
        scalar oldLastTime=-1;
        bool notEmpty=false;

        if(storedValues_.size()>0) {
            oldLastTime=storedValues_.last().first();
            notEmpty=true;
        }

        Pbug << "Appending " << settingResult_ << endl;

        storedValues_.append(ValueAtTime(time,settingResult_));
        if(notEmpty) {
            while(
                oldLastTime-storedValues_.first().first()
                >=
                delay_
            ) {
                Pbug << "Removing t=" << storedValues_.first().first()
                    << " because it is older than " << delay_ << endl;

                storedValues_.removeHead();
            }
        }
    } else {
        Pbug << "Replacing with " << settingResult_ << endl;

        storedValues_.last().second()=settingResult_;
    }
}