function varargout = pref_screen(varargin)
% PREF_SCREEN M-file for pref_screen.fig
%      PREF_SCREEN, by itself, creates a new PREF_SCREEN or raises the existing
%      singleton*.
%
%      H = PREF_SCREEN returns the handle to a new PREF_SCREEN or the handle to
%      the existing singleton*.
%
%      PREF_SCREEN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in PREF_SCREEN.M with the given input arguments.
%
%      PREF_SCREEN('Property','Value',...) creates a new PREF_SCREEN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before pref_screen_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to pref_screen_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 pref_screen

% Last Modified by GUIDE v2.5 17-May-2005 16:59:06

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @pref_screen_OpeningFcn, ...
                   'gui_OutputFcn',  @pref_screen_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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


% --- Executes just before pref_screen is made visible.
function pref_screen_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% 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 pref_screen (see VARARGIN)

% Choose default command line output for pref_screen
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes pref_screen wait for user response (see UIRESUME)
% uiwait(handles.figure1);

handles.prefs=varargin{1};
set(handles.buttfilt,'value',handles.prefs.buttfilton);
set(handles.buttfiltcutoff,'string',handles.prefs.cutoff);
set(handles.buttfiltslope,'string',handles.prefs.slope);

set(handles.thresh,'value',handles.prefs.thresholdon);
set(handles.threshlevel,'string',20*log10(handles.prefs.threshold));

set(handles.gausslpf,'value',handles.prefs.gaussLPFon);
set(handles.gausslpfkernel,'string',handles.prefs.gaussLPF);

set(handles.fir,'value',handles.prefs.FIRon);
set(handles.fircutoff,'string',handles.prefs.FIRcutoff);

set(handles.mincalltime,'string',handles.prefs.mincalltime);
set(handles.mincallsep,'string',handles.prefs.mincallsep);
handles.prefs
set(handles.f12thresh,'string',handles.prefs.f12thresh);
set(handles.edit9,'string',20*log10(handles.prefs.showcallthresh));

set(handles.ChkOther,'Value',handles.prefs.CO);
set(handles.ChkNull,'Value',handles.prefs.CN);
set(handles.ChkA,'Value',handles.prefs.CA);
set(handles.ChkB,'Value',handles.prefs.CB);
set(handles.ChkC,'Value',handles.prefs.CC);
set(handles.ChkD,'Value',handles.prefs.CD);
set(handles.ChkE,'Value',handles.prefs.CE);
set(handles.ChkF,'Value',handles.prefs.CF);
set(handles.ChkG,'Value',handles.prefs.CG);
set(handles.ChkH,'Value',handles.prefs.CH);

guidata(hObject, handles);


% --- Outputs from this function are returned to the command line.
function varargout = pref_screen_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes during object creation, after setting all properties.
function threshlevel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to threshlevel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function threshlevel_Callback(hObject, eventdata, handles)
% hObject    handle to threshlevel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of threshlevel as text
%        str2double(get(hObject,'String')) returns contents of threshlevel as a double

level_dB=str2num(get(handles.threshlevel,'string')); 
handles.prefs.threshold=10^(level_dB/20);guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function buttfiltcutoff_CreateFcn(hObject, eventdata, handles)
% hObject    handle to buttfiltcutoff (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function buttfiltcutoff_Callback(hObject, eventdata, handles)
% hObject    handle to buttfiltcutoff (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of buttfiltcutoff as text
%        str2double(get(hObject,'String')) returns contents of buttfiltcutoff as a double

handles.prefs.cutoff=str2num(get(handles.buttfiltcutoff,'string')); guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function gausslpfkernel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to gausslpfkernel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function gausslpfkernel_Callback(hObject, eventdata, handles)
% hObject    handle to gausslpfkernel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of gausslpfkernel as text
%        str2double(get(hObject,'String')) returns contents of gausslpfkernel as a double

handles.prefs.gaussLPF=str2num(get(handles.gausslpfkernel,'string')); guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function fircutoff_CreateFcn(hObject, eventdata, handles)
% hObject    handle to fircutoff (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function fircutoff_Callback(hObject, eventdata, handles)
% hObject    handle to fircutoff (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of fircutoff as text
%        str2double(get(hObject,'String')) returns contents of fircutoff as a double

handles.prefs.FIRcutoff=str2num(get(handles.fircutoff,'string')); guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function mincalltime_CreateFcn(hObject, eventdata, handles)
% hObject    handle to mincalltime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function mincalltime_Callback(hObject, eventdata, handles)
% hObject    handle to mincalltime (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of mincalltime as text
%        str2double(get(hObject,'String')) returns contents of mincalltime as a double

handles.prefs.mincalltime=str2num(get(handles.mincalltime,'string')); guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function mincallsep_CreateFcn(hObject, eventdata, handles)
% hObject    handle to mincallsep (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function mincallsep_Callback(hObject, eventdata, handles)
% hObject    handle to mincallsep (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of mincallsep as text
%        str2double(get(hObject,'String')) returns contents of mincallsep as a double

handles.prefs.mincallsep=str2num(get(handles.mincallsep,'string')); guidata(hObject, handles);


% --- Executes on button press in buttfilt.
function buttfilt_Callback(hObject, eventdata, handles)
% hObject    handle to buttfilt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of buttfilt

handles.prefs.buttfilton=get(handles.buttfilt,'value'); guidata(hObject, handles);

% --- Executes on button press in thresh.
function thresh_Callback(hObject, eventdata, handles)
% hObject    handle to thresh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of thresh

handles.prefs.thresholdon=get(handles.thresh,'value'); guidata(hObject, handles);

% --- Executes on button press in gausslpf.
function gausslpf_Callback(hObject, eventdata, handles)
% hObject    handle to gausslpf (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of gausslpf

handles.prefs.gaussLPFon=get(handles.gausslpf,'value'); guidata(hObject, handles);

% --- Executes on button press in fir.
function fir_Callback(hObject, eventdata, handles)
% hObject    handle to fir (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of fir

handles.prefs.FIRon=get(handles.fir,'value'); guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function buttfiltslope_CreateFcn(hObject, eventdata, handles)
% hObject    handle to buttfiltslope (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function buttfiltslope_Callback(hObject, eventdata, handles)
% hObject    handle to buttfiltslope (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of buttfiltslope as text
%        str2double(get(hObject,'String')) returns contents of buttfiltslope as a double

handles.prefs.slope=str2num(get(handles.buttfiltslope,'string')); guidata(hObject, handles);

% --- Executes on button press in ok.
function ok_Callback(hObject, eventdata, handles)
% hObject    handle to ok (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

bob = handles.prefs

close(handles.output)
main(handles.prefs)


% --- Executes on button press in ChkOther.
function ChkOther_Callback(hObject, eventdata, handles)
% hObject    handle to ChkOther (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkOther
handles.prefs.CO = get(handles.ChkOther,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkNull.
function ChkNull_Callback(hObject, eventdata, handles)
% hObject    handle to ChkNull (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkNull
handles.prefs.CN = get(handles.ChkNull,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkA.
function ChkA_Callback(hObject, eventdata, handles)
% hObject    handle to ChkA (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkA
handles.prefs.CA = get(handles.ChkA,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkB.
function ChkB_Callback(hObject, eventdata, handles)
% hObject    handle to ChkB (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkB
handles.prefs.CB = get(handles.ChkB,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkC.
function ChkC_Callback(hObject, eventdata, handles)
% hObject    handle to ChkC (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkC
handles.prefs.CC = get(handles.ChkC,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkD.
function ChkD_Callback(hObject, eventdata, handles)
% hObject    handle to ChkD (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkD
handles.prefs.CD = get(handles.ChkD,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkE.
function ChkE_Callback(hObject, eventdata, handles)
% hObject    handle to ChkE (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkE
handles.prefs.CE = get(handles.ChkE,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkF.
function ChkF_Callback(hObject, eventdata, handles)
% hObject    handle to ChkF (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkF
handles.prefs.CF = get(handles.ChkF,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkG.
function ChkG_Callback(hObject, eventdata, handles)
% hObject    handle to ChkG (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkG
handles.prefs.CG = get(handles.ChkG,'Value');
guidata(hObject, handles);

% --- Executes on button press in ChkH.
function ChkH_Callback(hObject, eventdata, handles)
% hObject    handle to ChkH (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of ChkH
handles.prefs.CH = get(handles.ChkH,'Value');
guidata(hObject, handles);


% % --- Executes on button press in f12threshold.
% function f12threshold_Callback(hObject, eventdata, handles)
% % hObject    handle to f12threshold (see GCBO)
% % eventdata  reserved - to be defined in a future version of MATLAB
% % handles    structure with handles and user data (see GUIDATA)
% 
% % Hint: get(hObject,'Value') returns toggle state of f12threshold
% 
% handles.prefs.f12thresh=get(handles.f12threshold,'value'); guidata(hObject, handles);


% --- Executes on button press in checkbox20.
function checkbox20_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox20 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of checkbox20


% --- Executes during object creation, after setting all properties.
function f12thresh_CreateFcn(hObject, eventdata, handles)
% hObject    handle to f12thresh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


function f12thresh_Callback(hObject, eventdata, handles)
% hObject    handle to f12thresh (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of f12thresh as text
%        str2double(get(hObject,'String')) returns contents of f12thresh as a double

handles.prefs.f12thresh=get(handles.f12thresh,'value');
guidata(hObject, handles);


function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double

handles.prefs.showcallthresh=10^(str2num(get(handles.edit9,'string'))/20);
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


