forked from ndwork/dworkLib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannounceCompletion.m
More file actions
58 lines (50 loc) · 1.79 KB
/
Copy pathannounceCompletion.m
File metadata and controls
58 lines (50 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
function announceCompletion( varargin )
% announceCompletion( [ 'earlyTime', earlyTime, 'lateTime', lateTime ] )
%
% This function makes an audible sound when the function is called.
% Intended to be run at the end of the program to let you know it's done.
%
% Inputs:
% earlyTime - specified as hh:mm 24 hour format. If specified, won't make a sound
% before this time in the morning.
% lateTime - specified as hh:mm 24 hour format. If sepcified, won't make a sound
% after this time in the evening.
%
% Written by Nicholas Dwork - Copyright 2016
%
% This software is offered under the GNU General Public License 3.0. It
% is offered without any warranty expressed or implied, including the
% implied warranties of merchantability or fitness for a particular
% purpose.
p = inputParser;
p.addParameter( 'earlyTime', [], @(x) true );
p.addParameter( 'lateTime', [], @(x) true );
p.parse( varargin{:} );
earlyTime = p.Results.earlyTime;
lateTime = p.Results.lateTime;
t = clock();
if numel( earlyTime ) > 0
earlyTimeParts = strsplit( earlyTime, ':' );
earlyHour = str2double( earlyTimeParts(1) );
earlyMin = str2double( earlyTimeParts(2) );
if( t(4) <= earlyHour )
if( t(4) < earlyHour ), return; end;
if( t(4) == earlyHour && t(5) <= earlyMin ), return; end;
end
end
if numel( lateTime ) > 0
lateTimeParts = strsplit( lateTime, ':' );
lateHour = str2double( lateTimeParts(1) );
lateMin = str2double( lateTimeParts(2) );
if( t(4) >= lateHour )
if( t(4) == lateHour && t(5) >= lateMin ), return; end;
if( t(4) > lateHour ), return; end;
end
end
if exist( 'programComplete.wav', 'file' )
[y,Fs] = audioread( 'programComplete.wav' );
else
load( 'gong' );
end
soundsc( y, Fs );
end