Package org.jfugue.theory
Class Note
- java.lang.Object
-
- org.jfugue.theory.Note
-
- All Implemented Interfaces:
PatternProducer
public class Note extends java.lang.Object implements PatternProducer
-
-
Field Summary
Fields Modifier and Type Field Description static byte
MAX_OCTAVE
static byte
MIN_OCTAVE
static java.lang.String[]
NOTE_NAMES_COMMON
static java.lang.String[]
NOTE_NAMES_FLAT
static java.lang.String[]
NOTE_NAMES_SHARP
static byte
OCTAVE
java.lang.String
originalString
static java.lang.String[]
PERCUSSION_NAMES
static Note
REST
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Note
changeValue(int delta)
static Note
createRest(double duration)
boolean
equals(java.lang.Object o)
java.lang.String
getDecoratorString()
Returns the "decorators" to the base note, which includes the duration if one is explicitly specified, and velocity dynamics if providedstatic java.lang.String
getDispositionedToneStringWithoutOctave(int dispose, byte noteValue)
Returns a MusicString representation of the given MIDI note value, just the note (not the octave), disposed to use either flats or sharps.double
getDuration()
static java.lang.String
getDurationString(double decimalDuration)
Returns a MusicString representation of a decimal duration.static java.lang.String
getDurationStringForBeat(int beat)
static double
getFrequencyForNote(int noteValue)
Returns the frequency, in Hertz, for the given note value.static double
getFrequencyForNote(java.lang.String note)
Returns the frequency, in Hertz, for the given note.double
getMicrosecondDuration(double mpq)
byte
getOctave()
byte
getOffVelocity()
byte
getOnVelocity()
java.lang.String
getOriginalString()
Pattern
getPattern()
Returns a pattern representing this note.Pattern
getPercussionPattern()
static java.lang.String
getPercussionString(byte noteValue)
Returns a MusicString representation of the given MIDI note value using the name of a percussion instrument.byte
getPositionInOctave()
java.lang.String
getToneString()
static java.lang.String
getToneString(byte noteValue)
Returns a MusicString representation of the given MIDI note value, which indicates a note and an octave.static java.lang.String
getToneStringWithoutOctave(byte noteValue)
Returns a MusicString representation of the given MIDI note value, but just the note - not the octave.byte
getValue()
java.lang.String
getVelocityString()
boolean
isDurationExplicitlySet()
boolean
isEndOfTie()
boolean
isFirstNote()
boolean
isHarmonicNote()
boolean
isMelodicNote()
boolean
isOctaveExplicitlySet()
boolean
isPercussionNote()
boolean
isRest()
static boolean
isSameNote(java.lang.String note1, java.lang.String note2)
boolean
isStartOfTie()
static boolean
isValidNote(java.lang.String candidateNote)
static boolean
isValidQualifier(java.lang.String candidateQualifier)
Note
setDuration(double d)
Note
setDuration(java.lang.String duration)
Note
setEndOfTie(boolean isEndOfTie)
Note
setFirstNote(boolean isFirstNote)
Note
setHarmonicNote(boolean isHarmonicNote)
Note
setImplicitDurationForTestingOnly(double d)
FOR TESTING PURPOSES ONLY - avoids setting "isDurationExplicitlySet" - Please use setDuration instead!Note
setMelodicNote(boolean isMelodicNote)
Note
setOctaveExplicitlySet(boolean set)
Note
setOffVelocity(byte velocity)
Note
setOnVelocity(byte velocity)
Note
setOriginalString(java.lang.String originalString)
Note
setPercussionNote(boolean perc)
Note
setRest(boolean rest)
Note
setStartOfTie(boolean isStartOfTie)
Note
setValue(byte value)
static void
sortNotesBy(Note[] notes, org.jfugue.theory.Note.SortingCallback callback)
This is just Bubble Sort, but allows you to pass a Note.SortingCallback that returns a value that you want to sort for a note.java.lang.String
toDebugString()
java.lang.String
toString()
java.lang.String
toStringWithoutDuration()
Note
useDefaultDuration()
Note
useSameDurationAs(Note note2)
Note
useSameExplicitOctaveSettingAs(Note note2)
-
-
-
Field Detail
-
originalString
public java.lang.String originalString
-
NOTE_NAMES_COMMON
public static final java.lang.String[] NOTE_NAMES_COMMON
-
NOTE_NAMES_SHARP
public static final java.lang.String[] NOTE_NAMES_SHARP
-
NOTE_NAMES_FLAT
public static final java.lang.String[] NOTE_NAMES_FLAT
-
PERCUSSION_NAMES
public static final java.lang.String[] PERCUSSION_NAMES
-
REST
public static final Note REST
-
OCTAVE
public static final byte OCTAVE
- See Also:
- Constant Field Values
-
MIN_OCTAVE
public static final byte MIN_OCTAVE
- See Also:
- Constant Field Values
-
MAX_OCTAVE
public static final byte MAX_OCTAVE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Note
public Note()
-
Note
public Note(java.lang.String note)
-
Note
public Note(Note note)
-
Note
public Note(int value)
-
Note
public Note(byte value)
-
Note
public Note(int value, double duration)
-
Note
public Note(byte value, double duration)
-
-
Method Detail
-
setValue
public Note setValue(byte value)
-
getValue
public byte getValue()
-
changeValue
public Note changeValue(int delta)
-
setOctaveExplicitlySet
public Note setOctaveExplicitlySet(boolean set)
-
getOctave
public byte getOctave()
-
getDuration
public double getDuration()
-
setDuration
public Note setDuration(double d)
-
useDefaultDuration
public Note useDefaultDuration()
-
setDuration
public Note setDuration(java.lang.String duration)
-
isDurationExplicitlySet
public boolean isDurationExplicitlySet()
-
isOctaveExplicitlySet
public boolean isOctaveExplicitlySet()
-
setImplicitDurationForTestingOnly
public Note setImplicitDurationForTestingOnly(double d)
FOR TESTING PURPOSES ONLY - avoids setting "isDurationExplicitlySet" - Please use setDuration instead!
-
setRest
public Note setRest(boolean rest)
-
isRest
public boolean isRest()
-
setPercussionNote
public Note setPercussionNote(boolean perc)
-
isPercussionNote
public boolean isPercussionNote()
-
setOnVelocity
public Note setOnVelocity(byte velocity)
-
getOnVelocity
public byte getOnVelocity()
-
setOffVelocity
public Note setOffVelocity(byte velocity)
-
getOffVelocity
public byte getOffVelocity()
-
setStartOfTie
public Note setStartOfTie(boolean isStartOfTie)
-
setEndOfTie
public Note setEndOfTie(boolean isEndOfTie)
-
isStartOfTie
public boolean isStartOfTie()
-
isEndOfTie
public boolean isEndOfTie()
-
setFirstNote
public Note setFirstNote(boolean isFirstNote)
-
isFirstNote
public boolean isFirstNote()
-
setMelodicNote
public Note setMelodicNote(boolean isMelodicNote)
-
isMelodicNote
public boolean isMelodicNote()
-
setHarmonicNote
public Note setHarmonicNote(boolean isHarmonicNote)
-
isHarmonicNote
public boolean isHarmonicNote()
-
setOriginalString
public Note setOriginalString(java.lang.String originalString)
-
getOriginalString
public java.lang.String getOriginalString()
-
getMicrosecondDuration
public double getMicrosecondDuration(double mpq)
-
getPositionInOctave
public byte getPositionInOctave()
-
isSameNote
public static boolean isSameNote(java.lang.String note1, java.lang.String note2)
-
sortNotesBy
public static void sortNotesBy(Note[] notes, org.jfugue.theory.Note.SortingCallback callback)
This is just Bubble Sort, but allows you to pass a Note.SortingCallback that returns a value that you want to sort for a note. For example, to sort based on position in octave, your SortingCallback would return note.getPositionInOctave(). This lets you sort by note value, octave, position in octave, duration, velocity, and so on.
-
createRest
public static Note createRest(double duration)
-
getToneString
public static java.lang.String getToneString(byte noteValue)
Returns a MusicString representation of the given MIDI note value, which indicates a note and an octave.- Parameters:
noteValue
- this MIDI note value, like 60- Returns:
- a MusicString value, like C5
-
getToneStringWithoutOctave
public static java.lang.String getToneStringWithoutOctave(byte noteValue)
Returns a MusicString representation of the given MIDI note value, but just the note - not the octave. This means that the value returned can not be used to accurately recalculate the noteValue, since information will be missing. But this is useful for knowing what note within any octave the corresponding value belongs to.- Parameters:
noteValue
- this MIDI note value, like 60- Returns:
- a MusicString value, like C
-
getDispositionedToneStringWithoutOctave
public static java.lang.String getDispositionedToneStringWithoutOctave(int dispose, byte noteValue)
Returns a MusicString representation of the given MIDI note value, just the note (not the octave), disposed to use either flats or sharps. Pass -1 to get a flat name and +1 to get a sharp name for any notes that are accidentals.- Parameters:
dispose
- -1 to get a flat value, +1 to get a sharp valuenoteValue
- this MIDI note value, like 61- Returns:
- a MusicString value, like Db if -1 or C# if +1
-
getPercussionString
public static java.lang.String getPercussionString(byte noteValue)
Returns a MusicString representation of the given MIDI note value using the name of a percussion instrument.- Parameters:
noteValue
- this MIDI note value, like 60- Returns:
- a MusicString value, like [AGOGO]
-
getFrequencyForNote
public static double getFrequencyForNote(java.lang.String note)
Returns the frequency, in Hertz, for the given note. For example, the frequency for A5 (MIDI note 69) is 440.0- Parameters:
noteValue
- the MIDI note value- Returns:
- frequency in Hertz
-
getFrequencyForNote
public static double getFrequencyForNote(int noteValue)
Returns the frequency, in Hertz, for the given note value. For example, the frequency for A5 (MIDI note 69) is 440.0- Parameters:
noteValue
- the MIDI note value- Returns:
- frequency in Hertz
-
isValidNote
public static boolean isValidNote(java.lang.String candidateNote)
-
isValidQualifier
public static boolean isValidQualifier(java.lang.String candidateQualifier)
-
getDurationString
public static java.lang.String getDurationString(double decimalDuration)
Returns a MusicString representation of a decimal duration. This code currently only converts single duration values representing whole, half, quarter, eighth, etc. durations; and dotted durations associated with those durations (such as "h.", equal to 0.75). This method does not convert combined durations (for example, "hi" for 0.625). For these values, the original decimal duration is returned in a string, prepended with a "/" to make the returned value a valid MusicString duration indicator. It does handle durations greater than 1.0 (for example, "wwww" for 4.0).- Parameters:
decimalDuration
- The decimal value of the duration to convert- Returns:
- a MusicString fragment representing the duration
-
getDurationStringForBeat
public static java.lang.String getDurationStringForBeat(int beat)
-
getVelocityString
public java.lang.String getVelocityString()
-
getPattern
public Pattern getPattern()
Returns a pattern representing this note. Does not return indicators of whether the note is harmonic or melodic.- Specified by:
getPattern
in interfacePatternProducer
-
getPercussionPattern
public Pattern getPercussionPattern()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toStringWithoutDuration
public java.lang.String toStringWithoutDuration()
-
getToneString
public java.lang.String getToneString()
-
getDecoratorString
public java.lang.String getDecoratorString()
Returns the "decorators" to the base note, which includes the duration if one is explicitly specified, and velocity dynamics if provided
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
toDebugString
public java.lang.String toDebugString()
-
-