function [] = initializeArtoa4()
%INITIALIZEARTOA4 Initializes variables required for artoa4 and creates the main window if required.
%

global artoaDataInput artoaWorkspace artoaGui artoaConfig;

%% When the gui exists, focus it
if isfield(artoaGui, 'figures') && isfield(artoaGui.figures, 'main')
    figure(artoaGui.figures.main.Number);
    return
end

%% Initalize required variables
artoaDataInput = struct();
artoaWorkspace = struct();
artoaWorkspace.hideDeletedDataPoints = false;

artoaWorkspace.artoaVersion = ['4' artoa.versioning.getVersionString(true)];

artoaWorkspace.plugins = struct();
artoaWorkspace.plugins.tracking = struct();

artoaGui = struct();
artoaGui.figures = struct();
artoaGui.main = struct();
artoaGui.trackParameter = struct();
artoaGui.callbacks = struct();
artoaWorkspace.editOffsets = struct();
artoaWorkspace.editOffsets.useOffsets = false;

%% Read ini file if existent
artoa.controller.file.loadArtoaIni();

%% Configure artoa defaults
artoa.controller.addDefaults();

%% Read soundsource file if existent
try
    soundsourceFilepath = artoaConfig.files.soundsourcefile;
    if ~isfile(soundsourceFilepath)
        error([mfilename ': ' soundsourceFilepath ' is not a file. Please check your artoa.ini!']);
    end
    artoaDataInput.soundsources = artoa.load.soundsources(soundsourceFilepath);
catch ex
    error([mfilename ': Reading soundsource file failed with the following message: ' ex.message]);
end

%% Initialize all plugins
artoa.plugins.initialize();

%% Open main gui
artoa.controller.main.open();

%% Move main window to the center of the screen
movegui(artoaGui.figures.main, 'center');

%% Update the settings defined by ini
if artoa.data.getMember(artoaConfig, {'view', 'hidedeleteddatapoints'}, false)
    artoa.controller.switchHideDeletedPoints();
end

end
