org.niffty
Class TimeSlice

java.lang.Object
  |
  +--org.niffty.HeirarchyNode
        |
        +--org.niffty.TimeSlice
All Implemented Interfaces:
Anchored

public class TimeSlice
extends HeirarchyNode
implements Anchored

A TimeSlice has a type, start time and optional tags. The type is EVENT since all time slices of type MEASURE_START are handled by MeasureStartTimeSlice. A TimeSlice also stores the music symbols following the time slice. Strictly speaking, this is slightly different than the NIFF spec where all the time slice and music symbol chunks are on the same "level" in the Staff, but formally dividing up music symbols into their EVENT time slice, and the EVENT time slices into their MEASURE_START time slice makes the data easier to process.

See Also:
MeasureStartTimeSlice

Constructor Summary
TimeSlice(Rational startTime, Tags tags)
          Creates a new TimeSlice with the given start time and tags, and an empty MusicSymbol list.
 
Method Summary
 void addMusicSymbol(MusicSymbol mysicSymbol)
          Add the given mysicSymbol to the MusicSymbol list.
 void draw(java.awt.Graphics graphics)
           
 int getIndex()
          Return the index of this time slice in the parent's time slice list.
 int getLeftPositionedSymbolCount()
          Return the count of music symbols in this time slice for which isLeftPositionedSymbol() is true.
 MusicSymbol getMusicSymbol(int index)
          Return the music symbol at the given index.
 int getMusicSymbolCount()
          Return the number of music symbols in the music symbol list.
 MeasureStartTimeSlice getParentMeasureStart()
          Return the parent MeasureStartTimeSlice.
 Score getParentScore()
          Return the ultimate Score object of which this is a child.
 FinalPoint getScreenHotspot()
          Get the hotspot for this object in screen coordinates.
 Rational getStartTime()
          Returns the start time Rational.
 Tags getTags()
          Returns the Tags object containing the optional tags.
 void invalidate()
          This is automatically called after the object is modified to force this and all child objects to recompute their values when the "get" method is called for the value.
 void print(java.lang.String indent, java.io.PrintStream output)
          This prints the time slice including all following music symbols.
 java.lang.String toString()
          This only returns the info for this time slice, not the following music symbols.
 
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, wait, wait, wait
 

Constructor Detail

TimeSlice

public TimeSlice(Rational startTime,
                 Tags tags)
Creates a new TimeSlice with the given start time and tags, and an empty MusicSymbol list. The type is EVENT. To create a time slice of type MEASURE_START, see MeasureStartTimeSlice

Parameters:
startTime - see getStartTime()
tags - the tags for this time slice. If this is null, then this uses an empty Tags object.
Method Detail

addMusicSymbol

public void addMusicSymbol(MusicSymbol mysicSymbol)
Add the given mysicSymbol to the MusicSymbol list. This does not call invalidate(), but you may need to before displaying.

Parameters:
mysicSymbol - the MusicSymbol to add. It is an error if this is already the child of an object.
Throws:
HeirarchyException - if the mysicSymbol has already been added as a child to another object.
See Also:
invalidate()

getParentMeasureStart

public MeasureStartTimeSlice getParentMeasureStart()
Return the parent MeasureStartTimeSlice.


getParentScore

public Score getParentScore()
Return the ultimate Score object of which this is a child.


getTags

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


getStartTime

public Rational getStartTime()
Returns the start time Rational. Since this is an EVENT time slice, this is the time since the beginning of the measure as given by the parent MeasureStartTimeSlice.

See Also:
getParentMeasureStart()

getMusicSymbolCount

public int getMusicSymbolCount()
Return the number of music symbols in the music symbol list.


getMusicSymbol

public MusicSymbol getMusicSymbol(int index)
Return the music symbol at the given index. The actual object returned is a subclass of MusicSymbol such as Notehead, etc. Use instanceof to determine the type.

Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index is negative or not less than the number of nodes in the child node list.

getIndex

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

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

invalidate

public void invalidate()
This is automatically called after the object is modified to force this and all child objects to recompute their values when the "get" method is called for the value.


getScreenHotspot

public FinalPoint getScreenHotspot()
Get the hotspot for this object in screen coordinates.

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()

getLeftPositionedSymbolCount

public int getLeftPositionedSymbolCount()
Return the count of music symbols in this time slice for which isLeftPositionedSymbol() is true.


draw

public void draw(java.awt.Graphics graphics)

toString

public java.lang.String toString()
This only returns the info for this time slice, not the following music symbols.

Overrides:
toString in class java.lang.Object

print

public void print(java.lang.String indent,
                  java.io.PrintStream output)
This prints the time slice including all following music symbols.

Parameters:
indent - A string such as " " to print at the beginning of the line
output - the PrintStream to print to, such as System.out