classdef equalizerV2 < audioPlugin
    properties
        GainLow = 0
        FreqLow = sqrt(20*500)
        GainMid = 0
        FreqMid = sqrt(500*3e3)
        GainHigh = 0
        FreqHigh = sqrt(3e3*20e3)
        Volume = 1;
        Enable = true;
    end
    properties (Constant)
        PluginInterface = audioPluginInterface( ...
            audioPluginParameter('GainLow', ...
                'Label','dB', ...
                'Mapping',{'lin',-20,20}, ...
                'Style','vslider', ...                                     %<--
                'Layout',[2,1;4,1], ...                                    %<--
                'DisplayName','Low','DisplayNameLocation','Above'), ...    %<--
            audioPluginParameter('FreqLow', ...
                'Label','Hz', ...
                'Mapping',{'log',20,500}, ...
                'Style','rotaryknob', ...                                  %<--
                'Layout',[5,1], ...                                        %<--
                'DisplayNameLocation','None'), ...                         %<--
            audioPluginParameter('GainMid', ...
                'Label','dB', ...
                'Mapping',{'lin',-20,20}, ...
                'Style','vslider', ...                                     %<--
                'Layout',[2,2;4,2], ...                                    %<--
                'DisplayNameLocation','None'), ...                         %<--
            audioPluginParameter('FreqMid', ...
                'Label','Hz', ...
                'Mapping',{'log',500,3e3}, ...
                'Style','rotaryknob', ...                                  %<--
                'Layout',[5,2], ...                                        %<--
                'DisplayNameLocation','None'), ...                         %<--
            audioPluginParameter('GainHigh', ...
                'Label','dB', ...
                'Mapping',{'lin',-20,20}, ...
                'Style','vslider', ...                                     %<--
                'Layout',[2,3;4,3], ...                                    %<--
                'DisplayName','High','DisplayNameLocation','Above'), ...   %<--
            audioPluginParameter('FreqHigh', ...
                'Label','Hz', ...
                'Mapping',{'log',3e3,20e3}, ...
                'Style','rotaryknob', ...                                  %<--
                'Layout',[5,3], ...                                        %<--
                'DisplayNameLocation','None'), ...                         %<--
            audioPluginParameter('Volume', ...
                'Mapping',{'lin',0,2}, ...
                'Style','rotaryknob', ...                                  %<--
                'Layout',[3,5], ...                                        %<--
                'DisplayNameLocation','Above'), ...                        %<--
            audioPluginParameter('Enable', ...
                'Style','vtoggle', ...                                     %<--
                'Layout',[5,5], ...                                        %<--
                'DisplayNameLocation','None'), ...                         %<--
                ...
            audioPluginGridLayout( ...                                     %<--
                'RowHeight',[20,20,160,20,100], ...                        %<--
                'ColumnWidth',[100,100,100,50,150], ...                    %<--
                'Padding',[10,10,10,10]))                                  %<--
    end
    properties (Access = private)
        mPEQ
    end
    methods
        function obj = equalizerV2
            obj.mPEQ = multibandParametricEQ('HasHighpassFilter',false, ...
                'HasLowShelfFilter',false,'HasHighShelfFilter',false, ...
                'HasLowpassFilter',false,'Oversample',false,'NumEQBands',3, ...
                'EQOrder',2);
        end
        function y = process(obj, x)
            if obj.Enable
                y = step(obj.mPEQ,x);
                y = y*obj.Volume;
            else
                y = x;
            end
        end
        function reset(obj)
            obj.mPEQ.SampleRate = getSampleRate(obj);
            reset(obj.mPEQ);
        end
        function set.FreqLow(obj,val)
            obj.FreqLow = val;
            obj.mPEQ.Frequencies(1) = val; %#ok<*MCSUP>
        end
        function set.GainLow(obj,val)
            obj.GainLow = val;
            obj.mPEQ.PeakGains(1) = val;
        end
        function set.FreqMid(obj,val)
            obj.FreqMid = val;
            obj.mPEQ.Frequencies(2) = val;
        end
        function set.GainMid(obj,val)
            obj.GainMid = val;
            obj.mPEQ.PeakGains(2) = val;
        end
        function set.FreqHigh(obj,val)
            obj.FreqHigh = val;
            obj.mPEQ.Frequencies(3) = val;
        end
        function set.GainHigh(obj,val)
            obj.GainHigh = val;
            obj.mPEQ.PeakGains(3) = val;
        end
    end
end