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

% Last Modified by GUIDE v2.5 04-Apr-2009 20:00:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @fotball_OpeningFcn, ...
                   'gui_OutputFcn',  @fotball_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

% --- Executes just before fotball is made visible.
function fotball_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 fotball (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes fotball wait for user response (see UIRESUME)
% uiwait(handles.figure1);
set(handles.axes1,'SelectionHighlight','on')


% --- Outputs from this function are returned to the command line.
function varargout = fotball_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;
set(handles.checkbox5,'Visible','off');
set(handles.checkbox6,'Visible','off');
set(handles.checkbox7,'Visible','off');
set(handles.checkbox8,'Visible','off');

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)

global cesta
global FileName
global fs
[FileName cesta fs]=otevrit;
if FileName ~= 0
    set(handles.text1,'String', ['Soubor pro analýzu: "', FileName ...
        '"     Fvz = ' num2str(fs/1000) ' kHz']);
    set(handles.listbox1,'FontName','Courier New')
else
    set(handles.text1,'String',['Nebyl vybrán žadný soubor pro analýzu.'...
        ' Doporučuji zkusit to znovu. :-)'])
end



% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)

z=get(handles.checkbox1,'Value');
if z==1;
    set(handles.checkbox5,'Visible','on');
else
    set(handles.checkbox5,'Value',0);
    set(handles.checkbox5,'Visible','off');
end


% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)

z=get(handles.checkbox2,'Value');
if z==1;
    set(handles.checkbox6,'Visible','on');
else
    set(handles.checkbox6,'Value',0);
    set(handles.checkbox6,'Visible','off');
end

% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)

z=get(handles.checkbox3,'Value');
if z==1;
    set(handles.checkbox7,'Visible','on');
else
    set(handles.checkbox7,'Value',0);
    set(handles.checkbox7,'Visible','off');
end

% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)

z=get(handles.checkbox4,'Value');
if z==1;
    set(handles.checkbox8,'Visible','on');
else
    set(handles.checkbox8,'Value',0);
    set(handles.checkbox8,'Visible','off');
end

% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)

global cesta
global fs
global vysH
global FileName

info(1)=get(handles.checkbox1,'Value');     %hymna
info(2)=get(handles.checkbox2,'Value');       %okamziky
info(3)=get(handles.checkbox3,'Value');       %hvizd
info(4)=get(handles.checkbox4,'Value');       %energie
set(handles.listbox2,'String','');

if isempty(cesta)==0 && sum(info)>0      %nebyl vybran soubor tak ...  
    set(handles.text1,'String','Probíhá analýza')
    pause(0.001)

% % % % % % % fce pro detekci % % % % % % % % % % % % % % % % % % % % %
    [vysH]=analyza(cesta,info(1),info(2),info(3),info(4),fs,handles);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % % 
    set(handles.text1,'String',['Analýza souboru: ,,' FileName '" je hotova'])
%     ulozeni logu
    ulozeni_logu(info, cesta, vysH,handles)
    
elseif sum(info)==0
    set(handles.text1,'String','Nebyla vybrána volba analýzy prosím vyberte.')    
else
    set(handles.text1,'String',['Před použítím analýzy je nutné načíst'...
        ' soubor pro analýzu. Doporučuji vybrat soubor. :-)'])
    pushbutton1_Callback(hObject, eventdata, handles);
    pushbutton2_Callback(hObject, eventdata, handles);
end

% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)

global vysH
if isempty(vysH)==0
    index=get(handles.listbox1,'Value');
    part=get(handles.slider1,'Value');
    if vysH(1).time(1)>0
    naznaceni(index,part,vysH,handles);
    end
end


% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)

global vysH
set(handles.slider1, 'Value',round(get(handles.slider1, 'Value')));
part=round(get(handles.slider1, 'Value'));
if isempty(vysH)==0
    if get(handles.checkbox7,'Value')==1
        set(handles.listbox1,'String',vysH(part).ramec);
        bar(handles.axes1,vysH(:,part).time/60,vysH(:,part).res,'k');
        set(handles.listbox1,'Value',1);
    elseif get(handles.checkbox5,'Value')==1
        bar(handles.axes1,vysH(part).hymna(2,:)/60,vysH(part).hymna(1,:))
        set(handles.axes1,'XLim',[min(vysH(part).hymna(2,:))/60 max(vysH(part).hymna(2,:))/60])
    elseif get(handles.checkbox6,'Value')==1
        f_okam(vysH(part).F0,0,0,handles)
    elseif get(handles.checkbox8,'Value')==1
        plot(handles.axes1,vysH(part).F0(2,:)/60,vysH(part).E)
    end
end

% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)

if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on selection change in listbox2.
function listbox2_Callback(hObject, eventdata, handles)



% --- Executes during object creation, after setting all properties.
function listbox2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject, eventdata, handles)
global vysH
if isempty(vysH)==1
    slider1_Callback(hObject, eventdata, handles)
end

% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject, eventdata, handles)
global vysH
if isempty(vysH)==1
    slider1_Callback(hObject, eventdata, handles)
end

% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject, eventdata, handles)
global vysH
if isempty(vysH)==1
    slider1_Callback(hObject, eventdata, handles)
end

% --- Executes on button press in checkbox8.
function checkbox8_Callback(hObject, eventdata, handles)
global vysH
if isempty(vysH)==1
    slider1_Callback(hObject, eventdata, handles)
end



% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)



% --- Executes on mouse press over figure background.
function figure1_ButtonDownFcn(hObject, eventdata, handles)

% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)

% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)

global cesta
global vysH
global fs

info(1)=get(handles.checkbox5,'Value');     %hymna
info(2)=get(handles.checkbox6,'Value');       %okamziky
info(3)=get(handles.checkbox7,'Value');       %hvizd
info(4)=get(handles.checkbox8,'Value');       %volne
% funkce pro vytvoreni noveho okna s moznosti prehrani danneho useku
wdetail(vysH,info,cesta,fs,handles);


% std var kouknout se na fce 
% % najít rozpoznání řeči
% dle zadaného slova prohledat zapas. najít řešení. 



