This commit is contained in:
5684185+vsariola@users.noreply.github.com
2026-01-02 02:03:05 +02:00
parent fcb9a06249
commit 06a1fb6b52
5 changed files with 145 additions and 38 deletions

View File

@ -44,6 +44,7 @@ func Scope(th *Theme, m *tracker.ScopeModel, st *OscilloscopeState) Oscilloscope
}
func (s *Oscilloscope) Layout(gtx C) D {
t := TrackerFromContext(gtx)
leftSpacer := layout.Spacer{Width: unit.Dp(6), Height: unit.Dp(24)}.Layout
rightSpacer := layout.Spacer{Width: unit.Dp(6)}.Layout
@ -58,11 +59,11 @@ func (s *Oscilloscope) Layout(gtx C) D {
w := s.Model.Waveform()
cx := float32(w.Cursor) / float32(len(w.Buffer))
data := func(chn int, xr plotRange) (yr plotRange) {
data := func(chn int, xr plotRange) (yr plotRange, ok bool) {
x1 := max(int(xr.a*float32(len(w.Buffer))), 0)
x2 := min(int(xr.b*float32(len(w.Buffer))), len(w.Buffer)-1)
if x1 > x2 {
return plotRange{1, 0}
return plotRange{}, false
}
y1 := float32(math.Inf(-1))
y2 := float32(math.Inf(+1))
@ -71,18 +72,31 @@ func (s *Oscilloscope) Layout(gtx C) D {
y1 = max(y1, sample)
y2 = min(y2, sample)
}
return plotRange{-y1, -y2}
return plotRange{-y1, -y2}, true
}
xticks := func(r plotRange, yield func(pos float32, label string)) {
l := s.Model.LengthInBeats().Value()
rpb := max(t.Model.RowsPerBeat().Value(), 1)
xticks := func(r plotRange, count int, yield func(pos float32, label string)) {
l := s.Model.LengthInBeats().Value() * rpb
a := max(int(math.Ceil(float64(r.a*float32(l)))), 0)
b := min(int(math.Floor(float64(r.b*float32(l)))), l)
for i := a; i <= b; i++ {
yield(float32(i)/float32(l), strconv.Itoa(i))
step := 1
n := rpb
for (b-a+1)/step > count {
step *= n
n = 2
}
a = (a / step) * step
for i := a; i <= b; i += step {
if i%rpb == 0 {
beat := i / rpb
yield(float32(i)/float32(l), strconv.Itoa(beat))
} else {
yield(float32(i)/float32(l), "")
}
}
}
yticks := func(r plotRange, yield func(pos float32, label string)) {
yticks := func(r plotRange, count int, yield func(pos float32, label string)) {
yield(-1, "")
yield(1, "")
}