InstantaniousTempoExpression.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. import {AbstractTempoExpression} from "./AbstractTempoExpression";
  2. import {PlacementEnum} from "./AbstractExpression";
  3. import {ArgumentOutOfRangeException} from "../../Exceptions";
  4. import {Fraction} from "../../../Common/DataObjects/Fraction";
  5. import {MultiTempoExpression} from "./MultiTempoExpression";
  6. export class InstantaniousTempoExpression extends AbstractTempoExpression {
  7. constructor(label: string, placement: PlacementEnum, staffNumber: number, soundTempo: number, parentMultiTempoExpression: MultiTempoExpression) {
  8. super(label, placement, staffNumber, parentMultiTempoExpression);
  9. this.setTempoAndTempoType(soundTempo);
  10. }
  11. private static listInstantaniousTempoLarghissimo: string[] = ["Larghissimo", "Sehr breit", "very, very slow"]; // }), TempoEnum.larghissimo);
  12. private static listInstantaniousTempoGrave: string[] = ["Grave", "Schwer", "slow and solemn"]; // }), TempoEnum.grave);
  13. private static listInstantaniousTempoLento: string[] = ["Lento", "Lent", "Langsam", "slowly"]; // }), TempoEnum.lento);
  14. private static listInstantaniousTempoLargo: string[] = ["Largo", "Breit", "broadly"]; // }), TempoEnum.largo);
  15. private static listInstantaniousTempoLarghetto: string[] = ["Larghetto", "Etwas breit", "rather broadly"]; // }), TempoEnum.larghetto);
  16. private static listInstantaniousTempoAdagio: string[] = ["Adagio", "Langsam", "Ruhig", "slow and stately"]; // }), TempoEnum.adagio);
  17. private static listInstantaniousTempoAdagietto: string[] = ["Adagietto", "Ziemlich ruhig", "Ziemlich langsam", "rather slow"]; // }), TempoEnum.adagietto);
  18. private static listInstantaniousTempoAndanteModerato: string[] = ["Andante moderato"]; // }), TempoEnum.andanteModerato);
  19. private static listInstantaniousTempoAndante: string[] = ["Andante", "Gehend", "Schreitend", "at a walking pace"]; // }), TempoEnum.andante);
  20. private static listInstantaniousTempoAndantino: string[] = ["Andantino"]; // }), TempoEnum.andantino);
  21. private static listInstantaniousTempoModerato: string[] = ["Moderato", "M��ig", "Mod�r�", "moderately"]; // }), TempoEnum.moderato);
  22. private static listInstantaniousTempoAllegretto: string[] = ["Allegretto", "fast"]; // }), TempoEnum.allegretto);
  23. private static listInstantaniousTempoAllegroModerato: string[] = ["Allegro moderato"]; // }), TempoEnum.allegroModerato);
  24. private static listInstantaniousTempoAllegro: string[] = ["Allegro", "Rapide", "Vite", "Rasch", "Schnell", "Fr�hlich"]; // }), TempoEnum.allegro);
  25. private static listInstantaniousTempoVivace: string[] = ["Vivace", "Lebhaft", "Lebendig", "lively and fast"]; // }), TempoEnum.vivace);
  26. private static listInstantaniousTempoVivacissimo: string[] = ["Vivacissimo", "Sehr lebhaft", "Sehr lebendig"]; // }), TempoEnum.vivacissimo);
  27. private static listInstantaniousTempoAllegrissimo: string[] = ["Allegrissimo", "very fast"]; // }), TempoEnum.allegrissimo);
  28. private static listInstantaniousTempoPresto: string[] = ["Presto", "Sehr schnell", "Geschwind"]; // }), TempoEnum.presto);
  29. private static listInstantaniousTempoPrestissimo: string[] = ["Prestissimo", "�u�erst schnell"]; // }), TempoEnum.prestissimo);
  30. private static listInstantaniousTempoChangesGeneral: string[] = [
  31. "tempo primo",
  32. "a tempo",
  33. "tempo i",
  34. "rubato",
  35. "doppio movimento",
  36. ];
  37. private static listInstantaniousTempoAddons: string[] = [
  38. "assai",
  39. "amoroso",
  40. "cantabile",
  41. "con brio",
  42. "con dolore",
  43. "con espressione",
  44. "con fuoco",
  45. "con moto",
  46. "con spirito",
  47. "spiritoso",
  48. "espressivo",
  49. "giocoso",
  50. "giusto",
  51. "grazioso",
  52. "lesto",
  53. "lugubre",
  54. "maestoso",
  55. "ma non troppo",
  56. "marcato",
  57. "molto",
  58. "morendo",
  59. "mosso",
  60. "non tanto",
  61. "piu",
  62. "un poco",
  63. "poco",
  64. "quasi",
  65. "risoluto",
  66. "scherzando",
  67. "sostenuto",
  68. "teneramente",
  69. "tempo giusto",
  70. "tranquillo",
  71. "sehr",
  72. "lieblich",
  73. "liebevoll",
  74. "mit Leidenschaft",
  75. "mit Liebe",
  76. "amour�s",
  77. "gesanglich",
  78. "mit Schwung",
  79. "mit Feuer",
  80. "mit Schmerz",
  81. "mit Ausdruck",
  82. "mit Bewegung",
  83. "geistvoll",
  84. "ausdrucksvoll",
  85. "freudig",
  86. "verspielt",
  87. "angemessen",
  88. "grazi�s",
  89. "mit Grazie",
  90. "flink",
  91. "beh�nde",
  92. "traurig",
  93. "klagend",
  94. "majest�tisch",
  95. "aber nicht zu sehr",
  96. "markant",
  97. "gem��igt",
  98. "viel",
  99. "sehr",
  100. "ersterbend",
  101. "bewegt",
  102. "nicht zu sehr",
  103. "mehr",
  104. "ein wenig",
  105. "gleichsam",
  106. "entschlossen",
  107. "zupackend",
  108. "heiter",
  109. "nachdr�cklich",
  110. "getragen",
  111. "gewichtig",
  112. "zart",
  113. "z�rtlich",
  114. "im angemessenen Zeitma�",
  115. "ruhig",
  116. "ein wenig",
  117. "alla marcia",
  118. "ad libitum",
  119. "alla breve",
  120. ];
  121. private tempoEnum: TempoEnum;
  122. private tempoInBpm: number;
  123. // Must refactor: In c# use 'out' arguments
  124. //private findTempoEnum(inputString: string, pre: string, post: string): TempoEnum {
  125. // let result: TempoEnum = this.splitStringAfterInstructionWord(inputString,
  126. // InstantaniousTempoExpression.listInstantaniousTempoLarghissimo, TempoEnum.larghissimo, pre,
  127. // post);
  128. // if (result !== TempoEnum.none)
  129. // return result;
  130. // result = this.splitStringAfterInstructionWord(inputString, InstantaniousTempoExpression.listInstantaniousTempoGrave, TempoEnum.grave, pre,
  131. // post);
  132. // if (result !== TempoEnum.none)
  133. // return result;
  134. // return TempoEnum.none;
  135. //}
  136. //private splitStringAfterInstructionWord(inputString: string, instruction: string[], value: TempoEnum, pre: string, post: string): TempoEnum {
  137. // pre = undefined;
  138. // post = undefined;
  139. // for (let idx: number = 0, len: number = instruction.length; idx < len; ++idx) {
  140. // let instructionWord: string = instruction[idx];
  141. // let separators: string[] = [" " + instructionWord, instructionWord + " ", "," + instructionWord, instructionWord + ","];
  142. // for (let j: number = 0; j < 4; j++) {
  143. // let splits:string[] = inputString.split(separators[j], 2);
  144. // if (splits.length > 1) {
  145. // pre = splits[0];
  146. // post = splits[1];
  147. // return value;
  148. // }
  149. // }
  150. // }
  151. // return TempoEnum.none;
  152. //}
  153. public static getDefaultValueForTempoType(tempoEnum: TempoEnum): number {
  154. switch (tempoEnum) {
  155. case TempoEnum.larghissimo:
  156. return 20;
  157. case TempoEnum.grave:
  158. return 30;
  159. case TempoEnum.lento:
  160. return 48;
  161. case TempoEnum.largo:
  162. return 52;
  163. case TempoEnum.larghetto:
  164. return 63;
  165. case TempoEnum.adagio:
  166. return 70;
  167. case TempoEnum.adagietto:
  168. return 75;
  169. case TempoEnum.andanteModerato:
  170. return 88;
  171. case TempoEnum.andante:
  172. return 92;
  173. case TempoEnum.andantino:
  174. return 96;
  175. case TempoEnum.moderato:
  176. return 106;
  177. case TempoEnum.allegretto:
  178. return 112;
  179. case TempoEnum.allegroModerato:
  180. return 118;
  181. case TempoEnum.allegro:
  182. return 130;
  183. case TempoEnum.vivace:
  184. return 140;
  185. case TempoEnum.vivacissimo:
  186. return 155;
  187. case TempoEnum.allegrissimo:
  188. return 170;
  189. case TempoEnum.presto:
  190. return 184;
  191. case TempoEnum.prestissimo:
  192. return 200;
  193. default:
  194. throw new ArgumentOutOfRangeException("tempoEnum");
  195. }
  196. }
  197. public static isInputStringInstantaniousTempo(inputString: string): boolean {
  198. if (inputString === undefined) { return false; }
  199. return (
  200. (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLarghissimo, inputString))
  201. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoGrave, inputString))
  202. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLento, inputString))
  203. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLargo, inputString))
  204. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLarghetto, inputString))
  205. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAdagio, inputString))
  206. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAdagietto, inputString))
  207. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAndanteModerato, inputString))
  208. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAndante, inputString))
  209. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAndantino, inputString))
  210. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoModerato, inputString))
  211. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegretto, inputString))
  212. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegroModerato, inputString))
  213. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegro, inputString))
  214. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoVivace, inputString))
  215. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoVivacissimo, inputString))
  216. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegrissimo, inputString))
  217. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoPresto, inputString))
  218. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoPrestissimo, inputString))
  219. || (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoChangesGeneral, inputString))
  220. );
  221. }
  222. public get Label(): string {
  223. return this.label;
  224. }
  225. public set Label(value: string) {
  226. this.label = value;
  227. }
  228. public get Placement(): PlacementEnum {
  229. return this.placement;
  230. }
  231. public set Placement(value: PlacementEnum) {
  232. this.placement = value;
  233. }
  234. public get StaffNumber(): number {
  235. return this.staffNumber;
  236. }
  237. public set StaffNumber(value: number) {
  238. this.staffNumber = value;
  239. }
  240. public get Enum(): TempoEnum {
  241. return this.tempoEnum;
  242. }
  243. public get TempoInBpm(): number {
  244. return this.tempoInBpm;
  245. }
  246. public set TempoInBpm(value: number) {
  247. this.tempoInBpm = value;
  248. }
  249. public get ParentMultiTempoExpression(): MultiTempoExpression {
  250. return this.parentMultiTempoExpression;
  251. }
  252. public getAbsoluteTimestamp(): Fraction {
  253. return Fraction.plus(this.ParentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp, this.ParentMultiTempoExpression.Timestamp);
  254. }
  255. public getAbsoluteFloatTimestamp(): number {
  256. return Fraction.plus(this.ParentMultiTempoExpression.SourceMeasureParent.AbsoluteTimestamp, this.ParentMultiTempoExpression.Timestamp).RealValue;
  257. }
  258. private setTempoAndTempoType(soundTempo: number): void {
  259. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLarghissimo, this.label)) {
  260. if (soundTempo === 0) {
  261. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.larghissimo);
  262. }
  263. this.tempoInBpm = soundTempo;
  264. this.tempoEnum = TempoEnum.larghissimo;
  265. return;
  266. }
  267. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoGrave, this.label)) {
  268. if (soundTempo === 0) {
  269. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.grave);
  270. }
  271. this.tempoInBpm = soundTempo;
  272. this.tempoEnum = TempoEnum.grave;
  273. return;
  274. }
  275. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLento, this.label)) {
  276. if (soundTempo === 0) {
  277. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.lento);
  278. }
  279. this.tempoInBpm = soundTempo;
  280. this.tempoEnum = TempoEnum.lento;
  281. return;
  282. }
  283. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLargo, this.label)) {
  284. if (soundTempo === 0) {
  285. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.largo);
  286. }
  287. this.tempoInBpm = soundTempo;
  288. this.tempoEnum = TempoEnum.largo;
  289. return;
  290. }
  291. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoLarghetto, this.label)) {
  292. if (soundTempo === 0) {
  293. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.larghetto);
  294. }
  295. this.tempoInBpm = soundTempo;
  296. this.tempoEnum = TempoEnum.larghetto;
  297. return;
  298. }
  299. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAdagio, this.label)) {
  300. if (soundTempo === 0) {
  301. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.adagio);
  302. }
  303. this.tempoInBpm = soundTempo;
  304. this.tempoEnum = TempoEnum.adagio;
  305. return;
  306. }
  307. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAdagietto, this.label)) {
  308. if (soundTempo === 0) {
  309. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.adagietto);
  310. }
  311. this.tempoInBpm = soundTempo;
  312. this.tempoEnum = TempoEnum.adagietto;
  313. return;
  314. }
  315. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAndanteModerato, this.label)) {
  316. if (soundTempo === 0) {
  317. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.andanteModerato);
  318. }
  319. this.tempoInBpm = soundTempo;
  320. this.tempoEnum = TempoEnum.andanteModerato;
  321. return;
  322. }
  323. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAndante, this.label)) {
  324. if (soundTempo === 0) {
  325. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.andante);
  326. }
  327. this.tempoInBpm = soundTempo;
  328. this.tempoEnum = TempoEnum.andante;
  329. return;
  330. }
  331. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAndantino, this.label)) {
  332. if (soundTempo === 0) {
  333. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.andantino);
  334. }
  335. this.tempoInBpm = soundTempo;
  336. this.tempoEnum = TempoEnum.andantino;
  337. return;
  338. }
  339. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoModerato, this.label)) {
  340. if (soundTempo === 0) {
  341. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.moderato);
  342. }
  343. this.tempoInBpm = soundTempo;
  344. this.tempoEnum = TempoEnum.moderato;
  345. return;
  346. }
  347. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegretto, this.label)) {
  348. if (soundTempo === 0) {
  349. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.allegretto);
  350. }
  351. this.tempoInBpm = soundTempo;
  352. this.tempoEnum = TempoEnum.allegretto;
  353. return;
  354. }
  355. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegroModerato, this.label)) {
  356. if (soundTempo === 0) {
  357. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.allegroModerato);
  358. }
  359. this.tempoInBpm = soundTempo;
  360. this.tempoEnum = TempoEnum.allegroModerato;
  361. return;
  362. }
  363. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegro, this.label)) {
  364. if (soundTempo === 0) {
  365. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.allegro);
  366. }
  367. this.tempoInBpm = soundTempo;
  368. this.tempoEnum = TempoEnum.allegro;
  369. return;
  370. }
  371. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoVivace, this.label)) {
  372. if (soundTempo === 0) {
  373. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.vivace);
  374. }
  375. this.tempoInBpm = soundTempo;
  376. this.tempoEnum = TempoEnum.vivace;
  377. return;
  378. }
  379. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoVivacissimo, this.label)) {
  380. if (soundTempo === 0) {
  381. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.vivacissimo);
  382. }
  383. this.tempoInBpm = soundTempo;
  384. this.tempoEnum = TempoEnum.vivacissimo;
  385. return;
  386. }
  387. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAllegrissimo, this.label)) {
  388. if (soundTempo === 0) {
  389. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.allegrissimo);
  390. }
  391. this.tempoInBpm = soundTempo;
  392. this.tempoEnum = TempoEnum.allegrissimo;
  393. return;
  394. }
  395. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoPresto, this.label)) {
  396. if (soundTempo === 0) {
  397. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.presto);
  398. }
  399. this.tempoInBpm = soundTempo;
  400. this.tempoEnum = TempoEnum.presto;
  401. return;
  402. }
  403. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoPrestissimo, this.label)) {
  404. if (soundTempo === 0) {
  405. soundTempo = InstantaniousTempoExpression.getDefaultValueForTempoType(TempoEnum.prestissimo);
  406. }
  407. this.tempoInBpm = soundTempo;
  408. this.tempoEnum = TempoEnum.prestissimo;
  409. return;
  410. }
  411. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoAddons, this.label)) {
  412. this.tempoInBpm = 0;
  413. this.tempoEnum = TempoEnum.addon;
  414. return;
  415. }
  416. if (InstantaniousTempoExpression.isStringInStringList(InstantaniousTempoExpression.listInstantaniousTempoChangesGeneral, this.label)) {
  417. this.tempoInBpm = 0;
  418. this.tempoEnum = TempoEnum.changes;
  419. return;
  420. }
  421. }
  422. }
  423. export enum TempoEnum {
  424. none,
  425. larghissimo,
  426. grave,
  427. lento,
  428. largo,
  429. larghetto,
  430. adagio,
  431. adagietto,
  432. andanteModerato,
  433. andante,
  434. andantino,
  435. moderato,
  436. allegretto,
  437. allegroModerato,
  438. allegro,
  439. vivace,
  440. vivacissimo,
  441. allegrissimo,
  442. presto,
  443. prestissimo,
  444. lastRealTempo,
  445. addon,
  446. changes
  447. }