2015年12月26日 星期六

簡易 piano_GUI (使用GUIDE)







程式碼

function varargout = piano(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, 'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @piano_OpeningFcn, 'gui_OutputFcn',  @piano_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

function piano_OpeningFcn(hObject, ~, handles, varargin)
global ff Fs t m;
Fs = 11025; t = 0:1/Fs:(1-1/Fs); m = exp(-(0:Fs-1)/3/Fs);
pitch = 60:72;
ff = fix(440 * 2.^((pitch - 69)/12));
handles.output = hObject;
guidata(hObject, handles);                                      % Update handles structure

function varargout = piano_OutputFcn(~, ~, handles)
varargout{1} = handles.output;

function pushbuttonE_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(5) * t).*m;  wavplay(y, Fs);

function pushbuttonC_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(1) * t).*m;  wavplay(y, Fs);

function pushbuttonD_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(3) * t).*m;  wavplay(y, Fs);

function pushbuttonF_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(6) * t).*m;  wavplay(y, Fs);

function pushbuttonG_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(8) * t).*m;  wavplay(y, Fs);

function pushbuttonA_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(10) * t).*m;  wavplay(y, Fs);

function pushbuttonB_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(12) * t).*m;  wavplay(y, Fs);

function pushbuttonC__Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(13) * t).*m;  wavplay(y, Fs);

function pushbutton1_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(2) * t).*m;  wavplay(y, Fs);

function pushbutton2_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(4) * t).*m;  wavplay(y, Fs);

function pushbutton3_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(7) * t).*m;  wavplay(y, Fs);

function pushbutton4_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(9) * t).*m;  wavplay(y, Fs);

function pushbutton5_Callback(~, ~, ~)
global ff t Fs m;  y = sin(2 * pi * ff(11) * t).*m;  wavplay(y, Fs);

function pushbutton6_Callback(~, ~, ~)

沒有留言:

張貼留言