Package org.jjazz.harmony.api
Class Chord
java.lang.Object
org.jjazz.harmony.api.Chord
- All Implemented Interfaces:
- Cloneable
A chord is an array of notes which have different pitches.
 
Notes are kept ordered by pitch.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdd a Note to the chord.voidcenterChordOctave(int lowPitch, int maxPitch) Transpose the chord of +/- n octaves so that chord is centered between lowPitch and maxPitch;voidclear()Remove all notes from the chord.clone()intCalculate a "distance" between notes of chord c and this chord.computeParallelChord(List<Integer> relPitches, boolean startBelow) Use the specified relative pitches and this chord intervals to create a new chord.booleanbooleanCompare the relative intervals of 2 Chords.intReturn the pitch of the highest note of the chord, 0 if no notes in the MidiChord.intReturn the pitch of the lowest note of the chord, 0 if no notes in the MidiChord.getNote(int index) Return a single note of this chord.getNotes()Return the notes of this chord.Return the pitches of this chord.Get a chord built from the unique relative pitches present in this chord.inthashCode()Compute the hashcode based only on the pitches of notes composing the MidiChord.intindexOfPitch(int p) Find a MidiNote within the Chord whose pitch equals p.intindexOfRelativePitch(int p) Find a MidiNote within the MidiChord whose pitch relatively equals p, i.e independently of the octave (module 12 semitons).voidMake the MidiChord start at first octave : the lowest note of the MidiChord is transposed to be in octave 0.removeNote(int index) Remove a specific note in the chord.removePitch(int p) Remove the Note who has a specific pitch from the chord.intsize()Get the number of notes in this Chord.toRelativeNoteString(Note.Alteration flatOrSharp) toString()voidtranspose(int t) Transpose all the notes of the MidiChord.
- 
Constructor Details- 
Chordpublic Chord()
- 
Chord
 
- 
- 
Method Details- 
sizepublic int size()Get the number of notes in this Chord.- Returns:
 
- 
addAdd a Note to the chord.Nothing is done if note's pitch is already present. Notes are kept ordered by pitch. - Parameters:
- note-
 
- 
removePitchRemove 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
- 
clearpublic void clear()Remove all notes from the chord.
- 
getNotesReturn the notes of this chord.- Returns:
- A list of Note objects ordered by ascending pitch.
 
- 
getPitchesReturn the pitches of this chord.- Returns:
- A list ordered by ascending pitch.
 
- 
getRelativePitchChordGet 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:
 
- 
computeParallelChordUse 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,C4Ex: 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,C5Normally 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.
 
- 
getNoteReturn a single note of this chord.- Parameters:
- index- Index of the note in the chord.
- Returns:
 
- 
removeNoteRemove a specific note in the chord.- Parameters:
- index- Index of the note in the chord.
- Returns:
- The removed Note.
 
- 
indexOfPitchpublic 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.
 
- 
indexOfRelativePitchpublic 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.
 
- 
getMaxPitchpublic int getMaxPitch()Return the pitch of the highest note of the chord, 0 if no notes in the MidiChord.- Returns:
 
- 
getMinPitchpublic int getMinPitch()Return the pitch of the lowest note of the chord, 0 if no notes in the MidiChord.- Returns:
 
- 
centerChordOctavepublic 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
 
- 
transposepublic void transpose(int t) Transpose all the notes of the MidiChord.- Parameters:
- t- An integer representing the transposition value in semitons.
 
- 
computeDistanceCalculate 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.
 
- 
normalizepublic void normalize()Make the MidiChord start at first octave : the lowest note of the MidiChord is transposed to be in octave 0.
- 
equals
- 
equalsRelativeCompare 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.
 
- 
hashCodepublic int hashCode()Compute the hashcode based only on the pitches of notes composing the MidiChord.
- 
toString
- 
toRelativeNoteString- Parameters:
- flatOrSharp- Alteration display (if required) = Note.FLAT or Note.SHARP
- Returns:
- E.g. the string "[D,F#,C,E,D,A#]".
 
- 
toAbsoluteNoteString- Returns:
- E.g. the string "[D3,F#4,C5,E5,D6,Bb6]".
 
 
-