class Module(BaseModule):
    """
    "Multi-band frequency shifter module"

    Description

    MultiBandFreqShift implements four separated spectral band 
    frequency shifters with independent amount of shift and gain.
    
    Sliders
    
        # Frequency Splitter : 
            Split points for multi-band processing
        # Freq Shift Band 1 : 
            Shift frequency of first band
        # Gain Band 1 : 
            Gain of the shifted first band
        # Freq Shift Band 2 : 
            Shift frequency of second band
        # Gain Band 2 : 
            Gain of the shifted second band
        # Freq Shift Band 3 : 
            Shift frequency of third band
        # Gain Band 3 : 
            Gain of the shifted third band
        # Freq Shift Band 4 : 
            Shift frequency of fourth band
        # Gain Band 5 : 
            Gain of the shifted fourth band
        # Dry / Wet : 
            Mix between the original signal and the shifted signals

    Graph Only
    
        # Overall Amplitude : 
            The amplitude curve applied on the total duration of the performance
    
    Popups & Toggles
    
        # Polyphony Voices : 
            Number of voices played simultaneously (polyphony), 
            only available at initialization time
        # Polyphony Spread : 
            Pitch variation between voices (chorus), 
            only available at initialization time
    
    """
    def __init__(self):
        BaseModule.__init__(self)
        self.snd = self.addSampler("snd")
        freqs = self.splitter.get(True)
        self.FBfade = SigTo(value=1, time=.01, init=1)
        self.split = FourBand(input=self.snd, freq1=freqs[0], freq2=freqs[1], freq3=freqs[2], mul=self.FBfade)
        self.shifts = self.duplicate([self.shift1,self.shift2,self.shift3,self.shift4], len(self.snd))
        self.mul1 = DBToA(self.gain1)
        self.mul2 = DBToA(self.gain2)
        self.mul3 = DBToA(self.gain3)
        self.mul4 = DBToA(self.gain4)
        self.muls = self.duplicate([self.mul1,self.mul2,self.mul3,self.mul4], len(self.snd))
        self.realups = FreqShift(self.split, self.shifts, self.muls)
        self.out = Interp(self.snd, self.realups, self.drywet, mul=self.env*0.2)

    def splitter_up(self, value):
        self.FBfade.value = 0
        time.sleep(.02)
        self.split.freq1 = value[0]
        self.split.freq2 = value[1]
        self.split.freq3 = value[2]
        time.sleep(.02)
        self.FBfade.value = 1

Interface = [   csampler(name="snd"), 
                cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue1"),
                csplitter(name="splitter", label="Frequency Splitter", min=100, max=18000, init=[150, 500, 2000], 
                          num_knobs=3, rel="log", gliss=0, up=True, unit="Hz", col="grey"),
                cslider(name="shift1", label="Freq Shift Band 1", min=-2000, max=2000, init=600, rel="lin", unit="Hz", col="purple1", half=True),
                cslider(name="gain1", label="Gain Band 1", min=-48, max=18, init=0, rel="lin", unit="dB", col="purple2", half=True),
                cslider(name="shift2", label="Freq Shift Band 2", min=-2000, max=2000, init=500, rel="lin", unit="Hz", col="red1", half=True),
                cslider(name="gain2", label="Gain Band 2", min=-48, max=18, init=0, rel="lin", unit="dB", col="red2", half=True),
                cslider(name="shift3", label="Freq Shift Band 3", min=-2000, max=2000, init=400, rel="lin", unit="Hz", col="green1", half=True),
                cslider(name="gain3", label="Gain Band 3", min=-48, max=18, init=0, rel="lin", unit="dB", col="green2", half=True),
                cslider(name="shift4", label="Freq Shift Band 4", min=-2000, max=2000, init=300, rel="lin", unit="Hz", col="orange1", half=True),
                cslider(name="gain4", label="Gain Band 4", min=-48, max=18, init=0, rel="lin", unit="dB", col="orange2", half=True),
                cslider(name="drywet", label="Dry / Wet", min=0, max=1, init=1, rel="lin", unit="x", col="blue1"),
                cpoly()
          ]

