TA的每日心情 | 怒 2019-11-20 15:22 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
! H: B5 V3 H; K4 B1 ~6 v! h2 ~一、简介
' y4 O! c8 z' g
( l: s' s" g7 @& I基于matlab GUI音乐闹钟设计
5 A! R8 v/ ]9 F: n7 \$ D/ z* s8 m
7 r7 ]% c% R* {6 [* y6 e* d/ _
2 @4 W+ v7 l7 L7 u8 `, S4 K+ d二、源代码
$ J, a' Y3 s( _9 r7 d: y$ ^. r. e+ t) L6 P6 f" I
- function varargout = wying(varargin)
- % WYING M-file for wying.fig
- % WYING, by itself, creates a new WYING or raises the existing
- % singleton*.
- %
- % H = WYING returns the handle to a new WYING or the handle to
- % the existing singleton*.
- %
- % WYING('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in WYING.M with the given input arguments.
- %
- % WYING('Property','Value',...) creates a new WYING or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before wying_OpeningFcn gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to wying_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 wying
- % Last Modified by GUIDE v2.5 02-Jun-2021 10:01:54
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @wying_OpeningFcn, ...
- 'gui_OutputFcn', @wying_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
- % --- Executes just before wying is made visible.
- function wying_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 wying (see VARARGIN)
- %设置定时器
- if ~isempty(timeRFindall), stop(timerfindall);delete(timerfindall);end
- %在这里设置radiobutton,是创建时设置的属性不起作用?
- %set(handles.radiobutton_music,'value',handles.clockSaveData(3));
- set(handles.radiobutton_music,'Value',handles.clockSaveData(3));
- %设置图标*******************************************************************
- filename='d:\我的文档\My Pictures\picture\pink素材.jpg';
- javaFrame=get(hObject,'javaFrame');
- set(javaFrame,'FigureIcon',javax.swing.ImageIcon(filename));
- %**************************************************************************
- %设置com对象媒体播放器
- temp=get(handles.uipanel_outerFrame,'Units');set(handles.uipanel_outerFrame,'Units','pixels');
- position=get(handles.uipanel_outerFrame,'position');%【左下X,左下Y,宽,高】
- position(4)=position(2)-20;position(2)=8;position(3)=position(3)+position(1)-13;
- handles.sound_player=actxcontrol('wmplayer.ocx.7',position,handles.figure_bkground);
- handles.sound_player.settings.volume=100;%音量【0,,100】
- set(handles.uipanel_outerFrame,'Units',temp);%uipanellll_outerFrame还原回原来的单位
- handles.timer=timer;%这句要放set之前,否则handles里无timer域
- set(handles.timer,'TimerFcn',{@timer_action,handles});%计时器
- start_timer(handles);%启动定时器
- start_timer2(handles);
- %*************************************************************************
- %set(handles.pushbutton_browse,'visible','off');%默认为隐藏浏览框
- %set(handles.edit_musicFile,'visible','off');
- %*************************************************************************
- % Choose default command line output for wying
- handles.output = hObject;
- % Update handles structure
- guidata(hObject, handles);
- % UIWAIT makes wying wait for user response (see UIRESUME)
- % uiwait(handles.figure_bkground);
- % --- Outputs from this function are returned to the command line.
- function varargout = wying_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 pushbutton_browse.
- function pushbutton_browse_Callback(hObject, eventdata, handles)
- % hObject handle to pushbutton_browse (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- %set(handles.activex1,'URL','d:\我的文档\我的音乐\music\阿桑\阿桑.mp3');
- [filename,pathname]=uigetfile(...%调用windows的打开文件窗口
- {'*.mp3;*.wav;*.asf;*.wma;*.wmv;*.rm;*.avi;...*.mpg;*.mp4;*.rmvb;*.mkv',...
- '可以播放的文件';},'选定是播放的音乐','MultiSelect','off');
- %形成完整的“路径名+文件名”字符串
- handles.musicSaveData=fullfile(pathname,filename);
- %将上部的字符串写入edit_musicFile空间的string域内
- set(handles.edit_musicFile,'String',handles.musicSaveData);
- musicSaveData=handles.musicSaveData;%供下部save使用musicSaveData变量
- %每次都sava是为了提供记录功能,是每次打开闹钟者都有上次记录的文件名
- save('musicSaveData.txt','-ascii','musicSaveData');%写入一个txt文件
- guidata(hObject,handles);%因为增加了handles的域,所以要更新数据供其他函数用
- % --- Executes on selection change in popupmenu_hour.
- function popupmenu_hour_Callback(hObject, eventdata, handles)
- % hObject handle to popupmenu_hour (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 popupmenu_hour contents as cell array
- % contents{get(hObject,'Value')} returns selected item from popupmenu_hour
- %提取当前的小时数的位置编号(不是具体小时数)
- handles.clockSaveData(1)=get(hObject,'Value');
- clockSaveData=handles.clockSaveData;
- save('clockSaveData.txt','-ascii','clockSaveData');
- guidata(hObject,handles);%更新数据
- %下面启动定时器
- start_timer(handles);
- % --- Executes during object creation, after setting all properties.
- function popupmenu_hour_CreateFcn(hObject, eventdata, handles)
- % hObject handle to popupmenu_hour (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.
- % See ISPC and COMPUTER.
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- %载入以前的定时
- set(hObject,'Value',handles.clockSaveData(1));
- %控件对象的句柄写入handles中
- handles.popupmenu_hour=hObject;
- guidata(hObject,handles);
- % --- Executes on selection change in popupmenu_minute.
- function popupmenu_minute_Callback(hObject, eventdata, handles)
- % hObject handle to popupmenu_minute (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 popupmenu_minute contents as cell array
- % contents{get(hObject,'Value')} returns selected item from popupmenu_minute
- handles.clockSaveData(2)=get(hObject,'Value');
- clockSaveData=handles.clockSaveData;
- save('clockSaveData.txt','-ascii','clockSaveData');
- guidata(hObject,handles);%更新数据
- %下面启动定时器
- start_timer(handles);
- % --- Executes during object creation, after setting all properties.
- function popupmenu_minute_CreateFcn(hObject, eventdata, handles)
- % hObject handle to popupmenu_minute (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.
- % See ISPC and COMPUTER.
- if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
- set(hObject,'BackgroundColor','white');
- end
- %载入以前的定时
- set(hObject,'Value',handles.clockSaveData(2));
- %控件对象的句柄写入handles中
- handles.popupmenu_minute=hObject;
- guidata(hObject,handles);
- function edit_musicFile_Callback(hObject, eventdata, handles)
- % hObject handle to edit_musicFile (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 edit_musicFile as text
- % str2double(get(hObject,'String')) returns contents of edit_musicFile as a double
- handles.musicSaveData=get(hObject,'String');%从编辑框控件中获得文件名(string)
- musicSaveData=handles.musicSaveData;%文件名临时存到musicSaveData中供记录
- %将文件名musicSaveData写入musicSaveData.txt文本文件中,保存到硬盘上
- save('musicSaveData.txt','-ascii','musicSaveData');
- guidata(hObject,handles);%更新handles数据
- 2 \! G& i4 {$ }6 k
( ~) S. E" v0 a/ d5 i& [
/ X9 D, n. t9 O6 i3 {2 B8 k- ^8 k) I" N$ ?; m+ j# E- U
三、运行结果
- @4 [. C8 p/ q, h' h9 d2 V4 S6 k9 P5 o" w4 C. {- q
4 X! L9 u+ |2 e, n, F* B1 e, k) w: E( d$ g
|
|