Files
Aroll-Cutter/transcode/timeline.go

41 lines
1.0 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package transcode
// ZoomResult is the result of a TimelineZoom calculation.
type ZoomResult struct {
Type string `json:"type"`
Percent float64 `json:"percent"`
ViewStart float64 `json:"viewStart"`
ViewEnd float64 `json:"viewEnd"`
}
// TimelineZoom computes the visible time window for the given zoomPercentage
// (1100, where 100 = full duration visible) centered on zoomCenter.
func TimelineZoom(zoomCenter, zoomPercentage, duration float64) *ZoomResult {
visibleDuration := duration * (zoomPercentage / 100)
half := visibleDuration / 2
viewStart := zoomCenter - half
viewEnd := zoomCenter + half
// Clamp to [0, duration], shifting the window rather than just truncating
// so the visible span stays the same size when near the edges.
if viewStart < 0 {
viewEnd -= viewStart
viewStart = 0
}
if viewEnd > duration {
viewStart -= viewEnd - duration
viewEnd = duration
}
if viewStart < 0 {
viewStart = 0
}
return &ZoomResult{
Type: "zoom",
Percent: zoomPercentage,
ViewStart: viewStart,
ViewEnd: viewEnd,
}
}