AnyWave:BuildReader

From WikiMEG
Revision as of 11:40, 23 March 2015 by Bruno (Talk | contribs)

Jump to: navigation, search

One important thing with AnyWave is to be able to read a data file.
Although that AnyWave is able to read some common EEG or MEG file formats, you might need to read a particular data file.
The only way to achieve that is to build a Reader plug-in for AnyWave.
This will require implementing a C++ plug-in using the SDK.
See the previous sections of the Developer's corner to see how to build the SDK and use it to build a new plug-in.

Let's start with the basic cmake project that we will modify to suit our needs.

ADES reader as example

AnyWave is able to read .ades file format which is a simple file format built upon a text header file and a binary data file.
This 'plug-in' is embedded within AnyWave but we are going to implement it as an external plug-in, for the sake of demonstration.

Define the C++ classes

A C++ plug-in is defined by two classes:

  • A class that describes the plug-in to AnyWave.
  • A class that describes the core mechanism of the plug-in.

That is true for all kind of plug-ins in AnyWave.

AwReaderPlugin and AwFileReader classes

As mentioned above, two C++ classes must be described and implemented to build a Reader plug-in.
Here are the two classes, described within one header file:

#ifndef DESREADER_H
#define DESREADER_H
 
#include <AwReaderInterface.h>
#include <QtCore>
#include <QDataStream>
 
class ADesReader : public AwFileReader
{
	Q_OBJECT
	Q_INTERFACES(AwFileReader)
public:
	ADesReader(const QString& filename);
	~ADesReader() { cleanUpAndClose(); }
 
	long readDataFromChannels(float start, float duration, QList<AwChannel *> &channelList);
	FileStatus openFile(const QString &path);
	FileStatus canRead(const QString &path);
 
	void cleanUpAndClose();
private:
	QFile m_headerFile;
	QFile m_binFile;
	QTextStream m_headerStream;
	QDataStream m_binStream;
	float m_samplingRate;
	int m_nSamples;
	QString m_binPath;
};
 
class ADesReaderPlugin : public AwReaderPlugin
{
	Q_OBJECT
	Q_INTERFACES(AwReaderPlugin)
public:
	ADesReaderPlugin();
	ADesReader *newInstance(const QString& filename) { return new ADesReader(filename); }
};
 
#endif // DESREADER_H