Mercurial > hg > camir-aes2014
comparison toolboxes/MIRtoolbox1.3.2/MIRToolbox/miroptions.m @ 0:e9a9cd732c1e tip
first hg version after svn
author | wolffd |
---|---|
date | Tue, 10 Feb 2015 15:05:51 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e9a9cd732c1e |
---|---|
1 function [orig during after] = miroptions(method,orig,specif,varg) | |
2 | |
3 DEFAULTFRAMELENGTH = .05; | |
4 DEFAULTFRAMEHOP = .5; | |
5 | |
6 % The options are determined during the bottom-up process design (see below). | |
7 | |
8 % During the following top-down evaluation initiation, the options being | |
9 % therefore already computed have simply been passed as fourth and fifth | |
10 % arguments of miroptions. | |
11 if not(isempty(varg)) && (isstruct(varg{1}) || isempty(varg{1})) | |
12 during = varg{1}; | |
13 if isstruct(varg{1}) | |
14 if isfield(during,'struct') | |
15 if isa(orig,'mirdesign') | |
16 orig = set(orig,'Struct',during.struct); | |
17 elseif iscell(orig) | |
18 for i = 1:length(orig) | |
19 if isa(orig{i},'mirdesign') | |
20 orig{i} = set(orig{i},'Struct',during.struct); | |
21 end | |
22 end | |
23 end | |
24 during = rmfield(during,'struct'); | |
25 end | |
26 end | |
27 if length(varg) > 1 | |
28 after = varg{2}; | |
29 else | |
30 after = []; | |
31 end | |
32 return | |
33 %elseif length(varg) > 1 && isstruct(varg{2}) | |
34 % during = varg{1}; | |
35 % after = varg{2}; | |
36 % return | |
37 %elseif length(varg) >= 1 && isempty(varg{1}) | |
38 % during = []; | |
39 % after = []; | |
40 % return | |
41 end | |
42 | |
43 | |
44 during = struct; | |
45 after = struct; | |
46 if isfield(specif,'option') | |
47 option = specif.option; | |
48 else | |
49 option = struct; | |
50 end | |
51 frame = []; | |
52 after = []; | |
53 fields = fieldnames(option); | |
54 persoframe = ''; | |
55 for i = 1:length(fields) | |
56 field = fields{i}; | |
57 if isfield(option.(field),'key') && ischar(option.(field).key) ... | |
58 && strcmpi(option.(field).key,'Frame') | |
59 persoframe = field; | |
60 during.(field).auto = 0; | |
61 end | |
62 if isfield(option.(field),'when') && ... | |
63 (strcmpi(option.(field).when,'After') || ... | |
64 strcmpi(option.(field).when,'Both')) | |
65 if isamir(orig,func2str(method)) ... | |
66 && not(strcmp(func2str(method),'miraudio')) | |
67 after.(field) = 0; | |
68 elseif strcmp(field,'detect') | |
69 %if haspeaks(orig) | |
70 % after.(field) = 0; | |
71 %else | |
72 after.(field) = 'Peaks'; | |
73 %end | |
74 elseif isfield(specif,'title') | |
75 if isa(orig,'mirdata') | |
76 title = get(orig,'Title'); | |
77 sameclass = (length(title) > length(specif.title) && ... | |
78 strcmp(title(1:length(specif.title)),specif.title)); | |
79 else | |
80 sameclass = strcmp(func2str(get(orig,'Method')),'mironsets'); | |
81 end | |
82 if sameclass | |
83 after.(field) = 0; | |
84 else | |
85 after.(field) = option.(field).default; | |
86 end | |
87 elseif isfield(option.(field),'default') | |
88 after.(field) = option.(field).default; | |
89 else | |
90 after.(field) = 0; | |
91 end | |
92 end | |
93 if not(isfield(option.(field),'when')) || strcmpi(option.(field).when,'Both') | |
94 if isfield(option.(field),'default') | |
95 if strcmpi(persoframe,field) | |
96 during.(field).length.val = option.(field).default(1); | |
97 during.(field).length.unit = 's'; | |
98 during.(field).hop.val = option.(field).default(2); | |
99 during.(field).hop.unit = '/1'; | |
100 else | |
101 during.(field) = option.(field).default; | |
102 end | |
103 end | |
104 end | |
105 end | |
106 i = 1; | |
107 while i <= length(varg) | |
108 arg = varg{i}; | |
109 if strcmpi(arg,'Frame') | |
110 frame.auto = isempty(persoframe); | |
111 frame.length.unit = 's'; | |
112 frame.hop.unit = '/1'; | |
113 if length(varg) > i && isnumeric(varg{i+1}) | |
114 i = i+1; | |
115 frame.length.val = varg{i}; | |
116 if length(varg) > i && ischar(varg{i+1}) && ... | |
117 (strcmpi(varg{i+1},'s') || strcmpi(varg{i+1},'sp')) | |
118 i = i+1; | |
119 frame.length.unit = varg{i}; | |
120 end | |
121 if length(varg) > i && isnumeric(varg{i+1}) | |
122 i = i+1; | |
123 frame.hop.val = varg{i}; | |
124 if length(varg) > i && ischar(varg{i+1}) && ... | |
125 (strcmpi(varg{i+1},'%') || strcmpi(varg{i+1},'/1') || ... | |
126 strcmpi(varg{i+1},'s') || strcmpi(varg{i+1},'sp')|| ... | |
127 strcmpi(varg{i+1},'Hz')) | |
128 i = i+1; | |
129 frame.hop.unit = varg{i}; | |
130 end | |
131 if not(frame.hop.val || strcmpi(frame.hop.unit,'Hz')) | |
132 mirerror(func2str(method),'The hop factor should be strictly positive.') | |
133 end | |
134 else | |
135 if not(isempty(persoframe)) | |
136 if isfield(option.(persoframe),'keydefault') | |
137 frame.hop.val = option.(persoframe).keydefault(2); | |
138 else | |
139 frame.hop.val = option.(persoframe).default(2); | |
140 end | |
141 elseif isfield(specif,'defaultframehop') | |
142 frame.hop.val = specif.defaultframehop; | |
143 else | |
144 frame.hop.val = DEFAULTFRAMEHOP; | |
145 end | |
146 end | |
147 else | |
148 if not(isempty(persoframe)) | |
149 if isfield(option.(persoframe),'keydefault') | |
150 frame.length.val = option.(persoframe).keydefault(1); | |
151 else | |
152 frame.length.val = option.(persoframe).default(1); | |
153 end | |
154 elseif isfield(specif,'defaultframelength') | |
155 frame.length.val = specif.defaultframelength; | |
156 else | |
157 frame.length.val = DEFAULTFRAMELENGTH; | |
158 end | |
159 if not(isempty(persoframe)) | |
160 if isfield(option.(persoframe),'keydefault') | |
161 frame.hop.val = option.(persoframe).keydefault(2); | |
162 else | |
163 frame.hop.val = option.(persoframe).default(2); | |
164 end | |
165 elseif isfield(specif,'defaultframehop') | |
166 frame.hop.val = specif.defaultframehop; | |
167 else | |
168 frame.hop.val = DEFAULTFRAMEHOP; | |
169 end | |
170 end | |
171 frame.eval = 0; | |
172 if not(isfield(option,'frame')) || ... | |
173 not(isfield(option.frame,'when')) || ... | |
174 strcmpi(option.frame.when,'Before') || ... | |
175 strcmpi(option.frame.when,'Both') | |
176 during.frame = frame; | |
177 end | |
178 if isfield(option,'frame') && ... | |
179 isfield(option.frame,'when') && ... | |
180 (strcmpi(option.frame.when,'After') || ... | |
181 strcmpi(option.frame.when,'Both')) | |
182 after.frame = frame; | |
183 end | |
184 else | |
185 match = 0; | |
186 k = 0; | |
187 while not(match) && k<length(fields) | |
188 k = k+1; | |
189 field = fields{k}; | |
190 if isfield(option.(field),'key') | |
191 key = option.(field).key; | |
192 if not(iscell(key)) | |
193 key = {key}; | |
194 end | |
195 for j = 1:length(key) | |
196 if strcmpi(arg,key{j}) | |
197 match = 1; | |
198 end | |
199 end | |
200 if match | |
201 if isfield(option.(field),'type') | |
202 type = option.(field).type; | |
203 else | |
204 type = []; | |
205 end | |
206 if isfield(option.(field),'unit') | |
207 unit = option.(field).unit; | |
208 defaultunit = option.(field).defaultunit; | |
209 else | |
210 unit = {}; | |
211 end | |
212 if isfield(option.(field),'from') | |
213 from = option.(field).from; | |
214 defaultfrom = option.(field).defaultfrom; | |
215 else | |
216 from = {}; | |
217 end | |
218 if strcmpi(type,'String') | |
219 if length(varg) > i && ... | |
220 (ischar(varg{i+1}) || varg{i+1} == 0) | |
221 if isfield(option.(field),'choice') | |
222 match2 = 0; | |
223 arg2 = varg{i+1}; | |
224 for j = option.(field).choice | |
225 if (ischar(j{1}) && strcmpi(arg2,j)) || ... | |
226 (not(ischar(j{1})) && isequal(arg2,j{1})) | |
227 match2 = 1; | |
228 i = i+1; | |
229 optionvalue = arg2; | |
230 end | |
231 end | |
232 if not(match2) | |
233 if isfield(option.(field),'keydefault') | |
234 optionvalue = option.(field).keydefault; | |
235 else | |
236 error(['SYNTAX ERROR IN ',func2str(method),... | |
237 ': Unexpected keyword after key ',arg'.']); | |
238 end | |
239 end | |
240 else | |
241 i = i+1; | |
242 optionvalue = varg{i}; | |
243 end | |
244 elseif isfield(option.(field),'keydefault') | |
245 optionvalue = option.(field).keydefault; | |
246 elseif isfield(option.(field),'default') | |
247 optionvalue = option.(field).default; | |
248 else | |
249 error(['SYNTAX ERROR IN ',func2str(method),... | |
250 ': A string should follow the key ',arg'.']); | |
251 end | |
252 elseif strcmpi(type,'Boolean') | |
253 if length(varg) > i && (isnumeric(varg{i+1}) || islogical(varg{i+1})) | |
254 i = i+1; | |
255 optionvalue = varg{i}; | |
256 elseif length(varg) > i && ischar(varg{i+1}) ... | |
257 && (strcmpi(varg{i+1},'on') || ... | |
258 strcmpi(varg{i+1},'yes')) | |
259 i = i+1; | |
260 optionvalue = 1; | |
261 elseif length(varg) > i && ischar(varg{i+1}) ... | |
262 && (strcmpi(varg{i+1},'off') || ... | |
263 strcmpi(varg{i+1},'no')) | |
264 i = i+1; | |
265 optionvalue = 0; | |
266 else | |
267 optionvalue = 1; | |
268 end | |
269 elseif strcmpi(type,'Integer') || strcmpi(type,'Integers') | |
270 if length(varg) > i && isnumeric(varg{i+1}) | |
271 i = i+1; | |
272 optionvalue = varg{i}; | |
273 elseif isfield(option.(field),'keydefault') | |
274 if strcmpi(type,'Integers') | |
275 optionvalue = option.(field).keydefault; | |
276 else | |
277 optionvalue = option.(field).keydefault(1); | |
278 end | |
279 elseif isfield(option.(field),'default') | |
280 if strcmpi(type,'Integers') | |
281 optionvalue = option.(field).default; | |
282 else | |
283 optionvalue = option.(field).default(1); | |
284 end | |
285 else | |
286 error(['SYNTAX ERROR IN ',func2str(method),... | |
287 ': An integer should follow the key ',arg'.']); | |
288 end | |
289 if isfield(option.(field),'number')... | |
290 && option.(field).number == 2 | |
291 if length(varg) > i && isnumeric(varg{i+1}) | |
292 i = i+1; | |
293 optionvalue = [optionvalue varg{i}]; | |
294 elseif isfield(option.(field),'keydefault') | |
295 optionvalue = [optionvalue option.(field).keydefault(2)]; | |
296 elseif isfield(option.(field),'default') | |
297 optionvalue = [optionvalue option.(field).default(2)]; | |
298 else | |
299 error(['SYNTAX ERROR IN ',func2str(method),... | |
300 ': Two integers should follow the key ',arg'.']); | |
301 end | |
302 end | |
303 if not(isempty(unit)) | |
304 if (strcmpi(unit{1},'s') || ... | |
305 strcmpi(unit{2},'s')) && ... | |
306 (strcmpi(unit{1},'Hz') || ... | |
307 strcmpi(unit{2},'Hz')) | |
308 if length(varg) > i && ... | |
309 ischar(varg{i+1}) && ... | |
310 (strcmpi(varg{i+1},'s') || ... | |
311 strcmpi(varg{i+1},'Hz')) | |
312 i = i+1; | |
313 if not(strcmpi(varg{i},defaultunit)) | |
314 if isfield(option.(field),'opposite') | |
315 field = option.(field).opposite; | |
316 end | |
317 optionvalue = 1/optionvalue; | |
318 end | |
319 end | |
320 end | |
321 if (strcmpi(unit{1},'s') || ... | |
322 strcmpi(unit{2},'s')) && ... | |
323 (strcmpi(unit{1},'sp') || ... | |
324 strcmpi(unit{2},'sp')) | |
325 if length(varg) > i && ... | |
326 ischar(varg{i+1}) && ... | |
327 (strcmpi(varg{i+1},'sp') || ... | |
328 strcmpi(varg{i+1},'s')) | |
329 i = i+1; | |
330 if strcmpi(varg{i},'sp') | |
331 optionvalue = [optionvalue 0]; | |
332 else | |
333 optionvalue = [optionvalue 1]; | |
334 end | |
335 else | |
336 optionvalue = [optionvalue 1]; | |
337 end | |
338 end | |
339 end | |
340 if not(isempty(from)) | |
341 if length(varg) > i && ... | |
342 ischar(varg{i+1}) && ... | |
343 (strcmpi(varg{i+1},'Start') || ... | |
344 strcmpi(varg{i+1},'Middle') || ... | |
345 strcmpi(varg{i+1},'End')) | |
346 i = i+1; | |
347 if strcmpi(varg{i},'Start') | |
348 optionvalue = [optionvalue 0]; | |
349 elseif strcmpi(varg{i},'Middle') | |
350 optionvalue = [optionvalue 1]; | |
351 elseif strcmpi(varg{i},'End') | |
352 optionvalue = [optionvalue 2]; | |
353 end | |
354 else | |
355 optionvalue = [optionvalue 0]; | |
356 end | |
357 if isa(orig,'mirdesign') | |
358 orig = set(orig,'Size',optionvalue); | |
359 end | |
360 end | |
361 else | |
362 if length(varg) > i | |
363 i = i+1; | |
364 optionvalue = varg{i}; | |
365 elseif isfield(option.(field),'keydefault') | |
366 optionvalue = option.(field).keydefault(1); | |
367 else | |
368 error(['SYNTAX ERROR IN ',func2str(method),... | |
369 ': Data should follow the key ',arg'.']); | |
370 end | |
371 end | |
372 end | |
373 else | |
374 if isfield(option.(field),'choice') | |
375 for j = option.(field).choice | |
376 if strcmpi(arg,j) | |
377 match = 1; | |
378 optionvalue = arg; | |
379 end | |
380 end | |
381 end | |
382 end | |
383 if not(match) | |
384 if isfield(option.(field),'position') | |
385 if i+1 == option.(field).position | |
386 match = 1; | |
387 optionvalue = arg; | |
388 end | |
389 %else | |
390 % error(['SYNTAX ERROR IN ',func2str(method),... | |
391 % ': Badly specified key ',arg'.']); | |
392 end | |
393 end | |
394 if match == 1 | |
395 match = 2; | |
396 if isfield(option.(field),'when') ... | |
397 && (strcmpi(option.(field).when,'After') || ... | |
398 strcmpi(option.(field).when,'Both')) | |
399 after.(field) = optionvalue; | |
400 end | |
401 if not(isfield(option.(field),'when')) ... | |
402 || strcmpi(option.(field).when,'Both') | |
403 during.(field) = optionvalue; | |
404 end | |
405 end | |
406 end | |
407 if not(match) | |
408 if isnumeric(arg) || islogical(arg) | |
409 arg = num2str(arg); | |
410 end | |
411 error(['SYNTAX ERROR IN ',func2str(method),... | |
412 ': Unknown parameter ',arg'.']); | |
413 end | |
414 end | |
415 i = i+1; | |
416 end |