// ZMQ_RATE: Set multicast data rate
//
// See: http://api.zeromq.org/4-1:zmq-setsockopt#toc26
196013
func (soc *Socket) SetRate(value int) error {
	return soc.setInt(C.ZMQ_RATE, value)
}
585816
func (blp BLowPass) Rate(rate int8) Input {
	CheckRate(rate)
	(&blp).defaults()
	return NewInput("BLowPass", rate, 0, 1, blp.In, blp.Freq, blp.RQ)
}
300588
func ZmqRequest(_socket *zmq.Socket, dat ...string) (string, error) {
	_msg := strings.Join(dat, " ")
	_socket.Send([]byte(_msg), 0)
	response, err := _socket.Recv(0)
	return string(response), err
}
588799
func (soc *Socket) SetSwap(value int64) error {
	return soc.setInt64(C.ZMQ_SWAP, value)
}
928701
func (s SoundIn) Rate(rate int8) Input {
	CheckRate(rate)

	var (
		nobs   = NumOutputBuses{}.Rate(IR)
		result Input
	)
	// TODO: simplify this.
	switch x := s.Bus.(type) {
	case C:
		first := NewUgen("In", rate, 0, 1, nobs)

		if x > 0 {
			result = NewUgen("In", rate, 0, 1, nobs.Add(x))
		} else if x == 0 {
			result = first
		} else {
			panic("SoundIn bus indices must not be negative")
		}
	case Inputs:
		var (
			curr   = soundInParams{numOutputs: 1}
			params = []soundInParams{}
			prev   C
		)
		for i, input := range x {
			switch y := input.(type) {
			case C:
				if i == 0 {
					prev = y
					continue
				}
				if prev+1 == y {
					curr.numOutputs++

					if i == len(x)-1 {
						params = append(params, curr)
					}
					continue
				}
				params = append(params, curr)

				if i == len(x)-1 {
					params = append(params, soundInParams{
						startBus:   y,
						numOutputs: 1,
					})
				} else {
					curr = soundInParams{startBus: y, numOutputs: 1}
				}
			default:
				panic("SoundIn busses must be constant or an array of constants")
			}
		}
		arr := make(Inputs, len(params))

		for i, params := range params {
			if params.startBus == 0 {
				arr[i] = NewUgen("In", rate, 0, params.numOutputs, nobs)
			} else {
				arr[i] = NewUgen("In", rate, 0, params.numOutputs, nobs.Add(params.startBus))
			}
		}
		result = arr
	default:
		panic("SoundIn busses must be constant or an array of constants")
	}
	return result
}
1106247
func (r Ringz) Rate(rate int8) Input {
	CheckRate(rate)
	(&r).defaults()
	return NewInput("Ringz", rate, 0, 1, r.In, r.Freq, r.DecayTime)
}
999143
func (jpv JPverb) Rate(rate int8) Input {
	CheckRate(rate)
	if jpv.In == nil {
		panic("JPverb requires an input signal")
	}
	(&jpv).defaults()

	var in1, in2 Input

	switch x := jpv.In.(type) {
	case Inputs:
		if len(x) == 0 {
			panic("JPverb requires an input signal")
		}
		in1, in2 = x[0], x[len(x)-1]
	default:
		in1, in2 = jpv.In, jpv.In
	}
	return NewInput("JPverbRaw", rate, 0, 2, in1, in2, jpv.T60, jpv.Damp, jpv.Size, jpv.EarlyDiff, jpv.ModDepth, jpv.ModFreq, jpv.Low, jpv.Mid, jpv.High, jpv.LowCut, jpv.HighCut)
}
49184
func (maxLocalBufs) Rate(rate int8) Input {
	CheckRate(rate)
	return NewInput("MaxLocalBufs", rate, 0, 1, C(1))
}
1071349
func (lfpulse LFPulse) Rate(rate int8) Input {
	CheckRate(rate)
	(&lfpulse).defaults()
	return NewInput("LFPulse", rate, 0, 1, lfpulse.Freq, lfpulse.IPhase, lfpulse.Width)
}
462907
func (out OffsetOut) Rate(rate int8) Input {
	CheckRate(rate)
	return NewInput("OffsetOut", rate, 0, 1, out.Bus, out.Channels)
}
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
}
720532
func (g GrainSin) Rate(rate int8) Input {
	CheckRate(rate)
	(&g).defaults()

	in := NewInput("GrainSin", rate, 0, 1, g.Trigger, g.Dur, g.Freq, g.Pan, g.EnvBuf, g.MaxGrains)
	if g.NumChannels == 1 {
		return in
	}
	mult := make([]Input, g.NumChannels)
	for i := range mult {
		mult[i] = in
	}
	return Multi(mult...)
}
35450
func (g GrainIn) Rate(rate int8) Input {
	CheckRate(rate)
	if g.In == nil {
		panic("GrainIn requires an input signal")
	}
	(&g).defaults()

	in := NewInput("GrainIn", rate, 0, 1, g.Trigger, g.Dur, g.In, g.Pan, g.EnvBuf, g.MaxGrains)
	if g.NumChannels == 1 {
		return in
	}
	mult := make([]Input, g.NumChannels)
	for i := range mult {
		mult[i] = in
	}
	return Multi(mult...)
}
238944
func (wrp Warp1) Rate(rate int8) Input {
	CheckRate(rate)
	(&wrp).defaults()
	return NewInput("Warp1", rate, 0, wrp.NumChannels, wrp.BufNum, wrp.Pointer, wrp.FreqScale, wrp.WindowSize, wrp.EnvBufNum, wrp.Overlaps, wrp.WindowRandRatio, wrp.Interp)
}
112866
func (delay Delay) Rate(rate int8) Input {
	CheckRate(rate)
	if delay.In == nil {
		panic("Delay expects In to not be nil")
	}
	if delay.MaxDelayTime == nil {
		delay.MaxDelayTime = C(0.2)
	}
	if delay.DelayTime == nil {
		delay.DelayTime = C(0.2)
	}
	switch delay.Interpolation {
	case InterpolationNone:
		return NewInput("DelayN", rate, 0, 1, delay.In, delay.MaxDelayTime, delay.DelayTime)
	case InterpolationLinear:
		return NewInput("DelayL", rate, 0, 1, delay.In, delay.MaxDelayTime, delay.DelayTime)
	case InterpolationCubic:
		return NewInput("DelayC", rate, 0, 1, delay.In, delay.MaxDelayTime, delay.DelayTime)
	default:
		panic(fmt.Errorf("invalid interpolation %d", delay.Interpolation))
	}
}
180200
func (lftri LFTri) Rate(rate int8) Input {
	CheckRate(rate)
	(&lftri).defaults()
	return NewInput("LFTri", rate, 0, 1, lftri.Freq, lftri.Iphase)
}
895193
func ZmqRequestSocket(ip string, request_ports []int) *zmq.Socket {
	context, _ := zmq.NewContext()
	socket, _ := context.NewSocket(zmq.REQ)
	for _, _port := range request_ports {
		socket.Connect(fmt.Sprintf("tcp://%s:%d", ip, _port))
	}
	return socket
}