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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a Note to the chord.void
centerChordOctave
(int lowPitch, int maxPitch) Transpose the chord of +/- n octaves so that chord is centered between lowPitch and maxPitch;void
clear()
Remove all notes from the chord.clone()
int
Calculate 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.boolean
boolean
Compare the relative intervals of 2 Chords.int
Return the pitch of the highest note of the chord, 0 if no notes in the MidiChord.int
Return 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.int
hashCode()
Compute the hashcode based only on the pitches of notes composing the MidiChord.int
indexOfPitch
(int p) Find a MidiNote within the Chord whose pitch equals p.int
indexOfRelativePitch
(int p) Find a MidiNote within the MidiChord whose pitch relatively equals p, i.e independently of the octave (module 12 semitons).void
Make 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.int
size()
Get the number of notes in this Chord.toRelativeNoteString
(Note.Alteration flatOrSharp) toString()
void
transpose
(int t) Transpose all the notes of the MidiChord.
-
Constructor Details
-
Chord
public Chord() -
Chord
-
-
Method Details
-
size
public int size()Get the number of notes in this Chord.- Returns:
-
add
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
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
-
clear
public void clear()Remove all notes from the chord. -
getNotes
Return the notes of this chord.- Returns:
- A list of Note objects ordered by ascending pitch.
-
getPitches
Return the pitches of this chord.- Returns:
- A list ordered by ascending pitch.
-
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
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,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.
-
getNote
Return a single note of this chord.- Parameters:
index
- Index of the note in the chord.- Returns:
-
removeNote
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
- intmaxPitch
- 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
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
-
equalsRelative
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. -
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]".
-