Lume
    Preparing search index...

    Class NoteTracker

    NoteTracker logs data regarding MIDI note data. It is used to keep track of the currently active notes, and record the timestamps of when notes were last added/removed.

    NoteTracker comes with a filtering system to prevent notes from being added if their channel number doesn't match a list of accepted numbers. Additionally, it cannot store multiple instances of the same note. If a note already exists within the tracker, it is ignored.

    Note timestamps are generated using Date.now(), meaning that the timestamp is in milliseconds, relative to the epoch (12:00 AM, January 1, 1970, UTC).

    Notes are stored as the actual MIDI note value, meaning that the note value range is 0 to 127, rather than 1 to 128.

    Index

    Accessors

    • get filter(): number[]

      The MIDI channels that the tracker will accept notes from.

      Returns number[]

    • get notes(): number[]

      The list of currently active notes, sorted by MIDI value.

      Returns number[]

    • get timeSinceNoteAdded(): number

      Returns the amount of time (in milleseconds) that has passed since the last note was added to the tracker.

      Returns number

    Constructors

    • Creates a new instance of NoteTracker

      Parameters

      • filter: number[] = []

        An array representing the MIDI channel values that NoteTracker accepts. Default value is an empty array, meaning all MIDI notes will be accepted.

      Returns NoteTracker

    Methods

    • Gets the timestamp of when a note was last added. If there has not been an instance of the provided note being added, this method will return 0.

      Parameters

      • note: number

      Returns number

      Timestamps are generated using Date.now(), meaning that the timestamp is in milliseconds, relative to the epoch (12:00 AM, January 1, 1970, UTC).

    • Gets the timestamp of when a note was last removed. If there has not been an instance of the provided note being removed, this method will return 0.

      Parameters

      • note: number

      Returns number

    • Removes a note from the tracker.

      If the note provided doesn't exist, this method does nothing.

      Parameters

      • note: number

        The note to remove.

      Returns void

    • Attempts to store a note within the tracker. If the channel argument matches a number in the filter, it is accepted. If the filter is an empty array, the note will always be accepted.

      If a note could not be added, this method returns nothing.

      Parameters

      • note: number
      • channel: number

      Returns boolean

      True if the note was added, false if rejected by the filter, or if the note already exists in the tracker.

    Properties

    onNoteAdded?: (note: number) => void

    Callback that is invoked when a note is successfully added. Acts as an event.

    Override this property to handle this event.

    const tracker = new NoteTracker();
    tracker.onNoteAdded = () => {
    console.log("new note added");
    };

    The implementation of this property means that there can only ever be one callback for onNoteAdded events, as reassigning this value means that the old callback will be deleted. As a general workaround, each DynamicGraphic instance should be given it's own NoteTracker when creating a new layout.

    onNoteDeleted?: (note: number) => void

    Callback that is invoked when a note is deleted. Acts as an event.

    Override this property to handle this event.

    const tracker = new NoteTracker();
    tracker.onNoteDeleted = () => {
    console.log("note deleted");
    };

    The implementation of this property means that there can only ever be one callback for onNoteDeleted events, as reassigning this value means that the old callback will be deleted. As a general workaround, each DynamicGraphic instance should be given it's own NoteTracker when creating a new layout.