Class ChordTypeDatabase

java.lang.Object
org.jjazz.harmony.api.ChordTypeDatabase

public class ChordTypeDatabase extends Object
Manage the list of recognized chordtypes and their aliases.

Used to retrieve instances of ChordTypes (which are unmutable). User can alter aliases which are saved as preferences.

  • Method Details

    • getInstance

      public static ChordTypeDatabase getInstance()
    • guessExtension

      public int guessExtension(String ctStr)
      Try to guess where the extension part of a chord type string starts.

      For example for "madd9", return 1 because base=m and extension="add9". Should be used only if a ChordType.getOriginalName() differs from ChordType.getName().

      Parameters:
      ctStr - A chord type string like "", "sus7", "7dim7M", "Maj7aug", "madd9", etc.
      Returns:
      The index of the first char of the extension. -1 if no extension found.
    • addAlias

      public void addAlias(ChordType ct, String alias) throws ChordTypeDatabase.InvalidAliasException
      Add an alias for the specified chord type.

      An alias can be used by only one chord type.

      Parameters:
      ct -
      alias - e.g. "-7" for the "m7" chord type
      Throws:
      IllegalArgumentException - If ct is not part of this database
      ChordTypeDatabase.InvalidAliasException - If alias is invalid, e.g. it's already used by a different chord type.
    • resetAliases

      public void resetAliases(ChordType ct)
    • resetAliasesToDefault

      public final void resetAliasesToDefault()
      Clear all the user changes.
    • getAliases

      public List<String> getAliases(ChordType ct)
      Get the aliases of the specified chord type.

      Use the aliases stored in the preferences if available, otherwise return the default aliases.

      Parameters:
      ct -
      Returns:
    • getChordTypes

      public ChordType[] getChordTypes()
      Get all the ChordTypes of the database.
      Returns:
    • getSize

      public int getSize()
      Get the number of chord types in the database.
      Returns:
    • getChordType

      public ChordType getChordType(int i)
      Get a chord type from the database.
      Parameters:
      i - The index of the chord type
      Returns:
    • getChordType

      public ChordType getChordType(String s)
      Get a chord type from the database from a String description.

      The String must match the chord type name or one of its aliases.

      Parameters:
      s - The String, e.g. "m7".
      Returns:
      A ChordType, null if no ChordType correspond to s.
    • getChordType

      public ChordType getChordType(List<Degree> degrees)
      Get the ChordType which match the specified degrees.
      Parameters:
      degrees -
      Returns:
      Can be null
    • getChordTypeIndex

      public int getChordTypeIndex(ChordType ct)
      The index of the ct in the database.
      Parameters:
      ct -
      Returns:
      -1 if ct is not present in the database.