「VexFlow 音符」の版間の差分

提供:yonewiki
35行目: 35行目:
     new StaveNote({ keys: ["c/4"], duration: "1" }),  
     new StaveNote({ keys: ["c/4"], duration: "1" }),  
   ];
   ];
   Formatter.FormatAndDraw(ctx, stave1, notes1);
   Formatter.FormatAndDraw(ctx, stave1, notes1);


   const stave2 = new Stave(360, 50, 350).setContext(ctx).draw();
   const stave2 = new Stave(360, 50, 350).setContext(ctx).draw();
   const notes2 = [
   const notes2 = [
     new StaveNote({ keys: ["c/4"], duration: "2" }),  
     new StaveNote({ keys: ["c/4"], duration: "2" }),  
46行目: 43行目:
     new StaveNote({ keys: ["e/4"], duration: "4" }),  
     new StaveNote({ keys: ["e/4"], duration: "4" }),  
   ];
   ];
   Formatter.FormatAndDraw(ctx, stave2, notes2);
   Formatter.FormatAndDraw(ctx, stave2, notes2);


   const stave3 = new Stave(710, 50, 450).setEndBarType(Barline.type.END).setContext(ctx).draw();
   const stave3 = new Stave(710, 50, 450).setEndBarType(Barline.type.END).setContext(ctx).draw();
   const notes3 = [
   const notes3 = [
     new StaveNote({ keys: ["c/4"], duration: "8" }),  
     new StaveNote({ keys: ["c/4"], duration: "8" }),  
70行目: 65行目:
   stave3.setContext(ctx).draw();
   stave3.setContext(ctx).draw();
   voice3.setContext(ctx).draw();
   voice3.setContext(ctx).draw();
//  Formatter.FormatAndDraw(ctx, stave3, notes3);
 
})();
})();
</yjavascript>
</yjavascript>




<syntaxhighlight lang="JavaScript" line start="1">
<div id="yonet202302_Output01"></div>
<script>
(function(){
  const {
    Factory,
    Stave,
    StaveNote,
    Formatter,
    Voice,
    Barline,
  } = Vex.Flow;
  const f = new Factory({ renderer: { elementId: 'yonet202302_Output01', width: 1500, height: 195 } });
  const ctx = f.getContext();
  const stave1 = new Stave(10, 50, 350).setContext(ctx).draw();
  stave1.addClef("treble").setContext(ctx).draw();
  stave1.addTimeSignature('C').setContext(ctx).draw();
  const notes1 = [
    new StaveNote({ keys: ["c/4"], duration: "1" }),
  ];
  Formatter.FormatAndDraw(ctx, stave1, notes1);
  const stave2 = new Stave(360, 50, 350).setContext(ctx).draw();
  const notes2 = [
    new StaveNote({ keys: ["c/4"], duration: "2" }),
    new StaveNote({ keys: ["d/4"], duration: "4" }),
    new StaveNote({ keys: ["e/4"], duration: "4" }),
  ];
  Formatter.FormatAndDraw(ctx, stave2, notes2);
  const stave3 = new Stave(710, 50, 450).setEndBarType(Barline.type.END).setContext(ctx).draw();
  const notes3 = [
    new StaveNote({ keys: ["c/4"], duration: "8" }),
    new StaveNote({ keys: ["d/4"], duration: "8" }),
    new StaveNote({ keys: ["e/4"], duration: "16" }),
    new StaveNote({ keys: ["f/4"], duration: "16" }),
    new StaveNote({ keys: ["g/4"], duration: "16" }),
    new StaveNote({ keys: ["a/4"], duration: "16" }),
    new StaveNote({ keys: ["c/4"], duration: "8" }),
    new StaveNote({ keys: ["d/4"], duration: "8" }),
    new StaveNote({ keys: ["e/4"], duration: "16" }),
    new StaveNote({ keys: ["f/4"], duration: "16" }),
    new StaveNote({ keys: ["g/4"], duration: "16" }),
    new StaveNote({ keys: ["a/4"], duration: "16" }),
  ];
  notes3.forEach((StaveNote) => StaveNote.setStave(stave3));
  const voice3 = new Voice({beat_value: 4, num_beats: 4}).setMode(3).addTickables(notes3);
  new Formatter().joinVoices([voice3]).formatToStave([voice3], stave3);
  stave3.setContext(ctx).draw();
  voice3.setContext(ctx).draw();
})();
</script>
</syntaxhighlight>
 
 


[[VexFlow 使い方]]に戻る。
[[VexFlow 使い方]]に戻る。

2023年2月9日 (木) 22:07時点における版

VexFlow 使い方に戻る。

概要

 音符を記述するまでにその土台となる楽譜の構造を知らなければならなかったので、遅くなりましたが、ようやっと本文をえがけるようになるという感じです。ただし、音符も構成要素は複雑なので、ここではシンプルな音符の機能のみを紹介したいと思います。旗同士を繋ぐ連桁(れんこう:英 Beem ビーム)、連符や休符については別の項目で記します。この先の3つあたりまで把握できてやっと音を記録する楽譜というものが構成できるようになります。あと3つ先までは音符の範疇。ここでは、その一部しか紹介しないことに注意しておいて下さい。

 

音符の種類

 小節において何拍分を鳴らすかの違いで音符の種類が異なります。まずは、種類について見てみましょう。



<div id="yonet202302_Output01"></div>
<script>
(function(){
  const {
    Factory,
    Stave,
    StaveNote,
    Formatter,
    Voice,
    Barline,
  } = Vex.Flow;

  const f = new Factory({ renderer: { elementId: 'yonet202302_Output01', width: 1500, height: 195 } });
  const ctx = f.getContext();
  const stave1 = new Stave(10, 50, 350).setContext(ctx).draw();
  stave1.addClef("treble").setContext(ctx).draw();
  stave1.addTimeSignature('C').setContext(ctx).draw();

  const notes1 = [
    new StaveNote({ keys: ["c/4"], duration: "1" }), 
  ];
  Formatter.FormatAndDraw(ctx, stave1, notes1);

  const stave2 = new Stave(360, 50, 350).setContext(ctx).draw();
  const notes2 = [
    new StaveNote({ keys: ["c/4"], duration: "2" }), 
    new StaveNote({ keys: ["d/4"], duration: "4" }), 
    new StaveNote({ keys: ["e/4"], duration: "4" }), 
  ];
  Formatter.FormatAndDraw(ctx, stave2, notes2);

  const stave3 = new Stave(710, 50, 450).setEndBarType(Barline.type.END).setContext(ctx).draw();
  const notes3 = [
    new StaveNote({ keys: ["c/4"], duration: "8" }), 
    new StaveNote({ keys: ["d/4"], duration: "8" }), 
    new StaveNote({ keys: ["e/4"], duration: "16" }), 
    new StaveNote({ keys: ["f/4"], duration: "16" }), 
    new StaveNote({ keys: ["g/4"], duration: "16" }), 
    new StaveNote({ keys: ["a/4"], duration: "16" }), 
    new StaveNote({ keys: ["c/4"], duration: "8" }), 
    new StaveNote({ keys: ["d/4"], duration: "8" }), 
    new StaveNote({ keys: ["e/4"], duration: "16" }), 
    new StaveNote({ keys: ["f/4"], duration: "16" }), 
    new StaveNote({ keys: ["g/4"], duration: "16" }), 
    new StaveNote({ keys: ["a/4"], duration: "16" }), 
  ];
  notes3.forEach((StaveNote) => StaveNote.setStave(stave3));
  const voice3 = new Voice({beat_value: 4, num_beats: 4}).setMode(3).addTickables(notes3);
  new Formatter().joinVoices([voice3]).formatToStave([voice3], stave3);
  stave3.setContext(ctx).draw();
  voice3.setContext(ctx).draw();

})();
</script>

 

VexFlow 使い方に戻る。