SlideShare a Scribd company logo
1 of 15
Download to read offline
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

More Related Content

What's hot

компьютерийн сүлжээ
компьютерийн сүлжээкомпьютерийн сүлжээ
компьютерийн сүлжээ
Enkh Gvnj
 
Software engineering mca
Software engineering mcaSoftware engineering mca
Software engineering mca
Aman Adhikari
 

What's hot (20)

Spiral Model in Software Engineering with Case Study
Spiral Model in Software Engineering with Case StudySpiral Model in Software Engineering with Case Study
Spiral Model in Software Engineering with Case Study
 
компьютерийн сүлжээ
компьютерийн сүлжээкомпьютерийн сүлжээ
компьютерийн сүлжээ
 
Characterizing the Software Process: A Maturity Framework
Characterizing the Software Process:  A Maturity FrameworkCharacterizing the Software Process:  A Maturity Framework
Characterizing the Software Process: A Maturity Framework
 
Застосування сучасних засобів спілкування
Застосування сучасних засобів спілкуванняЗастосування сучасних засобів спілкування
Застосування сучасних засобів спілкування
 
Software engineering srs, dfd
Software engineering srs, dfdSoftware engineering srs, dfd
Software engineering srs, dfd
 
Cocomo model
Cocomo modelCocomo model
Cocomo model
 
2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGN2.1.1 PROBLEM SOLVING & DESIGN
2.1.1 PROBLEM SOLVING & DESIGN
 
Криптологийн тухай ойлголт - Cryptology
Криптологийн тухай ойлголт - CryptologyКриптологийн тухай ойлголт - Cryptology
Криптологийн тухай ойлголт - Cryptology
 
1
11
1
 
Software Engineering concept
Software Engineering concept Software Engineering concept
Software Engineering concept
 
Software Configuration Management
Software Configuration ManagementSoftware Configuration Management
Software Configuration Management
 
Infosec
InfosecInfosec
Infosec
 
Методичні поради для педагогів по впровадженню ІКТ у навчально-виховний процес
Методичні поради для педагогів по впровадженню ІКТ у навчально-виховний процесМетодичні поради для педагогів по впровадженню ІКТ у навчально-виховний процес
Методичні поради для педагогів по впровадженню ІКТ у навчально-виховний процес
 
It101-1
It101-1It101-1
It101-1
 
өгөгдлийн сангийн системийн үндэс
өгөгдлийн сангийн системийн үндэсөгөгдлийн сангийн системийн үндэс
өгөгдлийн сангийн системийн үндэс
 
сургуулийн мэдээллийн системийг хөгжүүлэх нь
сургуулийн мэдээллийн системийг хөгжүүлэх ньсургуулийн мэдээллийн системийг хөгжүүлэх нь
сургуулийн мэдээллийн системийг хөгжүүлэх нь
 
OOSDLC.pptx
OOSDLC.pptxOOSDLC.pptx
OOSDLC.pptx
 
Behavioural modelling
Behavioural modellingBehavioural modelling
Behavioural modelling
 
Software engineering mca
Software engineering mcaSoftware engineering mca
Software engineering mca
 
Improving of software processes
Improving of software processesImproving of software processes
Improving of software processes
 

Similar to Piano Keyboard Application Project using MATLAB

Antenna Physical Characetristics
Antenna Physical CharacetristicsAntenna Physical Characetristics
Antenna Physical Characetristics
Assignmentpedia
 
Unit1 jwfiles
Unit1 jwfilesUnit1 jwfiles
Unit1 jwfiles
mrecedu
 
TRAFFIC CODE MATLAB Function varargouttraffic code
TRAFFIC CODE MATLAB Function varargouttraffic codeTRAFFIC CODE MATLAB Function varargouttraffic code
TRAFFIC CODE MATLAB Function varargouttraffic code
Yograj Ghodekar
 
Digital Signal Processing
Digital Signal ProcessingDigital Signal Processing
Digital Signal Processing
Assignmentpedia
 
Control Systems Using Matlab
Control Systems Using MatlabControl Systems Using Matlab
Control Systems Using Matlab
Assignmentpedia
 
Final project report
Final project reportFinal project report
Final project report
ssuryawanshi
 
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
catheryncouper
 
#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
alstradecentreerode
 
PHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & PinbaPHP applications/environments monitoring: APM & Pinba
PHP applications/environments monitoring: APM & Pinba
Patrick 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.docx
SUBHI7
 

Similar to Piano Keyboard Application Project using MATLAB (20)

Antenna Physical Characetristics
Antenna Physical CharacetristicsAntenna Physical Characetristics
Antenna Physical Characetristics
 
matlab.code.has.docx
matlab.code.has.docxmatlab.code.has.docx
matlab.code.has.docx
 
dsp.pdf
dsp.pdfdsp.pdf
dsp.pdf
 
C Language Unit-1
C Language Unit-1C Language Unit-1
C Language Unit-1
 
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
 

Recently uploaded

1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
meharikiros2
 

Recently uploaded (20)

Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)Theory of Time 2024 (Universal Theory for Everything)
Theory of Time 2024 (Universal Theory for Everything)
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor8086 Microprocessor Architecture: 16-bit microprocessor
8086 Microprocessor Architecture: 16-bit microprocessor
 
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
👉 Yavatmal Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top Class Call Girl S...
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Electromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptxElectromagnetic relays used for power system .pptx
Electromagnetic relays used for power system .pptx
 

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.