diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/bukkit/Note.java | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/Note.java b/src/main/java/org/bukkit/Note.java index 3d5f1254..8e053fd7 100644 --- a/src/main/java/org/bukkit/Note.java +++ b/src/main/java/org/bukkit/Note.java @@ -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"); } @@ -139,6 +142,18 @@ public class Note { } /** + * 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. * * @return the internal id of this note. |