首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在VexFlow中渲染配乐?

如何在VexFlow中渲染配乐?
EN

Stack Overflow用户
提问于 2019-06-16 05:45:24
回答 1查看 282关注 0票数 1

使用Tone.js和我可以播放这首旋律:

代码语言:javascript
复制
const textMeasures = ['rest/4 B4/16 A4/16 G#4/16 A4/16',
'C5/8 rest/8 D5/16 C5/16 B4/16 C5/16',
'E5/8 rest/8 F5/16 E5/16 D#5/16 E5/16',
'B5/16 A5/16 G#5/16 A5/16 B5/16 A5/16 G#5/16 A5/16',
'C6/4 A5/8 C6/8',
'B5/8 A5/8 G5/8 A5/8',
'B5/8 A5/8 G5/8 A5/8',
'B5/8 A5/8 G5/8 F#5/8',
'E5/4'];

现在,我想使用VexFlow在一些staves上呈现这些音符。

请记住,在移动设备上显示应该是正常的,并且配乐上可能有多个声音。

现在,我创建了一个方法来为每个度量设置一个stave:

代码语言:javascript
复制
private renderSoundtrackVexflow(name: string, soundtrack: Soundtrack) {
  const context = this.renderVexflowContext(name, VEXFLOW_WIDTH, VEXFLOW_HEIGHT);
  context.setFont('Arial', 10, '').setBackgroundFillStyle('#eed'); // TODO Hard coded values

  if (soundtrack.hasTracks()) {
    let staveIndex: number = 0;
    const voices: Array<vexflow.Flow.Voice> = new Array<vexflow.Flow.Voice>();
    for (const track of soundtrack.tracks) {
      if (track.hasMeasures()) {
        for (const measure of track.measures) {
          if (measure.hasNotes()) {
            const stave = new this.VF.Stave(0, staveIndex * (VEXFLOW_STAVE_HEIGHT + VEXFLOW_STAVE_MARGIN), VEXFLOW_WIDTH);
            staveIndex++;
            stave.setContext(context);
            stave.addClef(VEXFLOW_CLEF);
            stave.addTimeSignature(this.renderTimeSignature(measure));
            stave.draw();

            const notes = new Array<vexflow.Flow.StaveNote>();
            const voice = new this.VF.Voice();
            voice.setStrict(false);
            voice.setContext(context);
            voice.setStave(stave);
            for (const placedNote of measure.placedNotes) {
              const note: Note = placedNote.note;
              notes.push(new this.VF.StaveNote({ keys: [ this.renderAbc(note) ], duration: this.renderDuration(note) }));
            }
            voice.addTickables(notes);
            voices.push(voice);
          }
        }
        const formatter = new this.VF.Formatter();
        formatter.joinVoices(voices).format(voices, VEXFLOW_WIDTH);
        for (const voice of voices) {
          voice.draw();
          console.log('Min voice width: ' + formatter.getMinTotalWidth(voice));
        }
      }
    }
  }
}

但音符显示在横杆上,但一些音符显示在横杆之间,在页面上。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-22 08:37:03

这个问题有点老了,但是如果你仍然需要一个解决方案的话...

问题是所有音符的词干都是向上的。要解决此问题,请将auto_stem: trueclef: "treble"添加到传递给VF.StaveNote()的选项列表中,有关详细信息,请参阅VexFlow: Stem Direction。以下是创建注释的更正行:

代码语言:javascript
复制
notes.push(new this.VF.StaveNote({
      keys: [ this.renderAbc(note) ],
      duration: this.renderDuration(note),
      auto_stem: true,
      clef: "treble"
}));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56614387

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档