我正在创建一个具有多个关键点的stave音符:
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 });更新:根据一个建议,我可以创建一些方法来对音符进行排序,然后再将它们作为键添加到stave中:
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警告消息。
发布于 2020-03-25 05:05:23
Vexflow希望你的笔记是垂直排序的,这是没有办法的。您需要编写自己的函数来比较以字符串形式给出的两个注释。
下面是一个不考虑意外情况的工作注释-字符串-比较-函数:repl.it/repls/WobblyFavorableYottabyte
为清晰起见进行了编辑,感谢@gristow的更正!
https://stackoverflow.com/questions/60801367
复制相似问题