class Module(BaseModule):
    """
    "Parametric equalizer"
    
    Description

    Standard parametric equalizer built with four lowshelf/highshelf/peak/notch filters.
    
    Sliders
    
        # Freq 1 Boost/Cut : 
            Gain of the first EQ
        # Freq 1 : 
            Center frequency of the first EQ
        # Freq 1 Q : 
            Q factor of the first EQ
        # Freq 2 Boost/Cut : 
            Gain of the second EQ
        # Freq 2 : 
            Center frequency of the second EQ
        # Freq 2 Q : 
            Q factor of the second EQ
        # Freq 3 Boost/Cut : 
            Gain of the third EQ
        # Freq 3 : 
            Center frequency of the third EQ
        # Freq 3 Q : 
            Q factor of the third EQ
        # Freq 5 Boost/Cut : 
            Gain of the fourth EQ
        # Freq 4 : 
            Center frequency of the fourth EQ
        # Freq 5 Q : 
            Q factor of the fourth EQ

    Graph Only
    
        # Overall Amplitude : 
            The amplitude curve applied on the total duration of the performance
    
    Popups & Toggles
    
        # EQ Type 1 : 
            EQ type of the first EQ
        # EQ Type 2 : 
            EQ type of the second EQ
        # EQ Type 3 : 
            EQ type of the third EQ
        # EQ Type 4 :
            EQ type of the fourth EQ
        # Balance :
            Compression mode. Off, balanced with a fixed signal
            or balanced with the input source.
        # 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")
        self.eq1 = EQ(self.snd, freq=self.freq1, q=self.freq1q, boost=self.freq1gain, type=self.eq1type_index)
        self.eq2 = EQ(self.eq1, freq=self.freq2, q=self.freq2q, boost=self.freq2gain, type=self.eq2type_index)
        self.eq3 = EQ(self.eq2, freq=self.freq3, q=self.freq3q, boost=self.freq3gain, type=self.eq3type_index)
        self.eq4 = EQ(self.eq3, freq=self.freq4, q=self.freq4q, boost=self.freq4gain, type=self.eq4type_index, mul=self.env)

        self.osc = Sine(10000,mul=.1)
        self.balanced = Balance(self.eq4, self.osc, freq=10)
        self.out = Interp(self.eq4, self.balanced)

#INIT
        self.balance(self.balance_index, self.balance_value)

    def eq1type(self, index, value):
        self.eq1.type = index
    
    def eq2type(self, index, value):
        self.eq2.type = index

    def eq3type(self, index, value):
        self.eq3.type = index

    def eq4type(self, index, value):
        self.eq4.type = index
        
    def balance(self,index,value):
        if index == 0:
            self.out.interp  = 0
        elif index == 1:
            self.out.interp= 1
            self.balanced.input2 = self.osc
        elif index == 2:
            self.out.interp = 1
            self.balanced.input2 = self.snd

Interface = [   csampler(name="snd"), 
                cgraph(name="env", label="Overall Amplitude", func=[(0,1),(1,1)], col="blue"),
                cslider(name="freq1gain", label="Freq 1 Boost/Cut", min=-48, max=24, init=-3, rel="lin", unit="dB", col="purple1"),
                cslider(name="freq1", label="Freq 1", min=1, max=20000, init=500, rel="log", unit="Hz", col="purple1", half=True),
                cslider(name="freq1q", label="Freq 1 Q", min=0.5, max=10, init=0.707, rel="lin", unit="x", col="purple1",half=True),
                cslider(name="freq2gain", label="Freq 2 Boost/Cut", min=-48, max=24, init=-3, rel="lin", unit="dB", col="red"),
                cslider(name="freq2", label="Freq 2", min=1, max=20000, init=1000, rel="log", unit="Hz", col="red", half=True),
                cslider(name="freq2q", label="Freq 2 Q", min=0.5, max=10, init=0.707, rel="lin", unit="x", col="red", half=True),
                cslider(name="freq3gain", label="Freq 3 Boost/Cut", min=-48, max=24, init=-3, rel="lin", unit="dB", col="blue1"),
                cslider(name="freq3", label="Freq 3", min=1, max=20000, init=1500, rel="log", unit="Hz", col="blue1", half=True),
                cslider(name="freq3q", label="Freq 3 Q", min=0.5, max=10, init=0.707, rel="lin", unit="x", col="blue1", half=True),
                cslider(name="freq4gain", label="Freq 4 Boost/Cut", min=-48, max=24, init=-3, rel="lin", unit="dB", col="green1"),
                cslider(name="freq4", label="Freq 4", min=1, max=20000, init=2000, rel="log", unit="Hz", col="green1", half=True),
                cslider(name="freq4q", label="Freq 4 Q", min=0.5, max=10, init=0.707, rel="lin", unit="x", col="green1", half=True),
                cpopup(name="eq1type", label="EQ 1 Type", init="Lowshelf", col="purple1", value=["Peak/Notch", "Lowshelf", "Highshelf"]),
                cpopup(name="eq2type", label="EQ 2 Type", init="Peak/Notch", col="red", value=["Peak/Notch", "Lowshelf", "Highshelf"]),
                cpopup(name="eq3type", label="EQ 3 Type", init="Peak/Notch", col="blue1", value=["Peak/Notch", "Lowshelf", "Highshelf"]),
                cpopup(name="eq4type", label="EQ 4 Type", init="Highshelf", col="green1", value=["Peak/Notch", "Lowshelf", "Highshelf"]),
                cpopup(name="balance", label = "Balance", init= "Off", col="blue", value=["Off","Compress", "Source"]),
                cpoly()
          ]

