Piano notes book, powered by Astro and React.
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

154 righe
2.9 KiB

  1. import * as React from 'react';
  2. import * as Vexflow from 'vexflow';
  3. export const Notation = () => {
  4. const ref = React.useRef<HTMLElementTagNameMap['div']>(null);
  5. const id = React.useId();
  6. React.useEffect(() => {
  7. const render = (id: string) => {
  8. const el = window.document.getElementById(id);
  9. if (!el) {
  10. return;
  11. }
  12. el.innerHTML = '';
  13. const { Factory } = Vexflow;
  14. const width = el.clientWidth;
  15. const vf = new Factory({
  16. renderer: { elementId: id, width, height: 300 },
  17. });
  18. vf.getContext().scale(0.75, 0.75);
  19. const score = vf.EasyScore();
  20. let currentX = 20;
  21. let currentY = 40;
  22. const getCurrentBar = (width: number) => {
  23. const system = vf.System({
  24. x: currentX,
  25. y: currentY,
  26. width,
  27. });
  28. currentX += width;
  29. return system;
  30. };
  31. let system = getCurrentBar(130);
  32. system.addStave({
  33. voices: [
  34. score.voice([
  35. ...score.notes('D5/8'),
  36. ], {
  37. time: '1/8',
  38. })
  39. ]
  40. })
  41. .addClef('treble')
  42. .addKeySignature('Gm')
  43. .addTimeSignature('C')
  44. .setTempo(
  45. {
  46. name: 'Adagio.'
  47. },
  48. -30
  49. );
  50. system.addStave({
  51. voices: [
  52. score.voice([
  53. ...score.notes('D3/8/r', { clef: 'bass' }),
  54. ], {
  55. time: '1/8',
  56. })
  57. ]
  58. })
  59. .addClef('bass')
  60. .addKeySignature('Gm')
  61. .addTimeSignature('C');
  62. system.addConnector('brace');
  63. system.addConnector('singleLeft');
  64. system.addConnector('singleRight');
  65. system = getCurrentBar(350);
  66. system
  67. .addStave({
  68. voices: [
  69. score.voice(
  70. [
  71. ...score.tuplet(
  72. score.beam(
  73. score.notes('G5/16, B5, A5, G5, F#5, G5'),
  74. ),
  75. {
  76. ratioed: false,
  77. notesOccupied: 4,
  78. }
  79. ),
  80. ...score.tuplet(
  81. score.beam(
  82. score.notes('G5/16, F5, G5, D6, F5, G5'),
  83. ),
  84. {
  85. ratioed: false,
  86. notesOccupied: 4,
  87. yOffset: Infinity,
  88. }
  89. ),
  90. // ...score.beam(score.notes('E5/8, D5')),
  91. ...score.beam(score.notes('E5/8, D5')),
  92. ...score.tuplet(
  93. score.beam(
  94. score.notes('D5/16, E5, F5, G5, A5, B5'),
  95. ),
  96. {
  97. ratioed: false,
  98. notesOccupied: 4,
  99. yOffset: Infinity,
  100. }
  101. ),
  102. ]
  103. ),
  104. ]
  105. });
  106. system
  107. .addStave({
  108. voices: [
  109. score.voice([
  110. ...score.beam(
  111. score.notes('(G3 B3 D4)/8, (G3 B3 D4)', { clef: 'bass' })
  112. ),
  113. ...score.beam(
  114. score.notes('(G3 B3 D4)/8, (G3 B3 D4)', { clef: 'bass' })
  115. ),
  116. ...score.beam(
  117. score.notes('(G3 C4)/8, (G3 B3)', { clef: 'bass' })
  118. ),
  119. ...score.beam(
  120. score.notes('(G3 B3)/8, (G3 B3)', { clef: 'bass' })
  121. ),
  122. ]),
  123. ]
  124. });
  125. system.addConnector('singleLeft');
  126. system.addConnector('singleRight');
  127. vf.draw();
  128. };
  129. render(id);
  130. }, []);
  131. return (
  132. <div
  133. ref={ref}
  134. id={id}
  135. />
  136. );
  137. };