mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 16:57:42 +01:00
[Bleeding] Allow sharping notes that aren't sharpable, and a factory method to create flat notes. Addresses BUKKIT-861
- Uses enharmonic equivalences to rewrite the note in the normalized form, E-sharp becomes F and A-flat becomes G-sharp By: Celtic Minstrel <celtic.minstrel.ca@some.place>
This commit is contained in:
parent
e6391643af
commit
a4bbcfc4e2
@ -127,10 +127,13 @@ public class Note {
|
||||
*
|
||||
* @param octave The octave where the note is in. Has to be 0 - 2.
|
||||
* @param tone The tone within the octave. If the octave is 2 the note has to be F#.
|
||||
* @param sharped Set it the tone is sharped (e.g. for F#).
|
||||
* @param sharped Set if the tone is sharped (e.g. for F#).
|
||||
*/
|
||||
public Note(int octave, Tone tone, boolean sharped) {
|
||||
Validate.isTrue(!(sharped && !tone.isSharpable()), "This tone could not be sharped.");
|
||||
if (sharped && !tone.isSharpable()) {
|
||||
tone = tone == Tone.F ? Tone.G : Tone.values()[tone.ordinal() + 1];
|
||||
sharped = false;
|
||||
}
|
||||
if (octave < 0 || octave > 2 || (octave == 2 && !(tone == Tone.F && sharped))) {
|
||||
throw new IllegalArgumentException("Tone and octave have to be between F#0 and F#2");
|
||||
}
|
||||
@ -138,6 +141,18 @@ public class Note {
|
||||
this.note = (byte) (octave * Tone.TONES_COUNT + tone.getId(sharped));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new note for a flat tone, such as A-flat.
|
||||
*
|
||||
* @param octave The octave where the note is in. Has to be 0 - 2.
|
||||
* @param tone The tone within the octave. If the octave is 2 the note has to be F#.
|
||||
* @return The new note.
|
||||
*/
|
||||
public static Note flat(int octave, Tone tone) {
|
||||
tone = tone == Tone.G ? Tone.F : Tone.values()[tone.ordinal() - 1];
|
||||
return new Note(octave, tone, tone.isSharpable());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the internal id of this note.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user