// Custom JSON marshaler for the Beats struct that represents the internal times as (float) seconds.
Custom JSON marshaler for the Beats struct that represents the internal times as (float) seconds.
// Custom JSON marshaler for the Beats struct that represents the internal times as ( float ) seconds .
func (beats Beats) MarshalJSON() ([]byte, error) {
	type beat struct {
		At       instant   `json:"at"`
		Mean     instant   `json:"mean"`
		Variance instant   `json:"variance"`
		Taps     []instant `json:"taps"`
	}
	b := struct {
		BPM    uint    `json:"BPM"`
		Offset instant `json:"offset"`
		Beats  []beat  `json:"beats"`
	}{
		BPM:    beats.BPM,
		Offset: instant(beats.Offset),
		Beats:  make([]beat, len(beats.Beats)),
	}
	for i, bb := range beats.Beats {
		b.Beats[i] = beat{
			At:       instant(bb.At),
			Mean:     instant(bb.Mean),
			Variance: instant(bb.Variance),
			Taps:     make([]instant, len(bb.Taps)),
		}
		for j, t := range bb.Taps {
			b.Beats[i].Taps[j] = instant(t)
		}
	}
	return json.Marshal(b)
}
func ( beats Beats ) MarshalJSON ( ) ( [ ] byte , error ) { type beat struct { At instant `json:"at"` Mean instant `json:"mean"` Variance instant `json:"variance"` Taps [ ] instant `json:"taps"` } b := struct { BPM uint `json:"BPM"` Offset instant `json:"offset"` Beats [ ] beat `json:"beats"` } { BPM : beats . BPM , Offset : instant ( beats . Offset ) , Beats : make ( [ ] beat , len ( beats . Beats ) ) , } for i , bb := range beats . Beats { b . Beats [ i ] = beat { At : instant ( bb . At ) , Mean : instant ( bb . Mean ) , Variance : instant ( bb . Variance ) , Taps : make ( [ ] instant , len ( bb . Taps ) ) , } for j , t := range bb . Taps { b . Beats [ i ] . Taps [ j ] = instant ( t ) } } return json . Marshal ( b ) }
Custom JSON marshaler for the Beats struct that represents the internal times as (float) seconds.
Custom JSON marshaler for the Beats struct that represents the internal times as ( float ) seconds .