nbs.js - v6.1.0
    Preparing search index...

    Class LayerNotes

    Represents the Notes of a Layer with helper methods.

    import { readFileSync, writeFileSync } from "node:fs";
    import { fromArrayBuffer, toArrayBuffer } from "@nbsjs/core";

    // Read a NBS file named "song.nbs"
    const originalFile = readFileSync("song.nbs");
    const originalBuffer = new Uint8Array(originalFile).buffer;
    const song = fromArrayBuffer(originalBuffer);

    // "get" is a getter function and should be cached during these operations
    const instruments = song.instruments.get;

    for (const layer of song.layers) {
    // Every layer
    for (const [tick, note] of layer.notes) {
    // Every note in the layer
    const songInstrument = instruments[note.instrument];
    console.log(`Note on layer ${layer.name}, tick ${tick}, is a ${songInstrument.name}`);

    note.key++;
    console.log(`The note's key has been increased to ${note.key}`);

    // Delete notes above or below the octave limit
    if (note.key < 33 || note.key > 57) {
    layer.notes.delete(tick);
    }
    }

    console.log(`There are now ${layer.notes.total} notes in this layer.`);
    }

    // Done transforming! Write the result to "transformed.nbs"
    const exportedBuffer = toArrayBuffer(song);
    writeFileSync("transformed.nbs", new Uint8Array(exportedBuffer));
    Index

    Properties

    Methods

    Accessors

    Constructors

    Properties

    all: ExistingNotes = {}

    Tick-note pair of every note in the layer.

    This should not be modified directly! Instead, utilize the various helper methods in this class.

    Methods

    • Create and add a Note to a tick.

      Parameters

      • tick: number

        Tick to set the note at

      • instrument: number

        The ID of the instrument for the note to use.

      • options: NoteOptions = defaultNoteOptions

        Options for the note

      Returns Note

    • Delete a Note at the specified tick.

      Parameters

      • tick: number

        Tick to remove the note from

      Returns void

    • Set an existing Note at the specified tick.

      Parameters

      • tick: number

        Tick to set the note on

      • note: Note

        Note to set on tick

      Returns Note

      Any existing note at the same tick as the added note will be overwritten.

    Accessors

    Constructors