classdef AmbiEncoderPlugin < audioPlugin
% AmbiEncoderPlugin Ambisonic encoder plugin
%  This object is used in the "Ambisonic Plugin Generation" featured
%  example.
%
% See also: audiopluginexample.AmbiDecoderPlugin

%   Copyright 2018-2022 The MathWorks, Inc.

%#codegen

    properties
        azimuth1 = 45
        azimuth2 = 135
        azimuth3 = 225
        azimuth4 = 315
        azimuth5 = 45
        azimuth6 = 135
        azimuth7 = 225
        azimuth8 = 315
        elevation1 = -45
        elevation2 = -45
        elevation3 = -45
        elevation4 = -45
        elevation5 = 45
        elevation6 = 45
        elevation7 = 45
        elevation8 = 45
        deviceType1 = 1
        deviceType2 = 1
        deviceType3 = 1
        deviceType4 = 1
        deviceType5 = 1
        deviceType6 = 1
        deviceType7 = 1
        deviceType8 = 1
    end
    % ---------------------------------------------------------------------
    properties
        emtrx = zeros(8,16);
    end
    % ---------------------------------------------------------------------
    properties (Constant)
        PluginInterface = audioPluginInterface( ...
            audioPluginParameter("azimuth1", DisplayName="Azimuth 1", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 1]), ...
            audioPluginParameter("elevation1", DisplayName="Elevation 1", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 1]), ...
            audioPluginParameter("azimuth2", DisplayName="Azimuth 2", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 2]), ...
            audioPluginParameter("elevation2", DisplayName="Elevation 2", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 2]), ...
            audioPluginParameter("azimuth3", DisplayName="Azimuth 3", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 3]), ...
            audioPluginParameter("elevation3", DisplayName="Elevation 3", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 3]), ...
            audioPluginParameter("azimuth4", DisplayName="Azimuth 4", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 4]), ...
            audioPluginParameter("elevation4", DisplayName="Elevation 4", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 4]), ...
            audioPluginParameter("azimuth5", DisplayName="Azimuth 5", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 5]), ...
            audioPluginParameter("elevation5", DisplayName="Elevation 5", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 5]), ...
            audioPluginParameter("azimuth6", DisplayName="Azimuth 6", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 6]), ...
            audioPluginParameter("elevation6", DisplayName="Elevation 6", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 6]), ...
            audioPluginParameter("azimuth7", DisplayName="Azimuth 7", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 7]), ...
            audioPluginParameter("elevation7", DisplayName="Elevation 7", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 7]), ...
            audioPluginParameter("azimuth8", DisplayName="Azimuth 8", ...
                Label="deg", Mapping={"lin",0,360}, Style="rotaryknob", ...
                DisplayNameLocation="below", Layout=[3 8]), ...
            audioPluginParameter("elevation8", DisplayName="Elevation 8", ...
                Label="deg", Mapping={"lin",-90,90}, Style="vslider", ...
                DisplayNameLocation="above", EditBoxLocation="above", Layout=[2 8]), ...
            audioPluginGridLayout(RowHeight=[20 200 100 20], ...
                ColumnWidth=[100 100 100 100 100 100 100 100], ...
                Padding=[10 10 10 30]), ...
            BackgroundImage=audiopluginexample.private.mwatlogo, ...
            PluginName="AmbiEncoderPlugin", ...
            VendorName="MathWorks", ...
            VendorVersion="1.1", ...
            UniqueId="dnIs", ...
            InputChannels=8, ...
            OutputChannels=16);
    end
    % ---------------------------------------------------------------------
    methods
        % -----------------------------------------------------------------
        function obj = AmbiEncoderPlugin()
            obj.emtrx = audioexample.ambisonics.ambiencodemtrx( 3, ...
                [45 135 225 315 45 135 225 315; -45 -45 -45 -45 45 45 45 45; 1 1 1 1 1 1 1 1]);
        end
        % -----------------------------------------------------------------
        function out = process(obj, x)
            out = audioexample.ambisonics.ambiencode(x, obj.emtrx, 'acn-sn3d');
        end
        % -----------------------------------------------------------------
        %#ok<*MCSUP>
        function set.azimuth1(obj, val)
            obj.azimuth1 = val;
            obj.emtrx(1,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation1; obj.deviceType1]);
        end
        function set.azimuth2(obj, val)
            obj.azimuth2 = val;
            obj.emtrx(2,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation2; obj.deviceType2]);
        end
        function set.azimuth3(obj, val)
            obj.azimuth3 = val;
            obj.emtrx(3,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation3; obj.deviceType3]);
        end
        function set.azimuth4(obj, val)
            obj.azimuth4 = val;
            obj.emtrx(4,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation4; obj.deviceType4]);
        end
        function set.azimuth5(obj, val)
            obj.azimuth5 = val;
            obj.emtrx(5,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation5; obj.deviceType5]);
        end
        function set.azimuth6(obj, val)
            obj.azimuth6 = val;
            obj.emtrx(6,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation6; obj.deviceType6]);
        end
        function set.azimuth7(obj, val)
            obj.azimuth7 = val;
            obj.emtrx(7,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation7; obj.deviceType7]);
        end
        function set.azimuth8(obj, val)
            obj.azimuth8 = val;
            obj.emtrx(8,:) = audioexample.ambisonics.ambiencodemtrx(3, [val; obj.elevation8; obj.deviceType8]);
        end
        % -----------------------------------------------------------------
        function set.elevation1(obj, val)
            obj.elevation1 = val;
            obj.emtrx(1,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth1; val; obj.deviceType1]);
        end
        function set.elevation2(obj, val)
            obj.elevation2 = val;
            obj.emtrx(2,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth2; val; obj.deviceType2]);
        end
        function set.elevation3(obj, val)
            obj.elevation3 = val;
            obj.emtrx(3,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth3; val; obj.deviceType3]);
        end
        function set.elevation4(obj, val)
            obj.elevation4 = val;
            obj.emtrx(4,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth4; val; obj.deviceType4]);
        end
        function set.elevation5(obj, val)
            obj.elevation5 = val;
            obj.emtrx(5,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth5; val; obj.deviceType5]);
        end
        function set.elevation6(obj, val)
            obj.elevation6 = val;
            obj.emtrx(6,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth6; val; obj.deviceType6]);
        end
        function set.elevation7(obj, val)
            obj.elevation7 = val;
            obj.emtrx(7,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth7; val; obj.deviceType7]);
        end
        function set.elevation8(obj, val)
            obj.elevation8 = val;
            obj.emtrx(8,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth8; val; obj.deviceType8]);
        end
        % -----------------------------------------------------------------
        function set.deviceType1(obj, val)
            obj.deviceType1 = val;
            obj.emtrx(1,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth1; obj.elevation1; val;]);
        end
        function set.deviceType2(obj, val)
            obj.deviceType2 = val;
            obj.emtrx(2,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth2; obj.elevation2; val;]);
        end
        function set.deviceType3(obj, val)
            obj.deviceType3 = val;
            obj.emtrx(3,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth3; obj.elevation3; val;]);
        end
        function set.deviceType4(obj, val)
            obj.deviceType4 = val;
            obj.emtrx(4,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth4; obj.elevation4; val;]);
        end
        function set.deviceType5(obj, val)
            obj.deviceType5 = val;
            obj.emtrx(5,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth5; obj.elevation5; val;]);
        end
        function set.deviceType6(obj, val)
            obj.deviceType6 = val;
            obj.emtrx(6,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth6; obj.elevation6; val;]);
        end
        function set.deviceType7(obj, val)
            obj.deviceType7 = val;
            obj.emtrx(7,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth7; obj.elevation7; val;]);
        end
        function set.deviceType8(obj, val)
            obj.deviceType8 = val;
            obj.emtrx(8,:) = audioexample.ambisonics.ambiencodemtrx(3, [obj.azimuth8; obj.elevation8; val;]);
        end
    % -----------------------------------------------------------------
    function s = saveobj(obj)
        s = saveobj@audioPlugin(obj);
        s.azimuth1 = obj.azimuth1;
        s.azimuth2 = obj.azimuth2;
        s.azimuth3 = obj.azimuth3;
        s.azimuth4 = obj.azimuth4;
        s.azimuth5 = obj.azimuth5;
        s.azimuth6 = obj.azimuth6;
        s.azimuth7 = obj.azimuth7;
        s.azimuth8 = obj.azimuth8;
        s.elevation1 = obj.elevation1;
        s.elevation2 = obj.elevation2;
        s.elevation3 = obj.elevation3;
        s.elevation4 = obj.elevation4;
        s.elevation5 = obj.elevation5;
        s.elevation6 = obj.elevation6;
        s.elevation7 = obj.elevation7;
        s.elevation8 = obj.elevation8;
        s.deviceType1 = obj.deviceType1;
        s.deviceType2 = obj.deviceType2;
        s.deviceType3 = obj.deviceType3;
        s.deviceType4 = obj.deviceType4;
        s.deviceType5 = obj.deviceType5;
        s.deviceType6 = obj.deviceType6;
        s.deviceType7 = obj.deviceType7;
        s.deviceType8 = obj.deviceType8;
        s.emtrx = obj.emtrx;
    end
    function obj = reload(obj,s)
        obj = reload@audioPlugin(obj,s);
        obj.azimuth1 = s.azimuth1;
        obj.azimuth2 = s.azimuth2;
        obj.azimuth3 = s.azimuth3;
        obj.azimuth4 = s.azimuth4;
        obj.azimuth5 = s.azimuth5;
        obj.azimuth6 = s.azimuth6;
        obj.azimuth7 = s.azimuth7;
        obj.azimuth8 = s.azimuth8;
        obj.elevation1 = s.elevation1;
        obj.elevation2 = s.elevation2;
        obj.elevation3 = s.elevation3;
        obj.elevation4 = s.elevation4;
        obj.elevation5 = s.elevation5;
        obj.elevation6 = s.elevation6;
        obj.elevation7 = s.elevation7;
        obj.elevation8 = s.elevation8;
        obj.deviceType1 = s.deviceType1;
        obj.deviceType2 = s.deviceType2;
        obj.deviceType3 = s.deviceType3;
        obj.deviceType4 = s.deviceType4;
        obj.deviceType5 = s.deviceType5;
        obj.deviceType6 = s.deviceType6;
        obj.deviceType7 = s.deviceType7;
        obj.deviceType8 = s.deviceType8;
        obj.emtrx = s.emtrx;
    end
        % -----------------------------------------------------------------
    end
        methods(Static)
        function obj = loadobj(s)
            if isstruct(s)
                obj = audiopluginexample.AmbiEncoderPlugin;
                obj = reload(obj,s);
            end
        end     
    end
end
