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.

  • Constructor Details

    • NoteEvent

      public NoteEvent(int pitch, float duration, int velocity, float posInBeats)
      Create a new NoteEvent.
      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 -
    • NoteEvent

      public NoteEvent(NoteEvent ne, int pitch, float duration, int velocity, float posInBeats)
      Create a new NoteEvent from another NoteEvent.

      Client properties are also copied.

      Parameters:
      ne -
      pitch - if < 0 reuse ne's pitch, otherwise use this value
      duration - if < 0 reuse ne's duration, otherwise use this value
      velocity - if < 0 reuse ne's velocity, otherwise use this value
      posInBeats - if < 0 reuse ne's position, otherwise use this value
  • Method Details

    • getCopyPitch

      public NoteEvent getCopyPitch(int pitch)
      Get a copy with one parameter modified.

      Client properties are also copied.

      Parameters:
      pitch -
      Returns:
    • getCopyDur

      public NoteEvent getCopyDur(float durationInBeats)
      Get a copy with one parameter modified.

      Client properties are also copied.

      Parameters:
      durationInBeats -
      Returns:
    • getCopyVel

      public NoteEvent getCopyVel(int velocity)
      Get a copy with one parameter modified.

      Client properties are also copied.

      Parameters:
      velocity -
      Returns:
    • getCopyPos

      public NoteEvent getCopyPos(float posInBeats)
      Get a copy with one parameter modified.

      Client properties are also copied.

      Parameters:
      posInBeats -
      Returns:
    • getCopyDurPos

      public NoteEvent getCopyDurPos(float durationInBeats, float posInBeats)
      Get a copy with the specified parameters modified.

      Client properties are also copied.

      Parameters:
      durationInBeats -
      posInBeats -
      Returns:
    • getCopyPitchVel

      public NoteEvent getCopyPitchVel(int pitch, int velocity)
      Get a copy with the specified parameters modified.

      Client properties are also copied.

      Parameters:
      pitch -
      velocity -
      Returns:
    • getCopyPitchPos

      public NoteEvent getCopyPitchPos(int pitch, float posInBeats)
      Get a copy with the specified parameters modified.

      Client properties are also copied.

      Parameters:
      pitch -
      posInBeats -
      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 -
      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 alteration.
      Returns:
    • getAsNoteKey

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

      public boolean equals(Object o)
      Return false unless o is the same object.
      Overrides:
      equals in class Note
      Parameters:
      o -
      Returns:
    • hashCode

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

      public NoteEvent clone()
      Also clone 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
      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, AlterationDisplay=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: