function varargout = Midterm(varargin)
% MIDTERM MATLAB code for Midterm.fig
% MIDTERM, by itself, creates a new MIDTERM or raises the existing
% H = MIDTERM returns the handle to a new MIDTERM or the handle to
% the existing singleton*.
% MIDTERM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MIDTERM.M with the given input arguments.
% MIDTERM('Property','Value',...) creates a new MIDTERM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Midterm_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Midterm_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 help Midterm
% Last Modified by GUIDE v2.5 03-May-2017 03:51:32
% Begin initialization code - DO NOT EDIT
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Midterm_OpeningFcn, ...
'gui_OutputFcn', @Midterm_OutputFcn, ...
'gui_LayoutFcn', [] , ...
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
gui_mainfcn(gui_State, varargin{:});
% End initialization code - DO NOT EDIT
% --- Executes just before Midterm is made visible.
function Midterm_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 Midterm (see VARARGIN)
% Choose default command line output for Midterm
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Midterm wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Midterm_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
if get(handles.checkbox2,'value')==1
if get(handles.checkbox2,'value')==0
cla(handles.axes1,'reset');
melody_matching=get(handles.popupmenu1,'Value');
[y,hz]= audioread('C:\Users\user\Desktop\卡農.mp3'); % read the song's frequency
if get(handles.checkbox,'value')==1
sound(y*get(handles.slider1, 'Value'), hz*get(handles.slider2, 'Value')); % broadcast music
time = (1 : length(y) ) / hz; % Setting X axis is time
plot(handles.axes1,time/get(handles.slider2, 'Value'),y*get(handles.slider1, 'Value'),'r'); % print wave picture with graduation
melody_matching = 'Written In The Stars';
[y,hz] = audioread('C:\Users\user\Desktop\Written In The Stars.mp3');
if get(handles.checkbox,'value')==1
sound(y*get(handles.slider1, 'Value'),hz*get(handles.slider2, 'Value'));
time = (1 : length(y) ) / hz;
plot(handles.axes1,time/get(handles.slider2, 'Value'),y*get(handles.slider1, 'Value'),'b'); % print curve picture 'b' can change wave color
[y,hz] = audioread('C:\Users\user\Desktop\G.mp3');
if get(handles.checkbox,'value')==1
time = (1 : length(y) ) / hz;
sound(y*get(handles.slider1, 'Value'), hz*get(handles.slider2, 'Value'));
plot(handles.axes1,time/get(handles.slider2, 'Value'),y*get(handles.slider1, 'Value'),'m');
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton1.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
slider_value1 = get(handles.slider1, 'Value');
set(handles.text3,'String',slider_value1);
%handles.player = audioplayer(y, 10000*get(handles.slider1, 'Value'));
% hObject handle to slider1 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
% --- Executes during object creation, after setting all properties.
function text3_CreateFcn(hObject, eventdata, handles)
% hObject handle to text3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on mouse press over figure background.
function figure1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (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 checkbox2
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
slider_value2 = get(handles.slider2, 'Value');
set(handles.text8,'String',slider_value2);
% hObject handle to slider2 (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
% --- Executes on button press in checkbox.
function checkbox_Callback(hObject, eventdata, handles)
% hObject handle to checkbox (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 checkbox