summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCeltic Minstrel <celtic.minstrel.ca@some.place>2012-02-26 12:48:34 -0500
committerEvilSeph <evilseph@gmail.com>2012-02-29 22:40:41 -0500
commit674ce005385d50ce18b8626d58189a156e9a9d62 (patch)
tree9627d7d7b447136a99ad0e8353edfc4861481c74
parent37e90d74e7486757d7de325426c0ab3103e19ed9 (diff)
downloadbukkit-674ce005385d50ce18b8626d58189a156e9a9d62.tar
bukkit-674ce005385d50ce18b8626d58189a156e9a9d62.tar.gz
bukkit-674ce005385d50ce18b8626d58189a156e9a9d62.tar.lz
bukkit-674ce005385d50ce18b8626d58189a156e9a9d62.tar.xz
bukkit-674ce005385d50ce18b8626d58189a156e9a9d62.zip
[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
-rw-r--r--src/main/java/org/bukkit/Note.java19
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.