class Module(BaseModule):
    """
    "Sound looper bank with independant pitch and amplitude random"
    
    Description

    Huge oscillator bank (up to 500 players) looping a soundfile stored in a waveform 
    table. The frequencies and amplitudes can be modulated by two random generators 
    with interpolation (each partial have a different set of randoms).
    
    Sliders

        # Transposition : 
            Transposition of the base frequency of the process, given by the sound length.
        # Frequency Spread : 
            Coefficient of expansion used to compute partial frequencies. If 0, all 
            partials will be at the base frequency. A value of 1 will generate integer 
            harmonics, a value of 2 will skip even harmonics and non-integer values will 
            generate different series of inharmonic frequencies.
        # Amplitude Slope : 
            Specifies the multiplier in the series of amplitude coefficients.
        # Boost / Cut : 
            Controls the overall amplitude.
        # Freq Rand Speed : 
            Frequency, in cycle per second, of the frequency modulations.
        # Freq Rand Gain : 
            Maximum frequency deviation (positive and negative) in portion of the partial 
            frequency. A value of 1 means that the frequency can drift from 0 Hz to twice 
            the partial frequency. A value of 0 deactivates the frequency deviations.
        # Amp Rand Speed : 
            Frequency, in cycle per second, of the amplitude modulations.
        # Amp Rand Gain : 
            Amount of amplitude deviation. 0 deactivates the amplitude modulations 
            and 1 gives full amplitude modulations.
        # Voices Per Channel : 
            Number of loopers created for each output channel. Changes will be 
            effective on next start.
    
    Graph Only
    
        # Overall Amplitude : 
            The amplitude curve applied on the total duration of the performance

    Popups & Toggles
    
        # Partials Freq Jitter : 
            If active, a small jitter is added to the frequency of each partial. For a 
            large number of oscillators and a very small `Frequency Spread`, the
            periodicity between partial frequencies can cause very strange artefact. 
            Adding a jitter breaks the periodicity.
    
    """
    def __init__(self):
        BaseModule.__init__(self)
        self.snd = self.addFilein("snd")
        self.gain = DBToA(self.boost, mul=self.env)
        self.transpo = CentsToTranspo(self.pitch, mul=self.snd.getRate())
        self.out = OscBank(self.snd, self.transpo, self.spread, self.slope, self.frndf, self.frnda, self.arndf, self.arnda, 
                           [int(self.num.get())]*self.nchnls, self.fjit_value, self.gain).out()

    def num_up(self, value):
        pass

    def fjit(self, value):
        self.out.fjit = value

Interface = [   cfilein(name="snd"), 
                cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
                cslider(name="pitch", label="Transposition", min=-4800, max=4800, init=0, rel="lin", unit="cnts", col="green1"),
                cslider(name="spread", label="Frequency Spread", min=0, max=2, init=0.002, rel="lin", unit="x", col="green2"),
                cslider(name="slope", label="Amplitude Slope", min=0, max=1, init=0.9, rel="lin", unit="x", col="red1"),
                cslider(name="boost", label="Boost / Cut", min=-32, max=32, init=0, rel="lin", unit="dB", col="red2"),
                cslider(name="frndf", label="Freq Rand Speed", min=0.001, max=20, init=1, rel="log", unit="Hz", col="green3", half=True),
                cslider(name="arndf", label="Amp Rand Speed", min=0.001, max=20, init=1, rel="log", unit="Hz", col="red3", half=True),
                cslider(name="frnda", label="Freq Rand Gain", min=0, max=1, init=0, rel="lin", unit="x", col="green4", half=True),
                cslider(name="arnda", label="Amp Rand Gain", min=0, max=1, init=0, rel="lin", unit="x", col="red4", half=True),
                cslider(name="num", label="Voices Per Channel", min=1, max=500, init=100, rel="lin", res="int", unit="x", up=True),
                ctoggle(name="fjit", label="Partials Freq Jitter", init=False, col="green1"),
          ]