Class SongLayers

Represents the Layers of a Song with helper methods.


import { Song, toJSON } from "@nbsjs/core";

const song = new Song();
song.name = "Chaos";
song.description = "A randomly generated song.";
song.author = "Pseudorandomness";

// Create four random layers
for (let i = 0; i < 4; i++) {
createRandomLayer(i);
}

// Create a new layer with random notes
function createRandomLayer(number: number) {
const layer = song.layers.create();
layer.name = `Randomness ${number}`;
layer.stereo = number % 2 === 0 ? -100 : 100;

// Add ten notes with random key and instrument, four ticks apart
for (let i = 0; i < 10; i++) {
layer.notes.add(i + 4, random(1, song.instruments.total - 1), {
"key": random(0, 87)
});
}
}

// Ye Olde RNG
function random(min: number, max: number) {
return Math.floor(Math.random() * (max - min)) + min;
}

console.dir(JSON.stringify(toJSON(song), undefined, 4));

Properties

Methods

Constructors

Properties

all: Layer[] = []

Array of every layer in the song.

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

Methods

  • Add an existing Layer.

    Parameters

    • layer: Layer

      Layer to add

    Returns void

    Any existing layer with the same ID as the added layer will be overwritten.

Constructors