VexFlow 強弱表示

提供:yonewiki
2024年3月14日 (木) 19:45時点におけるYo-net (トーク | 投稿記録)による版 (ページの作成:「<yjavascript></script> <script src="https://cdn.jsdelivr.net/npm/vexflow@4.2.3/build/cjs/vexflow.js"></script> <script> </yjavascript> VexFlow 使い方に戻る。 == '''概要''' ==  いろいろ重ねていくと横方向の表示があまりよくないのに、縦にしか位置調整できないという。いたい。横幅0のゴースト小節をつくって横方向を調節した方がいいのかもしれない。VexFlowやっぱかゆいところ…」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)

VexFlow 使い方に戻る。

概要

 いろいろ重ねていくと横方向の表示があまりよくないのに、縦にしか位置調整できないという。いたい。横幅0のゴースト小節をつくって横方向を調節した方がいいのかもしれない。VexFlowやっぱかゆいところに手が届かないよね。staveクラスのオブジェクトのメンバ関数にsetTempoというのがあるので、そこの第一引数でテンポの基準となる音符とbpm値(1分当たりの基準の音符の数)を指定して、第二引数にはY方向のオフセット座標を入力します。


 第一引数は { duration: "q", dots: 1, bpm: 80 } のように設定します。基準の音符をdurationキーにdotを何個つけるか(付点音符)をdotsキーに設定する感じですね。あまり使わないでしょうね。基本は0だと思います。bpmキーにはbpm値です。


音の長さ

コード 表示内容
1 or w 全音符
2 or h 2分音符
4 or q 4分音符
8 8分音符
16 16分音符
32 32分音符


 ほかにも、速さ記号を表示するだけのものがあります。{ name: "Andante", note: "8", bpm: 120 } のようにnameキーが設定されていると文字表示になるようです。


速度標語 意味
Lento(レント) 非常に遅い、落ち着いた速度40~60 BPM
Largo(ラルゴ) 非常にゆっくり、広々とした速度45~50 BPM
Adagio(アダージョ) ゆっくりと、穏やかに55~65 BPM
Andante(アンダンテ) 歩く速さ、落ち着いた速度で76~108 BPM
Moderato(モデラート) 中程度の速さで、適度に108~120 BPM
Allegro(アレグロ) 速く、楽しく、心地よいテンポで120~168 BPM
Vivace(ヴィヴァーチェ) 生き生きと、かなり速いテンポで168~176 BPM
Presto(プレスト) 非常に速く、急速に168~208 BPM
Accelerando(アチェレランド) 徐々に速く
Stringendo(ストリンジェンド) 徐々に急迫して
Ritardando(リタルダンド) 次第に遅く
Rallentando(ラレンタンド) 次第に遅く
Ritenuto(リテヌート) 直ちに遅く
A tempo(ア・テンポ) 元の速度で
ad libitum(ad lib.)(アド・リビタム) 「思うままに」や「自由に」
rubato(ルバート) 「盗む」という意味。テンポを一時的に緩めたり速めたり自由に
fermata(フェルマータ) 通常よりも長く、一定の音または休止を持続させる
a piacere(ア・ピアチェーレ) 気に入ったように
tempo giusto(テンポ・ジュスト) 正確な速さで
grazioso(グラツィオーソ) 優美に

 

強弱表示


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


<div id="yonet202403Mid_Output01"></div>
<script>
class Position {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}
var VF = Vex.Flow;
const Instrument1 = new Position(0, 0);
const Instrument2 = new Position(0, 0);
(function(){
const {
  Factory,
  Stave,
  StaveNote,
  Formatter,
  Voice,
  StaveTie,
  BarLine,
  StaveConnector,
  Modifier,
  RenderContext,
  Renderer
} = Vex.Flow;

let nscale = 0.64;
let nwidth = 1040;
let nheight = 720;

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(80, 150, nHeadMargin + nStaveWidth).setContext(ctx);
stave1.setClef("treble").setContext(ctx);
stave1.setTimeSignature('4/4').setContext(ctx);
stave1.setSection("A", 0);
stave1.setMeasure(1);
stave1.setTempo({ duration: "q", dots: 0, bpm: 120 }, 0);
stave1.setBegBarType(VF.Barline.type.REPEAT_BEGIN);//BarLine.type.REPEAT_BEGIN

Instrument1.x = stave1.x - 30;
Instrument1.y = stave1.y + 90; 

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();


var stave2 = new Vex.Flow.Stave(stave1.width + stave1.x, stave1.y, nStaveWidth);
stave2.setEndBarType(VF.Barline.type.REPEAT_BOTH);
stave2.setMeasure(2);
stave2.setTempo({ name: "Andante", note: "8", bpm: 120 }, 0);
stave2.setContext(ctx).draw();

var note2_1 = new Vex.Flow.StaveNote({ keys: ["C/4"], duration: "q" });
var note2_2 = new Vex.Flow.StaveNote({ keys: ["D/4"], duration: "q" });
var note2_3 = new Vex.Flow.StaveNote({ keys: ["E/4"], duration: "q" });
var note2_4 = new Vex.Flow.StaveNote({ keys: ["F/4"], duration: "q" });
var stave2Voice = new Vex.Flow.Voice({ num_beats: 4, beat_value: 4 });
stave2Voice.addTickables([note2_1, note2_2, note2_3, note2_4]);
//stave2Voice.setStave(stave2);

var formatter2 = new Vex.Flow.Formatter().joinVoices([stave2Voice]);//.format([stave2Voice], nStaveWidth);
formatter2.formatToStave([stave2Voice], stave2);

stave2Voice.draw(ctx, stave2);

var note2_1_X = note2_1.getAbsoluteX();
var staveFrom1To4_Y = note2_1.getStave().getYForLine(2.5);

const stave3 = new Stave(stave2.width + stave2.x, stave1.y, nStaveWidth).setContext(ctx);
stave3.setEndBarType(VF.Barline.type.NONE);
stave3.setSection("B", 0);
stave3.setMeasure(3);
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.setMeasure(4);
stave4.draw();


const stave5 = new Stave(stave1.x, stave1.y + 200, nHeadMargin + nStaveWidth).setContext(ctx);
stave5.addClef("treble").setContext(ctx);
stave5.addTimeSignature('4/4').setContext(ctx);
stave5.setSection("C", 0);
stave5.setMeasure(5);
stave5.setEndBarType(VF.Barline.type.SINGLE);

stave5.draw();

var connector = new VF.StaveConnector(stave1, stave5);
connector.setType(VF.StaveConnector.type.SINGLE);
connector.setContext(ctx);
connector.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.setMeasure(6);

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.setMeasure(7);
stave7.draw();


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


const stave9 = new Stave(stave5.x, stave5.y + 200, nHeadMargin + nStaveWidth).setContext(ctx);
stave9.setMeasure(9);
stave9.draw();

var connector9 = new VF.StaveConnector(stave5, stave9);
connector9.setType(VF.StaveConnector.type.SINGLE);
connector9.setContext(ctx);
connector9.draw();

var connector9_2 = new VF.StaveConnector(stave5, stave9);
connector9_2.setType(VF.StaveConnector.type.BRACKET);
connector9_2.setContext(ctx);
//connector9_2.setText('E.Guitar');
connector9_2.draw();

Instrument2.x = stave1.x - 30;
Instrument2.y = stave5.y + ((stave9.y - stave5.y) / 2) + 90; 


const stave10 = new Stave(stave9.width + stave9.x, stave9.y, nStaveWidth).setContext(ctx);
stave10.setMeasure(10);
stave10.draw();


const stave11 = new Stave(stave10.width + stave10.x, stave9.y, nStaveWidth).setContext(ctx);
stave11.setMeasure(11);
stave11.draw();


const stave12 = new Stave(stave11.width + stave11.x, stave9.y, nStaveWidth).setContext(ctx);
stave12.setMeasure(12);
stave12.draw();

})();

const svgElement2 = document.querySelector('#yonet202403Mid_Output01 svg');
svgElement2.style.backgroundColor = '#F5F5F5';

var svgContainer = document.getElementById('yonet202403Mid_Output01');

var svgElement = svgContainer.querySelector('svg');

var newText = document.createElementNS('http://www.w3.org/2000/svg', 'text');
newText.setAttribute('x', '100');
newText.setAttribute('y', '100');
newText.setAttribute('font-family', 'Hiragino Kaku Gothic Pro, メイリオ, MS Gothic, sans-serif');
newText.setAttribute('font-size', '50');
newText.setAttribute('fill', 'black');
newText.textContent = 'TestTitle - subTitle - lyrics: yo-net, music: yo-net';
svgElement.appendChild(newText);


var newText2 = document.createElementNS('http://www.w3.org/2000/svg', 'text');
newText2.setAttribute('x', Instrument1.x);
newText2.setAttribute('y', Instrument1.y);
newText2.setAttribute('font-family', 'Bravura, VexFlow, Arial, sans-serif');
newText2.setAttribute('font-size', '20pt');
newText2.setAttribute('fill', 'black');
newText2.textContent = 'Vocal';

var textGroup2 = document.createElementNS('http://www.w3.org/2000/svg', 'g');
textGroup2.setAttribute('transform', 'rotate(-90 ' + Instrument1.x + ' ' + Instrument1.y + ')');

textGroup2.appendChild(newText2);

svgElement.appendChild(textGroup2);

var newText3 = document.createElementNS('http://www.w3.org/2000/svg', 'text');
newText3.setAttribute('x', Instrument2.x);
newText3.setAttribute('y', Instrument2.y);
newText3.setAttribute('font-family', 'Bravura, VexFlow, Arial, sans-serif');
newText3.setAttribute('font-size', '20pt');
newText3.setAttribute('fill', 'black');
newText3.textContent = 'E.Guitar';

var textGroup3 = document.createElementNS('http://www.w3.org/2000/svg', 'g');
textGroup3.setAttribute('transform', 'rotate(-90 ' + Instrument2.x + ' ' + Instrument2.y + ')');

textGroup3.appendChild(newText3);

svgElement.appendChild(textGroup3);
</script>

 とくに最後にいうこともありません。長くなってきたので、そろそろ、前の項目でやった技術に対する重ね書きをやめて、整理しなあかんかな。でも重ねることによってわかることもあるし。まぁね。おいおい。

 

VexFlow 使い方に戻る。