Class ChordSymbol

java.lang.Object
org.jjazz.harmony.api.ChordSymbol
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
ExtChordSymbol

public class ChordSymbol extends Object implements Cloneable
A jazz chord symbol.

Examples : "Cm7", "F7b9", "Dbalt", "Amaj7/F#".

This is an immutable class.

  • Constructor Details

    • ChordSymbol

      public ChordSymbol()
      A "C" chord symbol.
    • ChordSymbol

      public ChordSymbol(Note rootDg, ChordType ct)
    • ChordSymbol

      public ChordSymbol(Note rootDg, Note bassDg, ChordType ct)
      Parameters:
      rootDg -
      bassDg - If null or it represents the same note, reuse rootDg
      ct -
    • ChordSymbol

      public ChordSymbol(String str) throws ParseException
      Construct a ChordSymbol from a string.

      All notes are made uppercase. Unusual notes Cb/B#/E#/Fb are renamed to B/C/F/E. Bass note is removed if identical to root note. Root accidental for natural notes is set based on usage (e.g. sharp for a D chord, flat for an F chord).

      Note that the special "NC" chord is not supported (see ExtChordSymbol.get()).

      Parameters:
      str - A string like "Cm7", "Abmaj7", "Bm7b5", "G#MAJ7", "cm/eb"
      Throws:
      ParseException
  • Method Details

    • clone

      public ChordSymbol clone()
    • getRootNote

      public Note getRootNote()
      Returns:
      Can not be null
    • getBassNote

      public Note getBassNote()
      Returns:
      Can not be null. Can be the root note if no different bass note was specified at construction.
    • isSlashChord

      public boolean isSlashChord()
      Check if chord sympbol has a bass note different from the root note.
      Returns:
    • getChordType

      public ChordType getChordType()
    • getName

      public String getName()
      The standard ChordSymbol recognized by JJazzLab.

      This may differ from the original name.

      Returns:
      See Also:
    • getOriginalName

      public String getOriginalName()
      Return the name used at creation if the ChordType(String) constructor has been used.

      It may differ from the getName() if a chord type alias was used. First char is always upper case.

      Returns:
    • getDefaultAccidental

      public Note.Accidental getDefaultAccidental()
      Return the most probable accidental to use when representing black key notes based on this chord symbol.
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dump

      public void dump()
      Print the ChordSymbol, its aliases and degrees
    • getTransposedChordSymbol

      public ChordSymbol getTransposedChordSymbol(int t, Note.Accidental alt)
      Get a transposed ChordSymbol.

      The originalName is also updated.

      Parameters:
      t - The amount of transposition in semi-tons.
      alt - If null, accidental of returned root and bass notes is unchanged. If not null use alt as root and bass notes accidental.
      Returns:
      A new transposed ChordSymbol.
    • getSimplified

      public ChordSymbol getSimplified(int nbMaxDegrees)
      Get a simplified ChordSymbol by keeping only the first nbMaxDegrees degrees.
      Parameters:
      nbMaxDegrees - Must be > 2
      Returns:
      Can't be null
    • getChord

      public Chord getChord()
      Get the chord corresponding to this ChordSymbol.

      First note of the chord is the relative pitch of the root note (bass note is ignored), then next notes are above the root note, with extension notes 9-11-13 at the end.

      The method chooses to use flat or sharp notes depending on the ChordSymbol, using the most "common" tonality associated to the ChordSymbol.

      Returns:
    • toNoteString

      public String toNoteString()
      Returns:
      E.g. for D7 return "[D, F#, A, C]"
    • isSameChordType

      public boolean isSameChordType(ChordSymbol cs)
      Compare chord types of 2 chord symbols.
      Parameters:
      cs - A chord symbol
      Returns:
      True if chords types are equivalent, e.g. for "Am7" and "Ebm-7"
    • getRelativePitch

      public int getRelativePitch(int relPitch, ChordSymbol destCs)
      Get the equivalent of relPitch but for the specified destination chord symbol.

      Ex: this=Dbm7, destCs=F, relPitch=4=E => return 8=Ab

      Parameters:
      relPitch - A relative pitch
      destCs -
      Returns:
      A relative pitch.
    • getRelativePitch

      public int getRelativePitch(ChordType.DegreeIndex di)
      Return the relative pitch corresponding to the specified degree index for this chord symbol.

      Ex: this=E7, degreeIndex=THIRD_OR_FOURTH, return G#=8.

      Note that it may return -1 even for degreeIndex=THIRD_OR_FOURTH when applied to a C2 chord.

      Parameters:
      di -
      Returns:
      -1 if no such degreeIndex.
    • getRelativePitch

      public int getRelativePitch(Degree d)
      Return the relative pitch corresponding to the specified degree based on this chord symbol root note.

      Ex: this=E7, degree=THIRT_FLAT, return G

      Parameters:
      d -
      Returns:
      A relative pitch.
    • equals

      public boolean equals(Object obj)
      Comparison is based on rootNote and bassNote relative pitch, ChordType and originalName.

      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getRandom

      public static ChordSymbol getRandom()
      Create a random chord symbol: random root note and chord type, sometimes with a different bass note.
      Returns: