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