Programming Reference:ApplicationBase Class: Difference between revisions
Zfreudenburg (talk | contribs) |
|||
| (12 intermediate revisions by one other user not shown) | |||
| Line 5: | Line 5: | ||
The <tt>ApplicationBase</tt> class bundles base functionality which is useful for any BCI2000 application module. This base functionality comprises | The <tt>ApplicationBase</tt> class bundles base functionality which is useful for any BCI2000 application module. This base functionality comprises | ||
*generation of random numbers, | *generation of random numbers, | ||
*maintaining an application log file, and application log messages to the operator user | *maintaining an application log file, and application log messages to the operator user. | ||
==Usage== | ==Usage== | ||
An application module uses the <tt>ApplicationBase</tt> class by deriving its [[ | An application module uses the <tt>ApplicationBase</tt> class by deriving its [[BCI2000 Glossary#Task|task filter]] from <tt>ApplicationBase</tt> rather than <tt>GenericFilter</tt> directly. It has then access to the facilities explained below. | ||
==Access to Application Windows== | |||
The <tt>ApplicationBase</tt> class inherits from the [[Programming Reference:ApplicationWindowClient Class|<tt>ApplicationWindowClient</tt> class]], and thus provides access to framework-managed [[Programming Reference:ApplicationWindow Class|application windows]]. | |||
To access, and possibly create, the main application window from your <tt>ApplicationBase</tt>-derived application filter class, initialize an <tt>ApplicationWindow</tt> reference in its constructor with the <tt>ApplicationWindowClient::Window()</tt> function: | |||
<pre> | |||
class MyTaskFilter : public ApplicationBase | |||
{ | |||
... | |||
private: | |||
ApplicationWindow& mrWindow; | |||
... | |||
}; | |||
MyTaskFilter::MyTaskFilter() | |||
: mrWindow( ApplicationWindowClient::Window() ) | |||
{ | |||
... | |||
} | |||
MyTaskFilter::Initialize( ... ) | |||
{ | |||
... | |||
ImageStimulus* pImageStimulus = new ImageStimulus( mrWindow ); | |||
... | |||
} | |||
</pre> | |||
You may also test windows for existence from the <tt>Preflight()</tt> function, and only use them when they already exist. This way, your code can adapt to the presence of certain filters in the application module. For more details, see the [[Programming Reference:ApplicationWindowClient Class|<tt>ApplicationWindowClient</tt> class]] reference page. | |||
==RandomNumberGenerator== | ==RandomNumberGenerator== | ||
| Line 33: | Line 58: | ||
// Write a message to both screen and file: | // Write a message to both screen and file: | ||
AppLog << "This message is displayed by the operator module, and written into the log file." << endl; | AppLog << "This message is displayed by the operator module, and written into the log file." << endl; | ||
Make sure to include the "endl" as nothing is written until the AppLog receives a newline command. | |||
The application log file is located in the current session directory, and named after the current session; it carries an '''.applog''' extension. | The application log file is located in the current session directory, and named after the current session; it carries an '''.applog''' extension. | ||
Operator log window messages have ''APLG'' as their [[Technical Reference:BCI2000 | Operator log window messages have ''APLG'' as their [[Technical Reference:BCI2000 Messages|visualization source ID]]. | ||
==Remarks== | ==Remarks== | ||
Typically, a BCI2000 application will | Typically, a BCI2000 application module will implement a paradigm that belongs to one of two categories: | ||
* | *evoking responses using stimulus presentation, | ||
* | *continuously presenting feedback of brain activity. | ||
A BCI2000 task filter implementing one of these paradigms will not inherit from the <tt>ApplicationBase</tt> directly but either from the [[Programming Reference: | A BCI2000 task filter implementing one of these paradigms will not inherit from the <tt>ApplicationBase</tt> directly but either from the [[Programming Reference:StimulusTask Class|StimulusTask]] or [[Programming Reference:FeedbackTask Class|FeedbackTask]]. | ||
Still, such a task filter has access to all functionality provided by <tt>ApplicationBase</tt>. | |||
==See also== | ==See also== | ||
[[Programming Reference: | [[Programming Reference:StimulusTask Class]], [[Programming Reference:FeedbackTask Class]], [[Programming Reference:ApplicationWindowClient Class]] | ||
[[Category:Framework API]][[Category:Development]] | [[Category:Framework API]][[Category:Development]] | ||
Latest revision as of 18:39, 10 February 2012
Location
BCI2000/src/shared/modules/application
Synopsis
The ApplicationBase class bundles base functionality which is useful for any BCI2000 application module. This base functionality comprises
- generation of random numbers,
- maintaining an application log file, and application log messages to the operator user.
Usage
An application module uses the ApplicationBase class by deriving its task filter from ApplicationBase rather than GenericFilter directly. It has then access to the facilities explained below.
Access to Application Windows
The ApplicationBase class inherits from the ApplicationWindowClient class, and thus provides access to framework-managed application windows. To access, and possibly create, the main application window from your ApplicationBase-derived application filter class, initialize an ApplicationWindow reference in its constructor with the ApplicationWindowClient::Window() function:
class MyTaskFilter : public ApplicationBase
{
...
private:
ApplicationWindow& mrWindow;
...
};
MyTaskFilter::MyTaskFilter()
: mrWindow( ApplicationWindowClient::Window() )
{
...
}
MyTaskFilter::Initialize( ... )
{
...
ImageStimulus* pImageStimulus = new ImageStimulus( mrWindow );
...
}
You may also test windows for existence from the Preflight() function, and only use them when they already exist. This way, your code can adapt to the presence of certain filters in the application module. For more details, see the ApplicationWindowClient class reference page.
RandomNumberGenerator
The ApplicationBase class provides an object of type RandomGenerator which may be used to obtain integer pseudo-random numbers uniformly distributed over a specified range:
int rnd = RandomNumberGenerator(10);
will assign a number between 0 and 9 to the variable named "rnd". Compared with other options to obtain pseudo-random numbers, the advantage of using ApplicationBase::RandomNumberGenerator object is that its behavior is governed by a global random seed value; this allows consistent, predictable BCI2000 behavior, e.g. for testing purposes. For more information, refer to the RandomGenerator reference page.
Application Log
Typically, a BCI2000 application module displays messages to the operator user to indicate that a new trial has started, a target has been hit or missed, or to display statistics about the current run. Often, this is information, in conjunction with additional, more detailed information is written into a log file, and that log file is maintained side-by-side with recorded data in the current session directory.
The ApplicationBase class provides an object named AppLog as a convenient interface to write messages to screen, log file, or both at the same time. That AppLog object uses a LogFile object to write into a log file; it uses a GenericVisualization object to write messages into an operator window.
The AppLog object is a <std::ostream>, and may be used as in the following examples:
// Write a message to the log file only AppLog.File << "This message goes into the log file." << endl;
// Write a message to the screen only AppLog.Screen << "This message goes into an operator window." << endl;
// Write a message to both screen and file: AppLog << "This message is displayed by the operator module, and written into the log file." << endl;
Make sure to include the "endl" as nothing is written until the AppLog receives a newline command.
The application log file is located in the current session directory, and named after the current session; it carries an .applog extension.
Operator log window messages have APLG as their visualization source ID.
Remarks
Typically, a BCI2000 application module will implement a paradigm that belongs to one of two categories:
- evoking responses using stimulus presentation,
- continuously presenting feedback of brain activity.
A BCI2000 task filter implementing one of these paradigms will not inherit from the ApplicationBase directly but either from the StimulusTask or FeedbackTask. Still, such a task filter has access to all functionality provided by ApplicationBase.
See also
Programming Reference:StimulusTask Class, Programming Reference:FeedbackTask Class, Programming Reference:ApplicationWindowClient Class