「VexFlow 小節開始終了線」の版間の差分

提供:yonewiki
 
(同じ利用者による、間の29版が非表示)
5行目: 5行目:
[[VexFlow 使い方]]に戻る。
[[VexFlow 使い方]]に戻る。
== '''概要''' ==
== '''概要''' ==
 小節区切りの設定をする手順を示します。
 小節区切りの設定をする手順を示します。約1年近く絶賛挫折中でしたが、久しぶりに更新しました。2024年3月中旬時点。このサイトのこの記事がかなり世の中的に期待されているようです。続編を書かないといけないなと思った次第です。次の記事も頑張っていこう!




49行目: 49行目:
<yjavascript></script>
<yjavascript></script>
<script>
<script>
var VF = Vex.Flow;
(function(){
(function(){
const {
const {
57行目: 58行目:
   Voice,
   Voice,
   StaveTie,
   StaveTie,
  BarLine,
   Renderer
   Renderer
} = Vex.Flow;
} = Vex.Flow;


let nscale = 0.5
let nscale = 0.68
let nwidth = 1040;
let nwidth = 1040;
let nheight = 320;
let nheight = 320;
let nHeadMargin = 70;
let nStaveWidth = 350;
const f = new Factory({  
const f = new Factory({  
   renderer: { elementId: 'yonet202403Mid_Output01', width: nwidth, height: nheight * nscale }
   renderer: { elementId: 'yonet202403Mid_Output01', width: nwidth, height: nheight * nscale }
79行目: 85行目:
   ctx.lineTo(0 + i, nheight);
   ctx.lineTo(0 + i, nheight);
   if (i % 100 === 0){
   if (i % 100 === 0){
     ctx.setLineWidth(1); // 線の太さ
     ctx.setLineWidth(1);
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
   }
   }
   else{
   else{
     ctx.setLineWidth(0.5); // 線の太さ
     ctx.setLineWidth(0.5);
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
   }
   }
94行目: 100行目:
   ctx.lineTo(nwidth * (1 / nscale), i);
   ctx.lineTo(nwidth * (1 / nscale), i);
   if (i % 100 === 0){
   if (i % 100 === 0){
     ctx.setLineWidth(1); // 線の太さ
     ctx.setLineWidth(1);
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
   }
   }
   else{
   else{
     ctx.setLineWidth(0.5); // 線の太さ
     ctx.setLineWidth(0.5);
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
   }
   }
107行目: 113行目:
ctx.strokeStyle = defaultStyle.strokeStyle;
ctx.strokeStyle = defaultStyle.strokeStyle;


const stave1 = new Stave(10, 50, 350).setContext(ctx);
const stave1 = new Stave(10, 50, nHeadMargin + nStaveWidth).setContext(ctx);
stave1.addClef("treble").setContext(ctx);
stave1.setClef("treble").setContext(ctx);
stave1.addTimeSignature('4/4').setContext(ctx);
stave1.setTimeSignature('4/4').setContext(ctx);
//stave1.setBegBarType(4);//BarLine.type.REPEAT_BEGIN
stave1.setBegBarType(VF.Barline.type.REPEAT_BEGIN);//BarLine.type.REPEAT_BEGIN
stave1.draw();


const stave2 = new Stave(stave1.width + stave1.x, stave1.y, 350).setContext(ctx);
//SINGLE:1, DOUBLE:2, END:3, REPEAT_BEGIN:4, REPEAT_END:5, REPEAT_BOTH:6, NONE:7
stave2.addClef("treble").setContext(ctx);
stave2.addTimeSignature('4/4').setContext(ctx);
 
const stave5 = new Stave(stave1.x, stave1.y + 100, 350).setContext(ctx);
stave5.addClef("treble").setContext(ctx);
stave5.addTimeSignature('4/4').setContext(ctx);


const notes1 = [
const notes1 = [
126行目: 129行目:
];
];


stave1.draw();
Formatter.FormatAndDraw(ctx, stave1, notes1);


const tie1 = new StaveTie({
const tie1 = new StaveTie({
142行目: 145行目:
});
});


Formatter.FormatAndDraw(ctx, stave1, notes1);
tie1.setContext(ctx).draw();
tie1.setContext(ctx).draw();
tie2.setContext(ctx).draw();
tie2.setContext(ctx).draw();
const stave2 = new Stave(stave1.width + stave1.x, stave1.y, nStaveWidth).setContext(ctx);
stave2.setEndBarType(VF.Barline.type.REPEAT_BOTH);
stave2.draw();
const stave3 = new Stave(stave2.width + stave2.x, stave1.y, nStaveWidth).setContext(ctx);
stave3.setEndBarType(VF.Barline.type.NONE);
stave3.draw();
const stave4 = new Stave(stave3.width + stave3.x, stave1.y, nStaveWidth).setContext(ctx);
stave4.setBegBarType(VF.Barline.type.NONE);
stave4.setEndBarType(VF.Barline.type.REPEAT_END);
stave4.draw();
const stave5 = new Stave(stave1.x, stave1.y + 100, nHeadMargin + nStaveWidth).setContext(ctx);
stave5.addClef("treble").setContext(ctx);
stave5.addTimeSignature('4/4').setContext(ctx);
stave5.setEndBarType(VF.Barline.type.SINGLE);//規定値(省略可能)


stave5.draw();
stave5.draw();
158行目: 182行目:


const tie3 = new StaveTie({
const tie3 = new StaveTie({
   first_note: notes2[1],
   first_note: notes5[1],
   last_note: notes2[2],
   last_note: notes5[2],
   first_indices: [0],
   first_indices: [0],
   last_indices: [0],
   last_indices: [0],
165行目: 189行目:


const tie4 = new StaveTie({
const tie4 = new StaveTie({
   first_note: notes2[2],
   first_note: notes5[2],
   last_note: notes2[3],
   last_note: notes5[3],
   first_indices: [0],
   first_indices: [0],
   last_indices: [0],
   last_indices: [0],
174行目: 198行目:
tie4.setContext(ctx).draw();
tie4.setContext(ctx).draw();


const stave6 = new Stave(stave5.width + stave5.x, stave5.y, 350).setContext(ctx);
const stave6 = new Stave(stave5.width + stave5.x, stave5.y, nStaveWidth).setContext(ctx);
stave6.setEndBarType(VF.Barline.type.DOUBLE);
 
stave6.draw();
 
const notes6 = [
const notes6 = [
   new StaveNote({ keys: ["e/5"], duration: "q" }),
   new StaveNote({ keys: ["e/5"], duration: "q" }),
181行目: 209行目:
   new StaveNote({ keys: ["a/5"], duration: "q" }),
   new StaveNote({ keys: ["a/5"], duration: "q" }),
];
];
stave6.draw();


Formatter.FormatAndDraw(ctx, stave6, notes6);
Formatter.FormatAndDraw(ctx, stave6, notes6);


const tie5 = new StaveTie({
const tie5 = new StaveTie({
   first_note: notes2[3],
   first_note: notes5[3],
   last_note: notes3[0],
   last_note: notes6[0],
   first_indices: [0],
   first_indices: [0],
   last_indices: [0],
   last_indices: [0],
195行目: 221行目:
tie5.setContext(ctx).draw();
tie5.setContext(ctx).draw();


// 灰色の背景
 
ctx.setFillStyle('#F5F5F5'); // 灰色に設定
const stave7 = new Stave(stave6.width + stave6.x, stave5.y, nStaveWidth).setContext(ctx);
stave7.draw();
 
 
const stave8 = new Stave(stave7.width + stave7.x, stave5.y, nStaveWidth).setContext(ctx);
stave8.setEndBarType(VF.Barline.type.END);
stave8.draw();
 
ctx.setFillStyle('#F5F5F5');
ctx.fillRect(0, 0, f.width, f.height);
ctx.fillRect(0, 0, f.width, f.height);


203行目: 237行目:
const svgElement = document.querySelector('#Output svg');
const svgElement = document.querySelector('#Output svg');
svgElement.style.backgroundColor = '#F5F5F5';
svgElement.style.backgroundColor = '#F5F5F5';
  const svgNS = 'http://www.w3.org/2000/svg';
const svgNS = 'http://www.w3.org/2000/svg';
  const lineColor = '#EEEEEE';
const lineColor = '#EEEEEE';
  //
  // 縦線(10pxごと)
  //for (let x = 10; x < svgElement.getAttribute('width'); x += 10) {
  //  const line = document.createElementNS(svgNS, 'line');
  //  line.setAttribute('x1', x);
  //  line.setAttribute('y1', 0);
  //  line.setAttribute('x2', x);
  //  line.setAttribute('y2', svgElement.getAttribute('height'));
  //  line.setAttribute('stroke', lineColor);
  //  line.setAttribute('stroke-width', '1');
  //  svgElement.appendChild(line);
  //}
 
  // 横線(10pxごと)
  //for (let y = 10; y < svgElement.getAttribute('height'); y += 10) {
  //  const line = document.createElementNS(svgNS, 'line');
  //  line.setAttribute('x1', 0);
  //  line.setAttribute('y1', y);
  //  line.setAttribute('x2', svgElement.getAttribute('width'));
  //  line.setAttribute('y2', y);
  //  line.setAttribute('stroke', lineColor);
  //  line.setAttribute('stroke-width', '1');
  //  svgElement.appendChild(line);
  //}
 
</yjavascript>
</yjavascript>


237行目: 246行目:
<div id="yonet202403Mid_Output01"></div>
<div id="yonet202403Mid_Output01"></div>
<script>
<script>
var VF = Vex.Flow;
(function(){
(function(){
const {
const {
245行目: 255行目:
   Voice,
   Voice,
   StaveTie,
   StaveTie,
  BarLine,
   Renderer
   Renderer
} = Vex.Flow;
} = Vex.Flow;


let nscale = 0.5
let nscale = 0.68
let nwidth = 1040;
let nwidth = 1040;
let nheight = 320;
let nheight = 320;
let nHeadMargin = 70;
let nStaveWidth = 350;
const f = new Factory({  
const f = new Factory({  
   renderer: { elementId: 'yonet202403Mid_Output01', width: nwidth, height: nheight * nscale }
   renderer: { elementId: 'yonet202403Mid_Output01', width: nwidth, height: nheight * nscale }
267行目: 282行目:
   ctx.lineTo(0 + i, nheight);
   ctx.lineTo(0 + i, nheight);
   if (i % 100 === 0){
   if (i % 100 === 0){
     ctx.setLineWidth(1); // 線の太さ
     ctx.setLineWidth(1);
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
   }
   }
   else{
   else{
     ctx.setLineWidth(0.5); // 線の太さ
     ctx.setLineWidth(0.5);
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
   }
   }
282行目: 297行目:
   ctx.lineTo(nwidth * (1 / nscale), i);
   ctx.lineTo(nwidth * (1 / nscale), i);
   if (i % 100 === 0){
   if (i % 100 === 0){
     ctx.setLineWidth(1); // 線の太さ
     ctx.setLineWidth(1);
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
     ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
   }
   }
   else{
   else{
     ctx.setLineWidth(0.5); // 線の太さ
     ctx.setLineWidth(0.5);
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
     ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
   }
   }
295行目: 310行目:
ctx.strokeStyle = defaultStyle.strokeStyle;
ctx.strokeStyle = defaultStyle.strokeStyle;


const stave1 = new Stave(10, 50, 350).setContext(ctx);
const stave1 = new Stave(10, 50, nHeadMargin + nStaveWidth).setContext(ctx);
stave1.addClef("treble").setContext(ctx);
stave1.setClef("treble").setContext(ctx);
stave1.addTimeSignature('4/4').setContext(ctx);
stave1.setTimeSignature('4/4').setContext(ctx);
//stave1.setBegBarType(4);//BarLine.type.REPEAT_BEGIN
stave1.setBegBarType(VF.Barline.type.REPEAT_BEGIN);//BarLine.type.REPEAT_BEGIN
stave1.draw();


const stave2 = new Stave(stave1.x, stave1.y + 100, 350).setContext(ctx);
//SINGLE:1, DOUBLE:2, END:3, REPEAT_BEGIN:4, REPEAT_END:5, REPEAT_BOTH:6, NONE:7
stave2.addClef("treble").setContext(ctx);
stave2.addTimeSignature('4/4').setContext(ctx);


const notes1 = [
const notes1 = [
310行目: 326行目:
];
];


stave1.draw();
Formatter.FormatAndDraw(ctx, stave1, notes1);


const tie1 = new StaveTie({
const tie1 = new StaveTie({
326行目: 342行目:
});
});


Formatter.FormatAndDraw(ctx, stave1, notes1);
tie1.setContext(ctx).draw();
tie1.setContext(ctx).draw();
tie2.setContext(ctx).draw();
tie2.setContext(ctx).draw();


const stave2 = new Stave(stave1.width + stave1.x, stave1.y, nStaveWidth).setContext(ctx);
stave2.setEndBarType(VF.Barline.type.REPEAT_BOTH);
stave2.draw();
stave2.draw();


const notes2 = [
 
const stave3 = new Stave(stave2.width + stave2.x, stave1.y, nStaveWidth).setContext(ctx);
stave3.setEndBarType(VF.Barline.type.NONE);
stave3.draw();
 
 
const stave4 = new Stave(stave3.width + stave3.x, stave1.y, nStaveWidth).setContext(ctx);
stave4.setBegBarType(VF.Barline.type.NONE);
stave4.setEndBarType(VF.Barline.type.REPEAT_END);
stave4.draw();
 
 
const stave5 = new Stave(stave1.x, stave1.y + 100, nHeadMargin + nStaveWidth).setContext(ctx);
stave5.addClef("treble").setContext(ctx);
stave5.addTimeSignature('4/4').setContext(ctx);
stave5.setEndBarType(VF.Barline.type.SINGLE);//規定値(省略可能)
 
stave5.draw();
 
const notes5 = [
   new StaveNote({ keys: ["a/4"], duration: "q" }),
   new StaveNote({ keys: ["a/4"], duration: "q" }),
   new StaveNote({ keys: ["b/4"], duration: "q" }),
   new StaveNote({ keys: ["b/4"], duration: "q" }),
339行目: 376行目:
];
];


Formatter.FormatAndDraw(ctx, stave2, notes2);
Formatter.FormatAndDraw(ctx, stave5, notes5);


const tie3 = new StaveTie({
const tie3 = new StaveTie({
   first_note: notes2[1],
   first_note: notes5[1],
   last_note: notes2[2],
   last_note: notes5[2],
   first_indices: [0],
   first_indices: [0],
   last_indices: [0],
   last_indices: [0],
349行目: 386行目:


const tie4 = new StaveTie({
const tie4 = new StaveTie({
   first_note: notes2[2],
   first_note: notes5[2],
   last_note: notes2[3],
   last_note: notes5[3],
   first_indices: [0],
   first_indices: [0],
   last_indices: [0],
   last_indices: [0],
358行目: 395行目:
tie4.setContext(ctx).draw();
tie4.setContext(ctx).draw();


const stave3 = new Stave(stave2.width + stave2.x, stave2.y, 350).setContext(ctx);
const stave6 = new Stave(stave5.width + stave5.x, stave5.y, nStaveWidth).setContext(ctx);
const notes3 = [
stave6.setEndBarType(VF.Barline.type.DOUBLE);
 
stave6.draw();
 
const notes6 = [
   new StaveNote({ keys: ["e/5"], duration: "q" }),
   new StaveNote({ keys: ["e/5"], duration: "q" }),
   new StaveNote({ keys: ["f/5"], duration: "q" }),
   new StaveNote({ keys: ["f/5"], duration: "q" }),
366行目: 407行目:
];
];


stave3.draw();
Formatter.FormatAndDraw(ctx, stave6, notes6);
 
Formatter.FormatAndDraw(ctx, stave3, notes3);


const tie5 = new StaveTie({
const tie5 = new StaveTie({
   first_note: notes2[3],
   first_note: notes5[3],
   last_note: notes3[0],
   last_note: notes6[0],
   first_indices: [0],
   first_indices: [0],
   last_indices: [0],
   last_indices: [0],
379行目: 418行目:
tie5.setContext(ctx).draw();
tie5.setContext(ctx).draw();


// 灰色の背景
 
ctx.setFillStyle('#F5F5F5'); // 灰色に設定
const stave7 = new Stave(stave6.width + stave6.x, stave5.y, nStaveWidth).setContext(ctx);
stave7.draw();
 
 
const stave8 = new Stave(stave7.width + stave7.x, stave5.y, nStaveWidth).setContext(ctx);
stave8.setEndBarType(VF.Barline.type.END);
stave8.draw();
 
ctx.setFillStyle('#F5F5F5');
ctx.fillRect(0, 0, f.width, f.height);
ctx.fillRect(0, 0, f.width, f.height);


389行目: 436行目:
const svgNS = 'http://www.w3.org/2000/svg';
const svgNS = 'http://www.w3.org/2000/svg';
const lineColor = '#EEEEEE';
const lineColor = '#EEEEEE';
 
</script>
</script>
</syntaxhighlight>
</syntaxhighlight>




 スラーでもStaveTie というオブジェクトを利用します。
 VFというオブジェクトをvar VF = Vex.Flowと定義しておくと、Barlineのようなオブジェクト定数を保持しているものにアクセスできるようになります。VF.Barlineのように使います。VexFlow公式のExamplesでもそのように設定されていました。いきなりBarline.type.ENDのように使おうとしても未定義になるようです。冷たいな。
 
 
 配列で [new StaveTie({オブジェクト}), …] という構造のものを用意し、配列を代入した変数を作ります。
 
 
 const Ties1 = [new StaveTie({オブジェクト}), new StaveTie({オブジェクト})]; のような形式です。オブジェクトには以下のようなキーと値を設定します。




*first_note: タイの始まりの音符を設定します。例:notes1[2]
 あと、規定値でStaveつまり小節をつくると線が引かれるので、線をなくすときは、終了位置からも開始位置からもNONEを設定しないとどちらかが規定値で描画されたときに線がひかれてしまいますので、気を付けたいですね。SINGLEが規定値です。
*last_note: タイの終わりの音符を設定します。例:notes1[3]
*first_indices: タイの始まりの音符の和音の番号を設定します。和音になっていない場合は配列番号 0 を指定します。例:[0]
*last_indices: タイの終わりの音符の和音の番号を設定します。和音になっていない場合は配列番号 0 を指定します。例:[0]


 
 


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

2024年3月11日 (月) 00:46時点における最新版

VexFlow 使い方に戻る。

概要

 小節区切りの設定をする手順を示します。約1年近く絶賛挫折中でしたが、久しぶりに更新しました。2024年3月中旬時点。このサイトのこの記事がかなり世の中的に期待されているようです。続編を書かないといけないなと思った次第です。次の記事も頑張っていこう!


コード 表示内容
Barline.type.SINGLE 一本線
Barline.type.DOUBLE 二本線
Barline.type.END 二本線で右側が太線
Barline.type.REPEAT_BEGIN リピート開始記号
Barline.type.REPEAT_END リピート終了記号
Barline.type.REPEAT_BOTH リピート両側記号
Barline.type.NONE 線無し

 

小節開始終了線

 コードは以下のとおりです。

<div id="yonet202403Mid_Output01"></div>
<script>
var VF = Vex.Flow;
(function(){
const {
  Factory,
  Stave,
  StaveNote,
  Formatter,
  Voice,
  StaveTie,
  BarLine,
  Renderer
} = Vex.Flow;

let nscale = 0.68
let nwidth = 1040;
let nheight = 320;

let nHeadMargin = 70;
let nStaveWidth = 350;

const f = new Factory({ 
  renderer: { elementId: 'yonet202403Mid_Output01', width: nwidth, height: nheight * nscale }
  });
const ctx = f.getContext();
ctx.scale(nscale, nscale);

const defaultStyle = {
  lineWidth: ctx.lineWidth,
  strokeStyle: ctx.strokeStyle,
};

for (let i = 0; i <= nwidth * (1 / nscale); i += 10) {
  ctx.beginPath();
  ctx.moveTo(0 + i, 0);
  ctx.lineTo(0 + i, nheight);
  if (i % 100 === 0){
    ctx.setLineWidth(1);
    ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
  }
  else{
    ctx.setLineWidth(0.5);
    ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
  }
  ctx.stroke();
}

for (let i = 0; i <= nheight; i += 10) {
  ctx.beginPath();
  ctx.moveTo(0, i);
  ctx.lineTo(nwidth * (1 / nscale), i);
  if (i % 100 === 0){
    ctx.setLineWidth(1);
    ctx.setStrokeStyle('rgba(200, 200, 200, 0.8)');
  }
  else{
    ctx.setLineWidth(0.5);
    ctx.setStrokeStyle('rgba(230, 230, 230, 0.8)');
  }
  ctx.stroke();
}

ctx.lineWidth = defaultStyle.lineWidth;
ctx.strokeStyle = defaultStyle.strokeStyle;

const stave1 = new Stave(10, 50, nHeadMargin + nStaveWidth).setContext(ctx);
stave1.setClef("treble").setContext(ctx);
stave1.setTimeSignature('4/4').setContext(ctx);
//stave1.setBegBarType(4);//BarLine.type.REPEAT_BEGIN
stave1.setBegBarType(VF.Barline.type.REPEAT_BEGIN);//BarLine.type.REPEAT_BEGIN
stave1.draw();

//SINGLE:1, DOUBLE:2, END:3, REPEAT_BEGIN:4, REPEAT_END:5, REPEAT_BOTH:6, NONE:7

const notes1 = [
  new StaveNote({ keys: ["d/5"], duration: "q" }),
  new StaveNote({ keys: ["e/5"], duration: "q" }),
  new StaveNote({ keys: ["f/5"], duration: "q" }),
  new StaveNote({ keys: ["g/5"], duration: "q" }),
];

Formatter.FormatAndDraw(ctx, stave1, notes1);

const tie1 = new StaveTie({
  first_note: notes1[1],
  last_note: notes1[2],
  first_indices: [0],
  last_indices: [0],
});

const tie2 = new StaveTie({
  first_note: notes1[2],
  last_note: notes1[3],
  first_indices: [0],
  last_indices: [0],
});

tie1.setContext(ctx).draw();
tie2.setContext(ctx).draw();


const stave2 = new Stave(stave1.width + stave1.x, stave1.y, nStaveWidth).setContext(ctx);
stave2.setEndBarType(VF.Barline.type.REPEAT_BOTH);
stave2.draw();


const stave3 = new Stave(stave2.width + stave2.x, stave1.y, nStaveWidth).setContext(ctx);
stave3.setEndBarType(VF.Barline.type.NONE);
stave3.draw();


const stave4 = new Stave(stave3.width + stave3.x, stave1.y, nStaveWidth).setContext(ctx);
stave4.setBegBarType(VF.Barline.type.NONE);
stave4.setEndBarType(VF.Barline.type.REPEAT_END);
stave4.draw();


const stave5 = new Stave(stave1.x, stave1.y + 100, nHeadMargin + nStaveWidth).setContext(ctx);
stave5.addClef("treble").setContext(ctx);
stave5.addTimeSignature('4/4').setContext(ctx);
stave5.setEndBarType(VF.Barline.type.SINGLE);//規定値(省略可能)

stave5.draw();

const notes5 = [
  new StaveNote({ keys: ["a/4"], duration: "q" }),
  new StaveNote({ keys: ["b/4"], duration: "q" }),
  new StaveNote({ keys: ["c/5"], duration: "q" }),
  new StaveNote({ keys: ["d/5"], duration: "q" }),
];

Formatter.FormatAndDraw(ctx, stave5, notes5);

const tie3 = new StaveTie({
  first_note: notes5[1],
  last_note: notes5[2],
  first_indices: [0],
  last_indices: [0],
});

const tie4 = new StaveTie({
  first_note: notes5[2],
  last_note: notes5[3],
  first_indices: [0],
  last_indices: [0],
});

tie3.setContext(ctx).draw();
tie4.setContext(ctx).draw();

const stave6 = new Stave(stave5.width + stave5.x, stave5.y, nStaveWidth).setContext(ctx);
stave6.setEndBarType(VF.Barline.type.DOUBLE);

stave6.draw();

const notes6 = [
  new StaveNote({ keys: ["e/5"], duration: "q" }),
  new StaveNote({ keys: ["f/5"], duration: "q" }),
  new StaveNote({ keys: ["g/5"], duration: "q" }),
  new StaveNote({ keys: ["a/5"], duration: "q" }),
];

Formatter.FormatAndDraw(ctx, stave6, notes6);

const tie5 = new StaveTie({
  first_note: notes5[3],
  last_note: notes6[0],
  first_indices: [0],
  last_indices: [0],
});

tie5.setContext(ctx).draw();


const stave7 = new Stave(stave6.width + stave6.x, stave5.y, nStaveWidth).setContext(ctx);
stave7.draw();


const stave8 = new Stave(stave7.width + stave7.x, stave5.y, nStaveWidth).setContext(ctx);
stave8.setEndBarType(VF.Barline.type.END);
stave8.draw();

ctx.setFillStyle('#F5F5F5');
ctx.fillRect(0, 0, f.width, f.height);

})();

const svgElement = document.querySelector('#Output svg');
svgElement.style.backgroundColor = '#F5F5F5';
const svgNS = 'http://www.w3.org/2000/svg';
const lineColor = '#EEEEEE';
</script>


 VFというオブジェクトをvar VF = Vex.Flowと定義しておくと、Barlineのようなオブジェクト定数を保持しているものにアクセスできるようになります。VF.Barlineのように使います。VexFlow公式のExamplesでもそのように設定されていました。いきなりBarline.type.ENDのように使おうとしても未定義になるようです。冷たいな。


 あと、規定値でStaveつまり小節をつくると線が引かれるので、線をなくすときは、終了位置からも開始位置からもNONEを設定しないとどちらかが規定値で描画されたときに線がひかれてしまいますので、気を付けたいですね。SINGLEが規定値です。

 

VexFlow 使い方に戻る。