Package de.maramuse.soundcomp.process

Source Code of de.maramuse.soundcomp.process.EventFlipFlop

package de.maramuse.soundcomp.process;

/*
* 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 flip flop that is triggered by the TimerMap
* TODO: native counterpart. Needs no setter for state, only the value getter.
*/

import de.maramuse.soundcomp.process.StandardParameters.Parameter;
import de.maramuse.soundcomp.process.TimerMap.Event;
import de.maramuse.soundcomp.util.NativeObjects;
import de.maramuse.soundcomp.util.ReadOnlyMap;
import de.maramuse.soundcomp.util.ReadOnlyMapImpl;

public class EventFlipFlop implements ProcessElement, Stateful {
  public long nativeSpace=-1;
  private boolean state=false;
  private boolean state_int=false;
  private String abstractName;
  private String instanceName;

  public EventFlipFlop() {
  NativeObjects.registerNativeObject(this);
  }

  EventFlipFlop(boolean s) {
  }

  public Event getOnEvent() {
  return new Event() {
    @Override
    public void notifyElement(ProcessElement processElement) {
    // processElement is always the flipflop here
    EventFlipFlop.this.setOn();
    }
  };
  }

  public Event getOffEvent() {
  return new Event() {
    @Override
    public void notifyElement(ProcessElement processElement) {
    // processElement is always the flipflop here
    EventFlipFlop.this.setOff();
    }
  };
  }

  private static final ReadOnlyMapImpl<Integer, ValueType> sourceTypes=new ReadOnlyMapImpl<Integer, ValueType>();
  private static final ReadOnlyMapImpl<Integer, ValueType> destMap=new ReadOnlyMapImpl<Integer, ValueType>();
  private static ParameterMap inputsMap=new ParameterMap();
  private static ParameterMap outputsMap=new ParameterMap();
  static{
  outputsMap.put(StandardParameters.OUT);
  }
  static{
  sourceTypes.put(StandardParameters.OUT.i, ValueType.STREAM);
  }

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

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

  @Override
  public void setSource(int connectionIndex, NamedSource source,
            int sourceIndex) throws UnknownConnectionException,
    TypeMismatchException {
  // no sources to set
  }

  @Override
  public double getValue(int index) {
  return state ? 1.0 : 0.0;
  }

  @Override
  public void advanceOutput() {
  state=state_int;
  }

  @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 EventFlipFlop clone() {
  EventFlipFlop n=new EventFlipFlop();
  n.state=state;
  n.state_int=state_int;
  return n;
  }

  private void setOn() {
  state_int=true;
  }

  private void setOff() {
  state_int=false;
  }

  @Override
  public ReadOnlyMap<Integer, SourceStore> getSourceMap() {
  return ReadOnlyMapImpl.emptyMapIntSource;
  }

  /*
   * (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.process.EventFlipFlop

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.