org.niffty
Class MusicSymbol

java.lang.Object
  |
  +--org.niffty.HeirarchyNode
        |
        +--org.niffty.MusicSymbol
All Implemented Interfaces:
Anchored
Direct Known Subclasses:
Accidental, AugmentationDot, Barline, Beam, Clef, KeySignature, Notehead, Rest, Stem, Tie, TimeSignature

public class MusicSymbol
extends HeirarchyNode
implements Anchored

MusicSymbol is a base class for music symbol classes used in a Staff. It is usually not constructed directly. MusicSymbol is used as a type for the objects which follow a TimeSlice in a Staff. Every MusicSymbol has a parent TimeSlice which is the object in which the MusicSymbol is listed.


Field Summary
protected  Tags _tags
           
 
Constructor Summary
MusicSymbol(Tags tags)
          Creates a new MusicSymbol with the given tags.
 
Method Summary
 void draw(java.awt.Graphics graphics)
          It is expected that the subclass will override this.
protected  Anchored findDefaultAnchor()
          This is a utility function to return the anchor of the previous MusicSymbol in the parent TimeSlice, or to return the parent time slice if there are no previous music symbols.
protected  int findLeftPositionedX()
          This is a utility function to return the screen X position of a left-positioned symbol (as defined by isLeftPositioned()).
protected  java.util.Vector findMultiNodes()
          This is a utility method which returns a list of nodes in this ID group for objects of the same type.
 int getIndex()
          Return the index of this music symbol in the parent's music symbol list.
 TimeSlice getParentTimeSlice()
          Return the parent TimeSlice.
 FinalPoint getScreenHotspot()
          This is a method of the Anchored interface.
 Tags getTags()
          Returns the Tags object containing the optional tags.
 void invalidate()
          This is automatically called after the object is modified to force this to recompute all its values when the "get" method is called for the value.
 boolean isLeftPositionedSymbol()
          Return true if this is a symbol, like a cleff change, which appears to the left of the main symbol in the time slice, like the stem.
 MusicSymbol nextInstanceOfInScore(java.lang.Class desiredClass)
          Return the next instance of the given class type looking forwards from this MusicSymbol in the entire score.
 MusicSymbol previousInstanceOf(java.lang.Class desiredClass)
          Return the previous instance of the given class type looking backwards from this MusicSymbol in the parent TimeSlice.
 MusicSymbol previousInstanceOfInScore(java.lang.Class desiredClass)
          Return the previous instance of the given class type looking backwards from this MusicSymbol in the entire score.
 MusicSymbol previousInstanceOfInStaff(java.lang.Class desiredClass)
          Return the previous instance of the given class type looking backwards from this MusicSymbol at all previous MusicSymbols in the same staff.
 
Methods inherited from class org.niffty.HeirarchyNode
addChild, getChild, getChildCount, getParentNode, nextInHeirarchy, previousInHeirarchy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_tags

protected Tags _tags
Constructor Detail

MusicSymbol

public MusicSymbol(Tags tags)
Creates a new MusicSymbol with the given tags. The parent will be set when this is added as a child to the parent.

Parameters:
tags - the tags for this music symbol. If this is null, then this uses an empty Tags object.
Method Detail

getParentTimeSlice

public TimeSlice getParentTimeSlice()
Return the parent TimeSlice. The parent is the TimeSlice object which created this Music Symbol and to which this MusicSymbol belongs. This is not to be confused with the _anchor which could be another MusicSymbol.


getTags

public Tags getTags()
Returns the Tags object containing the optional tags.


invalidate

public void invalidate()
This is automatically called after the object is modified to force this to recompute all its values when the "get" method is called for the value. The invalidate() method for MusicSymbol does nothing. A subclass deriving from this MusicSymbol should override this to do its own invalidate operations


findDefaultAnchor

protected Anchored findDefaultAnchor()
This is a utility function to return the anchor of the previous MusicSymbol in the parent TimeSlice, or to return the parent time slice if there are no previous music symbols.


findLeftPositionedX

protected int findLeftPositionedX()
This is a utility function to return the screen X position of a left-positioned symbol (as defined by isLeftPositioned()). This finds the hotspot of the next symbol in the time slice which isLeftPositioned() (or the hotspot of the time slice itself if there are no more) and subtracts from its X value the (measure width - 10) / (the measure symbol count - 1).


getScreenHotspot

public FinalPoint getScreenHotspot()
This is a method of the Anchored interface. As a default, just return the hotspot of the parent time slice. It is expected that the subclass will override this.

Specified by:
getScreenHotspot in interface Anchored
Returns:
The position of the hotspot in screen coordinates from top-left of screen (not relative to an anchor). This is a FinalPoint and not a Point so that the class can give access to its screen hotspot object knowing that the caller will not modify it. This is more efficient that returning a new Point every time getScreenHotspot() is called.
See Also:
FinalPoint.newPoint()

getIndex

public int getIndex()
Return the index of this music symbol in the parent's music symbol list.

Overrides:
getIndex in class HeirarchyNode
Throws:
HeirarchyException - if this does not have a parent.

isLeftPositionedSymbol

public boolean isLeftPositionedSymbol()
Return true if this is a symbol, like a cleff change, which appears to the left of the main symbol in the time slice, like the stem. The default return value is false but Cleff, TimeSignature, etc. should override and return true.


previousInstanceOf

public MusicSymbol previousInstanceOf(java.lang.Class desiredClass)
Return the previous instance of the given class type looking backwards from this MusicSymbol in the parent TimeSlice. For example, previousInstanceOf(Notehead.class) gets the previous Notehead.

Parameters:
desiredClass - Class object for the MusicSymbol being sought
Returns:
the previous MusicSymbol of the desired class in the parent TimeSlice, or null if not found.

previousInstanceOfInScore

public MusicSymbol previousInstanceOfInScore(java.lang.Class desiredClass)
Return the previous instance of the given class type looking backwards from this MusicSymbol in the entire score. For example, previousInstanceOfInScore(Beam.class) gets the previous Beam.

Parameters:
desiredClass - Class object for the MusicSymbol being sought
Returns:
the previous MusicSymbol of the desired class in the entire Score, or null if not found.

previousInstanceOfInStaff

public MusicSymbol previousInstanceOfInStaff(java.lang.Class desiredClass)
Return the previous instance of the given class type looking backwards from this MusicSymbol at all previous MusicSymbols in the same staff. For example, previousInstanceOfInStaff(Notehead.class) gets the previous Notehead in the staff.

Parameters:
desiredClass - Class object for the MusicSymbol being sought
Returns:
the previous MusicSymbol of the desired class in the same staff, or null if not found.

nextInstanceOfInScore

public MusicSymbol nextInstanceOfInScore(java.lang.Class desiredClass)
Return the next instance of the given class type looking forwards from this MusicSymbol in the entire score. For example, nextInstanceOfInScore(Beam.class) gets the next Beam. To find the next instance of the same class, see nextInstanceOfInScore()

Parameters:
desiredClass - Class object for the MusicSymbol being sought
Returns:
the next MusicSymbol of the desired class in the entire Score, or null if not found.

findMultiNodes

protected java.util.Vector findMultiNodes()
This is a utility method which returns a list of nodes in this ID group for objects of the same type. If there is no numberOfNodes tag (which defines the first node in the multi-node symbol), this returns a new empty Vector. If there is a numberOfNodes tag, this creates a new Vector and adds the given number of nodes of the same type and with the same ID tag, including this first node, and stops searching after that number have been found. If this reaches the end of the Score before the required number have been found, this also stops, and the returned Vector will not be complete. If a subsequent node of the same type and ID, which also has a numberOfNodes tag, is encountered before the number of nodes are found, this does not add it and stops searching.


draw

public void draw(java.awt.Graphics graphics)
It is expected that the subclass will override this.