API 參考取自原始碼中的 Go 文件註解,以英文撰寫。
package rhythm
import "github.com/nsgo-dev/game/pkg/rhythm"概覽
Package rhythm keeps a rhythm game in time with its music: a beat map read from YAML, a music clock that reads the track's position and beat at any engine time, and a calibration of each device's audio and video latency.
Beat maps
A BeatMap is a track's tempo map in a versioned YAML file: where beat 0 falls in the audio, tempo changes at any beat and meter changes on bar lines. ParseBeatMap refuses unknown fields and EncodeBeatMap writes the fields in a fixed order, so a map round-trips unchanged. BeatMap.Timing turns it into a Timing that converts track time to beats and bars and back, at float64 precision from each change's own start, so a beat's time never drifts with the length of the track.
The music clock
A Clock runs on the engine's clock, audio.Now, which audio.Voice.StartAt also counts on. Start it at the time a track starts playing, and it extrapolates the output's position from there; Sync, fed from an audio.Player's OnProgress, moves it only when the player drifts past a tolerance. Position and Beat are what the player hears, corrected by the device's Offsets, and judge input; DrawPosition and DrawBeat add the video offset for the frame being drawn; BeatTime is when to start a hit sound or a metronome click with audio.Voice.StartAt.
Calibration
A Calibrator matches taps with cues every Interval and measures the median offset and its spread. A Calibration runs one on the engine: clicks scheduled ahead with audio.Voice.StartAt for the audio offset, seeded with audio.OutputLatency, or silent cues to flash for the video offset. CalibrationScreen is the gameui screen a player calibrates on, and OffsetStore keeps each device's Offsets as a versioned YAML document in core.Storage, keyed by DeviceKey.
索引
- 常數
- func DeviceKey(cx *core.Scope) string
- func EncodeBeatMap(m *BeatMap) ([]byte, error)
- func EncodeCalibrations(c *Calibrations) ([]byte, error)
- type BeatMap
- type Calibration
- func NewCalibration(cx *core.Scope, kind CalibrationKind, click *audio.Sound) *Calibration
- func (c *Calibration) Apply(o Offsets) (Offsets, bool)
- func (c *Calibration) OutputLatency() (time.Duration, bool)
- func (c *Calibration) Start()
- func (c *Calibration) Stop()
- func (c *Calibration) Tap() (offset time.Duration, counted bool)
- func (c *Calibration) Update()
- type CalibrationKind
- type CalibrationResult
- type CalibrationScreen
- func NewCalibrationScreen(cal *Calibration, store *OffsetStore, device string) *CalibrationScreen
- func (s *CalibrationScreen) Calibration() *Calibration
- func (s *CalibrationScreen) Draw(d *core.Drawing, bounds core.Bounds)
- func (s *CalibrationScreen) Err() error
- func (s *CalibrationScreen) OnKeyDown(ev core.KeyEvent) bool
- func (s *CalibrationScreen) OnPress(ev core.PressEvent) bool
- func (s *CalibrationScreen) OnPressDown(ev core.PressEvent) bool
- func (s *CalibrationScreen) Retry()
- func (s *CalibrationScreen) Root() *gameui.Root
- func (s *CalibrationScreen) Save() error
- func (s *CalibrationScreen) Stop()
- type CalibrationText
- type Calibrations
- type Calibrator
- func (c *Calibrator) Count() int
- func (c *Calibrator) Cue(k int) time.Time
- func (c *Calibrator) CueAt(now time.Time) int
- func (c *Calibrator) Done() bool
- func (c *Calibrator) Present(k int, at time.Time)
- func (c *Calibrator) Pulse(now time.Time) (cue int, level float64)
- func (c *Calibrator) Result() (CalibrationResult, bool)
- func (c *Calibrator) Start(at time.Time)
- func (c *Calibrator) Started() bool
- func (c *Calibrator) Tap(at time.Time) (offset time.Duration, counted bool)
- type Clock
- func NewClock(t *Timing) *Clock
- func (c *Clock) Beat(now time.Time) float64
- func (c *Clock) BeatTime(beat float64) time.Time
- func (c *Clock) DrawBeat(now time.Time) float64
- func (c *Clock) DrawPosition(now time.Time) time.Duration
- func (c *Clock) Judge(at time.Time, beat float64) time.Duration
- func (c *Clock) Offsets() Offsets
- func (c *Clock) Pause(at time.Time)
- func (c *Clock) Position(now time.Time) time.Duration
- func (c *Clock) Resume(at time.Time)
- func (c *Clock) Running() bool
- func (c *Clock) SetOffsets(o Offsets)
- func (c *Clock) Start(at time.Time, from time.Duration)
- func (c *Clock) Sync(reported time.Duration, at time.Time) bool
- func (c *Clock) Timing() *Timing
- func (c *Clock) Track(now time.Time) time.Duration
- func (c *Clock) TrackTime(pos time.Duration) time.Time
- type DeviceOffsets
- type Meter
- type OffsetStore
- type Offsets
- type Tempo
- type Timing
- func (t *Timing) BPM(beat float64) float64
- func (t *Timing) Bar(beat float64) (bar int, inBar float64)
- func (t *Timing) Beat(d time.Duration) float64
- func (t *Timing) BeatAtSeconds(sec float64) float64
- func (t *Timing) BeatsPerBar(beat float64) int
- func (t *Timing) Seconds(beat float64) float64
- func (t *Timing) Time(beat float64) time.Duration
常數
const (
// MinBPM is the slowest tempo a beat map may set, so every time a valid map gives, up to MaxBeat, fits a time.Duration many times over.
MinBPM = 1
// MaxBPM is the fastest tempo a beat map may set.
MaxBPM = 2000
// MaxBeat is the latest beat a tempo or meter change may start at.
MaxBeat = 1_000_000
// MaxOffsetMs is the largest offset, either way, of beat 0 from the start of the track: one hour.
MaxOffsetMs = 3_600_000
// MaxChanges is the most tempo changes, and separately meter changes, a beat map may hold.
MaxChanges = 10_000
// MaxBeatsPerBar is the longest bar a meter may set.
MaxBeatsPerBar = 64
)Limits a beat map is validated against.
const (
// DefaultInterval is the time between cues: 80 beats a minute, so a tap up to 375 milliseconds off its seed still finds its cue.
DefaultInterval = 750 * time.Millisecond
// DefaultTaps is how many taps a calibration counts.
DefaultTaps = 16
// DefaultWarmup is how many first taps it ignores while the player finds the beat.
DefaultWarmup = 4
// DefaultLead is the time from Calibration.Start to the first cue.
DefaultLead = time.Second
// SteadySpread is the most a result's spread may be for Steady to hold.
SteadySpread = 30 * time.Millisecond
)Defaults of a Calibrator.
const (
// MaxOffsetMsAbs is the largest offset, either way, a device may keep: ten seconds.
MaxOffsetMsAbs = 10_000
// MaxDevices is the most devices a calibration file may keep.
MaxDevices = 256
// MaxDeviceKey is the longest device key, in bytes.
MaxDeviceKey = 256
)Limits a calibration file is validated against.
const BeatMapVersion = 1BeatMapVersion is the beat map schema version this package reads and writes.
const CalibrationsVersion = 1CalibrationsVersion is the calibration file schema version this package reads and writes.
const DefaultTolerance = 30 * time.MillisecondDefaultTolerance is how far a player's reported position may stray from a Clock before Sync moves the clock to it.
函式
func DeviceKey(cx *core.Scope) stringDeviceKey returns a key for the device cx runs on: its OS and hardware model, such as "ios/iPhone15,2", or the OS and "unknown" where the platform names no model, as the web does, cut to MaxDeviceKey bytes at a character's start. NSGo names no audio output route, so a game that wants separate offsets for headphones and speakers adds its own suffix, such as "/bluetooth", chosen by the player.
func EncodeBeatMap(m *BeatMap) ([]byte, error)EncodeBeatMap validates m and writes it as deterministic 2-space YAML that ParseBeatMap reads back to an equal map.
func EncodeCalibrations(c *Calibrations) ([]byte, error)EncodeCalibrations validates c and writes it as deterministic 2-space YAML, devices in key order.
型別
type BeatMap struct {
// Version is the schema version; it must be BeatMapVersion.
Version int `yaml:"version"`
// Title names the track for people reading the file; nothing uses it.
Title string `yaml:"title,omitempty"`
// OffsetMs is where beat 0 plays in the track, in milliseconds from its start; negative when the track starts after beat 0.
OffsetMs float64 `yaml:"offsetMs,omitempty"`
// Tempos are the tempo changes in beat order, the first at beat 0.
Tempos []Tempo `yaml:"tempos"`
// Meters are the meter changes in beat order, the first at beat 0; none means 4 beats to a bar.
Meters []Meter `yaml:"meters,omitempty"`
}BeatMap is a track's tempo map, as written in a versioned YAML file next to the track: where beat 0 falls in the audio, the tempo from each beat on, and optionally the meter from each bar on.
version: 1
title: Opening
offsetMs: 120
tempos:
- beat: 0
bpm: 120
- beat: 64
bpm: 140
meters:
- beat: 0
beatsPerBar: 4
A beat is the unit the tempo counts, so a tempo change can start between beats (beat: 62.5) while a meter change starts on a whole bar of the meter before it. Parse and Encode keep the fields in this order and round-trip a valid map unchanged; Timing turns it into times.
func ParseBeatMap(data []byte) (*BeatMap, error)ParseBeatMap decodes a YAML beat map and validates it. Unknown fields, a second YAML document, anchors and aliases, and a fraction where a whole number belongs are refused.
func (m *BeatMap) Timing() (*Timing, error)Timing validates m and returns its times, which later changes to m do not affect.
func (m *BeatMap) Validate() errorValidate reports the first way m breaks the version 1 schema: a wrong version, no tempo, a change out of order or range, or a meter change off its bar line.
type Calibration struct {
Calibrator
// Kind is which offset it measures.
Kind CalibrationKind
// Lead is the time from Start to the first cue; DefaultLead when 0.
Lead time.Duration
// contains filtered or unexported fields
}Calibration runs a Calibrator on the engine's clock: for CalibrateAudio it plays a click at each cue, scheduled ahead with audio.Voice.StartAt where audio.CanSchedule says the platform can and otherwise on the first Update at or after the cue; for CalibrateVideo it plays nothing and the screen flashes by Pulse. It seeds an audio calibration with the output latency audio.OutputLatency reads.
Call Update every frame, as CalibrationScreen.Draw does, and Tap from the input that taps. Its methods run on the engine's goroutine.
func NewCalibration(cx *core.Scope, kind CalibrationKind, click *audio.Sound) *CalibrationNewCalibration returns a calibration of kind on cx's engine, clicking click at each cue of an audio calibration; click may be nil for a video calibration. It starts at Start.
func (c *Calibration) Apply(o Offsets) (Offsets, bool)Apply returns o with the offset this calibration measures set to its result, and whether it had a steady result to set.
func (c *Calibration) OutputLatency() (time.Duration, bool)OutputLatency returns the output latency the platform reported at Start, and whether it reported one.
func (c *Calibration) Start()Start begins the calibration, its first cue Lead from now, forgetting the taps of any run before and stopping the clicks it scheduled for it. An audio calibration asks for the output latency and, when the platform knows it, seeds with it.
func (c *Calibration) Stop()Stop ends the run: it stops the clicks scheduled ahead and takes no more taps until Start, keeping the result so far. Call it when the calibration's screen goes away mid-run.
func (c *Calibration) Tap() (offset time.Duration, counted bool)Tap records a tap now, by the engine's clock, as Calibrator.Tap does. The tap that finishes the calibration stops the clicks still scheduled.
func (c *Calibration) Update()Update plays the clicks of an audio calibration that are due: those within two intervals ahead, scheduled at their cue, where the platform schedules sounds, and otherwise the latest cue that has come, at once, recording when it played. Once the calibration is done it stops the clicks still scheduled.
type CalibrationKind uint8CalibrationKind is which offset a calibration measures.
const (
// CalibrateAudio measures Offsets.Audio: the player taps to clicks they hear and sees nothing move.
CalibrateAudio CalibrationKind = iota
// CalibrateVideo measures Offsets.Video: the player taps to flashes they see and hears nothing.
CalibrateVideo
)type CalibrationResult struct {
// Offset is the median of the counted taps' offsets: how late, on this device, a player taps after a cue.
Offset time.Duration
// Spread is the median of how far each tap is from Offset; a few milliseconds for a steady player.
Spread time.Duration
// Taps is how many taps it counted.
Taps int
}CalibrationResult is what a calibration measured.
func (r CalibrationResult) Steady() boolSteady reports whether the taps agree well enough to keep the result: a spread of at most SteadySpread.
type CalibrationScreen struct {
// Text is the words shown; DefaultCalibrationText until set.
Text CalibrationText
// FlashColor is the video calibration's flash; the gameui theme's accent when 0.
FlashColor core.Color
// OnSave runs after Save keeps the offsets, with the device's offsets as kept.
OnSave func(Offsets)
// contains filtered or unexported fields
}CalibrationScreen is the screen a player calibrates a device on, drawn into a core.Canvas with gameui: a prompt, the taps counted, the result, a Retry button and a Save button that keeps the result in an OffsetStore for the device. A video calibration flashes a disc at each cue; an audio one shows nothing that moves, so the player taps to what they hear.
Draw it every frame from the canvas, which also drives its Calibration. A tap is taken on the edge it goes down, as gameplay judges a hit, never on a completed press, which comes only as the finger lifts: wrap the canvas in a core.View and pass its OnPressDown, OnPress and OnKeyDown here. A press going down off the buttons is a tap and a press on a button presses it; a key going down is a tap unless it moves the focus or presses a focused button, and once the calibration is done the focus moves to Save, or to Retry for an unsteady result, so a player on a keyboard or a switch reaches them.
func NewCalibrationScreen(cal *Calibration, store *OffsetStore, device string) *CalibrationScreenNewCalibrationScreen returns a screen running cal and keeping its result for device in store. It starts cal.
func (s *CalibrationScreen) Calibration() *CalibrationCalibration returns the calibration the screen runs.
func (s *CalibrationScreen) Draw(d *core.Drawing, bounds core.Bounds)Draw updates the calibration, the words and the buttons, and draws the screen into bounds of d. A video calibration records the frame that first flashes each cue as when the cue was presented.
func (s *CalibrationScreen) Err() errorErr returns why the last Save failed, nil after one that kept the offsets.
func (s *CalibrationScreen) OnKeyDown(ev core.KeyEvent) boolOnKeyDown handles a key going down: Tab and the arrows move the focus among the buttons and Return or Space presses the focused one, as gameui.Root does; any other key going down, not a held key's repeat, is a tap. It reports whether it used the key.
func (s *CalibrationScreen) OnPress(ev core.PressEvent) boolOnPress handles a completed press on the canvas: one on a button presses it, and Return or Space presses the focused button. Taps are taken by OnPressDown and OnKeyDown, not here. It reports whether it used the press.
func (s *CalibrationScreen) OnPressDown(ev core.PressEvent) boolOnPressDown handles a press going down on the canvas: a tap, unless it lands on a button, which OnPress then presses. It reports whether the tap counted.
func (s *CalibrationScreen) Retry()Retry starts the calibration over.
func (s *CalibrationScreen) Root() *gameui.RootRoot returns the screen's gameui tree, to set its Theme or Viewport or route keys through it.
func (s *CalibrationScreen) Save() errorSave keeps the device's offsets with the calibration's result in the store and runs OnSave. It does nothing until the result is steady.
func (s *CalibrationScreen) Stop()Stop stops the calibration's clicks and taps, for when the screen goes away mid-run; Retry starts it again.
type CalibrationText struct {
// AudioPrompt and VideoPrompt ask the player to tap along to the clicks or the flashes.
AudioPrompt, VideoPrompt string
// Progress shows the taps counted and needed, as "%d / %d".
Progress string
// Result shows a steady result's offset in milliseconds, as "%+d ms".
Result string
// Unsteady shows a result too spread out to keep, given its spread in milliseconds.
Unsteady string
// Retry and Save label the buttons that start over and keep the result.
Retry, Save string
}CalibrationText is the words a CalibrationScreen shows, for a game to translate. Progress, Result and Unsteady are fmt formats.
func DefaultCalibrationText() CalibrationTextDefaultCalibrationText returns the English words.
type Calibrations struct {
// Version is the schema version; it must be CalibrationsVersion.
Version int `yaml:"version"`
// Devices are the offsets by device key, such as DeviceKey returns.
Devices map[string]DeviceOffsets `yaml:"devices,omitempty"`
}Calibrations are the offsets calibration measured on each device, as the YAML text an OffsetStore keeps:
version: 1
devices:
ios/iPhone15,2:
audioMs: 182.5
videoMs: 21
Devices are written in key order, so the same offsets always encode to the same text, and ParseCalibrations reads it back unchanged.
func ParseCalibrations(data []byte) (*Calibrations, error)ParseCalibrations decodes a YAML calibration file and validates it. Unknown fields, a second YAML document, anchors and aliases, and a fractional version are refused.
func (c *Calibrations) Validate() errorValidate reports the first way c breaks the version 1 schema: a wrong version, too many devices, an empty, overlong or invalid UTF-8 key, or an offset that is not a number within ±MaxOffsetMsAbs.
type Calibrator struct {
// Interval is the time between cues; DefaultInterval when 0.
Interval time.Duration
// Taps is how many taps it counts; DefaultTaps when 0.
Taps int
// Warmup is how many first taps it ignores; DefaultWarmup when 0, none when negative.
Warmup int
// Seed is the offset expected before measuring, such as the output latency audio.OutputLatency reads: a tap is matched with the cue nearest to it less Seed.
Seed time.Duration
// contains filtered or unexported fields
}Calibrator measures an offset from taps to cues: cues come every Interval from a start time, the player taps along, and the median of how late each tap is, after the first Warmup, is the offset. It keeps no clock of its own, so the times it is given decide everything and a test can drive it exactly.
func (c *Calibrator) Count() intCount returns how many taps counted so far.
func (c *Calibrator) Cue(k int) time.TimeCue returns the nominal time of cue k.
func (c *Calibrator) CueAt(now time.Time) intCueAt returns the last cue at or before now, -1 before cue 0.
func (c *Calibrator) Done() boolDone reports whether it counted Taps taps.
func (c *Calibrator) Present(k int, at time.Time)Present records that cue k was really presented at at, as the first frame to show a flash or the moment a click without a scheduled start played, so taps are measured from it. Only the first time for a cue counts.
func (c *Calibrator) Pulse(now time.Time) (cue int, level float64)Pulse returns the last cue at or before now and how brightly to show it: 1 at the cue, fading to 0 a quarter of the interval later. It returns -1 and 0 before cue 0 and once the calibration is done.
func (c *Calibrator) Result() (CalibrationResult, bool)Result returns what the counted taps measured, and whether it is Done.
func (c *Calibrator) Start(at time.Time)Start begins a calibration with cue 0 at at, forgetting any taps before.
func (c *Calibrator) Started() boolStarted reports whether Start was called.
func (c *Calibrator) Tap(at time.Time) (offset time.Duration, counted bool)Tap records a tap at at and returns how late it is for its cue, the cue nearest to at less Seed, and whether it counted: not before Start, a cue before 0, during the warmup or once done.
type Clock struct {
// Tolerance is how far a reported position may stray before Sync moves the clock; DefaultTolerance when 0.
Tolerance time.Duration
// contains filtered or unexported fields
}Clock is a track's music clock: the position the audio output plays, in the track's beats, read at any time of the engine's clock (audio.Now, which audio.Voice.StartAt also counts on), and corrected by a device's Offsets for judging input and drawing notes.
Start it when the track starts playing: at the time passed to audio.Voice.StartAt for a sound, or in an audio.Player's Play callback with the player's position. Between starts it extrapolates from the engine's clock, so it does not move in the steps of a player's progress reports; Sync, called from the player's OnProgress, moves it only when the player drifts past Tolerance, as after a seek, a loop or a stall.
A Clock is used from the engine's goroutine, as the audio package is.
func NewClock(t *Timing) *ClockNewClock returns a stopped clock at track position 0, counting beats by t.
func (c *Clock) Beat(now time.Time) float64Beat returns the beat at Position(now).
func (c *Clock) BeatTime(beat float64) time.TimeBeatTime returns TrackTime of beat.
func (c *Clock) DrawBeat(now time.Time) float64DrawBeat returns the beat at DrawPosition(now): where a frame drawn at now puts the hit line.
func (c *Clock) DrawPosition(now time.Time) time.DurationDrawPosition returns the track position a frame drawn at engine time now should show, so that what it shows reaches the player with the beat they hear: the output's position plus the video offset less the audio offset.
func (c *Clock) Judge(at time.Time, beat float64) time.DurationJudge returns how early (negative) or late (positive) an input going down at engine time at is for beat, corrected by the device's audio offset. Take at from the edge calibration took taps on, a press going down (core.View.OnPressDown) or a key going down, never a completed press.
func (c *Clock) Offsets() OffsetsOffsets returns the device's offsets the clock corrects by.
func (c *Clock) Pause(at time.Time)Pause stops the clock at the position the output plays at engine time at.
func (c *Clock) Position(now time.Time) time.DurationPosition returns the track position a player acting at engine time now acts on: the output's position less the device's audio offset. Judge input by it.
func (c *Clock) Resume(at time.Time)Resume has a paused clock run on from where it paused, played by the output at engine time at.
func (c *Clock) Running() boolRunning reports whether the clock runs, between Start or Resume and Pause.
func (c *Clock) SetOffsets(o Offsets)SetOffsets sets the device's offsets the clock corrects by, such as those OffsetStore.Get returns.
func (c *Clock) Start(at time.Time, from time.Duration)Start has the clock run from track position from, played by the output at engine time at.
func (c *Clock) Sync(reported time.Duration, at time.Time) boolSync compares the position a player reports, reported at engine time at, with the clock, and moves the clock to it when they differ by more than Tolerance, reporting whether it did. A stopped clock does not move. Call it from audio.PlayerOptions.OnProgress with audio.Now.
func (c *Clock) Timing() *TimingTiming returns the beat map's timing the clock counts by.
func (c *Clock) Track(now time.Time) time.DurationTrack returns the track position the output plays at engine time now, uncorrected: where the track is, not what is heard.
func (c *Clock) TrackTime(pos time.Duration) time.TimeTrackTime returns the engine time at which the output plays track position pos while the clock runs. Pass it to audio.Voice.StartAt to start a hit sound or a metronome click in time with the track: both go through the same output, so no offset applies.
type DeviceOffsets struct {
// AudioMs is Offsets.Audio in milliseconds.
AudioMs float64 `yaml:"audioMs"`
// VideoMs is Offsets.Video in milliseconds.
VideoMs float64 `yaml:"videoMs"`
}DeviceOffsets are a device's Offsets in milliseconds, as written.
func DeviceOffsetsOf(o Offsets) DeviceOffsetsDeviceOffsetsOf returns o in milliseconds.
func (d DeviceOffsets) Offsets() OffsetsOffsets returns d as durations, rounded to the nanosecond.
type Meter struct {
// Beat is where the first bar of the meter starts: a whole number of the previous meter's bars after the previous change.
Beat int `yaml:"beat"`
// BeatsPerBar is the beats in each bar, 1 to MaxBeatsPerBar.
BeatsPerBar int `yaml:"beatsPerBar"`
}Meter is a meter change: from Beat on, bars of BeatsPerBar beats.
type OffsetStore struct {
// contains filtered or unexported fields
}OffsetStore keeps each device's offsets as a Calibrations YAML document in the app's storage (core.Storage) under one key, so they hold across launches and a player who moves their save to another device calibrates that device anew.
func NewOffsetStore(cx *core.Scope, key string) *OffsetStoreNewOffsetStore returns a store keeping its document in cx's storage under key, such as "rhythm.calibration".
func (s *OffsetStore) Get(device string) (Offsets, bool)Get returns device's offsets and whether they are kept; a document that is not readable keeps none.
func (s *OffsetStore) Load() (*Calibrations, error)Load returns the document kept, an empty one when none is, or why the text kept is not one. Read in a computation, it subscribes it to changes, as core.Storage does.
func (s *OffsetStore) Remove(device string) errorRemove forgets device's offsets. It fails as Set does, and also when the document kept is not readable, which it leaves as it is.
func (s *OffsetStore) Set(device string, o Offsets) errorSet keeps o for device, rounded to the nanosecond as milliseconds, alongside the other devices'. A document that is not readable, such as one a later schema wrote, is replaced. It fails when o or device is out of range, or with a *core.StorageFullError when the storage is full, keeping what it held.
type Offsets struct {
// Audio is how long after the engine starts a sound the player taps to it: the output's latency, the input's and the player's habit together. It is usually positive, and tens to hundreds of milliseconds over Bluetooth.
Audio time.Duration
// Video is how long after the engine draws a frame the player taps to what it shows: the display's latency, the input's and the player's habit together.
Video time.Duration
}Offsets are the delays between the engine starting a sound or drawing a frame and the player acting on it, as calibration measures them on a device.
type Tempo struct {
// Beat is where the tempo starts, 0 or later and after the change before it.
Beat float64 `yaml:"beat"`
// BPM is the beats a minute, from MinBPM to MaxBPM.
BPM float64 `yaml:"bpm"`
}Tempo is a tempo change: from Beat on, BPM beats a minute.
type Timing struct {
// contains filtered or unexported fields
}Timing converts between a track's time and its beats and bars, by a BeatMap. Times are from the start of the audio, the position a player reports; a beat before 0 or after the last change keeps the tempo nearest it. A Timing never changes, so goroutines may share one.
func (t *Timing) Bar(beat float64) (bar int, inBar float64)Bar returns the bar beat falls in, counted from 0 at beat 0 and negative before it, and how many beats into that bar it is.
func (t *Timing) Beat(d time.Duration) float64Beat returns the beat that plays at track time d.
func (t *Timing) BeatAtSeconds(sec float64) float64BeatAtSeconds returns the beat that plays sec seconds into the track.
func (t *Timing) BeatsPerBar(beat float64) intBeatsPerBar returns the meter at beat.
func (t *Timing) Seconds(beat float64) float64Seconds returns the track time beat plays at, in seconds, at full float64 precision.
func (t *Timing) Time(beat float64) time.DurationTime returns the track time beat plays at, rounded to the nanosecond.