tomwalters@0: % method of class @parameter tomwalters@0: % bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org tomwalters@0: function param=add(param,type,text,argument4,argument5,argument6,argument7,argument8,argument9) tomwalters@0: % add a new parameter to the structure tomwalters@0: % and set its inital state variables tomwalters@0: tomwalters@0: cont=param.entries; tomwalters@0: newentrynr=length(cont)+1; tomwalters@0: tomwalters@0: % each entry must be one of the following types: tomwalters@0: % float (% floats can have an UNIT) tomwalters@0: % int tomwalters@0: % string tomwalters@0: % bool (checkbox) tomwalters@0: % button tomwalters@0: % radiobutton (radiobutton) tomwalters@0: % filename (a button and a string box) tomwalters@0: % directoryname (a button and a string box) tomwalters@0: % pop-up menu (a couple of strings) tomwalters@0: % slider (a float plus a slider) tomwalters@0: % tomwalters@0: % it can also be a panel that is a subpanel that contains different uicontrols for example radiobuttons tomwalters@0: tomwalters@0: if strcmp(type,'panel') tomwalters@0: param.panelinfo.panelcount=0; % reset the counter because the next n entries are in this panel tomwalters@0: param.panelinfo.is_in_panel=1; % flag for the next ones tomwalters@0: param.panelinfo.count_panels_up_to=argument4; % so many are coming tomwalters@0: param.panelinfo.current_panel=text; tomwalters@0: end tomwalters@0: tomwalters@0: % every entry is part of a panel. Either of type 'all' or of the given tomwalters@0: % subpanels tomwalters@0: if ~isfield(param.panelinfo,'panelcount') || ~param.panelinfo.is_in_panel tomwalters@0: cont{newentrynr}.panel='all'; tomwalters@0: else tomwalters@0: cont{newentrynr}.panel=param.panelinfo.current_panel; tomwalters@0: param.panelinfo.panelcount=param.panelinfo.panelcount+1; tomwalters@0: if param.panelinfo.panelcount>param.panelinfo.count_panels_up_to tomwalters@0: param.panelinfo.is_in_panel=0; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: cont{newentrynr}.type=type; tomwalters@0: cont{newentrynr}.enable=1; % enable it by default tomwalters@0: tomwalters@0: % each entry has a text that characterises it uniqly: tomwalters@0: cont{newentrynr}.text=text; tomwalters@0: tomwalters@0: % each entry can have an callback function that is called after it looses tomwalters@0: % its focus or is pressed: tomwalters@0: cont{newentrynr}.callback=''; tomwalters@0: tomwalters@0: tomwalters@0: % set the tooltip as the name (currently for debugging) tomwalters@0: cont{newentrynr}.tooltiptext=cont{newentrynr}.text; tomwalters@0: tomwalters@0: switch type tomwalters@0: case {'int'} tomwalters@0: % 1 2 3 4 5 6 tomwalters@0: % object type name val minval maxval tomwalters@0: % eg params=add(params,'int','min bins above thres',2, 0, inf); tomwalters@0: tomwalters@0: if nargin>=4 tomwalters@0: cont{newentrynr}.value=argument4; tomwalters@0: else tomwalters@0: cont{newentrynr}.value=0; tomwalters@0: end tomwalters@0: if nargin<5 tomwalters@0: cont{newentrynr}.minvalue=intmin; tomwalters@0: else tomwalters@0: cont{newentrynr}.minvalue=argument5; tomwalters@0: end tomwalters@0: if nargin<6 tomwalters@0: cont{newentrynr}.maxvalue=intmax; tomwalters@0: else tomwalters@0: cont{newentrynr}.maxvalue=argument6; tomwalters@0: end tomwalters@0: tomwalters@0: case {'float'} tomwalters@0: % 1 2 3 4 5 6 7 8 tomwalters@0: % object type name unittype val userunit minval maxval tomwalters@0: % eg params=add(params,'float','window start',unit_time,0, 'ms', 0 ,lenstim); tomwalters@0: if ~isobject(argument4) % without a unit its a unit_none and argument4 is the value tomwalters@0: if isnumeric(argument4) tomwalters@0: cont{newentrynr}.stringvalue=num2str(argument4); tomwalters@0: cont{newentrynr}.rawvalue=argument4; tomwalters@0: else tomwalters@0: cont{newentrynr}.stringvalue=argument4; tomwalters@0: cont{newentrynr}.rawvalue=str2num(argument4); tomwalters@0: end tomwalters@0: cont{newentrynr}.unittype=unit_none; tomwalters@0: cont{newentrynr}.orgunit=unit_none; tomwalters@0: else tomwalters@0: cont{newentrynr}.unittype=argument4; % the general unit (eg unit_time) tomwalters@0: if ischar(argument5) tomwalters@0: cont{newentrynr}.stringvalue=argument5; tomwalters@0: else tomwalters@0: cont{newentrynr}.stringvalue=num2str(argument5); tomwalters@0: end tomwalters@0: if ~isa(argument4,'unit_none') tomwalters@0: cont{newentrynr}.orgunit=argument6; % the definition unit (later used in calls with set) tomwalters@0: if ischar(argument5) && ~strcmp(argument5,'auto') tomwalters@0: cont{newentrynr}.rawvalue=fromunits(argument4,str2num(argument5),argument6); tomwalters@0: elseif ~strcmp(argument5,'auto') tomwalters@0: cont{newentrynr}.rawvalue=fromunits(argument4,argument5,argument6); tomwalters@0: else tomwalters@0: cont{newentrynr}.rawvalue='auto'; tomwalters@0: end tomwalters@0: else tomwalters@0: if exist('argument6','var') && isnumeric(argument6) tomwalters@0: temp=argument7; tomwalters@0: argument7=argument6; tomwalters@0: argument8=temp; tomwalters@0: end tomwalters@0: cont{newentrynr}.orgunit=''; % the definition unit (later used in calls with set) tomwalters@0: cont{newentrynr}.rawvalue=argument5; tomwalters@0: end tomwalters@0: end % without unit tomwalters@0: if nargin<7 tomwalters@0: cont{newentrynr}.minvalue=-inf; tomwalters@0: else tomwalters@0: cont{newentrynr}.minvalue=argument7; tomwalters@0: end tomwalters@0: if nargin<8 tomwalters@0: cont{newentrynr}.maxvalue=+inf; tomwalters@0: else tomwalters@0: cont{newentrynr}.maxvalue=argument8; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: case {'slider'} tomwalters@0: % 1 2 3 4 5 6 7 8 9 tomwalters@0: % object type name unittype val userunit minval maxval logornot tomwalters@0: % eg params=add(params,'slider','slidval',unit_time, 0, 'ms', 0 , inf, islog); tomwalters@0: if ~isobject(argument4) % without a unit its a unit_none and argument4 is the value tomwalters@0: if isnumeric(argument4) tomwalters@0: cont{newentrynr}.stringvalue=num2str(argument4); tomwalters@0: cont{newentrynr}.rawvalue=argument4; tomwalters@0: else tomwalters@0: cont{newentrynr}.stringvalue=argument4; tomwalters@0: cont{newentrynr}.rawvalue=str2num(argument4); tomwalters@0: end tomwalters@0: cont{newentrynr}.unittype=unit_none; tomwalters@0: cont{newentrynr}.orgunit=unit_none; tomwalters@0: if nargin<7 % is log or not tomwalters@0: tmp=1; tomwalters@0: else tomwalters@0: tmp=argument7; tomwalters@0: end tomwalters@0: argument7=argument5; % minvalue tomwalters@0: argument8=argument6; % maxvalue must be there! tomwalters@0: argument9=tmp; tomwalters@0: else tomwalters@0: cont{newentrynr}.unittype=argument4; % the general unit (eg unit_time) tomwalters@0: if ischar(argument5) tomwalters@0: cont{newentrynr}.stringvalue=argument5; tomwalters@0: else tomwalters@0: cont{newentrynr}.stringvalue=num2str(argument5); tomwalters@0: end tomwalters@0: if ~isa(argument4,'unit_none') tomwalters@0: cont{newentrynr}.orgunit=argument6; % the definition unit (later used in calls with set) tomwalters@0: if ischar(argument5) && ~strcmp(argument5,'auto') tomwalters@0: cont{newentrynr}.rawvalue=fromunits(argument4,str2num(argument5),argument6); tomwalters@0: elseif ~strcmp(argument5,'auto') tomwalters@0: cont{newentrynr}.rawvalue=fromunits(argument4,argument5,argument6); tomwalters@0: else tomwalters@0: cont{newentrynr}.rawvalue='auto'; tomwalters@0: end tomwalters@0: else tomwalters@0: if exist('argument6','var') && isnumeric(argument6) tomwalters@0: temp=argument7; tomwalters@0: argument7=argument6; tomwalters@0: argument8=temp; tomwalters@0: end tomwalters@0: cont{newentrynr}.orgunit=''; % the definition unit (later used in calls with set) tomwalters@0: cont{newentrynr}.rawvalue=argument5; tomwalters@0: end tomwalters@0: end % without unit tomwalters@0: if ~exist('argument7','var') tomwalters@0: cont{newentrynr}.minvalue=-inf; tomwalters@0: else tomwalters@0: cont{newentrynr}.minvalue=argument7; tomwalters@0: end tomwalters@0: if ~exist('argument8','var') tomwalters@0: cont{newentrynr}.maxvalue=+inf; tomwalters@0: else tomwalters@0: cont{newentrynr}.maxvalue=argument8; tomwalters@0: end tomwalters@0: if ~exist('argument9','var') tomwalters@0: cont{newentrynr}.islog=0; tomwalters@0: else tomwalters@0: cont{newentrynr}.islog=argument9; tomwalters@0: end tomwalters@0: if isa(cont{newentrynr}.orgunit,'unit_none') tomwalters@0: cont{newentrynr}.editscaler=1; tomwalters@0: else tomwalters@0: cont{newentrynr}.editscaler=tounits(argument4,1,argument6); tomwalters@0: cont{newentrynr}.minvalue=fromunits(argument4,cont{newentrynr}.minvalue,argument6); tomwalters@0: cont{newentrynr}.maxvalue=fromunits(argument4,cont{newentrynr}.maxvalue,argument6); tomwalters@0: end tomwalters@0: cont{newentrynr}.nreditdigits=4; tomwalters@0: tomwalters@0: % 1 2 3 4 5 tomwalters@0: % object type name val other value tomwalters@0: % params=add(params,'bool','swap dimensions','true','othervalue'); tomwalters@0: case {'bool','radiobutton'} tomwalters@0: if nargin<4 tomwalters@0: argument4=''; tomwalters@0: end tomwalters@0: if ischar(argument4) tomwalters@0: if strcmp(argument4,'true') tomwalters@0: cont{newentrynr}.value=1; tomwalters@0: else tomwalters@0: cont{newentrynr}.value=0; tomwalters@0: end tomwalters@0: else tomwalters@0: cont{newentrynr}.value=argument4; tomwalters@0: end tomwalters@0: cont{newentrynr}.tooltiptext=[cont{newentrynr}.panel ': ' cont{newentrynr}.text]; tomwalters@0: cont{newentrynr}.enables={}; % these are the ones that are switched on by me tomwalters@0: cont{newentrynr}.enables_inbox={}; tomwalters@0: cont{newentrynr}.disables={}; % and these are switched off tomwalters@0: cont{newentrynr}.disables_inbox={}; tomwalters@0: if nargin==5 tomwalters@0: cont{newentrynr}.userdata=argument5; tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: % 1 2 3 4 5 tomwalters@0: % object type name callback default tomwalters@0: % params=add(params,'button','analyse','ret=fkt(d,params,''plot'');',1); tomwalters@0: case 'button' tomwalters@0: cont{newentrynr}.value=0; tomwalters@0: if strcmp(text,'OK') tomwalters@0: cont{newentrynr}.callback='close'; tomwalters@0: if nargin==4 && isnumeric(argument4) tomwalters@0: cont{newentrynr}.isdefaultbutton=argument4; tomwalters@0: else tomwalters@0: cont{newentrynr}.isdefaultbutton=0; tomwalters@0: end tomwalters@0: else tomwalters@0: cont{newentrynr}.callback=argument4; tomwalters@0: end tomwalters@0: cont{newentrynr}.tooltiptext=['button: ' cont{newentrynr}.text]; tomwalters@0: if nargin==5 && isnumeric(argument5) tomwalters@0: cont{newentrynr}.isdefaultbutton=argument5; tomwalters@0: else tomwalters@0: if ~strcmp(text,'OK') tomwalters@0: cont{newentrynr}.isdefaultbutton=0; tomwalters@0: end tomwalters@0: end tomwalters@0: tomwalters@0: case 'pop-up menu' tomwalters@0: cont{newentrynr}.value=argument4{1}; tomwalters@0: cont{newentrynr}.numeric_value=1; tomwalters@0: cont{newentrynr}.possible_values=argument4; tomwalters@0: cont{newentrynr}.tooltiptext=['pop-up menu: ' cont{newentrynr}.text]; tomwalters@0: tomwalters@0: % 1 2 3 4 5 tomwalters@0: % object type name strvalue length of window tomwalters@0: % dstruct=add(dstruct,'string','comment',WHATcomment,30); tomwalters@0: case 'string' tomwalters@0: cont{newentrynr}.value=argument4; tomwalters@0: if nargin>=5 tomwalters@0: cont{newentrynr}.width=argument5; tomwalters@0: else tomwalters@0: cont{newentrynr}.width=-1; tomwalters@0: end tomwalters@0: cont{newentrynr}.tooltiptext=['string: ' cont{newentrynr}.text]; tomwalters@0: tomwalters@0: % 1 2 3 4 tomwalters@0: % object type name nr rows tomwalters@0: % dstruct=add(dstruct,'panel','unit type',10); tomwalters@0: case 'panel' tomwalters@0: cont{newentrynr}.panel=text; tomwalters@0: cont{newentrynr}.tooltiptext=['panel: ' cont{newentrynr}.text]; tomwalters@0: cont{newentrynr}.nr_elements=argument4; tomwalters@0: case 'filename' tomwalters@0: if nargin<4 tomwalters@0: cont{newentrynr}.value=''; tomwalters@0: else tomwalters@0: cont{newentrynr}.value=argument4; tomwalters@0: end tomwalters@0: cont{newentrynr}.tooltiptext=['file name: ' cont{newentrynr}.text]; tomwalters@0: case 'directoryname' tomwalters@0: if nargin<4 tomwalters@0: cont{newentrynr}.value=''; tomwalters@0: else tomwalters@0: cont{newentrynr}.value=argument4; tomwalters@0: end tomwalters@0: cont{newentrynr}.tooltiptext=['directry name: ' cont{newentrynr}.text]; tomwalters@0: otherwise tomwalters@0: error(sprintf('dont know type ''%s''',type)) tomwalters@0: end tomwalters@0: tomwalters@0: tomwalters@0: tomwalters@0: % save them tomwalters@0: param.entries=cont;