paulrosen / abcjs

javascript for rendering abc music notation
Other
1.94k stars 285 forks source link

New system for first line-only tablature drawing #976

Closed seisiuneer closed 11 months ago

seisiuneer commented 11 months ago

This solution allows the user to set a flag in their tab descriptions to only show tab labels on the first staff of each voice, for example:

params = { tablature: [{ instrument: 'violin', label: theLabel, tuning: ['G,', 'D', 'A', 'e'], highestNote: "f'", capo: gCapo, firstStaffOnly:true // <---- New tablature parameter }], responsive: 'resize', oneSvgPerLine: 'true', expandToWidest: 'true', selectTypes: false, format: commonFontFormat }

I'm working at the layoutTablatures level in this solution since it's where you have the top level view of the voices and the staves being rendered and can isolate the first stave for all the voices, then modify or inject properties into the tablature descriptions that are ultimately used at the lowest rendering level to either draw or suppress the tab labels, while still keeping proper spacing.

paulrosen commented 11 months ago

In general this looks good for the regression tests where firstStaffOnly is not present. The spacing is generally better.

However, this test crashes: http://localhost:5500/tests/all.html?grep=Tablature%20skip%20staff

TypeError: Cannot read properties of null (reading 'params')
    at Object.layoutTablatures (http://localhost:5501/src/api/abc_tablatures.js:118:22)
paulrosen commented 11 months ago

I tried this string:

    var firstStaffOnly = "X:1\n" +
        "%%stretchlast\n" +
        "L:1/4\n" +
        "K:C\n" +
        "|:\"Gbmaj7\"DEGB:|\n" +
        "|:\"Gbmaj7\"DEGB:|\n" +
        "|:\"Gbmaj7\"DEGB:|\n" +
        "|:\"Gbmaj7\"DEGB:|\n" +
        "|:\"Gbmaj7\"DEGB:|\n"

With both firstStaffOnly and not. It definitely worked, but it didn't make the staffs tighten up. That is, with and without is the same height. Wasn't the intent to get rid of vertical space?