Skip to content

Commit 87f6b98

Browse files
committed
Improve timestamp source information on events info objects
1 parent 0108be8 commit 87f6b98

3 files changed

Lines changed: 76 additions & 5 deletions

File tree

Source/Processors/Channel/InfoObjects.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,28 @@ bool DataChannel::checkEqual(const InfoObjectCommon& other, bool similar) const
337337

338338
//EventChannel
339339
EventChannel::EventChannel(EventChannelTypes type, unsigned int nChannels, unsigned int dataLength, float sampleRate, GenericProcessor* source, uint16 subproc)
340-
: InfoObjectCommon(source->eventChannelCount++, source->eventChannelTypeCount[type]++, sampleRate, source, subproc),
341-
m_type(type)
340+
: InfoObjectCommon(source->eventChannelCount++, source->eventChannelTypeCount[type]++,
341+
((sampleRate > 0) ? sampleRate : (source->isGeneratesTimestamps() ? source->getSampleRate(subproc) : CoreServices::getGlobalSampleRate())),
342+
source, subproc),
343+
m_type(type),
344+
m_timestampOrigin(source->isGeneratesTimestamps() ? timestampsFromContinuousSource : timestampsFromGlobalSource ),
345+
m_timestampOriginProcessor(source->getNodeId()),
346+
m_timestampOriginSubProcessor(subproc)
347+
{
348+
initializeEvent(nChannels, dataLength);
349+
}
350+
351+
EventChannel::EventChannel(EventChannelTypes type, unsigned int nChannels, unsigned int dataLength, const DataChannel* originChannel, GenericProcessor* source, uint16 subproc)
352+
: InfoObjectCommon(source->eventChannelCount++, source->eventChannelTypeCount[type]++, originChannel->getSampleRate(), source, subproc),
353+
m_type(type),
354+
m_timestampOrigin(timestampsDerivedFromChannel),
355+
m_timestampOriginProcessor(originChannel->getSourceNodeID()),
356+
m_timestampOriginSubProcessor(originChannel->getSubProcessorIdx())
357+
{
358+
initializeEvent(nChannels, dataLength);
359+
}
360+
361+
void EventChannel::initializeEvent(int nChannels, int dataLength)
342362
{
343363
m_numChannels = nChannels;
344364
if (m_type == TTL)

Source/Processors/Channel/InfoObjects.h

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,11 +299,22 @@ class PLUGIN_API EventChannel :
299299
BINARY_BASE_VALUE = 10
300300
};
301301

302-
/** Default constructor
302+
/**
303+
Enumerator indicating where the timestamps for the event are originating, so they can be easily synchronized
304+
*/
305+
enum EventTimestampOrigin
306+
{
307+
timestampsFromContinuousSource, /* The timestamps from this event originate in a source processor alongside related continuous signals.
308+
Typical for */
309+
timestampsDerivedFromChannel, /* The timestamps are derived from a channel. Typical for events created by filter nodes */
310+
timestampsFromGlobalSource /* The timestamps are derived from the global timed. Typical for sources without continuous channels */
311+
};
312+
313+
/** Default constructor. Use this if the event is unrelated to any continuous data.
303314
@param type The type of event this channel represents (TTL, TEXT, BYINARY_MSG)
304315
@param numChannels The number of virtual channels
305316
@param dataLength The length of the event payload
306-
@param sampleRate the sample rate this channel timestamps are referred to
317+
@param sampleRate the sample rate this channel timestamps are referred to. If less or equal than zero will automatically get set to the processor sample rate or the global one
307318
@param source A pointer to the source processor
308319
@param subproc Optional. The source subprocessor index.
309320
@@ -316,9 +327,35 @@ class PLUGIN_API EventChannel :
316327
-For message events, the length of the string in characters
317328
-For typed array events, the number of elements
318329
330+
This constructor will set the timestamp origin flag to timestampFromContinuousSource if the source processor isGeneratesTimestamps() returns true
331+
and to timestampsFromGlobalSource otherwise
332+
319333
*/
320334
EventChannel(EventChannelTypes type, unsigned int numChannels, unsigned int dataLength, float sampleRate, GenericProcessor* source, uint16 subproc = 0);
321335

336+
/** Constructor for derived events.
337+
Intended for events that are created from a continuous channel data
338+
@param type The type of event this channel represents (TTL, TEXT, BYINARY_MSG)
339+
@param numChannels The number of virtual channels
340+
@param dataLength The length of the event payload
341+
@param originChannel The channel this event is derived from
342+
@param source A pointer to the source processor
343+
@param subproc Optional. The source subprocessor index.
344+
345+
The virtual channels mean:
346+
-For TTL signals, it must be the number of bits in the TTL word.
347+
-For other events, this might be used to differentiate between different origins within the same processor
348+
349+
The event length mean:
350+
-For TTL signals, this method will do nothing, as the size is fixed by the number of ttl channels
351+
-For message events, the length of the string in characters
352+
-For typed array events, the number of elements
353+
354+
This constructor will set the timestamp origin flag to timestampDerivedFromChannel and set the sample rate to that of the channel
355+
356+
*/
357+
EventChannel(EventChannelTypes type, unsigned int numChannels, unsigned int dataLength, const DataChannel* originChannel, GenericProcessor* source, uint16 subproc = 0);
358+
322359
virtual ~EventChannel();
323360

324361
EventChannelTypes getChannelType() const;
@@ -358,11 +395,25 @@ class PLUGIN_API EventChannel :
358395
/** Handy method to get an equivalente metadata value type for the main event data*/
359396
BaseType getEquivalentMetaDataType() const;
360397

398+
/** Returns which kind of origin the timestamps for these events have */
399+
EventTimestampOrigin getTimestampOrigin() const;
400+
401+
/** Returns the processor id which generated the timestamps, in case they are derived from a channel. Otherwise it returns the same as getSourceNodeId()*/
402+
uint16 getTimestampOriginProcessor() const;
403+
404+
/** Returns the subprocessor index which generated the timestamps, in case they are derived from a channel. Otherwise it returns the same as getSubProcessorIdx()*/
405+
uint16 getTimestampOriginSubProcessor() const;
406+
361407
InfoObjectType getInfoObjectType() const override;
362408
void setDefaultNameAndDescription() override;
363409
private:
364410
bool checkEqual(const InfoObjectCommon& other, bool similar) const override;
411+
void initializeEvent(int nChannels, int dataLength);
365412
const EventChannelTypes m_type;
413+
const EventTimestampOrigin m_timestampOrigin;
414+
const uint16 m_timestampOriginProcessor;
415+
const uint16 m_timestampOriginSubProcessor;
416+
366417
unsigned int m_numChannels{ 1 };
367418
size_t m_dataSize{ 1 };
368419
unsigned int m_length{ 1 };

Source/Processors/PluginManager/OpenEphysPlugin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class SourceNode;
4848
class RecordEngineManager;
4949
class FileSource;
5050

51-
#define PLUGIN_API_VER 5
51+
#define PLUGIN_API_VER 6
5252

5353
typedef GenericProcessor*(*ProcessorCreator)();
5454
typedef DataThread*(*DataThreadCreator)(SourceNode*);

0 commit comments

Comments
 (0)