Class Chord

java.lang.Object
org.jjazz.harmony.api.Chord
All Implemented Interfaces:
Cloneable

public class Chord extends Object implements Cloneable
A chord is an array of notes which have different pitches.

Notes are kept ordered by pitch.

  • Constructor Details

    • Chord

      public Chord()
    • Chord

      public Chord(List<? extends Note> newNotes)
  • Method Details

    • size

      public int size()
      Get the number of notes in this Chord.
      Returns:
    • add

      public void add(Note note)
      Add a Note to the chord.

      Nothing is done if note's pitch is already present. Notes are kept ordered by pitch.

      Parameters:
      note -
    • removePitch

      public Note removePitch(int p)
      Remove the Note who has a specific pitch from the chord.
      Parameters:
      p - Pitch of the note to remove.
      Returns:
      The removed Note. Null if not found.
    • clone

      public Chord clone()
    • clear

      public void clear()
      Remove all notes from the chord.
    • getNotes

      public List<Note> getNotes()
      Return the notes of this chord.
      Returns:
      A list of Note objects ordered by ascending pitch.
    • getPitches

      public List<Integer> getPitches()
      Return the pitches of this chord.
      Returns:
      A list ordered by ascending pitch.
    • getRelativePitchChord

      public Chord getRelativePitchChord()
      Get a chord built from the unique relative pitches present in this chord.

      Ex: if chord notes=C2,C3,E3,G4, return a chord with notes=C1,E1,G1

      Returns:
    • computeParallelChord

      public Chord computeParallelChord(List<Integer> relPitches, boolean startBelow)
      Use the specified relative pitches and this chord intervals to create a new chord.

      Ex: if this=C2,G3,E4 and relPitches=Ab0,Eb0,C0 (3,7,5 degrees of Fm7) and startBelow=true
      then result chord=Ab1,Eb3,C4

      Ex: if this=C1,C2,G3,E4 and relPitches=Ab0,Eb0,C0 (3,7,5 degrees of Fm7) and startBelow=false
      then result chord=Ab1,Ab2,Eb4,C5

      Normally the resulting chord has the same size than this chord. However if we reach the upper pitch limit (127) during the calculation this can result in a smallest chord (because 2 notes end up having the same pitch).

      Parameters:
      relPitches - A list of relative pitch [0-11]. Size must be equal to this chord's number of unique notes.
      startBelow - If true the first (lowest) note is created equals or below the first note of this chord.
      Returns:
      A Chord whose size is equals or less than this Chord size.
    • getNote

      public Note getNote(int index)
      Return a single note of this chord.
      Parameters:
      index - Index of the note in the chord.
      Returns:
    • removeNote

      public Note removeNote(int index)
      Remove a specific note in the chord.
      Parameters:
      index - Index of the note in the chord.
      Returns:
      The removed Note.
    • indexOfPitch

      public int indexOfPitch(int p)
      Find a MidiNote within the Chord whose pitch equals p.
      Parameters:
      p - Pitch to search for.
      Returns:
      The index of the object if found, otherwise -1.
    • indexOfRelativePitch

      public int indexOfRelativePitch(int p)
      Find a MidiNote within the MidiChord whose pitch relatively equals p, i.e independently of the octave (module 12 semitons).
      Parameters:
      p - Relative pitch to search for, 0-11.
      Returns:
      The index of the MidiNote if found, otherwise -1.
    • getMaxPitch

      public int getMaxPitch()
      Return the pitch of the highest note of the chord, 0 if no notes in the MidiChord.
      Returns:
    • getMinPitch

      public int getMinPitch()
      Return the pitch of the lowest note of the chord, 0 if no notes in the MidiChord.
      Returns:
    • centerChordOctave

      public void centerChordOctave(int lowPitch, int maxPitch)
      Transpose the chord of +/- n octaves so that chord is centered between lowPitch and maxPitch;
      Parameters:
      lowPitch - int
      maxPitch - int
    • transpose

      public void transpose(int t)
      Transpose all the notes of the MidiChord.
      Parameters:
      t - An integer representing the transposition value in semitons.
    • computeDistance

      public int computeDistance(Chord c)
      Calculate a "distance" between notes of chord c and this chord.
      Parameters:
      c - Must have the same number of notes than this chord.
      Returns:
      The sum of note-to-note absolute distances in semi-tons.
    • normalize

      public void normalize()
      Make the MidiChord start at first octave : the lowest note of the MidiChord is transposed to be in octave 0.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      Parameters:
      obj -
      Returns:
      True if the notes composing the specified MidiChord are the same.
    • equalsRelative

      public boolean equalsRelative(Chord c)
      Compare the relative intervals of 2 Chords.

      E.g. [C2,E2].equalsRelative([F4,A4]) will return true.

      Parameters:
      c - The chord to compare to.
      Returns:
      True if chords relatively represent the same voicing.
    • hashCode

      public int hashCode()
      Compute the hashcode based only on the pitches of notes composing the MidiChord.
      Overrides:
      hashCode in class Object
      Returns:
      The hashcode of the MidiChord.
    • toString

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

      public String toRelativeNoteString(Note.Alteration flatOrSharp)
      Parameters:
      flatOrSharp - Alteration display (if required) = Note.FLAT or Note.SHARP
      Returns:
      E.g. the string "[D,F#,C,E,D,A#]".
    • toAbsoluteNoteString

      public String toAbsoluteNoteString()
      Returns:
      E.g. the string "[D3,F#4,C5,E5,D6,Bb6]".