Package de.saar.coli.arranger
Class Note
- java.lang.Object
-
- de.saar.coli.arranger.Note
-
public class Note extends Object
A note with a certain pitch and duration. Durations are always measured in integer multiples of eighth notes for now.We distinguish the following terminology:
- An absolute note number is an integer number that uniquely determines the note e.g. on a keyboard. Technically, it is the note's MIDI number, so e.g. the absolute number 60 represents middle C.
- The relative note number of a note is its position within the octave. C is always mapped to 0, C#/Db is mapped to 1, and so on. The notes C3 and C4 have different absolute numbers (48 and 60, respectively), but both have the relative number 0. You can map from absolute to relative note numbers by modulo 12.
- An object of the class Note represents a note based on its absolute note number and its duration in eighth notes.
-
-
Constructor Summary
Constructors Constructor Description Note()
-
Method Summary
Modifier and Type Method Description Noteadd(int offset)Returns the note that is "offset" semitones above this note.static Notecreate(int absoluteNote, int duration)Creates a note with the given absolute note number and duration.static Notecreate(int relativeNote, int octave, int duration)Creates a note based on its relative note number and the octave.static Notecreate(String noteWithOctave, int duration)Creates a note based on its scientific name (e.g.static Notecreate(String relativeNote, int octave, int duration)Creates a note based on a string representing its relative note (e.g.booleanequals(Object o)intgetAbsoluteDistance(Note other)Returns the absolute value of the distance to the other note, in semitones.intgetAbsoluteNote()Returns the absolute note number of this note.intgetDuration()Returns the duration of this note in eighth notes.static intgetNoteId(String noteName)Returns the absolute note number of the note with the given canonical name.static StringgetNoteName(int relativeNote)Returns a canonical note name for the given relative note number.StringgetNoteName(Key key)Returns the name of this note in the given key.StringgetNoteName(Key key, boolean forceNatural)Returns the name of this note in the given key.intgetOctave()Returns the octave of this note (C4 is middle C).intgetRelativeNote()Returns the relative note number of this note.inthashCode()StringtoString()Notetranspose(int halfsteps)Transposes this note up or down the given number of half-steps.
-
-
-
Method Detail
-
create
public static Note create(int absoluteNote, int duration)
Creates a note with the given absolute note number and duration.- Parameters:
absoluteNote-duration-- Returns:
-
create
public static Note create(int relativeNote, int octave, int duration)
Creates a note based on its relative note number and the octave.- Parameters:
relativeNote-octave-duration-- Returns:
-
create
public static Note create(String relativeNote, int octave, int duration)
Creates a note based on a string representing its relative note (e.g. "C" or "Db") and octave. Note that all halftones need to be spelled with b's; so Db and not C#.- Parameters:
relativeNote-octave-duration-- Returns:
-
create
public static Note create(String noteWithOctave, int duration)
Creates a note based on its scientific name (e.g. "C4"). Note that all halftones need to be spelled with b's; so Db and not C#.- Parameters:
noteWithOctave-duration-- Returns:
-
getAbsoluteNote
public int getAbsoluteNote()
Returns the absolute note number of this note.- Returns:
-
getAbsoluteDistance
public int getAbsoluteDistance(Note other)
Returns the absolute value of the distance to the other note, in semitones.- Parameters:
other-- Returns:
-
add
public Note add(int offset)
Returns the note that is "offset" semitones above this note. If "offset" is negative, the note is shifted down.- Parameters:
offset-- Returns:
-
getRelativeNote
public int getRelativeNote()
Returns the relative note number of this note.- Returns:
-
getOctave
public int getOctave()
Returns the octave of this note (C4 is middle C).- Returns:
-
getDuration
public int getDuration()
Returns the duration of this note in eighth notes.- Returns:
-
getNoteName
public static String getNoteName(int relativeNote)
Returns a canonical note name for the given relative note number. Because we have no information about the key in this method, accidentals are always spelled as flats; so relative number 1 is "Db" and not "C#".- Parameters:
relativeNote-- Returns:
-
getNoteName
public String getNoteName(Key key)
Returns the name of this note in the given key. SeegetNoteName(Key, boolean)for details.- Parameters:
key-- Returns:
-
getNoteName
public String getNoteName(Key key, boolean forceNatural)
Returns the name of this note in the given key. Accidentals are spelled with respect to the key; so relative note number 1 is spelled "Db" in Bb minor and "C#" in A major. Naturals are spelled as "@", and are usually suppressed, so relative note 2 is just "D" in C major. However, you can force the note to be spelled with the natural, "D@", by setting the parameter "forceNatural" to true. This can be useful when spelling a chord note in the context of a different key.- Parameters:
key-- Returns:
-
getNoteId
public static int getNoteId(String noteName)
Returns the absolute note number of the note with the given canonical name. Note that accidentals must be spelled with flats in the canonical name, i.e. "Db" and not "C#".- Parameters:
noteName-- Returns:
-
transpose
public Note transpose(int halfsteps)
Transposes this note up or down the given number of half-steps.- Parameters:
halfsteps-- Returns:
-
-