Package de.maramuse.soundcomp.math

Source Code of de.maramuse.soundcomp.math.BasicMath

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 (one 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.UnnamedSource;
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 BasicMath implements ProcessElement, UnnamedSource, Stateless {
  public long nativeSpace=-1;
  private String abstractName;
  private String instanceName;

  public BasicMath() {
  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);
  outputsMap.put(StandardParameters.OUT);
  }
  static{
  destMap.put(StandardParameters.IN.i, ValueType.STREAM);
  srcMap.put(StandardParameters.OUT.i, ValueType.STREAM);
  }

  @Override
  public ReadOnlyMap<Integer, ValueType> getDestinationTypes() {
  return destMap;
  }

  SourceStore in=null;

  @Override
  public void setSource(int connectionIndex, NamedSource source,
            int sourceIndex) throws UnknownConnectionException,
      TypeMismatchException {
  if(connectionIndex!=StandardParameters.IN.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");
  in=new SourceStore(source, sourceIndex);
  sourceMap.put(StandardParameters.IN.i, in);
  }

  @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 double getValue(int index){
  return getValue();
  }
 
  @Override
  public ValueType getSourceType(){
  return ValueType.STREAM;
  }
 
  @Override
  public abstract BasicMath 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;
  }
}
TOP

Related Classes of de.maramuse.soundcomp.math.BasicMath

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.