Difference between revisions of "AnyWave:BuildReader"

From WikiMEG
Jump to: navigation, search
(AwReaderPlugin and AwFileReader classes)
(AwReaderPlugin and AwFileReader classes)
Line 22: Line 22:
 
Here are the two classes, described within one header file:
 
Here are the two classes, described within one header file:
 
<syntaxhighlight lang="C++">
 
<syntaxhighlight lang="C++">
 +
#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
 +
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 11:40, 23 March 2015

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:

Invalid language.

You need to specify a language like this: <source lang="html4strict">...</source>

Supported languages for syntax highlighting:

4cs, 6502acme, 6502kickass, 6502tasm, 68000devpac, abap, actionscript, actionscript3, ada, algol68, apache, applescript, apt_sources, arm, asm, asp, asymptote, autoconf, autohotkey, autoit, avisynth, awk, bascomavr, bash, basic4gl, bf, bibtex, blitzbasic, bnf, boo, c, c_loadrunner, c_mac, caddcl, cadlisp, cfdg, cfm, chaiscript, cil, clojure, cmake, cobol, coffeescript, cpp, cpp-qt, csharp, css, cuesheet, d, dcl, dcpu16, dcs, delphi, diff, div, dos, dot, e, ecmascript, eiffel, email, epc, erlang, euphoria, f1, falcon, fo, fortran, freebasic, freeswitch, fsharp, gambas, gdb, genero, genie, gettext, glsl, gml, gnuplot, go, groovy, gwbasic, haskell, haxe, hicest, hq9plus, html4strict, html5, icon, idl, ini, inno, intercal, io, j, java, java5, javascript, jquery, kixtart, klonec, klonecpp, latex, lb, ldif, lisp, llvm, locobasic, logtalk, lolcode, lotusformulas, lotusscript, lscript, lsl2, lua, m68k, magiksf, make, mapbasic, matlab, mirc, mmix, modula2, modula3, mpasm, mxml, mysql, nagios, netrexx, newlisp, nsis, oberon2, objc, objeck, ocaml, ocaml-brief, octave, oobas, oorexx, oracle11, oracle8, oxygene, oz, parasail, parigp, pascal, pcre, per, perl, perl6, pf, php, php-brief, pic16, pike, pixelbender, pli, plsql, postgresql, povray, powerbuilder, powershell, proftpd, progress, prolog, properties, providex, purebasic, pycon, pys60, python, q, qbasic, rails, rebol, reg, rexx, robots, rpmspec, rsplus, ruby, sas, scala, scheme, scilab, sdlbasic, smalltalk, smarty, spark, sparql, sql, stonescript, systemverilog, tcl, teraterm, text, thinbasic, tsql, typoscript, unicon, upc, urbi, uscript, vala, vb, vbnet, vedit, verilog, vhdl, vim, visualfoxpro, visualprolog, whitespace, whois, winbatch, xbasic, xml, xorg_conf, xpp, yaml, z80, zxbasic


#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