/*
* Copyright 2010 Jan Schmidt-Reinisch
*
* SoundComp - a sound processing library
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; in version 2.1
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package de.maramuse.soundcomp.parser.math;
import de.maramuse.soundcomp.parser.AccelMode;
import de.maramuse.soundcomp.parser.Bpm;
import de.maramuse.soundcomp.parser.Number;
import de.maramuse.soundcomp.parser.SCParser;
import de.maramuse.soundcomp.parser.TemplateProvider;
import de.maramuse.soundcomp.parser.SCParser.ParserVal;
import de.maramuse.soundcomp.process.ProcessElement;
/**
* this symbol class represents a mathematical exponentiation operation (1 or 2 arguments)
* Besides, it is also the keyword for the "exponential" acceleration mode
*/
public class MExp extends ParserVal implements TemplateProvider, FormulaElement1, AccelMode {
private static final ProcessElement template=new de.maramuse.soundcomp.math.exp();
public MExp(String s) {
super(SCParser.MEXP, s);
}
@Override
public ParserVal eliminateConst() {
if(inner.size()==1){
if(inner.get(0).isConstant())
return new Number(Math.exp(inner.get(0).asDouble()));
return this;
}
throw new IllegalArgumentException("exp needs one argument "+getLocationText());
}
/* (non-Javadoc)
* @see de.maramuse.soundcomp.parser.TemplateProvider#getTemplate()
*/
@Override
public ProcessElement getTemplate() {
return template;
}
/* (non-Javadoc)
* @see de.maramuse.soundcomp.parser.FormulaElement#getInput1Val()
*/
@Override
public ParserVal getInput1Val() {
return inner.get(0);
}
@Override
public int getAccelMode() {
return Bpm.ACCELMODE_EXPONENTIAL;
}
}