Source: AlphaTab/Track.js

const TrackMetaData = require("./TrackMetaData.js");
/**
 * @class
 * @classdesc Encapsulates each track in the music composed of an array of track names and a TrackMetaData object
 */
class Track {
    /**
     * Creates a new Track
     */
    constructor() {
        this.trackNames = [];
        this.trackData = new TrackMetaData();
    }

    /**
     * Add name to track names
     * @param {string} name name to be added
     */
    addTrackName(name) { this.trackNames.push(name); }
    
    /**
     * Gets the first track name
     * @returns {string} The first value in trackNames
     */
    getTrackName() {
        return this.trackNames[0];
    }

    /**
     * Copies trackNames and trackData from source
     * @param {object} source Source must have trackNames and trackData
     * @property {string[]} source.trackNames The names for the track
     * @property {TrackMetaData} source.trackData The data for the track
     */
    copy(source) {
        source.trackNames.forEach((item) => {
            this.addTrackName(item);
        });
        this.trackData.copy(source.trackData);
    }

    /**
     * Converts Track to a pretty string
     * @returns {string} The pretty string representation of the track
     */
    toString() {
        let output = "";

        output += "Track Name : ";

        this.trackNames.forEach((trackName) => {
            output += trackName;
            output += "  ";
        });
        output += "\n";

        output += "Track Metadata: ";
        output += "\n";
        output += this.trackData.toString();
        return output;
    }
}

module.exports = Track