1

使用Tone.js并且我可以演奏这个旋律:

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在一些五线谱上渲染这些音符。

请记住,移动设备上的显示应该没问题,并且配乐上可能有多个声音。

现在我创建了一个方法来让每个小节都有一个五线谱:

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

但是音符在五线谱上显示了一点,但有些音符显示在五线谱之间,在页面上。

之间

4

1 回答 1

0

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

问题是所有音符的词干都朝上。要解决此问题,请将auto_stem: true和添加clef: "treble"到传递给的选项列表中VF.StaveNote(),请参阅VexFlow:Stem Direction了解更多信息。这是创建注释的更正行:

notes.push(new this.VF.StaveNote({
      keys: [ this.renderAbc(note) ],
      duration: this.renderDuration(note),
      auto_stem: true,
      clef: "treble"
}));
于 2019-11-22T00:37:02.867 回答