From cafa0b0eec653790b8b53682b1277c3245ee958d Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Thu, 22 Apr 2021 18:45:30 -0700 Subject: [PATCH 1/6] WORK-IN-PROGRESS: user beaming. --- src/artist.coffee | 20 ++++++++++++++++++++ src/vextab.coffee | 31 +++++++++++++++++-------------- tests/tests.coffee | 8 ++++++++ 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/src/artist.coffee b/src/artist.coffee index 942c446..f882510 100644 --- a/src/artist.coffee +++ b/src/artist.coffee @@ -68,6 +68,8 @@ class Artist @current_octave_shift = 0 @bend_start_index = null @bend_start_strings = null + @in_beam = false + @beam_notes = [] @rendered = false @renderer_context = null @@ -340,6 +342,8 @@ class Artist stave_note.addDotToAll() stave_note.setPlayNote(params.play_note) if params.play_note? + if @in_beam + @beam_notes.push stave_note stave_notes.push stave_note addTabNote: (spec, play_note=null) -> @@ -388,6 +392,22 @@ class Artist stave.tab_notes.push(bar_note) stave.note_notes.push(bar_note) if stave.note? + openBeam: (type) -> + L "openBeam: ", type + if @in_beam + throw new Vex.RERR("ArtistError", "Already in beam") + @in_beam = true + @beam_notes = [] + + closeBeam: (type) -> + L "closeBeam: ", type + if not @in_beam + throw new Vex.RERR("ArtistError", "Not in beam") + b = new Vex.Flow.Beam(@beam_notes, true) + @stave_articulations.push b + @in_beam = false + @beam_notes = [] + makeBend = (from_fret, to_fret) -> direction = Vex.Flow.Bend.UP text = "" diff --git a/src/vextab.coffee b/src/vextab.coffee index 8ab25c6..40fed3e 100644 --- a/src/vextab.coffee +++ b/src/vextab.coffee @@ -73,20 +73,23 @@ class VexTab return params parseCommand: (element) -> - if element.command is "bar" - @artist.addBar(element.type) - - if element.command is "tuplet" - @artist.makeTuplets(element.params.tuplet, element.params.notes) - - if element.command is "annotations" - @artist.addAnnotations(element.params) - - if element.command is "rest" - @artist.addRest(element.params) - - if element.command is "command" - @artist.runCommand(element.params, element._l, element._c) + switch element.command + when "bar" + @artist.addBar(element.type) + when "tuplet" + @artist.makeTuplets(element.params.tuplet, element.params.notes) + when "annotations" + @artist.addAnnotations(element.params) + when "rest" + @artist.addRest(element.params) + when "command" + @artist.runCommand(element.params, element._l, element._c) + when "open_beam" + @artist.openBeam(element.params) + when "close_beam" + @artist.closeBeam(element.params) + else + throw newError(element.command, "Invalid command '#{element.command}'") parseChord: (element) -> L "parseChord:", element diff --git a/tests/tests.coffee b/tests/tests.coffee index b064313..c5bc98a 100644 --- a/tests/tests.coffee +++ b/tests/tests.coffee @@ -53,6 +53,7 @@ class VexTabTests test "Rests in Tab", @restsInTab test "Multi String Tab", @multiStringTab test "Time Signature based Beaming", @timeSigBeaming + test "User Beaming", @beaming test "Override Fret-Note", @overrideFretNote test "Mixed Tuplets", @mixedTuplets test "Accidental Strategies", @accidentalStrategies @@ -595,6 +596,13 @@ class VexTabTests """ renderTest assert, "Time Signature based Beaming", code + @beaming: (assert) -> + code = """ + tabstave notation=true tablature=true time=4/4 + notes :32 [ 2/3 5/2 ] :q 5/1 + """ + renderTest assert, "User Beaming", code + @multiStringTab: (assert) -> code = """ tabstave key=A strings=4 From 2f0f73e3e8a53d3d727095e1fa76ec6281158a3d Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Fri, 23 Apr 2021 07:29:47 -0700 Subject: [PATCH 2/6] Set beam explicitly per wip PR suggestion - no change to output, but good to know. --- src/artist.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/artist.coffee b/src/artist.coffee index f882510..b714833 100644 --- a/src/artist.coffee +++ b/src/artist.coffee @@ -404,6 +404,8 @@ class Artist if not @in_beam throw new Vex.RERR("ArtistError", "Not in beam") b = new Vex.Flow.Beam(@beam_notes, true) + for n in @beam_notes + n.setBeam(b) @stave_articulations.push b @in_beam = false @beam_notes = [] From ae27e266275852f071da7c795bd14c7802b046dd Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Fri, 23 Apr 2021 07:56:46 -0700 Subject: [PATCH 3/6] Attempt: avoid TickContext error, still have beams and flags on notes. --- src/artist.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/artist.coffee b/src/artist.coffee index b714833..ebb68b9 100644 --- a/src/artist.coffee +++ b/src/artist.coffee @@ -344,7 +344,8 @@ class Artist stave_note.setPlayNote(params.play_note) if params.play_note? if @in_beam @beam_notes.push stave_note - stave_notes.push stave_note + else + stave_notes.push stave_note addTabNote: (spec, play_note=null) -> tab_notes = _.last(@staves).tab_notes @@ -406,6 +407,8 @@ class Artist b = new Vex.Flow.Beam(@beam_notes, true) for n in @beam_notes n.setBeam(b) + _.last(@staves).note_notes.push n + @stave_articulations.push b @in_beam = false @beam_notes = [] From a69fc65b58fd8709674a49fd7a54c0eeb2d262b0 Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Fri, 23 Apr 2021 07:57:42 -0700 Subject: [PATCH 4/6] Attempt: don't add beam to articulations, still flags and beam. --- src/artist.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/artist.coffee b/src/artist.coffee index ebb68b9..6afe883 100644 --- a/src/artist.coffee +++ b/src/artist.coffee @@ -409,7 +409,7 @@ class Artist n.setBeam(b) _.last(@staves).note_notes.push n - @stave_articulations.push b + # @stave_articulations.push b @in_beam = false @beam_notes = [] From e1e18a3c312b33e7980a7624a4fa987df1781908 Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Fri, 23 Apr 2021 07:59:24 -0700 Subject: [PATCH 5/6] comment only --- src/artist.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/artist.coffee b/src/artist.coffee index 6afe883..03cdac5 100644 --- a/src/artist.coffee +++ b/src/artist.coffee @@ -407,6 +407,7 @@ class Artist b = new Vex.Flow.Beam(@beam_notes, true) for n in @beam_notes n.setBeam(b) + # _.last(@staves).note_notes.push b # doesn't work _.last(@staves).note_notes.push n # @stave_articulations.push b From 830d750b84926e2d14a4084c8eccacac9e7e5597 Mon Sep 17 00:00:00 2001 From: Jeff Zohrab Date: Thu, 27 May 2021 12:57:24 -0700 Subject: [PATCH 6/6] Added code from https://github.com/0xfe/vextab/pull/124#issuecomment-833214140 --- src/artist.coffee | 5 +++++ src/vextab.coffee | 7 +++++++ tests/tests.coffee | 8 ++++++++ 3 files changed, 20 insertions(+) diff --git a/src/artist.coffee b/src/artist.coffee index 03cdac5..61698e8 100644 --- a/src/artist.coffee +++ b/src/artist.coffee @@ -342,6 +342,7 @@ class Artist stave_note.addDotToAll() stave_note.setPlayNote(params.play_note) if params.play_note? + stave_note.beamset = @beamset # adapted from https://github.com/0xfe/vextab/pull/124#issuecomment-833214140 if @in_beam @beam_notes.push stave_note else @@ -393,6 +394,10 @@ class Artist stave.tab_notes.push(bar_note) stave.note_notes.push(bar_note) if stave.note? + # adapted from https://github.com/0xfe/vextab/pull/124#issuecomment-833214140 + setBeam: (action) -> + @beamset = action + openBeam: (type) -> L "openBeam: ", type if @in_beam diff --git a/src/vextab.coffee b/src/vextab.coffee index 40fed3e..3fe6ec7 100644 --- a/src/vextab.coffee +++ b/src/vextab.coffee @@ -113,6 +113,13 @@ class VexTab @artist.setDuration(element.time, element.dot) if element.command + # Code here adapted from https://github.com/0xfe/vextab/pull/124#issuecomment-833214140 + # open_beam and close_beam are not really command but state + # set beam state (this state would be saved in stavenote array) + if (element.command == "open_beam") + @artist.setBeam("open") + if (element.command == "close_beam") + @artist.setBeam("close") @parseCommand(element) if element.chord diff --git a/tests/tests.coffee b/tests/tests.coffee index c5bc98a..e3289a4 100644 --- a/tests/tests.coffee +++ b/tests/tests.coffee @@ -603,6 +603,14 @@ class VexTabTests """ renderTest assert, "User Beaming", code + # adapted from https://github.com/0xfe/vextab/pull/124#issuecomment-833214140 + code = """ +tabstave notation=true tablature=false clef=treble time=4/4 + notes =|: :8 F/4 :q F/4 :8 F/4 [ tF/4 E/4 ] :q D/4 + notes | :qd D/4 :8 F/4 [ F/4 A/4 G/4 F/4 ] + """ + renderTest assert, "User Beaming 2", code + @multiStringTab: (assert) -> code = """ tabstave key=A strings=4