package de.maramuse.soundcomp.math;
/*
* 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
*/
/**
* A base class for many kinds of mathematical operations (two argument functions).
*/
import de.maramuse.soundcomp.process.NamedSource;
import de.maramuse.soundcomp.process.ParameterMap;
import de.maramuse.soundcomp.process.ProcessElement;
import de.maramuse.soundcomp.process.SourceStore;
import de.maramuse.soundcomp.process.StandardParameters;
import de.maramuse.soundcomp.process.Stateless;
import de.maramuse.soundcomp.process.TypeMismatchException;
import de.maramuse.soundcomp.process.UnknownConnectionException;
import de.maramuse.soundcomp.process.ValueType;
import de.maramuse.soundcomp.process.StandardParameters.Parameter;
import de.maramuse.soundcomp.util.NativeObjects;
import de.maramuse.soundcomp.util.ReadOnlyMap;
import de.maramuse.soundcomp.util.ReadOnlyMapImpl;
public abstract class BasicMath2 implements ProcessElement, Stateless {
public long nativeSpace=-1;
private String abstractName;
private String instanceName;
public BasicMath2() {
NativeObjects.registerNativeObject(this);
}
private static final ReadOnlyMapImpl<Integer, ValueType> destMap=new ReadOnlyMapImpl<Integer, ValueType>();
private static final ReadOnlyMapImpl<Integer, ValueType> srcMap=new ReadOnlyMapImpl<Integer, ValueType>();
private final ReadOnlyMapImpl<Integer, SourceStore> sourceMap=new ReadOnlyMapImpl<Integer, SourceStore>();
private static ParameterMap inputsMap=new ParameterMap();
private static ParameterMap outputsMap=new ParameterMap();
static{
inputsMap.put(StandardParameters.IN_IMAG);
inputsMap.put(StandardParameters.IN);
outputsMap.put(StandardParameters.OUT);
}
static{
destMap.put(StandardParameters.IN.i, ValueType.STREAM);
destMap.put(StandardParameters.IN_IMAG.i, ValueType.STREAM);
srcMap.put(StandardParameters.OUT.i, ValueType.STREAM);
}
@Override
public ReadOnlyMap<Integer, ValueType> getDestinationTypes() {
return destMap;
}
SourceStore in1=null, in2=null;
@Override
public void setSource(int connectionIndex, NamedSource source,
int sourceIndex) throws UnknownConnectionException,
TypeMismatchException {
if(connectionIndex!=StandardParameters.IN.i&&connectionIndex!=StandardParameters.IN_IMAG.i)
throw new UnknownConnectionException("attempt to set invalid calculation parameter");
if(!source.getSourceTypes().containsKey(sourceIndex))
throw new UnknownConnectionException("attempt to set invalid calculation parameter source");
if(connectionIndex==StandardParameters.IN.i){
in1=new SourceStore(source, sourceIndex);
sourceMap.put(StandardParameters.IN.i, in1);
}else{
in2=new SourceStore(source, sourceIndex);
sourceMap.put(StandardParameters.IN_IMAG.i, in2);
}
}
@Override
public ReadOnlyMap<Integer, ValueType> getSourceTypes() {
return srcMap;
}
@Override
public void advanceOutput() {
// nothing to do
}
@Override
public void advanceState() {
// nothing to do
}
@Override
public String getAbstractName() {
return abstractName;
}
@Override
public String getInstanceName() {
return instanceName;
}
@Override
public void setAbstractName(String abstractName) {
this.abstractName=abstractName;
}
@Override
public void setInstanceName(String instanceName) {
this.instanceName=instanceName;
}
@Override
public long getNativeSpace() {
return nativeSpace;
}
@Override
public ReadOnlyMap<Integer, SourceStore> getSourceMap() {
return sourceMap;
}
@Override
public abstract BasicMath2 clone();
/*
* (non-Javadoc)
*
* @see de.maramuse.soundcomp.process.ProcessElement#outputsByName()
*/
@Override
public ReadOnlyMap<String, Parameter> outputsByName() {
return outputsMap;
}
/*
* (non-Javadoc)
*
* @see de.maramuse.soundcomp.process.ProcessElement#inputsByName()
*/
@Override
public ReadOnlyMap<String, Parameter> inputsByName() {
return inputsMap;
}
}