/**
* @class
* @classdesc Encapsulates each staff in the music composed of a staff option, string attributes, and an array of measures
*/
class Staff {
/**
* Creates a new Staff
*/
constructor() {
this.staffOption = "";
this.attributesStr = new Map();
this.measures = [];
}
/**
* Sets the string option
* @param {string} option String option to be set
*/
setStaffOption(option) {
this.staffOption = option;
}
/**
* Copies attributes from source
* @param {object} source Source must have attributesStr
* @property {Map} source.attributesStr Map relating String attributes to String values
*/
copyAttributes(source) {
source.attributesStr.forEach((value, key, map) => {
this.attributesStr.set(key, value);
});
}
/**
* Copies measures from source
* @param {object} source Source must have measures array
* @property {Measure[]} source.measures Array of Measures
*/
copyMeasures(source) {
source.measures.forEach((element) => {
this.addMeasure(element);
});
}
/**
* Adds a measure to the list of measures
* @param {Measure} measure Measure object to be added
*/
addMeasure(measure) {
this.measures.push(measure);
}
/**
* Converts Staff to a pretty string
* @returns {string} The pretty string representation of the staff
*/
toString() {
let output = "";
output += "Staff: ";
output += "\n";
output += "Staff option: ";
output += this.staffOption;
output += "\n";
output += "Staff attributes: \n";
this.attributesStr.forEach((value, key, map) => {
output += "\t";
output += key;
output += " : ";
output += value;
output += "\n";
});
output += "\n";
this.measures.forEach((element) => {
output += element.toString();
output += "\n";
});
return output;
}
}
module.exports = Staff