Class Position

java.lang.Object
org.jjazz.chordleadsheet.api.item.Position
All Implemented Interfaces:
Serializable, Comparable<Position>

public final class Position extends Object implements Comparable<Position>, Serializable
A position in a leadsheet.
See Also:
  • Field Details

  • Constructor Details

    • Position

      public Position()
      Equivalent to Position(0,0)
    • Position

      public Position(Position pos)
    • Position

      public Position(int bar, float beat)
      Parameters:
      bar - The index of the bar (>=0).
      beat - The beat within this bar.
  • Method Details

    • setBeat

      public void setBeat(float beat)
    • setBar

      public void setBar(int bar)
    • reset

      public void reset()
      Set bar and beat to 0.
    • set

      public void set(Position p)
      Set the position from another position.

      Parameters:
      p - A Position.
    • setFirstBarBeat

      public void setFirstBarBeat()
      Change position to be on first beat.
    • setLastBarBeat

      public void setLastBarBeat(TimeSignature ts)
      Change position to be on last beat of the bar which has the specified TimeSignature.
      Parameters:
      ts - The TimeSignature of the bar.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(Position p)
      Specified by:
      compareTo in interface Comparable<Position>
    • isFirstBarBeat

      public boolean isFirstBarBeat()
      Returns:
      True if position is beat=0.
    • isOffBeat

      public boolean isOffBeat()
      Returns:
      True if beat's fractional part is != 0, eg true if beat=1.2
    • isLastBarBeat

      public boolean isLastBarBeat(TimeSignature ts)
      True if position is equals or after the last logical beat of a bar.

      Ex: ts=4/4 => return true if beat=3 or 3.3, false if beat < 3.

      Parameters:
      ts - The TimeSignature of the bar.
      Returns:
    • isHalfBarBeat

      public boolean isHalfBarBeat(TimeSignature ts, boolean swing)
      True if position is at the half of the bar for the specified TimeSignature.

      Ex: beat 2 for ts=4/4, beat 1.5 for 3/4 (if not swing), or beat 3 for 5/4.

      Parameters:
      ts - The TimeSignature of the bar.
      swing - If true for example half beat for a 3/4 waltz is 5/3=1.666...
      Returns:
    • limitToTimeSignature

      public Position limitToTimeSignature(TimeSignature ts)
      Get a new adjusted position which is guaranteed to fit the specified time signature.
      Parameters:
      ts -
      Returns:
    • getConvertedPosition

      public Position getConvertedPosition(TimeSignature tsFrom, TimeSignature tsTo)
      Convert the current position in tsFrom context, to a new position in tsTo context.
      Parameters:
      tsFrom -
      tsTo -
      Returns:
    • getMovedPosition

      public Position getMovedPosition(int barOffset, float beatOffset)
      Get a new position where bar and beat are moved by the offset parameters.
      Parameters:
      barOffset -
      beatOffset -
      Returns:
      Throws:
      IllegalArgumentException - If resulting bar or beat is a negative value.
    • getNext

      public Position getNext(TimeSignature ts)
      Get the next integer beat position in the specified TimeSignature context.
      Parameters:
      ts -
      Returns:
    • getPrevious

      public Position getPrevious(TimeSignature ts)
      Get the previous integer beat position in the specified TimeSignature context.
      Parameters:
      ts -
      Returns:
      Throws:
      IllegalArgumentException - If this position is already bar=0 beat=0.
    • getPositionInBeats

      public float getPositionInBeats(TimeSignature ts)
      The position in natural beats if all bars use the specified TimeSignature.
      Parameters:
      ts -
      Returns:
    • getDuration

      public float getDuration(Position pos, TimeSignature ts)
      The duration in natural beats between this position and the specified position.
      Parameters:
      pos - Can be before or after this position.
      ts -
      Returns:
      A positive value.
    • getBar

      public int getBar()
    • getBeat

      public float getBeat()
    • getBeatFractionalPart

      public float getBeatFractionalPart()
      The fractional part of the beat.
      Returns:
      eg .2 if beat=3.2
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      "[3:2.5]" means bar=3, beat=2.5. Note that bar and beat start at 0.
    • toUserString

      public String toUserString()
      Same as toString() except bar and beat start at 1 instead of 0
      Returns:
    • getBeatAsUserString

      public String getBeatAsUserString()
      The beat as a string (beat start at 1), e.g 2 if beat=1, 2.5 if beat=1.5
      Returns:
    • toDouble

      public double toDouble()
      Return the position as a double value = bar + beat/10

      Returns:
      double
    • valueOf

      public void valueOf(String userString, int defaultBar) throws ParseException
      Set the position from a string as the one returned by toString() eg "[2:3.5]" or "[3]"

      Ex: "[2:3.5]" will set bar=2 and beat=3.5
      Ex: "[3.5]" set bar=defaultBar and beat=3.5

      Parameters:
      userString - The string as returned by toString()
      defaultBar - If bar is not specified, defaultBar is used.
      Throws:
      ParseException - If syntax error in string.
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener listener)
      Add PropertyChangeListener.
      Parameters:
      listener -
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener listener)
      Remove PropertyChangeListener.
      Parameters:
      listener -