Class NoteEvent

java.lang.Object
org.jjazz.harmony.api.Note
org.jjazz.phrase.api.NoteEvent
All Implemented Interfaces:
Cloneable, Comparable<Note>

public class NoteEvent extends Note implements Cloneable, Comparable<Note>
A Note with a position and optional client properties.

This is an immutable class EXCEPT for the client properties.

Two different NoteEvent instances can not be equal. If you need NoteEvent map keys to be considered equal when they share the same Note attributes, use the AsNoteKey inner class.

  • Field Details

    • SYSTEM_PROP_NOTEEVENT_TOSTRING_FORMAT

      public static final String SYSTEM_PROP_NOTEEVENT_TOSTRING_FORMAT
      System property used to customize NoteEvent.toString().

      Used as String.format() parameter with arguments 1=toPianoOctaveString(), 2=position, 3=durationInBeats, 4=velocity, 5=identityHashCode

      Example: "[%1$s, dur=%3$.2f]"

      See Also:
    • PROP_IS_ADJUSTING

      public static final String PROP_IS_ADJUSTING
      If true this note is an "adjusting note".

      "Adjusting" means it's a temporary note used by an action which will eventually replace the temporary note by a non-adjusting note. For example if user is mouse-dragging a note in an editor, editor might generate "adjusting notes" until drag operation is complete.

      Note that this property is not directly used by the NoteEvent class.

      See Also:
  • Constructor Details

    • NoteEvent

      public NoteEvent(int pitch, float duration, int velocity, float posInBeats, Note.Accidental acc)
      Create a new NoteEvent.
      Parameters:
      pitch -
      duration -
      velocity -
      posInBeats -
      acc -
    • NoteEvent

      public NoteEvent(int pitch, float duration, int velocity, float posInBeats)
      Create a new NoteEvent with Accidental.FLAT.

      Parameters:
      pitch -
      duration -
      velocity -
      posInBeats -
    • NoteEvent

      public NoteEvent(Note n, float posInBeats)
      Create a new NoteEvent from a Note at specified position.

      Parameters:
      n -
      posInBeats -
  • Method Details

    • markIsAdjustingNote

      public static void markIsAdjustingNote(NoteEvent note, boolean b)
      Set or reset the note as isAdjusting.
      Parameters:
      note -
      b - If true note is marked isAdjusting.
      See Also:
    • isAdjustingNote

      public static boolean isAdjustingNote(NoteEvent ne)
      Check if note is marked isAdjusting.
      Parameters:
      ne -
      Returns:
    • setAll

      public NoteEvent setAll(int pitch, float duration, int velocity, float posInBeats, Note.Accidental acc, boolean copyProperties)
      Create a new and possibly modified NoteEvent from this instance.

      Parameters:
      pitch - if < 0 reuse this instance's pitch, otherwise use the parameter value
      duration - if < 0 reuse this instance's duration, otherwise use the parameter value
      velocity - if < 0 reuse this instance's velocity, otherwise use the parameter value
      posInBeats - if < 0 reuse this instance's position, otherwise use the parameter value
      acc - if null reuse this instance's accidental, otherwise use the parameter value
      copyProperties - if true copy the properties
      Returns:
    • setPitch

      public NoteEvent setPitch(int newPitch, boolean copyProperties)
      Get a copy with the pitch parameter modified.

      Client properties are copied.

      Parameters:
      newPitch - The new pitch
      copyProperties -
      Returns:
    • setDuration

      public NoteEvent setDuration(float newDurationInBeats, boolean copyProperties)
      Get a copy with the duration parameter modified.

      Parameters:
      newDurationInBeats -
      copyProperties - If true copy the properties
      Returns:
    • setVelocity

      public NoteEvent setVelocity(int newVelocity, boolean copyProperties)
      Get a copy with the velocity parameter modified.

      Parameters:
      newVelocity -
      copyProperties - If true copy the properties
      Returns:
    • setPosition

      public NoteEvent setPosition(float newPositionInBeats, boolean copyProperties)
      Get a copy with the position parameter modified.

      Parameters:
      newPositionInBeats -
      copyProperties - If true copy the properties
      Returns:
    • setAccidental

      public NoteEvent setAccidental(Note.Accidental newAccidental, boolean copyProperties)
      Get a copy with the alteration parameter modified.

      Parameters:
      newAccidental -
      copyProperties - If true copy the properties
      Returns:
    • getClientProperties

      public ObservableProperties<Object> getClientProperties()
      Get the client properties.
      Returns:
    • toMidiEvents

      public List<MidiEvent> toMidiEvents(int channel)
      Convert a note into 2 MidiEvents (NoteON and NoteOFF).
      Parameters:
      channel -
      Returns:
    • isBefore

      public boolean isBefore(NoteEvent mne)
    • getPositionInBeats

      public float getPositionInBeats()
    • getBeatRange

      public FloatRange getBeatRange()
    • isNear

      public boolean isNear(float posInBeats, float nearWindow)
      Test if this note is near the specified position.

      A "near" position is in the interval [posInBeats-nearWindow;posInBeats+nearWindow[.

      Parameters:
      posInBeats -
      nearWindow - Must be >= 0
      Returns:
    • equalsAsNoteNearPosition

      public boolean equalsAsNoteNearPosition(NoteEvent ne, float nearWindow)
      Check for equality as a Note tolerating slight differences in position and duration.

      If the positions are equals +/- beatWindow, positions are considered equal. If the durations are equals +/- 2*beatWindow, durations are considered equal.

      ClientProperties are ignored.

      Parameters:
      ne -
      nearWindow - Must be >= 0
      Returns:
    • compareTo

      public int compareTo(Note n)
      Compare this NoteEvent to a Note or NoteEvent.

      Specified by:
      compareTo in interface Comparable<Note>
      Overrides:
      compareTo in class Note
      Parameters:
      n -
      Returns:
      0 only if this == n.
    • compareToAsPosition

      public int compareToAsPosition(NoteEvent n)
      Compare using only position.

      Parameters:
      n -
      Returns:
    • toNote

      public Note toNote()
      Get a new Note instance built from this object's pitch, duration, velocity and accidental.
      Returns:
    • getAsNoteKey

      public NoteEvent.AsNoteKey getAsNoteKey()
      Get the "as Note" map key for this instance.
      Returns:
      See Also:
    • equals

      public boolean equals(Object o)
      Return false unless o is the same object.

      Use equalsAsNoteNearPosition(ne, 0) for equality based on the NoteEvent musical attributes.

      Overrides:
      equals in class Note
      Parameters:
      o -
      Returns:
      See Also:
    • hashCode

      public int hashCode()
      Return the identify hash code.
      Overrides:
      hashCode in class Note
      Returns:
    • clone

      public NoteEvent clone()
      Clone this instance, including the client properties.
      Overrides:
      clone in class Note
      Returns:
    • toString

      public String toString()
      Description copied from class: Note
      Same as toPianoOctaveString().
      Overrides:
      toString in class Note
      Returns:
      See Also:
    • addClientPropertyChangeListener

      public void addClientPropertyChangeListener(PropertyChangeListener l)
    • removeClientPropertyChangeListener

      public void removeClientPropertyChangeListener(PropertyChangeListener l)
    • saveAsString

      public static String saveAsString(NoteEvent ne)
      Save the specified NoteEvent as a string.

      NOTE: client properties are NOT saved.

      Parameters:
      ne -
      Returns:
      See Also:
    • loadAsString

      public static NoteEvent loadAsString(String s) throws ParseException
      Create a NoteEvent from the specified string.

      Example "60,FLAT,102,2.5:1.25" means pitch=60, AccidentalDisplay=FLAT, velocity=102, duration=2.5 beats, and position=1.25 beats

      Parameters:
      s -
      Returns:
      Throws:
      ParseException - If s is not a valid string.
      See Also: