Document version: 1.0
Author(s): Sven Gijsen
Date: July 2015
The purpose of this document is to show you the basic features of BrainStim in a tutorial way.
The best way working through this document is starting from the beginning and follow all tutorials
till the end of the document, you could also only follow a single specific
topic of your interest but then please bear
in mind that some topics expect you to already
have some knowledge of previous topics.
This Getting Started guide mainly covers the basic usage of
BrainStim and it's features, most user plan to use BrainStim
for creating and running their behavioral, psychological and
physiological experiments but because these features are
beyond the basic BrainStim features these are described in
the Creating Experiments with the Experiment Manager guide.
Please be aware that this guide may expect you to read the
below Getting Started Guide first.
This Getting started guide is
not perfect and continuously under construction, so we would be happy to receive feedback about bugs, typos, comments,
new ideas.
Installing BrainStim on your computer is easy, you can download the latest release from the GitHub project site. The public BrainStim source code repository is also hosted here. You can choose between a 32 and 64-bit version of BrainStim depending on the Windows operating system type you're using. You can use the previous link as a guidance for checking this configuration or alternatively you can execute the following Command Prompt command (a Command prompt can be opened using the: Windows start button --> Run... --> enter the text cmd --> hit the enter key):
|
If it echoes with x86 then you're working on a 32-bit architecture, if not then it's an 64-bit architecture.
BrainStim strongly depends on the OpenGL 2.0 (or higher) graphics library, so for an optimal usage please make sure that your graphics card supports OpenGL 2.0 (or higher) and that the drivers for this graphics card are up to date. When installing BrainStim you should try to do this using administrator privileges. There are also some virus scanners which trigger a false virus detection due to the automatic installation of various (network) libraries. If you should receive a detection message like this, you could consider deactivating the real-time virus detection while installing BrainStim.
The BrainStim release download is compressed inside a zip file and should first be extracted, after that you can execute the BrainStim installer. Please read about the first time start of BrainStim and the Update Manager Tool
The BrainStim installer copies the program files to the default Main Program directory (default: C:\Program Files (x86)\BrainStim), during installation the location for this directory can be customized. Inside this directory you can find the BrainStim.exe executable file that you can use to execute the BrainStim program. Some sub-directories found in this directory are:
Directory | Description |
---|---|
Apis | The files inside this directory are used for supporting the BrainStim document editing, like call tips and auto completion. Each API (Application Program Interface) defines the way to handle a specific programming language. |
Documents | This directory contains all the necessary files for the BrainStim Help. |
Include | The default include directory used for script files when using the "Include()" script function. |
Menus | This directory can contain some custom menu definition files that define some custom Menu Bar commands, read this document for more information regarding this topic. |
Plugins | This is the root directory in which BrainStim searches for default plug-ins to load during startup, if compatible then they are automatically embedded in BrainStim and are then ready for usage. |
Qml/plugins/[architecture] | This is the root directory in which BrainStim searches for QML plug-ins to include during the startup of the QML viewer. |
Updates | This directory can contain some updates that are placed here by the installer. The first time a user starts BrainStim he or she is asked whether these available updates can be installed. |
Xsd | This directory contains XML Schema (*.xsd) files, which let BrainStim validate experiment (*.exml) files. It is used to express a set of rules to which an experiment must conform in order to be considered 'valid' according to that schema. |
BrainStim makes use of two additional directories, these directories are created and used after the first start of BrainStim, these are:
Depending on the windows login username and BrainStim version the path is:
C:\Users\<login username>\BrainStim(vx.x.x.x, xx-bits)
This directory is mainly used for user specific dynamic data access(read/write) and is empty (or perhaps not present) before the first start of BrainStim. Inside this directory you can find the following sub-directories/files:
File/Directory | Description |
---|---|
Examples | This directory contains various example and tutorial files, some of them are also referred to by this document (see the sub-directory BrainStim\examples\GettingStartedGuide\). These files can be viewed/executed by a user and provide information about a certain topic of a feature or functionality. |
Examples\Plugins | This directory contains the example and tutorial files for installed custom plugins. |
Outputs | This directory is used when needed by BrainStim for saving logfiles that are generated during the execution of an experiment. |
Temp | This directory is used by BrainStim for storage of temporarily files. |
logfile.txt | This logfile is used by BrainStim for logging all main program execution information, warnings and errors. See this document for more information. |
BrainStim.ini | This file is used by BrainStim for storing and retrieving all internal settings/configurations. |
You can change this directory using the BrainStim Settings Dialog. Important! Although the BrainStim Settings File (BrainStim.ini) is located inside this directory by default the location of this file doesn't change by changing this setting, for all the remaining directories and files it does.
Depending on the windows login username and BrainStim version it's located at:
C:\Users\<login username>\AppData\Local\MBIC\BrainStim\BrainStim(vx.x.x.x, xx-bits)\Plugins\<architecture>\
This directory is used for the installation of user specific custom Plugin and additional files that are needed for this plugin.
You can change this directory using the BrainStim Settings Dialog. Important! After changing this setting you should copy all needed Plugin files from the "old" directory setting to this "new" directory setting for the plugin(s) that you still want to make use of in BrainStim.
The default BrainStim User interface contains a MenuBar, ToolBar, Document Editing, OutputLog and StatusBar area. These area's can be resized and moved around by a user and these customization are then automatically saved by file type extension of the current active document. Read this document for more information about the default User-Interface. Furthermore (custom) plugins may also define custom editing area's for different file type editing purposes, read this document for more information about that topic.
The default menu bar includes the following menu's:
File/Directory | Description |
---|---|
File | contains commands for various file operations like opening, saving and printing files. |
Edit | contains commands for the editing of files and search/replace features. Furthermore there are some additional commands for controlling the Output Log tab(s). |
Window | contains commands for organizing, selecting and viewing one or more document(s). |
Markers | contains commands for the management of markers that can be used to mark or quickly jump to one or more specific position(s) in a loaded document. |
Document | contains commands for controlling the execution of various documents like script (*.qs) files. |
Tools | contains an option command that lets you configure the BrainStim settings. |
Plugins | contains commands for the loaded/embedded plug-ins in BrainStim. With these commands you can open the plug-in's User Interface. Plug-ins are automatic divided in Extension and Device plug-ins. You can also open the Plugin Managers dialog from this menu. |
Help | contains commands for opening the BrainStim help and viewing release information about BrainStim. |
The default menu bar can be extended by implementing one or more menu configuration files, read this document for more information about this topic.
BrainStim makes use of a configuration file to store all settings/configurations. This configuration file, named BrainStim.ini is located in the Main Program Directory, because this directory is different per Windows login user the settings are stored separately. The settings file is also used by BrainStim for storing custom layout settings of the different UI areas.
You can open the settings dialog from BrainStim by selecting the menu commands: Tools - Options. Read more about this topic in this document.
BrainStim can be started from the command prompt with special defined switches accompanied with one or more parameter(s). Read more about this topic in this document.
At first glance BrainStim features various text editing tools that are found in standard text editing applications, like for example notepad. BrainStim allows to open and edit multiple documents simultaneously. The user interface of BrainStim may completely change depending of the document type (which is automatically resolved by the document extension) which makes BrainStim very flexible for editing various file types, read this document for more information about this topic.
Although the below scripting exercises a pretty easy to understand for a general programmer, they do expect you to have already gained some knowledge about scripting and basic programming.
Let's first try to open/view and execute a very basic script with BrainStim
You can see again that the plain text is automatically highlighted/styled according to the syntax it contains. Text/code can be commented using the single line comment ?//? or the multi-line ?/*? and ?*/? combination, commented text is not executed by the internal script engine but can be used for the documentation of script code for a better understanding. In the script three variables are declared (using the var statement) and a value is assigned to them, the third variable is assigned to the calculated sum of the first two variables. The value of this third variable is then used in a special function called Log() that appends the provided string parameter to the BrainStim Output Log pane. To clear the Output Log pane right-click on it and select Clear All Output Item(s). Some times you might want to copy some text from the output log pane, you can do this by selecting the text to copy to the clipboard and then right-click on it and select Copy Selected Text. Alternatively you can also use the default operating systems Copy/Paste commands.
The QtScript code of the current active document is then evaluated and executed. You can see in the Output Log pane when the script started/stopped evaluation and how many time it took to evaluate. We can also see that for each Log() function call there's one additional line appended to the Log Output pane.
Within the BrainStim script (QtScript) you can define functions and includes that allow you to structure this script in a more modular way read more about this topic in this document.
In a previous exercise we already made use of the additional Log() function to write text to the log output pane which can be very useful for debugging purpose. This Log() function is made available in the script environment by the BrainStim application to provide a convenient way for the user to easily output information from the running script to the main BrainStim User Interface. There are more additional convenient functions made available to the script environment by the BrainStim application, as you can see in the following example.
When we look at the script code we see that it uses some additional functions prepended with the ?BrainStim? namespace (followed/separated by a dot) because these used functions belong to the BrainStim main program. We see some functions that can retrieve absolute directory paths, environment information etc, but also some functions that perform BrainStim UI functionality like find() and closeSelectedScriptFile(). All available additional BrainStim script functions are described in the BrainStim Main Application Scripting Reference.
The Log() function is actually the same as the BrainStim.write2OutputWindow() function (internally it does exactly the same) but because this functionality it's so commonly used and the BrainStim.write2OutputWindow() function takes a lot of characters(key presses) and time to code that it has been made available to the script engine under the short Log() function signature.
The internal BrainStim script engine uses a garbage collection method to reclaim memory used by the script objects when they are no longer needed. Because this is important it's a good programming practice to follow some guidelines to make sure this can happen, read this document for more information about this topic.
To further extend the script engine functionality BrainStim has a feature that automatically detects and integrates (pre-generated) Qt bindings for the Qt Script environment. With these bindings you get access to substantial portions of the Qt API from within Qt Script. Read this document for more information about this topic.
The BrainStim script engine supports Qt-style signal and slot connections, that can make the script very powerful, see this document for more information regarding this topic.
BrainStim has the ability to automatically integrate (load and embed) plug-ins that extend the functionality of BrainStim (see the plug-in reference for a list of available plug-ins). These plug-ins can expose their functionality to the BrainStim Script engine, allowing the user to take advantage of these plug-ins inside the script context. Usually this is done by constructing a object dynamically inside the script from the exposed plug-in script class which we can then make use of. Each plug-in has the possibility to implement its own custom User Interface that can be opened from BrainStim, normally this User Interface offers a user friendly way for accessing and testing the plug-ins functionality. For a c++ programmer it's not difficult to create a new custom BrainStim plug-in to extend the program (if you are interested in this please contact us at sven dot gijsen at maastrichtuniversity dot nl).
Important: The internal plug-in object, used by the plug-ins User Interface to show its functionality, is in no way connected to the script or any script object created from this plug-ins class! This is because that internal plug-in is only used for testing purpose and easy access it's features but not for a global configuration. Objects that are dynamically created inside the script context from the plug-ins script class are new instances and in no way connected to the plug-ins UI.
BrainStim has totally no knowledge of the internal plug-ins implementation and does not define what or how they should do things, making this plug-in framework very flexible for developers. A BrainStim installation contains some standard plug-ins that are automatically installed together with BrainStim. These can be installed as a separate plug-in file or build inside the BrainStim executable (these plug-ins are called static). Plug-ins are grouped in either Device or Extension plug-ins. As we already know by now a plug-in can define a custom (script) class from which we can construct new script plug-in objects. Let's first take a look at a plug-ins implemented UI and some of its features:
We can also construct a new plug-in object from this plug-ins script class, lets try this:
We saw that the key codes (a unique number for each key) of the captured key presses where logged to the Output Log Pane and after having pressed 4 times the script automatically ended. The line var KeyBoardCaptureObj = new KeyBoardCapture(); constructs a new object from the class defined by the KeyBoardCapture plug-in. This object is then used by the script. We now need to know what this plug-in object can do:
This help document is a script class reference, that shows all the available signals/slots and member function that can be used inside the script context for this plug-ins script class.
We saw that BrainStim is a rich multiple document editor with an internal script engine that can execute scripts and that it can be extended by the use of custom plug-ins. However, the main goal during development was to create a platform for editing and executing behavioral experiments for supporting cognitive research. Creating behavioral experiments can be done by using solely the BrainStim script engine but this is pretty difficult for an average user. Therefore a BrainStim plug-in called the Experiment Manager was created to support more functionality for creating and running behavioral experiments. Important! It's advised to read the document Creating Experiments with the Experiment Manager to get started!
Due to the huge capabilities of BrainStim this Getting Started guide might be
somehow difficult to fully understand immediately, this is not a
real problem. It's important to gain a general idea of how BrainStim works and what it's main capabilities are. If you then want to give it a try you could then start by
changing an example from this Getting Started Guide or proceed
with one of the
Advanced
Examples found in the <BrainStim Installation Directory>\examples\BrainStim\Advanced\ directory.
Off course you can always contact us at sven dot gijsen at
maastrichtuniversity dot nl for feedback and questions!