Longer durations then "w"?

69 views
Skip to first unread message

Robert Wildling

unread,
Apr 2, 2020, 5:35:54 AM4/2/20
to vexflow
In my little app I display various scales underneath each other and of various length. The notes of those scales are displayed as whole notes (w), and the stave adds up to 48 (giving space all 12 notes of the chromatic scale) by adding whole-note rests. (I should mention that I do not need a time signatue.)

Now I would like to display the scale's name above the scale, for which I use TextNote. The scale name is displayed at the first tick (s that the way to say it?) and has a duration of a whole note, too. Again, adding empty texts, each with a duration of a whole note, fills the gaps up to 48.

But the text takes too much place and interrupts the flow of the scale notes as can be seen in the screen shot.

Is there a way to use larger duration values then "w"?


scale-names-need-more-space.png
Message has been deleted

Robert Wildling

unread,
Apr 2, 2020, 6:11:58 AM4/2/20
to vexflow
For testing purposes I changed the note duration to quarter notes, except for the first textNote, which still has a value of a whole note. This is the code for the TextNotes:

let textVoiceTickables = []


// Add the scale name as text via an extra voice
let scaleNameText = new Vex.Flow.TextNote({
text: scaleName, // "scaleName" retrieved from tonal.js, saved in Vuex 
font: {[...]},
duration: 'w' // WHOLE NOTE
})
  .setLine(2)
  .setStave(currStaff)
  .setJustification(Vex.Flow.TextNote.Justification.LEFT)


textVoiceTickables.push(scaleNameText)


// Add empty text notes for the remaining duration (up to 48 quater notes)
for (let i = 0; i < 44; i++) {
  const ghost = new Vex.Flow.TextNote({ text: '', duration: 'q' }) // QUATER NOTES
  ghost.setLine(2)
  ghost.setStave(currStaff)
  ghost.setJustification(Vex.Flow.TextNote.Justification.LEFT)


  textVoiceTickables.push(ghost)
}


const voiceForScaleNameText = new Vex.Flow.Voice({ num_beats: 48, beat_value: 4, resolution: Vex.Flow.RESOLUTION })
voiceForScaleNameText.addTickables(textVoiceTickables)
voiceForScaleNameText.setStave(currStaff)


The result can be seen in the screenshot.

I was expecting that the first TextNote, which has a value of a whole note, would span over the first four quarter notes, but it does not.

What am I doing wrong here? Or do I misunderstand the inner workings of TextNote spacing?
vexflow-wrong-textnote-spacing.png

Robert Wildling

unread,
Apr 2, 2020, 6:16:34 AM4/2/20
to vexflow

After more testing I can answer this to myself. The secret lies in how to handle the formatter.



        // Formatter
        const formatter = new Vex.Flow.Formatter()
        formatter.joinVoices([voice, voiceForScaleNameText])
        formatter.format([voice], 48 * noteWidth)
        formatter.format([voiceForScaleNameText], 48 * noteWidth)


While `joinVoices` can be ussed on "voice" (the voice for the scales) and "voiceForScaleNameText" at the same time, `format` should be run separately on each voice. Then the spacing works fine.



Reply all
Reply to author
Forward
0 new messages