Interface RhythmDatabase

All Known Implementing Classes:
DefaultRhythmDatabase

public interface RhythmDatabase
A RhythmDatabase is a collection of rhythms.

RhythmInfo instances are used to describe the available rhythms. Use getRhythmInstance(RhythmInfo) to get the Rhythm instance from a RhythmInfo instance.

  • Method Details

    • getDefault

      static RhythmDatabase getDefault()
      A helper method which just calls RhythmDatabaseFactory.getDefault().get().
      Returns:
    • getRhythmInstance

      Rhythm getRhythmInstance(String rId) throws UnavailableRhythmException
      Get a rhythm instance from its id.

      If rId contains 2 instances of the AdaptedRhythm.RHYTHM_ID_DELIMITER, then this id represents an AdaptedRhythm which is created on demand, see AdaptedRhythm.getUniqueId().In that case, the rhythm provider, the original rhythm and the time signature are obtained from rId, and the returned rhythm instance is obtained by calling RhythmProvider.getAdaptedRhythmInstance(Rhythm, TimeSignature).

      Rhythm instances can be cached.

      Parameters:
      rId - Unique rhythm id
      Returns:
      The rhythm whose uniqueId matches rId
      Throws:
      UnavailableRhythmException
      See Also:
    • getRhythmInstance

      Rhythm getRhythmInstance(RhythmInfo rhythmInfo) throws UnavailableRhythmException
      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

      RhythmInfo getRhythm(String rhythmId)
      Get the RhythmInfo instance from the specified rhythm unique id.

      RhyhmtInfo instances are cached.

      Parameters:
      rhythmId -
      Returns:
      Can be null if not found.
    • getAdaptedRhythmInstance

      AdaptedRhythm getAdaptedRhythmInstance(Rhythm r, TimeSignature ts)
      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

      List<RhythmInfo> getRhythms(Predicate<RhythmInfo> tester)
      Get the rhythms which are tested OK.
      Parameters:
      tester -
      Returns:
    • getRhythms

      default List<RhythmInfo> getRhythms(TimeSignature ts)
      Get the rhythms which match the specified time signature.
      Parameters:
      ts - TimeSignature
      Returns:
      All rhythms corresponding to TimeSignature ts.
    • getRhythms

      List<RhythmInfo> getRhythms(RhythmProvider rp)
      The rhythms associated to the specified RhythmProvider
      Parameters:
      rp -
      Returns:
      Throws:
      IllegalArgumentException - If rp is not a RhythmProvider available.
    • getRhythms

      default List<RhythmInfo> getRhythms()
      Returns:
      All rhythms stored in the database.
    • findRhythm

      default RhythmInfo findRhythm(RhythmFeatures rf, Predicate<RhythmInfo> tester)
      Find the RhythmInfo which "best matches" rf.

      Default implementation relies on RhythmFeatures.getMatchingScore().

      Parameters:
      rf -
      tester - Limit the search to RhythmInfo instances which match this tester.
      Returns:
      Can be null if can't match genre
      See Also:
    • findRhythm

      default RhythmInfo findRhythm(String text, Predicate<RhythmInfo> tester)
      Find the RhythmInfo which "best matches" text.

      Default implementation returns the first RhythmInfo for which one of the tags is contained in text. Or whose name or description contains text (ignoring case).

      Parameters:
      text -
      tester - Limit the search to RhythmInfo instances which match this tester.
      Returns:
      Can be null
    • getRhythmProvider

      RhythmProvider getRhythmProvider(Rhythm rhythm)
      Parameters:
      rhythm -
      Returns:
      The RhythmProvider of the specified rhythm. Null if not found.
    • getRhythmProvider

      RhythmProvider getRhythmProvider(RhythmInfo ri)
      Get the RhythmProvider for specified RhythmInfo.
      Parameters:
      ri -
      Returns:
      The RhythmProvider of the specified RhythmInfo. Can be null.
    • getRhythmProviders

      List<RhythmProvider> getRhythmProviders()
      The RhythmProviders used by this database.
      Returns:
    • getTimeSignatures

      default Set<TimeSignature> getTimeSignatures()
      Returns:
      The list of TimeSignature for which we have at least 1 rhythm in the database
    • getDefaultRhythm

      RhythmInfo getDefaultRhythm(TimeSignature ts)
      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

      default Rhythm getDefaultStubRhythmInstance(TimeSignature ts)
      Get the default stub rhythm for the specified TimeSignature.
      Parameters:
      ts -
      Returns:
      Can't be null.
    • setDefaultRhythm

      void setDefaultRhythm(TimeSignature ts, RhythmInfo ri)
      Set the default rhythm for this TimeSignature.
      Parameters:
      ts - TimeSignature
      ri -
      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.
    • addRhythm

      boolean addRhythm(RhythmProvider rp, RhythmInfo rInfo)
      Add one RhythmInfo to the database for the specified RhythmProvider.

      Fire a state changed event if RhythmInfo is actually added.

      Parameters:
      rp -
      rInfo -
      Returns:
      True if rInfo was actually added.
    • addRhythmInstance

      boolean addRhythmInstance(RhythmProvider rp, Rhythm r)
      Add one Rhythm instance to the database for the specified RhythmProvider.

      Fire a state changed event if Rhythm is actually added.

      Parameters:
      rp -
      r -
      Returns:
      True if r was actually added.
    • addChangeListener

      void addChangeListener(ChangeListener l)
      Listeners are notified when the rhythm database has changed.

      Note that listeners might be notified out of the Event Dispatch Thread.

      Parameters:
      l -
    • removeChangeListener

      void removeChangeListener(ChangeListener l)
    • toContentString

      default String toContentString()
      Return a string with the contents of the database.
      Returns:
    • toStatsString

      default String toStatsString()
      A string showing statistics about the specified database.
      Returns: