Skip to content

Commit 52a0b09

Browse files
committed
Rework global timestamp source system
1 parent e8c0e9b commit 52a0b09

21 files changed

Lines changed: 486 additions & 253 deletions

Builds/VisualStudio2013/open-ephys.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@
325325
<ClCompile Include="..\..\Source\Processors\Visualization\Visualizer.cpp" />
326326
<ClCompile Include="..\..\Source\Processors\Visualization\DataWindow.cpp" />
327327
<ClCompile Include="..\..\Source\Processors\Visualization\MatlabLikePlot.cpp" />
328+
<ClCompile Include="..\..\Source\UI\TimestampSourceSelection.cpp" />
328329
<ClCompile Include="..\..\Source\UI\Utils\TiledButtonGroupManager.cpp" />
329330
<ClCompile Include="..\..\Source\UI\Utils\LinearButtonGroupManager.cpp" />
330331
<ClCompile Include="..\..\Source\UI\Utils\ButtonGroupManager.cpp" />
@@ -1994,6 +1995,7 @@
19941995
<ClInclude Include="..\..\Source\Processors\Visualization\DataWindow.h" />
19951996
<ClInclude Include="..\..\Source\Processors\Visualization\Visualizer.h" />
19961997
<ClInclude Include="..\..\Source\Processors\Visualization\MatlabLikePlot.h" />
1998+
<ClInclude Include="..\..\Source\UI\TimestampSourceSelection.h" />
19971999
<ClInclude Include="..\..\Source\UI\Utils\TiledButtonGroupManager.h" />
19982000
<ClInclude Include="..\..\Source\UI\Utils\LinearButtonGroupManager.h" />
19992001
<ClInclude Include="..\..\Source\UI\Utils\ButtonGroupManager.h" />

Builds/VisualStudio2013/open-ephys.vcxproj.filters

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2337,6 +2337,9 @@
23372337
<ClCompile Include="..\..\Source\Processors\Events\Events.cpp">
23382338
<Filter>open-ephys\Source\Processors\Events</Filter>
23392339
</ClCompile>
2340+
<ClCompile Include="..\..\Source\UI\TimestampSourceSelection.cpp">
2341+
<Filter>open-ephys\Source\UI</Filter>
2342+
</ClCompile>
23402343
</ItemGroup>
23412344
<ItemGroup>
23422345
<ClInclude Include="..\..\Source\Audio\AudioComponent.h">
@@ -4546,6 +4549,23 @@
45464549
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_gui_extra\juce_gui_extra.h" />
45474550
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_opengl\juce_opengl.h" />
45484551
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_video\juce_video.h" />
4552+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_audio_basics\juce_audio_basics.h" />
4553+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_audio_devices\juce_audio_devices.h" />
4554+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_audio_formats\juce_audio_formats.h" />
4555+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_audio_processors\juce_audio_processors.h" />
4556+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_audio_utils\juce_audio_utils.h" />
4557+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_core\juce_core.h" />
4558+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_cryptography\juce_cryptography.h" />
4559+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_data_structures\juce_data_structures.h" />
4560+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_events\juce_events.h" />
4561+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_graphics\juce_graphics.h" />
4562+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_gui_basics\juce_gui_basics.h" />
4563+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_gui_extra\juce_gui_extra.h" />
4564+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_opengl\juce_opengl.h" />
4565+
<ClInclude Include="..\..\JuceLibraryCode\modules\juce_video\juce_video.h" />
4566+
<ClInclude Include="..\..\Source\UI\TimestampSourceSelection.h">
4567+
<Filter>open-ephys\Source\UI</Filter>
4568+
</ClInclude>
45494569
</ItemGroup>
45504570
<ItemGroup>
45514571
<None Include="..\..\Resources\Icons\icon-large.png">

Source/CoreServices.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,22 @@ void highlightEditor(GenericEditor* ed)
8080

8181
int64 getGlobalTimestamp()
8282
{
83-
return static_cast<MessageCenter*>(&(getMessageCenter()->processor))->getGlobalTimestamp();
83+
return getProcessorGraph()->getGlobalTimestamp(false);
8484
}
8585

8686
int64 getSoftwareTimestamp()
8787
{
88-
return static_cast<MessageCenter*>(&(getMessageCenter()->processor))->getGlobalTimestamp(true);
88+
return getProcessorGraph()->getGlobalTimestamp(true);
8989
}
9090

9191
float getGlobalSampleRate()
9292
{
93-
return static_cast<MessageCenter*>(&(getMessageCenter()->processor))->getGlobalSampleRate();
93+
return getProcessorGraph()->getGlobalSampleRate(false);
94+
}
95+
96+
float getSoftwareSampleRate()
97+
{
98+
return getProcessorGraph()->getGlobalSampleRate(true);
9499
}
95100

96101
void setRecordingDirectory(String dir)

Source/CoreServices.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ PLUGIN_API float getGlobalSampleRate();
7171
/** Gets the software timestamp based on a high resolution timer aligned to the start of each processing block */
7272
PLUGIN_API int64 getSoftwareTimestamp();
7373

74+
/** Gets the ticker frequency of the software timestamp clock*/
75+
PLUGIN_API float getSoftwareSampleRate();
76+
7477
/** Set new recording directory */
7578
PLUGIN_API void setRecordingDirectory(String dir);
7679

Source/Processors/GenericProcessor/GenericProcessor.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ GenericProcessor::GenericProcessor (const String& name)
4646
, m_processorType (PROCESSOR_TYPE_UTILITY)
4747
{
4848
settings.numInputs = settings.numOutputs = 0;
49+
m_lastProcessTime = Time::getHighResolutionTicks();
4950
}
5051

5152

@@ -797,8 +798,10 @@ void GenericProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& even
797798
m_currentMidiBuffer = &eventBuffer;
798799
processEventBuffer (); // extract buffer sizes and timestamps,
799800
// set flag on all TTL events to zero
800-
801+
802+
m_lastProcessTime = Time::getHighResolutionTicks();
801803
process (buffer);
804+
802805
}
803806

804807
const DataChannel* GenericProcessor::getDataChannel(int index) const
@@ -1193,6 +1196,17 @@ void GenericProcessor::setEnabledState (bool t)
11931196
isEnabled = t;
11941197
}
11951198

1199+
bool GenericProcessor::enableProcessor()
1200+
{
1201+
m_lastProcessTime = Time::getHighResolutionTicks();
1202+
return enable();
1203+
}
1204+
1205+
bool GenericProcessor::disableProcessor()
1206+
{
1207+
return disable();
1208+
}
1209+
11961210
bool GenericProcessor::enable()
11971211
{
11981212
return isEnabled;
@@ -1223,6 +1237,11 @@ uint32 GenericProcessor::getProcessorFullId(uint16 sid, uint16 subid)
12231237
return uint32(sid) << 16 + subid;
12241238
}
12251239

1240+
int64 GenericProcessor::getLastProcessedsoftwareTime() const
1241+
{
1242+
return m_lastProcessTime;
1243+
}
1244+
12261245
void ChannelCreationIndexes::clearChannelCreationCounts()
12271246
{
12281247
dataChannelCount = 0;
@@ -1231,4 +1250,4 @@ void ChannelCreationIndexes::clearChannelCreationCounts()
12311250
eventChannelTypeCount.clear();
12321251
spikeChannelCount = 0;
12331252
spikeChannelTypeCount.clear();
1234-
}
1253+
}

Source/Processors/GenericProcessor/GenericProcessor.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,13 @@ class PLUGIN_API GenericProcessor : public AudioProcessor
337337
/** Returns true if a processor is ready to process data (e.g., all of its parameters are initialized, and its data source is connected).*/
338338
virtual bool isReady();
339339

340+
bool enableProcessor();
341+
340342
/** Called immediately prior to the start of data acquisition, once all processors in the signal chain have indicated they are ready to process data.*/
341343
virtual bool enable();
342344

345+
bool disableProcessor();
346+
343347
/** Called immediately after the end of data acquisition.*/
344348
virtual bool disable();
345349

@@ -484,9 +488,6 @@ class PLUGIN_API GenericProcessor : public AudioProcessor
484488
@see GenericProcessor::getProcessorFullId(uint16,uint16) */
485489
uint64 getSourceTimestamp(uint32 fullSourceID) const;
486490

487-
/** Used to set the timestamp for a given buffer, for a given source node. */
488-
void setTimestampAndSamples (uint64 timestamp, uint32 nSamples, int subProcessorIdx = 0);
489-
490491
virtual int getNumSubProcessors() const;
491492

492493
int getDataChannelIndex(int channelIdx, int processorID, int subProcessorIdx = 0) const;
@@ -517,6 +518,8 @@ class PLUGIN_API GenericProcessor : public AudioProcessor
517518

518519
PluginProcessorType getProcessorType() const;
519520

521+
int64 getLastProcessedsoftwareTime() const;
522+
520523
static uint32 getProcessorFullId(uint16 processorId, uint16 subprocessorIdx);
521524

522525
class PLUGIN_API DefaultEventInfo
@@ -531,6 +534,8 @@ class PLUGIN_API GenericProcessor : public AudioProcessor
531534
};
532535

533536
protected:
537+
/** Used to set the timestamp for a given buffer, for a given source node. */
538+
void setTimestampAndSamples(uint64 timestamp, uint32 nSamples, int subProcessorIdx = 0);
534539

535540
/** Can be called by processors that need to respond to incoming events.
536541
Set respondToSpikes to true if the processor should also search for spikes*/
@@ -595,6 +600,8 @@ class PLUGIN_API GenericProcessor : public AudioProcessor
595600
std::map<uint32, uint32> numSamples;
596601
std::map<uint32, int64> timestamps;
597602

603+
int64 m_lastProcessTime;
604+
598605
void createDataChannelsByType(DataChannel::DataChannelTypes type);
599606

600607
/** Each processor has a unique integer ID that can be used to identify it.*/

Source/Processors/MessageCenter/MessageCenter.cpp

Lines changed: 4 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
//---------------------------------------------------------------------
3030

3131
MessageCenter::MessageCenter() :
32-
GenericProcessor("Message Center"), newEventAvailable(false), isRecording(false), sourceNodeId(0), sourceNodeSubIdx(0),
33-
timestampSource(nullptr), lastTime(0), softTimestamp(0)
32+
GenericProcessor("Message Center"), newEventAvailable(false), isRecording(false)
3433
{
3534

3635
setPlayConfigDetails(0, // number of inputs
@@ -46,7 +45,7 @@ MessageCenter::~MessageCenter()
4645

4746
void MessageCenter::addSpecialProcessorChannels(Array<EventChannel*>& channels)
4847
{
49-
EventChannel* chan = new EventChannel(EventChannel::TEXT, 1, MAX_MSG_LENGTH, getGlobalSampleRate(), this, 0);
48+
EventChannel* chan = new EventChannel(EventChannel::TEXT, 1, MAX_MSG_LENGTH, CoreServices::getGlobalSampleRate(), this, 0);
5049
chan->setName("GUI Messages");
5150
chan->setDescription("Messages from the GUI Message Center");
5251
channels.add(chan);
@@ -80,25 +79,6 @@ void MessageCenter::setParameter(int parameterIndex, float newValue)
8079
bool MessageCenter::enable()
8180
{
8281
messageCenterEditor->startAcquisition();
83-
lastTime = Time::getHighResolutionTicks();
84-
softTimestamp = 0;
85-
if (sourceNodeId)
86-
{
87-
AudioProcessorGraph::Node* node = AccessClass::getProcessorGraph()->getNodeForId(sourceNodeId);
88-
if (node)
89-
{
90-
timestampSource = static_cast<GenericProcessor*>(node->getProcessor());
91-
}
92-
else
93-
{
94-
std::cout << "Message Center: BAD node id " << sourceNodeId << std::endl;
95-
timestampSource = nullptr;
96-
sourceNodeId = 0;
97-
}
98-
}
99-
else
100-
timestampSource = nullptr;
101-
10282
return true;
10383
}
10484

@@ -108,52 +88,14 @@ bool MessageCenter::disable()
10888
return true;
10989
}
11090

111-
void MessageCenter::setSourceNodeId(int id, int sub)
112-
{
113-
sourceNodeId = id;
114-
sourceNodeSubIdx = sub;
115-
AudioProcessorGraph::Node* node = AccessClass::getProcessorGraph()->getNodeForId(sourceNodeId);
116-
if (node)
117-
{
118-
timestampSource = static_cast<GenericProcessor*>(node->getProcessor());
119-
}
120-
}
121-
122-
int MessageCenter::getSourceNodeId()
123-
{
124-
return sourceNodeId;
125-
}
126-
127-
int MessageCenter::getSourceSubIdx()
128-
{
129-
return sourceNodeSubIdx;
130-
}
131-
132-
int64 MessageCenter::getGlobalTimestamp(bool softwareTime)
133-
{
134-
if (!softwareTime && sourceNodeId > 0)
135-
return timestampSource->getSourceTimestamp(sourceNodeId, sourceNodeSubIdx);
136-
else
137-
return (softTimestamp);
138-
}
139-
140-
float MessageCenter::getGlobalSampleRate()
141-
{
142-
if (sourceNodeId > 0)
143-
return timestampSource->getSampleRate(sourceNodeSubIdx);
144-
else
145-
return Time::getHighResolutionTicksPerSecond();
146-
}
14791

14892
void MessageCenter::process(AudioSampleBuffer& buffer)
14993
{
150-
softTimestamp = Time::getHighResolutionTicks() - lastTime;
151-
setTimestampAndSamples(getGlobalTimestamp(), 0);
15294
if (needsToSendTimestampMessage)
15395
{
15496
MidiBuffer& eventBuffer = *AccessClass::ExternalProcessorAccessor::getMidiBuffer(this);
15597
HeapBlock<char> data;
156-
size_t dataSize = SystemEvent::fillTimestampSyncTextData(data, this, 0, getTimestamp(true), true);
98+
size_t dataSize = SystemEvent::fillTimestampSyncTextData(data, this, 0, CoreServices::getGlobalTimestamp(), true);
15799

158100
eventBuffer.addEvent(data, dataSize, 0);
159101

@@ -168,21 +110,11 @@ void MessageCenter::process(AudioSampleBuffer& buffer)
168110

169111
eventString = eventString.dropLastCharacters(eventString.length() - MAX_MSG_LENGTH);
170112

171-
TextEventPtr event = TextEvent::createTextEvent(getEventChannel(0), getGlobalTimestamp(), eventString);
113+
TextEventPtr event = TextEvent::createTextEvent(getEventChannel(0), CoreServices::getGlobalTimestamp(), eventString);
172114
addEvent(getEventChannel(0), event, 0);
173115

174116
newEventAvailable = false;
175117
}
176118

177119

178-
}
179-
180-
void MessageCenter::addSourceProcessor(GenericProcessor* p)
181-
{
182-
messageCenterEditor->addSourceProcessor(p);
183-
}
184-
185-
void MessageCenter::removeSourceProcessor(GenericProcessor* p)
186-
{
187-
messageCenterEditor->removeSourceProcessor(p);
188120
}

Source/Processors/MessageCenter/MessageCenter.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,11 @@ class MessageCenter : public GenericProcessor
7575
needsToSendTimestampMessage = false;
7676
}
7777

78-
void setSourceNodeId(int id, int sub);
79-
int getSourceNodeId();
80-
int getSourceSubIdx();
81-
82-
void addSourceProcessor(GenericProcessor* p);
83-
void removeSourceProcessor(GenericProcessor* p);
84-
85-
int64 getGlobalTimestamp(bool softwareTime = false);
86-
float getGlobalSampleRate();
87-
8878
void addSpecialProcessorChannels(Array<EventChannel*>& channel);
8979
private:
9080

9181
bool newEventAvailable;
9282
bool isRecording;
93-
int sourceNodeId;
94-
int sourceNodeSubIdx;
95-
const GenericProcessor* timestampSource;
96-
int64 lastTime, softTimestamp;
9783
bool needsToSendTimestampMessage;
9884

9985
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MessageCenter);

0 commit comments

Comments
 (0)