Interface RhythmDatabase
Implementation should populate the database upon creation.
RhythmInfo instances are used to describe the available rhythms. They can be serialized by a Rhythmdatabase implementation in a cache file to avoid requesting all the Rhythm instances upon each startup -this is very time consuming when hundreds of rhythm files are used. Use getRhythmInstance(RhythmInfo) to get the Rhythm instance.
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
Associate a Rhythm instance to a RhythmProvider. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Listeners are notified when the rhythm database has changed.int
Add extra rhythms to the database.void
forceRescan
(boolean immediate) Force a rescan of all the RhythmProviders available in the lookup to add rhythms in the database.Try to provide the rhythm instance which is an adapted version of r for a different time signature.static RhythmDatabase
Use the first implementation present in the global lookup.Get the default Rhythm for TimeSignature ts.Get the default stub rhythm for the specified TimeSignature.Get the RhythmInfo instance from the specified rhythm unique id.getRhythmInstance
(String rhythmId) Get a rhythm instance from its id.getRhythmInstance
(RhythmInfo rhythmInfo) Get a rhythm instance from a RhythmInfo.getRhythmProvider
(String rpId) Get the RhythmProviderId which matchs the specified unique id.getRhythmProvider
(Rhythm rhythm) Get the RhythmProvider for specified RhythmInfo.The RhythmProviders instances currently available, sorted by name.getRhythms
(Predicate<RhythmInfo> tester) Get the rhythms which are tested OK.Get the rhythms which match the specified time signature.The rhythms associated to the specified RhythmProviderTry to find a rhythm in the database which is "similar" to the specified rhythm info.static RhythmDatabase
Get a special RhythmDatabase instance for unit tests.void
void
setDefaultRhythm
(TimeSignature ts, RhythmInfo ri) Set the default rhythm for this TimeSignature.int
size()
-
Method Details
-
getDefault
Use the first implementation present in the global lookup.If nothing found, use the default one.
- Returns:
-
getUnitTestDefault
Get a special RhythmDatabase instance for unit tests.- Returns:
-
getRhythmInstance
Get a rhythm instance from its id.If rhythmId contains 2 instances of the AdaptedRhythm.RHYTHM_ID_DELIMITER, then this id represents an AdaptedRhythm which is created on demand, see AdaptedRhythm.getUniqueId(). The rhythm provider, the original rhythm and the time signature are obtained from rhythmId, and the returned rhythm instance is obtained by calling RhythmProvider.getAdaptedRhythmInstance(Rhythm, TimeSignature). Rhythm instances are cached.
- Parameters:
rhythmId
- A unique id- Returns:
- The rhythm whose uniqueSerialId matches the specified id
- Throws:
UnavailableRhythmException
-
getRhythmInstance
Get a rhythm instance from a RhythmInfo.This might result in a lengthy operation (e.g. because of file reading). Rhythm instances are cached.
- Parameters:
rhythmInfo
-- Returns:
- Throws:
UnavailableRhythmException
-
getRhythm
Get the RhythmInfo instance from the specified rhythm unique id.RhyhmtInfo instances are cached.
- Parameters:
rhythmId
-- Returns:
- Can be null if not found.
-
getAdaptedRhythmInstance
Try to provide the rhythm instance which is an adapted version of r for a different time signature.If the adapted rhythm could be obtained it is added in the database. AdaptedRhythm instances are cached.
- Parameters:
r
-ts
-- Returns:
- Can be null if no adapted rhythm is available.
- Throws:
IllegalArgumentException
- If ts is the time signature of r, or if r is not a rhythm of this database.
-
getRhythms
Get the rhythms which are tested OK.- Parameters:
tester
-- Returns:
-
getRhythms
Get the rhythms which match the specified time signature.- Parameters:
ts
- TimeSignature- Returns:
- All rhythms corresponding to TimeSignature ts.
-
getRhythms
The rhythms associated to the specified RhythmProvider- Parameters:
rp
-- Returns:
- Throws:
IllegalArgumentException
- If rp is not a RhythmProvider available.
-
getSimilarRhythm
Try to find a rhythm in the database which is "similar" to the specified rhythm info."Similar" means at least share the same time signature. The implementation could for example use RhythmFeatures.getMatchingScore() to help identify the most similar rhythm.
- Parameters:
ri
-- Returns:
- A "similar" rhythm which at least share the same timesignature. Null if nothing relevant found.
-
getRhythms
List<RhythmInfo> getRhythms()- Returns:
- All rhythms stored in the database.
-
getRhythmProvider
- Parameters:
rhythm
-- Returns:
- The RhythmProvider of the specified rhythm. Null if not found.
-
getRhythmProvider
Get the RhythmProvider for specified RhythmInfo.- Parameters:
ri
-- Returns:
- The RhythmProvider of the specified RhythmInfo. Can be null.
-
getRhythmProvider
Get the RhythmProviderId which matchs the specified unique id.- Parameters:
rpId
-- Returns:
-
getRhythmProviders
List<RhythmProvider> getRhythmProviders()The RhythmProviders instances currently available, sorted by name.- Returns:
-
getTimeSignatures
List<TimeSignature> getTimeSignatures()- Returns:
- The list of TimeSignature for which we have at least 1 rhythm in the database
-
getDefaultRhythm
Get the default Rhythm for TimeSignature ts.- Parameters:
ts
- TimeSignature- Returns:
- Can not be null, but there is no guarantee that getRhythmInstance() on the returned value will work (e.g. if this RhythmInfo depends on a file which is no more available).
-
getDefaultStubRhythmInstance
Get the default stub rhythm for the specified TimeSignature.- Parameters:
ts
-- Returns:
- Can't be null.
-
setDefaultRhythm
Set the default rhythm for this TimeSignature.- Parameters:
ts
- TimeSignatureri
-- Throws:
IllegalArgumentException
- If rhythm is not part of this database or if ri is an AdaptedRhythm
-
size
int size()- Returns:
- The number of rhythms in the database.
-
forceRescan
void forceRescan(boolean immediate) Force a rescan of all the RhythmProviders available in the lookup to add rhythms in the database.Rescan is programmed to be performed at next application startup. It might be done immediatly if the immediate parameter is true and if the implementation supports it.
Note: once added in the database, a RhythmProvider and its Rhythms can't be removed (until program restarts).
Fire a change event if database has changed after the forceRescanUponStartup.- Parameters:
immediate
- If true try to rescan immediatly (without waiting for a restart).
-
addExtraRhythms
Add extra rhythms to the database.Add new rhythms to a populated database. Fire a change event after rhythms have been added.
- Parameters:
pairs
-- Returns:
- The nb of rhythms actually added.
-
addChangeListener
Listeners are notified when the rhythm database has changed.Note that listeners might be notified out of the Event Dispatch Thread.
- Parameters:
l
-
-
removeChangeListener
-