continuousTempoExpression.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import {Fraction} from "../../../../Common/DataObjects/fraction";
  2. import {PlacementEnum} from "../abstractExpression";
  3. import {MultiTempoExpression} from "../multiTempoExpression";
  4. import {AbstractTempoExpression} from "../abstractTempoExpression";
  5. export class ContinuousTempoExpression extends AbstractTempoExpression {
  6. constructor(label: string, placement: PlacementEnum, staffNumber: number, parentMultiTempoExpression: MultiTempoExpression) {
  7. super(label, placement, staffNumber, parentMultiTempoExpression);
  8. //super.label = label;
  9. //super.placement = placement;
  10. //super.staffNumber = staffNumber;
  11. //super.parentMultiTempoExpression = parentMultiTempoExpression;
  12. this.setTempoType();
  13. }
  14. private absoluteEndTimestamp: Fraction;
  15. private tempoType: ContinuousTempoType;
  16. private startTempo: number;
  17. private endTempo: number;
  18. private static listContinuousTempoFaster: string[] = ["accelerando","piu mosso","poco piu","stretto"];
  19. private static listContinuousTempoSlower: string[] = ["poco meno","meno mosso","piu lento","calando","allargando","rallentando","ritardando","ritenuto","ritard.","ritard","rit.","rit","riten.","riten"];
  20. public get TempoType(): ContinuousTempoType {
  21. return this.tempoType;
  22. }
  23. public set TempoType(value: ContinuousTempoType) {
  24. this.tempoType = value;
  25. }
  26. public get StartTempo(): number {
  27. return this.startTempo;
  28. }
  29. public set StartTempo(value: number) {
  30. this.startTempo = value;
  31. }
  32. public get EndTempo(): number {
  33. return this.endTempo;
  34. }
  35. public set EndTempo(value: number) {
  36. this.endTempo = value;
  37. }
  38. public get AbsoluteEndTimestamp(): Fraction {
  39. return this.absoluteEndTimestamp;
  40. }
  41. public set AbsoluteEndTimestamp(value: Fraction) {
  42. this.absoluteEndTimestamp = value;
  43. }
  44. public static isInputStringContinuousTempo(inputString: string): boolean {
  45. if (inputString == null)
  46. return false;
  47. if (ContinuousTempoExpression.isStringInStringList(ContinuousTempoExpression.listContinuousTempoFaster, inputString))
  48. return true;
  49. if (ContinuousTempoExpression.isStringInStringList(ContinuousTempoExpression.listContinuousTempoSlower, inputString))
  50. return true;
  51. return false;
  52. }
  53. private setTempoType(): void {
  54. if (ContinuousTempoExpression.isStringInStringList(ContinuousTempoExpression.listContinuousTempoFaster, this.label))
  55. this.tempoType = ContinuousTempoType.accelerando;
  56. else if (ContinuousTempoExpression.isStringInStringList(ContinuousTempoExpression.listContinuousTempoSlower, this.label))
  57. this.tempoType = ContinuousTempoType.ritardando;
  58. }
  59. public get AbsoluteTimestamp(): Fraction {
  60. return this.ParentMultiTempoExpression.AbsoluteTimestamp;
  61. }
  62. public getAbsoluteFloatTimestamp(): number {
  63. return this.ParentMultiTempoExpression.AbsoluteTimestamp.RealValue;
  64. }
  65. public getInterpolatedTempo(currentAbsoluteTimestamp: Fraction): number {
  66. var continuousAbsoluteStartTimestamp: Fraction = Fraction.plus(this.parentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp, this.parentMultiTempoExpression.Timestamp);
  67. if (currentAbsoluteTimestamp.lt(continuousAbsoluteStartTimestamp))
  68. return -1;
  69. if (currentAbsoluteTimestamp.lt(this.absoluteEndTimestamp))
  70. return -2;
  71. var interpolationRatio: number = Fraction.minus(currentAbsoluteTimestamp, continuousAbsoluteStartTimestamp).RealValue / Fraction.minus(this.absoluteEndTimestamp, continuousAbsoluteStartTimestamp).RealValue;
  72. var interpolatedTempo: number = Math.max(0.0, Math.min(250.0, this.startTempo + (this.endTempo - this.startTempo) * interpolationRatio));
  73. return <number>interpolatedTempo;
  74. }
  75. public static isIncreasingTempo(tempoType: ContinuousTempoType): boolean {
  76. if (tempoType <= ContinuousTempoType.piuMosso)
  77. return true;
  78. else return false;
  79. }
  80. public static isDecreasingTempo(tempoType: ContinuousTempoType): boolean {
  81. if ((tempoType >= ContinuousTempoType.allargando) && (tempoType <= ContinuousTempoType.ritenuto))
  82. return true;
  83. else return false;
  84. }
  85. }
  86. export enum ContinuousTempoType {
  87. accelerando = 0,
  88. stretto = 1,
  89. stringendo = 2,
  90. mosso = 3,
  91. piuMosso = 4,
  92. allargando = 5,
  93. calando = 6,
  94. menoMosso = 7,
  95. rallentando = 8,
  96. ritardando = 9,
  97. ritard = 10,
  98. rit = 11,
  99. ritenuto = 12,
  100. rubato = 13,
  101. precipitando = 14
  102. }