注释中未排序的键将被排序

Unsorted keys in note will be sorted

我正在用多个键创建五线谱音符:

const staveNote: vexflow.Flow.StaveNote = new this.VF.StaveNote({
  keys: this.renderNotesSortedByPitch(placedChord.notes),
  duration: chordDuration,
  auto_stem: true,
  clef: Clef.TREBLE
});

private renderNotesSortedByPitch(notes: Array<Note>): Array<string> {
  const vexflowNotes: Array<string> = new Array<string>();
  notes
  // this.sortNotesByPitch(notes)
  .forEach((note: Note) => {
    vexflowNotes.push(this.renderNote(note));
  });
  return vexflowNotes;
}

private sortNotesByPitch(notes: Array<Note>): Array<Note> {
  return notes.sort((noteA: Note, noteB: Note) => {
    return noteA.pitch.chroma.value - noteB.pitch.chroma.value   <--- No arithmetic operation on strings
  });
}

我在浏览器控制台中收到以下警告:

Warning:  Unsorted keys in note will be sorted. See https://github.com/0xfe/vexflow/issues/104 for details. Error
    at Function.b.StackTrace (http://localhost:4200/vendor.js:93990:4976)
    at Function.b.W (http://localhost:4200/vendor.js:93990:5134)
    at http://localhost:4200/vendor.js:93990:255605
    at Array.forEach (<anonymous>)
    at e.value (http://localhost:4200/vendor.js:93990:255572)
    at new e (http://localhost:4200/vendor.js:93990:250357)
    at SheetService.vexflowRenderSoundtrack (http://localhost:4200/main.js:2083:51)
    at SheetService.createSoundtrackSheet (http://localhost:4200/main.js:2004:14)
    at SheetComponent.createSheet (http://localhost:4200/main.js:2465:35)
    at SheetComponent.ngAfterViewInit (http://localhost:4200/main.js:2452:14)

我知道我需要提供已经按照 Vexflow sorting 排序的键。

也描述了类似的问题 there

如何对 note.pitch.chroma.value 为字符串的键进行排序?

最好能有一些与以下方法相同的方法:

staveNote.setKeyStyle(0, { fillStyle: 'red' });

比如说,一些这样的方法:

staveNote.setDotted(0);

或:

staveNote.setKeyStyle(0, { fillStyle: 'red', dotted: true });

更新:根据建议,我可以创建在将音符作为键添加到五线谱之前对音符进行排序的方法:

  private getNoteFrequency(note: Note): number {
    return Tone.Frequency(note.renderAbc()).toFrequency();
  }

  private sortNotesByPitch(notes: Array<Note>): Array<Note> {
    return notes.sort((noteA: Note, noteB: Note) => {
      return this.getNoteFrequency(noteA) - this.getNoteFrequency(noteB);
    });
  }

浏览器控制台中不再显示 Vexflow 警告消息。

Vexflow 希望您的笔记垂直排序,没有办法解决这个问题。 您需要编写自己的函数来比较以字符串形式给出的两个音符。

这是一个有效的音符字符串比较功能,它不考虑意外情况:repl.it/repls/WobblyFavorableYottabyte

为清楚起见进行了编辑,感谢@gristow 的更正!