org.rubato.base
Class AbstractRubette

java.lang.Object
  extended by org.rubato.base.AbstractRubette
All Implemented Interfaces:
Rubette
Direct Known Subclasses:
AddressEvalRubette, AlterationRubette, BigBangRubette, BooleanRubette, ConstructorRubette, DisplayRubette, LatchRubette, ListRubette, MacroInputRubette, MacroOutputRubette, MacroRubette, MidiFileInRubette, MidiFileOutRubette, ModuleMapRubette, MuxRubette, RealArithRubette, ReformRubette, RegisterRubette, ScaleRubette, SchemeRubette, ScorePlayRubette, ScoreToCsoundRubette, Select2DRubette, SelectFormRubette, SetRubette, SimpleAbstractRubette, SimpleRubette, SourceRubette, SplitRubette, StatRubette, WallpaperRubette

public abstract class AbstractRubette
extends java.lang.Object
implements Rubette

Abstract base class for Rubettes. Any implementation of a Rubette must derive from this class. The methods are divided into four class:

  1. Methods that must be implemented
  2. Methods that can overridden, and provide default implementations
  3. Methods that can be used, but cannot be overridden
  4. Methods that are for internal use, and must not be used by an implementation

Author:
Gérard Milmeister

Constructor Summary
AbstractRubette()
          The default constructor must/should perform initializations specfic to each rubette instance, for example set the number of inputs and outputs, or initializing the rubette state.
 
Method Summary
 void addError(java.lang.Exception e)
          Adds an exception message to the current error state.
 void addError(java.lang.String msg, java.lang.Object... objects)
          Adds an error string to the current error state.
 boolean applyProperties()
          Makes changes in the properties dialog permanent.
 void clearErrors()
          Removes all errors from the error list.
abstract  Rubette duplicate()
          Creates a duplicate from this rubette instance.
abstract  Rubette fromXML(XMLReader reader, org.w3c.dom.Element element)
          Creates a rubette from an XML description starting with element.
 java.util.List<java.lang.String> getErrors()
          Returns a list of the current errors.
 java.lang.String getGroup()
          Returns the group this Rubette belongs to.
 javax.swing.ImageIcon getIcon()
          Returns an icon for this Rubette.
 int getInCount()
          Returns the current number of input connectors.
 java.lang.String getInfo()
          Returns the info string for the info label.
 Denotator getInput(int i)
          Returns the input denotator at input connector number i.
 java.lang.String getInTip(int i)
          Returns the tooltip for the input connector number i.
 java.lang.String getLongDescription()
          Returns a long description.
 RubetteModel getModel()
          Returns the RubetteModel, that this Rubette is attached to.
abstract  java.lang.String getName()
          Returns the name of the rubette.
 int getOutCount()
          Returns the current number of output connectors.
 Denotator getOutput(int i)
          Returns the output denotator of connectir number i.
 java.lang.String getOutTip(int i)
          Returns the tooltip for the output connector number i.
 javax.swing.JComponent getProperties()
          Returns the Swing component for the properties dialog.
 java.lang.String getShortDescription()
          Returns a short description.
 javax.swing.JComponent getView()
          Returns the Swing component for the view.
 boolean hasErrors()
          Returns true iff any error has occurred.
 boolean hasInfo()
          Returns true iff this Rubette has an info label.
 boolean hasProperties()
          Returns true iff this rubette has a properties dialog.
 boolean hasView()
          Returns true iff this Rubette has a view.
 void init()
          Initializes Rubette.
 Rubette newInstance()
          Creates a new instance from a protoype.
 void revertProperties()
          Reverts values in the properties dialog to the values in the Rubette.
abstract  void run(RunInfo runInfo)
          Runs the Rubette.
 void setInCount(int n)
          Sets the number of input connectors.
 void setModel(RubetteModel model)
          Sets the model this Rubette is attached to.
 void setOutCount(int n)
          Sets the number of output connectors.
 void setOutput(int i, Denotator d)
          Stores the output denotator d for output connector number i.
abstract  void toXML(XMLWriter writer)
          Writes an XML description of this rubette.
 void updateView()
          Updates the view reflecting the changes of the values in the Rubette.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractRubette

public AbstractRubette()
The default constructor must/should perform initializations specfic to each rubette instance, for example set the number of inputs and outputs, or initializing the rubette state.

Method Detail

run

public abstract void run(RunInfo runInfo)
Runs the Rubette. This is the heart of the Rubette and implements the actual computation. Input values are retrieved with the getInput method and output values are stored using the setOutput method. The runInfo parameter object has a method stopped() which should be called regularly, and, in the case it returns false, the run() method should exit gracefully.

Specified by:
run in interface Rubette
Parameters:
runInfo - contains information about the Runner that executes the network

getName

public abstract java.lang.String getName()
Returns the name of the rubette.

Specified by:
getName in interface Rubette

fromXML

public abstract Rubette fromXML(XMLReader reader,
                                org.w3c.dom.Element element)
Creates a rubette from an XML description starting with element.

Specified by:
fromXML in interface Rubette

toXML

public abstract void toXML(XMLWriter writer)
Writes an XML description of this rubette. This method should write XML for the configuration of this Rubette.

Specified by:
toXML in interface Rubette

init

public void init()
Initializes Rubette. This method is called when a Rubette is instantiated as a prototype. It does nothing by default.

Specified by:
init in interface Rubette

duplicate

public abstract Rubette duplicate()
Creates a duplicate from this rubette instance. All properties are copied if possible. This must be correctly implemented in order that many functions work as expected.

Specified by:
duplicate in interface Rubette

getGroup

public java.lang.String getGroup()
Returns the group this Rubette belongs to. The default group is "Other".

Specified by:
getGroup in interface Rubette

getIcon

public javax.swing.ImageIcon getIcon()
Returns an icon for this Rubette.

Specified by:
getIcon in interface Rubette

hasProperties

public boolean hasProperties()
Returns true iff this rubette has a properties dialog. Properties reflect the configuration of this Rubette, any changes in the properties dialog may affect the computation.

Specified by:
hasProperties in interface Rubette

getProperties

public javax.swing.JComponent getProperties()
Returns the Swing component for the properties dialog. If this rubette has no properties dialog, simply return null.

Specified by:
getProperties in interface Rubette

applyProperties

public boolean applyProperties()
Makes changes in the properties dialog permanent.

Specified by:
applyProperties in interface Rubette
Returns:
true iff the values in the properties dialog are correct

revertProperties

public void revertProperties()
Reverts values in the properties dialog to the values in the Rubette.

Specified by:
revertProperties in interface Rubette

hasView

public boolean hasView()
Returns true iff this Rubette has a view. A view should provide a visual (or aural) representation of the configuration (resp. values) of the Rubette, but must never affect the computation.

Specified by:
hasView in interface Rubette

getView

public javax.swing.JComponent getView()
Returns the Swing component for the view. If this Rubette has no view, this simply returns null.

Specified by:
getView in interface Rubette

updateView

public void updateView()
Updates the view reflecting the changes of the values in the Rubette. If there is no view, do nothing.

Specified by:
updateView in interface Rubette

hasInfo

public boolean hasInfo()
Returns true iff this Rubette has an info label. The info label is a short string that is displayed in the JRubette.

Specified by:
hasInfo in interface Rubette

getInfo

public java.lang.String getInfo()
Returns the info string for the info label. If this Rubette has no info label, this simply returns null.

Specified by:
getInfo in interface Rubette

getShortDescription

public java.lang.String getShortDescription()
Returns a short description. The short description is shown as a tooltip over the JRubette. The default text is the name of the rubette.

Specified by:
getShortDescription in interface Rubette

getLongDescription

public java.lang.String getLongDescription()
Returns a long description. The long description is shown in the text area below the Rubette list, if this Rubette is selected in the list.

Specified by:
getLongDescription in interface Rubette

getInTip

public java.lang.String getInTip(int i)
Returns the tooltip for the input connector number i.

Specified by:
getInTip in interface Rubette

getOutTip

public java.lang.String getOutTip(int i)
Returns the tooltip for the output connector number i.

Specified by:
getOutTip in interface Rubette

newInstance

public Rubette newInstance()
Creates a new instance from a protoype.

Specified by:
newInstance in interface Rubette

setInCount

public final void setInCount(int n)
Sets the number of input connectors. This method should be called with default value in the init() method. It can be called afterwards if the number of connectors changes.

Specified by:
setInCount in interface Rubette

getInCount

public final int getInCount()
Returns the current number of input connectors.

Specified by:
getInCount in interface Rubette

getInput

public final Denotator getInput(int i)
Returns the input denotator at input connector number i. This is usually called at the beginning of the run() method to get the input values. The run() method must check the return value which may be null.

Specified by:
getInput in interface Rubette

setOutCount

public final void setOutCount(int n)
Sets the number of output connectors. This method should be called with default value in the init() method. It can be called afterwards if the number of connectors changes.

Specified by:
setOutCount in interface Rubette

getOutCount

public final int getOutCount()
Returns the current number of output connectors.

Specified by:
getOutCount in interface Rubette

setOutput

public final void setOutput(int i,
                            Denotator d)
Stores the output denotator d for output connector number i. This is usually called at the end of the run() method to store the result of the computation.

Specified by:
setOutput in interface Rubette

getOutput

public final Denotator getOutput(int i)
Returns the output denotator of connectir number i. This is usually called by the Runner.

Specified by:
getOutput in interface Rubette

getModel

public final RubetteModel getModel()
Returns the RubetteModel, that this Rubette is attached to. This may be useful to retrieve information about the environment.

Specified by:
getModel in interface Rubette

addError

public final void addError(java.lang.String msg,
                           java.lang.Object... objects)
Adds an error string to the current error state. If an error occurs in the run() method, this method should be called with a short description of the error.

Specified by:
addError in interface Rubette

addError

public final void addError(java.lang.Exception e)
Adds an exception message to the current error state. A period (".") is appended if there is none in the message.


getErrors

public final java.util.List<java.lang.String> getErrors()
Returns a list of the current errors. This is called by the Runner. If no error has occurred, it returns an empty list, but never null.

Specified by:
getErrors in interface Rubette

clearErrors

public final void clearErrors()
Removes all errors from the error list. This is called by the Runner, before the run() method is executed.

Specified by:
clearErrors in interface Rubette

hasErrors

public final boolean hasErrors()
Returns true iff any error has occurred. This is called by the Runner, after the run() method has been executed.

Specified by:
hasErrors in interface Rubette

setModel

public final void setModel(RubetteModel model)
Sets the model this Rubette is attached to. This is called by the Composer, and should, in general, never be used by a Rubette implementation.

Specified by:
setModel in interface Rubette