Skip to content

Commit f658603

Browse files
committed
fix(dotted): fix dotted static spacing on dotted and make it dynamic
1 parent 44851bb commit f658603

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

internal/rhythm/dotted.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"github.com/jodi-ivan/numbered-notation-xml/internal/entity"
66
)
77

8+
// TODO: remove the dot positioning operation here, since it handled in the align justify.
89
func (ri *rhythmInteractor) AdjustMultiDottedRenderer(notes []*entity.NoteRenderer, x int, y int) (int, int) {
910

1011
xNotes := 0
@@ -30,7 +31,7 @@ func (ri *rhythmInteractor) AdjustMultiDottedRenderer(notes []*entity.NoteRender
3031
} else if n.Articulation != nil && n.Articulation.BreathMark != nil {
3132
if prev != nil && prev.IsDotted {
3233
n.PositionX -= constant.LOWERCASE_LENGTH
33-
} // FIXME: a non dotted before the breath mark has excessive length
34+
}
3435
} else {
3536
xNotes = x
3637
continueDot = false

internal/staff/align.go

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,31 @@ type renderStaffAlign struct {
3333
Lyric lyric.Lyric
3434
}
3535

36+
type dotPosition struct {
37+
beforeXpos int
38+
afterXPos int
39+
address []*int
40+
}
41+
42+
func (dt *dotPosition) Reset(startPosition int) {
43+
dt.beforeXpos = startPosition
44+
dt.address = []*int{}
45+
}
46+
47+
func (dt *dotPosition) Render(endPosition int) {
48+
if len(dt.address) > 0 {
49+
dt.afterXPos = endPosition
50+
space := (dt.afterXPos - dt.beforeXpos) / (len(dt.address) + 1)
51+
for i, d := range dt.address {
52+
*d = (dt.beforeXpos + (space * (i + 1)))
53+
}
54+
55+
// reset here
56+
dt.beforeXpos = endPosition
57+
dt.address = []*int{}
58+
}
59+
}
60+
3661
func (rsa *renderStaffAlign) RenderWithAlign(ctx context.Context, canv canvas.Canvas, y int, noteRenderer [][]*entity.NoteRenderer) {
3762

3863
flatten := []*entity.NoteRenderer{}
@@ -57,6 +82,7 @@ func (rsa *renderStaffAlign) RenderWithAlign(ctx context.Context, canv canvas.Ca
5782

5883
count := 1
5984
slurTiesNote := []*entity.NoteRenderer{}
85+
dotPositioner := dotPosition{}
6086
canv.Group("staff")
6187
for mi, measure := range noteRenderer {
6288

@@ -69,19 +95,34 @@ func (rsa *renderStaffAlign) RenderWithAlign(ctx context.Context, canv canvas.Ca
6995
slurTiesNote = append(slurTiesNote, note)
7096
}
7197

72-
// do not add left spacing on first not first measure
98+
// do not add left spacing on first note on the first measure
7399
if i == 0 && mi == 0 {
100+
dotPositioner.Reset(note.PositionX)
74101
continue
75102
}
76103

77104
// don't add to the end either
78105
if mi == len(noteRenderer)-1 && i == len(measure)-1 {
106+
dotPositioner.Render(note.PositionX)
79107
continue
80108
}
81109

82110
note.PositionX += int(added * float64(count))
83111
count++
84112

113+
if note.IsDotted {
114+
if dotPositioner.address == nil {
115+
dotPositioner.address = []*int{}
116+
}
117+
dotPositioner.address = append(dotPositioner.address, &note.PositionX)
118+
} else {
119+
if len(dotPositioner.address) > 0 {
120+
dotPositioner.Render(note.PositionX)
121+
} else {
122+
dotPositioner.Reset(note.PositionX)
123+
}
124+
}
125+
85126
//TODO: reposition if distance betweeb 2 lyrics are zless than 2spaces and 1 dashes space.
86127
// move the prev to -x distance
87128
}

0 commit comments

Comments
 (0)