Skip to content

Commit 9445288

Browse files
Refine the spacing algorithm a bit
we offer extra space to one- and two- note bars only if there is no clef in the bar.
1 parent c5f3116 commit 9445288

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/VexFlow/Abc/TickableContext.purs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Data.List.NonEmpty (head, length, toUnfoldable) as Nel
2121
import Data.Maybe (Maybe, maybe, fromMaybe)
2222
import Data.Int (round, toNumber)
2323
import Data.Rational ((%), fromInt)
24-
import Prelude (class Monoid, class Semigroup, map, mempty, (*), (+), ($), (||), (==))
24+
import Prelude (class Monoid, class Semigroup, map, mempty, not, (*), (+), ($), (||), (&&), (==))
2525

2626
-- | The default horizontal separation between notes in a bar (measured
2727
-- | in pixels at a standard scale of 1.0)
@@ -136,17 +136,13 @@ estimateBarWidth hasClef hasTimeSig maybeKeySig pixelsPerItem abcBar =
136136
if hasTimeSig then 1.0 else 0.0
137137
keySigSpace =
138138
maybe 0.0 keySignatureWidth maybeKeySig
139-
-- offer a little more space if the bar only has a note or two
140-
smallBarSpace =
141-
if ((noteCount == 2) || (noteCount == 2)) then 0.5 else 0.0
142139
in
143140
round $
144141
( clefSpace
145142
+ timeSigSpace
146143
+ keySigSpace
147-
+ (tickableCountWidth noteCount)
144+
+ (tickableCountWidth hasClef noteCount)
148145
+ (0.5 * toNumber graceCount)
149-
+ smallBarSpace
150146
) * pixelsPerItem
151147

152148
-- heuristic to decide how much width to dedicate to a key signature
@@ -165,10 +161,15 @@ keySignatureWidth keySignature =
165161
_ ->
166162
2.0
167163

168-
-- | heuristic to allocate width to 'tickables'
169-
tickableCountWidth :: Int -> Number
170-
tickableCountWidth n =
171-
case n of
172-
1 -> 1.5 -- just 1.0 is too small
173-
2 -> 2.5 -- just 2.0 is too small
174-
_ -> toNumber n
164+
-- | heuristic to allocate width to note 'tickables'
165+
-- | in a non-start bar (with no clef) we need to offer a bit more space
166+
-- | if there are only one or two noted
167+
tickableCountWidth :: Boolean -> Int -> Number
168+
tickableCountWidth hasClef n =
169+
if hasClef then
170+
toNumber n
171+
else
172+
case n of
173+
1 -> 1.90 -- just 1.0 is too small
174+
2 -> 2.70 -- just 2.0 is too small
175+
_ -> toNumber n

0 commit comments

Comments
 (0)