Commit ec005643 authored by Mueller-Trapet's avatar Mueller-Trapet

Merge branch 'master' of https://git.rwth-aachen.de/ita/toolbox

parents 3dc78697 263bbe7d
Contact: rsc@akustik.rwth-aachen.de
Description: Database for (binaural) room impulse responses
function bindb()
% Synopsis:
% bindb() or bindb
% Description:
% Launch the bindb Toolbox feature.
% <ITA-Toolbox>
% This file is part of the application bindb for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% Register globals
global bindb_data;
if isfield(bindb_data, 'Settings')
% Launch gui
bindb_gui();
else
fprintf(1, 'bindb is not initialized, run <a href="matlab:bindb_setup">bindb_setup</a> first\n');
end
function bindb_addlog( source, message, open )
% Synopsis:
% bindb_addlog( source, message, open )
% Description:
% Creates a log entry and updates the log window.
% Parameters:
% (string) source
% The source of the message. Usually the current gui.
% (string) message
% The message of the log entry.
% (int) open
% If true, the log window is opened. Only for important
% entries.
% <ITA-Toolbox>
% This file is part of the application bindb for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
global bindb_data;
bindb_data.Log = [{datestr(now, 'HH:MM:SS'), source, message}; bindb_data.Log];
% Update log if opened
global bindb_logtable
if open
bindb_gui_log;
elseif ishandle(bindb_logtable)
set(bindb_logtable, 'Data', bindb_data.Log);
end
function bindb_admin_createsqltables()
% Synopsis:
% bindb_admin_createsqltables()
% Description:
% Create the entire table structure for the bindb database. This function
% requires AdminMode. Use 'help bindb_setadmin' for more information.
% <ITA-Toolbox>
% This file is part of the application bindb for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% Register globals
global bindb_data
if ~bindb_data.Settings.AdminMode
bindb_addlog('Create sql tables', 'AdminMode is required to run this function', 1);
return;
end
Messages = '';
% Measurements
cmd = 'CREATE TABLE `Measurements` ( `M_ID` int(11) NOT NULL AUTO_INCREMENT, `O_ID` int(11) NOT NULL, `Date` date NOT NULL, `Version` int(11) NOT NULL, `Author` text NOT NULL, `Comment` text, `Humidity` double NOT NULL, `Volume` double NOT NULL, `Temperature` double NOT NULL, PRIMARY KEY (`M_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Responses
cmd = 'CREATE TABLE `Responses` ( `R_ID` int(11) NOT NULL AUTO_INCREMENT, `M_ID` int(11) NOT NULL, `X` double NOT NULL, `Y` double NOT NULL, `Height` double NOT NULL, `Description` text, `Hardware` text NOT NULL, PRIMARY KEY (`R_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Sources
cmd = 'CREATE TABLE `Sources` ( `S_ID` int(11) NOT NULL AUTO_INCREMENT, `M_ID` int(11) NOT NULL, `X` double NOT NULL, `Y` double NOT NULL, `Height` double NOT NULL, `Description` text, `Hardware` text NOT NULL, PRIMARY KEY (`S_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Rooms
cmd = 'CREATE TABLE `Rooms` ( `O_ID` int(11) NOT NULL AUTO_INCREMENT, `Name` text NOT NULL, `Description` text, `Layout` text NOT NULL, PRIMARY KEY (`O_ID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Fields
cmd = 'CREATE TABLE `Fields` ( `Name` text NOT NULL, `Description` text NOT NULL, `Type` int(11) NOT NULL, `Values` text ) ENGINE=InnoDB DEFAULT CHARSET=latin1';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
if length(Messages > 0)
bindb_addlog('Create sql tables', Messages(1:end-2), 1);
end
function bindb_admin_dropsqltables()
% Synopsis:
% bindb_admin_dropsqltables()
% Description:
% Remove the entire table structure from the bindb database. This function
% requires AdminMode. Use 'help bindb_setadmin' for more information.
% <ITA-Toolbox>
% This file is part of the application bindb for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% Register globals
global bindb_data
if ~bindb_data.Settings.AdminMode
bindb_addlog('Drop sql tables', 'AdminMode is required to run this function', 1);
return;
end
Messages = '';
% Measurements
cmd = 'DROP TABLE `Measurements`';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Responses
cmd = 'DROP TABLE `Responses`';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Sources
cmd = 'DROP TABLE `Sources`';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Rooms
cmd = 'DROP TABLE `Rooms`';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
% Fields
cmd = 'DROP TABLE `Fields`';
curs = bindb_exec(cmd);
if length(curs.Message) > 0
Messages = [Messages curs.Message ', '];
end
if length(Messages > 0)
bindb_addlog('Create sql tables', Messages(1:end-2), 1);
end
function varargout = bindb_admin_gui(varargin)
% BINDB_ADMIN_GUI MATLAB code for bindb_admin_gui.fig
% BINDB_ADMIN_GUI, by itself, creates a new BINDB_ADMIN_GUI or raises the existing
% singleton*.
%
% <ITA-Toolbox>
% This file is part of the application bindb for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% H = BINDB_ADMIN_GUI returns the handle to a new BINDB_ADMIN_GUI or the handle to
% the existing singleton*.
%
% BINDB_ADMIN_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BINDB_ADMIN_GUI.M with the given input arguments.
%
% BINDB_ADMIN_GUI('Property','Value',...) creates a new BINDB_ADMIN_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before bindb_admin_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to bindb_admin_gui_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 bindb_admin_gui
% Last Modified by GUIDE v2.5 26-May-2012 09:31:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @bindb_admin_gui_OpeningFcn, ...
'gui_OutputFcn', @bindb_admin_gui_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 bindb_admin_gui is made visible.
function bindb_admin_gui_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 bindb_admin_gui (see VARARGIN)
% Choose default command line output for bindb_admin_gui
handles.output = hObject;
% Disable delete if no connection
if ~bindb_isonline()
set(handles.database_fields, 'Enable', 'off');
end
% Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = bindb_admin_gui_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 on button press in local_reset.
function local_reset_Callback(hObject, eventdata, handles)
% hObject handle to local_reset (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete(bindb_filepath('localdata', 'fields.mat'));
delete(bindb_filepath('localdata', 'measurements.mat'));
delete(bindb_filepath('localdata', 'rooms.mat'));
delete(bindb_filepath('localdata', 'system.mat'));
% --- Executes on button press in database_fields.
function database_fields_Callback(hObject, eventdata, handles)
% hObject handle to database_fields (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Open measurement fields gui
bindb_admin_gui_fields();
% --- Executes on button press in database_tablestructure.
function database_tablestructure_Callback(hObject, eventdata, handles)
% hObject handle to database_tablestructure (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in sql_create.
function sql_create_Callback(hObject, eventdata, handles)
% hObject handle to sql_create (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
bindb_admin_createsqltables();
% --- Executes on button press in sql_remove.
function sql_remove_Callback(hObject, eventdata, handles)
% hObject handle to sql_remove (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
bindb_admin_dropsqltables();
function varargout = bindb_admin_gui_fields(varargin)
% BINDB_ADMIN_GUI_FIELDS MATLAB code for bindb_admin_gui_fields.fig
% BINDB_ADMIN_GUI_FIELDS, by itself, creates a new BINDB_ADMIN_GUI_FIELDS or raises the existing
% singleton*.
%
% <ITA-Toolbox>
% This file is part of the application bindb for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% H = BINDB_ADMIN_GUI_FIELDS returns the handle to a new BINDB_ADMIN_GUI_FIELDS or the handle to
% the existing singleton*.
%
% BINDB_ADMIN_GUI_FIELDS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BINDB_ADMIN_GUI_FIELDS.M with the given input arguments.
%
% BINDB_ADMIN_GUI_FIELDS('Property','Value',...) creates a new BINDB_ADMIN_GUI_FIELDS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before bindb_admin_gui_fields_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to bindb_admin_gui_fields_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 bindb_admin_gui_fields
% Last Modified by GUIDE v2.5 12-Dec-2011 14:30:06
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @bindb_admin_gui_fields_OpeningFcn, ...
'gui_OutputFcn', @bindb_admin_gui_fields_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 bindb_admin_gui_fields is made visible.
function bindb_admin_gui_fields_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 bindb_admin_gui_fields (see VARARGIN)
% Choose default command line output for bindb_admin_gui_fields
handles.output = hObject;
% Register globals
global bindb_data;
% Update list
handles = updateList(hObject, handles);
% Update handles structure
guidata(hObject, handles);
% Admin mode
if bindb_data.Settings.AdminMode ~= 1
set(handles.actions_add, 'Enable', 'off');
set(handles.actions_remove, 'Enable', 'off');
bindb_addlog('Measurement fields', 'Window functionality requires admin mode.', 1);
end
% --- Outputs from this function are returned to the command line.
function varargout = bindb_admin_gui_fields_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 on button press in action_save.
function action_save_Callback(hObject, eventdata, handles)
% hObject handle to action_save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close(handles.figure1);
% --- Executes on button press in actions_add.
function actions_add_Callback(hObject, eventdata, handles)
% hObject handle to actions_add (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Open add field gui and wait
waitfor(bindb_admin_gui_fields_add());
% Update list
handles = updateList(hObject, handles);
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in actions_remove.
function actions_remove_Callback(hObject, eventdata, handles)
% hObject handle to actions_remove (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Open remove field gui and wait
waitfor(bindb_admin_gui_fields_remove());
% Update list
handles = updateList(hObject, handles);
% Update handles structure
guidata(hObject, handles);
% --- Executes when selected cell(s) is changed in fields_list.
function fields_list_CellSelectionCallback(hObject, eventdata, handles)
% hObject handle to fields_list (see GCBO)
% eventdata structure with the following fields (see UITABLE)
% Indices: row and column indices of the cell(s) currently selecteds
% handles structure with handles and user data (see GUIDATA)
if ~isempty(eventdata.Indices)
set(handles.fields_description, 'String', sprintf(handles.Fields{eventdata.Indices(1), 3}));
end
function handles = updateList(hObject, handles)
% hObject handle to GCBO
% handles structure with handles and user data (see GUIDATA)
% Load and store current fields
bindb_fields_get();
bindb_fields_store();
% Declare globals
global bindb_data;
if ~isempty(bindb_data.Fields)
handles.Fields = cell(length(bindb_data.Fields), 3);
for index = 1:length(bindb_data.Fields)
% Store name
handles.Fields{index, 1} = bindb_data.Fields(index).Name;
% Store type
types = { 'Numeric - Integer', 'Numeric - Double', 'String - no length limit', 'String - predefined values' };
handles.Fields{index, 2} = types{bindb_data.Fields(index).Type};
% Store description
handles.Fields{index, 3} = bindb_data.Fields(index).Description;
end
% Display fields in table
set(handles.fields_list, 'Data', handles.Fields(:, 1:2));
else
handles.Fields = {};
set(handles.fields_list, 'Data', {});
end
% --- Executes on button press in health_check.
function health_check_Callback(hObject, eventdata, handles)
% hObject handle to health_check (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if bindb_fields_check == 1
set(handles.health_status, 'String', 'field tables are healty');
else
set(handles.health_status, 'String', 'maintenance required');
end
function varargout = bindb_admin_gui_fields_add(varargin)
% BINDB_ADMIN_GUI_FIELDS_ADD MATLAB code for bindb_admin_gui_fields_add.fig
% BINDB_ADMIN_GUI_FIELDS_ADD, by itself, creates a new BINDB_ADMIN_GUI_FIELDS_ADD or raises the existing
% singleton*.
%
% <ITA-Toolbox>
% This file is part of the application bindb for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>
% H = BINDB_ADMIN_GUI_FIELDS_ADD returns the handle to a new BINDB_ADMIN_GUI_FIELDS_ADD or the handle to
% the existing singleton*.
%
% BINDB_ADMIN_GUI_FIELDS_ADD('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in BINDB_ADMIN_GUI_FIELDS_ADD.M with the given input arguments.
%
% BINDB_ADMIN_GUI_FIELDS_ADD('Property','Value',...) creates a new BINDB_ADMIN_GUI_FIELDS_ADD or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before bindb_admin_gui_fields_add_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to bindb_admin_gui_fields_add_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 bindb_admin_gui_fields_add
% Last Modified by GUIDE v2.5 26-Jan-2012 13:39:10
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @bindb_admin_gui_fields_add_OpeningFcn, ...
'gui_OutputFcn', @bindb_admin_gui_fields_add_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 bindb_admin_gui_fields_add is made visible.
function bindb_admin_gui_fields_add_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 bindb_admin_gui_fields_add (see VARARGIN)
% Choose default command line output for bindb_admin_gui_fields_add
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes bindb_admin_gui_fields_add wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = bindb_admin_gui_fields_add_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 on button press in actions_OK.
function actions_OK_Callback(hObject, eventdata, handles)
% hObject handle to actions_OK (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Declare globals
global bindb_data;
% Check if name field is empty
name = strtrim(get(handles.name_field, 'String'));
if strcmp(name, '') == 0
% Check if column name is taken
data = bindb_querymat(['SELECT COUNT(*) FROM `Fields` WHERE `Name`=''' name '''']);
if data > 0
set(handles.name_field, 'BackgroundColor', [1.0, 0.8, 0.8]);
req1 = 0;
bindb_addlog('Add measurement field', 'column name must be unique', 1);
else
set(handles.name_field, 'BackgroundColor', [1.0, 1.0, 1.0]);