Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- classdef DebugApp < matlab.apps.AppBase
- % Properties that correspond to app components
- properties (Access = public)
- UIFigure matlab.ui.Figure
- AChordButton matlab.ui.control.Button
- CChordButton matlab.ui.control.Button
- AmChordButton matlab.ui.control.Button
- DChordButton matlab.ui.control.Button
- D7ChordButton matlab.ui.control.Button
- EButton_2 matlab.ui.control.Button
- AButton matlab.ui.control.Button
- DButton matlab.ui.control.Button
- GButton matlab.ui.control.Button
- BButton matlab.ui.control.Button
- EButton_7 matlab.ui.control.Button
- EChordButton matlab.ui.control.Button
- EmChordButton matlab.ui.control.Button
- FChordButton matlab.ui.control.Button
- GChordButton matlab.ui.control.Button
- VolumeSliderLabel matlab.ui.control.Label
- VolumeSlider matlab.ui.control.Slider
- SustainSliderLabel matlab.ui.control.Label
- SustainSlider matlab.ui.control.Slider
- DistortionSwitchLabel matlab.ui.control.Label
- DistortionSwitch matlab.ui.control.RockerSwitch
- TremoloSwitchLabel matlab.ui.control.Label
- TremoloSwitch matlab.ui.control.RockerSwitch
- WahWahSwitchLabel matlab.ui.control.Label
- WahWahSwitch matlab.ui.control.RockerSwitch
- end
- properties (Access = private)
- Fs = 44100;
- Volume = 0.5;
- Gain = 0.498;
- Distortion = -1;
- Tremolo = -1;
- WahWah = -1;
- E2 = 534;
- A2 = 400;
- D3 = 299;
- G3 = 224;
- B3 = 177;
- E4 = 133;
- %Chord A
- AE3 = 267;
- AA3 = 199;
- ACS4 = 158;
- %Chord Am
- AmC4 = 167;
- %Chord C
- CC3 = 335;
- %Chord D
- DD4 = 149;
- DFS4 = 118;
- %Chord E
- EB2 = 356;
- EAb3 = 211;
- %Chord F
- FF3 = 252;
- FF4 = 125;
- %Chord G
- GG2 = 445;
- GG4 = 224;
- end
- methods (Access = private)
- function Pluck(app, ~, N, g)
- if ~exist('g','var')
- g = 0;
- end
- duration = 500; %100
- gain = app.Gain - g;
- x = 2*randi([0 1], fix(N), 1)-1; %Random noise burst
- x(x>0) = x(x>0)-(1-app.Volume); %Change volume
- x(x<0) = x(x<0)+(1-app.Volume);
- rx = x; %Real input
- x = [x; zeros(length(x)*duration, 1)]; %Make input longer
- out = [rx; zeros(length(x)*5,1)]; %Initialise empty output channel
- prev = out(length(rx)); %Previous sample value
- for n = length(rx)+1:length(out) %Only modify after noise burst
- %Add lowpass filter and to delayed channel.
- out(n) = (out(n-length(rx)) + prev)*gain;
- prev = out(n);
- end
- if app.Distortion == 1
- out = app.Distort(out);
- end
- if app.Tremolo == 1
- out = app.ApplyTremolo(out);
- end
- if app.WahWah == 1
- out = app.ApplyWahWah(out);
- end
- sound(out, app.Fs);
- end
- function out = Distort(app, out)
- out = out*50;
- out(out>1) = 1 * app.Volume;
- out(out<-1) = -1 * app.Volume;
- end
- function out = ApplyTremolo(app, out)
- t = [1:length(out)] * (1/app.Fs);
- t = t(:);
- LFO = sin(20* t);
- out = out.*LFO;
- end
- function out = ApplyWahWah(app, out)
- t = [1:length(out)*5] * (1/app.Fs);
- t = t(:);
- LFO = sin(20 * t)*200;
- channel = out;
- for n = 1:length(out)
- if n-fix(LFO(n)) > 1
- out(n) = out(n) + channel(n-fix(LFO(n)));
- end
- end
- end
- end
- methods (Access = private)
- % Button pushed function: EButton_2
- function EButton_2Pushed(app, event)
- app.Pluck(app, app.E2);
- end
- % Button pushed function: AButton
- function AButtonPushed(app, event)
- app.Pluck(app, app.A2);
- end
- % Button pushed function: DButton
- function DButtonPushed(app, event)
- app.Pluck(app, app.D3);
- end
- % Button pushed function: GButton
- function GButtonPushed(app, event)
- app.Pluck(app, app.G3);
- end
- % Button pushed function: BButton
- function BButtonPushed(app, event)
- app.Pluck(app, app.B3);
- end
- % Button pushed function: EButton_7
- function EButton_7Pushed(app, event)
- app.Pluck(app, app.E4);
- end
- % Button pushed function: AChordButton
- function AChordButtonPushed(app, event)
- app.Pluck(app, app.E2, 0.01);
- app.Pluck(app, app.A2);
- app.Pluck(app, app.AE3);
- app.Pluck(app, app.AA3);
- app.Pluck(app, app.ACS4);
- app.Pluck(app, app.E4);
- end
- % Button pushed function: AmChordButton
- function AmChordButtonPushed(app, event)
- app.Pluck(app, app.A2);
- app.Pluck(app, app.AE3);
- app.Pluck(app, app.AA3);
- app.Pluck(app, app.AmC4);
- app.Pluck(app, app.E4);
- end
- % Button pushed function: CChordButton
- function CChordButtonPushed(app, event)
- app.Pluck(app, app.CC3);
- app.Pluck(app, app.AE3);
- app.Pluck(app, app.G3);
- app.Pluck(app, app.AmC4);
- app.Pluck(app, app.E4);
- end
- % Button pushed function: DChordButton
- function DChordButtonPushed(app, event)
- app.Pluck(app, app.A2, 0.01);
- app.Pluck(app, app.D3);
- app.Pluck(app, app.AA3);
- app.Pluck(app, app.DD4);
- app.Pluck(app, app.DFS4);
- end
- % Button pushed function: EChordButton
- function EChordButtonPushed(app, event)
- app.Pluck(app, app.E2, 0.01);
- app.Pluck(app, app.EB2);
- app.Pluck(app, app.AE3);
- app.Pluck(app, app.EAb3);
- app.Pluck(app, app.B3);
- app.Pluck(app, app.E4);
- end
- % Button pushed function: EmChordButton
- function EmChordButtonPushed(app, event)
- app.Pluck(app, app.E2, 0.01);
- app.Pluck(app, app.EB2);
- app.Pluck(app, app.AE3);
- app.Pluck(app, app.G3);
- app.Pluck(app, app.B3);
- app.Pluck(app, app.E4);
- end
- % Button pushed function: FChordButton
- function FChordButtonPushed(app, event)
- app.Pluck(app, app.A2, 0.01);
- app.Pluck(app, app.FF3);
- app.Pluck(app, app.AA3);
- app.Pluck(app, app.AmC4);
- app.Pluck(app, app.FF4);
- end
- % Button pushed function: GChordButton
- function GChordButtonPushed(app, event)
- app.Pluck(app, app.GG2, 0.01);
- app.Pluck(app, app.EB2);
- app.Pluck(app, app.D3);
- app.Pluck(app, app.G3);
- app.Pluck(app, app.DD4);
- app.Pluck(app, app.GG4);
- end
- % Button pushed function: D7ChordButton
- function D7ChordButtonPushed(app, event)
- app.Pluck(app, app.A2, 0.01);
- app.Pluck(app, app.D3);
- app.Pluck(app, app.AA3);
- app.Pluck(app, app.AmC4);
- app.Pluck(app, app.DFS4);
- end
- % Value changed function: VolumeSlider
- function VolumeSliderValueChanged(app, event)
- app.Volume = app.VolumeSlider.Value;
- end
- % Value changed function: SustainSlider
- function SustainSliderValueChanged(app, event)
- app.Gain = app.SustainSlider.Value;
- end
- % Value changed function: DistortionSwitch
- function DistortionSwitchValueChanged(app, event)
- app.Distortion = app.Distortion*-1;
- end
- % Value changed function: TremoloSwitch
- function TremoloSwitchValueChanged(app, event)
- app.Tremolo = app.Tremolo*-1;
- end
- % Value changed function: WahWahSwitch
- function WahWahSwitchValueChanged(app, event)
- app.WahWah = app.WahWah*-1;
- end
- end
- % App initialization and construction
- methods (Access = private)
- % Create UIFigure and components
- function createComponents(app)
- % Create UIFigure
- app.UIFigure = uifigure;
- app.UIFigure.Position = [100 100 648 420];
- app.UIFigure.Name = 'UI Figure';
- % Create AChordButton
- app.AChordButton = uibutton(app.UIFigure, 'push');
- app.AChordButton.ButtonPushedFcn = createCallbackFcn(app, @AChordButtonPushed, true);
- app.AChordButton.Position = [34 337 90 56];
- app.AChordButton.Text = 'A Chord';
- % Create CChordButton
- app.CChordButton = uibutton(app.UIFigure, 'push');
- app.CChordButton.ButtonPushedFcn = createCallbackFcn(app, @CChordButtonPushed, true);
- app.CChordButton.Position = [232 337 90 56];
- app.CChordButton.Text = 'C Chord';
- % Create AmChordButton
- app.AmChordButton = uibutton(app.UIFigure, 'push');
- app.AmChordButton.ButtonPushedFcn = createCallbackFcn(app, @AmChordButtonPushed, true);
- app.AmChordButton.Position = [133 337 90 56];
- app.AmChordButton.Text = 'Am Chord';
- % Create DChordButton
- app.DChordButton = uibutton(app.UIFigure, 'push');
- app.DChordButton.ButtonPushedFcn = createCallbackFcn(app, @DChordButtonPushed, true);
- app.DChordButton.Position = [331 337 90 56];
- app.DChordButton.Text = 'D Chord';
- % Create D7ChordButton
- app.D7ChordButton = uibutton(app.UIFigure, 'push');
- app.D7ChordButton.ButtonPushedFcn = createCallbackFcn(app, @D7ChordButtonPushed, true);
- app.D7ChordButton.Position = [430 337 90 56];
- app.D7ChordButton.Text = 'D7 Chord';
- % Create EButton_2
- app.EButton_2 = uibutton(app.UIFigure, 'push');
- app.EButton_2.ButtonPushedFcn = createCallbackFcn(app, @EButton_2Pushed, true);
- app.EButton_2.Position = [144 219 50 42];
- app.EButton_2.Text = 'E';
- % Create AButton
- app.AButton = uibutton(app.UIFigure, 'push');
- app.AButton.ButtonPushedFcn = createCallbackFcn(app, @AButtonPushed, true);
- app.AButton.Position = [209 219 50 42];
- app.AButton.Text = 'A';
- % Create DButton
- app.DButton = uibutton(app.UIFigure, 'push');
- app.DButton.ButtonPushedFcn = createCallbackFcn(app, @DButtonPushed, true);
- app.DButton.Position = [274 219 50 42];
- app.DButton.Text = 'D';
- % Create GButton
- app.GButton = uibutton(app.UIFigure, 'push');
- app.GButton.ButtonPushedFcn = createCallbackFcn(app, @GButtonPushed, true);
- app.GButton.Position = [339 219 50 42];
- app.GButton.Text = 'G';
- % Create BButton
- app.BButton = uibutton(app.UIFigure, 'push');
- app.BButton.ButtonPushedFcn = createCallbackFcn(app, @BButtonPushed, true);
- app.BButton.Position = [404 219 50 42];
- app.BButton.Text = 'B';
- % Create EButton_7
- app.EButton_7 = uibutton(app.UIFigure, 'push');
- app.EButton_7.ButtonPushedFcn = createCallbackFcn(app, @EButton_7Pushed, true);
- app.EButton_7.Position = [469 219 50 42];
- app.EButton_7.Text = 'E';
- % Create EChordButton
- app.EChordButton = uibutton(app.UIFigure, 'push');
- app.EChordButton.ButtonPushedFcn = createCallbackFcn(app, @EChordButtonPushed, true);
- app.EChordButton.Position = [529 337 90 56];
- app.EChordButton.Text = 'E Chord';
- % Create EmChordButton
- app.EmChordButton = uibutton(app.UIFigure, 'push');
- app.EmChordButton.ButtonPushedFcn = createCallbackFcn(app, @EmChordButtonPushed, true);
- app.EmChordButton.Position = [183 270 90 56];
- app.EmChordButton.Text = 'Em Chord';
- % Create FChordButton
- app.FChordButton = uibutton(app.UIFigure, 'push');
- app.FChordButton.ButtonPushedFcn = createCallbackFcn(app, @FChordButtonPushed, true);
- app.FChordButton.Position = [282 270 90 56];
- app.FChordButton.Text = 'F Chord';
- % Create GChordButton
- app.GChordButton = uibutton(app.UIFigure, 'push');
- app.GChordButton.ButtonPushedFcn = createCallbackFcn(app, @GChordButtonPushed, true);
- app.GChordButton.Position = [380 270 90 56];
- app.GChordButton.Text = 'G Chord';
- % Create VolumeSliderLabel
- app.VolumeSliderLabel = uilabel(app.UIFigure);
- app.VolumeSliderLabel.HorizontalAlignment = 'right';
- app.VolumeSliderLabel.Position = [34 60 46 22];
- app.VolumeSliderLabel.Text = 'Volume';
- % Create VolumeSlider
- app.VolumeSlider = uislider(app.UIFigure);
- app.VolumeSlider.Limits = [0 1];
- app.VolumeSlider.MajorTicks = [0 1];
- app.VolumeSlider.MajorTickLabels = {'Min', 'Max', ''};
- app.VolumeSlider.ValueChangedFcn = createCallbackFcn(app, @VolumeSliderValueChanged, true);
- app.VolumeSlider.Position = [101 69 506 3];
- app.VolumeSlider.Value = 0.5;
- % Create SustainSliderLabel
- app.SustainSliderLabel = uilabel(app.UIFigure);
- app.SustainSliderLabel.HorizontalAlignment = 'right';
- app.SustainSliderLabel.Position = [34 114 46 22];
- app.SustainSliderLabel.Text = 'Sustain';
- % Create SustainSlider
- app.SustainSlider = uislider(app.UIFigure);
- app.SustainSlider.Limits = [0.49 0.50005];
- app.SustainSlider.MajorTicks = [0.46 0.50005];
- app.SustainSlider.MajorTickLabels = {'Min', 'Max', ''};
- app.SustainSlider.ValueChangedFcn = createCallbackFcn(app, @SustainSliderValueChanged, true);
- app.SustainSlider.Position = [101 123 505 3];
- app.SustainSlider.Value = 0.498;
- % Create DistortionSwitchLabel
- app.DistortionSwitchLabel = uilabel(app.UIFigure);
- app.DistortionSwitchLabel.HorizontalAlignment = 'center';
- app.DistortionSwitchLabel.Position = [447 145 56 22];
- app.DistortionSwitchLabel.Text = 'Distortion';
- % Create DistortionSwitch
- app.DistortionSwitch = uiswitch(app.UIFigure, 'rocker');
- app.DistortionSwitch.Orientation = 'horizontal';
- app.DistortionSwitch.ValueChangedFcn = createCallbackFcn(app, @DistortionSwitchValueChanged, true);
- app.DistortionSwitch.Position = [452 175 45 20];
- % Create TremoloSwitchLabel
- app.TremoloSwitchLabel = uilabel(app.UIFigure);
- app.TremoloSwitchLabel.HorizontalAlignment = 'center';
- app.TremoloSwitchLabel.Position = [313 145 49 22];
- app.TremoloSwitchLabel.Text = 'Tremolo';
- % Create TremoloSwitch
- app.TremoloSwitch = uiswitch(app.UIFigure, 'rocker');
- app.TremoloSwitch.Orientation = 'horizontal';
- app.TremoloSwitch.ValueChangedFcn = createCallbackFcn(app, @TremoloSwitchValueChanged, true);
- app.TremoloSwitch.Position = [314 175 45 20];
- % Create WahWahSwitchLabel
- app.WahWahSwitchLabel = uilabel(app.UIFigure);
- app.WahWahSwitchLabel.HorizontalAlignment = 'center';
- app.WahWahSwitchLabel.Position = [160.5 145 58 22];
- app.WahWahSwitchLabel.Text = 'Wah-Wah';
- % Create WahWahSwitch
- app.WahWahSwitch = uiswitch(app.UIFigure, 'rocker');
- app.WahWahSwitch.Orientation = 'horizontal';
- app.WahWahSwitch.ValueChangedFcn = createCallbackFcn(app, @WahWahSwitchValueChanged, true);
- app.WahWahSwitch.Position = [166 175 45 20];
- end
- end
- methods (Access = public)
- % Construct app
- function app = DebugApp
- % Create and configure components
- createComponents(app)
- % Register the app with App Designer
- registerApp(app, app.UIFigure)
- 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
Add Comment
Please, Sign In to add comment