Interface SongStructure
Implementation must fire the relevant SgsChangeEvents when a method mutates the song structure. If a RhythmParameter uses a value class which is mutable (implements MutableRpValue), the SongStructure will listen to value changes and propagate the change event via SgsChangeEvents.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener to changes of this object.void
addSongParts
(List<SongPart> spts) Add one by one a list of SongParts.void
Add a listener to undoable edits.void
authorizeAddSongParts
(List<SongPart> spts) Check if add operation is doable.void
authorizeRemoveSongParts
(List<SongPart> spts) Check if remove operation is doable.void
authorizeReplaceSongParts
(List<SongPart> oldSpts, List<SongPart> newSpts) Check if replace operation is doable.createSongPart
(Rhythm r, String name, int startBarIndex, int nbBars, CLI_Section parentSection, boolean reusePrevParamValues) Create a new SongPart instance whose container is this object.default IntRange
The bar range corresponding to this song structure.Returns the last rhythm used in this songStructure for this TimeSignature.An optional parent ChordLeadSheet.getRecommendedRhythm
(TimeSignature ts, int sptStartBarIndex) Get the recommended rhythm to use for a new SongPart.int
Get the size in bars of the song.getSongPart
(int absoluteBarIndex) Get the SongPart which contains a specific bar.getSongParts
(Predicate<SongPart> tester) Get the SongParts which match the tester.getSptItemPosition
(SongPart spt, ChordLeadSheetItem<?> clsItem) Get the absolute position in the song structure of a chordleadsheet item referred to by the specified song part.default List<AdaptedRhythm>
Return the list of unique AdaptedRhythms used in this SongStructure.getUniqueRhythms
(boolean excludeAdaptedRhythms, boolean excludeImplicitSourceRhythms) Return the list of unique rhythms used in this SongStructure.default List<RhythmVoice>
getUniqueRhythmVoices
(boolean excludeAdaptedRhythms, boolean excludeImplicitRhythms) Get all the unique RhythmVoices used by this SongStructure.default List<TimeSignature>
Get the list of unique TimeSignatures used in the SongStructure.void
Remove a listener to this object's changes.void
removeSongParts
(List<SongPart> spts) Remove some SongParts.void
Remove a listener to undoable edits.void
replaceSongParts
(List<SongPart> oldSpts, List<SongPart> newSpts) Replace SongParts by other SongParts.void
resizeSongParts
(Map<SongPart, Integer> mapSptSize) Change the size in bars of SongParts.<T> void
setRhythmParameterValue
(SongPart spt, RhythmParameter<T> rp, T value) Change the value of a specific RhythmParameter.void
setSongPartsName
(List<SongPart> spts, String name) Change the name of one or more SongParts.toBeatRange
(IntRange barRange) Converts the specified bar range into a natural beat range.default Position
toClsPosition
(Position pos) Converts a song structure position into a chord leadsheet position.toPosition
(float posInBeats) Converts a natural beats position into a bar/beats Position.float
toPositionInNaturalBeats
(int absoluteBarIndex) Converts the position of the specified bar in natural beats: take into account the possible different time signatures before specified bar.default float
Converts the specified position in natural beats: take into account the possible different time signatures before specified bar.
-
Method Details
-
getUniqueRhythms
default List<Rhythm> getUniqueRhythms(boolean excludeAdaptedRhythms, boolean excludeImplicitSourceRhythms) Return the list of unique rhythms used in this SongStructure.Parameters can be used to exclude from the return list AdaptedRhythm and "implicit source rhythm" instances.
An "implicit source rhythm" is the source rhythm of an AdaptedRhythm in a song which does not directly use the source rhythm. For example if song contains only spt1=bossa[3/4], then bossa(4/4) is the implicit source rhythm of the AdaptedRhythm bossa[3/4]. If song contains spt1=bossa and spt2=bossa[3/4], then bossa(4/4) is a source rhythm but is not an "implicit source rhythm".
If both excludeAdaptedRhythms and excludeImplicitSourceRhythms parameters are false and there is an implicit source rhythm, then the return list will contain the AdaptedRhythm instance juste before the implicit rhythm instance.
- Parameters:
excludeAdaptedRhythms
- If true, don't return AdaptedRhythm instancesexcludeImplicitSourceRhythms
- If true don't return "implicit source rhythms" instances- Returns:
- The list of rhythms, in the order they are used in the song.
-
getUniqueAdaptedRhythms
Return the list of unique AdaptedRhythms used in this SongStructure.- Returns:
- Can be empty. List is ordered by SongPart order.
-
getUniqueRhythmVoices
default List<RhythmVoice> getUniqueRhythmVoices(boolean excludeAdaptedRhythms, boolean excludeImplicitRhythms) Get all the unique RhythmVoices used by this SongStructure.Parameters are used to exclude RhythmVoice instances from AdaptedRhythms or "implicit source rhythms" (see getUniqueRhythms()).
- Parameters:
excludeAdaptedRhythms
- If true exclude the RhythmVoiceDelegate instances of AdaptedRhythmsexcludeImplicitRhythms
- If true exclude the RhythmVoice instances of the "implicit source rhythms"- Returns:
- See Also:
-
getUniqueTimeSignatures
Get the list of unique TimeSignatures used in the SongStructure.- Returns:
- List is ordered by SongPart order.
-
getParentChordLeadSheet
ChordLeadSheet getParentChordLeadSheet()An optional parent ChordLeadSheet.The SongStructure might listen to ChordLeadSheet changes to update itself accordingly.
- Returns:
- Can be null.
-
createSongPart
SongPart createSongPart(Rhythm r, String name, int startBarIndex, int nbBars, CLI_Section parentSection, boolean reusePrevParamValues) Create a new SongPart instance whose container is this object.Use default rhythm parameters values, unless reusePrevParamValues is true and there is a previous song part.
- Parameters:
r
-name
- The name of the created SongPart.startBarIndex
-nbBars
-parentSection
- Can be nullreusePrevParamValues
-- Returns:
-
getSongParts
- Returns:
- A copy of the list of SongParts ordered according to their getStartBarIndex().
-
getSongParts
Get the SongParts which match the tester.- Parameters:
tester
-- Returns:
-
getSongPart
Get the SongPart which contains a specific bar.- Parameters:
absoluteBarIndex
-- Returns:
- Can be null
-
getSizeInBars
int getSizeInBars()Get the size in bars of the song.- Returns:
-
getBarRange
The bar range corresponding to this song structure.- Returns:
- [0;getSizeInBars()-1]
- See Also:
-
toBeatRange
Converts the specified bar range into a natural beat range.The method must take into account SongParts with possibly different time signatures.
- Parameters:
barRange
- If null use the whole song structure.- Returns:
- Can be an empty range if barRange is not contained in the song structure.
-
toPositionInNaturalBeats
float toPositionInNaturalBeats(int absoluteBarIndex) Converts the position of the specified bar in natural beats: take into account the possible different time signatures before specified bar.- Parameters:
absoluteBarIndex
- A value in the range [0; getSizeInBars()].- Returns:
-
toPositionInNaturalBeats
Converts the specified position in natural beats: take into account the possible different time signatures before specified bar.- Parameters:
pos
-- Returns:
-
toClsPosition
Converts a song structure position into a chord leadsheet position.- Parameters:
pos
-- Returns:
- null if pos is beyond the end of the song
-
toPosition
Converts a natural beats position into a bar/beats Position.Take into account the possible different time signatures of the song.
- Parameters:
posInBeats
-- Returns:
- Null if posInBeats is beyond the end of the song.
-
getSptItemPosition
Get the absolute position in the song structure of a chordleadsheet item referred to by the specified song part.- Parameters:
spt
-clsItem
-- Returns:
- A position within spt range
- Throws:
IllegalArgumentException
- If clsItem does not belong to spt's parent Section.IllegalStateException
- If getParentChordLeadSheet() returns null.
-
authorizeAddSongParts
Check if add operation is doable.Operation is not doable if a new rhythm could not be accepted by listeners.
- Parameters:
spts
-- Throws:
UnsupportedEditException
-
addSongParts
Add one by one a list of SongParts.Each SongPart's startBarIndex must be a valid barIndex, either:
- equals to the startBarIndex of an existing SongPart
- the last barIndex+1
The startBarIndex of the trailing SongParts is shifted accordingly. The SongPart container will be set to this object.- Parameters:
spts
-- Throws:
UnsupportedEditException
- Exception is thrown before any change is done. See authorizeAddSongParts().
-
authorizeRemoveSongParts
Check if remove operation is doable.- Parameters:
spts
-- Throws:
UnsupportedEditException
-
removeSongParts
Remove some SongParts.The startBarIndex of the trailing SongParts are updated.
- Parameters:
spts
- A List of SongParts.- Throws:
UnsupportedEditException
- Exception is thrown before any change is done. See authorizeRemoveSongParts()
-
resizeSongParts
Change the size in bars of SongParts.The startBarIndex of the trailing SongParts are updated.
- Parameters:
mapSptSize
- A map which associates a SongPart and the new desired size.
-
authorizeReplaceSongParts
void authorizeReplaceSongParts(List<SongPart> oldSpts, List<SongPart> newSpts) throws UnsupportedEditException Check if replace operation is doable.UnsupportedEditException is thrown if replacement is impossible, because :
- not enough Midi channels for a new rhythm- Parameters:
oldSpts
-newSpts
-- Throws:
UnsupportedEditException
-
replaceSongParts
void replaceSongParts(List<SongPart> oldSpts, List<SongPart> newSpts) throws UnsupportedEditException Replace SongParts by other SongParts.Typically used to changed rhythm. The size and startBarIndex of new SongParts must be the same than the replaced ones. The container of newSpt will be set to this object.
- Parameters:
oldSpts
-newSpts
- size must match oldSpts- Throws:
UnsupportedEditException
- Exception is thrown before any change is done. See authorizeReplaceSongParts()
-
setSongPartsName
Change the name of one or more SongParts.- Parameters:
spts
-name
- The name of the SongParts.
-
setRhythmParameterValue
Change the value of a specific RhythmParameter.- Type Parameters:
T
-- Parameters:
spt
- The SongPart rp belongs to.rp
- The RhythmParameter.value
- The new value to apply for rp.
-
getLastUsedRhythm
Returns the last rhythm used in this songStructure for this TimeSignature.- Parameters:
ts
-- Returns:
- Can be null if the specified time signature has never been used by this SongStructure.
-
getRecommendedRhythm
Get the recommended rhythm to use for a new SongPart.If possible use getLastUsedRhythm(). If not possible then :
- return an AdaptedRhythm of the current rhythm at sptStartBarIndex,
- otherwise return the RhythmDatabase default rhythm for the time signature.- Parameters:
ts
- The TimeSignature of the rhythmsptStartBarIndex
- The start bar index of the new song part, can be on an existing song part, or right after the last song part.- Returns:
- Can't be null
-
addSgsChangeListener
Add a listener to changes of this object.- Parameters:
l
-
-
removeSgsChangeListener
Remove a listener to this object's changes.- Parameters:
l
-
-
addUndoableEditListener
Add a listener to undoable edits.- Parameters:
l
-
-
removeUndoableEditListener
Remove a listener to undoable edits.- Parameters:
l
-
-