SlideShare ist ein Scribd-Unternehmen logo
1 von 15
Downloaden Sie, um offline zu lesen
PIANO KEYBOARD APPLICATION
Using MATLAB R2018a
SUBMITTED BY
DIVYANSHU CHHABRA
AYUSH DEVAL (17105049)
Objective/Aim
The aim/objective of this project is to create a Piano Keyboard App that can produce musical
notes in three different waveforms i.e., Sine waveform, Square waveform and Sawtooth
waveform. The app should be able to record the previously played musical notes or a
musical pattern and should also be able to set the tempo of the notes. The app must have
several options for 1/8th note, 1/4th note, 1/2th note and 1 note for user comfortability of
producing a melody.
Theory
MATLAB: MATLAB (matrix laboratory) is a multi-paradigm numerical computing
environment and proprietary programming language developed by MathWorks. MATLAB
allows matrix manipulations, plotting of functions and data, implementation of algorithms,
creation of user interfaces, and interfacing with programs written in other languages,
including C, C++, C#, Java, Fortran and Python.
Although MATLAB is intended primarily for numerical computing, an optional toolbox uses
the MuPAD symbolic engine, allowing access to symbolic computing abilities. An additional
package, Simulink, adds graphical multi-domain simulation and model-based design for
dynamic and embedded systems.
GUIs: GUIs (also known as graphical user interfaces or UIs) provide point-and-click control of
software applications, eliminating the need to learn a language or type commands in order
to run the application.
MATLAB® apps are self-contained MATLAB programs with GUI front ends that automate a
task or calculation. The GUI typically contains controls such as menus, toolbars, buttons, and
sliders. Many MATLAB products, such as Curve Fitting Toolbox™, Signal Processing Toolbox™,
and Control System Toolbox™ include apps with custom user interfaces. You can also create
your own custom apps, including their corresponding UIs, for others to use.
DIGITAL PIANO: Digital pianos are also non-acoustic and do not have strings or hammers.
They use digital sampling technology to reproduce the acoustic sound of each piano note
accurately. They also must be connected to a power amplifier and speaker to produce sound
(however, most digital pianos have a built-in amp and speaker). Alternatively, a person can
practice with headphones to avoid disturbing others. Digital pianos can include sustain
pedals, weighted or semi-weighted keys, multiple voice options (e.g., sampled or synthesized
imitations of electric piano, Hammond organ, violin, etc.), and MIDI interfaces.
MUSICAL SOUNDS: Musical sounds are vibrations which are strongly regular. When you
hear a regular vibration, your ear detects the frequency, and you perceive this as the pitch of
a musical tone.
There are two main properties of a regular
vibration - the amplitude and the frequency - which
affect the way it sounds.
Amplitude is the size of the vibration, and this
determines how loud the sound is. We have already seen that larger vibrations make a
louder sound.
Amplitude is important when balancing and controlling the loudness of sounds, such as with
the volume control on your CD player. It is also the origin of the word amplifier, a device
which increases the amplitude of a waveform.
Frequency is the speed of the vibration, and this determines the pitch of the sound. It is only
useful or meaningful for musical sounds, where there is a strongly regular waveform.
Frequency is measured as the number of wave cycles that occur in one second. The unit of
frequency measurement is Hertz (Hz for short).
A frequency of 1 Hz means one wave cycle per second. A frequency of 10 Hz means ten
wave cycles per second, where the cycles are much shorter and closer together.
The note A which is above Middle C (more on this later) has a frequency of 440 Hz. It is often
used as a reference frequency for tuning musical instruments. Frequency of the musical
notes are in the following table.
Working of Piano Keyboard Application
The application checks the key pressed on the piano and then produces its sound based on
its frequency programmed in the app.
• Time_Callback() function sets the rate of the musical note production in terms of beats
per minute (bpm)
• SinWave_Callback() function produces the sound of the pressed note in sine
waveform.
• SquareWave_Callback() function produces the sound of the pressed note in square
waveform.
• SawtoothWave_Callback() function produces the sound of the pressed note in
sawtooth waveform.
GUI and its produced code
GUI of Piano Keyboard Application
GUI Code
function varargout = piano2(varargin)
% PIANO2 M-file for piano2.fig
% PIANO2, by itself, creates a new PIANO2 or raises the existing
% singleton*.
%
% H = PIANO2 returns the handle to a new PIANO2 or the handle to
% the existing singleton*.
%
% PIANO2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PIANO2.M with the given input arguments.
%
% PIANO2('Property','Value',...) creates a new PIANO2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before piano2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to piano2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to he lp piano2
% Last Modified by GUIDE v2.5 24-Apr-2019 14:32:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @piano2_OpeningFcn, ...
'gui_OutputFcn', @piano2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% AUTHOR: MARK FRANKOSKY (MFRANKOSKY@GMAIL.COM)
% --- Executes just before piano2 is made visible.
function piano2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to piano2 (see VARARGIN)
% Choose default command line output for piano2
handles.output = hObject;
handles.SampleRate = 1/20000;
handles.SoundVector = 0;
handles.TimeValue = 0.3488;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes piano2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = piano2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in GShparp3.
function GShparp3_Callback(hObject, eventdata, handles)
% hObject handle to GShparp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 207.65;
PlayNote(handles,freq);
% --- Executes on button press in ASharp3.
function ASharp3_Callback(hObject, eventdata, handles)
% hObject handle to ASharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 233.08;
PlayNote(handles,freq);
% --- Executes on button press in FSharp5.
function FSharp5_Callback(hObject, eventdata, handles)
% hObject handle to FSharp5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 739.99;
PlayNote(handles,freq);
% --- Executes on button press in FSharp3.
function FSharp3_Callback(hObject, eventdata, handles)
% hObject handle to FSharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 185.00;
PlayNote(handles,freq);
% --- Executes on button press in ASharp4.
function ASharp4_Callback(hObject, eventdata, handles)
% hObject handle to ASharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 466.16;
PlayNote(handles,freq);
% --- Executes on button press in DSharp5.
function DSharp5_Callback(hObject, eventdata, handles)
% hObject handle to DSharp5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 622.25;
PlayNote(handles,freq);
% --- Executes on button press in CSharp5.
function CSharp5_Callback(hObject, eventdata, handles)
% hObject handle to CSharp5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 554.37;
PlayNote(handles,freq);
% --- Executes on button press in GSharp4.
function GSharp4_Callback(hObject, eventdata, handles)
% hObject handle to GSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 415.3;
PlayNote(handles,freq);
% --- Executes on button press in CSharp4.
function CSharp4_Callback(hObject, eventdata, handles)
% hObject handle to CSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 277.18;
PlayNote(handles,freq);
% --- Executes on button press in G3.
function G3_Callback(hObject, eventdata, handles)
% hObject handle to G3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 196;
PlayNote(handles,freq);
% --- Executes on button press in A3.
function A3_Callback(hObject, eventdata, handles)
% hObject handle to A3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 220;
PlayNote(handles,freq);
% --- Executes on button press in B3.
function B3_Callback(hObject, eventdata, handles)
% hObject handle to B3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 246.94;
PlayNote(handles,freq);
% --- Executes on button press in C4.
function C4_Callback(hObject, eventdata, handles)
% hObject handle to C4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 261.625;
PlayNote(handles,freq);
% --- Executes on button press in D4.
function D4_Callback(hObject, eventdata, handles)
% hObject handle to D4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 293.66;
PlayNote(handles,freq);
% --- Executes on button press in E4.
function E4_Callback(hObject, eventdata, handles)
% hObject handle to E4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 329.63;
PlayNote(handles,freq);
% --- Executes on button press in F4.
function F4_Callback(hObject, eventdata, handles)
% hObject handle to F4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 349.23;
PlayNote(handles,freq);
% --- Executes on button press in G4.
function G4_Callback(hObject, eventdata, handles)
% hObject handle to G4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 392;
PlayNote(handles,freq);
% --- Executes on button press in A4.
function A4_Callback(hObject, eventdata, handles)
% hObject handle to A4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 440;
PlayNote(handles,freq);
% --- Executes on button press in B4.
function B4_Callback(hObject, eventdata, handles)
% hObject handle to B4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 493.88;
PlayNote(handles,freq);
% --- Executes on button press in C5.
function C5_Callback(hObject, eventdata, handles)
% hObject handle to C5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 523.25;
PlayNote(handles,freq);
% --- Executes on button press in D5.
function D5_Callback(hObject, eventdata, handles)
% hObject handle to D5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 587.33;
PlayNote(handles,freq);
% --- Executes on button press in E5.
function E5_Callback(hObject, eventdata, handles)
% hObject handle to E5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 659.26;
PlayNote(handles,freq);
% --- Executes on button press in F5.
function F5_Callback(hObject, eventdata, handles)
% hObject handle to F5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 698.46;
PlayNote(handles,freq);
% --- Executes on button press in FSharp4.
function FSharp4_Callback(hObject, eventdata, handles)
% hObject handle to FSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 369.99;
PlayNote(handles,freq);
% --- Executes on button press in DSharp4.
function DSharp4_Callback(hObject, eventdata, handles)
% hObject handle to DSharp4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 311.13;
PlayNote(handles,freq);
% --- Executes on button press in G5.
function G5_Callback(hObject, eventdata, handles)
% hObject handle to G5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 783.99;
PlayNote(handles,freq);
% --- Executes on button press in F3.
function F3_Callback(hObject, eventdata, handles)
% hObject handle to F3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 174.61;
PlayNote(handles,freq);
% --- Executes on button press in E3.
function E3_Callback(hObject, eventdata, handles)
% hObject handle to E3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 164.81;
PlayNote(handles,freq);
% --- Executes on button press in D3.
function D3_Callback(hObject, eventdata, handles)
% hObject handle to D3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 146.83;
PlayNote(handles,freq);
% --- Executes on button press in A5.
function A5_Callback(hObject, eventdata, handles)
% hObject handle to A5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 880;
PlayNote(handles,freq);
% --- Executes on button press in C3.
function C3_Callback(hObject, eventdata, handles)
% hObject handle to C3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 130.81;
PlayNote(handles,freq);
% --- Executes on button press in B5.
function B5_Callback(hObject, eventdata, handles)
% hObject handle to B5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 987.77;
PlayNote(handles,freq);
% --- Executes on button press in GSharp5.
function GSharp5_Callback(hObject, eventdata, handles)
% hObject handle to GSharp5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 830.61;
PlayNote(handles,freq);
% --- Executes on button press in ASharp5.
function ASharp5_Callback(hObject, eventdata, handles)
% hObject handle to ASharp5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 932.33;
PlayNote(handles,freq);
% --- Executes on button press in DSharp3.
function DSharp3_Callback(hObject, eventdata, handles)
% hObject handle to DSharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 155.56;
PlayNote(handles,freq);
% --- Executes on button press in CSharp3.
function CSharp3_Callback(hObject, eventdata, handles)
% hObject handle to CSharp3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
freq = 138.59;
PlayNote(handles,freq);
function PlayNote(handles,freq)
% plays the note that was pressed for 1 second
% also sets the frequency value on GUI for last played note.
strFreq = num2str(freq);
set(handles.STFreqValue, 'String', strFreq);
SampleRate = handles.SampleRate;
TimeValue = handles.TimeValue;
Samples = 0:SampleRate:TimeValue;
SinOn = get(handles.SinWave, 'Value');
SquareOn = get(handles.SquareWave, 'Value');
SawtoothOn = get(handles.SawtoothWave, 'Value');
if SinOn == 1
soundVector = sin(2*pi*freq*Samples);
elseif SquareOn == 1
soundVector = square(2*pi*freq*Samples);
elseif SawtoothOn == 1
soundVector = sawtooth(2*pi*freq*Samples);
end
sound(soundVector, 1/SampleRate)
RecordOn = get(handles.Record, 'Value');
if RecordOn == 1
SoundVectorLong = handles.SoundVector;
if SoundVectorLong == 0
SoundVectorLong = soundVector;
else
SoundVectorLong = cat(2, SoundVectorLong, soundVector);
end
handles.SoundVector = SoundVectorLong;
guidata(handles.figure1, handles);
end
% --- Executes on button press in Play.
function Play_Callback(hObject, eventdata, handles)
% hObject handle to Play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SoundVector = handles.SoundVector;
SampleRate = handles.SampleRate;
sound(SoundVector, 1/SampleRate)
% --- Executes on button press in Stop.
function Stop_Callback(hObject, eventdata, handles)
% hObject handle to Stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.SoundVector = 0;
guidata(handles.figure1, handles);
function Time_Callback(hObject, eventdata, handles)
% hObject handle to Time (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of Time as text
% str2double(get(hObject,'String')) returns contents of Time as a double
Value = str2double(get(hObject, 'String'));
TimeValue = 60/Value;
half = get(handles.HalfNote, 'Value');
Whole = get(handles.WholeNote, 'Value');
Eighth = get(handles.EighthNote, 'Value');
if half == 1
TimeValue = TimeValue * 2;
elseif Whole == 1
TimeValue = TimeValue * 4;
elseif Eighth == 1
TimeValue = TimeValue / 2;
end
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
% --- Executes on button press in QuarterNote.
function QuarterNote_Callback(hObject, eventdata, handles)
% hObject handle to QuarterNote (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.QuarterNote, 'Value', 1);
set(handles.HalfNote, 'Value', 0);
set(handles.EighthNote, 'Value', 0);
set(handles.WholeNote, 'Value', 0);
Value = str2double(get(handles.Time, 'String'));
TimeValue = 60/Value;
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
% --- Executes on button press in HalfNote.
function HalfNote_Callback(hObject, eventdata, handles)
% hObject handle to HalfNote (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.QuarterNote, 'Value', 0);
set(handles.HalfNote, 'Value', 1);
set(handles.EighthNote, 'Value', 0);
set(handles.WholeNote, 'Value', 0);
Value = str2double(get(handles.Time, 'String'));
TimeValue = 60/Value * 2;
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
% --- Executes on button press in EighthNote.
function EighthNote_Callback(hObject, eventdata, handles)
% hObject handle to EighthNote (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.QuarterNote, 'Value', 0);
set(handles.HalfNote, 'Value', 0);
set(handles.EighthNote, 'Value', 1);
set(handles.WholeNote, 'Value', 0);
Value = str2double(get(handles.Time, 'String'));
TimeValue = (60/Value) / 2;
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
% --- Executes on button press in WholeNote.
function WholeNote_Callback(hObject, eventdata, handles)
% hObject handle to WholeNote (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.EighthNote, 'Value', 0);
set(handles.QuarterNote, 'Value', 0);
set(handles.HalfNote, 'Value', 0);
set(handles.WholeNote, 'Value', 1);
Value = str2double(get(handles.Time, 'String'));
TimeValue = 60/Value * 4;
handles.TimeValue = TimeValue;
guidata(handles.figure1, handles);
% --- Executes during object creation, after setting all properties.
function QuarterNote_CreateFcn(hObject, eventdata, handles)
% hObject handle to QuarterNote (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Value', 1);
% --- Executes on button press in SinWave.
function SinWave_Callback(hObject, eventdata, handles)
% hObject handle to SinWave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of SinWave
set(handles.SinWave, 'Value', 1);
set(handles.SquareWave, 'Value', 0);
set(handles.SawtoothWave, 'Value', 0);
% --- Executes during object creation, after setting all properties.
function SinWave_CreateFcn(hObject, eventdata, handles)
% hObject handle to SinWave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
set(hObject, 'Value', 1);
% --- Executes on button press in SquareWave.
function SquareWave_Callback(hObject, eventdata, handles)
% hObject handle to SquareWave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of SquareWave
set(handles.SinWave, 'Value', 0);
set(handles.SquareWave, 'Value', 1);
set(handles.SawtoothWave, 'Value', 0);
% --- Executes on button press in SawtoothWave.
function SawtoothWave_Callback(hObject, eventdata, handles)
% hObject handle to SawtoothWave (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of SawtoothWave
set(handles.SinWave, 'Value', 0);
set(handles.SquareWave, 'Value', 0);
set(handles.SawtoothWave, 'Value', 1);
% --- Executes on key press with focus on F3 and none of its controls.
function F3_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to F3 (see GCBO)
% eventdata structure with the following fields (see
MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles structure with handles and user data (see GUIDATA)
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over STFreqValue.
Piano Keyboard Application

Weitere ähnliche Inhalte

Ähnlich wie Piano Keyboard Application Project using MATLAB

Unit1 jwfiles
Unit1 jwfilesUnit1 jwfiles
Unit1 jwfilesmrecedu
 
TRAFFIC CODE MATLAB Function varargouttraffic code
TRAFFIC CODE MATLAB Function varargouttraffic codeTRAFFIC CODE MATLAB Function varargouttraffic code
TRAFFIC CODE MATLAB Function varargouttraffic codeYograj Ghodekar
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal ProcessingAssignmentpedia
 
Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)Yango Alexander Colmenares
 
Control Systems Using Matlab
Control Systems Using MatlabControl Systems Using Matlab
Control Systems Using MatlabAssignmentpedia
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
intro_gui
intro_guiintro_gui
intro_guifilipb2
 
Final project report
Final project reportFinal project report
Final project reportssuryawanshi
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabMohan Raj
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio filesMinh Anh Nguyen
 
Question I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docxQuestion I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docxcatheryncouper
 
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdfalstradecentreerode
 
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPatrick Allaert
 
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docxRobotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docxSUBHI7
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağıMerve Cvdr
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptxGuy Komari
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 appletsraksharao
 
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das Databricks
 

Ähnlich wie Piano Keyboard Application Project using MATLAB (20)

Unit1 jwfiles
Unit1 jwfilesUnit1 jwfiles
Unit1 jwfiles
 
TRAFFIC CODE MATLAB Function varargouttraffic code
TRAFFIC CODE MATLAB Function varargouttraffic codeTRAFFIC CODE MATLAB Function varargouttraffic code
TRAFFIC CODE MATLAB Function varargouttraffic code
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
 
Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)Actividad #7 codigo detección de errores (yango colmenares)
Actividad #7 codigo detección de errores (yango colmenares)
 
Control Systems Using Matlab
Control Systems Using MatlabControl Systems Using Matlab
Control Systems Using Matlab
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
intro_gui
intro_guiintro_gui
intro_gui
 
functions
functionsfunctions
functions
 
Final project report
Final project reportFinal project report
Final project report
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
The method of comparing two audio files
The method of comparing two audio filesThe method of comparing two audio files
The method of comparing two audio files
 
Question I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docxQuestion I Part (a) 1.SOURCE CODE LISTING for numb.docx
Question I Part (a) 1.SOURCE CODE LISTING for numb.docx
 
Deep Learning in theano
Deep Learning in theanoDeep Learning in theano
Deep Learning in theano
 
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf#define LOGFILE signal_log.txt  Signal handlers void sigusr1.pdf
#define LOGFILE signal_log.txt Signal handlers void sigusr1.pdf
 
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & Pinba
 
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docxRobotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
Robotics.DS_Store__MACOSXRobotics._.DS_StoreRobotics.docx
 
Matlab kod taslağı
Matlab kod taslağıMatlab kod taslağı
Matlab kod taslağı
 
golang_getting_started.pptx
golang_getting_started.pptxgolang_getting_started.pptx
golang_getting_started.pptx
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
 
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das
Apache Spark 2.0: A Deep Dive Into Structured Streaming - by Tathagata Das
 

Kürzlich hochgeladen

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptMsecMca
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Bookingroncy bisnoi
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...ranjana rawat
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordAsst.prof M.Gokilavani
 

Kürzlich hochgeladen (20)

Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 

Piano Keyboard Application Project using MATLAB

  • 1. PIANO KEYBOARD APPLICATION Using MATLAB R2018a SUBMITTED BY DIVYANSHU CHHABRA AYUSH DEVAL (17105049)
  • 2. Objective/Aim The aim/objective of this project is to create a Piano Keyboard App that can produce musical notes in three different waveforms i.e., Sine waveform, Square waveform and Sawtooth waveform. The app should be able to record the previously played musical notes or a musical pattern and should also be able to set the tempo of the notes. The app must have several options for 1/8th note, 1/4th note, 1/2th note and 1 note for user comfortability of producing a melody. Theory MATLAB: MATLAB (matrix laboratory) is a multi-paradigm numerical computing environment and proprietary programming language developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages, including C, C++, C#, Java, Fortran and Python. Although MATLAB is intended primarily for numerical computing, an optional toolbox uses the MuPAD symbolic engine, allowing access to symbolic computing abilities. An additional package, Simulink, adds graphical multi-domain simulation and model-based design for dynamic and embedded systems. GUIs: GUIs (also known as graphical user interfaces or UIs) provide point-and-click control of software applications, eliminating the need to learn a language or type commands in order to run the application. MATLAB® apps are self-contained MATLAB programs with GUI front ends that automate a task or calculation. The GUI typically contains controls such as menus, toolbars, buttons, and sliders. Many MATLAB products, such as Curve Fitting Toolbox™, Signal Processing Toolbox™, and Control System Toolbox™ include apps with custom user interfaces. You can also create your own custom apps, including their corresponding UIs, for others to use. DIGITAL PIANO: Digital pianos are also non-acoustic and do not have strings or hammers. They use digital sampling technology to reproduce the acoustic sound of each piano note accurately. They also must be connected to a power amplifier and speaker to produce sound (however, most digital pianos have a built-in amp and speaker). Alternatively, a person can practice with headphones to avoid disturbing others. Digital pianos can include sustain pedals, weighted or semi-weighted keys, multiple voice options (e.g., sampled or synthesized imitations of electric piano, Hammond organ, violin, etc.), and MIDI interfaces. MUSICAL SOUNDS: Musical sounds are vibrations which are strongly regular. When you hear a regular vibration, your ear detects the frequency, and you perceive this as the pitch of a musical tone.
  • 3. There are two main properties of a regular vibration - the amplitude and the frequency - which affect the way it sounds. Amplitude is the size of the vibration, and this determines how loud the sound is. We have already seen that larger vibrations make a louder sound. Amplitude is important when balancing and controlling the loudness of sounds, such as with the volume control on your CD player. It is also the origin of the word amplifier, a device which increases the amplitude of a waveform. Frequency is the speed of the vibration, and this determines the pitch of the sound. It is only useful or meaningful for musical sounds, where there is a strongly regular waveform. Frequency is measured as the number of wave cycles that occur in one second. The unit of frequency measurement is Hertz (Hz for short). A frequency of 1 Hz means one wave cycle per second. A frequency of 10 Hz means ten wave cycles per second, where the cycles are much shorter and closer together. The note A which is above Middle C (more on this later) has a frequency of 440 Hz. It is often used as a reference frequency for tuning musical instruments. Frequency of the musical notes are in the following table.
  • 4. Working of Piano Keyboard Application The application checks the key pressed on the piano and then produces its sound based on its frequency programmed in the app. • Time_Callback() function sets the rate of the musical note production in terms of beats per minute (bpm) • SinWave_Callback() function produces the sound of the pressed note in sine waveform. • SquareWave_Callback() function produces the sound of the pressed note in square waveform. • SawtoothWave_Callback() function produces the sound of the pressed note in sawtooth waveform. GUI and its produced code GUI of Piano Keyboard Application GUI Code function varargout = piano2(varargin) % PIANO2 M-file for piano2.fig % PIANO2, by itself, creates a new PIANO2 or raises the existing % singleton*. % % H = PIANO2 returns the handle to a new PIANO2 or the handle to % the existing singleton*. % % PIANO2('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PIANO2.M with the given input arguments. % % PIANO2('Property','Value',...) creates a new PIANO2 or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before piano2_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application
  • 5. % stop. All inputs are passed to piano2_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to he lp piano2 % Last Modified by GUIDE v2.5 24-Apr-2019 14:32:01 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @piano2_OpeningFcn, ... 'gui_OutputFcn', @piano2_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % AUTHOR: MARK FRANKOSKY (MFRANKOSKY@GMAIL.COM) % --- Executes just before piano2 is made visible. function piano2_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to piano2 (see VARARGIN) % Choose default command line output for piano2 handles.output = hObject; handles.SampleRate = 1/20000; handles.SoundVector = 0; handles.TimeValue = 0.3488; % Update handles structure guidata(hObject, handles); % UIWAIT makes piano2 wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = piano2_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure
  • 6. varargout{1} = handles.output; % --- Executes on button press in GShparp3. function GShparp3_Callback(hObject, eventdata, handles) % hObject handle to GShparp3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 207.65; PlayNote(handles,freq); % --- Executes on button press in ASharp3. function ASharp3_Callback(hObject, eventdata, handles) % hObject handle to ASharp3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 233.08; PlayNote(handles,freq); % --- Executes on button press in FSharp5. function FSharp5_Callback(hObject, eventdata, handles) % hObject handle to FSharp5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 739.99; PlayNote(handles,freq); % --- Executes on button press in FSharp3. function FSharp3_Callback(hObject, eventdata, handles) % hObject handle to FSharp3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 185.00; PlayNote(handles,freq); % --- Executes on button press in ASharp4. function ASharp4_Callback(hObject, eventdata, handles) % hObject handle to ASharp4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 466.16; PlayNote(handles,freq); % --- Executes on button press in DSharp5. function DSharp5_Callback(hObject, eventdata, handles) % hObject handle to DSharp5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 622.25; PlayNote(handles,freq); % --- Executes on button press in CSharp5. function CSharp5_Callback(hObject, eventdata, handles) % hObject handle to CSharp5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB
  • 7. % handles structure with handles and user data (see GUIDATA) freq = 554.37; PlayNote(handles,freq); % --- Executes on button press in GSharp4. function GSharp4_Callback(hObject, eventdata, handles) % hObject handle to GSharp4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 415.3; PlayNote(handles,freq); % --- Executes on button press in CSharp4. function CSharp4_Callback(hObject, eventdata, handles) % hObject handle to CSharp4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 277.18; PlayNote(handles,freq); % --- Executes on button press in G3. function G3_Callback(hObject, eventdata, handles) % hObject handle to G3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 196; PlayNote(handles,freq); % --- Executes on button press in A3. function A3_Callback(hObject, eventdata, handles) % hObject handle to A3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 220; PlayNote(handles,freq); % --- Executes on button press in B3. function B3_Callback(hObject, eventdata, handles) % hObject handle to B3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 246.94; PlayNote(handles,freq); % --- Executes on button press in C4. function C4_Callback(hObject, eventdata, handles) % hObject handle to C4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 261.625; PlayNote(handles,freq); % --- Executes on button press in D4.
  • 8. function D4_Callback(hObject, eventdata, handles) % hObject handle to D4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 293.66; PlayNote(handles,freq); % --- Executes on button press in E4. function E4_Callback(hObject, eventdata, handles) % hObject handle to E4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 329.63; PlayNote(handles,freq); % --- Executes on button press in F4. function F4_Callback(hObject, eventdata, handles) % hObject handle to F4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 349.23; PlayNote(handles,freq); % --- Executes on button press in G4. function G4_Callback(hObject, eventdata, handles) % hObject handle to G4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 392; PlayNote(handles,freq); % --- Executes on button press in A4. function A4_Callback(hObject, eventdata, handles) % hObject handle to A4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 440; PlayNote(handles,freq); % --- Executes on button press in B4. function B4_Callback(hObject, eventdata, handles) % hObject handle to B4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 493.88; PlayNote(handles,freq); % --- Executes on button press in C5. function C5_Callback(hObject, eventdata, handles) % hObject handle to C5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 523.25; PlayNote(handles,freq);
  • 9. % --- Executes on button press in D5. function D5_Callback(hObject, eventdata, handles) % hObject handle to D5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 587.33; PlayNote(handles,freq); % --- Executes on button press in E5. function E5_Callback(hObject, eventdata, handles) % hObject handle to E5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 659.26; PlayNote(handles,freq); % --- Executes on button press in F5. function F5_Callback(hObject, eventdata, handles) % hObject handle to F5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 698.46; PlayNote(handles,freq); % --- Executes on button press in FSharp4. function FSharp4_Callback(hObject, eventdata, handles) % hObject handle to FSharp4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 369.99; PlayNote(handles,freq); % --- Executes on button press in DSharp4. function DSharp4_Callback(hObject, eventdata, handles) % hObject handle to DSharp4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 311.13; PlayNote(handles,freq); % --- Executes on button press in G5. function G5_Callback(hObject, eventdata, handles) % hObject handle to G5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 783.99; PlayNote(handles,freq); % --- Executes on button press in F3. function F3_Callback(hObject, eventdata, handles) % hObject handle to F3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
  • 10. freq = 174.61; PlayNote(handles,freq); % --- Executes on button press in E3. function E3_Callback(hObject, eventdata, handles) % hObject handle to E3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 164.81; PlayNote(handles,freq); % --- Executes on button press in D3. function D3_Callback(hObject, eventdata, handles) % hObject handle to D3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 146.83; PlayNote(handles,freq); % --- Executes on button press in A5. function A5_Callback(hObject, eventdata, handles) % hObject handle to A5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 880; PlayNote(handles,freq); % --- Executes on button press in C3. function C3_Callback(hObject, eventdata, handles) % hObject handle to C3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 130.81; PlayNote(handles,freq); % --- Executes on button press in B5. function B5_Callback(hObject, eventdata, handles) % hObject handle to B5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 987.77; PlayNote(handles,freq); % --- Executes on button press in GSharp5. function GSharp5_Callback(hObject, eventdata, handles) % hObject handle to GSharp5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 830.61; PlayNote(handles,freq); % --- Executes on button press in ASharp5. function ASharp5_Callback(hObject, eventdata, handles) % hObject handle to ASharp5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB
  • 11. % handles structure with handles and user data (see GUIDATA) freq = 932.33; PlayNote(handles,freq); % --- Executes on button press in DSharp3. function DSharp3_Callback(hObject, eventdata, handles) % hObject handle to DSharp3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 155.56; PlayNote(handles,freq); % --- Executes on button press in CSharp3. function CSharp3_Callback(hObject, eventdata, handles) % hObject handle to CSharp3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) freq = 138.59; PlayNote(handles,freq); function PlayNote(handles,freq) % plays the note that was pressed for 1 second % also sets the frequency value on GUI for last played note. strFreq = num2str(freq); set(handles.STFreqValue, 'String', strFreq); SampleRate = handles.SampleRate; TimeValue = handles.TimeValue; Samples = 0:SampleRate:TimeValue; SinOn = get(handles.SinWave, 'Value'); SquareOn = get(handles.SquareWave, 'Value'); SawtoothOn = get(handles.SawtoothWave, 'Value'); if SinOn == 1 soundVector = sin(2*pi*freq*Samples); elseif SquareOn == 1 soundVector = square(2*pi*freq*Samples); elseif SawtoothOn == 1 soundVector = sawtooth(2*pi*freq*Samples); end sound(soundVector, 1/SampleRate) RecordOn = get(handles.Record, 'Value'); if RecordOn == 1 SoundVectorLong = handles.SoundVector; if SoundVectorLong == 0 SoundVectorLong = soundVector; else SoundVectorLong = cat(2, SoundVectorLong, soundVector); end handles.SoundVector = SoundVectorLong; guidata(handles.figure1, handles); end % --- Executes on button press in Play.
  • 12. function Play_Callback(hObject, eventdata, handles) % hObject handle to Play (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) SoundVector = handles.SoundVector; SampleRate = handles.SampleRate; sound(SoundVector, 1/SampleRate) % --- Executes on button press in Stop. function Stop_Callback(hObject, eventdata, handles) % hObject handle to Stop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) handles.SoundVector = 0; guidata(handles.figure1, handles); function Time_Callback(hObject, eventdata, handles) % hObject handle to Time (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of Time as text % str2double(get(hObject,'String')) returns contents of Time as a double Value = str2double(get(hObject, 'String')); TimeValue = 60/Value; half = get(handles.HalfNote, 'Value'); Whole = get(handles.WholeNote, 'Value'); Eighth = get(handles.EighthNote, 'Value'); if half == 1 TimeValue = TimeValue * 2; elseif Whole == 1 TimeValue = TimeValue * 4; elseif Eighth == 1 TimeValue = TimeValue / 2; end handles.TimeValue = TimeValue; guidata(handles.figure1, handles); % --- Executes on button press in QuarterNote. function QuarterNote_Callback(hObject, eventdata, handles) % hObject handle to QuarterNote (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.QuarterNote, 'Value', 1); set(handles.HalfNote, 'Value', 0); set(handles.EighthNote, 'Value', 0); set(handles.WholeNote, 'Value', 0); Value = str2double(get(handles.Time, 'String')); TimeValue = 60/Value; handles.TimeValue = TimeValue; guidata(handles.figure1, handles);
  • 13. % --- Executes on button press in HalfNote. function HalfNote_Callback(hObject, eventdata, handles) % hObject handle to HalfNote (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.QuarterNote, 'Value', 0); set(handles.HalfNote, 'Value', 1); set(handles.EighthNote, 'Value', 0); set(handles.WholeNote, 'Value', 0); Value = str2double(get(handles.Time, 'String')); TimeValue = 60/Value * 2; handles.TimeValue = TimeValue; guidata(handles.figure1, handles); % --- Executes on button press in EighthNote. function EighthNote_Callback(hObject, eventdata, handles) % hObject handle to EighthNote (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.QuarterNote, 'Value', 0); set(handles.HalfNote, 'Value', 0); set(handles.EighthNote, 'Value', 1); set(handles.WholeNote, 'Value', 0); Value = str2double(get(handles.Time, 'String')); TimeValue = (60/Value) / 2; handles.TimeValue = TimeValue; guidata(handles.figure1, handles); % --- Executes on button press in WholeNote. function WholeNote_Callback(hObject, eventdata, handles) % hObject handle to WholeNote (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.EighthNote, 'Value', 0); set(handles.QuarterNote, 'Value', 0); set(handles.HalfNote, 'Value', 0); set(handles.WholeNote, 'Value', 1); Value = str2double(get(handles.Time, 'String')); TimeValue = 60/Value * 4; handles.TimeValue = TimeValue; guidata(handles.figure1, handles); % --- Executes during object creation, after setting all properties. function QuarterNote_CreateFcn(hObject, eventdata, handles) % hObject handle to QuarterNote (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called set(hObject, 'Value', 1);
  • 14. % --- Executes on button press in SinWave. function SinWave_Callback(hObject, eventdata, handles) % hObject handle to SinWave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of SinWave set(handles.SinWave, 'Value', 1); set(handles.SquareWave, 'Value', 0); set(handles.SawtoothWave, 'Value', 0); % --- Executes during object creation, after setting all properties. function SinWave_CreateFcn(hObject, eventdata, handles) % hObject handle to SinWave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called set(hObject, 'Value', 1); % --- Executes on button press in SquareWave. function SquareWave_Callback(hObject, eventdata, handles) % hObject handle to SquareWave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of SquareWave set(handles.SinWave, 'Value', 0); set(handles.SquareWave, 'Value', 1); set(handles.SawtoothWave, 'Value', 0); % --- Executes on button press in SawtoothWave. function SawtoothWave_Callback(hObject, eventdata, handles) % hObject handle to SawtoothWave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of SawtoothWave set(handles.SinWave, 'Value', 0); set(handles.SquareWave, 'Value', 0); set(handles.SawtoothWave, 'Value', 1); % --- Executes on key press with focus on F3 and none of its controls. function F3_KeyPressFcn(hObject, eventdata, handles) % hObject handle to F3 (see GCBO) % eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL) % Key: name of the key that was pressed, in lower case % Character: character interpretation of the key(s) that was pressed % Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed % handles structure with handles and user data (see GUIDATA) % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over STFreqValue.