Source: AlphaTab/Chord.js

  1. const AlphaTexStructure = require("./AlphaTexStructure.js");
  2. /**
  3. * @class
  4. * @classdesc Encapsulates each chord in the music composed of an array of notes
  5. */
  6. class Chord {
  7. /**
  8. * Constructs a new Chord
  9. */
  10. constructor() {
  11. this.notes = [];
  12. }
  13. /**
  14. * Adds a note to the array of notes
  15. * @param {Object} note Note object to add to this chord
  16. */
  17. addNote(note) {
  18. this.notes.push(note);
  19. }
  20. /**
  21. * Converts Chord to a pretty string
  22. * @returns {String} The pretty string representation of the chord
  23. */
  24. toString() {
  25. let output = "";
  26. output += "{";
  27. let noteCounter = this.notes.length;
  28. this.notes.forEach((note) => {
  29. output += note.toString();
  30. if (noteCounter > 1) {
  31. output += " ";
  32. noteCounter--;
  33. }
  34. });
  35. output += "}";
  36. return output;
  37. }
  38. }
  39. module.exports = Chord