RhythmInstruction.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {AbstractNotationInstruction} from "./AbstractNotationInstruction";
  2. import {Fraction} from "../../../Common/DataObjects/Fraction";
  3. /**
  4. * A [[RhythmInstruction]] is the time signature which specifies the number of beats in each bar, and the value of one beat.
  5. */
  6. export class RhythmInstruction extends AbstractNotationInstruction {
  7. constructor(rhythm: Fraction, rhythmSymbolEnum: RhythmSymbolEnum) {
  8. super(undefined); // FIXME no parent SourceStaffEntry
  9. this.rhythm = rhythm;
  10. this.numerator = rhythm.Numerator;
  11. this.denominator = rhythm.Denominator;
  12. this.symbolEnum = rhythmSymbolEnum;
  13. }
  14. private numerator: number;
  15. private denominator: number;
  16. private rhythm: Fraction;
  17. private symbolEnum: RhythmSymbolEnum;
  18. public get Rhythm(): Fraction {
  19. return this.rhythm;
  20. }
  21. public set Rhythm(value: Fraction) {
  22. this.rhythm = value;
  23. }
  24. public get SymbolEnum(): RhythmSymbolEnum {
  25. return this.symbolEnum;
  26. }
  27. public set SymbolEnum(value: RhythmSymbolEnum) {
  28. this.symbolEnum = value;
  29. }
  30. public clone(): RhythmInstruction {
  31. return new RhythmInstruction(this.rhythm.clone(), this.symbolEnum);
  32. }
  33. public OperatorEquals(rhythm2: RhythmInstruction): boolean {
  34. const rhythm1: RhythmInstruction = this;
  35. if (rhythm1 === rhythm2) {
  36. return true;
  37. }
  38. if ((<Object>rhythm1 === undefined) || (<Object>rhythm2 === undefined)) {
  39. return false;
  40. }
  41. return (rhythm1.numerator === rhythm2.numerator && rhythm1.denominator === rhythm2.denominator);
  42. }
  43. public OperatorNotEqual(rhythm2: RhythmInstruction): boolean {
  44. const rhythm1: RhythmInstruction = this;
  45. return !(rhythm1 === rhythm2);
  46. }
  47. public ToString(): string {
  48. return "Rhythm: " + this.rhythm.toString();
  49. }
  50. }
  51. export enum RhythmSymbolEnum {
  52. NONE = 0,
  53. COMMON = 1,
  54. CUT = 2,
  55. }