Class Note
- All Implemented Interfaces:
Cloneable
,Comparable<Note>
- Direct Known Subclasses:
NoteEvent
This is an immutable class.
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionNote()
Use MidiConst.PITCH_STD, Quarter duration, Alteration.Flat and standard velocity.Note
(int p) Create a note with a default beatDuration=1 and standard velocity.Note
(int p, float bd) Create a Note with a pitch and a beat duration and standard velocity.Note
(int p, float bd, int v) Create a Note with a pitch, a duration in beat, standard velocity and an alteration if any.Note
(int p, float bd, int v, Note.Alteration alt) Create a Note with a pitch, a duration in beat, a velocity and an alteration if any.Build a note from a string as specified below.A new note based on n but with pitch=newPitchNote
(Note n, Note.Alteration alt) A new note based on n but with the specified alteration. -
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checkOctave
(int o) This is the "natural" octave, from 0 to 10.static boolean
checkPitch
(int p) static boolean
checkVelocity
(int v) clone()
int
Compare 2 notes.boolean
Compare 2 objects.boolean
Compare the relative pitch of 2 notes.final Note.Alteration
getCentered
(int lowPitch, int highPitch) Change the octave of this note so that pitch is within the pitch limits (included).static Note[]
getChromaticNotesArray
(int pitchFrom, int pitchTo) Return an array of notes whose pitch start from pitchFrom up to pitchTo (included).
E.g., if pitchFrom=0 and pitchTo=12, return the array ["C0", "C#0", "D0"...."int
getClosestPitch
(int relPitch) Return the absolute pitch of the closest note from this note.final float
int
Get the G-clef staff line for this note.int
getLowerPitch
(int relPitch, boolean acceptEquals) Return the absolute pitch corresponding to relPitch below this note (or possibly equals if acceptEquals is true).static int
getNormalizedRelPitch
(int absPitch) Convert a positive or relative absolute pitch to a relative pitch between 0 and 11.final int
The octave starting at 0 for pitch=0, so for example the "Midi middle C=60" octave is 5.final int
getPitch()
int
int
final int
int
getRelativePitchDelta
(int relPitch) Calculate the shortest pitch delta from this note's relative pitch to relPitch.final SymbolicDuration
getTransposed
(int t) Transpose the note from t semi-tons.getTransposed
(int pitchShift, int pitchLimit) Get a new transposed note.getTransposedWithinOctave
(int t) Get a transposed note which is guaranteed to be in the same C-based octave.int
getUpperPitch
(int relPitch, boolean inclusive) Return the absolute pitch corresponding to relPitch above this note (or possibly equals if inclusive is true).int
int
hashCode()
Uses pitch, beatDuration and velocity, alterationDisplay is ignored.boolean
isFlat()
static boolean
isWhiteKey
(int pitch) Return Check if a pitch corresponds to keyboard white key (C major scale).static int
limitPitch
(int pitch, int lowPitch, int highPitch) Return a pitch which is guaranteed to be between lowPitch and highPitch.static Note
Create a Note from a String created with saveAsString().static Note
Convert a string generated by toPianoOctaveString() (like "C4") to a note.static String
saveAsString
(Note n, boolean skipAlteration) Save a Note as a String object.The note using the "piano octave", e.g.toString()
Same as toPianoOctaveString().
-
Field Details
-
VELOCITY_MIN
public static final int VELOCITY_MIN- See Also:
-
VELOCITY_STD
public static final int VELOCITY_STD- See Also:
-
VELOCITY_MAX
public static final int VELOCITY_MAX- See Also:
-
PITCH_MIN
public static final int PITCH_MIN- See Also:
-
PITCH_STD
public static final int PITCH_STD- See Also:
-
PITCH_MAX
public static final int PITCH_MAX- See Also:
-
OCTAVE_MIN
public static final int OCTAVE_MIN- See Also:
-
OCTAVE_STD
public static final int OCTAVE_STD- See Also:
-
OCTAVE_MAX
public static final int OCTAVE_MAX- See Also:
-
notesFlat
-
notesSharp
Available for general use.
-
-
Constructor Details
-
Note
public Note()Use MidiConst.PITCH_STD, Quarter duration, Alteration.Flat and standard velocity. -
Note
public Note(int p) Create a note with a default beatDuration=1 and standard velocity. Use FLAT symbols if relevant- Parameters:
p
- The pitch of the note.
-
Note
public Note(int p, float bd) Create a Note with a pitch and a beat duration and standard velocity. Use FLAT symbol by default.- Parameters:
p
- The pitch of the note.bd
- The beat duration of the note.
-
Note
public Note(int p, float bd, int v) Create a Note with a pitch, a duration in beat, standard velocity and an alteration if any.- Parameters:
p
-bd
-v
-
-
Note
Create a Note with a pitch, a duration in beat, a velocity and an alteration if any.- Parameters:
p
-bd
- Must be > 0v
- velocityalt
-
-
Note
A new note based on n but with pitch=newPitch- Parameters:
n
-newPitch
-
-
Note
A new note based on n but with the specified alteration.- Parameters:
n
-alt
-
-
Note
Build a note from a string as specified below.Ex: "G", "Cb", "A#m6", "E7" will generate notes G, B, A#, E with Const.OCTAVE_STD for the octave id.
Ex: "C!3", "Db!6", "A#dim!2" will generate notes C octave 3, Db octave 6, A# octave 2.
Important: note that the octave range is [0-10], unlike for toPianoOctaveString().- Parameters:
s
- A string- Throws:
ParseException
- If syntax error in string specification.
-
-
Method Details
-
clone
-
getPitch
public final int getPitch() -
getRelativePitch
public final int getRelativePitch()- Returns:
- An integer between 0 and 11.
-
getDurationInBeats
public final float getDurationInBeats() -
getSymbolicDuration
-
getOctave
public final int getOctave()The octave starting at 0 for pitch=0, so for example the "Midi middle C=60" octave is 5.- Returns:
-
getAlterationDisplay
-
getRelativeAscInterval
- Parameters:
n
- A Note.- Returns:
- The relative ascendant interval in semitons towards n.
-
getRelativeDescInterval
- Parameters:
n
- A Note.- Returns:
- The ascendant interval in semitons towards n.
-
getRelativePitchDelta
public int getRelativePitchDelta(int relPitch) Calculate the shortest pitch delta from this note's relative pitch to relPitch.Ex: if this=B3 and relPitch=0(C) then return 1.
Ex: if this=E2 and relPitch=1(Db) then return -3.- Parameters:
relPitch
-- Returns:
- A value between -5 and +6.
-
getTransposed
Transpose the note from t semi-tons.- Parameters:
t
- Transposition value in positive/negative semi-tons.- Returns:
- A new note transposed with the same alteration display.
-
getCentered
Change the octave of this note so that pitch is within the pitch limits (included).- Parameters:
lowPitch
- Must be < (highPitch-12)highPitch
-- Returns:
- The new note with corrected pitch and same alteration display
-
getTransposed
Get a new transposed note.If the new note is beyond pitchLimit, the note's octave is changed to remain below (pitchShift > 0) or above (pitchSshift < 0) pitchLimit.
- Parameters:
pitchShift
- A negative or positive value i semi-tons.pitchLimit
- Authorized values are [13, 119]- Returns:
- The new transposed Note with same alteration display
-
getTransposedWithinOctave
Get a transposed note which is guaranteed to be in the same C-based octave.- Parameters:
t
- Transposition value in positive/negative semi-tons.- Returns:
- A new note transposed from t semi-tons but within the same octave and same alteration display.
-
getLowerPitch
public int getLowerPitch(int relPitch, boolean acceptEquals) Return the absolute pitch corresponding to relPitch below this note (or possibly equals if acceptEquals is true).If this note's relative pitch is less than relativePitch, return this note's absolute pitch-12.
Ex: this=G3. If relativePitch=F return value=F3, if relativePitch=A return value=A2If resulting pitch < 0, return resulting pitch+12
- Parameters:
relPitch
-acceptEquals
-- Returns:
- An absolute note pitch
- Throws:
IllegalArgumentException
- If there is no lower pitch possible.
-
getUpperPitch
public int getUpperPitch(int relPitch, boolean inclusive) Return the absolute pitch corresponding to relPitch above this note (or possibly equals if inclusive is true).Ex: this=G3. If relativePitch=F return value=F4, if relativePitch=A return value=A3
If resulting pitch >127, return resulting pitch-12.
- Parameters:
relPitch
-inclusive
-- Returns:
- Throws:
IllegalArgumentException
- If there is no lower pitch possible.
-
getClosestPitch
public int getClosestPitch(int relPitch) Return the absolute pitch of the closest note from this note.Ex: if this=Ab3 and relPitch=0(C) then return C4.
- Parameters:
relPitch
- The relative pitch of the closest note.- Returns:
-
getVelocity
public int getVelocity() -
equalsRelativePitch
Compare the relative pitch of 2 notes.- Parameters:
n
- Note The note to compare with this note.- Returns:
- boolean Return true if Note n has the same relative pitch than this note.
-
equals
Compare 2 objects. -
hashCode
public int hashCode()Uses pitch, beatDuration and velocity, alterationDisplay is ignored. -
compareTo
Compare 2 notes.Uses pitch, then beatDuration, then velocity. AlterationDisplay is ignored.
- Specified by:
compareTo
in interfaceComparable<Note>
- Parameters:
n
-- Returns:
-
toString
Same as toPianoOctaveString(). -
toPianoOctaveBeatString
- Returns:
- String E.g. "C4:2.5" = Midi "Middle C" (pitch=60), beatDuration=2.5 beats
-
toRelativeNoteString
- Returns:
- E.g. "Db" or "E" (octave independent).
-
toRelativeNoteString
- Parameters:
alt
- Use the specified alteration.- Returns:
- E.g. "Db" if alt=FLAT, "C#" if alt=SHARP.
-
toPianoOctaveString
The note using the "piano octave", e.g. "D-1" for pitch=2 or "C4" for pitch=60 (Midi Middle C)."A0" is the lowest 88-note piano note.
- Returns:
- See Also:
-
parsePianoOctaveString
Convert a string generated by toPianoOctaveString() (like "C4") to a note.- Parameters:
s
-- Returns:
- Throws:
ParseException
- See Also:
-
checkPitch
public static boolean checkPitch(int p) -
checkVelocity
public static boolean checkVelocity(int v) -
checkOctave
public static boolean checkOctave(int o) This is the "natural" octave, from 0 to 10.- Parameters:
o
-- Returns:
-
isFlat
public boolean isFlat() -
getGStaffLineNumber
public int getGStaffLineNumber()Get the G-clef staff line for this note.- Returns:
- 0 for the line of middle C (Midi 60) or C#, 1 for D or Db or D#, 2 for E or Eb, 3 for F or F#, etc.
-
loadAsString
Create a Note from a String created with saveAsString().- Parameters:
s
-- Returns:
- Throws:
ParseException
- If s is not valid- See Also:
-
saveAsString(Note)
-
saveAsString
Save a Note as a String object.Example "60,FLAT,102,2.5" means pitch=60, AlterationDisplay=FLAT, velocity=102, duration=2.5 beats
- Parameters:
n
-skipAlteration
- Don't save the alteration- Returns:
- See Also:
-
getNormalizedRelPitch
public static int getNormalizedRelPitch(int absPitch) Convert a positive or relative absolute pitch to a relative pitch between 0 and 11.Ex: absPitch=13, result=1
Ex: absPitch=-15, result=9- Parameters:
absPitch
- Can be negative or positive, provided that -1 means 11(=B), -2 means 10(=Bb) etc.- Returns:
-
isWhiteKey
public static boolean isWhiteKey(int pitch) Return Check if a pitch corresponds to keyboard white key (C major scale).- Parameters:
pitch
-- Returns:
-
limitPitch
public static int limitPitch(int pitch, int lowPitch, int highPitch) Return a pitch which is guaranteed to be between lowPitch and highPitch. If pitch is out of bounds, go up/down 1 octave until we're within the limits.- Parameters:
pitch
-lowPitch
- Constraint: highPitch-lowPitch must be > 11.highPitch
- Constraint: highPitch-lowPitch must be > 11.- Returns:
- A pitch between lowPitch and highPitch
-
getChromaticNotesArray
Return an array of notes whose pitch start from pitchFrom up to pitchTo (included).
E.g., if pitchFrom=0 and pitchTo=12, return the array ["C0", "C#0", "D0"...."C1"]- Parameters:
pitchFrom
- A positive integer.pitchTo
- A positive integer.- Returns:
- An array of Note objects.
-