Skip to content

Commit

Permalink
Merge pull request #122 from jzohrab/fix-score-tab-bar-alignment
Browse files Browse the repository at this point in the history
Fix notation-vs-tab bar misalignment
  • Loading branch information
0xfe authored Apr 20, 2021
2 parents 562bdbf + cc1ca14 commit 42c213e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
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
57 changes: 56 additions & 1 deletion tests/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,51 @@ class VexTabTests
tab.getArtist().render(renderer)
assert.ok(true, "all pass")

# ID counter for getRenderedContent.
idcounter = 0

# 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

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

renderCodeInCanvas = ->
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)

container.append(makeCanvas())
renderCodeInCanvas()
content = $('#' + canvasid).
html().
replace(/id=\".*?\"/g, 'id="xxx"')
return content

# 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 +264,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 +555,7 @@ class VexTabTests
"""
renderTest assert, "Render Complex", code


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

0 comments on commit 42c213e

Please sign in to comment.