// NewRateFromFormatted returns the rate from the formatted version.
323931
func NewRateFromFormatted(formatted string) (Rate, error) {
	rate := Rate{}

	values := strings.Split(formatted, "-")
	if len(values) != 2 {
		return rate, errors.Errorf("incorrect format '%s'", formatted)
	}

	periods := map[string]time.Duration{
		"S": time.Second, // Second
		"M": time.Minute, // Minute
		"H": time.Hour,   // Hour
	}

	limit, period := values[0], strings.ToUpper(values[1])

	duration, ok := periods[period]
	if !ok {
		return rate, errors.Errorf("incorrect period '%s'", period)
	}

	p := 1 * duration
	l, err := strconv.ParseInt(limit, 10, 64)
	if err != nil {
		return rate, errors.Errorf("incorrect limit '%s'", limit)
	}

	rate = Rate{
		Formatted: formatted,
		Period:    p,
		Limit:     l,
	}

	return rate, nil
}
462907
func (out OffsetOut) Rate(rate int8) Input {
	CheckRate(rate)
	return NewInput("OffsetOut", rate, 0, 1, out.Bus, out.Channels)
}
374730
func (x XFade2) Rate(rate int8) Input {
	CheckRate(rate)
	(&x).defaults()
	return NewInput("XFade2", rate, 0, 1, x.A, x.B, x.Pan, x.Level)
}
346661
func (h *ADXL345Driver) SetRate(rate byte) (err error) {
	if rate <= ADXL345_RATE_3200HZ {
		return errors.New("not a valid rate")
	}
	h.bwRate.rate = rate & 0x0F
	if _, err := h.connection.Write([]byte{ADXL345_REG_BW_RATE, h.bwRate.toByte()}); err != nil {
		return err
	}
	return
}
996805
func (playbuf PlayBuf) Rate(rate int8) Input {
	CheckRate(rate)
	if playbuf.BufNum == nil {
		panic(fmt.Errorf("BufNum can not be nil"))
	}
	(&playbuf).defaults()
	done := C(float32(playbuf.Done))
	return NewInput("PlayBuf", rate, 0, playbuf.NumChannels, playbuf.BufNum, playbuf.Speed, playbuf.Trigger, playbuf.Start, playbuf.Loop, done)
}
740721
func (bpf BPF) Rate(rate int8) Input {
	if bpf.In == nil {
		panic("BPF expects In to not be nil")
	}
	CheckRate(rate)
	(&bpf).defaults()
	return NewInput("BPF", rate, 0, 1, bpf.In, bpf.Freq, bpf.RQ)
}
1242265
func (s Shaper) Rate(rate int8) Input {
	CheckRate(rate)
	if s.BufNum == nil {
		panic("Shaper requires a buffer number")
	}
	(&s).defaults()
	return NewInput("Shaper", rate, 0, 1, s.BufNum, s.In)
}
838968
func (s SinOscFB) Rate(rate int8) Input {
	CheckRate(rate)
	(&s).defaults()
	return NewInput("SinOscFB", rate, 0, 1, s.Freq, s.Feedback)
}
916886
func NewFormatter(verb, format string) (Formatter, error) {
	switch verb {
	case "color":
		return newColorFormatter(format)
	case "id":
		return newSequenceFormatter(format), nil
	case "level":
		return newLevelFormatter(format), nil
	case "message":
		return newMessageFormatter(format), nil
	case "module":
		return newModuleFormatter(format), nil
	case "shortfunc":
		return newShortFuncFormatter(format), nil
	case "time":
		return newTimeFormatter(format), nil
	default:
		return nil, fmt.Errorf("unknown verb: %s", verb)
	}
}
123372
func NewDiskUsageFormat(source string, verbose bool) Format {
	switch {
	case verbose && source == RawFormatKey:
		format := `{{range .Images}}type: Image
` + NewImageFormat(source, false, true) + `
{{end -}}
{{range .Containers}}type: Container
` + NewContainerFormat(source, false, true) + `
{{end -}}
{{range .Volumes}}type: Volume
` + NewVolumeFormat(source, false) + `
{{end -}}
{{range .BuildCache}}type: Build Cache
` + NewBuildCacheFormat(source, false) + `
{{end -}}`
		return format
	case !verbose && source == TableFormatKey:
		return Format(defaultDiskUsageTableFormat)
	case !verbose && source == RawFormatKey:
		format := `type: {{.Type}}
total: {{.TotalCount}}
active: {{.Active}}
size: {{.Size}}
reclaimable: {{.Reclaimable}}
`
		return Format(format)
	default:
		return Format(source)
	}
}
702947
func (t ToggleFF) Rate(rate int8) Input {
	CheckRate(rate)
	(&t).defaults()
	return NewInput("ToggleFF", rate, 0, 1, t.Trig)
}
173891
func (sin SinOsc) Rate(rate int8) Input {
	CheckRate(rate)
	(&sin).defaults()
	return NewInput("SinOsc", rate, 0, 1, sin.Freq, sin.Phase)
}
765121
func NewFormat(source string, quiet bool) formatter.Format {
	switch source {
	case formatter.TableFormatKey:
		if quiet {
			return formatter.DefaultQuietFormat
		}
		return defaultNetworkTableFormat
	case formatter.RawFormatKey:
		if quiet {
			return `network_id: {{.ID}}`
		}
		return `network_id: {{.ID}}\nname: {{.Name}}\ndriver: {{.Driver}}\nscope: {{.Scope}}\n`
	}
	return formatter.Format(source)
}
151611
func RateScaledInterval(rate float64, min time.Duration, n int) time.Duration {
	if rate <= minRate {
		return min
	}
	interval := time.Duration(float64(time.Second) * float64(n) / rate)
	if interval < min {
		return min
	}

	return interval
}
514360
func NewRateSet() *RateSet {
	rs := new(RateSet)
	rs.m = make(map[time.Duration]*rate)
	return rs
}
1168085
func (vs VarSaw) Rate(rate int8) Input {
	CheckRate(rate)
	(&vs).defaults()
	return NewInput("VarSaw", rate, 0, 1, vs.Freq, vs.IPhase, vs.Width)
}
1118400
func (fp *formatParser) addFormatFunc(
	f func(*LineData, *bytes.Buffer) error, size int,
) {
	fp.commitStatic()
	fp.formatFuncs = append(fp.formatFuncs, f)
	fp.initialSize += size
}