Interface ChordLeadSheet
The leadsheet is made of sections (a name + a time signature) and items like chord symbols. Implementation must fire the relevant ClsChangeEvents when a method mutates the chord leadsheet.
Regarding sections:
- The first bar must always contain a section
- 2 sections can't have the same name
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a listener to item changes of this object.void
addItem
(ChordLeadSheetItem<?> item) Add an item to the leadsheet.void
addSection
(CLI_Section section) Add a section to the leadsheet.void
Add a listener to undoable edits.<T> void
changeItem
(ChordLeadSheetItem<T> item, T data) Change the data of a specific item.void
cleanup()
Cleanup function to be called so that the object can be garbaged.boolean
contains
(ChordLeadSheetItem<?> item) Test if specified item belongs to this object.void
deleteBars
(int barIndexFrom, int barIndexTo) Delete bars and items from barIndexFrom to barIndexTo (inclusive).default <T extends ChordLeadSheetItem<?>>
TgetBarFirstItem
(int barIndex, Class<T> itemClass, Predicate<T> tester) Get the first matching item in the specified bar.default <T extends ChordLeadSheetItem<?>>
TgetBarLastItem
(int barIndex, Class<T> itemClass, Predicate<T> tester) Get the last matching item in the specified bar.default IntRange
Get the bar range of this chord leadsheet.default IntRange
getBarRange
(CLI_Section cliSection) The bar range of the specified section.<T extends ChordLeadSheetItem<?>>
TgetFirstItemAfter
(Position posFrom, boolean inclusiveFrom, Class<T> itemClass, Predicate<T> tester) Get the first matching item whose position is after (or equal, if inclusive is true) posFrom.default List<ChordLeadSheetItem>
getItems()
Get all the items.default <T extends ChordLeadSheetItem<?>>
List<T>Get the matching items which belong to bars between barFrom and barTo (included).default <T extends ChordLeadSheetItem<?>>
List<T>Get the matching items which belong to bars between barFrom and barTo (included).default <T extends ChordLeadSheetItem<?>>
List<T>Get all the matching items of this leadsheet.default <T extends ChordLeadSheetItem<?>>
List<T>Get all the matching items of this leadsheet.default <T extends ChordLeadSheetItem<?>>
List<T>getItems
(CLI_Section cliSection, Class<T> itemClass) Get the items which belong to a specific section.default <T extends ChordLeadSheetItem<?>>
List<T>getItems
(CLI_Section cliSection, Class<T> itemClass, Predicate<T> tester) Get the matching items which belong to a specific section.<T extends ChordLeadSheetItem<?>>
List<T>getItems
(Position posFrom, boolean inclusiveFrom, Position posTo, boolean inclusiveTo, Class<T> itemClass, Predicate<T> tester) Get the matching items whose position is in the position range.default <T extends ChordLeadSheetItem<?>>
List<T>getItemsAfter
(Position posFrom, boolean inclusive, Class<T> itemClass, Predicate<T> tester) Get the matching items whose position is after (or equal, if inclusive is true) posLow.default <T extends ChordLeadSheetItem<?>>
List<T>getItemsBefore
(Position posTo, boolean inclusive, Class<T> itemClass, Predicate<T> tester) Get the matching items whose position is before (or equal, if inclusive is true) posTo.<T extends ChordLeadSheetItem<?>>
TgetLastItemBefore
(Position posTo, boolean inclusiveTo, Class<T> itemClass, Predicate<T> tester) Get the last matching item whose position is before (or equal, if inclusive is true) posHigh.default <T> ChordLeadSheetItem<T>
getNextItem
(ChordLeadSheetItem<T> item) Get the next similar item (same class or subclass) after the specified item.default <T> ChordLeadSheetItem<T>
getPreviousItem
(ChordLeadSheetItem<T> item) Get the previous similar item (same class or subclass) before the specified item.default CLI_Section
getSection
(int barIndex) Get the Section of a specific bar.default CLI_Section
getSection
(String sectionName) Get a CLI_Section from its name.int
Get the size of the leadsheet in bars.void
insertBars
(int barIndex, int nbBars) Insert bars from a specific position.void
moveItem
(ChordLeadSheetItem<?> item, Position pos) Move an item to a new position.void
moveSection
(CLI_Section section, int newBarIndex) Move a section to a new position.void
Remove a listener to this object's changes.void
removeItem
(ChordLeadSheetItem<?> item) Remove an item from the leadsheet.void
removeSection
(CLI_Section section) Remove a section from the leadsheet.void
Remove a listener to undoable edits.void
setSectionName
(CLI_Section section, String name) Change the name of section.void
setSectionTimeSignature
(CLI_Section section, TimeSignature ts) Change the TimeSignature of a section.void
setSizeInBars
(int size) Set the size of the ChordLeadSheet.
-
Field Details
-
MAX_SIZE
static final int MAX_SIZE- See Also:
-
-
Method Details
-
addItem
Add an item to the leadsheet.Item position might be adjusted to the bar's TimeSignature. This will set the item's container to this ChordLeadSheet.
- Parameters:
item
- The ChordLeadSheetItem to add.- Throws:
IllegalArgumentException
- If item's position out of leadsheet bounds or item is a section.
-
removeItem
Remove an item from the leadsheet.- Parameters:
item
- The item to be removed.- Throws:
IllegalArgumentException
- If no such item or item is a section.
-
addSection
Add a section to the leadsheet.Trailing items' position might be adjusted if it results in a time signature change.
- Parameters:
section
-- Throws:
IllegalArgumentException
- If section already exists at specified position or invalid section.UnsupportedEditException
- If a ChordLeadSheet change listener does not authorize this edit. Exception is thrown before any change is done.
-
removeSection
Remove a section from the leadsheet.The section on bar 0 can not be removed. Trailing items' position might be adjusted if it results in a time signature change.
- Parameters:
section
-- Throws:
UnsupportedEditException
- If a ChordLeadSheet change listener does not authorize this edit. Exception is thrown before any change is done.
-
setSectionName
Change the name of section.- Parameters:
section
- The section to be changed.name
-- Throws:
IllegalArgumentException
- If name already exist, is a reserved name, or section does not belong to this leadsheet.
-
setSectionTimeSignature
Change the TimeSignature of a section.Trailing items' position might be adjusted to fit the new TimeSignature.
- Parameters:
section
- The section to be changed.ts
-- Throws:
IllegalArgumentException
- If section does not belong to this leadsheet.UnsupportedEditException
- If a ChordLeadSheet change listener does not authorize this edit. Exception is thrown before any change is done.
-
moveSection
Move a section to a new position.New position must be free of a section. Section on first bar can not be moved. Some items position might be adjusted to the new bar's TimeSignature.
- Parameters:
section
- The section to be movednewBarIndex
- The bar index section will be moved to- Throws:
UnsupportedEditException
- If a ChordLeadSheet change listener does not authorize this edit. Exception is thrown before any change is done.IllegalArgumentException
- If new position is not valid.
-
moveItem
Move an item to a new position.Can not be used on a Section. Item position might be adjusted to the bar's TimeSignature.
- Parameters:
item
- The item to be movedpos
- The new position.- Throws:
IllegalArgumentException
- If new position is not valid.
-
contains
Test if specified item belongs to this object.- Parameters:
item
-- Returns:
-
changeItem
Change the data of a specific item.Can not be used on Section, use setSectionName() or setSectionTimeSignature() instead.
- Type Parameters:
T
-- Parameters:
item
-data
-
-
insertBars
void insertBars(int barIndex, int nbBars) Insert bars from a specific position.If there are bars after barIndex, they are shifted accordingly.
- Parameters:
barIndex
- The bar index from which to insert the new bars.nbBars
- The number of bars to insert.- Throws:
IllegalArgumentException
- If barIndex < 0 or barIndex > size()
-
deleteBars
Delete bars and items from barIndexFrom to barIndexTo (inclusive).Bars after the deleted bars are shifted accordingly. Trailing items positions might be adjusted if it results in a time signature change.
- Parameters:
barIndexFrom
-barIndexTo
-- Throws:
UnsupportedEditException
- If a ChordLeadSheet change listener does not authorize this edit. IMPORTANT:some undoable changes might have been done before exception is thrown, caller will need to rollback them.
-
cleanup
void cleanup()Cleanup function to be called so that the object can be garbaged. -
getItems
<T extends ChordLeadSheetItem<?>> List<T> getItems(Position posFrom, boolean inclusiveFrom, Position posTo, boolean inclusiveTo, Class<T> itemClass, Predicate<T> tester) Get the matching items whose position is in the position range.- Type Parameters:
T
-- Parameters:
posFrom
-inclusiveFrom
-posTo
-inclusiveTo
-itemClass
- Accept items which are instance of class itemClasstester
- Accept items which satisfy the tester.- Returns:
- A non-modifiable ordered list of items
-
getLastItemBefore
<T extends ChordLeadSheetItem<?>> T getLastItemBefore(Position posTo, boolean inclusiveTo, Class<T> itemClass, Predicate<T> tester) Get the last matching item whose position is before (or equal, if inclusive is true) posHigh.- Type Parameters:
T
-- Parameters:
posTo
-inclusiveTo
-itemClass
- Accept items which are assignable from aClasstester
-- Returns:
- Can be null.
-
getFirstItemAfter
<T extends ChordLeadSheetItem<?>> T getFirstItemAfter(Position posFrom, boolean inclusiveFrom, Class<T> itemClass, Predicate<T> tester) Get the first matching item whose position is after (or equal, if inclusive is true) posFrom.- Type Parameters:
T
-- Parameters:
posFrom
-inclusiveFrom
-itemClass
-tester
-- Returns:
- Can be null
-
getItems
Get all the items.- Returns:
- A non-modifiable ordered list of items
-
getItems
Get all the matching items of this leadsheet.- Type Parameters:
T
-- Parameters:
itemClass
- Accept items which are instance of class itemClass- Returns:
- A non-modifiable ordered list of items
-
getItems
Get all the matching items of this leadsheet.- Type Parameters:
T
-- Parameters:
itemClass
- Accept items which are instance of class itemClasstester
- Accept items which satisfy the tester.- Returns:
- A non-modifiable ordered list of items
-
getItems
default <T extends ChordLeadSheetItem<?>> List<T> getItems(int barFrom, int barTo, Class<T> itemClass, Predicate<T> tester) Get the matching items which belong to bars between barFrom and barTo (included).- Type Parameters:
T
-- Parameters:
barFrom
-barTo
-itemClass
- Accept items which are instance of class aClass.tester
- Accept items which satisfy the tester.- Returns:
- A non-modifiable ordered list of items
-
getItems
default <T extends ChordLeadSheetItem<?>> List<T> getItems(int barFrom, int barTo, Class<T> itemClass) Get the matching items which belong to bars between barFrom and barTo (included).- Type Parameters:
T
-- Parameters:
barFrom
-barTo
-itemClass
- Accept items which are instance of class aClass.- Returns:
- A non-modifiable ordered list of items
-
getItemsAfter
default <T extends ChordLeadSheetItem<?>> List<T> getItemsAfter(Position posFrom, boolean inclusive, Class<T> itemClass, Predicate<T> tester) Get the matching items whose position is after (or equal, if inclusive is true) posLow.- Type Parameters:
T
-- Parameters:
posFrom
-inclusive
-itemClass
- Accept items which are instance of class itemClasstester
- Accept items which satisfy the tester.- Returns:
- A non-modifiable ordered list of items
-
getItemsBefore
default <T extends ChordLeadSheetItem<?>> List<T> getItemsBefore(Position posTo, boolean inclusive, Class<T> itemClass, Predicate<T> tester) Get the matching items whose position is before (or equal, if inclusive is true) posTo.- Type Parameters:
T
-- Parameters:
posTo
-inclusive
-itemClass
- Accept items which are instance of class itemClass. Can't be null.tester
- Accept items which satisfy the tester.- Returns:
- A non-modifiable ordered list of items
-
getItems
default <T extends ChordLeadSheetItem<?>> List<T> getItems(CLI_Section cliSection, Class<T> itemClass, Predicate<T> tester) Get the matching items which belong to a specific section.- Type Parameters:
T
-- Parameters:
cliSection
-itemClass
- Accept items which are instance of class aClasstester
- Accept items which satisfy the tester.- Returns:
- A non-modifiable ordered list of items
-
getItems
default <T extends ChordLeadSheetItem<?>> List<T> getItems(CLI_Section cliSection, Class<T> itemClass) Get the items which belong to a specific section.- Type Parameters:
T
-- Parameters:
cliSection
-itemClass
- Accept items which are instance of class aClass- Returns:
- A non-modifiable ordered list of items
-
getBarFirstItem
default <T extends ChordLeadSheetItem<?>> T getBarFirstItem(int barIndex, Class<T> itemClass, Predicate<T> tester) Get the first matching item in the specified bar.- Type Parameters:
T
-- Parameters:
barIndex
-itemClass
-tester
-- Returns:
- Can be null
-
getBarLastItem
default <T extends ChordLeadSheetItem<?>> T getBarLastItem(int barIndex, Class<T> itemClass, Predicate<T> tester) Get the last matching item in the specified bar.- Type Parameters:
T
-- Parameters:
barIndex
-itemClass
-tester
-- Returns:
- Can be null
-
getNextItem
Get the next similar item (same class or subclass) after the specified item.- Type Parameters:
T
-- Parameters:
item
-- Returns:
- Can be null if item is the last item of its kind.
-
getPreviousItem
Get the previous similar item (same class or subclass) before the specified item.- Type Parameters:
T
-- Parameters:
item
-- Returns:
- Can be null if item is the first item of its kind.
-
getSection
Get the Section of a specific bar.If the bar is after the end of the leadsheet, return the section of the last bar.
- Parameters:
barIndex
- The index of the bar.- Returns:
- The section.
-
getSection
Get a CLI_Section from its name.- Parameters:
sectionName
-- Returns:
- The section or null if not found.
-
getSizeInBars
int getSizeInBars()Get the size of the leadsheet in bars.- Returns:
-
getBarRange
Get the bar range of this chord leadsheet.- Returns:
- [0; getSizeInBars()-1]
-
getBarRange
The bar range of the specified section.- Parameters:
cliSection
-- Returns:
- Throws:
IllegalArgumentException
- If section does not exist in this ChordLeadSheet.
-
setSizeInBars
Set the size of the ChordLeadSheet.- Parameters:
size
- The numbers of bars, must be >= 1 and < MAX_SIZE.- Throws:
UnsupportedEditException
- If a ChordLeadSheet change listener does not authorize this edit. Exception is thrown before any change is done.
-
addClsChangeListener
Add a listener to item changes of this object.- Parameters:
l
-
-
removeClsChangeListener
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
-
-