VexFlowConverter_Clef_Test.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {IXmlElement} from "../../../../src/Common/FileIO/Xml";
  2. import {MusicSheet} from "../../../../src/MusicalScore/MusicSheet";
  3. import {MusicSheetReader} from "../../../../src/MusicalScore/ScoreIO/MusicSheetReader";
  4. describe("Clef Converter MusicXML to VexFlow", () => {
  5. let reader: MusicSheetReader;
  6. let parser: DOMParser;
  7. before((): void => {
  8. reader = new MusicSheetReader();
  9. parser = new DOMParser();
  10. });
  11. it("reads treble key", (done: MochaDone) => {
  12. getMusicSheetWithClef("G").getStaffFromIndex(0);
  13. done();
  14. });
  15. /**
  16. * Simulates loading a [[MusicSheet]] with the specified clef.
  17. *
  18. * @see https://usermanuals.musicxml.com/MusicXML/Content/EL-MusicXML-clef.htm
  19. */
  20. function getMusicSheetWithClef(sign: string, line?: number, clefOcatveChange?: number, additional?: string, size?: string): MusicSheet {
  21. const doc: Document = parser.parseFromString(getMusicXmlWithClef(sign, line, clefOcatveChange, additional, size), "text/xml");
  22. chai.expect(doc).to.not.be.undefined;
  23. const score: IXmlElement = new IXmlElement(doc.getElementsByTagName("score-partwise")[0]);
  24. chai.expect(score).to.not.be.undefined;
  25. return reader.createMusicSheet(score, "template.xml");
  26. }
  27. function getMusicXmlWithClef(sign: string, line?: number, clefOcatveChange?: number, additional?: string, size?: string): string {
  28. // let modeElement: string = mode ? `<mode>${mode}</mode>` : "";
  29. // let fifthsElement: string = fifths ? `<fifths>${fifths}</fifths>` : "";
  30. return `<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  31. <!DOCTYPE score-partwise PUBLIC
  32. "-//Recordare//DTD MusicXML 3.0 Partwise//EN"
  33. "http://www.musicxml.org/dtds/partwise.dtd">
  34. <score-partwise version="3.0">
  35. <part-list>
  36. <score-part id="P1">
  37. <part-name>Music</part-name>
  38. </score-part>
  39. </part-list>
  40. <part id="P1">
  41. <measure number="1">
  42. <attributes>
  43. <divisions>1</divisions>
  44. <key>
  45. </key>
  46. <time>
  47. <beats>4</beats>
  48. <beat-type>4</beat-type>
  49. </time>
  50. <clef>
  51. <sign>G</sign>
  52. <line>2</line>
  53. </clef>
  54. </attributes>
  55. <note>
  56. <pitch>
  57. <step>C</step>
  58. <octave>4</octave>
  59. </pitch>
  60. <duration>4</duration>
  61. <type>whole</type>
  62. </note>
  63. </measure>
  64. </part>
  65. </score-partwise>`;
  66. }
  67. });