-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathaarae.m
executable file
·6736 lines (6063 loc) · 297 KB
/
aarae.m
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% DO NOT EDIT THIS INITIALIZATION FUNCTION!!!!!!!!!!!!!!!!!!!!!!!!!!!
function varargout = aarae(varargin)
% AARAE MATLAB code for aarae.fig
% AARAE, by itself, creates a new AARAE or raises the existing
% singleton*.
%
% H = AARAE returns the handle to a new AARAE or the handle to
% the existing singleton*.
%
% AARAE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in AARAE.M with the given input arguments.
%
% AARAE('Property','Value',...) creates a new AARAE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before aarae_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to aarae_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 aarae
% Last Modified by GUIDE v2.5 14-Feb-2017 16:48:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @aarae_OpeningFcn, ...
'gui_OutputFcn', @aarae_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
% *************************************************************************
% *************************************************************************
% STARTING AARAE
% *************************************************************************
% *************************************************************************
% *************************************************************************
% INITIALIZE AARAE THINGS
% *************************************************************************
% --- Executes just before aarae is made visible.
function aarae_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to aarae
% 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 aarae (see VARARGIN)
AARAEversion = 'AARAE Release 9'; % *** UPDATE THIS WITH EACH RELEASE ***
% Choose default command line output for aarae
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Setup the 'desktop'
setappdata(0, 'hMain', gcf);
hMain = getappdata(0,'hMain');
setappdata(hMain,'testsignal',[]);
setappdata(hMain,'audio_recorder_input',1)
setappdata(hMain,'audio_recorder_output',1)
setappdata(hMain,'audio_recorder_numchs',1)
setappdata(hMain,'audio_recorder_numchsout',1)
setappdata(hMain,'audio_recorder_duration',1)
setappdata(hMain,'audio_recorder_fs',48000)
%setappdata(hMain,'audio_recorder_nbits',16)
setappdata(hMain,'audio_recorder_ASIO',0) % redundant
setappdata(hMain,'audio_recorder_buffer',2048) %
setappdata(hMain,'audio_recorder_silencerequest',0)
setappdata(hMain,'audio_recorder_playbackdelay',0)
setappdata(hMain,'trim_method_after_convolution',1)
setappdata(hMain,'AARAEversion',AARAEversion)
set(hObject,'Name','AARAE')
% Read settings file
Settings = [];
if ~isempty(dir([cd '/Settings.mat']))
load([cd '/Settings.mat']);
handles.Settings = Settings;
% The following is to avoid problems when the format of Settings.mat is
% changed (future releases). It should be extended as new settings are
% added. Previously the old settings file needed to be deleted for
% aarae to run with a changed settings format.
if ~isfield(handles.Settings,'maxtimetodisplay'), handles.Settings.maxtimetodisplay = 10; end
if ~isfield(handles.Settings,'frequencylimits'), handles.Settings.frequencylimits = 'Default'; end
if ~isfield(handles.Settings,'calibrationtoggle'), handles.Settings.calibrationtoggle = 1; end
if ~isfield(handles.Settings,'maxlines'), handles.Settings.maxlines = 100; end
if ~isfield(handles.Settings,'colormap'), handles.Settings.colormap = 'Jet'; end
if ~isfield(handles.Settings,'specmagscale'), handles.Settings.specmagscale = 'Raw'; end
if ~isfield(handles.Settings,'username'), handles.Settings.username = 'AARAE User'; end
if ~isfield(handles.Settings,'recordaddress'), handles.Settings.recordaddress = 1; end
if ~isfield(handles.Settings,'recordIPdata'), handles.Settings.recordIPdata = 1; end
if ~isfield(handles.Settings,'recordlogin'), handles.Settings.recordlogin = 1; end
else
Settings.maxtimetodisplay = 10;
Settings.frequencylimits = 'Default';
Settings.calibrationtoggle = 1;
Settings.maxlines = 100;
Settings.colormap = 'Jet';
Settings.specmagscale = 'Raw';
Settings.username = 'AARAE User';
Settings.recordaddress = 1;
Settings.recordIPdata = 1;
Settings.recordlogin = 1;
handles.Settings = Settings;
save([cd '/Settings.mat'],'Settings')
end
handles.compareaudio = -1; % prevents a timing bug when large files are loaded and the compare button pressed immediately
if ~isdir([cd '/Log']), mkdir([cd '/Log']); end
if ~isdir([cd '/Utilities/Temp'])
mkdir([cd '/Utilities/Temp']);
else
results = dir([cd '/Utilities/Temp']);
set(handles.result_box,'String',[' ';cellstr({results(3:length(results)).name}')]);
end
if ~isdir([cd '/Utilities/Backup'])
mkdir([cd '/Utilities/Backup']);
handles.defaultaudiopath = [cd '/Audio'];
else
handles.defaultaudiopath = [cd '/Utilities/Backup'];
set(handles.recovery_txt,'Visible','on')
end
% Add folder paths for filter functions and signal analyzers
addpath(genpath(cd));
handles.player = audioplayer(0,48000);
if ~isdir([cd '/Audio/REQUIRED_AUDIO'])
mkdir([cd '/Audio/REQUIRED_AUDIO']);
end
try
[handles.reference_audio.audio, handles.reference_audio.fs] = audioread('/Audio/REQUIRED_AUDIO/REFERENCE_AUDIO.wav');
catch
h = warndlg('REFERENCE_AUDIO.wav is missing from the REQUIRED_AUDIO directory (within AARAE''s Audio directory). Please select an alternative reference audio recording.');
uiwait(h)
audiochoice = importaudio;
if ~isempty(audiochoice)
handles.reference_audio = mean(audiochoice(:,:,1,1,1,1),2); %mixdown if multichan
else
handles.reference_audio.audio = sin(2*pi*1000*(0:48000)'./48000); % 1 kHz sine
handles.reference_audio.fs = 48000;
end
end
try
[handles.silenceplease.audio, handles.silenceplease.fs] = audioread('/Audio/REQUIRED_AUDIO/SILENCE_PLEASE.wav');
catch
modulator = 10*sin(2*pi*8*(0:48000)'./48000); % 8 Hz freq modulation
handles.silenceplease.audio = sin(modulator+2*pi*1000*(0:48000)'./48000);
handles.silenceplease.fs = 48000;
end
try
[handles.thankyou.audio, handles.thankyou.fs] = audioread('/Audio/REQUIRED_AUDIO/THANKYOU.wav');
catch
handles.thankyou.audio = sin(2*pi*1000*(0:48000)'./48000);
handles.thankyou.fs = 48000;
end
% Setup for Densil's tree
iconPath = fullfile(matlabroot,'/toolbox/matlab/icons/matlabicon.gif');
handles.root = uitreenode('v0', 'project', 'My project', iconPath, false);
iconPath = fullfile(matlabroot,'/toolbox/matlab/icons/foldericon.gif');
handles.testsignals = uitreenode('v0', 'testsignals', 'Test signals', iconPath, false);
handles.measurements = uitreenode('v0', 'measurements', 'Measurements', iconPath, false);
handles.processed = uitreenode('v0', 'processed', 'Processed', iconPath, false);
handles.results = uitreenode('v0', 'results', 'Results', iconPath, false);
handles.root.add(handles.testsignals);
handles.root.add(handles.measurements);
handles.root.add(handles.processed);
handles.root.add(handles.results);
[handles.mytree,container] = uitree('v0','Root', handles.root,'SelectionChangeFcn',@mySelectFcn);
set(container, 'Parent', hObject);
treeheight_char = get(handles.process_panel,'Position')+get(handles.analysis_panel,'Position')+get(handles.uipanel1,'Position');
treewidth_char = get(handles.analysis_panel,'Position');
set(handles.analysis_panel,'Units','pixels');
treewidth_pix = get(handles.analysis_panel,'Position');
factor = treewidth_pix./treewidth_char;
set(handles.mytree,'Position',[0,treewidth_char(1,2)*factor(1,2),treewidth_char(1,1)*factor(1,1),treeheight_char(1,4)*factor(1,4)]);
handles.mytree.expand(handles.root);
handles.mytree.setSelectedNode(handles.root);
handles.mytree.setMultipleSelectionEnabled(true);
% Generate activity log
activity = dir([cd '/Log' '/activity log 1.txt']);
if isempty(activity)
activitylog = '/activity log 1.txt';
handles.fid = fopen([cd '/Log' activitylog], 'w');
handles.activitylog = activitylog; % used for export all
else
index = 2;
% This while cycle is just to make sure no files are overwriten
while isempty(dir([cd '/Log' '/activity log ',num2str(index),'.txt'])) == 0
index = index + 1;
end
activitylog = ['/activity log ',num2str(index),'.txt'];
handles.fid = fopen([cd '/Log' activitylog], 'w');
handles.activitylog = activitylog; % used for export all
end
handles.alternate = 0;
if Settings.recordlogin == 1
[status, login] = system('who');
if status == 0
handles.login = login;
else
handles.login = '';
end
else
handles.login = '';
end
if Settings.recordaddress == 1
try
handles.address = char(java.net.InetAddress.getLocalHost);
catch
handles.address = '';
end
else
handles.address = '';
end
if Settings.recordIPdata == 1
handles.IPdata = checkIPdata;
else
handles.IPdata = [];
end
fprintf(handles.fid, ['%% AARAE session started ' datestr(now) '\n']);
fprintf(handles.fid, ['%% User: ' handles.Settings.username '\n']);
if ~isempty(handles.login), fprintf(handles.fid, ['%% System user: ' handles.login '\n']); end
if ~isempty(handles.address), fprintf(handles.fid, ['%% Address: ' handles.address '\n']); end
if isstruct(handles.IPdata)
fprintf(handles.fid, ['%% City: ' handles.IPdata.city ...
', Country: ' handles.IPdata.country ...
', Lat: ' handles.IPdata.lat ', Lon: ' ...
handles.IPdata.lon ', Time zone: ' handles.IPdata.timezone '\n']);
fprintf(handles.fid, ['%% ISP: ' handles.IPdata.isp ...
', Organization: ' handles.IPdata.org '\n']);
else
fprintf(handles.fid, ['%% IP data unavailable \n']);
end
fprintf(handles.fid, '%% \n');
fprintf(handles.fid, '%% Audio and Acoustical Response Environment (AARAE) for Matlab\n');
fprintf(handles.fid, ['%% ' AARAEversion '\n']);
fprintf(handles.fid, '%% http://aarae.org\n\n');
fprintf(handles.fid, '%% Reference:\n');
fprintf(handles.fid, '%% Cabrera, D., Jimenez, D., & Martens, W. L. (2014, November).\n');
fprintf(handles.fid, '%% Audio and Acoustical Response Analysis Environment (AARAE): \n');
fprintf(handles.fid, '%% a tool to support education and research in acoustics. \n');
fprintf(handles.fid, '%% In Proceedings of Internoise. Melbourne, Australia.\n\n');
fprintf(handles.fid, '%% For other publications about AARAE refer to aarae.org\n\n');
fprintf(handles.fid, '%% This AARAE log file contains a record of activity, including:\n');
fprintf(handles.fid, '%% * descriptions of audio and other data;\n');
fprintf(handles.fid, '%% * descriptions of activity;\n');
fprintf(handles.fid, '%% * results tables from analysers;\n');
fprintf(handles.fid, '%% * names of exported files; and\n');
fprintf(handles.fid, '%% * function call equivalents to AARAE activity.\n\n');
fprintf(handles.fid, '%% When opening the log file in a spreadsheet program, use comma delimiting to distribute table data into the appropriate spreadsheet cells.\n');
fprintf(handles.fid, '%% (However, bear in mind that the commas required in the log file''s function calls will be removed when you do that.)\n\n');
fprintf(handles.fid, '%% The code written to this log file may be useful for adapting in writing an AARAE workflow function.\n');
fprintf(handles.fid, '%% Examples of workflows are in AARAE''s Workflows folder.\n\n');
fprintf(handles.fid, '%% **************************************************\n\n\n\n');
guidata(hObject, handles);
% AARAE function for dealing with differences between Windows and Mac font
% size
fontsize
% Set waiting flag in appdata
setappdata(handles.aarae,'waiting',1)
% UIWAIT makes aarae wait for user response (see UIRESUME)
uiwait(handles.aarae);
% *************************************************************************
% SETTINGS BUTTON
% *************************************************************************
% --- Executes on button press in settings_btn.
function settings_btn_Callback(hObject, ~, handles) %#ok : Executed when Settings button is clicked
% hObject handle to settings_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Settings = settings_aarae('main_stage1', handles.aarae);%inputdlg('Maximum time period to display','AARAE settings',[1 50],{num2str(handles.Settings.maxtimetodisplay)});
if ~isempty(Settings)
%newpref = cell2struct(newpref,{'maxtimetodisplay'});
%newpref.maxtimetodisplay = str2double(newpref.maxtimetodisplay);
handles.Settings = Settings;
save([cd '/Settings.mat'],'Settings')
guidata(hObject,handles)
selectedNodes = handles.mytree.getSelectedNodes;
handles.mytree.setSelectedNode(handles.root);
handles.mytree.setSelectedNode(selectedNodes(1));
end
% *************************************************************************
% LOGTEXT BUTTON
% *************************************************************************
% --- Executes on button press in logtextbutton.
function logtextbutton_Callback(hObject, ~, handles)
% hObject handle to logtextbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
answer = inputdlg('Add comment to the log file and the selection''s history field(s):','Log comment',[15 150]);
% write to log file
if ~isempty(answer)
answer = char(answer);
logtext('%% **************************************************\n');
logtext(['%% User comment ' datestr(now,16) ' \n']);
logtext('%% \n');
for n = 1:size(answer,1)
logtext(['%% ' answer(n,:) '\n']);
end
logtext('%% \n');
logtext('%% **************************************************\n');
end
% write to selected AARAE structures
selectedNodes = handles.mytree.getSelectedNodes;
for nleafs = 1:length(selectedNodes)
handles.nleafs = nleafs;
guidata(hObject,handles)
signaldata = selectedNodes(nleafs).handle.UserData;
if ~isempty(signaldata)
row = cell(1,4);
row{1,1} = datestr(now);
row{1,2} = 'COMMENT';
row{1,4} = answer;
if isfield(signaldata,'history')
signaldata.history = [signaldata.history;row];
else
signaldata.history = row;
end
% Save as you go
delete([cd '/Utilities/Backup/' selectedNodes(nleafs).getName.char '.mat'])
save([cd '/Utilities/Backup/' selectedNodes(nleafs).getName.char '.mat'], 'signaldata','-v7.3');
try
handles.(matlab.lang.makeValidName(char(selectedNodes(nleafs).getName))).UserData = signaldata;
catch
warndlg('Sorry - an error occured in writing comment to the tree. Please let Densil know about this.','Bug!');
end
selectedParent = selectedNodes(nleafs).getParent;
handles.mytree.reloadNode(selectedParent);
end
handles.mytree.setSelectedNodes(selectedNodes)
end
guidata(hObject,handles)
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over logtextbutton.
function logtextbutton_ButtonDownFcn(hObject, ~, ~)
% hObject handle to logtextbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% *************************************************************************
% KEYBOARD SHORTCUTS
% *************************************************************************
% --- Executes on key press with focus on aarae or any of its controls.
function aarae_WindowKeyPressFcn(hObject, eventdata, handles) %#ok
% hObject handle to aarae (see GCBO)
% eventdata structure with the following fields (see FIGURE)
% 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)
handles = guidata(hObject);
if strcmp(eventdata.Modifier,'alt')
handles.alternate = 1;
else
handles.alternate = 0;
end
%guidata(hObject,handles)
selectedNodes = handles.mytree.getSelectedNodes;
signaldata = selectedNodes(1).handle.UserData;
if ~isempty(signaldata)
if strcmp(eventdata.Key,'l') && ~isfield(handles,'legend')
if ismatrix(signaldata.audio)
if isfield(signaldata,'chanID')
handles.legend = legend(handles.axestime,signaldata.chanID);
end
end
if ~ismatrix(signaldata.audio)
if isfield(signaldata,'bandID')
handles.legend = legend(handles.axestime,cellstr(num2str(signaldata.bandID')));
end
end
elseif strcmp(eventdata.Key,'l') && isfield(handles,'legend')
legend(handles.axestime,'off');
handles = rmfield(handles,'legend');
end
end
if ~isempty(eventdata.Modifier)
if strcmp(eventdata.Modifier,'control') == 1
switch eventdata.Key
case 'r'
rec_btn_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
case 'g'
genaudio_btn_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
case 'l'
load_btn_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
case 'c'
calc_btn_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
case 'e'
if strcmp(get(handles.tools_panel,'Visible'),'on')
edit_btn_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
end
case 's'
if strcmp(get(handles.tools_panel,'Visible'),'on')
save_btn_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
end
case 'delete'
if strcmp(get(handles.tools_panel,'Visible'),'on')
delete_btn_Callback(hObject, eventdata, handles)
handles = guidata(hObject);
end
case 't'
logtextbutton_Callback(hObject, eventdata, handles)
%handles = guidata(hObject);
end
end
end
guidata(hObject,handles)
% *************************************************************************
% *************************************************************************
% ENDING, CLEARING & EXPORTING FROM AARAE
% *************************************************************************
% *************************************************************************
% *************************************************************************
% FINISH AARAE SESSION
% *************************************************************************
% --- Executes on button press in finish_btn.
function finish_btn_Callback(~, eventdata, handles) %#ok
% hObject handle to finish_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if strcmp(get(handles.export_btn,'Enable'),'on')
choice = questdlg('Are you sure to want to finish this AARAE session? Unexported data will be lost.',...
'Exit AARAE',...
'Yes','No','Export all & exit','Yes');
switch choice
case 'Yes'
uiresume(handles.aarae);
case 'Export all & exit'
export_btn_Callback(handles.export_btn,eventdata,handles)
uiresume(handles.aarae);
end
else
uiresume(handles.aarae);
end
% *************************************************************************
% EXPORT ALL DATA FROM AARAE (CREATE A 'PROJECT')
% *************************************************************************
% --- Executes on button press in export_btn.
function export_btn_Callback(hObject, ~, handles)
% hObject handle to export_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
uitreedescription
root = handles.root; % Get selected leaf
root = root(1);
first = root.getFirstChild;
nbranches = root.getChildCount;
branches = cell(nbranches,1);
branches{1,1} = char(first.getValue);
nleaves = 0;
nleaves = nleaves + handles.(matlab.lang.makeValidName(branches{1,1}))(1).getChildCount;
next = first.getNextSibling;
for n = 2:nbranches
branches{n,1} = char(next.getValue);
nleaves = nleaves + handles.(matlab.lang.makeValidName(branches{n,1}))(1).getChildCount;
next = next.getNextSibling;
end
if nleaves == 0
warndlg('Nothing to export!','AARAE info');
else
% leaves = cell(nleaves,1);
% i = 0;
% for n = 1:size(branches,1)
% currentbranch = handles.(matlab.lang.makeValidName(branches{n,1}));
% if currentbranch.getChildCount ~= 0
% i = i + 1;
% first = currentbranch.getFirstChild;
% %leafnames(i,:) = first.getName;
% leaves{i,1} = char(first.getValue);
% next = first.getNextSibling;
% if ~isempty(next)
% for m = 1:currentbranch.getChildCount-1
% i = i + 1;
% %leafnames(i,:) = next.getName;
% leaves{i,1} = char(next.getValue);
% next = next.getNextSibling;
% end
% end
% end
% end
if ~isdir([cd '/Projects']), mkdir([cd '/Projects']); end
folder = uigetdir([cd '/Projects'],'Export all');
if ischar(folder)
set(hObject,'BackgroundColor','red');
set(hObject,'Enable','off');
pause on
pause(0.001)
pause off
% h = waitbar(0,['1 of ' num2str(size(leaves,1))],'Name','Saving files...');
% steps = size(leaves,1);
% for i = 1:size(leaves,1)
% current = handles.(matlab.lang.makeValidName(leaves{i,:}));
% current = current(1);
% data = current.handle.UserData; %#ok : used in save
% if ~exist([folder '/' leaves{i,:} '.mat'],'file')
% try
% save([folder '/' leaves{i,:} '.mat'], 'data');
% catch error
% warndlg(error.message,'AARAE info')
% end
% else
% button = questdlg(['A file called ' leaves{i,:} '.mat is already in the destination folder, would you like to replace it?'],...
% 'AARAE info','Yes','No','Append','Append');
% switch button
% case 'Yes'
% save([folder '/' leaves{i,:} '.mat'], 'data');
% case 'Append'
% index = 1;
% % This while cycle is just to make sure no signals are
% % overwriten
% while exist([folder '/' leaves{i,:} '_' num2str(index) '.mat'],'file')
% index = index + 1;
% end
% try
% save([folder '/' leaves{i,:} '_' num2str(index) '.mat'], 'data');
% catch error
% warndlg(error.message,'AARAE info')
% end
% end
% end
% waitbar(i / steps,h,sprintf('%d of %d',i,size(leaves,1)))
% end
% close(h)
if isdir([cd '/Utilities/Backup'])
leaves = dir([cd '/Utilities/Backup/*.mat']);
copyfile([cd '/Utilities/Backup'],folder);
end
if isdir([cd '/Utilities/Temp'])
nfigs = dir([cd '/Utilities/Temp/*.fig']);
copyfile([cd '/Utilities/Temp'],[folder '/figures']);
end
fprintf(handles.fid, ['%% ' datestr(now,16) ' - Exported ' num2str(size(leaves,1)) ' data files and ' num2str(size(nfigs,1)) ' figures to "%s" \n\n'],folder);
if isfield(handles,'activitylog')
if isdir([cd '/Log'])
copyfile([cd '/Log' handles.activitylog],folder);
end
end
addpath(genpath([cd '/Projects']))
set(hObject,'BackgroundColor',[0.94 0.94 0.94]);
set(hObject,'Enable','off');
else
addpath(genpath([cd '/Projects']))
end
end
guidata(hObject,handles)
% *************************************************************************
% CLEAR ALL FROM THE AARAE WORKSPACE
% *************************************************************************
% --- Executes on button press in clrall_btn.
function clrall_btn_Callback(hObject, ~, handles) %#ok
% hObject handle to clrall_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
root = handles.root; % Get selected leaf
root = root(1);
first = root.getFirstChild;
nbranches = root.getChildCount;
branches = cell(nbranches,1);
branches{1,1} = char(first.getValue);
nleaves = 0;
nleaves = nleaves + handles.(matlab.lang.makeValidName(branches{1,1}))(1).getChildCount;
next = first.getNextSibling;
for n = 2:nbranches
branches{n,1} = char(next.getValue);
nleaves = nleaves + handles.(matlab.lang.makeValidName(branches{n,1}))(1).getChildCount;
next = next.getNextSibling;
end
leaves = cell(nleaves,1);
i = 0;
for n = 1:size(branches,1)
currentbranch = handles.(matlab.lang.makeValidName(branches{n,1}));
if currentbranch.getChildCount ~= 0
i = i + 1;
first = currentbranch.getFirstChild;
%leafnames(i,:) = first.getName;
leaves{i,:} = char(first.getValue);
next = first.getNextSibling;
if ~isempty(next)
for m = 1:currentbranch.getChildCount-1
i = i + 1;
%leafnames(i,:) = next.getName;
leaves{i,:} = char(next.getValue);
next = next.getNextSibling;
end
end
end
end
if nleaves == 0
warndlg('Nothing to delete!','AARAE info');
else
%leafnames = char(leafnames);
%leaves = char(leaves);
delete = questdlg('Current workspace will be cleared, would you like to proceed?',...
'Warning',...
'Yes','No','Yes');
switch delete
case 'Yes'
set(hObject,'BackgroundColor','red');
set(hObject,'Enable','off');
for i = 1:size(leaves,1)
current = handles.(matlab.lang.makeValidName(leaves{i,1}));
handles.mytree.remove(current);
handles = rmfield(handles,matlab.lang.makeValidName(leaves{i,1}));
end
handles.mytree.reloadNode(handles.root);
handles.mytree.setSelectedNode(handles.root);
rmpath([cd '/Utilities/Temp']);
rmdir([cd '/Utilities/Temp'],'s');
rmpath([cd '/Utilities/Backup']);
rmdir([cd '/Utilities/Backup'],'s');
mkdir([cd '/Utilities/Temp']);
mkdir([cd '/Utilities/Backup']);
addpath([cd '/Utilities/Temp']);
addpath([cd '/Utilities/Backup']);
set(handles.result_box,'Value',1);
set(handles.result_box,'String',cell(1,1));
fprintf(handles.fid, ['%% ' datestr(now,16) ' - Cleared workspace \n\n']);
set(hObject,'BackgroundColor',[0.94 0.94 0.94]);
set(hObject,'Enable','off');
set(handles.export_btn,'Enable','off');
end
end
guidata(hObject,handles)
% --- Executes on button press in CloseFiguresButton.
function CloseFiguresButton_Callback(hObject, eventdata, handles)
% hObject handle to CloseFiguresButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = findobj('type','figure','-not','tag','aarae');
delete(h)
% *************************************************************************
% CLOSE AARAE
% *************************************************************************
% --- Executes when user attempts to close aarae.
function aarae_CloseRequestFcn(hObject,eventdata,handles) %#ok
% hObject handle to aarae (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if strcmp(get(handles.export_btn,'Enable'),'on')
choice = questdlg('Are you sure to want to finish this AARAE session? Unexported data will be lost.',...
'Exit AARAE',...
'Yes','No','Export all & exit','Yes');
switch choice
case 'Yes'
if getappdata(handles.aarae,'waiting')
% The GUI is still in UIWAIT, so call UIRESUME and return
uiresume(hObject);
setappdata(handles.aarae,'waiting',0);
else
% The GUI is no longer waiting, so destroy it now.
delete(hObject);
end
% uiresume(handles.aarae);
case 'Export all & exit'
export_btn_Callback(handles.export_btn,eventdata,handles)
if getappdata(handles.aarae,'waiting')
% The GUI is still in UIWAIT, so call UIRESUME and return
uiresume(hObject);
setappdata(handles.aarae,'waiting',0);
else
% The GUI is no longer waiting, so destroy it now.
delete(hObject);
end
%uiresume(handles.aarae);
end
else
uiresume(handles.aarae);
end
% Check appdata flag to see if the main GUI is in a wait state
%if getappdata(handles.aarae,'waiting')
% The GUI is still in UIWAIT, so call UIRESUME and return
% uiresume(hObject);
% setappdata(handles.aarae,'waiting',0);
%else
% % The GUI is no longer waiting, so destroy it now.
% delete(hObject);
%end
% *************************************************************************
% CLEAN UP AFTER CLOSING GUI
% *************************************************************************
% --- Outputs from this function are returned to the command line.
function varargout = aarae_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to aarae
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Clean up the mess after closing the GUI
rmappdata(0,'hMain');
rmpath(genpath(cd));
rmdir([cd '/Utilities/Temp'],'s');
rmdir([cd '/Utilities/Backup'],'s');
fprintf(handles.fid, ['\n%% - End of AARAE session - ' datestr(now)]);
fclose('all');
if ~isempty(handles.aarae)
delete(handles.aarae);
end
java.lang.Runtime.getRuntime.gc % Java 'garbage collection'
% Get default command line output from handles structure
varargout{1} = [];
% *************************************************************************
% *************************************************************************
% THE 'START' BUTTONS: ACQUIRING AUDIO DATA
% *************************************************************************
% *************************************************************************
% *************************************************************************
% GENERATE AUDIO
% *************************************************************************
% --- Executes on button press in genaudio_btn.
function genaudio_btn_Callback(hObject, ~, handles)
% hObject handle to genaudio_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if strcmp(get(handles.recovery_txt,'Visible'),'on'), set(handles.recovery_txt,'Visible','off'); end
% Call the 'desktop'
hMain = getappdata(0,'hMain');
setappdata(hMain,'testsignal',[]);
% Call the window that allows signal generation
newleaf = genaudio('main_stage1', handles.aarae);
%set(handles.aarae,'CurrentObject',[])
% Update the tree with the generated signal
handles.mytree.setSelectedNode(handles.root);
if ~isempty(getappdata(hMain,'testsignal'))
signaldata = getappdata(hMain,'testsignal');
if isfield(signaldata,'tag'), signaldata = rmfield(signaldata,'tag'); end
signaldata.datatype = 'testsignals';
if isfield(signaldata,'audio')
%signaldata.nbits = 16;
iconPath = fullfile(matlabroot,'/toolbox/fixedpoint/fixedpointtool/resources/plot.png');
else
iconPath = fullfile(matlabroot,'/toolbox/matlab/icons/notesicon.gif');
end
signaldata = checkcal(signaldata);
signaldata = addhistory(signaldata,['Generated by ' handles.Settings.username ' using ' getappdata(hMain,'AARAEversion')],'all');
if isstruct(handles.IPdata)
historycell = cell(12,4);
historycell(:,3) = fieldnames(handles.IPdata);
historycell(:,4) = struct2cell(handles.IPdata);
signaldata.history = [signaldata.history; historycell];
end
if ~isempty(handles.login)
historycell = cell(1,4);
historycell{1,3} = 'System login';
historycell{1,4} = handles.login;
signaldata.history = [signaldata.history; historycell];
end
% if ~isempty(handles.address)
% historycell = cell(1,4);
% historycell{1,3} = 'Address';
% historycell{1,4} = handles.address;
% signaldata.history = [signaldata.history; historycell];
% end
leafname = isfield(handles,matlab.lang.makeValidName(newleaf));
if leafname == 1
index = 1;
% This while cycle is just to make sure no signals are
% overwriten
if length(matlab.lang.makeValidName([newleaf,'_',num2str(index)])) >= namelengthmax-2, newleaf = newleaf(1:round(end/2)); end
while isfield(handles,matlab.lang.makeValidName([newleaf,'_',num2str(index)])) == 1
index = index + 1;
end
newleaf = [newleaf,'_',num2str(index)];
end
% Save as you go
save([cd '/Utilities/Backup/' newleaf '.mat'], 'signaldata','-v7.3');
% Generate new leaf
signaldata.name = matlab.lang.makeValidName(newleaf);
handles.(signaldata.name) = uitreenode('v0', newleaf, newleaf, iconPath, true);
handles.(signaldata.name).UserData = signaldata;
handles.testsignals.add(handles.(signaldata.name));
handles.mytree.reloadNode(handles.testsignals);
handles.mytree.expand(handles.testsignals);
handles.mytree.setSelectedNode(handles.(signaldata.name));
set([handles.clrall_btn,handles.export_btn],'Enable','on')
% Log event
fprintf(handles.fid, ['%% ' datestr(now,16) ' - Generated ' newleaf ': duration = ' num2str(size(signaldata.audio,1)/signaldata.fs) ' s ; fs = ' num2str(signaldata.fs) ' Hz; size = ' num2str(size(signaldata.audio)) '\n']);
% Log verbose metadata
logaudioleaffields(signaldata,0);
end
java.lang.Runtime.getRuntime.gc % Java garbage collection
guidata(hObject, handles);
% *************************************************************************
% LOAD DATA INTO AARAE
% *************************************************************************
% --- Executes on button press in load_btn.
function load_btn_Callback(hObject, ~, handles)
% hObject handle to load_btn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Call the 'desktop'
hMain = getappdata(0,'hMain');
if strcmp(get(handles.recovery_txt,'Visible'),'on'), set(handles.recovery_txt,'Visible','off'); end
% Get path of the file to load
[filename,handles.defaultaudiopath,filterindex] = uigetfile(...
{'*.wav;*.mat;.WAV;.MAT','Test Signals (*.wav,*.mat)';...
'*.wav;*.mat;.WAV;.MAT','Measurement files (*.wav,*.mat)';...
'*.wav;*.mat;.WAV;.MAT','Processed files (*.wav,*.mat)';...
'*.wav;*.mat;.WAV;.MAT','Result files (*.wav,*.mat)'},...
'Select audio file',handles.defaultaudiopath,...
'MultiSelect','on');
if ~iscell(filename)
if ischar(filename), filename = cellstr(filename);
else return
end
end
h = waitbar(0,['Loading 1 of ' num2str(length(filename)) ' files'],'Name','AARAE info','WindowStyle','modal','Tag','progressbar');
steps = length(filename);
for i = 1:length(filename)
if filename{i} ~= 0
newleaf = cell(1,1);
[~,newleaf{1,1},ext] = fileparts(filename{i});
% Check type of file. First 'if' is for .mat, second is for .wav
if strcmp(ext,'.mat') || strcmp(ext,'.MAT')
file = importdata(fullfile(handles.defaultaudiopath,filename{i}));
if isstruct(file)
signaldata = file;
else
specs = inputdlg('Please specify the sampling frequency','Sampling frequency',1);
if (isempty(specs))
warndlg('Input field is blank, cannot load data!','AARAE info');
%signaldata = [];
return;
else
fs = str2double(specs{1,1});
%nbits = str2double(specs{2,1});
if isnan(fs) || fs<=0 % || isnan(nbits) || nbits<=0)
warndlg('Input MUST be a real positive number, cannot load data!','AARAE info');
%signaldata = [];
return;
else
signaldata = [];
signaldata.audio = file;
signaldata.fs = fs;
%signaldata.nbits = nbits;
end
end
end
end
if strcmp(ext,'.wav') || strcmp(ext,'.WAV')
signaldata = [];
[signaldata.audio,signaldata.fs] = audioread(fullfile(handles.defaultaudiopath,filename{i}));
%signaldata.nbits = 16;
end;
% Generate new leaf and update the tree
if ~isempty(signaldata)
if ~isfield(signaldata,'chanID') && isfield(signaldata,'audio')
signaldata.chanID = cellstr([repmat('Chan',size(signaldata.audio,2),1) num2str((1:size(signaldata.audio,2))')]);
end
if ~isfield(signaldata,'datatype') || (isfield(signaldata,'datatype') && strcmp(signaldata.datatype,'IR'))
if filterindex == 1, signaldata.datatype = 'testsignals'; end;
if filterindex == 2, signaldata.datatype = 'measurements'; end;
if filterindex == 3, signaldata.datatype = 'processed'; end;
if filterindex == 4, signaldata.datatype = 'results'; end;
end
signaldata = checkcal(signaldata);
signaldata = addhistory(signaldata,['Loaded by ' handles.Settings.username ' using ' getappdata(hMain,'AARAEversion')],'all');
if isstruct(handles.IPdata)
historycell = cell(12,4);
historycell(:,3) = fieldnames(handles.IPdata);
historycell(:,4) = struct2cell(handles.IPdata);
signaldata.history = [signaldata.history; historycell];
end
if isfield(signaldata,'audio') && ~strcmp(signaldata.datatype,'syscal')
iconPath = fullfile(matlabroot,'/toolbox/fixedpoint/fixedpointtool/resources/plot.png');
elseif strcmp(signaldata.datatype,'syscal')
iconPath = fullfile(matlabroot,'/toolbox/matlab/icons/boardicon.gif');