Files
aego/modules/audio/editor/wave_ruler.go
sanspie 50be5c04bc
ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Stage 12.5: Art Workspace and asset authoring
Add dockable Art tools, animation and previews, guarded asset workflows,
and the Web Asset Studio built on the shared Art Core. Expand English and
Russian documentation, interactive Try scenes, examples and editor icons.

Add audio waveform navigation, source analysis, guarded previews and a
browser Worker mixer. Preserve source changes and recovery with bounded
checks, and strengthen native, browser and interoperability CI.

Prepare version 0.12.5 and manually built native artifact candidates.
Fix the production site image demo build dependency.
Reuse immutable scene indices when capturing keyframes.
Wait for real Persist save/load completion in component tests.
Stabilize browser Game View captures outside pointer hover.
Aseprite interchange and persistent Audio EDL recovery remain limited;
the artifact workflow does not publish releases or change stable.
2026-11-15 10:37:50 +03:00

95 lines
2.8 KiB
Go

package editor
import (
"math"
"strconv"
"aego/core/mathx"
"aego/engine/i18n"
"aego/ui/core"
)
const (
audioRulerGap = 72
audioRulerMaxTicks = 32
)
type audioRulerTick struct {
X float32
Seconds float64
}
// audioRulerTicks uses source time, not pyramid bucket indices. Its bounded
// result is only a visual guide; input handling is separate from tick layout.
func audioRulerTicks(start, end int64, rate int, width float32) ([audioRulerMaxTicks]audioRulerTick, int, float64) {
var ticks [audioRulerMaxTicks]audioRulerTick
if start < 0 || end <= start || end > 1<<53 || rate <= 0 || width <= 0 ||
math.IsNaN(float64(width)) || math.IsInf(float64(width), 0) {
return ticks, 0, 0
}
span := float64(end - start)
gap := max(float64(audioRulerGap), float64(width)/float64(audioRulerMaxTicks-2))
ideal := max(span/float64(rate)*gap/float64(width), 1/float64(rate))
base := math.Pow(10, math.Floor(math.Log10(ideal)))
step := 10 * base
for _, multiplier := range [...]float64{1, 2, 5, 10} {
if multiplier*base >= ideal {
step = multiplier * base
break
}
}
first := math.Ceil(float64(start)/float64(rate)/step - 1e-10)
n := 0
for i := 0; i < audioRulerMaxTicks; i++ {
seconds := (first + float64(i)) * step
frame := seconds*float64(rate) - float64(start)
// Roundoff at a tick exactly on the viewport boundary is harmless;
// never display a tick which is genuinely outside the visible range.
if frame > span+1e-4 {
break
}
if frame < -1e-4 {
continue
}
ticks[n] = audioRulerTick{X: float32(min(max(frame/span, 0), 1) * float64(width)), Seconds: seconds}
n++
}
return ticks, n, step
}
func audioRulerLabel(seconds, step float64) string {
precision := 0
if step < 1 {
precision = min(max(int(math.Ceil(-math.Log10(step)-1e-10)), 0), 9)
}
return i18n.Tr("i18n.audio.wave_time", "{time} s", i18n.Str("time", strconv.FormatFloat(seconds, 'f', precision, 64)))
}
func drawAudioRuler(ui *core.Context, v ClipView) mathx.Rect {
r := ui.Cursor().Next(ui.Theme.RowHeight)
start, end := audioWaveBounds(v.WaveStart, v.WaveEnd, v.Frames)
ticks, n, step := audioRulerTicks(start, end, v.Rate, r.W)
if n == 0 || r.H <= 0 {
return r
}
lineY := r.Y + r.H - 1
ui.Rect(mathx.Rect{X: r.X, Y: lineY, W: r.W, H: 1}, ui.Theme.Separator)
lastRight := r.X - 4
for _, tick := range ticks[:n] {
x := min(r.X+tick.X, r.X+r.W-1)
ui.Rect(mathx.Rect{X: x, Y: lineY - 4, W: 1, H: 5}, ui.Theme.TextDim)
label := audioRulerLabel(tick.Seconds, step)
size := ui.TextSize(label)
if size.X <= 0 || size.X > r.W {
continue
}
left := min(max(x-size.X/2, r.X), r.X+r.W-size.X)
if left < lastRight+4 {
continue
}
ui.Text(label, mathx.Vec2{X: left, Y: ui.TextY(mathx.Rect{Y: r.Y, H: max(r.H-5, 0)})}, ui.Theme.TextDim)
lastRight = left + size.X
}
return r
}