public class Note extends Object
Modifier and Type | Field and Description |
---|---|
static boolean |
DEBUG |
static int |
OCTAVE_MAX
Constant for the maximum legal value that an octave can have.
|
static int |
OCTAVE_MIN
Constant for the minimum legal value that an octave can have.
|
Constructor and Description |
---|
Note(double duration,
boolean repeat)
Constructs a new rest (Pitch.R) of the given duration.
|
Note(double duration,
Pitch pitch,
int octave,
Accidental accidental,
boolean repeat)
Constructs a Note with the given information.
|
Note(double duration,
String pitch,
int octave,
String accidental,
boolean repeat)
Constructs a Note with the given information.
|
Note(String line)
Constructs a Note with the information contained in the given line.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o)
Returns true if o refers to a Note object with the same state
as this Note object; otherwise false.
|
Accidental |
getAccidental()
Returns this Note's accidental value of SHARP, FLAT, or NATURAL.
|
double |
getDuration()
Returns this Note's duration in seconds.
|
int |
getOctave()
Returns this Note's octave.
|
Pitch |
getPitch()
Returns this Note's pitch value of A-G or R for a rest.
|
boolean |
isRepeat()
Returns true if this Note is the start or end of a repeated section.
|
boolean |
isRest()
Returns true if this Note is a rest.
|
void |
play()
Plays this note through the underlying audio system.
|
void |
setAccidental(Accidental accidental)
Sets this Note's accidental value to be the given value: SHARP, FLAT, or NATURAL.
|
void |
setAccidental(String accidental)
Sets this Note's accidental value to be the given value: "SHARP", "FLAT", or "NATURAL".
|
void |
setDuration(double duration)
Sets this Note's duration in seconds to be the given value.
|
void |
setOctave(int octave)
Sets this Note's octave to be the given value.
|
void |
setPitch(Pitch pitch)
Sets this Note's pitch to be the given value.
|
void |
setPitch(String pitch)
Sets this Note's pitch to be the given value.
|
void |
setRepeat(boolean repeat)
Sets this Note's repeat flag to be the given value.
|
String |
toString()
Returns a string representation of this note.
|
public static final int OCTAVE_MIN
public static final int OCTAVE_MAX
public static boolean DEBUG
public Note(String line)
line
- a line of input data such as "0.2 C 4 NATURAL false" or "0.4 R false" for a restNullPointerException
- if line is null.IllegalArgumentException
- if duration is negative or octave is not
between OCTAVE_MIN and OCTAVE_MAX inclusive.public Note(double duration, Pitch pitch, int octave, Accidental accidental, boolean repeat)
duration
- Note's duration in seconds.pitch
- Note's pitch from Pitch.A through Pitch.G, or Pitch.R for a rest.octave
- Note's octave from OCTAVE_MIN through OCTAVE_MAX inclusive.accidental
- Note's accidental from Accidental.SHARP, FLAT, or NATURAL.repeat
- true if this note starts/ends a repeated section.NullPointerException
- if pitch or accidental is null.IllegalArgumentException
- if duration is negative or octave is not
between OCTAVE_MIN and OCTAVE_MAX inclusive.public Note(double duration, String pitch, int octave, String accidental, boolean repeat)
duration
- Note's duration in seconds.pitch
- Note's pitch from "A" through "G", or "R" for a rest.octave
- Note's octave from OCTAVE_MIN through OCTAVE_MAX inclusive.accidental
- Note's accidental from "SHARP", "FLAT", or "NATURAL".repeat
- true if this note starts/ends a repeated section.NullPointerException
- if pitch or accidental is null.IllegalArgumentException
- if duration is negative or octave is not
between OCTAVE_MIN and OCTAVE_MAX inclusive.public Note(double duration, boolean repeat)
duration
- Note's duration in seconds.repeat
- true if this rest starts/ends a repeated section.NullPointerException
- if accidental is null.IllegalArgumentException
- if duration is negative.public boolean equals(Object o)
public Accidental getAccidental()
public double getDuration()
public int getOctave()
public Pitch getPitch()
public boolean isRepeat()
public boolean isRest()
public void play()
public void setAccidental(Accidental accidental)
accidental
- Note's accidental from Accidental.SHARP, FLAT, or NATURAL.NullPointerException
- if the accidental is null.public void setAccidental(String accidental)
accidental
- Note's accidental from "SHARP", "FLAT", or "NATURAL".public void setDuration(double duration)
duration
- Note's duration in seconds.IllegalArgumentException
- if duration is negative.public void setOctave(int octave)
octave
- Note's octave from OCTAVE_MIN through OCTAVE_MAX inclusive.IllegalArgumentException
- if octave is not between OCTAVE_MIN
and OCTAVE_MAX inclusive.public void setPitch(Pitch pitch)
pitch
- Note's pitch from Pitch.A through Pitch.G, or Pitch.R for a rest.NullPointerException
- if pitch is null.public void setPitch(String pitch)
pitch
- Note's pitch from "A" through "G", or "R" for a rest.NullPointerException
- if pitch is null.public void setRepeat(boolean repeat)
repeat
- true to indicate that this note is the start/end of a
repeated section, or false if not.