Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix notation-vs-tab bar misalignment #122

Merged
merged 6 commits into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/artist.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ class Artist
if last_note instanceof Vex.Flow.BarNote
notes.pop()
stave.setEndBarType(last_note.getType())
stave.formatted = true

for stave in @staves
L "Rendering staves."
Expand Down
55 changes: 54 additions & 1 deletion tests/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,49 @@ class VexTabTests
tab.getArtist().render(renderer)
assert.ok(true, "all pass")

makeCanvas = (vex, test_id, flex)->
c = $('<div></div>').css('flex', flex).css('font-size', '0.8em')
p = $('<p></p>').css('margin-top', '0px')
p.append($('<pre></pre>').text(vex).css('font-family', 'courier'))
c.append(p)
canvas = $('<div></div>').addClass("vex-tabdiv").attr('id', test_id).css('flex', flex)
c.append(canvas)
return c

renderCodeInCanvasId = (code, canvasid) ->
tab = new VexTab(new Artist(0, 0, 500, {scale: 0.8}))
tab.parse(code)
canvas = $('#' + canvasid)
renderer = new Vex.Flow.Renderer(canvas[0], Vex.Flow.Renderer.Backends.SVG)
renderer.getContext().setBackgroundFillStyle("#eed")
tab.getArtist().render(renderer)

# Render content to a new div, and return the content.
# Remove some things that change but aren't relevant (IDs)
getRenderedContent = (container, code, cssflex) ->
idcounter += 1
canvasid = 'rendered-' + idcounter
container.append(makeCanvas(code, canvasid, cssflex))
renderCodeInCanvasId(code, canvasid)
content = $('#' + canvasid).
html().
replace(/id=\".*?\"/g, 'id="xxx"')
return content

# ID counter for the equivalence tests
idcounter = 0

# Ensure that the rendered content of vex1 and vex2 are equivalent.
assertEquivalent = (assert, title, vex1, vex2) ->
test_div = $('<div></div>').addClass("testcanvas")
test_div.append($('<div></div>').addClass("name").text(title))
container = $('<div></div>').css('display', 'flex')
test_div.append(container)
$("body").append(test_div)
oldhtml = getRenderedContent(container, vex1, '0 0 30%')
newhtml = getRenderedContent(container, vex2, '1')
assert.equal(oldhtml, newhtml, title)

@basic: (assert) ->
assert.expect 3
tab = makeParser()
Expand Down Expand Up @@ -219,14 +262,23 @@ class VexTabTests
assert.ok true, "all pass"

@bar: (assert) ->
assert.expect 5
assert.expect 7
tab = makeParser()

assert.notEqual null, tab.parse("tabstave\n notes |10s11/3")
assert.notEqual null, tab.parse("tabstave\n notes 10s11h12p10/3|")
assert.notEqual null, tab.parse("tabstave notation=true key=A\n notes || :w || 5/5 ||| T5/5 | T5V/5")
catchError(assert, tab, "tabstave\n | notes 10/2s10")

code = """tabstave notation=true key=E time=12/8
notes :w 7/4 | :w 6/5"""
assertEquivalent(assert, "Sole notes line ends with bar", code, code + " |")

code = """tabstave notation=true key=E time=12/8
notes :w 7/4 |
notes :w 6/5"""
assertEquivalent(assert, "Last notes line ends with bar", code, code + " |")

assert.ok true, "all pass"


Expand Down Expand Up @@ -501,6 +553,7 @@ class VexTabTests
"""
renderTest assert, "Render Complex", code


@tabStems: (assert) ->
code = """
options tab-stems=true
Expand Down