VerticalGraphicalStaffEntryContainer.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {Fraction} from "../../Common/DataObjects/Fraction";
  2. import {GraphicalStaffEntry} from "./GraphicalStaffEntry";
  3. export class VerticalGraphicalStaffEntryContainer {
  4. constructor(numberOfEntries: number, absoluteTimestamp: Fraction) {
  5. this.absoluteTimestamp = absoluteTimestamp;
  6. this.staffEntries = new Array(numberOfEntries);
  7. }
  8. //public relativeInMeasureTimestamp: Fraction;
  9. private index: number;
  10. private absoluteTimestamp: Fraction;
  11. private staffEntries: GraphicalStaffEntry[] = [];
  12. public get Index(): number {
  13. return this.index;
  14. }
  15. public set Index(value: number) {
  16. this.index = value;
  17. }
  18. public get AbsoluteTimestamp(): Fraction {
  19. return this.absoluteTimestamp;
  20. }
  21. //public set AbsoluteTimestamp(value: Fraction) {
  22. // this.absoluteTimestamp = value;
  23. //}
  24. public get StaffEntries(): GraphicalStaffEntry[] {
  25. return this.staffEntries;
  26. }
  27. public set StaffEntries(value: GraphicalStaffEntry[]) {
  28. this.staffEntries = value;
  29. }
  30. public static compareByTimestamp(x: VerticalGraphicalStaffEntryContainer, y: VerticalGraphicalStaffEntryContainer): number {
  31. const xValue: number = x.absoluteTimestamp.RealValue;
  32. const yValue: number = y.absoluteTimestamp.RealValue;
  33. if (xValue < yValue) {
  34. return -1;
  35. } else if (xValue > yValue) {
  36. return 1;
  37. } else {
  38. return 0;
  39. }
  40. }
  41. /**
  42. * Return the first non-null [[GraphicalStaffEntry]].
  43. * @returns {any}
  44. */
  45. public getFirstNonNullStaffEntry(): GraphicalStaffEntry {
  46. for (let idx: number = 0, len: number = this.staffEntries.length; idx < len; ++idx) {
  47. const graphicalStaffEntry: GraphicalStaffEntry = this.staffEntries[idx];
  48. if (graphicalStaffEntry !== undefined) {
  49. return graphicalStaffEntry;
  50. }
  51. }
  52. return undefined;
  53. }
  54. }