Class Position
java.lang.Object
org.jjazz.chordleadsheet.api.item.Position
- All Implemented Interfaces:
Serializable
,Comparable<Position>
A position in a leadsheet.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add PropertyChangeListener.int
boolean
int
getBar()
float
getBeat()
The beat as a string (beat start at 1), e.g 2 if beat=1, 2.5 if beat=1.5float
The fractional part of the beat.getConvertedPosition
(TimeSignature tsFrom, TimeSignature tsTo) Convert the current position in tsFrom context, to a new position in tsTo context.float
getDuration
(Position pos, TimeSignature ts) The duration in natural beats between this position and the specified position.getMovedPosition
(int barOffset, float beatOffset) Get a new position where bar and beat are moved by the offset parameters.getNext
(TimeSignature ts) Get the next integer beat position in the specified TimeSignature context.float
The position in natural beats if all bars use the specified TimeSignature.Get the previous integer beat position in the specified TimeSignature context.int
hashCode()
boolean
boolean
isHalfBarBeat
(TimeSignature ts, boolean swing) True if position is at the half of the bar for the specified TimeSignature.boolean
True if position is equals or after the last logical beat of a bar.boolean
Get a new adjusted position which is guaranteed to fit the specified time signature.void
Remove PropertyChangeListener.void
reset()
Set bar and beat to 0.void
Set the position from another position.void
setBar
(int bar) void
setBeat
(float beat) void
Change position to be on first beat.void
Change position to be on last beat of the bar which has the specified TimeSignature.double
toDouble()
Return the position as a double value = bar + beat/10toString()
Same as toString() except bar and beat start at 1 instead of 0void
Set the position from a string as the one returned by toString() eg "[2:3.5]" or "[3]"
-
Field Details
-
PROP_BAR
- See Also:
-
PROP_BEAT
- See Also:
-
SEPARATOR_CHAR
public static final char SEPARATOR_CHARSeparator char, e.g ':' in "[8:2.5])".- See Also:
-
START_CHAR
public static final char START_CHAR- See Also:
-
END_CHAR
public static final char END_CHAR- See Also:
-
-
Constructor Details
-
Position
public Position()Equivalent to Position(0,0) -
Position
-
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
Set the position from another position.- Parameters:
p
- A Position.
-
setFirstBarBeat
public void setFirstBarBeat()Change position to be on first beat. -
setLastBarBeat
Change position to be on last beat of the bar which has the specified TimeSignature.- Parameters:
ts
- The TimeSignature of the bar.
-
equals
-
hashCode
public int hashCode() -
compareTo
- Specified by:
compareTo
in interfaceComparable<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
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
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
Get a new adjusted position which is guaranteed to fit the specified time signature.- Parameters:
ts
-- Returns:
-
getConvertedPosition
Convert the current position in tsFrom context, to a new position in tsTo context.- Parameters:
tsFrom
-tsTo
-- Returns:
-
getMovedPosition
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
Get the next integer beat position in the specified TimeSignature context.- Parameters:
ts
-- Returns:
-
getPrevious
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
The position in natural beats if all bars use the specified TimeSignature.- Parameters:
ts
-- Returns:
-
getDuration
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
-
toUserString
Same as toString() except bar and beat start at 1 instead of 0- Returns:
-
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
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
Add PropertyChangeListener.- Parameters:
listener
-
-
removePropertyChangeListener
Remove PropertyChangeListener.- Parameters:
listener
-
-