Package de.maramuse.soundcomp.generator

Source Code of de.maramuse.soundcomp.generator.In

package de.maramuse.soundcomp.generator;

/*
* Copyright 2013 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 signal "generator" (from SoundComp perspective) that represents any kind of direct hardware input
*
* It provides no control inputs as hardware inputs are generally not influencable by software.
* If you need an influence (like a volume setting, muting etc) you can almost always do this at a
* later position within the SoundComp signal chain.
* The signal selection is carried out by string attributes that are machine dependent.
* In this rare case this is ok, there can not be a machine independent selection of external signal sources
* as their mere existence is machine dependent anyway.
* To use this element in a mostly portable way, use macros for signal sources so you can shift the
* selection to the song file header.
* The only output is a numeric representation of the selected input signal. It may have a slower time
* resolution than one update per sample. For example, serial or midi lines update only once per several
* hundred samples. In between the value will just be repeated.
*
* This generator only should be instantiated in global processes and must not be instantiated in any
* "per-note" or "per-voice" situations, as access to hardware quite often is limited to one accessor
* at a time. Since practically any per-voice or per-note element can access global instances (if not
* directly then via proxies like variables), this is no real limitation.
* TODO: enforce this type of use and guard it with a useful error message. The errors resulting from
* other types of use might not give the user a meaningful hint to the actual problem.
*
*/
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.Stateful;
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 class In implements ProcessElement, Stateful {
  private long nativeSpace;
  private double val=Double.NaN, _val=val;
  public In() {
  NativeObjects.registerNativeObject(this);
  }

  In(boolean s) {
  }

  private static ReadOnlyMap<Integer, SourceStore> sourceStoreMap=new ReadOnlyMapImpl<Integer, SourceStore>();
  private static final ReadOnlyMapImpl<Integer, ValueType> destTypeMap=new ReadOnlyMapImpl<Integer, ValueType>();
  protected static final ReadOnlyMapImpl<Integer, ValueType> sourceTypeMap=new ReadOnlyMapImpl<Integer, ValueType>();
  static{
  sourceTypeMap.put(StandardParameters.OUT.i, ValueType.STREAM);
  }
  private static ParameterMap inputsMap=new ParameterMap();
  private static ParameterMap outputsMap=new ParameterMap();
  static{
  outputsMap.put(StandardParameters.OUT);
  }

  SourceStore freq=null;
  SourceStore sync=null;
  SourceStore syncphase=null;
  private String instanceName, abstractName;

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

  @Override
  public void setSource(int connection, NamedSource source,
            int sourceIndex) throws UnknownConnectionException,
      TypeMismatchException {
  throw new UnknownConnectionException("attempt to set unknown generator parameter");
  }

  @Override
  public ReadOnlyMap<Integer, ValueType> getSourceTypes() {
  return sourceTypeMap;
  }

  @Override
  public double getValue(int index) {
  return val;
  }

  @Override
  public void advanceState() {
  // TODO: depending on type and inName, determine the next value.
  // May become a rather large if/else or switch/case structure
  // TODO: allow a mechanism for platform dependent inputs (like analog joysticks
  // on PCs, audio inputs, midi or serial lines, analog or digital inputs on
  // embedded platforms etc). This will require a native library with platform
  // dependent extensions for anything beyond the possibilities of java audio
  // and standard serial lines.
  _val=0d;
  }

  @Override
  public void advanceOutput() {
  val=_val;
  }

  @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 sourceStoreMap;
  }

  /**
   * @see de.maramuse.soundcomp.process.ProcessElement#clone()
   */
  @Override
  public In clone() {
  In c=new In();
  c.abstractName=abstractName;
  return c;
  }

  /*
   * (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.generator.In

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.