classdef app < matlab.apps.AppBase

    % Properties that correspond to app components
    properties (Access = public)
        UIFigure                       matlab.ui.Figure
        GridLayout                     matlab.ui.container.GridLayout
        LeftPanel                      matlab.ui.container.Panel
        SRClocationEditField           matlab.ui.control.EditField
        SRClocationEditFieldLabel      matlab.ui.control.Label
        DutySpinner_2                  matlab.ui.control.Spinner
        DutySpinner_2Label             matlab.ui.control.Label
        PhaseSpinner_2                 matlab.ui.control.Spinner
        PhaseSpinner_2Label            matlab.ui.control.Label
        FrequencySpinner_2             matlab.ui.control.Spinner
        FrequencySpinner_2Label        matlab.ui.control.Label
        AmplitudeSpinner_2             matlab.ui.control.Spinner
        AmplitudeSpinner_2Label        matlab.ui.control.Label
        DutySpinner                    matlab.ui.control.Spinner
        DutySpinnerLabel               matlab.ui.control.Label
        DurationSpinner                matlab.ui.control.Spinner
        DurationSpinnerLabel           matlab.ui.control.Label
        PhaseSpinner                   matlab.ui.control.Spinner
        PhaseSpinnerLabel              matlab.ui.control.Label
        SamplingFsSpinner              matlab.ui.control.Spinner
        SamplingFsSpinnerLabel         matlab.ui.control.Label
        FrequencySpinner               matlab.ui.control.Spinner
        FrequencySpinnerLabel          matlab.ui.control.Label
        AmplitudeSpinner               matlab.ui.control.Spinner
        AmplitudeSpinnerLabel          matlab.ui.control.Label
        MiddleSpinner                  matlab.ui.control.Spinner
        MiddleSpinnerLabel             matlab.ui.control.Label
        AdditionalFilterDropDown       matlab.ui.control.DropDown
        AdditionalFilterDropDownLabel  matlab.ui.control.Label
        CeilingSpinner_2               matlab.ui.control.Spinner
        CeilingSpinner_2Label          matlab.ui.control.Label
        FloorSpinner_2                 matlab.ui.control.Spinner
        FloorSpinner_2Label            matlab.ui.control.Label
        Generator2DropDown             matlab.ui.control.DropDown
        Generator2DropDownLabel        matlab.ui.control.Label
        Generator1DropDown             matlab.ui.control.DropDown
        Generator1DropDownLabel        matlab.ui.control.Label
        CeilingSpinner                 matlab.ui.control.Spinner
        CeilingSpinnerLabel            matlab.ui.control.Label
        FloorSpinner                   matlab.ui.control.Spinner
        FloorSpinnerLabel              matlab.ui.control.Label
        BandPassFilterLabel            matlab.ui.control.Label
        CenterPanel                    matlab.ui.container.Panel
        RecordButton                   matlab.ui.control.Button
        PauseButton                    matlab.ui.control.Button
        PlayButton                     matlab.ui.control.Button
        UIAxes_4                       matlab.ui.control.UIAxes
        UIAxes_3                       matlab.ui.control.UIAxes
        UIAxes_2                       matlab.ui.control.UIAxes
        UIAxes2                        matlab.ui.control.UIAxes
        UIAxes                         matlab.ui.control.UIAxes
        RightPanel                     matlab.ui.container.Panel
        AmpEnvelopeDropDown            matlab.ui.control.DropDown
        AmpEnvelopeDropDownLabel       matlab.ui.control.Label
        PitchEnvelopeDropDownLabel     matlab.ui.control.Label
        PitchEnvelopeDropDown          matlab.ui.control.DropDown
        A_RelSlider                    matlab.ui.control.Slider
        RelSlider_3Label               matlab.ui.control.Label
        A_SusSlider                    matlab.ui.control.Slider
        SusSlider_3Label               matlab.ui.control.Label
        A_DecaySlider                  matlab.ui.control.Slider
        DecaySlider_3Label             matlab.ui.control.Label
        A_AttackSlider                 matlab.ui.control.Slider
        AttackSlider_3Label            matlab.ui.control.Label
        P_RelSlider                    matlab.ui.control.Slider
        RelSlider_2Label               matlab.ui.control.Label
        P_SusSlider                    matlab.ui.control.Slider
        SusSlider_2Label               matlab.ui.control.Label
        P_DecaySlider                  matlab.ui.control.Slider
        DecaySlider_2Label             matlab.ui.control.Label
        P_AttackSlider                 matlab.ui.control.Slider
        AttackSlider_2Label            matlab.ui.control.Label
        ModulationLabel                matlab.ui.control.Label
        LFOLabel                       matlab.ui.control.Label
        OscFreqSpinner                 matlab.ui.control.Spinner
        OscFreqSpinnerLabel            matlab.ui.control.Label
    end

    % Properties that correspond to apps with auto-reflow
    properties (Access = private)
        onePanelWidth = 576;
        twoPanelWidth = 768;
    end

    
    properties (Access = public)
        Property % Description
        play = 0;
    end
    
    methods (Access = public)
        function results = func(app)
            %Basic Example test 
            %Written by Darell
            fs = app.SamplingFsSpinner.Value();
            duration = app.DurationSpinner.Value();
            
            tdomain = 0:1/fs:(duration - 1/fs); %to plot against t     
            Len = length(tdomain);
            Fdomain = fs * (-Len/2 : (Len/2 - 1))/Len ; %to plot against F
            FTtestinput = 100 * ones([1,Len]);
            
            %Sound Bite generator 
            amplitude = app.AmplitudeSpinner.Value();
            frequency = app.FrequencySpinner.Value();
            phase = app.PhaseSpinner.Value();
            
            duty = app.DutySpinner.Value();
            number = app.Generator1DropDown.Value();
            x = SoundGeneratorSelect(amplitude, frequency, phase, fs, duration, duty,number);
            
            amplitude = app.AmplitudeSpinner_2.Value();
            frequency = app.FrequencySpinner_2.Value();
            phase = app.PhaseSpinner_2.Value();
            duty = app.DutySpinner_2.Value();
            number = app.Generator2DropDown.Value();
            x = x + SoundGeneratorSelect(amplitude, frequency, phase, fs, duration, duty,number);
            
            
            %Band Pass Filter
            LOW = app.FloorSpinner.Value();
            HIGH = app.CeilingSpinner.Value();
            MED = "unused";

            new_x = DarellbandpassFilter(x,fs,LOW,MED,HIGH);
            fttestinput = ifft(FTtestinput);
            fttestoutput = DarellbandpassFilter(fttestinput,fs,LOW,MED,HIGH);
            
            FilterEnv = fftshift(fft(fttestoutput));
            plot(app.UIAxes_3,Fdomain,FilterEnv)
            
            x = new_x;
            
            %Amplitude Envelope
            attack = app.A_AttackSlider.Value();
            decay = app.A_DecaySlider.Value();
            sustain = app.A_SusSlider.Value();
            release = app.A_RelSlider.Value();
            
            number = app.AmpEnvelopeDropDown.Value();
            new_x = AmpEnvelopeSelect(x, fs, attack,decay,sustain,release,number); %output new sound in time domain
           
            AmplitudeEnv = new_x ./ x;
            plot(app.UIAxes_2,tdomain,AmplitudeEnv)
            plot(app.UIAxes,tdomain,new_x)
            
            after_freq = fftshift(fft(new_x));    
            plot(app.UIAxes2,Fdomain,after_freq)

            app.play_continuous_inapp(new_x, fs)


        end
        
        function play_continuous_inapp(app, wave, fs)
            soundfile = audioplayer(wave,fs);
            while app.play > 0 %change to counts/while play button active
                playblocking(soundfile);
            end
        end
        
    end
    

    % Callbacks that handle component events
    methods (Access = private)

        % Code that executes after component creation
        function startupFcn(app)
            cd(string(app.SRClocationEditField.Value()));
            app.play = 0;
        end

        % Callback function
        function PitchEnvelopeListBoxValueChanged(app, event)
            value = app.PitchEnvelopeListBox.Value;
            
        end

        % Changes arrangement of the app based on UIFigure width
        function updateAppLayout(app, event)
            currentFigureWidth = app.UIFigure.Position(3);
            if(currentFigureWidth <= app.onePanelWidth)
                % Change to a 3x1 grid
                app.GridLayout.RowHeight = {639, 639, 639};
                app.GridLayout.ColumnWidth = {'1x'};
                app.CenterPanel.Layout.Row = 1;
                app.CenterPanel.Layout.Column = 1;
                app.LeftPanel.Layout.Row = 2;
                app.LeftPanel.Layout.Column = 1;
                app.RightPanel.Layout.Row = 3;
                app.RightPanel.Layout.Column = 1;
            elseif (currentFigureWidth > app.onePanelWidth && currentFigureWidth <= app.twoPanelWidth)
                % Change to a 2x2 grid
                app.GridLayout.RowHeight = {639, 639};
                app.GridLayout.ColumnWidth = {'1x', '1x'};
                app.CenterPanel.Layout.Row = 1;
                app.CenterPanel.Layout.Column = [1,2];
                app.LeftPanel.Layout.Row = 2;
                app.LeftPanel.Layout.Column = 1;
                app.RightPanel.Layout.Row = 2;
                app.RightPanel.Layout.Column = 2;
            else
                % Change to a 1x3 grid
                app.GridLayout.RowHeight = {'1x'};
                app.GridLayout.ColumnWidth = {220, '1x', 220};
                app.LeftPanel.Layout.Row = 1;
                app.LeftPanel.Layout.Column = 1;
                app.CenterPanel.Layout.Row = 1;
                app.CenterPanel.Layout.Column = 2;
                app.RightPanel.Layout.Row = 1;
                app.RightPanel.Layout.Column = 3;
            end
        end

        % Button pushed function: PlayButton
        function PlayButtonPushed(app, event)
            app.play = 1;
            app.func()
        end

        % Button pushed function: PauseButton
        function PauseButtonPushed(app, event)
            app.play = 0;
        end
    end

    % Component initialization
    methods (Access = private)

        % Create UIFigure and components
        function createComponents(app)

            % Create UIFigure and hide until all components are created
            app.UIFigure = uifigure('Visible', 'off');
            app.UIFigure.AutoResizeChildren = 'off';
            app.UIFigure.Position = [100 100 860 639];
            app.UIFigure.Name = 'MATLAB App';
            app.UIFigure.SizeChangedFcn = createCallbackFcn(app, @updateAppLayout, true);

            % Create GridLayout
            app.GridLayout = uigridlayout(app.UIFigure);
            app.GridLayout.ColumnWidth = {220, '1x', 220};
            app.GridLayout.RowHeight = {'1x'};
            app.GridLayout.ColumnSpacing = 0;
            app.GridLayout.RowSpacing = 0;
            app.GridLayout.Padding = [0 0 0 0];
            app.GridLayout.Scrollable = 'on';

            % Create LeftPanel
            app.LeftPanel = uipanel(app.GridLayout);
            app.LeftPanel.Layout.Row = 1;
            app.LeftPanel.Layout.Column = 1;

            % Create BandPassFilterLabel
            app.BandPassFilterLabel = uilabel(app.LeftPanel);
            app.BandPassFilterLabel.FontWeight = 'bold';
            app.BandPassFilterLabel.Position = [10 215 100 22];
            app.BandPassFilterLabel.Text = 'Band-Pass Filter';

            % Create FloorSpinnerLabel
            app.FloorSpinnerLabel = uilabel(app.LeftPanel);
            app.FloorSpinnerLabel.HorizontalAlignment = 'right';
            app.FloorSpinnerLabel.Position = [35 194 33 22];
            app.FloorSpinnerLabel.Text = 'Floor';

            % Create FloorSpinner
            app.FloorSpinner = uispinner(app.LeftPanel);
            app.FloorSpinner.Step = 100;
            app.FloorSpinner.Limits = [0 Inf];
            app.FloorSpinner.Position = [83 194 100 22];
            app.FloorSpinner.Value = 20;

            % Create CeilingSpinnerLabel
            app.CeilingSpinnerLabel = uilabel(app.LeftPanel);
            app.CeilingSpinnerLabel.HorizontalAlignment = 'right';
            app.CeilingSpinnerLabel.Position = [26 173 42 22];
            app.CeilingSpinnerLabel.Text = 'Ceiling';

            % Create CeilingSpinner
            app.CeilingSpinner = uispinner(app.LeftPanel);
            app.CeilingSpinner.Step = 100;
            app.CeilingSpinner.Limits = [0 Inf];
            app.CeilingSpinner.Position = [83 173 100 22];
            app.CeilingSpinner.Value = 20000;

            % Create Generator1DropDownLabel
            app.Generator1DropDownLabel = uilabel(app.LeftPanel);
            app.Generator1DropDownLabel.HorizontalAlignment = 'right';
            app.Generator1DropDownLabel.FontWeight = 'bold';
            app.Generator1DropDownLabel.Position = [9 504 73 22];
            app.Generator1DropDownLabel.Text = 'Generator 1';

            % Create Generator1DropDown
            app.Generator1DropDown = uidropdown(app.LeftPanel);
            app.Generator1DropDown.Position = [96 504 100 22];

            % Create Generator2DropDownLabel
            app.Generator2DropDownLabel = uilabel(app.LeftPanel);
            app.Generator2DropDownLabel.HorizontalAlignment = 'right';
            app.Generator2DropDownLabel.FontWeight = 'bold';
            app.Generator2DropDownLabel.Position = [9 370 73 22];
            app.Generator2DropDownLabel.Text = 'Generator 2';

            % Create Generator2DropDown
            app.Generator2DropDown = uidropdown(app.LeftPanel);
            app.Generator2DropDown.Items = {'Option 1', 'Option 2', 'Option 3', 'Option 4', 'NIL'};
            app.Generator2DropDown.Position = [96 370 100 22];
            app.Generator2DropDown.Value = 'NIL';

            % Create FloorSpinner_2Label
            app.FloorSpinner_2Label = uilabel(app.LeftPanel);
            app.FloorSpinner_2Label.HorizontalAlignment = 'right';
            app.FloorSpinner_2Label.Position = [40 96 33 22];
            app.FloorSpinner_2Label.Text = 'Floor';

            % Create FloorSpinner_2
            app.FloorSpinner_2 = uispinner(app.LeftPanel);
            app.FloorSpinner_2.Step = 100;
            app.FloorSpinner_2.Position = [88 96 100 22];

            % Create CeilingSpinner_2Label
            app.CeilingSpinner_2Label = uilabel(app.LeftPanel);
            app.CeilingSpinner_2Label.HorizontalAlignment = 'right';
            app.CeilingSpinner_2Label.Position = [31 55 42 22];
            app.CeilingSpinner_2Label.Text = 'Ceiling';

            % Create CeilingSpinner_2
            app.CeilingSpinner_2 = uispinner(app.LeftPanel);
            app.CeilingSpinner_2.Step = 100;
            app.CeilingSpinner_2.Position = [88 55 100 22];
            app.CeilingSpinner_2.Value = 22000;

            % Create AdditionalFilterDropDownLabel
            app.AdditionalFilterDropDownLabel = uilabel(app.LeftPanel);
            app.AdditionalFilterDropDownLabel.HorizontalAlignment = 'right';
            app.AdditionalFilterDropDownLabel.FontWeight = 'bold';
            app.AdditionalFilterDropDownLabel.Position = [8 120 96 22];
            app.AdditionalFilterDropDownLabel.Text = 'Additional Filter';

            % Create AdditionalFilterDropDown
            app.AdditionalFilterDropDown = uidropdown(app.LeftPanel);
            app.AdditionalFilterDropDown.Items = {'Option 1', 'Option 2', 'Option 3', 'Option 4', 'NIL'};
            app.AdditionalFilterDropDown.Position = [118 120 94 22];
            app.AdditionalFilterDropDown.Value = 'NIL';

            % Create MiddleSpinnerLabel
            app.MiddleSpinnerLabel = uilabel(app.LeftPanel);
            app.MiddleSpinnerLabel.HorizontalAlignment = 'right';
            app.MiddleSpinnerLabel.Position = [31 75 42 22];
            app.MiddleSpinnerLabel.Text = 'Middle';

            % Create MiddleSpinner
            app.MiddleSpinner = uispinner(app.LeftPanel);
            app.MiddleSpinner.Step = 100;
            app.MiddleSpinner.Position = [88 75 100 22];
            app.MiddleSpinner.Value = 11000;

            % Create AmplitudeSpinnerLabel
            app.AmplitudeSpinnerLabel = uilabel(app.LeftPanel);
            app.AmplitudeSpinnerLabel.HorizontalAlignment = 'right';
            app.AmplitudeSpinnerLabel.Position = [10 482 60 22];
            app.AmplitudeSpinnerLabel.Text = 'Amplitude';

            % Create AmplitudeSpinner
            app.AmplitudeSpinner = uispinner(app.LeftPanel);
            app.AmplitudeSpinner.Step = 100;
            app.AmplitudeSpinner.Limits = [0 Inf];
            app.AmplitudeSpinner.Position = [85 482 100 22];
            app.AmplitudeSpinner.Value = 1;

            % Create FrequencySpinnerLabel
            app.FrequencySpinnerLabel = uilabel(app.LeftPanel);
            app.FrequencySpinnerLabel.HorizontalAlignment = 'right';
            app.FrequencySpinnerLabel.Position = [8 461 62 22];
            app.FrequencySpinnerLabel.Text = 'Frequency';

            % Create FrequencySpinner
            app.FrequencySpinner = uispinner(app.LeftPanel);
            app.FrequencySpinner.Step = 100;
            app.FrequencySpinner.Limits = [0 Inf];
            app.FrequencySpinner.Position = [85 461 100 22];
            app.FrequencySpinner.Value = 200;

            % Create SamplingFsSpinnerLabel
            app.SamplingFsSpinnerLabel = uilabel(app.LeftPanel);
            app.SamplingFsSpinnerLabel.HorizontalAlignment = 'right';
            app.SamplingFsSpinnerLabel.Position = [16 558 72 22];
            app.SamplingFsSpinnerLabel.Text = 'Sampling Fs';

            % Create SamplingFsSpinner
            app.SamplingFsSpinner = uispinner(app.LeftPanel);
            app.SamplingFsSpinner.Step = 100;
            app.SamplingFsSpinner.Limits = [0 Inf];
            app.SamplingFsSpinner.Position = [103 558 100 22];
            app.SamplingFsSpinner.Value = 44800;

            % Create PhaseSpinnerLabel
            app.PhaseSpinnerLabel = uilabel(app.LeftPanel);
            app.PhaseSpinnerLabel.HorizontalAlignment = 'right';
            app.PhaseSpinnerLabel.Position = [31 439 39 22];
            app.PhaseSpinnerLabel.Text = 'Phase';

            % Create PhaseSpinner
            app.PhaseSpinner = uispinner(app.LeftPanel);
            app.PhaseSpinner.Step = 100;
            app.PhaseSpinner.Limits = [0 Inf];
            app.PhaseSpinner.Position = [85 439 100 22];

            % Create DurationSpinnerLabel
            app.DurationSpinnerLabel = uilabel(app.LeftPanel);
            app.DurationSpinnerLabel.HorizontalAlignment = 'right';
            app.DurationSpinnerLabel.Position = [37 537 51 22];
            app.DurationSpinnerLabel.Text = 'Duration';

            % Create DurationSpinner
            app.DurationSpinner = uispinner(app.LeftPanel);
            app.DurationSpinner.Step = 100;
            app.DurationSpinner.Limits = [0 Inf];
            app.DurationSpinner.Position = [103 537 100 22];
            app.DurationSpinner.Value = 1;

            % Create DutySpinnerLabel
            app.DutySpinnerLabel = uilabel(app.LeftPanel);
            app.DutySpinnerLabel.HorizontalAlignment = 'right';
            app.DutySpinnerLabel.Position = [40 418 30 22];
            app.DutySpinnerLabel.Text = 'Duty';

            % Create DutySpinner
            app.DutySpinner = uispinner(app.LeftPanel);
            app.DutySpinner.Step = 100;
            app.DutySpinner.Limits = [0 Inf];
            app.DutySpinner.Position = [85 418 100 22];
            app.DutySpinner.Value = 0.01;

            % Create AmplitudeSpinner_2Label
            app.AmplitudeSpinner_2Label = uilabel(app.LeftPanel);
            app.AmplitudeSpinner_2Label.HorizontalAlignment = 'right';
            app.AmplitudeSpinner_2Label.Position = [11 348 60 22];
            app.AmplitudeSpinner_2Label.Text = 'Amplitude';

            % Create AmplitudeSpinner_2
            app.AmplitudeSpinner_2 = uispinner(app.LeftPanel);
            app.AmplitudeSpinner_2.Step = 100;
            app.AmplitudeSpinner_2.Limits = [0 Inf];
            app.AmplitudeSpinner_2.Position = [86 348 100 22];
            app.AmplitudeSpinner_2.Value = 1;

            % Create FrequencySpinner_2Label
            app.FrequencySpinner_2Label = uilabel(app.LeftPanel);
            app.FrequencySpinner_2Label.HorizontalAlignment = 'right';
            app.FrequencySpinner_2Label.Position = [9 327 62 22];
            app.FrequencySpinner_2Label.Text = 'Frequency';

            % Create FrequencySpinner_2
            app.FrequencySpinner_2 = uispinner(app.LeftPanel);
            app.FrequencySpinner_2.Step = 100;
            app.FrequencySpinner_2.Limits = [0 Inf];
            app.FrequencySpinner_2.Position = [86 327 100 22];
            app.FrequencySpinner_2.Value = 202;

            % Create PhaseSpinner_2Label
            app.PhaseSpinner_2Label = uilabel(app.LeftPanel);
            app.PhaseSpinner_2Label.HorizontalAlignment = 'right';
            app.PhaseSpinner_2Label.Position = [32 306 39 22];
            app.PhaseSpinner_2Label.Text = 'Phase';

            % Create PhaseSpinner_2
            app.PhaseSpinner_2 = uispinner(app.LeftPanel);
            app.PhaseSpinner_2.Step = 100;
            app.PhaseSpinner_2.Limits = [0 Inf];
            app.PhaseSpinner_2.Position = [86 306 100 22];

            % Create DutySpinner_2Label
            app.DutySpinner_2Label = uilabel(app.LeftPanel);
            app.DutySpinner_2Label.HorizontalAlignment = 'right';
            app.DutySpinner_2Label.Position = [41 285 30 22];
            app.DutySpinner_2Label.Text = 'Duty';

            % Create DutySpinner_2
            app.DutySpinner_2 = uispinner(app.LeftPanel);
            app.DutySpinner_2.Step = 100;
            app.DutySpinner_2.Limits = [0 Inf];
            app.DutySpinner_2.Position = [86 285 100 22];
            app.DutySpinner_2.Value = 0.01;

            % Create SRClocationEditFieldLabel
            app.SRClocationEditFieldLabel = uilabel(app.LeftPanel);
            app.SRClocationEditFieldLabel.HorizontalAlignment = 'right';
            app.SRClocationEditFieldLabel.FontWeight = 'bold';
            app.SRClocationEditFieldLabel.Position = [14 609 83 22];
            app.SRClocationEditFieldLabel.Text = 'SRC location:';

            % Create SRClocationEditField
            app.SRClocationEditField = uieditfield(app.LeftPanel, 'text');
            app.SRClocationEditField.Position = [20 588 183 22];
            app.SRClocationEditField.Value = '/Users/DarellCHUA/Documents/GitHub/ece45-project/src';

            % Create CenterPanel
            app.CenterPanel = uipanel(app.GridLayout);
            app.CenterPanel.Layout.Row = 1;
            app.CenterPanel.Layout.Column = 2;

            % Create UIAxes
            app.UIAxes = uiaxes(app.CenterPanel);
            title(app.UIAxes, 'Time Domain')
            xlabel(app.UIAxes, 'X')
            ylabel(app.UIAxes, 'Y')
            zlabel(app.UIAxes, 'Z')
            app.UIAxes.Position = [203 391 211 240];

            % Create UIAxes2
            app.UIAxes2 = uiaxes(app.CenterPanel);
            title(app.UIAxes2, 'Frequency Domain')
            xlabel(app.UIAxes2, 'X')
            ylabel(app.UIAxes2, 'Y')
            zlabel(app.UIAxes2, 'Z')
            app.UIAxes2.Position = [203 120 211 251];

            % Create UIAxes_2
            app.UIAxes_2 = uiaxes(app.CenterPanel);
            title(app.UIAxes_2, 'Amplitude Envelope')
            xlabel(app.UIAxes_2, 'X')
            ylabel(app.UIAxes_2, 'Y')
            zlabel(app.UIAxes_2, 'Z')
            app.UIAxes_2.Position = [6 483 189 148];

            % Create UIAxes_3
            app.UIAxes_3 = uiaxes(app.CenterPanel);
            title(app.UIAxes_3, 'Filter')
            xlabel(app.UIAxes_3, 'X')
            ylabel(app.UIAxes_3, 'Y')
            zlabel(app.UIAxes_3, 'Z')
            app.UIAxes_3.Position = [6 312 189 172];

            % Create UIAxes_4
            app.UIAxes_4 = uiaxes(app.CenterPanel);
            title(app.UIAxes_4, 'Pitch Envelope')
            xlabel(app.UIAxes_4, 'X')
            ylabel(app.UIAxes_4, 'Y')
            zlabel(app.UIAxes_4, 'Z')
            app.UIAxes_4.Position = [6 120 189 193];

            % Create PlayButton
            app.PlayButton = uibutton(app.CenterPanel, 'push');
            app.PlayButton.ButtonPushedFcn = createCallbackFcn(app, @PlayButtonPushed, true);
            app.PlayButton.Position = [38 56 100 22];
            app.PlayButton.Text = 'Play';

            % Create PauseButton
            app.PauseButton = uibutton(app.CenterPanel, 'push');
            app.PauseButton.ButtonPushedFcn = createCallbackFcn(app, @PauseButtonPushed, true);
            app.PauseButton.Position = [162 56 100 22];
            app.PauseButton.Text = 'Pause';

            % Create RecordButton
            app.RecordButton = uibutton(app.CenterPanel, 'push');
            app.RecordButton.Position = [292 56 100 22];
            app.RecordButton.Text = 'Record';

            % Create RightPanel
            app.RightPanel = uipanel(app.GridLayout);
            app.RightPanel.Layout.Row = 1;
            app.RightPanel.Layout.Column = 3;

            % Create OscFreqSpinnerLabel
            app.OscFreqSpinnerLabel = uilabel(app.RightPanel);
            app.OscFreqSpinnerLabel.HorizontalAlignment = 'right';
            app.OscFreqSpinnerLabel.Position = [25 567 55 22];
            app.OscFreqSpinnerLabel.Text = 'Osc Freq';

            % Create OscFreqSpinner
            app.OscFreqSpinner = uispinner(app.RightPanel);
            app.OscFreqSpinner.Limits = [0 20];
            app.OscFreqSpinner.Position = [95 567 100 22];

            % Create LFOLabel
            app.LFOLabel = uilabel(app.RightPanel);
            app.LFOLabel.FontWeight = 'bold';
            app.LFOLabel.Position = [10 588 29 22];
            app.LFOLabel.Text = 'LFO';

            % Create ModulationLabel
            app.ModulationLabel = uilabel(app.RightPanel);
            app.ModulationLabel.FontSize = 14;
            app.ModulationLabel.FontWeight = 'bold';
            app.ModulationLabel.Position = [69 609 81 22];
            app.ModulationLabel.Text = 'Modulation';

            % Create AttackSlider_2Label
            app.AttackSlider_2Label = uilabel(app.RightPanel);
            app.AttackSlider_2Label.HorizontalAlignment = 'right';
            app.AttackSlider_2Label.Position = [1 516 40 22];
            app.AttackSlider_2Label.Text = 'Attack';

            % Create P_AttackSlider
            app.P_AttackSlider = uislider(app.RightPanel);
            app.P_AttackSlider.Limits = [0 1];
            app.P_AttackSlider.Position = [62 525 135 3];
            app.P_AttackSlider.Value = 0.2;

            % Create DecaySlider_2Label
            app.DecaySlider_2Label = uilabel(app.RightPanel);
            app.DecaySlider_2Label.HorizontalAlignment = 'right';
            app.DecaySlider_2Label.Position = [2 474 39 22];
            app.DecaySlider_2Label.Text = 'Decay';

            % Create P_DecaySlider
            app.P_DecaySlider = uislider(app.RightPanel);
            app.P_DecaySlider.Limits = [0 1];
            app.P_DecaySlider.Position = [62 483 135 3];
            app.P_DecaySlider.Value = 0.2;

            % Create SusSlider_2Label
            app.SusSlider_2Label = uilabel(app.RightPanel);
            app.SusSlider_2Label.HorizontalAlignment = 'right';
            app.SusSlider_2Label.Position = [15 432 26 22];
            app.SusSlider_2Label.Text = 'Sus';

            % Create P_SusSlider
            app.P_SusSlider = uislider(app.RightPanel);
            app.P_SusSlider.Limits = [0 1];
            app.P_SusSlider.Position = [62 441 135 3];
            app.P_SusSlider.Value = 0.8;

            % Create RelSlider_2Label
            app.RelSlider_2Label = uilabel(app.RightPanel);
            app.RelSlider_2Label.HorizontalAlignment = 'right';
            app.RelSlider_2Label.Position = [16 391 25 22];
            app.RelSlider_2Label.Text = 'Rel';

            % Create P_RelSlider
            app.P_RelSlider = uislider(app.RightPanel);
            app.P_RelSlider.Limits = [0 1];
            app.P_RelSlider.Position = [62 400 135 3];
            app.P_RelSlider.Value = 0.2;

            % Create AttackSlider_3Label
            app.AttackSlider_3Label = uilabel(app.RightPanel);
            app.AttackSlider_3Label.HorizontalAlignment = 'right';
            app.AttackSlider_3Label.Position = [2 320 40 22];
            app.AttackSlider_3Label.Text = 'Attack';

            % Create A_AttackSlider
            app.A_AttackSlider = uislider(app.RightPanel);
            app.A_AttackSlider.Limits = [0 1];
            app.A_AttackSlider.Position = [63 329 135 3];
            app.A_AttackSlider.Value = 0.2;

            % Create DecaySlider_3Label
            app.DecaySlider_3Label = uilabel(app.RightPanel);
            app.DecaySlider_3Label.HorizontalAlignment = 'right';
            app.DecaySlider_3Label.Position = [3 278 39 22];
            app.DecaySlider_3Label.Text = 'Decay';

            % Create A_DecaySlider
            app.A_DecaySlider = uislider(app.RightPanel);
            app.A_DecaySlider.Limits = [0 1];
            app.A_DecaySlider.Position = [63 287 135 3];
            app.A_DecaySlider.Value = 0.2;

            % Create SusSlider_3Label
            app.SusSlider_3Label = uilabel(app.RightPanel);
            app.SusSlider_3Label.HorizontalAlignment = 'right';
            app.SusSlider_3Label.Position = [16 236 26 22];
            app.SusSlider_3Label.Text = 'Sus';

            % Create A_SusSlider
            app.A_SusSlider = uislider(app.RightPanel);
            app.A_SusSlider.Limits = [0 1];
            app.A_SusSlider.Position = [63 245 135 3];
            app.A_SusSlider.Value = 0.8;

            % Create RelSlider_3Label
            app.RelSlider_3Label = uilabel(app.RightPanel);
            app.RelSlider_3Label.HorizontalAlignment = 'right';
            app.RelSlider_3Label.Position = [17 195 25 22];
            app.RelSlider_3Label.Text = 'Rel';

            % Create A_RelSlider
            app.A_RelSlider = uislider(app.RightPanel);
            app.A_RelSlider.Limits = [0 1];
            app.A_RelSlider.Position = [63 204 135 3];
            app.A_RelSlider.Value = 0.2;

            % Create PitchEnvelopeDropDown
            app.PitchEnvelopeDropDown = uidropdown(app.RightPanel);
            app.PitchEnvelopeDropDown.Items = {'Option 1', 'Option 2', 'Option 3', 'Option 4', 'NIL'};
            app.PitchEnvelopeDropDown.Position = [106 537 100 22];
            app.PitchEnvelopeDropDown.Value = 'NIL';

            % Create PitchEnvelopeDropDownLabel
            app.PitchEnvelopeDropDownLabel = uilabel(app.RightPanel);
            app.PitchEnvelopeDropDownLabel.HorizontalAlignment = 'right';
            app.PitchEnvelopeDropDownLabel.FontWeight = 'bold';
            app.PitchEnvelopeDropDownLabel.Position = [1 537 91 22];
            app.PitchEnvelopeDropDownLabel.Text = 'Pitch Envelope';

            % Create AmpEnvelopeDropDownLabel
            app.AmpEnvelopeDropDownLabel = uilabel(app.RightPanel);
            app.AmpEnvelopeDropDownLabel.HorizontalAlignment = 'right';
            app.AmpEnvelopeDropDownLabel.FontWeight = 'bold';
            app.AmpEnvelopeDropDownLabel.Position = [1 341 88 22];
            app.AmpEnvelopeDropDownLabel.Text = 'Amp Envelope';

            % Create AmpEnvelopeDropDown
            app.AmpEnvelopeDropDown = uidropdown(app.RightPanel);
            app.AmpEnvelopeDropDown.Items = {'Option 1', 'Option 2', 'Option 3', 'Option 4', 'NIL'};
            app.AmpEnvelopeDropDown.Position = [103 341 100 22];
            app.AmpEnvelopeDropDown.Value = 'NIL';

            % Show the figure after all components are created
            app.UIFigure.Visible = 'on';
        end
    end

    % App creation and deletion
    methods (Access = public)

        % Construct app
        function app = app

            % Create UIFigure and components
            createComponents(app)

            % Register the app with App Designer
            registerApp(app, app.UIFigure)

            % Execute the startup function
            runStartupFcn(app, @startupFcn)

            if nargout == 0
                clear app
            end
        end

        % Code that executes before app deletion
        function delete(app)

            % Delete UIFigure when app is deleted
            delete(app.UIFigure)
        end
    end
end